@tanstack/table-core 9.0.0-beta.55 → 9.0.0-beta.58

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.
Files changed (95) hide show
  1. package/dist/core/cells/constructCell.d.ts +2 -2
  2. package/dist/core/cells/constructCell.js +2 -0
  3. package/dist/core/cells/coreCellsFeature.types.d.ts +2 -2
  4. package/dist/core/cells/coreCellsFeature.utils.d.ts +2 -2
  5. package/dist/core/columns/constructColumn.js +2 -2
  6. package/dist/core/headers/buildHeaderGroups.js +2 -0
  7. package/dist/core/headers/constructHeader.js +2 -0
  8. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +4 -4
  9. package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
  10. package/dist/core/row-models/createCoreRowModel.d.ts +1 -1
  11. package/dist/core/row-models/createCoreRowModel.js +5 -1
  12. package/dist/core/rows/constructRow.d.ts +1 -1
  13. package/dist/core/rows/constructRow.js +2 -2
  14. package/dist/core/rows/coreRowsFeature.types.d.ts +2 -2
  15. package/dist/core/rows/coreRowsFeature.utils.d.ts +4 -4
  16. package/dist/core/rows/coreRowsFeature.utils.js +4 -3
  17. package/dist/core/table/constructTable.js +19 -1
  18. package/dist/core/table/coreTablesFeature.types.d.ts +21 -1
  19. package/dist/features/cell-selection/cellSelectionFeature.d.ts +9 -0
  20. package/dist/features/cell-selection/cellSelectionFeature.js +117 -0
  21. package/dist/features/cell-selection/cellSelectionFeature.types.d.ts +273 -0
  22. package/dist/features/cell-selection/cellSelectionFeature.utils.d.ts +288 -0
  23. package/dist/features/cell-selection/cellSelectionFeature.utils.js +732 -0
  24. package/dist/features/column-faceting/columnFacetingFeature.utils.d.ts +1 -1
  25. package/dist/features/column-faceting/createFacetedRowModel.d.ts +1 -1
  26. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +1 -1
  27. package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +1 -1
  28. package/dist/features/column-filtering/columnFilteringFeature.utils.js +9 -2
  29. package/dist/features/column-filtering/createFilteredRowModel.d.ts +1 -1
  30. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +3 -3
  31. package/dist/features/column-grouping/createGroupedRowModel.d.ts +1 -1
  32. package/dist/features/column-pinning/columnPinningFeature.types.d.ts +1 -1
  33. package/dist/features/column-pinning/columnPinningFeature.utils.d.ts +3 -3
  34. package/dist/features/column-resizing/columnResizingFeature.utils.js +0 -1
  35. package/dist/features/column-sizing/columnSizingFeature.utils.d.ts +1 -1
  36. package/dist/features/column-visibility/columnVisibilityFeature.types.d.ts +1 -1
  37. package/dist/features/column-visibility/columnVisibilityFeature.utils.d.ts +3 -3
  38. package/dist/features/global-filtering/globalFilteringFeature.types.d.ts +1 -1
  39. package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +1 -1
  40. package/dist/features/row-aggregation/rowAggregationFeature.types.d.ts +9 -9
  41. package/dist/features/row-aggregation/rowAggregationFeature.utils.d.ts +2 -2
  42. package/dist/features/row-expanding/createExpandedRowModel.d.ts +1 -1
  43. package/dist/features/row-expanding/createExpandedRowModel.js +3 -2
  44. package/dist/features/row-expanding/rowExpandingFeature.utils.d.ts +2 -5
  45. package/dist/features/row-expanding/rowExpandingFeature.utils.js +1 -5
  46. package/dist/features/row-pagination/createPaginatedRowModel.d.ts +1 -1
  47. package/dist/features/row-pinning/rowPinningFeature.utils.d.ts +1 -1
  48. package/dist/features/row-selection/rowSelectionFeature.utils.d.ts +2 -3
  49. package/dist/features/row-selection/rowSelectionFeature.utils.js +1 -3
  50. package/dist/features/row-sorting/createSortedRowModel.d.ts +1 -1
  51. package/dist/features/row-sorting/rowSortingFeature.utils.d.ts +2 -3
  52. package/dist/features/row-sorting/rowSortingFeature.utils.js +2 -4
  53. package/dist/features/stockFeatures.d.ts +3 -1
  54. package/dist/features/stockFeatures.js +3 -1
  55. package/dist/index.d.ts +24 -22
  56. package/dist/index.js +2 -1
  57. package/dist/static-functions.d.ts +2 -1
  58. package/dist/static-functions.js +2 -1
  59. package/dist/types/Cell.d.ts +5 -3
  60. package/dist/types/Column.d.ts +9 -9
  61. package/dist/types/ColumnDef.d.ts +14 -12
  62. package/dist/types/Header.d.ts +1 -1
  63. package/dist/types/Row.d.ts +5 -5
  64. package/dist/types/RowModel.d.ts +4 -4
  65. package/dist/types/RowModelFns.d.ts +3 -3
  66. package/dist/types/Table.d.ts +15 -13
  67. package/dist/types/TableFeatures.d.ts +40 -5
  68. package/dist/types/TableOptions.d.ts +17 -15
  69. package/dist/types/TableState.d.ts +11 -9
  70. package/dist/types/type-utils.d.ts +1 -1
  71. package/dist/worker/createWorkerRowModel.d.ts +1 -1
  72. package/package.json +1 -1
  73. package/skills/aggregation/SKILL.md +2 -2
  74. package/skills/api-not-found/SKILL.md +1 -1
  75. package/skills/cell-selection/SKILL.md +180 -0
  76. package/skills/client-vs-server/SKILL.md +1 -1
  77. package/skills/column-faceting/SKILL.md +1 -1
  78. package/skills/column-filtering/SKILL.md +1 -1
  79. package/skills/column-ordering/SKILL.md +1 -1
  80. package/skills/column-pinning/SKILL.md +1 -1
  81. package/skills/column-resizing/SKILL.md +1 -1
  82. package/skills/column-sizing/SKILL.md +1 -1
  83. package/skills/column-visibility/SKILL.md +1 -1
  84. package/skills/core/SKILL.md +1 -1
  85. package/skills/custom-features/SKILL.md +1 -1
  86. package/skills/expanding/SKILL.md +1 -1
  87. package/skills/global-filtering/SKILL.md +1 -1
  88. package/skills/grouping/SKILL.md +1 -1
  89. package/skills/migrate-v8-to-v9/SKILL.md +1 -1
  90. package/skills/pagination/SKILL.md +1 -1
  91. package/skills/row-pinning/SKILL.md +1 -1
  92. package/skills/row-selection/SKILL.md +1 -1
  93. package/skills/sorting/SKILL.md +1 -1
  94. package/skills/table-features/SKILL.md +1 -1
  95. package/skills/typescript/SKILL.md +1 -1
