@macrostrat/data-sheet 3.0.4 → 4.0.0-dev1

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 (185) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/actions/builtin.cjs +56 -0
  3. package/dist/actions/builtin.cjs.map +1 -0
  4. package/dist/actions/builtin.d.ts +15 -0
  5. package/dist/actions/builtin.js +56 -0
  6. package/dist/actions/builtin.js.map +1 -0
  7. package/dist/actions/clipboard.cjs +250 -0
  8. package/dist/actions/clipboard.cjs.map +1 -0
  9. package/dist/actions/clipboard.d.ts +42 -0
  10. package/dist/actions/clipboard.js +250 -0
  11. package/dist/actions/clipboard.js.map +1 -0
  12. package/dist/actions/filters.cjs +123 -0
  13. package/dist/actions/filters.cjs.map +1 -0
  14. package/dist/actions/filters.d.ts +6 -0
  15. package/dist/actions/filters.js +123 -0
  16. package/dist/actions/filters.js.map +1 -0
  17. package/dist/actions/index.d.ts +6 -0
  18. package/dist/actions/selection.cjs +194 -0
  19. package/dist/actions/selection.cjs.map +1 -0
  20. package/dist/actions/selection.d.ts +40 -0
  21. package/dist/actions/selection.js +192 -0
  22. package/dist/actions/selection.js.map +1 -0
  23. package/dist/actions/toolbar.cjs +171 -0
  24. package/dist/actions/toolbar.cjs.map +1 -0
  25. package/dist/actions/toolbar.d.ts +10 -0
  26. package/dist/actions/toolbar.js +171 -0
  27. package/dist/actions/toolbar.js.map +1 -0
  28. package/dist/actions/toolbar.module.sass.cjs +22 -0
  29. package/dist/actions/toolbar.module.sass.cjs.map +1 -0
  30. package/dist/actions/toolbar.module.sass.js +20 -0
  31. package/dist/actions/toolbar.module.sass.js.map +1 -0
  32. package/dist/actions/types.d.ts +143 -0
  33. package/dist/cell-renderer.cjs +165 -0
  34. package/dist/cell-renderer.cjs.map +1 -0
  35. package/dist/cell-renderer.d.ts +3 -0
  36. package/dist/cell-renderer.js +165 -0
  37. package/dist/cell-renderer.js.map +1 -0
  38. package/dist/components/actions.module.sass.cjs +3 -3
  39. package/dist/components/actions.module.sass.js +2 -2
  40. package/dist/components/colors.cjs +20 -16
  41. package/dist/components/colors.cjs.map +1 -1
  42. package/dist/components/colors.d.ts +4 -3
  43. package/dist/components/colors.js +20 -16
  44. package/dist/components/colors.js.map +1 -1
  45. package/dist/components/editor-popup.cjs +4 -3
  46. package/dist/components/editor-popup.cjs.map +1 -1
  47. package/dist/components/editor-popup.js +4 -3
  48. package/dist/components/editor-popup.js.map +1 -1
  49. package/dist/components/index.d.ts +1 -0
  50. package/dist/components/main.module.sass.cjs +12 -12
  51. package/dist/components/main.module.sass.js +11 -11
  52. package/dist/components/text-areas.cjs +23 -18
  53. package/dist/components/text-areas.cjs.map +1 -1
  54. package/dist/components/text-areas.d.ts +8 -4
  55. package/dist/components/text-areas.js +20 -13
  56. package/dist/components/text-areas.js.map +1 -1
  57. package/dist/components/view-info.cjs +18 -0
  58. package/dist/components/view-info.cjs.map +1 -0
  59. package/dist/components/view-info.d.ts +1 -0
  60. package/dist/components/view-info.js +18 -0
  61. package/dist/components/view-info.js.map +1 -0
  62. package/dist/core.cjs +201 -300
  63. package/dist/core.cjs.map +1 -1
  64. package/dist/core.d.ts +18 -10
  65. package/dist/core.js +204 -299
  66. package/dist/core.js.map +1 -1
  67. package/dist/data-sheet.css +190 -52
  68. package/dist/index.cjs +47 -8
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.ts +3 -0
  71. package/dist/index.js +48 -9
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.module.sass.cjs +15 -14
  74. package/dist/main.module.sass.cjs.map +1 -1
  75. package/dist/main.module.sass.js +14 -13
  76. package/dist/main.module.sass.js.map +1 -1
  77. package/dist/notifications.cjs +19 -0
  78. package/dist/notifications.cjs.map +1 -0
  79. package/dist/notifications.d.ts +9 -0
  80. package/dist/notifications.js +19 -0
  81. package/dist/notifications.js.map +1 -0
  82. package/dist/postgrest-table/data-loaders.cjs +181 -104
  83. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  84. package/dist/postgrest-table/data-loaders.d.ts +52 -28
  85. package/dist/postgrest-table/data-loaders.js +181 -104
  86. package/dist/postgrest-table/data-loaders.js.map +1 -1
  87. package/dist/postgrest-table/index.cjs +205 -79
  88. package/dist/postgrest-table/index.cjs.map +1 -1
  89. package/dist/postgrest-table/index.d.ts +14 -17
  90. package/dist/postgrest-table/index.js +186 -58
  91. package/dist/postgrest-table/index.js.map +1 -1
  92. package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
  93. package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
  94. package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
  95. package/dist/postgrest-table/lazy-loader-table.js +17 -14
  96. package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
  97. package/dist/postgrest-table/loading-utils.cjs +16 -0
  98. package/dist/postgrest-table/loading-utils.cjs.map +1 -0
  99. package/dist/postgrest-table/loading-utils.d.ts +13 -0
  100. package/dist/postgrest-table/loading-utils.js +16 -0
  101. package/dist/postgrest-table/loading-utils.js.map +1 -0
  102. package/dist/postgrest-table/main.module.sass.cjs +18 -13
  103. package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
  104. package/dist/postgrest-table/main.module.sass.js +18 -13
  105. package/dist/postgrest-table/main.module.sass.js.map +1 -1
  106. package/dist/provider.cjs +96 -344
  107. package/dist/provider.cjs.map +1 -1
  108. package/dist/provider.js +96 -343
  109. package/dist/provider.js.map +1 -1
  110. package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
  111. package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
  112. package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
  113. package/dist/renderers/column-header-cell-postgrest.js +216 -0
  114. package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
  115. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
  116. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
  117. package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
  118. package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
  119. package/dist/renderers/column-header-cell.cjs +103 -0
  120. package/dist/renderers/column-header-cell.cjs.map +1 -0
  121. package/dist/renderers/column-header-cell.d.ts +30 -0
  122. package/dist/renderers/column-header-cell.js +101 -0
  123. package/dist/renderers/column-header-cell.js.map +1 -0
  124. package/dist/renderers/index.d.ts +2 -0
  125. package/dist/table-updates/data-parameter.d.ts +14 -0
  126. package/dist/table-updates/filter.d.ts +16 -0
  127. package/dist/table-updates/index.d.ts +19 -0
  128. package/dist/types.cjs +9 -0
  129. package/dist/types.cjs.map +1 -0
  130. package/dist/types.d.ts +108 -0
  131. package/dist/types.js +9 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/column-spec.cjs +9 -1
  134. package/dist/utils/column-spec.cjs.map +1 -1
  135. package/dist/utils/column-spec.d.ts +21 -0
  136. package/dist/utils/column-spec.js +9 -1
  137. package/dist/utils/column-spec.js.map +1 -1
  138. package/dist/utils/key-handling.cjs +161 -47
  139. package/dist/utils/key-handling.cjs.map +1 -1
  140. package/dist/utils/key-handling.d.ts +3 -3
  141. package/dist/utils/key-handling.js +161 -47
  142. package/dist/utils/key-handling.js.map +1 -1
  143. package/dist/zustand-store.cjs +485 -0
  144. package/dist/zustand-store.cjs.map +1 -0
  145. package/dist/zustand-store.d.ts +6 -0
  146. package/dist/zustand-store.js +483 -0
  147. package/dist/zustand-store.js.map +1 -0
  148. package/package.json +6 -5
  149. package/src/actions/builtin.ts +65 -0
  150. package/src/actions/clipboard.ts +350 -0
  151. package/src/actions/filters.ts +150 -0
  152. package/src/actions/index.ts +6 -0
  153. package/src/actions/selection.ts +271 -0
  154. package/src/actions/toolbar.module.sass +30 -0
  155. package/src/actions/toolbar.ts +212 -0
  156. package/src/actions/types.ts +159 -0
  157. package/src/cell-renderer.ts +221 -0
  158. package/src/components/colors.ts +22 -19
  159. package/src/components/editor-popup.ts +3 -2
  160. package/src/components/index.ts +1 -0
  161. package/src/components/main.module.sass +1 -0
  162. package/src/components/text-areas.ts +34 -19
  163. package/src/components/view-info.ts +17 -0
  164. package/src/core.ts +273 -360
  165. package/src/index.ts +4 -0
  166. package/src/main.module.sass +14 -2
  167. package/src/notifications.ts +22 -0
  168. package/src/postgrest-table/data-loaders.ts +300 -201
  169. package/src/postgrest-table/index.ts +260 -86
  170. package/src/postgrest-table/lazy-loader-table.ts +18 -17
  171. package/src/postgrest-table/loading-utils.ts +49 -0
  172. package/src/postgrest-table/main.module.sass +16 -0
  173. package/src/provider.ts +110 -487
  174. package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
  175. package/src/renderers/column-header-cell-postgrest.ts +282 -0
  176. package/src/renderers/column-header-cell.ts +388 -0
  177. package/src/renderers/index.ts +2 -0
  178. package/src/table-updates/data-parameter.ts +44 -0
  179. package/src/table-updates/filter.ts +124 -0
  180. package/src/table-updates/index.ts +239 -0
  181. package/src/types.ts +121 -0
  182. package/src/utils/column-spec.ts +47 -0
  183. package/src/utils/key-handling.ts +201 -66
  184. package/src/zustand-store.ts +582 -0
  185. package/dist/provider.d.ts +0 -69
