@macrostrat/data-sheet 4.1.0 → 4.2.0

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 (302) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -184
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -182
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -50
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -51
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/{table-controls.cjs → table-actions.cjs} +7 -24
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -19
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +36 -97
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +123 -181
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +92 -150
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +21 -4
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +5 -4
  121. package/dist/filters/operators.js +21 -4
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +129 -103
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +110 -84
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +77 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +37 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +22 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +68 -35
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +66 -33
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +40 -17
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +2 -2
  184. package/dist/renderers/column-header-cell.js +40 -17
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +123 -226
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -228
  214. package/src/actions/column-filter.ts +28 -63
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -20
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +53 -126
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +144 -306
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +38 -6
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +250 -181
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +34 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +36 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +146 -58
  251. package/src/renderers/column-header-cell.ts +51 -17
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +143 -236
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs.map +0 -1
  264. package/dist/actions/table-controls.js.map +0 -1
  265. package/dist/actions/toolbar.cjs +0 -246
  266. package/dist/actions/toolbar.cjs.map +0 -1
  267. package/dist/actions/toolbar.js.map +0 -1
  268. package/dist/actions/toolbar.module.sass.cjs +0 -27
  269. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  270. package/dist/actions/toolbar.module.sass.js +0 -25
  271. package/dist/actions/toolbar.module.sass.js.map +0 -1
  272. package/dist/cell-renderer.cjs.map +0 -1
  273. package/dist/cell-renderer.js.map +0 -1
  274. package/dist/components/view-info.cjs +0 -55
  275. package/dist/components/view-info.cjs.map +0 -1
  276. package/dist/components/view-info.js.map +0 -1
  277. package/dist/core.cjs.map +0 -1
  278. package/dist/core.d.ts +0 -113
  279. package/dist/core.js.map +0 -1
  280. package/dist/provider.cjs +0 -191
  281. package/dist/provider.cjs.map +0 -1
  282. package/dist/provider.d.ts +0 -25
  283. package/dist/provider.js +0 -189
  284. package/dist/provider.js.map +0 -1
  285. package/dist/table-updates/data-parameter.d.ts +0 -14
  286. package/dist/table-updates/filter.d.ts +0 -16
  287. package/dist/table-updates/index.d.ts +0 -19
  288. package/dist/utils/column-spec.cjs.map +0 -1
  289. package/dist/utils/column-spec.js.map +0 -1
  290. package/dist/utils/index.cjs +0 -9
  291. package/dist/utils/index.cjs.map +0 -1
  292. package/dist/utils/index.js +0 -9
  293. package/dist/utils/index.js.map +0 -1
  294. package/dist/zustand-store.cjs.map +0 -1
  295. package/dist/zustand-store.js.map +0 -1
  296. package/src/actions/filters.ts +0 -176
  297. package/src/components/actions.module.sass +0 -8
  298. package/src/provider.ts +0 -250
  299. package/src/table-updates/data-parameter.ts +0 -44
  300. package/src/table-updates/filter.ts +0 -124
  301. package/src/table-updates/index.ts +0 -239
  302. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -6,20 +6,19 @@ import {
6
6
  DS_ROW_ID,
7
7
  StateUpdater,
8
8
  TableElementStatus,
9
- VisibleCells,
10
9
  } from "./types.ts";
11
10
  import {
12
11
  type FocusedCellCoordinates,
13
12
  type Region,
14
13
  RegionCardinality,
15
14
  } from "@blueprintjs/table";
16
- import { range } from "./utils";
17
15
  import update, { Spec } from "immutability-helper";
18
16
  import {
19
17
  getSelectedColumnKeys,
20
18
  getSelectedRowIndices,
21
19
  getSelectionCardinality,
22
- } from "./actions";
20
+ range,
21
+ } from "../actions";
23
22
 
24
23
  /** Monotonic counter for synthetic ids on in-table-added rows. */
25
24
  let _addedRowCounter = 0;
@@ -32,6 +31,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
32
31
  rowStatus: [],
