{"version":3,"file":"store.mjs","sources":["../../../../../../packages/components/cascader-panel/src/store.ts"],"sourcesContent":["import { isEqual } from 'lodash-unified'\nimport Node from './node'\n\nimport type { Nullable } from '@element-plus/utils'\nimport type {\n CascaderConfig,\n CascaderNodePathValue,\n CascaderNodeValue,\n CascaderOption,\n} from './node'\n\nconst flatNodes = (nodes: Node[], leafOnly: boolean) => {\n return nodes.reduce((res, node) => {\n if (node.isLeaf) {\n res.push(node)\n } else {\n !leafOnly && res.push(node)\n res = res.concat(flatNodes(node.children, leafOnly))\n }\n return res\n }, [] as Node[])\n}\n\nexport default class Store {\n readonly nodes: Node[]\n readonly allNodes: Node[]\n readonly leafNodes: Node[]\n\n constructor(data: CascaderOption[], readonly config: CascaderConfig) {\n const nodes = (data || []).map(\n (nodeData) => new Node(nodeData, this.config)\n )\n this.nodes = nodes\n this.allNodes = flatNodes(nodes, false)\n this.leafNodes = flatNodes(nodes, true)\n }\n\n getNodes() {\n return this.nodes\n }\n\n getFlattedNodes(leafOnly: boolean) {\n return leafOnly ? this.leafNodes : this.allNodes\n }\n\n appendNode(nodeData: CascaderOption, parentNode?: Node) {\n const node = parentNode\n ? parentNode.appendChild(nodeData)\n : new Node(nodeData, this.config)\n\n if (!parentNode) this.nodes.push(node)\n\n this.allNodes.push(node)\n node.isLeaf && this.leafNodes.push(node)\n }\n\n appendNodes(nodeDataList: CascaderOption[], parentNode: Node) {\n nodeDataList.forEach((nodeData) => this.appendNode(nodeData, parentNode))\n }\n\n // when checkStrictly, leaf node first\n getNodeByValue(\n value: CascaderNodeValue | CascaderNodePathValue,\n leafOnly = false\n ): Nullable {\n if (!value && value !== 0) return null\n\n const node = this.getFlattedNodes(leafOnly).find(\n (node) => isEqual(node.value, value) || isEqual(node.pathValues, value)\n )\n\n return node || null\n }\n\n getSameNode(node: Node): Nullable {\n if (!node) return null\n\n const node_ = this.getFlattedNodes(false).find(\n ({ value, level }) => isEqual(node.value, value) && node.level === level\n )\n\n return node_ || null\n }\n}\n"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