@macrostrat/data-sheet 4.1.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -196
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -194
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -73
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -74
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/table-actions.cjs +41 -0
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -23
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +123 -190
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +92 -159
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +19 -2
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +4 -3
  121. package/dist/filters/operators.js +19 -2
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +128 -95
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +109 -76
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +73 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +21 -13
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +3 -2
  184. package/dist/renderers/column-header-cell.js +20 -12
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +117 -229
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -245
  214. package/src/actions/column-filter.ts +28 -92
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +145 -330
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +33 -3
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +244 -171
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +30 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
  251. package/src/renderers/column-header-cell.ts +21 -14
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +137 -239
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs +0 -62
  264. package/dist/actions/table-controls.cjs.map +0 -1
  265. package/dist/actions/table-controls.js.map +0 -1
  266. package/dist/actions/toolbar.cjs +0 -260
  267. package/dist/actions/toolbar.cjs.map +0 -1
  268. package/dist/actions/toolbar.js.map +0 -1
  269. package/dist/actions/toolbar.module.sass.cjs +0 -27
  270. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  271. package/dist/actions/toolbar.module.sass.js +0 -25
  272. package/dist/actions/toolbar.module.sass.js.map +0 -1
  273. package/dist/cell-renderer.cjs.map +0 -1
  274. package/dist/cell-renderer.js.map +0 -1
  275. package/dist/components/view-info.cjs +0 -55
  276. package/dist/components/view-info.cjs.map +0 -1
  277. package/dist/components/view-info.js.map +0 -1
  278. package/dist/core.cjs.map +0 -1
  279. package/dist/core.d.ts +0 -117
  280. package/dist/core.js.map +0 -1
  281. package/dist/provider.cjs +0 -197
  282. package/dist/provider.cjs.map +0 -1
  283. package/dist/provider.d.ts +0 -26
  284. package/dist/provider.js +0 -195
  285. package/dist/provider.js.map +0 -1
  286. package/dist/table-updates/data-parameter.d.ts +0 -14
  287. package/dist/table-updates/filter.d.ts +0 -16
  288. package/dist/table-updates/index.d.ts +0 -19
  289. package/dist/utils/column-spec.cjs.map +0 -1
  290. package/dist/utils/column-spec.js.map +0 -1
  291. package/dist/utils/index.cjs +0 -9
  292. package/dist/utils/index.cjs.map +0 -1
  293. package/dist/utils/index.js +0 -9
  294. package/dist/utils/index.js.map +0 -1
  295. package/dist/zustand-store.cjs.map +0 -1
  296. package/dist/zustand-store.js.map +0 -1
  297. package/src/actions/filters.ts +0 -176
  298. package/src/components/actions.module.sass +0 -8
  299. package/src/provider.ts +0 -267
  300. package/src/table-updates/data-parameter.ts +0 -44
  301. package/src/table-updates/filter.ts +0 -124
  302. package/src/table-updates/index.ts +0 -239
  303. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -0,0 +1,141 @@
