@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,350 @@
1
+ import { RegionCardinality } from "@blueprintjs/table";
2
+ import type { TableAction, TableActionContext, CellEdit } from "./types";
3
+ import type { ClipboardProxy } from "../types.ts";
4
+
5
+ /** Serialize the current selection to tab-separated values.
6
+ * For full-row/column copies, includes a header row and produces
7
+ * a `ClipboardProxy` for potential backend-mediated paste. */
8
+ export function serializeSelectionToTSV<T>(ctx: TableActionContext<T>): {
9
+ text: string;
10
+ proxy?: ClipboardProxy;
11
+ } {
12
+ const { data, updatedData, columnSpec } = ctx;
13
+ const cardinality = ctx.selectionCardinality ?? RegionCardinality.FULL_TABLE;
14
+ const numRows = Math.max(data.length, updatedData.length);
15
+
16
+ let rowIndices: number[];
17
+ let columnKeys: string[];
18
+ let includeHeaders = false;
19
+
20
+ switch (cardinality) {
21
+ case RegionCardinality.CELLS:
22
+ rowIndices = ctx.getSelectedRowIndices();
23
+ columnKeys = ctx.getSelectedColumnKeys();
24
+ break;
25
+ case RegionCardinality.FULL_ROWS:
26
+ rowIndices = ctx.getSelectedRowIndices();
27
+ columnKeys = columnSpec.map((c) => c.key);
28
+ // TODO: include headers, but copy using proxy...
29
+ includeHeaders = false;
30
+ break;
31
+ case RegionCardinality.FULL_COLUMNS:
32
+ rowIndices = Array.from({ length: numRows }, (_, i) => i);
33
+ columnKeys = ctx.getSelectedColumnKeys();
34
+ includeHeaders = false;
35
+ break;
36
+ default:
37
+ rowIndices = Array.from({ length: numRows }, (_, i) => i);
38
+ columnKeys = columnSpec.map((c) => c.key);
39
+ includeHeaders = false;
40
+ break;
41
+ }
42
+
43
+ const rows: string[] = [];
44
+ if (includeHeaders) {
45
+ const headers = columnKeys.map((key) => {
46
+ const col = columnSpec.find((c) => c.key === key);
47
+ return col?.name ?? key;
48
+ });
49
+ rows.push(headers.join("\t"));
50
+ }
51
+
52
+ const selectedColumns = columnSpec.filter((d) => columnKeys.includes(d.key));
53
+
54
+ for (const i of rowIndices) {
55
+ const row = { ...data[i], ...updatedData[i] };
56
+ rows.push(
57
+ selectedColumns
58
+ .map((col) => {
59
+ const value = row[col.key];
60
+ return String(col.valueRenderer?.(value) ?? value ?? "");
61
+ })
62
+ .join("\t"),
63
+ );
64
+ }
65
+
66
+ const text = rows.join("\n");
67
+
68
+ // For full rows/columns, also create a proxy for backend-mediated paste
69
+ let proxy: ClipboardProxy | undefined;
70
+ if (
71
+ cardinality === RegionCardinality.FULL_ROWS ||
72
+ cardinality === RegionCardinality.FULL_COLUMNS
73
+ ) {
74
+ proxy = {
75
+ cardinality,
76
+ rowIndices:
77
+ cardinality === RegionCardinality.FULL_ROWS ? rowIndices : undefined,
78
+ columnKeys:
79
+ cardinality === RegionCardinality.FULL_COLUMNS ? columnKeys : undefined,
80
+ text,
81
+ };
82
+ }
83
+
84
+ return { text, proxy };
85
+ }
86
+
87
+ /** Parse tab-separated text into a 2D string array. */
88
+ function parseTSV(text: string): string[][] {
89
+ return text
90
+ .trim()
91
+ .split("\n")
92
+ .map((row) => row.split("\t"));
93
+ }
94
+
95
+ /** Copy the current selection to the clipboard as tab-separated text.
96
+ * For full-row/column copies, a `ClipboardProxy` is also stored in the
97
+ * table state, enabling backend-mediated paste in lazy-loaded tables. */
98
+ export const copyAction: TableAction = {
99
+ id: "copy",
100
+ name: "Copy",
101
+ icon: "clipboard",
102
+ targets: [
103
+ RegionCardinality.CELLS,
104
+ RegionCardinality.FULL_ROWS,
105
+ RegionCardinality.FULL_COLUMNS,
106
+ RegionCardinality.FULL_TABLE,
107
+ ],
108
+ requiresEditable: false,
109
+ async run(ctx) {
110
+ const { text, proxy } = serializeSelectionToTSV(ctx);
111
+ console.log("Copying text:", text);
112
+ await navigator.clipboard.writeText(text);
113
+ ctx.setClipboardProxy(proxy ?? null);
114
+ },
115
+ hotkey: "mod+c",
116
+ };
117
+
118
+ export const cutAction: TableAction = {
119
+ id: "cut",
120
+ name: "Cut",
121
+ icon: "clipboard",
122
+ targets: [
123
+ RegionCardinality.CELLS,
124
+ RegionCardinality.FULL_ROWS,
125
+ RegionCardinality.FULL_COLUMNS,
126
+ RegionCardinality.FULL_TABLE,
127
+ ],
128
+ requiresEditable: true,
129
+ async run(ctx) {
130
+ const { text, proxy } = serializeSelectionToTSV(ctx);
131
+ console.log("Cutting text:", text);
132
+ await navigator.clipboard.writeText(text);
133
+ ctx.setClipboardProxy(proxy ?? null);
134
+ ctx.clearSelection();
135
+ },
136
+ hotkey: "mod+x",
137
+ };
138
+
139
+ /** Describes the shape relationship between pasted data and the target region */
140
+ export enum PasteShape {
141
+ /** Data fits exactly into the target region */
142
+ EXACT = "exact",
143
+ /** Data is smaller than the target region in one or both dimensions */
144
+ SMALLER = "smaller",
145
+ /** Data is larger than the target region in one or both dimensions */
146
+ LARGER = "larger",
147
+ /** Pasting into a single cell — expand from that anchor */
148
+ SINGLE_CELL = "single-cell",
149
+ }
150
+
151
+ /** Determine the relationship between clipboard data shape and target region */
152
+ function getPasteShape(
153
+ parsed: string[][],
154
+ targetRows: number,
155
+ targetCols: number,
156
+ ): PasteShape {
157
+ if (targetRows === 1 && targetCols === 1) return PasteShape.SINGLE_CELL;
158
+ const dataRows = parsed.length;
159
+ const dataCols = Math.max(...parsed.map((r) => r.length));
160
+ if (dataRows === targetRows && dataCols === targetCols)
161
+ return PasteShape.EXACT;
162
+ if (dataRows <= targetRows && dataCols <= targetCols)
163
+ return PasteShape.SMALLER;
164
+ return PasteShape.LARGER;
165
+ }
166
+
167
+ /** Build cell edits for an Excel-style paste.
168
+ *
169
+ * Behavior by shape:
170
+ * - **SINGLE_CELL**: Paste the full clipboard grid anchored at the focused
171
+ * cell, expanding rightward and downward. Clips at table boundaries.
172
+ * - **EXACT**: Paste one-to-one into the selected region.
173
+ * - **SMALLER**: Tile (repeat) the clipboard data to fill the selection,
174
+ * matching Excel's behavior when the selection is an even multiple of the
175
+ * data. Otherwise, just paste once from the top-left of the selection.
176
+ * - **LARGER**: Truncate the data to fit the target selection. */
177
+ function buildPasteEdits(
178
+ parsed: string[][],
179
+ startRow: number,
180
+ startColIdx: number,
181
+ targetRowCount: number,
182
+ targetColCount: number,
183
+ shape: PasteShape,
184
+ ctx: TableActionContext,
185
+ ): CellEdit[] {
186
+ const dataRows = parsed.length;
187
+ const dataCols = Math.max(...parsed.map((r) => r.length));
188
+ const numDataRows = Math.max(ctx.data.length, ctx.updatedData.length);
189
+ const numCols = ctx.columnSpec.length;
190
+ const edits: CellEdit[] = [];
191
+
192
+ let pasteRows: number;
193
+ let pasteCols: number;
194
+
195
+ switch (shape) {
196
+ case PasteShape.SINGLE_CELL:
197
+ // Expand from the anchor cell; clip at table boundaries
198
+ pasteRows = Math.min(dataRows, numDataRows - startRow);
199
+ pasteCols = Math.min(dataCols, numCols - startColIdx);
200
+ break;
201
+ case PasteShape.EXACT:
202
+ pasteRows = targetRowCount;
203
+ pasteCols = targetColCount;
204
+ break;
205
+ case PasteShape.SMALLER:
206
+ // Tile to fill the selection if it's an even multiple
207
+ pasteRows = targetRowCount;
208
+ pasteCols = targetColCount;
209
+ break;
210
+ case PasteShape.LARGER:
211
+ // Truncate to fit
212
+ pasteRows = Math.min(dataRows, targetRowCount);
213
+ pasteCols = Math.min(dataCols, targetColCount);
214
+ break;
215
+ }
216
+
217
+ for (let r = 0; r < pasteRows; r++) {
218
+ const dataRow = startRow + r;
219
+ if (dataRow >= numDataRows) break;
220
+ // For SMALLER shape, wrap around the source data rows
221
+ const srcR = dataRows > 0 ? r % dataRows : 0;
222
+ const row = parsed[srcR];
223
+ if (row == null) continue;
224
+
225
+ for (let c = 0; c < pasteCols; c++) {
226
+ const colIdx = startColIdx + c;
227
+ if (colIdx >= numCols) break;
228
+ // Wrap around source columns for tiling
229
+ const srcC = dataCols > 0 ? c % dataCols : 0;
230
+ const value = row[srcC] ?? "";
231
+ edits.push({
232
+ rowIndex: dataRow,
233
+ columnKey: ctx.columnSpec[colIdx].key,
234
+ value,
235
+ });
236
+ }
237
+ }
238
+ return edits;
239
+ }
240
+
241
+ /** Paste tab-separated text from the clipboard into the table.
242
+ *
243
+ * Follows Excel-style paste semantics:
244
+ * - **Single-cell selection**: Anchors the paste at the focused cell and
245
+ * expands to accommodate the full clipboard data, clipping at table edges.
246
+ * - **Matching region**: Pastes one-to-one into the selected cells.
247
+ * - **Selection larger than data**: Tiles the data to fill the selection
248
+ * when the selection is an even multiple; otherwise pastes once from the
249
+ * top-left corner.
250
+ * - **Selection smaller than data**: Truncates the pasted data to fit.
251
+ *
252
+ * When a `ClipboardProxy` is stored and the clipboard text matches,
253
+ * the proxy metadata is available for consumers to detect same-table
254
+ * pastes and optionally delegate to the backend. */
255
+ export const pasteAction: TableAction = {
256
+ id: "paste",
257
+ name: "Paste",
258
+ icon: "bring-data",
259
+ hotkey: "mod+v",
260
+ targets: [
261
+ RegionCardinality.CELLS,
262
+ RegionCardinality.FULL_ROWS,
263
+ RegionCardinality.FULL_COLUMNS,
264
+ RegionCardinality.FULL_TABLE,
265
+ ],
266
+ requiresEditable: true,
267
+ async run(ctx) {
268
+ const text = await navigator.clipboard.readText();
269
+ if (!text) return;
270
+
271
+ const parsed = parseTSV(text);
272
+ if (parsed.length === 0) return;
273
+
274
+ const cardinality =
275
+ ctx.selectionCardinality ?? RegionCardinality.FULL_TABLE;
276
+ const numDataRows = Math.max(ctx.data.length, ctx.updatedData.length);
277
+ const numCols = ctx.columnSpec.length;
278
+
279
+ // Determine the target region
280
+ const rowIndices = ctx.getSelectedRowIndices();
281
+ const columnKeys = ctx.getSelectedColumnKeys();
282
+
283
+ let startRow: number;
284
+ let startColIdx: number;
285
+ let targetRowCount: number;
286
+ let targetColCount: number;
287
+
288
+ switch (cardinality) {
289
+ case RegionCardinality.CELLS: {
290
+ startRow = rowIndices[0] ?? 0;
291
+ startColIdx =
292
+ columnKeys.length > 0
293
+ ? ctx.columnSpec.findIndex((c) => c.key === columnKeys[0])
294
+ : 0;
295
+ targetRowCount = rowIndices.length;
296
+ targetColCount = columnKeys.length;
297
+ break;
298
+ }
299
+ case RegionCardinality.FULL_ROWS: {
300
+ startRow = rowIndices[0] ?? 0;
301
+ startColIdx = 0;
302
+ targetRowCount = rowIndices.length;
303
+ targetColCount = numCols;
304
+ break;
305
+ }
306
+ case RegionCardinality.FULL_COLUMNS: {
307
+ startRow = 0;
308
+ startColIdx =
309
+ columnKeys.length > 0
310
+ ? ctx.columnSpec.findIndex((c) => c.key === columnKeys[0])
311
+ : 0;
312
+ targetRowCount = numDataRows;
313
+ targetColCount = columnKeys.length;
314
+ break;
315
+ }
316
+ default: {
317
+ // FULL_TABLE
318
+ startRow = 0;
319
+ startColIdx = 0;
320
+ targetRowCount = numDataRows;
321
+ targetColCount = numCols;
322
+ break;
323
+ }
324
+ }
325
+
326
+ if (startColIdx < 0) startColIdx = 0;
327
+
328
+ const shape = getPasteShape(parsed, targetRowCount, targetColCount);
329
+ const edits = buildPasteEdits(
330
+ parsed,
331
+ startRow,
332
+ startColIdx,
333
+ targetRowCount,
334
+ targetColCount,
335
+ shape,
336
+ ctx,
337
+ );
338
+
339
+ if (edits.length > 0) {
340
+ ctx.editCells(edits);
341
+ }
342
+ },
343
+ };
344
+
345
+ /** Convenience array of clipboard-related actions. */
346
+ export const clipboardActions: TableAction[] = [
347
+ copyAction,
348
+ cutAction,
349
+ pasteAction,
350
+ ];
@@ -0,0 +1,150 @@
1
+ import {
2
+ Button,
3
+ ButtonGroup,
4
+ Menu,
5
+ MenuItem,
6
+ PopoverNext,
7
+ Tag,
8
+ } from "@blueprintjs/core";
9
+ import { useMemo, useState } from "react";
10
+ import h from "./toolbar.module.sass";
11
+ import { useSelector, useStoreAPI } from "../provider";
12
+ import { collectAllFilters } from "./selection";
13
+ import type { TableFilter } from "./types";
14
+
15
+ /** Bar showing active filters as interactive tags, with a button to
16
+ * add new filters from the available set (global + column-spec). */
17
+ export function FilterBar<T>({ filters = [] }: { filters?: TableFilter<T>[] }) {
18
+ const columnSpec = useSelector((state) => state.columnSpec);
19
+ const storeAPI = useStoreAPI();
20
+ const activeFilters = useSelector((state) => state.activeFilters);
21
+
22
+ const allFilters = useMemo(
23
+ () => collectAllFilters(filters, columnSpec),
24
+ [filters, columnSpec],
25
+ );
26
+
27
+ const activeIds = useMemo(() => new Set(activeFilters.keys()), [activeFilters]);
28
+
29
+ const availableFilters = useMemo(
30
+ () => allFilters.filter((f) => !activeIds.has(f.id)),
31
+ [allFilters, activeIds],
32
+ );
33
+
34
+ const hasActive = activeFilters.size > 0;
35
+
36
+ return h("div.filter-bar", [
37
+ h(
38
+ ButtonGroup,
39
+ { minimal: true },
40
+ Array.from(activeFilters.entries()).map(([id, entry]) =>
41
+ h(ActiveFilterChip, { key: id, filterId: id, entry }),
42
+ ),
43
+ ),
44
+ h.if(availableFilters.length > 0)(AddFilterPopover, {
45
+ filters: availableFilters,
46
+ }),
47
+ h.if(hasActive)(
48
+ Button,
49
+ {
50
+ minimal: true,
51
+ small: true,
52
+ icon: "cross",
53
+ onClick() {
54
+ storeAPI.getState().clearFilters();
55
+ },
56
+ },
57
+ "Clear filters",
58
+ ),
59
+ ]);
60
+ }
61
+
62
+ /** A single active filter displayed as a tag. Clicking opens a popover
63
+ * for reconfiguring the filter; the remove button deactivates it. */
64
+ function ActiveFilterChip<T>({
65
+ filterId,
66
+ entry,
67
+ }: {
68
+ filterId: string;
69
+ entry: { filter: TableFilter<T>; state: any };
70
+ }) {
71
+ const storeAPI = useStoreAPI();
72
+ const [configOpen, setConfigOpen] = useState(false);
73
+ const { filter, state: filterState } = entry;
74
+
75
+ const tag = h(
76
+ Tag,
77
+ {
78
+ icon: filter.icon ?? "filter",
79
+ onRemove() {
80
+ storeAPI.getState().removeFilter(filterId);
81
+ },
82
+ interactive: true,
83
+ intent: "primary",
84
+ onClick: filter.filterForm ? () => setConfigOpen(!configOpen) : undefined,
85
+ },
86
+ filter.name,
87
+ );
88
+
89
+ if (filter.filterForm == null) return tag;
90
+
91
+ return h(
92
+ PopoverNext,
93
+ {
94
+ isOpen: configOpen,
95
+ onClose: () => setConfigOpen(false),
96
+ content: h("div.filter-config", [
97
+ h.if(filter.description != null)("p.description", filter.description),
98
+ h(filter.filterForm, {
99
+ state: filterState,
100
+ setState(newState) {
101
+ storeAPI.getState().setFilter(filterId, filter, newState);
102
+ },
103
+ }),
104
+ ]),
105
+ placement: "bottom-start",
106
+ enforceFocus: false,
107
+ autoFocus: false,
108
+ },
109
+ tag,
110
+ );
111
+ }
112
+
113
+ /** Popover menu listing available (not-yet-active) filters. */
114
+ function AddFilterPopover<T>({
115
+ filters,
116
+ }: {
117
+ filters: TableFilter<T>[];
118
+ }) {
119
+ const storeAPI = useStoreAPI();
120
+
121
+ return h(
122
+ PopoverNext,
123
+ {
124
+ content: h(
125
+ Menu,
126
+ filters.map((f) =>
127
+ h(MenuItem, {
128
+ key: f.id,
129
+ text: f.name,
130
+ icon: f.icon ?? "filter",
131
+ onClick() {
132
+ storeAPI.getState().setFilter(f.id, f, f.defaultState);
133
+ },
134
+ }),
135
+ ),
136
+ ),
137
+ placement: "bottom-start",
138
+ },
139
+ h(
140
+ Button,
141
+ {
142
+ minimal: true,
143
+ small: true,
144
+ icon: "filter",
145
+ },
146
+ "Add filter",
147
+ ),
148
+ );
149
+ }
150
+
@@ -0,0 +1,6 @@
1
+ export * from "./types";
2
+ export * from "./selection";
3
+ export * from "./builtin";
4
+ export * from "./toolbar";
5
+ export * from "./clipboard";
6
+ export * from "./filters";