{"version":3,"file":"node.js","sources":["../../../../../../packages/components/cascader-panel/src/node.ts"],"sourcesContent":["// @ts-nocheck\nimport {\n capitalize,\n isEmpty,\n isFunction,\n isUndefined,\n} from '@element-plus/utils'\nimport type { VNode } from 'vue'\n\nexport type CascaderNodeValue = string | number\nexport type CascaderNodePathValue = CascaderNodeValue[]\nexport type CascaderValue =\n | CascaderNodeValue\n | CascaderNodePathValue\n | (CascaderNodeValue | CascaderNodePathValue)[]\nexport type CascaderConfig = Required\nexport type ExpandTrigger = 'click' | 'hover'\nexport type isDisabled = (data: CascaderOption, node: Node) => boolean\nexport type isLeaf = (data: CascaderOption, node: Node) => boolean\nexport type Resolve = (dataList?: CascaderOption[]) => void\nexport type LazyLoad = (node: Node, resolve: Resolve) => void\nexport type RenderLabel = ({\n node: Node,\n data: CascaderOption,\n}) => VNode | VNode[]\nexport interface CascaderOption extends Record {\n label?: string\n value?: CascaderNodeValue\n children?: CascaderOption[]\n disabled?: boolean\n leaf?: boolean\n}\n\nexport interface CascaderProps {\n expandTrigger?: ExpandTrigger\n multiple?: boolean\n checkStrictly?: boolean\n emitPath?: boolean\n lazy?: boolean\n lazyLoad?: LazyLoad\n value?: string\n label?: string\n children?: string\n disabled?: string | isDisabled\n leaf?: string | isLeaf\n hoverThreshold?: number\n}\n\nexport type Nullable = null | T\n\ntype ChildrenData = CascaderOption[] | undefined\n\nlet uid = 0\n\nconst calculatePathNodes = (node: Node) => {\n const nodes = [node]\n let { parent } = node\n\n while (parent) {\n nodes.unshift(parent)\n parent = parent.parent\n }\n\n return nodes\n}\n\nclass Node {\n readonly uid: number = uid++\n readonly level: number\n readonly value: CascaderNodeValue\n readonly label: string\n readonly pathNodes: Node[]\n readonly pathValues: CascaderNodePathValue\n readonly pathLabels: string[]\n\n childrenData: ChildrenData\n children: Node[]\n text: string\n loaded: boolean\n /**\n * Is it checked\n *\n * @default false\n */\n checked = false\n /**\n * Used to indicate the intermediate state of unchecked and fully checked child nodes\n *\n * @default false\n */\n indeterminate = false\n /**\n * Loading Status\n *\n * @default false\n */\n loading = false\n\n constructor(\n readonly data: Nullable,\n readonly config: CascaderConfig,\n readonly parent?: Node,\n readonly root = false\n ) {\n const { value: valueKey, label: labelKey, children: childrenKey } = config\n\n const childrenData = data[childrenKey] as ChildrenData\n const pathNodes = calculatePathNodes(this)\n\n this.level = root ? 0 : parent ? parent.level + 1 : 1\n this.value = data[valueKey] as CascaderNodeValue\n this.label = data[labelKey] as string\n this.pathNodes = pathNodes\n this.pathValues = pathNodes.map((node) => node.value)\n this.pathLabels = pathNodes.map((node) => node.label)\n this.childrenData = childrenData\n this.children = (childrenData || []).map(\n (child) => new Node(child, config, this)\n )\n this.loaded = !config.lazy || this.isLeaf || !isEmpty(childrenData)\n }\n\n get isDisabled(): boolean {\n const { data, parent, config } = this\n const { disabled, checkStrictly } = config\n const isDisabled = isFunction(disabled)\n ? disabled(data, this)\n : !!data[disabled]\n return isDisabled || (!checkStrictly && parent?.isDisabled)\n }\n\n get isLeaf(): boolean {\n const { data, config, childrenData, loaded } = this\n const { lazy, leaf } = config\n const isLeaf = isFunction(leaf) ? leaf(data, this) : data[leaf]\n\n return isUndefined(isLeaf)\n ? lazy && !loaded\n ? false\n : !(Array.isArray(childrenData) && childrenData.length)\n : !!isLeaf\n }\n\n get valueByOption() {\n return this.config.emitPath ? this.pathValues : this.value\n }\n\n appendChild(childData: CascaderOption) {\n const { childrenData, children } = this\n const node = new Node(childData, this.config, this)\n\n if (Array.isArray(childrenData)) {\n childrenData.push(childData)\n } else {\n this.childrenData = [childData]\n }\n\n children.push(node)\n\n return node\n }\n\n calcText(allLevels: boolean, separator: string) {\n const text = allLevels ? this.pathLabels.join(separator) : this.label\n this.text = text\n return text\n }\n\n broadcast(event: string, ...args: unknown[]) {\n const handlerName = `onParent${capitalize(event)}`\n this.children.forEach((child) => {\n if (child) {\n // bottom up\n child.broadcast(event, ...args)\n child[handlerName] && child[handlerName](...args)\n }\n })\n }\n\n emit(event: string, ...args: unknown[]) {\n const { parent } = this\n const handlerName = `onChild${capitalize(event)}`\n if (parent) {\n parent[handlerName] && parent[handlerName](...args)\n parent.emit(event, ...args)\n }\n }\n\n onParentCheck(checked: boolean) {\n if (!this.isDisabled) {\n this.setCheckState(checked)\n }\n }\n\n onChildCheck() {\n const { children } = this\n const validChildren = children.filter((child) => !child.isDisabled)\n const checked = validChildren.length\n ? validChildren.every((child) => child.checked)\n : false\n\n this.setCheckState(checked)\n }\n\n setCheckState(checked: boolean) {\n const totalNum = this.children.length\n const checkedNum = this.children.reduce((c, p) => {\n const num = p.checked ? 1 : p.indeterminate ? 0.5 : 0\n return c + num\n }, 0)\n\n this.checked =\n this.loaded &&\n this.children\n .filter((child) => !child.isDisabled)\n .every((child) => child.loaded && child.checked) &&\n checked\n this.indeterminate =\n this.loaded && checkedNum !== totalNum && checkedNum > 0\n }\n\n doCheck(checked: boolean) {\n if (this.checked === checked) return\n\n const { checkStrictly, multiple } = this.config\n\n if (checkStrictly || !multiple) {\n this.checked = checked\n } else {\n // bottom up to unify the calculation of the indeterminate state\n this.broadcast('check', checked)\n this.setCheckState(checked)\n this.emit('check')\n }\n }\n}\n\nexport default Node\n"],"names":["isEmpty","isFunction","isUndefined","capitalize"],"mappings":";;;;;;;;;AAMA,IAAI,GAAG,GAAG,CAAC,CAAC;AACZ,MAAM,kBAAkB,GAAG,CAAC,IAAI,KAAK;AACrC,EAAE,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC;AACvB,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;AACxB,EAAE,OAAO,MAAM,EAAE;AACjB,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAC1B,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;AAC3B,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AACF,MAAM,IAAI,CAAC;AACX,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM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