UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

118 lines (109 loc) 2.69 kB
import _createClass from "@babel/runtime/helpers/createClass"; import { Node as ShellNode } from './node'; import { selectionSymbol } from '../symbols'; export var Selection = /*#__PURE__*/function () { function Selection(document) { this[selectionSymbol] = void 0; this[selectionSymbol] = document.selection; } /** * 返回选中的节点 id */ var _proto = Selection.prototype; /** * 选中指定节点(覆盖方式) * @param id */ _proto.select = function select(id) { this[selectionSymbol].select(id); } /** * 批量选中指定节点们 * @param ids */; _proto.selectAll = function selectAll(ids) { this[selectionSymbol].selectAll(ids); } /** * 移除选中的指定节点 * @param id */; _proto.remove = function remove(id) { this[selectionSymbol].remove(id); } /** * 清除所有选中节点 */; _proto.clear = function clear() { this[selectionSymbol].clear(); } /** * 判断是否选中了指定节点 * @param id * @returns */; _proto.has = function has(id) { return this[selectionSymbol].has(id); } /** * 选中指定节点(增量方式) * @param id */; _proto.add = function add(id) { this[selectionSymbol].add(id); } /** * 获取选中的节点实例 * @returns */; _proto.getNodes = function getNodes() { var innerNodes = this[selectionSymbol].getNodes(); var nodes = []; innerNodes.forEach(function (node) { var shellNode = ShellNode.create(node); if (shellNode) { nodes.push(shellNode); } }); return nodes; } /** * 获取选区的顶层节点 * for example: * getNodes() returns [A, subA, B], then * getTopNodes() will return [A, B], subA will be removed * @returns */; _proto.getTopNodes = function getTopNodes(includeRoot) { if (includeRoot === void 0) { includeRoot = false; } var innerNodes = this[selectionSymbol].getTopNodes(includeRoot); var nodes = []; innerNodes.forEach(function (node) { var shellNode = ShellNode.create(node); if (shellNode) { nodes.push(shellNode); } }); return nodes; }; _proto.onSelectionChange = function onSelectionChange(fn) { return this[selectionSymbol].onSelectionChange(fn); }; return _createClass(Selection, [{ key: "selected", get: function get() { return this[selectionSymbol].selected; } /** * return selected Node instance */ }, { key: "node", get: function get() { var nodes = this.getNodes(); return nodes && nodes.length > 0 ? nodes[0] : null; } }]); }();