1
+ import {
2
+ columnSpecAtom,
3
+ ctx,
4
+ interactionOptionsAtom,
5
+ itemLabelAtom,
6
+ pluralize,
7
+ selectionAtom,
8
+ tableNameAtom,
9
+ } from "../../provider";
10
+ import { atom } from "jotai";
11
+ import { computeSelectionShape, getSelectedColumnKeys } from "../../actions";
12
+ import { RegionCardinality } from "@blueprintjs/table";
13
+ import classNames from "classnames";
14
+ import h from "./selection.module.sass";
15
+ import { Tag } from "@blueprintjs/core";
16
+
17
+ /** A short title describing the current selection (its shape), shown as the
18
+ * toolbar's leading label — no icon. */
19
+ const selectionTitleAtom = atom<string | null>((get) => {
20
+ const sel = get(selectionAtom);
21
+ if (sel == null || sel.length === 0) return null;
22
+ const sh = computeSelectionShape(sel);
23
+ const itemName = get(itemLabelAtom);
24
+
25
+ switch (sh.cardinality) {
26
+ case RegionCardinality.FULL_COLUMNS: {
27
+ if (sh.columns == 1) {
28
+ const columnSpec = get(columnSpecAtom);
29
+ const columnKey = getSelectedColumnKeys(sel, columnSpec)[0];
30
+ const col = columnSpec.find((c) => c.key === columnKey);
31
+ return col?.name ?? "1 column";
32
+ }
33
+ return itemCount(sh.columns, "column");
34
+ }
35
+ case RegionCardinality.FULL_ROWS:
36
+ return itemCount(sh.rows, itemName);
37
+ case RegionCardinality.CELLS:
38
+ if (sh.columns == 1 || sh.rows == 1) {
39
+ const nCells = Math.max(sh.columns, sh.rows);
40
+ return itemCount(nCells, "cell");
41
+ }
42
+ return `${sh.columns}×${sh.rows} cells`;
43
+ case RegionCardinality.FULL_TABLE:
44
+ return null;
45
+ default:
46
+ return null;
47
+ }
48
+ });
49
+
50
+ function itemCount(n: number, itemType: string) {
51
+ return `${n} ` + pluralize(itemType, n);
52
+ }
53
+
54
+ const toggleModalSelectionAtom = atom(null, (get, set) => {
55
+ const interactionState = get(interactionOptionsAtom);
56
+ if (interactionState.enableModalSelection) {
57
+ const enableSelection = !interactionState.enableSelection;
58
+
59
+ if (!enableSelection) {
60
+ set(clearableSelectionAtom);
61
+ }
62
+
63
+ set(interactionOptionsAtom, {
64
+ ...interactionState,
65
+ enableSelection,
66
+ });
67
+ }
68
+ });
69
+ const clearableSelectionAtom = atom(
70
+ (get) => get(selectionAtom),
71
+ (get, set) => {
72
+ set(selectionAtom, []);
73
+ },
74
+ );
75
+
76
+ export function SelectionIndicator({ minimal = true }: { minimal?: boolean }) {
77
+ /** An indicator that shows the table's current selection shape, and optionally modal selection status */
78
+ // The leading title doubles as the clear-selection affordance: with an active
79
+ // selection it renders as a dismissible tag (its ✕ clears the selection),
80
+ // which ties "clear" to the selection it acts on and frees toolbar space.
81
+ // With no selection it's a plain label (table name).
82
+ // Both states render as a `large` `Tag` so the title keeps a constant font
83
+ // and height; only the selected one has a filled background + a ✕ (which
84
+ // clears the selection). The unselected label is a transparent, non-removable
85
+ // tag — visually a plain title, but the same box.
86
+
87
+ const [selection, clearSelection] = ctx.use(clearableSelectionAtom);
88
+ const interactionState = ctx.useValue(interactionOptionsAtom);
89
+ const tableName = ctx.useValue(tableNameAtom);
90
+
91
+ const toggleModalSelection = ctx.useSet(toggleModalSelectionAtom);
92
+ const { enableModalSelection, enableSelection } = interactionState;
93
+
94
+ const hasSelection = selection != null && selection.length > 0;
95
+
96
+ let selectionName: string | null = ctx.useValue(selectionTitleAtom);
97
+
98
+ let _name = tableName;
99
+ if (hasSelection) {
100
+ _name = selectionName ?? tableName;
101
+ } else if (enableModalSelection) {
102
+ _name = "Select";
103
+ }
104
+
105
+ const isClearable = hasSelection || (enableModalSelection && enableSelection);
106
+
107
+ if (minimal && !(hasSelection || enableModalSelection)) {
108
+ return null;
109
+ }
110
+
111
+ let onClick = null;
112
+ let icon: string | null = null;
113
+ let enterSelectionButton: React.ReactNode = null;
114
+ if (enableModalSelection) {
115
+ onClick = toggleModalSelection;
116
+ if (!isClearable) {
117
+ icon = "more";
118
+ }
119
+ }
120
+
121
+ const className = classNames("selection-indicator-tag", {
122
+ enabled: isClearable,
123
+ interactive: onClick != null || hasSelection,
124
+ });
125
+
126
+ return h("div.selection-indicator", [
127
+ h(
128
+ Tag,
129
+ {
130
+ minimal: true,
131
+ large: true,
132
+ onClick,
133
+ rightIcon: icon,
134
+ intent: isClearable ? "primary" : undefined,
135
+ className,
136
+ onRemove: isClearable ? clearSelection : undefined,
137
+ },
138
+ [_name, enterSelectionButton],
139
+ ),
140
+ ]);
141
+ }
@@ -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
+