tdesign-mobile-vue
Version:
tdesign-mobile-vue
267 lines (263 loc) • 7.49 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import { _ as _classCallCheck, a as _createClass } from '../../../_chunks/dep-f1766f7d.mjs';
import { _ as _defineProperty } from '../../../_chunks/dep-219bb5a7.mjs';
import { i as isUndefined_1 } from '../../../_chunks/dep-1bbfa76e.mjs';
import { i as isBoolean_1 } from '../../../_chunks/dep-ea9a17dc.mjs';
import { o as omit_1 } from '../../../_chunks/dep-55c9adc0.mjs';
import { g as get_1 } from '../../../_chunks/dep-4f59c35d.mjs';
import log from '../log/log.mjs';
import '../../../_chunks/dep-620d73f7.mjs';
import '../../../_chunks/dep-8bf3054e.mjs';
import '../../../_chunks/dep-3d249f65.mjs';
import '../../../_chunks/dep-9b2de386.mjs';
import '../../../_chunks/dep-0d52e58f.mjs';
import '../../../_chunks/dep-6c53a3e4.mjs';
import '../../../_chunks/dep-d2161895.mjs';
import '../../../_chunks/dep-89951f45.mjs';
import '../../../_chunks/dep-08bc7a4c.mjs';
import '../../../_chunks/dep-91d696ea.mjs';
import '../../../_chunks/dep-e6c129ab.mjs';
import '../../../_chunks/dep-6bc862af.mjs';
import '../../../_chunks/dep-4931819d.mjs';
import '../../../_chunks/dep-10f4d030.mjs';
import '../../../_chunks/dep-8ee6f5cd.mjs';
import '../../../_chunks/dep-e57d46f3.mjs';
import '../../../_chunks/dep-4f44985d.mjs';
import '../../../_chunks/dep-b84be35c.mjs';
import '../../../_chunks/dep-019e292f.mjs';
import '../../../_chunks/dep-32364550.mjs';
import '../../../_chunks/dep-933f3a85.mjs';
import '../../../_chunks/dep-2bce42ea.mjs';
import '../../../_chunks/dep-c51d4905.mjs';
import '../../../_chunks/dep-a836a38c.mjs';
import '../../../_chunks/dep-8140c29b.mjs';
import '../../../_chunks/dep-0ea7bbde.mjs';
import '../../../_chunks/dep-ba131d9c.mjs';
var nodeKey = "__tdesign_tree-node__";
var TreeNodeModel = /*#__PURE__*/function () {
function TreeNodeModel(node) {
_classCallCheck(this, TreeNodeModel);
_defineProperty(this, nodeKey, void 0);
this[nodeKey] = node;
}
return _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: "disabled",
get: function get() {
var node = this[nodeKey];
return node.isDisabled();
}
}, {
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 syncAttrs = ["value", "label", "disabled"];
var cleanData = omit_1(data, ["children"].concat(syncAttrs));
var keys = node.tree.config.keys;
syncAttrs.forEach(function (attr) {
var dataAttrValue = get_1(data, (keys === null || keys === void 0 ? void 0 : keys[attr]) || attr);
if (!isUndefined_1(dataAttrValue)) cleanData[attr] = dataAttrValue;
});
Object.assign(node.data, cleanData);
Object.assign(node, cleanData);
node.update();
}
}]);
}();
function createNodeModel(node) {
var model = new TreeNodeModel(node);
return model;
}
export { TreeNodeModel, createNodeModel, nodeKey };
//# sourceMappingURL=tree-node-model.mjs.map