@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,478 @@
1
+ import type { ColumnSpec } from "../../provider";
2
+ import { ReactNode, useCallback, useMemo, useState } from "react";
3
+ import {
4
+ buildMultiOperatorColumnFilter,
5
+ ColumnFilterState,
6
+ type TableFilter,
7
+ } from "../../actions";
8
+ import { ColumnSort, ctx, storeAtom } from "../../provider";
9
+ import {
10
+ Button,
11
+ HTMLSelect,
12
+ InputGroup,
13
+ Menu,
14
+ MenuItem,
15
+ PopoverNext,
16
+ Tag,
17
+ } from "@blueprintjs/core";
18
+ import { FilterOperator, OPERATOR_LABELS } from "../../filters/operators";
19
+ import classNames from "classnames";
20
+ import { atom } from "jotai";
21
+ import h from "./filter-and-sort.module.sass";
22
+
23
+ /** The filter for a column: its own rich `TableFilter` (from
24
+ * `col.filters`) when present — so the header matches the top bar and the rich
25
+ * filter is prioritized — else the built-in operator `columnFilter`. */
26
+ export function resolveColumnFilter(col: ColumnSpec): TableFilter {
27
+ const rich = (col.filters as TableFilter[] | undefined)?.find(
28
+ (f) => (f.columnKey ?? col.key) === col.key,
29
+ );
30
+ if (rich != null) return { ...rich, columnKey: rich.columnKey ?? col.key };
31
+ return buildMultiOperatorColumnFilter(col);
32
+ }
33
+
34
+ /** Shows an active column filter in the top menu */
35
+ export function ColumnFilterControl({ col }: { col: ColumnSpec }) {
36
+ // Same `TableFilter` the FilterBar and any provider consume, so the header,
37
+ // the bar, and the query stay in sync (rich filter prioritized).
38
+ const filter = useMemo(() => resolveColumnFilter(col), [col]);
39
+ return h(FilterIndicator, {
40
+ filter,
41
+ large: true,
42
+ minimal: true,
43
+ showSubject: false,
44
+ });
45
+ }
46
+
47
+ export function FilterIndicator({
48
+ filter,
49
+ large,
50
+ minimal = false,
51
+ showSubject = true,
52
+ }: {
53
+ filter: TableFilter;
54
+ state: any;
55
+ large?: boolean;
56
+ minimal?: boolean;
57
+ showSubject: boolean;
58
+ }) {
59
+ const props = useFilterProps(filter);
60
+
61
+ const { valueText, filterForm, icon, intent, isActive, onRemove } = props;
62
+
63
+ let rightIcon: string | undefined = "caret-down";
64
+ if (isActive) {
65
+ rightIcon = undefined;
66
+ }
67
+
68
+ const label = buildFilterTagLabel(filter, valueText, {
69
+ minimal,
70
+ showSubject,
71
+ isActive,
72
+ });
73
+
74
+ return h(
75
+ MenuDropdown,
76
+ {
77
+ content: filterForm,
78
+ },
79
+ h(
80
+ Tag,
81
+ {
82
+ minimal: true,
83
+ large,
84
+ icon,
85
+ rightIcon,
86
+ intent,
87
+ onRemove,
88
+ className: classNames("filter-tag", { active: isActive }),
89
+ },
90
+ h("span.filter-label", label),
91
+ ),
92
+ );
93
+ }
94
+
95
+ export function MenuDropdown({ children, content, isOpen, ...props }: any) {
96
+ return h(
97
+ PopoverNext,
98
+ {
99
+ content,
100
+ placement: "bottom-start",
101
+ enforceFocus: true,
102
+ autoFocus: false,
103
+ arrow: false,
104
+ },
105
+ children,
106
+ );
107
+ }
108
+
109
+ function buildFilterTagLabel(
110
+ filter: TableFilter,
111
+ valueText: ReactNode | null,
112
+ {
113
+ minimal,
114
+ showSubject,
115
+ isActive,
116
+ }: { minimal: boolean; showSubject: boolean; isActive: boolean },
117
+ ): ReactNode {
118
+ let name = filter.name;
119
+ if (!showSubject) {
120
+ name = "Filter";
121
+ }
122
+
123
+ let _showColumnKey = showSubject ?? !minimal;
124
+ let columnKeyEl: ReactNode = null;
125
+ const subj = filter.subject ?? filter.columnKey;
126
+ if (_showColumnKey && subj != null) {
127
+ columnKeyEl = h([h("span.subject", subj), h("span.sep", " ")]);
128
+ }
129
+
130
+ const showOperator = (!minimal || !isActive) && name != subj;
131
+ let operatorEl: ReactNode = null;
132
+ if (showOperator) {
133
+ operatorEl = h([h("span.operator", name), h("span.sep", ": ")]);
134
+ }
135
+
136
+ let filterWindow: ReactNode = null;
137
+ if (valueText != null && valueText != "") {
138
+ filterWindow = h("span.filter-value", valueText);
139
+ }
140
+
141
+ return h([columnKeyEl, operatorEl, filterWindow]);
142
+ }
143
+
144
+ /** Every filter applicable to a column: its rich `col.filters` (there may be
145
+ * several) plus the built-in operator `columnFilter` when the column is
146
+ * `filterable` and no rich filter already targets it. The menu lists all of
147
+ * them; the toolbar's `render` collapses to `resolveColumnFilter` (a single
148
+ * control). */
149
+ function applicableColumnFilters(col: ColumnSpec): TableFilter[] {
150
+ const result: TableFilter[] = [];
151
+ const rich = (col.filters as TableFilter[] | undefined) ?? [];
152
+ for (const f of rich) {
153
+ result.push({ ...f, columnKey: f.columnKey ?? col.key });
154
+ }
155
+ const hasOwnColumnFilter = result.some((r) => r.columnKey === col.key);
156
+ if (
157
+ (col.filterable === true || typeof col.filterable === "object") &&
158
+ !hasOwnColumnFilter
159
+ ) {
160
+ result.push(buildMultiOperatorColumnFilter(col));
161
+ }
162
+ return result;
163
+ }
164
+
165
+ /** One filter, as a menu item whose submenu carries its edit form. Active
166
+ * filters get a warning intent and show their `describeState` summary. The
167
+ * displayed `label` may differ from `filter.name` (e.g. the built-in operator
168
+ * filter reads "Filter" in a column's own menu, where the column is implicit). */
169
+ export function ColumnFilterMenuItem({
170
+ filter,
171
+ label,
172
+ }: {
173
+ filter: TableFilter;
174
+ label: string;
175
+ }) {
176
+ const { filterForm, icon, intent, valueText } = useFilterProps(filter);
177
+ return h(
178
+ MenuItem,
179
+ {
180
+ icon,
181
+ text: label,
182
+ label: valueText,
183
+ intent,
184
+ shouldDismissPopover: false,
185
+ },
186
+ filterForm,
187
+ );
188
+ }
189
+
190
+ function useFilterProps(filter: TableFilter) {
191
+ const [state, setState] = useFilterAtom(filter);
192
+
193
+ const onRemove = useCallback(
194
+ (event) => {
195
+ setState(null);
196
+ event.stopPropagation();
197
+ },
198
+ [setState],
199
+ );
200
+
201
+ const isActive = state != null;
202
+ let summary: ReactNode = null;
203
+ let label: ReactNode = filter.name ?? "Filter";
204
+ if (isActive) {
205
+ summary = filter.describeState?.(state);
206
+ label = summary ?? filter.name;
207
+ if (summary == "") summary = null;
208
+ if (summary != null) {
209
+ label = h([filter.name, h("span.filter-window", [": ", summary])]);
210
+ }
211
+ }
212
+
213
+ let filterForm: ReactNode = null;
214
+ if (filter.filterForm != null) {
215
+ filterForm = h(
216
+ "div.filter-form-container",
217
+ h(filter.filterForm, {
218
+ state: state ?? filter.defaultState,
219
+ setState,
220
+ }),
221
+ );
222
+ }
223
+
224
+ return {
225
+ filterForm,
226
+ label,
227
+ icon: filter.icon ?? "filter",
228
+ intent: isActive ? "primary" : "none",
229
+ isActive,
230
+ nameText: filter.name,
231
+ valueText: summary,
232
+ onRemove: isActive ? onRemove : undefined,
233
+ };
234
+ }
235
+
236
+ /** Menu-native filter: one item per applicable filter, each opening its form
237
+ * in a submenu. */
238
+ export function ColumnFilterMenu({ col }: { col: ColumnSpec }) {
239
+ const filters = useMemo(() => applicableColumnFilters(col), [col]);
240
+ return h(
241
+ filters.map((f) =>
242
+ h(ColumnFilterMenuItem, {
243
+ key: f.id,
244
+ filter: f,
245
+ // The generic operator filter is just "Filter" in its own column's
246
+ // menu; rich (user-provided) filters keep their descriptive names.
247
+ label: f.columnKey === col.key ? "Filter" : f.name,
248
+ }),
249
+ ),
250
+ );
251
+ }
252
+
253
+ export function ColumnFilterForm({
254
+ operators,
255
+ state,
256
+ setState,
257
+ }: {
258
+ operators: FilterOperator[];
259
+ state: ColumnFilterState;
260
+ setState: (s: ColumnFilterState) => void;
261
+ }) {
262
+ // Operator and value are held locally, seeded once from the incoming state.
263
+ // The operator must be local: committing it with an empty value clears the
264
+ // filter (so the store round-trips back to the default state), which would
265
+ // otherwise snap the dropdown back to the default — the operator wouldn't
266
+ // "stick" until a value was typed. The value commits (triggering a server
267
+ // re-fetch) on blur / Enter, not on every keystroke.
268
+ const [op, setOp] = useState<FilterOperator>(state?.operator ?? operators[0]);
269
+ const [val, setVal] = useState<string>(state?.value ?? "");
270
+
271
+ const commit = (nextOp: FilterOperator, nextVal: string) =>
272
+ setState({ operator: nextOp, value: nextVal });
273
+
274
+ const clear = () => {
275
+ setVal("");
276
+ commit(op, "");
277
+ };
278
+
279
+ return h("div.column-filter-form", [
280
+ // Compact header: title + operator on one row (with a clear ✕ when set),
281
+ // value on the next — space-efficient and full-width for the value.
282
+ h("div", { style: { display: "flex", alignItems: "center", gap: "6px" } }, [
283
+ h("span", { style: { fontWeight: 600 } }, "Filter"),
284
+ h(HTMLSelect, {
285
+ small: true,
286
+ value: op,
287
+ options: operators.map((o) => ({
288
+ value: o,
289
+ label: OPERATOR_LABELS[o] ?? o,
290
+ })),
291
+ onChange: (e) => {
292
+ const nextOp = e.currentTarget.value as FilterOperator;
293
+ setOp(nextOp);
294
+ commit(nextOp, val);
295
+ },
296
+ }),
297
+ h("div", { style: { flex: 1 } }),
298
+ h.if(val !== "")(Button, {
299
+ small: true,
300
+ minimal: true,
301
+ icon: "cross",
302
+ "aria-label": "Clear filter",
303
+ onClick: clear,
304
+ }),
305
+ ]),
306
+ h(InputGroup, {
307
+ small: true,
308
+ fill: true,
309
+ value: val,
310
+ placeholder: "value",
311
+ autoFocus: true,
312
+ onChange: (e) => setVal(e.target.value),
313
+ onBlur: () => commit(op, val),
314
+ onKeyDown: (e) => {
315
+ if (e.key === "Enter") commit(op, val);
316
+ },
317
+ }),
318
+ ]);
319
+ }
320
+
321
+ function ColumnSortActions({ sort, setSort }) {
322
+ return h([
323
+ h(MenuItem, {
324
+ key: "asc",
325
+ text: "Ascending",
326
+ icon: "sort-asc",
327
+ active: sort?.ascending === true,
328
+ onClick: () => setSort(true),
329
+ shouldDismissPopover: false,
330
+ }),
331
+ h(MenuItem, {
332
+ key: "desc",
333
+ text: "Descending",
334
+ icon: "sort-desc",
335
+ active: sort?.ascending === false,
336
+ onClick: () => setSort(false),
337
+ shouldDismissPopover: false,
338
+ }),
339
+ ]);
340
+ }
341
+
342
+ function displayParamsForSort(sort: ColumnSort | undefined) {
343
+ const icon =
344
+ sort == null ? "sort" : sort.ascending ? "sort-asc" : "sort-desc";
345
+ const label =
346
+ sort == null ? null : sort.ascending ? "Ascending" : "Descending";
347
+
348
+ let intent = "none";
349
+ if (sort != null) {
350
+ intent = "primary";
351
+ }
352
+
353
+ return { icon, label, intent };
354
+ }
355
+
356
+ export function ColumnSortIndicator({
357
+ columnKey,
358
+ showColumnKey,
359
+ small,
360
+ large,
361
+ }: {
362
+ showColumnKey: string;
363
+ columnKey: string;
364
+ small?: boolean;
365
+ large?: boolean;
366
+ }) {
367
+ const [sort, setSort] = useSortAtom(columnKey);
368
+ const { icon, label, intent } = displayParamsForSort(sort);
369
+
370
+ const columnLabel = showColumnKey ? `${columnKey}: ` : "";
371
+ let onRemove: any = undefined;
372
+ let rightIcon: string | undefined = "caret-down";
373
+ if (sort != null) {
374
+ rightIcon = undefined;
375
+ onRemove = () => setSort(null);
376
+ }
377
+
378
+ let valLabel = label;
379
+ valLabel ??= showColumnKey ? columnKey : "Sort";
380
+
381
+ return h(
382
+ MenuDropdown,
383
+ {
384
+ content: h(Menu, h(ColumnSortActions, { sort, setSort })),
385
+ },
386
+ h(
387
+ Tag,
388
+ {
389
+ small,
390
+ large,
391
+ minimal: true,
392
+ icon,
393
+ rightIcon,
394
+ intent,
395
+ onRemove,
396
+ },
397
+ h([columnLabel, valLabel]),
398
+ ),
399
+ );
400
+ }
401
+
402
+ /** Menu-native sort: a "Sort" item whose submenu holds Ascending / Descending.
403
+ * Clicking the *active* direction again clears the sort (toggle off) — there's
404
+ * no explicit "Clear" item, since the active-filter/sort tag in the status bar
405
+ * already offers direct removal. `text` overrides the parent item's label (the
406
+ * `DataPanel` uses the column name, so its Sort menu lists one item per field). */
407
+ export function ColumnSortMenu({
408
+ columnKey,
409
+ defaultLabel,
410
+ }: {
411
+ columnKey: string;
412
+ text?: string;
413
+ defaultLabel?: string;
414
+ }) {
415
+ const [sort, setSort] = useSortAtom(columnKey);
416
+ const { icon, label, intent } = displayParamsForSort(sort);
417
+ return h(
418
+ MenuItem,
419
+ { icon, text: label ?? defaultLabel ?? columnKey, intent },
420
+ h(ColumnSortActions, { sort, setSort }),
421
+ );
422
+ }
423
+
424
+ const setFilterAtom = atom(null, (get, set, filter: TableFilter, next: any) => {
425
+ const store = get(storeAtom);
426
+ if (store == null) return;
427
+ if (next == null || next.value === "") {
428
+ store.removeFilter(filter.id);
429
+ } else {
430
+ store.setFilter(filter.id, filter, next);
431
+ }
432
+ });
433
+
434
+ function useFilterAtom(filter: TableFilter) {
435
+ const filterStateAtom = useMemo(
436
+ () =>
437
+ atom(
438
+ (get) => {
439
+ const store = get(storeAtom);
440
+ return store?.activeFilters.get(filter.id)?.state;
441
+ },
442
+ (get, set, next: any) => {
443
+ set(setFilterAtom, filter, next);
444
+ },
445
+ ),
446
+ [filter.id],
447
+ );
448
+ return ctx.use(filterStateAtom);
449
+ }
450
+
451
+ function useSortAtom(columnKey) {
452
+ const sortAtom = useMemo(
453
+ () =>
454
+ atom(
455
+ (get) => {
456
+ return get(storeAtom)?.columnSorts.find((x) => x.key === columnKey);
457
+ },
458
+ (get, set, ascending: boolean | null) => {
459
+ const store = get(storeAtom);
460
+ if (store == null) return;
461
+ const currentVal = store.columnSorts.find(
462
+ (x) => x.key === columnKey,
463
+ )?.ascending;
464
+ let nextVal = ascending;
465
+ if (currentVal != null) {
466
+ if (currentVal == nextVal) {
467
+ // Unset
468
+ nextVal = null;
469
+ }
470
+ }
471
+
472
+ store.setColumnSort(columnKey, nextVal);
473
+ },
474
+ ),
475
+ [columnKey],
476
+ );
477
+ return ctx.use(sortAtom);
478
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./filter-and-sort.ts";
2
+ export * from "./selection";
3
+ export * from "./view-info";
4
+ export * from "./unified-filters.ts";
@@ -0,0 +1,22 @@
1
+ .selection-indicator
2
+ user-select: none
3
+
4
+ .selection-indicator-tag
5
+ display: flex
6
+ align-items: center
7
+ gap: 4px
8
+ :global(.bp6-icon)
9
+ color: var(--bp-typography-color-muted)
10
+
11
+ &.enabled
12
+ :global(.bp6-icon)
13
+ color: var(--intent-primary)
14
+
15
+ &.interactive
16
+ cursor: pointer
17
+ &:not(.enabled)
18
+ color: var(--bp-typography-color-muted) !important
19
+
20
+ &:not(.interactive)
21
+ background: transparent !important
22
+
@@ -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
+ }