bkui-vue 0.0.1-beta.58 → 0.0.1-beta.59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +25 -25
- package/dist/index.esm.js +311 -208
- package/dist/index.umd.js +25 -25
- package/dist/style.css +1 -1
- package/lib/breadcrumb/breadcrumb.css +2 -2
- package/lib/breadcrumb/breadcrumb.variable.css +2 -2
- package/lib/button/button.less +2 -1
- package/lib/card/card.css +10 -10
- package/lib/card/card.less +12 -8
- package/lib/card/card.variable.css +10 -10
- package/lib/container/container.css +5 -5
- package/lib/container/container.less +1 -1
- package/lib/container/container.variable.css +5 -5
- package/lib/dialog/dialog.css +0 -2
- package/lib/dialog/dialog.less +4 -2
- package/lib/dialog/dialog.variable.css +0 -2
- package/lib/input/input.css +3 -3
- package/lib/input/input.less +2 -1
- package/lib/input/input.variable.css +3 -3
- package/lib/loading/loading.css +2 -2
- package/lib/loading/loading.variable.css +2 -2
- package/lib/menu/menu.css +2 -2
- package/lib/menu/menu.variable.css +2 -2
- package/lib/progress/progress.css +2 -2
- package/lib/progress/progress.variable.css +2 -2
- package/lib/styles/mixins/clearfix.css +2 -2
- package/lib/styles/mixins/clearfix.less +2 -2
- package/lib/styles/mixins/clearfix.variable.css +2 -2
- package/lib/styles/mixins/mixins.css +2 -2
- package/lib/styles/mixins/mixins.variable.css +2 -2
- package/lib/switcher/switcher.css +2 -2
- package/lib/switcher/switcher.variable.css +2 -2
- package/lib/table/plugins/settings.css +41 -41
- package/lib/table/plugins/settings.less +28 -22
- package/lib/table/plugins/settings.variable.css +41 -41
- package/lib/table/table.css +47 -47
- package/lib/table/table.less +10 -8
- package/lib/table/table.variable.css +47 -47
- package/lib/tree/index.d.ts +31 -52
- package/lib/tree/index.js +1 -1
- package/lib/tree/props.d.ts +10 -0
- package/lib/tree/tree.d.ts +14 -17
- package/lib/tree/use-async.d.ts +5 -0
- package/lib/tree/use-node-action.d.ts +6 -0
- package/lib/tree/use-node-attribute.d.ts +13 -0
- package/package.json +4 -4
package/dist/index.esm.js
CHANGED
@@ -20239,6 +20239,7 @@ const Transfer = withInstall(Component$1);
|
|
20239
20239
|
const treeProps = {
|
20240
20240
|
data: PropTypes.arrayOf(PropTypes.any).def([]),
|
20241
20241
|
label: PropTypes.oneOfType([PropTypes.func.def(void 0), PropTypes.string.def("label")]),
|
20242
|
+
nodeKey: PropTypes.string.def(null),
|
20242
20243
|
children: PropTypes.string.def("children"),
|
20243
20244
|
indent: PropTypes.number.def(18),
|
20244
20245
|
lineHeight: PropTypes.number.def(32),
|
@@ -20255,10 +20256,49 @@ const treeProps = {
|
|
20255
20256
|
]).def(true),
|
20256
20257
|
async: PropTypes.shape({
|
20257
20258
|
callback: PropTypes.func.def(null),
|
20258
|
-
cache: PropTypes.bool.def(true)
|
20259
|
+
cache: PropTypes.bool.def(true),
|
20260
|
+
deepAutoOpen: PropTypes.commonType(["once", "every"], "columnType").def("once")
|
20259
20261
|
}),
|
20260
20262
|
offsetLeft: PropTypes.number.def(5)
|
20261
20263
|
};
|
20264
|
+
var useNodeAttribute = (flatData) => {
|
20265
|
+
const schemaValues = computed(() => Array.from(flatData.schema.values()));
|
20266
|
+
const getSchemaVal2 = (key) => flatData.schema.get(key);
|
20267
|
+
const getNodeAttr2 = (node, attr) => {
|
20268
|
+
var _a;
|
20269
|
+
return (_a = getSchemaVal2(node.__uuid)) == null ? void 0 : _a[attr];
|
20270
|
+
};
|
20271
|
+
const setNodeAttr = (node, attr, val) => flatData.schema.set(node.__uuid, __spreadProps(__spreadValues({}, getSchemaVal2(node.__uuid)), {
|
20272
|
+
[attr]: val
|
20273
|
+
}));
|
20274
|
+
const getNodePath = (node) => getNodeAttr2(node, "__path");
|
20275
|
+
const isRootNode = (node) => getNodeAttr2(node, "__isRoot");
|
20276
|
+
const isNodeOpened = (node) => getNodeAttr2(node, "__isOpen");
|
20277
|
+
const hasChildNode = (node) => getNodeAttr2(node, "__hasChild");
|
20278
|
+
const isItemOpen = (item) => {
|
20279
|
+
var _a;
|
20280
|
+
if (typeof item === "object") {
|
20281
|
+
return isNodeOpened(item);
|
20282
|
+
}
|
20283
|
+
if (typeof item === "string") {
|
20284
|
+
return (_a = getSchemaVal2(item)) == null ? void 0 : _a.__isOpen;
|
20285
|
+
}
|
20286
|
+
return false;
|
20287
|
+
};
|
20288
|
+
const checkNodeIsOpen = (node) => isRootNode(node) || isItemOpen(node) || isItemOpen(getNodeAttr2(node, "__parentId"));
|
20289
|
+
return {
|
20290
|
+
schemaValues,
|
20291
|
+
getSchemaVal: getSchemaVal2,
|
20292
|
+
getNodeAttr: getNodeAttr2,
|
20293
|
+
setNodeAttr,
|
20294
|
+
getNodePath,
|
20295
|
+
isRootNode,
|
20296
|
+
isNodeOpened,
|
20297
|
+
hasChildNode,
|
20298
|
+
isItemOpen,
|
20299
|
+
checkNodeIsOpen
|
20300
|
+
};
|
20301
|
+
};
|
20262
20302
|
var rngBrowser = { exports: {} };
|
20263
20303
|
var getRandomValues = typeof crypto != "undefined" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != "undefined" && typeof window.msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto);
|
20264
20304
|
if (getRandomValues) {
|
@@ -20403,6 +20443,13 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
|
|
20403
20443
|
const outputData = [];
|
20404
20444
|
let order2 = 0;
|
20405
20445
|
const schema = /* @__PURE__ */ new Map();
|
20446
|
+
function getUid(item) {
|
20447
|
+
let uid = null;
|
20448
|
+
if (typeof props.nodeKey === "string") {
|
20449
|
+
uid = item[props.nodeKey];
|
20450
|
+
}
|
20451
|
+
return uid || item.__uuid || uuid_1.v4();
|
20452
|
+
}
|
20406
20453
|
function getCachedTreeNodeAttr(uuid2, node, attr, cachedAttr) {
|
20407
20454
|
const cached = (cachedSchema || []).find((item) => item.__uuid === uuid2);
|
20408
20455
|
if (cached) {
|
@@ -20424,7 +20471,7 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
|
|
20424
20471
|
flatten(item, depth, parent, path);
|
20425
20472
|
} else {
|
20426
20473
|
if (typeof item === "object" && item !== null) {
|
20427
|
-
const uuid2 = item
|
20474
|
+
const uuid2 = getUid(item);
|
20428
20475
|
const currentPath = path !== null ? `${path}-${i}` : `${i}`;
|
20429
20476
|
const hasChildren = !!(item[children] || []).length;
|
20430
20477
|
const attrs = {
|
@@ -20436,7 +20483,7 @@ const getFlatdata = (props, treeData = void 0, cachedSchema = []) => {
|
|
20436
20483
|
__path: currentPath,
|
20437
20484
|
__isRoot: parent === null,
|
20438
20485
|
__order: order2,
|
20439
|
-
__isOpen: isCachedTreeNodeOpened(uuid2, item)
|
20486
|
+
__isOpen: isCachedTreeNodeOpened(uuid2, item),
|
20440
20487
|
__checked: isCachedTreeNodeChecked(uuid2, item),
|
20441
20488
|
[children]: null
|
20442
20489
|
};
|
@@ -20538,202 +20585,291 @@ const assignTreeNode = (path, treeData, childKey, assignVal) => {
|
|
20538
20585
|
}, treeData);
|
20539
20586
|
Object.assign(targetNode, assignVal || {});
|
20540
20587
|
};
|
20588
|
+
var useAsync = (props, flatData) => {
|
20589
|
+
const {
|
20590
|
+
setNodeAttr,
|
20591
|
+
getNodePath,
|
20592
|
+
getNodeAttr: getNodeAttr2
|
20593
|
+
} = useNodeAttribute(flatData);
|
20594
|
+
const setNodeRemoteLoad = (resp, item) => {
|
20595
|
+
if (typeof resp === "object" && resp !== null) {
|
20596
|
+
setNodeAttr(item, "__isOpen", true);
|
20597
|
+
const nodeValue = Array.isArray(resp) ? resp : [resp];
|
20598
|
+
updateTreeNode(getNodePath(item), props.data, props.children, props.children, nodeValue);
|
20599
|
+
}
|
20600
|
+
};
|
20601
|
+
const asyncNodeClick = (item) => {
|
20602
|
+
if (item.async) {
|
20603
|
+
const {
|
20604
|
+
callback = null,
|
20605
|
+
cache = true
|
20606
|
+
} = props.async || {};
|
20607
|
+
setNodeAttr(item, "__isAsyncInit", true);
|
20608
|
+
if (typeof callback === "function") {
|
20609
|
+
if (!item.cached) {
|
20610
|
+
Object.assign(item, {
|
20611
|
+
loading: true
|
20612
|
+
});
|
20613
|
+
return Promise.resolve(callback(item, (resp) => setNodeRemoteLoad(resp, item)).then((resp) => setNodeRemoteLoad(resp, item)).catch((err) => console.error("load remote data error:", err)).finally(() => {
|
20614
|
+
assignTreeNode(getNodePath(item), props.data, props.children, __spreadValues({
|
20615
|
+
loading: false
|
20616
|
+
}, cache ? {
|
20617
|
+
cached: true
|
20618
|
+
} : {}));
|
20619
|
+
}));
|
20620
|
+
}
|
20621
|
+
return Promise.resolve(true);
|
20622
|
+
}
|
20623
|
+
return Promise.reject("async need to set prop: asyncLoad with function wich will return promise object");
|
20624
|
+
}
|
20625
|
+
};
|
20626
|
+
const deepAutoOpen = () => {
|
20627
|
+
const autoOpenNodes = flatData.data.filter((item) => item.async && item.isOpen && !getNodeAttr2(item, "__isAsyncInit"));
|
20628
|
+
if (autoOpenNodes.length) {
|
20629
|
+
Promise.all(autoOpenNodes.map((item) => asyncNodeClick(item))).then(() => {
|
20630
|
+
deepAutoOpen();
|
20631
|
+
}).catch((err) => {
|
20632
|
+
console.warn(err);
|
20633
|
+
});
|
20634
|
+
}
|
20635
|
+
};
|
20636
|
+
return {
|
20637
|
+
asyncNodeClick,
|
20638
|
+
deepAutoOpen
|
20639
|
+
};
|
20640
|
+
};
|
20641
|
+
var useNodeAction = (props, ctx, flatData, renderData) => {
|
20642
|
+
const checkedNodes = [];
|
20643
|
+
const {
|
20644
|
+
setNodeAttr,
|
20645
|
+
getNodePath,
|
20646
|
+
getSchemaVal: getSchemaVal2,
|
20647
|
+
getNodeAttr: getNodeAttr2,
|
20648
|
+
isRootNode,
|
20649
|
+
hasChildNode,
|
20650
|
+
isItemOpen,
|
20651
|
+
isNodeOpened,
|
20652
|
+
schemaValues
|
20653
|
+
} = useNodeAttribute(flatData);
|
20654
|
+
const {
|
20655
|
+
asyncNodeClick,
|
20656
|
+
deepAutoOpen
|
20657
|
+
} = useAsync(props, flatData);
|
20658
|
+
const getRootIcon = (item) => isItemOpen(item) ? createVNode(folderShapeOpen, {
|
20659
|
+
"class": resolveClassName("tree-icon")
|
20660
|
+
}, null) : createVNode(folder, {
|
20661
|
+
"class": resolveClassName("tree-icon")
|
20662
|
+
}, null);
|
20663
|
+
const renderPrefixVal = (val) => {
|
20664
|
+
if (typeof val === "string") {
|
20665
|
+
return val;
|
20666
|
+
}
|
20667
|
+
if (typeof val === "object" && val !== null) {
|
20668
|
+
if (val.__v_isVNode) {
|
20669
|
+
return val;
|
20670
|
+
}
|
20671
|
+
const {
|
20672
|
+
node,
|
20673
|
+
className,
|
20674
|
+
text,
|
20675
|
+
style
|
20676
|
+
} = val;
|
20677
|
+
return h$1(node, {
|
20678
|
+
class: className,
|
20679
|
+
style
|
20680
|
+
}, text);
|
20681
|
+
}
|
20682
|
+
return null;
|
20683
|
+
};
|
20684
|
+
const getActionIcon = (item) => {
|
20685
|
+
let prefixFnVal = null;
|
20686
|
+
if (typeof props.prefixIcon === "function") {
|
20687
|
+
prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "action", item);
|
20688
|
+
if (prefixFnVal !== "default") {
|
20689
|
+
return renderPrefixVal(prefixFnVal);
|
20690
|
+
}
|
20691
|
+
}
|
20692
|
+
if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
|
20693
|
+
if (hasChildNode(item) || item.async) {
|
20694
|
+
return isItemOpen(item) ? createVNode(downShape, null, null) : createVNode(rightShape, null, null);
|
20695
|
+
}
|
20696
|
+
}
|
20697
|
+
return null;
|
20698
|
+
};
|
20699
|
+
const getNodePrefixIcon = (item) => {
|
20700
|
+
let prefixFnVal = null;
|
20701
|
+
if (typeof props.prefixIcon === "function") {
|
20702
|
+
prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "node_type", item);
|
20703
|
+
if (prefixFnVal !== "default") {
|
20704
|
+
return renderPrefixVal(prefixFnVal);
|
20705
|
+
}
|
20706
|
+
}
|
20707
|
+
if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
|
20708
|
+
return isRootNode(item) || hasChildNode(item) ? getRootIcon(item) : createVNode(textFile, {
|
20709
|
+
"class": resolveClassName("tree-icon")
|
20710
|
+
}, null);
|
20711
|
+
}
|
20712
|
+
return null;
|
20713
|
+
};
|
20714
|
+
const getLoadingIcon = (item) => item.loading ? createVNode(spinner, null, null) : "";
|
20715
|
+
const setNodeOpened = (item) => {
|
20716
|
+
const newVal = !isItemOpen(item);
|
20717
|
+
setNodeAttr(item, "__isOpen", newVal);
|
20718
|
+
if (newVal) {
|
20719
|
+
return;
|
20720
|
+
}
|
20721
|
+
renderData.value.filter((node) => String.prototype.startsWith.call(getNodePath(node), getNodePath(item))).forEach((filterNode) => setNodeAttr(filterNode, "__isOpen", newVal));
|
20722
|
+
};
|
20723
|
+
const hanldeTreeNodeClick = (item) => {
|
20724
|
+
asyncNodeClick(item);
|
20725
|
+
if (hasChildNode(item)) {
|
20726
|
+
setNodeOpened(item);
|
20727
|
+
}
|
20728
|
+
};
|
20729
|
+
const handleNodeActionClick = (e, node) => {
|
20730
|
+
e.stopImmediatePropagation();
|
20731
|
+
e.stopPropagation();
|
20732
|
+
e.preventDefault();
|
20733
|
+
hanldeTreeNodeClick(node);
|
20734
|
+
};
|
20735
|
+
const handleNodeContentClick = (item) => {
|
20736
|
+
if (!checkedNodes.includes(item.__uuid)) {
|
20737
|
+
checkedNodes.forEach((__uuid) => setNodeAttr({
|
20738
|
+
__uuid
|
20739
|
+
}, "__checked", false));
|
20740
|
+
checkedNodes.length = 0;
|
20741
|
+
setNodeAttr(item, "__checked", true);
|
20742
|
+
checkedNodes.push(item.__uuid);
|
20743
|
+
if (!isNodeOpened(item)) {
|
20744
|
+
hanldeTreeNodeClick(item);
|
20745
|
+
}
|
20746
|
+
ctx.emit("check", item, getSchemaVal2(item.__uuid));
|
20747
|
+
}
|
20748
|
+
};
|
20749
|
+
const filterNextNode = (depth, node) => {
|
20750
|
+
if (isRootNode(node)) {
|
20751
|
+
return false;
|
20752
|
+
}
|
20753
|
+
const nodepath = getNodePath(node);
|
20754
|
+
const paths = `${nodepath}`.split("-").slice(0, depth + 1);
|
20755
|
+
const currentPath = paths.join("-");
|
20756
|
+
if (currentPath === nodepath) {
|
20757
|
+
return true;
|
20758
|
+
}
|
20759
|
+
const lastLevel = paths.pop();
|
20760
|
+
const nextLevel = parseInt(lastLevel, 10);
|
20761
|
+
paths.push(`${nextLevel + 1}`);
|
20762
|
+
const nextNodePath = paths.join("-");
|
20763
|
+
return schemaValues.value.some((val) => val.__path === nextNodePath);
|
20764
|
+
};
|
20765
|
+
const getVirtualLines = (node) => {
|
20766
|
+
if (!props.levelLine) {
|
20767
|
+
return null;
|
20768
|
+
}
|
20769
|
+
const getNodeLineStyle = (dpth) => ({
|
20770
|
+
"--depth": dpth
|
20771
|
+
});
|
20772
|
+
const maxDeep = getNodeAttr2(node, "__depth") + 1;
|
20773
|
+
return new Array(maxDeep).fill("").map((_2, index) => index).filter((depth) => filterNextNode(depth, node)).filter((depth) => depth > 0).map((index) => createVNode("span", {
|
20774
|
+
"class": "node-virtual-line",
|
20775
|
+
"style": getNodeLineStyle(maxDeep - index)
|
20776
|
+
}, null));
|
20777
|
+
};
|
20778
|
+
const renderTreeNode = (item) => {
|
20779
|
+
var _a, _b, _c, _d, _e;
|
20780
|
+
return createVNode("div", {
|
20781
|
+
"class": getNodeRowClass(item, flatData.schema)
|
20782
|
+
}, [createVNode("div", {
|
20783
|
+
"class": getNodeItemClass(item, flatData.schema, props),
|
20784
|
+
"style": getNodeItemStyle(item, props, flatData),
|
20785
|
+
"onClick": () => handleNodeContentClick(item)
|
20786
|
+
}, [createVNode("span", {
|
20787
|
+
"class": resolveClassName("node-action"),
|
20788
|
+
"onClick": (e) => handleNodeActionClick(e, item)
|
20789
|
+
}, [getActionIcon(item)]), createVNode("span", {
|
20790
|
+
"class": resolveClassName("node-content")
|
20791
|
+
}, [[getNodePrefixIcon(item), getLoadingIcon(item)], createVNode("span", {
|
20792
|
+
"class": resolveClassName("node-text")
|
20793
|
+
}, [(_e = (_b = (_a = ctx.slots).node) == null ? void 0 : _b.call(_a, item)) != null ? _e : [getLabel(item, props), (_d = (_c = ctx.slots).nodeAppend) == null ? void 0 : _d.call(_c, item)]])]), getVirtualLines(item)])]);
|
20794
|
+
};
|
20795
|
+
return {
|
20796
|
+
renderTreeNode,
|
20797
|
+
hanldeTreeNodeClick,
|
20798
|
+
deepAutoOpen
|
20799
|
+
};
|
20800
|
+
};
|
20541
20801
|
var Component = defineComponent({
|
20542
20802
|
name: "Tree",
|
20543
20803
|
props: treeProps,
|
20544
20804
|
emits: ["check"],
|
20545
20805
|
setup(props, ctx) {
|
20806
|
+
var _a;
|
20546
20807
|
const formatData = getFlatdata(props);
|
20547
|
-
const checkedNodes = [];
|
20548
20808
|
const flatData = reactive({
|
20549
20809
|
data: formatData[0],
|
20550
20810
|
schema: formatData[1],
|
20551
20811
|
levelLineSchema: {}
|
20552
20812
|
});
|
20813
|
+
const {
|
20814
|
+
schemaValues,
|
20815
|
+
setNodeAttr,
|
20816
|
+
checkNodeIsOpen
|
20817
|
+
} = useNodeAttribute(flatData);
|
20818
|
+
const renderData = computed(() => flatData.data.filter((item) => checkNodeIsOpen(item)));
|
20819
|
+
const {
|
20820
|
+
renderTreeNode,
|
20821
|
+
hanldeTreeNodeClick,
|
20822
|
+
deepAutoOpen
|
20823
|
+
} = useNodeAction(props, ctx, flatData, renderData);
|
20824
|
+
if ((_a = props.async) == null ? void 0 : _a.callback) {
|
20825
|
+
deepAutoOpen();
|
20826
|
+
}
|
20553
20827
|
watch(() => [props.data], (newData) => {
|
20828
|
+
var _a2, _b;
|
20554
20829
|
const formatData2 = getFlatdata(props, newData, schemaValues.value);
|
20555
20830
|
flatData.data = formatData2[0];
|
20556
20831
|
flatData.schema = formatData2[1];
|
20832
|
+
if (((_a2 = props.async) == null ? void 0 : _a2.callback) && ((_b = props.async) == null ? void 0 : _b.deepAutoOpen) === "every") {
|
20833
|
+
deepAutoOpen();
|
20834
|
+
}
|
20557
20835
|
}, {
|
20558
20836
|
deep: true
|
20559
20837
|
});
|
20560
|
-
const
|
20561
|
-
|
20562
|
-
|
20563
|
-
|
20564
|
-
|
20565
|
-
|
20566
|
-
const setNodeAttr = (node, attr, val) => flatData.schema.set(node.__uuid, __spreadProps(__spreadValues({}, getSchemaVal2(node.__uuid)), {
|
20567
|
-
[attr]: val
|
20568
|
-
}));
|
20569
|
-
const getNodePath = (node) => getNodeAttr2(node, "__path");
|
20570
|
-
const isRootNode = (node) => getNodeAttr2(node, "__isRoot");
|
20571
|
-
const isNodeOpened = (node) => getNodeAttr2(node, "__isOpen");
|
20572
|
-
const hasChildNode = (node) => getNodeAttr2(node, "__hasChild");
|
20573
|
-
const renderData = computed(() => flatData.data.filter((item) => checkNodeIsOpen(item)));
|
20574
|
-
const isItemOpen = (item) => {
|
20575
|
-
var _a;
|
20576
|
-
if (typeof item === "object") {
|
20577
|
-
return isNodeOpened(item);
|
20578
|
-
}
|
20579
|
-
if (typeof item === "string") {
|
20580
|
-
return (_a = getSchemaVal2(item)) == null ? void 0 : _a.__isOpen;
|
20581
|
-
}
|
20582
|
-
return false;
|
20583
|
-
};
|
20584
|
-
const getRootIcon = (item) => isItemOpen(item) ? createVNode(folderShapeOpen, {
|
20585
|
-
"class": resolveClassName("tree-icon")
|
20586
|
-
}, null) : createVNode(folder, {
|
20587
|
-
"class": resolveClassName("tree-icon")
|
20588
|
-
}, null);
|
20589
|
-
const renderPrefixVal = (val) => {
|
20590
|
-
if (typeof val === "string") {
|
20591
|
-
return val;
|
20592
|
-
}
|
20593
|
-
if (typeof val === "object" && val !== null) {
|
20594
|
-
if (val.__v_isVNode) {
|
20595
|
-
return val;
|
20596
|
-
}
|
20597
|
-
const {
|
20598
|
-
node,
|
20599
|
-
className,
|
20600
|
-
text,
|
20601
|
-
style
|
20602
|
-
} = val;
|
20603
|
-
return h$1(node, {
|
20604
|
-
class: className,
|
20605
|
-
style
|
20606
|
-
}, text);
|
20607
|
-
}
|
20608
|
-
return null;
|
20609
|
-
};
|
20610
|
-
const getActionIcon = (item) => {
|
20611
|
-
let prefixFnVal = null;
|
20612
|
-
if (typeof props.prefixIcon === "function") {
|
20613
|
-
prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "action", item);
|
20614
|
-
if (prefixFnVal !== "default") {
|
20615
|
-
return renderPrefixVal(prefixFnVal);
|
20616
|
-
}
|
20617
|
-
}
|
20618
|
-
if (prefixFnVal === "default" || typeof props.prefixIcon === "boolean" && props.prefixIcon) {
|
20619
|
-
if (hasChildNode(item) || item.async) {
|
20620
|
-
return isItemOpen(item) ? createVNode(downShape, null, null) : createVNode(rightShape, null, null);
|
20838
|
+
const setNodeAction = (args, action, value) => {
|
20839
|
+
const resolveNodeItem = (node) => {
|
20840
|
+
if (typeof node === "string") {
|
20841
|
+
return {
|
20842
|
+
__uuid: node
|
20843
|
+
};
|
20621
20844
|
}
|
20622
|
-
|
20623
|
-
|
20624
|
-
};
|
20625
|
-
const getNodePrefixIcon = (item) => {
|
20626
|
-
let prefixFnVal = null;
|
20627
|
-
if (typeof props.prefixIcon === "function") {
|
20628
|
-
prefixFnVal = props.prefixIcon(isRootNode(item), hasChildNode(item) || item.async, isItemOpen(item), "node_type", item);
|
20629
|
-
if (prefixFnVal !== "default") {
|
20630
|
-
return renderPrefixVal(prefixFnVal);
|
20845
|
+
if (Object.prototype.hasOwnProperty.call(node, "__uuid")) {
|
20846
|
+
return node;
|
20631
20847
|
}
|
20632
|
-
|
20633
|
-
|
20634
|
-
|
20635
|
-
|
20636
|
-
|
20637
|
-
}
|
20638
|
-
return null;
|
20639
|
-
};
|
20640
|
-
const getLoadingIcon = (item) => item.loading ? createVNode(spinner, null, null) : "";
|
20641
|
-
const setNodeOpened = (item) => {
|
20642
|
-
const newVal = !isItemOpen(item);
|
20643
|
-
setNodeAttr(item, "__isOpen", newVal);
|
20644
|
-
if (newVal) {
|
20848
|
+
console.error("setNodeAction Error: cannot find uid for the ndoe item");
|
20849
|
+
return node;
|
20850
|
+
};
|
20851
|
+
if (Array.isArray(args)) {
|
20852
|
+
args.forEach((node) => setNodeAttr(resolveNodeItem(node), action, value));
|
20645
20853
|
return;
|
20646
20854
|
}
|
20647
|
-
|
20855
|
+
setNodeAttr(resolveNodeItem(args), action, value);
|
20648
20856
|
};
|
20649
|
-
const
|
20650
|
-
|
20651
|
-
setNodeAttr(item, "__isOpen", true);
|
20652
|
-
const nodeValue = Array.isArray(resp) ? resp : [resp];
|
20653
|
-
updateTreeNode(getNodePath(item), props.data, props.children, props.children, nodeValue);
|
20654
|
-
}
|
20857
|
+
const setOpen = (item, isOpen = true) => {
|
20858
|
+
setNodeAction(item, "__isOpen", isOpen);
|
20655
20859
|
};
|
20656
|
-
const
|
20657
|
-
|
20658
|
-
const {
|
20659
|
-
callback = null,
|
20660
|
-
cache = true
|
20661
|
-
} = props.async || {};
|
20662
|
-
if (typeof callback === "function") {
|
20663
|
-
if (!item.cached) {
|
20664
|
-
Object.assign(item, {
|
20665
|
-
loading: true
|
20666
|
-
});
|
20667
|
-
callback(item, (resp) => setNodeRemoteLoad(resp, item)).then((resp) => setNodeRemoteLoad(resp, item)).catch((err) => console.error("load remote data error:", err)).finally(() => {
|
20668
|
-
assignTreeNode(getNodePath(item), props.data, props.children, __spreadValues({
|
20669
|
-
loading: false
|
20670
|
-
}, cache ? {
|
20671
|
-
cached: true
|
20672
|
-
} : {}));
|
20673
|
-
});
|
20674
|
-
}
|
20675
|
-
} else {
|
20676
|
-
console.error("async need to set prop: asyncLoad with function wich will return promise object");
|
20677
|
-
}
|
20678
|
-
}
|
20679
|
-
if (hasChildNode(item)) {
|
20680
|
-
setNodeOpened(item);
|
20681
|
-
}
|
20682
|
-
};
|
20683
|
-
const handleNodeActionClick = (e, node) => {
|
20684
|
-
e.stopImmediatePropagation();
|
20685
|
-
e.stopPropagation();
|
20686
|
-
e.preventDefault();
|
20687
|
-
hanldeTreeNodeClick(node);
|
20688
|
-
};
|
20689
|
-
const handleNodeContentClick = (item) => {
|
20690
|
-
if (!checkedNodes.includes(item.__uuid)) {
|
20691
|
-
checkedNodes.forEach((__uuid) => setNodeAttr({
|
20692
|
-
__uuid
|
20693
|
-
}, "__checked", false));
|
20694
|
-
checkedNodes.length = 0;
|
20695
|
-
setNodeAttr(item, "__checked", true);
|
20696
|
-
checkedNodes.push(item.__uuid);
|
20697
|
-
if (!isNodeOpened(item)) {
|
20698
|
-
hanldeTreeNodeClick(item);
|
20699
|
-
}
|
20700
|
-
ctx.emit("check", item, getSchemaVal2(item.__uuid));
|
20701
|
-
}
|
20702
|
-
};
|
20703
|
-
const checkNodeIsOpen = (node) => isRootNode(node) || isItemOpen(node) || isItemOpen(getNodeAttr2(node, "__parentId"));
|
20704
|
-
const filterNextNode = (depth, node) => {
|
20705
|
-
if (isRootNode(node)) {
|
20706
|
-
return false;
|
20707
|
-
}
|
20708
|
-
const nodepath = getNodePath(node);
|
20709
|
-
const paths = `${nodepath}`.split("-").slice(0, depth + 1);
|
20710
|
-
const currentPath = paths.join("-");
|
20711
|
-
if (currentPath === nodepath) {
|
20712
|
-
return true;
|
20713
|
-
}
|
20714
|
-
const lastLevel = paths.pop();
|
20715
|
-
const nextLevel = parseInt(lastLevel, 10);
|
20716
|
-
paths.push(`${nextLevel + 1}`);
|
20717
|
-
const nextNodePath = paths.join("-");
|
20718
|
-
return schemaValues.value.some((val) => val.__path === nextNodePath);
|
20719
|
-
};
|
20720
|
-
const getVirtualLines = (node) => {
|
20721
|
-
if (!props.levelLine) {
|
20722
|
-
return null;
|
20723
|
-
}
|
20724
|
-
const getNodeLineStyle = (dpth) => ({
|
20725
|
-
"--depth": dpth
|
20726
|
-
});
|
20727
|
-
const maxDeep = getNodeAttr2(node, "__depth") + 1;
|
20728
|
-
return new Array(maxDeep).fill("").map((_2, index) => index).filter((depth) => filterNextNode(depth, node)).filter((depth) => depth > 0).map((index) => createVNode("span", {
|
20729
|
-
"class": "node-virtual-line",
|
20730
|
-
"style": getNodeLineStyle(maxDeep - index)
|
20731
|
-
}, null));
|
20860
|
+
const setChecked = (item, checked = true) => {
|
20861
|
+
setNodeAction(item, "__checked", checked);
|
20732
20862
|
};
|
20863
|
+
ctx.expose({
|
20864
|
+
hanldeTreeNodeClick,
|
20865
|
+
setOpen,
|
20866
|
+
setChecked,
|
20867
|
+
setNodeAction
|
20868
|
+
});
|
20733
20869
|
const root = ref();
|
20734
20870
|
const setNodeTextStyle = () => {
|
20735
|
-
var
|
20736
|
-
if ((
|
20871
|
+
var _a2;
|
20872
|
+
if ((_a2 = root.value) == null ? void 0 : _a2.$el) {
|
20737
20873
|
const selector = `.${resolveClassName("tree-node")}`;
|
20738
20874
|
const ctxSelector = `.${resolveClassName("node-content")}`;
|
20739
20875
|
Array.prototype.forEach.call(root.value.$el.querySelectorAll(selector), (nodeEl) => {
|
@@ -20752,48 +20888,15 @@ var Component = defineComponent({
|
|
20752
20888
|
onUpdated(() => {
|
20753
20889
|
setNodeTextStyle();
|
20754
20890
|
});
|
20755
|
-
return {
|
20756
|
-
renderData,
|
20757
|
-
flatData,
|
20758
|
-
root,
|
20759
|
-
hanldeTreeNodeClick,
|
20760
|
-
handleNodeContentClick,
|
20761
|
-
handleNodeActionClick,
|
20762
|
-
getActionIcon,
|
20763
|
-
getRootIcon,
|
20764
|
-
getVirtualLines,
|
20765
|
-
getNodePrefixIcon,
|
20766
|
-
getLoadingIcon
|
20767
|
-
};
|
20768
|
-
},
|
20769
|
-
render() {
|
20770
|
-
const props = this.$props;
|
20771
|
-
const renderTreeNode = (item) => {
|
20772
|
-
var _a, _b, _c, _d, _e;
|
20773
|
-
return createVNode("div", {
|
20774
|
-
"class": getNodeRowClass(item, this.flatData.schema)
|
20775
|
-
}, [createVNode("div", {
|
20776
|
-
"class": getNodeItemClass(item, this.flatData.schema, props),
|
20777
|
-
"style": getNodeItemStyle(item, props, this.flatData),
|
20778
|
-
"onClick": () => this.handleNodeContentClick(item)
|
20779
|
-
}, [createVNode("span", {
|
20780
|
-
"class": resolveClassName("node-action"),
|
20781
|
-
"onClick": (e) => this.handleNodeActionClick(e, item)
|
20782
|
-
}, [this.getActionIcon(item)]), createVNode("span", {
|
20783
|
-
"class": resolveClassName("node-content")
|
20784
|
-
}, [[this.getNodePrefixIcon(item), this.getLoadingIcon(item)], createVNode("span", {
|
20785
|
-
"class": resolveClassName("node-text")
|
20786
|
-
}, [(_e = (_b = (_a = this.$slots).node) == null ? void 0 : _b.call(_a, item)) != null ? _e : [getLabel(item, props), (_d = (_c = this.$slots).nodeAppend) == null ? void 0 : _d.call(_c, item)]])]), this.getVirtualLines(item)])]);
|
20787
|
-
};
|
20788
|
-
return createVNode(BkVirtualRender, {
|
20891
|
+
return () => createVNode(BkVirtualRender, {
|
20789
20892
|
"class": resolveClassName("tree"),
|
20790
20893
|
"style": getTreeStyle(null, props),
|
20791
|
-
"list":
|
20894
|
+
"list": renderData.value,
|
20792
20895
|
"lineHeight": props.lineHeight,
|
20793
20896
|
"enabled": props.virtualRender,
|
20794
20897
|
"contentClassName": resolveClassName("container"),
|
20795
20898
|
"throttleDelay": 0,
|
20796
|
-
"ref":
|
20899
|
+
"ref": root
|
20797
20900
|
}, {
|
20798
20901
|
default: (scoped) => (scoped.data || []).map(renderTreeNode)
|
20799
20902
|
});
|