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.

0 lines
6.8 KiB

1 month ago
  1. {"ast":null,"code":"import { getCurrentInstance, ref } from 'vue';\nimport { getKeysMap, getRowIdentity, toggleRowStatus } from '../util.mjs';\nfunction useExpand(watcherData) {\n const instance = getCurrentInstance();\n const defaultExpandAll = ref(false);\n const expandRows = ref([]);\n const updateExpandRows = () => {\n const data = watcherData.data.value || [];\n const rowKey = watcherData.rowKey.value;\n if (defaultExpandAll.value) {\n expandRows.value = data.slice();\n } else if (rowKey) {\n const expandRowsMap = getKeysMap(expandRows.value, rowKey);\n expandRows.value = data.reduce((prev, row) => {\n const rowId = getRowIdentity(row, rowKey);\n const rowInfo = expandRowsMap[rowId];\n if (rowInfo) {\n prev.push(row);\n }\n return prev;\n }, []);\n } else {\n expandRows.value = [];\n }\n };\n const toggleRowExpansion = (row, expanded) => {\n const changed = toggleRowStatus(expandRows.value, row, expanded);\n if (changed) {\n instance.emit(\"expand-change\", row, expandRows.value.slice());\n }\n };\n const setExpandRowKeys = rowKeys => {\n instance.store.assertRowKey();\n const data = watcherData.data.value || [];\n const rowKey = watcherData.rowKey.value;\n const keysMap = getKeysMap(data, rowKey);\n expandRows.value = rowKeys.reduce((prev, cur) => {\n const info = keysMap[cur];\n if (info) {\n prev.push(info.row);\n }\n return prev;\n }, []);\n };\n const isRowExpanded = row => {\n const rowKey = watcherData.rowKey.value;\n if (rowKey) {\n const expandMap = getKeysMap(expandRows.value, rowKey);\n return !!expandMap[getRowIdentity(row, rowKey)];\n }\n return expandRows.value.includes(row);\n };\n return {\n updateExpandRows,\n toggleRowExpansion,\n setExpandRowKeys,\n isRowExpanded,\n states: {\n expandRows,\n defaultExpandAll\n }\n };\n}\nexport { useExpand as default };","map":{"version":3,"names":["useExpand","watcherData","instance","getCurrentInstance","defaultExpandAll","ref","expandRows","updateExpandRows","data","value","rowKey","slice","expandRowsMap","getKeysMap","reduce","prev","row","rowId","getRowIdentity","rowInfo","push","toggleRowExpansion","expanded","changed","toggleRowStatus","emit","setExpandRowKeys","rowKeys","store","assertRowKey","keysMap","cur","info","isRowExpanded","expandMap","includes","states"],"sources":["../../../../../../../packages/components/table/src/store/expand.ts"],"sourcesContent":["// @ts-nocheck\nimport { getCurrentInstance, ref } from 'vue'\nimport { getKeysMap, getRowIdentity, toggleRowStatus } from '../util'\n\nimport type { Ref } from 'vue'\nimport type { WatcherPropsData } from '.'\nimport type { Table } from '../table/defaults'\n\nfunction useExpand<T>(watcherData: WatcherPropsData<T>) {\n const instance = getCurrentInstance() as Table<T>\n const defaultExpandAll = ref(false)\n const expandRows: Ref<T[]> = ref([])\n const updateExpandRows = () => {\n const data = watcherData.data.value || []\n const rowKey = watcherData.rowKey.value\n if (defaultExpandAll.value) {\n expandRows.value = data.slice()\n } else if (rowKey) {\n // TODO\n const expandRowsMap = getKeysMap(expandRows.value, rowKey)\n expandRows.value = data.reduce((prev: T[], row: T) => {\n const rowId = getRowIdentity(row, rowKey)\n const rowInfo = expandRowsMap[rowId]\n if (rowInfo) {\n prev.push(row)\n }\n return prev\n }, [])\n } else {\n expandRows.value = []\n }\n }\n\n const toggleRowExpansion = (row: T, expanded?: boolean) => {\n const changed = toggleRowStatus(expandRows.value, row, expanded)\n if (changed) {\n instance.emit('expand-change', row, expandRows.value.slice())\n }\n }\n\n const setExpandRowKeys = (rowKeys: string[]) => {\n instance.store.assertRowKey()\n // TODO\n const data = watcherData.data.value || []\