@macrostrat/data-sheet 3.0.4 → 4.0.0-dev1

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 (185) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/actions/builtin.cjs +56 -0
  3. package/dist/actions/builtin.cjs.map +1 -0
  4. package/dist/actions/builtin.d.ts +15 -0
  5. package/dist/actions/builtin.js +56 -0
  6. package/dist/actions/builtin.js.map +1 -0
  7. package/dist/actions/clipboard.cjs +250 -0
  8. package/dist/actions/clipboard.cjs.map +1 -0
  9. package/dist/actions/clipboard.d.ts +42 -0
  10. package/dist/actions/clipboard.js +250 -0
  11. package/dist/actions/clipboard.js.map +1 -0
  12. package/dist/actions/filters.cjs +123 -0
  13. package/dist/actions/filters.cjs.map +1 -0
  14. package/dist/actions/filters.d.ts +6 -0
  15. package/dist/actions/filters.js +123 -0
  16. package/dist/actions/filters.js.map +1 -0
  17. package/dist/actions/index.d.ts +6 -0
  18. package/dist/actions/selection.cjs +194 -0
  19. package/dist/actions/selection.cjs.map +1 -0
  20. package/dist/actions/selection.d.ts +40 -0
  21. package/dist/actions/selection.js +192 -0
  22. package/dist/actions/selection.js.map +1 -0
  23. package/dist/actions/toolbar.cjs +171 -0
  24. package/dist/actions/toolbar.cjs.map +1 -0
  25. package/dist/actions/toolbar.d.ts +10 -0
  26. package/dist/actions/toolbar.js +171 -0
  27. package/dist/actions/toolbar.js.map +1 -0
  28. package/dist/actions/toolbar.module.sass.cjs +22 -0
  29. package/dist/actions/toolbar.module.sass.cjs.map +1 -0
  30. package/dist/actions/toolbar.module.sass.js +20 -0
  31. package/dist/actions/toolbar.module.sass.js.map +1 -0
  32. package/dist/actions/types.d.ts +143 -0
  33. package/dist/cell-renderer.cjs +165 -0
  34. package/dist/cell-renderer.cjs.map +1 -0
  35. package/dist/cell-renderer.d.ts +3 -0
  36. package/dist/cell-renderer.js +165 -0
  37. package/dist/cell-renderer.js.map +1 -0
  38. package/dist/components/actions.module.sass.cjs +3 -3
  39. package/dist/components/actions.module.sass.js +2 -2
  40. package/dist/components/colors.cjs +20 -16
  41. package/dist/components/colors.cjs.map +1 -1
  42. package/dist/components/colors.d.ts +4 -3
  43. package/dist/components/colors.js +20 -16
  44. package/dist/components/colors.js.map +1 -1
  45. package/dist/components/editor-popup.cjs +4 -3
  46. package/dist/components/editor-popup.cjs.map +1 -1
  47. package/dist/components/editor-popup.js +4 -3
  48. package/dist/components/editor-popup.js.map +1 -1
  49. package/dist/components/index.d.ts +1 -0
  50. package/dist/components/main.module.sass.cjs +12 -12
  51. package/dist/components/main.module.sass.js +11 -11
  52. package/dist/components/text-areas.cjs +23 -18
  53. package/dist/components/text-areas.cjs.map +1 -1
  54. package/dist/components/text-areas.d.ts +8 -4
  55. package/dist/components/text-areas.js +20 -13
  56. package/dist/components/text-areas.js.map +1 -1
  57. package/dist/components/view-info.cjs +18 -0
  58. package/dist/components/view-info.cjs.map +1 -0
  59. package/dist/components/view-info.d.ts +1 -0
  60. package/dist/components/view-info.js +18 -0
  61. package/dist/components/view-info.js.map +1 -0
  62. package/dist/core.cjs +201 -300
  63. package/dist/core.cjs.map +1 -1
  64. package/dist/core.d.ts +18 -10
  65. package/dist/core.js +204 -299
  66. package/dist/core.js.map +1 -1
  67. package/dist/data-sheet.css +190 -52
  68. package/dist/index.cjs +47 -8
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.ts +3 -0
  71. package/dist/index.js +48 -9
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.module.sass.cjs +15 -14
  74. package/dist/main.module.sass.cjs.map +1 -1
  75. package/dist/main.module.sass.js +14 -13
  76. package/dist/main.module.sass.js.map +1 -1
  77. package/dist/notifications.cjs +19 -0
  78. package/dist/notifications.cjs.map +1 -0
  79. package/dist/notifications.d.ts +9 -0
  80. package/dist/notifications.js +19 -0
  81. package/dist/notifications.js.map +1 -0
  82. package/dist/postgrest-table/data-loaders.cjs +181 -104
  83. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  84. package/dist/postgrest-table/data-loaders.d.ts +52 -28
  85. package/dist/postgrest-table/data-loaders.js +181 -104
  86. package/dist/postgrest-table/data-loaders.js.map +1 -1
  87. package/dist/postgrest-table/index.cjs +205 -79
  88. package/dist/postgrest-table/index.cjs.map +1 -1
  89. package/dist/postgrest-table/index.d.ts +14 -17
  90. package/dist/postgrest-table/index.js +186 -58
  91. package/dist/postgrest-table/index.js.map +1 -1
  92. package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
  93. package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
  94. package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
  95. package/dist/postgrest-table/lazy-loader-table.js +17 -14
  96. package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
  97. package/dist/postgrest-table/loading-utils.cjs +16 -0
  98. package/dist/postgrest-table/loading-utils.cjs.map +1 -0
  99. package/dist/postgrest-table/loading-utils.d.ts +13 -0
  100. package/dist/postgrest-table/loading-utils.js +16 -0
  101. package/dist/postgrest-table/loading-utils.js.map +1 -0
  102. package/dist/postgrest-table/main.module.sass.cjs +18 -13
  103. package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
  104. package/dist/postgrest-table/main.module.sass.js +18 -13
  105. package/dist/postgrest-table/main.module.sass.js.map +1 -1
  106. package/dist/provider.cjs +96 -344
  107. package/dist/provider.cjs.map +1 -1
  108. package/dist/provider.js +96 -343
  109. package/dist/provider.js.map +1 -1
  110. package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
  111. package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
  112. package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
  113. package/dist/renderers/column-header-cell-postgrest.js +216 -0
  114. package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
  115. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
  116. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
  117. package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
  118. package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
  119. package/dist/renderers/column-header-cell.cjs +103 -0
  120. package/dist/renderers/column-header-cell.cjs.map +1 -0
  121. package/dist/renderers/column-header-cell.d.ts +30 -0
  122. package/dist/renderers/column-header-cell.js +101 -0
  123. package/dist/renderers/column-header-cell.js.map +1 -0
  124. package/dist/renderers/index.d.ts +2 -0
  125. package/dist/table-updates/data-parameter.d.ts +14 -0
  126. package/dist/table-updates/filter.d.ts +16 -0
  127. package/dist/table-updates/index.d.ts +19 -0
  128. package/dist/types.cjs +9 -0
  129. package/dist/types.cjs.map +1 -0
  130. package/dist/types.d.ts +108 -0
  131. package/dist/types.js +9 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/column-spec.cjs +9 -1
  134. package/dist/utils/column-spec.cjs.map +1 -1
  135. package/dist/utils/column-spec.d.ts +21 -0
  136. package/dist/utils/column-spec.js +9 -1
  137. package/dist/utils/column-spec.js.map +1 -1
  138. package/dist/utils/key-handling.cjs +161 -47
  139. package/dist/utils/key-handling.cjs.map +1 -1
  140. package/dist/utils/key-handling.d.ts +3 -3
  141. package/dist/utils/key-handling.js +161 -47
  142. package/dist/utils/key-handling.js.map +1 -1
  143. package/dist/zustand-store.cjs +485 -0
  144. package/dist/zustand-store.cjs.map +1 -0
  145. package/dist/zustand-store.d.ts +6 -0
  146. package/dist/zustand-store.js +483 -0
  147. package/dist/zustand-store.js.map +1 -0
  148. package/package.json +6 -5
  149. package/src/actions/builtin.ts +65 -0
  150. package/src/actions/clipboard.ts +350 -0
  151. package/src/actions/filters.ts +150 -0
  152. package/src/actions/index.ts +6 -0
  153. package/src/actions/selection.ts +271 -0
  154. package/src/actions/toolbar.module.sass +30 -0
  155. package/src/actions/toolbar.ts +212 -0
  156. package/src/actions/types.ts +159 -0
  157. package/src/cell-renderer.ts +221 -0
  158. package/src/components/colors.ts +22 -19
  159. package/src/components/editor-popup.ts +3 -2
  160. package/src/components/index.ts +1 -0
  161. package/src/components/main.module.sass +1 -0
  162. package/src/components/text-areas.ts +34 -19
  163. package/src/components/view-info.ts +17 -0
  164. package/src/core.ts +273 -360
  165. package/src/index.ts +4 -0
  166. package/src/main.module.sass +14 -2
  167. package/src/notifications.ts +22 -0
  168. package/src/postgrest-table/data-loaders.ts +300 -201
  169. package/src/postgrest-table/index.ts +260 -86
  170. package/src/postgrest-table/lazy-loader-table.ts +18 -17
  171. package/src/postgrest-table/loading-utils.ts +49 -0
  172. package/src/postgrest-table/main.module.sass +16 -0
  173. package/src/provider.ts +110 -487
  174. package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
  175. package/src/renderers/column-header-cell-postgrest.ts +282 -0
  176. package/src/renderers/column-header-cell.ts +388 -0
  177. package/src/renderers/index.ts +2 -0
  178. package/src/table-updates/data-parameter.ts +44 -0
  179. package/src/table-updates/filter.ts +124 -0
  180. package/src/table-updates/index.ts +239 -0
  181. package/src/types.ts +121 -0
  182. package/src/utils/column-spec.ts +47 -0
  183. package/src/utils/key-handling.ts +201 -66
  184. package/src/zustand-store.ts +582 -0
  185. package/dist/provider.d.ts +0 -69
