@ackplus/react-tanstack-data-table 1.1.19 → 1.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/lib/hooks/use-data-table-engine.d.ts.map +1 -1
  2. package/dist/lib/hooks/use-data-table-engine.js +54 -15
  3. package/dist/lib/types/data-table.types.d.ts +2 -1
  4. package/dist/lib/types/data-table.types.d.ts.map +1 -1
  5. package/package.json +3 -4
  6. package/src/index.ts +0 -75
  7. package/src/lib/components/data-table-view.tsx +0 -386
  8. package/src/lib/components/droupdown/menu-dropdown.tsx +0 -103
  9. package/src/lib/components/filters/filter-value-input.tsx +0 -225
  10. package/src/lib/components/filters/index.ts +0 -126
  11. package/src/lib/components/headers/draggable-header.tsx +0 -326
  12. package/src/lib/components/headers/index.ts +0 -6
  13. package/src/lib/components/headers/table-header.tsx +0 -175
  14. package/src/lib/components/index.ts +0 -21
  15. package/src/lib/components/pagination/data-table-pagination.tsx +0 -111
  16. package/src/lib/components/pagination/index.ts +0 -5
  17. package/src/lib/components/rows/data-table-row.tsx +0 -218
  18. package/src/lib/components/rows/empty-data-row.tsx +0 -69
  19. package/src/lib/components/rows/index.ts +0 -7
  20. package/src/lib/components/rows/loading-rows.tsx +0 -164
  21. package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +0 -125
  22. package/src/lib/components/toolbar/column-filter-control.tsx +0 -432
  23. package/src/lib/components/toolbar/column-pinning-control.tsx +0 -275
  24. package/src/lib/components/toolbar/column-reset-control.tsx +0 -74
  25. package/src/lib/components/toolbar/column-visibility-control.tsx +0 -105
  26. package/src/lib/components/toolbar/data-table-toolbar.tsx +0 -257
  27. package/src/lib/components/toolbar/index.ts +0 -17
  28. package/src/lib/components/toolbar/table-export-control.tsx +0 -233
  29. package/src/lib/components/toolbar/table-refresh-control.tsx +0 -62
  30. package/src/lib/components/toolbar/table-search-control.tsx +0 -155
  31. package/src/lib/components/toolbar/table-size-control.tsx +0 -102
  32. package/src/lib/contexts/data-table-context.tsx +0 -126
  33. package/src/lib/data-table.tsx +0 -29
  34. package/src/lib/features/README.md +0 -161
  35. package/src/lib/features/column-filter.feature.ts +0 -493
  36. package/src/lib/features/index.ts +0 -23
  37. package/src/lib/features/selection.feature.ts +0 -322
  38. package/src/lib/hooks/index.ts +0 -2
  39. package/src/lib/hooks/use-data-table-engine.ts +0 -1516
  40. package/src/lib/icons/add-icon.tsx +0 -23
  41. package/src/lib/icons/csv-icon.tsx +0 -15
  42. package/src/lib/icons/delete-icon.tsx +0 -30
  43. package/src/lib/icons/excel-icon.tsx +0 -15
  44. package/src/lib/icons/index.ts +0 -7
  45. package/src/lib/icons/unpin-icon.tsx +0 -18
  46. package/src/lib/icons/view-comfortable-icon.tsx +0 -45
  47. package/src/lib/icons/view-compact-icon.tsx +0 -55
  48. package/src/lib/types/column.types.ts +0 -63
  49. package/src/lib/types/data-table-api.ts +0 -191
  50. package/src/lib/types/data-table.types.ts +0 -192
  51. package/src/lib/types/export.types.ts +0 -223
  52. package/src/lib/types/index.ts +0 -24
  53. package/src/lib/types/slots.types.ts +0 -342
  54. package/src/lib/types/table.types.ts +0 -88
  55. package/src/lib/utils/column-helpers.ts +0 -72
  56. package/src/lib/utils/debounced-fetch.utils.ts +0 -131
  57. package/src/lib/utils/export-utils.ts +0 -712
  58. package/src/lib/utils/index.ts +0 -27
  59. package/src/lib/utils/logger.ts +0 -203
  60. package/src/lib/utils/slot-helpers.tsx +0 -194
  61. package/src/lib/utils/special-columns.utils.ts +0 -101
  62. package/src/lib/utils/styling-helpers.ts +0 -126
  63. package/src/lib/utils/table-helpers.ts +0 -106
