UNPKG

@alilc/lowcode-shell

Version:

Shell Layer for AliLowCodeEngine

123 lines (113 loc) 2.99 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.Selection = void 0; var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _node = require("./node"); var _symbols = require("../symbols"); var Selection = exports.Selection = /*#__PURE__*/function () { function Selection(document) { this[_symbols.selectionSymbol] = void 0; this[_symbols.selectionSymbol] = document.selection; } /** * 返回选中的节点 id */ var _proto = Selection.prototype; /** * 选中指定节点(覆盖方式) * @param id */ _proto.select = function select(id) { this[_symbols.selectionSymbol].select(id); } /** * 批量选中指定节点们 * @param ids */; _proto.selectAll = function selectAll(ids) { this[_symbols.selectionSymbol].selectAll(ids); } /** * 移除选中的指定节点 * @param id */; _proto.remove = function remove(id) { this[_symbols.selectionSymbol].remove(id); } /** * 清除所有选中节点 */; _proto.clear = function clear() { this[_symbols.selectionSymbol].clear(); } /** * 判断是否选中了指定节点 * @param id * @returns */; _proto.has = function has(id) { return this[_symbols.selectionSymbol].has(id); } /** * 选中指定节点(增量方式) * @param id */; _proto.add = function add(id) { this[_symbols.selectionSymbol].add(id); } /** * 获取选中的节点实例 * @returns */; _proto.getNodes = function getNodes() { var innerNodes = this[_symbols.selectionSymbol].getNodes(); var nodes = []; innerNodes.forEach(function (node) { var shellNode = _node.Node.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[_symbols.selectionSymbol].getTopNodes(includeRoot); var nodes = []; innerNodes.forEach(function (node) { var shellNode = _node.Node.create(node); if (shellNode) { nodes.push(shellNode); } }); return nodes; }; _proto.onSelectionChange = function onSelectionChange(fn) { return this[_symbols.selectionSymbol].onSelectionChange(fn); }; return (0, _createClass2["default"])(Selection, [{ key: "selected", get: function get() { return this[_symbols.selectionSymbol].selected; } /** * return selected Node instance */ }, { key: "node", get: function get() { var nodes = this.getNodes(); return nodes && nodes.length > 0 ? nodes[0] : null; } }]); }();