@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
@@ -1,10 +1,9 @@
1
1
  export * from "./types";
2
2
  export * from "./selection";
3
3
  export * from "./builtin";
4
- export * from "./toolbar";
5
4
  export * from "./clipboard";
6
- export * from "./filters";
7
5
  export * from "./column-controls";
8
6
  export * from "./edit-actions";
9
7
  export * from "./column-filter";
10
- export * from "./table-controls";
8
+ export * from "./table-actions.ts";
9
+ export * from "./context.ts";
@@ -1,18 +1,82 @@
1
1
  import { type Region, RegionCardinality } from "@blueprintjs/table";
2
- import type { ColumnSpec } from "../utils";
3
- import type {
4
- CellEdit,
5
- SelectionShape,
6
- TableAction,
7
- TableActionContext,
8
- TableFilter,
9
- } from "./types";
10
- import type { DataSheetStore } from "../types";
11
- import { columnFilter } from "./column-filter";
12
- import update from "immutability-helper";
2
+ import type { ColumnSpec } from "../provider";
3
+ import type { TableAction } from "./types";
4
+ import { RefObject } from "react";
5
+ import { SelectModifiers } from "../data-panel.ts";
6
+
7
+ export function buildDataViewSelection(
8
+ // index of selected item
9
+ index: number,
10
+ mods: SelectModifiers,
11
+ selection: Region[],
12
+ anchorRef: RefObject<number | null>,
13
+ enableMultipleSelection: boolean,
14
+ ): Region[] {
15
+ /** Build the selection for data views */
16
+ const current = new Set(getSelectedRowIndices(selection));
17
+ let next: Set<number>;
18
+
19
+ const isSingleSelect = current.size === 1;
20
+ const isCurrentlySelected = current.has(index);
21
+
22
+ if (!enableMultipleSelection) {
23
+ // Simpler path for single selection
24
+ next = new Set();
25
+ if (!isCurrentlySelected) {
26
+ next.add(index);
27
+ }
28
+ return rowIndicesToRegions(next);
29
+ }
30
+ // multiple selection
31
+ if (isSingleSelect && isCurrentlySelected && !mods.additive && !mods.range) {
32
+ // Clicking the only selected row with no modifiers clears the selection.
33
+ next = new Set();
34
+ } else if (mods.range && anchorRef.current != null) {
35
+ // We have a range select and an anchor: select the range between the anchor and the clicked row.
36
+ const a = anchorRef.current;
37
+ const [lo, hi] = a <= index ? [a, index] : [index, a];
38
+ // Shift extends the existing selection when combined with cmd/ctrl,
39
+ // otherwise replaces it with the range. The anchor stays put so the
40
+ // range can be re-dragged from the same origin.
41
+ next = mods.additive ? new Set(current) : new Set();
42
+ for (let i = lo; i <= hi; i++) next.add(i);
43
+ } else if (mods.additive) {
44
+ // We are adding or removing to the selection with the ctrl key
45
+ next = new Set(current);
46
+ if (next.has(index)) next.delete(index);
47
+ else next.add(index);
48
+ anchorRef.current = index;
49
+ } else {
50
+ next = new Set([index]);
51
+ anchorRef.current = index;
52
+ }
53
+
54
+ return rowIndicesToRegions(next);
55
+ }
56
+
57
+ /** Collapse a set of selected row indices into `FULL_ROWS` regions, merging
58
+ * contiguous runs into a single `{ rows: [start, end] }` range. */
59
+ export function rowIndicesToRegions(indices: Set<number>): Region[] {
60
+ const sorted = Array.from(indices).sort((a, b) => a - b);
61
+ const regions: Region[] = [];
62
+ let start: number | null = null;
63
+ let prev: number | null = null;
64
+ for (const i of sorted) {
65
+ if (start == null) {
66
+ start = prev = i;
67
+ } else if (i === prev! + 1) {
68
+ prev = i;
69
+ } else {
70
+ regions.push({ rows: [start, prev!] });
71
+ start = prev = i;
72
+ }
73
+ }
74
+ if (start != null) regions.push({ rows: [start, prev!] });
75
+ return regions;
76
+ }
13
77
 
