User:Moonythedwarf/libcui.js

"use strict";

if (window.libcui == undefined) { let cui = {}; window.libcui = cui; cui.build_element_from_desc = (desc, uibase, parent) => { if (OO.ui[desc.type] === undefined && !desc.rawtag) { throw new Error(`Encountered invalid element ${desc.type}!`); }		let elem; if (desc.settings === undefined) { desc.settings = {}; }		switch (desc.type) { case undefined: elem = new OO.ui.HtmlSnippet(desc.rawtag) break; case "FieldsetLayout": elem = new OO.ui.FieldsetLayout({       			label: desc.settings.label    			}); let built_children = []; for (let j of desc.children) { built_children.push({elem: cui.build_ui_impl([j.elem], uibase, elem)[0], label: i.label}); }				let items = []; for (let i of built_children) { items.push(new OO.ui.FieldLayout(i.elem, { "label": i.label } )); }				elem.addItems(items); break; default: elem = new OO.ui[desc.type]({					label: desc.settings.label,					expanded: desc.settings.expanded,					framed: desc.settings.framed,					padded: desc.settings.padded,					flags: desc.settings.flags,					placeholder: desc.settings.placeholder,					options: desc.settings.options,					classes: desc.settings.classes,				}); break; }		if (parent) { parent["uielem" + desc.name] = elem; } else { uibase[desc.name] = elem; }		if (desc.settings.ref_at_root) { uibase[desc.name] = elem; }		return elem; }	cui.build_ui_impl = (uidesc, uibase, parent) => { let built = []; for (let i of uidesc) { let e = cui.build_element_from_desc(i, uibase, parent); if (i.append) { let r = cui.build_ui_impl(i.append, uibase); e.$element.append(r.map(a => a.$element)); }			built.push(e); }		return built; };	cui.build_ui = (uidesc, uibase, target) => { let r = cui.build_ui_impl(uidesc, uibase, undefined); target.append(r.map(a => a.$element)); }	cui.load_libcui = async => { await mw.loader.using(["oojs", "oojs-ui-core", "oojs-ui-widgets", "oojs-ui-toolbars"]); } }