@@ -1,8 +1,8 @@
1
1
  import { CellData, RowData } from "../../types/type-utils.js";
2
- import { Cell } from "../../types/Cell.js";
3
- import { Row } from "../../types/Row.js";
4
2
  import { Table } from "../../types/Table.js";
5
3
  import { Column } from "../../types/Column.js";
4
+ import { Row } from "../../types/Row.js";
5
+ import { Cell } from "../../types/Cell.js";
6
6
  import { TableFeatures } from "../../types/TableFeatures.js";
7
7
 
8
8
  //#region src/core/cells/constructCell.d.ts
@@ -22,6 +22,8 @@ function constructCell(column, row, table) {
22
22
  cell.column = column;
23
23
  cell.id = `${row.id}_${column.id}`;
24
24
  cell.row = row;
25
+ const initFns = table._cellInstanceInitFns;
26
+ for (let i = 0; i < initFns.length; i++) initFns[i](cell);
25
27
  return cell;
26
28
  }
27
29
 
@@ -1,8 +1,8 @@
1
1
  import { CellData, Getter, RowData } from "../../types/type-utils.js";
2
- import { Cell } from "../../types/Cell.js";
3
- import { Row } from "../../types/Row.js";
4
2
  import { Table } from "../../types/Table.js";
5
3
  import { Column } from "../../types/Column.js";
4
+ import { Row } from "../../types/Row.js";
5
+ import { Cell } from "../../types/Cell.js";
6
6
  import { TableFeatures } from "../../types/TableFeatures.js";
7
7
 
8
8
  //#region src/core/cells/coreCellsFeature.types.d.ts
@@ -1,8 +1,8 @@
1
1
  import { CellData, NoInfer, RowData } from "../../types/type-utils.js";
2
- import { Cell } from "../../types/Cell.js";
3
- import { Row } from "../../types/Row.js";
4
2
  import { Table } from "../../types/Table.js";
