add seperate function to instantiate the extras

Can be done automatically under design()
This commit is contained in:
buzz-lightsnack-2007 2024-05-17 16:21:31 +08:00
parent b3b6522f52
commit f59e1d304c
2 changed files with 43 additions and 11 deletions

View file

@ -0,0 +1,9 @@
import {Search} from "./windowman.search.js";
import {Tabs} from "./windowman.tabs.js";
class UI {}
UI.search = Search;
UI.tabs = Tabs;
export {UI as default};

View file

@ -6,7 +6,7 @@ import Tabs from "/scripts/GUI/tabs.js";
import {global, observe} from "/scripts/secretariat.js";
import {URLs} from "/scripts/utils/URLs.js";
import wait from "/scripts/utils/wait.js";
import UI from "/scripts/GUI/builder/windowman.search.js";
import UI from "/scripts/GUI/builder/windowman.extras.js";
export default class windowman {
elements = {};
@ -308,10 +308,43 @@ export default class windowman {
actions();
}
/*
Instantiate the extras.
*/
const extras = () => {
// Add the search interface.
(Object.keys(UI)).forEach((FEATURE) => {
this.extra(FEATURE, (this[`options`] && (typeof this[`options`]).includes(`obj`)) ? this[`options`][FEATURE] : null);
})
}
// Add the elements.
this[`elements`] = appearance();
events();
// Add the extras.
(((this[`options`] && (typeof this[`options`]).includes(`obj`)) ? Object.hasOwn(this[`options`], `automatic`) : false) ? this[`options`][`automatic`] : true)
? extras()
: false;
}
/*
Instantiate the extras.
@param {string} name The name of the extra UI feature
@param {object} options The options for the extra UI feature
*/
extra(name, options) {
(Object.keys(UI)).includes(name)
?
// De-instantiate the feature if a cancel option is passed.
(((options && (typeof options).includes(`obj`)) ? options[`cancel`] : false)
? delete this[name]
: (this[name] = (this[name]) ? this[name] : new UI[name](options))
)
: false;
};
/* Run this function if you would like to synchronize with data. */
async sync() {
// Prepare flags.
@ -487,16 +520,6 @@ export default class windowman {
}
};
/*
Instantiate the extras.
*/
const extras = () => {
// Add the search interface.
(Object.keys(UI)).forEach((FEATURE) => {
this[FEATURE] = new UI[FEATURE]();
})
}
fill();
write();
extras();