@@ -1,322 +0,0 @@
1
- /**
2
- * Custom Selection Feature for TanStack Table
3
- *
4
- * This feature adds custom selection capabilities to TanStack Table
5
- * following the official custom features pattern (same as CustomColumnFilterFeature)
6
- */
7
- import {
8
- Table,
9
- TableFeature,
10
- RowData,
11
- Updater,
12
- functionalUpdate,
13
- makeStateUpdater,
14
- Row,
15
- } from '@tanstack/react-table';
16
-
17
- // Selection state interface
18
- export interface SelectionState {
19
- ids: string[];
20
- type: 'include' | 'exclude';
21
- selectMode?: 'page' | 'all';
22
- }
23
-
24
- // Row selectability function type (like MUI DataGrid)
25
- export type IsRowSelectableFunction<T = any> = (params: { row: T; id: string }) => boolean;
26
-
27
- // Selection mode type
28
- export type SelectMode = 'page' | 'all';
29
-
30
- // Options for the custom selection feature
31
- export interface SelectionOptions {
32
- enableAdvanceSelection?: boolean;
33
- selectMode?: SelectMode;
34
- isRowSelectable?: IsRowSelectableFunction;
35
- onSelectionStateChange?: (updater: Updater<SelectionState>) => void;
36
- }
37
-
38
- // Table state interface for selection
39
- export interface SelectionTableState {
40
- selectionState: SelectionState;
41
- }
42
-
43
- // Declaration merging to extend TanStack Table types
44
- declare module '@tanstack/react-table' {
45
- interface TableState extends SelectionTableState { }
46
- interface TableOptionsResolved<TData extends RowData>
47
- extends SelectionOptions { }
48
- interface Table<TData extends RowData> extends SelectionInstance<TData> { }
49
- }
50
-
51
- // Table instance methods for custom selection
52
- export interface SelectionInstance<TData extends RowData> {
53
- // Basic selection methods
54
- setSelectionState: (updater: Updater<SelectionState>) => void;
55
- toggleAllRowsSelected: () => void;
56
- toggleRowSelected: (rowId: string) => void;
57
- selectRow: (rowId: string) => void;
58
- deselectRow: (rowId: string) => void;
59
- selectAll: () => void;
60
- deselectAll: () => void;
61
-
62
- // State checkers
63
- getIsAllRowsSelected: () => boolean;
64
- getIsSomeRowsSelected: () => boolean;
65
- getIsRowSelected: (rowId: string) => boolean;
66
-
67
- // Getters
68
- getSelectionState: () => SelectionState;
69
- getSelectedCount: () => number;
70
- getSelectedRows: () => Row<TData>[];
71
- getSelectedRowIds: () => string[];
72
-
73
- // Helper methods
74
- canSelectRow: (rowId: string) => boolean;
75
- }
76
-
77
- // The custom selection feature implementation (same pattern as CustomColumnFilterFeature)
78
- export const SelectionFeature: TableFeature<any> = {
79
- // Define the feature's initial state
80
- getInitialState: (state): SelectionTableState => {
81
- return {
82
- selectionState: {
83
- ids: [],
84
- type: 'include',
85
- selectMode: 'page',
86
- },
87
- ...state,
88
- };
89
- },
90
-
91
- // Define the feature's default options
92
- getDefaultOptions: <TData extends RowData>(
93
- table: Table<TData>
94
- ): SelectionOptions => {
95
- return {
96
- enableAdvanceSelection: true,
97
- selectMode: 'page',
98
- onSelectionStateChange: makeStateUpdater('selectionState', table),
99
- } as SelectionOptions;
100
- },
101
-
102
- // Define the feature's table instance methods
103
- createTable: <TData extends RowData>(table: Table<TData>): void => {
104
- const getRowsForSelection = () => {
105
- // In client mode with pagination we can inspect all loaded rows.
106
- // In manual/server pagination only the loaded slice exists locally.
107
- if (table.options.manualPagination) {
108
- return table.getRowModel().rows;
109
- }
110
- return table.getPrePaginationRowModel?.().rows || table.getRowModel().rows;
111
- };
112
-
113
- table.setSelectionState = (updater) => {
114
- if (!table.options.enableAdvanceSelection) return;
115
- const safeUpdater: Updater<SelectionState> = (old) => {
116
- const newState = functionalUpdate(updater, old);
117
- return newState;
118
- };
119
- return table.options.onSelectionStateChange?.(safeUpdater);
120
- };
121
-
122
- // === BASIC SELECTION METHODS ===
123
- table.selectRow = (rowId: string) => {
124
- if (!table.options.enableAdvanceSelection) return;
125
- if (!table.canSelectRow(rowId)) return;
126
-
127
- table.setSelectionState((old) => {
128
- if (old.type === 'exclude') {
129
- // In exclude mode, selecting means removing from exclude list
130
- return {
131
- ...old,
132
- ids: old.ids.filter(id => id !== rowId),
133
- };
134
- } else {
135
- // In include mode, selecting means adding to include list
136
- const newIds = old.ids.includes(rowId) ? old.ids : [...old.ids, rowId];
137
- return {
138
- ...old,
139
- ids: newIds,
140
- };
141
- }
142
- });
143
- };
144
-
145
- table.deselectRow = (rowId: string) => {
146
- if (!table.options.enableAdvanceSelection) return;
147
- table.setSelectionState((old) => {
148
- if (old.type === 'exclude') {
149
- // In exclude mode, deselecting means adding to exclude list
150
- const newIds = old.ids.includes(rowId) ? old.ids : [...old.ids, rowId];
151
- return {
152
- ...old,
153
- ids: newIds,
154
- };
155
- } else {
156
- // In include mode, deselecting means removing from include list
157
- return {
158
- ...old,
159
- ids: old.ids.filter(id => id !== rowId),
160
- };
161
- }
162
- });
163
- };
164
-
165
- table.toggleRowSelected = (rowId: string) => {
166
- if (!table.options.enableAdvanceSelection) return;
167
- if (table.getIsRowSelected(rowId)) {
168
- table.deselectRow(rowId);
169
- } else {
170
- table.selectRow(rowId);
171
- }
172
- };
173
-
174
- table.selectAll = () => {
175
- if (!table.options.enableAdvanceSelection) return;
176
- const selectMode = table.options.selectMode || 'page';
177
-
178
- const currentRows = table.getPaginationRowModel?.()?.rows || table.getRowModel().rows;
179
-
180
- if (selectMode === 'all') {
181
- // In 'all' mode, use exclude type with empty list (select all)
182
- table.setSelectionState((old) => ({
183
- ...old,
184
- ids: [],
185
- type: 'exclude',
186
- }));
187
- } else {
188
- // In 'page' mode, select current page rows
189
- const selectableRowIds = currentRows
190
- .filter(row => table.canSelectRow(row.id))
191
- .map(row => row.id);
192
-
193
- table.setSelectionState((old) => ({
194
- ...old,
195
- ids: selectableRowIds,
196
- type: 'include',
197
- }));
198
- }
199
- };
200
-
201
- table.deselectAll = () => {
202
- if (!table.options.enableAdvanceSelection) return;
203
- table.setSelectionState((old) => ({
204
- ...old,
205
- ids: [],
206
- type: 'include',
207
- }));
208
- };
209
-
210
- table.toggleAllRowsSelected = () => {
211
- if (!table.options.enableAdvanceSelection) return;
212
- if (table.getIsAllRowsSelected()) {
213
- table.deselectAll();
214
- } else {
215
- table.selectAll();
216
- }
217
- };
218
-
219
- // === STATE CHECKERS ===
220
- table.getIsRowSelected = (rowId: string) => {
221
- const state = table.getSelectionState();
222
- if (state.type === 'exclude') {
223
- // In exclude mode, selected if NOT in exclude list
224
- return !state.ids.includes(rowId);
225
- } else {
226
- // In include mode, selected if in include list
227
- return state.ids.includes(rowId);
228
- }
229
- };
230
-
231
- table.getIsAllRowsSelected = () => {
232
- const state = table.getSelectionState();
233
- const selectMode = table.options.selectMode || 'page';
234
-
235
- if (selectMode === 'all') {
236
- const totalCount = table.getRowCount();
237
- if (totalCount === 0) return false;
238
-
239
- if (state.type === 'exclude') {
240
- return state.ids.length === 0;
241
- } else {
242
- return state.ids.length === totalCount;
243
- }
244
- } else {
245
- // Page mode - check if all selectable rows on current page are selected
246
- const currentPageRows = table.getPaginationRowModel?.()?.rows || table.getRowModel().rows;
247
- const selectableRows = currentPageRows.filter(row => table.canSelectRow(row.id));
248
-
249
- if (selectableRows.length === 0) return false;
250
- return selectableRows.every(row => table.getIsRowSelected(row.id));
251
- }
252
- };
253
-
254
- table.getIsSomeRowsSelected = () => {
255
- const state = table.getSelectionState();
256
- const selectMode = table.options.selectMode || 'page';
257
-
258
- if (selectMode === 'all' && state.type === 'exclude') {
259
- // In exclude mode, we have some selected if not all are excluded
260
- const totalCount = table.getRowCount();
261
- return totalCount > 0 && state.ids.length < totalCount;
262
- } else {
263
- // In include mode, we have some selected if list has items
264
- return state.ids.length > 0;
265
- }
266
- };
267
-
268
- // === GETTERS ===
269
- table.getSelectionState = () => {
270
- return table.getState().selectionState || {
271
- ids: [],
272
- type: 'include',
273
- selectMode: 'page',
274
- };
275
- };
276
-
277
- table.getSelectedCount = () => {
278
- const state = table.getSelectionState();
279
- const selectMode = table.options.selectMode || 'page';
280
-
281
- if (selectMode === 'all' && state.type === 'exclude') {
282
- // For server-side data, use rowCount which includes total from server
283
- // For client-side data, this will be the same as getRowModel().rows.length
284
- const totalCount = table.getRowCount();
285
- return Math.max(0, totalCount - state.ids.length);
286
- } else {
287
- return state.ids.length;
288
- }
289
- };
290
-
291
- table.getSelectedRowIds = () => {
292
- const state = table.getSelectionState();
293
- if (state.type === 'exclude') {
294
- return table.getSelectedRows().map((row) => row.id);
295
- }
296
- return state.ids;
297
- };
298
-
299
- table.getSelectedRows = () => {
300
- const state = table.getSelectionState();
301
- const allRows = getRowsForSelection();
302
-
303
- if (state.type === 'exclude') {
304
- // Return all rows except excluded ones
305
- return allRows.filter(row => !state.ids.includes(row.id))
306
- } else {
307
- // Return only included rows
308
- return allRows.filter(row => state.ids.includes(row.id))
309
- }
310
- };
311
-
312
- // === HELPER METHODS ===
313
- table.canSelectRow = (rowId: string) => {
314
- if (!table.options.isRowSelectable) return true;
315
-
316
- const row = table.getRowModel().rows.find(r => r.id === rowId);
317
- if (!row) return false;
318
-
319
- return table.options.isRowSelectable({ row: row.original, id: rowId });
320
- };
321
- },
322
- };
@@ -1,2 +0,0 @@
1
- export { useDataTableEngine } from './use-data-table-engine';
2
- export type { EngineResult } from './use-data-table-engine';