UNPKG

xdesign-vue-next

Version:

XDesign Component for vue-next

270 lines (266 loc) 7.94 kB
/** * xdesign v1.0.6 * (c) 2023 xdesign * @license MIT */ import { _ as _classCallCheck, a as _createClass } from '../../../_chunks/dep-72a1dd28.mjs'; import { _ as _defineProperty } from '../../../_chunks/dep-f9e836af.mjs'; import { i as isUndefined_1 } from '../../../_chunks/dep-1bae6a97.mjs'; import { i as isBoolean_1 } from '../../../_chunks/dep-b9fae426.mjs'; import { o as omit_1 } from '../../../_chunks/dep-60f1d7ee.mjs'; import { g as get_1 } from '../../../_chunks/dep-7fa157cd.mjs'; import log from '../log/log.mjs'; import '../../../_chunks/dep-82805301.mjs'; import '../../../_chunks/dep-10a947a6.mjs'; import '../../../_chunks/dep-b75d8d74.mjs'; import '../../../_chunks/dep-addc2a84.mjs'; import '../../../_chunks/dep-4903a8a8.mjs'; import '../../../_chunks/dep-a95026f2.mjs'; import '../../../_chunks/dep-068e912d.mjs'; import '../../../_chunks/dep-7dcfa37a.mjs'; import '../../../_chunks/dep-c4737535.mjs'; import '../../../_chunks/dep-81c83986.mjs'; import '../../../_chunks/dep-6aa0223b.mjs'; import '../../../_chunks/dep-db381ece.mjs'; import '../../../_chunks/dep-1cc1c24f.mjs'; import '../../../_chunks/dep-6ad18815.mjs'; import '../../../_chunks/dep-5755c21c.mjs'; import '../../../_chunks/dep-7f239c43.mjs'; import '../../../_chunks/dep-6f04869e.mjs'; import '../../../_chunks/dep-d32fbbb3.mjs'; import '../../../_chunks/dep-dafada74.mjs'; import '../../../_chunks/dep-6e7b37b8.mjs'; import '../../../_chunks/dep-e1ab85c5.mjs'; import '../../../_chunks/dep-5f0e0453.mjs'; import '../../../_chunks/dep-71f84cf2.mjs'; import '../../../_chunks/dep-0e832fc7.mjs'; import '../../../_chunks/dep-69963a8c.mjs'; import '../../../_chunks/dep-8d1c9a23.mjs'; import '../../../_chunks/dep-03412fab.mjs'; import '../../../_chunks/dep-205ff58d.mjs'; import '../../../_chunks/dep-fa6608fd.mjs'; import '../../../_chunks/dep-e901316d.mjs'; import '../../../_chunks/dep-765678ef.mjs'; import '../../../_chunks/dep-ed4e7c50.mjs'; import '../../../_chunks/dep-b57a2815.mjs'; import '../../../_chunks/dep-983ce253.mjs'; import '../../../_chunks/dep-3ec3335a.mjs'; var nodeKey = "__tdesign_tree-node__"; var TreeNodeModel = /*#__PURE__*/function () { function TreeNodeModel(node) { _classCallCheck(this, TreeNodeModel); _defineProperty(this, nodeKey, void 0); this[nodeKey] = node; } _createClass(TreeNodeModel, [{ key: "value", get: function get() { var node = this[nodeKey]; return node.value; } }, { key: "label", get: function get() { var node = this[nodeKey]; return node.label; } }, { key: "data", get: function get() { var node = this[nodeKey]; return node.data; } }, { key: "actived", get: function get() { var node = this[nodeKey]; return node.actived; } }, { key: "expanded", get: function get() { var node = this[nodeKey]; return node.expanded; } }, { key: "checked", get: function get() { var node = this[nodeKey]; return node.checked; } }, { key: "indeterminate", get: function get() { var node = this[nodeKey]; return node.indeterminate; } }, { key: "loading", get: function get() { var node = this[nodeKey]; return node.loading; } }, { key: "getLevel", value: function getLevel() { var node = this[nodeKey]; return node.getLevel(); } }, { key: "getIndex", value: function getIndex() { var node = this[nodeKey]; return node.getIndex(); } }, { key: "isFirst", value: function isFirst() { var node = this[nodeKey]; return node.isFirst(); } }, { key: "isLast", value: function isLast() { var node = this[nodeKey]; return node.isLast(); } }, { key: "isLeaf", value: function isLeaf() { var node = this[nodeKey]; return node.isLeaf(); } }, { key: "insertBefore", value: function insertBefore(newData) { var node = this[nodeKey]; return node.insertBefore(newData); } }, { key: "insertAfter", value: function insertAfter(newData) { var node = this[nodeKey]; return node.insertAfter(newData); } }, { key: "appendData", value: function appendData(data) { var node = this[nodeKey]; return node.append(data); } }, { key: "getPath", value: function getPath() { var node = this[nodeKey]; var nodes = node.getPath(); return nodes.map(function (item) { return item.getModel(); }); } }, { key: "getParent", value: function getParent() { var _node$parent; var node = this[nodeKey]; return (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.getModel(); } }, { key: "getParents", value: function getParents() { var node = this[nodeKey]; var nodes = node.getParents(); return nodes.map(function (item) { return item.getModel(); }); } }, { key: "getRoot", value: function getRoot() { var node = this[nodeKey]; var root = node.getRoot(); return root === null || root === void 0 ? void 0 : root.getModel(); } }, { key: "getSiblings", value: function getSiblings() { var node = this[nodeKey]; var nodes = node.getSiblings(); return nodes.map(function (item) { return item.getModel(); }); } }, { key: "getChildren", value: function getChildren(deep) { var node = this[nodeKey]; var childrenModel = false; var children = node.children; if (Array.isArray(children)) { if (children.length > 0) { if (deep) { var nodes = node.walk(); nodes.shift(); childrenModel = nodes.map(function (item) { return item.getModel(); }); } else { childrenModel = children.map(function (item) { return item.getModel(); }); } } else { childrenModel = false; } } else if (isBoolean_1(children)) { childrenModel = children; } return childrenModel; } }, { key: "remove", value: function remove(value) { var node = this[nodeKey]; if (!value) { node.remove(); return; } var tree = node.tree; var targetNode = tree.getNode(value); if (!targetNode) { log.warnOnce("Tree", "`".concat(value, "` is not exist")); return; } var parents = targetNode.getParents(); var parentValues = parents.map(function (pnode) { return pnode.value; }); if (parentValues.indexOf(node.value) < 0) { log.warnOnce("Tree", "`".concat(value, "` is not a childNode of current node")); return; } targetNode.remove(); } }, { key: "setData", value: function setData(data) { var node = this[nodeKey]; var _data = omit_1(data, ["children", "value", "label", "disabled"]); var keys = node.tree.config.keys; var dataValue = get_1(data, (keys === null || keys === void 0 ? void 0 : keys.value) || "value"); var dataLabel = get_1(data, (keys === null || keys === void 0 ? void 0 : keys.label) || "label"); var dataDisabled = get_1(data, (keys === null || keys === void 0 ? void 0 : keys.disabled) || "disabled"); if (!isUndefined_1(dataValue)) _data.value = dataValue; if (!isUndefined_1(dataLabel)) _data.label = dataLabel; if (!isUndefined_1(dataDisabled)) _data.disable = dataDisabled; Object.assign(node.data, _data); Object.assign(node, _data); } }]); return TreeNodeModel; }(); function createNodeModel(node) { var model = new TreeNodeModel(node); return model; } export { TreeNodeModel, createNodeModel, nodeKey }; //# sourceMappingURL=tree-node-model.mjs.map