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.
|
|
{"ast":null,"code":"import { reactive } from 'vue';\nimport { markNodeData, NODE_KEY } from './util.mjs';\nimport { hasOwn, isArray, isFunction, isString } from '@vue/shared';\nimport { isBoolean, isUndefined } from '../../../../utils/types.mjs';\nconst getChildState = node => {\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 return {\n all,\n none,\n allWithoutDisable,\n half: !all && !none\n };\n};\nconst reInitChecked = function (node) {\n if (node.childNodes.length === 0 || node.loading) return;\n const {\n all,\n none,\n half\n } = 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 const parent = node.parent;\n if (!parent || parent.level === 0) return;\n if (!node.store.checkStrictly) {\n reInitChecked(parent);\n }\n};\nconst getPropertyFromData = function (node, prop) {\n const props = node.store.props;\n const data = node.data || {};\n const config = props[prop];\n if (isFunction(config)) {\n return config(data, node);\n } else if (isString(config)) {\n return data[config];\n } else if (isUndefined(config)) {\n const dataProp = data[prop];\n return dataProp === void 0 ? \"\" : dataProp;\n }\n};\nlet nodeIdSeed = 0;\nclass Node {\n constructor(options) {\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 for (const name in options) {\n if (hasOwn(options, name)) {\n this[name] = options[name];\n }\n }\n this.level = 0;\n this.loaded = false;\n this.childNodes = [];\n this.loading = false;\n if (this.parent) {\n this.level = this.parent.level + 1;\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 const props = store.props;\n if (props && typeof props.isLeaf !== \"undefined\") {\n const isLeaf = getPropertyFromData(this, \"isLeaf\");\n if (isBoolean(isLeaf)) {\n this.isLeafByUser = isLeaf;\n }\n }\n if (store.lazy !== true && this.data) {\n this.setData(this.data);\n if (store.defaultExpandAll) {\n this.expanded = true;\n this.canFocus = true;\n }\n } else if (this.level > 0 && store.lazy && store.defaultExpandAll && !this.isLeafByUser) {\n this.expand();\n }\n if (!isArray(this.data)) {\n markNodeData(this, this.data);\n }\n if (!this.data) return;\n const defaultExpandedKeys = store.defaultExpandedKeys;\n const key = store.key;\n if (key && defaultExpandedKeys && defaultExpandedKeys.includes(this.key)) {\n this.expand(null, store.autoExpandParent);\n }\n if (key && store.currentNodeKey !== void 0 && this.key === store.currentNodeKey) {\n store.currentNode = this;\n store.currentNode.isCurrent = true;\n }\n if (store.lazy) {\n store._initDefaultCheckedNode(this);\n }\n this.updateLeafState();\n if (this.parent && (this.level === 1 || this.parent.expanded === true)) this.canFocus = true;\n }\n setData(data) {\n if (!isArray(data)) {\n markNodeData(this, data);\n }\n this.data = data;\n this.childNodes = [];\n let children;\n if (this.level === 0 && isArray(this.data)) {\n children = this.data;\n } else {\n children = getPropertyFromData(this, \"children\") || [];\
|