5
3
  import { Column } from "../../types/Column.js";
4
+ import { Row } from "../../types/Row.js";
5
+ import { Cell } from "../../types/Cell.js";
6
6
  import { TableFeatures } from "../../types/TableFeatures.js";
7
7
  //#region src/core/cells/coreCellsFeature.utils.d.ts
8
8
  /**
@@ -50,8 +50,8 @@ function constructColumn(table, columnDef, depth, parent) {
50
50
  column.depth = depth;
51
51
  column.id = `${String(id)}`;
52
52
  column.parent = parent;
53
- const features = Object.values(table._features);
54
- for (let i = 0; i < features.length; i++) features[i].initColumnInstanceData?.(column);
53
+ const initFns = table._columnInstanceInitFns;
54
+ for (let i = 0; i < initFns.length; i++) initFns[i](column);
55
55
  return column;
56
56
  }
57
57
 
@@ -21,6 +21,7 @@ function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
21
21
  };
22
22
  findMaxDepth(allColumns);
23
23
  const headerGroups = [];
24
+ const headerGroupInitFns = table._headerGroupInstanceInitFns;
24
25
  const constructHeaderGroup = (headersToGroup, depth) => {
25
26
  const headerGroup = {
26
27
  depth,
@@ -58,6 +59,7 @@ function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
58
59
  headerGroup.headers.push(headerToGroup);
59
60
  headerToGroup.headerGroup = headerGroup;
60
61
  });
62
+ for (let i = 0; i < headerGroupInitFns.length; i++) headerGroupInitFns[i](headerGroup);
61
63
  headerGroups.push(headerGroup);
62
64
  if (depth > 0) constructHeaderGroup(pendingParentHeaders, depth - 1);
63
65
  };
@@ -29,6 +29,8 @@ function constructHeader(table, column, options) {
29
29
  header.placeholderId = options.placeholderId;
30
30
  header.rowSpan = 0;
31
31
  header.subHeaders = [];
32
+ const initFns = table._headerInstanceInitFns;
33
+ for (let i = 0; i < initFns.length; i++) initFns[i](header);
32
34
  return header;
33
35
  }
34
36
 
@@ -1,11 +1,11 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { Table_RowModels_Grouped } from "../../features/column-grouping/columnGroupingFeature.types.js";
3
- import { Table_RowModels_Sorted } from "../../features/row-sorting/rowSortingFeature.types.js";
2
+ import { Table_RowModels_Faceted } from "../../features/column-faceting/columnFacetingFeature.types.js";
4
3
  import { Table_RowModels_Expanded } from "../../features/row-expanding/rowExpandingFeature.types.js";
4
+ import { Table_RowModels_Paginated } from "../../features/row-pagination/rowPaginationFeature.types.js";
5
+ import { Table_RowModels_Sorted } from "../../features/row-sorting/rowSortingFeature.types.js";
5
6
  import { Row } from "../../types/Row.js";
6
7
  import { Table_RowModels_Filtered } from "../../features/column-filtering/columnFilteringFeature.types.js";
7
- import { Table_RowModels_Paginated } from "../../features/row-pagination/rowPaginationFeature.types.js";
8
- import { Table_RowModels_Faceted } from "../../features/column-faceting/columnFacetingFeature.types.js";
8
+ import { Table_RowModels_Grouped } from "../../features/column-grouping/columnGroupingFeature.types.js";
9
9
  import { TableFeatures } from "../../types/TableFeatures.js";
10
10
 
11
11
  //#region src/core/row-models/coreRowModelsFeature.types.d.ts
@@ -1,6 +1,6 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { RowModel } from "./coreRowModelsFeature.types.js";
3
2
  import { Table } from "../../types/Table.js";
3
+ import { RowModel } from "./coreRowModelsFeature.types.js";
4
4
  import { TableFeatures } from "../../types/TableFeatures.js";
5
5
 
6
6
  //#region src/core/row-models/coreRowModelsFeature.utils.d.ts
@@ -1,6 +1,6 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { RowModel } from "./coreRowModelsFeature.types.js";
3
2
  import { Table } from "../../types/Table.js";
3
+ import { RowModel } from "./coreRowModelsFeature.types.js";
4
4
  import { TableFeatures } from "../../types/TableFeatures.js";
5
5
 
6
6
  //#region src/core/row-models/createCoreRowModel.d.ts
@@ -1,5 +1,6 @@
1
1
  import { makeObjectMap, tableMemo } from "../../utils.js";
2
2
  import { constructRow } from "../rows/constructRow.js";
3
+ import { table_autoResetCellSelection } from "../../features/cell-selection/cellSelectionFeature.utils.js";
3
4
  import { table_autoResetPageIndex } from "../../features/row-pagination/rowPaginationFeature.utils.js";
4
5
 
5
6
  //#region src/core/row-models/createCoreRowModel.ts
@@ -16,7 +17,10 @@ function createCoreRowModel() {
16
17
  fnName: "table.getCoreRowModel",
17
18
  memoDeps: () => [table.options.data],
18
19
  fn: () => _createCoreRowModel(table, table.options.data),
19
- onAfterUpdate: () => table_autoResetPageIndex(table)
20
+ onAfterUpdate: () => {
21
+ table_autoResetPageIndex(table);
22
+ table_autoResetCellSelection(table);
23
+ }
20
24
  });
21
25
  };
22
26
  }
@@ -1,6 +1,6 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { Row } from "../../types/Row.js";
3
2
  import { Table } from "../../types/Table.js";
3
+ import { Row } from "../../types/Row.js";
4
4
  import { TableFeatures } from "../../types/TableFeatures.js";
5
5
 
6
6
  //#region src/core/rows/constructRow.d.ts
@@ -30,8 +30,8 @@ const constructRow = (table, id, original, rowIndex, depth, subRows, parentId) =
30
30
  row.original = original;
31
31
  row.parentId = parentId;
32
32
  row.subRows = subRows ?? [];
33
- const features = Object.values(table._features);
34
- for (let i = 0; i < features.length; i++) features[i].initRowInstanceData?.(row);
33
+ const initFns = table._rowInstanceInitFns;
34
+ for (let i = 0; i < initFns.length; i++) initFns[i](row);
35
35
  return row;
36
36
  };
37
37
 
@@ -1,8 +1,8 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { Cell } from "../../types/Cell.js";
3
- import { Row } from "../../types/Row.js";
4
2
  import { Table } from "../../types/Table.js";
5
3
  import { Column } from "../../types/Column.js";
4
+ import { Row } from "../../types/Row.js";
5
+ import { Cell } from "../../types/Cell.js";
6
6
  import { TableFeatures } from "../../types/TableFeatures.js";
7
7
 
8
8
  //#region src/core/rows/coreRowsFeature.types.d.ts
@@ -1,7 +1,7 @@
1
1
  import { RowData } from "../../types/type-utils.js";
2
- import { Cell } from "../../types/Cell.js";
3
- import { Row } from "../../types/Row.js";
4
2
  import { Table } from "../../types/Table.js";
3
+ import { Row } from "../../types/Row.js";
4
+ import { Cell } from "../../types/Cell.js";
5
5
  import { TableFeatures } from "../../types/TableFeatures.js";
6
6
 
7
7
  //#region src/core/rows/coreRowsFeature.utils.d.ts
@@ -74,8 +74,8 @@ declare function table_getMaxSubRowDepth<TFeatures extends TableFeatures, TData
74
74
  /**
75
75
  * Looks up this row's direct parent, if it has one.
76
76
  *
77
- * Parent lookup searches the pre-pagination row model so parent relationships
78
- * are available even when the parent is not on the current page.
77
+ * Parent lookup prefers the core row model for structural parents, then falls
78
+ * back to the pre-pagination row model for generated parent rows.
79
79
  *
80
80
  * @example
81
81
  * ```ts
@@ -114,8 +114,8 @@ function table_getMaxSubRowDepth(table) {
114
114
  /**
115
115
  * Looks up this row's direct parent, if it has one.
116
116
  *
117
- * Parent lookup searches the pre-pagination row model so parent relationships
118
- * are available even when the parent is not on the current page.
117
+ * Parent lookup prefers the core row model for structural parents, then falls
118
+ * back to the pre-pagination row model for generated parent rows.
119
119
  *
120
120
  * @example
121
121
  * ```ts
@@ -123,7 +123,8 @@ function table_getMaxSubRowDepth(table) {
123
123
  * ```
124
124
  */