14
78
  /** Derive the selection cardinality from the current set of selected regions.
15
- * Returns "none" when there is no active selection. */
79
+ * Returns "null" when there is no active selection. */
16
80
  export function getSelectionCardinality(
17
81
  regions: Region[],
18
82
  ): RegionCardinality | null {
@@ -26,16 +90,39 @@ export function getSelectionCardinality(
26
90
  return RegionCardinality.FULL_TABLE;
27
91
  }
28
92
 
93
+ /** Selection cardinality including the case of no active selection */
94
+ export type SelectionCardinality = RegionCardinality | "none";
95
+
96
+ /** The concrete *shape* of the current selection — richer than cardinality
97
+ * alone. The "single X" cases are exposed as resolved identity fields on the
98
+ * action context (`columnKey`, `rowIndex`, `cell`); this carries the counts. */
99
+ export interface SelectionShape {
100
+ cardinality: SelectionCardinality;
101
+ /** Number of columns the selection spans (0 when not column-scoped). */
102
+ columns: number;
103
+ /** Number of rows the selection spans (0 when not row-scoped). */
104
+ rows: number;
105
+ }
106
+
29
107
  /** Compute the concrete shape of a selection (cardinality + column/row spans). */
30
108
  export function computeSelectionShape(regions: Region[]): SelectionShape {
31
109
  const cardinality = getSelectionCardinality(regions) ?? "none";
32
- const region = regions?.[0];
33
- const cols = region?.cols;
34
- const rows = region?.rows;
110
+ let columns = 0;
111
+ let rows = 0;
112
+ for (const region of regions) {
113
+ const c = region.cols;
114
+ if (c != null) {
115
+ columns += c[1] - c[0] + 1;
116
+ }
117
+ const r = region.rows;
118
+ if (r != null) {
119
+ rows += r[1] - r[0] + 1;
120
+ }
121
+ }
35
122
  return {
36
123
  cardinality,
37
- columns: cols != null ? cols[1] - cols[0] + 1 : 0,
38
- rows: rows != null ? rows[1] - rows[0] + 1 : 0,
124
+ columns,
125
+ rows,
39
126
  };
40
127
  }
41
128
 
@@ -47,7 +134,7 @@ export function getApplicableActions<T>(
47
134
  editable: boolean,
48
135
  ): TableAction<T>[] {
49
136
  return actions.filter((action) => {
50
- if (action.requiresEditable !== false && !editable) return false;
137
+ if (action.requiresEditable && !editable) return false;
51
138
  return action.targets.includes(cardinality);
52
139
  });
53
140
  }
@@ -96,119 +183,6 @@ export function getSelectedColumnKeys(
96
183
  return Array.from(keys);
97
184
  }
98
185
 
99
- /** Construct a `TableActionContext` from the current store state.
100
- * Call this at action-run time (not render time) to ensure
101
- * the context reflects the latest state.
102
- * @param setState - Optional store setState for direct mutation. Omit for
103
- * read-only contexts (e.g., disabled checks). */
104
- export function buildActionContext<T>(
105
- state: DataSheetStore<T>,
106
- setState: (partial: Record<string, any>) => void = () => {},
107
- ): TableActionContext<T> {
108
- // Lazy-compute filteredRowIndices to avoid cost during disabled checks
109
- let _filteredRowIndices: number[] | null | undefined = undefined;
110
- function getFilteredRowIndices(): number[] | null {
111
- if (_filteredRowIndices === undefined) {
112
- _filteredRowIndices = computeFilteredRowIndices(
113
- state.data,
114
- state.updatedData,
115
- state.activeFilters,
116
- );
117
- }
118
- return _filteredRowIndices;
119
- }
120
-
121
- const shape = computeSelectionShape(state.selection);
122
-
123
- return {
124
- selection: state.selection,
125
- selectionCardinality: getSelectionCardinality(state.selection),
126
- selectionShape: shape,
127
- // Resolved single-target identity (lazy — mapping rows through filters is
128
- // only paid when accessed).
129
- get columnKey() {
130
- return shape.columns === 1
131
- ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)
132
- : null;
133
- },
134
- get rowIndex() {
135
- return shape.rows === 1
136
- ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
137
- null)
138
- : null;
139
- },
140
- get cell() {
141
- if (
142
- shape.cardinality !== RegionCardinality.CELLS ||
143
- shape.columns !== 1 ||
144
- shape.rows !== 1
145
- ) {
146
- return null;
147
- }
148
- const columnKey =
149
- getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;
150
- const rowIndex =
151
- getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
152
- null;
153
- return columnKey != null && rowIndex != null
154
- ? { rowIndex, columnKey }
155
- : null;
156
- },
157
- data: state.data,
158
- updatedData: state.updatedData,
159
- rowStatus: state.rowStatus,
160
- columnSpec: state.columnSpec,
161
- editable: state.editable,
162
- canDeleteRows: state.canDeleteRows,
163
- getSelectedRowIndices: () =>
164
- getSelectedRowIndices(state.selection, getFilteredRowIndices()),
165
- getSelectedColumnKeys: () =>
166
- getSelectedColumnKeys(state.selection, state.columnSpec),
167
- onCellEdited: state.onCellEdited,
168
- editCells(edits: CellEdit[]) {
169
- state.setUpdatedData((updatedData: T[]) => {
170
- const spec: Record<number, any> = {};
171
- for (const e of edits) {
172
- const rowIndex = e.rowIndex;
173
- const columnKey = (e as any).columnKey ?? e.column;
174
- if (spec[rowIndex] == null) {
175
- const op = updatedData[rowIndex] != null ? "$merge" : "$set";
176
- spec[rowIndex] = { [op]: {} };
177
- }
178
- const opKey = Object.keys(spec[rowIndex])[0];
179
- spec[rowIndex][opKey][columnKey] = e.value;
180
- }
181
- return update(updatedData, spec);
182
- });
183
- // Emit a structured edit event so controlled consumers capture programmatic
184
- // batch edits (clipboard paste, fill) the same as inline edits.
185
- state.onEdit?.({
186
- type: "setCells",
187
- cells: edits.map((e) => ({
188
- rowIndex: e.rowIndex,
189
- column: (e as any).columnKey ?? e.column,
190
- value: e.value,
191
- row: state.data[e.rowIndex],
192
- })),
193
- });
194
- },
195
- deleteSelectedRows: state.deleteSelectedRows,
196
- addRow: state.addRow,
197
- setUpdatedData: state.setUpdatedData,
198
- resetChanges: state.resetChanges,
199
- clearSelection: state.clearSelection,
200
- scrollToRow: state.scrollToRow,
201
- setState,
202
- clipboardProxy: state.clipboardProxy,
203
- setClipboardProxy(proxy) {
204
- state.setClipboardProxy(proxy);
205
- },
206
- get filteredRowIndices() {
207
- return getFilteredRowIndices();
208
- },
209
- };
210
- }
211
-
212
186
  /** Compute which data row indices are visible given the active filters.
213
187
  * Returns `null` when no filters are active (all rows visible). */