33
32
  rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,
34
33
  columnSpec: [],
34
+ deferColumnSpec: false,
35
35
  defaultColumnWidth: 150,
36
36
  editable: false,
37
37
  selection: [],
@@ -221,7 +221,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
221
221
  },
222
222
  resetChanges(regions?: Region[]) {
223
223
  // Reset the updated data to the initial data
224
- set((state) => resetChangesForSelection(state, regions));
224
+ set((state) => resetChangesForSelection(state, regions ?? []));
225
225
  get().onEdit?.({ type: "resetChanges" });
226
226
  },
227
227
  onColumnWidthChanged(columnIx: number, newWidth: number) {
@@ -273,8 +273,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
273
273
  }
274
274
  },
275
275
  clearSelection() {
276
- const edits: { rowIndex: number; column: string; value: any; row?: any }[] =
277
- [];
276
+ const edits: {
277
+ rowIndex: number;
278
+ column: string;
279
+ value: any;
280
+ row?: any;
281
+ }[] = [];
278
282
  set((state) => {
279
283
  // Delete all selected cells
280
284
  const { selection, updatedData, columnSpec, data } = state;
@@ -297,7 +301,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
297
301
  const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
298
302
  if (currentValue != null && currentValue !== "") {
299
303
  vals[key] = "";
300
- edits.push({ rowIndex: row, column: key, value: "", row: data[row] });
304
+ edits.push({
305
+ rowIndex: row,
306
+ column: key,
307
+ value: "",
308
+ row: data[row],
309
+ });
301
310
  }
302
311
  }
303
312
  let op = updatedData[row] == null ? "$set" : "$merge";
@@ -314,8 +323,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
314
323
  },
315
324
  onSelection(selection: Region[]) {
316
325
  set((state) => {
326
+ const isSameAsPrevSelection = selectionEquals(
327
+ selection,
328
+ state.selection,
329
+ );
317
330
  if (
318
- selectionEquals(selection, state.selection) &&
331
+ isSameAsPrevSelection &&
319
332
  singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode
320
333
  ) {
321
334
  // If the selection is the same as the current selection, remove the selection.
@@ -350,8 +363,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
350
363
  },
351
364
  onSelectionEdited(value: any) {
352
365
  // Apply the same value to all selected cells
353
- const edits: { rowIndex: number; column: string; value: any; row?: any }[] =
354
- [];
366
+ const edits: {
367
+ rowIndex: number;
368
+ column: string;
369
+ value: any;
370
+ row?: any;
371
+ }[] = [];
355
372
  set((state) => {
356
373
  const { selection, updatedData, columnSpec, editable } = state;
357
374
  if (!editable) return {};
@@ -368,7 +385,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
368
385
  for (const col of colRange) {
369
386
  const key = columnSpec[col].key;
370
387
  vals[key] = value;
371
- edits.push({ rowIndex: row, column: key, value, row: state.data[row] });
388
+ edits.push({
389
+ rowIndex: row,
390
+ column: key,
391
+ value,
392
+ row: state.data[row],
393
+ });
372
394
  }
373
395
  let op = updatedData[row] == null ? "$set" : "$merge";
374
396
  spec[row] = { [op]: vals };
@@ -547,7 +569,7 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
547
569
  let regions = selection.map((region) => {
548
570
  const { cols, rows } = region;
549
571
  // Get the first column (maybe should be the last)
550
- const [col] = cols;
572
+ const [col] = cols ?? [];
551
573
  return { cols: [col, col], rows };
552
574
  });
553
575
 
@@ -561,7 +583,7 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
561
583
  const spec = {};
562
584
  for (const region of regions) {
563
585
  const { rows } = region;
564
- for (const visibleRow of range(rows)) {
586
+ for (const visibleRow of range(rows ?? [])) {
565
587
  const row = toDataRowIndex(state, visibleRow);
566
588
  let op = updatedData[row] == null ? "$set" : "$merge";
567
589
  spec[row] = { [op]: { [key]: value } };
@@ -657,7 +679,7 @@ function resetChangesForSelection<T>(
657
679
  }
658
680
  // TODO: if we allow column addition/deletion, this will require more adjustment
659
681
  return {
660
- updatedData: update(updatedData, spec),
682
+ updatedData: update(updatedData, spec as any),
661
683
  ...emptySelection,
662
684
  };
663
685
  case RegionCardinality.FULL_ROWS:
@@ -1,17 +1,65 @@
1
- import {
1
+ import type {
2
2
  ColumnSpec,
3
3
  CellRenderContext,
4
4
  CellDetailContext,
5
- editorKeyHandlerAtom,
6
- validateCell,
7
- } from "./utils";
8
- import { DataSheetStore, TableElementStatus } from "./types.ts";
9
- import h from "./main.module.sass";
10
- import { ReactNode, useEffect, useRef, useState } from "react";
11
- import { EditorPopup, CellDetailModal } from "./components";
12
- import { singleFocusedCell } from "./zustand-store.ts";
5
+ DataSheetStore,
6
+ } from "../provider";
7
+ import { TableElementStatus } from "../provider";
8
+ import { editorKeyHandlerAtom, validateCell } from "../utils";
9
+ import h from "../main.module.sass";
10
+ import { memo, ReactNode, useEffect, useRef, useState } from "react";
11
+ import { EditorPopup, CellDetailModal } from "../components";
12
+ import { singleFocusedCell } from "../provider";
13
13
  import { Cell } from "@blueprintjs/table";
14
- import { ctx, useSelector } from "./provider.ts";
14
+ import { ctx, dragValueHandlerAtom, useSelector } from "../provider";
15
+ import { Intent } from "@blueprintjs/core";
16
+
17
+ /** Two validations are equivalent if they convey the same thing — so a fresh
18
+ * `validateCell` result object doesn't force a re-render when nothing changed. */
19
+ function validationEqual(a: any, b: any): boolean {
20
+ if (a === b) return true;
21
+ if (a == null || b == null) return a == b;
22
+ return a.severity === b.severity && a.message === b.message;
23
+ }
24
+
25
+ /** Memoize on the *fields* of `cellContext` (not its identity — it's rebuilt
26
+ * fresh each render), so an unchanged cell skips re-rendering. */
27
+ function cellContentsEqual(
28
+ a: { cellContext: CellRenderContext },
29
+ b: { cellContext: CellRenderContext },
30
+ ): boolean {
31
+ const x = a.cellContext;
32
+ const y = b.cellContext;
33
+ return (
34
+ x.column === y.column &&
35
+ x.value === y.value &&
36
+ x.row === y.row &&
37
+ x.rowIndex === y.rowIndex &&
38
+ x.colIndex === y.colIndex &&
39
+ x.isEdited === y.isEdited &&
40
+ x.isDeleted === y.isDeleted &&
41
+ x.status === y.status &&
42
+ validationEqual(x.validation, y.validation)
43
+ );
44
+ }
45
+
46
+ /** The rendered *content* of a read-only cell — the value renderer's output —
47
+ * memoized on the cell's own inputs. It is placed as the CHILD of a real
48
+ * Blueprint `Cell` (never a wrapper: Blueprint clones the returned `Cell` to
49
+ * position/size it, so the renderer must return a `Cell` directly). This lets a
50
+ * re-render from unrelated state — the focused cell moving, or a
51
+ * scroll-triggered data load that swaps the `data`/overlay arrays — reposition
52
+ * the lightweight `Cell` without re-running this (possibly heavy) value
53
+ * renderer; only cells whose own value/status changed re-render. */
54
+ const CellContent = memo(function CellContent({
55
+ cellContext,
56
+ }: {
57
+ cellContext: CellRenderContext;
58
+ }) {
59
+ const { value, column } = cellContext;
60
+ if (value == null || value === "") return null;
61
+ return column.valueRenderer?.(value, cellContext) ?? value;
62
+ }, cellContentsEqual);
15
63
 
16
64
  export function basicCellRenderer<T>(
17
65
  rowIndex: number,
@@ -41,7 +89,8 @@ export function basicCellRenderer<T>(
41
89
  const isDeleted = statusVal == TableElementStatus.DELETED;
42
90
  // Presentation for this row's status (deleted, or a consumer-defined status
43
91
  // like "omitted"), from the merged `rowStatusStyles`.
44
- const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;
92
+ const statusStyle =
93
+ statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;
45
94
 
46
95
  const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
47
96
  const loading = row == null;
@@ -52,56 +101,28 @@ export function basicCellRenderer<T>(
52
101
 
53
102
  const value: T | undefined =
54
103
  updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
55
- const isEmpty = value == null || value === "";
56
104
 
57
105
  const edited =
58
106
  updatedData[dataRowIndex]?.[col.key] != null ||
59
107
  state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
60
108
 
61
109
  // Validate the cell (skipped for deleted rows). Orthogonal to edit status.
62
- const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);
63
-
64
- // Context passed to custom renderers so they can render based on the
65
- // row/column position and cell status (and, with the editing API, write
66
- // edits back). `rowIndex` is the data-row index, stable under sort/filter.
67
- const cellContext: CellRenderContext<T> = {
68
- value,
69
- rowIndex: dataRowIndex,
70
- colIndex,
71
- column: col,
72
- row,
73
- isEdited: edited,
74
- isDeleted,
75
- status: statusVal,
76
- validation,
77
- };
78
-
79
- const _renderedValue = isEmpty
110
+ const validation = isDeleted
80
111
  ? null
81
- : (col.valueRenderer?.(value, cellContext) ?? value);
82
-
83
- // Clone so we never mutate the caller's column-spec style object, then layer
84
- // the row-status presentation (deleted → dimmed/struck-through by default;
85
- // consumer statuses supply their own `cellStyle`).
86
- let style = { ...(col.style ?? {}) };
87
-
88
- if (statusStyle?.cellStyle != null) {
89
- style = { ...style, ...statusStyle.cellStyle };
90
- }
112
+ : validateCell(col, value, row, dataRowIndex);
91
113
 
92
114
  const editable = (col.editable ?? state.editable) && !isDeleted;
115
+ const tableIsEditable = state.editable;
93
116
 
94
117
  // topLeftCell stores visible row indices, so compare with the visible rowIndex
95
118
  const topLeft =
96
119
  _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
97
120
 
98
- const tableIsEditable = state.editable;
99
-
100
121
  // Intent precedence: error > warning > row-status intent > edited. Validation
101
122
  // state overrides the edited-green so an edited-but-invalid cell reads as
102
123
  // invalid. A row's status intent (e.g. deleted → danger) outranks the
103
124
  // edited-green so status reads through even on an edited row.
104
- let intent: string | undefined;
125
+ let intent: Intent | undefined;
105
126
  if (validation?.severity === "error") {
106
127
  intent = "danger";
107
128
  } else if (validation?.severity === "warning") {
@@ -112,12 +133,70 @@ export function basicCellRenderer<T>(
112
133
  intent = "success";
113
134
  }
114
135
 
136
+ // One context object, assembled once and threaded through every path (fast,
137
+ // slow, focused). `rowIndex` is the data-row index, stable under sort/filter.
138
+ const cellContext: CellRenderContext<T> = {
139
+ value,
140
+ rowIndex: dataRowIndex,
141
+ colIndex,
142
+ column: col,
143
+ row,
144
+ isEdited: edited,
145
+ isDeleted,
146
+ status: statusVal,
147
+ validation,
148
+ };
149
+
150
+ // Only allocate a new style object when a row-status style must be layered on
151
+ // (deleted → dimmed/struck-through; consumer statuses supply their own
152
+ // `cellStyle`). The common case passes the column's own `style` straight
153
+ // through — no per-cell clone, and a stable identity that diffs cheaply.
154
+ // (Nothing downstream mutates `style`.)
155
+ const style =
156
+ statusStyle?.cellStyle != null
157
+ ? { ...col.style, ...statusStyle.cellStyle }
158
+ : col.style;
159
+
160
+ const detailPresentation =
161
+ col.cellDetail != null ? (col.detailPresentation ?? "popover") : null;
162
+
163
+ // Fast path — any non-focused cell whose *unfocused* appearance is just the
164
+ // value viewer (a plain Blueprint `Cell`). That's everything except a custom
165
+ // `cellComponent` (its own markup on every cell) and an *inline* `cellDetail`
166
+ // (a persistent in-cell surface). A `cellDetail` popover/modal or a
167
+ // `detailRenderer` only surfaces on the focused cell, so unfocused they show
168
+ // the value viewer too — and take the fast path. Return a real `Cell`
169
+ // (Blueprint clones it to position/size it) whose CHILD is the memoized
170
+ // content, so unrelated re-renders (focus moving, a data load that swaps the
171
+ // arrays) reposition the cheap `Cell` without re-running the value renderer.
172
+ const usesCustomCell =
173
+ col.cellComponent != null || detailPresentation === "inline";
174
+ if (!topLeft && !usesCustomCell) {
175
+ return h(
176
+ Cell,
177
+ {
178
+ intent,
179
+ loading,
180
+ //value,
181
+ style,
182
+ interactive: false,
183
+ //disabled: tableIsEditable && !editable,
184
+ },
185
+ h(CellContent, { cellContext }),
186
+ );
187
+ }
188
+
189
+ const isEmpty = value == null || value === "";
190
+
191
+ const _renderedValue: any = isEmpty
192
+ ? null
193
+ : (col.valueRenderer?.(value, cellContext) ?? value);
194
+
115
195
  const _Cell = col.cellComponent ?? Cell;
116
196
 
117
197
  // Only forward the render context to a custom cell component; the default
118
198
  // Blueprint Cell would spread unknown props onto the DOM.
119
- const cellComponentProps =
120
- col.cellComponent != null ? { cellContext } : {};
199
+ const cellComponentProps = col.cellComponent != null ? { cellContext } : {};
121
200
 
122
201
  // Allow a column to pick the editor per-cell (e.g. textarea only when the
123
202
  // value is long). A returned key overrides the static column field even
@@ -149,12 +228,12 @@ export function basicCellRenderer<T>(
149
228
  state.tableElement?.focus?.();
150
229
  },
151
230
  });
152
- const detailPresentation =
153
- col.cellDetail != null ? (col.detailPresentation ?? "popover") : null;
154
231
 
155
232
  if (!topLeft) {
156
- // An inline surface is a persistent in-cell renderer, so it draws on every
157
- // cell (read-only when not the focused/editing cell).
233
+ // Non-focused cell that took the slow path — a custom `cellComponent`, or a
234
+ // `cellDetail` / `detailRenderer` surface. An inline surface is a persistent
235
+ // in-cell renderer (read-only here); others show the value viewer. (The
236
+ // plain default-`Cell` case is handled by the memoized fast path above.)
158
237
  if (detailPresentation === "inline") {
159
238
  return h(
160
239
  _Cell,
@@ -269,10 +348,10 @@ export function basicCellRenderer<T>(
269
348
  );
270
349
  }
271
350
 
272
- let cellContents: ReactNode = _renderedValue;
351
+ let cellContents: any = _renderedValue;
273
352
 
274
- let _dataEditor = null;
275
- let className = null;
353
+ let _dataEditor: ReactNode = null;
354
+ let className: string | null = null;
276
355
 
277
356
  if (dataEditorSpec != null) {
278
357
  _dataEditor = h(
@@ -287,7 +366,12 @@ export function basicCellRenderer<T>(
287
366
  isEdited: edited,
288
367
  onChange(value) {
289
368
  if (!editable) return;
290
- state.onSelectionEdited(value);
369
+ // Commit to THIS cell — not the live selection. The editor can
370
+ // commit (e.g. on blur) after the selection has moved to another
371
+ // cell or a whole column; `onSelectionEdited` would then write the
372
+ // value to the wrong target (emptying it). `onCellEdited` addresses
373
+ // the editor's own data cell.
374
+ state.onCellEdited(dataRowIndex, col.key, value);
291
375
  },
292
376
  resetValue() {
293
377
  state.resetChanges();
@@ -330,7 +414,7 @@ export function basicCellRenderer<T>(
330
414
 
331
415
  let _inlineEditor: ReactNode = null;
332
416
  if (typeof inlineEditor == "boolean") {
333
- let _value = value;
417
+ let _value: any = value;
334
418
  if (
335
419
  typeof _renderedValue === "string" ||
336
420
  typeof _renderedValue === "number" ||
@@ -378,7 +462,7 @@ export function basicCellRenderer<T>(
378
462
  },
379
463
  [
380
464
  cellContents,
381
- h.if(editable && isSingleCellSelection)(DragHandle),
465
+ h.if(editable && isSingleCellSelection)(CornerDragHandle),
382
466
  //hiddenInput,
383
467
  ],
384
468
  );
@@ -416,9 +500,13 @@ function EditorInput(props) {
416
500
  });
417
501
  }
418
502
 
419
- function DragHandle() {
503
+ function CornerDragHandle() {
420
504
  // TODO: we might want to drag multiple columns in some cases
421
505
  // This should be on the last cell of a selection
422
- const onMouseDown = useSelector((state) => state.onDragValue);
423
- return h("div.corner-drag-handle", { onMouseDown });
506
+ const onDragValue = ctx.useValue(dragValueHandlerAtom);
507
+ if (onDragValue == null) return null;
508
+
509
+ return h("div.corner-drag-handle", {
510
+ onMouseDown: onDragValue,
511
+ });
424
512
  }
@@ -9,13 +9,13 @@
9
9
  import h from "@macrostrat/hyper";
10
10
  import { ColumnHeaderCell, RegionCardinality } from "@blueprintjs/table";
11
11
  import { Icon, Menu, MenuItem } from "@blueprintjs/core";
12
- import { ctx, tableActionsAtom, useStoreAPI } from "../provider";
13
- import { buildActionContext } from "../actions/selection";
14
- import type { ColumnSpec } from "../utils/column-spec";
12
+ import { ctx, tableActionsAtom, type ColumnSpec } from "../provider";
15
13
  import type {
16
14
  PostgrestColumnFilter,
17
15
  ColumnSortEntry,
18
16
  } from "../postgrest-table";
17
+ import { buildActionContext } from "../actions";
18
+ import { useMemo } from "react";
19
19
 
20
20
  export interface ColumnActionsConfig {
21
21
  activeSort?: ColumnSortEntry | null;
@@ -47,8 +47,21 @@ export function renderColumnHeaderCell({
47
47
  const hasCustomActions =
48
48
  Array.isArray((col as any).actions) && (col as any).actions.length > 0;
49
49
 
50
+ // A column may be pinned against drag-reordering via `reorderable: false`.
51
+ const enableColumnReordering = col.reorderable !== false;
52
+
50
53
  if (!isSortable && !isFilterable && !hasCustomActions) {
51
- return h(ColumnHeaderCell, { name: col.name });
54
+ return h(ColumnHeaderCell, {
55
+ name: col.name,
56
+ enableColumnReordering,
57
+ nameRenderer: () =>
58
+ h(ColumnHeaderName, {
59
+ col,
60
+ hasSortActive: false,
61
+ hasFilterActive: false,
62
+ activeSort: null,
63
+ }) as any,
64
+ });
52
65
  }
53
66
 
54
67
  // `activeFilter` is the active store entry targeting this column (any filter
@@ -58,21 +71,32 @@ export function renderColumnHeaderCell({
58
71
 
59
72
  return h(ColumnHeaderCell, {
60
73
  name: col.name,
74
+ enableColumnReordering,
61
75
  // Persistent interaction bar so the menu caret is always clickable — the
62
76
  // hover-triggered caret was blocked by the selection overlay when the
63
77
  // column was selected.
64
78
  enableColumnInteractionBar: true,
65
79
  nameRenderer: () =>
66
- h(ColumnHeaderName, { col, hasSortActive, hasFilterActive, activeSort }),
80
+ h(ColumnHeaderName, {
81
+ col,
82
+ hasSortActive,
83
+ hasFilterActive,
84
+ activeSort,
85
+ }) as any,
67
86
  menuRenderer: () => h(ColumnHeaderControls, { colIndex }),
68
87
  });
69
88
  }
70
89
 
71
- /** Column name with active sort/filter indicator icons. */
90
+ /** Column name with active sort/filter indicator icons. The column key is
91
+ * exposed as `data-column-key` so consumers can target a specific header from
92
+ * CSS (e.g. to tint a column) without a bespoke styling prop. */
72
93
  function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
73
94
  return h(
74
95
  "div",
75
- { style: { display: "flex", alignItems: "center", width: "100%" } },
96
+ {
97
+ "data-column-key": col.key,
98
+ style: { display: "flex", alignItems: "center", width: "100%" },
99
+ },
76
100
  [
77
101
  h(
78
102
  "span",
@@ -106,7 +130,7 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
106
130
  h.if(hasFilterActive)(Icon, {
107
131
  icon: "filter",
108
132
  size: 12,
109
- style: { color: "var(--intent-warning, #d99e0b)" },
133
+ style: { color: "var(--intent-primary, #2965cc)" },
110
134
  }),
111
135
  ],
112
136
  ),
@@ -119,21 +143,27 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
119
143
  * single-column selection context — so the header and toolbar render the same
120
144
  * sort/filter (and custom column) controls. */
121
145
  function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
122
- const storeAPI = useStoreAPI();
123
146
  const actions = ctx.useValue(tableActionsAtom);
147
+ const store = ctx.useStore();
124
148
 
125
149
  // Scope the action context to this column (as if it were the selection).
126
- const actionCtx = buildActionContext(
127
- {
128
- ...storeAPI.getState(),
129
- selection: [{ cols: [colIndex, colIndex], rows: undefined }],
130
- } as any,
131
- storeAPI.setState,
132
- );
150
+ const actionCtx = useMemo(() => {
151
+ return buildActionContext(store.get, store.set, {
152
+ singleColumn: colIndex,
153
+ });
154
+ }, [actions, colIndex, store]);
133
155
 
156
+ // Only actions *limited* to column scope belong in a column's dropdown —
157
+ // sort/filter and column-specific actions. Global actions (Save / Reset /
158
+ // Clear-selection, marked by a FULL_TABLE or "none" target) are confusing
159
+ // here, so they're excluded even though they nominally apply to columns too.
160
+ const isGlobal = (a: (typeof actions)[number]) =>
161
+ a.targets.includes(RegionCardinality.FULL_TABLE) ||
162
+ a.targets.includes("none" as any);
134
163
  const controls = actions.filter(
135
164
  (a) =>
136
165
  a.targets.includes(RegionCardinality.FULL_COLUMNS) &&
166
+ !isGlobal(a) &&
137
167
  (a.appliesTo?.(actionCtx) ?? true),
138
168
  );
139
169
 
@@ -145,7 +175,11 @@ function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
145
175
  .map((a, i) => {
146
176
  if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);
147
177
  if (a.render != null)
148
- return h("li.column-header-control", { key: a.id ?? i }, a.render(actionCtx));
178
+ return h(
179
+ "li.column-header-control",
180
+ { key: a.id ?? i },
181
+ a.render(actionCtx),
182
+ );
149
183
  return h(MenuItem, {
150
184
  key: a.id ?? i,
151
185
  icon: a.icon,
@@ -1 +1,2 @@
1
1
  export * from "./column-header-cell";
2
+ export * from "./cell-renderer";