@ackplus/react-tanstack-data-table 1.0.35 → 1.1.3
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/LICENSE +21 -0
- package/{src → dist}/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +63 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.d.ts +2 -1
- package/dist/lib/components/droupdown/menu-dropdown.d.ts.map +1 -0
- package/{src → dist}/lib/components/droupdown/menu-dropdown.js +38 -7
- package/{src → dist}/lib/components/filters/filter-value-input.d.ts +3 -1
- package/dist/lib/components/filters/filter-value-input.d.ts.map +1 -0
- package/dist/lib/components/filters/filter-value-input.js +83 -0
- package/{src → dist}/lib/components/filters/index.d.ts +1 -0
- package/dist/lib/components/filters/index.d.ts.map +1 -0
- package/dist/lib/components/filters/index.js +142 -0
- package/{src → dist}/lib/components/headers/draggable-header.d.ts +2 -2
- package/dist/lib/components/headers/draggable-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/draggable-header.js +81 -17
- package/dist/lib/components/headers/index.d.ts +6 -0
- package/dist/lib/components/headers/index.d.ts.map +1 -0
- package/dist/lib/components/headers/index.js +21 -0
- package/{src → dist}/lib/components/headers/table-header.d.ts +15 -1
- package/dist/lib/components/headers/table-header.d.ts.map +1 -0
- package/{src → dist}/lib/components/headers/table-header.js +50 -17
- package/{src → dist}/lib/components/index.d.ts +6 -1
- package/dist/lib/components/index.d.ts.map +1 -0
- package/dist/lib/components/index.js +32 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.d.ts +2 -1
- package/dist/lib/components/pagination/data-table-pagination.d.ts.map +1 -0
- package/{src → dist}/lib/components/pagination/data-table-pagination.js +20 -6
- package/dist/lib/components/pagination/index.d.ts +5 -0
- package/dist/lib/components/pagination/index.d.ts.map +1 -0
- package/dist/lib/components/pagination/index.js +20 -0
- package/{src → dist}/lib/components/rows/data-table-row.d.ts +15 -2
- package/dist/lib/components/rows/data-table-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/data-table-row.js +58 -25
- package/{src → dist}/lib/components/rows/empty-data-row.d.ts +3 -3
- package/dist/lib/components/rows/empty-data-row.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/empty-data-row.js +12 -4
- package/dist/lib/components/rows/index.d.ts +7 -0
- package/dist/lib/components/rows/index.d.ts.map +1 -0
- package/dist/lib/components/rows/index.js +22 -0
- package/{src → dist}/lib/components/rows/loading-rows.d.ts +3 -1
- package/dist/lib/components/rows/loading-rows.d.ts.map +1 -0
- package/{src → dist}/lib/components/rows/loading-rows.js +27 -19
- package/{src → dist}/lib/components/toolbar/bulk-actions-toolbar.d.ts +4 -3
- package/dist/lib/components/toolbar/bulk-actions-toolbar.d.ts.map +1 -0
- package/dist/lib/components/toolbar/bulk-actions-toolbar.js +49 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-filter-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-filter-control.js +73 -4
- package/{src → dist}/lib/components/toolbar/column-pinning-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-pinning-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-pinning-control.js +70 -6
- package/{src → dist}/lib/components/toolbar/column-reset-control.d.ts +3 -1
- package/dist/lib/components/toolbar/column-reset-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/column-reset-control.js +9 -2
- package/{src → dist}/lib/components/toolbar/column-visibility-control.d.ts +2 -1
- package/dist/lib/components/toolbar/column-visibility-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/column-visibility-control.js +77 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.d.ts +3 -2
- package/dist/lib/components/toolbar/data-table-toolbar.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/data-table-toolbar.js +17 -4
- package/{src → dist}/lib/components/toolbar/index.d.ts +4 -0
- package/dist/lib/components/toolbar/index.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/index.js +6 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts +12 -0
- package/dist/lib/components/toolbar/table-export-control.d.ts.map +1 -0
- package/dist/lib/components/toolbar/table-export-control.js +67 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-search-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-search-control.js +45 -2
- package/{src → dist}/lib/components/toolbar/table-size-control.d.ts +3 -1
- package/dist/lib/components/toolbar/table-size-control.d.ts.map +1 -0
- package/{src → dist}/lib/components/toolbar/table-size-control.js +20 -8
- package/{src → dist}/lib/contexts/data-table-context.d.ts +6 -2
- package/dist/lib/contexts/data-table-context.d.ts.map +1 -0
- package/{src → dist}/lib/contexts/data-table-context.js +34 -1
- package/dist/lib/data-table.d.ts +5 -0
- package/dist/lib/data-table.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib}/data-table.js +427 -143
- package/dist/lib/features/column-filter.feature.d.ts +55 -0
- package/dist/lib/features/column-filter.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/column-filter.feature.js +116 -18
- package/dist/lib/features/index.d.ts +9 -0
- package/dist/lib/features/index.d.ts.map +1 -0
- package/{src → dist}/lib/features/index.js +7 -0
- package/{src → dist}/lib/features/selection.feature.d.ts +8 -1
- package/dist/lib/features/selection.feature.d.ts.map +1 -0
- package/{src → dist}/lib/features/selection.feature.js +76 -15
- package/dist/lib/icons/add-icon.d.ts +4 -0
- package/dist/lib/icons/add-icon.d.ts.map +1 -0
- package/dist/lib/icons/add-icon.js +12 -0
- package/dist/lib/icons/csv-icon.d.ts +4 -0
- package/dist/lib/icons/csv-icon.d.ts.map +1 -0
- package/dist/lib/icons/csv-icon.js +12 -0
- package/dist/lib/icons/delete-icon.d.ts +4 -0
- package/dist/lib/icons/delete-icon.d.ts.map +1 -0
- package/dist/lib/icons/delete-icon.js +12 -0
- package/dist/lib/icons/excel-icon.d.ts +4 -0
- package/dist/lib/icons/excel-icon.d.ts.map +1 -0
- package/dist/lib/icons/excel-icon.js +12 -0
- package/dist/lib/icons/index.d.ts +8 -0
- package/dist/lib/icons/index.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.d.ts +4 -0
- package/dist/lib/icons/unpin-icon.d.ts.map +1 -0
- package/dist/lib/icons/unpin-icon.js +12 -0
- package/{src → dist}/lib/icons/view-comfortable-icon.d.ts +3 -1
- package/dist/lib/icons/view-comfortable-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-comfortable-icon.js +12 -0
- package/dist/lib/icons/view-compact-icon.d.ts +4 -0
- package/dist/lib/icons/view-compact-icon.d.ts.map +1 -0
- package/dist/lib/icons/view-compact-icon.js +12 -0
- package/{src → dist}/lib/types/column.types.d.ts +10 -1
- package/dist/lib/types/column.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/data-table-api.d.ts +2 -1
- package/dist/lib/types/data-table-api.d.ts.map +1 -0
- package/{src/lib/components/table → dist/lib/types}/data-table.types.d.ts +10 -11
- package/dist/lib/types/data-table.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/export.types.d.ts +38 -0
- package/dist/lib/types/export.types.d.ts.map +1 -0
- package/dist/lib/types/export.types.js +6 -0
- package/{src → dist}/lib/types/index.d.ts +6 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +32 -0
- package/{src → dist}/lib/types/slots.types.d.ts +50 -3
- package/dist/lib/types/slots.types.d.ts.map +1 -0
- package/{src → dist}/lib/types/table.types.d.ts +14 -0
- package/dist/lib/types/table.types.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.d.ts +10 -0
- package/dist/lib/utils/column-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/column-helpers.js +20 -4
- package/{src → dist}/lib/utils/debounced-fetch.utils.d.ts +3 -5
- package/dist/lib/utils/debounced-fetch.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/debounced-fetch.utils.js +12 -6
- package/{src → dist}/lib/utils/export-utils.d.ts +13 -0
- package/dist/lib/utils/export-utils.d.ts.map +1 -0
- package/dist/lib/utils/export-utils.js +252 -0
- package/{src → dist}/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +35 -0
- package/{src → dist}/lib/utils/logger.d.ts +43 -0
- package/dist/lib/utils/logger.d.ts.map +1 -0
- package/{src → dist}/lib/utils/logger.js +22 -2
- package/{src → dist}/lib/utils/slot-helpers.d.ts +39 -1
- package/dist/lib/utils/slot-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/slot-helpers.js +55 -6
- package/{src → dist}/lib/utils/special-columns.utils.d.ts +10 -0
- package/dist/lib/utils/special-columns.utils.d.ts.map +1 -0
- package/{src → dist}/lib/utils/special-columns.utils.js +41 -5
- package/{src → dist}/lib/utils/styling-helpers.d.ts +20 -0
- package/dist/lib/utils/styling-helpers.d.ts.map +1 -0
- package/dist/lib/utils/styling-helpers.js +108 -0
- package/{src → dist}/lib/utils/table-helpers.d.ts +25 -0
- package/dist/lib/utils/table-helpers.d.ts.map +1 -0
- package/{src → dist}/lib/utils/table-helpers.js +24 -0
- package/package.json +36 -11
- package/src/index.ts +71 -0
- package/src/lib/components/droupdown/menu-dropdown.tsx +97 -0
- package/src/lib/components/filters/filter-value-input.tsx +225 -0
- package/src/lib/components/filters/{index.js → index.ts} +3 -6
- package/src/lib/components/headers/draggable-header.tsx +326 -0
- package/src/lib/components/headers/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/headers/table-header.tsx +173 -0
- package/src/lib/components/index.ts +21 -0
- package/src/lib/components/pagination/data-table-pagination.tsx +99 -0
- package/src/lib/components/pagination/index.ts +5 -0
- package/src/lib/components/rows/data-table-row.tsx +208 -0
- package/src/lib/components/rows/empty-data-row.tsx +69 -0
- package/src/lib/components/rows/{index.d.ts → index.ts} +4 -0
- package/src/lib/components/rows/loading-rows.tsx +160 -0
- package/src/lib/components/toolbar/bulk-actions-toolbar.tsx +125 -0
- package/src/lib/components/toolbar/column-filter-control.tsx +374 -0
- package/src/lib/components/toolbar/column-pinning-control.tsx +275 -0
- package/src/lib/components/toolbar/column-reset-control.tsx +74 -0
- package/src/lib/components/toolbar/column-visibility-control.tsx +105 -0
- package/src/lib/components/toolbar/data-table-toolbar.tsx +229 -0
- package/src/lib/components/toolbar/index.ts +17 -0
- package/src/lib/components/toolbar/table-export-control.tsx +179 -0
- package/src/lib/components/toolbar/table-search-control.tsx +155 -0
- package/src/lib/components/toolbar/table-size-control.tsx +102 -0
- package/src/lib/contexts/data-table-context.tsx +112 -0
- package/src/lib/data-table.tsx +1911 -0
- package/src/lib/features/README.md +161 -0
- package/src/lib/features/column-filter.feature.ts +456 -0
- package/src/lib/features/index.ts +23 -0
- package/src/lib/features/selection.feature.ts +318 -0
- package/src/lib/icons/add-icon.tsx +23 -0
- package/src/lib/icons/csv-icon.tsx +15 -0
- package/src/lib/icons/delete-icon.tsx +30 -0
- package/src/lib/icons/excel-icon.tsx +15 -0
- package/src/lib/icons/unpin-icon.tsx +18 -0
- package/src/lib/icons/view-comfortable-icon.tsx +45 -0
- package/src/lib/icons/view-compact-icon.tsx +55 -0
- package/src/lib/types/column.types.ts +44 -0
- package/src/lib/types/data-table-api.ts +169 -0
- package/src/lib/types/data-table.types.ts +136 -0
- package/src/lib/types/export.types.ts +154 -0
- package/src/lib/types/index.ts +24 -0
- package/src/lib/types/slots.types.ts +332 -0
- package/src/lib/types/table.types.ts +90 -0
- package/src/lib/utils/column-helpers.ts +72 -0
- package/src/lib/utils/debounced-fetch.utils.ts +54 -0
- package/src/lib/utils/export-utils.ts +285 -0
- package/src/lib/utils/index.ts +27 -0
- package/src/lib/utils/logger.ts +203 -0
- package/src/lib/utils/slot-helpers.tsx +194 -0
- package/src/lib/utils/special-columns.utils.ts +94 -0
- package/src/lib/utils/styling-helpers.ts +126 -0
- package/src/lib/utils/table-helpers.ts +106 -0
- package/src/index.js +0 -27
- package/src/lib/components/filters/filter-value-input.js +0 -41
- package/src/lib/components/headers/index.js +0 -5
- package/src/lib/components/index.js +0 -10
- package/src/lib/components/pagination/index.d.ts +0 -1
- package/src/lib/components/pagination/index.js +0 -4
- package/src/lib/components/rows/index.js +0 -6
- package/src/lib/components/table/data-table.d.ts +0 -4
- package/src/lib/components/table/index.d.ts +0 -2
- package/src/lib/components/table/index.js +0 -5
- package/src/lib/components/toolbar/bulk-actions-toolbar.js +0 -30
- package/src/lib/components/toolbar/column-visibility-control.js +0 -31
- package/src/lib/components/toolbar/table-export-control.d.ts +0 -31
- package/src/lib/components/toolbar/table-export-control.js +0 -56
- package/src/lib/examples/advanced-features-example.d.ts +0 -1
- package/src/lib/examples/advanced-features-example.js +0 -269
- package/src/lib/examples/bulk-actions-test.d.ts +0 -1
- package/src/lib/examples/bulk-actions-test.js +0 -44
- package/src/lib/examples/custom-column-filter-example.d.ts +0 -1
- package/src/lib/examples/custom-column-filter-example.js +0 -60
- package/src/lib/examples/index.d.ts +0 -8
- package/src/lib/examples/index.js +0 -19
- package/src/lib/examples/selection-test-example.d.ts +0 -1
- package/src/lib/examples/selection-test-example.js +0 -101
- package/src/lib/examples/server-side-fetching-example.d.ts +0 -1
- package/src/lib/examples/server-side-fetching-example.js +0 -245
- package/src/lib/examples/server-side-test.d.ts +0 -1
- package/src/lib/examples/server-side-test.js +0 -9
- package/src/lib/examples/simple-local-example.d.ts +0 -1
- package/src/lib/examples/simple-local-example.js +0 -95
- package/src/lib/examples/simple-slots-example.d.ts +0 -1
- package/src/lib/examples/simple-slots-example.js +0 -115
- package/src/lib/features/column-filter.feature.d.ts +0 -45
- package/src/lib/features/index.d.ts +0 -2
- package/src/lib/hooks/index.d.ts +0 -1
- package/src/lib/hooks/index.js +0 -4
- package/src/lib/hooks/use-data-table-api.d.ts +0 -46
- package/src/lib/hooks/use-data-table-api.js +0 -690
- package/src/lib/icons/add-icon.d.ts +0 -2
- package/src/lib/icons/add-icon.js +0 -8
- package/src/lib/icons/csv-icon.d.ts +0 -2
- package/src/lib/icons/csv-icon.js +0 -8
- package/src/lib/icons/delete-icon.d.ts +0 -2
- package/src/lib/icons/delete-icon.js +0 -8
- package/src/lib/icons/excel-icon.d.ts +0 -2
- package/src/lib/icons/excel-icon.js +0 -8
- package/src/lib/icons/unpin-icon.d.ts +0 -2
- package/src/lib/icons/unpin-icon.js +0 -8
- package/src/lib/icons/view-comfortable-icon.js +0 -8
- package/src/lib/icons/view-compact-icon.d.ts +0 -2
- package/src/lib/icons/view-compact-icon.js +0 -8
- package/src/lib/types/export.types.js +0 -2
- package/src/lib/types/index.js +0 -8
- package/src/lib/utils/export-utils.js +0 -175
- package/src/lib/utils/index.js +0 -11
- package/src/lib/utils/styling-helpers.js +0 -70
- package/tsconfig.tsbuildinfo +0 -1
- /package/{src → dist}/lib/icons/index.js +0 -0
- /package/{src → dist}/lib/types/column.types.js +0 -0
- /package/{src → dist}/lib/types/data-table-api.js +0 -0
- /package/{src/lib/components/table → dist/lib/types}/data-table.types.js +0 -0
- /package/{src → dist}/lib/types/slots.types.js +0 -0
- /package/{src → dist}/lib/types/table.types.js +0 -0
- /package/src/lib/icons/{index.d.ts → index.ts} +0 -0
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
table.setSelectionState = (updater) => {
|
|
105
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
106
|
+
const safeUpdater: Updater<SelectionState> = (old) => {
|
|
107
|
+
const newState = functionalUpdate(updater, old);
|
|
108
|
+
return newState;
|
|
109
|
+
};
|
|
110
|
+
return table.options.onSelectionStateChange?.(safeUpdater);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// === BASIC SELECTION METHODS ===
|
|
114
|
+
table.selectRow = (rowId: string) => {
|
|
115
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
116
|
+
if (!table.canSelectRow(rowId)) return;
|
|
117
|
+
|
|
118
|
+
table.setSelectionState((old) => {
|
|
119
|
+
if (old.type === 'exclude') {
|
|
120
|
+
// In exclude mode, selecting means removing from exclude list
|
|
121
|
+
return {
|
|
122
|
+
...old,
|
|
123
|
+
ids: old.ids.filter(id => id !== rowId),
|
|
124
|
+
};
|
|
125
|
+
} else {
|
|
126
|
+
// In include mode, selecting means adding to include list
|
|
127
|
+
const newIds = old.ids.includes(rowId) ? old.ids : [...old.ids, rowId];
|
|
128
|
+
return {
|
|
129
|
+
...old,
|
|
130
|
+
ids: newIds,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
table.deselectRow = (rowId: string) => {
|
|
137
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
138
|
+
table.setSelectionState((old) => {
|
|
139
|
+
if (old.type === 'exclude') {
|
|
140
|
+
// In exclude mode, deselecting means adding to exclude list
|
|
141
|
+
const newIds = old.ids.includes(rowId) ? old.ids : [...old.ids, rowId];
|
|
142
|
+
return {
|
|
143
|
+
...old,
|
|
144
|
+
ids: newIds,
|
|
145
|
+
};
|
|
146
|
+
} else {
|
|
147
|
+
// In include mode, deselecting means removing from include list
|
|
148
|
+
return {
|
|
149
|
+
...old,
|
|
150
|
+
ids: old.ids.filter(id => id !== rowId),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
table.toggleRowSelected = (rowId: string) => {
|
|
157
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
158
|
+
if (table.getIsRowSelected(rowId)) {
|
|
159
|
+
table.deselectRow(rowId);
|
|
160
|
+
} else {
|
|
161
|
+
table.selectRow(rowId);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
table.selectAll = () => {
|
|
166
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
167
|
+
const selectMode = table.options.selectMode || 'page';
|
|
168
|
+
|
|
169
|
+
const currentRows =
|
|
170
|
+
table.getPaginationRowModel?.()?.rows ||
|
|
171
|
+
table.getRowModel().rows;
|
|
172
|
+
|
|
173
|
+
if (selectMode === 'all') {
|
|
174
|
+
// In 'all' mode, use exclude type with empty list (select all)
|
|
175
|
+
table.setSelectionState((old) => ({
|
|
176
|
+
...old,
|
|
177
|
+
ids: [],
|
|
178
|
+
type: 'exclude',
|
|
179
|
+
}));
|
|
180
|
+
} else {
|
|
181
|
+
// In 'page' mode, select current page rows
|
|
182
|
+
const selectableRowIds = currentRows
|
|
183
|
+
.filter(row => table.canSelectRow(row.id))
|
|
184
|
+
.map(row => row.id);
|
|
185
|
+
|
|
186
|
+
table.setSelectionState((old) => ({
|
|
187
|
+
...old,
|
|
188
|
+
ids: selectableRowIds,
|
|
189
|
+
type: 'include',
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
table.deselectAll = () => {
|
|
195
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
196
|
+
table.setSelectionState((old) => ({
|
|
197
|
+
...old,
|
|
198
|
+
ids: [],
|
|
199
|
+
type: 'include',
|
|
200
|
+
}));
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
table.toggleAllRowsSelected = () => {
|
|
204
|
+
if (!table.options.enableAdvanceSelection) return;
|
|
205
|
+
if (table.getIsAllRowsSelected()) {
|
|
206
|
+
table.deselectAll();
|
|
207
|
+
} else {
|
|
208
|
+
table.selectAll();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// === STATE CHECKERS ===
|
|
213
|
+
table.getIsRowSelected = (rowId: string) => {
|
|
214
|
+
const state = table.getSelectionState();
|
|
215
|
+
if (state.type === 'exclude') {
|
|
216
|
+
// In exclude mode, selected if NOT in exclude list
|
|
217
|
+
return !state.ids.includes(rowId);
|
|
218
|
+
} else {
|
|
219
|
+
// In include mode, selected if in include list
|
|
220
|
+
return state.ids.includes(rowId);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
table.getIsAllRowsSelected = () => {
|
|
225
|
+
const state = table.getSelectionState();
|
|
226
|
+
const selectMode = table.options.selectMode || 'page';
|
|
227
|
+
|
|
228
|
+
if (selectMode === 'all') {
|
|
229
|
+
const totalCount = table.getRowCount();
|
|
230
|
+
if (totalCount === 0) return false;
|
|
231
|
+
|
|
232
|
+
if (state.type === 'exclude') {
|
|
233
|
+
return state.ids.length === 0;
|
|
234
|
+
} else {
|
|
235
|
+
return state.ids.length === totalCount;
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
// Page mode - check if all selectable rows on current page are selected
|
|
239
|
+
const currentPageRows = table.getPaginationRowModel?.()?.rows || table.getRowModel().rows;
|
|
240
|
+
const selectableRows = currentPageRows.filter(row => table.canSelectRow(row.id));
|
|
241
|
+
|
|
242
|
+
if (selectableRows.length === 0) return false;
|
|
243
|
+
return selectableRows.every(row => table.getIsRowSelected(row.id));
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
table.getIsSomeRowsSelected = () => {
|
|
248
|
+
const state = table.getSelectionState();
|
|
249
|
+
const selectMode = table.options.selectMode || 'page';
|
|
250
|
+
|
|
251
|
+
if (selectMode === 'all' && state.type === 'exclude') {
|
|
252
|
+
// In exclude mode, we have some selected if not all are excluded
|
|
253
|
+
const totalCount = table.getRowCount();
|
|
254
|
+
return totalCount > 0 && state.ids.length < totalCount;
|
|
255
|
+
} else {
|
|
256
|
+
// In include mode, we have some selected if list has items
|
|
257
|
+
return state.ids.length > 0;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// === GETTERS ===
|
|
262
|
+
table.getSelectionState = () => {
|
|
263
|
+
return table.getState().selectionState || {
|
|
264
|
+
ids: [],
|
|
265
|
+
type: 'include',
|
|
266
|
+
selectMode: 'page',
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
table.getSelectedCount = () => {
|
|
271
|
+
const state = table.getSelectionState();
|
|
272
|
+
const selectMode = table.options.selectMode || 'page';
|
|
273
|
+
|
|
274
|
+
if (selectMode === 'all' && state.type === 'exclude') {
|
|
275
|
+
// For server-side data, use rowCount which includes total from server
|
|
276
|
+
// For client-side data, this will be the same as getRowModel().rows.length
|
|
277
|
+
const totalCount = table.getRowCount();
|
|
278
|
+
return Math.max(0, totalCount - state.ids.length);
|
|
279
|
+
} else {
|
|
280
|
+
return state.ids.length;
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
table.getSelectedRowIds = () => {
|
|
285
|
+
const state = table.getSelectionState();
|
|
286
|
+
if (state.type === 'exclude') {
|
|
287
|
+
console.warn(
|
|
288
|
+
'[SelectionFeature] getSelectedRowIds() is not accurate in exclude mode. Use getSelectionState() to interpret selection properly.'
|
|
289
|
+
);
|
|
290
|
+
return []; // Return empty to avoid misleading API
|
|
291
|
+
}
|
|
292
|
+
return state.ids;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
table.getSelectedRows = () => {
|
|
296
|
+
const state = table.getSelectionState();
|
|
297
|
+
const allRows = table.getRowModel().rows;
|
|
298
|
+
|
|
299
|
+
if (state.type === 'exclude') {
|
|
300
|
+
// Return all rows except excluded ones
|
|
301
|
+
return allRows.filter(row => !state.ids.includes(row.id))
|
|
302
|
+
} else {
|
|
303
|
+
// Return only included rows
|
|
304
|
+
return allRows.filter(row => state.ids.includes(row.id))
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// === HELPER METHODS ===
|
|
309
|
+
table.canSelectRow = (rowId: string) => {
|
|
310
|
+
if (!table.options.isRowSelectable) return true;
|
|
311
|
+
|
|
312
|
+
const row = table.getRowModel().rows.find(r => r.id === rowId);
|
|
313
|
+
if (!row) return false;
|
|
314
|
+
|
|
315
|
+
return table.options.isRowSelectable({ row: row.original, id: rowId });
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function AddIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
|
12
|
+
<circle
|
|
13
|
+
cx="12"
|
|
14
|
+
cy="12"
|
|
15
|
+
r="9"
|
|
16
|
+
fill="none"
|
|
17
|
+
stroke="currentColor"
|
|
18
|
+
strokeWidth="0.5"
|
|
19
|
+
opacity="0.3"
|
|
20
|
+
/>
|
|
21
|
+
</SvgIcon>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function CsvIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" />
|
|
12
|
+
<path d="M7,12.5A0.5,0.5 0 0,1 7.5,12H8.5A0.5,0.5 0 0,1 9,12.5V13.5A0.5,0.5 0 0,1 8.5,14H7.5A0.5,0.5 0 0,1 7,13.5M10.5,12.5A0.5,0.5 0 0,1 11,12H12A0.5,0.5 0 0,1 12.5,12.5V13.5A0.5,0.5 0 0,1 12,14H11A0.5,0.5 0 0,1 10.5,13.5M14,12.5A0.5,0.5 0 0,1 14.5,12H15.5A0.5,0.5 0 0,1 16,12.5V13.5A0.5,0.5 0 0,1 15.5,14H14.5A0.5,0.5 0 0,1 14,13.5" />
|
|
13
|
+
</SvgIcon>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function DeleteIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<path d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" />
|
|
12
|
+
<rect
|
|
13
|
+
x="9"
|
|
14
|
+
y="8"
|
|
15
|
+
width="2"
|
|
16
|
+
height="9"
|
|
17
|
+
fill="currentColor"
|
|
18
|
+
opacity="0.6"
|
|
19
|
+
/>
|
|
20
|
+
<rect
|
|
21
|
+
x="13"
|
|
22
|
+
y="8"
|
|
23
|
+
width="2"
|
|
24
|
+
height="9"
|
|
25
|
+
fill="currentColor"
|
|
26
|
+
opacity="0.6"
|
|
27
|
+
/>
|
|
28
|
+
</SvgIcon>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function ExcelIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<path d="M14,2H6A2,2 0 0,0 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2M18,20H6V4H13V9H18V20Z" />
|
|
12
|
+
<path d="M11.5,15L9.75,12.5L11.5,10H10L8.75,11.5L7.5,10H6L7.75,12.5L6,15H7.5L8.75,13.5L10,15H11.5M15,10V12H17V10H15M15,14V16H17V14H15Z" />
|
|
13
|
+
</SvgIcon>
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function UnpinIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<path
|
|
12
|
+
d="M2 5.27L3.28 4 20 20.72 18.73 22l-3.41-3.41V22h-1.6v-6H8v-2l2-2V9.27L2 5.27zM16 12V4h1V2H7v2h1v3.73l8 8z"
|
|
13
|
+
opacity="0.7"
|
|
14
|
+
/>
|
|
15
|
+
<path d="M14.73 12L16 10.73V4h1V2H7v2h1v3.73l2.27 2.27z" />
|
|
16
|
+
</SvgIcon>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function ViewComfortableIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<rect
|
|
12
|
+
x="3"
|
|
13
|
+
y="3"
|
|
14
|
+
width="18"
|
|
15
|
+
height="3"
|
|
16
|
+
fill="currentColor"
|
|
17
|
+
rx="1"
|
|
18
|
+
/>
|
|
19
|
+
<rect
|
|
20
|
+
x="3"
|
|
21
|
+
y="8"
|
|
22
|
+
width="18"
|
|
23
|
+
height="3"
|
|
24
|
+
fill="currentColor"
|
|
25
|
+
rx="1"
|
|
26
|
+
/>
|
|
27
|
+
<rect
|
|
28
|
+
x="3"
|
|
29
|
+
y="13"
|
|
30
|
+
width="18"
|
|
31
|
+
height="3"
|
|
32
|
+
fill="currentColor"
|
|
33
|
+
rx="1"
|
|
34
|
+
/>
|
|
35
|
+
<rect
|
|
36
|
+
x="3"
|
|
37
|
+
y="18"
|
|
38
|
+
width="18"
|
|
39
|
+
height="3"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
rx="1"
|
|
42
|
+
/>
|
|
43
|
+
</SvgIcon>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { ReactElement } from 'react';
|
|
2
|
+
import { SvgIcon, SvgIconProps } from '@mui/material';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function ViewCompactIcon(props: SvgIconProps): ReactElement {
|
|
6
|
+
return (
|
|
7
|
+
<SvgIcon
|
|
8
|
+
{...props}
|
|
9
|
+
viewBox="0 0 24 24"
|
|
10
|
+
>
|
|
11
|
+
<rect
|
|
12
|
+
x="3"
|
|
13
|
+
y="4"
|
|
14
|
+
width="18"
|
|
15
|
+
height="2"
|
|
16
|
+
fill="currentColor"
|
|
17
|
+
/>
|
|
18
|
+
<rect
|
|
19
|
+
x="3"
|
|
20
|
+
y="7"
|
|
21
|
+
width="18"
|
|
22
|
+
height="2"
|
|
23
|
+
fill="currentColor"
|
|
24
|
+
/>
|
|
25
|
+
<rect
|
|
26
|
+
x="3"
|
|
27
|
+
y="10"
|
|
28
|
+
width="18"
|
|
29
|
+
height="2"
|
|
30
|
+
fill="currentColor"
|
|
31
|
+
/>
|
|
32
|
+
<rect
|
|
33
|
+
x="3"
|
|
34
|
+
y="13"
|
|
35
|
+
width="18"
|
|
36
|
+
height="2"
|
|
37
|
+
fill="currentColor"
|
|
38
|
+
/>
|
|
39
|
+
<rect
|
|
40
|
+
x="3"
|
|
41
|
+
y="16"
|
|
42
|
+
width="18"
|
|
43
|
+
height="2"
|
|
44
|
+
fill="currentColor"
|
|
45
|
+
/>
|
|
46
|
+
<rect
|
|
47
|
+
x="3"
|
|
48
|
+
y="19"
|
|
49
|
+
width="18"
|
|
50
|
+
height="2"
|
|
51
|
+
fill="currentColor"
|
|
52
|
+
/>
|
|
53
|
+
</SvgIcon>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ColumnDef, RowData, Column } from '@tanstack/react-table';
|
|
2
|
+
import { ColumnFilterRule } from '../features';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const DEFAULT_SELECTION_COLUMN_NAME = '_selection';
|
|
6
|
+
export const DEFAULT_EXPANDING_COLUMN_NAME = '_expanding';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Column Definition Types
|
|
10
|
+
* Consolidated column-related interfaces from various files
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Module augmentation to extend TanStack Table's ColumnMeta interface
|
|
15
|
+
* This automatically extends all ColumnDef types since they use ColumnMeta in their meta property
|
|
16
|
+
*/
|
|
17
|
+
declare module '@tanstack/react-table' {
|
|
18
|
+
interface ColumnDefBase<TData extends RowData, TValue> {
|
|
19
|
+
type?: 'boolean' | 'number' | 'date' | 'select' | 'text';
|
|
20
|
+
options?: {
|
|
21
|
+
label: string;
|
|
22
|
+
value: string;
|
|
23
|
+
}[];
|
|
24
|
+
align?: 'left' | 'center' | 'right';
|
|
25
|
+
filterable?: boolean;
|
|
26
|
+
hideInExport?: boolean;
|
|
27
|
+
wrapText?: boolean; // If true, text will wrap; if false, text will truncate with ellipsis (default: false)
|
|
28
|
+
editComponent?: React.ComponentType<{
|
|
29
|
+
value: any;
|
|
30
|
+
onChange: (value: any) => void;
|
|
31
|
+
filter: ColumnFilterRule;
|
|
32
|
+
column: Column<TData, TValue>;
|
|
33
|
+
}>;
|
|
34
|
+
filterComponent?: React.ComponentType<{
|
|
35
|
+
value: any;
|
|
36
|
+
onChange: (value: any) => void;
|
|
37
|
+
filter: ColumnFilterRule;
|
|
38
|
+
column: Column<TData, TValue>;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export type DataTableColumn<TData extends RowData, TValue = unknown> = ColumnDef<TData, TValue> & {
|
|
43
|
+
// All custom properties are now defined in the module augmentation above
|
|
44
|
+
}
|