@economic/taco 16.0.0 → 16.0.1-EC-87329-test-release.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/primitives/Table/Core/features/useTableRenderer.cjs +10 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.cjs.map +1 -1
- package/dist/primitives/Table/Core/features/useTableRenderer.js +10 -0
- package/dist/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
- package/dist/primitives/Table/useTableManager/util/rows.cjs +10 -2
- package/dist/primitives/Table/useTableManager/util/rows.cjs.map +1 -1
- package/dist/primitives/Table/useTableManager/util/rows.d.ts +1 -4
- package/dist/primitives/Table/useTableManager/util/rows.js +10 -2
- package/dist/primitives/Table/useTableManager/util/rows.js.map +1 -1
- package/package.json +2 -2
|
@@ -4,6 +4,7 @@ const reactVirtual = require("@tanstack/react-virtual");
|
|
|
4
4
|
const sortBy = require("lodash/sortBy");
|
|
5
5
|
const without = require("lodash/without");
|
|
6
6
|
const React = require("react");
|
|
7
|
+
const usePrevious = require("../../../../hooks/usePrevious.cjs");
|
|
7
8
|
const rows = require("../../useTableManager/util/rows.cjs");
|
|
8
9
|
const SkeletonRow = require("../components/Row/BuiltIns/SkeletonRow.cjs");
|
|
9
10
|
const Row = require("../components/Row/Row.cjs");
|
|
@@ -77,6 +78,15 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
|
|
|
77
78
|
},
|
|
78
79
|
[virtualItems.length, tableRef.current, totalSize, count]
|
|
79
80
|
);
|
|
81
|
+
const isLastRowLoaded = isServerDataLoader2 ? !!tableMeta.server.pages?.includes(tableMeta.server.pageCount - 1) : !!rows$2.at(-1)?.original;
|
|
82
|
+
const previousCount = usePrevious.usePreviousValue(count);
|
|
83
|
+
const wasLastRowLoaded = usePrevious.usePreviousValue(isLastRowLoaded);
|
|
84
|
+
React.useEffect(() => {
|
|
85
|
+
if (tableMeta.rowActive.rowActiveIndex === previousCount - 1 && !wasLastRowLoaded) {
|
|
86
|
+
tableMeta.rowActive.setRowActiveIndex(count - 1);
|
|
87
|
+
scrollToIndex(count - 1);
|
|
88
|
+
}
|
|
89
|
+
}, [count]);
|
|
80
90
|
const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;
|
|
81
91
|
const startValue = isTableRowGrouped ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0) : virtualItems[paddingStartIndex]?.start;
|
|
82
92
|
const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))] : [0, 0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTableRenderer.cjs","sources":["../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import type { Table as ReactTable, Row as ReactTableRow } from '@tanstack/react-table';\nimport type { ScrollToOptions as ReactVirtualScrollToOptions, Range } from '@tanstack/react-virtual';\nimport { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';\nimport sortBy from 'lodash/sortBy';\nimport without from 'lodash/without';\nimport type { CSSProperties } from 'react';\nimport React from 'react';\n\nimport type { TableRef } from '../../types';\nimport { getTableMeta } from '../../useTableManager/util/rows';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\nimport { Row } from '../components/Row/Row';\nimport type { useTableRenderers } from '../types';\nimport { ROW_HEIGHT_ESTIMATES, getGroupedServerRowLayout } from '../util/rows';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = getTableMeta(table);\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = getTableMeta(table);\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // v2 + grouping needs group headers interleaved into the virtualised rows (see getGroupedServerRowLayout)\n const isServerDataLoader2 = tableMeta.server.isEnabled && !!tableMeta.server._experimentalDataLoader2;\n const dataLoader2GroupLayout =\n isServerDataLoader2 && isTableRowGrouped\n ? getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, length)\n : undefined;\n\n // row groups - offset sticky headers into the v2 window's index space\n const rangeExtractor = useRowGroupVirtualisation<TType>(table, dataLoader2GroupLayout?.windowStartLeaf ?? 0);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n const count = isServerDataLoader2 ? (dataLoader2GroupLayout?.count ?? length) : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table),\n });\n\n const expandedState = table.getState().expanded;\n const previousExpandedStateRef = React.useRef(false);\n\n React.useEffect(() => {\n // only remeasure when transitioning between expand all and not expand all\n const isEmpty = JSON.stringify(expandedState) === '{}';\n\n if (expandedState === true || (isEmpty && previousExpandedStateRef.current === true)) {\n previousExpandedStateRef.current = expandedState === true;\n virtualiser.measure();\n }\n }, [expandedState]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0)\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (React.JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: Number.isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: Number.isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (dataLoader2GroupLayout) {\n // v2 + grouping: each slot is a loaded row (header/leaf) or a skeleton for an unloaded page\n const resolved = dataLoader2GroupLayout.resolve(virtualRow.index);\n\n if (resolved.type === 'skeleton') {\n return (\n <SkeletonRow\n key={`skeleton-${virtualRow.index}`}\n index={virtualRow.index}\n pageIndex={resolved.pageIndex}\n table={table}\n />\n );\n }\n\n row = resolved.row;\n } else if (isServerDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n // no `original` = an unloaded leaf (or, in v1's sparse array, a header for an unloaded group) - skeleton it\n if (!row?.original) {\n // Prefix skeleton keys to prevent collision with real data row keys\n const skeletonKey = `skeleton-${virtualRow.index}`;\n return <SkeletonRow key={skeletonKey} index={virtualRow.index} table={table} />;\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow.index, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\n// indexOffset shifts the header indexes into the paginated window's virtual index space (0 unless v2 + grouping)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>, indexOffset = 0) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index + indexOffset);\n }\n });\n }\n\n return indexes;\n }, [rows, indexOffset]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n rowGroupIndexes.toReversed().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n return activeRowGroupIndex === undefined\n ? defaultRangeExtractor(range)\n : sortBy([activeRowGroupIndex, ...without(defaultRangeExtractor(range), activeRowGroupIndex)], a => a);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["getTableMeta","ROW_HEIGHT_ESTIMATES","rows","getGroupedServerRowLayout","useVirtualizer","SkeletonRow","Row","defaultRangeExtractor"],"mappings":";;;;;;;;;;AAgBA,SAAS,0BAA2C,OAA0B;AAC1E,QAAM,YAAYA,KAAAA,aAAa,KAAK;AACpC,MAAI,SAAS;AAEb,MAAI,UAAU,OAAO,WAAW;AAC5B,cAAU;AAAA,EACd;AAEA,MAAI,MAAM,kBAAkB,SAAS,GAAG;AACpC,cAAU,MAAM,gBAAA,EAAkB,SAAS;AAAA,EAC/C;AAEA,MAAI,SAASC,4BAAqB,SAAS;AAE3C,QAAM,aAAa,MAAM,cAAA;AAEzB,MAAI,WAAW,QAAQ;AAEnB,cAAUA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;AAAAA,QAAA;AAAA,UACG,KAAK,IAAI;AAAA,UACT;AAAA,UACA,OAAO,WAAW;AAAA,UAClB;AAAA,UACA;AAAA,UACA,UAAU,UAAU;AAAA,UACpB,cAAc,UAAU;AAAA,QAAA;AAAA,MAAA;AAAA,IAGpC,CAAC;AAAA,EACL;AAEA,SAAO;AAAA,IACH,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EAAA;AAER;AAIA,SAAS,0BAA2C,OAA0B,cAAc,GAAG;AAC3F,QAAMJ,QAAO,MAAM,YAAA,EAAc;AACjC,QAAM,iBAAiB,CAAC,CAAC,MAAM,SAAA,EAAW,SAAS;AAEnD,QAAM,kBAAkB,MAAM,QAAQ,MAAM;AACxC,UAAM,UAAoB,CAAA;AAE1B,QAAI,gBAAgB;AAChB,MAAAA,MAAK,QAAQ,CAAC,KAAK,UAAU;AACzB,YAAI,IAAI,gBAAgB;AACpB,kBAAQ,KAAK,QAAQ,WAAW;AAAA,QACpC;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACX,GAAG,CAACA,OAAM,WAAW,CAAC;AAGtB,QAAM,iBAAiB,MAAM;AAAA,IACzB,CAAC,UAAiB;AACd,YAAM,sBACF,gBAAgB,WAAA,EAAa,KAAK,CAAA,UAAS,MAAM,cAAc,KAAK,KAAK,gBAAgB,CAAC;AAE9F,aAAO,wBAAwB,SACzBK,aAAAA,sBAAsB,KAAK,IAC3B,OAAO,CAAC,qBAAqB,GAAG,QAAQA,aAAAA,sBAAsB,KAAK,GAAG,mBAAmB,CAAC,GAAG,OAAK,CAAC;AAAA,IAC7G;AAAA,IACA,CAAC,eAAe;AAAA,EAAA;AAGpB,SAAO,iBAAiB,iBAAiB;AAC7C;;"}
|
|
1
|
+
{"version":3,"file":"useTableRenderer.cjs","sources":["../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import type { Table as ReactTable, Row as ReactTableRow } from '@tanstack/react-table';\nimport type { ScrollToOptions as ReactVirtualScrollToOptions, Range } from '@tanstack/react-virtual';\nimport { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';\nimport sortBy from 'lodash/sortBy';\nimport without from 'lodash/without';\nimport type { CSSProperties } from 'react';\nimport React from 'react';\n\nimport { usePreviousValue } from '@/hooks/usePrevious';\n\nimport type { TableRef } from '../../types';\nimport { getTableMeta } from '../../useTableManager/util/rows';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\nimport { Row } from '../components/Row/Row';\nimport type { useTableRenderers } from '../types';\nimport { ROW_HEIGHT_ESTIMATES, getGroupedServerRowLayout } from '../util/rows';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = getTableMeta(table);\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = getTableMeta(table);\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // v2 + grouping needs group headers interleaved into the virtualised rows (see getGroupedServerRowLayout)\n const isServerDataLoader2 = tableMeta.server.isEnabled && !!tableMeta.server._experimentalDataLoader2;\n const dataLoader2GroupLayout =\n isServerDataLoader2 && isTableRowGrouped\n ? getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, length)\n : undefined;\n\n // row groups - offset sticky headers into the v2 window's index space\n const rangeExtractor = useRowGroupVirtualisation<TType>(table, dataLoader2GroupLayout?.windowStartLeaf ?? 0);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n // keep in sync with getReachableRowCount\n const count = isServerDataLoader2 ? (dataLoader2GroupLayout?.count ?? length) : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table),\n });\n\n const expandedState = table.getState().expanded;\n const previousExpandedStateRef = React.useRef(false);\n\n React.useEffect(() => {\n // only remeasure when transitioning between expand all and not expand all\n const isEmpty = JSON.stringify(expandedState) === '{}';\n\n if (expandedState === true || (isEmpty && previousExpandedStateRef.current === true)) {\n previousExpandedStateRef.current = expandedState === true;\n virtualiser.measure();\n }\n }, [expandedState]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // v2 only holds the loaded window, so ask its pages; v1 and client row models hold the row itself\n const isLastRowLoaded = isServerDataLoader2\n ? !!tableMeta.server.pages?.includes(tableMeta.server.pageCount - 1)\n : !!rows.at(-1)?.original;\n const previousCount = usePreviousValue(count);\n const wasLastRowLoaded = usePreviousValue(isLastRowLoaded);\n\n // ctrl/cmd+down can target the last row before its page has loaded; in grouped server tables that page then adds\n // header slots, which moves the last row, so move the jump with it\n React.useEffect(() => {\n if (tableMeta.rowActive.rowActiveIndex === previousCount - 1 && !wasLastRowLoaded) {\n tableMeta.rowActive.setRowActiveIndex(count - 1);\n scrollToIndex(count - 1);\n }\n }, [count]);\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0)\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (React.JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: Number.isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: Number.isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (dataLoader2GroupLayout) {\n // v2 + grouping: each slot is a loaded row (header/leaf) or a skeleton for an unloaded page\n const resolved = dataLoader2GroupLayout.resolve(virtualRow.index);\n\n if (resolved.type === 'skeleton') {\n return (\n <SkeletonRow\n key={`skeleton-${virtualRow.index}`}\n index={virtualRow.index}\n pageIndex={resolved.pageIndex}\n table={table}\n />\n );\n }\n\n row = resolved.row;\n } else if (isServerDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n // no `original` = an unloaded leaf (or, in v1's sparse array, a header for an unloaded group) - skeleton it\n if (!row?.original) {\n // Prefix skeleton keys to prevent collision with real data row keys\n const skeletonKey = `skeleton-${virtualRow.index}`;\n return <SkeletonRow key={skeletonKey} index={virtualRow.index} table={table} />;\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow.index, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\n// indexOffset shifts the header indexes into the paginated window's virtual index space (0 unless v2 + grouping)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>, indexOffset = 0) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index + indexOffset);\n }\n });\n }\n\n return indexes;\n }, [rows, indexOffset]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n rowGroupIndexes.toReversed().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n return activeRowGroupIndex === undefined\n ? defaultRangeExtractor(range)\n : sortBy([activeRowGroupIndex, ...without(defaultRangeExtractor(range), activeRowGroupIndex)], a => a);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["getTableMeta","ROW_HEIGHT_ESTIMATES","rows","getGroupedServerRowLayout","useVirtualizer","usePreviousValue","SkeletonRow","Row","defaultRangeExtractor"],"mappings":";;;;;;;;;;;AAkBA,SAAS,0BAA2C,OAA0B;AAC1E,QAAM,YAAYA,KAAAA,aAAa,KAAK;AACpC,MAAI,SAAS;AAEb,MAAI,UAAU,OAAO,WAAW;AAC5B,cAAU;AAAA,EACd;AAEA,MAAI,MAAM,kBAAkB,SAAS,GAAG;AACpC,cAAU,MAAM,gBAAA,EAAkB,SAAS;AAAA,EAC/C;AAEA,MAAI,SAASC,4BAAqB,SAAS;AAE3C,QAAM,aAAa,MAAM,cAAA;AAEzB,MAAI,WAAW,QAAQ;AAEnB,cAAUA,OAAAA,qBAAqB,UAAU,UAAU,MAAM,IAAI,MAAM,WAAW;AAAA,EAClF;AAEA,SAAO;AACX;AAGA,SAAS,oBAAqC,OAA0B;AACpE,QAA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,sBAAsB,KAAK,GAAG,mBAAmB,CAAC,GAAG,OAAK,CAAC;AAAA,IAC7G;AAAA,IACA,CAAC,eAAe;AAAA,EAAA;AAGpB,SAAO,iBAAiB,iBAAiB;AAC7C;;"}
|
|
@@ -2,6 +2,7 @@ import { useVirtualizer, defaultRangeExtractor } from "@tanstack/react-virtual";
|
|
|
2
2
|
import sortBy from "lodash/sortBy";
|
|
3
3
|
import without from "lodash/without";
|
|
4
4
|
import React__default from "react";
|
|
5
|
+
import { usePreviousValue } from "../../../../hooks/usePrevious.js";
|
|
5
6
|
import { getTableMeta } from "../../useTableManager/util/rows.js";
|
|
6
7
|
import { SkeletonRow } from "../components/Row/BuiltIns/SkeletonRow.js";
|
|
7
8
|
import { Row } from "../components/Row/Row.js";
|
|
@@ -75,6 +76,15 @@ function useTableRenderer(renderers, table, tableRef, length, defaultRowActiveIn
|
|
|
75
76
|
},
|
|
76
77
|
[virtualItems.length, tableRef.current, totalSize, count]
|
|
77
78
|
);
|
|
79
|
+
const isLastRowLoaded = isServerDataLoader2 ? !!tableMeta.server.pages?.includes(tableMeta.server.pageCount - 1) : !!rows.at(-1)?.original;
|
|
80
|
+
const previousCount = usePreviousValue(count);
|
|
81
|
+
const wasLastRowLoaded = usePreviousValue(isLastRowLoaded);
|
|
82
|
+
React__default.useEffect(() => {
|
|
83
|
+
if (tableMeta.rowActive.rowActiveIndex === previousCount - 1 && !wasLastRowLoaded) {
|
|
84
|
+
tableMeta.rowActive.setRowActiveIndex(count - 1);
|
|
85
|
+
scrollToIndex(count - 1);
|
|
86
|
+
}
|
|
87
|
+
}, [count]);
|
|
78
88
|
const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;
|
|
79
89
|
const startValue = isTableRowGrouped ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0) : virtualItems[paddingStartIndex]?.start;
|
|
80
90
|
const [paddingTop, paddingBottom] = virtualItems.length > 0 ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))] : [0, 0];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTableRenderer.js","sources":["../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import type { Table as ReactTable, Row as ReactTableRow } from '@tanstack/react-table';\nimport type { ScrollToOptions as ReactVirtualScrollToOptions, Range } from '@tanstack/react-virtual';\nimport { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';\nimport sortBy from 'lodash/sortBy';\nimport without from 'lodash/without';\nimport type { CSSProperties } from 'react';\nimport React from 'react';\n\nimport type { TableRef } from '../../types';\nimport { getTableMeta } from '../../useTableManager/util/rows';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\nimport { Row } from '../components/Row/Row';\nimport type { useTableRenderers } from '../types';\nimport { ROW_HEIGHT_ESTIMATES, getGroupedServerRowLayout } from '../util/rows';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = getTableMeta(table);\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = getTableMeta(table);\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // v2 + grouping needs group headers interleaved into the virtualised rows (see getGroupedServerRowLayout)\n const isServerDataLoader2 = tableMeta.server.isEnabled && !!tableMeta.server._experimentalDataLoader2;\n const dataLoader2GroupLayout =\n isServerDataLoader2 && isTableRowGrouped\n ? getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, length)\n : undefined;\n\n // row groups - offset sticky headers into the v2 window's index space\n const rangeExtractor = useRowGroupVirtualisation<TType>(table, dataLoader2GroupLayout?.windowStartLeaf ?? 0);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n const count = isServerDataLoader2 ? (dataLoader2GroupLayout?.count ?? length) : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table),\n });\n\n const expandedState = table.getState().expanded;\n const previousExpandedStateRef = React.useRef(false);\n\n React.useEffect(() => {\n // only remeasure when transitioning between expand all and not expand all\n const isEmpty = JSON.stringify(expandedState) === '{}';\n\n if (expandedState === true || (isEmpty && previousExpandedStateRef.current === true)) {\n previousExpandedStateRef.current = expandedState === true;\n virtualiser.measure();\n }\n }, [expandedState]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0)\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (React.JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: Number.isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: Number.isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (dataLoader2GroupLayout) {\n // v2 + grouping: each slot is a loaded row (header/leaf) or a skeleton for an unloaded page\n const resolved = dataLoader2GroupLayout.resolve(virtualRow.index);\n\n if (resolved.type === 'skeleton') {\n return (\n <SkeletonRow\n key={`skeleton-${virtualRow.index}`}\n index={virtualRow.index}\n pageIndex={resolved.pageIndex}\n table={table}\n />\n );\n }\n\n row = resolved.row;\n } else if (isServerDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n // no `original` = an unloaded leaf (or, in v1's sparse array, a header for an unloaded group) - skeleton it\n if (!row?.original) {\n // Prefix skeleton keys to prevent collision with real data row keys\n const skeletonKey = `skeleton-${virtualRow.index}`;\n return <SkeletonRow key={skeletonKey} index={virtualRow.index} table={table} />;\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow.index, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\n// indexOffset shifts the header indexes into the paginated window's virtual index space (0 unless v2 + grouping)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>, indexOffset = 0) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index + indexOffset);\n }\n });\n }\n\n return indexes;\n }, [rows, indexOffset]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n rowGroupIndexes.toReversed().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n return activeRowGroupIndex === undefined\n ? defaultRangeExtractor(range)\n : sortBy([activeRowGroupIndex, ...without(defaultRangeExtractor(range), activeRowGroupIndex)], a => a);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["React"],"mappings":";;;;;;;;AAgBA,SAAS,0BAA2C,OAA0B;AAC1E,QAAM,YAAY,aAAa,KAAK;AACpC,MAAI,SAAS;AAEb,MAAI,UAAU,OAAO,WAAW;AAC5B,cAAU;AAAA,EACd;AAEA,MAAI,MAAM,kBAAkB,SAAS,GAAG;AACpC,cAAU,MAAM,gBAAA,EAAkB,SAAS;AAAA,EAC/C;AAEA,MAAI,SAAS,qBAAqB,SAAS;AAE3C,QAAM,aAAa,MAAM,cAAA;AAEzB,MAAI,WAAW,QAAQ;AAEnB,cAAU,qBAAqB,UAAU,UAAU,MAAM,IAAI,MAAM,WAAW;AAAA,EAClF;AAEA,SAAO;AACX;AAGA,SAAS,oBAAqC,OAA0B;AACpE,QAAM,aAAa,MAAM,cAAA,KAAmB,CAAA;AAC5C,SAAO,qBAAqB,SAAS,IAAI,WAAW;AACxD;AAGA,MAAM,qBAAqB;AAEpB,SAAS,iBACZ,WACA,OACA,UACA,QACA,uBACF;AACE,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,oBAAoB,CAAC,CAAC,MAAM,SAAA,EAAW,UAAU;AACvD,QAAM,OAAO,MAAM,cAAA,KAAmB,CAAA;AAGtC,QAAM,sBAAsB,UAAU,OAAO,aAAa,CAAC,CAAC,UAAU,OAAO;AAC7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I,IAAI,gBAAgB;AACpB,kBAAQ,KAAK,QAAQ,WAAW;AAAA,QACpC;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACX,GAAG,CAAC,MAAM,WAAW,CAAC;AAGtB,QAAM,iBAAiBA,eAAM;AAAA,IACzB,CAAC,UAAiB;AACd,YAAM,sBACF,gBAAgB,WAAA,EAAa,KAAK,CAAA,UAAS,MAAM,cAAc,KAAK,KAAK,gBAAgB,CAAC;AAE9F,aAAO,wBAAwB,SACzB,sBAAsB,KAAK,IAC3B,OAAO,CAAC,qBAAqB,GAAG,QAAQ,sBAAsB,KAAK,GAAG,mBAAmB,CAAC,GAAG,OAAK,CAAC;AAAA,IAC7G;AAAA,IACA,CAAC,eAAe;AAAA,EAAA;AAGpB,SAAO,iBAAiB,iBAAiB;AAC7C;"}
|
|
1
|
+
{"version":3,"file":"useTableRenderer.js","sources":["../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import type { Table as ReactTable, Row as ReactTableRow } from '@tanstack/react-table';\nimport type { ScrollToOptions as ReactVirtualScrollToOptions, Range } from '@tanstack/react-virtual';\nimport { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';\nimport sortBy from 'lodash/sortBy';\nimport without from 'lodash/without';\nimport type { CSSProperties } from 'react';\nimport React from 'react';\n\nimport { usePreviousValue } from '@/hooks/usePrevious';\n\nimport type { TableRef } from '../../types';\nimport { getTableMeta } from '../../useTableManager/util/rows';\nimport { SkeletonRow } from '../components/Row/BuiltIns/SkeletonRow';\nimport { Row } from '../components/Row/Row';\nimport type { useTableRenderers } from '../types';\nimport { ROW_HEIGHT_ESTIMATES, getGroupedServerRowLayout } from '../util/rows';\n\n// scroll padding end is designed to always show half of the next row\nfunction getScrollPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = getTableMeta(table);\n let offset = 2;\n\n if (tableMeta.footer.isEnabled) {\n offset += 1;\n }\n\n if (table.getHeaderGroups().length > 1) {\n offset += table.getHeaderGroups().length - 1;\n }\n\n let height = ROW_HEIGHT_ESTIMATES.medium * offset;\n\n const bottomRows = table.getBottomRows();\n\n if (bottomRows.length) {\n // 1.4 offsets for half rows and also accounts for increased row heights (which is likely in pinned rows)\n height += ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] * 1.4 * bottomRows.length;\n }\n\n return height;\n}\n\n// scroll padding end is designed to always show half of the next row\nfunction getPaddingEndOffset<TType = unknown>(table: ReactTable<TType>) {\n const bottomRows = table.getBottomRows() ?? [];\n return ROW_HEIGHT_ESTIMATES.medium * 1 * bottomRows.length;\n}\n\n// A higher number ensure less scroll jumping for dynamic row heights, but too high can reduce performance. 8 worked well\nconst OVERSCAN_ROW_COUNT = 8;\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n length: number,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = getTableMeta(table);\n const isTableRowGrouped = !!table.getState().grouping?.length;\n const rows = table.getCenterRows() ?? [];\n\n // v2 + grouping needs group headers interleaved into the virtualised rows (see getGroupedServerRowLayout)\n const isServerDataLoader2 = tableMeta.server.isEnabled && !!tableMeta.server._experimentalDataLoader2;\n const dataLoader2GroupLayout =\n isServerDataLoader2 && isTableRowGrouped\n ? getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, length)\n : undefined;\n\n // row groups - offset sticky headers into the v2 window's index space\n const rangeExtractor = useRowGroupVirtualisation<TType>(table, dataLoader2GroupLayout?.windowStartLeaf ?? 0);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n\n // keep in sync with getReachableRowCount\n const count = isServerDataLoader2 ? (dataLoader2GroupLayout?.count ?? length) : rows.length;\n\n const virtualiser = useVirtualizer({\n count,\n estimateSize: () => {\n return tableMeta.rowHeight.height ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height] : ROW_HEIGHT_ESTIMATES.medium;\n },\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? count : OVERSCAN_ROW_COUNT,\n rangeExtractor,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: getScrollPaddingEndOffset(table),\n paddingEnd: getPaddingEndOffset(table),\n });\n\n const expandedState = table.getState().expanded;\n const previousExpandedStateRef = React.useRef(false);\n\n React.useEffect(() => {\n // only remeasure when transitioning between expand all and not expand all\n const isEmpty = JSON.stringify(expandedState) === '{}';\n\n if (expandedState === true || (isEmpty && previousExpandedStateRef.current === true)) {\n previousExpandedStateRef.current = expandedState === true;\n virtualiser.measure();\n }\n }, [expandedState]);\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === count - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, count]\n );\n\n // v2 only holds the loaded window, so ask its pages; v1 and client row models hold the row itself\n const isLastRowLoaded = isServerDataLoader2\n ? !!tableMeta.server.pages?.includes(tableMeta.server.pageCount - 1)\n : !!rows.at(-1)?.original;\n const previousCount = usePreviousValue(count);\n const wasLastRowLoaded = usePreviousValue(isLastRowLoaded);\n\n // ctrl/cmd+down can target the last row before its page has loaded; in grouped server tables that page then adds\n // header slots, which moves the last row, so move the jump with it\n React.useEffect(() => {\n if (tableMeta.rowActive.rowActiveIndex === previousCount - 1 && !wasLastRowLoaded) {\n tableMeta.rowActive.setRowActiveIndex(count - 1);\n scrollToIndex(count - 1);\n }\n }, [count]);\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && count > 1 ? 1 : 0;\n\n const startValue = isTableRowGrouped\n ? (virtualItems[paddingStartIndex]?.start ?? 0) - (virtualItems[paddingStartIndex]?.size ?? 0)\n : virtualItems[paddingStartIndex]?.start;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [Math.max(0, startValue ?? 0), Math.max(0, totalSize - (virtualItems.at(-1)?.end ?? 0))]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (React.JSX.Element | null)[] | null = null;\n\n // bottom rows aren't virtualised (they're sticky) but we need to set the height\n if (count || table.getBottomRows().length) {\n style = {\n height: totalSize,\n paddingBottom: Number.isNaN(paddingBottom) ? 0 : paddingBottom,\n paddingTop: Number.isNaN(paddingTop) ? 0 : paddingTop,\n };\n }\n\n // only render non sticky rows\n if (count) {\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n let row: ReactTableRow<TType> | undefined;\n\n if (dataLoader2GroupLayout) {\n // v2 + grouping: each slot is a loaded row (header/leaf) or a skeleton for an unloaded page\n const resolved = dataLoader2GroupLayout.resolve(virtualRow.index);\n\n if (resolved.type === 'skeleton') {\n return (\n <SkeletonRow\n key={`skeleton-${virtualRow.index}`}\n index={virtualRow.index}\n pageIndex={resolved.pageIndex}\n table={table}\n />\n );\n }\n\n row = resolved.row;\n } else if (isServerDataLoader2) {\n const currentPageIndex =\n (Math.floor(virtualRow.index / tableMeta.server.pageSize) * tableMeta.server.pageSize) /\n tableMeta.server.pageSize;\n const pagePosition = tableMeta.server.pages?.indexOf(currentPageIndex) ?? -1;\n\n if (pagePosition > -1) {\n // \"flatten\" row indexes down into the dataloader2 dataset size\n // for example, with a page size of 100...\n // row index 14267 is actually one of index 67, 167, 267 etc within the dataset (depending on number of pages stored)\n const fakeIndex = pagePosition * tableMeta.server.pageSize + (virtualRow.index % tableMeta.server.pageSize);\n row = rows[fakeIndex];\n }\n } else {\n row = rows[virtualRow.index];\n }\n\n // no `original` = an unloaded leaf (or, in v1's sparse array, a header for an unloaded group) - skeleton it\n if (!row?.original) {\n // Prefix skeleton keys to prevent collision with real data row keys\n const skeletonKey = `skeleton-${virtualRow.index}`;\n return <SkeletonRow key={skeletonKey} index={virtualRow.index} table={table} />;\n }\n\n const measureRow = (rowHeight: number) => {\n virtualiser.resizeItem(virtualRow.index, rowHeight);\n };\n\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\n// indexOffset shifts the header indexes into the paginated window's virtual index space (0 unless v2 + grouping)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>, indexOffset = 0) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index + indexOffset);\n }\n });\n }\n\n return indexes;\n }, [rows, indexOffset]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n (range: Range) => {\n const activeRowGroupIndex =\n rowGroupIndexes.toReversed().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n return activeRowGroupIndex === undefined\n ? defaultRangeExtractor(range)\n : sortBy([activeRowGroupIndex, ...without(defaultRangeExtractor(range), activeRowGroupIndex)], a => a);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["React"],"mappings":";;;;;;;;;AAkBA,SAAS,0BAA2C,OAA0B;AAC1E,QAAM,YAAY,aAAa,KAAK;AACpC,MAAI,SAAS;AAEb,MAAI,UAAU,OAAO,WAAW;AAC5B,cAAU;AAAA,EACd;AAEA,MAAI,MAAM,kBAAkB,SAAS,GAAG;AACpC,cAAU,MAAM,gBAAA,EAAkB,SAAS;AAAA,EAC/C;AAEA,MAAI,SAAS,qBAAqB,SAAS;AAE3C,QAAM,aAAa,MAAM,cAAA;AAEzB,MAAI,WAAW,QAAQ;AAEnB,cAAU,qBAAqB,UAAU,UAAU,MAAM,IAAI,MAAM,WAAW;AAAA,EAClF;AAEA,SAAO;AACX;AAGA,SAAS,oBAAqC,OAA0B;AACpE,QAAM,aAAa,MAAM,cAAA,KAAmB,CAAA;AAC5C,SAAO,qBAAqB,SAAS,IAAI,WAAW;AACxD;AAGA,MAAM,qBAAqB;AAEpB,SAAS,iBACZ,WACA,OACA,UACA,QACA,uBACF;AACE,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,oBAAoB,CAAC,CAAC,MAAM,SAAA,EAAW,UAAU;AACvD,QAAM,OAAO,MAAM,cAAA,KAAmB,CAAA;AAGtC,QAAM,sBAAsB,UAAU,OAAO,aAAa,CAAC,CAAC,UAAU,OAAO;AAC7E,QAAM,yBACF,uBAAuB,oBACjB,0BAAiC,MAAM,UAAU,OAAO,SAAS,CAAA,GAAI,UAAU,OAAO,UAAU,MAAM,IACtG;AAGV,QAAM,iBAAiB,0BAAiC,OAAO,wBAAwB,mBAAmB,CAAC;AAG3G,QAAM,qBAAqB,qBAAqB;AAGhD,QAAM,QAAQ,sBAAuB,wBAAwB,SAAS,SAAU,KAAK;AAErF,QAAM,cAAc,eAAe;AAAA,IAC/B;AAAA,IACA,cAAc,MAAM;AAChB,aAAO,UAAU,UA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AAoB,CAAA;AAE1B,QAAI,gBAAgB;AAChB,WAAK,QAAQ,CAAC,KAAK,UAAU;AACzB,YAAI,IAAI,gBAAgB;AACpB,kBAAQ,KAAK,QAAQ,WAAW;AAAA,QACpC;AAAA,MACJ,CAAC;AAAA,IACL;AAEA,WAAO;AAAA,EACX,GAAG,CAAC,MAAM,WAAW,CAAC;AAGtB,QAAM,iBAAiBA,eAAM;AAAA,IACzB,CAAC,UAAiB;AACd,YAAM,sBACF,gBAAgB,WAAA,EAAa,KAAK,CAAA,UAAS,MAAM,cAAc,KAAK,KAAK,gBAAgB,CAAC;AAE9F,aAAO,wBAAwB,SACzB,sBAAsB,KAAK,IAC3B,OAAO,CAAC,qBAAqB,GAAG,QAAQ,sBAAsB,KAAK,GAAG,mBAAmB,CAAC,GAAG,OAAK,CAAC;AAAA,IAC7G;AAAA,IACA,CAAC,eAAe;AAAA,EAAA;AAGpB,SAAO,iBAAiB,iBAAiB;AAC7C;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const rows = require("../../Core/util/rows.cjs");
|
|
3
4
|
function getTableMeta(table) {
|
|
4
5
|
if (!table.options.meta) {
|
|
5
6
|
throw new Error("Table requires table meta");
|
|
@@ -8,8 +9,15 @@ function getTableMeta(table) {
|
|
|
8
9
|
}
|
|
9
10
|
function getReachableRowCount(table) {
|
|
10
11
|
const tableMeta = getTableMeta(table);
|
|
11
|
-
const
|
|
12
|
-
|
|
12
|
+
const rows$1 = table.getCenterRows() ?? [];
|
|
13
|
+
const bottomRowCount = table.getBottomRows().length;
|
|
14
|
+
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
|
|
15
|
+
if (table.getState().grouping?.length) {
|
|
16
|
+
return rows.getGroupedServerRowLayout(rows$1, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length).count + bottomRowCount;
|
|
17
|
+
}
|
|
18
|
+
return tableMeta.length + bottomRowCount;
|
|
19
|
+
}
|
|
20
|
+
return rows$1.length + bottomRowCount;
|
|
13
21
|
}
|
|
14
22
|
exports.getReachableRowCount = getReachableRowCount;
|
|
15
23
|
exports.getTableMeta = getTableMeta;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.cjs","sources":["../../../../../src/primitives/Table/useTableManager/util/rows.ts"],"sourcesContent":["import type { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\n\n// meta is always provided by useTableManager, so a missing one is an invariant violation, not a real state\nexport function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType> {\n if (!table.options.meta) {\n throw new Error('Table requires table meta');\n }\n\n return table.options.meta;\n}\n\n
|
|
1
|
+
{"version":3,"file":"rows.cjs","sources":["../../../../../src/primitives/Table/useTableManager/util/rows.ts"],"sourcesContent":["import type { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\n\nimport { getGroupedServerRowLayout } from '../../Core/util/rows';\n\n// meta is always provided by useTableManager, so a missing one is an invariant violation, not a real state\nexport function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType> {\n if (!table.options.meta) {\n throw new Error('Table requires table meta');\n }\n\n return table.options.meta;\n}\n\n/** rowActiveIndex indexes virtual slots, so this must match the virtualiser count in useTableRenderer (plus bottom rows) */\nexport function getReachableRowCount<TType = unknown>(table: ReactTable<TType>): number {\n const tableMeta = getTableMeta(table);\n const rows = table.getCenterRows() ?? [];\n const bottomRowCount = table.getBottomRows().length;\n\n // dataloader2 row models only hold the loaded window\n if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {\n if (table.getState().grouping?.length) {\n return (\n getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length)\n .count + bottomRowCount\n );\n }\n\n return tableMeta.length + bottomRowCount;\n }\n\n return rows.length + bottomRowCount;\n}\n"],"names":["rows","getGroupedServerRowLayout"],"mappings":";;;AAKO,SAAS,aAA8B,OAAiD;AAC3F,MAAI,CAAC,MAAM,QAAQ,MAAM;AACrB,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC/C;AAEA,SAAO,MAAM,QAAQ;AACzB;AAGO,SAAS,qBAAsC,OAAkC;AACpF,QAAM,YAAY,aAAa,KAAK;AACpC,QAAMA,SAAO,MAAM,cAAA,KAAmB,CAAA;AACtC,QAAM,iBAAiB,MAAM,cAAA,EAAgB;AAG7C,MAAI,UAAU,OAAO,aAAa,UAAU,OAAO,0BAA0B;AACzE,QAAI,MAAM,WAAW,UAAU,QAAQ;AACnC,aACIC,KAAAA,0BAAiCD,QAAM,UAAU,OAAO,SAAS,CAAA,GAAI,UAAU,OAAO,UAAU,UAAU,MAAM,EAC3G,QAAQ;AAAA,IAErB;AAEA,WAAO,UAAU,SAAS;AAAA,EAC9B;AAEA,SAAOA,OAAK,SAAS;AACzB;;;"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';
|
|
2
2
|
export declare function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType>;
|
|
3
|
-
/**
|
|
4
|
-
* Returns the number of reachable rows. Uses filtered count when search filtering is active,
|
|
5
|
-
* otherwise uses total dataset length to support virtualization. Includes bottom rows.
|
|
6
|
-
*/
|
|
3
|
+
/** rowActiveIndex indexes virtual slots, so this must match the virtualiser count in useTableRenderer (plus bottom rows) */
|
|
7
4
|
export declare function getReachableRowCount<TType = unknown>(table: ReactTable<TType>): number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getGroupedServerRowLayout } from "../../Core/util/rows.js";
|
|
1
2
|
function getTableMeta(table) {
|
|
2
3
|
if (!table.options.meta) {
|
|
3
4
|
throw new Error("Table requires table meta");
|
|
@@ -6,8 +7,15 @@ function getTableMeta(table) {
|
|
|
6
7
|
}
|
|
7
8
|
function getReachableRowCount(table) {
|
|
8
9
|
const tableMeta = getTableMeta(table);
|
|
9
|
-
const
|
|
10
|
-
|
|
10
|
+
const rows = table.getCenterRows() ?? [];
|
|
11
|
+
const bottomRowCount = table.getBottomRows().length;
|
|
12
|
+
if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {
|
|
13
|
+
if (table.getState().grouping?.length) {
|
|
14
|
+
return getGroupedServerRowLayout(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length).count + bottomRowCount;
|
|
15
|
+
}
|
|
16
|
+
return tableMeta.length + bottomRowCount;
|
|
17
|
+
}
|
|
18
|
+
return rows.length + bottomRowCount;
|
|
11
19
|
}
|
|
12
20
|
export {
|
|
13
21
|
getReachableRowCount,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rows.js","sources":["../../../../../src/primitives/Table/useTableManager/util/rows.ts"],"sourcesContent":["import type { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\n\n// meta is always provided by useTableManager, so a missing one is an invariant violation, not a real state\nexport function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType> {\n if (!table.options.meta) {\n throw new Error('Table requires table meta');\n }\n\n return table.options.meta;\n}\n\n
|
|
1
|
+
{"version":3,"file":"rows.js","sources":["../../../../../src/primitives/Table/useTableManager/util/rows.ts"],"sourcesContent":["import type { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\n\nimport { getGroupedServerRowLayout } from '../../Core/util/rows';\n\n// meta is always provided by useTableManager, so a missing one is an invariant violation, not a real state\nexport function getTableMeta<TType = unknown>(table: ReactTable<TType>): ReactTableMeta<TType> {\n if (!table.options.meta) {\n throw new Error('Table requires table meta');\n }\n\n return table.options.meta;\n}\n\n/** rowActiveIndex indexes virtual slots, so this must match the virtualiser count in useTableRenderer (plus bottom rows) */\nexport function getReachableRowCount<TType = unknown>(table: ReactTable<TType>): number {\n const tableMeta = getTableMeta(table);\n const rows = table.getCenterRows() ?? [];\n const bottomRowCount = table.getBottomRows().length;\n\n // dataloader2 row models only hold the loaded window\n if (tableMeta.server.isEnabled && tableMeta.server._experimentalDataLoader2) {\n if (table.getState().grouping?.length) {\n return (\n getGroupedServerRowLayout<TType>(rows, tableMeta.server.pages ?? [], tableMeta.server.pageSize, tableMeta.length)\n .count + bottomRowCount\n );\n }\n\n return tableMeta.length + bottomRowCount;\n }\n\n return rows.length + bottomRowCount;\n}\n"],"names":[],"mappings":";AAKO,SAAS,aAA8B,OAAiD;AAC3F,MAAI,CAAC,MAAM,QAAQ,MAAM;AACrB,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC/C;AAEA,SAAO,MAAM,QAAQ;AACzB;AAGO,SAAS,qBAAsC,OAAkC;AACpF,QAAM,YAAY,aAAa,KAAK;AACpC,QAAM,OAAO,MAAM,cAAA,KAAmB,CAAA;AACtC,QAAM,iBAAiB,MAAM,cAAA,EAAgB;AAG7C,MAAI,UAAU,OAAO,aAAa,UAAU,OAAO,0BAA0B;AACzE,QAAI,MAAM,WAAW,UAAU,QAAQ;AACnC,aACI,0BAAiC,MAAM,UAAU,OAAO,SAAS,CAAA,GAAI,UAAU,OAAO,UAAU,UAAU,MAAM,EAC3G,QAAQ;AAAA,IAErB;AAEA,WAAO,UAAU,SAAS;AAAA,EAC9B;AAEA,SAAO,KAAK,SAAS;AACzB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@economic/taco",
|
|
3
|
-
"version": "16.0.0",
|
|
3
|
+
"version": "16.0.1-EC-87329-test-release.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"vitest": "^4.1.12",
|
|
100
100
|
"vitest-fail-on-console": "^0.10.1"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "3a57a4fbeeb42605d452fc31beaeeda1c740d3f4"
|
|
103
103
|
}
|