@macrostrat/data-sheet 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (302) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -184
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -182
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -50
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -51
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/{table-controls.cjs → table-actions.cjs} +7 -24
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -19
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +36 -97
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +123 -181
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +92 -150
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +21 -4
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +5 -4
  121. package/dist/filters/operators.js +21 -4
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +129 -103
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +110 -84
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +77 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +37 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +22 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +68 -35
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +66 -33
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +40 -17
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +2 -2
  184. package/dist/renderers/column-header-cell.js +40 -17
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +123 -226
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -228
  214. package/src/actions/column-filter.ts +28 -63
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -20
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +53 -126
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +144 -306
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +38 -6
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +250 -181
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +34 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +36 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +146 -58
  251. package/src/renderers/column-header-cell.ts +51 -17
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +143 -236
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs.map +0 -1
  264. package/dist/actions/table-controls.js.map +0 -1
  265. package/dist/actions/toolbar.cjs +0 -246
  266. package/dist/actions/toolbar.cjs.map +0 -1
  267. package/dist/actions/toolbar.js.map +0 -1
  268. package/dist/actions/toolbar.module.sass.cjs +0 -27
  269. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  270. package/dist/actions/toolbar.module.sass.js +0 -25
  271. package/dist/actions/toolbar.module.sass.js.map +0 -1
  272. package/dist/cell-renderer.cjs.map +0 -1
  273. package/dist/cell-renderer.js.map +0 -1
  274. package/dist/components/view-info.cjs +0 -55
  275. package/dist/components/view-info.cjs.map +0 -1
  276. package/dist/components/view-info.js.map +0 -1
  277. package/dist/core.cjs.map +0 -1
  278. package/dist/core.d.ts +0 -113
  279. package/dist/core.js.map +0 -1
  280. package/dist/provider.cjs +0 -191
  281. package/dist/provider.cjs.map +0 -1
  282. package/dist/provider.d.ts +0 -25
  283. package/dist/provider.js +0 -189
  284. package/dist/provider.js.map +0 -1
  285. package/dist/table-updates/data-parameter.d.ts +0 -14
  286. package/dist/table-updates/filter.d.ts +0 -16
  287. package/dist/table-updates/index.d.ts +0 -19
  288. package/dist/utils/column-spec.cjs.map +0 -1
  289. package/dist/utils/column-spec.js.map +0 -1
  290. package/dist/utils/index.cjs +0 -9
  291. package/dist/utils/index.cjs.map +0 -1
  292. package/dist/utils/index.js +0 -9
  293. package/dist/utils/index.js.map +0 -1
  294. package/dist/zustand-store.cjs.map +0 -1
  295. package/dist/zustand-store.js.map +0 -1
  296. package/src/actions/filters.ts +0 -176
  297. package/src/components/actions.module.sass +0 -8
  298. package/src/provider.ts +0 -250
  299. package/src/table-updates/data-parameter.ts +0 -44
  300. package/src/table-updates/filter.ts +0 -124
  301. package/src/table-updates/index.ts +0 -239
  302. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -1,176 +0,0 @@
