@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
@@ -0,0 +1,161 @@
1
+ import {
2
+ ALL_CARDINALITIES,
3
+ isColumnFilterable,
4
+ TableAction,
5
+ } from "../../actions";
6
+ import { ctx, storeAtom, useSelector } from "../../provider";
7
+ import { useMemo } from "react";
8
+ import h from "../../data-panel.module.sass";
9
+ import { Menu, Tag } from "@blueprintjs/core";
10
+ import {
11
+ ColumnFilterMenuItem,
12
+ ColumnSortMenu,
13
+ MenuDropdown,
14
+ resolveColumnFilter,
15
+ } from "./filter-and-sort.ts";
16
+ import { atom } from "jotai";
17
+
18
+ /**
19
+ * Stand-in for the column-header dropdown the card list lacks: "Filter" and
20
+ * "Sort" menus listing the column-declared `filterable` / `sortable` fields.
21
+ * Each field reuses the *exact* data-sheet controls — `ColumnSortMenu`
22
+ * (Ascending/Descending submenu) and `ColumnFilterMenuItem` (the operator form
23
+ * in a submenu) — so sort/filter behave identically to the sheet and flow
24
+ * through the same store + provider seam (the server applies them).
25
+ */
26
+ export function useDataPanelControls(): TableAction[] {
27
+ const filterAction = useUnifiedFilterAction();
28
+
29
+ const actions: TableAction[] = [];
30
+ if (filterAction != null) {
31
+ actions.push(filterAction);
32
+ }
33
+ const sortAction = useSortAction();
34
+ if (sortAction != null) {
35
+ actions.push(sortAction);
36
+ }
37
+ return actions;
38
+ }
39
+
40
+ function useDisplayIntent(atom) {
41
+ const [hasActive, clearActive] = ctx.use(atom);
42
+ const intent = hasActive ? "primary" : "none";
43
+
44
+ let rightIcon: "caret-down" | undefined = "caret-down";
45
+ let onRemove: any = undefined;
46
+ if (hasActive) {
47
+ rightIcon = undefined;
48
+ onRemove = (evt) => {
49
+ clearActive();
50
+ evt.stopPropagation();
51
+ };
52
+ }
53
+
54
+ return { intent, rightIcon, onRemove, hasActive };
55
+ }
56
+
57
+ function useUnifiedFilterAction(): TableAction | null {
58
+ const columnSpec = useSelector((s) => s.columnSpec);
59
+ const filterableCols = useMemo(
60
+ () => columnSpec.filter((c) => isColumnFilterable(c)),
61
+ [columnSpec],
62
+ );
63
+
64
+ const rest = useDisplayIntent(hasActiveFiltersAtom);
65
+
66
+ if (filterableCols.length === 0) return null;
67
+
68
+ const filterMenu = h(
69
+ Menu,
70
+ filterableCols.map((col) =>
71
+ h(ColumnFilterMenuItem, {
72
+ key: col.key,
73
+ filter: resolveColumnFilter(col),
74
+ label: col.name,
75
+ }),
76
+ ),
77
+ );
78
+
79
+ const filterIndicator = h(
80
+ Tag,
81
+ {
82
+ minimal: true,
83
+ large: true,
84
+ icon: "filter",
85
+ ...rest,
86
+ },
87
+ "Filter",
88
+ );
89
+
90
+ return {
91
+ id: "filter",
92
+ name: "Filter",
93
+ icon: "filter",
94
+ description: "Add a filter to the data panel.",
95
+ targets: ALL_CARDINALITIES,
96
+ render: (ctx) =>
97
+ h(
98
+ MenuDropdown,
99
+ {
100
+ content: filterMenu,
101
+ placement: "bottom-start",
102
+ },
103
+ [filterIndicator],
104
+ ),
105
+ };
106
+ }
107
+
108
+ function useSortAction(): TableAction | null {
109
+ const columnSpec = useSelector((s) => s.columnSpec);
110
+
111
+ const rest = useDisplayIntent(hasActiveSortsAtom);
112
+
113
+ const sortableCols = useMemo(
114
+ () => columnSpec.filter((c) => c.sortable),
115
+ [columnSpec],
116
+ );
117
+
118
+ if (sortableCols.length == 0) {
119
+ return null;
120
+ }
121
+ const sortMenu = h(
122
+ Menu,
123
+ sortableCols.map((col) =>
124
+ h(ColumnSortMenu, { key: col.key, columnKey: col.key, text: col.name }),
125
+ ),
126
+ );
127
+
128
+ return {
129
+ id: "sort",
130
+ name: "Sort",
131
+ icon: "sort",
132
+ description: "Add a sort to the data panel.",
133
+ targets: ALL_CARDINALITIES,
134
+ render: (ctx) =>
135
+ h(MenuDropdown, { content: sortMenu }, [
136
+ h(
137
+ Tag,
138
+ {
139
+ minimal: true,
140
+ large: true,
141
+ icon: "sort",
142
+ ...rest,
143
+ },
144
+ "Sort",
145
+ ),
146
+ ]),
147
+ };
148
+ }
149
+
150
+ const hasActiveFiltersAtom = atom(
151
+ (get) => get(storeAtom)?.activeFilters.size ?? 0 > 0,
152
+ (get, set) => {
153
+ set(storeAtom, (s) => ({ ...s, activeFilters: new Map([]) }));
154
+ },
155
+ );
156
+ const hasActiveSortsAtom = atom(
157
+ (get) => get(storeAtom)?.columnSorts.length ?? 0 > 0,
158
+ (get, set) => {
159
+ set(storeAtom, (s) => ({ ...s, columnSorts: [] }));
160
+ },
161
+ );
@@ -1,23 +1,8 @@
1
- import h from "../postgrest-table/main.module.sass";
2
- import {
3
- ViewInfo,
4
- viewInfoAtom,
5
- tableFooterAtom,
6
- chunkPageAtom,
7
- } from "../postgrest-table";
8
- import { ctx } from "../provider.ts";
1
+ import h from "../../postgrest-table/main.module.sass";
2
+ import { tableFooterAtom, chunkPageAtom } from "../../postgrest-table";
3
+ import { ctx, useItemCount } from "../../provider";
9
4
  import { Button, ButtonGroup, Icon, Spinner } from "@blueprintjs/core";
