@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
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Table-scoped controls expressed as `TableAction`s (no special
|
|
3
|
+
* `dataSheetActions` chrome). They target every cardinality, so they sit in the
|
|
4
|
+
* toolbar regardless of selection — reachable from the one standard actions
|
|
5
|
+
* path like everything else. Opt-in: add them to the `actions` prop.
|
|
6
|
+
*/
|
|
7
|
+
import h from "@macrostrat/hyper";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { Button, ControlGroup, InputGroup } from "@blueprintjs/core";
|
|
10
|
+
import { useSelector } from "../provider";
|
|
11
|
+
import type { TableAction } from "./types";
|
|
12
|
+
import { ALL_CARDINALITIES } from "./edit-actions";
|
|
13
|
+
|
|
14
|
+
function ScrollToRowControl() {
|
|
15
|
+
const [value, setValue] = useState("");
|
|
16
|
+
const scrollToRow = useSelector((s) => s.scrollToRow);
|
|
17
|
+
const go = () => {
|
|
18
|
+
const r = parseInt(value, 10);
|
|
19
|
+
if (!Number.isNaN(r)) scrollToRow(r - 1);
|
|
20
|
+
};
|
|
21
|
+
return h(ControlGroup, [
|
|
22
|
+
h(InputGroup, {
|
|
23
|
+
type: "number",
|
|
24
|
+
placeholder: "Row #",
|
|
25
|
+
value,
|
|
26
|
+
small: true,
|
|
27
|
+
style: { width: "6em" },
|
|
28
|
+
onValueChange: setValue,
|
|
29
|
+
onKeyDown: (e: any) => {
|
|
30
|
+
if (e.key === "Enter") go();
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
h(Button, { small: true, minimal: true, icon: "arrow-right", onClick: go }),
|
|
34
|
+
]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Scroll to a 1-based row number. Meaningful for large, addressable sources;
|
|
38
|
+
* add it to `actions`. Present in the toolbar regardless of selection. */
|
|
39
|
+
export const scrollToRowAction: TableAction = {
|
|
40
|
+
id: "scroll-to-row",
|
|
41
|
+
name: "Scroll to row",
|
|
42
|
+
icon: "arrow-right",
|
|
43
|
+
targets: ALL_CARDINALITIES,
|
|
44
|
+
requiresEditable: false,
|
|
45
|
+
render: () => h(ScrollToRowControl),
|
|
46
|
+
};
|
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
.actions-toolbar
|
|
2
2
|
display: flex
|
|
3
3
|
flex-direction: row
|
|
4
|
-
gap:
|
|
5
|
-
margin-bottom: 4px
|
|
4
|
+
gap: 8px
|
|
6
5
|
align-items: center
|
|
6
|
+
min-height: 32px
|
|
7
|
+
padding: 4px 8px
|
|
8
|
+
background-color: var(--panel-secondary-background-color)
|
|
9
|
+
|
|
10
|
+
// Leading label naming the current selection shape (no icon) — reads as the
|
|
11
|
+
// toolbar's title.
|
|
12
|
+
.toolbar-title
|
|
13
|
+
font-weight: 600
|
|
14
|
+
white-space: nowrap
|
|
15
|
+
min-width: 100px
|
|
7
16
|
|
|
8
17
|
.spacer
|
|
9
18
|
flex-grow: 1
|
|
@@ -28,3 +37,14 @@
|
|
|
28
37
|
gap: 4px
|
|
29
38
|
margin-bottom: 4px
|
|
30
39
|
align-items: center
|
|
40
|
+
justify-content: flex-start
|
|
41
|
+
|
|
42
|
+
&>.group
|
|
43
|
+
display: flex
|
|
44
|
+
flex-direction: row
|
|
45
|
+
gap: 4px
|
|
46
|
+
|
|
47
|
+
// The current filter window shown after the filter name on its tag
|
|
48
|
+
.filter-window
|
|
49
|
+
opacity: 0.8
|
|
50
|
+
font-variant-numeric: tabular-nums
|
package/src/actions/toolbar.ts
CHANGED
|
@@ -12,15 +12,48 @@ import type { TableAction, TableActionContext } from "./types";
|
|
|
12
12
|
import { RegionCardinality } from "@blueprintjs/table";
|
|
13
13
|
import { useToaster } from "../notifications.ts";
|
|
14
14
|
import { DataSheetStore } from "../types.ts";
|
|
15
|
+
import { ColumnSpec } from "../utils";
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/** A short title describing the current selection (its shape), shown as the
|
|
18
|
+
* toolbar's leading label — no icon. */
|
|
19
|
+
function selectionTitle<T>(ctx: TableActionContext<T>): string | null {
|
|
20
|
+
const sh = ctx.selectionShape;
|
|
21
|
+
switch (sh.cardinality) {
|
|
22
|
+
case RegionCardinality.FULL_COLUMNS: {
|
|
23
|
+
if (ctx.columnKey != null) {
|
|
24
|
+
const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);
|
|
25
|
+
return col?.name ?? "Column";
|
|
26
|
+
}
|
|
27
|
+
return `${sh.columns} columns`;
|
|
28
|
+
}
|
|
29
|
+
case RegionCardinality.FULL_ROWS:
|
|
30
|
+
return ctx.rowIndex != null ? "1 row" : `${sh.rows} rows`;
|
|
31
|
+
case RegionCardinality.CELLS:
|
|
32
|
+
return ctx.cell != null ? "Cell" : `${sh.columns}×${sh.rows} cells`;
|
|
33
|
+
case RegionCardinality.FULL_TABLE:
|
|
34
|
+
return null;
|
|
35
|
+
default:
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Toolbar that renders the actions/controls applicable to the current
|
|
41
|
+
* selection cardinality (modal by selection) and edit mode. Actions with a
|
|
42
|
+
* `render` show their live control; others show a button (with an optional
|
|
43
|
+
* `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`
|
|
44
|
+
* are merged when their columns are selected. A capsule on the left shows the
|
|
45
|
+
* current selection polarity. */
|
|
46
|
+
export function ActionsToolbar<T>({
|
|
47
|
+
actions,
|
|
48
|
+
tableName,
|
|
49
|
+
}: {
|
|
50
|
+
actions: TableAction<T>[];
|
|
51
|
+
tableName?: string;
|
|
52
|
+
}) {
|
|
21
53
|
const selection = useSelector((state) => state.selection);
|
|
22
54
|
const editable = useSelector((state) => state.editable);
|
|
23
55
|
const columnSpec = useSelector((state) => state.columnSpec);
|
|
56
|
+
const storeAPI = useStoreAPI();
|
|
24
57
|
|
|
25
58
|
const cardinality = useMemo(
|
|
26
59
|
() => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,
|
|
@@ -38,18 +71,45 @@ export function ActionsToolbar<T>({ actions }: { actions: TableAction<T>[] }) {
|
|
|
38
71
|
[allActions, cardinality, editable],
|
|
39
72
|
);
|
|
40
73
|
|
|
41
|
-
|
|
74
|
+
// Context for `render`-style controls (they subscribe to the store
|
|
75
|
+
// themselves; this resolves the selected column/rows).
|
|
76
|
+
const ctx = buildActionContext(
|
|
77
|
+
storeAPI.getState(),
|
|
78
|
+
storeAPI.setState,
|
|
79
|
+
) as TableActionContext<T>;
|
|
42
80
|
|
|
43
|
-
|
|
44
|
-
|
|
81
|
+
// The toolbar is for actions that AREN'T keyboard-accessible: any action
|
|
82
|
+
// with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and
|
|
83
|
+
// is omitted here (it still works via its shortcut). Then refine by selection
|
|
84
|
+
// shape beyond cardinality (e.g. single column only).
|
|
85
|
+
const shownActions = applicableActions.filter(
|
|
86
|
+
(action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const toolbarIsShown = useMemo(
|
|
90
|
+
() => hasAnyDisplayableActions(actions, columnSpec),
|
|
91
|
+
[actions, columnSpec],
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (!toolbarIsShown) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The toolbar is always mounted if actions are available, so it can't flicker
|
|
99
|
+
// in/out as the selection or action set changes — the container is stable;
|
|
100
|
+
// only its contents (title + buttons) change. Avoids layout jank.
|
|
101
|
+
const title = selectionTitle(ctx) ?? tableName ?? "Table";
|
|
102
|
+
|
|
103
|
+
return h("div.actions-toolbar", [
|
|
104
|
+
h("span.toolbar-title", { key: "title" }, title),
|
|
45
105
|
h(
|
|
46
106
|
ButtonGroup,
|
|
47
|
-
{ minimal: true },
|
|
48
|
-
|
|
49
|
-
h(ActionButton, { key: action.id, action }),
|
|
107
|
+
{ key: "actions", minimal: true },
|
|
108
|
+
shownActions.map((action) =>
|
|
109
|
+
h(ActionButton, { key: action.id, action, ctx }),
|
|
50
110
|
),
|
|
51
111
|
),
|
|
52
|
-
);
|
|
112
|
+
]);
|
|
53
113
|
}
|
|
54
114
|
|
|
55
115
|
function getMessageForError(e: any) {
|
|
@@ -83,7 +143,7 @@ export function runActionWrapper<T>(
|
|
|
83
143
|
return;
|
|
84
144
|
}
|
|
85
145
|
try {
|
|
86
|
-
const res = action.run(ctx, configState);
|
|
146
|
+
const res = action.run?.(ctx, configState);
|
|
87
147
|
if (res instanceof Promise) {
|
|
88
148
|
res
|
|
89
149
|
.then(() => {})
|
|
@@ -96,9 +156,23 @@ export function runActionWrapper<T>(
|
|
|
96
156
|
}
|
|
97
157
|
}
|
|
98
158
|
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
function ActionButton<T>({
|
|
159
|
+
/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.
|
|
160
|
+
* Kept hook-free so the two paths don't share a hook order. */
|
|
161
|
+
function ActionButton<T>({
|
|
162
|
+
action,
|
|
163
|
+
ctx,
|
|
164
|
+
}: {
|
|
165
|
+
action: TableAction<T>;
|
|
166
|
+
ctx: TableActionContext<T>;
|
|
167
|
+
}) {
|
|
168
|
+
if (action.render != null) {
|
|
169
|
+
return action.render(ctx) as any;
|
|
170
|
+
}
|
|
171
|
+
return h(RunActionButton, { action });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A run/detailsForm action rendered as a button. */
|
|
175
|
+
function RunActionButton<T>({ action }: { action: TableAction<T> }) {
|
|
102
176
|
const storeAPI = useStoreAPI();
|
|
103
177
|
const toaster = useToaster();
|
|
104
178
|
|
|
@@ -210,3 +284,26 @@ function ActionButtonWithForm<T, S>({
|
|
|
210
284
|
),
|
|
211
285
|
);
|
|
212
286
|
}
|
|
287
|
+
|
|
288
|
+
function hasAnyDisplayableActions(
|
|
289
|
+
actions: TableAction[],
|
|
290
|
+
columnSpec: ColumnSpec[],
|
|
291
|
+
) {
|
|
292
|
+
/** Check whether there are any actions that can be displayed in the toolbar.
|
|
293
|
+
* for the entire table. This is used to determine whether the toolbar should
|
|
294
|
+
* be rendered. If any actions are available, the toolbar is rendered in ALL
|
|
295
|
+
* selection modes to avoid flickering
|
|
296
|
+
*/
|
|
297
|
+
const allActions = [
|
|
298
|
+
...actions,
|
|
299
|
+
...columnSpec.flatMap((c) => c.actions ?? []),
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
if (allActions.length === 0) {
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
// Check whether any action doesn't have hotkey and is not disabled
|
|
306
|
+
return allActions.some(
|
|
307
|
+
(action) => action.hotkey == null && !isActionDisabled(action, {}),
|
|
308
|
+
);
|
|
309
|
+
}
|
package/src/actions/types.ts
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import type { IconName, Intent } from "@blueprintjs/core";
|
|
2
2
|
import type { Region, RegionCardinality } from "@blueprintjs/table";
|
|
3
|
-
import type { ComponentType } from "react";
|
|
3
|
+
import type { ComponentType, ReactNode } from "react";
|
|
4
4
|
import type { ColumnSpec } from "../utils";
|
|
5
5
|
import { ClipboardProxy, TableElementStatus } from "../types.ts";
|
|
6
6
|
|
|
7
7
|
/** Selection cardinality including the case of no active selection */
|
|
8
8
|
export type SelectionCardinality = RegionCardinality | "none";
|
|
9
9
|
|
|
10
|
+
/** The concrete *shape* of the current selection — richer than cardinality
|
|
11
|
+
* alone. The "single X" cases are exposed as resolved identity fields on the
|
|
12
|
+
* action context (`columnKey`, `rowIndex`, `cell`); this carries the counts. */
|
|
13
|
+
export interface SelectionShape {
|
|
14
|
+
cardinality: SelectionCardinality;
|
|
15
|
+
/** Number of columns the selection spans (0 when not column-scoped). */
|
|
16
|
+
columns: number;
|
|
17
|
+
/** Number of rows the selection spans (0 when not row-scoped). */
|
|
18
|
+
rows: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
/** A single cell edit, used with `editCells` for batch updates. */
|
|
11
22
|
export interface CellEdit {
|
|
12
23
|
rowIndex: number;
|
|
13
|
-
|
|
24
|
+
column: string;
|
|
14
25
|
value: any;
|
|
15
26
|
}
|
|
16
27
|
|
|
@@ -37,6 +48,10 @@ export interface TableFilter<T = any, S = any> {
|
|
|
37
48
|
/** Component for configuring the filter value.
|
|
38
49
|
* Same `{ state, setState }` pattern as `TableAction.detailsForm`. */
|
|
39
50
|
filterForm?: ComponentType<{ state: S; setState(state: S): void }>;
|
|
51
|
+
/** Summarize the current filter state for display on the active-filter tag
|
|
52
|
+
* (e.g. the range `0–250` or the search term). Keep it short — the tag also
|
|
53
|
+
* shows the filter name. Return `null` to show just the name. */
|
|
54
|
+
describeState?: (state: S) => import("react").ReactNode;
|
|
40
55
|
/** Row predicate: return `true` if the row should be visible.
|
|
41
56
|
* Receives the merged row (updatedData overlaid on data). */
|
|
42
57
|
predicate(row: T, state: S): boolean;
|
|
@@ -60,6 +75,20 @@ export interface TableActionContext<T = any> {
|
|
|
60
75
|
selection: Region[];
|
|
61
76
|
/** Derived cardinality of the current selection */
|
|
62
77
|
selectionCardinality: SelectionCardinality;
|
|
78
|
+
/** Concrete shape of the current selection (cardinality + column/row counts). */
|
|
79
|
+
selectionShape: SelectionShape;
|
|
80
|
+
/** The single selected column's key when exactly one column is scoped
|
|
81
|
+
* (a single full column, or cells within one column); otherwise `null`. */
|
|
82
|
+
columnKey: string | null;
|
|
83
|
+
/** The single selected data-row index when exactly one row is scoped;
|
|
84
|
+
* otherwise `null`. */
|
|
85
|
+
rowIndex: number | null;
|
|
86
|
+
/** The single selected cell (data-row index + column key) when exactly one
|
|
87
|
+
* cell is selected; otherwise `null`. Presence of these resolved fields is
|
|
88
|
+
* how actions discriminate selection shape — e.g. `appliesTo: ctx =>
|
|
89
|
+
* ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`
|
|
90
|
+
* within a `FULL_COLUMNS` target for a single-column control. */
|
|
91
|
+
cell: { rowIndex: number; columnKey: string } | null;
|
|
63
92
|
/** The table's base data */
|
|
64
93
|
data: T[];
|
|
65
94
|
/** Sparse overlay of edited data */
|
|
@@ -70,6 +99,8 @@ export interface TableActionContext<T = any> {
|
|
|
70
99
|
columnSpec: ColumnSpec[];
|
|
71
100
|
/** Whether the table is in edit mode */
|
|
72
101
|
editable: boolean;
|
|
102
|
+
/** Whether row deletion is available (false when the provider can't delete). */
|
|
103
|
+
canDeleteRows: boolean;
|
|
73
104
|
|
|
74
105
|
// Convenience methods (derived from selection)
|
|
75
106
|
/** Row indices covered by the current selection */
|
|
@@ -131,6 +162,12 @@ export interface TableAction<T = any, S = null> {
|
|
|
131
162
|
* should be available even with no active selection. */
|
|
132
163
|
targets: SelectionCardinality[];
|
|
133
164
|
|
|
165
|
+
/** Optional refinement beyond `targets`, inspecting the resolved selection
|
|
166
|
+
* identity. Return `false` to hide the action for a given shape — e.g. sort
|
|
167
|
+
* and filter return `ctx.columnKey != null` (within their `FULL_COLUMNS`
|
|
168
|
+
* target), so they appear only for a single column. */
|
|
169
|
+
appliesTo?: (context: TableActionContext<T>) => boolean;
|
|
170
|
+
|
|
134
171
|
/** Whether this action requires the table to be in edit mode.
|
|
135
172
|
* Defaults to `true`. Set to `false` for read-only actions
|
|
136
173
|
* (e.g., "open URL", "copy to clipboard"). */
|
|
@@ -149,10 +186,18 @@ export interface TableAction<T = any, S = null> {
|
|
|
149
186
|
/** Check if the action is ready to run given its configuration state */
|
|
150
187
|
isReady?: (state: S) => boolean;
|
|
151
188
|
|
|
189
|
+
/** For live/stateful controls (a column sort or filter widget, say): render
|
|
190
|
+
* bespoke UI for the current context instead of the default action button.
|
|
191
|
+
* When present, the toolbar renders this and ignores `detailsForm` (and
|
|
192
|
+
* `run`, unless the control itself invokes it). This is how sort/filter/group
|
|
193
|
+
* are expressed as `FULL_COLUMNS`-scoped controls in the one action system. */
|
|
194
|
+
render?: (context: TableActionContext<T>) => ReactNode;
|
|
195
|
+
|
|
152
196
|
/** Execute the action. May be synchronous (local state manipulation)
|
|
153
197
|
* or asynchronous (backend fulfillment). For lazy-loaded tables,
|
|
154
|
-
* async actions are required when targeting non-loaded cells.
|
|
155
|
-
|
|
198
|
+
* async actions are required when targeting non-loaded cells.
|
|
199
|
+
* Optional for `render`-only controls. */
|
|
200
|
+
run?(context: TableActionContext<T>, state?: S): void | Promise<void>;
|
|
156
201
|
successMessage?: string;
|
|
157
202
|
errorMessage?: string;
|
|
158
203
|
hotkey?: string;
|
package/src/cell-renderer.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ColumnSpec,
|
|
3
|
+
CellRenderContext,
|
|
4
|
+
CellDetailContext,
|
|
5
|
+
editorKeyHandlerAtom,
|
|
6
|
+
validateCell,
|
|
7
|
+
} from "./utils";
|
|
2
8
|
import { DataSheetStore, TableElementStatus } from "./types.ts";
|
|
3
9
|
import h from "./main.module.sass";
|
|
4
|
-
import { ReactNode, useEffect, useState } from "react";
|
|
5
|
-
import { EditorPopup } from "./components";
|
|
10
|
+
import { ReactNode, useEffect, useRef, useState } from "react";
|
|
11
|
+
import { EditorPopup, CellDetailModal } from "./components";
|
|
6
12
|
import { singleFocusedCell } from "./zustand-store.ts";
|
|
7
13
|
import { Cell } from "@blueprintjs/table";
|
|
8
14
|
import { ctx, useSelector } from "./provider.ts";
|
|
@@ -12,9 +18,15 @@ export function basicCellRenderer<T>(
|
|
|
12
18
|
colIndex: number,
|
|
13
19
|
columnSpec: ColumnSpec,
|
|
14
20
|
state: DataSheetStore<T>,
|
|
15
|
-
autoFocusEditor = true,
|
|
16
21
|
filteredRowIndices?: number[] | null,
|
|
17
22
|
): any {
|
|
23
|
+
// Auto-activation is on when the mode is "auto" and it hasn't been suppressed
|
|
24
|
+
// (Escape enters navigation mode until the next click).
|
|
25
|
+
// Whether the inline editor grabs focus. It follows the store-owned surface
|
|
26
|
+
// open state, so it focuses on selection in auto mode and on click in manual
|
|
27
|
+
// mode, and not at all in navigation mode. The popover surfaces read the
|
|
28
|
+
// same state directly.
|
|
29
|
+
const focusOnOpen = state.cellSurfaceOpen;
|
|
18
30
|
// When filters are active, `rowIndex` is the visible row position.
|
|
19
31
|
// Map it to the actual data index for data access.
|
|
20
32
|
const dataRowIndex =
|
|
@@ -37,9 +49,34 @@ export function basicCellRenderer<T>(
|
|
|
37
49
|
const value: T | undefined =
|
|
38
50
|
updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
|
|
39
51
|
const isEmpty = value == null || value === "";
|
|
40
|
-
const _renderedValue = isEmpty ? null : (col.valueRenderer?.(value) ?? value);
|
|
41
52
|
|
|
42
|
-
|
|
53
|
+
const edited =
|
|
54
|
+
updatedData[dataRowIndex]?.[col.key] != null ||
|
|
55
|
+
state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
|
|
56
|
+
|
|
57
|
+
// Validate the cell (skipped for deleted rows). Orthogonal to edit status.
|
|
58
|
+
const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);
|
|
59
|
+
|
|
60
|
+
// Context passed to custom renderers so they can render based on the
|
|
61
|
+
// row/column position and cell status (and, with the editing API, write
|
|
62
|
+
// edits back). `rowIndex` is the data-row index, stable under sort/filter.
|
|
63
|
+
const cellContext: CellRenderContext<T> = {
|
|
64
|
+
value,
|
|
65
|
+
rowIndex: dataRowIndex,
|
|
66
|
+
colIndex,
|
|
67
|
+
column: col,
|
|
68
|
+
row,
|
|
69
|
+
isEdited: edited,
|
|
70
|
+
isDeleted,
|
|
71
|
+
validation,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const _renderedValue = isEmpty
|
|
75
|
+
? null
|
|
76
|
+
: (col.valueRenderer?.(value, cellContext) ?? value);
|
|
77
|
+
|
|
78
|
+
// Clone so we never mutate the caller's column-spec style object
|
|
79
|
+
let style = { ...(col.style ?? {}) };
|
|
43
80
|
|
|
44
81
|
if (isDeleted) {
|
|
45
82
|
style.opacity = 0.5;
|
|
@@ -54,19 +91,76 @@ export function basicCellRenderer<T>(
|
|
|
54
91
|
|
|
55
92
|
const tableIsEditable = state.editable;
|
|
56
93
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
94
|
+
// Intent precedence: error > warning > deleted > edited. Validation state
|
|
95
|
+
// overrides the edited-green so an edited-but-invalid cell reads as invalid.
|
|
96
|
+
let intent: string | undefined;
|
|
97
|
+
if (validation?.severity === "error") {
|
|
98
|
+
intent = "danger";
|
|
99
|
+
} else if (validation?.severity === "warning") {
|
|
100
|
+
intent = "warning";
|
|
101
|
+
} else if (isDeleted) {
|
|
62
102
|
intent = "danger";
|
|
103
|
+
} else if (edited) {
|
|
104
|
+
intent = "success";
|
|
63
105
|
}
|
|
64
106
|
|
|
65
107
|
const _Cell = col.cellComponent ?? Cell;
|
|
66
108
|
|
|
67
|
-
|
|
109
|
+
// Only forward the render context to a custom cell component; the default
|
|
110
|
+
// Blueprint Cell would spread unknown props onto the DOM.
|
|
111
|
+
const cellComponentProps =
|
|
112
|
+
col.cellComponent != null ? { cellContext } : {};
|
|
113
|
+
|
|
114
|
+
// Allow a column to pick the editor per-cell (e.g. textarea only when the
|
|
115
|
+
// value is long). A returned key overrides the static column field even
|
|
116
|
+
// when its value is false/null, so use `in` rather than nullish-coalesce.
|
|
117
|
+
const perCellEditors = col.editorForCell?.(cellContext);
|
|
118
|
+
const dataEditorSpec =
|
|
119
|
+
perCellEditors != null && "dataEditor" in perCellEditors
|
|
120
|
+
? perCellEditors.dataEditor
|
|
121
|
+
: col.dataEditor;
|
|
122
|
+
const inlineEditorSpec =
|
|
123
|
+
perCellEditors != null && "inlineEditor" in perCellEditors
|
|
124
|
+
? perCellEditors.inlineEditor
|
|
125
|
+
: col.inlineEditor;
|
|
126
|
+
|
|
127
|
+
let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;
|
|
128
|
+
|
|
129
|
+
// Build the detail context for the unified `cellDetail` surface.
|
|
130
|
+
const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({
|
|
131
|
+
...cellContext,
|
|
132
|
+
editable: editableFlag,
|
|
133
|
+
onChange(v: any) {
|
|
134
|
+
if (editableFlag) onCellEdited(dataRowIndex, col.key, v);
|
|
135
|
+
},
|
|
136
|
+
resetValue() {
|
|
137
|
+
state.resetChanges();
|
|
138
|
+
},
|
|
139
|
+
close() {
|
|
140
|
+
state.closeCellSurface();
|
|
141
|
+
state.tableElement?.focus?.();
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const detailPresentation =
|
|
145
|
+
col.cellDetail != null ? (col.detailPresentation ?? "popover") : null;
|
|
68
146
|
|
|
69
147
|
if (!topLeft) {
|
|
148
|
+
// An inline surface is a persistent in-cell renderer, so it draws on every
|
|
149
|
+
// cell (read-only when not the focused/editing cell).
|
|
150
|
+
if (detailPresentation === "inline") {
|
|
151
|
+
return h(
|
|
152
|
+
_Cell,
|
|
153
|
+
{
|
|
154
|
+
intent,
|
|
155
|
+
value,
|
|
156
|
+
style,
|
|
157
|
+
className: "value-viewer-cell",
|
|
158
|
+
interactive: false,
|
|
159
|
+
...cellComponentProps,
|
|
160
|
+
},
|
|
161
|
+
col.cellDetail!(makeDetailCtx(false)),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
70
164
|
return h(
|
|
71
165
|
_Cell,
|
|
72
166
|
{
|
|
@@ -76,6 +170,7 @@ export function basicCellRenderer<T>(
|
|
|
76
170
|
style,
|
|
77
171
|
disabled: tableIsEditable && !editable,
|
|
78
172
|
interactive: false,
|
|
173
|
+
...cellComponentProps,
|
|
79
174
|
},
|
|
80
175
|
_renderedValue,
|
|
81
176
|
);
|
|
@@ -83,20 +178,102 @@ export function basicCellRenderer<T>(
|
|
|
83
178
|
|
|
84
179
|
// The rest is for the top-left cell of a selection or the focused cell
|
|
85
180
|
|
|
181
|
+
// Unified cell surface: one renderer that acts as editor (when editable) or
|
|
182
|
+
// viewer (otherwise), presented as a popover / modal / inline. Supersedes
|
|
183
|
+
// dataEditor / detailRenderer / editorForCell.
|
|
184
|
+
if (col.cellDetail != null) {
|
|
185
|
+
const content = col.cellDetail(makeDetailCtx(editable));
|
|
186
|
+
|
|
187
|
+
if (detailPresentation === "inline") {
|
|
188
|
+
// Persistent in-cell surface (editable on the focused cell). No popover.
|
|
189
|
+
return h(
|
|
190
|
+
_Cell,
|
|
191
|
+
{
|
|
192
|
+
intent,
|
|
193
|
+
value,
|
|
194
|
+
style,
|
|
195
|
+
className: editable ? "input-cell" : "value-viewer-cell",
|
|
196
|
+
interactive: editable,
|
|
197
|
+
...cellComponentProps,
|
|
198
|
+
},
|
|
199
|
+
content,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (detailPresentation === "modal") {
|
|
204
|
+
// CellDetailModal subscribes to the store so the dialog closes reactively.
|
|
205
|
+
return h(
|
|
206
|
+
_Cell,
|
|
207
|
+
{
|
|
208
|
+
intent,
|
|
209
|
+
value,
|
|
210
|
+
style,
|
|
211
|
+
className: "value-viewer-cell",
|
|
212
|
+
interactive: false,
|
|
213
|
+
...cellComponentProps,
|
|
214
|
+
},
|
|
215
|
+
h(
|
|
216
|
+
CellDetailModal,
|
|
217
|
+
{ title: col.name, valueViewer: _renderedValue },
|
|
218
|
+
content,
|
|
219
|
+
),
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Default: popover (same open/close machinery as editors and panels).
|
|
224
|
+
const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);
|
|
225
|
+
return h(
|
|
226
|
+
_Cell,
|
|
227
|
+
{
|
|
228
|
+
intent,
|
|
229
|
+
value,
|
|
230
|
+
style,
|
|
231
|
+
className: "editor-cell",
|
|
232
|
+
interactive: editable,
|
|
233
|
+
...cellComponentProps,
|
|
234
|
+
},
|
|
235
|
+
panel,
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Read-only detail panel: a surface that opens on selection (auto) or click,
|
|
240
|
+
// shows arbitrary content, and never takes keyboard focus — so arrow keys
|
|
241
|
+
// keep navigating the table. Uses the same open/close machinery as editors.
|
|
242
|
+
if (col.detailRenderer != null) {
|
|
243
|
+
const panel = h(
|
|
244
|
+
EditorPopup,
|
|
245
|
+
{ valueViewer: _renderedValue },
|
|
246
|
+
col.detailRenderer(cellContext),
|
|
247
|
+
);
|
|
248
|
+
return h(
|
|
249
|
+
_Cell,
|
|
250
|
+
{
|
|
251
|
+
intent,
|
|
252
|
+
value,
|
|
253
|
+
style,
|
|
254
|
+
// Use the editor-cell popover layout so the target fills the cell
|
|
255
|
+
// without the double-padding offset of `value-viewer-cell`.
|
|
256
|
+
className: "editor-cell",
|
|
257
|
+
interactive: false,
|
|
258
|
+
...cellComponentProps,
|
|
259
|
+
},
|
|
260
|
+
panel,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
86
264
|
let cellContents: ReactNode = _renderedValue;
|
|
87
265
|
|
|
88
266
|
let _dataEditor = null;
|
|
89
267
|
let className = null;
|
|
90
268
|
|
|
91
|
-
if (
|
|
269
|
+
if (dataEditorSpec != null) {
|
|
92
270
|
_dataEditor = h(
|
|
93
271
|
EditorPopup,
|
|
94
272
|
{
|
|
95
|
-
autoFocus: autoFocusEditor,
|
|
96
273
|
valueViewer: _renderedValue,
|
|
97
274
|
},
|
|
98
275
|
[
|
|
99
|
-
h(
|
|
276
|
+
h(dataEditorSpec, {
|
|
100
277
|
value,
|
|
101
278
|
editable,
|
|
102
279
|
isEdited: edited,
|
|
@@ -126,6 +303,7 @@ export function basicCellRenderer<T>(
|
|
|
126
303
|
style,
|
|
127
304
|
className,
|
|
128
305
|
interactive: false,
|
|
306
|
+
...cellComponentProps,
|
|
129
307
|
},
|
|
130
308
|
cellContents,
|
|
131
309
|
);
|
|
@@ -155,7 +333,7 @@ export function basicCellRenderer<T>(
|
|
|
155
333
|
_inlineEditor = h(EditorInput, {
|
|
156
334
|
className: "main-editor",
|
|
157
335
|
value: _value ?? "",
|
|
158
|
-
autoFocus:
|
|
336
|
+
autoFocus: focusOnOpen,
|
|
159
337
|
onChange,
|
|
160
338
|
});
|
|
161
339
|
} else {
|
|
@@ -187,6 +365,7 @@ export function basicCellRenderer<T>(
|
|
|
187
365
|
className,
|
|
188
366
|
style,
|
|
189
367
|
interactive: true,
|
|
368
|
+
...cellComponentProps,
|
|
190
369
|
//truncated: false,
|
|
191
370
|
},
|
|
192
371
|
[
|
|
@@ -200,11 +379,27 @@ export function basicCellRenderer<T>(
|
|
|
200
379
|
function EditorInput(props) {
|
|
201
380
|
const { value, onChange, ...rest } = props;
|
|
202
381
|
const onKeyDown = ctx.useValue(editorKeyHandlerAtom);
|
|
382
|
+
const navDirection = useSelector((s) => s.lastNavDirection);
|
|
383
|
+
const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);
|
|
384
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
203
385
|
const [_value, setValue] = useState(value);
|
|
204
386
|
useEffect(() => {
|
|
205
387
|
setValue(value);
|
|
206
388
|
}, [value]);
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
// Focus when the cell's surface is open (on mount, and when reopened via
|
|
391
|
+
// click/F2 while already mounted), placing the cursor on the side we're
|
|
392
|
+
// travelling toward so another arrow in that direction leaves the cell.
|
|
393
|
+
const el = inputRef.current;
|
|
394
|
+
if (el == null || !surfaceOpen) return;
|
|
395
|
+
el.focus();
|
|
396
|
+
const atStart = navDirection === "up" || navDirection === "left";
|
|
397
|
+
const pos = atStart ? 0 : (el.value?.length ?? 0);
|
|
398
|
+
el.setSelectionRange(pos, pos);
|
|
399
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
400
|
+
}, [surfaceOpen]);
|
|
207
401
|
return h("input", {
|
|
402
|
+
ref: inputRef,
|
|
208
403
|
onKeyDown,
|
|
209
404
|
onBlur: onChange,
|
|
210
405
|
value: _value ?? value,
|