@tanstack/table-core 9.0.0-alpha.0 → 9.0.0-alpha.11
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/esm/core/cells/constructCell.d.ts +7 -0
- package/dist/esm/core/cells/constructCell.js +21 -0
- package/dist/esm/core/cells/constructCell.js.map +1 -0
- package/dist/esm/core/cells/coreCellsFeature.d.ts +10 -0
- package/dist/esm/core/cells/coreCellsFeature.js +26 -0
- package/dist/esm/core/cells/coreCellsFeature.js.map +1 -0
- package/dist/esm/core/cells/coreCellsFeature.types.d.ts +52 -0
- package/dist/esm/core/cells/coreCellsFeature.utils.d.ts +13 -0
- package/dist/esm/core/cells/coreCellsFeature.utils.js +23 -0
- package/dist/esm/core/cells/coreCellsFeature.utils.js.map +1 -0
- package/dist/esm/core/columns/constructColumn.d.ts +6 -0
- package/dist/esm/core/columns/constructColumn.js +60 -0
- package/dist/esm/core/columns/constructColumn.js.map +1 -0
- package/dist/esm/core/columns/coreColumnsFeature.d.ts +10 -0
- package/dist/esm/core/columns/coreColumnsFeature.js +61 -0
- package/dist/esm/core/columns/coreColumnsFeature.js.map +1 -0
- package/dist/esm/core/columns/coreColumnsFeature.types.d.ts +84 -0
- package/dist/esm/core/columns/coreColumnsFeature.utils.d.ts +13 -0
- package/dist/esm/core/columns/coreColumnsFeature.utils.js +91 -0
- package/dist/esm/core/columns/coreColumnsFeature.utils.js.map +1 -0
- package/dist/esm/core/coreFeatures.d.ts +15 -0
- package/dist/esm/core/coreFeatures.js +18 -0
- package/dist/esm/core/coreFeatures.js.map +1 -0
- package/dist/esm/core/headers/buildHeaderGroups.d.ts +6 -0
- package/dist/esm/core/headers/buildHeaderGroups.js +99 -0
- package/dist/esm/core/headers/buildHeaderGroups.js.map +1 -0
- package/dist/esm/core/headers/constructHeader.d.ts +12 -0
- package/dist/esm/core/headers/constructHeader.js +28 -0
- package/dist/esm/core/headers/constructHeader.js.map +1 -0
- package/dist/esm/core/headers/coreHeadersFeature.d.ts +10 -0
- package/dist/esm/core/headers/coreHeadersFeature.js +68 -0
- package/dist/esm/core/headers/coreHeadersFeature.js.map +1 -0
- package/dist/esm/core/headers/coreHeadersFeature.types.d.ts +99 -0
- package/dist/esm/core/headers/coreHeadersFeature.utils.d.ts +15 -0
- package/dist/esm/core/headers/coreHeadersFeature.utils.js +85 -0
- package/dist/esm/core/headers/coreHeadersFeature.utils.js.map +1 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.d.ts +10 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.js +52 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.js.map +1 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.types.d.ts +39 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.utils.d.ts +16 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.utils.js +85 -0
- package/dist/esm/core/row-models/coreRowModelsFeature.utils.js.map +1 -0
- package/dist/esm/core/row-models/createCoreRowModel.d.ts +5 -0
- package/dist/esm/core/row-models/createCoreRowModel.js +54 -0
- package/dist/esm/core/row-models/createCoreRowModel.js.map +1 -0
- package/dist/esm/core/rows/constructRow.d.ts +5 -0
- package/dist/esm/core/rows/constructRow.js +29 -0
- package/dist/esm/core/rows/constructRow.js.map +1 -0
- package/dist/esm/core/rows/coreRowsFeature.d.ts +10 -0
- package/dist/esm/core/rows/coreRowsFeature.js +52 -0
- package/dist/esm/core/rows/coreRowsFeature.js.map +1 -0
- package/dist/esm/core/rows/coreRowsFeature.types.d.ts +91 -0
- package/dist/esm/core/rows/coreRowsFeature.utils.d.ts +15 -0
- package/dist/esm/core/rows/coreRowsFeature.utils.js +94 -0
- package/dist/esm/core/rows/coreRowsFeature.utils.js.map +1 -0
- package/dist/esm/core/table/constructTable.d.ts +9 -0
- package/dist/esm/core/table/constructTable.js +65 -0
- package/dist/esm/core/table/constructTable.js.map +1 -0
- package/dist/esm/core/table/coreTablesFeature.d.ts +10 -0
- package/dist/esm/core/table/coreTablesFeature.js +22 -0
- package/dist/esm/core/table/coreTablesFeature.js.map +1 -0
- package/dist/esm/core/table/coreTablesFeature.types.d.ts +105 -0
- package/dist/esm/core/table/coreTablesFeature.utils.d.ts +7 -0
- package/dist/esm/core/table/coreTablesFeature.utils.js +23 -0
- package/dist/esm/core/table/coreTablesFeature.utils.js.map +1 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.d.ts +10 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.js +80 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.js.map +1 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.types.d.ts +68 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.utils.d.ts +11 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.utils.js +33 -0
- package/dist/esm/features/column-faceting/columnFacetingFeature.utils.js.map +1 -0
- package/dist/esm/features/column-faceting/createFacetedMinMaxValues.d.ts +4 -0
- package/dist/esm/features/column-faceting/createFacetedMinMaxValues.js +41 -0
- package/dist/esm/features/column-faceting/createFacetedMinMaxValues.js.map +1 -0
- package/dist/esm/features/column-faceting/createFacetedRowModel.d.ts +5 -0
- package/dist/esm/features/column-faceting/createFacetedRowModel.js +47 -0
- package/dist/esm/features/column-faceting/createFacetedRowModel.js.map +1 -0
- package/dist/esm/features/column-faceting/createFacetedUniqueValues.d.ts +4 -0
- package/dist/esm/features/column-faceting/createFacetedUniqueValues.js +46 -0
- package/dist/esm/features/column-faceting/createFacetedUniqueValues.js.map +1 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.d.ts +11 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.js +69 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.js.map +1 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.types.d.ts +145 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.utils.d.ts +16 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.utils.js +118 -0
- package/dist/esm/features/column-filtering/columnFilteringFeature.utils.js.map +1 -0
- package/dist/esm/features/column-filtering/createFilteredRowModel.d.ts +6 -0
- package/dist/esm/features/column-filtering/createFilteredRowModel.js +110 -0
- package/dist/esm/features/column-filtering/createFilteredRowModel.js.map +1 -0
- package/dist/esm/features/column-filtering/filterRowsUtils.d.ts +6 -0
- package/dist/esm/{utils → features/column-filtering}/filterRowsUtils.js +15 -19
- package/dist/esm/features/column-filtering/filterRowsUtils.js.map +1 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.d.ts +10 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.js +91 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.js.map +1 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.types.d.ts +153 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.utils.d.ts +22 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.utils.js +99 -0
- package/dist/esm/features/column-grouping/columnGroupingFeature.utils.js.map +1 -0
- package/dist/esm/features/column-grouping/createGroupedRowModel.d.ts +6 -0
- package/dist/esm/features/column-grouping/createGroupedRowModel.js +144 -0
- package/dist/esm/features/column-grouping/createGroupedRowModel.js.map +1 -0
- package/dist/esm/features/column-ordering/columnOrderingFeature.d.ts +10 -0
- package/dist/esm/features/column-ordering/columnOrderingFeature.js +60 -0
- package/dist/esm/features/column-ordering/columnOrderingFeature.js.map +1 -0
- package/dist/{cjs/features/ColumnOrdering.d.cts → esm/features/column-ordering/columnOrderingFeature.types.d.ts} +8 -22
- package/dist/esm/features/column-ordering/columnOrderingFeature.utils.d.ts +14 -0
- package/dist/esm/features/column-ordering/columnOrderingFeature.utils.js +72 -0
- package/dist/esm/features/column-ordering/columnOrderingFeature.utils.js.map +1 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.d.ts +10 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.js +260 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.js.map +1 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.types.d.ts +157 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.utils.d.ts +39 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.utils.js +325 -0
- package/dist/esm/features/column-pinning/columnPinningFeature.utils.js.map +1 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.d.ts +11 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.js +52 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.js.map +1 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.types.d.ts +68 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.utils.d.ts +14 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.utils.js +193 -0
- package/dist/esm/features/column-resizing/columnResizingFeature.utils.js.map +1 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.d.ts +11 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.js +95 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.js.map +1 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.types.d.ts +81 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.utils.d.ts +25 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.utils.js +128 -0
- package/dist/esm/features/column-sizing/columnSizingFeature.utils.js.map +1 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.d.ts +10 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.js +100 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.js.map +1 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.types.d.ts +84 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.utils.d.ts +22 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.utils.js +105 -0
- package/dist/esm/features/column-visibility/columnVisibilityFeature.utils.js.map +1 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.d.ts +11 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.js +51 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.js.map +1 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.types.d.ts +59 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.utils.d.ts +10 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.utils.js +30 -0
- package/dist/esm/features/global-filtering/globalFilteringFeature.utils.js.map +1 -0
- package/dist/esm/features/row-expanding/createExpandedRowModel.d.ts +6 -0
- package/dist/esm/features/row-expanding/createExpandedRowModel.js +49 -0
- package/dist/esm/features/row-expanding/createExpandedRowModel.js.map +1 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.d.ts +10 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.js +74 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.js.map +1 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.types.d.ts +116 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.utils.d.ts +20 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.utils.js +125 -0
- package/dist/esm/features/row-expanding/rowExpandingFeature.utils.js.map +1 -0
- package/dist/esm/features/row-pagination/createPaginatedRowModel.d.ts +5 -0
- package/dist/esm/features/row-pagination/createPaginatedRowModel.js +58 -0
- package/dist/esm/features/row-pagination/createPaginatedRowModel.js.map +1 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.d.ts +10 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.js +78 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.js.map +1 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.types.d.ts +119 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.utils.d.ts +21 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.utils.js +126 -0
- package/dist/esm/features/row-pagination/rowPaginationFeature.utils.js.map +1 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.d.ts +10 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.js +80 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.js.map +1 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.types.d.ts +72 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.utils.d.ts +16 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.utils.js +115 -0
- package/dist/esm/features/row-pinning/rowPinningFeature.utils.js.map +1 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.d.ts +10 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.js +112 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.js.map +1 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.types.d.ts +123 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.utils.d.ts +34 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.utils.js +290 -0
- package/dist/esm/features/row-selection/rowSelectionFeature.utils.js.map +1 -0
- package/dist/esm/features/row-sorting/createSortedRowModel.d.ts +6 -0
- package/dist/esm/features/row-sorting/createSortedRowModel.js +94 -0
- package/dist/esm/features/row-sorting/createSortedRowModel.js.map +1 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.d.ts +10 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.js +82 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.js.map +1 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.types.d.ts +178 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.utils.d.ts +20 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.utils.js +181 -0
- package/dist/esm/features/row-sorting/rowSortingFeature.utils.js.map +1 -0
- package/dist/esm/features/stockFeatures.d.ts +31 -0
- package/dist/esm/features/stockFeatures.js +34 -0
- package/dist/esm/features/stockFeatures.js.map +1 -0
- package/dist/esm/fns/aggregationFns.d.ts +49 -0
- package/dist/esm/fns/aggregationFns.js +110 -0
- package/dist/esm/fns/aggregationFns.js.map +1 -0
- package/dist/esm/fns/filterFns.d.ts +76 -0
- package/dist/esm/fns/filterFns.js +134 -0
- package/dist/esm/fns/filterFns.js.map +1 -0
- package/dist/esm/fns/sortFns.d.ts +17 -0
- package/dist/esm/{sortingFns.js → fns/sortFns.js} +21 -15
- package/dist/esm/fns/sortFns.js.map +1 -0
- package/dist/esm/helpers/columnHelper.d.ts +61 -0
- package/dist/esm/{columnHelper.js → helpers/columnHelper.js} +1 -0
- package/dist/esm/helpers/columnHelper.js.map +1 -0
- package/dist/esm/helpers/tableFeatures.d.ts +13 -0
- package/dist/esm/helpers/tableFeatures.js +7 -0
- package/dist/esm/helpers/tableFeatures.js.map +1 -0
- package/dist/esm/helpers/tableHelper.d.ts +25 -0
- package/dist/esm/helpers/tableHelper.js +13 -0
- package/dist/esm/helpers/tableHelper.js.map +1 -0
- package/dist/esm/helpers/tableOptions.d.ts +23 -0
- package/dist/esm/helpers/tableOptions.js +7 -0
- package/dist/esm/helpers/tableOptions.js.map +1 -0
- package/dist/esm/index.d.ts +109 -33
- package/dist/esm/index.js +397 -65
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/Cell.d.ts +13 -0
- package/dist/esm/types/Column.d.ts +26 -0
- package/dist/esm/types/ColumnDef.d.ts +64 -0
- package/dist/esm/types/Header.d.ts +14 -0
- package/dist/esm/types/HeaderGroup.d.ts +12 -0
- package/dist/esm/types/Row.d.ts +19 -0
- package/dist/esm/types/RowModel.d.ts +23 -0
- package/dist/esm/types/RowModelFns.d.ts +15 -0
- package/dist/esm/types/Table.d.ts +53 -0
- package/dist/esm/types/TableFeatures.d.ts +77 -0
- package/dist/esm/types/TableOptions.d.ts +39 -0
- package/dist/esm/types/TableState.d.ts +23 -0
- package/dist/esm/types/type-utils.d.ts +22 -0
- package/dist/esm/utils.d.ts +66 -33
- package/dist/esm/utils.js +183 -52
- package/dist/esm/utils.js.map +1 -1
- package/package.json +21 -12
- package/src/core/cells/constructCell.ts +49 -0
- package/src/core/cells/coreCellsFeature.ts +44 -0
- package/src/core/cells/coreCellsFeature.types.ts +68 -0
- package/src/core/cells/coreCellsFeature.utils.ts +35 -0
- package/src/core/columns/constructColumn.ts +111 -0
- package/src/core/columns/coreColumnsFeature.ts +90 -0
- package/src/core/columns/coreColumnsFeature.types.ts +103 -0
- package/src/core/columns/coreColumnsFeature.utils.ts +160 -0
- package/src/core/coreFeatures.ts +24 -0
- package/src/core/headers/buildHeaderGroups.ts +177 -0
- package/src/core/headers/constructHeader.ts +61 -0
- package/src/core/headers/coreHeadersFeature.ts +98 -0
- package/src/core/headers/coreHeadersFeature.types.ts +123 -0
- package/src/core/headers/coreHeadersFeature.utils.ts +131 -0
- package/src/core/row-models/coreRowModelsFeature.ts +78 -0
- package/src/core/row-models/coreRowModelsFeature.types.ts +67 -0
- package/src/core/row-models/coreRowModelsFeature.utils.ts +140 -0
- package/src/core/row-models/createCoreRowModel.ts +88 -0
- package/src/core/rows/constructRow.ts +59 -0
- package/src/core/rows/coreRowsFeature.ts +84 -0
- package/src/core/rows/coreRowsFeature.types.ts +111 -0
- package/src/core/rows/coreRowsFeature.utils.ts +152 -0
- package/src/core/table/constructTable.ts +95 -0
- package/src/core/table/coreTablesFeature.ts +36 -0
- package/src/core/table/coreTablesFeature.types.ts +123 -0
- package/src/core/table/coreTablesFeature.utils.ts +40 -0
- package/src/features/column-faceting/columnFacetingFeature.ts +112 -0
- package/src/features/column-faceting/columnFacetingFeature.types.ts +97 -0
- package/src/features/column-faceting/columnFacetingFeature.utils.ts +77 -0
- package/src/features/column-faceting/createFacetedMinMaxValues.ts +63 -0
- package/src/features/column-faceting/createFacetedRowModel.ts +76 -0
- package/src/features/column-faceting/createFacetedUniqueValues.ts +60 -0
- package/src/features/column-filtering/columnFilteringFeature.ts +121 -0
- package/src/features/column-filtering/columnFilteringFeature.types.ts +219 -0
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +213 -0
- package/src/features/column-filtering/createFilteredRowModel.ts +171 -0
- package/src/features/column-filtering/filterRowsUtils.ts +152 -0
- package/src/features/column-grouping/columnGroupingFeature.ts +151 -0
- package/src/features/column-grouping/columnGroupingFeature.types.ts +218 -0
- package/src/features/column-grouping/columnGroupingFeature.utils.ts +192 -0
- package/src/features/column-grouping/createGroupedRowModel.ts +215 -0
- package/src/features/column-ordering/columnOrderingFeature.ts +96 -0
- package/src/features/column-ordering/columnOrderingFeature.types.ts +49 -0
- package/src/features/column-ordering/columnOrderingFeature.utils.ts +133 -0
- package/src/features/column-pinning/columnPinningFeature.ts +324 -0
- package/src/features/column-pinning/columnPinningFeature.types.ts +176 -0
- package/src/features/column-pinning/columnPinningFeature.utils.ts +537 -0
- package/src/features/column-resizing/columnResizingFeature.ts +92 -0
- package/src/features/column-resizing/columnResizingFeature.types.ts +81 -0
- package/src/features/column-resizing/columnResizingFeature.utils.ts +265 -0
- package/src/features/column-sizing/columnSizingFeature.ts +146 -0
- package/src/features/column-sizing/columnSizingFeature.types.ts +92 -0
- package/src/features/column-sizing/columnSizingFeature.utils.ts +211 -0
- package/src/features/column-visibility/columnVisibilityFeature.ts +155 -0
- package/src/features/column-visibility/columnVisibilityFeature.types.ts +101 -0
- package/src/features/column-visibility/columnVisibilityFeature.utils.ts +183 -0
- package/src/features/global-filtering/globalFilteringFeature.ts +92 -0
- package/src/features/global-filtering/globalFilteringFeature.types.ts +84 -0
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +60 -0
- package/src/features/row-expanding/createExpandedRowModel.ts +72 -0
- package/src/features/row-expanding/rowExpandingFeature.ts +122 -0
- package/src/features/row-expanding/rowExpandingFeature.types.ts +141 -0
- package/src/features/row-expanding/rowExpandingFeature.utils.ts +207 -0
- package/src/features/row-pagination/createPaginatedRowModel.ts +78 -0
- package/src/features/row-pagination/rowPaginationFeature.ts +121 -0
- package/src/features/row-pagination/rowPaginationFeature.types.ts +141 -0
- package/src/features/row-pagination/rowPaginationFeature.utils.ts +204 -0
- package/src/features/row-pinning/rowPinningFeature.ts +121 -0
- package/src/features/row-pinning/rowPinningFeature.types.ts +89 -0
- package/src/features/row-pinning/rowPinningFeature.utils.ts +197 -0
- package/src/features/row-selection/rowSelectionFeature.ts +164 -0
- package/src/features/row-selection/rowSelectionFeature.types.ts +143 -0
- package/src/features/row-selection/rowSelectionFeature.utils.ts +464 -0
- package/src/features/row-sorting/createSortedRowModel.ts +147 -0
- package/src/features/row-sorting/rowSortingFeature.ts +136 -0
- package/src/features/row-sorting/rowSortingFeature.types.ts +229 -0
- package/src/features/row-sorting/rowSortingFeature.utils.ts +320 -0
- package/src/features/stockFeatures.ts +48 -0
- package/src/fns/aggregationFns.ts +220 -0
- package/src/fns/filterFns.ts +379 -0
- package/src/{sortingFns.ts → fns/sortFns.ts} +66 -21
- package/src/helpers/columnHelper.ts +117 -0
- package/src/helpers/tableFeatures.ts +24 -0
- package/src/helpers/tableHelper.ts +61 -0
- package/src/helpers/tableOptions.ts +82 -0
- package/src/index.ts +156 -42
- package/src/types/Cell.ts +41 -0
- package/src/types/Column.ts +86 -0
- package/src/types/ColumnDef.ts +217 -0
- package/src/types/Header.ts +45 -0
- package/src/types/HeaderGroup.ts +24 -0
- package/src/types/Row.ts +55 -0
- package/src/types/RowModel.ts +137 -0
- package/src/types/RowModelFns.ts +51 -0
- package/src/types/Table.ts +125 -0
- package/src/types/TableFeatures.ts +150 -0
- package/src/types/TableOptions.ts +125 -0
- package/src/types/TableState.ts +88 -0
- package/src/types/type-utils.ts +84 -0
- package/src/utils.ts +344 -163
- package/dist/cjs/aggregationFns.cjs +0 -98
- package/dist/cjs/aggregationFns.cjs.map +0 -1
- package/dist/cjs/aggregationFns.d.cts +0 -14
- package/dist/cjs/columnHelper.cjs +0 -19
- package/dist/cjs/columnHelper.cjs.map +0 -1
- package/dist/cjs/columnHelper.d.cts +0 -9
- package/dist/cjs/core/cell.cjs +0 -38
- package/dist/cjs/core/cell.cjs.map +0 -1
- package/dist/cjs/core/cell.d.cts +0 -50
- package/dist/cjs/core/column.cjs +0 -81
- package/dist/cjs/core/column.cjs.map +0 -1
- package/dist/cjs/core/column.d.cts +0 -56
- package/dist/cjs/core/headers.cjs +0 -310
- package/dist/cjs/core/headers.cjs.map +0 -1
- package/dist/cjs/core/headers.d.cts +0 -195
- package/dist/cjs/core/row.cjs +0 -93
- package/dist/cjs/core/row.cjs.map +0 -1
- package/dist/cjs/core/row.d.cts +0 -92
- package/dist/cjs/core/table.cjs +0 -228
- package/dist/cjs/core/table.cjs.map +0 -1
- package/dist/cjs/core/table.d.cts +0 -221
- package/dist/cjs/features/ColumnFaceting.cjs +0 -29
- package/dist/cjs/features/ColumnFaceting.cjs.map +0 -1
- package/dist/cjs/features/ColumnFaceting.d.cts +0 -35
- package/dist/cjs/features/ColumnFiltering.cjs +0 -137
- package/dist/cjs/features/ColumnFiltering.cjs.map +0 -1
- package/dist/cjs/features/ColumnFiltering.d.cts +0 -195
- package/dist/cjs/features/ColumnGrouping.cjs +0 -134
- package/dist/cjs/features/ColumnGrouping.cjs.map +0 -1
- package/dist/cjs/features/ColumnGrouping.d.cts +0 -202
- package/dist/cjs/features/ColumnOrdering.cjs +0 -76
- package/dist/cjs/features/ColumnOrdering.cjs.map +0 -1
- package/dist/cjs/features/ColumnPinning.cjs +0 -145
- package/dist/cjs/features/ColumnPinning.cjs.map +0 -1
- package/dist/cjs/features/ColumnPinning.d.cts +0 -127
- package/dist/cjs/features/ColumnSizing.cjs +0 -308
- package/dist/cjs/features/ColumnSizing.cjs.map +0 -1
- package/dist/cjs/features/ColumnSizing.d.cts +0 -194
- package/dist/cjs/features/ColumnVisibility.cjs +0 -144
- package/dist/cjs/features/ColumnVisibility.cjs.map +0 -1
- package/dist/cjs/features/ColumnVisibility.d.cts +0 -130
- package/dist/cjs/features/GlobalFaceting.cjs +0 -29
- package/dist/cjs/features/GlobalFaceting.cjs.map +0 -1
- package/dist/cjs/features/GlobalFaceting.d.cts +0 -27
- package/dist/cjs/features/GlobalFiltering.cjs +0 -50
- package/dist/cjs/features/GlobalFiltering.cjs.map +0 -1
- package/dist/cjs/features/GlobalFiltering.d.cts +0 -80
- package/dist/cjs/features/RowExpanding.cjs +0 -154
- package/dist/cjs/features/RowExpanding.cjs.map +0 -1
- package/dist/cjs/features/RowExpanding.d.cts +0 -155
- package/dist/cjs/features/RowPagination.cjs +0 -162
- package/dist/cjs/features/RowPagination.cjs.map +0 -1
- package/dist/cjs/features/RowPagination.d.cts +0 -166
- package/dist/cjs/features/RowPinning.cjs +0 -133
- package/dist/cjs/features/RowPinning.cjs.map +0 -1
- package/dist/cjs/features/RowPinning.d.cts +0 -99
- package/dist/cjs/features/RowSelection.cjs +0 -298
- package/dist/cjs/features/RowSelection.cjs.map +0 -1
- package/dist/cjs/features/RowSelection.d.cts +0 -177
- package/dist/cjs/features/RowSorting.cjs +0 -201
- package/dist/cjs/features/RowSorting.cjs.map +0 -1
- package/dist/cjs/features/RowSorting.d.cts +0 -238
- package/dist/cjs/filterFns.cjs +0 -88
- package/dist/cjs/filterFns.cjs.map +0 -1
- package/dist/cjs/filterFns.d.cts +0 -14
- package/dist/cjs/index.cjs +0 -87
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -34
- package/dist/cjs/sortingFns.cjs +0 -91
- package/dist/cjs/sortingFns.cjs.map +0 -1
- package/dist/cjs/sortingFns.d.cts +0 -12
- package/dist/cjs/types.d.cts +0 -120
- package/dist/cjs/utils/filterRowsUtils.cjs +0 -99
- package/dist/cjs/utils/filterRowsUtils.cjs.map +0 -1
- package/dist/cjs/utils/filterRowsUtils.d.cts +0 -3
- package/dist/cjs/utils/getCoreRowModel.cjs +0 -54
- package/dist/cjs/utils/getCoreRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getCoreRowModel.d.cts +0 -3
- package/dist/cjs/utils/getExpandedRowModel.cjs +0 -41
- package/dist/cjs/utils/getExpandedRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getExpandedRowModel.d.cts +0 -8
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs +0 -36
- package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +0 -1
- package/dist/cjs/utils/getFacetedMinMaxValues.d.cts +0 -3
- package/dist/cjs/utils/getFacetedRowModel.cjs +0 -35
- package/dist/cjs/utils/getFacetedRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getFacetedRowModel.d.cts +0 -3
- package/dist/cjs/utils/getFacetedUniqueValues.cjs +0 -38
- package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +0 -1
- package/dist/cjs/utils/getFacetedUniqueValues.d.cts +0 -3
- package/dist/cjs/utils/getFilteredRowModel.cjs +0 -116
- package/dist/cjs/utils/getFilteredRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getFilteredRowModel.d.cts +0 -3
- package/dist/cjs/utils/getGroupedRowModel.cjs +0 -118
- package/dist/cjs/utils/getGroupedRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getGroupedRowModel.d.cts +0 -3
- package/dist/cjs/utils/getPaginationRowModel.cjs +0 -49
- package/dist/cjs/utils/getPaginationRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getPaginationRowModel.d.cts +0 -5
- package/dist/cjs/utils/getSortedRowModel.cjs +0 -91
- package/dist/cjs/utils/getSortedRowModel.cjs.map +0 -1
- package/dist/cjs/utils/getSortedRowModel.d.cts +0 -3
- package/dist/cjs/utils.cjs +0 -100
- package/dist/cjs/utils.cjs.map +0 -1
- package/dist/cjs/utils.d.cts +0 -39
- package/dist/esm/aggregationFns.d.ts +0 -14
- package/dist/esm/aggregationFns.js +0 -98
- package/dist/esm/aggregationFns.js.map +0 -1
- package/dist/esm/columnHelper.d.ts +0 -9
- package/dist/esm/columnHelper.js.map +0 -1
- package/dist/esm/core/cell.d.ts +0 -50
- package/dist/esm/core/cell.js +0 -38
- package/dist/esm/core/cell.js.map +0 -1
- package/dist/esm/core/column.d.ts +0 -56
- package/dist/esm/core/column.js +0 -81
- package/dist/esm/core/column.js.map +0 -1
- package/dist/esm/core/headers.d.ts +0 -195
- package/dist/esm/core/headers.js +0 -310
- package/dist/esm/core/headers.js.map +0 -1
- package/dist/esm/core/row.d.ts +0 -92
- package/dist/esm/core/row.js +0 -93
- package/dist/esm/core/row.js.map +0 -1
- package/dist/esm/core/table.d.ts +0 -221
- package/dist/esm/core/table.js +0 -228
- package/dist/esm/core/table.js.map +0 -1
- package/dist/esm/features/ColumnFaceting.d.ts +0 -35
- package/dist/esm/features/ColumnFaceting.js +0 -29
- package/dist/esm/features/ColumnFaceting.js.map +0 -1
- package/dist/esm/features/ColumnFiltering.d.ts +0 -195
- package/dist/esm/features/ColumnFiltering.js +0 -137
- package/dist/esm/features/ColumnFiltering.js.map +0 -1
- package/dist/esm/features/ColumnGrouping.d.ts +0 -202
- package/dist/esm/features/ColumnGrouping.js +0 -134
- package/dist/esm/features/ColumnGrouping.js.map +0 -1
- package/dist/esm/features/ColumnOrdering.d.ts +0 -54
- package/dist/esm/features/ColumnOrdering.js +0 -76
- package/dist/esm/features/ColumnOrdering.js.map +0 -1
- package/dist/esm/features/ColumnPinning.d.ts +0 -127
- package/dist/esm/features/ColumnPinning.js +0 -145
- package/dist/esm/features/ColumnPinning.js.map +0 -1
- package/dist/esm/features/ColumnSizing.d.ts +0 -194
- package/dist/esm/features/ColumnSizing.js +0 -308
- package/dist/esm/features/ColumnSizing.js.map +0 -1
- package/dist/esm/features/ColumnVisibility.d.ts +0 -130
- package/dist/esm/features/ColumnVisibility.js +0 -144
- package/dist/esm/features/ColumnVisibility.js.map +0 -1
- package/dist/esm/features/GlobalFaceting.d.ts +0 -27
- package/dist/esm/features/GlobalFaceting.js +0 -29
- package/dist/esm/features/GlobalFaceting.js.map +0 -1
- package/dist/esm/features/GlobalFiltering.d.ts +0 -80
- package/dist/esm/features/GlobalFiltering.js +0 -50
- package/dist/esm/features/GlobalFiltering.js.map +0 -1
- package/dist/esm/features/RowExpanding.d.ts +0 -155
- package/dist/esm/features/RowExpanding.js +0 -154
- package/dist/esm/features/RowExpanding.js.map +0 -1
- package/dist/esm/features/RowPagination.d.ts +0 -166
- package/dist/esm/features/RowPagination.js +0 -162
- package/dist/esm/features/RowPagination.js.map +0 -1
- package/dist/esm/features/RowPinning.d.ts +0 -99
- package/dist/esm/features/RowPinning.js +0 -133
- package/dist/esm/features/RowPinning.js.map +0 -1
- package/dist/esm/features/RowSelection.d.ts +0 -177
- package/dist/esm/features/RowSelection.js +0 -298
- package/dist/esm/features/RowSelection.js.map +0 -1
- package/dist/esm/features/RowSorting.d.ts +0 -238
- package/dist/esm/features/RowSorting.js +0 -201
- package/dist/esm/features/RowSorting.js.map +0 -1
- package/dist/esm/filterFns.d.ts +0 -14
- package/dist/esm/filterFns.js +0 -88
- package/dist/esm/filterFns.js.map +0 -1
- package/dist/esm/sortingFns.d.ts +0 -12
- package/dist/esm/sortingFns.js.map +0 -1
- package/dist/esm/types.d.ts +0 -120
- package/dist/esm/utils/filterRowsUtils.d.ts +0 -3
- package/dist/esm/utils/filterRowsUtils.js.map +0 -1
- package/dist/esm/utils/getCoreRowModel.d.ts +0 -3
- package/dist/esm/utils/getCoreRowModel.js +0 -54
- package/dist/esm/utils/getCoreRowModel.js.map +0 -1
- package/dist/esm/utils/getExpandedRowModel.d.ts +0 -8
- package/dist/esm/utils/getExpandedRowModel.js +0 -41
- package/dist/esm/utils/getExpandedRowModel.js.map +0 -1
- package/dist/esm/utils/getFacetedMinMaxValues.d.ts +0 -3
- package/dist/esm/utils/getFacetedMinMaxValues.js +0 -36
- package/dist/esm/utils/getFacetedMinMaxValues.js.map +0 -1
- package/dist/esm/utils/getFacetedRowModel.d.ts +0 -3
- package/dist/esm/utils/getFacetedRowModel.js +0 -35
- package/dist/esm/utils/getFacetedRowModel.js.map +0 -1
- package/dist/esm/utils/getFacetedUniqueValues.d.ts +0 -3
- package/dist/esm/utils/getFacetedUniqueValues.js +0 -38
- package/dist/esm/utils/getFacetedUniqueValues.js.map +0 -1
- package/dist/esm/utils/getFilteredRowModel.d.ts +0 -3
- package/dist/esm/utils/getFilteredRowModel.js +0 -116
- package/dist/esm/utils/getFilteredRowModel.js.map +0 -1
- package/dist/esm/utils/getGroupedRowModel.d.ts +0 -3
- package/dist/esm/utils/getGroupedRowModel.js +0 -118
- package/dist/esm/utils/getGroupedRowModel.js.map +0 -1
- package/dist/esm/utils/getPaginationRowModel.d.ts +0 -5
- package/dist/esm/utils/getPaginationRowModel.js +0 -49
- package/dist/esm/utils/getPaginationRowModel.js.map +0 -1
- package/dist/esm/utils/getSortedRowModel.d.ts +0 -3
- package/dist/esm/utils/getSortedRowModel.js +0 -91
- package/dist/esm/utils/getSortedRowModel.js.map +0 -1
- package/src/aggregationFns.ts +0 -123
- package/src/columnHelper.ts +0 -91
- package/src/core/cell.ts +0 -91
- package/src/core/column.ts +0 -165
- package/src/core/headers.ts +0 -639
- package/src/core/row.ts +0 -201
- package/src/core/table.ts +0 -527
- package/src/features/ColumnFaceting.ts +0 -84
- package/src/features/ColumnFiltering.ts +0 -429
- package/src/features/ColumnGrouping.ts +0 -422
- package/src/features/ColumnOrdering.ts +0 -161
- package/src/features/ColumnPinning.ts +0 -336
- package/src/features/ColumnSizing.ts +0 -579
- package/src/features/ColumnVisibility.ts +0 -317
- package/src/features/GlobalFaceting.ts +0 -66
- package/src/features/GlobalFiltering.ts +0 -162
- package/src/features/RowExpanding.ts +0 -355
- package/src/features/RowPagination.ts +0 -396
- package/src/features/RowPinning.ts +0 -273
- package/src/features/RowSelection.ts +0 -668
- package/src/features/RowSorting.ts +0 -542
- package/src/filterFns.ts +0 -150
- package/src/types.ts +0 -361
- package/src/utils/filterRowsUtils.ts +0 -130
- package/src/utils/getCoreRowModel.ts +0 -82
- package/src/utils/getExpandedRowModel.ts +0 -51
- package/src/utils/getFacetedMinMaxValues.ts +0 -42
- package/src/utils/getFacetedRowModel.ts +0 -44
- package/src/utils/getFacetedUniqueValues.ts +0 -42
- package/src/utils/getFilteredRowModel.ts +0 -151
- package/src/utils/getGroupedRowModel.ts +0 -181
- package/src/utils/getPaginationRowModel.ts +0 -60
- package/src/utils/getSortedRowModel.ts +0 -121
package/dist/esm/utils.js
CHANGED
|
@@ -5,12 +5,14 @@ function noop() {
|
|
|
5
5
|
}
|
|
6
6
|
function makeStateUpdater(key, instance) {
|
|
7
7
|
return (updater) => {
|
|
8
|
-
instance.setState(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
instance.baseStore.setState(
|
|
9
|
+
(old) => {
|
|
10
|
+
return {
|
|
11
|
+
...old,
|
|
12
|
+
[key]: functionalUpdate(updater, old[key])
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
);
|
|
14
16
|
};
|
|
15
17
|
}
|
|
16
18
|
function isFunction(d) {
|
|
@@ -25,7 +27,7 @@ function flattenBy(arr, getChildren) {
|
|
|
25
27
|
subArr.forEach((item) => {
|
|
26
28
|
flat.push(item);
|
|
27
29
|
const children = getChildren(item);
|
|
28
|
-
if (children
|
|
30
|
+
if (children.length) {
|
|
29
31
|
recurse(children);
|
|
30
32
|
}
|
|
31
33
|
});
|
|
@@ -33,68 +35,197 @@ function flattenBy(arr, getChildren) {
|
|
|
33
35
|
recurse(arr);
|
|
34
36
|
return flat;
|
|
35
37
|
}
|
|
36
|
-
|
|
38
|
+
const $internalMemoFnMeta = /* @__PURE__ */ Symbol("memoFnMeta");
|
|
39
|
+
function setMemoFnMeta(fn, meta) {
|
|
40
|
+
Object.defineProperty(fn, $internalMemoFnMeta, { value: meta });
|
|
41
|
+
}
|
|
42
|
+
function getMemoFnMeta(fn) {
|
|
43
|
+
return (typeof fn === "function" && fn[$internalMemoFnMeta]) ?? null;
|
|
44
|
+
}
|
|
45
|
+
const memo = ({
|
|
46
|
+
fn,
|
|
47
|
+
memoDeps,
|
|
48
|
+
onAfterCompare,
|
|
49
|
+
onAfterUpdate,
|
|
50
|
+
onBeforeCompare,
|
|
51
|
+
onBeforeUpdate
|
|
52
|
+
}) => {
|
|
37
53
|
let deps = [];
|
|
38
54
|
let result;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const newDeps = getDeps(depArgs);
|
|
45
|
-
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
55
|
+
const memoizedFn = (depArgs) => {
|
|
56
|
+
onBeforeCompare?.();
|
|
57
|
+
const newDeps = memoDeps?.(depArgs);
|
|
58
|
+
const depsChanged = !newDeps || newDeps.length !== deps?.length || newDeps.some((dep, index) => deps?.[index] !== dep);
|
|
59
|
+
onAfterCompare?.(depsChanged);
|
|
46
60
|
if (!depsChanged) {
|
|
47
61
|
return result;
|
|
48
62
|
}
|
|
49
63
|
deps = newDeps;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
result
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
onBeforeUpdate?.();
|
|
65
|
+
result = fn(...newDeps ?? []);
|
|
66
|
+
onAfterUpdate?.(result);
|
|
67
|
+
return result;
|
|
68
|
+
};
|
|
69
|
+
setMemoFnMeta(memoizedFn, { originalArgsLength: fn.length });
|
|
70
|
+
return memoizedFn;
|
|
71
|
+
};
|
|
72
|
+
const pad = (str, num) => {
|
|
73
|
+
str = String(str);
|
|
74
|
+
while (str.length < num) {
|
|
75
|
+
str = " " + str;
|
|
76
|
+
}
|
|
77
|
+
return str;
|
|
78
|
+
};
|
|
79
|
+
function tableMemo({
|
|
80
|
+
feature,
|
|
81
|
+
fnName,
|
|
82
|
+
objectId,
|
|
83
|
+
onAfterUpdate,
|
|
84
|
+
table,
|
|
85
|
+
...memoOptions
|
|
86
|
+
}) {
|
|
87
|
+
let beforeCompareTime;
|
|
88
|
+
let afterCompareTime;
|
|
89
|
+
let startCalcTime;
|
|
90
|
+
let endCalcTime;
|
|
91
|
+
let runCount = 0;
|
|
92
|
+
let debug;
|
|
93
|
+
let debugCache;
|
|
94
|
+
if (process.env.NODE_ENV === "development") {
|
|
95
|
+
const { debugCache: _debugCache, debugAll } = table.options;
|
|
96
|
+
debugCache = _debugCache;
|
|
97
|
+
const { parentName } = getFunctionNameInfo(fnName, ".");
|
|
98
|
+
const debugByParent = (
|
|
99
|
+
// @ts-expect-error
|
|
100
|
+
table.options[`debug${(parentName != "table" ? parentName + "s" : parentName).replace(
|
|
101
|
+
parentName,
|
|
102
|
+
parentName.charAt(0).toUpperCase() + parentName.slice(1)
|
|
103
|
+
)}`]
|
|
104
|
+
);
|
|
105
|
+
const debugByFeature = feature ? (
|
|
106
|
+
// @ts-expect-error
|
|
107
|
+
table.options[`debug${feature.charAt(0).toUpperCase() + feature.slice(1)}`]
|
|
108
|
+
) : false;
|
|
109
|
+
debug = debugAll || debugByParent || debugByFeature;
|
|
110
|
+
}
|
|
111
|
+
function logTime(time, depsChanged) {
|
|
112
|
+
const runType = runCount === 0 ? "(1st run)" : depsChanged ? "(rerun #" + runCount + ")" : "(cache)";
|
|
113
|
+
runCount++;
|
|
114
|
+
console.groupCollapsed(
|
|
115
|
+
`%c⏱ ${pad(`${time.toFixed(1)} ms`, 12)} %c${runType}%c ${fnName}%c ${objectId ? `(${fnName.split(".")[0]}Id: ${objectId})` : ""}`,
|
|
116
|
+
`font-size: .6rem; font-weight: bold; ${depsChanged ? `color: hsl(
|
|
117
|
+
${Math.max(0, Math.min(120 - Math.log10(time) * 60, 120))}deg 100% 31%);` : ""} `,
|
|
118
|
+
`color: ${runCount < 2 ? "#FF00FF" : "#FF1493"}`,
|
|
119
|
+
"color: #666",
|
|
120
|
+
"color: #87CEEB"
|
|
121
|
+
);
|
|
122
|
+
console.info({
|
|
123
|
+
feature,
|
|
124
|
+
state: table.store.state,
|
|
125
|
+
deps: memoOptions.memoDeps?.toString()
|
|
126
|
+
});
|
|
127
|
+
console.trace();
|
|
128
|
+
console.groupEnd();
|
|
129
|
+
}
|
|
130
|
+
const debugOptions = process.env.NODE_ENV === "development" ? {
|
|
131
|
+
onBeforeCompare: () => {
|
|
132
|
+
if (debugCache) {
|
|
133
|
+
beforeCompareTime = performance.now();
|
|
78
134
|
}
|
|
135
|
+
},
|
|
136
|
+
onAfterCompare: (depsChanged) => {
|
|
137
|
+
if (debugCache) {
|
|
138
|
+
afterCompareTime = performance.now();
|
|
139
|
+
const compareTime = Math.round((afterCompareTime - beforeCompareTime) * 100) / 100;
|
|
140
|
+
if (!depsChanged) {
|
|
141
|
+
logTime(compareTime, depsChanged);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
onBeforeUpdate: () => {
|
|
146
|
+
if (debug) {
|
|
147
|
+
startCalcTime = performance.now();
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
onAfterUpdate: () => {
|
|
151
|
+
if (debug) {
|
|
152
|
+
endCalcTime = performance.now();
|
|
153
|
+
const executionTime = Math.round((endCalcTime - startCalcTime) * 100) / 100;
|
|
154
|
+
logTime(executionTime, true);
|
|
155
|
+
}
|
|
156
|
+
queueMicrotask(() => onAfterUpdate?.());
|
|
157
|
+
}
|
|
158
|
+
} : {
|
|
159
|
+
onAfterUpdate: () => {
|
|
160
|
+
queueMicrotask(() => onAfterUpdate?.());
|
|
79
161
|
}
|
|
80
|
-
return result;
|
|
81
162
|
};
|
|
163
|
+
return memo({
|
|
164
|
+
...memoOptions,
|
|
165
|
+
...debugOptions
|
|
166
|
+
});
|
|
82
167
|
}
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
168
|
+
function getFunctionNameInfo(staticFnName, splitBy = "_") {
|
|
169
|
+
const [parentName, fnKey] = staticFnName.split(splitBy);
|
|
170
|
+
const fnName = `${parentName}.${fnKey}`;
|
|
171
|
+
return { fnKey, fnName, parentName };
|
|
172
|
+
}
|
|
173
|
+
function assignTableAPIs(feature, table, apis) {
|
|
174
|
+
for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {
|
|
175
|
+
const { fnKey, fnName } = getFunctionNameInfo(staticFnName);
|
|
176
|
+
table[fnKey] = memoDeps ? tableMemo({
|
|
177
|
+
memoDeps,
|
|
178
|
+
fn,
|
|
179
|
+
fnName,
|
|
180
|
+
table,
|
|
181
|
+
feature
|
|
182
|
+
}) : fn;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function assignPrototypeAPIs(feature, prototype, table, apis) {
|
|
186
|
+
for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {
|
|
187
|
+
const { fnKey, fnName } = getFunctionNameInfo(staticFnName);
|
|
188
|
+
if (memoDeps) {
|
|
189
|
+
const memoKey = `_memo_${fnKey}`;
|
|
190
|
+
prototype[fnKey] = function(...args) {
|
|
191
|
+
if (!this[memoKey]) {
|
|
192
|
+
const self = this;
|
|
193
|
+
this[memoKey] = tableMemo({
|
|
194
|
+
memoDeps: () => memoDeps(self),
|
|
195
|
+
fn: (...deps) => fn(self, ...deps),
|
|
196
|
+
fnName,
|
|
197
|
+
objectId: self.id,
|
|
198
|
+
table,
|
|
199
|
+
feature
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return this[memoKey](...args);
|
|
203
|
+
};
|
|
204
|
+
} else {
|
|
205
|
+
prototype[fnKey] = function(...args) {
|
|
206
|
+
return fn(this, ...args);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
setMemoFnMeta(prototype[fnKey], { originalArgsLength: fn.length });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function callMemoOrStaticFn(obj, fnKey, staticFn, ...args) {
|
|
213
|
+
return obj[fnKey]?.(...args) ?? staticFn(obj, ...args);
|
|
89
214
|
}
|
|
90
215
|
export {
|
|
216
|
+
$internalMemoFnMeta,
|
|
217
|
+
assignPrototypeAPIs,
|
|
218
|
+
assignTableAPIs,
|
|
219
|
+
callMemoOrStaticFn,
|
|
91
220
|
flattenBy,
|
|
92
221
|
functionalUpdate,
|
|
93
|
-
|
|
222
|
+
getFunctionNameInfo,
|
|
223
|
+
getMemoFnMeta,
|
|
94
224
|
isFunction,
|
|
95
225
|
isNumberArray,
|
|
96
226
|
makeStateUpdater,
|
|
97
227
|
memo,
|
|
98
|
-
noop
|
|
228
|
+
noop,
|
|
229
|
+
tableMemo
|
|
99
230
|
};
|
|
100
231
|
//# sourceMappingURL=utils.js.map
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { TableOptionsResolved, TableState, Updater } from './types'\n\nexport type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>\nexport type RequiredKeys<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type Overwrite<T, U extends { [TKey in keyof T]?: any }> = Omit<\n T,\n keyof U\n> &\n U\n\nexport type UnionToIntersection<T> = (\n T extends any ? (x: T) => any : never\n) extends (x: infer R) => any\n ? R\n : never\n\nexport type IsAny<T, Y, N> = 1 extends 0 & T ? Y : N\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\n\ntype ComputeRange<\n N extends number,\n Result extends Array<unknown> = [],\n> = Result['length'] extends N\n ? Result\n : ComputeRange<N, [...Result, Result['length']]>\ntype Index40 = ComputeRange<40>[number]\n\n// Is this type a tuple?\ntype IsTuple<T> = T extends readonly any[] & { length: infer Length }\n ? Length extends Index40\n ? T\n : never\n : never\n\n// If this type is a tuple, what indices are allowed?\ntype AllowedIndexes<\n Tuple extends ReadonlyArray<any>,\n Keys extends number = never,\n> = Tuple extends readonly []\n ? Keys\n : Tuple extends readonly [infer _, ...infer Tail]\n ? AllowedIndexes<Tail, Keys | Tail['length']>\n : Keys\n\nexport type DeepKeys<T, TDepth extends any[] = []> = TDepth['length'] extends 5\n ? never\n : unknown extends T\n ? string\n : T extends readonly any[] & IsTuple<T>\n ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>, TDepth>\n : T extends any[]\n ? DeepKeys<T[number], [...TDepth, any]>\n : T extends Date\n ? never\n : T extends object\n ? (keyof T & string) | DeepKeysPrefix<T, keyof T, TDepth>\n : never\n\ntype DeepKeysPrefix<\n T,\n TPrefix,\n TDepth extends any[],\n> = TPrefix extends keyof T & (number | string)\n ? `${TPrefix}.${DeepKeys<T[TPrefix], [...TDepth, any]> & string}`\n : never\n\nexport type DeepValue<T, TProp> = T extends Record<string | number, any>\n ? TProp extends `${infer TBranch}.${infer TDeepProp}`\n ? DeepValue<T[TBranch], TDeepProp>\n : T[TProp & string]\n : never\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport type Getter<TValue> = <TTValue = TValue>() => NoInfer<TTValue>\n\n///\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (input: T) => T)(input)\n : updater\n}\n\nexport function noop() {\n //\n}\n\nexport function makeStateUpdater<K extends keyof TableState>(\n key: K,\n instance: unknown\n) {\n return (updater: Updater<TableState[K]>) => {\n ;(instance as any).setState(<TTableState>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n })\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is number[] {\n return Array.isArray(d) && d.every(val => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: TNode[],\n getChildren: (item: TNode) => TNode[]\n) {\n const flat: TNode[] = []\n\n const recurse = (subArr: TNode[]) => {\n subArr.forEach(item => {\n flat.push(item)\n const children = getChildren(item)\n if (children?.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport function memo<TDeps extends readonly any[], TDepArgs, TResult>(\n getDeps: (depArgs?: TDepArgs) => [...TDeps],\n fn: (...args: NoInfer<[...TDeps]>) => TResult,\n opts: {\n key: any\n debug?: () => any\n onChange?: (result: TResult) => void\n }\n): (depArgs?: TDepArgs) => TResult {\n let deps: any[] = []\n let result: TResult | undefined\n\n return depArgs => {\n let depTime: number\n if (opts.key && opts.debug) depTime = Date.now()\n\n const newDeps = getDeps(depArgs)\n\n const depsChanged =\n newDeps.length !== deps.length ||\n newDeps.some((dep: any, index: number) => deps[index] !== dep)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n let resultTime: number\n if (opts.key && opts.debug) resultTime = Date.now()\n\n result = fn(...newDeps)\n opts?.onChange?.(result)\n\n if (opts.key && opts.debug) {\n if (opts?.debug()) {\n const depEndTime = Math.round((Date.now() - depTime!) * 100) / 100\n const resultEndTime = Math.round((Date.now() - resultTime!) * 100) / 100\n const resultFpsPercentage = resultEndTime / 16\n\n const pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n }\n\n console.info(\n `%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,\n `\n font-size: .6rem;\n font-weight: bold;\n color: hsl(${Math.max(\n 0,\n Math.min(120 - 120 * resultFpsPercentage, 120)\n )}deg 100% 31%);`,\n opts?.key\n )\n }\n }\n\n return result!\n }\n}\n\nexport function getMemoOptions(\n tableOptions: Partial<TableOptionsResolved<any>>,\n debugLevel:\n | 'debugAll'\n | 'debugCells'\n | 'debugTable'\n | 'debugColumns'\n | 'debugRows'\n | 'debugHeaders',\n key: string,\n onChange?: (result: any) => void\n) {\n return {\n debug: () => tableOptions?.debugAll ?? tableOptions[debugLevel],\n key: process.env.NODE_ENV === 'development' && key,\n onChange,\n }\n}\n"],"names":[],"mappings":"AA+EgB,SAAA,iBAAoB,SAAqB,OAAa;AACpE,SAAO,OAAO,YAAY,aACrB,QAA4B,KAAK,IAClC;AACN;AAEO,SAAS,OAAO;AAEvB;AAEgB,SAAA,iBACd,KACA,UACA;AACA,SAAO,CAAC,YAAoC;AACxC,aAAiB,SAAS,CAAc,QAAqB;AACtD,aAAA;AAAA,QACL,GAAG;AAAA,QACH,CAAC,GAAG,GAAG,iBAAiB,SAAU,IAAY,GAAG,CAAC;AAAA,MAAA;AAAA,IACpD,CACD;AAAA,EAAA;AAEL;AAIO,SAAS,WAAkC,GAAgB;AAChE,SAAO,aAAa;AACtB;AAEO,SAAS,cAAc,GAAuB;AAC5C,SAAA,MAAM,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA,QAAO,OAAO,QAAQ,QAAQ;AACnE;AAEgB,SAAA,UACd,KACA,aACA;AACA,QAAM,OAAgB,CAAA;AAEhB,QAAA,UAAU,CAAC,WAAoB;AACnC,WAAO,QAAQ,CAAQ,SAAA;AACrB,WAAK,KAAK,IAAI;AACR,YAAA,WAAW,YAAY,IAAI;AACjC,UAAI,qCAAU,QAAQ;AACpB,gBAAQ,QAAQ;AAAA,MAClB;AAAA,IAAA,CACD;AAAA,EAAA;AAGH,UAAQ,GAAG;AAEJ,SAAA;AACT;AAEgB,SAAA,KACd,SACA,IACA,MAKiC;AACjC,MAAI,OAAc,CAAA;AACd,MAAA;AAEJ,SAAO,CAAW,YAAA;AAnEJ;AAoER,QAAA;AACA,QAAA,KAAK,OAAO,KAAK;AAAO,gBAAU,KAAK;AAErC,UAAA,UAAU,QAAQ,OAAO;AAE/B,UAAM,cACJ,QAAQ,WAAW,KAAK,UACxB,QAAQ,KAAK,CAAC,KAAU,UAAkB,KAAK,KAAK,MAAM,GAAG;AAE/D,QAAI,CAAC,aAAa;AACT,aAAA;AAAA,IACT;AAEO,WAAA;AAEH,QAAA;AACA,QAAA,KAAK,OAAO,KAAK;AAAO,mBAAa,KAAK;AAErC,aAAA,GAAG,GAAG,OAAO;AACtB,uCAAM,aAAN,8BAAiB;AAEb,QAAA,KAAK,OAAO,KAAK,OAAO;AACtB,UAAA,6BAAM,SAAS;AACX,cAAA,aAAa,KAAK,OAAO,KAAK,QAAQ,WAAY,GAAG,IAAI;AACzD,cAAA,gBAAgB,KAAK,OAAO,KAAK,QAAQ,cAAe,GAAG,IAAI;AACrE,cAAM,sBAAsB,gBAAgB;AAEtC,cAAA,MAAM,CAAC,KAAsB,QAAgB;AACjD,gBAAM,OAAO,GAAG;AACT,iBAAA,IAAI,SAAS,KAAK;AACvB,kBAAM,MAAM;AAAA,UACd;AACO,iBAAA;AAAA,QAAA;AAGD,gBAAA;AAAA,UACN,OAAO,IAAI,eAAe,CAAC,CAAC,KAAK,IAAI,YAAY,CAAC,CAAC;AAAA,UACnD;AAAA;AAAA;AAAA,yBAGe,KAAK;AAAA,YAChB;AAAA,YACA,KAAK,IAAI,MAAM,MAAM,qBAAqB,GAAG;AAAA,UAC9C,CAAA;AAAA,UACH,6BAAM;AAAA,QAAA;AAAA,MAEV;AAAA,IACF;AAEO,WAAA;AAAA,EAAA;AAEX;AAEO,SAAS,eACd,cACA,YAOA,KACA,UACA;AACO,SAAA;AAAA,IACL,OAAO,OAAM,6CAAc,aAAY,aAAa,UAAU;AAAA,IAC9D,KAAK,QAAQ,IAAI,aAAa,iBAAiB;AAAA,IAC/C;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type { Table, Table_Internal } from './types/Table'\nimport type { NoInfer, RowData, Updater } from './types/type-utils'\nimport type { TableFeatures } from './types/TableFeatures'\nimport type { TableState, TableState_All } from './types/TableState'\n\nexport function functionalUpdate<T>(updater: Updater<T>, input: T): T {\n return typeof updater === 'function'\n ? (updater as (i: T) => T)(input)\n : updater\n}\n\nexport function noop() {}\n\nexport function makeStateUpdater<\n TFeatures extends TableFeatures,\n K extends (string & {}) | keyof TableState_All | keyof TableState<TFeatures>,\n>(key: K, instance: Table<TFeatures, any>) {\n return (updater: Updater<TableState<any>[K & keyof TableState<any>]>) => {\n ;(instance as Table_Internal<any, any>).baseStore.setState(\n <TTableState extends TableState_All>(old: TTableState) => {\n return {\n ...old,\n [key]: functionalUpdate(updater, (old as any)[key]),\n }\n },\n )\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\nexport function isNumberArray(d: any): d is Array<number> {\n return Array.isArray(d) && d.every((val) => typeof val === 'number')\n}\n\nexport function flattenBy<TNode>(\n arr: Array<TNode>,\n getChildren: (item: TNode) => Array<TNode>,\n) {\n const flat: Array<TNode> = []\n\n const recurse = (subArr: Array<TNode>) => {\n subArr.forEach((item) => {\n flat.push(item)\n const children = getChildren(item)\n if (children.length) {\n recurse(children)\n }\n })\n }\n\n recurse(arr)\n\n return flat\n}\n\nexport const $internalMemoFnMeta = Symbol('memoFnMeta')\nexport type MemoFnMeta = { originalArgsLength?: number }\n\n/**\n * @internal\n */\nfunction setMemoFnMeta(fn: Function, meta: MemoFnMeta) {\n Object.defineProperty(fn, $internalMemoFnMeta, { value: meta })\n}\n\n/**\n * @internal\n */\nexport function getMemoFnMeta(fn: any): MemoFnMeta | null {\n return (typeof fn === 'function' && fn[$internalMemoFnMeta]) ?? null\n}\n\ninterface MemoOptions<TDeps extends ReadonlyArray<any>, TDepArgs, TResult> {\n fn: (...args: NoInfer<TDeps>) => TResult\n memoDeps?: (depArgs?: TDepArgs) => [...TDeps] | undefined\n onAfterCompare?: (depsChanged: boolean) => void\n onAfterUpdate?: (result: TResult) => void\n onBeforeCompare?: () => void\n onBeforeUpdate?: () => void\n}\n\nexport const memo = <TDeps extends ReadonlyArray<any>, TDepArgs, TResult>({\n fn,\n memoDeps,\n onAfterCompare,\n onAfterUpdate,\n onBeforeCompare,\n onBeforeUpdate,\n}: MemoOptions<TDeps, TDepArgs, TResult>): ((\n depArgs?: TDepArgs,\n) => TResult) => {\n let deps: Array<any> | undefined = []\n let result: TResult | undefined\n\n const memoizedFn = (depArgs?: TDepArgs): TResult => {\n onBeforeCompare?.()\n const newDeps = memoDeps?.(depArgs)\n const depsChanged =\n !newDeps ||\n newDeps.length !== deps?.length ||\n newDeps.some((dep: any, index: number) => deps?.[index] !== dep)\n onAfterCompare?.(depsChanged)\n\n if (!depsChanged) {\n return result!\n }\n\n deps = newDeps\n\n onBeforeUpdate?.()\n result = fn(...(newDeps ?? ([] as any)))\n onAfterUpdate?.(result)\n\n return result\n }\n\n setMemoFnMeta(memoizedFn, { originalArgsLength: fn.length })\n\n return memoizedFn\n}\n\ninterface TableMemoOptions<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n> extends MemoOptions<TDeps, TDepArgs, TResult> {\n feature?: keyof TFeatures & string\n fnName: string\n objectId?: string\n onAfterUpdate?: () => void\n table: Table_Internal<TFeatures, any>\n}\n\nconst pad = (str: number | string, num: number) => {\n str = String(str)\n while (str.length < num) {\n str = ' ' + str\n }\n return str\n}\n\nexport function tableMemo<\n TFeatures extends TableFeatures,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n TResult,\n>({\n feature,\n fnName,\n objectId,\n onAfterUpdate,\n table,\n ...memoOptions\n}: TableMemoOptions<TFeatures, TDeps, TDepArgs, TResult>) {\n let beforeCompareTime: number\n let afterCompareTime: number\n let startCalcTime: number\n let endCalcTime: number\n let runCount = 0\n let debug: boolean | undefined\n let debugCache: boolean | undefined\n\n if (process.env.NODE_ENV === 'development') {\n const { debugCache: _debugCache, debugAll } = table.options\n debugCache = _debugCache\n const { parentName } = getFunctionNameInfo(fnName, '.')\n\n const debugByParent =\n // @ts-expect-error\n table.options[\n `debug${(parentName != 'table' ? parentName + 's' : parentName).replace(\n parentName,\n parentName.charAt(0).toUpperCase() + parentName.slice(1),\n )}`\n ]\n const debugByFeature = feature\n ? // @ts-expect-error\n table.options[\n `debug${feature.charAt(0).toUpperCase() + feature.slice(1)}`\n ]\n : false\n\n debug = debugAll || debugByParent || debugByFeature\n }\n\n function logTime(time: number, depsChanged: boolean) {\n const runType =\n runCount === 0\n ? '(1st run)'\n : depsChanged\n ? '(rerun #' + runCount + ')'\n : '(cache)'\n runCount++\n\n console.groupCollapsed(\n `%c⏱ ${pad(`${time.toFixed(1)} ms`, 12)} %c${runType}%c ${fnName}%c ${objectId ? `(${fnName.split('.')[0]}Id: ${objectId})` : ''}`,\n `font-size: .6rem; font-weight: bold; ${\n depsChanged\n ? `color: hsl(\n ${Math.max(0, Math.min(120 - Math.log10(time) * 60, 120))}deg 100% 31%);`\n : ''\n } `,\n `color: ${runCount < 2 ? '#FF00FF' : '#FF1493'}`,\n 'color: #666',\n 'color: #87CEEB',\n )\n console.info({\n feature,\n state: table.store.state,\n deps: memoOptions.memoDeps?.toString(),\n })\n console.trace()\n console.groupEnd()\n }\n\n const debugOptions =\n process.env.NODE_ENV === 'development'\n ? {\n onBeforeCompare: () => {\n if (debugCache) {\n beforeCompareTime = performance.now()\n }\n },\n onAfterCompare: (depsChanged: boolean) => {\n if (debugCache) {\n afterCompareTime = performance.now()\n const compareTime =\n Math.round((afterCompareTime - beforeCompareTime) * 100) / 100\n if (!depsChanged) {\n logTime(compareTime, depsChanged)\n }\n }\n },\n onBeforeUpdate: () => {\n if (debug) {\n startCalcTime = performance.now()\n }\n },\n onAfterUpdate: () => {\n if (debug) {\n endCalcTime = performance.now()\n const executionTime =\n Math.round((endCalcTime - startCalcTime) * 100) / 100\n logTime(executionTime, true)\n }\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n : {\n onAfterUpdate: () => {\n queueMicrotask(() => onAfterUpdate?.())\n },\n }\n\n return memo({\n ...memoOptions,\n ...debugOptions,\n })\n}\n\nexport interface API<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (...args: any) => any\n memoDeps?: (depArgs?: any) => [...any] | undefined\n}\n\nexport type APIObject<TDeps extends ReadonlyArray<any>, TDepArgs> = Record<\n string,\n API<TDeps, TDepArgs>\n>\n\n/**\n * Assumes that a function name is in the format of `parentName_fnKey` and returns the `fnKey` and `fnName` in the format of `parentName.fnKey`.\n */\nexport function getFunctionNameInfo(\n staticFnName: string,\n splitBy: '_' | '.' = '_',\n) {\n const [parentName, fnKey] = staticFnName.split(splitBy)\n const fnName = `${parentName}.${fnKey}`\n return { fnKey, fnName, parentName } as {\n fnKey: string\n fnName: string\n parentName: string\n }\n}\n\n/**\n * Assigns Table API methods directly to the table instance.\n * Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.\n */\nexport function assignTableAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n table: Table_Internal<TFeatures, TData>,\n apis: APIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n ;(table as Record<string, any>)[fnKey] = memoDeps\n ? tableMemo({\n memoDeps,\n fn,\n fnName,\n table,\n feature,\n })\n : fn\n }\n}\n\nexport interface PrototypeAPI<TDeps extends ReadonlyArray<any>, TDepArgs> {\n fn: (self: any, ...args: any) => any\n memoDeps?: (self: any, depArgs?: any) => [...any] | undefined\n}\n\nexport type PrototypeAPIObject<\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n> = Record<string, PrototypeAPI<TDeps, TDepArgs>>\n\n/**\n * Assigns API methods to a prototype object for memory-efficient method sharing.\n * All instances created with this prototype will share the same method references.\n *\n * For memoized methods, the memo state is lazily created and stored on each instance.\n * This provides the best of both worlds: shared method code + per-instance caching.\n */\nexport function assignPrototypeAPIs<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TDeps extends ReadonlyArray<any>,\n TDepArgs,\n>(\n feature: keyof TFeatures & string,\n prototype: Record<string, any>,\n table: Table_Internal<TFeatures, TData>,\n apis: PrototypeAPIObject<TDeps, NoInfer<TDepArgs>>,\n): void {\n for (const [staticFnName, { fn, memoDeps }] of Object.entries(apis)) {\n const { fnKey, fnName } = getFunctionNameInfo(staticFnName)\n\n if (memoDeps) {\n // For memoized methods, create a function that lazily initializes\n // the memo on first access and stores it on the instance\n const memoKey = `_memo_${fnKey}`\n\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n // Lazily create memo on first access for this instance\n if (!this[memoKey]) {\n const self = this\n this[memoKey] = tableMemo({\n memoDeps: () => memoDeps(self),\n fn: (...deps) => fn(self, ...deps),\n fnName,\n objectId: self.id,\n table,\n feature,\n })\n }\n return this[memoKey](...args)\n }\n } else {\n // Non-memoized methods just call the static function with `this`\n prototype[fnKey] = function (this: any, ...args: Array<any>) {\n return fn(this, ...args)\n }\n }\n\n setMemoFnMeta(prototype[fnKey], { originalArgsLength: fn.length })\n }\n}\n\n/**\n * Looks to run the memoized function with the builder pattern on the object if it exists, otherwise fallback to the static method passed in.\n */\nexport function callMemoOrStaticFn<\n TObject extends Record<string, any>,\n TStaticFn extends AnyFunction,\n>(\n obj: TObject,\n fnKey: string,\n staticFn: TStaticFn,\n ...args: Parameters<TStaticFn> extends [any, ...infer Rest] ? Rest : never\n): ReturnType<TStaticFn> {\n return (\n (obj[fnKey] as Function | undefined)?.(...args) ?? staticFn(obj, ...args)\n )\n}\n"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/table-core",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.11",
|
|
4
4
|
"description": "Headless UI for building powerful tables & datagrids for TS/JS.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,34 +18,43 @@
|
|
|
18
18
|
"react",
|
|
19
19
|
"vue",
|
|
20
20
|
"solid",
|
|
21
|
+
"svelte",
|
|
22
|
+
"lit",
|
|
23
|
+
"angular",
|
|
21
24
|
"table",
|
|
22
25
|
"table-core",
|
|
23
26
|
"datagrid"
|
|
24
27
|
],
|
|
25
28
|
"type": "module",
|
|
26
29
|
"types": "dist/esm/index.d.ts",
|
|
27
|
-
"main": "dist/
|
|
30
|
+
"main": "dist/esm/index.js",
|
|
28
31
|
"module": "dist/esm/index.js",
|
|
29
32
|
"exports": {
|
|
30
33
|
".": {
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
"default": "./dist/esm/index.js"
|
|
34
|
-
},
|
|
35
|
-
"require": {
|
|
36
|
-
"types": "./dist/cjs/index.d.cts",
|
|
37
|
-
"default": "./dist/cjs/index.cjs"
|
|
38
|
-
}
|
|
34
|
+
"types": "./dist/esm/index.d.ts",
|
|
35
|
+
"default": "./dist/esm/index.js"
|
|
39
36
|
},
|
|
40
37
|
"./package.json": "./package.json"
|
|
41
38
|
},
|
|
42
39
|
"sideEffects": false,
|
|
43
40
|
"engines": {
|
|
44
|
-
"node": ">=
|
|
41
|
+
"node": ">=16"
|
|
45
42
|
},
|
|
46
43
|
"files": [
|
|
47
44
|
"dist/",
|
|
48
45
|
"src"
|
|
49
46
|
],
|
|
50
|
-
"
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@tanstack/store": "^0.8.0"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"clean": "rimraf ./build && rimraf ./dist",
|
|
52
|
+
"lint:fix": "eslint ./src --fix",
|
|
53
|
+
"test:eslint": "eslint ./src",
|
|
54
|
+
"test:lib": "vitest",
|
|
55
|
+
"test:lib:dev": "pnpm test:lib --watch",
|
|
56
|
+
"test:types": "tsc",
|
|
57
|
+
"test:build": "publint --strict",
|
|
58
|
+
"build": "vite build"
|
|
59
|
+
}
|
|
51
60
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Table_Internal } from '../../types/Table'
|
|
2
|
+
import type { CellData, RowData } from '../../types/type-utils'
|
|
3
|
+
import type { TableFeatures } from '../../types/TableFeatures'
|
|
4
|
+
import type { Row } from '../../types/Row'
|
|
5
|
+
import type { Cell } from '../../types/Cell'
|
|
6
|
+
import type { Column } from '../../types/Column'
|
|
7
|
+
import type { Cell_CoreProperties } from './coreCellsFeature.types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates or retrieves the cell prototype for a table.
|
|
11
|
+
* The prototype is cached on the table and shared by all cell instances.
|
|
12
|
+
*/
|
|
13
|
+
function getCellPrototype<
|
|
14
|
+
TFeatures extends TableFeatures,
|
|
15
|
+
TData extends RowData,
|
|
16
|
+
>(table: Table_Internal<TFeatures, TData>): object {
|
|
17
|
+
if (!table._cellPrototype) {
|
|
18
|
+
table._cellPrototype = { table }
|
|
19
|
+
for (const feature of Object.values(table._features)) {
|
|
20
|
+
feature.assignCellPrototype?.(table._cellPrototype, table)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return table._cellPrototype
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function constructCell<
|
|
27
|
+
TFeatures extends TableFeatures,
|
|
28
|
+
TData extends RowData,
|
|
29
|
+
TValue extends CellData = CellData,
|
|
30
|
+
>(
|
|
31
|
+
column: Column<TFeatures, TData, TValue>,
|
|
32
|
+
row: Row<TFeatures, TData>,
|
|
33
|
+
table: Table_Internal<TFeatures, TData>,
|
|
34
|
+
): Cell<TFeatures, TData, TValue> {
|
|
35
|
+
// Create cell with shared prototype for memory efficiency
|
|
36
|
+
const cellPrototype = getCellPrototype(table)
|
|
37
|
+
const cell = Object.create(cellPrototype) as Cell_CoreProperties<
|
|
38
|
+
TFeatures,
|
|
39
|
+
TData,
|
|
40
|
+
TValue
|
|
41
|
+
>
|
|
42
|
+
|
|
43
|
+
// Only assign instance-specific properties
|
|
44
|
+
cell.column = column
|
|
45
|
+
cell.id = `${row.id}_${column.id}`
|
|
46
|
+
cell.row = row
|
|
47
|
+
|
|
48
|
+
return cell as Cell<TFeatures, TData, TValue>
|
|
49
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { assignPrototypeAPIs } from '../../utils'
|
|
2
|
+
import {
|
|
3
|
+
cell_getContext,
|
|
4
|
+
cell_getValue,
|
|
5
|
+
cell_renderValue,
|
|
6
|
+
} from './coreCellsFeature.utils'
|
|
7
|
+
import type { RowData } from '../../types/type-utils'
|
|
8
|
+
import type { TableFeature, TableFeatures } from '../../types/TableFeatures'
|
|
9
|
+
// import type { Cell_Cell, TableOptions_Cell } from './coreCellsFeature.types'
|
|
10
|
+
|
|
11
|
+
interface CoreCellsFeatureConstructors<
|
|
12
|
+
TFeatures extends TableFeatures,
|
|
13
|
+
TData extends RowData,
|
|
14
|
+
> {
|
|
15
|
+
// Cell: Cell_Cell<TableFeatures, RowData>
|
|
16
|
+
// TableOptions: TableOptions_Cell
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function constructCoreCellsFeature<
|
|
20
|
+
TFeatures extends TableFeatures,
|
|
21
|
+
TData extends RowData,
|
|
22
|
+
>(): TableFeature<CoreCellsFeatureConstructors<TFeatures, TData>> {
|
|
23
|
+
return {
|
|
24
|
+
assignCellPrototype: (prototype, table) => {
|
|
25
|
+
assignPrototypeAPIs('coreCellsFeature', prototype, table, {
|
|
26
|
+
cell_getValue: {
|
|
27
|
+
fn: (cell) => cell_getValue(cell),
|
|
28
|
+
},
|
|
29
|
+
cell_renderValue: {
|
|
30
|
+
fn: (cell) => cell_renderValue(cell),
|
|
31
|
+
},
|
|
32
|
+
cell_getContext: {
|
|
33
|
+
fn: (cell) => cell_getContext(cell),
|
|
34
|
+
memoDeps: (cell) => [cell],
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The Core Cells feature provides the core cell functionality.
|
|
43
|
+
*/
|
|
44
|
+
export const coreCellsFeature = constructCoreCellsFeature()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { CellData, Getter, RowData } from '../../types/type-utils'
|
|
2
|
+
import type { TableFeatures } from '../../types/TableFeatures'
|
|
3
|
+
import type { Table, Table_Internal } from '../../types/Table'
|
|
4
|
+
import type { Row } from '../../types/Row'
|
|
5
|
+
import type { Cell } from '../../types/Cell'
|
|
6
|
+
import type { Column } from '../../types/Column'
|
|
7
|
+
|
|
8
|
+
export interface CellContext<
|
|
9
|
+
TFeatures extends TableFeatures,
|
|
10
|
+
TData extends RowData,
|
|
11
|
+
TValue extends CellData = CellData,
|
|
12
|
+
> {
|
|
13
|
+
cell: Cell<TFeatures, TData, TValue>
|
|
14
|
+
column: Column<TFeatures, TData, TValue>
|
|
15
|
+
getValue: Getter<TValue>
|
|
16
|
+
renderValue: Getter<TValue | null>
|
|
17
|
+
row: Row<TFeatures, TData>
|
|
18
|
+
table: Table<TFeatures, TData>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface Cell_CoreProperties<
|
|
22
|
+
TFeatures extends TableFeatures,
|
|
23
|
+
TData extends RowData,
|
|
24
|
+
TValue extends CellData = CellData,
|
|
25
|
+
> {
|
|
26
|
+
/**
|
|
27
|
+
* The associated Column object for the cell.
|
|
28
|
+
*/
|
|
29
|
+
column: Column<TFeatures, TData, TValue>
|
|
30
|
+
/**
|
|
31
|
+
* The unique ID for the cell across the entire table.
|
|
32
|
+
*/
|
|
33
|
+
id: string
|
|
34
|
+
/**
|
|
35
|
+
* The associated Row object for the cell.
|
|
36
|
+
*/
|
|
37
|
+
row: Row<TFeatures, TData>
|
|
38
|
+
/**
|
|
39
|
+
* Reference to the parent table instance.
|
|
40
|
+
*/
|
|
41
|
+
table: Table_Internal<TFeatures, TData>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface Cell_Cell<
|
|
45
|
+
TFeatures extends TableFeatures,
|
|
46
|
+
TData extends RowData,
|
|
47
|
+
TValue extends CellData = CellData,
|
|
48
|
+
> extends Cell_CoreProperties<TFeatures, TData, TValue> {
|
|
49
|
+
/**
|
|
50
|
+
* Returns the rendering context (or props) for cell-based components like cells and aggregated cells. Use these props with your framework's `flexRender` utility to render these using the template of your choice:
|
|
51
|
+
*/
|
|
52
|
+
getContext: () => CellContext<TFeatures, TData, TValue>
|
|
53
|
+
/**
|
|
54
|
+
* Returns the value for the cell, accessed via the associated column's accessor key or accessor function.
|
|
55
|
+
*/
|
|
56
|
+
getValue: CellContext<TFeatures, TData, TValue>['getValue']
|
|
57
|
+
/**
|
|
58
|
+
* Renders the value for a cell the same as `getValue`, but will return the `renderFallbackValue` if no value is found.
|
|
59
|
+
*/
|
|
60
|
+
renderValue: CellContext<TFeatures, TData, TValue>['renderValue']
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface TableOptions_Cell {
|
|
64
|
+
/**
|
|
65
|
+
* Value used when the desired value is not found in the data.
|
|
66
|
+
*/
|
|
67
|
+
renderFallbackValue?: any
|
|
68
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CellData, RowData } from '../../types/type-utils'
|
|
2
|
+
import type { TableFeatures } from '../../types/TableFeatures'
|
|
3
|
+
import type { Cell } from '../../types/Cell'
|
|
4
|
+
|
|
5
|
+
export function cell_getValue<
|
|
6
|
+
TFeatures extends TableFeatures,
|
|
7
|
+
TData extends RowData,
|
|
8
|
+
TValue extends CellData = CellData,
|
|
9
|
+
>(cell: Cell<TFeatures, TData, TValue>): TValue {
|
|
10
|
+
return cell.row.getValue(cell.column.id)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function cell_renderValue<
|
|
14
|
+
TFeatures extends TableFeatures,
|
|
15
|
+
TData extends RowData,
|
|
16
|
+
TValue extends CellData = CellData,
|
|
17
|
+
>(cell: Cell<TFeatures, TData, TValue>) {
|
|
18
|
+
return cell.getValue() ?? cell.table.options.renderFallbackValue
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function cell_getContext<
|
|
22
|
+
TFeatures extends TableFeatures,
|
|
23
|
+
TData extends RowData,
|
|
24
|
+
TValue extends CellData = CellData,
|
|
25
|
+
>(cell: Cell<TFeatures, TData, TValue>) {
|
|
26
|
+
return {
|
|
27
|
+
table: cell.table,
|
|
28
|
+
column: cell.column,
|
|
29
|
+
row: cell.row,
|
|
30
|
+
cell: cell,
|
|
31
|
+
// Wrap in arrow functions to preserve `this` binding (methods are on prototype)
|
|
32
|
+
getValue: () => cell.getValue(),
|
|
33
|
+
renderValue: () => cell.renderValue(),
|
|
34
|
+
}
|
|
35
|
+
}
|