214
188
  export function computeFilteredRowIndices<T>(
@@ -263,29 +237,8 @@ export function mergeColumnActions<T>(
263
237
  return [...globalActions, ...columnActions];
264
238
  }
265
239
 
266
- /** Collect all available filters from global filters and column specs. */
267
- export function collectAllFilters<T>(
268
- globalFilters: TableFilter<T>[],
269
- columnSpec: ColumnSpec[],
270
- ): TableFilter<T>[] {
271
- const result: TableFilter<T>[] = [...globalFilters];
272
- for (const col of columnSpec) {
273
- if (col.filters != null) {
274
- for (const f of col.filters as TableFilter<T>[]) {
275
- const withKey: TableFilter<T> = {
276
- ...f,
277
- columnKey: f.columnKey ?? col.key,
278
- };
279
- if (!result.some((r) => r.id === withKey.id)) {
280
- result.push(withKey);
281
- }
282
- }
283
- }
284
- // Auto-generate the built-in operator filter for a `filterable` column,
285
- // unless the column already supplies an explicit filter.
286
- if (col.filterable && !result.some((r) => r.columnKey === col.key)) {
287
- result.push(columnFilter(col) as TableFilter<T>);
288
- }
289
- }
290
- return result;
240
+ export function range(arr: number[]) {
241
+ if (arr.length != 2) throw new Error("Range must have two elements");
242
+ const [start, end] = arr;
243
+ return Array.from({ length: end - start + 1 }, (_, i) => i + start);
291
244
  }
@@ -7,7 +7,6 @@
7
7
  import h from "@macrostrat/hyper";
8
8
  import { useState } from "react";
9
9
  import { Button, ControlGroup, InputGroup } from "@blueprintjs/core";
10
- import { RegionCardinality } from "@blueprintjs/table";
11
10
  import { useSelector } from "../provider";
12
11
  import type { TableAction } from "./types";
13
12
  import { ALL_CARDINALITIES } from "./edit-actions";
@@ -35,25 +34,6 @@ function ScrollToRowControl() {
35
34
  ]);
36
35
  }
