@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.
Files changed (125) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +60 -19
  3. package/dist/actions/context.cjs +10 -1
  4. package/dist/actions/context.cjs.map +1 -1
  5. package/dist/actions/context.js +10 -1
  6. package/dist/actions/context.js.map +1 -1
  7. package/dist/actions/types.d.ts +4 -0
  8. package/dist/components/data-editor.cjs +527 -0
  9. package/dist/components/data-editor.cjs.map +1 -0
  10. package/dist/components/data-editor.d.ts +142 -0
  11. package/dist/components/data-editor.js +524 -0
  12. package/dist/components/data-editor.js.map +1 -0
  13. package/dist/components/editor-actions.cjs +167 -0
  14. package/dist/components/editor-actions.cjs.map +1 -0
  15. package/dist/components/editor-actions.d.ts +37 -0
  16. package/dist/components/editor-actions.js +165 -0
  17. package/dist/components/editor-actions.js.map +1 -0
  18. package/dist/components/editor-popup.cjs +11 -1
  19. package/dist/components/editor-popup.cjs.map +1 -1
  20. package/dist/components/editor-popup.js +11 -1
  21. package/dist/components/editor-popup.js.map +1 -1
  22. package/dist/components/index.d.ts +3 -0
  23. package/dist/components/indicators/selection.cjs +10 -4
  24. package/dist/components/indicators/selection.cjs.map +1 -1
  25. package/dist/components/indicators/selection.js +10 -4
  26. package/dist/components/indicators/selection.js.map +1 -1
  27. package/dist/components/row-editor.cjs +351 -0
  28. package/dist/components/row-editor.cjs.map +1 -0
  29. package/dist/components/row-editor.d.ts +181 -0
  30. package/dist/components/row-editor.js +349 -0
  31. package/dist/components/row-editor.js.map +1 -0
  32. package/dist/components/row-editor.module.sass.cjs +51 -0
  33. package/dist/components/row-editor.module.sass.cjs.map +1 -0
  34. package/dist/components/row-editor.module.sass.js +49 -0
  35. package/dist/components/row-editor.module.sass.js.map +1 -0
  36. package/dist/components/toolbars/actions-toolbar.cjs +1 -1
  37. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -1
  38. package/dist/components/toolbars/actions-toolbar.js +1 -1
  39. package/dist/components/toolbars/actions-toolbar.js.map +1 -1
  40. package/dist/data-panel.cjs +36 -0
  41. package/dist/data-panel.cjs.map +1 -1
  42. package/dist/data-panel.d.ts +3 -2
  43. package/dist/data-panel.js +37 -1
  44. package/dist/data-panel.js.map +1 -1
  45. package/dist/data-panel.module.sass.cjs +28 -26
  46. package/dist/data-panel.module.sass.cjs.map +1 -1
  47. package/dist/data-panel.module.sass.js +28 -26
  48. package/dist/data-panel.module.sass.js.map +1 -1
  49. package/dist/data-sheet.css +267 -56
  50. package/dist/data-sheet.d.ts +2 -1
  51. package/dist/data-view.d.ts +1 -0
  52. package/dist/index.cjs +28 -0
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.js +31 -3
  55. package/dist/index.js.map +1 -1
  56. package/dist/main.module.sass.cjs +14 -13
  57. package/dist/main.module.sass.cjs.map +1 -1
  58. package/dist/main.module.sass.js +14 -13
  59. package/dist/main.module.sass.js.map +1 -1
  60. package/dist/postgrest-table/data-loaders.cjs +8 -1
  61. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  62. package/dist/postgrest-table/data-loaders.js +9 -2
  63. package/dist/postgrest-table/data-loaders.js.map +1 -1
  64. package/dist/provider/column-spec.cjs +8 -1
  65. package/dist/provider/column-spec.cjs.map +1 -1
  66. package/dist/provider/column-spec.d.ts +105 -1
  67. package/dist/provider/column-spec.js +8 -1
  68. package/dist/provider/column-spec.js.map +1 -1
  69. package/dist/provider/core.cjs +32 -7
  70. package/dist/provider/core.cjs.map +1 -1
  71. package/dist/provider/core.d.ts +5 -1
  72. package/dist/provider/core.js +32 -7
  73. package/dist/provider/core.js.map +1 -1
  74. package/dist/provider/loader-state.cjs +11 -3
  75. package/dist/provider/loader-state.cjs.map +1 -1
  76. package/dist/provider/loader-state.d.ts +8 -1
  77. package/dist/provider/loader-state.js +12 -4
  78. package/dist/provider/loader-state.js.map +1 -1
  79. package/dist/provider/table-data.cjs +10 -1
  80. package/dist/provider/table-data.cjs.map +1 -1
  81. package/dist/provider/table-data.d.ts +10 -0
  82. package/dist/provider/table-data.js +11 -2
  83. package/dist/provider/table-data.js.map +1 -1
  84. package/dist/provider/types.cjs.map +1 -1
  85. package/dist/provider/types.d.ts +4 -1
  86. package/dist/provider/types.js.map +1 -1
  87. package/dist/provider/zustand-store.cjs +26 -13
  88. package/dist/provider/zustand-store.cjs.map +1 -1
  89. package/dist/provider/zustand-store.js +14 -1
  90. package/dist/provider/zustand-store.js.map +1 -1
  91. package/dist/renderers/cell-renderer.cjs +15 -4
  92. package/dist/renderers/cell-renderer.cjs.map +1 -1
  93. package/dist/renderers/cell-renderer.js +13 -4
  94. package/dist/renderers/cell-renderer.js.map +1 -1
  95. package/dist/renderers/column-header-cell.cjs +12 -1
  96. package/dist/renderers/column-header-cell.cjs.map +1 -1
  97. package/dist/renderers/column-header-cell.js +11 -1
  98. package/dist/renderers/column-header-cell.js.map +1 -1
  99. package/dist/types.cjs.map +1 -1
  100. package/dist/types.d.ts +30 -1
  101. package/dist/types.js.map +1 -1
  102. package/package.json +2 -2
  103. package/src/actions/context.ts +13 -2
  104. package/src/actions/types.ts +5 -0
  105. package/src/components/data-editor.ts +741 -0
  106. package/src/components/editor-actions.ts +228 -0
  107. package/src/components/editor-popup.ts +16 -3
  108. package/src/components/index.ts +3 -0
  109. package/src/components/indicators/selection.ts +12 -4
  110. package/src/components/row-editor.module.sass +161 -0
  111. package/src/components/row-editor.ts +620 -0
  112. package/src/components/toolbars/actions-toolbar.ts +3 -2
  113. package/src/data-panel.module.sass +25 -0
  114. package/src/data-panel.ts +50 -1
  115. package/src/main.module.sass +19 -0
  116. package/src/postgrest-table/data-loaders.ts +13 -0
  117. package/src/provider/column-spec.ts +94 -16
  118. package/src/provider/core.ts +41 -9
  119. package/src/provider/loader-state.ts +15 -2
  120. package/src/provider/table-data.ts +23 -1
  121. package/src/provider/types.ts +4 -1
  122. package/src/provider/zustand-store.ts +30 -1
  123. package/src/renderers/cell-renderer.ts +18 -3
  124. package/src/renderers/column-header-cell.ts +10 -0
  125. package/src/types.ts +31 -1
