UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

719 lines (656 loc) 17.2 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.Node = void 0; var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _lowcodeTypes = require("@alilc/lowcode-types"); var _prop = require("./prop"); var _props = require("./props"); var _documentModel = require("./document-model"); var _nodeChildren = require("./node-children"); var _componentMeta = require("./component-meta"); var _settingTopEntry = require("./setting-top-entry"); var _symbols = require("../symbols"); var _conditionGroup = require("./condition-group"); var shellNodeSymbol = Symbol('shellNodeSymbol'); function isShellNode(node) { return node[shellNodeSymbol]; } var Node = exports.Node = /*#__PURE__*/function () { function Node(node) { this[_symbols.documentSymbol] = void 0; this[_symbols.nodeSymbol] = void 0; this._id = void 0; /** * judge if it is a node or not */ this.isNode = true; this[_symbols.nodeSymbol] = node; this[_symbols.documentSymbol] = node.document; this._id = this[_symbols.nodeSymbol].id; } Node.create = function create(node) { if (!node) { return null; } // @ts-ignore 直接返回已挂载的 shell node 实例 if (isShellNode(node)) { return node[shellNodeSymbol]; } var shellNode = new Node(node); // @ts-ignore 挂载 shell node 实例 // eslint-disable-next-line no-param-reassign node[shellNodeSymbol] = shellNode; return shellNode; } /** * @deprecated use .children instead */; var _proto = Node.prototype; _proto.getChildren = function getChildren() { return this.children; } /** * 获取节点实例对应的 dom 节点 */; _proto.getDOMNode = function getDOMNode() { return this[_symbols.nodeSymbol].getDOMNode(); } /** * 执行新增、删除、排序等操作 * @param remover * @param adder * @param sorter */; _proto.mergeChildren = function mergeChildren(remover, adder, sorter) { var _this$children; return (_this$children = this.children) === null || _this$children === void 0 ? void 0 : _this$children.mergeChildren(remover, adder, sorter); } /** * 返回节点的尺寸、位置信息 * @returns */; _proto.getRect = function getRect() { return this[_symbols.nodeSymbol].getRect(); } /** * 是否有挂载插槽节点 * @returns */; _proto.hasSlots = function hasSlots() { return this[_symbols.nodeSymbol].hasSlots(); } /** * 是否设定了渲染条件 * @returns */; _proto.hasCondition = function hasCondition() { return this[_symbols.nodeSymbol].hasCondition(); } /** * 是否设定了循环数据 * @returns */; _proto.hasLoop = function hasLoop() { return this[_symbols.nodeSymbol].hasLoop(); }; _proto.getVisible = function getVisible() { return this[_symbols.nodeSymbol].getVisible(); }; _proto.setVisible = function setVisible(flag) { this[_symbols.nodeSymbol].setVisible(flag); }; _proto.isConditionalVisible = function isConditionalVisible() { return this[_symbols.nodeSymbol].isConditionalVisible(); } /** * 设置节点锁定状态 * @param flag */; _proto.lock = function lock(flag) { this[_symbols.nodeSymbol].lock(flag); } /** * @deprecated use .props instead */; _proto.getProps = function getProps() { return this.props; }; _proto.contains = function contains(node) { return this[_symbols.nodeSymbol].contains(node[_symbols.nodeSymbol]); } /** * 获取指定 path 的属性模型实例 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @returns */; _proto.getProp = function getProp(path, createIfNone) { if (createIfNone === void 0) { createIfNone = true; } return _prop.Prop.create(this[_symbols.nodeSymbol].getProp(path, createIfNone)); } /** * 获取指定 path 的属性模型实例值 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @returns */; _proto.getPropValue = function getPropValue(path) { var _this$getProp; return (_this$getProp = this.getProp(path, false)) === null || _this$getProp === void 0 ? void 0 : _this$getProp.getValue(); } /** * 获取指定 path 的属性模型实例, * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @param createIfNone 当没有属性的时候,是否创建一个属性 * @returns */; _proto.getExtraProp = function getExtraProp(path, createIfNone) { return _prop.Prop.create(this[_symbols.nodeSymbol].getExtraProp(path, createIfNone)); } /** * 获取指定 path 的属性模型实例, * 注:导出时,不同于普通属性,该属性并不挂载在 props 之下,而是与 props 同级 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @returns */; _proto.getExtraPropValue = function getExtraPropValue(path) { var _this$getExtraProp; return (_this$getExtraProp = this.getExtraProp(path)) === null || _this$getExtraProp === void 0 ? void 0 : _this$getExtraProp.getValue(); } /** * 设置指定 path 的属性模型实例值 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @param value 值 * @returns */; _proto.setPropValue = function setPropValue(path, value) { var _this$getProp2; return (_this$getProp2 = this.getProp(path)) === null || _this$getProp2 === void 0 ? void 0 : _this$getProp2.setValue(value); } /** * 设置指定 path 的属性模型实例值 * @param path 属性路径,支持 a / a.b / a.0 等格式 * @param value 值 * @returns */; _proto.setExtraPropValue = function setExtraPropValue(path, value) { var _this$getExtraProp2; return (_this$getExtraProp2 = this.getExtraProp(path)) === null || _this$getExtraProp2 === void 0 ? void 0 : _this$getExtraProp2.setValue(value); } /** * 导入节点数据 * @param data */; _proto.importSchema = function importSchema(data) { this[_symbols.nodeSymbol]["import"](data); } /** * 导出节点数据 * @param stage * @param options * @returns */; _proto.exportSchema = function exportSchema(stage, options) { if (stage === void 0) { stage = _lowcodeTypes.IPublicEnumTransformStage.Render; } return this[_symbols.nodeSymbol]["export"](stage, options); } /** * 在指定位置之前插入一个节点 * @param node * @param ref * @param useMutator */; _proto.insertBefore = function insertBefore(node, ref, useMutator) { this[_symbols.nodeSymbol].insertBefore(node[_symbols.nodeSymbol] || node, ref === null || ref === void 0 ? void 0 : ref[_symbols.nodeSymbol], useMutator); } /** * 在指定位置之后插入一个节点 * @param node * @param ref * @param useMutator */; _proto.insertAfter = function insertAfter(node, ref, useMutator) { this[_symbols.nodeSymbol].insertAfter(node[_symbols.nodeSymbol] || node, ref === null || ref === void 0 ? void 0 : ref[_symbols.nodeSymbol], useMutator); } /** * 替换指定节点 * @param node 待替换的子节点 * @param data 用作替换的节点对象或者节点描述 * @returns */; _proto.replaceChild = function replaceChild(node, data) { return Node.create(this[_symbols.nodeSymbol].replaceChild(node[_symbols.nodeSymbol], data)); } /** * 将当前节点替换成指定节点描述 * @param schema */; _proto.replaceWith = function replaceWith(schema) { this[_symbols.nodeSymbol].replaceWith(schema); } /** * 选中当前节点实例 */; _proto.select = function select() { this[_symbols.nodeSymbol].select(); } /** * 设置悬停态 * @param flag */; _proto.hover = function hover(flag) { if (flag === void 0) { flag = true; } this[_symbols.nodeSymbol].hover(flag); } /** * 删除当前节点实例 */; _proto.remove = function remove() { this[_symbols.nodeSymbol].remove(); } /** * @deprecated * 设置为磁贴布局节点 */; _proto.internalToShellNode = function internalToShellNode() { return this; }; _proto.canPerformAction = function canPerformAction(actionName) { return this[_symbols.nodeSymbol].canPerformAction(actionName); } /** * get conditionGroup * @since v1.1.0 */; /** * set value for conditionalVisible * @since v1.1.0 */ _proto.setConditionalVisible = function setConditionalVisible() { this[_symbols.nodeSymbol].setConditionalVisible(); }; _proto.getRGL = function getRGL() { var _this$nodeSymbol$getR = this[_symbols.nodeSymbol].getRGL(), isContainerNode = _this$nodeSymbol$getR.isContainerNode, isEmptyNode = _this$nodeSymbol$getR.isEmptyNode, isRGLContainerNode = _this$nodeSymbol$getR.isRGLContainerNode, isRGLNode = _this$nodeSymbol$getR.isRGLNode, isRGL = _this$nodeSymbol$getR.isRGL, rglNode = _this$nodeSymbol$getR.rglNode; return { isContainerNode: isContainerNode, isEmptyNode: isEmptyNode, isRGLContainerNode: isRGLContainerNode, isRGLNode: isRGLNode, isRGL: isRGL, rglNode: Node.create(rglNode) }; }; return (0, _createClass2["default"])(Node, [{ key: "id", get: /** * 节点 id */ function get() { return this._id; } /** * set id */, set: function set(id) { this._id = id; } /** * 节点标题 */ }, { key: "title", get: function get() { return this[_symbols.nodeSymbol].title; } /** * @deprecated * 是否为「容器型」节点 */ }, { key: "isContainer", get: function get() { return this[_symbols.nodeSymbol].isContainerNode; } /** * 是否为「容器型」节点 */ }, { key: "isContainerNode", get: function get() { return this[_symbols.nodeSymbol].isContainerNode; } /** * @deprecated * 是否为根节点 */ }, { key: "isRoot", get: function get() { return this[_symbols.nodeSymbol].isRootNode; } /** * 是否为根节点 */ }, { key: "isRootNode", get: function get() { return this[_symbols.nodeSymbol].isRootNode; } /** * @deprecated * 是否为空节点(无 children 或者 children 为空) */ }, { key: "isEmpty", get: function get() { return this[_symbols.nodeSymbol].isEmptyNode; } /** * 是否为空节点(无 children 或者 children 为空) */ }, { key: "isEmptyNode", get: function get() { return this[_symbols.nodeSymbol].isEmptyNode; } /** * @deprecated * 是否为 Page 节点 */ }, { key: "isPage", get: function get() { return this[_symbols.nodeSymbol].isPageNode; } /** * 是否为 Page 节点 */ }, { key: "isPageNode", get: function get() { return this[_symbols.nodeSymbol].isPageNode; } /** * @deprecated * 是否为 Component 节点 */ }, { key: "isComponent", get: function get() { return this[_symbols.nodeSymbol].isComponentNode; } /** * 是否为 Component 节点 */ }, { key: "isComponentNode", get: function get() { return this[_symbols.nodeSymbol].isComponentNode; } /** * @deprecated * 是否为「模态框」节点 */ }, { key: "isModal", get: function get() { return this[_symbols.nodeSymbol].isModalNode; } /** * 是否为「模态框」节点 */ }, { key: "isModalNode", get: function get() { return this[_symbols.nodeSymbol].isModalNode; } /** * @deprecated * 是否为插槽节点 */ }, { key: "isSlot", get: function get() { return this[_symbols.nodeSymbol].isSlotNode; } /** * 是否为插槽节点 */ }, { key: "isSlotNode", get: function get() { return this[_symbols.nodeSymbol].isSlotNode; } /** * @deprecated * 是否为父类/分支节点 */ }, { key: "isParental", get: function get() { return this[_symbols.nodeSymbol].isParentalNode; } /** * 是否为父类/分支节点 */ }, { key: "isParentalNode", get: function get() { return this[_symbols.nodeSymbol].isParentalNode; } /** * @deprecated * 是否为叶子节点 */ }, { key: "isLeaf", get: function get() { return this[_symbols.nodeSymbol].isLeafNode; } /** * 是否为叶子节点 */ }, { key: "isLeafNode", get: function get() { return this[_symbols.nodeSymbol].isLeafNode; } }, { key: "isLocked", get: /** * 获取当前节点的锁定状态 */ function get() { return this[_symbols.nodeSymbol].isLocked; } /** * 下标 */ }, { key: "index", get: function get() { return this[_symbols.nodeSymbol].index; } /** * 图标 */ }, { key: "icon", get: function get() { return this[_symbols.nodeSymbol].icon; } /** * 节点所在树的层级深度,根节点深度为 0 */ }, { key: "zLevel", get: function get() { return this[_symbols.nodeSymbol].zLevel; } /** * 节点 componentName */ }, { key: "componentName", get: function get() { return this[_symbols.nodeSymbol].componentName; } /** * 节点的物料元数据 */ }, { key: "componentMeta", get: function get() { return _componentMeta.ComponentMeta.create(this[_symbols.nodeSymbol].componentMeta); } /** * 获取节点所属的文档模型对象 * @returns */ }, { key: "document", get: function get() { return _documentModel.DocumentModel.create(this[_symbols.documentSymbol]); } /** * 获取当前节点的前一个兄弟节点 * @returns */ }, { key: "prevSibling", get: function get() { return Node.create(this[_symbols.nodeSymbol].prevSibling); } /** * 获取当前节点的后一个兄弟节点 * @returns */ }, { key: "nextSibling", get: function get() { return Node.create(this[_symbols.nodeSymbol].nextSibling); } /** * 获取当前节点的父亲节点 * @returns */ }, { key: "parent", get: function get() { return Node.create(this[_symbols.nodeSymbol].parent); } /** * 获取当前节点的孩子节点模型 * @returns */ }, { key: "children", get: function get() { return _nodeChildren.NodeChildren.create(this[_symbols.nodeSymbol].children); } /** * 节点上挂载的插槽节点们 */ }, { key: "slots", get: function get() { return this[_symbols.nodeSymbol].slots.map(function (node) { return Node.create(node); }); } /** * 当前节点为插槽节点时,返回节点对应的属性实例 */ }, { key: "slotFor", get: function get() { return _prop.Prop.create(this[_symbols.nodeSymbol].slotFor); } /** * 返回节点的属性集 */ }, { key: "props", get: function get() { return _props.Props.create(this[_symbols.nodeSymbol].props); } /** * 返回节点的属性集 */ }, { key: "propsData", get: function get() { return this[_symbols.nodeSymbol].propsData; } /** * 获取符合搭建协议 - 节点 schema 结构 */ }, { key: "schema", get: function get() { return this[_symbols.nodeSymbol].schema; } }, { key: "settingEntry", get: function get() { return _settingTopEntry.SettingTopEntry.create(this[_symbols.nodeSymbol].settingEntry); } }, { key: "visible", get: function get() { return this[_symbols.nodeSymbol].getVisible(); }, set: function set(value) { this[_symbols.nodeSymbol].setVisible(value); } }, { key: "isRGLContainer", get: /** * @deprecated * 获取磁贴布局节点设置状态 * @returns Boolean */ function get() { return this[_symbols.nodeSymbol].isRGLContainerNode; } /** * 设置为磁贴布局节点 */, set: function set(flag) { this[_symbols.nodeSymbol].isRGLContainerNode = flag; } }, { key: "isRGLContainerNode", get: /** * 获取磁贴布局节点设置状态 * @returns Boolean */ function get() { return this[_symbols.nodeSymbol].isRGLContainerNode; }, set: function set(flag) { this[_symbols.nodeSymbol].isRGLContainerNode = flag; } }, { key: "conditionGroup", get: function get() { return _conditionGroup.ConditionGroup.create(this[_symbols.nodeSymbol].conditionGroup); } }]); }();