{"version":3,"file":"use-row.mjs","sources":["../../../../../../../packages/components/table-v2/src/composables/use-row.ts"],"sourcesContent":["import { computed, getCurrentInstance, ref, shallowRef, unref } from 'vue'\nimport { debounce } from 'lodash-unified'\nimport { isNumber } from '@element-plus/utils'\nimport { FixedDir } from '../constants'\n\nimport type { ComponentInternalInstance, Ref, ShallowRef } from 'vue'\nimport type { TableV2Props } from '../table'\nimport type {\n RowExpandParams,\n RowHeightChangedParams,\n RowHoverParams,\n} from '../row'\nimport type { FixedDirection, KeyType } from '../types'\nimport type { onRowRenderedParams } from '../grid'\nimport type { TableGridInstance } from '../table-grid'\nimport type { UseNamespaceReturn } from '@element-plus/hooks'\n\ntype Heights = Record\ntype GridInstanceRef = Ref\n\ntype UseRowProps = {\n mainTableRef: GridInstanceRef\n leftTableRef: GridInstanceRef\n rightTableRef: GridInstanceRef\n tableInstance: ComponentInternalInstance\n ns: UseNamespaceReturn\n isScrolling: ShallowRef\n}\n\nexport const useRow = (\n props: TableV2Props,\n {\n mainTableRef,\n leftTableRef,\n rightTableRef,\n tableInstance,\n ns,\n isScrolling,\n }: UseRowProps\n) => {\n const vm = getCurrentInstance()!\n const { emit } = vm\n const isResetting = shallowRef(false)\n const expandedRowKeys = ref(props.defaultExpandedRowKeys || [])\n const lastRenderedRowIndex = ref(-1)\n const resetIndex = shallowRef(null)\n const rowHeights = ref({})\n const pendingRowHeights = ref({})\n const leftTableHeights = shallowRef({})\n const mainTableHeights = shallowRef({})\n const rightTableHeights = shallowRef({})\n const isDynamic = computed(() => isNumber(props.estimatedRowHeight))\n\n function onRowsRendered(params: onRowRenderedParams) {\n props.onRowsRendered?.(params)\n\n if (params.rowCacheEnd > unref(lastRenderedRowIndex)) {\n lastRenderedRowIndex.value = params.rowCacheEnd\n }\n }\n\n function onRowHovered({ hovered, rowKey }: RowHoverParams) {\n if (isScrolling.value) {\n return\n }\n const tableRoot = tableInstance!.vnode.el as HTMLElement\n const rows = tableRoot.querySelectorAll(`[rowkey=\"${String(rowKey)}\"]`)\n rows.forEach((row) => {\n if (hovered) {\n row.classList.add(ns.is('hovered'))\n } else {\n row.classList.remove(ns.is('hovered'))\n }\n })\n }\n\n function onRowExpanded({\n expanded,\n rowData,\n rowIndex,\n rowKey,\n }: RowExpandParams) {\n const _expandedRowKeys = [...unref(expandedRowKeys)]\n const currentKeyIndex = _expandedRowKeys.indexOf(rowKey)\n if (expanded) {\n if (currentKeyIndex === -1) _expandedRowKeys.push(rowKey)\n } else {\n if (currentKeyIndex > -1) _expandedRowKeys.splice(currentKeyIndex, 1)\n }\n expandedRowKeys.value = _expandedRowKeys\n\n emit('update:expandedRowKeys', _expandedRowKeys)\n props.onRowExpand?.({\n expanded,\n rowData,\n rowIndex,\n rowKey,\n })\n // If this is not controlled, then use this to notify changes\n props.onExpandedRowsChange?.(_expandedRowKeys)\n }\n\n const flushingRowHeights = debounce(() => {\n isResetting.value = true\n rowHeights.value = { ...unref(rowHeights), ...unref(pendingRowHeights) }\n resetAfterIndex(unref(resetIndex)!, false)\n pendingRowHeights.value = {}\n // force update\n resetIndex.value = null\n mainTableRef.value?.forceUpdate()\n leftTableRef.value?.forceUpdate()\n rightTableRef.value?.forceUpdate()\n vm.proxy?.$forceUpdate()\n isResetting.value = false\n }, 0)\n\n function resetAfterIndex(index: number, forceUpdate = false) {\n if (!unref(isDynamic)) return\n ;[mainTableRef, leftTableRef, rightTableRef].forEach((tableRef) => {\n const table = unref(tableRef)\n if (table) table.resetAfterRowIndex(index, forceUpdate)\n })\n }\n\n function resetHeights(rowKey: KeyType, height: number, rowIdx: number) {\n const resetIdx = unref(resetIndex)\n if (resetIdx === null) {\n resetIndex.value = rowIdx\n } else {\n if (resetIdx > rowIdx) {\n resetIndex.value = rowIdx\n }\n }\n\n pendingRowHeights.value[rowKey] = height\n }\n\n function onRowHeightChange(\n { rowKey, height, rowIndex }: RowHeightChangedParams,\n fixedDir: FixedDirection\n ) {\n if (!fixedDir) {\n mainTableHeights.value[rowKey] = height\n } else {\n if (fixedDir === FixedDir.RIGHT) {\n rightTableHeights.value[rowKey] = height\n } else {\n leftTableHeights.value[rowKey] = height\n }\n }\n\n const maximumHeight = Math.max(\n ...[leftTableHeights, rightTableHeights, mainTableHeights].map(\n (records) => records.value[rowKey] || 0\n )\n )\n\n if (unref(rowHeights)[rowKey] !== maximumHeight) {\n resetHeights(rowKey, maximumHeight, rowIndex)\n flushingRowHeights()\n }\n }\n\n return {\n expandedRowKeys,\n lastRenderedRowIndex,\n isDynamic,\n isResetting,\n rowHeights,\n\n resetAfterIndex,\n onRowExpanded,\n onRowHovered,\n onRowsRendered,\n onRowHeightChange,\n }\n}\n\nexport type UseRowReturn = ReturnType\n"],"names":[],"mappings":";;;;;;AAIY,MAAC,MAAM,GAAG,CAAC,KAAK,EAAE;AAC9B,EAAE,YAAY;AACd,EAAE,YAAY;AACd,EAAE,aAAa;AACf,EAAE,aAAa;AACf,EAAE,EAAE;AACJ,EAAE,WAAW;AACb,CAAC,KAAK;AACN,EAAE,MAAM,EAAE,GAAG,kBAAkB,EAAE,CAAC;AAClC,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACtB,EAAE,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;AACxC,EAAE,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;AAClE,EAAE,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,EAAE,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;AACtC,EAAE,MAAM,UAAU,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC;AAC7B,EAAE,MAAM,iBAAiB,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC;AACpC,EAAE,MAAM,gBAAgB,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;AAC1C,EAAE,MAAM,gBAAgB,GAAG,UAAU,CAAC,EAAE,CAAC,CAA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