125
125
  function row_getParentRow(row) {
126
- return row.parentId ? row.table.getRow(row.parentId, true) : void 0;
126
+ if (!row.parentId) return;
127
+ return row.table.getCoreRowModel().rowsById[row.parentId] ?? row.table.getRow(row.parentId, true);
127
128
  }
128
129
  /**
129
130
  * Collects this row's ancestor chain from root to direct parent.
@@ -95,7 +95,25 @@ function constructTable(tableOptions) {
95
95
  }
96
96
  return snapshot;
97
97
  }, { debugName: "table/store" }));
98
- for (let i = 0; i < featuresList.length; i++) featuresList[i].initTableInstanceData?.(table);
98
+ const cellInstanceInitFns = [];
99
+ const columnInstanceInitFns = [];
100
+ const headerGroupInstanceInitFns = [];
101
+ const headerInstanceInitFns = [];
102
+ const rowInstanceInitFns = [];
103
+ for (let i = 0; i < featuresList.length; i++) {
104
+ const feature = featuresList[i];
105
+ if (feature.initCellInstanceData) cellInstanceInitFns.push(feature.initCellInstanceData.bind(feature));
106
+ if (feature.initColumnInstanceData) columnInstanceInitFns.push(feature.initColumnInstanceData.bind(feature));
107
+ if (feature.initHeaderGroupInstanceData) headerGroupInstanceInitFns.push(feature.initHeaderGroupInstanceData.bind(feature));
108
+ if (feature.initHeaderInstanceData) headerInstanceInitFns.push(feature.initHeaderInstanceData.bind(feature));
109
+ if (feature.initRowInstanceData) rowInstanceInitFns.push(feature.initRowInstanceData.bind(feature));
110
+ feature.initTableInstanceData?.(table);
111
+ }
112
+ table._cellInstanceInitFns = cellInstanceInitFns;
113
+ table._columnInstanceInitFns = columnInstanceInitFns;
114
+ table._headerGroupInstanceInitFns = headerGroupInstanceInitFns;
115
+ table._headerInstanceInitFns = headerInstanceInitFns;
116
+ table._rowInstanceInitFns = rowInstanceInitFns;
99
117
  if (process.env.NODE_ENV === "development" && (tableOptions.debugAll || tableOptions.debugTable)) {
100
118
  const features = Object.keys(table._features);
101
119
  const rowModels = Object.entries({
@@ -5,7 +5,7 @@ import { CachedRowModels } from "../../types/RowModel.js";
5
5
  import { RowModelFns } from "../../types/RowModelFns.js";
6
6
  import { TableState, TableState_All } from "../../types/TableState.js";
7
7
  import { TableOptions } from "../../types/TableOptions.js";
8
- import { IsAny, TableFeatures, ValidateFeatureSlots } from "../../types/TableFeatures.js";
8
+ import { IsAny, TableFeature, TableFeatures, ValidateFeatureSlots } from "../../types/TableFeatures.js";
9
9
  import { Atom, ReadonlyAtom, ReadonlyStore } from "@tanstack/store";
10
10
 
11
11
  //#region src/core/table/coreTablesFeature.types.d.ts
@@ -119,10 +119,18 @@ interface Table_CoreProperties<in out TFeatures extends TableFeatures, in out TD
119
119
  * Table reactivity bindings for interacting with TanStack Store.
120
120
  */
