UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

264 lines (241 loc) 6.65 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.NodeChildren = void 0; var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _lowcodeTypes = require("@alilc/lowcode-types"); var _node = require("./node"); var _symbols = require("../symbols"); var NodeChildren = exports.NodeChildren = /*#__PURE__*/function () { function NodeChildren(nodeChildren) { this[_symbols.nodeChildrenSymbol] = void 0; this[_symbols.nodeChildrenSymbol] = nodeChildren; } NodeChildren.create = function create(nodeChildren) { if (!nodeChildren) { return null; } return new NodeChildren(nodeChildren); } /** * 返回当前 children 实例所属的节点实例 */; var _proto = NodeChildren.prototype; /** * 删除指定节点 * delete the node * @param node */ _proto["delete"] = function _delete(node) { return this[_symbols.nodeChildrenSymbol]["delete"](node === null || node === void 0 ? void 0 : node[_symbols.nodeSymbol]); } /** * 插入一个节点 * @param node 待插入节点 * @param at 插入下标 * @returns */; _proto.insert = function insert(node, at) { return this[_symbols.nodeChildrenSymbol].insert(node === null || node === void 0 ? void 0 : node[_symbols.nodeSymbol], at); } /** * 返回指定节点的下标 * @param node * @returns */; _proto.indexOf = function indexOf(node) { return this[_symbols.nodeChildrenSymbol].indexOf(node === null || node === void 0 ? void 0 : node[_symbols.nodeSymbol]); } /** * 类似数组 splice 操作 * @param start * @param deleteCount * @param node */; _proto.splice = function splice(start, deleteCount, node) { var removedNode = this[_symbols.nodeChildrenSymbol].splice(start, deleteCount, node === null || node === void 0 ? void 0 : node[_symbols.nodeSymbol]); return removedNode.map(function (item) { return _node.Node.create(item); }); } /** * 返回指定下标的节点 * @param index * @returns */; _proto.get = function get(index) { return _node.Node.create(this[_symbols.nodeChildrenSymbol].get(index)); } /** * 是否包含指定节点 * @param node * @returns */; _proto.has = function has(node) { return this[_symbols.nodeChildrenSymbol].has(node === null || node === void 0 ? void 0 : node[_symbols.nodeSymbol]); } /** * 类似数组的 forEach * @param fn */; _proto.forEach = function forEach(fn) { this[_symbols.nodeChildrenSymbol].forEach(function (item, index) { fn(_node.Node.create(item), index); }); } /** * 类似数组的 reverse */; _proto.reverse = function reverse() { return this[_symbols.nodeChildrenSymbol].reverse().map(function (d) { return _node.Node.create(d); }); } /** * 类似数组的 map * @param fn */; _proto.map = function map(fn) { return this[_symbols.nodeChildrenSymbol].map(function (item, index) { return fn(_node.Node.create(item), index); }); } /** * 类似数组的 every * @param fn */; _proto.every = function every(fn) { return this[_symbols.nodeChildrenSymbol].every(function (item, index) { return fn(_node.Node.create(item), index); }); } /** * 类似数组的 some * @param fn */; _proto.some = function some(fn) { return this[_symbols.nodeChildrenSymbol].some(function (item, index) { return fn(_node.Node.create(item), index); }); } /** * 类似数组的 filter * @param fn */; _proto.filter = function filter(fn) { return this[_symbols.nodeChildrenSymbol].filter(function (item, index) { return fn(_node.Node.create(item), index); }).map(function (item) { return _node.Node.create(item); }); } /** * 类似数组的 find * @param fn */; _proto.find = function find(fn) { return _node.Node.create(this[_symbols.nodeChildrenSymbol].find(function (item, index) { return fn(_node.Node.create(item), index); })); } /** * 类似数组的 reduce * @param fn */; _proto.reduce = function reduce(fn, initialValue) { return this[_symbols.nodeChildrenSymbol].reduce(function (acc, cur) { return fn(acc, _node.Node.create(cur)); }, initialValue); } /** * 导入 schema * @param data */; _proto.importSchema = function importSchema(data) { this[_symbols.nodeChildrenSymbol]["import"](data); } /** * 导出 schema * @param stage * @returns */; _proto.exportSchema = function exportSchema(stage) { if (stage === void 0) { stage = _lowcodeTypes.IPublicEnumTransformStage.Render; } return this[_symbols.nodeChildrenSymbol]["export"](stage); } /** * 执行新增、删除、排序等操作 * @param remover * @param adder * @param sorter */; _proto.mergeChildren = function mergeChildren(remover, adder, originalSorter) { var sorter = originalSorter; if (!sorter) { sorter = function sorter() { return 0; }; } this[_symbols.nodeChildrenSymbol].mergeChildren(function (node, idx) { return remover(_node.Node.create(node), idx); }, function (children) { return adder(children.map(function (node) { return _node.Node.create(node); })); }, function (firstNode, secondNode) { return sorter(_node.Node.create(firstNode), _node.Node.create(secondNode)); }); }; return (0, _createClass2["default"])(NodeChildren, [{ key: "owner", get: function get() { return _node.Node.create(this[_symbols.nodeChildrenSymbol].owner); } /** * children 内的节点实例数 */ }, { key: "size", get: function get() { return this[_symbols.nodeChildrenSymbol].size; } /** * @deprecated * 是否为空 * @returns */ }, { key: "isEmpty", get: function get() { return this[_symbols.nodeChildrenSymbol].isEmptyNode; } /** * 是否为空 * @returns */ }, { key: "isEmptyNode", get: function get() { return this[_symbols.nodeChildrenSymbol].isEmptyNode; } /** * @deprecated * judge if it is not empty */ }, { key: "notEmpty", get: function get() { return this[_symbols.nodeChildrenSymbol].notEmptyNode; } /** * judge if it is not empty */ }, { key: "notEmptyNode", get: function get() { return this[_symbols.nodeChildrenSymbol].notEmptyNode; } }]); }();