@macrostrat/data-sheet 4.1.1 → 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 (303) hide show
  1. package/CHANGELOG.md +34 -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 -196
  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 -194
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -73
  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 -74
  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-actions.cjs +41 -0
  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 -23
  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} +37 -112
  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 -190
  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 -159
  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 +19 -2
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +4 -3
  121. package/dist/filters/operators.js +19 -2
  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 +128 -95
  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 +109 -76
  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 +73 -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} +36 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
  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} +65 -32
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +21 -13
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +3 -2
  184. package/dist/renderers/column-header-cell.js +20 -12
  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 +117 -229
  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 -245
  214. package/src/actions/column-filter.ts +28 -92
  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 -24
  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} +49 -150
  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} +145 -330
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +33 -3
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +244 -171
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +30 -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} +35 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
  251. package/src/renderers/column-header-cell.ts +21 -14
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +137 -239
  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 +0 -62
  264. package/dist/actions/table-controls.cjs.map +0 -1
  265. package/dist/actions/table-controls.js.map +0 -1
  266. package/dist/actions/toolbar.cjs +0 -260
  267. package/dist/actions/toolbar.cjs.map +0 -1
  268. package/dist/actions/toolbar.js.map +0 -1
  269. package/dist/actions/toolbar.module.sass.cjs +0 -27
  270. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  271. package/dist/actions/toolbar.module.sass.js +0 -25
  272. package/dist/actions/toolbar.module.sass.js.map +0 -1
  273. package/dist/cell-renderer.cjs.map +0 -1
  274. package/dist/cell-renderer.js.map +0 -1
  275. package/dist/components/view-info.cjs +0 -55
  276. package/dist/components/view-info.cjs.map +0 -1
  277. package/dist/components/view-info.js.map +0 -1
  278. package/dist/core.cjs.map +0 -1
  279. package/dist/core.d.ts +0 -117
  280. package/dist/core.js.map +0 -1
  281. package/dist/provider.cjs +0 -197
  282. package/dist/provider.cjs.map +0 -1
  283. package/dist/provider.d.ts +0 -26
  284. package/dist/provider.js +0 -195
  285. package/dist/provider.js.map +0 -1
  286. package/dist/table-updates/data-parameter.d.ts +0 -14
  287. package/dist/table-updates/filter.d.ts +0 -16
  288. package/dist/table-updates/index.d.ts +0 -19
  289. package/dist/utils/column-spec.cjs.map +0 -1
  290. package/dist/utils/column-spec.js.map +0 -1
  291. package/dist/utils/index.cjs +0 -9
  292. package/dist/utils/index.cjs.map +0 -1
  293. package/dist/utils/index.js +0 -9
  294. package/dist/utils/index.js.map +0 -1
  295. package/dist/zustand-store.cjs.map +0 -1
  296. package/dist/zustand-store.js.map +0 -1
  297. package/src/actions/filters.ts +0 -176
  298. package/src/components/actions.module.sass +0 -8
  299. package/src/provider.ts +0 -267
  300. package/src/table-updates/data-parameter.ts +0 -44
  301. package/src/table-updates/filter.ts +0 -124
  302. package/src/table-updates/index.ts +0 -239
  303. /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;
@@ -222,7 +221,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
222
221
  },
223
222
  resetChanges(regions?: Region[]) {
224
223
  // Reset the updated data to the initial data
225
- set((state) => resetChangesForSelection(state, regions));
224
+ set((state) => resetChangesForSelection(state, regions ?? []));
226
225
  get().onEdit?.({ type: "resetChanges" });
227
226
  },
228
227
  onColumnWidthChanged(columnIx: number, newWidth: number) {
@@ -274,8 +273,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
274
273
  }
275
274
  },
276
275
  clearSelection() {
277
- const edits: { rowIndex: number; column: string; value: any; row?: any }[] =
278
- [];
276
+ const edits: {
277
+ rowIndex: number;
278
+ column: string;
279
+ value: any;
280
+ row?: any;
281
+ }[] = [];
279
282
  set((state) => {
280
283
  // Delete all selected cells
281
284
  const { selection, updatedData, columnSpec, data } = state;
@@ -298,7 +301,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
298
301
  const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
299
302
  if (currentValue != null && currentValue !== "") {
300
303
  vals[key] = "";
301
- 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
+ });
302
310
  }
303
311
  }
304
312
  let op = updatedData[row] == null ? "$set" : "$merge";
@@ -315,8 +323,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
315
323
  },