121
121
  readonly _reactivity: TableReactivityBindings;
122
+ /**
123
+ * Cache of the `initCellInstanceData` functions for features that define one.
124
+ */
125
+ _cellInstanceInitFns?: Array<NonNullable<TableFeature['initCellInstanceData']>>;
122
126
  /**
123
127
  * Prototype cache for Cell objects - shared by all cells in this table
124
128
  */
125
129
  _cellPrototype?: object;
130
+ /**
131
+ * Cache of the `initColumnInstanceData` functions for features that define one.
132
+ */
133
+ _columnInstanceInitFns?: Array<NonNullable<TableFeature['initColumnInstanceData']>>;
126
134
  /**
127
135
  * Prototype cache for Column objects - shared by all columns in this table
128
136
  */
@@ -131,6 +139,14 @@ interface Table_CoreProperties<in out TFeatures extends TableFeatures, in out TD
131
139
  * The features that are enabled for the table.
132
140
  */
133
141
  readonly _features: Partial<CoreFeatures> & TFeatures;
142
+ /**
143
+ * Cache of the `initHeaderGroupInstanceData` functions for features that define one.
144
+ */
145
+ _headerGroupInstanceInitFns?: Array<NonNullable<TableFeature['initHeaderGroupInstanceData']>>;
146
+ /**
147
+ * Cache of the `initHeaderInstanceData` functions for features that define one.
148
+ */
149
+ _headerInstanceInitFns?: Array<NonNullable<TableFeature['initHeaderInstanceData']>>;
134
150
  /**
135
151
  * Prototype cache for Header objects - shared by all headers in this table
136
152
  */
