UNPKG

@difizen/mana-core

Version:

96 lines (95 loc) 7.45 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } var _dec, _dec2, _class, _class2, _descriptor; function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; } function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); } import { Emitter } from '@difizen/mana-common'; import { prop } from '@difizen/mana-observable'; import { contrib, inject, singleton, Syringe } from '@difizen/mana-syringe'; import { ApplicationContribution } from "../application"; import { ToolbarItem, ToolbarItemFactory } from "./toolbar-protocol"; /** * Clients should implement this interface if they want to contribute to the toolbar. */ export var ToolbarContribution = Syringe.defineToken('ToolbarContribution'); /** * Main, shared registry for tab-bar toolbar items. */ export var ToolbarRegistry = (_dec = singleton({ contrib: ApplicationContribution }), _dec2 = prop(), _dec(_class = (_class2 = /*#__PURE__*/function () { function ToolbarRegistry(toolbarItemFactory, contributionProvider) { _classCallCheck(this, ToolbarRegistry); _initializerDefineProperty(this, "items", _descriptor, this); this.onDidChangeEmitter = new Emitter(); this.toolbarItemFactory = toolbarItemFactory; this.contributionProvider = contributionProvider; } ToolbarRegistry = contrib(ToolbarContribution)(ToolbarRegistry, undefined, 1) || ToolbarRegistry; ToolbarRegistry = inject(ToolbarItemFactory)(ToolbarRegistry, undefined, 0) || ToolbarRegistry; _createClass(ToolbarRegistry, [{ key: "onStart", value: function onStart() { var contributions = this.contributionProvider.getContributions(); var _iterator = _createForOfIteratorHelper(contributions), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var contribution = _step.value; contribution.registerToolbarItems(this); } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } /** * Registers the given item. Throws an error, if the corresponding command cannot be found or an item has been already registered for the desired command. * * @param item the item to register. */ }, { key: "registerItem", value: function registerItem(def) { var _this = this; var id = def.id; if (this.items.has(id)) { throw new Error("A toolbar item is already registered with the '".concat(id, "' ID.")); } var item = ToolbarItem.is(def) ? def : this.toolbarItemFactory(def); this.items.set(id, item); item.onDisposed(function () { return _this.items.delete(id); }); return item; } }, { key: "getToolbarItem", value: function getToolbarItem(id) { return this.items.get(id); } }, { key: "unregisterItem", value: function unregisterItem(itemOrId) { var id = typeof itemOrId === 'string' ? itemOrId : itemOrId.id; this.items.delete(id); } }]); return ToolbarRegistry; }(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "items", [_dec2], { configurable: true, enumerable: true, writable: true, initializer: function initializer() { return new Map(); } })), _class2)) || _class);