37
36
 
38
- /** Clear the current selection. Auto-included: appears (on the right, being a
39
- * general action) whenever something is selected — targets every cardinality
40
- * except `"none"`. */
41
- export const clearSelectionAction: TableAction = {
42
- id: "clear-selection",
43
- name: "Clear selection",
44
- icon: "cross",
45
- requiresEditable: false,
46
- targets: [
47
- RegionCardinality.CELLS,
48
- RegionCardinality.FULL_ROWS,
49
- RegionCardinality.FULL_COLUMNS,
50
- RegionCardinality.FULL_TABLE,
51
- ],
52
- run(ctx) {
53
- ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });
54
- },
55
- };
56
-
57
37
  /** Scroll to a 1-based row number. Meaningful for large, addressable sources;
58
38
  * add it to `actions`. Present in the toolbar regardless of selection. */
59
39
  export const scrollToRowAction: TableAction = {
@@ -1,32 +1,7 @@
1
1
  import type { IconName, Intent } from "@blueprintjs/core";
2
- import type { Region, RegionCardinality } from "@blueprintjs/table";
3
2
  import type { ComponentType, ReactNode } from "react";
4
- import type { ColumnSpec } from "../utils";
5
- import { ClipboardProxy, TableElementStatus } from "../types.ts";
6
-
7
- /** Selection cardinality including the case of no active selection */
8
- export type SelectionCardinality = RegionCardinality | "none";
9
-
10
- /** The concrete *shape* of the current selection — richer than cardinality
11
- * alone. The "single X" cases are exposed as resolved identity fields on the
12
- * action context (`columnKey`, `rowIndex`, `cell`); this carries the counts. */
13
- export interface SelectionShape {
14
- cardinality: SelectionCardinality;
15
- /** Number of columns the selection spans (0 when not column-scoped). */
16
- columns: number;
17
- /** Number of rows the selection spans (0 when not row-scoped). */
18
- rows: number;
19
- }
20
-
21
- /** A single cell edit, used with `editCells` for batch updates. */
22
- export interface CellEdit {
23
- rowIndex: number;
24
- column: string;
25
- value: any;
26
- /** The underlying row (base data). Populated on emitted `onEdit` events so a
27
- * handler can address the row (identity) without reaching into the store. */
28
- row?: any;
29
- }
3
+ import { SelectionCardinality } from "./selection.ts";
4
+ import { TableActionContext } from "./context.ts";
30
5
 
31
6
  /** A column filter that can be activated to hide non-matching rows.
32
7
  * Parallel to `TableAction` but with persistent state while active.
@@ -54,91 +29,32 @@ export interface TableFilter<T = any, S = any> {
54
29
  /** Summarize the current filter state for display on the active-filter tag
55
30
  * (e.g. the range `0–250` or the search term). Keep it short — the tag also
56
31
  * shows the filter name. Return `null` to show just the name. */
57
- describeState?: (state: S) => import("react").ReactNode;
32
+ describeState?: (state: S) => ReactNode;
33
+ /** The entity (e.g., a column) being described. */
34
+ subject?: string;
58
35
  /** Row predicate: return `true` if the row should be visible.
59
36
  * Receives the merged row (updatedData overlaid on data). */
60
37
  predicate(row: T, state: S): boolean;
61
38
  }
62
39
 
40
+ export interface ColumnFilter<T = any, S = any> extends Omit<
41
+ TableFilter<T, S>,
42
+ "columnKey"
43
+ > {
44
+ columnKey: string;
45
+ }
46
+
47
+ export type ColumnFilterOptions<T = any, S = any> = Omit<
48
+ ColumnFilter<T, S>,
49
+ "columnKey" | "subject" | "name"
50
+ > & { name?: string };
51
+
63
52
  /** An active filter entry stored in the table state. */
64
53
  export interface ActiveFilterEntry<T = any> {
65
54
  filter: TableFilter<T>;
66
55
  state: any;
67
56
  }
68
57
 
