@alilc/lowcode-shell
Version:
Shell Layer for AliLowCodeEngine
259 lines (237 loc) • 6.17 kB
JavaScript
import _createClass from "@babel/runtime/helpers/createClass";
import { IPublicEnumTransformStage } from '@alilc/lowcode-types';
import { Node as ShellNode } from './node';
import { nodeSymbol, nodeChildrenSymbol } from '../symbols';
export var NodeChildren = /*#__PURE__*/function () {
function NodeChildren(nodeChildren) {
this[nodeChildrenSymbol] = void 0;
this[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[nodeChildrenSymbol]["delete"](node === null || node === void 0 ? void 0 : node[nodeSymbol]);
}
/**
* 插入一个节点
* @param node 待插入节点
* @param at 插入下标
* @returns
*/;
_proto.insert = function insert(node, at) {
return this[nodeChildrenSymbol].insert(node === null || node === void 0 ? void 0 : node[nodeSymbol], at);
}
/**
* 返回指定节点的下标
* @param node
* @returns
*/;
_proto.indexOf = function indexOf(node) {
return this[nodeChildrenSymbol].indexOf(node === null || node === void 0 ? void 0 : node[nodeSymbol]);
}
/**
* 类似数组 splice 操作
* @param start
* @param deleteCount
* @param node
*/;
_proto.splice = function splice(start, deleteCount, node) {
var removedNode = this[nodeChildrenSymbol].splice(start, deleteCount, node === null || node === void 0 ? void 0 : node[nodeSymbol]);
return removedNode.map(function (item) {
return ShellNode.create(item);
});
}
/**
* 返回指定下标的节点
* @param index
* @returns
*/;
_proto.get = function get(index) {
return ShellNode.create(this[nodeChildrenSymbol].get(index));
}
/**
* 是否包含指定节点
* @param node
* @returns
*/;
_proto.has = function has(node) {
return this[nodeChildrenSymbol].has(node === null || node === void 0 ? void 0 : node[nodeSymbol]);
}
/**
* 类似数组的 forEach
* @param fn
*/;
_proto.forEach = function forEach(fn) {
this[nodeChildrenSymbol].forEach(function (item, index) {
fn(ShellNode.create(item), index);
});
}
/**
* 类似数组的 reverse
*/;
_proto.reverse = function reverse() {
return this[nodeChildrenSymbol].reverse().map(function (d) {
return ShellNode.create(d);
});
}
/**
* 类似数组的 map
* @param fn
*/;
_proto.map = function map(fn) {
return this[nodeChildrenSymbol].map(function (item, index) {
return fn(ShellNode.create(item), index);
});
}
/**
* 类似数组的 every
* @param fn
*/;
_proto.every = function every(fn) {
return this[nodeChildrenSymbol].every(function (item, index) {
return fn(ShellNode.create(item), index);
});
}
/**
* 类似数组的 some
* @param fn
*/;
_proto.some = function some(fn) {
return this[nodeChildrenSymbol].some(function (item, index) {
return fn(ShellNode.create(item), index);
});
}
/**
* 类似数组的 filter
* @param fn
*/;
_proto.filter = function filter(fn) {
return this[nodeChildrenSymbol].filter(function (item, index) {
return fn(ShellNode.create(item), index);
}).map(function (item) {
return ShellNode.create(item);
});
}
/**
* 类似数组的 find
* @param fn
*/;
_proto.find = function find(fn) {
return ShellNode.create(this[nodeChildrenSymbol].find(function (item, index) {
return fn(ShellNode.create(item), index);
}));
}
/**
* 类似数组的 reduce
* @param fn
*/;
_proto.reduce = function reduce(fn, initialValue) {
return this[nodeChildrenSymbol].reduce(function (acc, cur) {
return fn(acc, ShellNode.create(cur));
}, initialValue);
}
/**
* 导入 schema
* @param data
*/;
_proto.importSchema = function importSchema(data) {
this[nodeChildrenSymbol]["import"](data);
}
/**
* 导出 schema
* @param stage
* @returns
*/;
_proto.exportSchema = function exportSchema(stage) {
if (stage === void 0) {
stage = IPublicEnumTransformStage.Render;
}
return this[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[nodeChildrenSymbol].mergeChildren(function (node, idx) {
return remover(ShellNode.create(node), idx);
}, function (children) {
return adder(children.map(function (node) {
return ShellNode.create(node);
}));
}, function (firstNode, secondNode) {
return sorter(ShellNode.create(firstNode), ShellNode.create(secondNode));
});
};
return _createClass(NodeChildren, [{
key: "owner",
get: function get() {
return ShellNode.create(this[nodeChildrenSymbol].owner);
}
/**
* children 内的节点实例数
*/
}, {
key: "size",
get: function get() {
return this[nodeChildrenSymbol].size;
}
/**
* @deprecated
* 是否为空
* @returns
*/
}, {
key: "isEmpty",
get: function get() {
return this[nodeChildrenSymbol].isEmptyNode;
}
/**
* 是否为空
* @returns
*/
}, {
key: "isEmptyNode",
get: function get() {
return this[nodeChildrenSymbol].isEmptyNode;
}
/**
* @deprecated
* judge if it is not empty
*/
}, {
key: "notEmpty",
get: function get() {
return this[nodeChildrenSymbol].notEmptyNode;
}
/**
* judge if it is not empty
*/
}, {
key: "notEmptyNode",
get: function get() {
return this[nodeChildrenSymbol].notEmptyNode;
}
}]);
}();