@tanstack/table-core 9.0.0-beta.2 → 9.0.0-beta.21
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.d.cts +3 -3
- package/dist/core/cells/constructCell.d.ts +3 -3
- package/dist/core/cells/coreCellsFeature.cjs +11 -20
- package/dist/core/cells/coreCellsFeature.cjs.map +1 -1
- package/dist/core/cells/coreCellsFeature.d.cts +4 -12
- package/dist/core/cells/coreCellsFeature.d.ts +4 -12
- package/dist/core/cells/coreCellsFeature.js +12 -20
- package/dist/core/cells/coreCellsFeature.js.map +1 -1
- package/dist/core/cells/coreCellsFeature.types.d.cts +6 -6
- package/dist/core/cells/coreCellsFeature.types.d.ts +6 -6
- package/dist/core/cells/coreCellsFeature.utils.d.cts +3 -3
- package/dist/core/cells/coreCellsFeature.utils.d.ts +3 -3
- package/dist/core/columns/constructColumn.cjs +5 -0
- package/dist/core/columns/constructColumn.cjs.map +1 -1
- package/dist/core/columns/constructColumn.d.cts +3 -3
- package/dist/core/columns/constructColumn.d.ts +3 -3
- package/dist/core/columns/constructColumn.js +5 -0
- package/dist/core/columns/constructColumn.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.cjs +59 -68
- package/dist/core/columns/coreColumnsFeature.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.d.cts +4 -12
- package/dist/core/columns/coreColumnsFeature.d.ts +4 -12
- package/dist/core/columns/coreColumnsFeature.js +60 -68
- package/dist/core/columns/coreColumnsFeature.js.map +1 -1
- package/dist/core/columns/coreColumnsFeature.types.d.cts +7 -7
- package/dist/core/columns/coreColumnsFeature.types.d.ts +7 -7
- package/dist/core/columns/coreColumnsFeature.utils.cjs +2 -2
- package/dist/core/columns/coreColumnsFeature.utils.cjs.map +1 -1
- package/dist/core/columns/coreColumnsFeature.utils.d.cts +9 -9
- package/dist/core/columns/coreColumnsFeature.utils.d.ts +9 -9
- package/dist/core/columns/coreColumnsFeature.utils.js +3 -3
- package/dist/core/columns/coreColumnsFeature.utils.js.map +1 -1
- package/dist/core/coreFeatures.cjs.map +1 -1
- package/dist/core/coreFeatures.d.cts +1 -1
- package/dist/core/coreFeatures.d.ts +1 -1
- package/dist/core/coreFeatures.js.map +1 -1
- package/dist/core/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.d.cts +2 -2
- package/dist/core/headers/buildHeaderGroups.d.ts +2 -2
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- package/dist/core/headers/constructHeader.d.cts +2 -2
- package/dist/core/headers/constructHeader.d.ts +2 -2
- package/dist/core/headers/coreHeadersFeature.cjs +44 -53
- package/dist/core/headers/coreHeadersFeature.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.d.cts +4 -12
- package/dist/core/headers/coreHeadersFeature.d.ts +4 -12
- package/dist/core/headers/coreHeadersFeature.js +45 -53
- package/dist/core/headers/coreHeadersFeature.js.map +1 -1
- package/dist/core/headers/coreHeadersFeature.types.d.cts +6 -6
- package/dist/core/headers/coreHeadersFeature.types.d.ts +6 -6
- package/dist/core/headers/coreHeadersFeature.utils.cjs.map +1 -1
- package/dist/core/headers/coreHeadersFeature.utils.d.cts +6 -6
- package/dist/core/headers/coreHeadersFeature.utils.d.ts +6 -6
- package/dist/core/headers/coreHeadersFeature.utils.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.cjs +17 -26
- package/dist/core/row-models/coreRowModelsFeature.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.d.cts +4 -12
- package/dist/core/row-models/coreRowModelsFeature.d.ts +4 -12
- package/dist/core/row-models/coreRowModelsFeature.js +18 -26
- package/dist/core/row-models/coreRowModelsFeature.js.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.types.d.cts +6 -16
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +6 -16
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs +13 -13
- package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
- package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +14 -14
- package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +14 -14
- package/dist/core/row-models/coreRowModelsFeature.utils.js +13 -13
- 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 +3 -4
- package/dist/core/row-models/createCoreRowModel.js.map +1 -1
- package/dist/core/rows/constructRow.cjs +3 -2
- package/dist/core/rows/constructRow.cjs.map +1 -1
- package/dist/core/rows/constructRow.d.cts +2 -2
- package/dist/core/rows/constructRow.d.ts +2 -2
- package/dist/core/rows/constructRow.js +4 -2
- package/dist/core/rows/constructRow.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.cjs +27 -36
- package/dist/core/rows/coreRowsFeature.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.d.cts +4 -12
- package/dist/core/rows/coreRowsFeature.d.ts +4 -12
- package/dist/core/rows/coreRowsFeature.js +28 -36
- package/dist/core/rows/coreRowsFeature.js.map +1 -1
- package/dist/core/rows/coreRowsFeature.types.d.cts +6 -6
- package/dist/core/rows/coreRowsFeature.types.d.ts +6 -6
- package/dist/core/rows/coreRowsFeature.utils.cjs +3 -3
- package/dist/core/rows/coreRowsFeature.utils.cjs.map +1 -1
- package/dist/core/rows/coreRowsFeature.utils.d.cts +3 -3
- package/dist/core/rows/coreRowsFeature.utils.d.ts +3 -3
- package/dist/core/rows/coreRowsFeature.utils.js +4 -4
- package/dist/core/rows/coreRowsFeature.utils.js.map +1 -1
- package/dist/core/table/constructTable.cjs +21 -6
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.d.cts +1 -1
- package/dist/core/table/constructTable.d.ts +1 -1
- package/dist/core/table/constructTable.js +21 -6
- package/dist/core/table/constructTable.js.map +1 -1
- package/dist/core/table/coreTablesFeature.cjs +7 -16
- package/dist/core/table/coreTablesFeature.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.d.cts +4 -12
- package/dist/core/table/coreTablesFeature.d.ts +4 -12
- package/dist/core/table/coreTablesFeature.js +8 -16
- package/dist/core/table/coreTablesFeature.js.map +1 -1
- package/dist/core/table/coreTablesFeature.types.d.cts +28 -16
- package/dist/core/table/coreTablesFeature.types.d.ts +28 -16
- package/dist/core/table/coreTablesFeature.utils.cjs +33 -12
- package/dist/core/table/coreTablesFeature.utils.cjs.map +1 -1
- package/dist/core/table/coreTablesFeature.utils.d.cts +8 -6
- package/dist/core/table/coreTablesFeature.utils.d.ts +8 -6
- package/dist/core/table/coreTablesFeature.utils.js +33 -12
- package/dist/core/table/coreTablesFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.cjs +49 -61
- package/dist/features/column-faceting/columnFacetingFeature.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.d.cts +4 -15
- package/dist/features/column-faceting/columnFacetingFeature.d.ts +4 -15
- package/dist/features/column-faceting/columnFacetingFeature.js +50 -61
- package/dist/features/column-faceting/columnFacetingFeature.js.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.types.d.cts +8 -29
- package/dist/features/column-faceting/columnFacetingFeature.types.d.ts +8 -29
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs +12 -12
- package/dist/features/column-faceting/columnFacetingFeature.utils.cjs.map +1 -1
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.cts +8 -8
- package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +8 -8
- package/dist/features/column-faceting/columnFacetingFeature.utils.js +12 -12
- package/dist/features/column-faceting/columnFacetingFeature.utils.js.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.d.cts +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.d.ts +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
- 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.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.d.cts +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.d.ts +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.cjs +40 -53
- package/dist/features/column-filtering/columnFilteringFeature.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.d.cts +4 -16
- package/dist/features/column-filtering/columnFilteringFeature.d.ts +4 -16
- package/dist/features/column-filtering/columnFilteringFeature.js +42 -54
- package/dist/features/column-filtering/columnFilteringFeature.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +40 -26
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +40 -26
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +12 -12
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +12 -12
- package/dist/features/column-filtering/columnFilteringFeature.utils.js +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs +12 -7
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +5 -3
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +5 -3
- package/dist/features/column-filtering/createFilteredRowModel.js +13 -8
- package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
- package/dist/features/column-filtering/filterRowsUtils.cjs +3 -2
- package/dist/features/column-filtering/filterRowsUtils.cjs.map +1 -1
- package/dist/features/column-filtering/filterRowsUtils.js +3 -2
- package/dist/features/column-filtering/filterRowsUtils.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.cjs +57 -69
- package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.d.cts +4 -15
- package/dist/features/column-grouping/columnGroupingFeature.d.ts +4 -15
- package/dist/features/column-grouping/columnGroupingFeature.js +59 -70
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +28 -21
- package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +28 -21
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +4 -4
- package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +11 -11
- package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +11 -11
- package/dist/features/column-grouping/columnGroupingFeature.utils.js +5 -5
- package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs +9 -7
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.d.cts +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.d.ts +6 -3
- package/dist/features/column-grouping/createGroupedRowModel.js +10 -8
- package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.cjs +47 -59
- package/dist/features/column-ordering/columnOrderingFeature.cjs.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.d.cts +4 -15
- package/dist/features/column-ordering/columnOrderingFeature.d.ts +4 -15
- package/dist/features/column-ordering/columnOrderingFeature.js +48 -59
- package/dist/features/column-ordering/columnOrderingFeature.js.map +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.types.d.cts +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.types.d.ts +1 -1
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.cts +9 -9
- package/dist/features/column-ordering/columnOrderingFeature.utils.d.ts +9 -9
- package/dist/features/column-pinning/columnPinningFeature.cjs +209 -221
- package/dist/features/column-pinning/columnPinningFeature.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.d.cts +4 -15
- package/dist/features/column-pinning/columnPinningFeature.d.ts +4 -15
- package/dist/features/column-pinning/columnPinningFeature.js +210 -221
- package/dist/features/column-pinning/columnPinningFeature.js.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.types.d.cts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.types.d.ts +2 -2
- package/dist/features/column-pinning/columnPinningFeature.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +31 -30
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +31 -30
- package/dist/features/column-pinning/columnPinningFeature.utils.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.cjs +31 -43
- package/dist/features/column-resizing/columnResizingFeature.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.d.cts +4 -15
- package/dist/features/column-resizing/columnResizingFeature.d.ts +4 -15
- package/dist/features/column-resizing/columnResizingFeature.js +32 -43
- package/dist/features/column-resizing/columnResizingFeature.js.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.types.d.cts +1 -4
- package/dist/features/column-resizing/columnResizingFeature.types.d.ts +1 -4
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs +2 -5
- package/dist/features/column-resizing/columnResizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-resizing/columnResizingFeature.utils.d.cts +6 -6
- package/dist/features/column-resizing/columnResizingFeature.utils.d.ts +6 -6
- package/dist/features/column-resizing/columnResizingFeature.utils.js +3 -6
- package/dist/features/column-resizing/columnResizingFeature.utils.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.cjs +112 -125
- package/dist/features/column-sizing/columnSizingFeature.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.d.cts +4 -16
- package/dist/features/column-sizing/columnSizingFeature.d.ts +4 -16
- package/dist/features/column-sizing/columnSizingFeature.js +113 -125
- package/dist/features/column-sizing/columnSizingFeature.js.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs +11 -4
- package/dist/features/column-sizing/columnSizingFeature.utils.cjs.map +1 -1
- package/dist/features/column-sizing/columnSizingFeature.utils.d.cts +12 -12
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +12 -12
- package/dist/features/column-sizing/columnSizingFeature.utils.js +12 -5
- package/dist/features/column-sizing/columnSizingFeature.utils.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.cjs +83 -95
- package/dist/features/column-visibility/columnVisibilityFeature.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.d.cts +4 -15
- package/dist/features/column-visibility/columnVisibilityFeature.d.ts +4 -15
- package/dist/features/column-visibility/columnVisibilityFeature.js +84 -95
- package/dist/features/column-visibility/columnVisibilityFeature.js.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.cts +2 -2
- package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +2 -2
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs +12 -9
- package/dist/features/column-visibility/columnVisibilityFeature.utils.cjs.map +1 -1
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.cts +14 -14
- package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +14 -14
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js +13 -10
- package/dist/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.cjs +31 -43
- package/dist/features/global-filtering/globalFilteringFeature.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.d.cts +4 -15
- package/dist/features/global-filtering/globalFilteringFeature.d.ts +4 -15
- package/dist/features/global-filtering/globalFilteringFeature.js +32 -43
- package/dist/features/global-filtering/globalFilteringFeature.js.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.types.d.cts +2 -2
- package/dist/features/global-filtering/globalFilteringFeature.types.d.ts +2 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +10 -8
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +10 -8
- package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
- 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.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.cjs +37 -49
- package/dist/features/row-expanding/rowExpandingFeature.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.d.cts +4 -15
- package/dist/features/row-expanding/rowExpandingFeature.d.ts +4 -15
- package/dist/features/row-expanding/rowExpandingFeature.js +38 -49
- package/dist/features/row-expanding/rowExpandingFeature.js.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.types.d.cts +5 -14
- package/dist/features/row-expanding/rowExpandingFeature.types.d.ts +5 -14
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs +21 -12
- package/dist/features/row-expanding/rowExpandingFeature.utils.cjs.map +1 -1
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.cts +10 -10
- package/dist/features/row-expanding/rowExpandingFeature.utils.d.ts +10 -10
- package/dist/features/row-expanding/rowExpandingFeature.utils.js +22 -13
- package/dist/features/row-expanding/rowExpandingFeature.utils.js.map +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.cjs +1 -1
- 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 +1 -1
- package/dist/features/row-pagination/createPaginatedRowModel.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.cjs +35 -47
- package/dist/features/row-pagination/rowPaginationFeature.cjs.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.d.cts +4 -15
- package/dist/features/row-pagination/rowPaginationFeature.d.ts +4 -15
- package/dist/features/row-pagination/rowPaginationFeature.js +36 -47
- package/dist/features/row-pagination/rowPaginationFeature.js.map +1 -1
- package/dist/features/row-pagination/rowPaginationFeature.types.d.cts +4 -13
- package/dist/features/row-pagination/rowPaginationFeature.types.d.ts +4 -13
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.cts +17 -17
- package/dist/features/row-pagination/rowPaginationFeature.utils.d.ts +17 -17
- package/dist/features/row-pinning/rowPinningFeature.cjs +55 -67
- package/dist/features/row-pinning/rowPinningFeature.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.d.cts +4 -15
- package/dist/features/row-pinning/rowPinningFeature.d.ts +4 -15
- package/dist/features/row-pinning/rowPinningFeature.js +56 -67
- package/dist/features/row-pinning/rowPinningFeature.js.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.types.d.cts +2 -2
- package/dist/features/row-pinning/rowPinningFeature.types.d.ts +2 -2
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs +2 -2
- package/dist/features/row-pinning/rowPinningFeature.utils.cjs.map +1 -1
- package/dist/features/row-pinning/rowPinningFeature.utils.d.cts +7 -7
- package/dist/features/row-pinning/rowPinningFeature.utils.d.ts +7 -7
- package/dist/features/row-pinning/rowPinningFeature.utils.js +2 -2
- package/dist/features/row-pinning/rowPinningFeature.utils.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.cjs +108 -77
- package/dist/features/row-selection/rowSelectionFeature.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.d.cts +4 -15
- package/dist/features/row-selection/rowSelectionFeature.d.ts +4 -15
- package/dist/features/row-selection/rowSelectionFeature.js +110 -78
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.types.d.cts +13 -5
- package/dist/features/row-selection/rowSelectionFeature.types.d.ts +13 -5
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs +76 -60
- package/dist/features/row-selection/rowSelectionFeature.utils.cjs.map +1 -1
- package/dist/features/row-selection/rowSelectionFeature.utils.d.cts +48 -23
- package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +48 -23
- package/dist/features/row-selection/rowSelectionFeature.utils.js +77 -62
- package/dist/features/row-selection/rowSelectionFeature.utils.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs +5 -3
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.d.cts +5 -3
- package/dist/features/row-sorting/createSortedRowModel.d.ts +5 -3
- package/dist/features/row-sorting/createSortedRowModel.js +6 -4
- package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.cjs +45 -57
- package/dist/features/row-sorting/rowSortingFeature.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.d.cts +4 -15
- package/dist/features/row-sorting/rowSortingFeature.d.ts +4 -15
- package/dist/features/row-sorting/rowSortingFeature.js +46 -57
- package/dist/features/row-sorting/rowSortingFeature.js.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.types.d.cts +24 -21
- package/dist/features/row-sorting/rowSortingFeature.types.d.ts +24 -21
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs +8 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- package/dist/features/row-sorting/rowSortingFeature.utils.d.cts +16 -16
- package/dist/features/row-sorting/rowSortingFeature.utils.d.ts +16 -16
- package/dist/features/row-sorting/rowSortingFeature.utils.js +8 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
- package/dist/fns/aggregationFns.cjs +18 -18
- package/dist/fns/aggregationFns.cjs.map +1 -1
- package/dist/fns/aggregationFns.d.cts +21 -19
- package/dist/fns/aggregationFns.d.ts +21 -19
- package/dist/fns/aggregationFns.js +18 -18
- package/dist/fns/aggregationFns.js.map +1 -1
- package/dist/fns/filterFns.cjs +51 -65
- package/dist/fns/filterFns.cjs.map +1 -1
- package/dist/fns/filterFns.d.cts +82 -28
- package/dist/fns/filterFns.d.ts +82 -28
- package/dist/fns/filterFns.js +51 -65
- package/dist/fns/filterFns.js.map +1 -1
- package/dist/fns/sortFns.cjs +18 -6
- package/dist/fns/sortFns.cjs.map +1 -1
- package/dist/fns/sortFns.d.cts +15 -13
- package/dist/fns/sortFns.d.ts +15 -13
- package/dist/fns/sortFns.js +18 -6
- package/dist/fns/sortFns.js.map +1 -1
- package/dist/helpers/columnHelper.cjs.map +1 -1
- package/dist/helpers/columnHelper.d.cts +2 -2
- package/dist/helpers/columnHelper.d.ts +2 -2
- package/dist/helpers/columnHelper.js.map +1 -1
- package/dist/helpers/metaHelper.cjs +30 -0
- package/dist/helpers/metaHelper.cjs.map +1 -0
- package/dist/helpers/metaHelper.d.cts +26 -0
- package/dist/helpers/metaHelper.d.ts +26 -0
- package/dist/helpers/metaHelper.js +29 -0
- package/dist/helpers/metaHelper.js.map +1 -0
- package/dist/helpers/tableFeatures.cjs +31 -3
- package/dist/helpers/tableFeatures.cjs.map +1 -1
- package/dist/helpers/tableFeatures.d.cts +33 -5
- package/dist/helpers/tableFeatures.d.ts +33 -5
- package/dist/helpers/tableFeatures.js +31 -3
- package/dist/helpers/tableFeatures.js.map +1 -1
- package/dist/index.cjs +4 -20
- package/dist/index.d.cts +50 -49
- package/dist/index.d.ts +50 -49
- package/dist/index.js +23 -22
- 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 -1
- package/dist/store-reactivity-bindings.cjs.map +1 -1
- package/dist/store-reactivity-bindings.d.cts +1 -1
- package/dist/store-reactivity-bindings.d.ts +1 -1
- package/dist/store-reactivity-bindings.js +1 -1
- package/dist/store-reactivity-bindings.js.map +1 -1
- package/dist/types/Cell.d.cts +4 -9
- package/dist/types/Cell.d.ts +4 -9
- package/dist/types/Column.d.cts +11 -18
- package/dist/types/Column.d.ts +11 -18
- package/dist/types/ColumnDef.d.cts +23 -14
- package/dist/types/ColumnDef.d.ts +23 -14
- package/dist/types/Header.d.cts +5 -10
- package/dist/types/Header.d.ts +5 -10
- package/dist/types/HeaderGroup.d.cts +4 -9
- package/dist/types/HeaderGroup.d.ts +4 -9
- package/dist/types/Row.d.cts +7 -12
- package/dist/types/Row.d.ts +7 -12
- package/dist/types/RowModel.d.cts +12 -28
- package/dist/types/RowModel.d.ts +12 -28
- package/dist/types/RowModelFns.d.cts +6 -11
- package/dist/types/RowModelFns.d.ts +6 -11
- package/dist/types/Table.d.cts +26 -36
- package/dist/types/Table.d.ts +26 -36
- package/dist/types/TableFeatures.d.cts +328 -54
- package/dist/types/TableFeatures.d.ts +328 -54
- package/dist/types/TableOptions.d.cts +22 -17
- package/dist/types/TableOptions.d.ts +22 -17
- package/dist/types/TableState.d.cts +11 -16
- package/dist/types/TableState.d.ts +11 -16
- package/dist/utils.cjs +24 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +23 -7
- package/dist/utils.d.ts +23 -7
- package/dist/utils.js +23 -3
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/skills/column-definitions/SKILL.md +3 -6
- package/skills/column-layout/SKILL.md +0 -2
- package/skills/customizing-feature-behavior/SKILL.md +63 -56
- package/skills/filtering/SKILL.md +60 -42
- package/skills/filtering/references/faceting-and-fuzzy.md +59 -32
- package/skills/grouping/SKILL.md +49 -54
- package/skills/migrate-v8-to-v9/SKILL.md +30 -33
- package/skills/pagination/SKILL.md +22 -20
- package/skills/row-expanding/SKILL.md +33 -25
- package/skills/row-pinning/SKILL.md +11 -7
- package/skills/row-selection/SKILL.md +0 -3
- package/skills/setup/SKILL.md +55 -65
- package/skills/sorting/SKILL.md +21 -21
- package/skills/state-management/SKILL.md +40 -25
- package/src/core/cells/coreCellsFeature.ts +17 -39
- package/src/core/cells/coreCellsFeature.types.ts +6 -6
- package/src/core/columns/constructColumn.ts +6 -0
- package/src/core/columns/coreColumnsFeature.ts +56 -83
- package/src/core/columns/coreColumnsFeature.types.ts +8 -8
- package/src/core/columns/coreColumnsFeature.utils.ts +4 -4
- package/src/core/coreFeatures.ts +1 -1
- package/src/core/headers/buildHeaderGroups.ts +4 -2
- package/src/core/headers/coreHeadersFeature.ts +42 -64
- package/src/core/headers/coreHeadersFeature.types.ts +12 -12
- package/src/core/headers/coreHeadersFeature.utils.ts +1 -1
- package/src/core/row-models/coreRowModelsFeature.ts +43 -64
- package/src/core/row-models/coreRowModelsFeature.types.ts +7 -24
- package/src/core/row-models/coreRowModelsFeature.utils.ts +7 -7
- package/src/core/row-models/createCoreRowModel.ts +7 -6
- package/src/core/rows/constructRow.ts +3 -2
- package/src/core/rows/coreRowsFeature.ts +45 -72
- package/src/core/rows/coreRowsFeature.types.ts +8 -8
- package/src/core/rows/coreRowsFeature.utils.ts +4 -4
- package/src/core/table/constructTable.ts +50 -13
- package/src/core/table/coreTablesFeature.ts +13 -35
- package/src/core/table/coreTablesFeature.types.ts +40 -17
- package/src/core/table/coreTablesFeature.utils.ts +52 -18
- package/src/features/column-faceting/columnFacetingFeature.ts +71 -102
- package/src/features/column-faceting/columnFacetingFeature.types.ts +11 -44
- package/src/features/column-faceting/columnFacetingFeature.utils.ts +6 -6
- package/src/features/column-faceting/createFacetedMinMaxValues.ts +1 -1
- package/src/features/column-faceting/createFacetedRowModel.ts +1 -1
- package/src/features/column-faceting/createFacetedUniqueValues.ts +1 -1
- package/src/features/column-filtering/columnFilteringFeature.ts +61 -103
- package/src/features/column-filtering/columnFilteringFeature.types.ts +55 -39
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +2 -2
- package/src/features/column-filtering/createFilteredRowModel.ts +18 -17
- package/src/features/column-filtering/filterRowsUtils.ts +3 -2
- package/src/features/column-grouping/columnGroupingFeature.ts +83 -126
- package/src/features/column-grouping/columnGroupingFeature.types.ts +42 -34
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +4 -2
- package/src/features/column-grouping/createGroupedRowModel.ts +17 -16
- package/src/features/column-ordering/columnOrderingFeature.ts +52 -84
- package/src/features/column-ordering/columnOrderingFeature.types.ts +2 -2
- package/src/features/column-pinning/columnPinningFeature.ts +268 -304
- package/src/features/column-pinning/columnPinningFeature.types.ts +4 -4
- package/src/features/column-pinning/columnPinningFeature.utils.ts +11 -19
- package/src/features/column-resizing/columnResizingFeature.ts +44 -78
- package/src/features/column-resizing/columnResizingFeature.types.ts +1 -4
- package/src/features/column-resizing/columnResizingFeature.utils.ts +5 -6
- package/src/features/column-sizing/columnSizingFeature.ts +115 -152
- package/src/features/column-sizing/columnSizingFeature.utils.ts +27 -5
- package/src/features/column-visibility/columnVisibilityFeature.ts +92 -129
- package/src/features/column-visibility/columnVisibilityFeature.types.ts +4 -4
- package/src/features/column-visibility/columnVisibilityFeature.utils.ts +31 -15
- package/src/features/global-filtering/globalFilteringFeature.ts +45 -79
- package/src/features/global-filtering/globalFilteringFeature.types.ts +4 -4
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +5 -3
- package/src/features/row-expanding/createExpandedRowModel.ts +1 -1
- package/src/features/row-expanding/rowExpandingFeature.ts +65 -101
- package/src/features/row-expanding/rowExpandingFeature.types.ts +8 -22
- package/src/features/row-expanding/rowExpandingFeature.utils.ts +38 -13
- package/src/features/row-pagination/createPaginatedRowModel.ts +2 -2
- package/src/features/row-pagination/rowPaginationFeature.ts +69 -103
- package/src/features/row-pagination/rowPaginationFeature.types.ts +6 -20
- package/src/features/row-pinning/rowPinningFeature.ts +72 -104
- package/src/features/row-pinning/rowPinningFeature.types.ts +4 -4
- package/src/features/row-selection/rowSelectionFeature.ts +125 -135
- package/src/features/row-selection/rowSelectionFeature.types.ts +17 -7
- package/src/features/row-selection/rowSelectionFeature.utils.ts +144 -66
- package/src/features/row-sorting/createSortedRowModel.ts +12 -15
- package/src/features/row-sorting/rowSortingFeature.ts +73 -114
- package/src/features/row-sorting/rowSortingFeature.types.ts +33 -32
- package/src/features/row-sorting/rowSortingFeature.utils.ts +8 -6
- package/src/fns/aggregationFns.ts +26 -42
- package/src/fns/filterFns.ts +237 -264
- package/src/fns/sortFns.ts +51 -29
- package/src/helpers/columnHelper.ts +4 -4
- package/src/helpers/metaHelper.ts +24 -0
- package/src/helpers/tableFeatures.ts +36 -5
- package/src/index.ts +1 -0
- package/src/store-reactivity-bindings.ts +1 -1
- package/src/types/Cell.ts +5 -21
- package/src/types/Column.ts +12 -26
- package/src/types/ColumnDef.ts +28 -18
- package/src/types/Header.ts +4 -20
- package/src/types/HeaderGroup.ts +7 -18
- package/src/types/Row.ts +6 -21
- package/src/types/RowModel.ts +15 -88
- package/src/types/RowModelFns.ts +9 -24
- package/src/types/Table.ts +54 -44
- package/src/types/TableFeatures.ts +402 -123
- package/src/types/TableOptions.ts +59 -21
- package/src/types/TableState.ts +5 -17
- package/src/utils.ts +40 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rowSortingFeature.utils.cjs","names":["cloneState","reSplitAlphaNumeric","sortFn_basic","isFunction"],"sources":["../../../src/features/row-sorting/rowSortingFeature.utils.ts"],"sourcesContent":["import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Column_Internal } from '../../types/Column'\nimport type {\n SortDirection,\n SortFn,\n SortingState,\n} from './rowSortingFeature.types'\n\n// State Utils\n\n/**\n * Creates the default sorting state.\n *\n * The feature default is an empty array, meaning no columns are sorted. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const sorting = getDefaultSortingState()\n * ```\n */\nexport function getDefaultSortingState(): SortingState {\n return []\n}\n\n/**\n * Routes a sorting updater through the table's sorting change handler.\n *\n * The updater may be a next `SortingState` array or a function of the previous\n * sorting state, matching the instance `table.setSorting` behavior.\n *\n * @example\n * ```ts\n * table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])\n * ```\n */\nexport function table_setSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<SortingState>) {\n table.options.onSortingChange?.(updater)\n}\n\n/**\n * Resets `sorting` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.sorting` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetSorting(table)\n * table_resetSorting(table, true)\n * ```\n */\nexport function table_resetSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setSorting(\n table,\n defaultState ? [] : cloneState(table.initialState.sorting ?? []),\n )\n}\n\n// Column Utils\n\n/**\n * Chooses a built-in sorting function from sampled filtered row values.\n *\n * Date-like values use `datetime`, mixed text/numeric strings use\n * `alphanumeric`, plain strings use `text`, and unknown values fall back to\n * `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getAutoSortFn(column)\n * ```\n */\nexport function column_getAutoSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n let sortFn: SortFn<TFeatures, TData> | undefined\n\n const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10)\n\n let isString = false\n\n for (let i = 0; i < firstRows.length; i++) {\n const value = firstRows[i]!.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n sortFn = sortFns?.datetime\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n sortFn = sortFns?.alphanumeric\n }\n }\n }\n\n if (isString) {\n sortFn = sortFns?.text\n }\n\n return sortFn ?? sortFn_basic\n}\n\n/**\n * Chooses the default first sort direction from the first filtered row value.\n *\n * String columns start ascending so alphabetical order is natural; other value\n * types start descending.\n *\n * @example\n * ```ts\n * const direction = column_getAutoSortDir(column)\n * ```\n */\nexport function column_getAutoSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const firstRow = column.table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow ? firstRow.getValue(column.id) : undefined\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n}\n\n/**\n * Resolves the sorting function configured for a column.\n *\n * Function-valued `columnDef.sortFn` is returned directly, `'auto'` delegates\n * to `column_getAutoSortFn`, and string values are looked up in the table's\n * sorting function registry before falling back to `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getSortFn(column)\n * ```\n */\nexport function column_getSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n return isFunction(column.columnDef.sortFn)\n ? column.columnDef.sortFn\n : column.columnDef.sortFn === 'auto'\n ? column_getAutoSortFn(column)\n : (sortFns?.[column.columnDef.sortFn as string] ?? sortFn_basic)\n}\n\n/**\n * Applies the next sorting state for this column.\n *\n * The toggle can add, replace, flip, or remove this column's sort entry. Multi\n * sorting respects `enableMultiSort`, `maxMultiSortColCount`, and the `multi`\n * argument.\n *\n * @example\n * ```ts\n * column_toggleSorting(column, undefined, true)\n * ```\n */\nexport function column_toggleSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n desc?: boolean,\n multi?: boolean,\n) {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column_getNextSortingOrder(column)\n const hasManualValue = typeof desc !== 'undefined'\n\n table_setSorting(column.table, (old) => {\n // Find any existing sorting for this column\n const existingSorting = old.find((d) => d.id === column.id)\n const existingIndex = old.findIndex((d) => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n const nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old.length && column_getCanMultiSort(column) && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (column.table.options.maxMultiSortColCount ??\n Number.MAX_SAFE_INTEGER),\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map((d) => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter((d) => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n}\n\n/**\n * Resolves the first direction used when this column begins sorting.\n *\n * Column-level `sortDescFirst` wins, then table-level `sortDescFirst`, then the\n * auto direction inferred from sampled values.\n *\n * @example\n * ```ts\n * const firstDirection = column_getFirstSortDir(column)\n * ```\n */\nexport function column_getFirstSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n column.table.options.sortDescFirst ??\n column_getAutoSortDir(column) === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n}\n\n/**\n * Resolves the next sort order for this column's toggle cycle.\n *\n * The cycle starts with the first sort direction, flips between `asc` and\n * `desc`, and can return `false` when sorting removal is enabled.\n *\n * @example\n * ```ts\n * const nextOrder = column_getNextSortingOrder(column)\n * ```\n */\nexport function column_getNextSortingOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>, multi?: boolean) {\n const firstSortDirection = column_getFirstSortDir(column)\n const isSorted = column_getIsSorted(column)\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (column.table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? (column.table.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n}\n\n/**\n * Checks whether this accessor column can participate in sorting.\n *\n * The column must have an accessor and sorting must be enabled by both the\n * column definition and table options.\n *\n * @example\n * ```ts\n * const canSort = column_getCanSort(column)\n * ```\n */\nexport function column_getCanSort<\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.enableSorting ?? true) &&\n (column.table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Checks whether this column can be added to a multi-sort state.\n *\n * Column-level `enableMultiSort` wins over table-level `enableMultiSort`; if\n * neither is set, accessor columns can multi-sort by default.\n *\n * @example\n * ```ts\n * const canMultiSort = column_getCanMultiSort(column)\n * ```\n */\nexport function column_getCanMultiSort<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n column.columnDef.enableMultiSort ??\n column.table.options.enableMultiSort ??\n !!column.accessorFn\n )\n}\n\n/**\n * Reads this column's current sort direction.\n *\n * The result is `false` when the column is not sorted, otherwise `'asc'` or\n * `'desc'` based on the column's entry in `state.sorting`.\n *\n * @example\n * ```ts\n * const direction = column_getIsSorted(column)\n * ```\n */\nexport function column_getIsSorted<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): false | SortDirection {\n const columnSort = column.table.atoms.sorting\n ?.get()\n ?.find((d) => d.id === column.id)\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n}\n\n/**\n * Finds this column's position in the ordered `state.sorting` array.\n *\n * The result is `-1` when the column is not sorted.\n *\n * @example\n * ```ts\n * const index = column_getSortIndex(column)\n * ```\n */\nexport function column_getSortIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return (\n column.table.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ??\n -1\n )\n}\n\n/**\n * Removes this column from the sorting state.\n *\n * Other sorted columns are preserved, including their relative order.\n *\n * @example\n * ```ts\n * column_clearSorting(column)\n * ```\n */\nexport function column_clearSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n // clear sorting for just 1 column\n table_setSorting(column.table, (old) =>\n old.length ? old.filter((d) => d.id !== column.id) : [],\n )\n}\n\n/**\n * Creates a header event handler that toggles this column's sorting.\n *\n * The handler ignores events when the column cannot sort, persists React-style\n * synthetic events when present, and asks `options.isMultiSortEvent` whether\n * the event should add to a multi-sort.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleSortingHandler(column)\n * ```\n */\nexport function column_getToggleSortingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canSort = column_getCanSort(column)\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column_toggleSorting(\n column,\n\n undefined,\n column_getCanMultiSort(column)\n ? column.table.options.isMultiSortEvent?.(e)\n : false,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,yBAAuC;CACrD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,iBAGd,OAAyC,SAAgC;;CACzE,iDAAM,SAAQ,4GAAkB,OAAO;AACzC;;;;;;;;;;;;;AAcA,SAAgB,mBAGd,OAAyC,cAAwB;CACjE,iBACE,OACA,eAAe,CAAC,IAAIA,yBAAW,MAAM,aAAa,WAAW,CAAC,CAAC,CACjE;AACF;;;;;;;;;;;;;AAgBA,SAAgB,qBAId,QAA6E;CAC7E,MAAM,UACJ,OAAO,MAAM,aAAa;CAE5B,IAAI;CAEJ,MAAM,YAAY,OAAO,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE;CAEzE,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,UAAU,EAAE,CAAE,SAAS,OAAO,EAAE;EAE9C,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,iBAC5C,2DAAS,QAAS;EAGpB,IAAI,OAAO,UAAU,UA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E;CAClC,OAAO,CAAC,aAAa,QAAQ,WAAW,OAAO,SAAS;AAC1D;;;;;;;;;;;AAYA,SAAgB,oBAId,QAA2D;;CAC3D,kCACE,OAAO,MAAM,MAAM,2GAAS,IAAI,mFAAG,WAAW,MAAM,EAAE,OAAO,OAAO,EAAE,MACtE;AAEJ;;;;;;;;;;;AAYA,SAAgB,oBAId,QAAmD;CAEnD,iBAAiB,OAAO,QAAQ,QAC9B,IAAI,SAAS,IAAI,QAAQ,MAAM,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,CACxD;AACF;;;;;;;;;;;;;AAcA,SAAgB,+BAId,QAAmD;CACnD,MAAM,UAAU,kBAAkB,MAAM;CAExC,QAAQ,MAAe;;EACrB,IAAI,CAAC,SAAS;EACb,YAAC,EAAU,2DAAU;EACtB,qBACE,QAEA,QACA,uBAAuB,MAAM,uDACzB,OAAO,MAAM,SAAQ,6HAAmB,CAAC,IACzC,KACN;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"rowSortingFeature.utils.cjs","names":["cloneState","reSplitAlphaNumeric","sortFn_basic","isFunction"],"sources":["../../../src/features/row-sorting/rowSortingFeature.utils.ts"],"sourcesContent":["import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Column_Internal } from '../../types/Column'\nimport type {\n SortDirection,\n SortFn,\n SortingState,\n} from './rowSortingFeature.types'\n\n// State Utils\n\n/**\n * Creates the default sorting state.\n *\n * The feature default is an empty array, meaning no columns are sorted. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const sorting = getDefaultSortingState()\n * ```\n */\nexport function getDefaultSortingState(): SortingState {\n return []\n}\n\n/**\n * Routes a sorting updater through the table's sorting change handler.\n *\n * The updater may be a next `SortingState` array or a function of the previous\n * sorting state, matching the instance `table.setSorting` behavior.\n *\n * @example\n * ```ts\n * table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])\n * ```\n */\nexport function table_setSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<SortingState>) {\n table.options.onSortingChange?.(updater)\n}\n\n/**\n * Resets `sorting` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.sorting` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetSorting(table)\n * table_resetSorting(table, true)\n * ```\n */\nexport function table_resetSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setSorting(\n table,\n defaultState ? [] : cloneState(table.initialState.sorting ?? []),\n )\n}\n\n// Column Utils\n\n/**\n * Chooses a built-in sorting function from sampled filtered row values.\n *\n * Date-like values use `datetime`, mixed text/numeric strings use\n * `alphanumeric`, plain strings use `text`, and unknown values fall back to\n * `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getAutoSortFn(column)\n * ```\n */\nexport function column_getAutoSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10)\n\n let isString = false\n\n for (let i = 0; i < firstRows.length; i++) {\n const value = firstRows[i]!.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n if (sortFns?.datetime) {\n return sortFns.datetime\n }\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n if (sortFns?.alphanumeric) {\n return sortFns.alphanumeric\n }\n }\n }\n }\n\n if (isString) {\n return sortFns?.text ?? sortFn_basic\n }\n\n return sortFn_basic\n}\n\n/**\n * Chooses the default first sort direction from the first filtered row value.\n *\n * String columns start ascending so alphabetical order is natural; other value\n * types start descending.\n *\n * @example\n * ```ts\n * const direction = column_getAutoSortDir(column)\n * ```\n */\nexport function column_getAutoSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const firstRow = column.table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow ? firstRow.getValue(column.id) : undefined\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n}\n\n/**\n * Resolves the sorting function configured for a column.\n *\n * Function-valued `columnDef.sortFn` is returned directly, `'auto'` delegates\n * to `column_getAutoSortFn`, and string values are looked up in the table's\n * sorting function registry before falling back to `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getSortFn(column)\n * ```\n */\nexport function column_getSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n return isFunction(column.columnDef.sortFn)\n ? column.columnDef.sortFn\n : column.columnDef.sortFn === 'auto'\n ? column_getAutoSortFn(column)\n : (sortFns?.[column.columnDef.sortFn as string] ?? sortFn_basic)\n}\n\n/**\n * Applies the next sorting state for this column.\n *\n * The toggle can add, replace, flip, or remove this column's sort entry. Multi\n * sorting respects `enableMultiSort`, `maxMultiSortColCount`, and the `multi`\n * argument.\n *\n * @example\n * ```ts\n * column_toggleSorting(column, undefined, true)\n * ```\n */\nexport function column_toggleSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n desc?: boolean,\n multi?: boolean,\n) {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column_getNextSortingOrder(column)\n const hasManualValue = typeof desc !== 'undefined'\n\n table_setSorting(column.table, (old) => {\n // Find any existing sorting for this column\n const existingSorting = old.find((d) => d.id === column.id)\n const existingIndex = old.findIndex((d) => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n const nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old.length && column_getCanMultiSort(column) && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (column.table.options.maxMultiSortColCount ??\n Number.MAX_SAFE_INTEGER),\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map((d) => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter((d) => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n}\n\n/**\n * Resolves the first direction used when this column begins sorting.\n *\n * Column-level `sortDescFirst` wins, then table-level `sortDescFirst`, then the\n * auto direction inferred from sampled values.\n *\n * @example\n * ```ts\n * const firstDirection = column_getFirstSortDir(column)\n * ```\n */\nexport function column_getFirstSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n column.table.options.sortDescFirst ??\n column_getAutoSortDir(column) === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n}\n\n/**\n * Resolves the next sort order for this column's toggle cycle.\n *\n * The cycle starts with the first sort direction, flips between `asc` and\n * `desc`, and can return `false` when sorting removal is enabled.\n *\n * @example\n * ```ts\n * const nextOrder = column_getNextSortingOrder(column)\n * ```\n */\nexport function column_getNextSortingOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>, multi?: boolean) {\n const firstSortDirection = column_getFirstSortDir(column)\n const isSorted = column_getIsSorted(column)\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (column.table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? (column.table.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n}\n\n/**\n * Checks whether this accessor column can participate in sorting.\n *\n * The column must have an accessor and sorting must be enabled by both the\n * column definition and table options.\n *\n * @example\n * ```ts\n * const canSort = column_getCanSort(column)\n * ```\n */\nexport function column_getCanSort<\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.enableSorting ?? true) &&\n (column.table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Checks whether this column can be added to a multi-sort state.\n *\n * Column-level `enableMultiSort` wins over table-level `enableMultiSort`; if\n * neither is set, accessor columns can multi-sort by default.\n *\n * @example\n * ```ts\n * const canMultiSort = column_getCanMultiSort(column)\n * ```\n */\nexport function column_getCanMultiSort<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n column.columnDef.enableMultiSort ??\n column.table.options.enableMultiSort ??\n !!column.accessorFn\n )\n}\n\n/**\n * Reads this column's current sort direction.\n *\n * The result is `false` when the column is not sorted, otherwise `'asc'` or\n * `'desc'` based on the column's entry in `state.sorting`.\n *\n * @example\n * ```ts\n * const direction = column_getIsSorted(column)\n * ```\n */\nexport function column_getIsSorted<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): false | SortDirection {\n const columnSort = column.table.atoms.sorting\n ?.get()\n ?.find((d) => d.id === column.id)\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n}\n\n/**\n * Finds this column's position in the ordered `state.sorting` array.\n *\n * The result is `-1` when the column is not sorted.\n *\n * @example\n * ```ts\n * const index = column_getSortIndex(column)\n * ```\n */\nexport function column_getSortIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return (\n column.table.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ??\n -1\n )\n}\n\n/**\n * Removes this column from the sorting state.\n *\n * Other sorted columns are preserved, including their relative order.\n *\n * @example\n * ```ts\n * column_clearSorting(column)\n * ```\n */\nexport function column_clearSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n // clear sorting for just 1 column\n table_setSorting(column.table, (old) =>\n old.length ? old.filter((d) => d.id !== column.id) : [],\n )\n}\n\n/**\n * Creates a header event handler that toggles this column's sorting.\n *\n * The handler ignores events when the column cannot sort, persists React-style\n * synthetic events when present, and asks `options.isMultiSortEvent` whether\n * the event should add to a multi-sort.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleSortingHandler(column)\n * ```\n */\nexport function column_getToggleSortingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canSort = column_getCanSort(column)\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column_toggleSorting(\n column,\n\n undefined,\n column_getCanMultiSort(column)\n ? column.table.options.isMultiSortEvent?.(e)\n : false,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,yBAAuC;CACrD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,iBAGd,OAAyC,SAAgC;;CACzE,iDAAM,SAAQ,4GAAkB,OAAO;AACzC;;;;;;;;;;;;;AAcA,SAAgB,mBAGd,OAAyC,cAAwB;CACjE,iBACE,OACA,eAAe,CAAC,IAAIA,yBAAW,MAAM,aAAa,WAAW,CAAC,CAAC,CACjE;AACF;;;;;;;;;;;;;AAgBA,SAAgB,qBAId,QAA6E;CAC7E,MAAM,UACJ,OAAO,MAAM,aAAa;CAE5B,MAAM,YAAY,OAAO,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE;CAEzE,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,UAAU,EAAE,CAAE,SAAS,OAAO,EAAE;EAE9C,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,iBAC5C;yDAAI,QAAS,UACX,OAAO,QAAQ;EACjB;EAGF,IAAI,OAAO,UAAU,UAAU;GAC7B,WAAW;GAEX,IAAI,MAAM,MAAMC,mCAAmB,CAAC,CAAC,SAAS,GAC5C;0DAAI,QAAS,cACX,OAAO,QAAQ;GACjB;EAEJ;CACF;CAEA,IAAI,UACF,0DAAO,QAAS,SAAQC;CAG1B,OAAOA;AACT;;;;;;;;;;;;AAaA,SAAgB,sBAId,QAAmD;CACnD,MAAM,WAAW,OAAO,MAAM,oBAAoB,CAAC,CAAC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BAAiB,OAAO,QAAQ,QAC9B,IAAI,SAAS,IAAI,QAAQ,MAAM,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,CACxD;AACF;;;;;;;;;;;;;AAcA,SAAgB,+BAId,QAAmD;CACnD,MAAM,UAAU,kBAAkB,MAAM;CAExC,QAAQ,MAAe;;EACrB,IAAI,CAAC,SAAS;EACb,YAAC,EAAU,2DAAU;EACtB,qBACE,QAEA,QACA,uBAAuB,MAAM,uDACzB,OAAO,MAAM,SAAQ,6HAAmB,CAAC,IACzC,KACN;CACF;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CellData, RowData, Updater } from "../../types/type-utils.cjs";
|
|
2
2
|
import { SortDirection, SortFn, SortingState } from "./rowSortingFeature.types.cjs";
|
|
3
|
-
import {
|
|
3
|
+
import { Table } from "../../types/Table.cjs";
|
|
4
|
+
import { Column } from "../../types/Column.cjs";
|
|
4
5
|
import { TableFeatures } from "../../types/TableFeatures.cjs";
|
|
5
|
-
import { Table_Internal } from "../../types/Table.cjs";
|
|
6
6
|
|
|
7
7
|
//#region src/features/row-sorting/rowSortingFeature.utils.d.ts
|
|
8
8
|
/**
|
|
@@ -28,7 +28,7 @@ declare function getDefaultSortingState(): SortingState;
|
|
|
28
28
|
* table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
declare function table_setSorting<TFeatures extends TableFeatures, TData extends RowData>(table:
|
|
31
|
+
declare function table_setSorting<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, updater: Updater<SortingState>): void;
|
|
32
32
|
/**
|
|
33
33
|
* Resets `sorting` to the configured initial state or feature default.
|
|
34
34
|
*
|
|
@@ -41,7 +41,7 @@ declare function table_setSorting<TFeatures extends TableFeatures, TData extends
|
|
|
41
41
|
* table_resetSorting(table, true)
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
declare function table_resetSorting<TFeatures extends TableFeatures, TData extends RowData>(table:
|
|
44
|
+
declare function table_resetSorting<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, defaultState?: boolean): void;
|
|
45
45
|
/**
|
|
46
46
|
* Chooses a built-in sorting function from sampled filtered row values.
|
|
47
47
|
*
|
|
@@ -54,7 +54,7 @@ declare function table_resetSorting<TFeatures extends TableFeatures, TData exten
|
|
|
54
54
|
* const sortFn = column_getAutoSortFn(column)
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
57
|
+
declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): SortFn<TFeatures, TData>;
|
|
58
58
|
/**
|
|
59
59
|
* Chooses the default first sort direction from the first filtered row value.
|
|
60
60
|
*
|
|
@@ -66,7 +66,7 @@ declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData ext
|
|
|
66
66
|
* const direction = column_getAutoSortDir(column)
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
69
|
+
declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): "asc" | "desc";
|
|
70
70
|
/**
|
|
71
71
|
* Resolves the sorting function configured for a column.
|
|
72
72
|
*
|
|
@@ -79,7 +79,7 @@ declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData ex
|
|
|
79
79
|
* const sortFn = column_getSortFn(column)
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
declare function column_getSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
82
|
+
declare function column_getSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): SortFn<TFeatures, TData>;
|
|
83
83
|
/**
|
|
84
84
|
* Applies the next sorting state for this column.
|
|
85
85
|
*
|
|
@@ -92,7 +92,7 @@ declare function column_getSortFn<TFeatures extends TableFeatures, TData extends
|
|
|
92
92
|
* column_toggleSorting(column, undefined, true)
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
declare function column_toggleSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
95
|
+
declare function column_toggleSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, desc?: boolean, multi?: boolean): void;
|
|
96
96
|
/**
|
|
97
97
|
* Resolves the first direction used when this column begins sorting.
|
|
98
98
|
*
|
|
@@ -104,7 +104,7 @@ declare function column_toggleSorting<TFeatures extends TableFeatures, TData ext
|
|
|
104
104
|
* const firstDirection = column_getFirstSortDir(column)
|
|
105
105
|
* ```
|
|
106
106
|
*/
|
|
107
|
-
declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
107
|
+
declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): "asc" | "desc";
|
|
108
108
|
/**
|
|
109
109
|
* Resolves the next sort order for this column's toggle cycle.
|
|
110
110
|
*
|
|
@@ -116,7 +116,7 @@ declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData e
|
|
|
116
116
|
* const nextOrder = column_getNextSortingOrder(column)
|
|
117
117
|
* ```
|
|
118
118
|
*/
|
|
119
|
-
declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
119
|
+
declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, multi?: boolean): false | "asc" | "desc";
|
|
120
120
|
/**
|
|
121
121
|
* Checks whether this accessor column can participate in sorting.
|
|
122
122
|
*
|
|
@@ -128,7 +128,7 @@ declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TDa
|
|
|
128
128
|
* const canSort = column_getCanSort(column)
|
|
129
129
|
* ```
|
|
130
130
|
*/
|
|
131
|
-
declare function column_getCanSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
131
|
+
declare function column_getCanSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): boolean;
|
|
132
132
|
/**
|
|
133
133
|
* Checks whether this column can be added to a multi-sort state.
|
|
134
134
|
*
|
|
@@ -140,7 +140,7 @@ declare function column_getCanSort<TFeatures extends TableFeatures, TData extend
|
|
|
140
140
|
* const canMultiSort = column_getCanMultiSort(column)
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
|
-
declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
143
|
+
declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): boolean;
|
|
144
144
|
/**
|
|
145
145
|
* Reads this column's current sort direction.
|
|
146
146
|
*
|
|
@@ -152,7 +152,7 @@ declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData e
|
|
|
152
152
|
* const direction = column_getIsSorted(column)
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
|
-
declare function column_getIsSorted<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
155
|
+
declare function column_getIsSorted<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): false | SortDirection;
|
|
156
156
|
/**
|
|
157
157
|
* Finds this column's position in the ordered `state.sorting` array.
|
|
158
158
|
*
|
|
@@ -163,7 +163,7 @@ declare function column_getIsSorted<TFeatures extends TableFeatures, TData exten
|
|
|
163
163
|
* const index = column_getSortIndex(column)
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
166
|
-
declare function column_getSortIndex<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
166
|
+
declare function column_getSortIndex<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): number;
|
|
167
167
|
/**
|
|
168
168
|
* Removes this column from the sorting state.
|
|
169
169
|
*
|
|
@@ -174,7 +174,7 @@ declare function column_getSortIndex<TFeatures extends TableFeatures, TData exte
|
|
|
174
174
|
* column_clearSorting(column)
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
|
-
declare function column_clearSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
177
|
+
declare function column_clearSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): void;
|
|
178
178
|
/**
|
|
179
179
|
* Creates a header event handler that toggles this column's sorting.
|
|
180
180
|
*
|
|
@@ -187,7 +187,7 @@ declare function column_clearSorting<TFeatures extends TableFeatures, TData exte
|
|
|
187
187
|
* const onClick = column_getToggleSortingHandler(column)
|
|
188
188
|
* ```
|
|
189
189
|
*/
|
|
190
|
-
declare function column_getToggleSortingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
190
|
+
declare function column_getToggleSortingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): (e: unknown) => void;
|
|
191
191
|
//#endregion
|
|
192
192
|
export { column_clearSorting, column_getAutoSortDir, column_getAutoSortFn, column_getCanMultiSort, column_getCanSort, column_getFirstSortDir, column_getIsSorted, column_getNextSortingOrder, column_getSortFn, column_getSortIndex, column_getToggleSortingHandler, column_toggleSorting, getDefaultSortingState, table_resetSorting, table_setSorting };
|
|
193
193
|
//# sourceMappingURL=rowSortingFeature.utils.d.cts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CellData, RowData, Updater } from "../../types/type-utils.js";
|
|
2
2
|
import { SortDirection, SortFn, SortingState } from "./rowSortingFeature.types.js";
|
|
3
|
-
import {
|
|
3
|
+
import { Table } from "../../types/Table.js";
|
|
4
|
+
import { Column } from "../../types/Column.js";
|
|
4
5
|
import { TableFeatures } from "../../types/TableFeatures.js";
|
|
5
|
-
import { Table_Internal } from "../../types/Table.js";
|
|
6
6
|
|
|
7
7
|
//#region src/features/row-sorting/rowSortingFeature.utils.d.ts
|
|
8
8
|
/**
|
|
@@ -28,7 +28,7 @@ declare function getDefaultSortingState(): SortingState;
|
|
|
28
28
|
* table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
declare function table_setSorting<TFeatures extends TableFeatures, TData extends RowData>(table:
|
|
31
|
+
declare function table_setSorting<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, updater: Updater<SortingState>): void;
|
|
32
32
|
/**
|
|
33
33
|
* Resets `sorting` to the configured initial state or feature default.
|
|
34
34
|
*
|
|
@@ -41,7 +41,7 @@ declare function table_setSorting<TFeatures extends TableFeatures, TData extends
|
|
|
41
41
|
* table_resetSorting(table, true)
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
declare function table_resetSorting<TFeatures extends TableFeatures, TData extends RowData>(table:
|
|
44
|
+
declare function table_resetSorting<TFeatures extends TableFeatures, TData extends RowData>(table: Table<TFeatures, TData>, defaultState?: boolean): void;
|
|
45
45
|
/**
|
|
46
46
|
* Chooses a built-in sorting function from sampled filtered row values.
|
|
47
47
|
*
|
|
@@ -54,7 +54,7 @@ declare function table_resetSorting<TFeatures extends TableFeatures, TData exten
|
|
|
54
54
|
* const sortFn = column_getAutoSortFn(column)
|
|
55
55
|
* ```
|
|
56
56
|
*/
|
|
57
|
-
declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
57
|
+
declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): SortFn<TFeatures, TData>;
|
|
58
58
|
/**
|
|
59
59
|
* Chooses the default first sort direction from the first filtered row value.
|
|
60
60
|
*
|
|
@@ -66,7 +66,7 @@ declare function column_getAutoSortFn<TFeatures extends TableFeatures, TData ext
|
|
|
66
66
|
* const direction = column_getAutoSortDir(column)
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
69
|
+
declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): "asc" | "desc";
|
|
70
70
|
/**
|
|
71
71
|
* Resolves the sorting function configured for a column.
|
|
72
72
|
*
|
|
@@ -79,7 +79,7 @@ declare function column_getAutoSortDir<TFeatures extends TableFeatures, TData ex
|
|
|
79
79
|
* const sortFn = column_getSortFn(column)
|
|
80
80
|
* ```
|
|
81
81
|
*/
|
|
82
|
-
declare function column_getSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
82
|
+
declare function column_getSortFn<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): SortFn<TFeatures, TData>;
|
|
83
83
|
/**
|
|
84
84
|
* Applies the next sorting state for this column.
|
|
85
85
|
*
|
|
@@ -92,7 +92,7 @@ declare function column_getSortFn<TFeatures extends TableFeatures, TData extends
|
|
|
92
92
|
* column_toggleSorting(column, undefined, true)
|
|
93
93
|
* ```
|
|
94
94
|
*/
|
|
95
|
-
declare function column_toggleSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
95
|
+
declare function column_toggleSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, desc?: boolean, multi?: boolean): void;
|
|
96
96
|
/**
|
|
97
97
|
* Resolves the first direction used when this column begins sorting.
|
|
98
98
|
*
|
|
@@ -104,7 +104,7 @@ declare function column_toggleSorting<TFeatures extends TableFeatures, TData ext
|
|
|
104
104
|
* const firstDirection = column_getFirstSortDir(column)
|
|
105
105
|
* ```
|
|
106
106
|
*/
|
|
107
|
-
declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
107
|
+
declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): "asc" | "desc";
|
|
108
108
|
/**
|
|
109
109
|
* Resolves the next sort order for this column's toggle cycle.
|
|
110
110
|
*
|
|
@@ -116,7 +116,7 @@ declare function column_getFirstSortDir<TFeatures extends TableFeatures, TData e
|
|
|
116
116
|
* const nextOrder = column_getNextSortingOrder(column)
|
|
117
117
|
* ```
|
|
118
118
|
*/
|
|
119
|
-
declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
119
|
+
declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>, multi?: boolean): false | "asc" | "desc";
|
|
120
120
|
/**
|
|
121
121
|
* Checks whether this accessor column can participate in sorting.
|
|
122
122
|
*
|
|
@@ -128,7 +128,7 @@ declare function column_getNextSortingOrder<TFeatures extends TableFeatures, TDa
|
|
|
128
128
|
* const canSort = column_getCanSort(column)
|
|
129
129
|
* ```
|
|
130
130
|
*/
|
|
131
|
-
declare function column_getCanSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
131
|
+
declare function column_getCanSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): boolean;
|
|
132
132
|
/**
|
|
133
133
|
* Checks whether this column can be added to a multi-sort state.
|
|
134
134
|
*
|
|
@@ -140,7 +140,7 @@ declare function column_getCanSort<TFeatures extends TableFeatures, TData extend
|
|
|
140
140
|
* const canMultiSort = column_getCanMultiSort(column)
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
|
-
declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
143
|
+
declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): boolean;
|
|
144
144
|
/**
|
|
145
145
|
* Reads this column's current sort direction.
|
|
146
146
|
*
|
|
@@ -152,7 +152,7 @@ declare function column_getCanMultiSort<TFeatures extends TableFeatures, TData e
|
|
|
152
152
|
* const direction = column_getIsSorted(column)
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
|
-
declare function column_getIsSorted<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
155
|
+
declare function column_getIsSorted<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): false | SortDirection;
|
|
156
156
|
/**
|
|
157
157
|
* Finds this column's position in the ordered `state.sorting` array.
|
|
158
158
|
*
|
|
@@ -163,7 +163,7 @@ declare function column_getIsSorted<TFeatures extends TableFeatures, TData exten
|
|
|
163
163
|
* const index = column_getSortIndex(column)
|
|
164
164
|
* ```
|
|
165
165
|
*/
|
|
166
|
-
declare function column_getSortIndex<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
166
|
+
declare function column_getSortIndex<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): number;
|
|
167
167
|
/**
|
|
168
168
|
* Removes this column from the sorting state.
|
|
169
169
|
*
|
|
@@ -174,7 +174,7 @@ declare function column_getSortIndex<TFeatures extends TableFeatures, TData exte
|
|
|
174
174
|
* column_clearSorting(column)
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
|
-
declare function column_clearSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
177
|
+
declare function column_clearSorting<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): void;
|
|
178
178
|
/**
|
|
179
179
|
* Creates a header event handler that toggles this column's sorting.
|
|
180
180
|
*
|
|
@@ -187,7 +187,7 @@ declare function column_clearSorting<TFeatures extends TableFeatures, TData exte
|
|
|
187
187
|
* const onClick = column_getToggleSortingHandler(column)
|
|
188
188
|
* ```
|
|
189
189
|
*/
|
|
190
|
-
declare function column_getToggleSortingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column:
|
|
190
|
+
declare function column_getToggleSortingHandler<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>(column: Column<TFeatures, TData, TValue>): (e: unknown) => void;
|
|
191
191
|
//#endregion
|
|
192
192
|
export { column_clearSorting, column_getAutoSortDir, column_getAutoSortFn, column_getCanMultiSort, column_getCanSort, column_getFirstSortDir, column_getIsSorted, column_getNextSortingOrder, column_getSortFn, column_getSortIndex, column_getToggleSortingHandler, column_toggleSorting, getDefaultSortingState, table_resetSorting, table_setSorting };
|
|
193
193
|
//# sourceMappingURL=rowSortingFeature.utils.d.ts.map
|
|
@@ -60,19 +60,22 @@ function table_resetSorting(table, defaultState) {
|
|
|
60
60
|
*/
|
|
61
61
|
function column_getAutoSortFn(column) {
|
|
62
62
|
const sortFns = column.table._rowModelFns.sortFns;
|
|
63
|
-
let sortFn;
|
|
64
63
|
const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10);
|
|
65
64
|
let isString = false;
|
|
66
65
|
for (let i = 0; i < firstRows.length; i++) {
|
|
67
66
|
const value = firstRows[i].getValue(column.id);
|
|
68
|
-
if (Object.prototype.toString.call(value) === "[object Date]")
|
|
67
|
+
if (Object.prototype.toString.call(value) === "[object Date]") {
|
|
68
|
+
if (sortFns === null || sortFns === void 0 ? void 0 : sortFns.datetime) return sortFns.datetime;
|
|
69
|
+
}
|
|
69
70
|
if (typeof value === "string") {
|
|
70
71
|
isString = true;
|
|
71
|
-
if (value.split(reSplitAlphaNumeric).length > 1)
|
|
72
|
+
if (value.split(reSplitAlphaNumeric).length > 1) {
|
|
73
|
+
if (sortFns === null || sortFns === void 0 ? void 0 : sortFns.alphanumeric) return sortFns.alphanumeric;
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
|
-
if (isString)
|
|
75
|
-
return
|
|
77
|
+
if (isString) return (sortFns === null || sortFns === void 0 ? void 0 : sortFns.text) ?? sortFn_basic;
|
|
78
|
+
return sortFn_basic;
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* Chooses the default first sort direction from the first filtered row value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rowSortingFeature.utils.js","names":[],"sources":["../../../src/features/row-sorting/rowSortingFeature.utils.ts"],"sourcesContent":["import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Column_Internal } from '../../types/Column'\nimport type {\n SortDirection,\n SortFn,\n SortingState,\n} from './rowSortingFeature.types'\n\n// State Utils\n\n/**\n * Creates the default sorting state.\n *\n * The feature default is an empty array, meaning no columns are sorted. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const sorting = getDefaultSortingState()\n * ```\n */\nexport function getDefaultSortingState(): SortingState {\n return []\n}\n\n/**\n * Routes a sorting updater through the table's sorting change handler.\n *\n * The updater may be a next `SortingState` array or a function of the previous\n * sorting state, matching the instance `table.setSorting` behavior.\n *\n * @example\n * ```ts\n * table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])\n * ```\n */\nexport function table_setSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<SortingState>) {\n table.options.onSortingChange?.(updater)\n}\n\n/**\n * Resets `sorting` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.sorting` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetSorting(table)\n * table_resetSorting(table, true)\n * ```\n */\nexport function table_resetSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setSorting(\n table,\n defaultState ? [] : cloneState(table.initialState.sorting ?? []),\n )\n}\n\n// Column Utils\n\n/**\n * Chooses a built-in sorting function from sampled filtered row values.\n *\n * Date-like values use `datetime`, mixed text/numeric strings use\n * `alphanumeric`, plain strings use `text`, and unknown values fall back to\n * `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getAutoSortFn(column)\n * ```\n */\nexport function column_getAutoSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n let sortFn: SortFn<TFeatures, TData> | undefined\n\n const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10)\n\n let isString = false\n\n for (let i = 0; i < firstRows.length; i++) {\n const value = firstRows[i]!.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n sortFn = sortFns?.datetime\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n sortFn = sortFns?.alphanumeric\n }\n }\n }\n\n if (isString) {\n sortFn = sortFns?.text\n }\n\n return sortFn ?? sortFn_basic\n}\n\n/**\n * Chooses the default first sort direction from the first filtered row value.\n *\n * String columns start ascending so alphabetical order is natural; other value\n * types start descending.\n *\n * @example\n * ```ts\n * const direction = column_getAutoSortDir(column)\n * ```\n */\nexport function column_getAutoSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const firstRow = column.table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow ? firstRow.getValue(column.id) : undefined\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n}\n\n/**\n * Resolves the sorting function configured for a column.\n *\n * Function-valued `columnDef.sortFn` is returned directly, `'auto'` delegates\n * to `column_getAutoSortFn`, and string values are looked up in the table's\n * sorting function registry before falling back to `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getSortFn(column)\n * ```\n */\nexport function column_getSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n return isFunction(column.columnDef.sortFn)\n ? column.columnDef.sortFn\n : column.columnDef.sortFn === 'auto'\n ? column_getAutoSortFn(column)\n : (sortFns?.[column.columnDef.sortFn as string] ?? sortFn_basic)\n}\n\n/**\n * Applies the next sorting state for this column.\n *\n * The toggle can add, replace, flip, or remove this column's sort entry. Multi\n * sorting respects `enableMultiSort`, `maxMultiSortColCount`, and the `multi`\n * argument.\n *\n * @example\n * ```ts\n * column_toggleSorting(column, undefined, true)\n * ```\n */\nexport function column_toggleSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n desc?: boolean,\n multi?: boolean,\n) {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column_getNextSortingOrder(column)\n const hasManualValue = typeof desc !== 'undefined'\n\n table_setSorting(column.table, (old) => {\n // Find any existing sorting for this column\n const existingSorting = old.find((d) => d.id === column.id)\n const existingIndex = old.findIndex((d) => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n const nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old.length && column_getCanMultiSort(column) && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (column.table.options.maxMultiSortColCount ??\n Number.MAX_SAFE_INTEGER),\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map((d) => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter((d) => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n}\n\n/**\n * Resolves the first direction used when this column begins sorting.\n *\n * Column-level `sortDescFirst` wins, then table-level `sortDescFirst`, then the\n * auto direction inferred from sampled values.\n *\n * @example\n * ```ts\n * const firstDirection = column_getFirstSortDir(column)\n * ```\n */\nexport function column_getFirstSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n column.table.options.sortDescFirst ??\n column_getAutoSortDir(column) === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n}\n\n/**\n * Resolves the next sort order for this column's toggle cycle.\n *\n * The cycle starts with the first sort direction, flips between `asc` and\n * `desc`, and can return `false` when sorting removal is enabled.\n *\n * @example\n * ```ts\n * const nextOrder = column_getNextSortingOrder(column)\n * ```\n */\nexport function column_getNextSortingOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>, multi?: boolean) {\n const firstSortDirection = column_getFirstSortDir(column)\n const isSorted = column_getIsSorted(column)\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (column.table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? (column.table.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n}\n\n/**\n * Checks whether this accessor column can participate in sorting.\n *\n * The column must have an accessor and sorting must be enabled by both the\n * column definition and table options.\n *\n * @example\n * ```ts\n * const canSort = column_getCanSort(column)\n * ```\n */\nexport function column_getCanSort<\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.enableSorting ?? true) &&\n (column.table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Checks whether this column can be added to a multi-sort state.\n *\n * Column-level `enableMultiSort` wins over table-level `enableMultiSort`; if\n * neither is set, accessor columns can multi-sort by default.\n *\n * @example\n * ```ts\n * const canMultiSort = column_getCanMultiSort(column)\n * ```\n */\nexport function column_getCanMultiSort<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n column.columnDef.enableMultiSort ??\n column.table.options.enableMultiSort ??\n !!column.accessorFn\n )\n}\n\n/**\n * Reads this column's current sort direction.\n *\n * The result is `false` when the column is not sorted, otherwise `'asc'` or\n * `'desc'` based on the column's entry in `state.sorting`.\n *\n * @example\n * ```ts\n * const direction = column_getIsSorted(column)\n * ```\n */\nexport function column_getIsSorted<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): false | SortDirection {\n const columnSort = column.table.atoms.sorting\n ?.get()\n ?.find((d) => d.id === column.id)\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n}\n\n/**\n * Finds this column's position in the ordered `state.sorting` array.\n *\n * The result is `-1` when the column is not sorted.\n *\n * @example\n * ```ts\n * const index = column_getSortIndex(column)\n * ```\n */\nexport function column_getSortIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return (\n column.table.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ??\n -1\n )\n}\n\n/**\n * Removes this column from the sorting state.\n *\n * Other sorted columns are preserved, including their relative order.\n *\n * @example\n * ```ts\n * column_clearSorting(column)\n * ```\n */\nexport function column_clearSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n // clear sorting for just 1 column\n table_setSorting(column.table, (old) =>\n old.length ? old.filter((d) => d.id !== column.id) : [],\n )\n}\n\n/**\n * Creates a header event handler that toggles this column's sorting.\n *\n * The handler ignores events when the column cannot sort, persists React-style\n * synthetic events when present, and asks `options.isMultiSortEvent` whether\n * the event should add to a multi-sort.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleSortingHandler(column)\n * ```\n */\nexport function column_getToggleSortingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canSort = column_getCanSort(column)\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column_toggleSorting(\n column,\n\n undefined,\n column_getCanMultiSort(column)\n ? column.table.options.isMultiSortEvent?.(e)\n : false,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,yBAAuC;CACrD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,iBAGd,OAAyC,SAAgC;;CACzE,iDAAM,SAAQ,4GAAkB,OAAO;AACzC;;;;;;;;;;;;;AAcA,SAAgB,mBAGd,OAAyC,cAAwB;CACjE,iBACE,OACA,eAAe,CAAC,IAAI,WAAW,MAAM,aAAa,WAAW,CAAC,CAAC,CACjE;AACF;;;;;;;;;;;;;AAgBA,SAAgB,qBAId,QAA6E;CAC7E,MAAM,UACJ,OAAO,MAAM,aAAa;CAE5B,IAAI;CAEJ,MAAM,YAAY,OAAO,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,EAAE;CAEzE,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,UAAU,EAAE,CAAE,SAAS,OAAO,EAAE;EAE9C,IAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,iBAC5C,2DAAS,QAAS;EAGpB,IAAI,OAAO,UAAU,UAAU;GAC7B,WAAW;GAEX,IAAI,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,GAC5C,2DAAS,QAAS;EAEtB;CACF;CAEA,IAAI,UACF,2DAAS,QAAS;CAGpB,OAAO,UAAU;AACnB;;;;;;;;;;;;AAaA,SAAgB,sBAId,QAAmD;CACnD,MAAM,WAAW,OAAO,MAAM,oBAAoB,CAAC,CAAC,SAAS;CAI7D,IAAI,QAFU,WAAW,SAAS,SAAS,OAAO,EAAE,IAAI,YAEnC,UACnB,OAAO;CAGT,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,iBAId,QAA6E;CAC7E,MAAM,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M,UAAU,kBAAkB,MAAM;CAExC,QAAQ,MAAe;;EACrB,IAAI,CAAC,SAAS;EACb,YAAC,EAAU,2DAAU;EACtB,qBACE,QAEA,QACA,uBAAuB,MAAM,uDACzB,OAAO,MAAM,SAAQ,6HAAmB,CAAC,IACzC,KACN;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"rowSortingFeature.utils.js","names":[],"sources":["../../../src/features/row-sorting/rowSortingFeature.utils.ts"],"sourcesContent":["import { reSplitAlphaNumeric, sortFn_basic } from '../../fns/sortFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { CellData, RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Column_Internal } from '../../types/Column'\nimport type {\n SortDirection,\n SortFn,\n SortingState,\n} from './rowSortingFeature.types'\n\n// State Utils\n\n/**\n * Creates the default sorting state.\n *\n * The feature default is an empty array, meaning no columns are sorted. Reset\n * APIs use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const sorting = getDefaultSortingState()\n * ```\n */\nexport function getDefaultSortingState(): SortingState {\n return []\n}\n\n/**\n * Routes a sorting updater through the table's sorting change handler.\n *\n * The updater may be a next `SortingState` array or a function of the previous\n * sorting state, matching the instance `table.setSorting` behavior.\n *\n * @example\n * ```ts\n * table_setSorting(table, (old) => [...old, { id: 'age', desc: true }])\n * ```\n */\nexport function table_setSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: Updater<SortingState>) {\n table.options.onSortingChange?.(updater)\n}\n\n/**\n * Resets `sorting` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.sorting` when it\n * exists. Passing `true` ignores initial state and resets to `[]`.\n *\n * @example\n * ```ts\n * table_resetSorting(table)\n * table_resetSorting(table, true)\n * ```\n */\nexport function table_resetSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setSorting(\n table,\n defaultState ? [] : cloneState(table.initialState.sorting ?? []),\n )\n}\n\n// Column Utils\n\n/**\n * Chooses a built-in sorting function from sampled filtered row values.\n *\n * Date-like values use `datetime`, mixed text/numeric strings use\n * `alphanumeric`, plain strings use `text`, and unknown values fall back to\n * `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getAutoSortFn(column)\n * ```\n */\nexport function column_getAutoSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n const firstRows = column.table.getFilteredRowModel().flatRows.slice(0, 10)\n\n let isString = false\n\n for (let i = 0; i < firstRows.length; i++) {\n const value = firstRows[i]!.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n if (sortFns?.datetime) {\n return sortFns.datetime\n }\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n if (sortFns?.alphanumeric) {\n return sortFns.alphanumeric\n }\n }\n }\n }\n\n if (isString) {\n return sortFns?.text ?? sortFn_basic\n }\n\n return sortFn_basic\n}\n\n/**\n * Chooses the default first sort direction from the first filtered row value.\n *\n * String columns start ascending so alphabetical order is natural; other value\n * types start descending.\n *\n * @example\n * ```ts\n * const direction = column_getAutoSortDir(column)\n * ```\n */\nexport function column_getAutoSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const firstRow = column.table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow ? firstRow.getValue(column.id) : undefined\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n}\n\n/**\n * Resolves the sorting function configured for a column.\n *\n * Function-valued `columnDef.sortFn` is returned directly, `'auto'` delegates\n * to `column_getAutoSortFn`, and string values are looked up in the table's\n * sorting function registry before falling back to `basic`.\n *\n * @example\n * ```ts\n * const sortFn = column_getSortFn(column)\n * ```\n */\nexport function column_getSortFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): SortFn<TFeatures, TData> {\n const sortFns: Record<string, SortFn<TFeatures, TData>> | undefined =\n column.table._rowModelFns.sortFns\n\n return isFunction(column.columnDef.sortFn)\n ? column.columnDef.sortFn\n : column.columnDef.sortFn === 'auto'\n ? column_getAutoSortFn(column)\n : (sortFns?.[column.columnDef.sortFn as string] ?? sortFn_basic)\n}\n\n/**\n * Applies the next sorting state for this column.\n *\n * The toggle can add, replace, flip, or remove this column's sort entry. Multi\n * sorting respects `enableMultiSort`, `maxMultiSortColCount`, and the `multi`\n * argument.\n *\n * @example\n * ```ts\n * column_toggleSorting(column, undefined, true)\n * ```\n */\nexport function column_toggleSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(\n column: Column_Internal<TFeatures, TData, TValue>,\n desc?: boolean,\n multi?: boolean,\n) {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column_getNextSortingOrder(column)\n const hasManualValue = typeof desc !== 'undefined'\n\n table_setSorting(column.table, (old) => {\n // Find any existing sorting for this column\n const existingSorting = old.find((d) => d.id === column.id)\n const existingIndex = old.findIndex((d) => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n const nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old.length && column_getCanMultiSort(column) && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (column.table.options.maxMultiSortColCount ??\n Number.MAX_SAFE_INTEGER),\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map((d) => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter((d) => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n}\n\n/**\n * Resolves the first direction used when this column begins sorting.\n *\n * Column-level `sortDescFirst` wins, then table-level `sortDescFirst`, then the\n * auto direction inferred from sampled values.\n *\n * @example\n * ```ts\n * const firstDirection = column_getFirstSortDir(column)\n * ```\n */\nexport function column_getFirstSortDir<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n column.table.options.sortDescFirst ??\n column_getAutoSortDir(column) === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n}\n\n/**\n * Resolves the next sort order for this column's toggle cycle.\n *\n * The cycle starts with the first sort direction, flips between `asc` and\n * `desc`, and can return `false` when sorting removal is enabled.\n *\n * @example\n * ```ts\n * const nextOrder = column_getNextSortingOrder(column)\n * ```\n */\nexport function column_getNextSortingOrder<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>, multi?: boolean) {\n const firstSortDirection = column_getFirstSortDir(column)\n const isSorted = column_getIsSorted(column)\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (column.table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? (column.table.options.enableMultiRemove ?? true) : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n}\n\n/**\n * Checks whether this accessor column can participate in sorting.\n *\n * The column must have an accessor and sorting must be enabled by both the\n * column definition and table options.\n *\n * @example\n * ```ts\n * const canSort = column_getCanSort(column)\n * ```\n */\nexport function column_getCanSort<\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.enableSorting ?? true) &&\n (column.table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Checks whether this column can be added to a multi-sort state.\n *\n * Column-level `enableMultiSort` wins over table-level `enableMultiSort`; if\n * neither is set, accessor columns can multi-sort by default.\n *\n * @example\n * ```ts\n * const canMultiSort = column_getCanMultiSort(column)\n * ```\n */\nexport function column_getCanMultiSort<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n column.columnDef.enableMultiSort ??\n column.table.options.enableMultiSort ??\n !!column.accessorFn\n )\n}\n\n/**\n * Reads this column's current sort direction.\n *\n * The result is `false` when the column is not sorted, otherwise `'asc'` or\n * `'desc'` based on the column's entry in `state.sorting`.\n *\n * @example\n * ```ts\n * const direction = column_getIsSorted(column)\n * ```\n */\nexport function column_getIsSorted<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): false | SortDirection {\n const columnSort = column.table.atoms.sorting\n ?.get()\n ?.find((d) => d.id === column.id)\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n}\n\n/**\n * Finds this column's position in the ordered `state.sorting` array.\n *\n * The result is `-1` when the column is not sorted.\n *\n * @example\n * ```ts\n * const index = column_getSortIndex(column)\n * ```\n */\nexport function column_getSortIndex<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): number {\n return (\n column.table.atoms.sorting?.get()?.findIndex((d) => d.id === column.id) ??\n -1\n )\n}\n\n/**\n * Removes this column from the sorting state.\n *\n * Other sorted columns are preserved, including their relative order.\n *\n * @example\n * ```ts\n * column_clearSorting(column)\n * ```\n */\nexport function column_clearSorting<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n // clear sorting for just 1 column\n table_setSorting(column.table, (old) =>\n old.length ? old.filter((d) => d.id !== column.id) : [],\n )\n}\n\n/**\n * Creates a header event handler that toggles this column's sorting.\n *\n * The handler ignores events when the column cannot sort, persists React-style\n * synthetic events when present, and asks `options.isMultiSortEvent` whether\n * the event should add to a multi-sort.\n *\n * @example\n * ```ts\n * const onClick = column_getToggleSortingHandler(column)\n * ```\n */\nexport function column_getToggleSortingHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>) {\n const canSort = column_getCanSort(column)\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column_toggleSorting(\n column,\n\n undefined,\n column_getCanMultiSort(column)\n ? column.table.options.isMultiSortEvent?.(e)\n : false,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAyBA,SAAgB,yBAAuC;CACrD,OAAO,CAAC;AACV;;;;;;;;;;;;AAaA,SAAgB,iBAGd,OAAyC,SAAgC;;CACzE,iDAAM,SAAQ,4GAAkB,OAAO;AACzC;;;;;;;;;;;;;AAcA,S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,IACE,aAAa,uBACZ,OAAO,MAAM,QAAQ,wBAAwB,UAC7C,QAAS,OAAO,MAAM,QAAQ,qBAAqB,OAAQ,OAE5D,OAAO;CAET,OAAO,aAAa,SAAS,QAAQ;AACvC;;;;;;;;;;;;AAaA,SAAgB,kBAId,QAAmD;CACnD,QACG,OAAO,UAAU,iBAAiB,UAClC,OAAO,MAAM,QAAQ,iBAAiB,SACvC,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,uBAId,QAA4D;CAC5D,OACE,OAAO,UAAU,mBACjB,OAAO,MAAM,QAAQ,mBACrB,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,mBAId,QAA0E;;CAC1E,MAAM,sCAAa,OAAO,MAAM,MAAM,wGAClC,IAAI,iFACJ,MAAM,MAAM,EAAE,OAAO,OAAO,EAAE;CAClC,OAAO,CAAC,aAAa,QAAQ,WAAW,OAAO,SAAS;AAC1D;;;;;;;;;;;AAYA,SAAgB,oBAId,QAA2D;;CAC3D,kCACE,OAAO,MAAM,MAAM,2GAAS,IAAI,mFAAG,WAAW,MAAM,EAAE,OAAO,OAAO,EAAE,MACtE;AAEJ;;;;;;;;;;;AAYA,SAAgB,oBAId,QAAmD;CAEnD,iBAAiB,OAAO,QAAQ,QAC9B,IAAI,SAAS,IAAI,QAAQ,MAAM,EAAE,OAAO,OAAO,EAAE,IAAI,CAAC,CACxD;AACF;;;;;;;;;;;;;AAcA,SAAgB,+BAId,QAAmD;CACnD,MAAM,UAAU,kBAAkB,MAAM;CAExC,QAAQ,MAAe;;EACrB,IAAI,CAAC,SAAS;EACb,YAAC,EAAU,2DAAU;EACtB,qBACE,QAEA,QACA,uBAAuB,MAAM,uDACzB,OAAO,MAAM,SAAQ,6HAAmB,CAAC,IACzC,KACN;CACF;AACF"}
|
|
@@ -6,47 +6,47 @@
|
|
|
6
6
|
* Non-number values contribute `0`. Child rows are used so nested group totals
|
|
7
7
|
* can reuse already aggregated values.
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
function aggregationFn_sum(columnId, _leafRows, childRows) {
|
|
10
10
|
return childRows.reduce((sumValue, next) => {
|
|
11
11
|
const nextValue = next.getValue(columnId);
|
|
12
12
|
return sumValue + (typeof nextValue === "number" ? nextValue : 0);
|
|
13
13
|
}, 0);
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
/**
|
|
16
16
|
* Finds the minimum numeric child-row value for a grouped column.
|
|
17
17
|
*
|
|
18
18
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
19
19
|
* numeric value is found.
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
function aggregationFn_min(columnId, _leafRows, childRows) {
|
|
22
22
|
let minValue;
|
|
23
23
|
childRows.forEach((row) => {
|
|
24
24
|
const value = row.getValue(columnId);
|
|
25
25
|
if (value != null && typeof value === "number" && (minValue === void 0 || value < minValue)) minValue = value;
|
|
26
26
|
});
|
|
27
27
|
return minValue;
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
/**
|
|
30
30
|
* Finds the maximum numeric child-row value for a grouped column.
|
|
31
31
|
*
|
|
32
32
|
* Nullish and non-number values are ignored. Returns `undefined` when no
|
|
33
33
|
* numeric value is found.
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
function aggregationFn_max(columnId, _leafRows, childRows) {
|
|
36
36
|
let maxValue;
|
|
37
37
|
childRows.forEach((row) => {
|
|
38
38
|
const value = row.getValue(columnId);
|
|
39
39
|
if (value != null && typeof value === "number" && (maxValue === void 0 || value > maxValue)) maxValue = value;
|
|
40
40
|
});
|
|
41
41
|
return maxValue;
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
/**
|
|
44
44
|
* Finds the numeric extent for a grouped column.
|
|
45
45
|
*
|
|
46
46
|
* Returns `[min, max]`, where each entry is `undefined` when no numeric value is
|
|
47
47
|
* present.
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
function aggregationFn_extent(columnId, _leafRows, childRows) {
|
|
50
50
|
let minValue;
|
|
51
51
|
let maxValue;
|
|
52
52
|
childRows.forEach((row) => {
|
|
@@ -58,14 +58,14 @@ const aggregationFn_extent = (columnId, _leafRows, childRows) => {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
return [minValue, maxValue];
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
/**
|
|
63
63
|
* Averages numeric leaf-row values for a grouped column.
|
|
64
64
|
*
|
|
65
65
|
* Number-like values are coerced with unary `+`; nullish and non-numeric values
|
|
66
66
|
* are ignored.
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
function aggregationFn_mean(columnId, leafRows) {
|
|
69
69
|
let count = 0;
|
|
70
70
|
let sumValue = 0;
|
|
71
71
|
leafRows.forEach((row) => {
|
|
@@ -82,14 +82,14 @@ const aggregationFn_mean = (columnId, leafRows) => {
|
|
|
82
82
|
}
|
|
83
83
|
});
|
|
84
84
|
if (count) return sumValue / count;
|
|
85
|
-
}
|
|
85
|
+
}
|
|
86
86
|
/**
|
|
87
87
|
* Computes the median of numeric leaf-row values for a grouped column.
|
|
88
88
|
*
|
|
89
89
|
* All values must be numbers. If any value is non-numeric, or no leaf rows are
|
|
90
90
|
* present, the result is `undefined`.
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
function aggregationFn_median(columnId, leafRows) {
|
|
93
93
|
if (!leafRows.length) return;
|
|
94
94
|
const values = new Array(leafRows.length);
|
|
95
95
|
for (let i = 0; i < leafRows.length; i++) {
|
|
@@ -101,35 +101,35 @@ const aggregationFn_median = (columnId, leafRows) => {
|
|
|
101
101
|
const mid = Math.floor(values.length / 2);
|
|
102
102
|
values.sort((a, b) => a - b);
|
|
103
103
|
return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2;
|
|
104
|
-
}
|
|
104
|
+
}
|
|
105
105
|
/**
|
|
106
106
|
* Collects unique leaf-row values for a grouped column.
|
|
107
107
|
*
|
|
108
108
|
* Values are compared with JavaScript `Set` semantics.
|
|
109
109
|
*/
|
|
110
|
-
|
|
110
|
+
function aggregationFn_unique(columnId, leafRows) {
|
|
111
111
|
const set = /* @__PURE__ */ new Set();
|
|
112
112
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
113
113
|
return Array.from(set.values());
|
|
114
|
-
}
|
|
114
|
+
}
|
|
115
115
|
/**
|
|
116
116
|
* Counts unique leaf-row values for a grouped column.
|
|
117
117
|
*
|
|
118
118
|
* Values are compared with JavaScript `Set` semantics.
|
|
119
119
|
*/
|
|
120
|
-
|
|
120
|
+
function aggregationFn_uniqueCount(columnId, leafRows) {
|
|
121
121
|
const set = /* @__PURE__ */ new Set();
|
|
122
122
|
for (let i = 0; i < leafRows.length; i++) set.add(leafRows[i].getValue(columnId));
|
|
123
123
|
return set.size;
|
|
124
|
-
}
|
|
124
|
+
}
|
|
125
125
|
/**
|
|
126
126
|
* Counts the number of leaf rows in the group.
|
|
127
127
|
*
|
|
128
128
|
* The column id is ignored because the result is based only on group size.
|
|
129
129
|
*/
|
|
130
|
-
|
|
130
|
+
function aggregationFn_count(_columnId, leafRows) {
|
|
131
131
|
return leafRows.length;
|
|
132
|
-
}
|
|
132
|
+
}
|
|
133
133
|
/**
|
|
134
134
|
* The built-in aggregation function registry.
|
|
135
135
|
*
|