@@ -0,0 +1,239 @@
1
+ import {
2
+ Filter,
3
+ createFiltersKey,
4
+ addFilterToURL,
5
+ rowPassesFilters,
6
+ } from "./filter";
7
+ import { DataParameters, cloneDataParameters } from "./data-parameter";
8
+ import {
9
+ ProgressPopoverProps,
10
+ submitColumnCopy,
11
+ } from "#/maps/ingestion/@id/components";
12
+
13
+ export interface TableUpdate {
14
+ // Used to merge updates
15
+ key?: string;
16
+ // Column
17
+ column: string;
18
+ // Helpful for debugging
19
+ description?: string;
20
+ // Function to execute this update
21
+ execute: () => Promise<void>;
22
+ // Function to lyTablely this update to a cell
23
+ applyToCell: (
24
+ currentValue: boolean | string | number | null,
25
+ row: Record<string, boolean | string | number | null>,
26
+ cellColumnName: string,
27
+ ) => string;
28
+ }
29
+
30
+ export const applyTableUpdate = (
31
+ data: Record<string, boolean | string | number | null>[],
32
+ tableUpdate: TableUpdate,
33
+ ) => {
34
+ for (const [rowIndex, row] of data.entries()) {
35
+ data[rowIndex][tableUpdate.column] = tableUpdate.applyToCell(
36
+ data[rowIndex][tableUpdate.column],
37
+ row,
38
+ tableUpdate.column,
39
+ );
40
+ }
41
+
42
+ return data;
43
+ };
44
+
45
+ export const applyTableUpdates = (
46
+ data: Record<string, boolean | string | number | null>[],
47
+ tableUpdates: TableUpdate[],
48
+ ) => {
49
+ for (const tableUpdate of tableUpdates) {
50
+ data = applyTableUpdate(data, tableUpdate);
51
+ }
52
+ return data;
53
+ };
54
+
55
+ export const createTableUpdateCopyColumn = (
56
+ url: string,
57
+ selectedColumn: string,
58
+ copiedColumn: string,
59
+ dataParameters: DataParameters,
60
+ ): TableUpdate => {
61
+ dataParameters = cloneDataParameters(dataParameters);
62
+
63
+ return {
64
+ column: selectedColumn,
65
+ description: `Copy column ${copiedColumn} to ${selectedColumn}`,
66
+ applyToCell: (value, row, cellColumnName) => {
67
+ if (!rowPassesFilters(row, Object.values(dataParameters.filter))) {
68
+ return value;
69
+ }
70
+
71
+ if (cellColumnName == selectedColumn) {
72
+ return row[copiedColumn];
73
+ }
74
+
75
+ return value;
76
+ },
77
+ execute: async () => {
78
+ await submitColumnCopy(url, copiedColumn, selectedColumn, dataParameters);
79
+ },
80
+ };
81
+ };
82
+
83
+ export const createTableUpdate = (
84
+ url: string,
85
+ value: string,
86
+ columnName: string,
87
+ row: Record<string, boolean | string | number | null>,
88
+ dataParameters: DataParameters,
89
+ ): TableUpdate => {
90
+ /** Create an update operation that is queued for application to the
91
+ * table
92
+ */
93
+ console.log(url, value, columnName, row, dataParameters);
94
+ let newDataParameters = cloneDataParameters(dataParameters);
95
+
96
+ // If we are grouped by a column, set the filter based on that.
97
+
98
+ const group = newDataParameters.group;
99
+
100
+ if (group != undefined) {
101
+ if (group != null) {
102
+ newDataParameters.filter[group] = new Filter(group, "eq", row[group]);
103
+ } else {
104
+ // special case for remaining elements not in a group
105
+ newDataParameters.filter[group] = new Filter(group, "is", "null");
106
+ }
107
+ } else {
108
+ newDataParameters.filter["_pkid"] = new Filter("_pkid", "eq", row["_pkid"]);
109
+ }
110
+
111
+ console.log(newDataParameters.filter);
112
+
113
+ const execute = async () =>
114
+ submitChange(url, value, [columnName], newDataParameters.filter);
115
+
116
+ const apply = (
117
+ currentValue: string,
118
+ row: { [key: string]: string },
119
+ cellColumnName: string,
120
+ ) => {
121
+ // If this row doesn't pass all the filters skip it
122
+ if (!rowPassesFilters(row, Object.values(newDataParameters.filter))) {
123
+ return currentValue;
124
+ }
125
+
126
+ // Return the new value
127
+ return value;
128
+ };
129
+
130
+ const filterKey = createFiltersKey(Object.values(newDataParameters.filter));
131
+
132
+ return {
133
+ column: columnName,
134
+ key: filterKey,
135
+ description: `Update ${columnName} to ${value} for ${filterKey}`,
136
+ execute: execute,
137
+ applyToCell: apply,
138
+ } as TableUpdate;
139
+ };
140
+
141
+ export const submitChange = async (
142
+ url: string,
143
+ value: string,
144
+ columns: string[],
145
+ filters: { [key: string]: Filter },
146
+ ) => {
147
+ for (const column of columns) {
148
+ let updateURL = new URL(url);
149
+
150
+ // Add the filters to the query parameters
151
+ Object.values(filters).forEach((filter) => {
152
+ addFilterToURL(updateURL, filter);
153
+ });
154
+
155
+ // Create the request body
156
+ let patch = { [column]: value };
157
+
158
+ // Send the request
159
+ let response = await fetch(updateURL, {
160
+ method: "PATCH",
161
+ headers: {
162
+ "Content-Type": "application/json",
163
+ },
164
+ body: JSON.stringify(patch),
165
+ });
166
+
167
+ if (response.status != 204) {
168
+ // Stop execution if the request failed
169
+ throw Error("Failed to update");
170
+ }
171
+ }
172
+ };
173
+
174
+ /*
175
+ * Squash adjacent updates with the same key
176
+ *
177
+ * If one update is followed by another update to the same set of cells
178
+ * remove the first update
179
+ */
180
+ export const squashTableUpdates = (
181
+ tableUpdates: TableUpdate[],
182
+ ): TableUpdate[] => {
183
+ let squashedTableUpdates = [];
184
+ let lastTableUpdate = null;
185
+ for (const tableUpdate of tableUpdates) {
186
+ if (
187
+ tableUpdate.key == lastTableUpdate?.key &&
188
+ tableUpdate.column == lastTableUpdate?.column
189
+ ) {
190
+ squashedTableUpdates.pop();
191
+ }
192
+ squashedTableUpdates.push(tableUpdate);
193
+ lastTableUpdate = tableUpdate;
194
+ }
195
+
196
+ return squashedTableUpdates;
197
+ };
198
+
199
+ /*
200
+ * Submit table updates, returning any updates that were not submitted
201
+ */
202
+ export const submitTableUpdates = async (
203
+ tableUpdates: TableUpdate[],
204
+ setProgress: (p: ProgressPopoverProps) => void,
205
+ ): Promise<TableUpdate[]> => {
206
+ let index = 0;
207
+ for (const tableUpdate of tableUpdates) {
208
+ setProgress({
209
+ text: tableUpdate?.description ?? "Submitting changes",
210
+ });
211
+
212
+ try {
213
+ await tableUpdate.execute();
214
+ } catch (e) {
215
+ // If there is an error, set the progress to an error state and stop submitting
216
+ setProgress({
217
+ progressBarProps: { intent: "danger" },
218
+ value: 1,
219
+ text: "Error submitting changes",
220
+ });
221
+
222
+ setTimeout(() => {
223
+ setProgress(undefined);
224
+ }, 5000);
225
+
226
+ // Return remaining table updates
227
+ return tableUpdates.slice(index);
228
+ }
229
+
230
+ index += 1;
231
+ setProgress({
232
+ value: index / tableUpdates.length,
233
+ });
234
+ }
235
+
236
+ setProgress(undefined);
237
+
238
+ return [];
239
+ };
package/src/types.ts ADDED
@@ -0,0 +1,121 @@
1
+ import type {
2
+ FocusedCellCoordinates,
3
+ Region,
4
+ RegionCardinality,
5
+ Table2,
6
+ } from "@blueprintjs/table";
7
+ import { ColumnSpec, ColumnSpecOptions } from "./utils";
8
+ import { OverlayToaster, Toaster } from "@blueprintjs/core";
9
+
10
+ /** A single column sort entry for client-side sorting.
11
+ * Defined here (rather than in actions/types) to avoid circular imports. */
12
+ export interface ColumnSort {
13
+ key: string;
14
+ ascending: boolean;
15
+ }
16
+
17
+ export interface DataSheetCoreProps<T> {
18
+ data: T[];
19
+ columnSpec?: ColumnSpec[];
20
+ editable?: boolean;
21
+ enableColumnReordering?: boolean;
22
+ defaultColumnWidth?: number;
23
+ }
24
+
25
+ export enum TableElementStatus {
26
+ DELETED = "deleted",
27
+ ADDED = "added",
28
+ }
29
+
30
+ /** Proxy stored during a copy operation, enabling backend-mediated paste
31
+ * for lazy-loaded tables where not all data is available locally. */
32
+ export interface ClipboardProxy {
33
+ cardinality: RegionCardinality;
34
+ /** Source row indices (for row/cell copies) */
35
+ rowIndices?: number[];
36
+ /** Source column keys (for column/cell copies) */
37
+ columnKeys?: string[];
38
+ /** The plain text written to the clipboard, used to verify the proxy
39
+ * is still valid on paste (i.e., clipboard hasn't been overwritten). */
40
+ text: string;
41
+ }
42
+
43
+ export interface DataSheetState<T> {
44
+ selection: Region[];
45
+ columnSpec: ColumnSpec[];
46
+ fillValueBaseCell: FocusedCellCoordinates | null;
47
+ focusedCell: FocusedCellCoordinates | null;
48
+ topLeftCell: FocusedCellCoordinates | null;
49
+ /**
50
+ * Set of row indices that have been added to the table,
51
+ * but not yet committed to the underlying data array.
52
+ *
53
+ * This is used to track which rows should be reverted when
54
+ * a "reset" action is performed.
55
+ */
56
+ rowStatus: TableElementStatus[];
57
+ // Sparse data structure for updated data
58
+ updatedData: T[];
59
+ initialized: boolean;
60
+ columnWidthsIndex: Map<string, number>;
61
+ /** Active column/table filters. Keys are filter IDs, values carry the
62
+ * filter definition and its current configuration state. */
63
+ activeFilters: Map<string, { filter: any; state: any }>;
64
+ /** Clipboard proxy from the last copy operation */
65
+ clipboardProxy: ClipboardProxy | null;
66
+ /** Visible row indices when filters are active. `null` means show all rows. */
67
+ filteredRowIndices: number[] | null;
68
+ /** Active column sort entries for client-side sorting. */
69
+ columnSorts: ColumnSort[];
70
+ }
71
+
72
+ type DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;
73
+ export type StateUpdater<T> = T[] | ((state: T[]) => T[]);
74
+
75
+ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
76
+ setSelection(selection: Region[]): void;
77
+ onDragValue(event: MouseEvent): void;
78
+ setUpdatedData(data: StateUpdater<T>): void;
79
+ onCellEdited(rowIndex: number, columnName: string, value: any): void;
80
+ onSelectionEdited(value: any): void;
81
+ onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
82
+ onColumnWidthChanged(columnIndex: number, newWidth: number): void;
83
+ moveFocusedCell(direction: "up" | "down" | "left" | "right"): void;
84
+ deleteSelectedRows(): void;
85
+ clearSelection(): void;
86
+ resetChanges(): void;
87
+ addRow(): void;
88
+ /** Activate or update a column/table filter.
89
+ * Filter is any object satisfying `TableFilter` from the actions module. */
90
+ setFilter(filterId: string, filter: any, filterState: any): void;
91
+ /** Remove a filter by ID */
92
+ removeFilter(filterId: string): void;
93
+ /** Remove all active filters */
94
+ clearFilters(): void;
95
+ /** Set or clear a column sort. Pass `null` for ascending to clear. */
96
+ setColumnSort(key: string, ascending: boolean | null): void;
97
+ /** Remove all active column sorts */
98
+ clearColumnSorts(): void;
99
+ /** Store a clipboard proxy for potential backend-mediated paste */
100
+ setClipboardProxy(proxy: ClipboardProxy | null): void;
101
+ initialize(props: Partial<DataSheetStoreMain<T>>): void;
102
+ onSelection(selection: Region[]): void;
103
+ // Internal method used for infinite scrolling
104
+ scrollToRow(rowIndex: number): void;
105
+ tableRef: React.MutableRefObject<Table2>;
106
+ columnWidthsIndex: Map<string, number>;
107
+ defaultColumnWidth: number;
108
+ }
109
+
110
+ export type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {
111
+ children: React.ReactNode;
112
+ columnSpecOptions?: ColumnSpecOptions<T>;
113
+ toaster?: OverlayToaster;
114
+ };
115
+
116
+ export interface VisibleCells {
117
+ rowIndexStart: number;
118
+ rowIndexEnd: number;
119
+ }
120
+
121
+ export type DataSheetStore<T> = DataSheetStoreMain<T>;
@@ -17,6 +17,17 @@ interface ColumnSpecGenerateOptions {
17
17
 
18
18
  const defaultWidthForValue = (val) => String(val).length * 8;
19
19
 
20
+ /** Inferred data type of a column, used to select appropriate
21
+ * sort/filter operators. */
22
+ export type ColumnDataType =
23
+ | "text"
24
+ | "string"
25
+ | "number"
26
+ | "integer"
27
+ | "boolean"
28
+ | "object"
29
+ | "array";
30
+
20
31
  export interface ColumnSpec {
21
32
  name: string;
22
33
  key: string;
@@ -24,6 +35,7 @@ export interface ColumnSpec {
24
35
  isValid?: (d: any) => boolean;
25
36
  transformValue?: (d: any) => any;
26
37
  valueRenderer?: (d: any) => string | React.ReactNode;
38
+ headerRenderer?: (d: any) => string | React.ReactNode;
27
39
  dataEditor?: any;
28
40
  cellComponent?: any;
29
41
  category?: string;
@@ -31,6 +43,21 @@ export interface ColumnSpec {
31
43
  inlineEditor?: boolean | React.ComponentType<any> | string | null;
32
44
  style?: React.CSSProperties;
33
45
  width?: number;
46
+ /** Column-specific table actions (TableAction[]). These appear in the
47
+ * actions toolbar when this column is part of the current selection. */
48
+ actions?: any[];
49
+ /** Column-specific table filters (TableFilter[]). These appear in the
50
+ * filter bar and apply to this column's values. */
51
+ filters?: any[];
52
+ /** Whether this column supports server-side sorting. */
53
+ sortable?: boolean;
54
+ /** Whether this column supports server-side filtering.
55
+ * Set to `true` for default operators, or provide a config object
56
+ * with a custom set of operators. */
57
+ filterable?: boolean | { operators?: string[] };
58
+ /** Inferred data type, used to select context-appropriate filter
59
+ * operators when `filterable` is `true` without explicit operators. */
60
+ dataType?: ColumnDataType;
34
61
  }
35
62
 
36
63
  export interface ColumnSpecOptions<T> {
@@ -89,6 +116,11 @@ export function generateDefaultColumnSpec<T>(
89
116
  type = "array";
90
117
  }
91
118
 
119
+ // Check if it is strictly a string, if so, we can explicitly mark it as text
120
+ if (type === "string") {
121
+ type = "text";
122
+ }
123
+
92
124
  if (types.has(key)) {
93
125
  if (types.get(key) !== type) {
94
126
  if (type === "number" && types.get(key) === "integer") {
@@ -118,11 +150,26 @@ export function generateDefaultColumnSpec<T>(
118
150
  );
119
151
  }
120
152
 
153
+ const dataType = (types.get(key) ?? "string") as ColumnDataType;
154
+
155
+ // Auto-infer sortable/filterable based on data type.
156
+ // Scalar types (string, number, integer, boolean) get sort/filter;
157
+ // complex types (object, array) do not.
158
+ const isScalar =
159
+ dataType === "text" ||
160
+ dataType === "string" ||
161
+ dataType === "number" ||
162
+ dataType === "integer" ||
163
+ dataType === "boolean";
164
+
121
165
  spec.push({
122
166
  name: key,
123
167
  key,
124
168
  valueRenderer: defaultRenderers[types.get(key)],
125
169
  width,
170
+ dataType,
171
+ sortable: isScalar,
172
+ filterable: isScalar,
126
173
  });
127
174
  }
128
175
  return spec;