@macrostrat/data-sheet 4.8.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 +33 -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-sheet.css +208 -20
- package/dist/index.cjs +27 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +29 -2
- 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/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 +16 -4
- package/dist/provider/core.cjs.map +1 -1
- package/dist/provider/core.d.ts +4 -0
- package/dist/provider/core.js +16 -4
- package/dist/provider/core.js.map +1 -1
- package/dist/provider/types.cjs.map +1 -1
- package/dist/provider/types.d.ts +1 -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 +5 -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/main.module.sass +19 -0
- package/src/provider/column-spec.ts +94 -16
- package/src/provider/core.ts +19 -4
- package/src/provider/types.ts +1 -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 +5 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import type { Placement } from "@blueprintjs/core";
|
|
2
3
|
import { enhanceColumnFilter, TableFilter } from "../actions";
|
|
3
4
|
|
|
4
5
|
const defaultRenderers = {
|
|
@@ -21,13 +22,7 @@ const defaultWidthForValue = (val) => String(val).length * 8;
|
|
|
21
22
|
/** Inferred data type of a column, used to select appropriate
|
|
22
23
|
* sort/filter operators. */
|
|
23
24
|
export type ColumnDataType =
|
|
24
|
-
| "
|
|
25
|
-
| "string"
|
|
26
|
-
| "number"
|
|
27
|
-
| "integer"
|
|
28
|
-
| "boolean"
|
|
29
|
-
| "object"
|
|
30
|
-
| "array";
|
|
25
|
+
"text" | "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
31
26
|
|
|
32
27
|
/** Severity of a cell validation result. `warning` is soft (flagged, doesn't
|
|
33
28
|
* block saving); `error` is hard (blocks saving). */
|
|
@@ -91,14 +86,42 @@ export interface CellEditors {
|
|
|
91
86
|
export interface CellDetailContext<T = any> extends CellRenderContext<T> {
|
|
92
87
|
/** Whether this cell is editable (column × table × not-deleted). */
|
|
93
88
|
editable: boolean;
|
|
94
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* When the surface stands for several cells at once (the row editor over a
|
|
91
|
+
* multi-row selection), the cells it stands for. `value` is then the value
|
|
92
|
+
* they share, or `undefined` when they differ (`mixed`), and `onChange`
|
|
93
|
+
* writes every one of them. Only offered to a column that declares
|
|
94
|
+
* `multiCell`; absent for a single cell.
|
|
95
|
+
*/
|
|
96
|
+
cells?: CellSelectionEntry<T>[];
|
|
97
|
+
/** True when `cells` hold differing values. */
|
|
98
|
+
mixed?: boolean;
|
|
99
|
+
/** Where the surface is drawn: `"cell"`, the grid's own popover, modal or
|
|
100
|
+
* in-cell surface; `"row-editor"`, a field of the sheet's row editor; or
|
|
101
|
+
* `"editor"`, a field of a standalone `DataEditor` — so a surface can lay
|
|
102
|
+
* itself out to suit (a picker nesting its own popovers only where it has
|
|
103
|
+
* room). */
|
|
104
|
+
surface?: "cell" | "row-editor" | "editor";
|
|
105
|
+
/** Commit a new value for this cell — for every cell, when the surface
|
|
106
|
+
* stands for several. */
|
|
95
107
|
onChange: (value: any) => void;
|
|
108
|
+
/** With `cells`, commit a value for each cell, aligned with them — for a
|
|
109
|
+
* surface that changes each cell's own value (adding a tag to every row's
|
|
110
|
+
* list) rather than setting them all to one. */
|
|
111
|
+
onChangeCells?: (values: any[]) => void;
|
|
96
112
|
/** Reset this cell (and selection) to its base value. */
|
|
97
113
|
resetValue: () => void;
|
|
98
114
|
/** Close the surface and return focus to the table. */
|
|
99
115
|
close: () => void;
|
|
100
116
|
}
|
|
101
117
|
|
|
118
|
+
/** One of the cells a multi-cell surface stands for. */
|
|
119
|
+
export interface CellSelectionEntry<T = any> {
|
|
120
|
+
rowIndex: number;
|
|
121
|
+
row: T | null | undefined;
|
|
122
|
+
value: any;
|
|
123
|
+
}
|
|
124
|
+
|
|
102
125
|
/** How a cell's detail surface is presented. Orthogonal to what it renders. */
|
|
103
126
|
export type DetailPresentation = "popover" | "modal" | "inline";
|
|
104
127
|
|
|
@@ -148,11 +171,45 @@ export interface ColumnSpec {
|
|
|
148
171
|
* same component works in any container.
|
|
149
172
|
*/
|
|
150
173
|
cellDetail?: (ctx: CellDetailContext) => React.ReactNode;
|
|
174
|
+
/**
|
|
175
|
+
* Whether this column's `cellDetail` can stand for several cells at once —
|
|
176
|
+
* read the shared value (or `ctx.mixed`) and write every cell in
|
|
177
|
+
* `ctx.cells` through one `onChange`. A surface that doesn't declare this
|
|
178
|
+
* is shown read-only over a multi-row selection, with "Multiple values"
|
|
179
|
+
* where they differ. The default editors (an input by `dataType`) always
|
|
180
|
+
* can, since setting one value on every cell is what they do.
|
|
181
|
+
*/
|
|
182
|
+
multiCell?: boolean;
|
|
151
183
|
/** How `cellDetail` is presented. Defaults to `"popover"`. */
|
|
152
184
|
detailPresentation?: DetailPresentation;
|
|
185
|
+
/** What one cell of the column is called, for the selection indicator
|
|
186
|
+
* ("1 lithology", "3 lithologies"). Defaults to the column's name. */
|
|
187
|
+
cellLabel?: string;
|
|
188
|
+
/** Where a popover `cellDetail` opens against its cell. Defaults to
|
|
189
|
+
* `"right-start"`; a wide surface (a tag picker) reads better below, at
|
|
190
|
+
* `"bottom-start"`. */
|
|
191
|
+
detailPlacement?: Placement;
|
|
153
192
|
cellComponent?: any;
|
|
154
193
|
category?: string;
|
|
155
194
|
editable?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* A **derived** column holds values computed from other data — a total, an
|
|
197
|
+
* age that follows from an interval and a proportion — rather than values
|
|
198
|
+
* anyone types. It is never writable, whatever `editable` or the table
|
|
199
|
+
* says, and every write path (inline editing, fill, paste, the row editor)
|
|
200
|
+
* leaves it alone; it is drawn dimmed so a reader can tell what is a record
|
|
201
|
+
* and what is a restatement of one. Use it instead of `editable: false` when
|
|
202
|
+
* the read-only-ness is a property of the *data* rather than of the view.
|
|
203
|
+
*/
|
|
204
|
+
derived?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* A **hidden** column stays in the spec but is left out of the working
|
|
207
|
+
* spec the table is built from: it isn't rendered, isn't part of a
|
|
208
|
+
* selection, and isn't written by a fill or a paste. A consumer keeps one
|
|
209
|
+
* spec and toggles this flag ("show absolute ages", "show generated ids")
|
|
210
|
+
* rather than maintaining two arrays. Resolved by `postprocessColumnSpec`.
|
|
211
|
+
*/
|
|
212
|
+
hidden?: boolean;
|
|
156
213
|
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
157
214
|
style?: React.CSSProperties;
|
|
158
215
|
width?: number;
|
|
@@ -328,15 +385,36 @@ export function generateColumnSpec<T>(
|
|
|
328
385
|
|
|
329
386
|
export function postprocessColumnSpec(columnSpec: ColumnSpec[]) {
|
|
330
387
|
/** Postprocess column spec to make sure that, e.g., column filters are
|
|
331
|
-
* properly established, etc.
|
|
388
|
+
* properly established, etc. Hidden columns are dropped here, so everything
|
|
389
|
+
* downstream — the renderer, the selection, the edit paths — works with the
|
|
390
|
+
* visible columns only and indexes into one array.
|
|
332
391
|
*/
|
|
333
|
-
return columnSpec
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
392
|
+
return columnSpec
|
|
393
|
+
.filter((col) => !col.hidden)
|
|
394
|
+
.map((col) => {
|
|
395
|
+
return {
|
|
396
|
+
...col,
|
|
397
|
+
filters: postprocessColumnFilters(col),
|
|
398
|
+
actions: col.actions ?? [],
|
|
399
|
+
};
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Whether a column takes writes at all: the table is editable, the column
|
|
405
|
+
* isn't locked (`editable: false`) and it isn't `derived`. This is the one
|
|
406
|
+
* rule every write path consults — the inline editor, `onSelectionEdited`,
|
|
407
|
+
* fill, clear, clipboard paste and the row editor — so a locked column is
|
|
408
|
+
* locked however the edit arrives, not only when it is typed into.
|
|
409
|
+
*/
|
|
410
|
+
export function isColumnWritable(
|
|
411
|
+
col: ColumnSpec | null | undefined,
|
|
412
|
+
tableEditable: boolean = true,
|
|
413
|
+
): boolean {
|
|
414
|
+
if (col == null) return false;
|
|
415
|
+
if (!tableEditable) return false;
|
|
416
|
+
if (col.derived) return false;
|
|
417
|
+
return col.editable !== false;
|
|
340
418
|
}
|
|
341
419
|
|
|
342
420
|
function postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {
|
package/src/provider/core.ts
CHANGED
|
@@ -402,7 +402,7 @@ export function DataSheetProviderInner<T>(
|
|
|
402
402
|
const rows = loadedData.filter((r) => r != null);
|
|
403
403
|
if (rows.length === 0) return;
|
|
404
404
|
derivedSpecFor.current = columnSpec;
|
|
405
|
-
storeAPI.setState({ columnSpec: columnSpec(rows) });
|
|
405
|
+
storeAPI.setState({ columnSpec: postprocessColumnSpec(columnSpec(rows)) });
|
|
406
406
|
}, [columnSpec, loadedData, storeAPI]);
|
|
407
407
|
|
|
408
408
|
const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);
|
|
@@ -642,10 +642,25 @@ function itemCount(n: number, dataKind: string) {
|
|
|
642
642
|
}
|
|
643
643
|
|
|
644
644
|
export function pluralize(singularForm: string, n: number) {
|
|
645
|
-
const pluralForm = singularForm + "s";
|
|
646
|
-
if (n == 0) return `${pluralForm}`;
|
|
647
645
|
if (n == 1) return singularForm;
|
|
648
|
-
return
|
|
646
|
+
return pluralFormOf(singularForm);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
/** An English plural, well enough for the nouns a sheet uses: "row" → "rows",
|
|
650
|
+
* "lithology" → "lithologies", "thickness (m)" → "thicknesses (m)" — a
|
|
651
|
+
* trailing parenthetical (a unit, say) stays as it is. */
|
|
652
|
+
export function pluralFormOf(singularForm: string): string {
|
|
653
|
+
const match = singularForm.match(/^(.*?)(\s*\([^)]*\))?$/);
|
|
654
|
+
const head = match?.[1] ?? singularForm;
|
|
655
|
+
const tail = match?.[2] ?? "";
|
|
656
|
+
if (head === "") return singularForm;
|
|
657
|
+
let plural = head + "s";
|
|
658
|
+
if (/(s|x|z|ch|sh)$/i.test(head)) {
|
|
659
|
+
plural = head + "es";
|
|
660
|
+
} else if (/[^aeiou]y$/i.test(head)) {
|
|
661
|
+
plural = head.slice(0, -1) + "ies";
|
|
662
|
+
}
|
|
663
|
+
return plural + tail;
|
|
649
664
|
}
|
|
650
665
|
|
|
651
666
|
export function capitalize(s: string) {
|
package/src/provider/types.ts
CHANGED
|
@@ -147,7 +147,7 @@ export interface DataSheetState<T> {
|
|
|
147
147
|
/** Whether selecting a cell automatically activates its surface (opens an
|
|
148
148
|
* editor/detail panel and, for editors, focuses it). `"manual"` opens only
|
|
149
149
|
* on click. */
|
|
150
|
-
cellInteraction: "auto" | "manual";
|
|
150
|
+
cellInteraction: "auto" | "manual" | "second-click";
|
|
151
151
|
/** Runtime override of `cellInteraction`: while `false`, auto-activation is
|
|
152
152
|
* suppressed (set by pressing Escape, re-armed by clicking a cell) so the
|
|
153
153
|
* keyboard prioritizes navigation. */
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getSelectionCardinality,
|
|
20
20
|
range,
|
|
21
21
|
} from "../actions";
|
|
22
|
+
import { isColumnWritable } from "./column-spec.ts";
|
|
22
23
|
|
|
23
24
|
/** Monotonic counter for synthetic ids on in-table-added rows. */
|
|
24
25
|
let _addedRowCounter = 0;
|
|
@@ -240,6 +241,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
240
241
|
event.preventDefault();
|
|
241
242
|
},
|
|
242
243
|
onCellEdited(rowIndex: number, columnName: string, value: any) {
|
|
244
|
+
// The column decides whether it takes writes (see `isColumnWritable`):
|
|
245
|
+
// a locked or derived column is refused here as well as in the cell
|
|
246
|
+
// renderer, so a programmatic caller — the row editor, say — can't
|
|
247
|
+
// write what the grid wouldn't let you type.
|
|
248
|
+
const targetColumn = get().columnSpec.find((c) => c.key === columnName);
|
|
249
|
+
if (!isColumnWritable(targetColumn, get().editable)) return;
|
|
243
250
|
set((state) => {
|
|
244
251
|
const { editable, updatedData, data } = state;
|
|
245
252
|
if (!editable) return {};
|
|
@@ -297,6 +304,8 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
297
304
|
if (rowIsDeleted) continue;
|
|
298
305
|
let vals = {};
|
|
299
306
|
for (const col of colRange) {
|
|
307
|
+
// A locked or derived column is never cleared
|
|
308
|
+
if (!isColumnWritable(columnSpec[col], state.editable)) continue;
|
|
300
309
|
const key = columnSpec[col].key;
|
|
301
310
|
const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
|
|
302
311
|
if (currentValue != null && currentValue !== "") {
|
|
@@ -309,6 +318,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
309
318
|
});
|
|
310
319
|
}
|
|
311
320
|
}
|
|
321
|
+
if (Object.keys(vals).length === 0) continue;
|
|
312
322
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
313
323
|
spec[row] = { [op]: vals };
|
|
314
324
|
}
|
|
@@ -355,8 +365,12 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
355
365
|
// target's click toggle — this avoids racing the selection event
|
|
356
366
|
// (which fires on mousedown, possibly more than once) and is what
|
|
357
367
|
// makes both re-focus-to-open and click-to-close reliable.
|
|
368
|
+
// In "second-click" mode a new selection only selects; the click on
|
|
369
|
+
// the already-selected cell opens it.
|
|
358
370
|
if (!selectionEquals(selection, state.selection)) {
|
|
359
|
-
spec.cellSurfaceOpen =
|
|
371
|
+
spec.cellSurfaceOpen =
|
|
372
|
+
state.cellInteraction !== "second-click" &&
|
|
373
|
+
singleFocusedCell(selection) != null;
|
|
360
374
|
}
|
|
361
375
|
return spec;
|
|
362
376
|
});
|
|
@@ -381,8 +395,13 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
381
395
|
for (const visibleRow of rowRange) {
|
|
382
396
|
// Selection indices are visible positions; map to the data row.
|
|
383
397
|
const row = toDataRowIndex(state, visibleRow);
|
|
398
|
+
// A deleted row takes no edits
|
|
399
|
+
if (state.rowStatus[row] === TableElementStatus.DELETED) continue;
|
|
384
400
|
let vals = {};
|
|
385
401
|
for (const col of colRange) {
|
|
402
|
+
// Only the columns that take writes — a selection spanning a
|
|
403
|
+
// locked or derived column writes around it
|
|
404
|
+
if (!isColumnWritable(columnSpec[col], editable)) continue;
|
|
386
405
|
const key = columnSpec[col].key;
|
|
387
406
|
vals[key] = value;
|
|
388
407
|
edits.push({
|
|
@@ -392,6 +411,7 @@ export function createZustandStore<T>(set, get): DataSheetStoreMain<T> {
|
|
|
392
411
|
row: state.data[row],
|
|
393
412
|
});
|
|
394
413
|
}
|
|
414
|
+
if (Object.keys(vals).length === 0) continue;
|
|
395
415
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
396
416
|
spec[row] = { [op]: vals };
|
|
397
417
|
}
|
|
@@ -594,6 +614,8 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
|
|
|
594
614
|
// Fill values downwards
|
|
595
615
|
if (!editable || fillValueBaseCell == null) return updatedData;
|
|
596
616
|
const { col, row: baseVisibleRow } = fillValueBaseCell;
|
|
617
|
+
// Dragging from a locked or derived column fills nothing
|
|
618
|
+
if (!isColumnWritable(columnSpec[col], editable)) return updatedData;
|
|
597
619
|
// The base cell and target rows are visible positions; map to data rows.
|
|
598
620
|
const baseRow = toDataRowIndex(state, baseVisibleRow);
|
|
599
621
|
const key = columnSpec[col].key;
|
|
@@ -603,6 +625,7 @@ function fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {
|
|
|
603
625
|
const { rows } = region;
|
|
604
626
|
for (const visibleRow of range(rows ?? [])) {
|
|
605
627
|
const row = toDataRowIndex(state, visibleRow);
|
|
628
|
+
if (state.rowStatus[row] === TableElementStatus.DELETED) continue;
|
|
606
629
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
607
630
|
spec[row] = { [op]: { [key]: value } };
|
|
608
631
|
}
|
|
@@ -643,6 +666,12 @@ function valuesAreEquivalent(a: any, b: any): boolean {
|
|
|
643
666
|
const aBlank = a == null || a === "";
|
|
644
667
|
const bBlank = b == null || b === "";
|
|
645
668
|
if (aBlank || bBlank) return aBlank && bBlank;
|
|
669
|
+
// Structured values (an interval position, a list of lithologies) compare
|
|
670
|
+
// by content: as strings, every object is "[object Object]", so any edit
|
|
671
|
+
// to one — or to a list that keeps its length — read as no change
|
|
672
|
+
if (typeof a === "object" || typeof b === "object") {
|
|
673
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
674
|
+
}
|
|
646
675
|
return String(a) === String(b);
|
|
647
676
|
}
|
|
648
677
|
|
|
@@ -13,6 +13,7 @@ import { singleFocusedCell } from "../provider";
|
|
|
13
13
|
import { Cell } from "@blueprintjs/table";
|
|
14
14
|
import { ctx, dragValueHandlerAtom, useSelector } from "../provider";
|
|
15
15
|
import { Intent } from "@blueprintjs/core";
|
|
16
|
+
import classNames from "classnames";
|
|
16
17
|
|
|
17
18
|
/** Two validations are equivalent if they convey the same thing — so a fresh
|
|
18
19
|
* `validateCell` result object doesn't force a re-render when nothing changed. */
|
|
@@ -111,7 +112,10 @@ export function basicCellRenderer<T>(
|
|
|
111
112
|
? null
|
|
112
113
|
: validateCell(col, value, row, dataRowIndex);
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
// A derived column is never writable, whatever `editable` says — see
|
|
116
|
+
// `isColumnWritable`, which every write path in the store applies too.
|
|
117
|
+
const editable =
|
|
118
|
+
(col.editable ?? state.editable) && !isDeleted && !col.derived;
|
|
115
119
|
const tableIsEditable = state.editable;
|
|
116
120
|
|
|
117
121
|
// topLeftCell stores visible row indices, so compare with the visible rowIndex
|
|
@@ -160,6 +164,10 @@ export function basicCellRenderer<T>(
|
|
|
160
164
|
const detailPresentation =
|
|
161
165
|
col.cellDetail != null ? (col.detailPresentation ?? "popover") : null;
|
|
162
166
|
|
|
167
|
+
// Derived values are drawn dimmed, so a reader can tell a record from a
|
|
168
|
+
// restatement of one. Applied on every path below.
|
|
169
|
+
const derivedClass = col.derived ? "derived-cell" : undefined;
|
|
170
|
+
|
|
163
171
|
// Fast path — any non-focused cell whose *unfocused* appearance is just the
|
|
164
172
|
// value viewer (a plain Blueprint `Cell`). That's everything except a custom
|
|
165
173
|
// `cellComponent` (its own markup on every cell) and an *inline* `cellDetail`
|
|
@@ -179,6 +187,7 @@ export function basicCellRenderer<T>(
|
|
|
179
187
|
loading,
|
|
180
188
|
//value,
|
|
181
189
|
style,
|
|
190
|
+
className: derivedClass,
|
|
182
191
|
interactive: false,
|
|
183
192
|
//disabled: tableIsEditable && !editable,
|
|
184
193
|
},
|
|
@@ -216,6 +225,7 @@ export function basicCellRenderer<T>(
|
|
|
216
225
|
// Build the detail context for the unified `cellDetail` surface.
|
|
217
226
|
const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({
|
|
218
227
|
...cellContext,
|
|
228
|
+
surface: "cell",
|
|
219
229
|
editable: editableFlag,
|
|
220
230
|
onChange(v: any) {
|
|
221
231
|
if (editableFlag) onCellEdited(dataRowIndex, col.key, v);
|
|
@@ -255,6 +265,7 @@ export function basicCellRenderer<T>(
|
|
|
255
265
|
loading,
|
|
256
266
|
value,
|
|
257
267
|
style,
|
|
268
|
+
className: derivedClass,
|
|
258
269
|
disabled: tableIsEditable && !editable,
|
|
259
270
|
interactive: false,
|
|
260
271
|
...cellComponentProps,
|
|
@@ -308,7 +319,11 @@ export function basicCellRenderer<T>(
|
|
|
308
319
|
}
|
|
309
320
|
|
|
310
321
|
// Default: popover (same open/close machinery as editors and panels).
|
|
311
|
-
const panel = h(
|
|
322
|
+
const panel = h(
|
|
323
|
+
EditorPopup,
|
|
324
|
+
{ valueViewer: _renderedValue, placement: col.detailPlacement },
|
|
325
|
+
content,
|
|
326
|
+
);
|
|
312
327
|
return h(
|
|
313
328
|
_Cell,
|
|
314
329
|
{
|
|
@@ -385,7 +400,7 @@ export function basicCellRenderer<T>(
|
|
|
385
400
|
if (_dataEditor != null) {
|
|
386
401
|
cellContents = _dataEditor;
|
|
387
402
|
}
|
|
388
|
-
const className = "value-viewer-cell";
|
|
403
|
+
const className = classNames("value-viewer-cell", derivedClass);
|
|
389
404
|
|
|
390
405
|
return h(
|
|
391
406
|
_Cell,
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
} from "../postgrest-table";
|
|
17
17
|
import { buildActionContext } from "../actions";
|
|
18
18
|
import { useMemo } from "react";
|
|
19
|
+
import classNames from "classnames";
|
|
19
20
|
|
|
20
21
|
export interface ColumnActionsConfig {
|
|
21
22
|
activeSort?: ColumnSortEntry | null;
|
|
@@ -107,9 +108,18 @@ function ColumnHeaderName({ col, hasSortActive, hasFilterActive, activeSort }) {
|
|
|
107
108
|
textOverflow: "ellipsis",
|
|
108
109
|
whiteSpace: "nowrap",
|
|
109
110
|
},
|
|
111
|
+
className: classNames({ "derived-column-name": col.derived }),
|
|
110
112
|
},
|
|
111
113
|
col.name,
|
|
112
114
|
),
|
|
115
|
+
// A derived column says so in its header: the values below are computed
|
|
116
|
+
// and won't take an edit.
|
|
117
|
+
h.if(col.derived === true)(Icon, {
|
|
118
|
+
icon: "function",
|
|
119
|
+
size: 12,
|
|
120
|
+
title: "Derived — computed from other values, not editable",
|
|
121
|
+
style: { marginLeft: "4px", flexShrink: 0, opacity: 0.6 },
|
|
122
|
+
}),
|
|
113
123
|
h.if(hasSortActive || hasFilterActive)(
|
|
114
124
|
"span",
|
|
115
125
|
{
|
package/src/types.ts
CHANGED
|
@@ -143,8 +143,12 @@ export enum DataSheetDensity {
|
|
|
143
143
|
* until the next click.
|
|
144
144
|
* - `"manual"` (default when `autoFocusEditor` is `false`): the surface stays
|
|
145
145
|
* closed until the cell is clicked; arrow keys always navigate the table.
|
|
146
|
+
* - `"second-click"`: a click selects a cell and nothing more; a second click
|
|
147
|
+
* on it (or Enter / F2) opens its surface. For a sheet whose selection
|
|
148
|
+
* already feeds an editor of its own — a row editor beside the grid — so
|
|
149
|
+
* selecting doesn't also open a popover over the cells.
|
|
146
150
|
*/
|
|
147
|
-
export type CellInteraction = "auto" | "manual";
|
|
151
|
+
export type CellInteraction = "auto" | "manual" | "second-click";
|
|
148
152
|
|
|
149
153
|
export interface DataSheetRendererProps<T = any>
|
|
150
154
|
extends TableProps, DataViewSharedProps<T> {
|