UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

274 lines (260 loc) 8.79 kB
import _extends from "@babel/runtime/helpers/extends"; import _createClass from "@babel/runtime/helpers/createClass"; import { globalContext } from '@alilc/lowcode-editor-core'; import { SkeletonEvents } from '@alilc/lowcode-editor-skeleton'; import { skeletonSymbol } from '../symbols'; import { getLogger } from '@alilc/lowcode-utils'; import { SkeletonItem } from '../model/skeleton-item'; var innerSkeletonSymbol = Symbol('skeleton'); var logger = getLogger({ level: 'warn', bizName: 'shell-skeleton' }); export var Skeleton = /*#__PURE__*/function () { function Skeleton(skeleton, pluginName, workspaceMode) { if (workspaceMode === void 0) { workspaceMode = false; } this.workspaceMode = workspaceMode; this[innerSkeletonSymbol] = void 0; this.pluginName = void 0; this[innerSkeletonSymbol] = skeleton; this.pluginName = pluginName; } /** * 增加一个面板实例 * @param config * @param extraConfig * @returns */ var _proto = Skeleton.prototype; _proto.add = function add(config, extraConfig) { var configWithName = _extends({}, config, { pluginName: this.pluginName }); var item = this[skeletonSymbol].add(configWithName, extraConfig); if (item) { return new SkeletonItem(item); } } /** * 移除一个面板实例 * @param config * @returns */; _proto.remove = function remove(config) { var _skeleton$normalizeAr; var area = config.area, name = config.name; var skeleton = this[skeletonSymbol]; if (!normalizeArea(area)) { return; } (_skeleton$normalizeAr = skeleton[normalizeArea(area)].container) === null || _skeleton$normalizeAr === void 0 ? void 0 : _skeleton$normalizeAr.remove(name); }; _proto.getAreaItems = function getAreaItems(areaName) { var _this$skeletonSymbol$; return (_this$skeletonSymbol$ = this[skeletonSymbol][normalizeArea(areaName)].container.items) === null || _this$skeletonSymbol$ === void 0 ? void 0 : _this$skeletonSymbol$.map(function (d) { return new SkeletonItem(d); }); }; _proto.getPanel = function getPanel(name) { var item = this[skeletonSymbol].getPanel(name); if (!item) { return; } return new SkeletonItem(item); } /** * 显示面板 * @param name */; _proto.showPanel = function showPanel(name) { var _this$skeletonSymbol$2; (_this$skeletonSymbol$2 = this[skeletonSymbol].getPanel(name)) === null || _this$skeletonSymbol$2 === void 0 ? void 0 : _this$skeletonSymbol$2.show(); } /** * 隐藏面板 * @param name */; _proto.hidePanel = function hidePanel(name) { var _this$skeletonSymbol$3; (_this$skeletonSymbol$3 = this[skeletonSymbol].getPanel(name)) === null || _this$skeletonSymbol$3 === void 0 ? void 0 : _this$skeletonSymbol$3.hide(); } /** * 显示 widget * @param name */; _proto.showWidget = function showWidget(name) { var _this$skeletonSymbol$4; (_this$skeletonSymbol$4 = this[skeletonSymbol].getWidget(name)) === null || _this$skeletonSymbol$4 === void 0 ? void 0 : _this$skeletonSymbol$4.show(); } /** * enable widget * @param name */; _proto.enableWidget = function enableWidget(name) { var _this$skeletonSymbol$5, _this$skeletonSymbol$6; (_this$skeletonSymbol$5 = this[skeletonSymbol].getWidget(name)) === null || _this$skeletonSymbol$5 === void 0 ? void 0 : (_this$skeletonSymbol$6 = _this$skeletonSymbol$5.enable) === null || _this$skeletonSymbol$6 === void 0 ? void 0 : _this$skeletonSymbol$6.call(_this$skeletonSymbol$5); } /** * 隐藏 widget * @param name */; _proto.hideWidget = function hideWidget(name) { var _this$skeletonSymbol$7; (_this$skeletonSymbol$7 = this[skeletonSymbol].getWidget(name)) === null || _this$skeletonSymbol$7 === void 0 ? void 0 : _this$skeletonSymbol$7.hide(); } /** * disable widget,不可点击 * @param name */; _proto.disableWidget = function disableWidget(name) { var _this$skeletonSymbol$8, _this$skeletonSymbol$9; (_this$skeletonSymbol$8 = this[skeletonSymbol].getWidget(name)) === null || _this$skeletonSymbol$8 === void 0 ? void 0 : (_this$skeletonSymbol$9 = _this$skeletonSymbol$8.disable) === null || _this$skeletonSymbol$9 === void 0 ? void 0 : _this$skeletonSymbol$9.call(_this$skeletonSymbol$8); } /** * show area * @param areaName name of area */; _proto.showArea = function showArea(areaName) { var _areaName; (_areaName = this[skeletonSymbol][areaName]) === null || _areaName === void 0 ? void 0 : _areaName.show(); } /** * hide area * @param areaName name of area */; _proto.hideArea = function hideArea(areaName) { var _areaName2; (_areaName2 = this[skeletonSymbol][areaName]) === null || _areaName2 === void 0 ? void 0 : _areaName2.hide(); } /** * 监听 panel 显示事件 * @param listener * @returns */; _proto.onShowPanel = function onShowPanel(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.PANEL_SHOW, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.PANEL_SHOW, listener); }; }; _proto.onDisableWidget = function onDisableWidget(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.WIDGET_DISABLE, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.WIDGET_DISABLE, listener); }; }; _proto.onEnableWidget = function onEnableWidget(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.WIDGET_ENABLE, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.WIDGET_ENABLE, listener); }; } /** * 监听 panel 隐藏事件 * @param listener * @returns */; _proto.onHidePanel = function onHidePanel(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.PANEL_HIDE, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.PANEL_HIDE, listener); }; } /** * 监听 widget 显示事件 * @param listener * @returns */; _proto.onShowWidget = function onShowWidget(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.WIDGET_SHOW, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.WIDGET_SHOW, listener); }; } /** * 监听 widget 隐藏事件 * @param listener * @returns */; _proto.onHideWidget = function onHideWidget(listener) { var editor = this[skeletonSymbol].editor; editor.eventBus.on(SkeletonEvents.WIDGET_HIDE, function (name, panel) { listener(name, new SkeletonItem(panel)); }); return function () { return editor.eventBus.off(SkeletonEvents.WIDGET_HIDE, listener); }; }; _proto.registerConfigTransducer = function registerConfigTransducer(fn, level, id) { this[skeletonSymbol].registerConfigTransducer(fn, level, id); }; return _createClass(Skeleton, [{ key: skeletonSymbol, get: function get() { if (this.workspaceMode) { return this[innerSkeletonSymbol]; } var workspace = globalContext.get('workspace'); if (workspace.isActive) { var _workspace$window; if (!((_workspace$window = workspace.window) !== null && _workspace$window !== void 0 && _workspace$window.innerSkeleton)) { logger.error('skeleton api 调用时机出现问题,请检查'); return this[innerSkeletonSymbol]; } return workspace.window.innerSkeleton; } return this[innerSkeletonSymbol]; } }]); }(); function normalizeArea(area) { switch (area) { case 'leftArea': case 'left': return 'leftArea'; case 'rightArea': case 'right': return 'rightArea'; case 'topArea': case 'top': return 'topArea'; case 'toolbar': return 'toolbar'; case 'mainArea': case 'main': case 'center': case 'centerArea': return 'mainArea'; case 'bottomArea': case 'bottom': return 'bottomArea'; case 'leftFixedArea': return 'leftFixedArea'; case 'leftFloatArea': return 'leftFloatArea'; case 'stages': return 'stages'; case 'subTopArea': return 'subTopArea'; default: throw new Error(area + " not supported"); } }