Files
pig-farm-controller-fe/node_modules/element-plus/es/components/tree-select/src/tree.mjs.map

1 line
17 KiB
Plaintext
Raw Normal View History

2025-09-19 14:25:20 +08:00
{"version":3,"file":"tree.mjs","sources":["../../../../../../packages/components/tree-select/src/tree.ts"],"sourcesContent":["// @ts-nocheck\nimport { computed, nextTick, toRefs, watch } from 'vue'\nimport { isEqual, isNil, pick } from 'lodash-unified'\nimport { UPDATE_MODEL_EVENT } from '@element-plus/constants'\nimport { escapeStringRegexp, isEmpty, isFunction } from '@element-plus/utils'\nimport ElTree from '@element-plus/components/tree'\nimport TreeSelectOption from './tree-select-option'\nimport {\n isValidArray,\n isValidValue,\n toValidArray,\n treeEach,\n treeFind,\n} from './utils'\n\nimport type { CacheOption } from './cache-options'\nimport type { Ref } from 'vue'\nimport type { SelectInstance } from '@element-plus/components/select'\nimport type Node from '@element-plus/components/tree/src/model/node'\nimport type { TreeNodeData } from '@element-plus/components/tree/src/tree.type'\nimport type { TreeInstance } from '@element-plus/components/tree'\n\nexport const useTree = (\n props,\n { attrs, slots, emit },\n {\n select,\n tree,\n key,\n }: {\n select: Ref<SelectInstance | undefined>\n tree: Ref<TreeInstance | undefined>\n key: Ref<string>\n }\n) => {\n watch(\n [() => props.modelValue, tree],\n () => {\n if (props.showCheckbox) {\n nextTick(() => {\n const treeInstance = tree.value\n if (\n treeInstance &&\n !isEqual(\n treeInstance.getCheckedKeys(),\n toValidArray(props.modelValue)\n )\n ) {\n treeInstance.setCheckedKeys(toValidArray(props.modelValue))\n }\n })\n }\n },\n {\n immediate: true,\n deep: true,\n }\n )\n\n const propsMap = computed(() => ({\n value: key.value,\n label: 'label',\n children: 'children',\n disabled: 'disabled',\n isLeaf: 'isLeaf',\n ...props.props,\n }))\n\n const getNodeValByProp = (\n prop: 'value' | 'label' | 'children' | 'disabled' | 'isLeaf',\n data: TreeNodeData\n ) => {\n const propVal = propsMap.value[prop]\n if (isFunction(propVal)) {\n return propVal(\n data,\n tree.value?.getNode(getNodeValByProp('value', data)) as Node\n )\n } else {\n return data[propVal as string]\n }\n }\n\n const defaultExpandedParentKeys = toValidArray(props.modelValue)\n .map((value) => {\n return treeFind(\n props.data || [],\n (data) => getNodeValByProp('value', data) === value,\n (data) => getNodeValByProp('children', data),\n (data, index, array, parent) =>\n parent && getNodeValByProp('value', parent)\n )\n })\n .filter((item) => isValidValue(item))\n\n const cacheOptions = computed(() => {\n if (!props.renderAfterExpand && !props.lazy) return []\n\n const options: CacheOption[] = []\n\n treeEach(\n props.data.concat(props.cacheData),\n (node) => {\n const value = getNodeValByProp('value', node)\n options.push({\n value,\n currentLabel: getNodeValByProp('label', node),\n isDisabled: getNodeValByProp('disabled', node),\n })\n },\n (data) => getNodeValByProp('children', data)\n )\n\n return options\n })\n\n const getChildCheckedKeys = () => {\n return tree.value?.getCheckedKeys().filter((checkedKey) => {\n const node = tree.value?.getNode(checkedKey) as Node\n return !isNil(node) && isEmpty(node.childNodes)\n })\n }\n\n return {\n ...pick(toRefs(props), Object.keys(ElTree.props)),\n ...attrs,\n nodeKey: key,\n\n // only expand on click node when the `check-strictly` is false\n expandOnClickNode: computed(() => {\n return !props.checkStrictly && props.expandOnClickNode\n }),\n\n // show current selected node only first time,\n // fix the problem of expanding multiple nodes when checking multiple nodes\n defaultExpandedKeys: computed(() => {\n return props.defaultExpandedKeys\n ? props.defaultExpandedKeys.concat(defaultExpandedParentKeys)\n