1
- import {
2
- Button,
3
- ButtonGroup,
4
- Menu,
5
- MenuItem,
6
- PopoverNext,
7
- Tag,
8
- } from "@blueprintjs/core";
9
- import { useMemo, useState } from "react";
10
- import { RegionCardinality } from "@blueprintjs/table";
11
- import h from "./toolbar.module.sass";
12
- import { useSelector, useStoreAPI } from "../provider";
13
- import { collectAllFilters, getSelectionCardinality } from "./selection";
14
- import type { TableFilter } from "./types";
15
-
16
- /** The single view-state bar: active **sorts** and **filters** shown as
17
- * removable tags (filters reconfigurable in place via their `filterForm`). The
18
- * "Add filter" button offers only **table-level** filters (no `columnKey`) and
19
- * only when no column is selected — per-column filters are added/configured
20
- * from the column header dropdown instead, so there's no redundancy. */
21
- export function FilterBar<T>({ filters = [] }: { filters?: TableFilter<T>[] }) {
22
- const columnSpec = useSelector((state) => state.columnSpec);
23
- const storeAPI = useStoreAPI();
24
- const activeFilters = useSelector((state) => state.activeFilters);
25
- const columnSorts = useSelector((state) => state.columnSorts);
26
- const selection = useSelector((state) => state.selection);
27
-
28
- const columnSelected =
29
- getSelectionCardinality(selection) === RegionCardinality.FULL_COLUMNS;
30
-
31
- const allFilters = useMemo(
32
- () => collectAllFilters(filters, columnSpec),
33
- [filters, columnSpec],
34
- );
35
-
36
- const activeIds = useMemo(
37
- () => new Set(activeFilters.keys()),
38
- [activeFilters],
39
- );
40
-
41
- // Only table-level filters are addable from the bar; column filters live in
42
- // the column header dropdown.
43
- const availableFilters = useMemo(
44
- () => allFilters.filter((f) => f.columnKey == null && !activeIds.has(f.id)),
45
- [allFilters, activeIds],
46
- );
47
- const showAdd = !columnSelected && availableFilters.length > 0;
48
-
49
- const hasAnything =
50
- columnSorts.length > 0 || activeFilters.size > 0 || showAdd;
51
- if (!hasAnything) return null;
52
-
53
- return h("div.filter-bar", [
54
- h(
55
- "div.group.sorts",
56
- columnSorts.map((s) =>
57
- h(
58
- Tag,
59
- {
60
- key: `sort-${s.key}`,
61
- icon: s.ascending ? "sort-asc" : "sort-desc",
62
- intent: "primary",
63
- minimal: true,
64
- onRemove() {
65
- storeAPI.getState().setColumnSort(s.key, null);
66
- },
67
- },
68
- `${s.key}: ${s.ascending ? "Ascending" : "Descending"}`,
69
- ),
70
- ),
71
- ),
72
- h(
73
- "div.group.filters",
74
- Array.from(activeFilters.entries()).map(([id, entry]) =>
75
- h(ActiveFilterChip, { key: id, filterId: id, entry }),
76
- ),
77
- ),
78
- h.if(showAdd)(AddFilterPopover, {
79
- filters: availableFilters,
80
- }),
81
- ]);
82
- }
83
-
84
- /** A single active filter displayed as a tag. Clicking opens a popover
85
- * for reconfiguring the filter; the remove button deactivates it. */
86
- function ActiveFilterChip<T>({
87
- filterId,
88
- entry,
89
- }: {
90
- filterId: string;
91
- entry: { filter: TableFilter<T>; state: any };
92
- }) {
93
- const storeAPI = useStoreAPI();
94
- const [configOpen, setConfigOpen] = useState(false);
95
- const { filter, state: filterState } = entry;
96
-
97
- // Summarize the active filter's window (e.g. "0–250") next to its name, so
98
- // the tag conveys not just what is filtered but the current setting.
99
- const summary = filter.describeState?.(filterState);
100
-
101
- const tag = h(
102
- Tag,
103
- {
104
- icon: filter.icon ?? "filter",
105
- onRemove() {
106
- storeAPI.getState().removeFilter(filterId);
107
- },
108
- interactive: true,
109
- intent: "primary",
110
- onClick: filter.filterForm ? () => setConfigOpen(!configOpen) : undefined,
111
- },
112
- [
113
- filter.name,
114
- summary != null && summary !== ""
115
- ? h("span.filter-window", [": ", summary])
116
- : null,
117
- ],
118
- );
119
-
120
- if (filter.filterForm == null) return tag;
121
-
122
- return h(
123
- PopoverNext,
124
- {
125
- isOpen: configOpen,
126
- onClose: () => setConfigOpen(false),
127
- content: h("div.filter-config", [
128
- h.if(filter.description != null)("p.description", filter.description),
129
- h(filter.filterForm, {
130
- state: filterState,
131
- setState(newState) {
132
- storeAPI.getState().setFilter(filterId, filter, newState);
133
- },
134
- }),
135
- ]),
136
- placement: "bottom-start",
137
- enforceFocus: false,
138
- autoFocus: false,
139
- },
140
- tag,
141
- );
142
- }
143
-
144
- /** Popover menu listing available (not-yet-active) filters. */
145
- function AddFilterPopover<T>({ filters }: { filters: TableFilter<T>[] }) {
146
- const storeAPI = useStoreAPI();
147
-
148
- return h(
149
- PopoverNext,
150
- {
151
- content: h(
152
- Menu,
153
- filters.map((f) =>
154
- h(MenuItem, {
155
- key: f.id,
156
- text: f.name,
157
- icon: f.icon ?? "filter",
158
- onClick() {
159
- storeAPI.getState().setFilter(f.id, f, f.defaultState);
160
- },
161
- }),
162
- ),
163
- ),
164
- placement: "bottom-start",
165
- },
166
- h(
167
- Button,
168
- {
169
- minimal: true,
170
- small: true,
171
- icon: "filter",
172
- },
173
- "Add filter",
174
- ),
175
- );
176
- }
@@ -1,8 +0,0 @@
1
- .table-actions, .table-action
2
- display: flex
3
- flex-direction: row
4
- gap: 0.5em
5
-
6
- .table-actions
7
- margin-bottom: 0.5em
8
- gap: 1em
package/src/provider.ts DELETED
@@ -1,250 +0,0 @@
1
- import { SetStateAction, useEffect, useRef, useState } from "react";
2
- import h from "@macrostrat/hyper";
3
- import { createStore, StoreApi, useStore } from "zustand";
4
- import type { Table } from "@blueprintjs/table";
5
- import { generateColumnSpec } from "./utils";
6
- import { createScopedStore } from "@macrostrat/data-components";
7
- import {
8
- DataSheetProviderProps,
9
- DataSheetState,
10
- DataSheetStore,
11
- DS_ROW_ID,
12
- TableElementStatus,
13
- } from "./types.ts";
14
- import { createZustandStore } from "./zustand-store.ts";
15
- import { atomWithStore } from "jotai-zustand";
16
- import { toasterAtom } from "./notifications.ts";
17
- import { TableAction } from "./actions";
18
- import { atom } from "jotai";
19
-
20
- /** Create a Jotai scoped store */
21
- export const ctx = createScopedStore();
22
-
23
- export const storeAPIAtom = atom<StoreApi<DataSheetStore<any>>>();
24
-
25
- const storeWrapperAtom = atom((get) => {
26
- const _storeAPIAtom = get(storeAPIAtom);
27
- if (_storeAPIAtom == null) {
28
- return undefined;
29
- }
30
- return atomWithStore(_storeAPIAtom);
31
- });
32
-
33
- /** This is the basis for all other atoms that manipulate the store. */
34
- export const storeAtom = atom(
35
- (get) => {
36
- const storeWrapper = get(storeWrapperAtom);
37
- if (storeWrapper == null) {
38
- return undefined;
39
- }
40
- return get(storeWrapper);
41
- },
42
- (get, set, action: SetStateAction<T>) => {
43
- const storeWrapper = get(storeWrapperAtom);
44
- if (storeWrapper == null) {
45
- throw new Error("Missing DataSheetProvider");
46
- }
47
- return set(storeWrapper, action);
48
- },
49
- );
50
-
51
- const initializeStoreAtom = atom(
52
- null,
53
- (get, set, payload: Partial<DataSheetStore<T>>) => {
54
- set(storeAtom, (state) => {
55
- return {
56
- ...state,
57
- ...payload,
58
- };
59
- });
60
- },
61
- );
62
-
63
- export const tableActionsAtom = atom<TableAction[]>([]);
64
-
65
- export function DataSheetProvider<T>(props: DataSheetProviderProps<T>) {
66
- const { toaster, ...rest } = props;
67
- const [store] = useState(() => {
68
- return createStore<DataSheetStore<T>>(createZustandStore);
69
- });
70
- return h(
71
- ctx.Provider,
72
- {
73
- atoms: [
74
- [storeAPIAtom, store],
75
- [toasterAtom, toaster],
76
- ],
77
- },
78
- h(DataSheetProviderInner, rest),
79
- );
80
- }
81
-
82
- export function DataSheetProviderInner<T>({
83
- children,
84
- data,
85
- columnSpec,
86
- columnSpecOptions,
87
- editable,
88
- enableColumnReordering,
89
- defaultColumnWidth = 150,
90
- }: DataSheetProviderProps<T>) {
91
- const tableRef = useRef<Table>(null);
92
-
93
- const initializeStore = ctx.useSet(initializeStoreAtom);
94
-
95
- // Not sure how required this initialization is
96
- useEffect(() => {
97
- initializeStore({
98
- columnSpec: columnSpec ?? generateColumnSpec(data, columnSpecOptions),
99
- editable,
100
- enableColumnReordering,
101
- data,
102
- defaultColumnWidth,
103
- tableRef,
104
- });
105
- }, [data, editable, columnSpec, columnSpecOptions, enableColumnReordering]);
106
-
107
- return children;
108
- }
109
-
110
- export function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {
111
- const store = ctx.useValue(storeAPIAtom);
112
- if (!store) {
113
- throw new Error("Missing DataSheetProvider");
114
- }
115
- return store;
116
- }
117
-
118
- export function useSelector<T = any, A = any>(
119
- selector: (state: DataSheetStore<T> & DataSheetComputedVals) => A,
120
- ): A {
121
- const store = useStoreAPI<T>();
122
- return useStore(store, selector);
123
- }
124
- /** Atoms for efficient sub-selection of state */
125
-
126
- export const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);
127
-
128
- export const tableDataAtom = atom(
129
- (get) => {
130
- return get(storeAtom)?.data ?? [];
131
- },
132
- (get, set, newData: any[]) => {
133
- set(storeAtom, (state: DataSheetState<any>): DataSheetState<any> => {
134
- let next: DataSheetState<any> = { ...state, data: newData };
135
- if (
136
- state.data.length == 0 &&
137
- newData.length > 0 &&
138
- state.columnSpec.length == 0
139
- ) {
140
- // We haven't yet generated the column spec, and we need to do so.
141
- next.columnSpec = generateColumnSpec(newData, state.columnSpecOptions);
142
- }
143
-
144
- // Re-attach the edit overlay by identity. The loader replaces `data` with
145
- // re-ordered windows on sort/filter, so an index-keyed overlay would
146
- // smear; keying by identity keeps edits (and deletes) on their rows, holds
147
- // edits for not-yet-loaded rows, and re-appends locally-added rows (which
148
- // aren't in the provider's data) after it. Skipped when the consumer
149
- // controls the overlay (they own reconciliation).
150
- if (!state.controlledOverlay) {
151
- const remap = remapOverlayByIdentity(state, newData);
152
- next.data = remap.data;
153
- next.updatedData = remap.updatedData;
154
- next.rowStatus = remap.rowStatus;
155
- next.pendingOverlayById = remap.pending;
156
- }
157
-
158
- return next;
159
- });
160
- },
161
- );
162
-
163
- type OverlayEntry = { edit?: any; status?: any };
164
-
165
- /** Row identity used by the overlay: an in-table-added row's synthetic id
166
- * (stable across its edits), else the provider/consumer `identity`. */
167
- function overlayIdentity(
168
- state: DataSheetState<any>,
169
- row: any,
170
- ): string | number | null | undefined {
171
- if (row == null) return undefined;
172
- const added = row[DS_ROW_ID];
173
- if (added != null) return added;
174
- return state.identity(row);
175
- }
176
-
177
- /** Re-project the (index-keyed) edit overlay from the old `data` order onto a
178
- * new one, matching rows by identity. Edits/statuses whose row is absent from
179
- * `newData` are held in `pending` and re-applied when the row loads; rows added
180
- * in-table (status `ADDED`) are re-appended after the provider data (they have
181
- * no provider row). Starts from the prior pending set so edits survive multiple
182
- * re-sorts. Returns the reconstructed data (provider rows + re-appended added
183
- * rows) alongside the re-aligned overlay. */
184
- function remapOverlayByIdentity(
185
- state: DataSheetState<any>,
186
- newData: any[],
187
- ): {
188
- data: any[];
189
- updatedData: any[];
190
- rowStatus: any[];
191
- pending: Map<string | number, OverlayEntry>;
192
- } {
193
- const { data: oldData, updatedData, rowStatus } = state;
194
-
195
- // Collect current overlay entries by identity, seeded with prior pending.
196
- const byId = new Map<string | number, OverlayEntry>(state.pendingOverlayById);
197
- const n = Math.max(
198
- oldData.length,
199
- updatedData?.length ?? 0,
200
- rowStatus?.length ?? 0,
201
- );
202
- for (let i = 0; i < n; i++) {
203
- const row = oldData[i];
204
- if (row == null) continue;
205
- const id = overlayIdentity(state, row);
206
- if (id == null) continue;
207
- const edit = updatedData?.[i];
208
- const status = rowStatus?.[i];
209
- if (edit != null || status != null) byId.set(id, { edit, status });
210
- }
211
-
212
- // Project onto the new data order.
213
- const resultData = newData.slice();
214
- const nextUpdated: any[] = [];
215
- const nextStatus: any[] = [];
216
- const attached = new Set<string | number>();
217
- for (let j = 0; j < resultData.length; j++) {
218
- const row = resultData[j];
219
- if (row == null) continue;
220
- const id = overlayIdentity(state, row);
221
- if (id == null) continue;
222
- const entry = byId.get(id);
223
- if (entry == null) continue;
224
- if (entry.edit != null) nextUpdated[j] = entry.edit;
225
- if (entry.status != null) nextStatus[j] = entry.status;
226
- attached.add(id);
227
- }
228
-
229
- // Re-append in-table-added rows (not present in the provider data), then hold
230
- // anything still unattached (rows not currently loaded) as pending.
231
- const pending = new Map<string | number, OverlayEntry>();
232
- for (const [id, entry] of byId) {
233
- if (attached.has(id)) continue;
234
- if (entry.status === TableElementStatus.ADDED) {
235
- const idx = resultData.length;
236
- resultData.push(entry.edit ?? {});
237
- nextUpdated[idx] = entry.edit;
238
- nextStatus[idx] = entry.status;
239
- } else {
240
- pending.set(id, entry);
241
- }
242
- }
243
-
244
- return {
245
- data: resultData,
246
- updatedData: nextUpdated,
247
- rowStatus: nextStatus,
248
- pending,
249
- };
250
- }
@@ -1,44 +0,0 @@
1
- import { Filter } from "./filter";
2
-
3
- interface DataParameters {
4
- group?: string;
5
- select: {
6
- page?: string;
7
- pageSize?: string;
8
- };
9
- filter: {
10
- [key: string]: Filter; // Used for filters
11
- };
12
- }
13
-
14
- const cloneDataParameters = (
15
- dataParameters: DataParameters
16
- ): DataParameters => {
17
- return {
18
- group: dataParameters?.group,
19
- select: { ...dataParameters?.select },
20
- filter: Object.entries(dataParameters?.filter).reduce(
21
- (acc, [key, value]) => {
22
- acc[key] = value.clone();
23
- return acc;
24
- },
25
- {}
26
- ),
27
- };
28
- };
29
-
30
- /*
31
- * Check if a column is active in the data parameters
32
- */
33
- export const isColumnActive = (
34
- dataParameters: DataParameters,
35
- column: string
36
- ) => {
37
- return (
38
- (column in dataParameters.filter &&
39
- dataParameters.filter[column].is_valid()) ||
40
- column == dataParameters?.group
41
- );
42
- };
43
-
44
- export { cloneDataParameters, DataParameters };
@@ -1,124 +0,0 @@
1
- import { ColumnOperators } from "../tables/defs";
2
-
3
- export class Filter {
4
- readonly column_name: string;
5
- readonly operator: ColumnOperators | undefined;
6
- readonly value: string | boolean | number | null;
7
-
8
- constructor(
9
- column_name: string,
10
- operator: ColumnOperators | undefined,
11
- value: string | boolean | number | null
12
- ) {
13
- this.column_name = column_name;
14
- this.operator = operator;
15
- this.value = value;
16
- }
17
-
18
- get formattedValue() {
19
- switch (this.operator) {
20
- case "in":
21
- return `(${this.value})`;
22
- default:
23
- return this.value;
24
- }
25
- }
26
-
27
- get urlValue() {
28
- return `${this.operator}.${this.formattedValue}`;
29
- }
30
-
31
- clone = () => {
32
- return new Filter(this.column_name, this.operator, this.value);
33
- };
34
-
35
- passes = (data: Record<string, string | boolean | number | null>) => {
36
- const filterValue = data[this.column_name];
37
- switch (this.operator) {
38
- case "eq":
39
- return filterValue == this.value;
40
- case "lt":
41
- return filterValue < this.value;
42
- case "le":
43
- return filterValue <= this.value;
44
- case "gt":
45
- return filterValue > this.value;
46
- case "ge":
47
- return filterValue >= this.value;
48
- case "ne":
49
- return filterValue != this.value;
50
- case "is_distinct_from":
51
- return filterValue != this.value;
52
- case "is_not_distinct_from":
53
- return filterValue == this.value;
54
- case "like":
55
- if (typeof filterValue != "string" || typeof this.value != "string") {
56
- return false;
57
- }
58
- return filterValue.includes(this.value);
59
- case "in":
60
- if (typeof filterValue != "string" || typeof this.value != "string") {
61
- return false;
62
- }
63
- return this.value.includes(filterValue);
64
- case "is":
65
- return filterValue == this.value;
66
- default:
67
- return false;
68
- }
69
- };
70
-
71
- is_valid = () => {
72
- if (this.operator == undefined) {
73
- return false;
74
- }
75
- return true;
76
- };
77
-
78
- to_array = () => {
79
- return [this.column_name, this.operator + "." + this.formattedValue];
80
- };
81
- }
82
-
83
- /*
84
- * Convert url and filter to a parameterized URL
85
- */
86
- export const addFilterToURL = (url: URL, filter: Filter) => {
87
- if (filter.is_valid()) {
88
- const [columnName, filterValue] = filter.to_array();
89
- url.searchParams.append(columnName, filterValue);
90
- }
91
- return url;
92
- };
93
-
94
- /*
95
- * Sort the filters by column name and stringify
96
- */
97
- export const createFiltersKey = (filters: Filter[]) => {
98
- const sortFilterEntries = (a: Filter, b: Filter) => {
99
- return a.column_name.localeCompare(b.column_name);
100
- };
101
-
102
- return filters
103
- .filter((filter) => filter.is_valid())
104
- .sort(sortFilterEntries)
105
- .map((filter) => filter.urlValue)
106
- .join("&");
107
- };
108
-
109
- export const rowPassesFilters = (
110
- row: Record<string, string | boolean | number | null>,
111
- filters: Filter[] | undefined
112
- ) => {
113
- for (const filter of filters) {
114
- // If the filter is invalid skip it
115
- if (!filter.is_valid()) {
116
- continue;
117
- }
118
-
119
- if (!filter.passes(row)) {
120
- return false;
121
- }
122
- }
123
- return true;
124
- };