@tanstack/table-core 9.0.0-alpha.46 → 9.0.0-alpha.48
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/README.md +10 -0
- package/dist/core/cells/constructCell.cjs +4 -3
- package/dist/core/cells/constructCell.cjs.map +1 -1
- package/dist/core/cells/constructCell.js +4 -3
- package/dist/core/cells/constructCell.js.map +1 -1
- package/dist/core/cells/coreCellsFeature.utils.cjs +11 -8
- package/dist/core/cells/coreCellsFeature.utils.cjs.map +1 -1
- package/dist/core/cells/coreCellsFeature.utils.d.cts +11 -8
- package/dist/core/cells/coreCellsFeature.utils.d.ts +11 -8
- package/dist/core/cells/coreCellsFeature.utils.js +11 -8
- package/dist/core/cells/coreCellsFeature.utils.js.map +1 -1
- package/dist/core/columns/constructColumn.cjs +6 -4
- package/dist/core/columns/constructColumn.cjs.map +1 -1
- package/dist/core/columns/constructColumn.js +6 -4
- package/dist/core/columns/constructColumn.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.types.d.cts +7 -6
- package/dist/core/columns/coreColumnsFeature.types.d.ts +7 -6
- package/dist/core/columns/coreColumnsFeature.utils.cjs +47 -29
- package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.d.cts +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.d.ts +37 -27
- package/dist/core/columns/coreColumnsFeature.utils.js +47 -29
- package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
- package/dist/core/headers/buildHeaderGroups.cjs +27 -19
- package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.js +27 -19
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- package/dist/core/headers/constructHeader.cjs +4 -3
- package/dist/core/headers/constructHeader.cjs.map +1 -1
- package/dist/core/headers/constructHeader.js +4 -3
- package/dist/core/headers/constructHeader.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.cjs +1 -6
- package/dist/core/headers/coreHeadersFeature.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.js +2 -7
- package/dist/core/headers/coreHeadersFeature.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.types.d.cts +6 -4
- package/dist/core/headers/coreHeadersFeature.types.d.ts +6 -4
- package/dist/core/headers/coreHeadersFeature.utils.cjs +43 -36
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.d.cts +24 -19
- package/dist/core/headers/coreHeadersFeature.utils.d.ts +24 -19
- package/dist/core/headers/coreHeadersFeature.utils.js +44 -37
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/reactivity/coreReactivityFeature.types.d.cts +4 -0
- package/dist/core/reactivity/coreReactivityFeature.types.d.ts +4 -0
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.js +48 -36
- package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
- package/dist/core/rows/constructRow.cjs +8 -6
- package/dist/core/rows/constructRow.cjs.map +1 -1
- package/dist/core/rows/constructRow.js +8 -6
- package/dist/core/rows/constructRow.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +4 -4
- package/dist/core/rows/coreRowsFeature.types.d.ts +4 -4
- package/dist/core/rows/coreRowsFeature.utils.cjs +43 -32
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +34 -28
- package/dist/core/rows/coreRowsFeature.utils.d.ts +34 -28
- package/dist/core/rows/coreRowsFeature.utils.js +43 -32
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/core/table/constructTable.cjs +9 -5
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +9 -5
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/core/table/coreTablesFeature.types.d.cts +6 -2
- package/dist/core/table/coreTablesFeature.types.d.ts +6 -2
- package/dist/core/table/coreTablesFeature.utils.cjs +7 -3
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +2 -2
- package/dist/core/table/coreTablesFeature.utils.d.ts +2 -2
- package/dist/core/table/coreTablesFeature.utils.js +7 -3
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.cts +16 -10
- package/dist/features/column-faceting/columnFacetingFeature.types.d.ts +16 -10
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +26 -18
- package/dist/features/column-faceting/columnFacetingFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs +8 -5
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.js +8 -5
- package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs +8 -3
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js +8 -3
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs +7 -4
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.js +7 -4
- package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +21 -11
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +21 -11
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +39 -28
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +11 -5
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.js +11 -5
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +18 -14
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +18 -14
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +55 -43
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.types.d.cts +14 -5
- package/dist/features/column-ordering/columnOrderingFeature.types.d.ts +14 -5
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs +46 -29
- package/dist/features/column-ordering/columnOrderingFeature.utils.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.cts +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.ts +30 -23
- package/dist/features/column-ordering/columnOrderingFeature.utils.js +46 -29
- package/dist/features/column-ordering/columnOrderingFeature.utils.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.cts +43 -31
- package/dist/features/column-pinning/columnPinningFeature.types.d.ts +43 -31
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs +152 -115
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +116 -95
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +116 -95
- package/dist/features/column-pinning/columnPinningFeature.utils.js +153 -116
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.types.d.cts +9 -9
- package/dist/features/column-resizing/columnResizingFeature.types.d.ts +9 -9
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.d.cts +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.d.ts +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.js +28 -19
- package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.cjs +28 -4
- package/dist/features/column-sizing/columnSizingFeature.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.js +28 -4
- package/dist/features/column-sizing/columnSizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.types.d.cts +19 -12
- package/dist/features/column-sizing/columnSizingFeature.types.d.ts +19 -12
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.js +52 -41
- package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.cjs +23 -14
- package/dist/features/column-visibility/columnVisibilityFeature.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.js +24 -15
- package/dist/features/column-visibility/columnVisibilityFeature.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.cts +19 -12
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +19 -12
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +91 -52
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +63 -40
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +63 -40
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +91 -53
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.types.d.cts +10 -5
- package/dist/features/global-filtering/globalFilteringFeature.types.d.ts +10 -5
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.js +20 -14
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.cts +16 -15
- package/dist/features/row-expanding/rowExpandingFeature.types.d.ts +16 -15
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +58 -43
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.cts +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.ts +56 -41
- package/dist/features/row-expanding/rowExpandingFeature.utils.js +58 -43
- package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.cts +19 -12
- package/dist/features/row-pagination/rowPaginationFeature.types.d.ts +19 -12
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.cts +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.ts +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.js +49 -32
- package/dist/features/row-pagination/rowPaginationFeature.utils.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.types.d.cts +12 -8
- package/dist/features/row-pinning/rowPinningFeature.types.d.ts +12 -8
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs +52 -36
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.d.cts +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.d.ts +39 -29
- package/dist/features/row-pinning/rowPinningFeature.utils.js +52 -36
- package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.cts +30 -24
- package/dist/features/row-selection/rowSelectionFeature.types.d.ts +30 -24
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +95 -72
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +89 -69
- package/dist/features/row-selection/rowSelectionFeature.utils.js +95 -72
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +13 -8
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.js +13 -8
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +10 -8
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +10 -8
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +63 -46
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.d.cts +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.d.ts +61 -44
- package/dist/features/row-sorting/rowSortingFeature.utils.js +63 -46
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/fns/aggregationFns.cjs +47 -16
- package/dist/fns/aggregationFns.cjs.map +1 -1
- package/dist/fns/aggregationFns.d.cts +33 -9
- package/dist/fns/aggregationFns.d.ts +33 -9
- package/dist/fns/aggregationFns.js +47 -17
- package/dist/fns/aggregationFns.js.map +1 -1
- package/dist/fns/filterFns.cjs +48 -17
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.d.cts +42 -15
- package/dist/fns/filterFns.d.ts +42 -15
- package/dist/fns/filterFns.js +48 -17
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/helpers/columnHelper.cjs +9 -4
- package/dist/helpers/columnHelper.cjs.map +1 -1
- package/dist/helpers/columnHelper.d.cts +9 -4
- package/dist/helpers/columnHelper.d.ts +9 -4
- package/dist/helpers/columnHelper.js +9 -4
- package/dist/helpers/columnHelper.js.map +1 -1
- package/dist/helpers/tableOptions.cjs.map +1 -1
- package/dist/helpers/tableOptions.d.cts +12 -9
- package/dist/helpers/tableOptions.d.ts +12 -9
- package/dist/helpers/tableOptions.js.map +1 -1
- package/dist/index.cjs +0 -4
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/static-functions.cjs +1 -0
- package/dist/static-functions.d.cts +2 -2
- package/dist/static-functions.d.ts +2 -2
- package/dist/static-functions.js +2 -2
- package/dist/store-reactivity-bindings.cjs +1 -0
- package/dist/store-reactivity-bindings.cjs.map +1 -1
- package/dist/store-reactivity-bindings.js +1 -0
- package/dist/store-reactivity-bindings.js.map +1 -1
- package/dist/types/ColumnDef.d.cts +38 -0
- package/dist/types/ColumnDef.d.ts +38 -0
- package/dist/types/TableOptions.d.cts +15 -0
- package/dist/types/TableOptions.d.ts +15 -0
- package/dist/types/TableState.d.cts +12 -0
- package/dist/types/TableState.d.ts +12 -0
- package/dist/utils.cjs +18 -39
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -23
- package/dist/utils.d.ts +1 -23
- package/dist/utils.js +19 -36
- package/dist/utils.js.map +1 -1
- package/package.json +5 -3
- package/skills/column-definitions/SKILL.md +333 -0
- package/skills/column-layout/SKILL.md +328 -0
- package/skills/column-layout/references/subsystems.md +220 -0
- package/skills/customizing-feature-behavior/SKILL.md +416 -0
- package/skills/filtering/SKILL.md +357 -0
- package/skills/filtering/references/faceting-and-fuzzy.md +191 -0
- package/skills/grouping/SKILL.md +448 -0
- package/skills/migrate-v8-to-v9/SKILL.md +495 -0
- package/skills/pagination/SKILL.md +385 -0
- package/skills/row-expanding/SKILL.md +348 -0
- package/skills/row-pinning/SKILL.md +269 -0
- package/skills/row-selection/SKILL.md +391 -0
- package/skills/setup/SKILL.md +400 -0
- package/skills/sorting/SKILL.md +344 -0
- package/skills/state-management/SKILL.md +388 -0
- package/src/core/cells/constructCell.ts +3 -2
- package/src/core/cells/coreCellsFeature.utils.ts +11 -8
- package/src/core/columns/constructColumn.ts +5 -3
- package/src/core/columns/coreColumnsFeature.types.ts +7 -6
- package/src/core/columns/coreColumnsFeature.utils.ts +43 -29
- package/src/core/headers/buildHeaderGroups.ts +29 -30
- package/src/core/headers/constructHeader.ts +3 -2
- package/src/core/headers/coreHeadersFeature.ts +2 -27
- package/src/core/headers/coreHeadersFeature.types.ts +6 -4
- package/src/core/headers/coreHeadersFeature.utils.ts +52 -61
- package/src/core/reactivity/coreReactivityFeature.types.ts +4 -0
- package/src/core/row-models/coreRowModelsFeature.utils.ts +48 -36
- package/src/core/rows/constructRow.ts +6 -4
- package/src/core/rows/coreRowsFeature.types.ts +4 -4
- package/src/core/rows/coreRowsFeature.utils.ts +45 -32
- package/src/core/table/constructTable.ts +6 -4
- package/src/core/table/coreTablesFeature.types.ts +6 -2
- package/src/core/table/coreTablesFeature.utils.ts +5 -3
- package/src/features/column-faceting/columnFacetingFeature.types.ts +16 -10
- package/src/features/column-faceting/columnFacetingFeature.utils.ts +26 -18
- package/src/features/column-faceting/createFacetedMinMaxValues.ts +8 -10
- package/src/features/column-faceting/createFacetedRowModel.ts +10 -6
- package/src/features/column-faceting/createFacetedUniqueValues.ts +4 -3
- package/src/features/column-filtering/columnFilteringFeature.types.ts +21 -11
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +39 -28
- package/src/features/column-filtering/createFilteredRowModel.ts +14 -8
- package/src/features/column-grouping/columnGroupingFeature.types.ts +18 -14
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +55 -43
- package/src/features/column-ordering/columnOrderingFeature.types.ts +14 -5
- package/src/features/column-ordering/columnOrderingFeature.utils.ts +44 -29
- package/src/features/column-pinning/columnPinningFeature.types.ts +43 -31
- package/src/features/column-pinning/columnPinningFeature.utils.ts +164 -128
- package/src/features/column-resizing/columnResizingFeature.types.ts +9 -9
- package/src/features/column-resizing/columnResizingFeature.utils.ts +28 -19
- package/src/features/column-sizing/columnSizingFeature.ts +16 -0
- package/src/features/column-sizing/columnSizingFeature.types.ts +19 -12
- package/src/features/column-sizing/columnSizingFeature.utils.ts +52 -41
- package/src/features/column-visibility/columnVisibilityFeature.ts +8 -0
- package/src/features/column-visibility/columnVisibilityFeature.types.ts +22 -12
- package/src/features/column-visibility/columnVisibilityFeature.utils.ts +101 -56
- package/src/features/global-filtering/globalFilteringFeature.types.ts +10 -5
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +20 -14
- package/src/features/row-expanding/rowExpandingFeature.types.ts +16 -15
- package/src/features/row-expanding/rowExpandingFeature.utils.ts +58 -43
- package/src/features/row-pagination/rowPaginationFeature.types.ts +19 -12
- package/src/features/row-pagination/rowPaginationFeature.utils.ts +49 -32
- package/src/features/row-pinning/rowPinningFeature.types.ts +12 -8
- package/src/features/row-pinning/rowPinningFeature.utils.ts +59 -47
- package/src/features/row-selection/rowSelectionFeature.types.ts +30 -24
- package/src/features/row-selection/rowSelectionFeature.utils.ts +109 -88
- package/src/features/row-sorting/createSortedRowModel.ts +16 -13
- package/src/features/row-sorting/rowSortingFeature.types.ts +10 -8
- package/src/features/row-sorting/rowSortingFeature.utils.ts +63 -46
- package/src/fns/aggregationFns.ts +53 -17
- package/src/fns/filterFns.ts +48 -17
- package/src/helpers/columnHelper.ts +9 -4
- package/src/helpers/tableOptions.ts +12 -9
- package/src/store-reactivity-bindings.ts +1 -0
- package/src/types/ColumnDef.ts +38 -0
- package/src/types/TableOptions.ts +15 -0
- package/src/types/TableState.ts +12 -0
- package/src/utils.ts +19 -46
|
@@ -38,7 +38,9 @@ function _createFilteredRowModel(table) {
|
|
|
38
38
|
const columnFilters = (_table$atoms$columnFi2 = table.atoms.columnFilters) === null || _table$atoms$columnFi2 === void 0 ? void 0 : _table$atoms$columnFi2.get();
|
|
39
39
|
const globalFilter = (_table$atoms$globalFi2 = table.atoms.globalFilter) === null || _table$atoms$globalFi2 === void 0 ? void 0 : _table$atoms$globalFi2.get();
|
|
40
40
|
if (!rowModel.rows.length || !(columnFilters === null || columnFilters === void 0 ? void 0 : columnFilters.length) && !globalFilter) {
|
|
41
|
-
|
|
41
|
+
const flatRows = rowModel.flatRows;
|
|
42
|
+
for (let i = 0; i < flatRows.length; i++) {
|
|
43
|
+
const row = flatRows[i];
|
|
42
44
|
row.columnFilters = {};
|
|
43
45
|
row.columnFiltersMeta = {};
|
|
44
46
|
}
|
|
@@ -71,16 +73,20 @@ function _createFilteredRowModel(table) {
|
|
|
71
73
|
});
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
const flatRows = rowModel.flatRows;
|
|
77
|
+
for (let i = 0; i < flatRows.length; i++) {
|
|
78
|
+
const row = flatRows[i];
|
|
75
79
|
row.columnFilters = {};
|
|
76
|
-
if (resolvedColumnFilters.length) for (
|
|
80
|
+
if (resolvedColumnFilters.length) for (let j = 0; j < resolvedColumnFilters.length; j++) {
|
|
81
|
+
const currentColumnFilter = resolvedColumnFilters[j];
|
|
77
82
|
const id = currentColumnFilter.id;
|
|
78
83
|
row.columnFilters[id] = currentColumnFilter.filterFn(row, id, currentColumnFilter.resolvedValue, (filterMeta) => {
|
|
79
84
|
!row.columnFiltersMeta ? row.columnFiltersMeta = {} : row.columnFiltersMeta[id] = filterMeta;
|
|
80
85
|
});
|
|
81
86
|
}
|
|
82
87
|
if (resolvedGlobalFilters.length) {
|
|
83
|
-
for (
|
|
88
|
+
for (let j = 0; j < resolvedGlobalFilters.length; j++) {
|
|
89
|
+
const currentGlobalFilter = resolvedGlobalFilters[j];
|
|
84
90
|
const id = currentGlobalFilter.id;
|
|
85
91
|
if (currentGlobalFilter.filterFn(row, id, currentGlobalFilter.resolvedValue, (filterMeta) => {
|
|
86
92
|
!row.columnFiltersMeta ? row.columnFiltersMeta = {} : row.columnFiltersMeta[id] = filterMeta;
|
|
@@ -93,7 +99,7 @@ function _createFilteredRowModel(table) {
|
|
|
93
99
|
}
|
|
94
100
|
}
|
|
95
101
|
const filterRowsImpl = (row) => {
|
|
96
|
-
for (
|
|
102
|
+
for (let i = 0; i < filterableIds.length; i++) if (row.columnFilters[filterableIds[i]] === false) return false;
|
|
97
103
|
return true;
|
|
98
104
|
};
|
|
99
105
|
return filterRows(rowModel.rows, filterRowsImpl, table);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFilteredRowModel.js","names":[],"sources":["../../../src/features/column-filtering/createFilteredRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport {\n column_getCanGlobalFilter,\n table_getGlobalFilterFn,\n} from '../global-filtering/globalFilteringFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { filterRows } from './filterRowsUtils'\nimport { column_getFilterFn } from './columnFilteringFeature.utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type {\n FilterFn,\n FilterFns,\n ResolvedColumnFilter,\n Row_ColumnFiltering,\n} from './columnFilteringFeature.types'\n\n/**\n * Creates a memoized filtered row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFilteredRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n filterFns: Record<keyof FilterFns, FilterFn<TFeatures, TData>>,\n): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table: Table_Internal<TFeatures, TData> = _table\n if (!table._rowModelFns.filterFns) table._rowModelFns.filterFns = filterFns\n return tableMemo({\n feature: 'columnFilteringFeature',\n table,\n fnName: 'table.getFilteredRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n ],\n fn: () => _createFilteredRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createFilteredRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreFilteredRowModel()\n const columnFilters = table.atoms.columnFilters?.get()\n const globalFilter = table.atoms.globalFilter?.get()\n\n if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n
|
|
1
|
+
{"version":3,"file":"createFilteredRowModel.js","names":[],"sources":["../../../src/features/column-filtering/createFilteredRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport {\n column_getCanGlobalFilter,\n table_getGlobalFilterFn,\n} from '../global-filtering/globalFilteringFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { filterRows } from './filterRowsUtils'\nimport { column_getFilterFn } from './columnFilteringFeature.utils'\nimport type { RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type {\n FilterFn,\n FilterFns,\n ResolvedColumnFilter,\n Row_ColumnFiltering,\n} from './columnFilteringFeature.types'\n\n/**\n * Creates a memoized filtered row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFilteredRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n filterFns: Record<keyof FilterFns, FilterFn<TFeatures, TData>>,\n): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table: Table_Internal<TFeatures, TData> = _table\n if (!table._rowModelFns.filterFns) table._rowModelFns.filterFns = filterFns\n return tableMemo({\n feature: 'columnFilteringFeature',\n table,\n fnName: 'table.getFilteredRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n ],\n fn: () => _createFilteredRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createFilteredRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreFilteredRowModel()\n const columnFilters = table.atoms.columnFilters?.get()\n const globalFilter = table.atoms.globalFilter?.get()\n\n if (!rowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n const flatRows = rowModel.flatRows as Array<\n Row<TFeatures, TData> & Partial<Row_ColumnFiltering<TFeatures, TData>>\n >\n for (let i = 0; i < flatRows.length; i++) {\n const row = flatRows[i]!\n row.columnFilters = {}\n row.columnFiltersMeta = {}\n }\n return rowModel\n }\n\n const resolvedColumnFilters: Array<ResolvedColumnFilter<TFeatures, TData>> =\n []\n const resolvedGlobalFilters: Array<ResolvedColumnFilter<TFeatures, TData>> =\n []\n\n columnFilters?.forEach((columnFilter) => {\n const column = table_getColumn(table, columnFilter.id)\n\n if (!column) {\n return\n }\n\n const filterFn = column_getFilterFn(column)!\n\n resolvedColumnFilters.push({\n id: columnFilter.id,\n filterFn,\n resolvedValue:\n filterFn.resolveFilterValue?.(columnFilter.value) ?? columnFilter.value,\n })\n })\n\n const filterableIds = columnFilters?.map((d) => d.id) ?? []\n\n const globalFilterFn = table_getGlobalFilterFn(table)\n\n const globallyFilterableColumns = table\n .getAllLeafColumns()\n .filter((column) => column_getCanGlobalFilter(column))\n\n if (globalFilter && globalFilterFn && globallyFilterableColumns.length) {\n filterableIds.push('__global__')\n\n globallyFilterableColumns.forEach((column) => {\n resolvedGlobalFilters.push({\n id: column.id,\n filterFn: globalFilterFn,\n resolvedValue:\n globalFilterFn.resolveFilterValue?.(globalFilter) ?? globalFilter,\n })\n })\n }\n\n // Flag the pre-filtered row model with each filter state\n const flatRows = rowModel.flatRows as Array<\n Row<TFeatures, TData> & Partial<Row_ColumnFiltering<TFeatures, TData>>\n >\n for (let i = 0; i < flatRows.length; i++) {\n const row = flatRows[i]!\n row.columnFilters = {}\n\n if (resolvedColumnFilters.length) {\n for (let j = 0; j < resolvedColumnFilters.length; j++) {\n const currentColumnFilter = resolvedColumnFilters[j]!\n const id = currentColumnFilter.id\n\n // Tag the row with the column filter state\n row.columnFilters[id] = currentColumnFilter.filterFn(\n row,\n id,\n currentColumnFilter.resolvedValue,\n (filterMeta) => {\n !row.columnFiltersMeta\n ? (row.columnFiltersMeta = {})\n : (row.columnFiltersMeta[id] = filterMeta)\n },\n )\n }\n }\n\n if (resolvedGlobalFilters.length) {\n for (let j = 0; j < resolvedGlobalFilters.length; j++) {\n const currentGlobalFilter = resolvedGlobalFilters[j]!\n const id = currentGlobalFilter.id\n // Tag the row with the first truthy global filter state\n if (\n currentGlobalFilter.filterFn(\n row,\n id,\n currentGlobalFilter.resolvedValue,\n (filterMeta) => {\n !row.columnFiltersMeta\n ? (row.columnFiltersMeta = {})\n : (row.columnFiltersMeta[id] = filterMeta)\n },\n )\n ) {\n row.columnFilters.__global__ = true\n break\n }\n }\n\n if (row.columnFilters.__global__ !== true) {\n row.columnFilters.__global__ = false\n }\n }\n }\n\n const filterRowsImpl = (\n row: Row<TFeatures, TData> & Row_ColumnFiltering<TFeatures, TData>,\n ) => {\n // Horizontally filter rows through each column\n for (let i = 0; i < filterableIds.length; i++) {\n if (row.columnFilters[filterableIds[i]!] === false) {\n return false\n }\n }\n return true\n }\n\n // Filter final rows using all of the active filters\n return filterRows(rowModel.rows, filterRowsImpl as any, table)\n}\n"],"mappings":";;;;;;;;;;;;;AA0BA,SAAgB,uBAId,WACsE;CACtE,QAAQ,WAAW;EACjB,MAAM,QAA0C;EAChD,IAAI,CAAC,MAAM,aAAa,WAAW,MAAM,aAAa,YAAY;EAClE,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;;KACd,MAAM,wBAAwB;8BAC9B,MAAM,MAAM,6FAAe,KAAK;8BAChC,MAAM,MAAM,4FAAc,KAAK;KAChC;;GACD,UAAU,wBAAwB,MAAM;GACxC,qBAAqB,yBAAyB,MAAM;GACrD,CAAC;;;AAIN,SAAS,wBAGP,OAAqE;;CACrE,MAAM,WAAW,MAAM,wBAAwB;CAC/C,MAAM,0CAAgB,MAAM,MAAM,+FAAe,KAAK;CACtD,MAAM,yCAAe,MAAM,MAAM,8FAAc,KAAK;CAEpD,IAAI,CAAC,SAAS,KAAK,UAAW,gEAAC,cAAe,WAAU,CAAC,cAAe;EACtE,MAAM,WAAW,SAAS;EAG1B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,MAAM,SAAS;GACrB,IAAI,gBAAgB,EAAE;GACtB,IAAI,oBAAoB,EAAE;;EAE5B,OAAO;;CAGT,MAAM,wBACJ,EAAE;CACJ,MAAM,wBACJ,EAAE;CAEJ,oEAAe,SAAS,iBAAiB;;EACvC,MAAM,SAAS,gBAAgB,OAAO,aAAa,GAAG;EAEtD,IAAI,CAAC,QACH;EAGF,MAAM,WAAW,mBAAmB,OAAO;EAE3C,sBAAsB,KAAK;GACzB,IAAI,aAAa;GACjB;GACA,yCACE,SAAS,iHAAqB,aAAa,MAAM,KAAI,aAAa;GACrE,CAAC;GACF;CAEF,MAAM,+EAAgB,cAAe,KAAK,MAAM,EAAE,GAAG,KAAI,EAAE;CAE3D,MAAM,iBAAiB,wBAAwB,MAAM;CAErD,MAAM,4BAA4B,MAC/B,mBAAmB,CACnB,QAAQ,WAAW,0BAA0B,OAAO,CAAC;CAExD,IAAI,gBAAgB,kBAAkB,0BAA0B,QAAQ;EACtE,cAAc,KAAK,aAAa;EAEhC,0BAA0B,SAAS,WAAW;;GAC5C,sBAAsB,KAAK;IACzB,IAAI,OAAO;IACX,UAAU;IACV,yCACE,eAAe,uHAAqB,aAAa,KAAI;IACxD,CAAC;IACF;;CAIJ,MAAM,WAAW,SAAS;CAG1B,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;EACxC,MAAM,MAAM,SAAS;EACrB,IAAI,gBAAgB,EAAE;EAEtB,IAAI,sBAAsB,QACxB,KAAK,IAAI,IAAI,GAAG,IAAI,sBAAsB,QAAQ,KAAK;GACrD,MAAM,sBAAsB,sBAAsB;GAClD,MAAM,KAAK,oBAAoB;GAG/B,IAAI,cAAc,MAAM,oBAAoB,SAC1C,KACA,IACA,oBAAoB,gBACnB,eAAe;IACd,CAAC,IAAI,oBACA,IAAI,oBAAoB,EAAE,GAC1B,IAAI,kBAAkB,MAAM;KAEpC;;EAIL,IAAI,sBAAsB,QAAQ;GAChC,KAAK,IAAI,IAAI,GAAG,IAAI,sBAAsB,QAAQ,KAAK;IACrD,MAAM,sBAAsB,sBAAsB;IAClD,MAAM,KAAK,oBAAoB;IAE/B,IACE,oBAAoB,SAClB,KACA,IACA,oBAAoB,gBACnB,eAAe;KACd,CAAC,IAAI,oBACA,IAAI,oBAAoB,EAAE,GAC1B,IAAI,kBAAkB,MAAM;MAEpC,EACD;KACA,IAAI,cAAc,aAAa;KAC/B;;;GAIJ,IAAI,IAAI,cAAc,eAAe,MACnC,IAAI,cAAc,aAAa;;;CAKrC,MAAM,kBACJ,QACG;EAEH,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KACxC,IAAI,IAAI,cAAc,cAAc,QAAS,OAC3C,OAAO;EAGX,OAAO;;CAIT,OAAO,WAAW,SAAS,MAAM,gBAAuB,MAAM"}
|
|
@@ -29,7 +29,9 @@ interface ColumnDef_ColumnGrouping<TFeatures extends TableFeatures, TData extend
|
|
|
29
29
|
*/
|
|
30
30
|
aggregationFn?: AggregationFnOption<TFeatures, TData>;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Allows this column to be added to grouping state.
|
|
33
|
+
*
|
|
34
|
+
* Defaults to `true`; table-level `enableGrouping` must also allow grouping.
|
|
33
35
|
*/
|
|
34
36
|
enableGrouping?: boolean;
|
|
35
37
|
/**
|
|
@@ -47,15 +49,15 @@ interface Column_ColumnGrouping<TFeatures extends TableFeatures, TData extends R
|
|
|
47
49
|
*/
|
|
48
50
|
getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
49
51
|
/**
|
|
50
|
-
*
|
|
52
|
+
* Checks whether this column can currently be grouped.
|
|
51
53
|
*/
|
|
52
54
|
getCanGroup: () => boolean;
|
|
53
55
|
/**
|
|
54
|
-
*
|
|
56
|
+
* Finds this column's position in the ordered grouping state.
|
|
55
57
|
*/
|
|
56
58
|
getGroupedIndex: () => number;
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
60
|
+
* Checks whether this column id is present in grouping state.
|
|
59
61
|
*/
|
|
60
62
|
getIsGrouped: () => boolean;
|
|
61
63
|
/**
|
|
@@ -70,11 +72,11 @@ interface Column_ColumnGrouping<TFeatures extends TableFeatures, TData extends R
|
|
|
70
72
|
interface Row_ColumnGrouping {
|
|
71
73
|
_groupingValuesCache: Record<string, any>;
|
|
72
74
|
/**
|
|
73
|
-
*
|
|
75
|
+
* Reads the value used to group this row for a column id.
|
|
74
76
|
*/
|
|
75
77
|
getGroupingValue: (columnId: string) => unknown;
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
79
|
+
* Checks whether this row represents a grouped row.
|
|
78
80
|
*/
|
|
79
81
|
getIsGrouped: () => boolean;
|
|
80
82
|
/**
|
|
@@ -88,15 +90,15 @@ interface Row_ColumnGrouping {
|
|
|
88
90
|
}
|
|
89
91
|
interface Cell_ColumnGrouping {
|
|
90
92
|
/**
|
|
91
|
-
*
|
|
93
|
+
* Checks whether this cell should render an aggregated value.
|
|
92
94
|
*/
|
|
93
95
|
getIsAggregated: () => boolean;
|
|
94
96
|
/**
|
|
95
|
-
*
|
|
97
|
+
* Checks whether this cell represents the active grouping column.
|
|
96
98
|
*/
|
|
97
99
|
getIsGrouped: () => boolean;
|
|
98
100
|
/**
|
|
99
|
-
*
|
|
101
|
+
* Checks whether this cell is hidden as a grouping placeholder.
|
|
100
102
|
*/
|
|
101
103
|
getIsPlaceholder: () => boolean;
|
|
102
104
|
}
|
|
@@ -106,7 +108,7 @@ interface ColumnDefaultOptions {
|
|
|
106
108
|
}
|
|
107
109
|
interface TableOptions_ColumnGrouping {
|
|
108
110
|
/**
|
|
109
|
-
*
|
|
111
|
+
* Allows columns to be grouped for this table.
|
|
110
112
|
*/
|
|
111
113
|
enableGrouping?: boolean;
|
|
112
114
|
/**
|
|
@@ -127,21 +129,23 @@ interface TableOptions_ColumnGrouping {
|
|
|
127
129
|
type GroupingColumnMode = false | 'reorder' | 'remove';
|
|
128
130
|
interface Table_ColumnGrouping<TFeatures extends TableFeatures, TData extends RowData> {
|
|
129
131
|
/**
|
|
130
|
-
* Resets
|
|
132
|
+
* Resets `grouping` to `initialState.grouping`.
|
|
133
|
+
*
|
|
134
|
+
* Pass `true` to ignore initial state and reset to `[]`.
|
|
131
135
|
*/
|
|
132
136
|
resetGrouping: (defaultState?: boolean) => void;
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
138
|
+
* Updates grouping state with a next ordered id array or updater function.
|
|
135
139
|
*/
|
|
136
140
|
setGrouping: (updater: Updater<GroupingState>) => void;
|
|
137
141
|
}
|
|
138
142
|
interface Table_RowModels_Grouped<TFeatures extends TableFeatures, TData extends RowData> {
|
|
139
143
|
/**
|
|
140
|
-
*
|
|
144
|
+
* Resolves the row model after grouping and aggregation have been applied.
|
|
141
145
|
*/
|
|
142
146
|
getGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
143
147
|
/**
|
|
144
|
-
*
|
|
148
|
+
* Reads the row model immediately before grouping.
|
|
145
149
|
*/
|
|
146
150
|
getPreGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
147
151
|
}
|
|
@@ -29,7 +29,9 @@ interface ColumnDef_ColumnGrouping<TFeatures extends TableFeatures, TData extend
|
|
|
29
29
|
*/
|
|
30
30
|
aggregationFn?: AggregationFnOption<TFeatures, TData>;
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Allows this column to be added to grouping state.
|
|
33
|
+
*
|
|
34
|
+
* Defaults to `true`; table-level `enableGrouping` must also allow grouping.
|
|
33
35
|
*/
|
|
34
36
|
enableGrouping?: boolean;
|
|
35
37
|
/**
|
|
@@ -47,15 +49,15 @@ interface Column_ColumnGrouping<TFeatures extends TableFeatures, TData extends R
|
|
|
47
49
|
*/
|
|
48
50
|
getAutoAggregationFn: () => AggregationFn<TFeatures, TData> | undefined;
|
|
49
51
|
/**
|
|
50
|
-
*
|
|
52
|
+
* Checks whether this column can currently be grouped.
|
|
51
53
|
*/
|
|
52
54
|
getCanGroup: () => boolean;
|
|
53
55
|
/**
|
|
54
|
-
*
|
|
56
|
+
* Finds this column's position in the ordered grouping state.
|
|
55
57
|
*/
|
|
56
58
|
getGroupedIndex: () => number;
|
|
57
59
|
/**
|
|
58
|
-
*
|
|
60
|
+
* Checks whether this column id is present in grouping state.
|
|
59
61
|
*/
|
|
60
62
|
getIsGrouped: () => boolean;
|
|
61
63
|
/**
|
|
@@ -70,11 +72,11 @@ interface Column_ColumnGrouping<TFeatures extends TableFeatures, TData extends R
|
|
|
70
72
|
interface Row_ColumnGrouping {
|
|
71
73
|
_groupingValuesCache: Record<string, any>;
|
|
72
74
|
/**
|
|
73
|
-
*
|
|
75
|
+
* Reads the value used to group this row for a column id.
|
|
74
76
|
*/
|
|
75
77
|
getGroupingValue: (columnId: string) => unknown;
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
79
|
+
* Checks whether this row represents a grouped row.
|
|
78
80
|
*/
|
|
79
81
|
getIsGrouped: () => boolean;
|
|
80
82
|
/**
|
|
@@ -88,15 +90,15 @@ interface Row_ColumnGrouping {
|
|
|
88
90
|
}
|
|
89
91
|
interface Cell_ColumnGrouping {
|
|
90
92
|
/**
|
|
91
|
-
*
|
|
93
|
+
* Checks whether this cell should render an aggregated value.
|
|
92
94
|
*/
|
|
93
95
|
getIsAggregated: () => boolean;
|
|
94
96
|
/**
|
|
95
|
-
*
|
|
97
|
+
* Checks whether this cell represents the active grouping column.
|
|
96
98
|
*/
|
|
97
99
|
getIsGrouped: () => boolean;
|
|
98
100
|
/**
|
|
99
|
-
*
|
|
101
|
+
* Checks whether this cell is hidden as a grouping placeholder.
|
|
100
102
|
*/
|
|
101
103
|
getIsPlaceholder: () => boolean;
|
|
102
104
|
}
|
|
@@ -106,7 +108,7 @@ interface ColumnDefaultOptions {
|
|
|
106
108
|
}
|
|
107
109
|
interface TableOptions_ColumnGrouping {
|
|
108
110
|
/**
|
|
109
|
-
*
|
|
111
|
+
* Allows columns to be grouped for this table.
|
|
110
112
|
*/
|
|
111
113
|
enableGrouping?: boolean;
|
|
112
114
|
/**
|
|
@@ -127,21 +129,23 @@ interface TableOptions_ColumnGrouping {
|
|
|
127
129
|
type GroupingColumnMode = false | 'reorder' | 'remove';
|
|
128
130
|
interface Table_ColumnGrouping<TFeatures extends TableFeatures, TData extends RowData> {
|
|
129
131
|
/**
|
|
130
|
-
* Resets
|
|
132
|
+
* Resets `grouping` to `initialState.grouping`.
|
|
133
|
+
*
|
|
134
|
+
* Pass `true` to ignore initial state and reset to `[]`.
|
|
131
135
|
*/
|
|
132
136
|
resetGrouping: (defaultState?: boolean) => void;
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
138
|
+
* Updates grouping state with a next ordered id array or updater function.
|
|
135
139
|
*/
|
|
136
140
|
setGrouping: (updater: Updater<GroupingState>) => void;
|
|
137
141
|
}
|
|
138
142
|
interface Table_RowModels_Grouped<TFeatures extends TableFeatures, TData extends RowData> {
|
|
139
143
|
/**
|
|
140
|
-
*
|
|
144
|
+
* Resolves the row model after grouping and aggregation have been applied.
|
|
141
145
|
*/
|
|
142
146
|
getGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
143
147
|
/**
|
|
144
|
-
*
|
|
148
|
+
* Reads the row model immediately before grouping.
|
|
145
149
|
*/
|
|
146
150
|
getPreGroupedRowModel: () => RowModel<TFeatures, TData>;
|
|
147
151
|
}
|
|
@@ -3,22 +3,24 @@ const require_coreColumnsFeature_utils = require('../../core/columns/coreColumns
|
|
|
3
3
|
|
|
4
4
|
//#region src/features/column-grouping/columnGroupingFeature.utils.ts
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Creates the default grouping state.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* The feature default is an empty array, meaning no columns are grouped. Reset
|
|
9
|
+
* APIs use this value when `defaultState` is `true`.
|
|
9
10
|
*
|
|
10
11
|
* @example
|
|
11
12
|
* ```ts
|
|
12
|
-
* const
|
|
13
|
+
* const grouping = getDefaultGroupingState()
|
|
13
14
|
* ```
|
|
14
15
|
*/
|
|
15
16
|
function getDefaultGroupingState() {
|
|
16
17
|
return [];
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* Adds or removes this column id from the grouping state.
|
|
20
21
|
*
|
|
21
|
-
*
|
|
22
|
+
* Existing grouped columns keep their order. A column already present in
|
|
23
|
+
* `state.grouping` is removed; otherwise it is appended.
|
|
22
24
|
*
|
|
23
25
|
* @example
|
|
24
26
|
* ```ts
|
|
@@ -32,26 +34,28 @@ function column_toggleGrouping(column) {
|
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
|
-
*
|
|
37
|
+
* Checks whether this column can be used for grouping.
|
|
36
38
|
*
|
|
37
|
-
*
|
|
39
|
+
* Grouping must be enabled at the column and table level, and the column must
|
|
40
|
+
* either have an accessor or provide `getGroupingValue`.
|
|
38
41
|
*
|
|
39
42
|
* @example
|
|
40
43
|
* ```ts
|
|
41
|
-
* const
|
|
44
|
+
* const canGroup = column_getCanGroup(column)
|
|
42
45
|
* ```
|
|
43
46
|
*/
|
|
44
47
|
function column_getCanGroup(column) {
|
|
45
48
|
return (column.columnDef.enableGrouping ?? true) && (column.table.options.enableGrouping ?? true) && (!!column.accessorFn || !!column.columnDef.getGroupingValue);
|
|
46
49
|
}
|
|
47
50
|
/**
|
|
48
|
-
*
|
|
51
|
+
* Checks whether this column id is present in `state.grouping`.
|
|
49
52
|
*
|
|
50
|
-
*
|
|
53
|
+
* The result only reflects grouping state, not whether the grouped row model has
|
|
54
|
+
* been calculated yet.
|
|
51
55
|
*
|
|
52
56
|
* @example
|
|
53
57
|
* ```ts
|
|
54
|
-
* const
|
|
58
|
+
* const isGrouped = column_getIsGrouped(column)
|
|
55
59
|
* ```
|
|
56
60
|
*/
|
|
57
61
|
function column_getIsGrouped(column) {
|
|
@@ -59,13 +63,13 @@ function column_getIsGrouped(column) {
|
|
|
59
63
|
return !!((_column$table$atoms$g = column.table.atoms.grouping) === null || _column$table$atoms$g === void 0 || (_column$table$atoms$g = _column$table$atoms$g.get()) === null || _column$table$atoms$g === void 0 ? void 0 : _column$table$atoms$g.includes(column.id));
|
|
60
64
|
}
|
|
61
65
|
/**
|
|
62
|
-
*
|
|
66
|
+
* Finds this column's position in the ordered grouping state.
|
|
63
67
|
*
|
|
64
|
-
*
|
|
68
|
+
* The result is `-1` when the column is not grouped.
|
|
65
69
|
*
|
|
66
70
|
* @example
|
|
67
71
|
* ```ts
|
|
68
|
-
* const
|
|
72
|
+
* const index = column_getGroupedIndex(column)
|
|
69
73
|
* ```
|
|
70
74
|
*/
|
|
71
75
|
function column_getGroupedIndex(column) {
|
|
@@ -73,13 +77,13 @@ function column_getGroupedIndex(column) {
|
|
|
73
77
|
return ((_column$table$atoms$g2 = column.table.atoms.grouping) === null || _column$table$atoms$g2 === void 0 || (_column$table$atoms$g2 = _column$table$atoms$g2.get()) === null || _column$table$atoms$g2 === void 0 ? void 0 : _column$table$atoms$g2.indexOf(column.id)) ?? -1;
|
|
74
78
|
}
|
|
75
79
|
/**
|
|
76
|
-
*
|
|
80
|
+
* Creates a header/control handler that toggles grouping for this column.
|
|
77
81
|
*
|
|
78
|
-
* The handler is
|
|
82
|
+
* The handler is a no-op when `column_getCanGroup(column)` is false.
|
|
79
83
|
*
|
|
80
84
|
* @example
|
|
81
85
|
* ```ts
|
|
82
|
-
* const
|
|
86
|
+
* const onClick = column_getToggleGroupingHandler(column)
|
|
83
87
|
* ```
|
|
84
88
|
*/
|
|
85
89
|
function column_getToggleGroupingHandler(column) {
|
|
@@ -90,13 +94,14 @@ function column_getToggleGroupingHandler(column) {
|
|
|
90
94
|
};
|
|
91
95
|
}
|
|
92
96
|
/**
|
|
93
|
-
*
|
|
97
|
+
* Chooses a built-in aggregation function from the first core row value.
|
|
94
98
|
*
|
|
95
|
-
*
|
|
99
|
+
* Numeric columns default to `sum`, date-like values default to `extent`, and
|
|
100
|
+
* other value types leave aggregation unspecified.
|
|
96
101
|
*
|
|
97
102
|
* @example
|
|
98
103
|
* ```ts
|
|
99
|
-
* const
|
|
104
|
+
* const aggregationFn = column_getAutoAggregationFn(column)
|
|
100
105
|
* ```
|
|
101
106
|
*/
|
|
102
107
|
function column_getAutoAggregationFn(column) {
|
|
@@ -107,13 +112,15 @@ function column_getAutoAggregationFn(column) {
|
|
|
107
112
|
if (Object.prototype.toString.call(value) === "[object Date]") return aggregationFns === null || aggregationFns === void 0 ? void 0 : aggregationFns.extent;
|
|
108
113
|
}
|
|
109
114
|
/**
|
|
110
|
-
*
|
|
115
|
+
* Resolves the aggregation function configured for a column.
|
|
111
116
|
*
|
|
112
|
-
*
|
|
117
|
+
* Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`
|
|
118
|
+
* delegates to `column_getAutoAggregationFn`, and string values are looked up in
|
|
119
|
+
* the table's aggregation function registry.
|
|
113
120
|
*
|
|
114
121
|
* @example
|
|
115
122
|
* ```ts
|
|
116
|
-
* const
|
|
123
|
+
* const aggregationFn = column_getAggregationFn(column)
|
|
117
124
|
* ```
|
|
118
125
|
*/
|
|
119
126
|
function column_getAggregationFn(column) {
|
|
@@ -121,13 +128,14 @@ function column_getAggregationFn(column) {
|
|
|
121
128
|
return require_utils.isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === "auto" ? column_getAutoAggregationFn(column) : aggregationFns === null || aggregationFns === void 0 ? void 0 : aggregationFns[column.columnDef.aggregationFn];
|
|
122
129
|
}
|
|
123
130
|
/**
|
|
124
|
-
*
|
|
131
|
+
* Routes a grouping updater through the table's grouping change handler.
|
|
125
132
|
*
|
|
126
|
-
* The updater
|
|
133
|
+
* The updater may be a next `GroupingState` array or a function of the previous
|
|
134
|
+
* grouping state, matching the instance `table.setGrouping` behavior.
|
|
127
135
|
*
|
|
128
136
|
* @example
|
|
129
137
|
* ```ts
|
|
130
|
-
* table_setGrouping(table, (old) => old)
|
|
138
|
+
* table_setGrouping(table, (old) => [...old, 'status'])
|
|
131
139
|
* ```
|
|
132
140
|
*/
|
|
133
141
|
function table_setGrouping(table, updater) {
|
|
@@ -135,9 +143,10 @@ function table_setGrouping(table, updater) {
|
|
|
135
143
|
(_table$options$onGrou = (_table$options = table.options).onGroupingChange) === null || _table$options$onGrou === void 0 || _table$options$onGrou.call(_table$options, updater);
|
|
136
144
|
}
|
|
137
145
|
/**
|
|
138
|
-
* Resets the
|
|
146
|
+
* Resets `grouping` to the configured initial state or feature default.
|
|
139
147
|
*
|
|
140
|
-
*
|
|
148
|
+
* With no argument, the reset clones `table.initialState.grouping` when it
|
|
149
|
+
* exists. Passing `true` ignores initial state and resets to `[]`.
|
|
141
150
|
*
|
|
142
151
|
* @example
|
|
143
152
|
* ```ts
|
|
@@ -149,26 +158,27 @@ function table_resetGrouping(table, defaultState) {
|
|
|
149
158
|
table_setGrouping(table, defaultState ? [] : require_utils.cloneState(table.initialState.grouping ?? []));
|
|
150
159
|
}
|
|
151
160
|
/**
|
|
152
|
-
*
|
|
161
|
+
* Checks whether this row was created as a grouped row.
|
|
153
162
|
*
|
|
154
|
-
*
|
|
163
|
+
* Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.
|
|
155
164
|
*
|
|
156
165
|
* @example
|
|
157
166
|
* ```ts
|
|
158
|
-
* const
|
|
167
|
+
* const isGrouped = row_getIsGrouped(row)
|
|
159
168
|
* ```
|
|
160
169
|
*/
|
|
161
170
|
function row_getIsGrouped(row) {
|
|
162
171
|
return !!row.groupingColumnId;
|
|
163
172
|
}
|
|
164
173
|
/**
|
|
165
|
-
*
|
|
174
|
+
* Reads and caches this row's grouping value for a column.
|
|
166
175
|
*
|
|
167
|
-
*
|
|
176
|
+
* `columnDef.getGroupingValue` wins when provided; otherwise the normal row
|
|
177
|
+
* accessor value is used.
|
|
168
178
|
*
|
|
169
179
|
* @example
|
|
170
180
|
* ```ts
|
|
171
|
-
* const
|
|
181
|
+
* const groupValue = row_getGroupingValue(row, 'status')
|
|
172
182
|
* ```
|
|
173
183
|
*/
|
|
174
184
|
function row_getGroupingValue(row, columnId) {
|
|
@@ -180,13 +190,13 @@ function row_getGroupingValue(row, columnId) {
|
|
|
180
190
|
return (_row$_groupingValuesC2 = row._groupingValuesCache) === null || _row$_groupingValuesC2 === void 0 ? void 0 : _row$_groupingValuesC2[columnId];
|
|
181
191
|
}
|
|
182
192
|
/**
|
|
183
|
-
*
|
|
193
|
+
* Checks whether this cell represents the grouped column for a grouped row.
|
|
184
194
|
*
|
|
185
|
-
* This is the
|
|
195
|
+
* This is the cell that usually renders the grouped value and expansion control.
|
|
186
196
|
*
|
|
187
197
|
* @example
|
|
188
198
|
* ```ts
|
|
189
|
-
* const
|
|
199
|
+
* const isGroupedCell = cell_getIsGrouped(cell)
|
|
190
200
|
* ```
|
|
191
201
|
*/
|
|
192
202
|
function cell_getIsGrouped(cell) {
|
|
@@ -194,26 +204,28 @@ function cell_getIsGrouped(cell) {
|
|
|
194
204
|
return column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId;
|
|
195
205
|
}
|
|
196
206
|
/**
|
|
197
|
-
*
|
|
207
|
+
* Checks whether this cell is a placeholder hidden by grouping.
|
|
198
208
|
*
|
|
199
|
-
*
|
|
209
|
+
* Placeholder cells belong to grouped columns other than the row's active
|
|
210
|
+
* grouping column.
|
|
200
211
|
*
|
|
201
212
|
* @example
|
|
202
213
|
* ```ts
|
|
203
|
-
* const
|
|
214
|
+
* const isPlaceholder = cell_getIsPlaceholder(cell)
|
|
204
215
|
* ```
|
|
205
216
|
*/
|
|
206
217
|
function cell_getIsPlaceholder(cell) {
|
|
207
218
|
return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column);
|
|
208
219
|
}
|
|
209
220
|
/**
|
|
210
|
-
*
|
|
221
|
+
* Checks whether this cell should render an aggregated value.
|
|
211
222
|
*
|
|
212
|
-
*
|
|
223
|
+
* Aggregated cells are non-placeholder, non-grouped cells on rows that have
|
|
224
|
+
* subRows.
|
|
213
225
|
*
|
|
214
226
|
* @example
|
|
215
227
|
* ```ts
|
|
216
|
-
* const
|
|
228
|
+
* const isAggregated = cell_getIsAggregated(cell)
|
|
217
229
|
* ```
|
|
218
230
|
*/
|
|
219
231
|
function cell_getIsAggregated(cell) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"columnGroupingFeature.utils.cjs","names":["isFunction","cloneState","table_getColumn"],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, isFunction } from '../../utils'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n AggregationFn,\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Returns the default grouping state.\n *\n * Feature constructors use this value to initialize the table state or option defaults when no user value is provided.\n *\n * @example\n * ```ts\n * const initialValue = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Toggles grouping for a column.\n *\n * The update is applied through the owning table state slice and respects the feature options for that column.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (old) => {\n // Find any existing grouping for this column\n if (old.includes(column.id)) {\n return old.filter((d) => d !== column.id)\n }\n\n return [...old, column.id]\n })\n}\n\n/**\n * Returns whether a column can use group.\n *\n * This combines column options, table options, and any required accessor or feature state for the capability.\n *\n * @example\n * ```ts\n * const value = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Returns is grouped for a column.\n *\n * This derives the value from the column definition, table options, and the feature state atoms registered on the table.\n *\n * @example\n * ```ts\n * const value = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Returns grouped index for a column.\n *\n * This derives the value from the column definition, table options, and the feature state atoms registered on the table.\n *\n * @example\n * ```ts\n * const value = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Returns an event handler for toggling grouping handler.\n *\n * The handler is intended for direct use in column header controls such as buttons or checkboxes.\n *\n * @example\n * ```ts\n * const value = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Infers aggregation fn for a column.\n *\n * The inference uses the column definition, table options, and sampled row values when needed.\n *\n * @example\n * ```ts\n * const value = column_getAutoAggregationFn(column)\n * ```\n */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n const firstRow = column.table.getCoreRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'number') {\n return aggregationFns?.sum\n }\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return aggregationFns?.extent\n }\n}\n\n/**\n * Returns aggregation fn for a column.\n *\n * This derives the value from the column definition, table options, and the feature state atoms registered on the table.\n *\n * @example\n * ```ts\n * const value = column_getAggregationFn(column)\n * ```\n */\nexport function column_getAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n return isFunction(column.columnDef.aggregationFn)\n ? column.columnDef.aggregationFn\n : column.columnDef.aggregationFn === 'auto'\n ? column_getAutoAggregationFn(column)\n : aggregationFns?.[column.columnDef.aggregationFn as string]\n}\n\n/**\n * Updates the table's grouping state slice.\n *\n * The updater follows TanStack Table updater semantics and is routed through the corresponding `on*Change` option or backing atom.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => old)\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets the table's grouping state slice.\n *\n * By default the reset uses `table.initialState`; when supported, a blank/default reset bypasses the saved initial value.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Returns is grouped for a row.\n *\n * This is the static implementation behind the matching row instance API and may read row caches or table state atoms.\n *\n * @example\n * ```ts\n * const value = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Returns grouping value for a row.\n *\n * This is the static implementation behind the matching row instance API and may read row caches or table state atoms.\n *\n * @example\n * ```ts\n * const value = row_getGroupingValue(row)\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache?.hasOwnProperty(columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = table_getColumn(row.table, columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Returns is grouped for a cell.\n *\n * This is the static implementation behind the matching cell instance API and uses the owning row and column context.\n *\n * @example\n * ```ts\n * const value = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Returns is placeholder for a cell.\n *\n * This is the static implementation behind the matching cell instance API and uses the owning row and column context.\n *\n * @example\n * ```ts\n * const value = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n\n/**\n * Returns is aggregated for a cell.\n *\n * This is the static implementation behind the matching cell instance API and uses the owning row and column context.\n *\n * @example\n * ```ts\n * const value = cell_getIsAggregated(cell)\n * ```\n */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return (\n !cell_getIsGrouped(cell) &&\n !cell_getIsPlaceholder(cell) &&\n !!cell.row.subRows.length\n )\n}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,SAAgB,0BAAyC;CACvD,OAAO,EAAE;;;;;;;;;;;;AAaX,SAAgB,sBAId,QAAmD;CACnD,kBAAkB,OAAO,QAAQ,QAAQ;EAEvC,IAAI,IAAI,SAAS,OAAO,GAAG,EACzB,OAAO,IAAI,QAAQ,MAAM,MAAM,OAAO,GAAG;EAG3C,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG;GAC1B;;;;;;;;;;;;AAaJ,SAAgB,mBAId,QAAmD;CACnD,QACG,OAAO,UAAU,kBAAkB,UACnC,OAAO,MAAM,QAAQ,kBAAkB,UACvC,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,OAAO,UAAU;;;;;;;;;;;;AAc/C,SAAgB,oBAId,QAA4D;;CAC5D,OAAO,CAAC,2BAAC,OAAO,MAAM,MAAM,yGAAU,KAAK,gFAAE,SAAS,OAAO,GAAG;;;;;;;;;;;;AAalE,SAAgB,uBAId,QAA2D;;CAC3D,kCAAO,OAAO,MAAM,MAAM,4GAAU,KAAK,kFAAE,QAAQ,OAAO,GAAG,KAAI;;;;;;;;;;;;AAanE,SAAgB,gCAId,QAAmD;CACnD,MAAM,WAAW,mBAAmB,OAAO;CAE3C,aAAa;EACX,IAAI,CAAC,UAAU;EACf,sBAAsB,OAAO;;;;;;;;;;;;;AAcjC,SAAgB,4BAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAE1C,MAAM,WAAW,OAAO,MAAM,iBAAiB,CAAC,SAAS;CAEzD,MAAM,4DAAQ,SAAU,SAAS,OAAO,GAAG;CAE3C,IAAI,OAAO,UAAU,UACnB,uEAAO,eAAgB;CAGzB,IAAI,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK,iBAC5C,uEAAO,eAAgB;;;;;;;;;;;;AAc3B,SAAgB,wBAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAE1C,OAAOA,yBAAW,OAAO,UAAU,cAAc,GAC7C,OAAO,UAAU,gBACjB,OAAO,UAAU,kBAAkB,SACjC,4BAA4B,OAAO,mEACnC,eAAiB,OAAO,UAAU;;;;;;;;;;;;AAa1C,SAAgB,kBAGd,OAAyC,SAAiC;;CAC1E,iDAAM,SAAQ,6GAAmB,QAAQ;;;;;;;;;;;;;AAc3C,SAAgB,oBAGd,OAAyC,cAAwB;CACjE,kBACE,OACA,eAAe,EAAE,GAAGC,yBAAW,MAAM,aAAa,YAAY,EAAE,CAAC,CAClE;;;;;;;;;;;;AAaH,SAAgB,iBAGd,KAA0D;CAC1D,OAAO,CAAC,CAAC,IAAI;;;;;;;;;;;;AAaf,SAAgB,qBAGd,KAA0D,UAAkB;;CAC5E,6BAAI,IAAI,oGAAsB,eAAe,SAAS,EACpD,OAAO,IAAI,qBAAqB;CAGlC,MAAM,SAASC,iDAAgB,IAAI,OAAO,SAAS;CAKnD,IAAI,CAAC,OAAO,UAAU,kBACpB,OAAO,IAAI,SAAS,SAAS;CAG/B,IAAI,IAAI,sBACN,IAAI,qBAAqB,YAAY,OAAO,UAAU,iBACpD,IAAI,SACL;CAGH,iCAAO,IAAI,sGAAuB;;;;;;;;;;;;AAapC,SAAgB,kBAId,MAAsC;CACtC,MAAM,MAAM,KAAK;CACjB,OACE,oBAAoB,KAAK,OAAO,IAAI,KAAK,OAAO,OAAO,IAAI;;;;;;;;;;;;AAc/D,SAAgB,sBAId,MAAsC;CACtC,OAAO,CAAC,kBAAkB,KAAK,IAAI,oBAAoB,KAAK,OAAO;;;;;;;;;;;;AAarE,SAAgB,qBAId,MAAsC;CACtC,OACE,CAAC,kBAAkB,KAAK,IACxB,CAAC,sBAAsB,KAAK,IAC5B,CAAC,CAAC,KAAK,IAAI,QAAQ"}
|
|
1
|
+
{"version":3,"file":"columnGroupingFeature.utils.cjs","names":["isFunction","cloneState","table_getColumn"],"sources":["../../../src/features/column-grouping/columnGroupingFeature.utils.ts"],"sourcesContent":["import { cloneState, isFunction } from '../../utils'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { Cell } from '../../types/Cell'\nimport type {\n AggregationFn,\n GroupingState,\n Row_ColumnGrouping,\n} from './columnGroupingFeature.types'\n\n/**\n * Creates the default grouping state.\n *\n * The feature default is an empty array, meaning no columns are grouped. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const grouping = getDefaultGroupingState()\n * ```\n */\nexport function getDefaultGroupingState(): GroupingState {\n return []\n}\n\n/**\n * Adds or removes this column id from the grouping state.\n *\n * Existing grouped columns keep their order. A column already present in\n * `state.grouping` is removed; otherwise it is appended.\n *\n * @example\n * ```ts\n * column_toggleGrouping(column)\n * ```\n */\nexport function column_toggleGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n table_setGrouping(column.table, (old) => {\n // Find any existing grouping for this column\n if (old.includes(column.id)) {\n return old.filter((d) => d !== column.id)\n }\n\n return [...old, column.id]\n })\n}\n\n/**\n * Checks whether this column can be used for grouping.\n *\n * Grouping must be enabled at the column and table level, and the column must\n * either have an accessor or provide `getGroupingValue`.\n *\n * @example\n * ```ts\n * const canGroup = column_getCanGroup(column)\n * ```\n */\nexport function column_getCanGroup<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n return (\n (column.columnDef.enableGrouping ?? true) &&\n (column.table.options.enableGrouping ?? true) &&\n (!!column.accessorFn || !!column.columnDef.getGroupingValue)\n )\n}\n\n/**\n * Checks whether this column id is present in `state.grouping`.\n *\n * The result only reflects grouping state, not whether the grouped row model has\n * been calculated yet.\n *\n * @example\n * ```ts\n * const isGrouped = column_getIsGrouped(column)\n * ```\n */\nexport function column_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return !!column.table.atoms.grouping?.get()?.includes(column.id)\n}\n\n/**\n * Finds this column's position in the ordered grouping state.\n *\n * The result is `-1` when the column is not grouped.\n *\n * @example\n * ```ts\n * const index = column_getGroupedIndex(column)\n * ```\n */\nexport function column_getGroupedIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return column.table.atoms.grouping?.get()?.indexOf(column.id) ?? -1\n}\n\n/**\n * Creates a header/control handler that toggles grouping for this column.\n *\n * The handler is a no-op when `column_getCanGroup(column)` is false.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleGroupingHandler(column)\n * ```\n */\nexport function column_getToggleGroupingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canGroup = column_getCanGroup(column)\n\n return () => {\n if (!canGroup) return\n column_toggleGrouping(column)\n }\n}\n\n/**\n * Chooses a built-in aggregation function from the first core row value.\n *\n * Numeric columns default to `sum`, date-like values default to `extent`, and\n * other value types leave aggregation unspecified.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAutoAggregationFn(column)\n * ```\n */\nexport function column_getAutoAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n const firstRow = column.table.getCoreRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'number') {\n return aggregationFns?.sum\n }\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return aggregationFns?.extent\n }\n}\n\n/**\n * Resolves the aggregation function configured for a column.\n *\n * Function-valued `columnDef.aggregationFn` is returned directly, `'auto'`\n * delegates to `column_getAutoAggregationFn`, and string values are looked up in\n * the table's aggregation function registry.\n *\n * @example\n * ```ts\n * const aggregationFn = column_getAggregationFn(column)\n * ```\n */\nexport function column_getAggregationFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const aggregationFns:\n | Record<string, AggregationFn<TFeatures, TData>>\n | undefined = column.table._rowModelFns.aggregationFns\n\n return isFunction(column.columnDef.aggregationFn)\n ? column.columnDef.aggregationFn\n : column.columnDef.aggregationFn === 'auto'\n ? column_getAutoAggregationFn(column)\n : aggregationFns?.[column.columnDef.aggregationFn as string]\n}\n\n/**\n * Routes a grouping updater through the table's grouping change handler.\n *\n * The updater may be a next `GroupingState` array or a function of the previous\n * grouping state, matching the instance `table.setGrouping` behavior.\n *\n * @example\n * ```ts\n * table_setGrouping(table, (old) => [...old, 'status'])\n * ```\n */\nexport function table_setGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<GroupingState>) {\n table.options.onGroupingChange?.(updater)\n}\n\n/**\n * Resets `grouping` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.grouping` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetGrouping(table)\n * table_resetGrouping(table, true)\n * ```\n */\nexport function table_resetGrouping<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGrouping(\n table,\n defaultState ? [] : cloneState(table.initialState.grouping ?? []),\n )\n}\n\n/**\n * Checks whether this row was created as a grouped row.\n *\n * Grouped rows carry a `groupingColumnId`; ordinary leaf rows do not.\n *\n * @example\n * ```ts\n * const isGrouped = row_getIsGrouped(row)\n * ```\n */\nexport function row_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>) {\n return !!row.groupingColumnId\n}\n\n/**\n * Reads and caches this row's grouping value for a column.\n *\n * `columnDef.getGroupingValue` wins when provided; otherwise the normal row\n * accessor value is used.\n *\n * @example\n * ```ts\n * const groupValue = row_getGroupingValue(row, 'status')\n * ```\n */\nexport function row_getGroupingValue<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData> & Partial<Row_ColumnGrouping>, columnId: string) {\n if (row._groupingValuesCache?.hasOwnProperty(columnId)) {\n return row._groupingValuesCache[columnId]\n }\n\n const column = table_getColumn(row.table, columnId) as Column_Internal<\n TFeatures,\n TData\n >\n\n if (!column.columnDef.getGroupingValue) {\n return row.getValue(columnId)\n }\n\n if (row._groupingValuesCache) {\n row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(\n row.original,\n )\n }\n\n return row._groupingValuesCache?.[columnId]\n}\n\n/**\n * Checks whether this cell represents the grouped column for a grouped row.\n *\n * This is the cell that usually renders the grouped value and expansion control.\n *\n * @example\n * ```ts\n * const isGroupedCell = cell_getIsGrouped(cell)\n * ```\n */\nexport function cell_getIsGrouped<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n const row = cell.row as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n return (\n column_getIsGrouped(cell.column) && cell.column.id === row.groupingColumnId\n )\n}\n\n/**\n * Checks whether this cell is a placeholder hidden by grouping.\n *\n * Placeholder cells belong to grouped columns other than the row's active\n * grouping column.\n *\n * @example\n * ```ts\n * const isPlaceholder = cell_getIsPlaceholder(cell)\n * ```\n */\nexport function cell_getIsPlaceholder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return !cell_getIsGrouped(cell) && column_getIsGrouped(cell.column)\n}\n\n/**\n * Checks whether this cell should render an aggregated value.\n *\n * Aggregated cells are non-placeholder, non-grouped cells on rows that have\n * subRows.\n *\n * @example\n * ```ts\n * const isAggregated = cell_getIsAggregated(cell)\n * ```\n */\nexport function cell_getIsAggregated<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(cell: Cell<TFeatures, TData, TValue>) {\n return (\n !cell_getIsGrouped(cell) &&\n !cell_getIsPlaceholder(cell) &&\n !!cell.row.subRows.length\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,0BAAyC;CACvD,OAAO,EAAE;;;;;;;;;;;;;AAcX,SAAgB,sBAId,QAAmD;CACnD,kBAAkB,OAAO,QAAQ,QAAQ;EAEvC,IAAI,IAAI,SAAS,OAAO,GAAG,EACzB,OAAO,IAAI,QAAQ,MAAM,MAAM,OAAO,GAAG;EAG3C,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG;GAC1B;;;;;;;;;;;;;AAcJ,SAAgB,mBAId,QAAmD;CACnD,QACG,OAAO,UAAU,kBAAkB,UACnC,OAAO,MAAM,QAAQ,kBAAkB,UACvC,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,OAAO,UAAU;;;;;;;;;;;;;AAe/C,SAAgB,oBAId,QAA4D;;CAC5D,OAAO,CAAC,2BAAC,OAAO,MAAM,MAAM,yGAAU,KAAK,gFAAE,SAAS,OAAO,GAAG;;;;;;;;;;;;AAalE,SAAgB,uBAId,QAA2D;;CAC3D,kCAAO,OAAO,MAAM,MAAM,4GAAU,KAAK,kFAAE,QAAQ,OAAO,GAAG,KAAI;;;;;;;;;;;;AAanE,SAAgB,gCAId,QAAmD;CACnD,MAAM,WAAW,mBAAmB,OAAO;CAE3C,aAAa;EACX,IAAI,CAAC,UAAU;EACf,sBAAsB,OAAO;;;;;;;;;;;;;;AAejC,SAAgB,4BAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAE1C,MAAM,WAAW,OAAO,MAAM,iBAAiB,CAAC,SAAS;CAEzD,MAAM,4DAAQ,SAAU,SAAS,OAAO,GAAG;CAE3C,IAAI,OAAO,UAAU,UACnB,uEAAO,eAAgB;CAGzB,IAAI,OAAO,UAAU,SAAS,KAAK,MAAM,KAAK,iBAC5C,uEAAO,eAAgB;;;;;;;;;;;;;;AAgB3B,SAAgB,wBAId,QAAmD;CACnD,MAAM,iBAEU,OAAO,MAAM,aAAa;CAE1C,OAAOA,yBAAW,OAAO,UAAU,cAAc,GAC7C,OAAO,UAAU,gBACjB,OAAO,UAAU,kBAAkB,SACjC,4BAA4B,OAAO,mEACnC,eAAiB,OAAO,UAAU;;;;;;;;;;;;;AAc1C,SAAgB,kBAGd,OAAyC,SAAiC;;CAC1E,iDAAM,SAAQ,6GAAmB,QAAQ;;;;;;;;;;;;;;AAe3C,SAAgB,oBAGd,OAAyC,cAAwB;CACjE,kBACE,OACA,eAAe,EAAE,GAAGC,yBAAW,MAAM,aAAa,YAAY,EAAE,CAAC,CAClE;;;;;;;;;;;;AAaH,SAAgB,iBAGd,KAA0D;CAC1D,OAAO,CAAC,CAAC,IAAI;;;;;;;;;;;;;AAcf,SAAgB,qBAGd,KAA0D,UAAkB;;CAC5E,6BAAI,IAAI,oGAAsB,eAAe,SAAS,EACpD,OAAO,IAAI,qBAAqB;CAGlC,MAAM,SAASC,iDAAgB,IAAI,OAAO,SAAS;CAKnD,IAAI,CAAC,OAAO,UAAU,kBACpB,OAAO,IAAI,SAAS,SAAS;CAG/B,IAAI,IAAI,sBACN,IAAI,qBAAqB,YAAY,OAAO,UAAU,iBACpD,IAAI,SACL;CAGH,iCAAO,IAAI,sGAAuB;;;;;;;;;;;;AAapC,SAAgB,kBAId,MAAsC;CACtC,MAAM,MAAM,KAAK;CACjB,OACE,oBAAoB,KAAK,OAAO,IAAI,KAAK,OAAO,OAAO,IAAI;;;;;;;;;;;;;AAe/D,SAAgB,sBAId,MAAsC;CACtC,OAAO,CAAC,kBAAkB,KAAK,IAAI,oBAAoB,KAAK,OAAO;;;;;;;;;;;;;AAcrE,SAAgB,qBAId,MAAsC;CACtC,OACE,CAAC,kBAAkB,KAAK,IACxB,CAAC,sBAAsB,KAAK,IAC5B,CAAC,CAAC,KAAK,IAAI,QAAQ"}
|