10
5
 
11
- function VisibleRegionControl() {
12
- const viewInfo: ViewInfo = ctx.useValue(viewInfoAtom);
13
-
14
- return h("p", [
15
- `Rows ${viewInfo.visibleRegion.rowIndexStart}–${viewInfo.visibleRegion.rowIndexEnd}`,
16
- " of ",
17
- h("span.total-count", viewInfo.totalCount),
18
- ]);
19
- }
20
-
21
6
  /** A minimal bottom-of-table footer reflecting the `useChunkLoader` source. In
22
7
  * scroll mode: rows loaded, "of total" when known, and a status icon (spinner
23
8
  * loading / check complete / dots incomplete). In paged mode: prev/next page
@@ -31,19 +16,23 @@ export function LoadProgressIndicator() {
31
16
  if (loading) {
32
17
  status = h(Spinner, { size: 12 });
33
18
  } else if (total != null && loaded >= total) {
34
- status = h(Icon, { icon: "tick-circle", intent: "success", size: 12 });
19
+ status = h(Icon, { icon: "tick", size: 12 });
35
20
  } else {
36
21
  status = h(Icon, { icon: "more", size: 12 });
37
22
  }
38
23
 
39
- return h("div.load-progress", [
40
- h("span.load-progress-label", [
41
- `${loaded}`,
42
- total != null ? ` of ${total}` : "",
43
- " rows",
44
- ]),
45
- status,
46
- ]);
24
+ return h("div.load-progress", [h(LoadProgressLabel), status]);
25
+ }
26
+
27
+ export function LoadProgressLabel() {
28
+ const { loaded, total } = ctx.useValue(tableFooterAtom);
29
+ const expectedCount = total ?? loaded;
30
+ let countText = useItemCount(expectedCount);
31
+ if (expectedCount === 0) return countText;
32
+ if (total != null && loaded <= total) {
33
+ countText = `${loaded} of ${countText}`;
34
+ }
35
+ return h("span.load-progress-label", countText);
47
36
  }
48
37
 
49
38
  /** Prev/next pager for paged fetch mode. */
