@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,13 +6,16 @@
6
6
  * omit them, replace them, or add their own controls at any cardinality.
7
7
  */
8
8
  import h from "@macrostrat/hyper";
9
- import { useMemo } from "react";
10
- import { Button, Menu, MenuItem, PopoverNext } from "@blueprintjs/core";
11
9
  import { RegionCardinality } from "@blueprintjs/table";
12
- import { useSelector, useStoreAPI } from "../provider";
13
- import type { TableAction, TableActionContext, TableFilter } from "./types";
14
- import type { ColumnSpec } from "../utils/column-spec";
15
- import { columnFilter } from "./column-filter";
10
+ import type { TableAction } from "./types";
11
+ import type { ColumnSpec } from "../provider";
12
+ import { TableActionContext } from "./context.ts";
13
+ import {
14
+ ColumnFilterControl,
15
+ ColumnFilterMenu,
16
+ ColumnSortIndicator,
17
+ ColumnSortMenu,
18
+ } from "../components";
16
19
 
17
20
  function selectedColumn(ctx: TableActionContext) {
18
21
  const key = ctx.getSelectedColumnKeys()[0];
@@ -22,96 +25,6 @@ function selectedColumn(ctx: TableActionContext) {
22
25
 
23
26
  // ---- Sort ----
24
27
 
25
- function ColumnSortControl({ columnKey }: { columnKey: string }) {
26
- const storeAPI = useStoreAPI();
27
- const sort = useSelector((s) => s.columnSorts.find((x) => x.key === columnKey));
28
- const set = (ascending: boolean | null) =>
29
- storeAPI.getState().setColumnSort(columnKey, ascending);
30
-
31
- const icon = sort == null ? "sort" : sort.ascending ? "sort-asc" : "sort-desc";
32
- const label =
33
- sort == null ? "Sort" : sort.ascending ? "Ascending" : "Descending";
34
-
35
- return h(
36
- PopoverNext,
37
- {
38
- placement: "bottom-start",
39
- content: h(Menu, [
40
- h(MenuItem, {
41
- key: "asc",
42
- text: "Ascending",
43
- icon: "sort-asc",
44
- active: sort?.ascending === true,
45
- onClick: () => set(true),
46
- }),
47
- h(MenuItem, {
48
- key: "desc",
49
- text: "Descending",
50
- icon: "sort-desc",
51
- active: sort?.ascending === false,
52
- onClick: () => set(false),
53
- }),
54
- h(MenuItem, {
55
- key: "clear",
56
- text: "Clear sort",
57
- icon: "cross",
58
- disabled: sort == null,
59
- onClick: () => set(null),
60
- }),
61
- ]),
62
- },
63
- h(
64
- Button,
65
- {
66
- small: true,
67
- minimal: true,
68
- icon,
69
- rightIcon: "caret-down",
70
- intent: sort != null ? "primary" : "none",
71
- },
72
- label,
73
- ),
74
- );
75
- }
76
-
77
- /** Menu-native sort: a "Sort" item whose submenu holds Ascending / Descending.
78
- * Clicking the *active* direction again clears the sort (toggle off) — there's
79
- * no explicit "Clear" item, since the active-filter/sort tag in the status bar
80
- * already offers direct removal. */
81
- function ColumnSortMenu({ columnKey }: { columnKey: string }) {
82
- const storeAPI = useStoreAPI();
83
- const sort = useSelector((s) => s.columnSorts.find((x) => x.key === columnKey));
84
- const toggle = (ascending: boolean) => {
85
- const store = storeAPI.getState();
86
- // A second click on the current direction toggles the sort off.
87
- const next = sort != null && sort.ascending === ascending ? null : ascending;
88
- store.setColumnSort(columnKey, next);
89
- };
90
- const icon = sort == null ? "sort" : sort.ascending ? "sort-asc" : "sort-desc";
91
- return h(
92
- MenuItem,
93
- { icon, text: "Sort" },
94
- [
95
- h(MenuItem, {
96
- key: "asc",
97
- icon: "sort-asc",
98
- text: "Ascending",
99
- active: sort?.ascending === true,
100
- shouldDismissPopover: false,
101
- onClick: () => toggle(true),
102
- }),
103
- h(MenuItem, {
104
- key: "desc",
105
- icon: "sort-desc",
106
- text: "Descending",
107
- active: sort?.ascending === false,
108
- shouldDismissPopover: false,
109
- onClick: () => toggle(false),
110
- }),
111
- ],
112
- );
113
- }
114
-
115
28
  /** Single-column sort control. Gated by `col.sortable`. */
116
29
  export const columnSortAction: TableAction = {
117
30
  id: "column-sort",
@@ -124,144 +37,15 @@ export const columnSortAction: TableAction = {
124
37
  render(ctx) {
125
38
  const col = selectedColumn(ctx);
126
39
  if (!col?.sortable) return null;
127
- return h(ColumnSortControl, { columnKey: col.key });
40
+ return h(ColumnSortIndicator, { columnKey: col.key, large: true });
128
41
  },
129
42
  renderMenuItem(ctx) {
130
43
  const col = selectedColumn(ctx);
131
44
  if (!col?.sortable) return null;
132
- return h(ColumnSortMenu, { columnKey: col.key });
45
+ return h(ColumnSortMenu, { columnKey: col.key, defaultLabel: "Sort" });
133
46
  },
134
47
  };
135
48
 
136
- // ---- Filter ----
137
-
138
- /** The filter offered for a column: its own rich `TableFilter` (from
139
- * `col.filters`) when present — so the header matches the top bar and the rich
140
- * filter is prioritized — else the built-in operator `columnFilter`. */
141
- function resolveColumnFilter(col: ColumnSpec): TableFilter {
142
- const rich = (col.filters as TableFilter[] | undefined)?.find(
143
- (f) => (f.columnKey ?? col.key) === col.key,
144
- );
145
- if (rich != null) return { ...rich, columnKey: rich.columnKey ?? col.key };
146
- return columnFilter(col);
147
- }
148
-
149
- function ColumnFilterControl({ col }: { col: ColumnSpec }) {
150
- const storeAPI = useStoreAPI();
151
- // Same `TableFilter` the FilterBar and any provider consume, so the header,
152
- // the bar, and the query stay in sync (rich filter prioritized).
153
- const filter = useMemo(() => resolveColumnFilter(col), [col]);
154
- const state = useSelector((s) => s.activeFilters.get(filter.id)?.state);
155
- const isActive = state != null;
156
- const summary = isActive ? filter.describeState?.(state) : null;
157
-
158
- const setState = (next: any) => {
159
- const store = storeAPI.getState();
160
- // An empty operator-filter value clears; otherwise activate/update.
161
- if (next == null || next.value === "") {
162
- store.removeFilter(filter.id);
163
- } else {
164
- store.setFilter(filter.id, filter, next);
165
- }
166
- };
167
-
168
- const label = isActive ? String(summary ?? filter.name) : "Filter";
169
-
170
- return h(
171
- PopoverNext,
172
- {
173
- placement: "bottom-start",
174
- content: h(
175
- "div",
176
- { style: { padding: "6px", minWidth: "220px" } },
177
- filter.filterForm != null
178
- ? h(filter.filterForm, {
179
- state: state ?? filter.defaultState,
180
- setState,
181
- })
182
- : null,
183
- ),
184
- },
185
- h(
186
- Button,
187
- {
188
- small: true,
189
- minimal: true,
190
- icon: "filter",
191
- rightIcon: "caret-down",
192
- intent: isActive ? "warning" : "none",
193
- },
194
- label,
195
- ),
196
- );
197
- }
198
-
199
- /** Every filter applicable to a column: its rich `col.filters` (there may be
200
- * several) plus the built-in operator `columnFilter` when the column is
201
- * `filterable` and no rich filter already targets it. The menu lists all of
202
- * them; the toolbar's `render` collapses to `resolveColumnFilter` (a single
203
- * control). */
204
- function applicableColumnFilters(col: ColumnSpec): TableFilter[] {
205
- const result: TableFilter[] = [];
206
- const rich = (col.filters as TableFilter[] | undefined) ?? [];
207
- for (const f of rich) {
208
- result.push({ ...f, columnKey: f.columnKey ?? col.key });
209
- }
210
- const hasOwnColumnFilter = result.some((r) => r.columnKey === col.key);
211
- if (
212
- (col.filterable === true || typeof col.filterable === "object") &&
213
- !hasOwnColumnFilter
214
- ) {
215
- result.push(columnFilter(col));
216
- }
217
- return result;
218
- }
219
-
220
- /** One filter, as a menu item whose submenu carries its edit form. Active
221
- * filters get a warning intent and show their `describeState` summary. */
222
- function ColumnFilterMenuItem({ filter }: { filter: TableFilter }) {
223
- const storeAPI = useStoreAPI();
224
- const state = useSelector((s) => s.activeFilters.get(filter.id)?.state);
225
- const isActive = state != null;
226
- const summary = isActive ? filter.describeState?.(state) : null;
227
-
228
- const setState = (next: any) => {
229
- const store = storeAPI.getState();
230
- if (next == null || next.value === "") {
231
- store.removeFilter(filter.id);
232
- } else {
233
- store.setFilter(filter.id, filter, next);
234
- }
235
- };
236
-
237
- return h(
238
- MenuItem,
239
- {
240
- icon: filter.icon ?? "filter",
241
- text: filter.name,
242
- label: summary != null ? String(summary) : undefined,
243
- intent: isActive ? "warning" : undefined,
244
- shouldDismissPopover: false,
245
- },
246
- filter.filterForm != null
247
- ? h(
248
- "div.filter-menu-form",
249
- { style: { padding: "6px", minWidth: "220px" } },
250
- h(filter.filterForm, { state: state ?? filter.defaultState, setState }),
251
- )
252
- : null,
253
- );
254
- }
255
-
256
- /** Menu-native filter: one item per applicable filter, each opening its form
257
- * in a submenu. */
258
- function ColumnFilterMenu({ col }: { col: ColumnSpec }) {
259
- const filters = useMemo(() => applicableColumnFilters(col), [col]);
260
- return h(
261
- filters.map((f) => h(ColumnFilterMenuItem, { key: f.id, filter: f })),
262
- );
263
- }
264
-
265
49
  /** Single-column filter control. Gated by `col.filterable`. */
266
50
  export const columnFilterAction: TableAction = {
267
51
  id: "column-filter",
@@ -294,6 +78,6 @@ export function isColumnFilterable(col: ColumnSpec): boolean {
294
78
 
295
79
  /** The built-in column controls (sort + filter), for inclusion in `actions`. */
296
80
  export const columnControlActions: TableAction[] = [
297
- columnSortAction,
298
81
  columnFilterAction,
82
+ columnSortAction,
299
83
  ];
@@ -9,16 +9,15 @@
9
9
  * (overridable via `filterable: { operators }`).
10
10
  */
11
11
  import hyper from "@macrostrat/hyper";
12
- import { useEffect, useState } from "react";
13
- import { ControlGroup, FormGroup, HTMLSelect, InputGroup } from "@blueprintjs/core";
14
- import type { ColumnSpec } from "../utils/column-spec";
15
- import type { TableFilter } from "./types";
12
+ import type { ColumnSpec } from "../provider/column-spec.ts";
13
+ import type { ColumnFilterOptions, TableFilter } from "./types";
16
14
  import {
17
15
  FilterOperator,
18
16
  getOperatorsForColumn,
19
17
  OPERATOR_LABELS,
20
18
  testFilterOperator,
21
19
  } from "../filters/operators";
20
+ import { ColumnFilterForm } from "../components";
22
21
 
23
22
  const h = hyper;
24
23
 
@@ -32,73 +31,39 @@ export function columnFilterId(key: string): string {
32
31
  return `column-filter:${key}`;
33
32
  }
34
33
 
35
- /** Generate the built-in operator filter for a `filterable` column. */
36
- export function columnFilter(
34
+ /** Built-in column filter for a column. */
35
+ export function buildMultiOperatorColumnFilter(
37
36
  col: ColumnSpec,
38
37
  ): TableFilter<any, ColumnFilterState> {
39
38
  const operators = getOperatorsForColumn(col);
40
- return {
41
- id: columnFilterId(col.key),
42
- name: col.name,
39
+ return enhanceColumnFilter(col, {
40
+ id: "default",
43
41
  icon: "filter",
44
- columnKey: col.key,
45
42
  defaultState: { operator: operators[0], value: "" },
46
- describeState: (s) =>
47
- s?.value
48
- ? `${OPERATOR_LABELS[s.operator] ?? s.operator} ${s.value}`
49
- : null,
50
- predicate: (row, s) =>
51
- testFilterOperator(row?.[col.key], s.operator, s.value),
43
+ describeState: (s) => {
44
+ const val = s?.value;
45
+ if (val == null || val === "") return null;
46
+ const op = OPERATOR_LABELS[s.operator] ?? s.operator;
47
+ return `${op} ${val}`;
48
+ },
49
+ predicate: (row, s) => {
50
+ return testFilterOperator(row?.[col.key], s.operator, s.value);
51
+ },
52
52
  filterForm: ({ state, setState }) =>
53
53
  h(ColumnFilterForm, { operators, state, setState }),
54
- };
54
+ });
55
55
  }
56
56
 
57
- function ColumnFilterForm({
58
- operators,
59
- state,
60
- setState,
61
- }: {
62
- operators: FilterOperator[];
63
- state: ColumnFilterState;
64
- setState: (s: ColumnFilterState) => void;
65
- }) {
66
- // The value is edited in local state and only committed (which triggers a
67
- // re-fetch for server sources) on blur or Enter — not on every keystroke.
68
- // The operator select commits immediately (a discrete choice).
69
- const [draft, setDraft] = useState(state.value ?? "");
70
- useEffect(() => setDraft(state.value ?? ""), [state.value]);
71
- const commit = () => {
72
- if (draft !== state.value) setState({ ...state, value: draft });
57
+ /** Enhance column filter into a full TableFilter object. */
58
+ export function enhanceColumnFilter(
59
+ col: ColumnSpec,
60
+ f: ColumnFilterOptions,
61
+ ): TableFilter<any, ColumnFilterState> {
62
+ return {
63
+ ...f,
64
+ id: `column-filter:${col.key}:${f.id}`,
65
+ name: f.name ?? col.name,
66
+ subject: col.name,
67
+ columnKey: col.key,
73
68
  };
74
- return h(
75
- FormGroup,
76
- { label: "Filter" },
77
- h(ControlGroup, { fill: true }, [
78
- h(HTMLSelect, {
79
- key: "op",
80
- value: state.operator,
81
- options: operators.map((op) => ({
82
- value: op,
83
- label: OPERATOR_LABELS[op] ?? op,
84
- })),
85
- onChange: (e) =>
86
- setState({
87
- ...state,
88
- operator: e.currentTarget.value as FilterOperator,
89
- }),
90
- }),
91
- h(InputGroup, {
92
- key: "val",
93
- value: draft,
94
- placeholder: "value",
95
- autoFocus: true,
96
- onChange: (e) => setDraft(e.target.value),
97
- onBlur: commit,
98
- onKeyDown: (e) => {
99
- if (e.key === "Enter") commit();
100
- },
101
- }),
102
- ]),
103
- );
104
69
  }
@@ -0,0 +1,299 @@
1
+ import {
2
+ CellEdit,
3
+ ClipboardProxy,
4
+ RowStatusValue,
5
+ tableDataAtom,
6
+ } from "../provider";
7
+ import { type Region, RegionCardinality } from "@blueprintjs/table";
8
+ import update from "immutability-helper";
9
+ import {
10
+ computeFilteredRowIndices,
11
+ computeSelectionShape,
12
+ getSelectedColumnKeys,
13
+ getSelectedRowIndices,
14
+ SelectionCardinality,
15
+ SelectionShape,
16
+ } from "./selection.ts";
17
+ import { Getter, Setter } from "jotai";
18
+ import type { Store as JotaiStore } from "jotai/vanilla/store";
19
+ import { storeAPIAtom } from "../provider";
20
+ import type { ColumnSpec } from "../provider";
21
+ import type { TableAction } from "./types.ts";
22
+
23
+ interface ActionContextOptions {
24
+ /** Override the action context to scope to a single column.
25
+ This is needed for actions that are invoked for a column header
26
+ drop-down, for instance */
27
+ singleColumn: number;
28
+ }
29
+
30
+ type StoreInterface = Omit<JotaiStore, "sub">;
31
+
32
+ /** Context passed to an action's `run` function, providing both data access
33
+ * and store manipulation methods. Constructed fresh at action-run time
34
+ * to ensure current state. */
35
+ export interface TableActionContext<T = any> {
36
+ /** Current selection regions */
37
+ selection: Region[];
38
+ /** Derived cardinality of the current selection */
39
+ selectionCardinality: SelectionCardinality;
40
+ /** Concrete shape of the current selection (cardinality + column/row counts). */
41
+ selectionShape: SelectionShape;
42
+ /** The single selected column's key when exactly one column is scoped
43
+ * (a single full column, or cells within one column); otherwise `null`. */
44
+ columnKey: string | null;
45
+ /** The single selected data-row index when exactly one row is scoped;
46
+ * otherwise `null`. */
47
+ rowIndex: number | null;
48
+ /** The single selected cell (data-row index + column key) when exactly one
49
+ * cell is selected; otherwise `null`. Presence of these resolved fields is
50
+ * how actions discriminate selection shape — e.g. `appliesTo: ctx =>
51
+ * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`
52
+ * within a `FULL_COLUMNS` target for a single-column control. */
53
+ cell: { rowIndex: number; columnKey: string } | null;
54
+ /** The table's base data */
55
+ data: T[];
56
+ /** Sparse overlay of edited data */
57
+ updatedData: (T | null | undefined)[];
58
+ /** Row status tracking added/deleted rows */
59
+ rowStatus: (RowStatusValue | null | undefined)[];
60
+ /** Column definitions */
61
+ columnSpec: ColumnSpec[];
62
+ /** Whether the table is in edit mode */
63
+ editable: boolean;
64
+ /** Whether row deletion is available (false when the provider can't delete). */
65
+ canDeleteRows: boolean;
66
+
67
+ // Convenience methods (derived from selection)
68
+ /** Row indices covered by the current selection */
69
+ getSelectedRowIndices(): number[];
70
+ /** The selected rows as resolved objects (not indices) — the natural input
71
+ * for an immediate-edit action. Only loaded rows are returned. */
72
+ getSelectedRows(): T[];
73
+ /** Column keys covered by the current selection */
74
+ getSelectedColumnKeys(): string[];
75
+
76
+ // Immediate-edit persistence (present when a persisting provider is wired,
77
+ // e.g. via DataPanel). Each mutates through the provider and auto-refreshes,
78
+ // so a selection action can edit rows without touching a `refreshToken`.
79
+ /** Persist edited rows (upsert), then refresh. */
80
+ saveRows?: (rows: T[]) => Promise<void>;
81
+ /** Delete rows by identity, then refresh. */
82
+ deleteRows?: (ids: Array<string | number>) => Promise<void>;
83
+ /** Insert a row, then refresh. */
84
+ insertRow?: (row: Partial<T>) => Promise<void>;
85
+ /** Force a re-fetch from scratch. */
86
+ refresh?: () => void;
87
+
88
+ // Store manipulation methods
89
+ onCellEdited(rowIndex: number, columnKey: string, value: any): void;
90
+ /** Edit multiple cells in a single batch update. Preferred over calling
91
+ * `onCellEdited` in a loop, which triggers separate store updates
92
+ * and may produce inconsistent intermediate states. */
93
+ editCells(edits: CellEdit[]): void;
94
+ deleteSelectedRows(): void;
95
+ addRow(row?: Partial<T>): void;
96
+ setUpdatedData(data: any): void;
97
+ resetChanges(region?: Region[]): void;
98
+ clearSelection(): void;
99
+ scrollToRow(rowIndex: number): void;
100
+ /** Direct store mutation for cases not covered by the convenience methods
101
+ * above (e.g., modifying `columnSpec` or `deletedRows`). */
102
+ setState(partial: Record<string, any>): void;
103
+
104
+ // Clipboard proxy support
105
+ /** Active clipboard proxy from a prior copy, if any */
106
+ clipboardProxy: ClipboardProxy | null;
107
+ /** Store a clipboard proxy for potential backend-mediated paste */
108
+ setClipboardProxy(proxy: ClipboardProxy | null): void;
109
+
110
+ // Filter support
111
+ /** Row index mapping when filters are active. When non-null,
112
+ * visible row `i` maps to data row `filteredRowIndices[i]`. */
113
+ filteredRowIndices: number[] | null;
114
+ }
115
+
116
+ /** Construct a `TableActionContext` from the current store state.
117
+ * Call this at action-run time (not render time) to ensure
118
+ * the context reflects the latest state.
119
+ * @param setState - Optional store setState for direct mutation. Omit for
120
+ * read-only contexts (e.g., disabled checks). */
121
+ export function buildActionContext<T>(
122
+ get: Getter,
123
+ set: Setter,
124
+ options?: ActionContextOptions,
125
+ ): TableActionContext<T> {
126
+ const storeAPI = get(storeAPIAtom);
127
+ if (storeAPI == null) {
128
+ throw new Error(
129
+ "No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.",
130
+ );
131
+ }
132
+
133
+ const data = get(tableDataAtom) as T[];
134
+
135
+ let state = storeAPI.getState();
136
+ if (options?.singleColumn != null) {
137
+ const colIndex = options.singleColumn;
138
+ state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];
139
+ }
140
+ const setState = storeAPI.setState;
141
+
142
+ // Lazy-compute filteredRowIndices to avoid cost during disabled checks
143
+ let _filteredRowIndices: number[] | null | undefined = undefined;
144
+ function getFilteredRowIndices(): number[] | null {
145
+ if (_filteredRowIndices === undefined) {
146
+ _filteredRowIndices = computeFilteredRowIndices(
147
+ data,
148
+ state.updatedData,
149
+ state.activeFilters,
150
+ );
151
+ }
152
+ return _filteredRowIndices;
153
+ }
154
+
155
+ const { selection, updatedData, rowStatus, rowEditing = {} } = state;
156
+
157
+ const shape = computeSelectionShape(selection);
158
+
159
+ return {
160
+ selection,
161
+ selectionCardinality: shape.cardinality,
162
+ selectionShape: shape,
163
+ data,
164
+ updatedData,
165
+ rowStatus,
166
+ // Immediate-edit persistence, wired by the consumer (DataPanel) when a
167
+ // persisting provider is present; each already auto-refreshes.
168
+ ...rowEditing,
169
+ // Resolved single-target identity (lazy — mapping rows through filters is
170
+ // only paid when accessed).
171
+ get columnKey() {
172
+ return shape.columns === 1
173
+ ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)
174
+ : null;
175
+ },
176
+ get rowIndex() {
177
+ return shape.rows === 1
178
+ ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
179
+ null)
180
+ : null;
181
+ },
182
+ get cell() {
183
+ if (
184
+ shape.cardinality !== RegionCardinality.CELLS ||
185
+ shape.columns !== 1 ||
186
+ shape.rows !== 1
187
+ ) {
188
+ return null;
189
+ }
190
+ const columnKey =
191
+ getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;
192
+ const rowIndex =
193
+ getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??
194
+ null;
195
+ return columnKey != null && rowIndex != null
196
+ ? { rowIndex, columnKey }
197
+ : null;
198
+ },
199
+ columnSpec: state.columnSpec,
200
+ editable: state.editable,
201
+ canDeleteRows: state.canDeleteRows,
202
+ getSelectedRowIndices: () =>
203
+ getSelectedRowIndices(state.selection, getFilteredRowIndices()),
204
+ getSelectedRows: () =>
205
+ getSelectedRowIndices(state.selection, getFilteredRowIndices())
206
+ .map((i) => data[i])
207
+ .filter((r) => r != null),
208
+ getSelectedColumnKeys: () =>
209
+ getSelectedColumnKeys(state.selection, state.columnSpec),
210
+ onCellEdited: state.onCellEdited,
211
+ editCells(edits: CellEdit[]) {
212
+ state.setUpdatedData((updatedData: T[]) => {
213
+ const spec: Record<number, any> = {};
214
+ for (const e of edits) {
215
+ const rowIndex = e.rowIndex;
216
+ const columnKey = (e as any).columnKey ?? e.column;
217
+ if (spec[rowIndex] == null) {
218
+ const op = updatedData[rowIndex] != null ? "$merge" : "$set";
219
+ spec[rowIndex] = { [op]: {} };
220
+ }
221
+ const opKey = Object.keys(spec[rowIndex])[0];
222
+ spec[rowIndex][opKey][columnKey] = e.value;
223
+ }
224
+ return update(updatedData, spec);
225
+ });
226
+ // Emit a structured edit event so controlled consumers capture programmatic
227
+ // batch edits (clipboard paste, fill) the same as inline edits.
228
+ state.onEdit?.({
229
+ type: "setCells",
230
+ cells: edits.map((e) => ({
231
+ rowIndex: e.rowIndex,
232
+ column: (e as any).columnKey ?? e.column,
233
+ value: e.value,
234
+ row: data[e.rowIndex],
235
+ })),
236
+ });
237
+ },
238
+ deleteSelectedRows: state.deleteSelectedRows,
239
+ addRow: state.addRow,
240
+ setUpdatedData: state.setUpdatedData,
241
+ resetChanges: state.resetChanges,
242
+ clearSelection: state.clearSelection,
243
+ scrollToRow: state.scrollToRow,
244
+ setState,
245
+ clipboardProxy: state.clipboardProxy,
246
+ setClipboardProxy(proxy) {
247
+ state.setClipboardProxy(proxy);
248
+ },
249
+ get filteredRowIndices() {
250
+ return getFilteredRowIndices();
251
+ },
252
+ };
253
+ }
254
+
255
+ function getMessageForError(e: any) {
256
+ if (e instanceof Error) return e.message;
257
+ if (typeof e === "string") return e;
258
+ if (e instanceof Object) return JSON.stringify(e);
259
+ return null;
260
+ }
261
+
262
+ export function runActionWrapper<T>(
263
+ action: TableAction<T>,
264
+ get: Getter,
265
+ set: Setter,
266
+ toaster: any,
267
+ configState: any = undefined,
268
+ ) {
269
+ console.log("runActionWrapper", action.id, configState);
270
+ const ctx = buildActionContext(get, set) as TableActionContext<T>;
271
+ if (action.disabled instanceof Function) {
272
+ if (action.disabled(ctx)) {
273
+ return;
274
+ }
275
+ } else if (action.disabled) {
276
+ return;
277
+ }
278
+ try {
279
+ const res = action.run?.(ctx, configState);
280
+ if (res instanceof Promise) {
281
+ res
282
+ .then(() => {})
283
+ .catch((e) => {
284
+ displayErrorForAction(action, e, toaster);
285
+ });
286
+ }
287
+ } catch (e) {
288
+ displayErrorForAction(action, e, toaster);
289
+ }
290
+ }
291
+
292
+ function displayErrorForAction(action: TableAction, error: any, toaster: any) {
293
+ const message =
294
+ getMessageForError(error) ?? action.errorMessage ?? "Action failed";
295
+ toaster.show({
296
+ message,
297
+ intent: "danger",
298
+ });
299
+ }
@@ -7,7 +7,9 @@
7
7
  */
8
8
  import { RegionCardinality } from "@blueprintjs/table";
9
9
  import { collectValidationErrors } from "../utils/validation";
10
- import type { SelectionCardinality, TableAction, TableActionContext } from "./types";
10
+ import type { TableAction } from "./types";
11
+ import { SelectionCardinality } from "./selection.ts";
12
+ import { TableActionContext } from "./context.ts";
11
13
 
12
14
  /** Every selection cardinality — an action targeting all of these is always
13
15
  * applicable, so the toolbar never empties out. */