@macrostrat/data-sheet 4.0.0-dev3 → 4.0.1
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.
- package/CHANGELOG.md +56 -0
- package/README.md +44 -0
- package/dist/actions/builtin.cjs +36 -5
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +3 -2
- package/dist/actions/builtin.js +36 -5
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/column-controls.cjs +149 -0
- package/dist/actions/column-controls.cjs.map +1 -0
- package/dist/actions/column-controls.d.ts +11 -0
- package/dist/actions/column-controls.js +147 -0
- package/dist/actions/column-controls.js.map +1 -0
- package/dist/actions/column-filter.cjs +68 -0
- package/dist/actions/column-filter.cjs.map +1 -0
- package/dist/actions/column-filter.d.ts +11 -0
- package/dist/actions/column-filter.js +66 -0
- package/dist/actions/column-filter.js.map +1 -0
- package/dist/actions/edit-actions.cjs +42 -0
- package/dist/actions/edit-actions.cjs.map +1 -0
- package/dist/actions/edit-actions.d.ts +14 -0
- package/dist/actions/edit-actions.js +42 -0
- package/dist/actions/edit-actions.js.map +1 -0
- package/dist/actions/filters.cjs +39 -23
- package/dist/actions/filters.cjs.map +1 -1
- package/dist/actions/filters.d.ts +6 -3
- package/dist/actions/filters.js +41 -25
- package/dist/actions/filters.js.map +1 -1
- package/dist/actions/index.d.ts +4 -0
- package/dist/actions/selection.cjs +51 -32
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +3 -7
- package/dist/actions/selection.js +51 -32
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-controls.cjs +41 -0
- package/dist/actions/table-controls.cjs.map +1 -0
- package/dist/actions/table-controls.d.ts +4 -0
- package/dist/actions/table-controls.js +39 -0
- package/dist/actions/table-controls.js.map +1 -0
- package/dist/actions/toolbar.cjs +69 -10
- package/dist/actions/toolbar.cjs.map +1 -1
- package/dist/actions/toolbar.d.ts +9 -6
- package/dist/actions/toolbar.js +69 -10
- package/dist/actions/toolbar.js.map +1 -1
- package/dist/actions/toolbar.module.sass.cjs +12 -7
- package/dist/actions/toolbar.module.sass.cjs.map +1 -1
- package/dist/actions/toolbar.module.sass.js +12 -7
- package/dist/actions/toolbar.module.sass.js.map +1 -1
- package/dist/actions/types.d.ts +49 -4
- package/dist/cell-renderer.cjs +150 -14
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.d.ts +1 -1
- package/dist/cell-renderer.js +151 -15
- package/dist/cell-renderer.js.map +1 -1
- package/dist/components/cell-detail.cjs +24 -0
- package/dist/components/cell-detail.cjs.map +1 -0
- package/dist/components/cell-detail.d.ts +12 -0
- package/dist/components/cell-detail.js +24 -0
- package/dist/components/cell-detail.js.map +1 -0
- package/dist/components/editor-popup.cjs +28 -24
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +29 -25
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/text-areas.cjs +51 -7
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +4 -1
- package/dist/components/text-areas.js +51 -7
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +46 -9
- package/dist/components/view-info.cjs.map +1 -1
- package/dist/components/view-info.d.ts +5 -1
- package/dist/components/view-info.js +47 -10
- package/dist/components/view-info.js.map +1 -1
- package/dist/core.cjs +167 -73
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +53 -6
- package/dist/core.js +169 -75
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +72 -123
- package/dist/filters/operators.cjs +91 -0
- package/dist/filters/operators.cjs.map +1 -0
- package/dist/filters/operators.d.ts +17 -0
- package/dist/filters/operators.js +91 -0
- package/dist/filters/operators.js.map +1 -0
- package/dist/index.cjs +38 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +44 -16
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +13 -12
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +13 -12
- package/dist/main.module.sass.js.map +1 -1
- package/dist/postgrest-table/data-loaders.cjs +255 -146
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +144 -46
- package/dist/postgrest-table/data-loaders.js +259 -150
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +58 -169
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +5 -2
- package/dist/postgrest-table/index.js +63 -174
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +0 -4
- package/dist/postgrest-table/loading-utils.cjs.map +1 -1
- package/dist/postgrest-table/loading-utils.js +1 -5
- package/dist/postgrest-table/loading-utils.js.map +1 -1
- package/dist/postgrest-table/main.module.sass.cjs +14 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +14 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +68 -11
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.ts +25 -0
- package/dist/provider.js +68 -11
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +95 -75
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -18
- package/dist/renderers/column-header-cell.js +98 -78
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +0 -1
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +84 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +101 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/debug-overlay.cjs +24 -0
- package/dist/utils/debug-overlay.cjs.map +1 -0
- package/dist/utils/debug-overlay.d.ts +4 -0
- package/dist/utils/debug-overlay.js +24 -0
- package/dist/utils/debug-overlay.js.map +1 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/key-handling.cjs +52 -6
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.js +52 -6
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +41 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/validation.d.ts +26 -0
- package/dist/utils/validation.js +41 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/zustand-store.cjs +119 -61
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +121 -63
- package/dist/zustand-store.js.map +1 -1
- package/package.json +3 -3
- package/src/actions/builtin.ts +62 -7
- package/src/actions/column-controls.ts +185 -0
- package/src/actions/column-filter.ts +104 -0
- package/src/actions/edit-actions.ts +67 -0
- package/src/actions/filters.ts +54 -28
- package/src/actions/index.ts +4 -0
- package/src/actions/selection.ts +73 -54
- package/src/actions/table-controls.ts +46 -0
- package/src/actions/toolbar.module.sass +22 -2
- package/src/actions/toolbar.ts +113 -16
- package/src/actions/types.ts +49 -4
- package/src/cell-renderer.ts +211 -16
- package/src/components/cell-detail.ts +30 -0
- package/src/components/editor-popup.ts +39 -25
- package/src/components/index.ts +2 -2
- package/src/components/text-areas.ts +80 -16
- package/src/components/view-info.ts +63 -4
- package/src/core.ts +321 -103
- package/src/filters/operators.ts +127 -0
- package/src/index.ts +2 -0
- package/src/main.module.sass +6 -0
- package/src/postgrest-table/data-loaders.ts +459 -209
- package/src/postgrest-table/index.ts +81 -254
- package/src/postgrest-table/main.module.sass +11 -0
- package/src/provider.ts +109 -12
- package/src/renderers/column-header-cell.ts +60 -272
- package/src/renderers/index.ts +0 -1
- package/src/types.ts +76 -2
- package/src/utils/column-spec.ts +112 -1
- package/src/utils/debug-overlay.ts +22 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/key-handling.ts +70 -6
- package/src/utils/validation.ts +72 -0
- package/src/zustand-store.ts +167 -60
- package/dist/components/actions.cjs +0 -12
- package/dist/components/actions.cjs.map +0 -1
- package/dist/components/actions.d.ts +0 -2
- package/dist/components/actions.js +0 -12
- package/dist/components/actions.js.map +0 -1
- package/dist/components/actions.module.sass.cjs +0 -12
- package/dist/components/actions.module.sass.cjs.map +0 -1
- package/dist/components/actions.module.sass.js +0 -11
- package/dist/components/actions.module.sass.js.map +0 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +0 -27
- package/dist/postgrest-table/lazy-loader-table.cjs.map +0 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +0 -3
- package/dist/postgrest-table/lazy-loader-table.js +0 -27
- package/dist/postgrest-table/lazy-loader-table.js.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +0 -216
- package/dist/renderers/column-header-cell-postgrest.cjs.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.d.ts +0 -13
- package/dist/renderers/column-header-cell-postgrest.js +0 -216
- package/dist/renderers/column-header-cell-postgrest.js.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +0 -23
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +0 -22
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +0 -1
- package/src/components/actions.ts +0 -9
- package/src/postgrest-table/lazy-loader-table.ts +0 -25
- package/src/renderers/column-header-cell-postgrest.ts +0 -282
|
@@ -7,19 +7,11 @@
|
|
|
7
7
|
* predicate filters for simple text search.
|
|
8
8
|
*/
|
|
9
9
|
import h from "@macrostrat/hyper";
|
|
10
|
-
import { ColumnHeaderCell } from "@blueprintjs/table";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Icon,
|
|
15
|
-
InputGroup,
|
|
16
|
-
Menu,
|
|
17
|
-
Tag as BPTag,
|
|
18
|
-
} from "@blueprintjs/core";
|
|
19
|
-
import { useCallback, useRef } from "react";
|
|
20
|
-
import { useSelector, useStoreAPI } from "../provider";
|
|
10
|
+
import { ColumnHeaderCell, RegionCardinality } from "@blueprintjs/table";
|
|
11
|
+
import { Button, Icon, Menu, MenuItem } from "@blueprintjs/core";
|
|
12
|
+
import { ctx, tableActionsAtom, useStoreAPI } from "../provider";
|
|
13
|
+
import { buildActionContext } from "../actions/selection";
|
|
21
14
|
import type { ColumnSpec } from "../utils/column-spec";
|
|
22
|
-
import type { ColumnSort, TableFilter } from "../actions/types";
|
|
23
15
|
import type {
|
|
24
16
|
PostgrestColumnFilter,
|
|
25
17
|
ColumnSortEntry,
|
|
@@ -36,69 +28,43 @@ export interface ColumnHeaderRendererProps extends ColumnActionsConfig {
|
|
|
36
28
|
//actions: ColumnHeaderActions;
|
|
37
29
|
}
|
|
38
30
|
|
|
39
|
-
// ---- Auto-generated column filter helpers ----
|
|
40
|
-
|
|
41
|
-
/** Build a simple text-contains filter for a column. */
|
|
42
|
-
function buildAutoFilter(col: ColumnSpec): TableFilter {
|
|
43
|
-
return {
|
|
44
|
-
id: autoFilterId(col.key),
|
|
45
|
-
name: col.name,
|
|
46
|
-
columnKey: col.key,
|
|
47
|
-
icon: "filter",
|
|
48
|
-
defaultState: { search: "" },
|
|
49
|
-
predicate(row, state) {
|
|
50
|
-
if (!state?.search) return true;
|
|
51
|
-
const val = String(row[col.key] ?? "").toLowerCase();
|
|
52
|
-
return val.includes(state.search.toLowerCase());
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Stable filter-ID prefix for auto-generated column filters. */
|
|
58
|
-
export function autoFilterId(key: string) {
|
|
59
|
-
return `__col_${key}`;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
31
|
// ---- Column header cell ----
|
|
63
32
|
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
33
|
+
/** Column header cell whose dropdown renders the `FULL_COLUMNS` controls
|
|
34
|
+
* (sort/filter + any custom column actions) from the shared action registry,
|
|
35
|
+
* scoped to this column. */
|
|
67
36
|
export function renderColumnHeaderCell({
|
|
68
37
|
col,
|
|
69
38
|
colIndex,
|
|
70
39
|
activeSort,
|
|
71
40
|
activeFilter,
|
|
72
41
|
}: ColumnHeaderRendererProps) {
|
|
73
|
-
return h(ColumnHeaderCell, { name: col.name });
|
|
74
|
-
|
|
75
42
|
const isSortable = col.sortable === true;
|
|
76
43
|
const isFilterable =
|
|
77
|
-
col.filterable === true ||
|
|
44
|
+
col.filterable === true ||
|
|
45
|
+
typeof col.filterable === "object" ||
|
|
46
|
+
(Array.isArray(col.filters) && col.filters.length > 0);
|
|
47
|
+
const hasCustomActions =
|
|
48
|
+
Array.isArray((col as any).actions) && (col as any).actions.length > 0;
|
|
78
49
|
|
|
79
|
-
if (!isSortable && !isFilterable) {
|
|
50
|
+
if (!isSortable && !isFilterable && !hasCustomActions) {
|
|
80
51
|
return h(ColumnHeaderCell, { name: col.name });
|
|
81
52
|
}
|
|
82
53
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
activeFilter.state?.search != null;
|
|
87
|
-
|
|
54
|
+
// `activeFilter` is the active store entry targeting this column (any filter
|
|
55
|
+
// type), or null — so the indicator lights for rich and operator filters.
|
|
56
|
+
const hasFilterActive = activeFilter != null;
|
|
88
57
|
const hasSortActive = activeSort != null;
|
|
89
58
|
|
|
90
59
|
return h(ColumnHeaderCell, {
|
|
91
60
|
name: col.name,
|
|
61
|
+
// Persistent interaction bar so the menu caret is always clickable — the
|
|
62
|
+
// hover-triggered caret was blocked by the selection overlay when the
|
|
63
|
+
// column was selected.
|
|
64
|
+
enableColumnInteractionBar: true,
|
|
92
65
|
nameRenderer: () =>
|
|
93
66
|
h(ColumnHeaderName, { col, hasSortActive, hasFilterActive, activeSort }),
|
|
94
|
-
menuRenderer: () =>
|
|
95
|
-
h(ClientColumnActionsMenu, {
|
|
96
|
-
col,
|
|
97
|
-
isSortable,
|
|
98
|
-
isFilterable,
|
|
99
|
-
activeSort,
|
|
100
|
-
activeFilter,
|
|
101
|
-
}),
|
|
67
|
+
menuRenderer: () => h(ColumnHeaderControls, { colIndex }),
|
|
102
68
|
});
|
|
103
69
|
}
|
|
104
70
|
|
|
@@ -148,241 +114,63 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
|
148
114
|
);
|
|
149
115
|
}
|
|
150
116
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/** Menu content rendered inside ColumnHeaderCell's built-in dropdown. */
|
|
158
|
-
function ClientColumnActionsMenu({
|
|
159
|
-
col,
|
|
160
|
-
isSortable,
|
|
161
|
-
isFilterable,
|
|
162
|
-
activeSort,
|
|
163
|
-
activeFilter,
|
|
164
|
-
}) {
|
|
117
|
+
/** Dropdown content: the `FULL_COLUMNS` controls for this column, sourced from
|
|
118
|
+
* the shared action registry and scoped to the column via a synthetic
|
|
119
|
+
* single-column selection context — so the header and toolbar render the same
|
|
120
|
+
* sort/filter (and custom column) controls. */
|
|
121
|
+
function ColumnHeaderControls({ colIndex }: { colIndex: number }) {
|
|
165
122
|
const storeAPI = useStoreAPI();
|
|
166
|
-
const
|
|
123
|
+
const actions = ctx.useValue(tableActionsAtom);
|
|
167
124
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}, [col, storeAPI]);
|
|
125
|
+
// Scope the action context to this column (as if it were the selection).
|
|
126
|
+
const actionCtx = buildActionContext(
|
|
127
|
+
{
|
|
128
|
+
...storeAPI.getState(),
|
|
129
|
+
selection: [{ cols: [colIndex, colIndex], rows: undefined }],
|
|
130
|
+
} as any,
|
|
131
|
+
storeAPI.setState,
|
|
132
|
+
);
|
|
178
133
|
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
134
|
+
const controls = actions.filter(
|
|
135
|
+
(a) =>
|
|
136
|
+
a.targets.includes(RegionCardinality.FULL_COLUMNS) &&
|
|
137
|
+
(a.appliesTo?.(actionCtx) ?? true),
|
|
138
|
+
);
|
|
184
139
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
h(
|
|
190
|
-
h(ButtonGroup, { minimal: true }, [
|
|
191
|
-
h(
|
|
192
|
-
Button,
|
|
193
|
-
{
|
|
194
|
-
icon: "sort-asc",
|
|
195
|
-
active: activeSort?.ascending === true,
|
|
196
|
-
intent: activeSort?.ascending === true ? "primary" : "none",
|
|
197
|
-
onClick() {
|
|
198
|
-
const store = storeAPI.getState();
|
|
199
|
-
if (activeSort?.ascending === true) {
|
|
200
|
-
store.setColumnSort(col.key, null);
|
|
201
|
-
} else {
|
|
202
|
-
store.setColumnSort(col.key, true);
|
|
203
|
-
}
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
"A→Z",
|
|
207
|
-
),
|
|
208
|
-
h(
|
|
209
|
-
Button,
|
|
210
|
-
{
|
|
211
|
-
icon: "sort-desc",
|
|
212
|
-
active: activeSort?.ascending === false,
|
|
213
|
-
intent: activeSort?.ascending === false ? "primary" : "none",
|
|
214
|
-
onClick() {
|
|
215
|
-
const store = storeAPI.getState();
|
|
216
|
-
if (activeSort?.ascending === false) {
|
|
217
|
-
store.setColumnSort(col.key, null);
|
|
218
|
-
} else {
|
|
219
|
-
store.setColumnSort(col.key, false);
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
"Z→A",
|
|
224
|
-
),
|
|
225
|
-
]),
|
|
226
|
-
]),
|
|
227
|
-
]),
|
|
228
|
-
h.if(isFilterable)("div", { style: { marginBottom: "12px" } }, [
|
|
229
|
-
h("div", { style: sortFilterLabelStyle }, "Filter"),
|
|
230
|
-
h(
|
|
231
|
-
"div",
|
|
232
|
-
{ style: { display: "flex", gap: "4px", alignItems: "center" } },
|
|
233
|
-
[
|
|
234
|
-
h(InputGroup, {
|
|
235
|
-
className: "filter-value-input",
|
|
236
|
-
small: true,
|
|
237
|
-
placeholder: "Search…",
|
|
238
|
-
defaultValue: activeFilterEntry?.state?.search ?? "",
|
|
239
|
-
inputRef: filterInputRef,
|
|
240
|
-
onKeyDown(e) {
|
|
241
|
-
if (e.key === "Enter") {
|
|
242
|
-
applyFilter();
|
|
243
|
-
}
|
|
244
|
-
},
|
|
245
|
-
rightElement: h(Button, {
|
|
246
|
-
icon: "arrow-right",
|
|
247
|
-
minimal: true,
|
|
248
|
-
small: true,
|
|
249
|
-
onClick: applyFilter,
|
|
250
|
-
}),
|
|
251
|
-
}),
|
|
252
|
-
],
|
|
253
|
-
),
|
|
254
|
-
]),
|
|
255
|
-
h.if(hasAnyActive)(
|
|
256
|
-
"div",
|
|
257
|
-
{
|
|
258
|
-
style: {
|
|
259
|
-
display: "flex",
|
|
260
|
-
justifyContent: "flex-end",
|
|
261
|
-
paddingTop: "4px",
|
|
262
|
-
borderTop: "1px solid var(--divider-color, rgba(16, 22, 26, 0.15))",
|
|
263
|
-
},
|
|
264
|
-
},
|
|
265
|
-
[
|
|
266
|
-
h(
|
|
140
|
+
const rendered = controls
|
|
141
|
+
.map((a) =>
|
|
142
|
+
a.render != null
|
|
143
|
+
? a.render(actionCtx)
|
|
144
|
+
: h(
|
|
267
145
|
Button,
|
|
268
146
|
{
|
|
147
|
+
key: a.id,
|
|
269
148
|
small: true,
|
|
270
149
|
minimal: true,
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
onClick()
|
|
274
|
-
const store = storeAPI.getState();
|
|
275
|
-
store.setColumnSort(col.key, null);
|
|
276
|
-
store.removeFilter(autoFilterId(col.key));
|
|
277
|
-
if (filterInputRef.current) {
|
|
278
|
-
filterInputRef.current.value = "";
|
|
279
|
-
}
|
|
280
|
-
},
|
|
150
|
+
icon: a.icon,
|
|
151
|
+
intent: a.intent,
|
|
152
|
+
onClick: () => a.run?.(actionCtx),
|
|
281
153
|
},
|
|
282
|
-
|
|
154
|
+
a.name,
|
|
283
155
|
),
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
]),
|
|
287
|
-
]);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const sortFilterLabelStyle = {
|
|
291
|
-
fontWeight: 600,
|
|
292
|
-
fontSize: "11px",
|
|
293
|
-
textTransform: "uppercase" as const,
|
|
294
|
-
letterSpacing: "0.5px",
|
|
295
|
-
color: "var(--secondary-color, #5c7080)",
|
|
296
|
-
marginBottom: "6px",
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
// ---- Sort/filter state bar ----
|
|
156
|
+
)
|
|
157
|
+
.filter(Boolean);
|
|
300
158
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
* are active. */
|
|
304
|
-
export function SortFilterBar() {
|
|
305
|
-
const columnSorts = useSelector((state) => state.columnSorts);
|
|
306
|
-
const activeFilters = useSelector((state) => state.activeFilters);
|
|
307
|
-
const storeAPI = useStoreAPI();
|
|
308
|
-
|
|
309
|
-
// Collect auto-generated column filters
|
|
310
|
-
const columnFilterEntries: { key: string; search: string }[] = [];
|
|
311
|
-
for (const [id, entry] of activeFilters) {
|
|
312
|
-
if (id.startsWith("__col_") && entry.state?.search) {
|
|
313
|
-
columnFilterEntries.push({
|
|
314
|
-
key: id.replace("__col_", ""),
|
|
315
|
-
search: entry.state.search,
|
|
316
|
-
});
|
|
317
|
-
}
|
|
159
|
+
if (rendered.length === 0) {
|
|
160
|
+
return h(Menu, [h(MenuItem, { text: "No options", disabled: true })]);
|
|
318
161
|
}
|
|
319
162
|
|
|
320
|
-
const hasAnything = columnSorts.length > 0 || columnFilterEntries.length > 0;
|
|
321
|
-
if (!hasAnything) return null;
|
|
322
|
-
|
|
323
163
|
return h(
|
|
324
|
-
"div",
|
|
164
|
+
"div.column-header-controls",
|
|
325
165
|
{
|
|
326
166
|
style: {
|
|
167
|
+
padding: "8px",
|
|
327
168
|
display: "flex",
|
|
328
|
-
flexDirection: "
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
marginBottom: "4px",
|
|
332
|
-
alignItems: "center",
|
|
169
|
+
flexDirection: "column",
|
|
170
|
+
gap: "6px",
|
|
171
|
+
alignItems: "flex-start",
|
|
333
172
|
},
|
|
334
173
|
},
|
|
335
|
-
|
|
336
|
-
columnSorts.map((s) =>
|
|
337
|
-
h(
|
|
338
|
-
BPTag,
|
|
339
|
-
{
|
|
340
|
-
key: `sort-${s.key}`,
|
|
341
|
-
icon: s.ascending ? "sort-asc" : "sort-desc",
|
|
342
|
-
intent: "primary",
|
|
343
|
-
onRemove() {
|
|
344
|
-
storeAPI.getState().setColumnSort(s.key, null);
|
|
345
|
-
},
|
|
346
|
-
minimal: true,
|
|
347
|
-
},
|
|
348
|
-
`${s.key}: ${s.ascending ? "A→Z" : "Z→A"}`,
|
|
349
|
-
),
|
|
350
|
-
),
|
|
351
|
-
columnFilterEntries.map((f) =>
|
|
352
|
-
h(
|
|
353
|
-
BPTag,
|
|
354
|
-
{
|
|
355
|
-
key: `filter-${f.key}`,
|
|
356
|
-
icon: "filter",
|
|
357
|
-
intent: "warning",
|
|
358
|
-
onRemove() {
|
|
359
|
-
storeAPI.getState().removeFilter(autoFilterId(f.key));
|
|
360
|
-
},
|
|
361
|
-
minimal: true,
|
|
362
|
-
},
|
|
363
|
-
`${f.key} contains "${f.search}"`,
|
|
364
|
-
),
|
|
365
|
-
),
|
|
366
|
-
h(
|
|
367
|
-
Button,
|
|
368
|
-
{
|
|
369
|
-
minimal: true,
|
|
370
|
-
small: true,
|
|
371
|
-
icon: "cross",
|
|
372
|
-
onClick() {
|
|
373
|
-
const store = storeAPI.getState();
|
|
374
|
-
// Clear all column sorts
|
|
375
|
-
store.clearColumnSorts();
|
|
376
|
-
// Clear auto-generated column filters
|
|
377
|
-
for (const [id] of activeFilters) {
|
|
378
|
-
if (id.startsWith("__col_")) {
|
|
379
|
-
store.removeFilter(id);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
},
|
|
383
|
-
},
|
|
384
|
-
"Clear all",
|
|
385
|
-
),
|
|
386
|
-
],
|
|
174
|
+
rendered,
|
|
387
175
|
);
|
|
388
176
|
}
|
package/src/renderers/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -5,7 +5,8 @@ import type {
|
|
|
5
5
|
Table2,
|
|
6
6
|
} from "@blueprintjs/table";
|
|
7
7
|
import { ColumnSpec, ColumnSpecOptions } from "./utils";
|
|
8
|
-
import { OverlayToaster
|
|
8
|
+
import { OverlayToaster } from "@blueprintjs/core";
|
|
9
|
+
import type { CellEdit } from "./actions";
|
|
9
10
|
|
|
10
11
|
/** A single column sort entry for client-side sorting.
|
|
11
12
|
* Defined here (rather than in actions/types) to avoid circular imports. */
|
|
@@ -14,6 +15,23 @@ export interface ColumnSort {
|
|
|
14
15
|
ascending: boolean;
|
|
15
16
|
}
|
|
16
17
|
|
|
18
|
+
/** Direction of keyboard navigation between cells. */
|
|
19
|
+
export type NavDirection = "up" | "down" | "left" | "right";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A structured, revertible description of a user edit. Emitted via the
|
|
23
|
+
* `onEdit` hook so a consumer can capture edits as operations (and, with the
|
|
24
|
+
* controlled-overlay API, own the edited state) instead of diffing
|
|
25
|
+
* `updatedData`. This is the write half of the data-sheet's read/write
|
|
26
|
+
* contract — the mirror of how data flows in.
|
|
27
|
+
*/
|
|
28
|
+
export type EditEvent<T = any> =
|
|
29
|
+
| { type: "setCells"; cells: CellEdit[] }
|
|
30
|
+
| { type: "deleteRows"; rowIndices: number[] }
|
|
31
|
+
| { type: "restoreRows"; rowIndices: number[] }
|
|
32
|
+
| { type: "addRow"; rowIndex: number; value: Partial<T> }
|
|
33
|
+
| { type: "resetChanges" };
|
|
34
|
+
|
|
17
35
|
export interface DataSheetCoreProps<T> {
|
|
18
36
|
data: T[];
|
|
19
37
|
columnSpec?: ColumnSpec[];
|
|
@@ -27,6 +45,11 @@ export enum TableElementStatus {
|
|
|
27
45
|
ADDED = "added",
|
|
28
46
|
}
|
|
29
47
|
|
|
48
|
+
/** Property key holding a stable synthetic id on rows added in-table. Added
|
|
49
|
+
* rows aren't in the data provider, so they need their own identity to survive
|
|
50
|
+
* a provider re-fetch; it's carried on the row and preserved through edits. */
|
|
51
|
+
export const DS_ROW_ID = "__dsRowId";
|
|
52
|
+
|
|
30
53
|
/** Proxy stored during a copy operation, enabling backend-mediated paste
|
|
31
54
|
* for lazy-loaded tables where not all data is available locally. */
|
|
32
55
|
export interface ClipboardProxy {
|
|
@@ -67,6 +90,46 @@ export interface DataSheetState<T> {
|
|
|
67
90
|
filteredRowIndices: number[] | null;
|
|
68
91
|
/** Active column sort entries for client-side sorting. */
|
|
69
92
|
columnSorts: ColumnSort[];
|
|
93
|
+
/** Whether selecting a cell automatically activates its surface (opens an
|
|
94
|
+
* editor/detail panel and, for editors, focuses it). `"manual"` opens only
|
|
95
|
+
* on click. */
|
|
96
|
+
cellInteraction: "auto" | "manual";
|
|
97
|
+
/** Runtime override of `cellInteraction`: while `false`, auto-activation is
|
|
98
|
+
* suppressed (set by pressing Escape, re-armed by clicking a cell) so the
|
|
99
|
+
* keyboard prioritizes navigation. */
|
|
100
|
+
autoActivateArmed: boolean;
|
|
101
|
+
/** Direction of the last keyboard navigation, used to place an editor's
|
|
102
|
+
* cursor on the side the user is travelling toward. `null` after a click. */
|
|
103
|
+
lastNavDirection: NavDirection | null;
|
|
104
|
+
/** The table's focusable holder element; editors return focus here when the
|
|
105
|
+
* cursor leaves them so arrow-key navigation resumes. */
|
|
106
|
+
tableElement: HTMLElement | null;
|
|
107
|
+
/** Whether the focused cell's surface (editor or detail panel) is open.
|
|
108
|
+
* Owned by the store — not per-popover — so navigation, clicks, and the
|
|
109
|
+
* Escape handler all agree on it. */
|
|
110
|
+
cellSurfaceOpen: boolean;
|
|
111
|
+
/** Optional observer called for every user edit as a structured
|
|
112
|
+
* `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a
|
|
113
|
+
* consumer capture edits as revertible operations. */
|
|
114
|
+
onEdit?: (event: EditEvent<T>) => void;
|
|
115
|
+
/** Row identity for the edit overlay — stable across a provider re-sort,
|
|
116
|
+
* unlike an array index. Defaults to `(row) => row?.id`; a data provider
|
|
117
|
+
* supplies its own (e.g. a PostgREST identity key). Used to re-attach edits
|
|
118
|
+
* when the loader replaces `data` with a re-ordered window. */
|
|
119
|
+
identity: (row: any) => string | number | null | undefined;
|
|
120
|
+
/** Edits/statuses held by identity for rows not currently loaded (server
|
|
121
|
+
* sources), re-attached when their row next arrives. */
|
|
122
|
+
pendingOverlayById: Map<
|
|
123
|
+
string | number,
|
|
124
|
+
{ edit?: any; status?: TableElementStatus }
|
|
125
|
+
>;
|
|
126
|
+
/** True when the consumer controls the `updatedData`/`rowStatus` overlay; the
|
|
127
|
+
* loader-boundary identity remap is skipped (the consumer owns it). */
|
|
128
|
+
controlledOverlay: boolean;
|
|
129
|
+
/** Whether row deletion is available. Set from the data provider: an explicit
|
|
130
|
+
* `provider` without `deleteRows` disables deletion entirely (the delete
|
|
131
|
+
* affordance greys out and the delete key is a no-op). Defaults to `true`. */
|
|
132
|
+
canDeleteRows: boolean;
|
|
70
133
|
}
|
|
71
134
|
|
|
72
135
|
type DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;
|
|
@@ -80,7 +143,18 @@ export interface DataSheetStoreMain<T> extends DataSheetVals<T> {
|
|
|
80
143
|
onSelectionEdited(value: any): void;
|
|
81
144
|
onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
|
|
82
145
|
onColumnWidthChanged(columnIndex: number, newWidth: number): void;
|
|
83
|
-
moveFocusedCell(direction:
|
|
146
|
+
moveFocusedCell(direction: NavDirection): void;
|
|
147
|
+
/** Suppress auto-activation until the next click (Escape enters nav mode). */
|
|
148
|
+
suppressAutoActivate(): void;
|
|
149
|
+
/** Re-arm auto-activation (a click re-enables auto-focus). */
|
|
150
|
+
armAutoActivate(): void;
|
|
151
|
+
/** Open the focused cell's surface (editor or detail panel). */
|
|
152
|
+
openCellSurface(): void;
|
|
153
|
+
/** Close the focused cell's surface. When `suppress` is true (the default,
|
|
154
|
+
* as for Escape), auto mode also enters navigation mode (auto-activation is
|
|
155
|
+
* suppressed until the next click). A click-dismiss passes `suppress: false`
|
|
156
|
+
* so it just closes without changing the global mode. */
|
|
157
|
+
closeCellSurface(opts?: { suppress?: boolean }): void;
|
|
84
158
|
deleteSelectedRows(): void;
|
|
85
159
|
clearSelection(): void;
|
|
86
160
|
resetChanges(): void;
|
package/src/utils/column-spec.ts
CHANGED
|
@@ -28,15 +28,126 @@ export type ColumnDataType =
|
|
|
28
28
|
| "object"
|
|
29
29
|
| "array";
|
|
30
30
|
|
|
31
|
+
/** Severity of a cell validation result. `warning` is soft (flagged, doesn't
|
|
32
|
+
* block saving); `error` is hard (blocks saving). */
|
|
33
|
+
export type ValidationSeverity = "warning" | "error";
|
|
34
|
+
|
|
35
|
+
/** The result of validating a cell. `null` means valid. */
|
|
36
|
+
export interface CellValidation {
|
|
37
|
+
severity: ValidationSeverity;
|
|
38
|
+
message?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Context handed to per-cell renderers (`valueRenderer`, and — as the
|
|
43
|
+
* `cellContext` prop — a custom `cellComponent`). It lets a renderer draw
|
|
44
|
+
* based on the row/column position and the cell's edit status, and, combined
|
|
45
|
+
* with the editing API, write edits back for a specific cell.
|
|
46
|
+
*
|
|
47
|
+
* `rowIndex` is the underlying **data-row index** (the value edit methods
|
|
48
|
+
* expect), so it stays stable when a sort or filter reorders the view.
|
|
49
|
+
*/
|
|
50
|
+
export interface CellRenderContext<T = any> {
|
|
51
|
+
/** The cell's current value (the edited value if present, else the base). */
|
|
52
|
+
value: any;
|
|
53
|
+
/** Underlying data-row index — stable under sort/filter. */
|
|
54
|
+
rowIndex: number;
|
|
55
|
+
/** Column index within the active column spec. */
|
|
56
|
+
colIndex: number;
|
|
57
|
+
/** The full column spec for this cell's column. */
|
|
58
|
+
column: ColumnSpec;
|
|
59
|
+
/** The full row object backing this cell (may be undefined while loading). */
|
|
60
|
+
row: T | undefined;
|
|
61
|
+
/** Whether this cell has an uncommitted edit. */
|
|
62
|
+
isEdited: boolean;
|
|
63
|
+
/** Whether this cell's row is marked for deletion. */
|
|
64
|
+
isDeleted: boolean;
|
|
65
|
+
/** Validation result for this cell, or `null` when valid. Orthogonal to the
|
|
66
|
+
* edit status — a cell can be both edited and invalid. */
|
|
67
|
+
validation: CellValidation | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The editor configuration for a cell. Mirrors the static `dataEditor` /
|
|
72
|
+
* `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can
|
|
73
|
+
* override either one for an individual cell.
|
|
74
|
+
*/
|
|
75
|
+
export interface CellEditors {
|
|
76
|
+
dataEditor?: any;
|
|
77
|
+
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Context for a cell's detail surface (`cellDetail`). Extends the render
|
|
82
|
+
* context with the edit affordances and controls a surface needs, so one
|
|
83
|
+
* component can act as an editor (when `editable`) or a read-only viewer
|
|
84
|
+
* (otherwise). This is the write side of the read/write contract, per-cell.
|
|
85
|
+
*/
|
|
86
|
+
export interface CellDetailContext<T = any> extends CellRenderContext<T> {
|
|
87
|
+
/** Whether this cell is editable (column × table × not-deleted). */
|
|
88
|
+
editable: boolean;
|
|
89
|
+
/** Commit a new value for this cell. */
|
|
90
|
+
onChange: (value: any) => void;
|
|
91
|
+
/** Reset this cell (and selection) to its base value. */
|
|
92
|
+
resetValue: () => void;
|
|
93
|
+
/** Close the surface and return focus to the table. */
|
|
94
|
+
close: () => void;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** How a cell's detail surface is presented. Orthogonal to what it renders. */
|
|
98
|
+
export type DetailPresentation = "popover" | "modal" | "inline";
|
|
99
|
+
|
|
31
100
|
export interface ColumnSpec {
|
|
32
101
|
name: string;
|
|
33
102
|
key: string;
|
|
103
|
+
/** When true, an empty value is an error (sugar over `validate`). */
|
|
34
104
|
required?: boolean;
|
|
105
|
+
/** Validate a cell's value. Return a `{ severity, message }` for a
|
|
106
|
+
* warning/error, or `null` when valid. Runs after the `required` check.
|
|
107
|
+
* `warning` flags the cell but allows saving; `error` blocks saving. */
|
|
108
|
+
validate?: (
|
|
109
|
+
value: any,
|
|
110
|
+
row: any,
|
|
111
|
+
ctx: { rowIndex: number },
|
|
112
|
+
) => CellValidation | null;
|
|
113
|
+
/** @deprecated Prefer `validate`, which carries severity + a message.
|
|
114
|
+
* A falsy result maps to an `error`. */
|
|
35
115
|
isValid?: (d: any) => boolean;
|
|
36
116
|
transformValue?: (d: any) => any;
|
|
37
|
-
valueRenderer?: (
|
|
117
|
+
valueRenderer?: (
|
|
118
|
+
d: any,
|
|
119
|
+
ctx?: CellRenderContext,
|
|
120
|
+
) => string | React.ReactNode;
|
|
38
121
|
headerRenderer?: (d: any) => string | React.ReactNode;
|
|
39
122
|
dataEditor?: any;
|
|
123
|
+
/**
|
|
124
|
+
* Choose the editor for an individual cell from its render context,
|
|
125
|
+
* overriding the static `dataEditor` / `inlineEditor` for that cell. Return
|
|
126
|
+
* `undefined` (or omit a key) to fall back to the static configuration —
|
|
127
|
+
* e.g. show a textarea only for cells whose value is long. A returned key is
|
|
128
|
+
* respected even when its value is `false`/`null` (i.e. "no editor here").
|
|
129
|
+
*/
|
|
130
|
+
editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Render a read-only detail panel for a cell. When set, selecting the cell
|
|
133
|
+
* opens a popover with this content (following the table's `cellInteraction`
|
|
134
|
+
* mode). The panel never takes keyboard focus, so arrow keys keep navigating
|
|
135
|
+
* the table; Escape closes it. Mutually distinct from `dataEditor` — use this
|
|
136
|
+
* for non-editable surfaces (previews, summaries, links).
|
|
137
|
+
*
|
|
138
|
+
* @deprecated Prefer `cellDetail`, which unifies editor and viewer.
|
|
139
|
+
*/
|
|
140
|
+
detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;
|
|
141
|
+
/**
|
|
142
|
+
* The unified cell surface (Workstream A): one renderer that acts as an
|
|
143
|
+
* editor when `ctx.editable` and a read-only viewer otherwise, superseding
|
|
144
|
+
* `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen
|
|
145
|
+
* separately via `detailPresentation` (popover / modal / inline), so the
|
|
146
|
+
* same component works in any container.
|
|
147
|
+
*/
|
|
148
|
+
cellDetail?: (ctx: CellDetailContext) => React.ReactNode;
|
|
149
|
+
/** How `cellDetail` is presented. Defaults to `"popover"`. */
|
|
150
|
+
detailPresentation?: DetailPresentation;
|
|
40
151
|
cellComponent?: any;
|
|
41
152
|
category?: string;
|
|
42
153
|
editable?: boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
|
|
3
|
+
export function CellRendererDebugOverlay({ cellRendererDependencies, names }) {
|
|
4
|
+
/** Debug overlay for cell renderer dependencies */
|
|
5
|
+
const lastRenderDependencies = useRef<any[]>(cellRendererDependencies);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
let changeDepNames = [];
|
|
8
|
+
for (const [i, dep] of cellRendererDependencies.entries()) {
|
|
9
|
+
if (dep !== lastRenderDependencies.current[i]) {
|
|
10
|
+
changeDepNames.push(names[i]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (changeDepNames.length > 0) {
|
|
14
|
+
console.log(
|
|
15
|
+
"Cell renderer dependencies changed:",
|
|
16
|
+
changeDepNames.join(", "),
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
lastRenderDependencies.current = cellRendererDependencies;
|
|
20
|
+
}, cellRendererDependencies);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export * from "./column-spec";
|
|
2
2
|
export * from "./key-handling";
|
|
3
|
+
export * from "./validation";
|
|
4
|
+
export { CellRendererDebugOverlay } from "./debug-overlay.ts";
|
|
3
5
|
|
|
4
6
|
export function range(arr: number[]) {
|
|
5
7
|
if (arr.length != 2) throw new Error("Range must have two elements");
|