316
324
  onSelection(selection: Region[]) {
317
325
  set((state) => {
326
+ const isSameAsPrevSelection = selectionEquals(
327
+ selection,
328
+ state.selection,
329
+ );
318
330
  if (
319
- selectionEquals(selection, state.selection) &&
331
+ isSameAsPrevSelection &&
320
332
  singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode
321
333
  ) {
322
334
  // If the selection is the same as the current selection, remove the selection.
@@ -351,8 +363,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
351
363
  },
352
364
  onSelectionEdited(value: any) {
353
365
  // Apply the same value to all selected cells
354
- const edits: { rowIndex: number; column: string; value: any; row?: any }[] =
355
- [];
366
+ const edits: {
367
+ rowIndex: number;
368
+ column: string;
369
+ value: any;
370
+ row?: any;
371
+ }[] = [];
356
372
  set((state) => {
357
373
  const { selection, updatedData, columnSpec, editable } = state;
358
374
  if (!editable) return {};
@@ -369,7 +385,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
369
385
  for (const col of colRange) {
370
386
  const key = columnSpec[col].key;
371
387
  vals[key] = value;
372
- 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
+ });
373
394
  }
374
395
  let op = updatedData[row] == null ? "$set" : "$merge";
375
396
  spec[row] = { [op]: vals };
@@ -548,7 +569,7 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
548
569
  let regions = selection.map((region) => {
549
570
  const { cols, rows } = region;
550
571
  // Get the first column (maybe should be the last)
551
- const [col] = cols;
572
+ const [col] = cols ?? [];
552
573
  return { cols: [col, col], rows };
553
574
  });
554
575
 
@@ -562,7 +583,7 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
562
583
  const spec = {};
563
584
  for (const region of regions) {
564
585
  const { rows } = region;
565
- for (const visibleRow of range(rows)) {
586
+ for (const visibleRow of range(rows ?? [])) {
566
587
  const row = toDataRowIndex(state, visibleRow);
567
588
  let op = updatedData[row] == null ? "$set" : "$merge";
568
589
  spec[row] = { [op]: { [key]: value } };
@@ -658,7 +679,7 @@ function resetChangesForSelection<T>(
658
679
  }
659
680
  // TODO: if we allow column addition/deletion, this will require more adjustment
660
681
  return {
661
- updatedData: update(updatedData, spec),
682
+ updatedData: update(updatedData, spec as any),
662
683
  ...emptySelection,
663
684
  };
664
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(
@@ -335,7 +414,7 @@ export function basicCellRenderer<T>(
335
414
 
336
415
  let _inlineEditor: ReactNode = null;
337
416
  if (typeof inlineEditor == "boolean") {
338
- let _value = value;
417
+ let _value: any = value;
339
418
  if (
340
419
  typeof _renderedValue === "string" ||
341
420
  typeof _renderedValue === "number" ||
@@ -383,7 +462,7 @@ export function basicCellRenderer<T>(
383
462
  },
384
463
  [
385
464
  cellContents,
386
- h.if(editable && isSingleCellSelection)(DragHandle),
465
+ h.if(editable && isSingleCellSelection)(CornerDragHandle),
387
466
  //hiddenInput,
388
467
  ],
389
468
  );
@@ -421,9 +500,13 @@ function EditorInput(props) {
421
500
  });
422
501
  }
423
502
 
424
- function DragHandle() {
503
+ function CornerDragHandle() {
425
504
  // TODO: we might want to drag multiple columns in some cases
426
505
  // This should be on the last cell of a selection
427
- const onMouseDown = useSelector((state) => state.onDragValue);
428
- 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
+ });
429
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;
@@ -60,7 +60,7 @@ export function renderColumnHeaderCell({
60
60
  hasSortActive: false,
61
61
  hasFilterActive: false,
62
62
  activeSort: null,
63
- }),
63
+ }) as any,
64
64
  });
65
65
  }
66
66
 
@@ -77,7 +77,12 @@ export function renderColumnHeaderCell({
77
77
  // column was selected.
78
78
  enableColumnInteractionBar: true,
79
79
  nameRenderer: () =>
80
- h(ColumnHeaderName, { col, hasSortActive, hasFilterActive, activeSort }),
80
+ h(ColumnHeaderName, {
81
+ col,
82
+ hasSortActive,
83
+ hasFilterActive,
84
+ activeSort,
85
+ }) as any,
81
86
  menuRenderer: () => h(ColumnHeaderControls, { colIndex }),
82
87
  });
83
88
  }
@@ -138,17 +143,15 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
138
143
  * single-column selection context — so the header and toolbar render the same
139
144
  * sort/filter (and custom column) controls. */
140
145
  function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
141
- const storeAPI = useStoreAPI();
142
146
  const actions = ctx.useValue(tableActionsAtom);
147
+ const store = ctx.useStore();
143
148
 
144
149
  // Scope the action context to this column (as if it were the selection).
145
- const actionCtx = buildActionContext(
146
- {
147
- ...storeAPI.getState(),
148
- selection: [{ cols: [colIndex, colIndex], rows: undefined }],
149
- } as any,
150
- storeAPI.setState,
151
- );
150
+ const actionCtx = useMemo(() => {
151
+ return buildActionContext(store.get, store.set, {
152
+ singleColumn: colIndex,
153
+ });
154
+ }, [actions, colIndex, store]);
152
155
 
153
156
  // Only actions *limited* to column scope belong in a column's dropdown —
154
157
  // sort/filter and column-specific actions. Global actions (Save / Reset /
@@ -172,7 +175,11 @@ function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
172
175
  .map((a, i) => {
173
176
  if (a.renderMenuItem != null) return a.renderMenuItem(actionCtx);
174
177
  if (a.render != null)
175
- 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
+ );
176
183
  return h(MenuItem, {
177
184
  key: a.id ?? i,
178
185
  icon: a.icon,
@@ -1 +1,2 @@
1
1
  export * from "./column-header-cell";
2
+ export * from "./cell-renderer";