You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
26 KiB

1 month ago
  1. {"ast":null,"code":"import { ref, shallowRef, watch, computed, nextTick } from 'vue';\nimport { TreeOptionsEnum, NODE_CLICK, NODE_DROP, CURRENT_CHANGE, NODE_EXPAND, NODE_COLLAPSE } from '../virtual-tree.mjs';\nimport { useCheck } from './useCheck.mjs';\nimport { useFilter } from './useFilter.mjs';\nimport { isObject } from '@vue/shared';\nfunction useTree(props, emit) {\n const expandedKeySet = ref(new Set(props.defaultExpandedKeys));\n const currentKey = ref();\n const tree = shallowRef();\n const listRef = ref();\n watch(() => props.currentNodeKey, key => {\n currentKey.value = key;\n }, {\n immediate: true\n });\n watch(() => props.data, data => {\n setData(data);\n }, {\n immediate: true\n });\n const {\n isIndeterminate,\n isChecked,\n toggleCheckbox,\n getCheckedKeys,\n getCheckedNodes,\n getHalfCheckedKeys,\n getHalfCheckedNodes,\n setChecked,\n setCheckedKeys\n } = useCheck(props, tree);\n const {\n doFilter,\n hiddenNodeKeySet,\n isForceHiddenExpandIcon\n } = useFilter(props, tree);\n const valueKey = computed(() => {\n var _a;\n return ((_a = props.props) == null ? void 0 : _a.value) || TreeOptionsEnum.KEY;\n });\n const childrenKey = computed(() => {\n var _a;\n return ((_a = props.props) == null ? void 0 : _a.children) || TreeOptionsEnum.CHILDREN;\n });\n const disabledKey = computed(() => {\n var _a;\n return ((_a = props.props) == null ? void 0 : _a.disabled) || TreeOptionsEnum.DISABLED;\n });\n const labelKey = computed(() => {\n var _a;\n return ((_a = props.props) == null ? void 0 : _a.label) || TreeOptionsEnum.LABEL;\n });\n const flattenTree = computed(() => {\n var _a;\n const expandedKeys = expandedKeySet.value;\n const hiddenKeys = hiddenNodeKeySet.value;\n const flattenNodes = [];\n const nodes = ((_a = tree.value) == null ? void 0 : _a.treeNodes) || [];\n const stack = [];\n for (let i = nodes.length - 1; i >= 0; --i) {\n stack.push(nodes[i]);\n }\n while (stack.length) {\n const node = stack.pop();\n if (hiddenKeys.has(node.key)) continue;\n flattenNodes.push(node);\n if (node.children && expandedKeys.has(node.key)) {\n for (let i = node.children.length - 1; i >= 0; --i) {\n stack.push(node.children[i]);\n }\n }\n }\n return flattenNodes;\n });\n const isNotEmpty = computed(() => {\n return flattenTree.value.length > 0;\n });\n function createTree(data) {\n const treeNodeMap = /* @__PURE__ */new Map();\n const levelTreeNodeMap = /* @__PURE__ */new Map();\n let maxLevel = 1;\n function traverse(nodes, level = 1, parent = void 0) {\n var _a;\n const siblings = [];\n for (const rawNode of nodes) {\n const value = getKey(rawNode);\n const node = {\n level,\n key: value,\n data: rawNode\n };\n node.label = getLabel(rawNode);\n node.parent = parent;\n const children = getChildren(rawNode);\n node.disabled = getDisabled(rawNode);\n node.isLeaf = !children || children.length === 0;\n if (children && children.length) {\n node.children = traverse(children, level + 1, node);\n }\n siblings.push(node);\n treeNodeMap.set(value, node);\n if (!levelTreeNodeMap.has(level)) {\n levelTreeNodeMap.set(level, []);\n }\n (_a = levelTreeNodeMap.get(level)) == null ? void 0 : _a.push(node);\n }\n if (level > maxLevel) {\n maxLevel = level;\n }\n return siblings;\n }\n const treeNodes = traverse(data);\n return {\n treeNodeMap,\n levelTreeNodeMap,\n maxLevel,\n treeNodes\n };\n }\n function filter(query) {\n const keys = doFilter(query);\n if (keys) {\n expandedKeySet.value = keys;\n }\n }\n function getChildren(node) {\n return node[childrenKey.value];\n }\n function getKey(node) {\n if (!node) {\n return \"\";\n }\n return node[valueKey.value];\n }\n function getD