@tanstack/table-core 9.0.0-beta.2 → 9.0.0-beta.7
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/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/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/headers/buildHeaderGroups.cjs.map +1 -1
- package/dist/core/headers/buildHeaderGroups.js.map +1 -1
- 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.utils.cjs.map +1 -1
- 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 +3 -5
- package/dist/core/row-models/coreRowModelsFeature.types.d.ts +3 -5
- package/dist/core/row-models/createCoreRowModel.cjs.map +1 -1
- package/dist/core/row-models/createCoreRowModel.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/table/constructTable.cjs +2 -2
- package/dist/core/table/constructTable.cjs.map +1 -1
- package/dist/core/table/constructTable.js +2 -2
- 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.utils.cjs.map +1 -1
- 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/createFacetedMinMaxValues.cjs.map +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.js.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +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 +41 -53
- package/dist/features/column-filtering/columnFilteringFeature.js.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +3 -3
- package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +3 -3
- package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +1 -1
- package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.cts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.d.ts +1 -1
- package/dist/features/column-filtering/createFilteredRowModel.js.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 +58 -69
- package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
- package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
- 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-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.utils.cjs.map +1 -1
- package/dist/features/column-pinning/columnPinningFeature.utils.d.cts +12 -12
- package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +12 -12
- 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-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.d.cts +3 -3
- package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +3 -3
- 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/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.utils.cjs.map +1 -1
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +4 -2
- package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +4 -2
- 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.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-pagination/createPaginatedRowModel.cjs.map +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-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-selection/rowSelectionFeature.cjs +65 -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 +66 -77
- package/dist/features/row-selection/rowSelectionFeature.js.map +1 -1
- package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
- 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.utils.cjs +8 -5
- package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
- 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/index.cjs +0 -20
- package/dist/index.d.cts +34 -34
- package/dist/index.d.ts +34 -34
- package/dist/index.js +21 -21
- package/dist/types/Cell.d.cts +3 -8
- package/dist/types/Cell.d.ts +3 -8
- package/dist/types/Column.d.cts +3 -8
- package/dist/types/Column.d.ts +3 -8
- package/dist/types/ColumnDef.d.cts +3 -8
- package/dist/types/ColumnDef.d.ts +3 -8
- package/dist/types/Header.d.cts +3 -8
- package/dist/types/Header.d.ts +3 -8
- package/dist/types/HeaderGroup.d.cts +3 -8
- package/dist/types/HeaderGroup.d.ts +3 -8
- package/dist/types/Row.d.cts +3 -8
- package/dist/types/Row.d.ts +3 -8
- package/dist/types/RowModel.d.cts +4 -10
- package/dist/types/RowModel.d.ts +4 -10
- package/dist/types/RowModelFns.d.cts +3 -8
- package/dist/types/RowModelFns.d.ts +3 -8
- package/dist/types/Table.d.cts +3 -8
- package/dist/types/Table.d.ts +3 -8
- package/dist/types/TableFeatures.d.cts +13 -39
- package/dist/types/TableFeatures.d.ts +13 -39
- package/dist/types/TableOptions.d.cts +3 -4
- package/dist/types/TableOptions.d.ts +3 -4
- package/dist/types/TableState.d.cts +5 -10
- package/dist/types/TableState.d.ts +5 -10
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/core/cells/coreCellsFeature.ts +17 -39
- package/src/core/columns/coreColumnsFeature.ts +56 -83
- package/src/core/headers/buildHeaderGroups.ts +1 -1
- package/src/core/headers/coreHeadersFeature.ts +42 -64
- 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 +2 -6
- package/src/core/row-models/createCoreRowModel.ts +1 -1
- package/src/core/rows/coreRowsFeature.ts +45 -72
- package/src/core/table/constructTable.ts +10 -7
- package/src/core/table/coreTablesFeature.ts +13 -35
- package/src/core/table/coreTablesFeature.utils.ts +1 -1
- package/src/features/column-faceting/columnFacetingFeature.ts +71 -102
- 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 +60 -103
- package/src/features/column-filtering/columnFilteringFeature.types.ts +3 -3
- package/src/features/column-filtering/columnFilteringFeature.utils.ts +4 -4
- package/src/features/column-filtering/createFilteredRowModel.ts +2 -2
- package/src/features/column-grouping/columnGroupingFeature.ts +82 -126
- package/src/features/column-grouping/createGroupedRowModel.ts +1 -1
- package/src/features/column-ordering/columnOrderingFeature.ts +52 -84
- package/src/features/column-pinning/columnPinningFeature.ts +268 -304
- package/src/features/column-pinning/columnPinningFeature.utils.ts +5 -5
- package/src/features/column-resizing/columnResizingFeature.ts +44 -78
- package/src/features/column-sizing/columnSizingFeature.ts +115 -152
- package/src/features/column-visibility/columnVisibilityFeature.ts +92 -129
- package/src/features/global-filtering/globalFilteringFeature.ts +45 -79
- package/src/features/global-filtering/globalFilteringFeature.utils.ts +4 -2
- package/src/features/row-expanding/createExpandedRowModel.ts +1 -1
- package/src/features/row-expanding/rowExpandingFeature.ts +65 -101
- package/src/features/row-pagination/createPaginatedRowModel.ts +1 -1
- package/src/features/row-pagination/rowPaginationFeature.ts +69 -103
- package/src/features/row-pinning/rowPinningFeature.ts +72 -104
- package/src/features/row-selection/rowSelectionFeature.ts +103 -135
- package/src/features/row-sorting/createSortedRowModel.ts +1 -1
- package/src/features/row-sorting/rowSortingFeature.ts +73 -114
- package/src/features/row-sorting/rowSortingFeature.utils.ts +8 -6
- package/src/fns/aggregationFns.ts +26 -42
- package/src/fns/filterFns.ts +231 -264
- package/src/fns/sortFns.ts +51 -29
- package/src/types/Cell.ts +3 -19
- package/src/types/Column.ts +2 -18
- package/src/types/ColumnDef.ts +2 -18
- package/src/types/Header.ts +2 -18
- package/src/types/HeaderGroup.ts +2 -13
- package/src/types/Row.ts +2 -17
- package/src/types/RowModel.ts +3 -25
- package/src/types/RowModelFns.ts +2 -17
- package/src/types/Table.ts +2 -17
- package/src/types/TableFeatures.ts +51 -112
- package/src/types/TableOptions.ts +1 -12
- package/src/types/TableState.ts +4 -30
- package/src/utils.ts +5 -4
package/dist/types/Table.d.ts
CHANGED
|
@@ -19,18 +19,13 @@ import { CachedRowModel_All, CreateRowModels_All } from "./RowModel.js";
|
|
|
19
19
|
import { TableState_All } from "./TableState.js";
|
|
20
20
|
import { Atoms_All, BaseAtoms_All, ExternalAtoms_All, Table_Table } from "../core/table/coreTablesFeature.types.js";
|
|
21
21
|
import { TableOptions_All } from "./TableOptions.js";
|
|
22
|
-
import { ExtractFeatureMapTypes,
|
|
22
|
+
import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.js";
|
|
23
23
|
import { Table_ColumnFaceting } from "../features/column-faceting/columnFacetingFeature.types.js";
|
|
24
24
|
import { Table_RowModels } from "../core/row-models/coreRowModelsFeature.types.js";
|
|
25
25
|
import { Table_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.js";
|
|
26
26
|
import { ReadonlyStore } from "@tanstack/store";
|
|
27
27
|
|
|
28
28
|
//#region src/types/Table.d.ts
|
|
29
|
-
/**
|
|
30
|
-
* Use this interface as a target for declaration merging to add your own plugin properties.
|
|
31
|
-
* Note: This will affect the types of all tables in your project.
|
|
32
|
-
*/
|
|
33
|
-
interface Table_Plugins<TFeatures extends TableFeatures, TData extends RowData> {}
|
|
34
29
|
/**
|
|
35
30
|
* The core table object that only includes the core table functionality such as column, header, row, and table APIS.
|
|
36
31
|
* No features are included.
|
|
@@ -55,7 +50,7 @@ interface Table_FeatureMap<TFeatures extends TableFeatures, TData extends RowDat
|
|
|
55
50
|
/**
|
|
56
51
|
* The table object that includes both the core table functionality and the features that are enabled via the `features` table option.
|
|
57
52
|
*/
|
|
58
|
-
type Table<TFeatures extends TableFeatures, TData extends RowData> = Table_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, Table_FeatureMap<TFeatures, TData
|
|
53
|
+
type Table<TFeatures extends TableFeatures, TData extends RowData> = Table_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, Table_FeatureMap<TFeatures, TData>>;
|
|
59
54
|
type Table_Internal<TFeatures extends TableFeatures, TData extends RowData = any> = Table<TFeatures, TData> & {
|
|
60
55
|
_rowModels: CachedRowModel_All<TFeatures, TData>;
|
|
61
56
|
_rowModelFns: RowModelFns_All<TFeatures, TData>;
|
|
@@ -71,5 +66,5 @@ type Table_Internal<TFeatures extends TableFeatures, TData extends RowData = any
|
|
|
71
66
|
store: ReadonlyStore<TableState_All>;
|
|
72
67
|
};
|
|
73
68
|
//#endregion
|
|
74
|
-
export { Table, Table_Core, Table_FeatureMap, Table_Internal
|
|
69
|
+
export { Table, Table_Core, Table_FeatureMap, Table_Internal };
|
|
75
70
|
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -8,72 +8,46 @@ import { StockFeatures } from "../features/stockFeatures.cjs";
|
|
|
8
8
|
import { Table_Internal } from "./Table.cjs";
|
|
9
9
|
|
|
10
10
|
//#region src/types/TableFeatures.d.ts
|
|
11
|
-
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: K extends 'coreReativityFeature' ? never : TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
12
11
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
CachedRowModel?: any;
|
|
16
|
-
Cell?: any;
|
|
17
|
-
Column?: any;
|
|
18
|
-
ColumnDef?: any;
|
|
19
|
-
CreateRowModels?: any;
|
|
20
|
-
Header?: any;
|
|
21
|
-
HeaderGroup?: any;
|
|
22
|
-
Row?: any;
|
|
23
|
-
RowModelFns?: any;
|
|
24
|
-
Table?: any;
|
|
25
|
-
TableOptions?: any;
|
|
26
|
-
TableState?: any;
|
|
27
|
-
}
|
|
12
|
+
type UnionToIntersectionOrEmpty<T> = [T] extends [never] ? {} : UnionToIntersection<T> & {};
|
|
13
|
+
type ExtractFeatureMapTypes<TFeatures extends TableFeatures, TFeatureMap extends object> = IsAny<TFeatures> extends true ? UnionToIntersection<TFeatureMap[keyof TFeatureMap]> : UnionToIntersectionOrEmpty<TFeatureMap[Extract<keyof TFeatures, keyof TFeatureMap>]>;
|
|
28
14
|
interface Plugins {}
|
|
29
15
|
interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, Partial<Plugins> {}
|
|
30
|
-
|
|
31
|
-
options: Partial<TConstructors['TableOptions']>;
|
|
32
|
-
}) => void;
|
|
33
|
-
type GetDefaultColumnDef<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue> & Partial<TConstructors['ColumnDef']>;
|
|
34
|
-
type GetDefaultTableOptions<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData> & Partial<TConstructors['Table']>) => Partial<TableOptions_All<TFeatures, TData>> & Partial<TConstructors['TableOptions']>;
|
|
35
|
-
type GetInitialState<TConstructors extends FeatureConstructors> = (initialState: Partial<TableState_All> & Partial<TConstructors['TableState']>) => TableState_All & Partial<TConstructors['TableState']>;
|
|
36
|
-
type GetDefaultStateSelector<TConstructors extends FeatureConstructors> = (state: TableState_All) => Partial<TableState_All> & Partial<TConstructors['TableState']>;
|
|
37
|
-
type AssignCellPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
38
|
-
type AssignColumnPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
39
|
-
type AssignHeaderPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
40
|
-
type AssignRowPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
41
|
-
type InitRowInstanceData<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData> & Partial<TConstructors['Row']>) => void;
|
|
42
|
-
interface TableFeature<TConstructors extends FeatureConstructors> {
|
|
16
|
+
interface TableFeature {
|
|
43
17
|
/**
|
|
44
18
|
* Assigns Cell APIs to the cell prototype for memory-efficient method sharing.
|
|
45
19
|
* This is called once per table to build a shared prototype for all cells.
|
|
46
20
|
*/
|
|
47
|
-
assignCellPrototype?:
|
|
21
|
+
assignCellPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
48
22
|
/**
|
|
49
23
|
* Assigns Column APIs to the column prototype for memory-efficient method sharing.
|
|
50
24
|
* This is called once per table to build a shared prototype for all columns.
|
|
51
25
|
*/
|
|
52
|
-
assignColumnPrototype?:
|
|
26
|
+
assignColumnPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
53
27
|
/**
|
|
54
28
|
* Assigns Header APIs to the header prototype for memory-efficient method sharing.
|
|
55
29
|
* This is called once per table to build a shared prototype for all headers.
|
|
56
30
|
*/
|
|
57
|
-
assignHeaderPrototype?:
|
|
31
|
+
assignHeaderPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
58
32
|
/**
|
|
59
33
|
* Assigns Row APIs to the row prototype for memory-efficient method sharing.
|
|
60
34
|
* This is called once per table to build a shared prototype for all rows.
|
|
61
35
|
*/
|
|
62
|
-
assignRowPrototype?:
|
|
36
|
+
assignRowPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
63
37
|
/**
|
|
64
38
|
* Assigns Table APIs to the table instance.
|
|
65
39
|
* Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.
|
|
66
40
|
*/
|
|
67
|
-
constructTableAPIs?:
|
|
68
|
-
getDefaultColumnDef?:
|
|
69
|
-
getDefaultTableOptions?:
|
|
70
|
-
getInitialState?:
|
|
41
|
+
constructTableAPIs?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData>) => void;
|
|
42
|
+
getDefaultColumnDef?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue>;
|
|
43
|
+
getDefaultTableOptions?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData>) => Partial<TableOptions_All<TFeatures, TData>>;
|
|
44
|
+
getInitialState?: (initialState: Partial<TableState_All>) => TableState_All;
|
|
71
45
|
/**
|
|
72
46
|
* Initializes instance-specific data on each row (e.g., caches).
|
|
73
47
|
* Methods should be assigned via assignRowPrototype instead.
|
|
74
48
|
*/
|
|
75
|
-
initRowInstanceData?:
|
|
49
|
+
initRowInstanceData?: <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>) => void;
|
|
76
50
|
}
|
|
77
51
|
//#endregion
|
|
78
|
-
export {
|
|
52
|
+
export { ExtractFeatureMapTypes, Plugins, TableFeature, TableFeatures };
|
|
79
53
|
//# sourceMappingURL=TableFeatures.d.cts.map
|
|
@@ -8,72 +8,46 @@ import { StockFeatures } from "../features/stockFeatures.js";
|
|
|
8
8
|
import { Table_Internal } from "./Table.js";
|
|
9
9
|
|
|
10
10
|
//#region src/types/TableFeatures.d.ts
|
|
11
|
-
type ExtractFeatureTypes<TKey extends keyof FeatureConstructors, TFeatures extends TableFeatures> = UnionToIntersection<{ [K in keyof TFeatures]: K extends 'coreReativityFeature' ? never : TFeatures[K] extends TableFeature<infer FeatureConstructorOptions> ? TKey extends keyof FeatureConstructorOptions ? FeatureConstructorOptions[TKey] : never : any }[keyof TFeatures]>;
|
|
12
11
|
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
CachedRowModel?: any;
|
|
16
|
-
Cell?: any;
|
|
17
|
-
Column?: any;
|
|
18
|
-
ColumnDef?: any;
|
|
19
|
-
CreateRowModels?: any;
|
|
20
|
-
Header?: any;
|
|
21
|
-
HeaderGroup?: any;
|
|
22
|
-
Row?: any;
|
|
23
|
-
RowModelFns?: any;
|
|
24
|
-
Table?: any;
|
|
25
|
-
TableOptions?: any;
|
|
26
|
-
TableState?: any;
|
|
27
|
-
}
|
|
12
|
+
type UnionToIntersectionOrEmpty<T> = [T] extends [never] ? {} : UnionToIntersection<T> & {};
|
|
13
|
+
type ExtractFeatureMapTypes<TFeatures extends TableFeatures, TFeatureMap extends object> = IsAny<TFeatures> extends true ? UnionToIntersection<TFeatureMap[keyof TFeatureMap]> : UnionToIntersectionOrEmpty<TFeatureMap[Extract<keyof TFeatures, keyof TFeatureMap>]>;
|
|
28
14
|
interface Plugins {}
|
|
29
15
|
interface TableFeatures extends Partial<CoreFeatures>, Partial<StockFeatures>, Partial<Plugins> {}
|
|
30
|
-
|
|
31
|
-
options: Partial<TConstructors['TableOptions']>;
|
|
32
|
-
}) => void;
|
|
33
|
-
type GetDefaultColumnDef<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue> & Partial<TConstructors['ColumnDef']>;
|
|
34
|
-
type GetDefaultTableOptions<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData> & Partial<TConstructors['Table']>) => Partial<TableOptions_All<TFeatures, TData>> & Partial<TConstructors['TableOptions']>;
|
|
35
|
-
type GetInitialState<TConstructors extends FeatureConstructors> = (initialState: Partial<TableState_All> & Partial<TConstructors['TableState']>) => TableState_All & Partial<TConstructors['TableState']>;
|
|
36
|
-
type GetDefaultStateSelector<TConstructors extends FeatureConstructors> = (state: TableState_All) => Partial<TableState_All> & Partial<TConstructors['TableState']>;
|
|
37
|
-
type AssignCellPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
38
|
-
type AssignColumnPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
39
|
-
type AssignHeaderPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
40
|
-
type AssignRowPrototype<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
41
|
-
type InitRowInstanceData<TConstructors extends FeatureConstructors> = <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData> & Partial<TConstructors['Row']>) => void;
|
|
42
|
-
interface TableFeature<TConstructors extends FeatureConstructors> {
|
|
16
|
+
interface TableFeature {
|
|
43
17
|
/**
|
|
44
18
|
* Assigns Cell APIs to the cell prototype for memory-efficient method sharing.
|
|
45
19
|
* This is called once per table to build a shared prototype for all cells.
|
|
46
20
|
*/
|
|
47
|
-
assignCellPrototype?:
|
|
21
|
+
assignCellPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
48
22
|
/**
|
|
49
23
|
* Assigns Column APIs to the column prototype for memory-efficient method sharing.
|
|
50
24
|
* This is called once per table to build a shared prototype for all columns.
|
|
51
25
|
*/
|
|
52
|
-
assignColumnPrototype?:
|
|
26
|
+
assignColumnPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
53
27
|
/**
|
|
54
28
|
* Assigns Header APIs to the header prototype for memory-efficient method sharing.
|
|
55
29
|
* This is called once per table to build a shared prototype for all headers.
|
|
56
30
|
*/
|
|
57
|
-
assignHeaderPrototype?:
|
|
31
|
+
assignHeaderPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
58
32
|
/**
|
|
59
33
|
* Assigns Row APIs to the row prototype for memory-efficient method sharing.
|
|
60
34
|
* This is called once per table to build a shared prototype for all rows.
|
|
61
35
|
*/
|
|
62
|
-
assignRowPrototype?:
|
|
36
|
+
assignRowPrototype?: <TFeatures extends TableFeatures, TData extends RowData>(prototype: Record<string, any>, table: Table_Internal<TFeatures, TData>) => void;
|
|
63
37
|
/**
|
|
64
38
|
* Assigns Table APIs to the table instance.
|
|
65
39
|
* Unlike row/cell/column/header, the table is a singleton so methods are assigned directly.
|
|
66
40
|
*/
|
|
67
|
-
constructTableAPIs?:
|
|
68
|
-
getDefaultColumnDef?:
|
|
69
|
-
getDefaultTableOptions?:
|
|
70
|
-
getInitialState?:
|
|
41
|
+
constructTableAPIs?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData>) => void;
|
|
42
|
+
getDefaultColumnDef?: <TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData>() => ColumnDefBase_All<TFeatures, TData, TValue>;
|
|
43
|
+
getDefaultTableOptions?: <TFeatures extends TableFeatures, TData extends RowData>(table: Table_Internal<TFeatures, TData>) => Partial<TableOptions_All<TFeatures, TData>>;
|
|
44
|
+
getInitialState?: (initialState: Partial<TableState_All>) => TableState_All;
|
|
71
45
|
/**
|
|
72
46
|
* Initializes instance-specific data on each row (e.g., caches).
|
|
73
47
|
* Methods should be assigned via assignRowPrototype instead.
|
|
74
48
|
*/
|
|
75
|
-
initRowInstanceData?:
|
|
49
|
+
initRowInstanceData?: <TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>) => void;
|
|
76
50
|
}
|
|
77
51
|
//#endregion
|
|
78
|
-
export {
|
|
52
|
+
export { ExtractFeatureMapTypes, Plugins, TableFeature, TableFeatures };
|
|
79
53
|
//# sourceMappingURL=TableFeatures.d.ts.map
|
|
@@ -16,11 +16,10 @@ import { TableOptions_Rows } from "../core/rows/coreRowsFeature.types.cjs";
|
|
|
16
16
|
import { TableOptions_Cell } from "../core/cells/coreCellsFeature.types.cjs";
|
|
17
17
|
import { TableOptions_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.cjs";
|
|
18
18
|
import { TableOptions_Table } from "../core/table/coreTablesFeature.types.cjs";
|
|
19
|
-
import { ExtractFeatureMapTypes,
|
|
19
|
+
import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.cjs";
|
|
20
20
|
import { TableOptions_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.cjs";
|
|
21
21
|
|
|
22
22
|
//#region src/types/TableOptions.d.ts
|
|
23
|
-
interface TableOptions_Plugins<TFeatures extends TableFeatures, TData extends RowData> {}
|
|
24
23
|
/**
|
|
25
24
|
* Core options that are always available on a table, before optional feature
|
|
26
25
|
* options are mixed in.
|
|
@@ -59,12 +58,12 @@ type TableOptions_FeatureMap_All<TFeatures extends TableFeatures, TData extends
|
|
|
59
58
|
* `TFeatures`, then custom feature/plugin options and debug options are mixed
|
|
60
59
|
* in.
|
|
61
60
|
*/
|
|
62
|
-
type TableOptions<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, TableOptions_FeatureMap<TFeatures, TData>> &
|
|
61
|
+
type TableOptions<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, TableOptions_FeatureMap<TFeatures, TData>> & DebugOptions<TFeatures>;
|
|
63
62
|
/**
|
|
64
63
|
* Internal broad option shape used where feature code may need to read options
|
|
65
64
|
* from features that are not present in the current generic feature set.
|
|
66
65
|
*/
|
|
67
66
|
type TableOptions_All<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & Partial<TableOptions_FeatureMap_All<TFeatures, TData>>;
|
|
68
67
|
//#endregion
|
|
69
|
-
export { DebugOptions, TableOptions, TableOptions_All, TableOptions_Core, TableOptions_FeatureMap, TableOptions_FeatureMap_All
|
|
68
|
+
export { DebugOptions, TableOptions, TableOptions_All, TableOptions_Core, TableOptions_FeatureMap, TableOptions_FeatureMap_All };
|
|
70
69
|
//# sourceMappingURL=TableOptions.d.cts.map
|
|
@@ -16,11 +16,10 @@ import { TableOptions_Rows } from "../core/rows/coreRowsFeature.types.js";
|
|
|
16
16
|
import { TableOptions_Cell } from "../core/cells/coreCellsFeature.types.js";
|
|
17
17
|
import { TableOptions_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.js";
|
|
18
18
|
import { TableOptions_Table } from "../core/table/coreTablesFeature.types.js";
|
|
19
|
-
import { ExtractFeatureMapTypes,
|
|
19
|
+
import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.js";
|
|
20
20
|
import { TableOptions_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.js";
|
|
21
21
|
|
|
22
22
|
//#region src/types/TableOptions.d.ts
|
|
23
|
-
interface TableOptions_Plugins<TFeatures extends TableFeatures, TData extends RowData> {}
|
|
24
23
|
/**
|
|
25
24
|
* Core options that are always available on a table, before optional feature
|
|
26
25
|
* options are mixed in.
|
|
@@ -59,12 +58,12 @@ type TableOptions_FeatureMap_All<TFeatures extends TableFeatures, TData extends
|
|
|
59
58
|
* `TFeatures`, then custom feature/plugin options and debug options are mixed
|
|
60
59
|
* in.
|
|
61
60
|
*/
|
|
62
|
-
type TableOptions<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, TableOptions_FeatureMap<TFeatures, TData>> &
|
|
61
|
+
type TableOptions<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & ExtractFeatureMapTypes<TFeatures, TableOptions_FeatureMap<TFeatures, TData>> & DebugOptions<TFeatures>;
|
|
63
62
|
/**
|
|
64
63
|
* Internal broad option shape used where feature code may need to read options
|
|
65
64
|
* from features that are not present in the current generic feature set.
|
|
66
65
|
*/
|
|
67
66
|
type TableOptions_All<TFeatures extends TableFeatures, TData extends RowData> = TableOptions_Core<TFeatures, TData> & Partial<TableOptions_FeatureMap_All<TFeatures, TData>>;
|
|
68
67
|
//#endregion
|
|
69
|
-
export { DebugOptions, TableOptions, TableOptions_All, TableOptions_Core, TableOptions_FeatureMap, TableOptions_FeatureMap_All
|
|
68
|
+
export { DebugOptions, TableOptions, TableOptions_All, TableOptions_Core, TableOptions_FeatureMap, TableOptions_FeatureMap_All };
|
|
70
69
|
//# sourceMappingURL=TableOptions.d.ts.map
|
|
@@ -10,15 +10,10 @@ import { TableState_RowExpanding } from "../features/row-expanding/rowExpandingF
|
|
|
10
10
|
import { TableState_RowPinning } from "../features/row-pinning/rowPinningFeature.types.cjs";
|
|
11
11
|
import { TableState_RowSelection } from "../features/row-selection/rowSelectionFeature.types.cjs";
|
|
12
12
|
import { TableState_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.cjs";
|
|
13
|
-
import { ExtractFeatureMapTypes,
|
|
13
|
+
import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.cjs";
|
|
14
14
|
import { TableState_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.cjs";
|
|
15
15
|
|
|
16
16
|
//#region src/types/TableState.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* Use this interface as a target for declaration merging to add your own state properties.
|
|
19
|
-
* Note: This will affect the types of all tables in your project.
|
|
20
|
-
*/
|
|
21
|
-
interface TableState_Plugins<TFeatures extends TableFeatures> {}
|
|
22
17
|
interface TableState_FeatureMap {
|
|
23
18
|
columnFilteringFeature: TableState_ColumnFiltering;
|
|
24
19
|
columnGroupingFeature: TableState_ColumnGrouping;
|
|
@@ -40,14 +35,14 @@ interface TableState_FeatureMap {
|
|
|
40
35
|
* State slices are included only when their feature is present in `TFeatures`,
|
|
41
36
|
* then custom feature/plugin state is mixed in.
|
|
42
37
|
*/
|
|
43
|
-
type TableState<TFeatures extends TableFeatures> = ExtractFeatureMapTypes<TFeatures, TableState_FeatureMap
|
|
38
|
+
type TableState<TFeatures extends TableFeatures> = ExtractFeatureMapTypes<TFeatures, TableState_FeatureMap>;
|
|
44
39
|
/**
|
|
45
|
-
* Internal broad state shape containing every
|
|
40
|
+
* Internal broad state shape containing every registered feature state slice.
|
|
46
41
|
*
|
|
47
42
|
* Feature internals use this when they may need to inspect optional slices owned
|
|
48
43
|
* by other features.
|
|
49
44
|
*/
|
|
50
|
-
type TableState_All = Partial<
|
|
45
|
+
type TableState_All = Partial<TableState<TableFeatures>>;
|
|
51
46
|
//#endregion
|
|
52
|
-
export { TableState, TableState_All, TableState_FeatureMap
|
|
47
|
+
export { TableState, TableState_All, TableState_FeatureMap };
|
|
53
48
|
//# sourceMappingURL=TableState.d.cts.map
|
|
@@ -10,15 +10,10 @@ import { TableState_RowExpanding } from "../features/row-expanding/rowExpandingF
|
|
|
10
10
|
import { TableState_RowPinning } from "../features/row-pinning/rowPinningFeature.types.js";
|
|
11
11
|
import { TableState_RowSelection } from "../features/row-selection/rowSelectionFeature.types.js";
|
|
12
12
|
import { TableState_RowPagination } from "../features/row-pagination/rowPaginationFeature.types.js";
|
|
13
|
-
import { ExtractFeatureMapTypes,
|
|
13
|
+
import { ExtractFeatureMapTypes, TableFeatures } from "./TableFeatures.js";
|
|
14
14
|
import { TableState_ColumnGrouping } from "../features/column-grouping/columnGroupingFeature.types.js";
|
|
15
15
|
|
|
16
16
|
//#region src/types/TableState.d.ts
|
|
17
|
-
/**
|
|
18
|
-
* Use this interface as a target for declaration merging to add your own state properties.
|
|
19
|
-
* Note: This will affect the types of all tables in your project.
|
|
20
|
-
*/
|
|
21
|
-
interface TableState_Plugins<TFeatures extends TableFeatures> {}
|
|
22
17
|
interface TableState_FeatureMap {
|
|
23
18
|
columnFilteringFeature: TableState_ColumnFiltering;
|
|
24
19
|
columnGroupingFeature: TableState_ColumnGrouping;
|
|
@@ -40,14 +35,14 @@ interface TableState_FeatureMap {
|
|
|
40
35
|
* State slices are included only when their feature is present in `TFeatures`,
|
|
41
36
|
* then custom feature/plugin state is mixed in.
|
|
42
37
|
*/
|
|
43
|
-
type TableState<TFeatures extends TableFeatures> = ExtractFeatureMapTypes<TFeatures, TableState_FeatureMap
|
|
38
|
+
type TableState<TFeatures extends TableFeatures> = ExtractFeatureMapTypes<TFeatures, TableState_FeatureMap>;
|
|
44
39
|
/**
|
|
45
|
-
* Internal broad state shape containing every
|
|
40
|
+
* Internal broad state shape containing every registered feature state slice.
|
|
46
41
|
*
|
|
47
42
|
* Feature internals use this when they may need to inspect optional slices owned
|
|
48
43
|
* by other features.
|
|
49
44
|
*/
|
|
50
|
-
type TableState_All = Partial<
|
|
45
|
+
type TableState_All = Partial<TableState<TableFeatures>>;
|
|
51
46
|
//#endregion
|
|
52
|
-
export { TableState, TableState_All, TableState_FeatureMap
|
|
47
|
+
export { TableState, TableState_All, TableState_FeatureMap };
|
|
53
48
|
//# sourceMappingURL=TableState.d.ts.map
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","names":[],"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\n/**\n * Applies a TanStack updater to a value.\n *\n * If the updater is a function it is called with the previous value; otherwise the updater value is returned directly.\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\n/**\n * Clones table state values while preserving non-plain objects.\n *\n * Plain objects and arrays are copied recursively so state updates can avoid mutating existing references.\n */\nexport function cloneState<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map(cloneState) as T\n }\n\n if (value && typeof value === 'object') {\n const proto = Object.getPrototypeOf(value)\n\n if (proto !== Object.prototype && proto !== null) {\n return value\n }\n\n const copy: Record<string, unknown> = {}\n const keys = Object.keys(value)\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n copy[key] = cloneState((value as Record<string, unknown>)[key])\n }\n\n return copy as T\n }\n\n return value\n}\n\n/**\n * Creates a table state updater for a single state slice.\n *\n * The updater writes through the table base atom for the slice and supports both value and functional updater forms.\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 const externalAtom = (instance.options as any).atoms?.[key]\n const targetAtom = externalAtom ?? (instance.baseAtoms as any)[key]\n targetAtom.set((old: any) => functionalUpdate(updater, old))\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\n/**\n * Returns whether a value is a function.\n */\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\n/**\n * Flattens a tree of nodes by recursively reading child nodes.\n *\n * The original nodes are preserved in depth-first order.\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\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\n/**\n * Creates a dependency-tracked memoized function for table internals.\n *\n * The memo recomputes only when its dependency tuple changes and can emit debug timing information.\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 let depsChanged = !newDeps || newDeps.length !== deps?.length\n if (!depsChanged && newDeps) {\n for (let i = 0; i < newDeps.length; i++) {\n if (newDeps[i] !== deps![i]) {\n depsChanged = true\n break\n }\n }\n }\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 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\n/**\n * Creates a table-aware memoized function.\n *\n * This wraps `memo` with table debug options and feature metadata so row models and derived APIs can share consistent diagnostics.\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 onAfterUpdateHandler = () => {\n if (!onAfterUpdate) {\n return\n }\n\n const { schedule, untrack } = table._reactivity\n schedule(() => untrack(() => onAfterUpdate()))\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 onAfterUpdateHandler()\n },\n }\n : {\n onAfterUpdate: () => {\n onAfterUpdateHandler()\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: (depArgs) => memoDeps(self, depArgs),\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}\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"],"mappings":";;;;;;;AAUA,SAAgB,iBAAoB,SAAqB,OAAa;CACpE,OAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;;;;;;AAOA,SAAgB,WAAc,OAAa;CACzC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,UAAU;CAG7B,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,QAAQ,OAAO,eAAe,KAAK;EAEzC,IAAI,UAAU,OAAO,aAAa,UAAU,MAC1C,OAAO;EAGT,MAAM,OAAgC,CAAC;EACvC,MAAM,OAAO,OAAO,KAAK,KAAK;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GACjB,KAAK,OAAO,WAAY,MAAkC,IAAI;EAChE;EAEA,OAAO;CACT;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,iBAGd,KAAQ,UAAiC;CACzC,QAAQ,YAAiE;;EAGvE,YAFsB,SAAS,QAAgB,uDAAQ,SACnB,SAAS,UAAkB,KACrD,CAAC,KAAK,QAAa,iBAAiB,SAAS,GAAG,CAAC;CAC7D;AACF;;;;AAOA,SAAgB,WAAkC,GAAgB;CAChE,OAAO,aAAa;AACtB;;;;;;AAOA,SAAgB,UACd,KACA,aACA;CACA,MAAM,OAAqB,CAAC;CAE5B,MAAM,WAAW,WAAyB;EACxC,OAAO,SAAS,SAAS;GACvB,KAAK,KAAK,IAAI;GACd,MAAM,WAAW,YAAY,IAAI;GACjC,IAAI,SAAS,QACX,QAAQ,QAAQ;EAEpB,CAAC;CACH;CAEA,QAAQ,GAAG;CAEX,OAAO;AACT;;;;;;AAgBA,MAAa,QAA6D,E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;AAeA,SAAgB,oBACd,cACA,UAAqB,KACrB;CACA,MAAM,CAAC,YAAY,SAAS,aAAa,MAAM,OAAO;CAEtD,OAAO;EAAE;EAAO,WADE,WAAW,GAAG;EACR;CAAW;AAKrC;;;;;AAMA,SAAgB,gBAMd,SACA,OACA,MACM;CACN,KAAK,MAAM,CAAC,cAAc,EAAE,IAAI,eAAe,OAAO,QAAQ,IAAI,GAAG;EACnE,MAAM,EAAE,OAAO,WAAW,oBAAoB,YAAY;EAEzD,AAAC,MAA8B,SAAS,WACrC,UAAU;GACR;GACA;GACA;GACA;GACA;EACF,CAAC,IACD;CACN;AACF;;;;;;;;AAmBA,SAAgB,oBAMd,SACA,WACA,OACA,MACM;CACN,KAAK,MAAM,CAAC,cAAc,EAAE,IAAI,eAAe,OAAO,QAAQ,IAAI,GAAG;EACnE,MAAM,EAAE,OAAO,WAAW,oBAAoB,YAAY;EAE1D,IAAI,UAAU;GAGZ,MAAM,UAAU,SAAS;GAEzB,UAAU,SAAS,SAAqB,GAAG,MAAkB;IAE3D,IAAI,CAAC,KAAK,UAAU;KAClB,MAAM,OAAO;KACb,KAAK,WAAW,UAAU;MACxB,WAAW,YAAY,SAAS,MAAM,OAAO;MAC7C,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI;MACjC;MACA,UAAU,KAAK;MACf;MACA;KACF,CAAC;IACH;IACA,OAAO,KAAK,QAAQ,CAAC,GAAG,IAAI;GAC9B;EACF,OAEE,UAAU,SAAS,SAAqB,GAAG,MAAkB;GAC3D,OAAO,GAAG,MAAM,GAAG,IAAI;EACzB;CAEJ;AACF;;;;AAKA,SAAgB,mBAId,KACA,OACA,UACA,GAAG,MACoB;;CACvB,sBACG,IAAI,0EAAkC,GAAG,IAAI,MAAK,SAAS,KAAK,GAAG,IAAI;AAE5E"}
|
|
1
|
+
{"version":3,"file":"utils.cjs","names":[],"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\n/**\n * Applies a TanStack updater to a value.\n *\n * If the updater is a function it is called with the previous value; otherwise the updater value is returned directly.\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\n/**\n * Clones table state values while preserving non-plain objects.\n *\n * Plain objects and arrays are copied recursively so state updates can avoid mutating existing references.\n */\nexport function cloneState<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map(cloneState) as T\n }\n\n if (value && typeof value === 'object') {\n const proto = Object.getPrototypeOf(value)\n\n if (proto !== Object.prototype && proto !== null) {\n return value\n }\n\n const copy: Record<string, unknown> = {}\n const keys = Object.keys(value)\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n copy[key] = cloneState((value as Record<string, unknown>)[key])\n }\n\n return copy as T\n }\n\n return value\n}\n\n/**\n * Creates a table state updater for a single state slice.\n *\n * The updater writes through the table base atom for the slice and supports both value and functional updater forms.\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 const externalAtom = (instance.options as any).atoms?.[key]\n const targetAtom = externalAtom ?? (instance.baseAtoms as any)[key]\n targetAtom.set((old: any) => functionalUpdate(updater, old))\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\n/**\n * Returns whether a value is a function.\n */\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\n/**\n * Flattens a tree of nodes by recursively reading child nodes.\n *\n * The original nodes are preserved in depth-first order.\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\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\n/**\n * Creates a dependency-tracked memoized function for table internals.\n *\n * The memo recomputes only when its dependency tuple changes and can emit debug timing information.\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 let depsChanged = !newDeps || newDeps.length !== deps?.length\n if (!depsChanged && newDeps) {\n for (let i = 0; i < newDeps.length; i++) {\n if (newDeps[i] !== deps![i]) {\n depsChanged = true\n break\n }\n }\n }\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 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\n/**\n * Creates a table-aware memoized function.\n *\n * This wraps `memo` with table debug options and feature metadata so row models and derived APIs can share consistent diagnostics.\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 onAfterUpdateHandler = () => {\n if (!onAfterUpdate) {\n return\n }\n\n const { schedule, untrack } = table._reactivity\n schedule(() => untrack(() => onAfterUpdate()))\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 onAfterUpdateHandler()\n },\n }\n : {\n onAfterUpdate: () => {\n onAfterUpdateHandler()\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: (depArgs) => memoDeps(self, depArgs),\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}\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 TArgs extends Array<any>,\n TReturn,\n>(\n obj: TObject,\n fnKey: string,\n staticFn: (obj: TObject, ...args: TArgs) => TReturn,\n ...args: TArgs\n): TReturn {\n return (\n (obj[fnKey] as Function | undefined)?.(...args) ?? staticFn(obj, ...args)\n )\n}\n"],"mappings":";;;;;;;AAUA,SAAgB,iBAAoB,SAAqB,OAAa;CACpE,OAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;;;;;;AAOA,SAAgB,WAAc,OAAa;CACzC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,UAAU;CAG7B,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,QAAQ,OAAO,eAAe,KAAK;EAEzC,IAAI,UAAU,OAAO,aAAa,UAAU,MAC1C,OAAO;EAGT,MAAM,OAAgC,CAAC;EACvC,MAAM,OAAO,OAAO,KAAK,KAAK;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GACjB,KAAK,OAAO,WAAY,MAAkC,IAAI;EAChE;EAEA,OAAO;CACT;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,iBAGd,KAAQ,UAAiC;CACzC,QAAQ,YAAiE;;EAGvE,YAFsB,SAAS,QAAgB,uDAAQ,SACnB,SAAS,UAAkB,KACrD,CAAC,KAAK,QAAa,iBAAiB,SAAS,GAAG,CAAC;CAC7D;AACF;;;;AAOA,SAAgB,WAAkC,GAAgB;CAChE,OAAO,aAAa;AACtB;;;;;;AAOA,SAAgB,UACd,KACA,aACA;CACA,MAAM,OAAqB,CAAC;CAE5B,MAAM,WAAW,WAAyB;EACxC,OAAO,SAAS,SAAS;GACvB,KAAK,KAAK,IAAI;GACd,MAAM,WAAW,YAAY,IAAI;GACjC,IAAI,SAA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/utils.d.cts
CHANGED
|
@@ -108,7 +108,7 @@ declare function assignPrototypeAPIs<TFeatures extends TableFeatures, TData exte
|
|
|
108
108
|
/**
|
|
109
109
|
* Looks to run the memoized function with the builder pattern on the object if it exists, otherwise fallback to the static method passed in.
|
|
110
110
|
*/
|
|
111
|
-
declare function callMemoOrStaticFn<TObject extends Record<string, any>,
|
|
111
|
+
declare function callMemoOrStaticFn<TObject extends Record<string, any>, TArgs extends Array<any>, TReturn>(obj: TObject, fnKey: string, staticFn: (obj: TObject, ...args: TArgs) => TReturn, ...args: TArgs): TReturn;
|
|
112
112
|
//#endregion
|
|
113
113
|
export { API, APIObject, PrototypeAPI, PrototypeAPIObject, assignPrototypeAPIs, assignTableAPIs, callMemoOrStaticFn, cloneState, flattenBy, functionalUpdate, getFunctionNameInfo, isFunction, makeStateUpdater, memo, tableMemo };
|
|
114
114
|
//# sourceMappingURL=utils.d.cts.map
|
package/dist/utils.d.ts
CHANGED
|
@@ -108,7 +108,7 @@ declare function assignPrototypeAPIs<TFeatures extends TableFeatures, TData exte
|
|
|
108
108
|
/**
|
|
109
109
|
* Looks to run the memoized function with the builder pattern on the object if it exists, otherwise fallback to the static method passed in.
|
|
110
110
|
*/
|
|
111
|
-
declare function callMemoOrStaticFn<TObject extends Record<string, any>,
|
|
111
|
+
declare function callMemoOrStaticFn<TObject extends Record<string, any>, TArgs extends Array<any>, TReturn>(obj: TObject, fnKey: string, staticFn: (obj: TObject, ...args: TArgs) => TReturn, ...args: TArgs): TReturn;
|
|
112
112
|
//#endregion
|
|
113
113
|
export { API, APIObject, PrototypeAPI, PrototypeAPIObject, assignPrototypeAPIs, assignTableAPIs, callMemoOrStaticFn, cloneState, flattenBy, functionalUpdate, getFunctionNameInfo, isFunction, makeStateUpdater, memo, tableMemo };
|
|
114
114
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"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\n/**\n * Applies a TanStack updater to a value.\n *\n * If the updater is a function it is called with the previous value; otherwise the updater value is returned directly.\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\n/**\n * Clones table state values while preserving non-plain objects.\n *\n * Plain objects and arrays are copied recursively so state updates can avoid mutating existing references.\n */\nexport function cloneState<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map(cloneState) as T\n }\n\n if (value && typeof value === 'object') {\n const proto = Object.getPrototypeOf(value)\n\n if (proto !== Object.prototype && proto !== null) {\n return value\n }\n\n const copy: Record<string, unknown> = {}\n const keys = Object.keys(value)\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n copy[key] = cloneState((value as Record<string, unknown>)[key])\n }\n\n return copy as T\n }\n\n return value\n}\n\n/**\n * Creates a table state updater for a single state slice.\n *\n * The updater writes through the table base atom for the slice and supports both value and functional updater forms.\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 const externalAtom = (instance.options as any).atoms?.[key]\n const targetAtom = externalAtom ?? (instance.baseAtoms as any)[key]\n targetAtom.set((old: any) => functionalUpdate(updater, old))\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\n/**\n * Returns whether a value is a function.\n */\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\n/**\n * Flattens a tree of nodes by recursively reading child nodes.\n *\n * The original nodes are preserved in depth-first order.\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\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\n/**\n * Creates a dependency-tracked memoized function for table internals.\n *\n * The memo recomputes only when its dependency tuple changes and can emit debug timing information.\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 let depsChanged = !newDeps || newDeps.length !== deps?.length\n if (!depsChanged && newDeps) {\n for (let i = 0; i < newDeps.length; i++) {\n if (newDeps[i] !== deps![i]) {\n depsChanged = true\n break\n }\n }\n }\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 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\n/**\n * Creates a table-aware memoized function.\n *\n * This wraps `memo` with table debug options and feature metadata so row models and derived APIs can share consistent diagnostics.\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 onAfterUpdateHandler = () => {\n if (!onAfterUpdate) {\n return\n }\n\n const { schedule, untrack } = table._reactivity\n schedule(() => untrack(() => onAfterUpdate()))\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 onAfterUpdateHandler()\n },\n }\n : {\n onAfterUpdate: () => {\n onAfterUpdateHandler()\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: (depArgs) => memoDeps(self, depArgs),\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}\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"],"mappings":";;;;;;AAUA,SAAgB,iBAAoB,SAAqB,OAAa;CACpE,OAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;;;;;;AAOA,SAAgB,WAAc,OAAa;CACzC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,UAAU;CAG7B,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,QAAQ,OAAO,eAAe,KAAK;EAEzC,IAAI,UAAU,OAAO,aAAa,UAAU,MAC1C,OAAO;EAGT,MAAM,OAAgC,CAAC;EACvC,MAAM,OAAO,OAAO,KAAK,KAAK;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GACjB,KAAK,OAAO,WAAY,MAAkC,IAAI;EAChE;EAEA,OAAO;CACT;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,iBAGd,KAAQ,UAAiC;CACzC,QAAQ,YAAiE;;EAGvE,YAFsB,SAAS,QAAgB,uDAAQ,SACnB,SAAS,UAAkB,KACrD,CAAC,KAAK,QAAa,iBAAiB,SAAS,GAAG,CAAC;CAC7D;AACF;;;;AAOA,SAAgB,WAAkC,GAAgB;CAChE,OAAO,aAAa;AACtB;;;;;;AAOA,SAAgB,UACd,KACA,aACA;CACA,MAAM,OAAqB,CAAC;CAE5B,MAAM,WAAW,WAAyB;EACxC,OAAO,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B,sBACG,IAAI,0EAAkC,GAAG,IAAI,MAAK,SAAS,KAAK,GAAG,IAAI;AAE5E"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"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\n/**\n * Applies a TanStack updater to a value.\n *\n * If the updater is a function it is called with the previous value; otherwise the updater value is returned directly.\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\n/**\n * Clones table state values while preserving non-plain objects.\n *\n * Plain objects and arrays are copied recursively so state updates can avoid mutating existing references.\n */\nexport function cloneState<T>(value: T): T {\n if (Array.isArray(value)) {\n return value.map(cloneState) as T\n }\n\n if (value && typeof value === 'object') {\n const proto = Object.getPrototypeOf(value)\n\n if (proto !== Object.prototype && proto !== null) {\n return value\n }\n\n const copy: Record<string, unknown> = {}\n const keys = Object.keys(value)\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i]!\n copy[key] = cloneState((value as Record<string, unknown>)[key])\n }\n\n return copy as T\n }\n\n return value\n}\n\n/**\n * Creates a table state updater for a single state slice.\n *\n * The updater writes through the table base atom for the slice and supports both value and functional updater forms.\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 const externalAtom = (instance.options as any).atoms?.[key]\n const targetAtom = externalAtom ?? (instance.baseAtoms as any)[key]\n targetAtom.set((old: any) => functionalUpdate(updater, old))\n }\n}\n\ntype AnyFunction = (...args: any) => any\n\n/**\n * Returns whether a value is a function.\n */\nexport function isFunction<T extends AnyFunction>(d: any): d is T {\n return d instanceof Function\n}\n\n/**\n * Flattens a tree of nodes by recursively reading child nodes.\n *\n * The original nodes are preserved in depth-first order.\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\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\n/**\n * Creates a dependency-tracked memoized function for table internals.\n *\n * The memo recomputes only when its dependency tuple changes and can emit debug timing information.\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 let depsChanged = !newDeps || newDeps.length !== deps?.length\n if (!depsChanged && newDeps) {\n for (let i = 0; i < newDeps.length; i++) {\n if (newDeps[i] !== deps![i]) {\n depsChanged = true\n break\n }\n }\n }\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 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\n/**\n * Creates a table-aware memoized function.\n *\n * This wraps `memo` with table debug options and feature metadata so row models and derived APIs can share consistent diagnostics.\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 onAfterUpdateHandler = () => {\n if (!onAfterUpdate) {\n return\n }\n\n const { schedule, untrack } = table._reactivity\n schedule(() => untrack(() => onAfterUpdate()))\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 onAfterUpdateHandler()\n },\n }\n : {\n onAfterUpdate: () => {\n onAfterUpdateHandler()\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: (depArgs) => memoDeps(self, depArgs),\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}\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 TArgs extends Array<any>,\n TReturn,\n>(\n obj: TObject,\n fnKey: string,\n staticFn: (obj: TObject, ...args: TArgs) => TReturn,\n ...args: TArgs\n): TReturn {\n return (\n (obj[fnKey] as Function | undefined)?.(...args) ?? staticFn(obj, ...args)\n )\n}\n"],"mappings":";;;;;;AAUA,SAAgB,iBAAoB,SAAqB,OAAa;CACpE,OAAO,OAAO,YAAY,aACrB,QAAwB,KAAK,IAC9B;AACN;;;;;;AAOA,SAAgB,WAAc,OAAa;CACzC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,UAAU;CAG7B,IAAI,SAAS,OAAO,UAAU,UAAU;EACtC,MAAM,QAAQ,OAAO,eAAe,KAAK;EAEzC,IAAI,UAAU,OAAO,aAAa,UAAU,MAC1C,OAAO;EAGT,MAAM,OAAgC,CAAC;EACvC,MAAM,OAAO,OAAO,KAAK,KAAK;EAE9B,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;GACpC,MAAM,MAAM,KAAK;GACjB,KAAK,OAAO,WAAY,MAAkC,IAAI;EAChE;EAEA,OAAO;CACT;CAEA,OAAO;AACT;;;;;;AAOA,SAAgB,iBAGd,KAAQ,UAAiC;CACzC,QAAQ,YAAiE;;EAGvE,YAFsB,SAAS,QAAgB,uDAAQ,SACnB,SAAS,UAAkB,KACrD,CAAC,KAAK,QAAa,iBAAiB,SAAS,GAAG,CAAC;CAC7D;AACF;;;;AAOA,SAAgB,WAAkC,GAAgB;CAChE,OAAO,aAAa;AAC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