@macrostrat/data-sheet 4.7.0 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +60 -19
- package/dist/actions/context.cjs +10 -1
- package/dist/actions/context.cjs.map +1 -1
- package/dist/actions/context.js +10 -1
- package/dist/actions/context.js.map +1 -1
- package/dist/actions/types.d.ts +4 -0
- package/dist/components/data-editor.cjs +527 -0
- package/dist/components/data-editor.cjs.map +1 -0
- package/dist/components/data-editor.d.ts +142 -0
- package/dist/components/data-editor.js +524 -0
- package/dist/components/data-editor.js.map +1 -0
- package/dist/components/editor-actions.cjs +167 -0
- package/dist/components/editor-actions.cjs.map +1 -0
- package/dist/components/editor-actions.d.ts +37 -0
- package/dist/components/editor-actions.js +165 -0
- package/dist/components/editor-actions.js.map +1 -0
- package/dist/components/editor-popup.cjs +11 -1
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +11 -1
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +3 -0
- package/dist/components/indicators/selection.cjs +10 -4
- package/dist/components/indicators/selection.cjs.map +1 -1
- package/dist/components/indicators/selection.js +10 -4
- package/dist/components/indicators/selection.js.map +1 -1
- package/dist/components/row-editor.cjs +351 -0
- package/dist/components/row-editor.cjs.map +1 -0
- package/dist/components/row-editor.d.ts +181 -0
- package/dist/components/row-editor.js +349 -0
- package/dist/components/row-editor.js.map +1 -0
- package/dist/components/row-editor.module.sass.cjs +51 -0
- package/dist/components/row-editor.module.sass.cjs.map +1 -0
- package/dist/components/row-editor.module.sass.js +49 -0
- package/dist/components/row-editor.module.sass.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.cjs +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
- package/dist/components/toolbars/actions-toolbar.js +1 -1
- package/dist/components/toolbars/actions-toolbar.js.map +1 -1
- package/dist/data-panel.cjs +36 -0
- package/dist/data-panel.cjs.map +1 -1
- package/dist/data-panel.d.ts +3 -2
- package/dist/data-panel.js +37 -1
- package/dist/data-panel.js.map +1 -1
- package/dist/data-panel.module.sass.cjs +28 -26
- package/dist/data-panel.module.sass.cjs.map +1 -1
- package/dist/data-panel.module.sass.js +28 -26
- package/dist/data-panel.module.sass.js.map +1 -1
- package/dist/data-sheet.css +267 -56
- package/dist/data-sheet.d.ts +2 -1
- package/dist/data-view.d.ts +1 -0
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +31 -3
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +14 -13
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +14 -13
- package/dist/main.module.sass.js.map +1 -1
- package/dist/postgrest-table/data-loaders.cjs +8 -1
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.js +9 -2
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/provider/column-spec.cjs +8 -1
- package/dist/provider/column-spec.cjs.map +1 -1
- package/dist/provider/column-spec.d.ts +105 -1
- package/dist/provider/column-spec.js +8 -1
- package/dist/provider/column-spec.js.map +1 -1
- package/dist/provider/core.cjs +32 -7
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +5 -1
- package/dist/provider/core.js +32 -7
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/loader-state.cjs +11 -3
- package/dist/provider/loader-state.cjs.map +1 -1
- package/dist/provider/loader-state.d.ts +8 -1
- package/dist/provider/loader-state.js +12 -4
- package/dist/provider/loader-state.js.map +1 -1
- package/dist/provider/table-data.cjs +10 -1
- package/dist/provider/table-data.cjs.map +1 -1
- package/dist/provider/table-data.d.ts +10 -0
- package/dist/provider/table-data.js +11 -2
- package/dist/provider/table-data.js.map +1 -1
- package/dist/provider/types.cjs.map +1 -1
- package/dist/provider/types.d.ts +4 -1
- package/dist/provider/types.js.map +1 -1
- package/dist/provider/zustand-store.cjs +26 -13
- package/dist/provider/zustand-store.cjs.map +1 -1
- package/dist/provider/zustand-store.js +14 -1
- package/dist/provider/zustand-store.js.map +1 -1
- package/dist/renderers/cell-renderer.cjs +15 -4
- package/dist/renderers/cell-renderer.cjs.map +1 -1
- package/dist/renderers/cell-renderer.js +13 -4
- package/dist/renderers/cell-renderer.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +12 -1
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.js +11 -1
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +30 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/src/actions/context.ts +13 -2
- package/src/actions/types.ts +5 -0
- package/src/components/data-editor.ts +741 -0
- package/src/components/editor-actions.ts +228 -0
- package/src/components/editor-popup.ts +16 -3
- package/src/components/index.ts +3 -0
- package/src/components/indicators/selection.ts +12 -4
- package/src/components/row-editor.module.sass +161 -0
- package/src/components/row-editor.ts +620 -0
- package/src/components/toolbars/actions-toolbar.ts +3 -2
- package/src/data-panel.module.sass +25 -0
- package/src/data-panel.ts +50 -1
- package/src/main.module.sass +19 -0
- package/src/postgrest-table/data-loaders.ts +13 -0
- package/src/provider/column-spec.ts +94 -16
- package/src/provider/core.ts +41 -9
- package/src/provider/loader-state.ts +15 -2
- package/src/provider/table-data.ts +23 -1
- package/src/provider/types.ts +4 -1
- package/src/provider/zustand-store.ts +30 -1
- package/src/renderers/cell-renderer.ts +18 -3
- package/src/renderers/column-header-cell.ts +10 -0
- package/src/types.ts +31 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.9.0] - 2026-09-25 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.8.0...@macrostrat/data-sheet-v4.9.0)
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Column roles, a row editor, and a standalone data editor
|
|
8
|
+
[dc1feb79](https://github.com/UW-Macrostrat/web-components/commit/dc1feb7961e6f901fe6a3dbb2d3f3bdba03cc32c)
|
|
9
|
+
|
|
10
|
+
- `ColumnSpec.derived` / `hidden` — computed, read-only columns and columns
|
|
11
|
+
kept out of the table; writability enforced on every write path
|
|
12
|
+
- `RowEditor` / `SelectedRowEditor` — the selection's fields as a form, over
|
|
13
|
+
one row or several, in a panel titled "Editing 3 rows"
|
|
14
|
+
- `rowEditorOpenAtom`, `ShowRowEditor`, `showRowEditorAction` — toggle the row
|
|
15
|
+
editor from the toolbar
|
|
16
|
+
- `DataEditor` — standalone form over one record from a data spec, with
|
|
17
|
+
Reset/Save and table actions scoped to the record and its fields
|
|
18
|
+
- `SelectedDataEditor` — a `DataEditor` over a panel's selected row, saving
|
|
19
|
+
through the provider
|
|
20
|
+
- `CellDetailContext` — `surface`, `onChangeCells`;
|
|
21
|
+
`ColumnSpec.detailPlacement`, `cellLabel`
|
|
22
|
+
- `cellInteraction: "second-click"`; `TableAction.placement: "end"`
|
|
23
|
+
- Selection indicator names single-column cells by column ("3 lithologies");
|
|
24
|
+
`pluralize` handles more English plurals
|
|
25
|
+
- Tags in cells are pinned to the row height
|
|
26
|
+
- Fix: Backspace in a cell popover's text field cleared the cell
|
|
27
|
+
- Fix: edits to object- and array-valued cells (an interval, a list of
|
|
28
|
+
lithologies) were dropped as unchanged
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- Updated dependencies
|
|
33
|
+
[dc1feb79](https://github.com/UW-Macrostrat/web-components/commit/dc1feb7961e6f901fe6a3dbb2d3f3bdba03cc32c)
|
|
34
|
+
- @macrostrat/data-components@1.7.0
|
|
35
|
+
|
|
36
|
+
## [4.8.0] - 2026-09-06 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.7.0...@macrostrat/data-sheet-v4.8.0)
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- - Keyset cursor in the provider contract: `FetchDataParams.after`;
|
|
41
|
+
`createLocalProvider` slices past it (`rowsAfter` exported)
|
|
42
|
+
[98e127f5](https://github.com/UW-Macrostrat/web-components/commit/98e127f51463a57bd2d1f93320a8d5e30c2cefdd)
|
|
43
|
+
- `startAfter` starts a view after a row (seeded into the store, passed to the
|
|
44
|
+
provider on every chunk, dropped on the first view change)
|
|
45
|
+
- `pageLinks` renders a visually hidden `rel="next"` link after the loaded
|
|
46
|
+
rows and a "Return to top" notice for a mid-list start, so a list is
|
|
47
|
+
crawlable from its server-rendered HTML
|
|
48
|
+
- Story: Data panel / Crawlable pages
|
|
49
|
+
|
|
3
50
|
## [4.7.0] - 2026-09-06 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v4.6.0...@macrostrat/data-sheet-v4.7.0)
|
|
4
51
|
|
|
5
52
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -39,34 +39,35 @@ recorded in the `CHANGELOG`. See the design doc in the Workbench
|
|
|
39
39
|
Workstreams, in sequence:
|
|
40
40
|
|
|
41
41
|
- [x] **G — Bugfixes** (small, low-risk, land first)
|
|
42
|
-
- [x] `onCellEdited` empty↔null normalization (no phantom edit when an
|
|
43
|
-
|
|
42
|
+
- [x] `onCellEdited` empty↔null normalization (no phantom edit when an empty
|
|
43
|
+
cell stays empty) — _story:_ `Data sheet/Editing`
|
|
44
44
|
- [x] Filter-aware edit methods (`clearSelection` / `onSelectionEdited` /
|
|
45
|
-
`fillValues` target the correct data row under sort/filter) —
|
|
46
|
-
|
|
45
|
+
`fillValues` target the correct data row under sort/filter) — _story:_
|
|
46
|
+
`Data sheet/Editing`, `Data sheet/Filters`
|
|
47
47
|
- [x] `col.style` clone (stop mutating the caller's style object)
|
|
48
48
|
- [x] Remove dead `onSaveData` prop (never invoked; save is a table action)
|
|
49
|
-
- [x] **B — Rich cell-render context** (pass
|
|
50
|
-
row, isEdited, isDeleted }` to
|
|
49
|
+
- [x] **B — Rich cell-render context** (pass
|
|
50
|
+
`{ rowIndex, colIndex, column, row, isEdited, isDeleted }` to
|
|
51
|
+
renderers)
|
|
51
52
|
- [x] **C — Cell interaction & editor UX** (`cellInteraction` auto/manual;
|
|
52
53
|
per-cell editor selection; focus flow-through with Escape→nav-mode,
|
|
53
|
-
direction-of-travel cursor, Enter/F2 to edit, click-to-toggle;
|
|
54
|
-
|
|
55
|
-
- [x] **A — Controlled editing** (`onEdit(event)` + controlled
|
|
56
|
-
`
|
|
57
|
-
|
|
54
|
+
direction-of-travel cursor, Enter/F2 to edit, click-to-toggle; read-only
|
|
55
|
+
`detailRenderer` panels)
|
|
56
|
+
- [x] **A — Controlled editing** (`onEdit(event)` + controlled `updatedData` /
|
|
57
|
+
`rowStatus` overlay; unified `cellDetail` / `detailPresentation` surface
|
|
58
|
+
API)
|
|
58
59
|
- [x] **D+E — Data source & view state** — one `TableDataProvider`
|
|
59
60
|
(`fetchData({ offset, limit, sorts, filters, cursor })` + `identity` +
|
|
60
61
|
optional `saveRows` / `deleteRows` / `insertRow`), passed via the
|
|
61
62
|
**`provider`** prop or the loose `data` / `fetchData` props;
|
|
62
63
|
`createLocalProvider` + `createPostgRESTProvider`; unified operator +
|
|
63
|
-
custom column filters and column sort (applied in memory or server-side
|
|
64
|
-
|
|
64
|
+
custom column filters and column sort (applied in memory or server-side by
|
|
65
|
+
the provider); identity-keyed edits that survive a re-sort; keyset &
|
|
65
66
|
unknown-length scroll. Table-scoped controls (`scrollToRowAction`,
|
|
66
67
|
`fullTextSearchAction`) are ordinary `TableAction`s (`dataSheetActions`
|
|
67
|
-
removed). _Stories:_ `Data sheet/Chunk loader`,
|
|
68
|
-
sheet`, `Data sheet/Filters`. _(Group-by stays a
|
|
69
|
-
concern for now — only the ingestion page needs it.)_
|
|
68
|
+
removed). _Stories:_ `Data sheet/Chunk loader`,
|
|
69
|
+
`Data sheet/PostgREST sheet`, `Data sheet/Filters`. _(Group-by stays a
|
|
70
|
+
consumer/page-side concern for now — only the ingestion page needs it.)_
|
|
70
71
|
- [x] **F — Row-header & row-status customization** — extensible `rowStatus`
|
|
71
72
|
(any string, not just added/deleted), per-status presentation via
|
|
72
73
|
**`rowStatusStyles`** (cell style + intent, row-header style; merged over
|
|
@@ -74,7 +75,47 @@ Workstreams, in sequence:
|
|
|
74
75
|
gutter content (group-key labels, omit markers), and `status` on
|
|
75
76
|
`CellRenderContext`. _Story:_ `Data sheet/Row status`.
|
|
76
77
|
- [x] **Column-header menus** — sort and filter render as native menu items in
|
|
77
|
-
the column-header dropdown via **`TableAction.renderMenuItem`**: sort as
|
|
78
|
-
Ascending/Descending submenu (re-click active to toggle off), filter as
|
|
79
|
-
list of every applicable filter, each with its edit form in a submenu.
|
|
78
|
+
the column-header dropdown via **`TableAction.renderMenuItem`**: sort as
|
|
79
|
+
an Ascending/Descending submenu (re-click active to toggle off), filter as
|
|
80
|
+
a list of every applicable filter, each with its edit form in a submenu.
|
|
80
81
|
_Stories:_ `Data sheet/Controls`, `Data sheet/Filters`.
|
|
82
|
+
|
|
83
|
+
## Locked, derived and hidden columns
|
|
84
|
+
|
|
85
|
+
The column spec is the only authority on what may be written, and it holds on
|
|
86
|
+
every write path — typing, the fill handle, a paste, "clear", and the row editor
|
|
87
|
+
— not only when a cell is clicked into. Three flags shape a column's role:
|
|
88
|
+
|
|
89
|
+
- `editable: false` — **locked**: a value this view shows but never changes (an
|
|
90
|
+
identifier).
|
|
91
|
+
- `derived: true` — **derived**: computed from other values, never writable,
|
|
92
|
+
drawn dimmed and marked ƒ in its header. The consumer recomputes it into the
|
|
93
|
+
edit overlay when its inputs change.
|
|
94
|
+
- `hidden: true` — **hidden**: kept in the spec but left out of the table, so
|
|
95
|
+
one spec serves every view and a control toggles flags rather than maintaining
|
|
96
|
+
several column arrays.
|
|
97
|
+
|
|
98
|
+
`isColumnWritable(col, tableEditable)` is the rule the store applies.
|
|
99
|
+
|
|
100
|
+
## Row editor
|
|
101
|
+
|
|
102
|
+
`RowEditor` renders one row's fields as a form derived from the column spec: the
|
|
103
|
+
column's `name` is the label, `valueRenderer` draws the value, `cellDetail` is
|
|
104
|
+
the editor when the column has one, and otherwise an input follows from
|
|
105
|
+
`dataType`. Locked and derived columns show read-only; with `editable: false`
|
|
106
|
+
the whole form is a read-only row viewer. It is store-free — a row, its edits
|
|
107
|
+
and an `onChange`.
|
|
108
|
+
|
|
109
|
+
Over several rows each field stands for that column across all of them: a
|
|
110
|
+
shared value is edited as one, differing values read "Multiple values", and a
|
|
111
|
+
change applies to every row. A column's `cellDetail` edits several cells only
|
|
112
|
+
when the column declares `multiCell` (its context then carries `cells` and
|
|
113
|
+
`mixed`); the default editors always do. Over a cell selection the selected
|
|
114
|
+
columns are the focus — editable and marked — and the rest of the row is
|
|
115
|
+
read-only context.
|
|
116
|
+
|
|
117
|
+
`SelectedRowEditor` binds it to the enclosing `DataSheetProvider`: it follows
|
|
118
|
+
the selected rows and columns and writes through `onCellEdited`, so an edit
|
|
119
|
+
made in the form is the same edit as one typed into the grid (same overlay,
|
|
120
|
+
same `onEdit`, same Reset), and it keeps working when the grid itself isn't
|
|
121
|
+
mounted. See `stories/row-editor.stories.ts`.
|
package/dist/actions/context.cjs
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const table = require("@blueprintjs/table");
|
|
4
4
|
const update = require("immutability-helper");
|
|
5
5
|
const selection = require("./selection.cjs");
|
|
6
|
+
const columnSpec = require("../provider/column-spec.cjs");
|
|
6
7
|
const core = require("../provider/core.cjs");
|
|
8
|
+
const types = require("../provider/types.cjs");
|
|
7
9
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
8
10
|
const update__default = /* @__PURE__ */ _interopDefault(update);
|
|
9
11
|
function buildActionContext(get, set, options) {
|
|
@@ -66,7 +68,14 @@ function buildActionContext(get, set, options) {
|
|
|
66
68
|
getSelectedRows: () => selection.getSelectedRowIndices(state.selection, getFilteredRowIndices()).map((i) => data[i]).filter((r) => r != null),
|
|
67
69
|
getSelectedColumnKeys: () => selection.getSelectedColumnKeys(state.selection, state.columnSpec),
|
|
68
70
|
onCellEdited: state.onCellEdited,
|
|
69
|
-
editCells(
|
|
71
|
+
editCells(rawEdits) {
|
|
72
|
+
const edits = rawEdits.filter((e) => {
|
|
73
|
+
const columnKey = e.columnKey ?? e.column;
|
|
74
|
+
const col = state.columnSpec.find((c) => c.key === columnKey);
|
|
75
|
+
if (!columnSpec.isColumnWritable(col, state.editable)) return false;
|
|
76
|
+
return state.rowStatus?.[e.rowIndex] !== types.TableElementStatus.DELETED;
|
|
77
|
+
});
|
|
78
|
+
if (edits.length === 0) return;
|
|
70
79
|
state.setUpdatedData((updatedData2) => {
|
|
71
80
|
const spec = {};
|
|
72
81
|
for (const e of edits) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.cjs","sources":["../../src/actions/context.ts"],"sourcesContent":["import {\n CellEdit,\n ClipboardProxy,\n RowStatusValue,\n tableDataAtom,\n} from \"../provider\";\nimport { type Region, RegionCardinality } from \"@blueprintjs/table\";\nimport update from \"immutability-helper\";\nimport {\n computeFilteredRowIndices,\n computeSelectionShape,\n getSelectedColumnKeys,\n getSelectedRowIndices,\n SelectionCardinality,\n SelectionShape,\n} from \"./selection.ts\";\nimport { Getter, Setter } from \"jotai\";\nimport type { Store as JotaiStore } from \"jotai/vanilla/store\";\nimport { storeAPIAtom } from \"../provider\";\nimport type { ColumnSpec } from \"../provider\";\nimport type { TableAction } from \"./types.ts\";\n\ninterface ActionContextOptions {\n /** Override the action context to scope to a single column.\n This is needed for actions that are invoked for a column header\n drop-down, for instance */\n singleColumn: number;\n}\n\ntype StoreInterface = Omit<JotaiStore, \"sub\">;\n\n/** Context passed to an action's `run` function, providing both data access\n * and store manipulation methods. Constructed fresh at action-run time\n * to ensure current state. */\nexport interface TableActionContext<T = any> {\n /** Current selection regions */\n selection: Region[];\n /** Derived cardinality of the current selection */\n selectionCardinality: SelectionCardinality;\n /** Concrete shape of the current selection (cardinality + column/row counts). */\n selectionShape: SelectionShape;\n /** The single selected column's key when exactly one column is scoped\n * (a single full column, or cells within one column); otherwise `null`. */\n columnKey: string | null;\n /** The single selected data-row index when exactly one row is scoped;\n * otherwise `null`. */\n rowIndex: number | null;\n /** The single selected cell (data-row index + column key) when exactly one\n * cell is selected; otherwise `null`. Presence of these resolved fields is\n * how actions discriminate selection shape — e.g. `appliesTo: ctx =>\n * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`\n * within a `FULL_COLUMNS` target for a single-column control. */\n cell: { rowIndex: number; columnKey: string } | null;\n /** The table's base data */\n data: T[];\n /** Sparse overlay of edited data */\n updatedData: (T | null | undefined)[];\n /** Row status tracking added/deleted rows */\n rowStatus: (RowStatusValue | null | undefined)[];\n /** Column definitions */\n columnSpec: ColumnSpec[];\n /** Whether the table is in edit mode */\n editable: boolean;\n /** Whether row deletion is available (false when the provider can't delete). */\n canDeleteRows: boolean;\n\n // Convenience methods (derived from selection)\n /** Row indices covered by the current selection */\n getSelectedRowIndices(): number[];\n /** The selected rows as resolved objects (not indices) — the natural input\n * for an immediate-edit action. Only loaded rows are returned. */\n getSelectedRows(): T[];\n /** Column keys covered by the current selection */\n getSelectedColumnKeys(): string[];\n\n // Immediate-edit persistence (present when a persisting provider is wired,\n // e.g. via DataPanel). Each mutates through the provider and auto-refreshes,\n // so a selection action can edit rows without touching a `refreshToken`.\n /** Persist edited rows (upsert), then refresh. */\n saveRows?: (rows: T[]) => Promise<void>;\n /** Delete rows by identity, then refresh. */\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n /** Insert a row, then refresh. */\n insertRow?: (row: Partial<T>) => Promise<void>;\n /** Force a re-fetch from scratch. */\n refresh?: () => void;\n\n // Store manipulation methods\n onCellEdited(rowIndex: number, columnKey: string, value: any): void;\n /** Edit multiple cells in a single batch update. Preferred over calling\n * `onCellEdited` in a loop, which triggers separate store updates\n * and may produce inconsistent intermediate states. */\n editCells(edits: CellEdit[]): void;\n deleteSelectedRows(): void;\n addRow(row?: Partial<T>): void;\n setUpdatedData(data: any): void;\n resetChanges(region?: Region[]): void;\n clearSelection(): void;\n scrollToRow(rowIndex: number): void;\n /** Direct store mutation for cases not covered by the convenience methods\n * above (e.g., modifying `columnSpec` or `deletedRows`). */\n setState(partial: Record<string, any>): void;\n\n // Clipboard proxy support\n /** Active clipboard proxy from a prior copy, if any */\n clipboardProxy: ClipboardProxy | null;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n\n // Filter support\n /** Row index mapping when filters are active. When non-null,\n * visible row `i` maps to data row `filteredRowIndices[i]`. */\n filteredRowIndices: number[] | null;\n}\n\n/** Construct a `TableActionContext` from the current store state.\n * Call this at action-run time (not render time) to ensure\n * the context reflects the latest state.\n * @param setState - Optional store setState for direct mutation. Omit for\n * read-only contexts (e.g., disabled checks). */\nexport function buildActionContext<T>(\n get: Getter,\n set: Setter,\n options?: ActionContextOptions,\n): TableActionContext<T> {\n const storeAPI = get(storeAPIAtom);\n if (storeAPI == null) {\n throw new Error(\n \"No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.\",\n );\n }\n\n const data = get(tableDataAtom) as T[];\n\n let state = storeAPI.getState();\n if (options?.singleColumn != null) {\n const colIndex = options.singleColumn;\n state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];\n }\n const setState = storeAPI.setState;\n\n // Lazy-compute filteredRowIndices to avoid cost during disabled checks\n let _filteredRowIndices: number[] | null | undefined = undefined;\n function getFilteredRowIndices(): number[] | null {\n if (_filteredRowIndices === undefined) {\n _filteredRowIndices = computeFilteredRowIndices(\n data,\n state.updatedData,\n state.activeFilters,\n );\n }\n return _filteredRowIndices;\n }\n\n const { selection, updatedData, rowStatus, rowEditing = {} } = state;\n\n const shape = computeSelectionShape(selection);\n\n return {\n selection,\n selectionCardinality: shape.cardinality,\n selectionShape: shape,\n data,\n updatedData,\n rowStatus,\n // Immediate-edit persistence, wired by the consumer (DataPanel) when a\n // persisting provider is present; each already auto-refreshes.\n ...rowEditing,\n // Resolved single-target identity (lazy — mapping rows through filters is\n // only paid when accessed).\n get columnKey() {\n return shape.columns === 1\n ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)\n : null;\n },\n get rowIndex() {\n return shape.rows === 1\n ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null)\n : null;\n },\n get cell() {\n if (\n shape.cardinality !== RegionCardinality.CELLS ||\n shape.columns !== 1 ||\n shape.rows !== 1\n ) {\n return null;\n }\n const columnKey =\n getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;\n const rowIndex =\n getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null;\n return columnKey != null && rowIndex != null\n ? { rowIndex, columnKey }\n : null;\n },\n columnSpec: state.columnSpec,\n editable: state.editable,\n canDeleteRows: state.canDeleteRows,\n getSelectedRowIndices: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices()),\n getSelectedRows: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices())\n .map((i) => data[i])\n .filter((r) => r != null),\n getSelectedColumnKeys: () =>\n getSelectedColumnKeys(state.selection, state.columnSpec),\n onCellEdited: state.onCellEdited,\n editCells(edits: CellEdit[]) {\n state.setUpdatedData((updatedData: T[]) => {\n const spec: Record<number, any> = {};\n for (const e of edits) {\n const rowIndex = e.rowIndex;\n const columnKey = (e as any).columnKey ?? e.column;\n if (spec[rowIndex] == null) {\n const op = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n spec[rowIndex] = { [op]: {} };\n }\n const opKey = Object.keys(spec[rowIndex])[0];\n spec[rowIndex][opKey][columnKey] = e.value;\n }\n return update(updatedData, spec);\n });\n // Emit a structured edit event so controlled consumers capture programmatic\n // batch edits (clipboard paste, fill) the same as inline edits.\n state.onEdit?.({\n type: \"setCells\",\n cells: edits.map((e) => ({\n rowIndex: e.rowIndex,\n column: (e as any).columnKey ?? e.column,\n value: e.value,\n row: data[e.rowIndex],\n })),\n });\n },\n deleteSelectedRows: state.deleteSelectedRows,\n addRow: state.addRow,\n setUpdatedData: state.setUpdatedData,\n resetChanges: state.resetChanges,\n clearSelection: state.clearSelection,\n scrollToRow: state.scrollToRow,\n setState,\n clipboardProxy: state.clipboardProxy,\n setClipboardProxy(proxy) {\n state.setClipboardProxy(proxy);\n },\n get filteredRowIndices() {\n return getFilteredRowIndices();\n },\n };\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n get: Getter,\n set: Setter,\n toaster: any,\n configState: any = undefined,\n) {\n console.log(\"runActionWrapper\", action.id, configState);\n const ctx = buildActionContext(get, set) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n"],"names":["storeAPIAtom","tableDataAtom","computeFilteredRowIndices","selection","computeSelectionShape","getSelectedColumnKeys","getSelectedRowIndices","RegionCardinality","updatedData","update"],"mappings":";;;;;;;;AAwHO,SAAS,mBACd,KACA,KACA,SACuB;AACvB,QAAM,WAAW,IAAIA,iBAAY;AACjC,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,QAAM,OAAO,IAAIC,kBAAa;AAE9B,MAAI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M;AAAA,IACpB,gBAAgB,MAAM;AAAA,IACtB,aAAa,MAAM;AAAA,IACnB;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,kBAAkB,OAAO;AACvB,YAAM,kBAAkB,KAAK;AAAA,IAC/B;AAAA,IACA,IAAI,qBAAqB;AACvB,aAAO,sBAAA;AAAA,IACT;AAAA,EAAA;AAEJ;AAEA,SAAS,mBAAmB,GAAQ;AAClC,MAAI,aAAa,MAAO,QAAO,EAAE;AACjC,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,MAAI,aAAa,OAAQ,QAAO,KAAK,UAAU,CAAC;AAChD,SAAO;AACT;AAEO,SAAS,iBACd,QACA,KACA,KACA,SACA,cAAmB,QACnB;AACA,UAAQ,IAAI,oBAAoB,OAAO,IAAI,WAAW;AACtD,QAAM,MAAM,mBAAmB,GAAQ;AACvC,MAAI,OAAO,oBAAoB,UAAU;AACvC,QAAI,OAAO,SAAS,GAAG,GAAG;AACxB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU;AAC1B;AAAA,EACF;AACA,MAAI;AACF,UAAM,MAAM,OAAO,MAAM,KAAK,WAAW;AACzC,QAAI,eAAe,SAAS;AAC1B,UACG,KAAK,MAAM;AAAA,MAAC,CAAC,EACb,MAAM,CAAC,MAAM;AACZ,8BAAsB,QAAQ,GAAG,OAAO;AAAA,MAC1C,CAAC;AAAA,IACL;AAAA,EACF,SAAS,GAAG;AACV,0BAAsB,QAAQ,GAAG,OAAO;AAAA,EAC1C;AACF;AAEA,SAAS,sBAAsB,QAAqB,OAAY,SAAc;AAC5E,QAAM,UACJ,mBAAmB,KAAK,KAAK,OAAO,gBAAgB;AACtD,UAAQ,KAAK;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,EAAA,CACT;AACH;;;"}
|
|
1
|
+
{"version":3,"file":"context.cjs","sources":["../../src/actions/context.ts"],"sourcesContent":["import {\n CellEdit,\n ClipboardProxy,\n RowStatusValue,\n tableDataAtom,\n} from \"../provider\";\nimport { type Region, RegionCardinality } from \"@blueprintjs/table\";\nimport update from \"immutability-helper\";\nimport {\n computeFilteredRowIndices,\n computeSelectionShape,\n getSelectedColumnKeys,\n getSelectedRowIndices,\n SelectionCardinality,\n SelectionShape,\n} from \"./selection.ts\";\nimport { Getter, Setter } from \"jotai\";\nimport type { Store as JotaiStore } from \"jotai/vanilla/store\";\nimport { storeAPIAtom, TableElementStatus } from \"../provider\";\nimport { isColumnWritable } from \"../provider/column-spec.ts\";\nimport type { ColumnSpec } from \"../provider\";\nimport type { TableAction } from \"./types.ts\";\n\ninterface ActionContextOptions {\n /** Override the action context to scope to a single column.\n This is needed for actions that are invoked for a column header\n drop-down, for instance */\n singleColumn: number;\n}\n\ntype StoreInterface = Omit<JotaiStore, \"sub\">;\n\n/** Context passed to an action's `run` function, providing both data access\n * and store manipulation methods. Constructed fresh at action-run time\n * to ensure current state. */\nexport interface TableActionContext<T = any> {\n /** Current selection regions */\n selection: Region[];\n /** Derived cardinality of the current selection */\n selectionCardinality: SelectionCardinality;\n /** Concrete shape of the current selection (cardinality + column/row counts). */\n selectionShape: SelectionShape;\n /** The single selected column's key when exactly one column is scoped\n * (a single full column, or cells within one column); otherwise `null`. */\n columnKey: string | null;\n /** The single selected data-row index when exactly one row is scoped;\n * otherwise `null`. */\n rowIndex: number | null;\n /** The single selected cell (data-row index + column key) when exactly one\n * cell is selected; otherwise `null`. Presence of these resolved fields is\n * how actions discriminate selection shape — e.g. `appliesTo: ctx =>\n * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`\n * within a `FULL_COLUMNS` target for a single-column control. */\n cell: { rowIndex: number; columnKey: string } | null;\n /** The table's base data */\n data: T[];\n /** Sparse overlay of edited data */\n updatedData: (T | null | undefined)[];\n /** Row status tracking added/deleted rows */\n rowStatus: (RowStatusValue | null | undefined)[];\n /** Column definitions */\n columnSpec: ColumnSpec[];\n /** Whether the table is in edit mode */\n editable: boolean;\n /** Whether row deletion is available (false when the provider can't delete). */\n canDeleteRows: boolean;\n\n // Convenience methods (derived from selection)\n /** Row indices covered by the current selection */\n getSelectedRowIndices(): number[];\n /** The selected rows as resolved objects (not indices) — the natural input\n * for an immediate-edit action. Only loaded rows are returned. */\n getSelectedRows(): T[];\n /** Column keys covered by the current selection */\n getSelectedColumnKeys(): string[];\n\n // Immediate-edit persistence (present when a persisting provider is wired,\n // e.g. via DataPanel). Each mutates through the provider and auto-refreshes,\n // so a selection action can edit rows without touching a `refreshToken`.\n /** Persist edited rows (upsert), then refresh. */\n saveRows?: (rows: T[]) => Promise<void>;\n /** Delete rows by identity, then refresh. */\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n /** Insert a row, then refresh. */\n insertRow?: (row: Partial<T>) => Promise<void>;\n /** Force a re-fetch from scratch. */\n refresh?: () => void;\n\n // Store manipulation methods\n onCellEdited(rowIndex: number, columnKey: string, value: any): void;\n /** Edit multiple cells in a single batch update. Preferred over calling\n * `onCellEdited` in a loop, which triggers separate store updates\n * and may produce inconsistent intermediate states. */\n editCells(edits: CellEdit[]): void;\n deleteSelectedRows(): void;\n addRow(row?: Partial<T>): void;\n setUpdatedData(data: any): void;\n resetChanges(region?: Region[]): void;\n clearSelection(): void;\n scrollToRow(rowIndex: number): void;\n /** Direct store mutation for cases not covered by the convenience methods\n * above (e.g., modifying `columnSpec` or `deletedRows`). */\n setState(partial: Record<string, any>): void;\n\n // Clipboard proxy support\n /** Active clipboard proxy from a prior copy, if any */\n clipboardProxy: ClipboardProxy | null;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n\n // Filter support\n /** Row index mapping when filters are active. When non-null,\n * visible row `i` maps to data row `filteredRowIndices[i]`. */\n filteredRowIndices: number[] | null;\n}\n\n/** Construct a `TableActionContext` from the current store state.\n * Call this at action-run time (not render time) to ensure\n * the context reflects the latest state.\n * @param setState - Optional store setState for direct mutation. Omit for\n * read-only contexts (e.g., disabled checks). */\nexport function buildActionContext<T>(\n get: Getter,\n set: Setter,\n options?: ActionContextOptions,\n): TableActionContext<T> {\n const storeAPI = get(storeAPIAtom);\n if (storeAPI == null) {\n throw new Error(\n \"No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.\",\n );\n }\n\n const data = get(tableDataAtom) as T[];\n\n let state = storeAPI.getState();\n if (options?.singleColumn != null) {\n const colIndex = options.singleColumn;\n state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];\n }\n const setState = storeAPI.setState;\n\n // Lazy-compute filteredRowIndices to avoid cost during disabled checks\n let _filteredRowIndices: number[] | null | undefined = undefined;\n function getFilteredRowIndices(): number[] | null {\n if (_filteredRowIndices === undefined) {\n _filteredRowIndices = computeFilteredRowIndices(\n data,\n state.updatedData,\n state.activeFilters,\n );\n }\n return _filteredRowIndices;\n }\n\n const { selection, updatedData, rowStatus, rowEditing = {} } = state;\n\n const shape = computeSelectionShape(selection);\n\n return {\n selection,\n selectionCardinality: shape.cardinality,\n selectionShape: shape,\n data,\n updatedData,\n rowStatus,\n // Immediate-edit persistence, wired by the consumer (DataPanel) when a\n // persisting provider is present; each already auto-refreshes.\n ...rowEditing,\n // Resolved single-target identity (lazy — mapping rows through filters is\n // only paid when accessed).\n get columnKey() {\n return shape.columns === 1\n ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)\n : null;\n },\n get rowIndex() {\n return shape.rows === 1\n ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null)\n : null;\n },\n get cell() {\n if (\n shape.cardinality !== RegionCardinality.CELLS ||\n shape.columns !== 1 ||\n shape.rows !== 1\n ) {\n return null;\n }\n const columnKey =\n getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;\n const rowIndex =\n getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null;\n return columnKey != null && rowIndex != null\n ? { rowIndex, columnKey }\n : null;\n },\n columnSpec: state.columnSpec,\n editable: state.editable,\n canDeleteRows: state.canDeleteRows,\n getSelectedRowIndices: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices()),\n getSelectedRows: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices())\n .map((i) => data[i])\n .filter((r) => r != null),\n getSelectedColumnKeys: () =>\n getSelectedColumnKeys(state.selection, state.columnSpec),\n onCellEdited: state.onCellEdited,\n editCells(rawEdits: CellEdit[]) {\n // Only the cells that take writes: a paste or a fill that spans a locked\n // or derived column, or a deleted row, writes around them — the same\n // rule the inline editor applies (`isColumnWritable`).\n const edits = rawEdits.filter((e) => {\n const columnKey = (e as any).columnKey ?? e.column;\n const col = state.columnSpec.find((c) => c.key === columnKey);\n if (!isColumnWritable(col, state.editable)) return false;\n return state.rowStatus?.[e.rowIndex] !== TableElementStatus.DELETED;\n });\n if (edits.length === 0) return;\n state.setUpdatedData((updatedData: T[]) => {\n const spec: Record<number, any> = {};\n for (const e of edits) {\n const rowIndex = e.rowIndex;\n const columnKey = (e as any).columnKey ?? e.column;\n if (spec[rowIndex] == null) {\n const op = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n spec[rowIndex] = { [op]: {} };\n }\n const opKey = Object.keys(spec[rowIndex])[0];\n spec[rowIndex][opKey][columnKey] = e.value;\n }\n return update(updatedData, spec);\n });\n // Emit a structured edit event so controlled consumers capture programmatic\n // batch edits (clipboard paste, fill) the same as inline edits.\n state.onEdit?.({\n type: \"setCells\",\n cells: edits.map((e) => ({\n rowIndex: e.rowIndex,\n column: (e as any).columnKey ?? e.column,\n value: e.value,\n row: data[e.rowIndex],\n })),\n });\n },\n deleteSelectedRows: state.deleteSelectedRows,\n addRow: state.addRow,\n setUpdatedData: state.setUpdatedData,\n resetChanges: state.resetChanges,\n clearSelection: state.clearSelection,\n scrollToRow: state.scrollToRow,\n setState,\n clipboardProxy: state.clipboardProxy,\n setClipboardProxy(proxy) {\n state.setClipboardProxy(proxy);\n },\n get filteredRowIndices() {\n return getFilteredRowIndices();\n },\n };\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n get: Getter,\n set: Setter,\n toaster: any,\n configState: any = undefined,\n) {\n console.log(\"runActionWrapper\", action.id, configState);\n const ctx = buildActionContext(get, set) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n"],"names":["storeAPIAtom","tableDataAtom","computeFilteredRowIndices","selection","computeSelectionShape","getSelectedColumnKeys","getSelectedRowIndices","RegionCardinality","isColumnWritable","TableElementStatus","updatedData","update"],"mappings":";;;;;;;;;;AAyHO,SAAS,mBACd,KACA,KACA,SACuB;AACvB,QAAM,WAAW,IAAIA,iBAAY;AACjC,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,QAAM,OAAO,IAAIC,kBAAa;AAE9B,MAAI,QAAQ,SAAS,SAAA;AACrB,MAAI,SAAS,gBAAgB,MAAM;AACjC,UAAM,WAAW,QAAQ;AACzB,UAAM,YAAY,CAAC,EAAE,MAAM,CAAC,UAAU,QAAQ,GAAG,MAAM,QAAW;AAAA,EACpE;AACA,QAAM,WAAW,SAAS;AAG1B,MAAI,sBAAmD;AACvD,WAAS,wBAAyC;AAChD,QAAI,wBAAwB,QAAW;AACrC,4BAAsBC,UAAAA;AAAAA,QACpB;AAAA,QACA,MAAM;AAAA,QACN,MAAM;AAAA,MAAA;AAAA,IAEV;AACA,WAAO;AAAA,EAC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,MAAM;AAAA,IACnB;AAAA,IACA,gBAAgB,MAAM;AAAA,IACtB,kBAAkB,OAAO;AACvB,YAAM,kBAAkB,KAAK;AAAA,IAC/B;AAAA,IACA,IAAI,qBAAqB;AACvB,aAAO,sBAAA;AAAA,IACT;AAAA,EAAA;AAEJ;AAEA,SAAS,mBAAmB,GAAQ;AAClC,MAAI,aAAa,MAAO,QAAO,EAAE;AACjC,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,MAAI,aAAa,OAAQ,QAAO,KAAK,UAAU,CAAC;AAChD,SAAO;AACT;AAEO,SAAS,iBACd,QACA,KACA,KACA,SACA,cAAmB,QACnB;AACA,UAAQ,IAAI,oBAAoB,OAAO,IAAI,WAAW;AACtD,QAAM,MAAM,mBAAmB,GAAQ;AACvC,MAAI,OAAO,oBAAoB,UAAU;AACvC,QAAI,OAAO,SAAS,GAAG,GAAG;AACxB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU;AAC1B;AAAA,EACF;AACA,MAAI;AACF,UAAM,MAAM,OAAO,MAAM,KAAK,WAAW;AACzC,QAAI,eAAe,SAAS;AAC1B,UACG,KAAK,MAAM;AAAA,MAAC,CAAC,EACb,MAAM,CAAC,MAAM;AACZ,8BAAsB,QAAQ,GAAG,OAAO;AAAA,MAC1C,CAAC;AAAA,IACL;AAAA,EACF,SAAS,GAAG;AACV,0BAAsB,QAAQ,GAAG,OAAO;AAAA,EAC1C;AACF;AAEA,SAAS,sBAAsB,QAAqB,OAAY,SAAc;AAC5E,QAAM,UACJ,mBAAmB,KAAK,KAAK,OAAO,gBAAgB;AACtD,UAAQ,KAAK;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,EAAA,CACT;AACH;;;"}
|
package/dist/actions/context.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { RegionCardinality } from "@blueprintjs/table";
|
|
2
2
|
import update from "immutability-helper";
|
|
3
3
|
import { computeSelectionShape, getSelectedColumnKeys, getSelectedRowIndices, computeFilteredRowIndices } from "./selection.js";
|
|
4
|
+
import { isColumnWritable } from "../provider/column-spec.js";
|
|
4
5
|
import { storeAPIAtom, tableDataAtom } from "../provider/core.js";
|
|
6
|
+
import { TableElementStatus } from "../provider/types.js";
|
|
5
7
|
function buildActionContext(get, set, options) {
|
|
6
8
|
const storeAPI = get(storeAPIAtom);
|
|
7
9
|
if (storeAPI == null) {
|
|
@@ -62,7 +64,14 @@ function buildActionContext(get, set, options) {
|
|
|
62
64
|
getSelectedRows: () => getSelectedRowIndices(state.selection, getFilteredRowIndices()).map((i) => data[i]).filter((r) => r != null),
|
|
63
65
|
getSelectedColumnKeys: () => getSelectedColumnKeys(state.selection, state.columnSpec),
|
|
64
66
|
onCellEdited: state.onCellEdited,
|
|
65
|
-
editCells(
|
|
67
|
+
editCells(rawEdits) {
|
|
68
|
+
const edits = rawEdits.filter((e) => {
|
|
69
|
+
const columnKey = e.columnKey ?? e.column;
|
|
70
|
+
const col = state.columnSpec.find((c) => c.key === columnKey);
|
|
71
|
+
if (!isColumnWritable(col, state.editable)) return false;
|
|
72
|
+
return state.rowStatus?.[e.rowIndex] !== TableElementStatus.DELETED;
|
|
73
|
+
});
|
|
74
|
+
if (edits.length === 0) return;
|
|
66
75
|
state.setUpdatedData((updatedData2) => {
|
|
67
76
|
const spec = {};
|
|
68
77
|
for (const e of edits) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sources":["../../src/actions/context.ts"],"sourcesContent":["import {\n CellEdit,\n ClipboardProxy,\n RowStatusValue,\n tableDataAtom,\n} from \"../provider\";\nimport { type Region, RegionCardinality } from \"@blueprintjs/table\";\nimport update from \"immutability-helper\";\nimport {\n computeFilteredRowIndices,\n computeSelectionShape,\n getSelectedColumnKeys,\n getSelectedRowIndices,\n SelectionCardinality,\n SelectionShape,\n} from \"./selection.ts\";\nimport { Getter, Setter } from \"jotai\";\nimport type { Store as JotaiStore } from \"jotai/vanilla/store\";\nimport { storeAPIAtom } from \"../provider\";\nimport type { ColumnSpec } from \"../provider\";\nimport type { TableAction } from \"./types.ts\";\n\ninterface ActionContextOptions {\n /** Override the action context to scope to a single column.\n This is needed for actions that are invoked for a column header\n drop-down, for instance */\n singleColumn: number;\n}\n\ntype StoreInterface = Omit<JotaiStore, \"sub\">;\n\n/** Context passed to an action's `run` function, providing both data access\n * and store manipulation methods. Constructed fresh at action-run time\n * to ensure current state. */\nexport interface TableActionContext<T = any> {\n /** Current selection regions */\n selection: Region[];\n /** Derived cardinality of the current selection */\n selectionCardinality: SelectionCardinality;\n /** Concrete shape of the current selection (cardinality + column/row counts). */\n selectionShape: SelectionShape;\n /** The single selected column's key when exactly one column is scoped\n * (a single full column, or cells within one column); otherwise `null`. */\n columnKey: string | null;\n /** The single selected data-row index when exactly one row is scoped;\n * otherwise `null`. */\n rowIndex: number | null;\n /** The single selected cell (data-row index + column key) when exactly one\n * cell is selected; otherwise `null`. Presence of these resolved fields is\n * how actions discriminate selection shape — e.g. `appliesTo: ctx =>\n * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`\n * within a `FULL_COLUMNS` target for a single-column control. */\n cell: { rowIndex: number; columnKey: string } | null;\n /** The table's base data */\n data: T[];\n /** Sparse overlay of edited data */\n updatedData: (T | null | undefined)[];\n /** Row status tracking added/deleted rows */\n rowStatus: (RowStatusValue | null | undefined)[];\n /** Column definitions */\n columnSpec: ColumnSpec[];\n /** Whether the table is in edit mode */\n editable: boolean;\n /** Whether row deletion is available (false when the provider can't delete). */\n canDeleteRows: boolean;\n\n // Convenience methods (derived from selection)\n /** Row indices covered by the current selection */\n getSelectedRowIndices(): number[];\n /** The selected rows as resolved objects (not indices) — the natural input\n * for an immediate-edit action. Only loaded rows are returned. */\n getSelectedRows(): T[];\n /** Column keys covered by the current selection */\n getSelectedColumnKeys(): string[];\n\n // Immediate-edit persistence (present when a persisting provider is wired,\n // e.g. via DataPanel). Each mutates through the provider and auto-refreshes,\n // so a selection action can edit rows without touching a `refreshToken`.\n /** Persist edited rows (upsert), then refresh. */\n saveRows?: (rows: T[]) => Promise<void>;\n /** Delete rows by identity, then refresh. */\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n /** Insert a row, then refresh. */\n insertRow?: (row: Partial<T>) => Promise<void>;\n /** Force a re-fetch from scratch. */\n refresh?: () => void;\n\n // Store manipulation methods\n onCellEdited(rowIndex: number, columnKey: string, value: any): void;\n /** Edit multiple cells in a single batch update. Preferred over calling\n * `onCellEdited` in a loop, which triggers separate store updates\n * and may produce inconsistent intermediate states. */\n editCells(edits: CellEdit[]): void;\n deleteSelectedRows(): void;\n addRow(row?: Partial<T>): void;\n setUpdatedData(data: any): void;\n resetChanges(region?: Region[]): void;\n clearSelection(): void;\n scrollToRow(rowIndex: number): void;\n /** Direct store mutation for cases not covered by the convenience methods\n * above (e.g., modifying `columnSpec` or `deletedRows`). */\n setState(partial: Record<string, any>): void;\n\n // Clipboard proxy support\n /** Active clipboard proxy from a prior copy, if any */\n clipboardProxy: ClipboardProxy | null;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n\n // Filter support\n /** Row index mapping when filters are active. When non-null,\n * visible row `i` maps to data row `filteredRowIndices[i]`. */\n filteredRowIndices: number[] | null;\n}\n\n/** Construct a `TableActionContext` from the current store state.\n * Call this at action-run time (not render time) to ensure\n * the context reflects the latest state.\n * @param setState - Optional store setState for direct mutation. Omit for\n * read-only contexts (e.g., disabled checks). */\nexport function buildActionContext<T>(\n get: Getter,\n set: Setter,\n options?: ActionContextOptions,\n): TableActionContext<T> {\n const storeAPI = get(storeAPIAtom);\n if (storeAPI == null) {\n throw new Error(\n \"No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.\",\n );\n }\n\n const data = get(tableDataAtom) as T[];\n\n let state = storeAPI.getState();\n if (options?.singleColumn != null) {\n const colIndex = options.singleColumn;\n state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];\n }\n const setState = storeAPI.setState;\n\n // Lazy-compute filteredRowIndices to avoid cost during disabled checks\n let _filteredRowIndices: number[] | null | undefined = undefined;\n function getFilteredRowIndices(): number[] | null {\n if (_filteredRowIndices === undefined) {\n _filteredRowIndices = computeFilteredRowIndices(\n data,\n state.updatedData,\n state.activeFilters,\n );\n }\n return _filteredRowIndices;\n }\n\n const { selection, updatedData, rowStatus, rowEditing = {} } = state;\n\n const shape = computeSelectionShape(selection);\n\n return {\n selection,\n selectionCardinality: shape.cardinality,\n selectionShape: shape,\n data,\n updatedData,\n rowStatus,\n // Immediate-edit persistence, wired by the consumer (DataPanel) when a\n // persisting provider is present; each already auto-refreshes.\n ...rowEditing,\n // Resolved single-target identity (lazy — mapping rows through filters is\n // only paid when accessed).\n get columnKey() {\n return shape.columns === 1\n ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)\n : null;\n },\n get rowIndex() {\n return shape.rows === 1\n ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null)\n : null;\n },\n get cell() {\n if (\n shape.cardinality !== RegionCardinality.CELLS ||\n shape.columns !== 1 ||\n shape.rows !== 1\n ) {\n return null;\n }\n const columnKey =\n getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;\n const rowIndex =\n getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null;\n return columnKey != null && rowIndex != null\n ? { rowIndex, columnKey }\n : null;\n },\n columnSpec: state.columnSpec,\n editable: state.editable,\n canDeleteRows: state.canDeleteRows,\n getSelectedRowIndices: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices()),\n getSelectedRows: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices())\n .map((i) => data[i])\n .filter((r) => r != null),\n getSelectedColumnKeys: () =>\n getSelectedColumnKeys(state.selection, state.columnSpec),\n onCellEdited: state.onCellEdited,\n editCells(edits: CellEdit[]) {\n state.setUpdatedData((updatedData: T[]) => {\n const spec: Record<number, any> = {};\n for (const e of edits) {\n const rowIndex = e.rowIndex;\n const columnKey = (e as any).columnKey ?? e.column;\n if (spec[rowIndex] == null) {\n const op = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n spec[rowIndex] = { [op]: {} };\n }\n const opKey = Object.keys(spec[rowIndex])[0];\n spec[rowIndex][opKey][columnKey] = e.value;\n }\n return update(updatedData, spec);\n });\n // Emit a structured edit event so controlled consumers capture programmatic\n // batch edits (clipboard paste, fill) the same as inline edits.\n state.onEdit?.({\n type: \"setCells\",\n cells: edits.map((e) => ({\n rowIndex: e.rowIndex,\n column: (e as any).columnKey ?? e.column,\n value: e.value,\n row: data[e.rowIndex],\n })),\n });\n },\n deleteSelectedRows: state.deleteSelectedRows,\n addRow: state.addRow,\n setUpdatedData: state.setUpdatedData,\n resetChanges: state.resetChanges,\n clearSelection: state.clearSelection,\n scrollToRow: state.scrollToRow,\n setState,\n clipboardProxy: state.clipboardProxy,\n setClipboardProxy(proxy) {\n state.setClipboardProxy(proxy);\n },\n get filteredRowIndices() {\n return getFilteredRowIndices();\n },\n };\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n get: Getter,\n set: Setter,\n toaster: any,\n configState: any = undefined,\n) {\n console.log(\"runActionWrapper\", action.id, configState);\n const ctx = buildActionContext(get, set) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n"],"names":["updatedData"],"mappings":";;;;AAwH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ent":["import {\n CellEdit,\n ClipboardProxy,\n RowStatusValue,\n tableDataAtom,\n} from \"../provider\";\nimport { type Region, RegionCardinality } from \"@blueprintjs/table\";\nimport update from \"immutability-helper\";\nimport {\n computeFilteredRowIndices,\n computeSelectionShape,\n getSelectedColumnKeys,\n getSelectedRowIndices,\n SelectionCardinality,\n SelectionShape,\n} from \"./selection.ts\";\nimport { Getter, Setter } from \"jotai\";\nimport type { Store as JotaiStore } from \"jotai/vanilla/store\";\nimport { storeAPIAtom, TableElementStatus } from \"../provider\";\nimport { isColumnWritable } from \"../provider/column-spec.ts\";\nimport type { ColumnSpec } from \"../provider\";\nimport type { TableAction } from \"./types.ts\";\n\ninterface ActionContextOptions {\n /** Override the action context to scope to a single column.\n This is needed for actions that are invoked for a column header\n drop-down, for instance */\n singleColumn: number;\n}\n\ntype StoreInterface = Omit<JotaiStore, \"sub\">;\n\n/** Context passed to an action's `run` function, providing both data access\n * and store manipulation methods. Constructed fresh at action-run time\n * to ensure current state. */\nexport interface TableActionContext<T = any> {\n /** Current selection regions */\n selection: Region[];\n /** Derived cardinality of the current selection */\n selectionCardinality: SelectionCardinality;\n /** Concrete shape of the current selection (cardinality + column/row counts). */\n selectionShape: SelectionShape;\n /** The single selected column's key when exactly one column is scoped\n * (a single full column, or cells within one column); otherwise `null`. */\n columnKey: string | null;\n /** The single selected data-row index when exactly one row is scoped;\n * otherwise `null`. */\n rowIndex: number | null;\n /** The single selected cell (data-row index + column key) when exactly one\n * cell is selected; otherwise `null`. Presence of these resolved fields is\n * how actions discriminate selection shape — e.g. `appliesTo: ctx =>\n * ctx.cell != null` for a single-cell control, or `ctx.columnKey != null`\n * within a `FULL_COLUMNS` target for a single-column control. */\n cell: { rowIndex: number; columnKey: string } | null;\n /** The table's base data */\n data: T[];\n /** Sparse overlay of edited data */\n updatedData: (T | null | undefined)[];\n /** Row status tracking added/deleted rows */\n rowStatus: (RowStatusValue | null | undefined)[];\n /** Column definitions */\n columnSpec: ColumnSpec[];\n /** Whether the table is in edit mode */\n editable: boolean;\n /** Whether row deletion is available (false when the provider can't delete). */\n canDeleteRows: boolean;\n\n // Convenience methods (derived from selection)\n /** Row indices covered by the current selection */\n getSelectedRowIndices(): number[];\n /** The selected rows as resolved objects (not indices) — the natural input\n * for an immediate-edit action. Only loaded rows are returned. */\n getSelectedRows(): T[];\n /** Column keys covered by the current selection */\n getSelectedColumnKeys(): string[];\n\n // Immediate-edit persistence (present when a persisting provider is wired,\n // e.g. via DataPanel). Each mutates through the provider and auto-refreshes,\n // so a selection action can edit rows without touching a `refreshToken`.\n /** Persist edited rows (upsert), then refresh. */\n saveRows?: (rows: T[]) => Promise<void>;\n /** Delete rows by identity, then refresh. */\n deleteRows?: (ids: Array<string | number>) => Promise<void>;\n /** Insert a row, then refresh. */\n insertRow?: (row: Partial<T>) => Promise<void>;\n /** Force a re-fetch from scratch. */\n refresh?: () => void;\n\n // Store manipulation methods\n onCellEdited(rowIndex: number, columnKey: string, value: any): void;\n /** Edit multiple cells in a single batch update. Preferred over calling\n * `onCellEdited` in a loop, which triggers separate store updates\n * and may produce inconsistent intermediate states. */\n editCells(edits: CellEdit[]): void;\n deleteSelectedRows(): void;\n addRow(row?: Partial<T>): void;\n setUpdatedData(data: any): void;\n resetChanges(region?: Region[]): void;\n clearSelection(): void;\n scrollToRow(rowIndex: number): void;\n /** Direct store mutation for cases not covered by the convenience methods\n * above (e.g., modifying `columnSpec` or `deletedRows`). */\n setState(partial: Record<string, any>): void;\n\n // Clipboard proxy support\n /** Active clipboard proxy from a prior copy, if any */\n clipboardProxy: ClipboardProxy | null;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n\n // Filter support\n /** Row index mapping when filters are active. When non-null,\n * visible row `i` maps to data row `filteredRowIndices[i]`. */\n filteredRowIndices: number[] | null;\n}\n\n/** Construct a `TableActionContext` from the current store state.\n * Call this at action-run time (not render time) to ensure\n * the context reflects the latest state.\n * @param setState - Optional store setState for direct mutation. Omit for\n * read-only contexts (e.g., disabled checks). */\nexport function buildActionContext<T>(\n get: Getter,\n set: Setter,\n options?: ActionContextOptions,\n): TableActionContext<T> {\n const storeAPI = get(storeAPIAtom);\n if (storeAPI == null) {\n throw new Error(\n \"No DataSheetProvider found in context. Wrap your component in a <DataSheetProvider>.\",\n );\n }\n\n const data = get(tableDataAtom) as T[];\n\n let state = storeAPI.getState();\n if (options?.singleColumn != null) {\n const colIndex = options.singleColumn;\n state.selection = [{ cols: [colIndex, colIndex], rows: undefined }];\n }\n const setState = storeAPI.setState;\n\n // Lazy-compute filteredRowIndices to avoid cost during disabled checks\n let _filteredRowIndices: number[] | null | undefined = undefined;\n function getFilteredRowIndices(): number[] | null {\n if (_filteredRowIndices === undefined) {\n _filteredRowIndices = computeFilteredRowIndices(\n data,\n state.updatedData,\n state.activeFilters,\n );\n }\n return _filteredRowIndices;\n }\n\n const { selection, updatedData, rowStatus, rowEditing = {} } = state;\n\n const shape = computeSelectionShape(selection);\n\n return {\n selection,\n selectionCardinality: shape.cardinality,\n selectionShape: shape,\n data,\n updatedData,\n rowStatus,\n // Immediate-edit persistence, wired by the consumer (DataPanel) when a\n // persisting provider is present; each already auto-refreshes.\n ...rowEditing,\n // Resolved single-target identity (lazy — mapping rows through filters is\n // only paid when accessed).\n get columnKey() {\n return shape.columns === 1\n ? (getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null)\n : null;\n },\n get rowIndex() {\n return shape.rows === 1\n ? (getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null)\n : null;\n },\n get cell() {\n if (\n shape.cardinality !== RegionCardinality.CELLS ||\n shape.columns !== 1 ||\n shape.rows !== 1\n ) {\n return null;\n }\n const columnKey =\n getSelectedColumnKeys(state.selection, state.columnSpec)[0] ?? null;\n const rowIndex =\n getSelectedRowIndices(state.selection, getFilteredRowIndices())[0] ??\n null;\n return columnKey != null && rowIndex != null\n ? { rowIndex, columnKey }\n : null;\n },\n columnSpec: state.columnSpec,\n editable: state.editable,\n canDeleteRows: state.canDeleteRows,\n getSelectedRowIndices: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices()),\n getSelectedRows: () =>\n getSelectedRowIndices(state.selection, getFilteredRowIndices())\n .map((i) => data[i])\n .filter((r) => r != null),\n getSelectedColumnKeys: () =>\n getSelectedColumnKeys(state.selection, state.columnSpec),\n onCellEdited: state.onCellEdited,\n editCells(rawEdits: CellEdit[]) {\n // Only the cells that take writes: a paste or a fill that spans a locked\n // or derived column, or a deleted row, writes around them — the same\n // rule the inline editor applies (`isColumnWritable`).\n const edits = rawEdits.filter((e) => {\n const columnKey = (e as any).columnKey ?? e.column;\n const col = state.columnSpec.find((c) => c.key === columnKey);\n if (!isColumnWritable(col, state.editable)) return false;\n return state.rowStatus?.[e.rowIndex] !== TableElementStatus.DELETED;\n });\n if (edits.length === 0) return;\n state.setUpdatedData((updatedData: T[]) => {\n const spec: Record<number, any> = {};\n for (const e of edits) {\n const rowIndex = e.rowIndex;\n const columnKey = (e as any).columnKey ?? e.column;\n if (spec[rowIndex] == null) {\n const op = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n spec[rowIndex] = { [op]: {} };\n }\n const opKey = Object.keys(spec[rowIndex])[0];\n spec[rowIndex][opKey][columnKey] = e.value;\n }\n return update(updatedData, spec);\n });\n // Emit a structured edit event so controlled consumers capture programmatic\n // batch edits (clipboard paste, fill) the same as inline edits.\n state.onEdit?.({\n type: \"setCells\",\n cells: edits.map((e) => ({\n rowIndex: e.rowIndex,\n column: (e as any).columnKey ?? e.column,\n value: e.value,\n row: data[e.rowIndex],\n })),\n });\n },\n deleteSelectedRows: state.deleteSelectedRows,\n addRow: state.addRow,\n setUpdatedData: state.setUpdatedData,\n resetChanges: state.resetChanges,\n clearSelection: state.clearSelection,\n scrollToRow: state.scrollToRow,\n setState,\n clipboardProxy: state.clipboardProxy,\n setClipboardProxy(proxy) {\n state.setClipboardProxy(proxy);\n },\n get filteredRowIndices() {\n return getFilteredRowIndices();\n },\n };\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n get: Getter,\n set: Setter,\n toaster: any,\n configState: any = undefined,\n) {\n console.log(\"runActionWrapper\", action.id, configState);\n const ctx = buildActionContext(get, set) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n"],"names":["updatedData"],"mappings":";;;;;;AAyHO,SAAS,mBACd,KACA,KACA,SACuB;AACvB,QAAM,WAAW,IAAI,YAAY;AACjC,MAAI,YAAY,MAAM;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AAEA,QAAM,OAAO,IAAI,aAAa;AAE9B,MAAI,QAAQ,SAAS,SAAA;AACrB,MAAI,SAAS,gBAAgB,MAAM;AACjC,UAAM,WAAW,QAAQ;AACzB,UAAM,YAAY,CAAC,EAAE,MAAM,CAAC,UAAU,QAAQ,GAAG,MAAM,QAAW;AAAA,EACpE;AACA,QAAM,WAAW,SAAS;AAG1B,MAAI,sBAAmD;AACvD,WAAS,wBAAyC;AAChD,QAAI,wBAAwB,QAAW;AACrC,4BAAsB;AAAA,QACpB;AAAA,QACA,MAAM;AAAA,QACN,MAAM;AAAA,MAAA;AAAA,IAEV;AACA,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,WAAW,aAAa,WAAW,aAAa,CAAA,MAAO;AAE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AA;AAEJ;AAEA,SAAS,mBAAmB,GAAQ;AAClC,MAAI,aAAa,MAAO,QAAO,EAAE;AACjC,MAAI,OAAO,MAAM,SAAU,QAAO;AAClC,MAAI,aAAa,OAAQ,QAAO,KAAK,UAAU,CAAC;AAChD,SAAO;AACT;AAEO,SAAS,iBACd,QACA,KACA,KACA,SACA,cAAmB,QACnB;AACA,UAAQ,IAAI,oBAAoB,OAAO,IAAI,WAAW;AACtD,QAAM,MAAM,mBAAmB,GAAQ;AACvC,MAAI,OAAO,oBAAoB,UAAU;AACvC,QAAI,OAAO,SAAS,GAAG,GAAG;AACxB;AAAA,IACF;AAAA,EACF,WAAW,OAAO,UAAU;AAC1B;AAAA,EACF;AACA,MAAI;AACF,UAAM,MAAM,OAAO,MAAM,KAAK,WAAW;AACzC,QAAI,eAAe,SAAS;AAC1B,UACG,KAAK,MAAM;AAAA,MAAC,CAAC,EACb,MAAM,CAAC,MAAM;AACZ,8BAAsB,QAAQ,GAAG,OAAO;AAAA,MAC1C,CAAC;AAAA,IACL;AAAA,EACF,SAAS,GAAG;AACV,0BAAsB,QAAQ,GAAG,OAAO;AAAA,EAC1C;AACF;AAEA,SAAS,sBAAsB,QAAqB,OAAY,SAAc;AAC5E,QAAM,UACJ,mBAAmB,KAAK,KAAK,OAAO,gBAAgB;AACtD,UAAQ,KAAK;AAAA,IACX;AAAA,IACA,QAAQ;AAAA,EAAA,CACT;AACH;"}
|
package/dist/actions/types.d.ts
CHANGED
|
@@ -88,6 +88,10 @@ export interface TableAction<T = any, S = null> {
|
|
|
88
88
|
* and filter return `ctx.columnKey != null` (within their `FULL_COLUMNS`
|
|
89
89
|
* target), so they appear only for a single column. */
|
|
90
90
|
appliesTo?: (context: TableActionContext<T>) => boolean;
|
|
91
|
+
/** Where the action sits in the toolbar: with the contextual actions at its
|
|
92
|
+
* start (default), or at its fixed end beside Save and Reset — for a
|
|
93
|
+
* control that doesn't change with the selection, like a panel toggle. */
|
|
94
|
+
placement?: "start" | "end";
|
|
91
95
|
/** Whether this action requires the table to be in edit mode.
|
|
92
96
|
* Defaults to `true`. Set to `false` for read-only actions
|
|
93
97
|
* (e.g., "open URL", "copy to clipboard"). */
|