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
5.5 KiB

1 month ago
  1. {"ast":null,"code":"import { ref, computed, unref, watch } from 'vue';\nimport { isArray } from '@vue/shared';\nconst useData = (props, {\n expandedRowKeys,\n lastRenderedRowIndex,\n resetAfterIndex\n}) => {\n const depthMap = ref({});\n const flattenedData = computed(() => {\n const depths = {};\n const {\n data: data2,\n rowKey\n } = props;\n const _expandedRowKeys = unref(expandedRowKeys);\n if (!_expandedRowKeys || !_expandedRowKeys.length) return data2;\n const array = [];\n const keysSet = /* @__PURE__ */new Set();\n _expandedRowKeys.forEach(x => keysSet.add(x));\n let copy = data2.slice();\n copy.forEach(x => depths[x[rowKey]] = 0);\n while (copy.length > 0) {\n const item = copy.shift();\n array.push(item);\n if (keysSet.has(item[rowKey]) && isArray(item.children) && item.children.length > 0) {\n copy = [...item.children, ...copy];\n item.children.forEach(child => depths[child[rowKey]] = depths[item[rowKey]] + 1);\n }\n }\n depthMap.value = depths;\n return array;\n });\n const data = computed(() => {\n const {\n data: data2,\n expandColumnKey\n } = props;\n return expandColumnKey ? unref(flattenedData) : data2;\n });\n watch(data, (val, prev) => {\n if (val !== prev) {\n lastRenderedRowIndex.value = -1;\n resetAfterIndex(0, true);\n }\n });\n return {\n data,\n depthMap\n };\n};\nexport { useData };","map":{"version":3,"names":["useData","props","expandedRowKeys","lastRenderedRowIndex","resetAfterIndex","depthMap","ref","flattenedData","computed","depths","data","data2","rowKey","_expandedRowKeys","unref","length","array","keysSet","Set","forEach","x","add","copy","slice","item","shift","push","has","isArray","children","child","value","expandColumnKey","watch","val","prev"],"sources":["../../../../../../../packages/components/table-v2/src/composables/use-data.ts"],"sourcesContent":["import { computed, ref, unref, watch } from 'vue'\nimport { isArray } from '@element-plus/utils'\n\nimport type { TableV2Props } from '../table'\nimport type { KeyType } from '../types'\nimport type { UseRowReturn } from './use-row'\n\ntype UseDataProps = {\n expandedRowKeys: UseRowReturn['expandedRowKeys']\n lastRenderedRowIndex: UseRowReturn['lastRenderedRowIndex']\n resetAfterIndex: UseRowReturn['resetAfterIndex']\n}\n\nexport const useData = (\n props: TableV2Props,\n { expandedRowKeys, lastRenderedRowIndex, resetAfterIndex }: UseDataProps\n) => {\n const depthMap = ref<Record<KeyType, number>>({})\n\n const flattenedData = computed(() => {\n const depths: Record<KeyType, number> = {}\n const { data, rowKey } = props\n\n const _expandedRowKeys = unref(expandedRowKeys)\n\n if (!_expandedRowKeys || !_expandedRowKeys.length) return data\n\n const array: any[] = []\n const keysSet = new Set()\n _expandedRowKeys.forEach((x) => keysSet.add(x))\n\n let copy: any[] = data.slice()\n copy.forEach((x) => (depths[x[rowKey]] = 0))\n while (copy.length > 0) {\n const item = copy.shift()!\n\n array.push(item)\n if (\n keysSet.has(item[rowKey]) &&\n isArray(item.children) &&\n item.children.length > 0\n ) {\n copy = [...item.children, ...copy]\n item.children.forEach(\n (child: any) => (depths[child[rowKey]] = depths[item[rowKey]] + 1)\n )\n }\n }\n\n depthMap.value = depths\n return array\n })\n\n const data = computed(() => {\n const { data, expandColumnKey } = props\n return expandColumnKey ? unref(flattenedData) : data\n })\n\n watch(data, (val, prev) => {\n if (val !== prev) {\n lastRenderedRowIndex.value = -1\n resetAfterIndex(0, true)\n }\n })\n\n return {\n data,\n depthMap,\n }\n}\n\nexport type UseDataReturn = ReturnType<typeof useData>\n"],"mappings":";;AAEY,MAACA,OAAO,GAAGA,CAACC,KAAK,EAAE;EAAEC,eAAe;EAAEC,oBAAoB;EAAEC;AAAe,CAAE,KAAK;EAC5F,MAAMC,QAAQ,GAAGC,GAAG,CAAC,EAAE,CAAC;EACxB,MAAMC,aAAa,GAAGC,QAAQ,CAAC,MAAM;IACnC,MAAMC,MAAM,GAAG,EAAE;I