@@ -0,0 +1,181 @@
1
+ import { IconName } from '@blueprintjs/core';
2
+ import { ReactNode } from 'react';
3
+ import { RegionCardinality } from '@blueprintjs/table';
4
+ import { CellValidation, ColumnSpec } from '../provider';
5
+ import { TableAction } from '../actions';
6
+ import { DataEditorField, DataEditorFrame, DataEditorProps, FieldSpec } from './data-editor';
7
+ export interface RowEditorProps<T = any> {
8
+ /** The columns to show, in order. Hidden columns are left out unless
9
+ * `showHidden` is set; derived and locked columns show read-only. */
10
+ columnSpec: ColumnSpec[];
11
+ /** The row as loaded (the base values). One row; see `rows` for several. */
12
+ row?: T | null;
13
+ /** The pending edits to `row`, laid over it for display. A field present
14
+ * here is marked as edited. */
15
+ edits?: Partial<T> | null;
16
+ /** Several rows at once (a multi-row selection). Takes precedence over
17
+ * `row`. Each field then stands for that column across all of them. */
18
+ rows?: T[];
19
+ /** Edit overlays aligned with `rows`. */
20
+ rowEdits?: (Partial<T> | null | undefined)[];
21
+ /** The rows' data indices, aligned with `rows`, handed to `validate` and
22
+ * `cellDetail`. */
23
+ rowIndices?: number[];
24
+ /** The columns the selection falls in, when it is a cell selection rather
25
+ * than whole rows. Those fields are editable and marked; the others are
26
+ * shown read-only for context. `null` means every writable field. */
27
+ focusColumns?: string[] | null;
28
+ /** Whether the form takes edits at all. Off, it is a row *viewer*. */
29
+ editable?: boolean;
30
+ /** A field was changed — for every row the form stands for. Absent, the
31
+ * form is read-only. */
32
+ onChange?: (columnKey: string, value: any) => void;
33
+ /** A field was changed row by row: a value for each of the form's rows,
34
+ * aligned with them (a `cellDetail`'s `onChangeCells`). */
35
+ onChangeCells?: (columnKey: string, values: any[]) => void;
36
+ /** The field to mark as active — the cell the sheet has selected, when the
37
+ * selection came from the form — without narrowing what is editable. */
38
+ activeColumn?: string | null;
39
+ /** A field was clicked. */
40
+ onFieldClick?: (columnKey: string) => void;
41
+ /** Revert one field to its base value, in every row. Absent, edited fields
42
+ * have no revert affordance. */
43
+ onResetField?: (columnKey: string) => void;
44
+ /** Also show the columns the spec hides (read-only). */
45
+ showHidden?: boolean;
46
+ /** Leave out fields with no value — a compact read-only view. Editable
47
+ * fields always show, so there is somewhere to type. */
48
+ hideEmpty?: boolean;
49
+ /** Labels beside values rather than above them. */
50
+ inline?: boolean;
51
+ className?: string;
52
+ /** Draw the form as a panel: bordered, with a title bar. */
53
+ panel?: boolean;
54
+ /** The panel's title ("Editing 1 row"). */
55
+ title?: ReactNode;
56
+ /** Close the panel — a ✕ at the end of the title bar. */
57
+ onClose?: () => void;
58
+ /** A label for the ✕ ("Clear selection"). */
59
+ closeLabel?: string;
60
+ /** Rendered above the fields. */
61
+ header?: ReactNode;
62
+ children?: ReactNode;
63
+ }
64
+ /** The form over one row or several, as the sheet's row editor draws it:
65
+ * `DataEditorFields` in a `DataEditorFrame`, with the sheet's notions of a
66
+ * focus (the columns a cell selection falls in) and an active field. */
67
+ export declare function RowEditor<T = any>(props: RowEditorProps<T>): import('react').FunctionComponentElement<{
68
+ panel?: boolean;
69
+ title?: ReactNode;
70
+ onClose?: () => void;
71
+ closeLabel?: string;
72
+ footer?: ReactNode;
73
+ className?: string;
74
+ children?: ReactNode;
75
+ }>;
76
+ /** The row editor's frame: the data editor's. */
77
+ export declare const RowEditorFrame: typeof DataEditorFrame;
78
+ /** A row editor field: the data editor's. */
79
+ export declare const RowEditorField: typeof DataEditorField;
80
+ export interface SelectedRows<T = any> {
81
+ /** Data indices of the selected rows; empty when nothing is selected. */
82
+ rowIndices: number[];
83
+ rows: (T | null | undefined)[];
84
+ edits: (Partial<T> | null | undefined)[];
85
+ /** The columns a cell selection falls in; `null` for whole rows (or the
86
+ * whole table), when every column is in play. */
87
+ columnKeys: string[] | null;
88
+ cardinality: RegionCardinality | null;
89
+ /** Whether any selected row is marked deleted. */
90
+ anyDeleted: boolean;
91
+ }
92
+ /** The rows the sheet's selection addresses, with their edit overlays and the
93
+ * columns the selection falls in. Must be read inside a
94
+ * `DataSheetProvider`. */
95
+ export declare function useSelectedRows<T = any>(): SelectedRows<T>;
96
+ export interface SelectedRow<T = any> {
97
+ rowIndex: number | null;
98
+ row: T | null;
99
+ edits: Partial<T> | null;
100
+ isDeleted: boolean;
101
+ }
102
+ /** The first selected row alone — the single-row view of `useSelectedRows`. */
103
+ export declare function useSelectedRow<T = any>(): SelectedRow<T>;
104
+ export interface SelectedRowEditorProps extends Omit<RowEditorProps, "columnSpec" | "row" | "edits" | "rows" | "rowEdits" | "rowIndices" | "focusColumns" | "onChange" | "onResetField"> {
105
+ /** Shown when no row is selected. Defaults to a `NonIdealState` saying so
106
+ * ("No units selected"). */
107
+ emptyState?: ReactNode;
108
+ /** Shown above the fields over a multi-row selection; the default says a
109
+ * change applies to all of them. Pass `null` for nothing. */
110
+ selectionSummary?: ((count: number) => ReactNode) | null;
111
+ /** Whether the panel's ✕ clears the selection (default). */
112
+ closeable?: boolean;
113
+ /** Follow the sheet's `rowEditorOpenAtom`, rendering nothing while it is
114
+ * off (default). */
115
+ toggleable?: boolean;
116
+ }
117
+ /**
118
+ * The row editor bound to the enclosing sheet's store: it follows the
119
+ * selected rows and the columns a cell selection falls in, and writes through
120
+ * the store's `onCellEdited` for every selected row, so an edit made here is
121
+ * the same edit as one typed into the grid — same overlay, same `onEdit`
122
+ * events, same reset. Render it anywhere under the `DataSheetProvider` (the
123
+ * `DataSheet`'s children, a sibling panel, or a page where the grid itself is
124
+ * not mounted).
125
+ */
126
+ export declare function SelectedRowEditor(props: SelectedRowEditorProps): import('react').FunctionComponentElement<{
127
+ panel?: boolean;
128
+ title?: ReactNode;
129
+ onClose?: () => void;
130
+ closeLabel?: string;
131
+ footer?: ReactNode;
132
+ className?: string;
133
+ children?: ReactNode;
134
+ }> | import('react').FunctionComponentElement<RowEditorProps<unknown>> | null;
135
+ export interface SelectedDataEditorProps<T = any> extends Omit<DataEditorProps<T>, "dataSpec" | "data" | "onSave"> {
136
+ /** The fields; defaults to the sheet's column spec. */
137
+ dataSpec?: FieldSpec[];
138
+ /** Persist the edited record. Defaults to the sheet's provider
139
+ * (`rowEditing.saveRows`), which refreshes the rows after. Without either,
140
+ * the editor is a viewer. */
141
+ onSave?: DataEditorProps<T>["onSave"];
142
+ /** Whether the ✕ in the title bar clears the selection (default). */
143
+ closeable?: boolean;
144
+ /** Show the sheet's actions, scoped to the record and its fields (off by
145
+ * default: the sheet's toolbar carries them). */
146
+ showActions?: boolean;
147
+ }
148
+ /**
149
+ * A `DataEditor` over the one row a sheet's or panel's selection holds: the
150
+ * immediate-edit counterpart of `SelectedRowEditor`, for a view (a `DataPanel`
151
+ * card list) whose edits are saved one record at a time rather than
152
+ * accumulated in the sheet's overlay. It keeps its own pending edits, and
153
+ * Save writes the record through the provider. Several rows selected, or
154
+ * none, it says so.
155
+ */
156
+ export declare function SelectedDataEditor<T = any>(props: SelectedDataEditorProps<T>): import('react').FunctionComponentElement<{
157
+ panel?: boolean;
158
+ title?: ReactNode;
159
+ onClose?: () => void;
160
+ closeLabel?: string;
161
+ footer?: ReactNode;
162
+ className?: string;
163
+ children?: ReactNode;
164
+ }> | import('react').FunctionComponentElement<DataEditorProps<T>>;
165
+ /** Whether the sheet's row editor is shown. Scoped to the sheet, like the
166
+ * rest of its state; `SelectedRowEditor` follows it unless `toggleable` is
167
+ * off. */
168
+ export declare const rowEditorOpenAtom: import('jotai').PrimitiveAtom<boolean> & {
169
+ init: boolean;
170
+ };
171
+ /** The row editor's open state, and a setter. */
172
+ export declare function useRowEditorOpen(): [boolean, (open: boolean) => void];
173
+ /** A toolbar toggle for the row editor, wherever it is mounted. */
174
+ export declare function ShowRowEditor({ label, icon, }: {
175
+ label?: string;
176
+ icon?: IconName;
177
+ }): import('react').FunctionComponentElement<import('@blueprintjs/core').ButtonProps>;
178
+ /** `ShowRowEditor` as a sheet action: add it to `actions` and the toggle sits
179
+ * at the toolbar's right end, whatever is selected, editable or not. */
180
+ export declare const showRowEditorAction: TableAction;
181
+ export type { CellValidation };
@@ -0,0 +1,349 @@
1
+ import h$1 from "@macrostrat/hyper";
2
+ import { NonIdealState, Button } from "@blueprintjs/core";
3
+ import { atom } from "jotai";
4
+ import { useRef, useMemo } from "react";
5
+ import { RegionCardinality } from "@blueprintjs/table";
6
+ import { getSelectedRowIndices, getSelectionCardinality, getSelectedColumnKeys } from "../actions/selection.js";
7
+ import { DataEditorField, DataEditorFrame, DataEditorFields, DataEditor } from "./data-editor.js";
8
+ import h$2 from "./row-editor.module.sass.js";
9
+ import { useStoreAPI, useSelector, ctx, tableActionsAtom, itemLabelAtom, pluralize } from "../provider/core.js";
10
+ import { selectionAtom } from "../provider/selection.js";
11
+ const h = h$1.styled(h$2);
12
+ function RowEditor(props) {
13
+ const {
14
+ columnSpec,
15
+ focusColumns = null,
16
+ editable = true,
17
+ onChange,
18
+ onChangeCells,
19
+ activeColumn = null,
20
+ onFieldClick,
21
+ onResetField,
22
+ showHidden = false,
23
+ hideEmpty = false,
24
+ inline = false,
25
+ className,
26
+ panel = false,
27
+ title,
28
+ onClose,
29
+ closeLabel,
30
+ header,
31
+ children
32
+ } = props;
33
+ const { rows, rowEdits, rowIndices } = resolveRows(props);
34
+ return h(DataEditorFrame, { className, panel, title, onClose, closeLabel }, [
35
+ header,
36
+ h(DataEditorFields, {
37
+ dataSpec: columnSpec,
38
+ rows,
39
+ rowEdits,
40
+ rowIndices,
41
+ surface: "row-editor",
42
+ editable,
43
+ onChange,
44
+ onChangeCells,
45
+ onResetField,
46
+ focusFields: focusColumns,
47
+ activeField: activeColumn,
48
+ onFieldClick,
49
+ showHidden,
50
+ hideEmpty,
51
+ inline
52
+ }),
53
+ children
54
+ ]);
55
+ }
56
+ const RowEditorFrame = DataEditorFrame;
57
+ const RowEditorField = DataEditorField;
58
+ function resolveRows(props) {
59
+ if (props.rows != null) {
60
+ return {
61
+ rows: props.rows,
62
+ rowEdits: props.rowEdits ?? [],
63
+ rowIndices: props.rowIndices ?? []
64
+ };
65
+ }
66
+ return {
67
+ rows: [props.row],
68
+ rowEdits: [props.edits],
69
+ rowIndices: props.rowIndices ?? []
70
+ };
71
+ }
72
+ function useSelectedRows() {
73
+ const selection = useSelector((s) => s.selection);
74
+ const data = useSelector((s) => s.data);
75
+ const updatedData = useSelector((s) => s.updatedData);
76
+ const rowStatus = useSelector((s) => s.rowStatus);
77
+ const columnSpec = useSelector((s) => s.columnSpec);
78
+ const filteredRowIndices = useSelector((s) => s.filteredRowIndices);
79
+ return useMemo(() => {
80
+ const regions = selection ?? [];
81
+ const rowIndices = getSelectedRowIndices(regions, filteredRowIndices);
82
+ const cardinality = getSelectionCardinality(regions) ?? null;
83
+ let columnKeys = null;
84
+ if (cardinality === RegionCardinality.CELLS) {
85
+ columnKeys = getSelectedColumnKeys(regions, columnSpec);
86
+ }
87
+ return {
88
+ rowIndices,
89
+ rows: rowIndices.map((i) => data?.[i]),
90
+ edits: rowIndices.map((i) => updatedData?.[i]),
91
+ columnKeys,
92
+ cardinality,
93
+ anyDeleted: rowIndices.some((i) => rowStatus?.[i] === "deleted")
94
+ };
95
+ }, [selection, data, updatedData, rowStatus, columnSpec, filteredRowIndices]);
96
+ }
97
+ function useSelectedRow() {
98
+ const { rowIndices, rows, edits, anyDeleted } = useSelectedRows();
99
+ if (rowIndices.length === 0) {
100
+ return { rowIndex: null, row: null, edits: null, isDeleted: false };
101
+ }
102
+ return {
103
+ rowIndex: rowIndices[0],
104
+ row: rows[0] ?? null,
105
+ edits: edits[0] ?? null,
106
+ isDeleted: anyDeleted
107
+ };
108
+ }
109
+ function SelectedRowEditor(props) {
110
+ const {
111
+ emptyState,
112
+ selectionSummary,
113
+ closeable = true,
114
+ toggleable = true,
115
+ panel = true,
116
+ editable,
117
+ header,
118
+ ...rest
119
+ } = props;
120
+ const store = useStoreAPI();
121
+ const columnSpec = useSelector((s) => s.columnSpec);
122
+ const tableEditable = useSelector((s) => s.editable);
123
+ const itemLabel = ctx.useValue(itemLabelAtom);
124
+ const setSelection = ctx.useSet(selectionAtom);
125
+ const open = ctx.useValue(rowEditorOpenAtom);
126
+ const selection = useSelector((s) => s.selection);
127
+ const filteredRowIndices = useSelector((s) => s.filteredRowIndices);
128
+ const { rowIndices, rows, edits, columnKeys, anyDeleted } = useSelectedRows();
129
+ const count = rowIndices.length;
130
+ const formSelection = useRef(null);
131
+ let activeColumn = null;
132
+ let focusColumns = columnKeys;
133
+ const own = formSelection.current;
134
+ if (own != null && sameRegions(own.regions, selection ?? [])) {
135
+ activeColumn = own.key;
136
+ focusColumns = null;
137
+ }
138
+ const items = `${count} ${pluralize(itemLabel, count)}`;
139
+ if (toggleable && !open) return null;
140
+ if (count === 0) {
141
+ let empty = emptyState;
142
+ if (empty === void 0) {
143
+ empty = h(NonIdealState, {
144
+ title: `No ${pluralize(itemLabel, 0)} selected`,
145
+ className: "row-editor-non-ideal"
146
+ });
147
+ }
148
+ return h(RowEditorFrame, { panel, className: "row-editor-empty" }, empty);
149
+ }
150
+ const canEdit = (editable ?? true) && tableEditable && !anyDeleted;
151
+ let title = `Viewing ${items}`;
152
+ if (canEdit) title = `Editing ${items}`;
153
+ let onClose;
154
+ if (closeable) onClose = () => setSelection([]);
155
+ const onChange = (columnKey, value) => {
156
+ const { onCellEdited } = store.getState();
157
+ for (const rowIndex of rowIndices) onCellEdited(rowIndex, columnKey, value);
158
+ };
159
+ const onResetField = (columnKey) => {
160
+ const { onCellEdited } = store.getState();
161
+ rowIndices.forEach((rowIndex, i) => {
162
+ const base = rows[i];
163
+ if (base == null) return;
164
+ onCellEdited(rowIndex, columnKey, base[columnKey]);
165
+ });
166
+ };
167
+ const onChangeCells = (columnKey, values) => {
168
+ const { onCellEdited } = store.getState();
169
+ rowIndices.forEach((rowIndex, i) => {
170
+ onCellEdited(rowIndex, columnKey, values[i]);
171
+ });
172
+ };
173
+ const onFieldClick = (columnKey) => {
174
+ if (activeColumn === columnKey) return;
175
+ const regions = cellRegions(
176
+ rowIndices,
177
+ columnSpec.findIndex((c) => c.key === columnKey),
178
+ filteredRowIndices
179
+ );
180
+ if (regions.length === 0) return;
181
+ formSelection.current = { regions, key: columnKey };
182
+ const state = store.getState();
183
+ store.setState({ cellSurfaceOpen: false });
184
+ state.setSelection(regions);
185
+ };
186
+ let summary = null;
187
+ if (count > 1 && canEdit && selectionSummary !== null) {
188
+ let text = `A change here applies to all ${items}.`;
189
+ if (selectionSummary != null) text = selectionSummary(count);
190
+ summary = h("div.selection-summary", text);
191
+ }
192
+ return h(RowEditor, {
193
+ ...rest,
194
+ columnSpec,
195
+ rows,
196
+ rowEdits: edits,
197
+ rowIndices,
198
+ focusColumns,
199
+ activeColumn,
200
+ onFieldClick,
201
+ panel,
202
+ title,
203
+ onClose,
204
+ closeLabel: "Clear selection",
205
+ header: h([header, summary]),
206
+ editable: canEdit,
207
+ onChange,
208
+ onChangeCells,
209
+ onResetField
210
+ });
211
+ }
212
+ function cellRegions(rowIndices, colIndex, filteredRowIndices) {
213
+ if (colIndex < 0) return [];
214
+ const visible = rowIndices.map((i) => {
215
+ if (filteredRowIndices == null) return i;
216
+ return filteredRowIndices.indexOf(i);
217
+ }).filter((i) => i >= 0).sort((a, b) => a - b);
218
+ const regions = [];
219
+ for (const row of visible) {
220
+ const last = regions[regions.length - 1];
221
+ if (last != null && last.rows[1] === row - 1) {
222
+ last.rows = [last.rows[0], row];
223
+ continue;
224
+ }
225
+ regions.push({ rows: [row, row], cols: [colIndex, colIndex] });
226
+ }
227
+ return regions;
228
+ }
229
+ function sameRegions(a, b) {
230
+ if (a.length !== b.length) return false;
231
+ return a.every((r, i) => {
232
+ const s = b[i];
233
+ return r.rows?.[0] === s.rows?.[0] && r.rows?.[1] === s.rows?.[1] && r.cols?.[0] === s.cols?.[0] && r.cols?.[1] === s.cols?.[1];
234
+ });
235
+ }
236
+ function SelectedDataEditor(props) {
237
+ const {
238
+ dataSpec,
239
+ onSave,
240
+ closeable = true,
241
+ showActions = false,
242
+ panel = true,
243
+ title,
244
+ editable,
245
+ ...rest
246
+ } = props;
247
+ useStoreAPI();
248
+ const columnSpec = useSelector((s) => s.columnSpec);
249
+ const saveRows = useSelector((s) => s.rowEditing?.saveRows);
250
+ const tableActions = ctx.useValue(
251
+ tableActionsAtom
252
+ );
253
+ const itemLabel = ctx.useValue(itemLabelAtom);
254
+ const setSelection = ctx.useSet(selectionAtom);
255
+ const { rows } = useSelectedRows();
256
+ const count = rows.length;
257
+ if (count !== 1 || rows[0] == null) {
258
+ let noun = pluralize(itemLabel, count);
259
+ let stateTitle = `${count} ${noun} selected`;
260
+ if (count === 0) stateTitle = `No ${noun} selected`;
261
+ return h(
262
+ RowEditorFrame,
263
+ { panel, className: "row-editor-empty" },
264
+ h(NonIdealState, {
265
+ title: stateTitle,
266
+ className: "row-editor-non-ideal"
267
+ })
268
+ );
269
+ }
270
+ let save = onSave;
271
+ if (save == null && saveRows != null) {
272
+ save = async (value) => {
273
+ await saveRows([value]);
274
+ };
275
+ }
276
+ const canEdit = (editable ?? true) && save != null;
277
+ let heading = title;
278
+ if (heading == null) {
279
+ heading = `Viewing 1 ${itemLabel}`;
280
+ if (canEdit) heading = `Editing 1 ${itemLabel}`;
281
+ }
282
+ let onClose;
283
+ if (closeable) onClose = () => setSelection([]);
284
+ return h(DataEditor, {
285
+ ...rest,
286
+ dataSpec: dataSpec ?? columnSpec,
287
+ data: rows[0],
288
+ onSave: save,
289
+ editable: canEdit,
290
+ panel,
291
+ title: heading,
292
+ onClose,
293
+ closeLabel: "Clear selection",
294
+ actions: tableActions,
295
+ showActions
296
+ });
297
+ }
298
+ const rowEditorOpenAtom = atom(true);
299
+ function useRowEditorOpen() {
300
+ const open = ctx.useValue(rowEditorOpenAtom);
301
+ const setOpen = ctx.useSet(rowEditorOpenAtom);
302
+ return [open, setOpen];
303
+ }
304
+ function ShowRowEditor({
305
+ label = "Row editor",
306
+ icon = "properties"
307
+ }) {
308
+ const [open, setOpen] = useRowEditorOpen();
309
+ let title = "Show the row editor";
310
+ if (open) title = "Hide the row editor";
311
+ return h(Button, {
312
+ minimal: true,
313
+ small: true,
314
+ icon,
315
+ active: open,
316
+ text: label,
317
+ title,
318
+ "aria-pressed": open,
319
+ onClick: () => setOpen(!open)
320
+ });
321
+ }
322
+ const showRowEditorAction = {
323
+ id: "show-row-editor",
324
+ name: "Row editor",
325
+ icon: "properties",
326
+ targets: [
327
+ RegionCardinality.CELLS,
328
+ RegionCardinality.FULL_ROWS,
329
+ RegionCardinality.FULL_COLUMNS,
330
+ RegionCardinality.FULL_TABLE
331
+ ],
332
+ requiresEditable: false,
333
+ placement: "end",
334
+ render: () => h(ShowRowEditor)
335
+ };
336
+ export {
337
+ RowEditor,
338
+ RowEditorField,
339
+ RowEditorFrame,
340
+ SelectedDataEditor,
341
+ SelectedRowEditor,
342
+ ShowRowEditor,
343
+ rowEditorOpenAtom,
344
+ showRowEditorAction,
345
+ useRowEditorOpen,
346
+ useSelectedRow,
347
+ useSelectedRows
348
+ };
349
+ //# sourceMappingURL=row-editor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row-editor.js","sources":["../../src/components/row-editor.ts"],"sourcesContent":["/**\n * Row editor — a selection's fields as a form, derived from the column spec:\n * the `DataEditor`'s form (see `data-editor.ts`) over the sheet's selected\n * rows.\n *\n * The row-level mirror of the cell viewer/editor split: every column becomes a\n * field whose label is the column's `name`, whose value is drawn by the\n * column's `valueRenderer`, and whose editor is the column's `cellDetail` when\n * it has one, else an input chosen from `dataType`. What may be written is the\n * same rule the grid applies (`isColumnWritable`): a locked or derived column\n * shows as read-only, and the form is read-only as a whole when `editable` is\n * off — a read-only \"row viewer\" and an editable \"row editor\" are one surface\n * in two modes.\n *\n * **Several rows at once.** Over a multi-row selection each field stands for\n * that column's cells in every selected row. A value they share is shown and\n * edited as one; where they differ the field reads \"Multiple values\". A\n * default editor (an input by `dataType`) sets one value on every cell, which\n * is always meaningful; a column's own `cellDetail` edits several cells only\n * when the column declares `multiCell`, and is otherwise shown read-only.\n *\n * **A cell selection.** When particular cells are selected rather than whole\n * rows, the columns they fall in are the *focus*: those fields are editable\n * and marked as selected, and the rest of the row is shown for context,\n * read-only.\n *\n * `RowEditor` knows nothing about the sheet's store: it takes rows, their edit\n * overlays, and an `onChange`, so a consumer can mount it beside a table, in a\n * dialog, or on a page where the table isn't rendered at all.\n * `SelectedRowEditor` binds it to a `DataSheetProvider`'s store — the selected\n * rows and columns, the edit overlay, the `editable` flag — and writes through\n * `onCellEdited`, so edits land in the same overlay and the same `onEdit`\n * stream as typing into the grid. It is drawn as a panel, titled with what it\n * is doing to how many of the sheet's items (\"Editing 3 samples\") in a bar\n * drawn as the toolbar's selection tag, whose ✕ clears the selection.\n *\n * Whether it is shown at all is the sheet's `rowEditorOpenAtom`, which the\n * toolbar's `ShowRowEditor` control toggles (add `showRowEditorAction` to a\n * sheet's `actions`), so the editor can be mounted wherever the layout wants\n * it and still be switched from the sheet.\n */\nimport hyper from \"@macrostrat/hyper\";\nimport classNames from \"classnames\";\nimport { Button, type IconName, NonIdealState } from \"@blueprintjs/core\";\nimport { atom } from \"jotai\";\nimport { type ReactNode, useMemo, useRef } from \"react\";\nimport { type Region, RegionCardinality } from \"@blueprintjs/table\";\nimport {\n type CellValidation,\n type ColumnSpec,\n ctx as sheetScope,\n itemLabelAtom,\n pluralize,\n selectionAtom,\n tableActionsAtom,\n useSelector,\n useStoreAPI,\n} from \"../provider\";\nimport {\n getSelectedColumnKeys,\n getSelectedRowIndices,\n getSelectionCardinality,\n} from \"../actions/selection.ts\";\nimport type { TableAction } from \"../actions\";\nimport {\n DataEditor,\n DataEditorField,\n DataEditorFields,\n DataEditorFrame,\n type DataEditorProps,\n type FieldSpec,\n} from \"./data-editor\";\nimport styles from \"./row-editor.module.sass\";\n\nconst h = hyper.styled(styles);\n\nexport interface RowEditorProps<T = any> {\n /** The columns to show, in order. Hidden columns are left out unless\n * `showHidden` is set; derived and locked columns show read-only. */\n columnSpec: ColumnSpec[];\n /** The row as loaded (the base values). One row; see `rows` for several. */\n row?: T | null;\n /** The pending edits to `row`, laid over it for display. A field present\n * here is marked as edited. */\n edits?: Partial<T> | null;\n /** Several rows at once (a multi-row selection). Takes precedence over\n * `row`. Each field then stands for that column across all of them. */\n rows?: T[];\n /** Edit overlays aligned with `rows`. */\n rowEdits?: (Partial<T> | null | undefined)[];\n /** The rows' data indices, aligned with `rows`, handed to `validate` and\n * `cellDetail`. */\n rowIndices?: number[];\n /** The columns the selection falls in, when it is a cell selection rather\n * than whole rows. Those fields are editable and marked; the others are\n * shown read-only for context. `null` means every writable field. */\n focusColumns?: string[] | null;\n /** Whether the form takes edits at all. Off, it is a row *viewer*. */\n editable?: boolean;\n /** A field was changed — for every row the form stands for. Absent, the\n * form is read-only. */\n onChange?: (columnKey: string, value: any) => void;\n /** A field was changed row by row: a value for each of the form's rows,\n * aligned with them (a `cellDetail`'s `onChangeCells`). */\n onChangeCells?: (columnKey: string, values: any[]) => void;\n /** The field to mark as active — the cell the sheet has selected, when the\n * selection came from the form — without narrowing what is editable. */\n activeColumn?: string | null;\n /** A field was clicked. */\n onFieldClick?: (columnKey: string) => void;\n /** Revert one field to its base value, in every row. Absent, edited fields\n * have no revert affordance. */\n onResetField?: (columnKey: string) => void;\n /** Also show the columns the spec hides (read-only). */\n showHidden?: boolean;\n /** Leave out fields with no value — a compact read-only view. Editable\n * fields always show, so there is somewhere to type. */\n hideEmpty?: boolean;\n /** Labels beside values rather than above them. */\n inline?: boolean;\n className?: string;\n /** Draw the form as a panel: bordered, with a title bar. */\n panel?: boolean;\n /** The panel's title (\"Editing 1 row\"). */\n title?: ReactNode;\n /** Close the panel — a ✕ at the end of the title bar. */\n onClose?: () => void;\n /** A label for the ✕ (\"Clear selection\"). */\n closeLabel?: string;\n /** Rendered above the fields. */\n header?: ReactNode;\n children?: ReactNode;\n}\n\n/** The form over one row or several, as the sheet's row editor draws it:\n * `DataEditorFields` in a `DataEditorFrame`, with the sheet's notions of a\n * focus (the columns a cell selection falls in) and an active field. */\nexport function RowEditor<T = any>(props: RowEditorProps<T>) {\n const {\n columnSpec,\n focusColumns = null,\n editable = true,\n onChange,\n onChangeCells,\n activeColumn = null,\n onFieldClick,\n onResetField,\n showHidden = false,\n hideEmpty = false,\n inline = false,\n className,\n panel = false,\n title,\n onClose,\n closeLabel,\n header,\n children,\n } = props;\n\n const { rows, rowEdits, rowIndices } = resolveRows(props);\n\n return h(DataEditorFrame, { className, panel, title, onClose, closeLabel }, [\n header,\n h(DataEditorFields<T>, {\n dataSpec: columnSpec,\n rows,\n rowEdits,\n rowIndices,\n surface: \"row-editor\",\n editable,\n onChange,\n onChangeCells,\n onResetField,\n focusFields: focusColumns,\n activeField: activeColumn,\n onFieldClick,\n showHidden,\n hideEmpty,\n inline,\n }),\n children,\n ]);\n}\n\n/** The row editor's frame: the data editor's. */\nexport const RowEditorFrame = DataEditorFrame;\n\n/** A row editor field: the data editor's. */\nexport const RowEditorField = DataEditorField;\n\n/** One row or several, as arrays either way. */\nfunction resolveRows<T>(props: RowEditorProps<T>): {\n rows: (T | null | undefined)[];\n rowEdits: (Partial<T> | null | undefined)[];\n rowIndices: number[];\n} {\n if (props.rows != null) {\n return {\n rows: props.rows,\n rowEdits: props.rowEdits ?? [],\n rowIndices: props.rowIndices ?? [],\n };\n }\n return {\n rows: [props.row],\n rowEdits: [props.edits],\n rowIndices: props.rowIndices ?? [],\n };\n}\n\n/* ---------------------------------------------------------- store-bound */\n\nexport interface SelectedRows<T = any> {\n /** Data indices of the selected rows; empty when nothing is selected. */\n rowIndices: number[];\n rows: (T | null | undefined)[];\n edits: (Partial<T> | null | undefined)[];\n /** The columns a cell selection falls in; `null` for whole rows (or the\n * whole table), when every column is in play. */\n columnKeys: string[] | null;\n cardinality: RegionCardinality | null;\n /** Whether any selected row is marked deleted. */\n anyDeleted: boolean;\n}\n\n/** The rows the sheet's selection addresses, with their edit overlays and the\n * columns the selection falls in. Must be read inside a\n * `DataSheetProvider`. */\nexport function useSelectedRows<T = any>(): SelectedRows<T> {\n const selection = useSelector((s) => s.selection);\n const data = useSelector((s) => s.data);\n const updatedData = useSelector((s) => s.updatedData);\n const rowStatus = useSelector((s) => s.rowStatus);\n const columnSpec = useSelector((s) => s.columnSpec);\n const filteredRowIndices = useSelector((s) => s.filteredRowIndices);\n\n return useMemo(() => {\n const regions = selection ?? [];\n const rowIndices = getSelectedRowIndices(regions, filteredRowIndices);\n const cardinality = getSelectionCardinality(regions) ?? null;\n let columnKeys: string[] | null = null;\n if (cardinality === RegionCardinality.CELLS) {\n columnKeys = getSelectedColumnKeys(regions, columnSpec);\n }\n return {\n rowIndices,\n rows: rowIndices.map((i) => data?.[i] as T | null | undefined),\n edits: rowIndices.map((i) => updatedData?.[i] as Partial<T> | undefined),\n columnKeys,\n cardinality,\n anyDeleted: rowIndices.some((i) => rowStatus?.[i] === \"deleted\"),\n };\n }, [selection, data, updatedData, rowStatus, columnSpec, filteredRowIndices]);\n}\n\nexport interface SelectedRow<T = any> {\n rowIndex: number | null;\n row: T | null;\n edits: Partial<T> | null;\n isDeleted: boolean;\n}\n\n/** The first selected row alone — the single-row view of `useSelectedRows`. */\nexport function useSelectedRow<T = any>(): SelectedRow<T> {\n const { rowIndices, rows, edits, anyDeleted } = useSelectedRows<T>();\n if (rowIndices.length === 0) {\n return { rowIndex: null, row: null, edits: null, isDeleted: false };\n }\n return {\n rowIndex: rowIndices[0],\n row: rows[0] ?? null,\n edits: edits[0] ?? null,\n isDeleted: anyDeleted,\n };\n}\n\nexport interface SelectedRowEditorProps extends Omit<\n RowEditorProps,\n | \"columnSpec\"\n | \"row\"\n | \"edits\"\n | \"rows\"\n | \"rowEdits\"\n | \"rowIndices\"\n | \"focusColumns\"\n | \"onChange\"\n | \"onResetField\"\n> {\n /** Shown when no row is selected. Defaults to a `NonIdealState` saying so\n * (\"No units selected\"). */\n emptyState?: ReactNode;\n /** Shown above the fields over a multi-row selection; the default says a\n * change applies to all of them. Pass `null` for nothing. */\n selectionSummary?: ((count: number) => ReactNode) | null;\n /** Whether the panel's ✕ clears the selection (default). */\n closeable?: boolean;\n /** Follow the sheet's `rowEditorOpenAtom`, rendering nothing while it is\n * off (default). */\n toggleable?: boolean;\n}\n\n/**\n * The row editor bound to the enclosing sheet's store: it follows the\n * selected rows and the columns a cell selection falls in, and writes through\n * the store's `onCellEdited` for every selected row, so an edit made here is\n * the same edit as one typed into the grid — same overlay, same `onEdit`\n * events, same reset. Render it anywhere under the `DataSheetProvider` (the\n * `DataSheet`'s children, a sibling panel, or a page where the grid itself is\n * not mounted).\n */\nexport function SelectedRowEditor(props: SelectedRowEditorProps) {\n const {\n emptyState,\n selectionSummary,\n closeable = true,\n toggleable = true,\n panel = true,\n editable,\n header,\n ...rest\n } = props;\n const store = useStoreAPI();\n const columnSpec = useSelector((s) => s.columnSpec);\n const tableEditable = useSelector((s) => s.editable);\n const itemLabel = sheetScope.useValue(itemLabelAtom);\n // Not the store's `clearSelection`, which clears the selected cells' values\n const setSelection = sheetScope.useSet(selectionAtom);\n const open = sheetScope.useValue(rowEditorOpenAtom);\n const selection = useSelector((s) => s.selection);\n const filteredRowIndices = useSelector((s) => s.filteredRowIndices);\n const { rowIndices, rows, edits, columnKeys, anyDeleted } = useSelectedRows();\n const count = rowIndices.length;\n // A click on a field selects its cells in the sheet. That selection is the\n // form's own: it marks the field without narrowing the form to it, as a\n // cell selection made in the grid would.\n const formSelection = useRef<{ regions: Region[]; key: string } | null>(null);\n let activeColumn: string | null = null;\n let focusColumns = columnKeys;\n const own = formSelection.current;\n if (own != null && sameRegions(own.regions, selection ?? [])) {\n activeColumn = own.key;\n focusColumns = null;\n }\n const items = `${count} ${pluralize(itemLabel, count)}`;\n\n if (toggleable && !open) return null;\n\n if (count === 0) {\n let empty = emptyState;\n if (empty === undefined) {\n empty = h(NonIdealState, {\n title: `No ${pluralize(itemLabel, 0)} selected`,\n className: \"row-editor-non-ideal\",\n });\n }\n return h(RowEditorFrame, { panel, className: \"row-editor-empty\" }, empty);\n }\n\n const canEdit = (editable ?? true) && tableEditable && !anyDeleted;\n let title = `Viewing ${items}`;\n if (canEdit) title = `Editing ${items}`;\n\n let onClose: (() => void) | undefined;\n if (closeable) onClose = () => setSelection([]);\n\n const onChange = (columnKey: string, value: any) => {\n const { onCellEdited } = store.getState();\n for (const rowIndex of rowIndices) onCellEdited(rowIndex, columnKey, value);\n };\n // Reverting a field is writing its loaded value back: the store drops an\n // override equal to the base, and a controlled consumer sees an ordinary\n // `setCells` rather than a whole-table reset.\n const onResetField = (columnKey: string) => {\n const { onCellEdited } = store.getState();\n rowIndices.forEach((rowIndex, i) => {\n const base = rows[i];\n if (base == null) return;\n onCellEdited(rowIndex, columnKey, base[columnKey]);\n });\n };\n\n const onChangeCells = (columnKey: string, values: any[]) => {\n const { onCellEdited } = store.getState();\n rowIndices.forEach((rowIndex, i) => {\n onCellEdited(rowIndex, columnKey, values[i]);\n });\n };\n\n const onFieldClick = (columnKey: string) => {\n if (activeColumn === columnKey) return;\n const regions = cellRegions(\n rowIndices,\n columnSpec.findIndex((c) => c.key === columnKey),\n filteredRowIndices,\n );\n if (regions.length === 0) return;\n formSelection.current = { regions, key: columnKey };\n const state = store.getState();\n // Selecting from the form opens nothing over the grid\n store.setState({ cellSurfaceOpen: false });\n state.setSelection(regions);\n };\n\n let summary: ReactNode = null;\n if (count > 1 && canEdit && selectionSummary !== null) {\n let text: ReactNode = `A change here applies to all ${items}.`;\n if (selectionSummary != null) text = selectionSummary(count);\n summary = h(\"div.selection-summary\", text);\n }\n\n return h(RowEditor, {\n ...rest,\n columnSpec,\n rows,\n rowEdits: edits,\n rowIndices,\n focusColumns,\n activeColumn,\n onFieldClick,\n panel,\n title,\n onClose,\n closeLabel: \"Clear selection\",\n header: h([header, summary]),\n editable: canEdit,\n onChange,\n onChangeCells,\n onResetField,\n });\n}\n\n/** One column's cells in the given rows, as the table's regions: the rows'\n * places in the view (under any filter), one region per run of adjacent\n * rows. */\nfunction cellRegions(\n rowIndices: number[],\n colIndex: number,\n filteredRowIndices: number[] | null | undefined,\n): Region[] {\n if (colIndex < 0) return [];\n const visible = rowIndices\n .map((i) => {\n if (filteredRowIndices == null) return i;\n return filteredRowIndices.indexOf(i);\n })\n .filter((i) => i >= 0)\n .sort((a, b) => a - b);\n const regions: Region[] = [];\n for (const row of visible) {\n const last = regions[regions.length - 1];\n if (last != null && last.rows![1] === row - 1) {\n last.rows = [last.rows![0], row];\n continue;\n }\n regions.push({ rows: [row, row], cols: [colIndex, colIndex] });\n }\n return regions;\n}\n\nfunction sameRegions(a: Region[], b: Region[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((r, i) => {\n const s = b[i];\n return (\n r.rows?.[0] === s.rows?.[0] &&\n r.rows?.[1] === s.rows?.[1] &&\n r.cols?.[0] === s.cols?.[0] &&\n r.cols?.[1] === s.cols?.[1]\n );\n });\n}\n\n/* -------------------------------------------------- selected data editor */\n\nexport interface SelectedDataEditorProps<T = any> extends Omit<\n DataEditorProps<T>,\n \"dataSpec\" | \"data\" | \"onSave\"\n> {\n /** The fields; defaults to the sheet's column spec. */\n dataSpec?: FieldSpec[];\n /** Persist the edited record. Defaults to the sheet's provider\n * (`rowEditing.saveRows`), which refreshes the rows after. Without either,\n * the editor is a viewer. */\n onSave?: DataEditorProps<T>[\"onSave\"];\n /** Whether the ✕ in the title bar clears the selection (default). */\n closeable?: boolean;\n /** Show the sheet's actions, scoped to the record and its fields (off by\n * default: the sheet's toolbar carries them). */\n showActions?: boolean;\n}\n\n/**\n * A `DataEditor` over the one row a sheet's or panel's selection holds: the\n * immediate-edit counterpart of `SelectedRowEditor`, for a view (a `DataPanel`\n * card list) whose edits are saved one record at a time rather than\n * accumulated in the sheet's overlay. It keeps its own pending edits, and\n * Save writes the record through the provider. Several rows selected, or\n * none, it says so.\n */\nexport function SelectedDataEditor<T = any>(props: SelectedDataEditorProps<T>) {\n const {\n dataSpec,\n onSave,\n closeable = true,\n showActions = false,\n panel = true,\n title,\n editable,\n ...rest\n } = props;\n const store = useStoreAPI();\n const columnSpec = useSelector((s) => s.columnSpec);\n const saveRows = useSelector((s) => s.rowEditing?.saveRows);\n const tableActions = sheetScope.useValue(\n tableActionsAtom,\n ) as TableAction<T>[];\n const itemLabel = sheetScope.useValue(itemLabelAtom);\n const setSelection = sheetScope.useSet(selectionAtom);\n const { rows } = useSelectedRows<T>();\n const count = rows.length;\n\n if (count !== 1 || rows[0] == null) {\n let noun = pluralize(itemLabel, count);\n let stateTitle = `${count} ${noun} selected`;\n if (count === 0) stateTitle = `No ${noun} selected`;\n return h(\n RowEditorFrame,\n { panel, className: \"row-editor-empty\" },\n h(NonIdealState, {\n title: stateTitle,\n className: \"row-editor-non-ideal\",\n }),\n );\n }\n\n let save = onSave;\n if (save == null && saveRows != null) {\n save = async (value: T) => {\n await saveRows([value]);\n };\n }\n const canEdit = (editable ?? true) && save != null;\n let heading = title;\n if (heading == null) {\n heading = `Viewing 1 ${itemLabel}`;\n if (canEdit) heading = `Editing 1 ${itemLabel}`;\n }\n let onClose: (() => void) | undefined;\n if (closeable) onClose = () => setSelection([]);\n\n return h(DataEditor<T>, {\n ...rest,\n dataSpec: dataSpec ?? columnSpec,\n data: rows[0] as T,\n onSave: save,\n editable: canEdit,\n panel,\n title: heading,\n onClose,\n closeLabel: \"Clear selection\",\n actions: tableActions,\n showActions,\n });\n}\n\n/* ------------------------------------------------------------ the toggle */\n\n/** Whether the sheet's row editor is shown. Scoped to the sheet, like the\n * rest of its state; `SelectedRowEditor` follows it unless `toggleable` is\n * off. */\nexport const rowEditorOpenAtom = atom(true);\n\n/** The row editor's open state, and a setter. */\nexport function useRowEditorOpen(): [boolean, (open: boolean) => void] {\n const open = sheetScope.useValue(rowEditorOpenAtom);\n const setOpen = sheetScope.useSet(rowEditorOpenAtom);\n return [open, setOpen];\n}\n\n/** A toolbar toggle for the row editor, wherever it is mounted. */\nexport function ShowRowEditor({\n label = \"Row editor\",\n icon = \"properties\",\n}: {\n label?: string;\n icon?: IconName;\n}) {\n const [open, setOpen] = useRowEditorOpen();\n let title = \"Show the row editor\";\n if (open) title = \"Hide the row editor\";\n return h(Button, {\n minimal: true,\n small: true,\n icon,\n active: open,\n text: label,\n title,\n \"aria-pressed\": open,\n onClick: () => setOpen(!open),\n });\n}\n\n/** `ShowRowEditor` as a sheet action: add it to `actions` and the toggle sits\n * at the toolbar's right end, whatever is selected, editable or not. */\nexport const showRowEditorAction: TableAction = {\n id: \"show-row-editor\",\n name: \"Row editor\",\n icon: \"properties\",\n targets: [\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n RegionCardinality.FULL_TABLE,\n ],\n requiresEditable: false,\n placement: \"end\",\n render: () => h(ShowRowEditor),\n};\n\nexport type { CellValidation };\n"],"names":["hyper","styles","sheetScope"],"mappings":";;;;;;;;;;AA0EA,MAAM,IAAIA,IAAM,OAAOC,GAAM;AA+DtB,SAAS,UAAmB,OAA0B;AAC3D,QAAM;AAAA,IACJ;AAAA,IACA,eAAe;AAAA,IACf,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,SAAS;AAAA,IACT;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AAEJ,QAAM,EAAE,MAAM,UAAU,WAAA,IAAe,YAAY,KAAK;AAExD,SAAO,EAAE,iBAAiB,EAAE,WAAW,OAAO,OAAO,SAAS,cAAc;AAAA,IAC1E;AAAA,IACA,EAAE,kBAAqB;AAAA,MACrB,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb,aAAa;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,IACD;AAAA,EAAA,CACD;AACH;AAGO,MAAM,iBAAiB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;AAAA,IAClB,kBAAkB;AAAA,EAAA;AAAA,EAEpB,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,QAAQ,MAAM,EAAE,aAAa;AAC/B;"}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
+ const h$1 = require("@macrostrat/hyper");
4
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
5
+ const h__default = /* @__PURE__ */ _interopDefault(h$1);
6
+ const panel = "_panel_kma62_39";
7
+ const edited = "_edited_kma62_87";
8
+ const derived = "_derived_kma62_90";
9
+ const inline = "_inline_kma62_98";
10
+ const empty = "_empty_kma62_139";
11
+ const selected = "_selected_kma62_151";
12
+ const styles = {
13
+ "row-editor": "_row-editor_kma62_1",
14
+ "field-actions": "_field-actions_kma62_8",
15
+ "editor-action-form": "_editor-action-form_kma62_19",
16
+ "data-editor-footer": "_data-editor-footer_kma62_27",
17
+ "data-editor-footer-spacer": "_data-editor-footer-spacer_kma62_35",
18
+ panel,
19
+ "row-editor-body": "_row-editor-body_kma62_44",
20
+ "row-editor-title-bar": "_row-editor-title-bar_kma62_65",
21
+ "row-editor-fields": "_row-editor-fields_kma62_74",
22
+ "row-editor-field": "_row-editor-field_kma62_74",
23
+ edited,
24
+ "field-name": "_field-name_kma62_87",
25
+ derived,
26
+ "field-value": "_field-value_kma62_90",
27
+ "read-only": "_read-only_kma62_94",
28
+ inline,
29
+ "field-label": "_field-label_kma62_102",
30
+ "field-marker": "_field-marker_kma62_115",
31
+ "required-marker": "_required-marker_kma62_122",
32
+ "reset-field": "_reset-field_kma62_126",
33
+ empty,
34
+ "field-surface": "_field-surface_kma62_143",
35
+ "cell-detail": "_cell-detail_kma62_143",
36
+ "row-editor-non-ideal": "_row-editor-non-ideal_kma62_147",
37
+ selected,
38
+ "mixed-values": "_mixed-values_kma62_163",
39
+ "selection-summary": "_selection-summary_kma62_168",
40
+ "row-editor-field-target": "_row-editor-field-target_kma62_174"
41
+ };
42
+ let h = h__default.default.styled(styles);
43
+ Object.assign(h, styles);
44
+ exports.default = h;
45
+ exports.derived = derived;
46
+ exports.edited = edited;
47
+ exports.empty = empty;
48
+ exports.inline = inline;
49
+ exports.panel = panel;
50
+ exports.selected = selected;
51
+ //# sourceMappingURL=row-editor.module.sass.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"row-editor.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}