69
- // Re-export ColumnSort from the main types module (defined there to
70
- // avoid a circular import, since actions/types imports from types.ts).
71
- export type { ColumnSort } from "../types.ts";
72
-
73
- /** Context passed to an action's `run` function, providing both data access
74
- * and store manipulation methods. Constructed fresh at action-run time
75
- * to ensure current state. */
76
- export interface TableActionContext<T = any> {
77
- /** Current selection regions */
78
- selection: Region[];
79
- /** Derived cardinality of the current selection */
80
- selectionCardinality: SelectionCardinality;
81
- /** Concrete shape of the current selection (cardinality + column/row counts). */
82
- selectionShape: SelectionShape;
83
- /** The single selected column's key when exactly one column is scoped
84
- * (a single full column, or cells within one column); otherwise `null`. */
85
- columnKey: string | null;
86
- /** The single selected data-row index when exactly one row is scoped;
87
- * otherwise `null`. */
88
- rowIndex: number | null;
89
- /** The single selected cell (data-row index + column key) when exactly one
90
- * cell is selected; otherwise `null`. Presence of these resolved fields is
91
- * how actions discriminate selection shape — e.g. `appliesTo: ctx =>
92
- * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`
93
- * within a `FULL_COLUMNS` target for a single-column control. */
94
- cell: { rowIndex: number; columnKey: string } | null;
95
- /** The table's base data */
96
- data: T[];
97
- /** Sparse overlay of edited data */
98
- updatedData: T[];
99
- /** Row status tracking added/deleted rows */
100
- rowStatus: TableElementStatus[];
101
- /** Column definitions */
102
- columnSpec: ColumnSpec[];
103
- /** Whether the table is in edit mode */
104
- editable: boolean;
105
- /** Whether row deletion is available (false when the provider can't delete). */
106
- canDeleteRows: boolean;
107
-
108
- // Convenience methods (derived from selection)
109
- /** Row indices covered by the current selection */
110
- getSelectedRowIndices(): number[];
111
- /** Column keys covered by the current selection */
112
- getSelectedColumnKeys(): string[];
113
-
114
- // Store manipulation methods
115
- onCellEdited(rowIndex: number, columnKey: string, value: any): void;
116
- /** Edit multiple cells in a single batch update. Preferred over calling
117
- * `onCellEdited` in a loop, which triggers separate store updates
118
- * and may produce inconsistent intermediate states. */
119
- editCells(edits: CellEdit[]): void;
120
- deleteSelectedRows(): void;
121
- addRow(row?: Partial<T>): void;
122
- setUpdatedData(data: any): void;
123
- resetChanges(region?: Region[]): void;
124
- clearSelection(): void;
125
- scrollToRow(rowIndex: number): void;
126
- /** Direct store mutation for cases not covered by the convenience methods
127
- * above (e.g., modifying `columnSpec` or `deletedRows`). */
128
- setState(partial: Record<string, any>): void;
129
-
130
- // Clipboard proxy support
131
- /** Active clipboard proxy from a prior copy, if any */
132
- clipboardProxy: ClipboardProxy | null;
133
- /** Store a clipboard proxy for potential backend-mediated paste */
134
- setClipboardProxy(proxy: ClipboardProxy | null): void;
135
-
136
- // Filter support
137
- /** Row index mapping when filters are active. When non-null,
138
- * visible row `i` maps to data row `filteredRowIndices[i]`. */
139
- filteredRowIndices: number[] | null;
140
- }
141
-
142
58
  /** Definition of a table action. Follows the `ActionDef` pattern from
143
59
  * `@macrostrat/form-components` with table-specific extensions.
144
60
  *
@@ -21,7 +21,7 @@ export function ColorCell({
21
21
  const darkMode = useInDarkMode();
22
22
  const _className = classNames(className, "color-cell");
23
23
  const _style = useMemo(() => {
24
- let mainColor = "var(--text-color)";
24
+ let mainColor: string | undefined = "var(--text-color)";
25
25
  let backgroundColor = value;
26
26
 
27
27
  if (adjustLuminance) {
@@ -2,4 +2,5 @@ export * from "./editor-popup";
2
2
  export * from "./cell-detail";
3
3
  export * from "./colors";
4
4
  export * from "./text-areas";
5
- export { LoadProgressIndicator } from "./view-info.ts";
5
+ export * from "./indicators";
6
+ export * from "./toolbars";
@@ -0,0 +1,13 @@
1
+ .filter-form-container
2
+ display: flex
3
+ flex-direction: column
4
+ gap: 6px
5
+ min-width: 240px
6
+ padding: 6px
7
+
8
+ span.sep
9
+ &:first-child, &:last-child
10
+ display: none
11
+
12
+ .filter-value
13
+ font-style: oblique