@@ -0,0 +1,71 @@
1
+ .column-header-cell
2
+ display: flex
3
+ align-items: center
4
+ width: 100%
5
+
6
+ .column-name
7
+ flex: 1
8
+ overflow: hidden
9
+ text-overflow: ellipsis
10
+ white-space: nowrap
11
+
12
+ .column-indicators
13
+ display: flex
14
+ align-items: center
15
+ gap: 2px
16
+ margin-left: 4px
17
+ flex-shrink: 0
18
+
19
+ :global(.bp6-icon)
20
+ opacity: 0.7
21
+ color: var(--text-color)
22
+
23
+ .sort-indicator
24
+ :global(.bp6-icon)
25
+ color: var(--intent-primary, #2965cc)
26
+ opacity: 1
27
+
28
+ .filter-indicator
29
+ :global(.bp6-icon)
30
+ color: var(--intent-warning, #d99e0b)
31
+ opacity: 1
32
+
33
+ .column-actions-popover
34
+ padding: 12px
35
+ min-width: 220px
36
+
37
+ .popover-section
38
+ margin-bottom: 12px
39
+ &:last-child
40
+ margin-bottom: 0
41
+
42
+ .popover-section-title
43
+ font-weight: 600
44
+ font-size: 11px
45
+ text-transform: uppercase
46
+ letter-spacing: 0.5px
47
+ color: var(--secondary-color, #5c7080)
48
+ margin-bottom: 6px
49
+
50
+ .sort-buttons
51
+ display: flex
52
+ gap: 4px
53
+
54
+ .filter-row
55
+ display: flex
56
+ gap: 4px
57
+ align-items: center
58
+
59
+ .filter-operator-select
60
+ flex-shrink: 0
61
+ width: 80px
62
+
63
+ .filter-value-input
64
+ flex: 1
65
+
66
+ .clear-section
67
+ display: flex
68
+ justify-content: flex-end
69
+ padding-top: 4px
70
+ border-top: 1px solid var(--divider-color, rgba(16, 22, 26, 0.15))
71
+
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Column header with server-side sort and filter controls.
3
+ *
4
+ * Uses Blueprint's ColumnHeaderCell `menuRenderer` prop to provide a
5
+ * dropdown menu with sort direction toggles and a filter input.
6
+ * The `nameRenderer` prop shows the column name plus visual indicators
7
+ * for any active sort or filter.
8
+ */
9
+ import { ColumnHeaderCell, ColumnHeaderCellProps } from "@blueprintjs/table";
10
+ import {
11
+ Button,
12
+ ButtonGroup,
13
+ HTMLSelect,
14
+ Icon,
15
+ InputGroup,
16
+ Menu,
17
+ } from "@blueprintjs/core";
18
+ import { useCallback, useRef, useState } from "react";
19
+ import h from "./column-header-cell-postgrest.module.sass";
20
+ import type { ColumnSpec, ColumnDataType } from "../utils/column-spec";
21
+ import type {
22
+ ColumnSortEntry,
23
+ PostgrestColumnFilter,
24
+ PostgrestFilterOperator,
25
+ } from "../postgrest-table/data-loaders";
26
+ import { ColumnHeaderRendererProps } from "./column-header-cell";
27
+
28
+ /** Operators appropriate for string columns. */
29
+ const STRING_FILTER_OPERATORS: PostgrestFilterOperator[] = [
30
+ "eq",
31
+ "neq",
32
+ "ilike",
33
+ ];
34
+
35
+ /** Operators appropriate for numeric / integer columns. */
36
+ const NUMERIC_FILTER_OPERATORS: PostgrestFilterOperator[] = [
37
+ "eq",
38
+ "neq",
39
+ "gt",
40
+ "lt",
41
+ "gte",
42
+ "lte",
43
+ ];
44
+
45
+ /** Operators appropriate for boolean columns. */
46
+ const BOOLEAN_FILTER_OPERATORS: PostgrestFilterOperator[] = ["eq", "neq"];
47
+
48
+ /** Fallback operators when no type information is available. */
49
+ const DEFAULT_FILTER_OPERATORS: PostgrestFilterOperator[] = [
50
+ "eq",
51
+ "neq",
52
+ "ilike",
53
+ "gt",
54
+ "lt",
55
+ "gte",
56
+ "lte",
57
+ ];
58
+
59
+ /** Map from data type to the appropriate set of filter operators. */
60
+ const OPERATORS_BY_TYPE: Record<string, PostgrestFilterOperator[]> = {
61
+ string: STRING_FILTER_OPERATORS,
62
+ number: NUMERIC_FILTER_OPERATORS,
63
+ integer: NUMERIC_FILTER_OPERATORS,
64
+ boolean: BOOLEAN_FILTER_OPERATORS,
65
+ };
66
+
67
+ export const OPERATOR_LABELS: Record<PostgrestFilterOperator, string> = {
68
+ eq: "=",
69
+ neq: "≠",
70
+ like: "like",
71
+ ilike: "contains",
72
+ gt: ">",
73
+ lt: "<",
74
+ gte: "≥",
75
+ lte: "≤",
76
+ is: "is",
77
+ };
78
+
79
+ export interface ColumnHeaderActions {
80
+ onSetSort: (key: string, ascending: boolean | null) => void;
81
+ onSetFilter: (
82
+ key: string,
83
+ operator: PostgrestFilterOperator | null,
84
+ value: string,
85
+ ) => void;
86
+ onClearColumn: (key: string) => void;
87
+ }
88
+
89
+ /** The main column header cell renderer for PostgREST tables. */
90
+ export function renderPostgRESTColumnHeaderCell(
91
+ props: ColumnHeaderRendererProps & { actions: ColumnHeaderActions },
92
+ ): React.ReactElement<ColumnHeaderCellProps> | null {
93
+ const { col, activeSort, activeFilter, actions } = props;
94
+
95
+ const isSortable = col.sortable === true;
96
+ const isFilterable =
97
+ col.filterable === true || typeof col.filterable === "object";
98
+
99
+ // If the column has no sort/filter capabilities, render a plain header
100
+ if (!isSortable && !isFilterable) {
101
+ return h(ColumnHeaderCell, { name: col.name });
102
+ }
103
+
104
+ return h(ColumnHeaderCell, {
105
+ name: col.name,
106
+ nameRenderer: (): any =>
107
+ h(ColumnHeaderName, { col, activeFilter, activeSort }),
108
+ menuRenderer: () =>
109
+ h(ColumnActionsMenu, {
110
+ col,
111
+ isSortable,
112
+ isFilterable,
113
+ activeSort,
114
+ activeFilter,
115
+ actions,
116
+ }),
117
+ });
118
+ }
119
+
120
+ /** Column name with active sort/filter indicator icons. */
121
+ function ColumnHeaderName({ col, activeSort, activeFilter }) {
122
+ const hasSortActive = activeSort != null;
123
+ const hasFilterActive = activeFilter != null;
124
+ return h("div.column-header-cell", [
125
+ h("span.column-name", col.name),
126
+ h.if(hasSortActive || hasFilterActive)("span.column-indicators", [
127
+ h.if(hasSortActive)(
128
+ "span.sort-indicator",
129
+ h(Icon, {
130
+ icon: activeSort?.ascending ? "sort-asc" : "sort-desc",
131
+ size: 12,
132
+ }),
133
+ ),
134
+ h.if(hasFilterActive)(
135
+ "span.filter-indicator",
136
+ h(Icon, { icon: "filter", size: 12 }),
137
+ ),
138
+ ]),
139
+ ]);
140
+ }
141
+
142
+ /** Resolve filter operators for a column, considering explicit config,
143
+ * inferred data type, and fallback defaults. */
144
+ function getOperatorsForColumn(col: ColumnSpec): PostgrestFilterOperator[] {
145
+ // Explicit operators in filterable config take priority
146
+ if (typeof col.filterable === "object" && col.filterable.operators?.length) {
147
+ return col.filterable.operators as PostgrestFilterOperator[];
148
+ }
149
+ // Otherwise, pick operators based on the inferred data type
150
+ if (col.dataType != null) {
151
+ return OPERATORS_BY_TYPE[col.dataType] ?? DEFAULT_FILTER_OPERATORS;
152
+ }
153
+ return DEFAULT_FILTER_OPERATORS;
154
+ }
155
+
156
+ /** Menu content rendered inside ColumnHeaderCell's built-in dropdown. */
157
+ function ColumnActionsMenu({
158
+ col,
159
+ isSortable,
160
+ isFilterable,
161
+ activeSort,
162
+ activeFilter,
163
+ actions,
164
+ }) {
165
+ const operators = getOperatorsForColumn(col);
166
+
167
+ const [filterOperator, setFilterOperator] = useState<PostgrestFilterOperator>(
168
+ activeFilter?.operator ?? operators[0],
169
+ );
170
+ const filterInputRef = useRef<HTMLInputElement>(null);
171
+
172
+ const applyFilter = useCallback(() => {
173
+ const val = filterInputRef.current?.value ?? "";
174
+ if (val.trim() === "") {
175
+ actions.onSetFilter(col.key, null, "");
176
+ } else {
177
+ actions.onSetFilter(col.key, filterOperator, val);
178
+ }
179
+ }, [col.key, filterOperator, actions]);
180
+
181
+ const hasAnyActive =
182
+ activeSort != null ||
183
+ (activeFilter != null &&
184
+ activeFilter.value !== "" &&
185
+ activeFilter.value != null);
186
+
187
+ return h(Menu, { className: "column-actions-menu" }, [
188
+ h("div.column-actions-popover", [
189
+ h.if(isSortable)("div.popover-section", [
190
+ h("div.popover-section-title", "Sort"),
191
+ h("div.sort-buttons", [
192
+ h(ButtonGroup, { minimal: true }, [
193
+ h(
194
+ Button,
195
+ {
196
+ icon: "sort-asc",
197
+ active: activeSort?.ascending === true,
198
+ intent: activeSort?.ascending === true ? "primary" : "none",
199
+ onClick() {
200
+ if (activeSort?.ascending === true) {
201
+ actions.onSetSort(col.key, null);
202
+ } else {
203
+ actions.onSetSort(col.key, true);
204
+ }
205
+ },
206
+ },
207
+ "A→Z",
208
+ ),
209
+ h(
210
+ Button,
211
+ {
212
+ icon: "sort-desc",
213
+ active: activeSort?.ascending === false,
214
+ intent: activeSort?.ascending === false ? "primary" : "none",
215
+ onClick() {
216
+ if (activeSort?.ascending === false) {
217
+ actions.onSetSort(col.key, null);
218
+ } else {
219
+ actions.onSetSort(col.key, false);
220
+ }
221
+ },
222
+ },
223
+ "Z→A",
224
+ ),
225
+ ]),
226
+ ]),
227
+ ]),
228
+ h.if(isFilterable)("div.popover-section", [
229
+ h("div.popover-section-title", "Filter"),
230
+ h("div.filter-row", [
231
+ h(HTMLSelect, {
232
+ className: "filter-operator-select",
233
+ value: filterOperator,
234
+ options: operators.map((op) => ({
235
+ value: op,
236
+ label: OPERATOR_LABELS[op] ?? op,
237
+ })),
238
+ onChange(e) {
239
+ setFilterOperator(e.target.value as PostgrestFilterOperator);
240
+ },
241
+ }),
242
+ h(InputGroup, {
243
+ className: "filter-value-input",
244
+ small: true,
245
+ placeholder: "Value…",
246
+ defaultValue: activeFilter?.value ?? "",
247
+ inputRef: filterInputRef,
248
+ onKeyDown(e) {
249
+ if (e.key === "Enter") {
250
+ applyFilter();
251
+ }
252
+ },
253
+ rightElement: h(Button, {
254
+ icon: "arrow-right",
255
+ minimal: true,
256
+ small: true,
257
+ onClick: applyFilter,
258
+ }),
259
+ }),
260
+ ]),
261
+ ]),
262
+ h.if(hasAnyActive)("div.clear-section", [
263
+ h(
264
+ Button,
265
+ {
266
+ small: true,
267
+ minimal: true,
268
+ intent: "danger",
269
+ icon: "cross",
270
+ onClick() {
271
+ actions.onClearColumn(col.key);
272
+ if (filterInputRef.current) {
273
+ filterInputRef.current.value = "";
274
+ }
275
+ },
276
+ },
277
+ "Clear all",
278
+ ),
279
+ ]),
280
+ ]),
281
+ ]);
282
+ }