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 lines
6.3 KiB

{"ast":null,"code":"import { watch } from 'vue';\nimport { debounce } from 'lodash-unified';\nimport useStore from './index.mjs';\nimport { isObject } from '@vue/shared';\nconst InitialStateMap = {\n rowKey: \"rowKey\",\n defaultExpandAll: \"defaultExpandAll\",\n selectOnIndeterminate: \"selectOnIndeterminate\",\n indent: \"indent\",\n lazy: \"lazy\",\n data: \"data\",\n [\"treeProps.hasChildren\"]: {\n key: \"lazyColumnIdentifier\",\n default: \"hasChildren\"\n },\n [\"treeProps.children\"]: {\n key: \"childrenColumnName\",\n default: \"children\"\n },\n [\"treeProps.checkStrictly\"]: {\n key: \"checkStrictly\",\n default: false\n }\n};\nfunction createStore(table, props) {\n if (!table) {\n throw new Error(\"Table is required.\");\n }\n const store = useStore();\n store.toggleAllSelection = debounce(store._toggleAllSelection, 10);\n Object.keys(InitialStateMap).forEach(key => {\n handleValue(getArrKeysValue(props, key), key, store);\n });\n proxyTableProps(store, props);\n return store;\n}\nfunction proxyTableProps(store, props) {\n Object.keys(InitialStateMap).forEach(key => {\n watch(() => getArrKeysValue(props, key), value => {\n handleValue(value, key, store);\n });\n });\n}\nfunction handleValue(value, propsKey, store) {\n let newVal = value;\n let storeKey = InitialStateMap[propsKey];\n if (isObject(InitialStateMap[propsKey])) {\n storeKey = storeKey.key;\n newVal = newVal || InitialStateMap[propsKey].default;\n }\n store.states[storeKey].value = newVal;\n}\nfunction getArrKeysValue(props, keys) {\n if (keys.includes(\".\")) {\n const keyList = keys.split(\".\");\n let value = props;\n keyList.forEach(key => {\n value = value[key];\n });\n return value;\n } else {\n return props[keys];\n }\n}\nexport { createStore };","map":{"version":3,"names":["InitialStateMap","rowKey","defaultExpandAll","selectOnIndeterminate","indent","lazy","data","key","default","createStore","table","props","Error","store","useStore","toggleAllSelection","debounce","_toggleAllSelection","Object","keys","forEach","handleValue","getArrKeysValue","proxyTableProps","watch","value","propsKey","newVal","storeKey","isObject","states","includes","keyList","split"],"sources":["../../../../../../../packages/components/table/src/store/helper.ts"],"sourcesContent":["// @ts-nocheck\nimport { watch } from 'vue'\nimport { debounce } from 'lodash-unified'\nimport { isObject } from '@element-plus/utils'\nimport useStore from '.'\n\nimport type { Store } from '.'\nimport type { Table, TableProps } from '../table/defaults'\n\nconst InitialStateMap = {\n rowKey: 'rowKey',\n defaultExpandAll: 'defaultExpandAll',\n selectOnIndeterminate: 'selectOnIndeterminate',\n indent: 'indent',\n lazy: 'lazy',\n data: 'data',\n ['treeProps.hasChildren']: {\n key: 'lazyColumnIdentifier',\n default: 'hasChildren',\n },\n ['treeProps.children']: {\n key: 'childrenColumnName',\n default: 'children',\n },\n ['treeProps.checkStrictly']: {\n key: 'checkStrictly',\n default: false,\n },\n}\n\nexport function createStore<T>(table: Table<T>, props: TableProps<T>) {\n if (!table) {\n throw new Error('Table is required.')\n }\n\n const store = useStore<T>()\n // fix https://github.com/ElemeFE/element/issues/14075\n // related pr https://github.com/ElemeFE/element/pull/14146\n store.toggleAllSelection = debounce(store._toggleAllSelection, 10)\n Object.keys(InitialStateMap).forEach((key) => {\n handleValue(getArrKeysValue(props, key), key, store)\n })\n proxyTableProps(store, props)\n return store\n}\n\nfunction proxyTableProps<T>(store: Store<T>, props: TableProps<T>) {\n Object.keys(InitialStateMap).forEach((key) => {\n watch(\n () => getArrKeysValue(props, key),\n (value) => {\n handleValue(value, key, store)\n }\n )\n })\n}\n\nfunction handleValue<T>(value, propsKey: string, store: Store<T>) {\n let newVal = value\n let storeKey = InitialStateMap[propsKey]\n if (isObject(InitialStateMap[propsKey])) {\n storeKey = storeKey.key\n newVal = newVal || InitialStateMap[propsKey].default\n }\n store.states[storeKey].value = newVal\n}\n\nfunction getArrKeysValue<T>(props: TableProps<T>, keys: string) {\n if (keys.includes('.')) {\n const keyList = keys.split('.')\n let value = props\n keyList.forEach((key) => {\n value = value[key]\n })\n return value\n } else {\n return props[keys]\n }\n}\n"],"mappings":";;;;A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