@@ -147,6 +163,10 @@ interface Table_CoreProperties<in out TFeatures extends TableFeatures, in out TD
147
163
  * Prototype cache for Row objects - shared by all rows in this table
148
164
  */
149
165
  _rowPrototype?: object;
166
+ /**
167
+ * Cache of the `initRowInstanceData` functions for features that define one.
168
+ */
169
+ _rowInstanceInitFns?: Array<NonNullable<TableFeature['initRowInstanceData']>>;
150
170
  /**
151
171
  * The readonly derived atoms for each `TableState` slice. Each derives from
152
172
  * its corresponding `baseAtom` plus, optionally, a per-slice external atom or
@@ -0,0 +1,9 @@
1
+ import { TableFeature } from "../../types/TableFeatures.js";
2
+
3
+ //#region src/features/cell-selection/cellSelectionFeature.d.ts
4
+ /**
5
+ * Feature that adds spreadsheet-style cell range selection state and APIs.
6
+ */
7
+ declare const cellSelectionFeature: TableFeature;
8
+ //#endregion
9
+ export { cellSelectionFeature };
@@ -0,0 +1,117 @@
1
+ import { assignPrototypeAPIs, assignTableAPIs, callMemoOrStaticFn, makeStateUpdater } from "../../utils.js";
2
+ import { cell_getCanSelect, cell_getIsFocused, cell_getIsSelected, cell_getSelectionEdges, cell_getSelectionExtendHandler, cell_getSelectionStartHandler, cell_getTabIndex, getDefaultCellSelectionState, table_autoResetCellSelection, table_extendCellSelection, table_getCellSelectionBounds, table_getCellSelectionColumnIds, table_getCellSelectionColumnIndexes, table_getCellSelectionRowIds, table_getFocusedCell, table_getSelectedCellCount, table_getSelectedCellIds, table_getSelectedCellRangesData, table_moveCellSelection, table_resetCellSelection, table_selectAllCells, table_selectCellRange, table_setCellSelection, table_setFocusedCell } from "./cellSelectionFeature.utils.js";
3
+
4
+ //#region src/features/cell-selection/cellSelectionFeature.ts
5
+ /**
6
+ * Feature that adds spreadsheet-style cell range selection state and APIs.
7
+ */
8
+ const cellSelectionFeature = {
9
+ initTableInstanceData: (table) => {
10
+ table._isSelectingCells = false;
11
+ },
12
+ resetTableInstanceData: (table) => {
13
+ table._isSelectingCells = false;
14
+ },
15
+ getInitialState: (initialState) => {
16
+ return {
17
+ cellSelection: getDefaultCellSelectionState(),
18
+ ...initialState
19
+ };
20
+ },
21
+ getDefaultTableOptions: (table) => {
22
+ return {
23
+ onCellSelectionChange: makeStateUpdater("cellSelection", table),
24
+ autoResetCellSelection: true,
25
+ enableCellSelection: true,
26
+ enableCellRangeSelection: true,
27
+ enableMultiCellRangeSelection: true,
28
+ enableCellSelectionDrag: true,
29
+ isCellRangeSelectionEvent: (event) => {
30
+ const rangeEvent = event;
31
+ return Boolean(rangeEvent.shiftKey || rangeEvent.nativeEvent?.shiftKey);
32
+ },
33
+ isMultiCellRangeSelectionEvent: (event) => {
34
+ const multiEvent = event;
35
+ return Boolean(multiEvent.ctrlKey || multiEvent.metaKey || multiEvent.nativeEvent?.ctrlKey || multiEvent.nativeEvent?.metaKey);
36
+ }
37
+ };
38
+ },
39
+ assignCellPrototype: (prototype, table) => {
40
+ assignPrototypeAPIs("cellSelectionFeature", prototype, table, {
41
+ cell_getCanSelect: { fn: (cell) => cell_getCanSelect(cell) },
42
+ cell_getIsSelected: { fn: (cell) => cell_getIsSelected(cell) },
43
+ cell_getIsFocused: { fn: (cell) => cell_getIsFocused(cell) },
44
+ cell_getTabIndex: { fn: (cell) => cell_getTabIndex(cell) },
45
+ cell_getSelectionEdges: { fn: (cell) => cell_getSelectionEdges(cell) },
46
+ cell_getSelectionStartHandler: { fn: (cell, contextDocument) => cell_getSelectionStartHandler(cell, contextDocument) },
47
+ cell_getSelectionExtendHandler: { fn: (cell) => cell_getSelectionExtendHandler(cell) }
48
+ });
49
+ },
50
+ constructTableAPIs: (table) => {
51
+ assignTableAPIs("cellSelectionFeature", table, {
52
+ table_setCellSelection: { fn: (updater) => table_setCellSelection(table, updater) },
53
+ table_resetCellSelection: { fn: (defaultState) => table_resetCellSelection(table, defaultState) },
54
+ table_autoResetCellSelection: { fn: () => table_autoResetCellSelection(table) },
55
+ table_getCellSelectionColumnIndexes: {
56
+ fn: () => table_getCellSelectionColumnIndexes(table),
57
+ memoDeps: () => [
58
+ table.atoms.columnVisibility?.get(),
59
+ table.atoms.columnOrder?.get(),
60
+ table.atoms.columnPinning?.get(),
61
+ table.atoms.grouping?.get(),
62
+ table.options.columns,
63
+ table.options.groupedColumnMode
64
+ ]
65
+ },
66
+ table_getCellSelectionBounds: {
67
+ fn: () => table_getCellSelectionBounds(table),
68
+ memoDeps: () => [
69
+ table.atoms.cellSelection?.get(),
70
+ table.getRowsInDisplayOrder(),
71
+ callMemoOrStaticFn(table, "getCellSelectionColumnIndexes", table_getCellSelectionColumnIndexes)
72
+ ]
73
+ },
74
+ table_selectCellRange: { fn: (range, opts) => table_selectCellRange(table, range, opts) },
75
+ table_selectAllCells: { fn: () => table_selectAllCells(table) },
76
+ table_setFocusedCell: { fn: (rowId, columnId) => table_setFocusedCell(table, rowId, columnId) },
77
+ table_getFocusedCell: { fn: () => table_getFocusedCell(table) },
78
+ table_moveCellSelection: { fn: (direction) => table_moveCellSelection(table, direction) },
79
+ table_extendCellSelection: { fn: (direction) => table_extendCellSelection(table, direction) },
80
+ table_getSelectedCellIds: {
81
+ fn: () => table_getSelectedCellIds(table),
82
+ memoDeps: () => [
83
+ callMemoOrStaticFn(table, "getCellSelectionBounds", table_getCellSelectionBounds),
84
+ table.getRowsInDisplayOrder(),
85
+ table.options.enableCellSelection
86
+ ]
87
+ },
88
+ table_getSelectedCellRangesData: {
89
+ fn: () => table_getSelectedCellRangesData(table),
90
+ memoDeps: () => [
91
+ callMemoOrStaticFn(table, "getCellSelectionBounds", table_getCellSelectionBounds),
92
+ table.getRowsInDisplayOrder(),
93
+ table.options.enableCellSelection
94
+ ]
95
+ },
96
+ table_getSelectedCellCount: {
97
+ fn: () => table_getSelectedCellCount(table),
98
+ memoDeps: () => [
99
+ callMemoOrStaticFn(table, "getCellSelectionBounds", table_getCellSelectionBounds),
100
+ table.getRowsInDisplayOrder(),
101
+ table.options.enableCellSelection
102
+ ]
103
+ },
104
+ table_getCellSelectionRowIds: {
105
+ fn: () => table_getCellSelectionRowIds(table),
106
+ memoDeps: () => [callMemoOrStaticFn(table, "getCellSelectionBounds", table_getCellSelectionBounds), table.getRowsInDisplayOrder()]
107
+ },
108
+ table_getCellSelectionColumnIds: {
109
+ fn: () => table_getCellSelectionColumnIds(table),
110
+ memoDeps: () => [callMemoOrStaticFn(table, "getCellSelectionBounds", table_getCellSelectionBounds)]
111
+ }
112
+ });
113
+ }
114
+ };
115
+
116
+ //#endregion
117
+ export { cellSelectionFeature };