UNPKG

mj-context-menu

Version:
73 lines 2.89 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { Command } from './item_command.js'; import { ContextMenu } from './context_menu.js'; import { Variable } from './variable.js'; import { Checkbox } from './item_checkbox.js'; import { Combo } from './item_combo.js'; import { Label } from './item_label.js'; import { Radio } from './item_radio.js'; import { Submenu } from './item_submenu.js'; import { Rule } from './item_rule.js'; import { Slider } from './item_slider.js'; import { SubMenu } from './sub_menu.js'; import { SelectionMenu, SelectionBox } from './selection_box.js'; import { ParserFactory } from './parser_factory.js'; export class Parser { constructor(init = []) { this._initList = [ ['command', Command.fromJson.bind(Command)], ['checkbox', Checkbox.fromJson.bind(Checkbox)], ['combo', Combo.fromJson.bind(Combo)], ['slider', Slider.fromJson.bind(Slider)], ['label', Label.fromJson.bind(Label)], ['radio', Radio.fromJson.bind(Radio)], ['rule', Rule.fromJson.bind(Rule)], ['submenu', Submenu.fromJson.bind(Submenu)], ['contextMenu', ContextMenu.fromJson.bind(ContextMenu)], ['subMenu', SubMenu.fromJson.bind(SubMenu)], ['variable', Variable.fromJson.bind(Variable)], ['items', this.items.bind(this)], ['selectionMenu', SelectionMenu.fromJson.bind(SelectionMenu)], ['selectionBox', SelectionBox.fromJson.bind(SelectionBox)] ]; this._factory = new ParserFactory(this._initList); init.forEach(([x, y]) => this.factory.add(x, y)); } get factory() { return this._factory; } items(_factory, its, ctxt) { const hidden = []; for (const item of its) { const entry = this.parse(item, ctxt); if (!entry) { continue; } ctxt.items.push(entry); if (item.disabled) { entry.disable(); } if (item.hidden) { hidden.push(entry); } } hidden.forEach((x) => x.hide()); return ctxt.items; } parse(_a, ...rest) { var { type: kind } = _a, json = __rest(_a, ["type"]); const func = this.factory.get(kind); return func ? func(this.factory, json, ...rest) : null; } } //# sourceMappingURL=parse.js.map