@@ -3,9 +3,8 @@
3
3
  flex-direction: row
4
4
  gap: 8px
5
5
  align-items: center
6
- min-height: 32px
7
- padding: 4px 8px
8
- background-color: var(--panel-secondary-background-color)
6
+ padding: 0.2em var(--data-panel-content-padding)
7
+ min-height: var(--panel-header-height, 40px)
9
8
 
10
9
  // Leading label naming the current selection shape (no icon) — reads as the
11
10
  // toolbar's title.
@@ -14,6 +13,12 @@
14
13
  white-space: nowrap
15
14
  min-width: 100px
16
15
 
16
+ .toolbar-group
17
+ display: flex
18
+ flex-direction: row
19
+ gap: 4px
20
+ align-items: center
21
+
17
22
  .spacer
18
23
  flex-grow: 1
19
24
 
@@ -35,16 +40,24 @@
35
40
  flex-direction: row
36
41
  flex-wrap: wrap
37
42
  gap: 4px
38
- margin-bottom: 4px
39
43
  align-items: center
40
44
  justify-content: flex-start
45
+ height: var(--filter-bar-height, 24px)
46
+ .description
47
+ margin: 0
48
+ color: var(--secondary-color)
49
+ font-size: 0.9em
41
50
 
42
51
  &>.group
43
52
  display: flex
44
53
  flex-direction: row
45
54
  gap: 4px
46
55
 
56
+ .filter-tag
57
+ display: flex
58
+
47
59
  // The current filter window shown after the filter name on its tag
48
60
  .filter-window
49
61
  opacity: 0.8
50
62
  font-variant-numeric: tabular-nums
63
+
@@ -1,41 +1,20 @@
1
1
  import { Button, ButtonGroup, PopoverNext } from "@blueprintjs/core";
2
- import { useCallback, useMemo, useState } from "react";
3
- import h from "./toolbar.module.sass";
4
- import { useSelector, useStoreAPI } from "../provider";
2
+ import { type ReactNode, useCallback, useMemo, useState } from "react";
3
+ import h from "./actions-toolbar.module.sass";
4
+ import { ctx, selectionAtom, useSelector } from "../../provider";
5
5
  import {
6
- buildActionContext,
7
6
  getApplicableActions,
8
7
  getSelectionCardinality,
9
8
  mergeColumnActions,
10
- } from "./selection";
11
- import type { TableAction, TableActionContext } from "./types";
9
+ buildActionContext,
10
+ TableActionContext,
11
+ runActionWrapper,
12
+ type TableAction,
13
+ } from "../../actions";
12
14
  import { RegionCardinality } from "@blueprintjs/table";
13
- import { useToaster } from "../notifications.ts";
14
- import { DataSheetStore } from "../types.ts";
15
- import { ColumnSpec } from "../utils";
16
-
17
- /** A short title describing the current selection (its shape), shown as the
18
- * toolbar's leading label — no icon. */
19
- function selectionTitle<T>(ctx: TableActionContext<T>): string | null {
20
- const sh = ctx.selectionShape;
21
- switch (sh.cardinality) {
22
- case RegionCardinality.FULL_COLUMNS: {
23
- if (ctx.columnKey != null) {
24
- const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);
25
- return col?.name ?? "Column";
26
- }
27
- return `${sh.columns} columns`;
28
- }
29
- case RegionCardinality.FULL_ROWS:
30
- return ctx.rowIndex != null ? "1 row" : `${sh.rows} rows`;
31
- case RegionCardinality.CELLS:
32
- return ctx.cell != null ? "Cell" : `${sh.columns}×${sh.rows} cells`;
33
- case RegionCardinality.FULL_TABLE:
34
- return null;
35
- default:
36
- return null;
37
- }
38
- }
15
+ import { useToaster } from "../../notifications.ts";
16
+ import type { ColumnSpec } from "../../provider";
17
+ import { SelectionIndicator } from "../index.ts";
39
18
 
