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.
1 line
29 KiB
1 line
29 KiB
|
2 years ago
|
{"version":3,"file":"node.mjs","sources":["../../../../../../../packages/components/tree/src/model/node.ts"],"sourcesContent":["// @ts-nocheck\nimport { reactive } from 'vue'\nimport { hasOwn } from '@element-plus/utils'\nimport { NODE_KEY, markNodeData } from './util'\nimport type TreeStore from './tree-store'\n\nimport type { Nullable } from '@element-plus/utils'\nimport type {\n FakeNode,\n TreeKey,\n TreeNodeChildState,\n TreeNodeData,\n TreeNodeLoadedDefaultProps,\n TreeNodeOptions,\n} from '../tree.type'\n\nexport const getChildState = (node: Node[]): TreeNodeChildState => {\n let all = true\n let none = true\n let allWithoutDisable = true\n for (let i = 0, j = node.length; i < j; i++) {\n const n = node[i]\n if (n.checked !== true || n.indeterminate) {\n all = false\n if (!n.disabled) {\n allWithoutDisable = false\n }\n }\n if (n.checked !== false || n.indeterminate) {\n none = false\n }\n }\n\n return { all, none, allWithoutDisable, half: !all && !none }\n}\n\nconst reInitChecked = function (node: Node): void {\n if (node.childNodes.length === 0 || node.loading) return\n\n const { all, none, half } = getChildState(node.childNodes)\n if (all) {\n node.checked = true\n node.indeterminate = false\n } else if (half) {\n node.checked = false\n node.indeterminate = true\n } else if (none) {\n node.checked = false\n node.indeterminate = false\n }\n\n const parent = node.parent\n if (!parent || parent.level === 0) return\n\n if (!node.store.checkStrictly) {\n reInitChecked(parent)\n }\n}\n\nconst getPropertyFromData = function (node: Node, prop: string): any {\n const props = node.store.props\n const data = node.data || {}\n const config = props[prop]\n\n if (typeof config === 'function') {\n return config(data, node)\n } else if (typeof config === 'string') {\n return data[config]\n } else if (typeof config === 'undefined') {\n const dataProp = data[prop]\n return dataProp === undefined ? '' : dataProp\n }\n}\n\nlet nodeIdSeed = 0\n\nclass Node {\n id: number\n text: string\n checked: boolean\n indeterminate: boolean\n data: TreeNodeData\n expanded: boolean\n parent: Node\n visible: boolean\n isCurrent: boolean\n store: TreeStore\n isLeafByUser: boolean\n isLeaf: boolean\n canFocus: boolean\n\n level: number\n loaded: boolean\n childNodes: Node[]\n loading: boolean\n\n constructor(options: TreeNodeOptions) {\n this.id = nodeIdSeed++\n this.text = null\n this.checked = false\n this.indeterminate = false\n this.data = null\n this.expanded = false\n this.parent = null\n this.visible = true\n this.isCurrent = false\n this.canFocus = false\n\n for (const name in options) {\n if (hasOwn(options, name)) {\n this[name] = options[name]\n }\n }\n\n // internal\n this.level = 0\n this.loaded = false\n this.childNodes = []\n this.loading = false\n\n if (this.parent) {\n this.level = this.parent.level + 1\n }\n }\n\n initialize() {\n const store = this.store\n if (!store) {\n throw new Error('[Node]store is required!')\n }\n store.registerNode(this)\n\n const props = store.props\n if (props && typeof props.isLeaf !== 'undefined') {\n const isLeaf = getPropertyFromData(this, 'isLeaf')\n if (typeof isLeaf === 'boolean') {\n this.isLeafByUser = isLeaf\n }\n }\n\n if (store.lazy !== true && this.data) {\n this.setData(this.data)\n\n if (store.defaultExpandAll) {\n this.expanded = true\n this.canFocus = true\n }\n } else if (this.level > 0 && store.lazy && store.defaultExpandAll) {\n this.expand()\n }\n if (!Array.isArray(this.data)) {\n markNodeData(this, this.data)\n }\n if (!this.data) return\n\n const defaultExpandedKeys = store.defaultExpandedKeys\n const key = store.key\n\n if (key && defaultExpandedKeys && defaultExpandedKeys.includes(this.key)) {\n this.expand(null, store.autoExpandParent)\n }\n\n if (\n
|