UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

122 lines 4.46 kB
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _createClass from "@babel/runtime/helpers/createClass"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import { globalContext } from '@alilc/lowcode-editor-core'; import { PluginInstance as ShellPluginInstance } from '../model'; import { pluginsSymbol } from '../symbols'; var innerPluginsSymbol = Symbol('plugin'); export var Plugins = /*#__PURE__*/function () { function Plugins(plugins, workspaceMode) { if (workspaceMode === void 0) { workspaceMode = false; } this.workspaceMode = workspaceMode; this[innerPluginsSymbol] = void 0; this[innerPluginsSymbol] = plugins; } var _proto = Plugins.prototype; _proto.register = /*#__PURE__*/function () { var _register = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(pluginModel, options, registerOptions) { return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return this[pluginsSymbol].register(pluginModel, options, registerOptions); case 2: case "end": return _context.stop(); } }, _callee, this); })); function register(_x, _x2, _x3) { return _register.apply(this, arguments); } return register; }(); _proto.init = /*#__PURE__*/function () { var _init = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(registerOptions) { return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return this[pluginsSymbol].init(registerOptions); case 2: case "end": return _context2.stop(); } }, _callee2, this); })); function init(_x4) { return _init.apply(this, arguments); } return init; }(); _proto.getPluginPreference = function getPluginPreference(pluginName) { return this[pluginsSymbol].getPluginPreference(pluginName); }; _proto.get = function get(pluginName) { var instance = this[pluginsSymbol].get(pluginName); if (instance) { return new ShellPluginInstance(instance); } return null; }; _proto.getAll = function getAll() { var _this$pluginsSymbol$g; return (_this$pluginsSymbol$g = this[pluginsSymbol].getAll()) === null || _this$pluginsSymbol$g === void 0 ? void 0 : _this$pluginsSymbol$g.map(function (d) { return new ShellPluginInstance(d); }); }; _proto.has = function has(pluginName) { return this[pluginsSymbol].has(pluginName); }; _proto["delete"] = /*#__PURE__*/function () { var _delete2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(pluginName) { return _regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return this[pluginsSymbol]["delete"](pluginName); case 2: return _context3.abrupt("return", _context3.sent); case 3: case "end": return _context3.stop(); } }, _callee3, this); })); function _delete(_x5) { return _delete2.apply(this, arguments); } return _delete; }(); _proto.toProxy = function toProxy() { return new Proxy(this, { get: function get(target, prop, receiver) { var _target = target[pluginsSymbol]; if (_target.pluginsMap.has(prop)) { var _target$pluginsMap$ge; // 禁用态的插件,直接返回 undefined if (_target.pluginsMap.get(prop).disabled) { return undefined; } return (_target$pluginsMap$ge = _target.pluginsMap.get(prop)) === null || _target$pluginsMap$ge === void 0 ? void 0 : _target$pluginsMap$ge.toProxy(); } return Reflect.get(target, prop, receiver); } }); }; return _createClass(Plugins, [{ key: pluginsSymbol, get: function get() { if (this.workspaceMode) { return this[innerPluginsSymbol]; } var workspace = globalContext.get('workspace'); if (workspace.isActive) { return workspace.window.innerPlugins; } return this[innerPluginsSymbol]; } }]); }();