40
19
  /** Toolbar that renders the actions/controls applicable to the current
41
20
  * selection cardinality (modal by selection) and edit mode. Actions with a
@@ -44,16 +23,23 @@ function selectionTitle<T>(ctx: TableActionContext<T>): string | null {
44
23
  * are merged when their columns are selected. A capsule on the left shows the
45
24
  * current selection polarity. */
46
25
  export function ActionsToolbar<T>({
47
- actions,
48
- tableName,
26
+ actions: _actions,
27
+ children,
28
+ className,
29
+ compact = false,
49
30
  }: {
50
31
  actions: TableAction<T>[];
51
32
  tableName?: string;
33
+ children: ReactNode;
34
+ className?: string;
35
+ compact: boolean;
52
36
  }) {
53
- const selection = useSelector((state) => state.selection);
37
+ const selection = ctx.useValue(selectionAtom);
54
38
  const editable = useSelector((state) => state.editable);
55
39
  const columnSpec = useSelector((state) => state.columnSpec);
56
- const storeAPI = useStoreAPI();
40
+
41
+ const actionIDs = new Set(_actions.map((a) => a.id));
42
+ const actions = useMemo(() => _actions, [actionIDs]);
57
43
 
58
44
  const cardinality = useMemo(
59
45
  () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,
@@ -71,19 +57,21 @@ export function ActionsToolbar<T>({
71
57
  [allActions, cardinality, editable],
72
58
  );
73
59
 
60
+ const store = ctx.useStore();
74
61
  // Context for `render`-style controls (they subscribe to the store
75
62
  // themselves; this resolves the selected column/rows).
76
- const ctx = buildActionContext(
77
- storeAPI.getState(),
78
- storeAPI.setState,
79
- ) as TableActionContext<T>;
63
+ const actionContext = useMemo(() => {
64
+ return buildActionContext(store.get, store.set);
65
+ }, [allActions]);
80
66
 
81
67
  // The toolbar is for actions that AREN'T keyboard-accessible: any action
82
68
  // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and
83
69
  // is omitted here (it still works via its shortcut). Then refine by selection
84
70
  // shape beyond cardinality (e.g. single column only).
85
71
  const shownActions = applicableActions.filter(
86
- (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),
72
+ (action: TableAction<T, any>) =>
73
+ action.hotkey == null &&
74
+ (action.appliesTo?.(actionContext as any) ?? true),
87
75
  );
88
76
 
89
77
  const toolbarIsShown = useMemo(
@@ -95,58 +83,41 @@ export function ActionsToolbar<T>({
95
83
  return null;
96
84
  }
97
85
 
98
- // The toolbar is always mounted if actions are available, so it can't flicker
99
- // in/out as the selection or action set changes — the container is stable;
100
- // only its contents (title + buttons) change. Avoids layout jank.
101
- const title = selectionTitle(ctx) ?? tableName ?? "Table";
102
-
103
- // Order left→right by generality: actions applicable to the whole table (or
104
- // no selection) are "global" and sit after a spacer on the right (Save /
105
- // Reset / Clear-selection); everything else is contextual and stays on the
106
- // left. So the left edge tracks the selection and the right edge is constant.
86
+ // Order left→right by generality: actions that require editing
87
+ // are "global" and sit after a spacer on the right (Save /
88
+ // Reset); everything else is contextual and stays on the left. So the left
89
+ // edge tracks the selection and the right edge is constant.
107
90
  const isGlobal = (a: TableAction<T>) =>
108
- a.targets.includes(RegionCardinality.FULL_TABLE) ||
109
- a.targets.includes("none" as any);
91
+ (a.targets.includes(RegionCardinality.FULL_TABLE) ||
92
+ a.targets.includes("none" as any)) &&
93
+ a.requiresEditable;
110
94
  const contextual = shownActions.filter((a) => !isGlobal(a));
111
- // Order the built-in global actions least→most impactful, left→right:
112
- // clear selection, reset changes, save. Any other global actions keep their
113
- // natural order to the left of these (stable sort, rank 0).
114
- const globalOrder: Record<string, number> = {
115
- "clear-selection": 1,
116
- "reset-changes": 2,
117
- "save-changes": 3,
118
- };
119
- const globalActions = shownActions
120
- .filter(isGlobal)
121
- .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
95
+ // Order the built-in global actions least→most impactful, left→right: reset
96
+ // changes, then save. Any other global actions keep their natural order to
97
+ // the left of these (stable sort, rank 0).
98
+
99
+ const globalActions = shownActions.filter(isGlobal);
122
100
 
123
- return h("div.actions-toolbar", [
124
- h("span.toolbar-title", { key: "title" }, title),
101
+ return h("div.actions-toolbar", { className }, [
102
+ h(SelectionIndicator, { minimal: compact }),
125
103
  h(
126
- ButtonGroup,
127
- { key: "contextual", minimal: true },
104
+ "div.toolbar-group.contextual",
128
105
  contextual.map((action) =>
129
- h(ActionButton, { key: action.id, action, ctx }),
106
+ h(ActionButton, { key: action.id, action, ctx: actionContext }),
130
107
  ),
131
108
  ),
132
- h("div.toolbar-spacer", { key: "spacer", style: { flex: 1 } }),
109
+ children,
110
+ h("div.toolbar-spacer", { style: { flex: 1 } }),
133
111
  h(
134
112
  ButtonGroup,
135
- { key: "global", minimal: true },
113
+ { minimal: true },
136
114
  globalActions.map((action) =>
137
- h(ActionButton, { key: action.id, action, ctx }),
115
+ h(ActionButton, { key: action.id, action, ctx: actionContext }),
138
116
  ),
139
117
  ),
140
118
  ]);
141
119
  }
142
120
 
143
- function getMessageForError(e: any) {
144
- if (e instanceof Error) return e.message;
145
- if (typeof e === "string") return e;
146
- if (e instanceof Object) return JSON.stringify(e);
147
- return null;
148
- }
149
-
150
121
  function isActionDisabled(action: TableAction, state: any): boolean {
151
122
  if (typeof action.disabled === "boolean") return action.disabled;
152
123
  if (typeof action.disabled === "function") {
@@ -155,35 +126,6 @@ function isActionDisabled(action: TableAction, state: any): boolean {
155
126
  return false;
156
127
  }
157
128
 
158
- export function runActionWrapper<T>(
159
- action: TableAction<T>,
160
- state: DataSheetStore<any>,
161
- setState: (state: Partial<DataSheetStore<any>>) => void,
162
- toaster: any,
163
- configState: any = undefined,
164
- ) {
165
- const ctx = buildActionContext(state, setState) as TableActionContext<T>;
166
- if (action.disabled instanceof Function) {
167
- if (action.disabled(ctx)) {
168
- return;
169
- }
170
- } else if (action.disabled) {
171
- return;
172
- }
173
- try {
174
- const res = action.run?.(ctx, configState);
175
- if (res instanceof Promise) {
176
- res
177
- .then(() => {})
178
- .catch((e) => {
179
- displayErrorForAction(action, e, toaster);
180
- });
181
- }
182
- } catch (e) {
183
- displayErrorForAction(action, e, toaster);
184
- }
185
- }
186
-
187
129
  /** Dispatcher: a live control (`action.render`) or a run/detailsForm button.
188
130
  * Kept hook-free so the two paths don't share a hook order. */
189
131
  function ActionButton<T>({
@@ -201,7 +143,7 @@ function ActionButton<T>({
201
143
 
202
144
  /** A run/detailsForm action rendered as a button. */
203
145
  function RunActionButton<T>({ action }: { action: TableAction<T> }) {
204
- const storeAPI = useStoreAPI();
146
+ const store = ctx.useStore();
205
147
  const toaster = useToaster();
206
148
 
207
149
  // Reactive disabled check — re-renders when relevant state changes
@@ -211,15 +153,9 @@ function RunActionButton<T>({ action }: { action: TableAction<T> }) {
211
153
 
212
154
  const runAction = useCallback(
213
155
  (configState?: any) => {
214
- runActionWrapper(
215
- action,
216
- storeAPI.getState(),
217
- storeAPI.setState,
218
- toaster,
219
- configState,
220
- );
156
+ runActionWrapper(action, store.get, store.set, toaster, configState);
221
157
  },
222
- [storeAPI, action, toaster],
158
+ [action, toaster],
223
159
  );
224
160
 
225
161
  if (action.detailsForm != null) {
@@ -240,15 +176,6 @@ function RunActionButton<T>({ action }: { action: TableAction<T> }) {
240
176
  );
241
177
  }
242
178
 
243
- function displayErrorForAction(action: TableAction, error: any, toaster: any) {
244
- const message =
245
- getMessageForError(error) ?? action.errorMessage ?? "Action failed";
246
- toaster.show({
247
- message,
248
- intent: "danger",
249
- });
250
- }
251
-
252
179
  /** Action button that opens a popover for pre-run configuration. */
253
180
  function ActionButtonWithForm<T, S>({
254
181
  action,
@@ -276,7 +203,7 @@ function ActionButtonWithForm<T, S>({
276
203
  onClose: () => setIsOpen(false),
277
204
  content: h("div.action-popover-content", [
278
205
  h.if(action.description != null)("p.description", action.description),
279
- h(action.detailsForm, {
206
+ h(action.detailsForm as any, {
280
207
  state: configState,
281
208
  setState: setConfigState,
282
209
  }),
@@ -0,0 +1,150 @@
1
+ import { Button, Menu, MenuItem, PopoverNext, Tag } from "@blueprintjs/core";
2
+ import { useMemo } from "react";
3
+ import { RegionCardinality } from "@blueprintjs/table";
4
+ import h from "./actions-toolbar.module.sass";
5
+ import { useSelector, useStoreAPI } from "../../provider";
6
+ import {
7
+ buildMultiOperatorColumnFilter,
8
+ getSelectionCardinality,
9
+ type TableFilter,
10
+ } from "../../actions";
11
+ import type { ColumnSpec } from "../../provider";
12
+ import { ColumnSortIndicator, FilterIndicator } from "../indicators";
13
+
14
+ /** Collect all available filters from global filters and column specs. */
15
+ function collectAllFilters<T>(
16
+ globalFilters: TableFilter<T>[],
17
+ columnSpec: ColumnSpec[],
18
+ ): TableFilter<T>[] {
19
+ const result: TableFilter<T>[] = [...globalFilters];
20
+ for (const col of columnSpec) {
21
+ if (col.filters != null) {
22
+ for (const f of col.filters as TableFilter<T>[]) {
23
+ const withKey: TableFilter<T> = {
24
+ ...f,
25
+ columnKey: f.columnKey ?? col.key,
26
+ };
27
+ if (!result.some((r) => r.id === withKey.id)) {
28
+ result.push(withKey);
29
+ }
30
+ }
31
+ }
32
+ // Auto-generate the built-in operator filter for a `filterable` column,
33
+ // unless the column already supplies an explicit filter.
34
+ if (col.filterable && !result.some((r) => r.columnKey === col.key)) {
35
+ result.push(buildMultiOperatorColumnFilter(col) as TableFilter<T>);
36
+ }
37
+ }
38
+ return result;
39
+ }
40
+
41
+ /** The single view-state bar: active **sorts** and **filters** shown as
42
+ * removable tags (filters reconfigurable in place via their `filterForm`). The
43
+ * "Add filter" button offers only **table-level** filters (no `columnKey`) and
44
+ * only when no column is selected — per-column filters are added/configured
45
+ * from the column header dropdown instead, so there's no redundancy. */
46
+ export function ActiveFiltersList<T>({
47
+ filters = [],
48
+ }: {
49
+ filters?: TableFilter<T>[];
50
+ }) {
51
+ const columnSpec = useSelector((state) => state.columnSpec);
52
+ const storeAPI = useStoreAPI();
53
+ const activeFilters = useSelector((state) => state.activeFilters);
54
+ const columnSorts = useSelector((state) => state.columnSorts);
55
+ const selection = useSelector((state) => state.selection);
56
+
57
+ const columnSelected =
58
+ getSelectionCardinality(selection) === RegionCardinality.FULL_COLUMNS;
59
+
60
+ const allFilters = useMemo(
61
+ () => collectAllFilters(filters, columnSpec),
62
+ [filters, columnSpec],
63
+ );
64
+
65
+ const activeIds = useMemo(
66
+ () => new Set(activeFilters.keys()),
67
+ [activeFilters],
68
+ );
69
+
70
+ // Only table-level filters are addable from the bar; column filters live in
71
+ // the column header dropdown.
72
+ const availableFilters = useMemo(
73
+ () => allFilters.filter((f) => f.columnKey == null && !activeIds.has(f.id)),
74
+ [allFilters, activeIds],
75
+ );
76
+
77
+ const showAdd = !columnSelected && availableFilters.length > 0;
78
+
79
+ const hasAnything =
80
+ columnSorts.length > 0 || activeFilters.size > 0 || showAdd;
81
+ if (!hasAnything)
82
+ return h(
83
+ "div.filter-bar.empty",
84
+ h("p.description", "No active filters or sorts"),
85
+ );
86
+
87
+ const filterArray = Array.from(activeFilters.entries()) as any[];
88
+
89
+ return h("div.filter-bar", [
90
+ h(
91
+ "div.group.filters",
92
+ filterArray.map(([id, entry]) =>
93
+ h(FilterIndicator, {
94
+ key: id,
95
+ ...entry,
96
+ large: false,
97
+ minimal: false,
98
+ showSubject: true,
99
+ }),
100
+ ),
101
+ ),
102
+ h(
103
+ "div.group.sorts",
104
+ columnSorts.map((s) => {
105
+ return h(ColumnSortIndicator, {
106
+ columnKey: s.key,
107
+ large: false,
108
+ showColumnKey: true,
109
+ });
110
+ }),
111
+ h.if(showAdd)(AddFilterPopover, {
112
+ filters: availableFilters,
113
+ }),
114
+ ),
115
+ ]);
116
+ }
117
+
118
+ /** Popover menu listing available (not-yet-active) filters. */
119
+ function AddFilterPopover<T>({ filters }: { filters: TableFilter<T>[] }) {
120
+ const storeAPI = useStoreAPI();
121
+
122
+ return h(
123
+ PopoverNext,
124
+ {
125
+ content: h(
126
+ Menu,
127
+ filters.map((f) =>
128
+ h(MenuItem, {
129
+ key: f.id,
130
+ text: f.name,
131
+ icon: f.icon ?? "filter",
132
+ onClick() {
133
+ storeAPI.getState().setFilter(f.id, f, f.defaultState);
134
+ },
135
+ }),
136
+ ),
137
+ ),
138
+ placement: "bottom-start",
139
+ },
140
+ h(
141
+ Button,
142
+ {
143
+ minimal: true,
144
+ small: true,
145
+ icon: "filter",
146
+ },
147
+ "Add filter",
148
+ ),
149
+ );
150
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./actions-toolbar";
2
+ export * from "./active-filters";