@tanstack/table-core 9.0.0-beta.31 → 9.0.0-beta.34
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/core/cells/constructCell.cjs +1 -4
- package/dist/core/cells/constructCell.cjs.map +1 -1
- package/dist/core/cells/constructCell.d.cts +1 -1
- package/dist/core/cells/constructCell.d.ts +1 -1
- package/dist/core/cells/constructCell.js +1 -4
- package/dist/core/cells/constructCell.js.map +1 -1
- package/dist/core/cells/coreCellsFeature.types.d.cts +1 -1
- package/dist/core/cells/coreCellsFeature.types.d.ts +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.cts +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.ts +1 -1
- package/dist/core/columns/constructColumn.cjs +3 -9
- package/dist/core/columns/constructColumn.cjs.map +1 -1
- package/dist/core/columns/constructColumn.js +3 -9
- package/dist/core/columns/constructColumn.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.cjs +12 -18
- package/dist/core/columns/coreColumnsFeature.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.js +12 -18
- package/dist/core/columns/coreColumnsFeature.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.cjs +2 -6
- package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.js +2 -6
- package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
- package/dist/core/headers/buildHeaderGroups.cjs +1 -2
- package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.js +1 -2
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- package/dist/core/headers/constructHeader.cjs +1 -4
- package/dist/core/headers/constructHeader.cjs.map +1 -1
- package/dist/core/headers/constructHeader.js +1 -4
- package/dist/core/headers/constructHeader.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.cjs +8 -11
- package/dist/core/headers/coreHeadersFeature.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.js +8 -11
- package/dist/core/headers/coreHeadersFeature.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.cjs +2 -4
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.js +2 -4
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.cts +3 -3
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +3 -3
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +6 -24
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.js +6 -24
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/core/row-models/createCoreRowModel.cjs +2 -3
- package/dist/core/row-models/createCoreRowModel.cjs.map +1 -1
- package/dist/core/row-models/createCoreRowModel.d.cts +1 -1
- package/dist/core/row-models/createCoreRowModel.d.ts +1 -1
- package/dist/core/row-models/createCoreRowModel.js +2 -3
- package/dist/core/row-models/createCoreRowModel.js.map +1 -1
- package/dist/core/rows/constructRow.cjs +2 -8
- package/dist/core/rows/constructRow.cjs.map +1 -1
- package/dist/core/rows/constructRow.js +2 -8
- package/dist/core/rows/constructRow.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.cjs +4 -1
- package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.js +4 -1
- package/dist/core/rows/coreRowsFeature.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.ts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.cjs +3 -4
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.ts +1 -1
- package/dist/core/rows/coreRowsFeature.utils.js +3 -4
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/core/table/constructTable.cjs +4 -10
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +4 -10
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/experimental-worker-plugin.cjs +14 -0
- package/dist/experimental-worker-plugin.d.cts +5 -0
- package/dist/experimental-worker-plugin.d.ts +5 -0
- package/dist/experimental-worker-plugin.js +6 -0
- package/dist/features/column-faceting/columnFacetingFeature.cjs +12 -18
- package/dist/features/column-faceting/columnFacetingFeature.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.js +12 -18
- package/dist/features/column-faceting/columnFacetingFeature.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.cts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.ts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs +7 -25
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +7 -25
- package/dist/features/column-faceting/columnFacetingFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs +8 -14
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.d.cts +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.d.ts +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js +8 -14
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +10 -13
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +10 -13
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +12 -18
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.js +12 -18
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.cjs +1 -4
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.js +1 -4
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +4 -4
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +4 -4
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +8 -13
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -2
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -2
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +8 -13
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +3 -7
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.js +3 -7
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.cjs +13 -19
- package/dist/features/column-ordering/columnOrderingFeature.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.js +13 -19
- package/dist/features/column-ordering/columnOrderingFeature.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs +6 -11
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.js +6 -11
- package/dist/features/column-ordering/columnOrderingFeature.utils.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.cjs +78 -114
- package/dist/features/column-pinning/columnPinningFeature.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.js +78 -114
- package/dist/features/column-pinning/columnPinningFeature.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.cts +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.ts +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs +15 -28
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.utils.js +15 -28
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs +12 -16
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.js +12 -16
- package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.cjs +24 -48
- package/dist/features/column-sizing/columnSizingFeature.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.js +24 -48
- package/dist/features/column-sizing/columnSizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs +11 -18
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.js +11 -18
- package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.cjs +25 -40
- package/dist/features/column-visibility/columnVisibilityFeature.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.js +25 -40
- package/dist/features/column-visibility/columnVisibilityFeature.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.cts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +3 -6
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +3 -6
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.cjs +1 -2
- package/dist/features/global-filtering/globalFilteringFeature.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.js +1 -2
- package/dist/features/global-filtering/globalFilteringFeature.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +3 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +3 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.cjs +6 -10
- package/dist/features/row-expanding/createExpandedRowModel.cjs.map +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.d.cts +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.d.ts +1 -1
- package/dist/features/row-expanding/createExpandedRowModel.js +6 -10
- package/dist/features/row-expanding/createExpandedRowModel.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.cts +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.ts +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +8 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.js +8 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.cjs +6 -10
- package/dist/features/row-pagination/createPaginatedRowModel.cjs.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.d.cts +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.d.ts +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.js +6 -10
- package/dist/features/row-pagination/createPaginatedRowModel.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.cts +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.ts +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs +8 -14
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.js +8 -14
- package/dist/features/row-pagination/rowPaginationFeature.utils.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.cjs +4 -16
- package/dist/features/row-pinning/rowPinningFeature.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.js +4 -16
- package/dist/features/row-pinning/rowPinningFeature.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs +7 -12
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.js +7 -12
- package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.cjs +30 -60
- package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.js +30 -60
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.cts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.ts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +11 -18
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.js +12 -19
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +20 -14
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.ts +1 -1
- package/dist/features/row-sorting/createSortedRowModel.js +21 -15
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +2 -2
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +2 -2
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +10 -14
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.js +10 -14
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/flex-render.d.cts +1 -1
- package/dist/flex-render.d.ts +1 -1
- package/dist/fns/filterFns.cjs +8 -12
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.js +8 -12
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +18 -18
- package/dist/index.d.ts +18 -18
- package/dist/index.js +2 -2
- package/dist/store-reactivity-bindings.cjs +2 -2
- package/dist/store-reactivity-bindings.cjs.map +1 -1
- package/dist/store-reactivity-bindings.js +2 -2
- package/dist/store-reactivity-bindings.js.map +1 -1
- package/dist/types/Cell.d.cts +1 -1
- package/dist/types/Cell.d.ts +1 -1
- package/dist/types/Column.d.cts +7 -7
- package/dist/types/Column.d.ts +7 -7
- package/dist/types/ColumnDef.d.cts +6 -6
- package/dist/types/ColumnDef.d.ts +6 -6
- package/dist/types/Header.d.cts +1 -1
- package/dist/types/Header.d.ts +1 -1
- package/dist/types/Row.d.cts +2 -2
- package/dist/types/Row.d.ts +2 -2
- package/dist/types/RowModel.d.cts +4 -4
- package/dist/types/RowModel.d.ts +4 -4
- package/dist/types/RowModelFns.d.cts +2 -2
- package/dist/types/RowModelFns.d.ts +2 -2
- package/dist/types/Table.d.cts +9 -9
- package/dist/types/Table.d.ts +9 -9
- package/dist/types/TableFeatures.d.cts +4 -4
- package/dist/types/TableFeatures.d.ts +4 -4
- package/dist/types/TableOptions.d.cts +7 -7
- package/dist/types/TableOptions.d.ts +7 -7
- package/dist/types/TableState.d.cts +6 -6
- package/dist/types/TableState.d.ts +6 -6
- package/dist/utils.cjs +23 -12
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +6 -1
- package/dist/utils.d.ts +6 -1
- package/dist/utils.js +23 -13
- package/dist/utils.js.map +1 -1
- package/dist/worker/createTableWorker.cjs +189 -0
- package/dist/worker/createTableWorker.cjs.map +1 -0
- package/dist/worker/createTableWorker.d.cts +102 -0
- package/dist/worker/createTableWorker.d.ts +102 -0
- package/dist/worker/createTableWorker.js +186 -0
- package/dist/worker/createTableWorker.js.map +1 -0
- package/dist/worker/createWorkerRowModel.cjs +78 -0
- package/dist/worker/createWorkerRowModel.cjs.map +1 -0
- package/dist/worker/createWorkerRowModel.d.cts +42 -0
- package/dist/worker/createWorkerRowModel.d.ts +42 -0
- package/dist/worker/createWorkerRowModel.js +78 -0
- package/dist/worker/createWorkerRowModel.js.map +1 -0
- package/dist/worker/initTableWorker.cjs +100 -0
- package/dist/worker/initTableWorker.cjs.map +1 -0
- package/dist/worker/initTableWorker.d.cts +33 -0
- package/dist/worker/initTableWorker.d.ts +33 -0
- package/dist/worker/initTableWorker.js +100 -0
- package/dist/worker/initTableWorker.js.map +1 -0
- package/dist/worker/rebuildRowModel.cjs +72 -0
- package/dist/worker/rebuildRowModel.cjs.map +1 -0
- package/dist/worker/rebuildRowModel.d.cts +9 -0
- package/dist/worker/rebuildRowModel.d.ts +9 -0
- package/dist/worker/rebuildRowModel.js +72 -0
- package/dist/worker/rebuildRowModel.js.map +1 -0
- package/dist/worker/serializeRowModel.cjs +53 -0
- package/dist/worker/serializeRowModel.cjs.map +1 -0
- package/dist/worker/serializeRowModel.js +52 -0
- package/dist/worker/serializeRowModel.js.map +1 -0
- package/dist/worker/tableWorkerProtocol.cjs +29 -0
- package/dist/worker/tableWorkerProtocol.cjs.map +1 -0
- package/dist/worker/tableWorkerProtocol.d.cts +88 -0
- package/dist/worker/tableWorkerProtocol.d.ts +88 -0
- package/dist/worker/tableWorkerProtocol.js +27 -0
- package/dist/worker/tableWorkerProtocol.js.map +1 -0
- package/package.json +6 -2
- package/src/core/rows/coreRowsFeature.ts +1 -0
- package/src/experimental-worker-plugin.ts +22 -0
- package/src/features/row-selection/rowSelectionFeature.utils.ts +2 -1
- package/src/features/row-sorting/createSortedRowModel.ts +31 -10
- package/src/features/row-sorting/rowSortingFeature.utils.ts +2 -10
- package/src/utils.ts +21 -0
- package/src/worker/createTableWorker.ts +357 -0
- package/src/worker/createWorkerRowModel.ts +121 -0
- package/src/worker/initTableWorker.ts +164 -0
- package/src/worker/rebuildRowModel.ts +117 -0
- package/src/worker/serializeRowModel.ts +80 -0
- package/src/worker/tableWorkerProtocol.ts +105 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const require_utils = require('../utils.cjs');
|
|
2
|
+
const require_tableWorkerProtocol = require('./tableWorkerProtocol.cjs');
|
|
3
|
+
const require_createTableWorker = require('./createTableWorker.cjs');
|
|
4
|
+
const require_rebuildRowModel = require('./rebuildRowModel.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/worker/createWorkerRowModel.ts
|
|
7
|
+
function capitalize(stage) {
|
|
8
|
+
return stage.charAt(0).toUpperCase() + stage.slice(1);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Turns any row model stage into a worker-backed one. The returned factory
|
|
12
|
+
* plugs into the standard feature slot for that stage, so it composes with
|
|
13
|
+
* the rest of the pipeline exactly like the sync factory it replaces.
|
|
14
|
+
*
|
|
15
|
+
* Register only the stages you want offloaded; each import is independent and
|
|
16
|
+
* tree-shakable. All stages on a table share one worker and one round trip
|
|
17
|
+
* per state change via the `tableWorker` handle. Until a result lands, the
|
|
18
|
+
* stage returns its pre-stage model (stale-while-revalidate).
|
|
19
|
+
*
|
|
20
|
+
* Offloaded stages must form a contiguous prefix of the pipeline
|
|
21
|
+
* (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes
|
|
22
|
+
* everything upstream as computed in the worker, so any upstream stage
|
|
23
|
+
* registered on the main thread must be offloaded too. A dev warning fires on
|
|
24
|
+
* mismatches.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const tableWorker = createTableWorker({ createWorker })
|
|
29
|
+
*
|
|
30
|
+
* const features = tableFeatures({
|
|
31
|
+
* rowSortingFeature,
|
|
32
|
+
* columnGroupingFeature,
|
|
33
|
+
* workerRowModelsFeature,
|
|
34
|
+
* filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),
|
|
35
|
+
* groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),
|
|
36
|
+
* sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function createWorkerRowModel(tableWorker, stage) {
|
|
41
|
+
return (_table) => {
|
|
42
|
+
const table = _table;
|
|
43
|
+
require_createTableWorker.getTableWorkerBridge(tableWorker, table).stages.add(stage);
|
|
44
|
+
let warned = false;
|
|
45
|
+
const warnOnce = (message) => {
|
|
46
|
+
if (process.env.NODE_ENV === "development" && !warned) {
|
|
47
|
+
warned = true;
|
|
48
|
+
console.warn(`[table-worker] ${message}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const memoized = require_utils.tableMemo({
|
|
52
|
+
table,
|
|
53
|
+
fnName: `table.get${capitalize(stage)}RowModel`,
|
|
54
|
+
memoDeps: () => [table.getCoreRowModel(), require_createTableWorker.getTableWorkerBridge(tableWorker, table).stageVersions[stage]],
|
|
55
|
+
fn: () => {
|
|
56
|
+
const bridge = require_createTableWorker.getTableWorkerBridge(tableWorker, table);
|
|
57
|
+
const payload = bridge.results[stage];
|
|
58
|
+
if (!payload) {
|
|
59
|
+
if (bridge.resultRequestId > 0) warnOnce(`The worker returned no '${stage}' result. Make sure the worker's initTableWorker() config registers a ${stage}RowModel factory.`);
|
|
60
|
+
return table[`getPre${capitalize(stage)}RowModel`]();
|
|
61
|
+
}
|
|
62
|
+
if (bridge.resultRequestId > 0) for (const upstream of require_tableWorkerProtocol.tableWorkerPipeline) {
|
|
63
|
+
if (upstream === stage) break;
|
|
64
|
+
if (table.options.features[`${upstream}RowModel`] && !bridge.results[upstream]) warnOnce(`This table has a ${upstream}RowModel, but the worker result for '${stage}' was computed without an offloaded '${upstream}' stage, so it is bypassed. Offload it too with createWorkerRowModel(tableWorker, '${upstream}').`);
|
|
65
|
+
}
|
|
66
|
+
return require_rebuildRowModel.rebuildRowModel(table, payload, stage !== "filtered");
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return () => {
|
|
70
|
+
require_createTableWorker.syncTableWorker(tableWorker, table);
|
|
71
|
+
return memoized();
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.createWorkerRowModel = createWorkerRowModel;
|
|
78
|
+
//# sourceMappingURL=createWorkerRowModel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorkerRowModel.cjs","names":["tableMemo","getTableWorkerBridge","tableWorkerPipeline","rebuildRowModel"],"sources":["../../src/worker/createWorkerRowModel.ts"],"sourcesContent":["import { tableMemo } from '../utils'\nimport { getTableWorkerBridge, syncTableWorker } from './createTableWorker'\nimport { rebuildRowModel } from './rebuildRowModel'\nimport { tableWorkerPipeline } from './tableWorkerProtocol'\nimport type { RowModel } from '../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../types/Table'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { RowData } from '../types/type-utils'\nimport type { TableWorker } from './createTableWorker'\nimport type { TableWorkerStage } from './tableWorkerProtocol'\n\ntype AnyTable = Table_Internal<any, any>\n\nfunction capitalize(stage: string) {\n return stage.charAt(0).toUpperCase() + stage.slice(1)\n}\n\n/**\n * Turns any row model stage into a worker-backed one. The returned factory\n * plugs into the standard feature slot for that stage, so it composes with\n * the rest of the pipeline exactly like the sync factory it replaces.\n *\n * Register only the stages you want offloaded; each import is independent and\n * tree-shakable. All stages on a table share one worker and one round trip\n * per state change via the `tableWorker` handle. Until a result lands, the\n * stage returns its pre-stage model (stale-while-revalidate).\n *\n * Offloaded stages must form a contiguous prefix of the pipeline\n * (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes\n * everything upstream as computed in the worker, so any upstream stage\n * registered on the main thread must be offloaded too. A dev warning fires on\n * mismatches.\n *\n * @example\n * ```ts\n * const tableWorker = createTableWorker({ createWorker })\n *\n * const features = tableFeatures({\n * rowSortingFeature,\n * columnGroupingFeature,\n * workerRowModelsFeature,\n * filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),\n * groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),\n * sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),\n * })\n * ```\n */\nexport function createWorkerRowModel(\n tableWorker: TableWorker,\n stage: TableWorkerStage,\n) {\n return <TFeatures extends TableFeatures, TData extends RowData>(\n _table: Table<TFeatures, TData>,\n ): (() => RowModel<TFeatures, TData>) => {\n const table = _table as unknown as AnyTable\n // Stages register per table as their factories initialize (first read).\n // The first render may therefore fire one extra coalesced request while\n // the stage set grows; single-flight makes it a cheap trailing request.\n getTableWorkerBridge(tableWorker, table).stages.add(stage)\n let warned = false\n\n const warnOnce = (message: string) => {\n if (process.env.NODE_ENV === 'development' && !warned) {\n warned = true\n console.warn(`[table-worker] ${message}`)\n }\n }\n\n const memoized = tableMemo({\n table,\n fnName: `table.get${capitalize(stage)}RowModel`,\n // The per-stage version bumps only when this stage's payload actually\n // changed, so stages the worker reported as `unchanged` skip the O(n)\n // rebuild entirely (the re-render itself rides the state slice bump).\n memoDeps: () => [\n table.getCoreRowModel(),\n getTableWorkerBridge(tableWorker, table).stageVersions[stage],\n ],\n fn: () => {\n const bridge = getTableWorkerBridge(tableWorker, table)\n const payload = bridge.results[stage]\n if (!payload) {\n if (bridge.resultRequestId > 0) {\n warnOnce(\n `The worker returned no '${stage}' result. Make sure the ` +\n `worker's initTableWorker() config registers a ` +\n `${stage}RowModel factory.`,\n )\n }\n return (table as any)[`getPre${capitalize(stage)}RowModel`]()\n }\n // Contiguous-prefix check: any upstream stage registered on this\n // table must also have a worker result, or it is silently bypassed.\n if (bridge.resultRequestId > 0) {\n for (const upstream of tableWorkerPipeline) {\n if (upstream === stage) break\n if (\n (table.options.features as Record<string, unknown>)[\n `${upstream}RowModel`\n ] &&\n !bridge.results[upstream]\n ) {\n warnOnce(\n `This table has a ${upstream}RowModel, but the worker result ` +\n `for '${stage}' was computed without an offloaded ` +\n `'${upstream}' stage, so it is bypassed. Offload it too ` +\n `with createWorkerRowModel(tableWorker, '${upstream}').`,\n )\n }\n }\n }\n return rebuildRowModel(table, payload, stage !== 'filtered')\n },\n })\n\n return () => {\n syncTableWorker(tableWorker, table)\n return memoized()\n }\n }\n}\n"],"mappings":";;;;;;AAaA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,qBACd,aACA,OACA;CACA,QACE,WACuC;EACvC,MAAM,QAAQ;EAId,+CAAqB,aAAa,KAAK,CAAC,CAAC,OAAO,IAAI,KAAK;EACzD,IAAI,SAAS;EAEb,MAAM,YAAY,YAAoB;GACpC,IAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ;IACrD,SAAS;IACT,QAAQ,KAAK,kBAAkB,SAAS;GAC1C;EACF;EAEA,MAAM,WAAWA,wBAAU;GACzB;GACA,QAAQ,YAAY,WAAW,KAAK,EAAE;GAItC,gBAAgB,CACd,MAAM,gBAAgB,GACtBC,+CAAqB,aAAa,KAAK,CAAC,CAAC,cAAc,MACzD;GACA,UAAU;IACR,MAAM,SAASA,+CAAqB,aAAa,KAAK;IACtD,MAAM,UAAU,OAAO,QAAQ;IAC/B,IAAI,CAAC,SAAS;KACZ,IAAI,OAAO,kBAAkB,GAC3B,SACE,2BAA2B,MAAM,wEAE5B,MAAM,kBACb;KAEF,OAAQ,MAAc,SAAS,WAAW,KAAK,EAAE,UAAU,CAAC;IAC9D;IAGA,IAAI,OAAO,kBAAkB,GAC3B,KAAK,MAAM,YAAYC,iDAAqB;KAC1C,IAAI,aAAa,OAAO;KACxB,IACG,MAAM,QAAQ,SACb,GAAG,SAAS,cAEd,CAAC,OAAO,QAAQ,WAEhB,SACE,oBAAoB,SAAS,uCACnB,MAAM,uCACV,SAAS,qFAC8B,SAAS,IACxD;IAEJ;IAEF,OAAOC,wCAAgB,OAAO,SAAS,UAAU,UAAU;GAC7D;EACF,CAAC;EAED,aAAa;GACX,0CAAgB,aAAa,KAAK;GAClC,OAAO,SAAS;EAClB;CACF;AACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.cjs";
|
|
2
|
+
import { TableWorkerStage } from "./tableWorkerProtocol.cjs";
|
|
3
|
+
import { RowModel } from "../core/row-models/coreRowModelsFeature.types.cjs";
|
|
4
|
+
import { Table } from "../types/Table.cjs";
|
|
5
|
+
import { TableFeatures } from "../types/TableFeatures.cjs";
|
|
6
|
+
import { TableWorker } from "./createTableWorker.cjs";
|
|
7
|
+
|
|
8
|
+
//#region src/worker/createWorkerRowModel.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Turns any row model stage into a worker-backed one. The returned factory
|
|
11
|
+
* plugs into the standard feature slot for that stage, so it composes with
|
|
12
|
+
* the rest of the pipeline exactly like the sync factory it replaces.
|
|
13
|
+
*
|
|
14
|
+
* Register only the stages you want offloaded; each import is independent and
|
|
15
|
+
* tree-shakable. All stages on a table share one worker and one round trip
|
|
16
|
+
* per state change via the `tableWorker` handle. Until a result lands, the
|
|
17
|
+
* stage returns its pre-stage model (stale-while-revalidate).
|
|
18
|
+
*
|
|
19
|
+
* Offloaded stages must form a contiguous prefix of the pipeline
|
|
20
|
+
* (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes
|
|
21
|
+
* everything upstream as computed in the worker, so any upstream stage
|
|
22
|
+
* registered on the main thread must be offloaded too. A dev warning fires on
|
|
23
|
+
* mismatches.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const tableWorker = createTableWorker({ createWorker })
|
|
28
|
+
*
|
|
29
|
+
* const features = tableFeatures({
|
|
30
|
+
* rowSortingFeature,
|
|
31
|
+
* columnGroupingFeature,
|
|
32
|
+
* workerRowModelsFeature,
|
|
33
|
+
* filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),
|
|
34
|
+
* groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),
|
|
35
|
+
* sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function createWorkerRowModel(tableWorker: TableWorker, stage: TableWorkerStage): <TFeatures extends TableFeatures, TData extends RowData>(_table: Table<TFeatures, TData>) => (() => RowModel<TFeatures, TData>);
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createWorkerRowModel };
|
|
42
|
+
//# sourceMappingURL=createWorkerRowModel.d.cts.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.js";
|
|
2
|
+
import { TableWorkerStage } from "./tableWorkerProtocol.js";
|
|
3
|
+
import { RowModel } from "../core/row-models/coreRowModelsFeature.types.js";
|
|
4
|
+
import { Table } from "../types/Table.js";
|
|
5
|
+
import { TableFeatures } from "../types/TableFeatures.js";
|
|
6
|
+
import { TableWorker } from "./createTableWorker.js";
|
|
7
|
+
|
|
8
|
+
//#region src/worker/createWorkerRowModel.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Turns any row model stage into a worker-backed one. The returned factory
|
|
11
|
+
* plugs into the standard feature slot for that stage, so it composes with
|
|
12
|
+
* the rest of the pipeline exactly like the sync factory it replaces.
|
|
13
|
+
*
|
|
14
|
+
* Register only the stages you want offloaded; each import is independent and
|
|
15
|
+
* tree-shakable. All stages on a table share one worker and one round trip
|
|
16
|
+
* per state change via the `tableWorker` handle. Until a result lands, the
|
|
17
|
+
* stage returns its pre-stage model (stale-while-revalidate).
|
|
18
|
+
*
|
|
19
|
+
* Offloaded stages must form a contiguous prefix of the pipeline
|
|
20
|
+
* (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes
|
|
21
|
+
* everything upstream as computed in the worker, so any upstream stage
|
|
22
|
+
* registered on the main thread must be offloaded too. A dev warning fires on
|
|
23
|
+
* mismatches.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const tableWorker = createTableWorker({ createWorker })
|
|
28
|
+
*
|
|
29
|
+
* const features = tableFeatures({
|
|
30
|
+
* rowSortingFeature,
|
|
31
|
+
* columnGroupingFeature,
|
|
32
|
+
* workerRowModelsFeature,
|
|
33
|
+
* filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),
|
|
34
|
+
* groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),
|
|
35
|
+
* sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare function createWorkerRowModel(tableWorker: TableWorker, stage: TableWorkerStage): <TFeatures extends TableFeatures, TData extends RowData>(_table: Table<TFeatures, TData>) => (() => RowModel<TFeatures, TData>);
|
|
40
|
+
//#endregion
|
|
41
|
+
export { createWorkerRowModel };
|
|
42
|
+
//# sourceMappingURL=createWorkerRowModel.d.ts.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { tableMemo } from "../utils.js";
|
|
2
|
+
import { tableWorkerPipeline } from "./tableWorkerProtocol.js";
|
|
3
|
+
import { getTableWorkerBridge, syncTableWorker } from "./createTableWorker.js";
|
|
4
|
+
import { rebuildRowModel } from "./rebuildRowModel.js";
|
|
5
|
+
|
|
6
|
+
//#region src/worker/createWorkerRowModel.ts
|
|
7
|
+
function capitalize(stage) {
|
|
8
|
+
return stage.charAt(0).toUpperCase() + stage.slice(1);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Turns any row model stage into a worker-backed one. The returned factory
|
|
12
|
+
* plugs into the standard feature slot for that stage, so it composes with
|
|
13
|
+
* the rest of the pipeline exactly like the sync factory it replaces.
|
|
14
|
+
*
|
|
15
|
+
* Register only the stages you want offloaded; each import is independent and
|
|
16
|
+
* tree-shakable. All stages on a table share one worker and one round trip
|
|
17
|
+
* per state change via the `tableWorker` handle. Until a result lands, the
|
|
18
|
+
* stage returns its pre-stage model (stale-while-revalidate).
|
|
19
|
+
*
|
|
20
|
+
* Offloaded stages must form a contiguous prefix of the pipeline
|
|
21
|
+
* (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes
|
|
22
|
+
* everything upstream as computed in the worker, so any upstream stage
|
|
23
|
+
* registered on the main thread must be offloaded too. A dev warning fires on
|
|
24
|
+
* mismatches.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const tableWorker = createTableWorker({ createWorker })
|
|
29
|
+
*
|
|
30
|
+
* const features = tableFeatures({
|
|
31
|
+
* rowSortingFeature,
|
|
32
|
+
* columnGroupingFeature,
|
|
33
|
+
* workerRowModelsFeature,
|
|
34
|
+
* filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),
|
|
35
|
+
* groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),
|
|
36
|
+
* sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function createWorkerRowModel(tableWorker, stage) {
|
|
41
|
+
return (_table) => {
|
|
42
|
+
const table = _table;
|
|
43
|
+
getTableWorkerBridge(tableWorker, table).stages.add(stage);
|
|
44
|
+
let warned = false;
|
|
45
|
+
const warnOnce = (message) => {
|
|
46
|
+
if (process.env.NODE_ENV === "development" && !warned) {
|
|
47
|
+
warned = true;
|
|
48
|
+
console.warn(`[table-worker] ${message}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const memoized = tableMemo({
|
|
52
|
+
table,
|
|
53
|
+
fnName: `table.get${capitalize(stage)}RowModel`,
|
|
54
|
+
memoDeps: () => [table.getCoreRowModel(), getTableWorkerBridge(tableWorker, table).stageVersions[stage]],
|
|
55
|
+
fn: () => {
|
|
56
|
+
const bridge = getTableWorkerBridge(tableWorker, table);
|
|
57
|
+
const payload = bridge.results[stage];
|
|
58
|
+
if (!payload) {
|
|
59
|
+
if (bridge.resultRequestId > 0) warnOnce(`The worker returned no '${stage}' result. Make sure the worker's initTableWorker() config registers a ${stage}RowModel factory.`);
|
|
60
|
+
return table[`getPre${capitalize(stage)}RowModel`]();
|
|
61
|
+
}
|
|
62
|
+
if (bridge.resultRequestId > 0) for (const upstream of tableWorkerPipeline) {
|
|
63
|
+
if (upstream === stage) break;
|
|
64
|
+
if (table.options.features[`${upstream}RowModel`] && !bridge.results[upstream]) warnOnce(`This table has a ${upstream}RowModel, but the worker result for '${stage}' was computed without an offloaded '${upstream}' stage, so it is bypassed. Offload it too with createWorkerRowModel(tableWorker, '${upstream}').`);
|
|
65
|
+
}
|
|
66
|
+
return rebuildRowModel(table, payload, stage !== "filtered");
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return () => {
|
|
70
|
+
syncTableWorker(tableWorker, table);
|
|
71
|
+
return memoized();
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
export { createWorkerRowModel };
|
|
78
|
+
//# sourceMappingURL=createWorkerRowModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWorkerRowModel.js","names":[],"sources":["../../src/worker/createWorkerRowModel.ts"],"sourcesContent":["import { tableMemo } from '../utils'\nimport { getTableWorkerBridge, syncTableWorker } from './createTableWorker'\nimport { rebuildRowModel } from './rebuildRowModel'\nimport { tableWorkerPipeline } from './tableWorkerProtocol'\nimport type { RowModel } from '../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../types/Table'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { RowData } from '../types/type-utils'\nimport type { TableWorker } from './createTableWorker'\nimport type { TableWorkerStage } from './tableWorkerProtocol'\n\ntype AnyTable = Table_Internal<any, any>\n\nfunction capitalize(stage: string) {\n return stage.charAt(0).toUpperCase() + stage.slice(1)\n}\n\n/**\n * Turns any row model stage into a worker-backed one. The returned factory\n * plugs into the standard feature slot for that stage, so it composes with\n * the rest of the pipeline exactly like the sync factory it replaces.\n *\n * Register only the stages you want offloaded; each import is independent and\n * tree-shakable. All stages on a table share one worker and one round trip\n * per state change via the `tableWorker` handle. Until a result lands, the\n * stage returns its pre-stage model (stale-while-revalidate).\n *\n * Offloaded stages must form a contiguous prefix of the pipeline\n * (filtered -> grouped -> sorted -> expanded): a stage's worker result encodes\n * everything upstream as computed in the worker, so any upstream stage\n * registered on the main thread must be offloaded too. A dev warning fires on\n * mismatches.\n *\n * @example\n * ```ts\n * const tableWorker = createTableWorker({ createWorker })\n *\n * const features = tableFeatures({\n * rowSortingFeature,\n * columnGroupingFeature,\n * workerRowModelsFeature,\n * filteredRowModel: createWorkerRowModel(tableWorker, 'filtered'),\n * groupedRowModel: createWorkerRowModel(tableWorker, 'grouped'),\n * sortedRowModel: createWorkerRowModel(tableWorker, 'sorted'),\n * })\n * ```\n */\nexport function createWorkerRowModel(\n tableWorker: TableWorker,\n stage: TableWorkerStage,\n) {\n return <TFeatures extends TableFeatures, TData extends RowData>(\n _table: Table<TFeatures, TData>,\n ): (() => RowModel<TFeatures, TData>) => {\n const table = _table as unknown as AnyTable\n // Stages register per table as their factories initialize (first read).\n // The first render may therefore fire one extra coalesced request while\n // the stage set grows; single-flight makes it a cheap trailing request.\n getTableWorkerBridge(tableWorker, table).stages.add(stage)\n let warned = false\n\n const warnOnce = (message: string) => {\n if (process.env.NODE_ENV === 'development' && !warned) {\n warned = true\n console.warn(`[table-worker] ${message}`)\n }\n }\n\n const memoized = tableMemo({\n table,\n fnName: `table.get${capitalize(stage)}RowModel`,\n // The per-stage version bumps only when this stage's payload actually\n // changed, so stages the worker reported as `unchanged` skip the O(n)\n // rebuild entirely (the re-render itself rides the state slice bump).\n memoDeps: () => [\n table.getCoreRowModel(),\n getTableWorkerBridge(tableWorker, table).stageVersions[stage],\n ],\n fn: () => {\n const bridge = getTableWorkerBridge(tableWorker, table)\n const payload = bridge.results[stage]\n if (!payload) {\n if (bridge.resultRequestId > 0) {\n warnOnce(\n `The worker returned no '${stage}' result. Make sure the ` +\n `worker's initTableWorker() config registers a ` +\n `${stage}RowModel factory.`,\n )\n }\n return (table as any)[`getPre${capitalize(stage)}RowModel`]()\n }\n // Contiguous-prefix check: any upstream stage registered on this\n // table must also have a worker result, or it is silently bypassed.\n if (bridge.resultRequestId > 0) {\n for (const upstream of tableWorkerPipeline) {\n if (upstream === stage) break\n if (\n (table.options.features as Record<string, unknown>)[\n `${upstream}RowModel`\n ] &&\n !bridge.results[upstream]\n ) {\n warnOnce(\n `This table has a ${upstream}RowModel, but the worker result ` +\n `for '${stage}' was computed without an offloaded ` +\n `'${upstream}' stage, so it is bypassed. Offload it too ` +\n `with createWorkerRowModel(tableWorker, '${upstream}').`,\n )\n }\n }\n }\n return rebuildRowModel(table, payload, stage !== 'filtered')\n },\n })\n\n return () => {\n syncTableWorker(tableWorker, table)\n return memoized()\n }\n }\n}\n"],"mappings":";;;;;;AAaA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,SAAgB,qBACd,aACA,OACA;CACA,QACE,WACuC;EACvC,MAAM,QAAQ;EAId,qBAAqB,aAAa,KAAK,CAAC,CAAC,OAAO,IAAI,KAAK;EACzD,IAAI,SAAS;EAEb,MAAM,YAAY,YAAoB;GACpC,IAAI,QAAQ,IAAI,aAAa,iBAAiB,CAAC,QAAQ;IACrD,SAAS;IACT,QAAQ,KAAK,kBAAkB,SAAS;GAC1C;EACF;EAEA,MAAM,WAAW,UAAU;GACzB;GACA,QAAQ,YAAY,WAAW,KAAK,EAAE;GAItC,gBAAgB,CACd,MAAM,gBAAgB,GACtB,qBAAqB,aAAa,KAAK,CAAC,CAAC,cAAc,MACzD;GACA,UAAU;IACR,MAAM,SAAS,qBAAqB,aAAa,KAAK;IACtD,MAAM,UAAU,OAAO,QAAQ;IAC/B,IAAI,CAAC,SAAS;KACZ,IAAI,OAAO,kBAAkB,GAC3B,SACE,2BAA2B,MAAM,wEAE5B,MAAM,kBACb;KAEF,OAAQ,MAAc,SAAS,WAAW,KAAK,EAAE,UAAU,CAAC;IAC9D;IAGA,IAAI,OAAO,kBAAkB,GAC3B,KAAK,MAAM,YAAY,qBAAqB;KAC1C,IAAI,aAAa,OAAO;KACxB,IACG,MAAM,QAAQ,SACb,GAAG,SAAS,cAEd,CAAC,OAAO,QAAQ,WAEhB,SACE,oBAAoB,SAAS,uCACnB,MAAM,uCACV,SAAS,qFAC8B,SAAS,IACxD;IAEJ;IAEF,OAAO,gBAAgB,OAAO,SAAS,UAAU,UAAU;GAC7D;EACF,CAAC;EAED,aAAa;GACX,gBAAgB,aAAa,KAAK;GAClC,OAAO,SAAS;EAClB;CACF;AACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const require_utils = require('../utils.cjs');
|
|
2
|
+
const require_constructTable = require('../core/table/constructTable.cjs');
|
|
3
|
+
const require_store_reactivity_bindings = require('../store-reactivity-bindings.cjs');
|
|
4
|
+
const require_serializeRowModel = require('./serializeRowModel.cjs');
|
|
5
|
+
|
|
6
|
+
//#region src/worker/initTableWorker.ts
|
|
7
|
+
function capitalize(stage) {
|
|
8
|
+
return stage.charAt(0).toUpperCase() + stage.slice(1);
|
|
9
|
+
}
|
|
10
|
+
/** Flatten column-group defs to leaf defs (mirrors core's id resolution). */
|
|
11
|
+
function flattenColumnDefs(defs) {
|
|
12
|
+
return defs.flatMap((def) => def.columns ? flattenColumnDefs(def.columns) : [def]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs a headless "shadow table" inside a dedicated Web Worker.
|
|
16
|
+
*
|
|
17
|
+
* Call this from a user-authored worker entry file, passing the same columns
|
|
18
|
+
* and processing features used on the main thread. The shadow table runs the
|
|
19
|
+
* real table-core row model pipeline (real fns, real Row objects) off the
|
|
20
|
+
* main thread and posts back one payload per stage the main thread requested:
|
|
21
|
+
* a transferable index permutation for flat results, a serialized row tree
|
|
22
|
+
* (with eagerly computed aggregates) when grouping produces synthetic rows.
|
|
23
|
+
*
|
|
24
|
+
* Everything passed here must be thread-portable: `accessorKey` columns or
|
|
25
|
+
* accessors defined in a shared module, and fns from registries or shared
|
|
26
|
+
* modules (no closures over app state).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // table.worker.ts
|
|
31
|
+
* import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'
|
|
32
|
+
* import { columns, sharedFeatures } from './tableConfig'
|
|
33
|
+
*
|
|
34
|
+
* initTableWorker({ features: sharedFeatures, columns })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function initTableWorker(config) {
|
|
38
|
+
let table;
|
|
39
|
+
let dataVersion = 0;
|
|
40
|
+
let coreIndexById = require_utils.makeObjectMap();
|
|
41
|
+
let aggregateColumnIds = [];
|
|
42
|
+
let lastSentModels = {};
|
|
43
|
+
self.onmessage = (event) => {
|
|
44
|
+
const message = event.data;
|
|
45
|
+
if (message.type === "data") {
|
|
46
|
+
dataVersion = message.dataVersion;
|
|
47
|
+
lastSentModels = {};
|
|
48
|
+
if (!table) {
|
|
49
|
+
table = require_constructTable.constructTable({
|
|
50
|
+
...config,
|
|
51
|
+
features: {
|
|
52
|
+
coreReactivityFeature: require_store_reactivity_bindings.storeReactivityBindings(),
|
|
53
|
+
...config.features
|
|
54
|
+
},
|
|
55
|
+
data: message.data
|
|
56
|
+
});
|
|
57
|
+
aggregateColumnIds = flattenColumnDefs(config.columns).filter((def) => def.aggregationFn != null || def.aggregatedCell != null).map((def) => def.id ?? (typeof def.accessorKey === "string" ? def.accessorKey.replaceAll(".", "_") : void 0)).filter((id) => id != null);
|
|
58
|
+
} else table.setOptions((prev) => ({
|
|
59
|
+
...prev,
|
|
60
|
+
data: message.data
|
|
61
|
+
}));
|
|
62
|
+
const coreFlatRows = table.getCoreRowModel().flatRows;
|
|
63
|
+
coreIndexById = require_utils.makeObjectMap();
|
|
64
|
+
for (let i = 0; i < coreFlatRows.length; i++) coreIndexById[coreFlatRows[i].id] = i;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!table) return;
|
|
68
|
+
const start = performance.now();
|
|
69
|
+
table._reactivity.batch(() => {
|
|
70
|
+
for (const [key, value] of Object.entries(message.state)) {
|
|
71
|
+
const baseAtom = table.baseAtoms[key];
|
|
72
|
+
if (baseAtom && value !== void 0) baseAtom.set(value);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const stages = {};
|
|
76
|
+
const transfer = [];
|
|
77
|
+
for (const stage of message.stages) {
|
|
78
|
+
if (!config.features[`${stage}RowModel`]) continue;
|
|
79
|
+
const model = table[`get${capitalize(stage)}RowModel`]();
|
|
80
|
+
if (lastSentModels[stage] === model) {
|
|
81
|
+
stages[stage] = { kind: "unchanged" };
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
lastSentModels[stage] = model;
|
|
85
|
+
stages[stage] = require_serializeRowModel.serializeRowModel(model, coreIndexById, aggregateColumnIds, transfer);
|
|
86
|
+
}
|
|
87
|
+
const response = {
|
|
88
|
+
type: "result",
|
|
89
|
+
requestId: message.requestId,
|
|
90
|
+
dataVersion,
|
|
91
|
+
stages,
|
|
92
|
+
computeMs: performance.now() - start
|
|
93
|
+
};
|
|
94
|
+
postMessage(response, { transfer });
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
exports.initTableWorker = initTableWorker;
|
|
100
|
+
//# sourceMappingURL=initTableWorker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initTableWorker.cjs","names":["makeObjectMap","constructTable","storeReactivityBindings","serializeRowModel"],"sources":["../../src/worker/initTableWorker.ts"],"sourcesContent":["import { constructTable } from '../core/table/constructTable'\nimport { storeReactivityBindings } from '../store-reactivity-bindings'\nimport { makeObjectMap } from '../utils'\nimport { serializeRowModel } from './serializeRowModel'\nimport type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { TableOptions } from '../types/TableOptions'\nimport type { Table_Internal } from '../types/Table'\nimport type {\n TableWorkerRequest,\n TableWorkerResult,\n TableWorkerStage,\n TableWorkerStagePayload,\n} from './tableWorkerProtocol'\n\nexport type TableWorkerConfig<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Omit<TableOptions<TFeatures, TData>, 'data'>\n\nfunction capitalize(stage: string) {\n return stage.charAt(0).toUpperCase() + stage.slice(1)\n}\n\n/** Flatten column-group defs to leaf defs (mirrors core's id resolution). */\nfunction flattenColumnDefs(defs: Array<any>): Array<any> {\n return defs.flatMap((def) =>\n def.columns ? flattenColumnDefs(def.columns) : [def],\n )\n}\n\n/**\n * Runs a headless \"shadow table\" inside a dedicated Web Worker.\n *\n * Call this from a user-authored worker entry file, passing the same columns\n * and processing features used on the main thread. The shadow table runs the\n * real table-core row model pipeline (real fns, real Row objects) off the\n * main thread and posts back one payload per stage the main thread requested:\n * a transferable index permutation for flat results, a serialized row tree\n * (with eagerly computed aggregates) when grouping produces synthetic rows.\n *\n * Everything passed here must be thread-portable: `accessorKey` columns or\n * accessors defined in a shared module, and fns from registries or shared\n * modules (no closures over app state).\n *\n * @example\n * ```ts\n * // table.worker.ts\n * import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'\n * import { columns, sharedFeatures } from './tableConfig'\n *\n * initTableWorker({ features: sharedFeatures, columns })\n * ```\n */\nexport function initTableWorker<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(config: TableWorkerConfig<TFeatures, TData>): void {\n let table: Table_Internal<TFeatures, TData> | undefined\n let dataVersion = 0\n let coreIndexById: Record<string, number> = makeObjectMap()\n let aggregateColumnIds: Array<string> = []\n // Last-sent model identity per stage: the memoized getters return stable\n // objects when their inputs did not change, so identity equality is exactly\n // \"this stage's result is unchanged\".\n let lastSentModels: { [K in TableWorkerStage]?: unknown } = {}\n\n self.onmessage = (event: MessageEvent<TableWorkerRequest<TData>>) => {\n const message = event.data\n\n if (message.type === 'data') {\n dataVersion = message.dataVersion\n lastSentModels = {}\n if (!table) {\n table = constructTable<TFeatures, TData>({\n ...(config as TableOptions<TFeatures, TData>),\n features: {\n coreReactivityFeature: storeReactivityBindings(),\n ...config.features,\n },\n data: message.data,\n }) as unknown as Table_Internal<TFeatures, TData>\n // Only columns with an explicit aggregation get eagerly aggregated\n // per group. Sync tables aggregate lazily (visible cells only), so\n // auto-aggregating every column would explode on high-cardinality\n // grouping for values nothing renders. Read the RAW column defs:\n // columnGroupingFeature injects default aggregatedCell/aggregationFn\n // into every resolved columnDef, so the resolved defs can't tell\n // explicit from default.\n aggregateColumnIds = flattenColumnDefs(config.columns as Array<any>)\n .filter(\n (def) => def.aggregationFn != null || def.aggregatedCell != null,\n )\n .map(\n (def) =>\n def.id ??\n (typeof def.accessorKey === 'string'\n ? def.accessorKey.replaceAll('.', '_')\n : undefined),\n )\n .filter((id): id is string => id != null)\n } else {\n table.setOptions((prev) => ({ ...prev, data: message.data }))\n }\n // Map row ids to data positions once per dataset; serialization uses it\n // to express every stage result in terms of core row positions.\n const coreFlatRows = table.getCoreRowModel().flatRows\n coreIndexById = makeObjectMap()\n for (let i = 0; i < coreFlatRows.length; i++) {\n coreIndexById[coreFlatRows[i]!.id] = i\n }\n return\n }\n\n if (!table) return\n\n const start = performance.now()\n\n // Apply the serializable state slices to the shadow table's base atoms.\n table._reactivity.batch(() => {\n for (const [key, value] of Object.entries(message.state)) {\n const baseAtom = (table!.baseAtoms as Record<string, any>)[key]\n if (baseAtom && value !== undefined) {\n baseAtom.set(value)\n }\n }\n })\n\n // Compute exactly the stages the main thread requested, skipping any this\n // shadow table has no row model factory for (the main thread warns).\n const stages: { [K in TableWorkerStage]?: TableWorkerStagePayload } = {}\n const transfer: Array<Transferable> = []\n\n for (const stage of message.stages) {\n if (!(config.features as Record<string, unknown>)[`${stage}RowModel`]) {\n continue\n }\n const model = (table as any)[`get${capitalize(stage)}RowModel`]()\n // Memoized getters return the same object when inputs are unchanged;\n // skip re-serializing (and the main thread skips rebuilding). Safe under\n // single-flight: results are never dropped within a dataVersion.\n if (lastSentModels[stage] === model) {\n stages[stage] = { kind: 'unchanged' }\n continue\n }\n lastSentModels[stage] = model\n stages[stage] = serializeRowModel(\n model,\n coreIndexById,\n aggregateColumnIds,\n transfer,\n )\n }\n\n const response: TableWorkerResult = {\n type: 'result',\n requestId: message.requestId,\n dataVersion,\n stages,\n computeMs: performance.now() - start,\n }\n postMessage(response, { transfer })\n }\n}\n"],"mappings":";;;;;;AAoBA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;AAGA,SAAS,kBAAkB,MAA8B;CACvD,OAAO,KAAK,SAAS,QACnB,IAAI,UAAU,kBAAkB,IAAI,OAAO,IAAI,CAAC,GAAG,CACrD;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBAGd,QAAmD;CACnD,IAAI;CACJ,IAAI,cAAc;CAClB,IAAI,gBAAwCA,4BAAc;CAC1D,IAAI,qBAAoC,CAAC;CAIzC,IAAI,iBAAwD,CAAC;CAE7D,KAAK,aAAa,UAAmD;EACnE,MAAM,UAAU,MAAM;EAEtB,IAAI,QAAQ,SAAS,QAAQ;GAC3B,cAAc,QAAQ;GACtB,iBAAiB,CAAC;GAClB,IAAI,CAAC,OAAO;IACV,QAAQC,sCAAiC;KACvC,GAAI;KACJ,UAAU;MACR,uBAAuBC,0DAAwB;MAC/C,GAAG,OAAO;KACZ;KACA,MAAM,QAAQ;IAChB,CAAC;IAQD,qBAAqB,kBAAkB,OAAO,OAAqB,CAAC,CACjE,QACE,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB,IAC9D,CAAC,CACA,KACE,QACC,IAAI,OACH,OAAO,IAAI,gBAAgB,WACxB,IAAI,YAAY,WAAW,KAAK,GAAG,IACnC,OACR,CAAC,CACA,QAAQ,OAAqB,MAAM,IAAI;GAC5C,OACE,MAAM,YAAY,UAAU;IAAE,GAAG;IAAM,MAAM,QAAQ;GAAK,EAAE;GAI9D,MAAM,eAAe,MAAM,gBAAgB,CAAC,CAAC;GAC7C,gBAAgBF,4BAAc;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,cAAc,aAAa,EAAE,CAAE,MAAM;GAEvC;EACF;EAEA,IAAI,CAAC,OAAO;EAEZ,MAAM,QAAQ,YAAY,IAAI;EAG9B,MAAM,YAAY,YAAY;GAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,KAAK,GAAG;IACxD,MAAM,WAAY,MAAO,UAAkC;IAC3D,IAAI,YAAY,UAAU,QACxB,SAAS,IAAI,KAAK;GAEtB;EACF,CAAC;EAID,MAAM,SAAgE,CAAC;EACvE,MAAM,WAAgC,CAAC;EAEvC,KAAK,MAAM,SAAS,QAAQ,QAAQ;GAClC,IAAI,CAAE,OAAO,SAAqC,GAAG,MAAM,YACzD;GAEF,MAAM,QAAS,MAAc,MAAM,WAAW,KAAK,EAAE,UAAU,CAAC;GAIhE,IAAI,eAAe,WAAW,OAAO;IACnC,OAAO,SAAS,EAAE,MAAM,YAAY;IACpC;GACF;GACA,eAAe,SAAS;GACxB,OAAO,SAASG,4CACd,OACA,eACA,oBACA,QACF;EACF;EAEA,MAAM,WAA8B;GAClC,MAAM;GACN,WAAW,QAAQ;GACnB;GACA;GACA,WAAW,YAAY,IAAI,IAAI;EACjC;EACA,YAAY,UAAU,EAAE,SAAS,CAAC;CACpC;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.cjs";
|
|
2
|
+
import { TableOptions } from "../types/TableOptions.cjs";
|
|
3
|
+
import { TableFeatures } from "../types/TableFeatures.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/worker/initTableWorker.d.ts
|
|
6
|
+
type TableWorkerConfig<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'>;
|
|
7
|
+
/**
|
|
8
|
+
* Runs a headless "shadow table" inside a dedicated Web Worker.
|
|
9
|
+
*
|
|
10
|
+
* Call this from a user-authored worker entry file, passing the same columns
|
|
11
|
+
* and processing features used on the main thread. The shadow table runs the
|
|
12
|
+
* real table-core row model pipeline (real fns, real Row objects) off the
|
|
13
|
+
* main thread and posts back one payload per stage the main thread requested:
|
|
14
|
+
* a transferable index permutation for flat results, a serialized row tree
|
|
15
|
+
* (with eagerly computed aggregates) when grouping produces synthetic rows.
|
|
16
|
+
*
|
|
17
|
+
* Everything passed here must be thread-portable: `accessorKey` columns or
|
|
18
|
+
* accessors defined in a shared module, and fns from registries or shared
|
|
19
|
+
* modules (no closures over app state).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // table.worker.ts
|
|
24
|
+
* import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'
|
|
25
|
+
* import { columns, sharedFeatures } from './tableConfig'
|
|
26
|
+
*
|
|
27
|
+
* initTableWorker({ features: sharedFeatures, columns })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function initTableWorker<TFeatures extends TableFeatures, TData extends RowData>(config: TableWorkerConfig<TFeatures, TData>): void;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { TableWorkerConfig, initTableWorker };
|
|
33
|
+
//# sourceMappingURL=initTableWorker.d.cts.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RowData } from "../types/type-utils.js";
|
|
2
|
+
import { TableOptions } from "../types/TableOptions.js";
|
|
3
|
+
import { TableFeatures } from "../types/TableFeatures.js";
|
|
4
|
+
|
|
5
|
+
//#region src/worker/initTableWorker.d.ts
|
|
6
|
+
type TableWorkerConfig<TFeatures extends TableFeatures, TData extends RowData> = Omit<TableOptions<TFeatures, TData>, 'data'>;
|
|
7
|
+
/**
|
|
8
|
+
* Runs a headless "shadow table" inside a dedicated Web Worker.
|
|
9
|
+
*
|
|
10
|
+
* Call this from a user-authored worker entry file, passing the same columns
|
|
11
|
+
* and processing features used on the main thread. The shadow table runs the
|
|
12
|
+
* real table-core row model pipeline (real fns, real Row objects) off the
|
|
13
|
+
* main thread and posts back one payload per stage the main thread requested:
|
|
14
|
+
* a transferable index permutation for flat results, a serialized row tree
|
|
15
|
+
* (with eagerly computed aggregates) when grouping produces synthetic rows.
|
|
16
|
+
*
|
|
17
|
+
* Everything passed here must be thread-portable: `accessorKey` columns or
|
|
18
|
+
* accessors defined in a shared module, and fns from registries or shared
|
|
19
|
+
* modules (no closures over app state).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // table.worker.ts
|
|
24
|
+
* import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'
|
|
25
|
+
* import { columns, sharedFeatures } from './tableConfig'
|
|
26
|
+
*
|
|
27
|
+
* initTableWorker({ features: sharedFeatures, columns })
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare function initTableWorker<TFeatures extends TableFeatures, TData extends RowData>(config: TableWorkerConfig<TFeatures, TData>): void;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { TableWorkerConfig, initTableWorker };
|
|
33
|
+
//# sourceMappingURL=initTableWorker.d.ts.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { makeObjectMap } from "../utils.js";
|
|
2
|
+
import { constructTable } from "../core/table/constructTable.js";
|
|
3
|
+
import { storeReactivityBindings } from "../store-reactivity-bindings.js";
|
|
4
|
+
import { serializeRowModel } from "./serializeRowModel.js";
|
|
5
|
+
|
|
6
|
+
//#region src/worker/initTableWorker.ts
|
|
7
|
+
function capitalize(stage) {
|
|
8
|
+
return stage.charAt(0).toUpperCase() + stage.slice(1);
|
|
9
|
+
}
|
|
10
|
+
/** Flatten column-group defs to leaf defs (mirrors core's id resolution). */
|
|
11
|
+
function flattenColumnDefs(defs) {
|
|
12
|
+
return defs.flatMap((def) => def.columns ? flattenColumnDefs(def.columns) : [def]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Runs a headless "shadow table" inside a dedicated Web Worker.
|
|
16
|
+
*
|
|
17
|
+
* Call this from a user-authored worker entry file, passing the same columns
|
|
18
|
+
* and processing features used on the main thread. The shadow table runs the
|
|
19
|
+
* real table-core row model pipeline (real fns, real Row objects) off the
|
|
20
|
+
* main thread and posts back one payload per stage the main thread requested:
|
|
21
|
+
* a transferable index permutation for flat results, a serialized row tree
|
|
22
|
+
* (with eagerly computed aggregates) when grouping produces synthetic rows.
|
|
23
|
+
*
|
|
24
|
+
* Everything passed here must be thread-portable: `accessorKey` columns or
|
|
25
|
+
* accessors defined in a shared module, and fns from registries or shared
|
|
26
|
+
* modules (no closures over app state).
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* // table.worker.ts
|
|
31
|
+
* import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'
|
|
32
|
+
* import { columns, sharedFeatures } from './tableConfig'
|
|
33
|
+
*
|
|
34
|
+
* initTableWorker({ features: sharedFeatures, columns })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function initTableWorker(config) {
|
|
38
|
+
let table;
|
|
39
|
+
let dataVersion = 0;
|
|
40
|
+
let coreIndexById = makeObjectMap();
|
|
41
|
+
let aggregateColumnIds = [];
|
|
42
|
+
let lastSentModels = {};
|
|
43
|
+
self.onmessage = (event) => {
|
|
44
|
+
const message = event.data;
|
|
45
|
+
if (message.type === "data") {
|
|
46
|
+
dataVersion = message.dataVersion;
|
|
47
|
+
lastSentModels = {};
|
|
48
|
+
if (!table) {
|
|
49
|
+
table = constructTable({
|
|
50
|
+
...config,
|
|
51
|
+
features: {
|
|
52
|
+
coreReactivityFeature: storeReactivityBindings(),
|
|
53
|
+
...config.features
|
|
54
|
+
},
|
|
55
|
+
data: message.data
|
|
56
|
+
});
|
|
57
|
+
aggregateColumnIds = flattenColumnDefs(config.columns).filter((def) => def.aggregationFn != null || def.aggregatedCell != null).map((def) => def.id ?? (typeof def.accessorKey === "string" ? def.accessorKey.replaceAll(".", "_") : void 0)).filter((id) => id != null);
|
|
58
|
+
} else table.setOptions((prev) => ({
|
|
59
|
+
...prev,
|
|
60
|
+
data: message.data
|
|
61
|
+
}));
|
|
62
|
+
const coreFlatRows = table.getCoreRowModel().flatRows;
|
|
63
|
+
coreIndexById = makeObjectMap();
|
|
64
|
+
for (let i = 0; i < coreFlatRows.length; i++) coreIndexById[coreFlatRows[i].id] = i;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (!table) return;
|
|
68
|
+
const start = performance.now();
|
|
69
|
+
table._reactivity.batch(() => {
|
|
70
|
+
for (const [key, value] of Object.entries(message.state)) {
|
|
71
|
+
const baseAtom = table.baseAtoms[key];
|
|
72
|
+
if (baseAtom && value !== void 0) baseAtom.set(value);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const stages = {};
|
|
76
|
+
const transfer = [];
|
|
77
|
+
for (const stage of message.stages) {
|
|
78
|
+
if (!config.features[`${stage}RowModel`]) continue;
|
|
79
|
+
const model = table[`get${capitalize(stage)}RowModel`]();
|
|
80
|
+
if (lastSentModels[stage] === model) {
|
|
81
|
+
stages[stage] = { kind: "unchanged" };
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
lastSentModels[stage] = model;
|
|
85
|
+
stages[stage] = serializeRowModel(model, coreIndexById, aggregateColumnIds, transfer);
|
|
86
|
+
}
|
|
87
|
+
const response = {
|
|
88
|
+
type: "result",
|
|
89
|
+
requestId: message.requestId,
|
|
90
|
+
dataVersion,
|
|
91
|
+
stages,
|
|
92
|
+
computeMs: performance.now() - start
|
|
93
|
+
};
|
|
94
|
+
postMessage(response, { transfer });
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { initTableWorker };
|
|
100
|
+
//# sourceMappingURL=initTableWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initTableWorker.js","names":[],"sources":["../../src/worker/initTableWorker.ts"],"sourcesContent":["import { constructTable } from '../core/table/constructTable'\nimport { storeReactivityBindings } from '../store-reactivity-bindings'\nimport { makeObjectMap } from '../utils'\nimport { serializeRowModel } from './serializeRowModel'\nimport type { RowData } from '../types/type-utils'\nimport type { TableFeatures } from '../types/TableFeatures'\nimport type { TableOptions } from '../types/TableOptions'\nimport type { Table_Internal } from '../types/Table'\nimport type {\n TableWorkerRequest,\n TableWorkerResult,\n TableWorkerStage,\n TableWorkerStagePayload,\n} from './tableWorkerProtocol'\n\nexport type TableWorkerConfig<\n TFeatures extends TableFeatures,\n TData extends RowData,\n> = Omit<TableOptions<TFeatures, TData>, 'data'>\n\nfunction capitalize(stage: string) {\n return stage.charAt(0).toUpperCase() + stage.slice(1)\n}\n\n/** Flatten column-group defs to leaf defs (mirrors core's id resolution). */\nfunction flattenColumnDefs(defs: Array<any>): Array<any> {\n return defs.flatMap((def) =>\n def.columns ? flattenColumnDefs(def.columns) : [def],\n )\n}\n\n/**\n * Runs a headless \"shadow table\" inside a dedicated Web Worker.\n *\n * Call this from a user-authored worker entry file, passing the same columns\n * and processing features used on the main thread. The shadow table runs the\n * real table-core row model pipeline (real fns, real Row objects) off the\n * main thread and posts back one payload per stage the main thread requested:\n * a transferable index permutation for flat results, a serialized row tree\n * (with eagerly computed aggregates) when grouping produces synthetic rows.\n *\n * Everything passed here must be thread-portable: `accessorKey` columns or\n * accessors defined in a shared module, and fns from registries or shared\n * modules (no closures over app state).\n *\n * @example\n * ```ts\n * // table.worker.ts\n * import { initTableWorker } from '@tanstack/table-core/experimental-worker-plugin'\n * import { columns, sharedFeatures } from './tableConfig'\n *\n * initTableWorker({ features: sharedFeatures, columns })\n * ```\n */\nexport function initTableWorker<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(config: TableWorkerConfig<TFeatures, TData>): void {\n let table: Table_Internal<TFeatures, TData> | undefined\n let dataVersion = 0\n let coreIndexById: Record<string, number> = makeObjectMap()\n let aggregateColumnIds: Array<string> = []\n // Last-sent model identity per stage: the memoized getters return stable\n // objects when their inputs did not change, so identity equality is exactly\n // \"this stage's result is unchanged\".\n let lastSentModels: { [K in TableWorkerStage]?: unknown } = {}\n\n self.onmessage = (event: MessageEvent<TableWorkerRequest<TData>>) => {\n const message = event.data\n\n if (message.type === 'data') {\n dataVersion = message.dataVersion\n lastSentModels = {}\n if (!table) {\n table = constructTable<TFeatures, TData>({\n ...(config as TableOptions<TFeatures, TData>),\n features: {\n coreReactivityFeature: storeReactivityBindings(),\n ...config.features,\n },\n data: message.data,\n }) as unknown as Table_Internal<TFeatures, TData>\n // Only columns with an explicit aggregation get eagerly aggregated\n // per group. Sync tables aggregate lazily (visible cells only), so\n // auto-aggregating every column would explode on high-cardinality\n // grouping for values nothing renders. Read the RAW column defs:\n // columnGroupingFeature injects default aggregatedCell/aggregationFn\n // into every resolved columnDef, so the resolved defs can't tell\n // explicit from default.\n aggregateColumnIds = flattenColumnDefs(config.columns as Array<any>)\n .filter(\n (def) => def.aggregationFn != null || def.aggregatedCell != null,\n )\n .map(\n (def) =>\n def.id ??\n (typeof def.accessorKey === 'string'\n ? def.accessorKey.replaceAll('.', '_')\n : undefined),\n )\n .filter((id): id is string => id != null)\n } else {\n table.setOptions((prev) => ({ ...prev, data: message.data }))\n }\n // Map row ids to data positions once per dataset; serialization uses it\n // to express every stage result in terms of core row positions.\n const coreFlatRows = table.getCoreRowModel().flatRows\n coreIndexById = makeObjectMap()\n for (let i = 0; i < coreFlatRows.length; i++) {\n coreIndexById[coreFlatRows[i]!.id] = i\n }\n return\n }\n\n if (!table) return\n\n const start = performance.now()\n\n // Apply the serializable state slices to the shadow table's base atoms.\n table._reactivity.batch(() => {\n for (const [key, value] of Object.entries(message.state)) {\n const baseAtom = (table!.baseAtoms as Record<string, any>)[key]\n if (baseAtom && value !== undefined) {\n baseAtom.set(value)\n }\n }\n })\n\n // Compute exactly the stages the main thread requested, skipping any this\n // shadow table has no row model factory for (the main thread warns).\n const stages: { [K in TableWorkerStage]?: TableWorkerStagePayload } = {}\n const transfer: Array<Transferable> = []\n\n for (const stage of message.stages) {\n if (!(config.features as Record<string, unknown>)[`${stage}RowModel`]) {\n continue\n }\n const model = (table as any)[`get${capitalize(stage)}RowModel`]()\n // Memoized getters return the same object when inputs are unchanged;\n // skip re-serializing (and the main thread skips rebuilding). Safe under\n // single-flight: results are never dropped within a dataVersion.\n if (lastSentModels[stage] === model) {\n stages[stage] = { kind: 'unchanged' }\n continue\n }\n lastSentModels[stage] = model\n stages[stage] = serializeRowModel(\n model,\n coreIndexById,\n aggregateColumnIds,\n transfer,\n )\n }\n\n const response: TableWorkerResult = {\n type: 'result',\n requestId: message.requestId,\n dataVersion,\n stages,\n computeMs: performance.now() - start,\n }\n postMessage(response, { transfer })\n }\n}\n"],"mappings":";;;;;;AAoBA,SAAS,WAAW,OAAe;CACjC,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,MAAM,CAAC;AACtD;;AAGA,SAAS,kBAAkB,MAA8B;CACvD,OAAO,KAAK,SAAS,QACnB,IAAI,UAAU,kBAAkB,IAAI,OAAO,IAAI,CAAC,GAAG,CACrD;AACF;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBAGd,QAAmD;CACnD,IAAI;CACJ,IAAI,cAAc;CAClB,IAAI,gBAAwC,cAAc;CAC1D,IAAI,qBAAoC,CAAC;CAIzC,IAAI,iBAAwD,CAAC;CAE7D,KAAK,aAAa,UAAmD;EACnE,MAAM,UAAU,MAAM;EAEtB,IAAI,QAAQ,SAAS,QAAQ;GAC3B,cAAc,QAAQ;GACtB,iBAAiB,CAAC;GAClB,IAAI,CAAC,OAAO;IACV,QAAQ,eAAiC;KACvC,GAAI;KACJ,UAAU;MACR,uBAAuB,wBAAwB;MAC/C,GAAG,OAAO;KACZ;KACA,MAAM,QAAQ;IAChB,CAAC;IAQD,qBAAqB,kBAAkB,OAAO,OAAqB,CAAC,CACjE,QACE,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB,IAC9D,CAAC,CACA,KACE,QACC,IAAI,OACH,OAAO,IAAI,gBAAgB,WACxB,IAAI,YAAY,WAAW,KAAK,GAAG,IACnC,OACR,CAAC,CACA,QAAQ,OAAqB,MAAM,IAAI;GAC5C,OACE,MAAM,YAAY,UAAU;IAAE,GAAG;IAAM,MAAM,QAAQ;GAAK,EAAE;GAI9D,MAAM,eAAe,MAAM,gBAAgB,CAAC,CAAC;GAC7C,gBAAgB,cAAc;GAC9B,KAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KACvC,cAAc,aAAa,EAAE,CAAE,MAAM;GAEvC;EACF;EAEA,IAAI,CAAC,OAAO;EAEZ,MAAM,QAAQ,YAAY,IAAI;EAG9B,MAAM,YAAY,YAAY;GAC5B,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAQ,KAAK,GAAG;IACxD,MAAM,WAAY,MAAO,UAAkC;IAC3D,IAAI,YAAY,UAAU,QACxB,SAAS,IAAI,KAAK;GAEtB;EACF,CAAC;EAID,MAAM,SAAgE,CAAC;EACvE,MAAM,WAAgC,CAAC;EAEvC,KAAK,MAAM,SAAS,QAAQ,QAAQ;GAClC,IAAI,CAAE,OAAO,SAAqC,GAAG,MAAM,YACzD;GAEF,MAAM,QAAS,MAAc,MAAM,WAAW,KAAK,EAAE,UAAU,CAAC;GAIhE,IAAI,eAAe,WAAW,OAAO;IACnC,OAAO,SAAS,EAAE,MAAM,YAAY;IACpC;GACF;GACA,eAAe,SAAS;GACxB,OAAO,SAAS,kBACd,OACA,eACA,oBACA,QACF;EACF;EAEA,MAAM,WAA8B;GAClC,MAAM;GACN,WAAW,QAAQ;GACnB;GACA;GACA,WAAW,YAAY,IAAI,IAAI;EACjC;EACA,YAAY,UAAU,EAAE,SAAS,CAAC;CACpC;AACF"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const require_utils = require('../utils.cjs');
|
|
2
|
+
const require_constructRow = require('../core/rows/constructRow.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/worker/rebuildRowModel.ts
|
|
5
|
+
function collectLeafRows(subRows, out) {
|
|
6
|
+
for (let i = 0; i < subRows.length; i++) {
|
|
7
|
+
const row = subRows[i];
|
|
8
|
+
if (row.groupingColumnId == null) out.push(row);
|
|
9
|
+
else collectLeafRows(row.subRows, out);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function rebuildRowModel(table, payload, resetDepths) {
|
|
13
|
+
const core = table.getCoreRowModel();
|
|
14
|
+
if (payload.kind === "flat") {
|
|
15
|
+
const { indices } = payload;
|
|
16
|
+
const rows = new Array(indices.length);
|
|
17
|
+
for (let i = 0; i < indices.length; i++) {
|
|
18
|
+
const row = core.flatRows[indices[i]];
|
|
19
|
+
if (resetDepths) {
|
|
20
|
+
row.depth = 0;
|
|
21
|
+
row.parentId = void 0;
|
|
22
|
+
}
|
|
23
|
+
rows[i] = row;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
rows,
|
|
27
|
+
flatRows: rows,
|
|
28
|
+
rowsById: core.rowsById
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const flatRows = [];
|
|
32
|
+
const rowsById = Object.create(core.rowsById);
|
|
33
|
+
const rebuildRows = (nodes, depth, parentId) => {
|
|
34
|
+
const rows = new Array(nodes.length);
|
|
35
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
36
|
+
const node = nodes[i];
|
|
37
|
+
if (typeof node === "number") {
|
|
38
|
+
const row = core.flatRows[node];
|
|
39
|
+
row.depth = depth;
|
|
40
|
+
row.parentId = parentId;
|
|
41
|
+
flatRows.push(row);
|
|
42
|
+
rows[i] = row;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const subRows = rebuildRows(node.children, depth + 1, node.id);
|
|
46
|
+
const leafRows = [];
|
|
47
|
+
collectLeafRows(subRows, leafRows);
|
|
48
|
+
const row = require_constructRow.constructRow(table, node.id, leafRows[0]?.original, node.index, depth, void 0, parentId);
|
|
49
|
+
const aggregates = node.aggregates;
|
|
50
|
+
Object.assign(row, {
|
|
51
|
+
groupingColumnId: node.groupingColumnId,
|
|
52
|
+
groupingValue: node.groupingValue,
|
|
53
|
+
subRows,
|
|
54
|
+
leafRows,
|
|
55
|
+
getValue: (columnId) => require_utils.hasOwn(aggregates, columnId) ? aggregates[columnId] : void 0
|
|
56
|
+
});
|
|
57
|
+
flatRows.push(row);
|
|
58
|
+
rowsById[node.id] = row;
|
|
59
|
+
rows[i] = row;
|
|
60
|
+
}
|
|
61
|
+
return rows;
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
rows: rebuildRows(payload.children, 0, void 0),
|
|
65
|
+
flatRows,
|
|
66
|
+
rowsById
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.rebuildRowModel = rebuildRowModel;
|
|
72
|
+
//# sourceMappingURL=rebuildRowModel.cjs.map
|