35 lines
1.5 KiB
JavaScript
35 lines
1.5 KiB
JavaScript
|
|
// machineGroupControl editor — namespace bootstrap.
|
||
|
|
//
|
||
|
|
// Attaches the editor's submodule registry to the shared
|
||
|
|
// window.EVOLV.nodes.machineGroupControl namespace (same one the menuManager
|
||
|
|
// and configManager endpoints populate). Each sibling module in this
|
||
|
|
// directory (mode-cards.js, demand-contract.js, oneditprepare.js) registers
|
||
|
|
// itself by writing additional members onto this namespace.
|
||
|
|
//
|
||
|
|
// Loaded first by mgc.html — must not depend on any other src/editor module.
|
||
|
|
|
||
|
|
(function () {
|
||
|
|
const root = window.EVOLV = window.EVOLV || {};
|
||
|
|
const nodes = root.nodes = root.nodes || {};
|
||
|
|
const ns = nodes.machineGroupControl = nodes.machineGroupControl || {};
|
||
|
|
const editor = ns.editor = ns.editor || {};
|
||
|
|
|
||
|
|
// Pub/sub for mode changes — mode-cards.js fires, anything that wants to
|
||
|
|
// re-render on mode change subscribes. Keep it tiny; no third-party emitter.
|
||
|
|
const modeListeners = [];
|
||
|
|
editor.onModeChange = (cb) => { if (typeof cb === 'function') modeListeners.push(cb); };
|
||
|
|
editor.emitModeChange = (newMode) => {
|
||
|
|
for (const cb of modeListeners) {
|
||
|
|
try { cb(newMode); } catch (e) { /* swallow — UI helper */ }
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// Read the currently selected mode from the hidden input that mode-cards.js
|
||
|
|
// keeps in sync with the active card. Falls back to optimalControl if the
|
||
|
|
// input isn't on the page yet (race against oneditprepare).
|
||
|
|
editor.getMode = () => {
|
||
|
|
const el = document.getElementById('node-input-mode');
|
||
|
|
return (el && el.value) || 'optimalControl';
|
||
|
|
};
|
||
|
|
})();
|