@macrostrat/data-sheet 4.8.0 → 4.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -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 +6 -1
- package/dist/provider/types.js.map +1 -1
- package/dist/provider/zustand-store.cjs +55 -33
- package/dist/provider/zustand-store.cjs.map +1 -1
- package/dist/provider/zustand-store.js +44 -22
- 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 +6 -1
- package/src/provider/zustand-store.ts +78 -26
- package/src/renderers/cell-renderer.ts +18 -3
- package/src/renderers/column-header-cell.ts +10 -0
- package/src/types.ts +5 -1
package/dist/index.js
CHANGED
|
@@ -14,12 +14,15 @@ import { CellRendererDebugOverlay } from "./utils/debug-overlay.js";
|
|
|
14
14
|
import { ColorCell, ColorPicker, colorSwatchRenderer } from "./components/colors.js";
|
|
15
15
|
import { ColumnFilterControl, ColumnFilterForm, ColumnFilterMenu, ColumnFilterMenuItem, ColumnSortIndicator, ColumnSortMenu, FilterIndicator, InlineFilterControl, MenuDropdown, MenuFormItem, MenuInlineFilterItem, resolveColumnFilter } from "./components/indicators/filter-and-sort.js";
|
|
16
16
|
import { DEFAULT_ROW_STATUS_STYLES, DS_ROW_ID, TableElementStatus } from "./provider/types.js";
|
|
17
|
-
import {
|
|
17
|
+
import { DataEditor, DataEditorField, DataEditorFields, DataEditorFrame, FieldValue, MixedValues, sharedValue, valueToken } from "./components/data-editor.js";
|
|
18
|
+
import { DataSheetProvider, DataSheetProviderInner, capitalize, columnSpecAtom, ctx, dataProviderAtom, itemLabelAtom, pluralFormOf, pluralize, splitDataProviderProps, storeAPIAtom, storeAtom, tableActionsAtom, tableDataAtom, tableNameAtom, useItemCount, useResolvedProvider, useSelector, useStoreAPI } from "./provider/core.js";
|
|
18
19
|
import { DataViewRendererType, SelectionInteractionStyle, dragValueHandlerAtom, enableDragValueAtom, enableSelectionAtom, interactionOptionsAtom, interactionOptionsKeys, resolveInteractionOptions, selectionModeActiveAtom } from "./provider/interactions.js";
|
|
19
20
|
import { EditableTextArea } from "./components/text-areas.js";
|
|
21
|
+
import { EditorActionButton, editorActionContext, editorActionsFor } from "./components/editor-actions.js";
|
|
20
22
|
import { EditorPopup } from "./components/editor-popup.js";
|
|
21
23
|
import { LoadProgressIndicator, LoadProgressLabel } from "./components/indicators/view-info.js";
|
|
22
24
|
import { PasteShape, clipboardActions, copyAction, cutAction, pasteAction, serializeSelectionToTSV } from "./actions/clipboard.js";
|
|
25
|
+
import { RowEditor, RowEditorField, RowEditorFrame, SelectedDataEditor, SelectedRowEditor, ShowRowEditor, rowEditorOpenAtom, showRowEditorAction, useRowEditorOpen, useSelectedRow, useSelectedRows } from "./components/row-editor.js";
|
|
23
26
|
import { SelectionIndicator, toggleModalSelectionAtom } from "./components/indicators/selection.js";
|
|
24
27
|
import { addRowAction, defaultTableActions, deleteRowsAction, resetChangesAction } from "./actions/builtin.js";
|
|
25
28
|
import { anchorRefAtom, selectionAtom } from "./provider/selection.js";
|
|
@@ -32,7 +35,7 @@ import { columnControlActions, columnFilterAction, columnSortAction, isColumnFil
|
|
|
32
35
|
import { compareRowsBySorts, createLocalProvider, dataRefreshTokenAtom, distinctValuesOf, persistViaProvider, rowsAfter } from "./provider/table-data.js";
|
|
33
36
|
import { createZustandStore, singleFocusedCell, topLeftCell, updateSelection } from "./provider/zustand-store.js";
|
|
34
37
|
import { editorKeyHandlerAtom, multiLineTextKeyHandler, tableHotkeysAtom } from "./utils/key-handling.js";
|
|
35
|
-
import { generateColumnSpec, generateDefaultColumnSpec, postprocessColumnSpec } from "./provider/column-spec.js";
|
|
38
|
+
import { generateColumnSpec, generateDefaultColumnSpec, isColumnWritable, postprocessColumnSpec } from "./provider/column-spec.js";
|
|
36
39
|
import { passThroughGet, passThroughSet, splitProps } from "./utils/atoms.js";
|
|
37
40
|
import { scrollToRowAction } from "./actions/table-actions.js";
|
|
38
41
|
import { useDataPanelControls } from "./components/indicators/unified-filters.js";
|
|
@@ -56,6 +59,10 @@ export {
|
|
|
56
59
|
DEFAULT_ROW_STATUS_STYLES,
|
|
57
60
|
DS_ROW_ID,
|
|
58
61
|
DataCard,
|
|
62
|
+
DataEditor,
|
|
63
|
+
DataEditorField,
|
|
64
|
+
DataEditorFields,
|
|
65
|
+
DataEditorFrame,
|
|
59
66
|
DataPanel,
|
|
60
67
|
DataPanelRenderer,
|
|
61
68
|
DataPanelToolbarStyle,
|
|
@@ -67,8 +74,10 @@ export {
|
|
|
67
74
|
DataView,
|
|
68
75
|
DataViewRendererType,
|
|
69
76
|
EditableTextArea,
|
|
77
|
+
EditorActionButton,
|
|
70
78
|
EditorPopup,
|
|
71
79
|
ExpandedLithologies,
|
|
80
|
+
FieldValue,
|
|
72
81
|
FilterIndicator,
|
|
73
82
|
InlineFilterControl,
|
|
74
83
|
IntervalCell,
|
|
@@ -79,12 +88,19 @@ export {
|
|
|
79
88
|
MenuDropdown,
|
|
80
89
|
MenuFormItem,
|
|
81
90
|
MenuInlineFilterItem,
|
|
91
|
+
MixedValues,
|
|
82
92
|
OPERATOR_LABELS,
|
|
83
93
|
PasteShape,
|
|
84
94
|
PostgRESTTableView,
|
|
95
|
+
RowEditor,
|
|
96
|
+
RowEditorField,
|
|
97
|
+
RowEditorFrame,
|
|
85
98
|
SearchAction,
|
|
99
|
+
SelectedDataEditor,
|
|
100
|
+
SelectedRowEditor,
|
|
86
101
|
SelectionIndicator,
|
|
87
102
|
SelectionInteractionStyle,
|
|
103
|
+
ShowRowEditor,
|
|
88
104
|
TableElementStatus,
|
|
89
105
|
addRowAction,
|
|
90
106
|
anchorRefAtom,
|
|
@@ -122,6 +138,8 @@ export {
|
|
|
122
138
|
deleteRowsAction,
|
|
123
139
|
distinctValuesOf,
|
|
124
140
|
dragValueHandlerAtom,
|
|
141
|
+
editorActionContext,
|
|
142
|
+
editorActionsFor,
|
|
125
143
|
editorKeyHandlerAtom,
|
|
126
144
|
enableDragValueAtom,
|
|
127
145
|
enableSelectionAtom,
|
|
@@ -138,6 +156,7 @@ export {
|
|
|
138
156
|
interactionOptionsAtom,
|
|
139
157
|
interactionOptionsKeys,
|
|
140
158
|
isColumnFilterable,
|
|
159
|
+
isColumnWritable,
|
|
141
160
|
itemLabelAtom,
|
|
142
161
|
lithologyRenderer,
|
|
143
162
|
mergeColumnActions,
|
|
@@ -147,6 +166,7 @@ export {
|
|
|
147
166
|
passThroughSet,
|
|
148
167
|
pasteAction,
|
|
149
168
|
persistViaProvider,
|
|
169
|
+
pluralFormOf,
|
|
150
170
|
pluralize,
|
|
151
171
|
postprocessColumnSpec,
|
|
152
172
|
range,
|
|
@@ -154,6 +174,7 @@ export {
|
|
|
154
174
|
resolveColumnFilter,
|
|
155
175
|
resolveInteractionOptions,
|
|
156
176
|
resumeBaselineAtom,
|
|
177
|
+
rowEditorOpenAtom,
|
|
157
178
|
rowIndicesToRegions,
|
|
158
179
|
rowsAfter,
|
|
159
180
|
runActionWrapper,
|
|
@@ -161,6 +182,8 @@ export {
|
|
|
161
182
|
selectionAtom,
|
|
162
183
|
selectionModeActiveAtom,
|
|
163
184
|
serializeSelectionToTSV,
|
|
185
|
+
sharedValue,
|
|
186
|
+
showRowEditorAction,
|
|
164
187
|
singleFocusedCell,
|
|
165
188
|
splitDataProviderProps,
|
|
166
189
|
splitProps,
|
|
@@ -183,10 +206,14 @@ export {
|
|
|
183
206
|
useItemCount,
|
|
184
207
|
useLoadControls,
|
|
185
208
|
useResolvedProvider,
|
|
209
|
+
useRowEditorOpen,
|
|
186
210
|
useScrollHandler,
|
|
211
|
+
useSelectedRow,
|
|
212
|
+
useSelectedRows,
|
|
187
213
|
useSelector,
|
|
188
214
|
useStoreAPI,
|
|
189
215
|
validateCell,
|
|
216
|
+
valueToken,
|
|
190
217
|
viewInfoAtom,
|
|
191
218
|
wrapWithErrorHandling
|
|
192
219
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,21 +3,22 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
3
3
|
const h$1 = require("@macrostrat/hyper");
|
|
4
4
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
5
5
|
const h__default = /* @__PURE__ */ _interopDefault(h$1);
|
|
6
|
-
const spacer = "
|
|
6
|
+
const spacer = "_spacer_1xwuq_116";
|
|
7
7
|
const styles = {
|
|
8
|
-
"data-sheet-container": "_data-sheet-
|
|
9
|
-
"data-sheet-holder": "_data-sheet-
|
|
10
|
-
"data-sheet": "_data-
|
|
11
|
-
"input-cell": "_input-
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
8
|
+
"data-sheet-container": "_data-sheet-container_1xwuq_1",
|
|
9
|
+
"data-sheet-holder": "_data-sheet-holder_1xwuq_1",
|
|
10
|
+
"data-sheet": "_data-sheet_1xwuq_1",
|
|
11
|
+
"input-cell": "_input-cell_1xwuq_45",
|
|
12
|
+
"derived-cell": "_derived-cell_1xwuq_62",
|
|
13
|
+
"value-viewer-cell": "_value-viewer-cell_1xwuq_67",
|
|
14
|
+
"editor-cell": "_editor-cell_1xwuq_75",
|
|
15
|
+
"hidden-input": "_hidden-input_1xwuq_87",
|
|
16
|
+
"data-editor-anchor": "_data-editor-anchor_1xwuq_93",
|
|
17
|
+
"corner-drag-handle": "_corner-drag-handle_1xwuq_100",
|
|
18
|
+
"data-sheet-toolbar": "_data-sheet-toolbar_1xwuq_110",
|
|
18
19
|
spacer,
|
|
19
|
-
"table-control": "_table-
|
|
20
|
-
"status-bar": "_status-
|
|
20
|
+
"table-control": "_table-control_1xwuq_120",
|
|
21
|
+
"status-bar": "_status-bar_1xwuq_126"
|
|
21
22
|
};
|
|
22
23
|
let h = h__default.default.styled(styles);
|
|
23
24
|
Object.assign(h, styles);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.module.sass.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/main.module.sass.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import h$1 from "@macrostrat/hyper";
|
|
2
|
-
const spacer = "
|
|
2
|
+
const spacer = "_spacer_1xwuq_116";
|
|
3
3
|
const styles = {
|
|
4
|
-
"data-sheet-container": "_data-sheet-
|
|
5
|
-
"data-sheet-holder": "_data-sheet-
|
|
6
|
-
"data-sheet": "_data-
|
|
7
|
-
"input-cell": "_input-
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
4
|
+
"data-sheet-container": "_data-sheet-container_1xwuq_1",
|
|
5
|
+
"data-sheet-holder": "_data-sheet-holder_1xwuq_1",
|
|
6
|
+
"data-sheet": "_data-sheet_1xwuq_1",
|
|
7
|
+
"input-cell": "_input-cell_1xwuq_45",
|
|
8
|
+
"derived-cell": "_derived-cell_1xwuq_62",
|
|
9
|
+
"value-viewer-cell": "_value-viewer-cell_1xwuq_67",
|
|
10
|
+
"editor-cell": "_editor-cell_1xwuq_75",
|
|
11
|
+
"hidden-input": "_hidden-input_1xwuq_87",
|
|
12
|
+
"data-editor-anchor": "_data-editor-anchor_1xwuq_93",
|
|
13
|
+
"corner-drag-handle": "_corner-drag-handle_1xwuq_100",
|
|
14
|
+
"data-sheet-toolbar": "_data-sheet-toolbar_1xwuq_110",
|
|
14
15
|
spacer,
|
|
15
|
-
"table-control": "_table-
|
|
16
|
-
"status-bar": "_status-
|
|
16
|
+
"table-control": "_table-control_1xwuq_120",
|
|
17
|
+
"status-bar": "_status-bar_1xwuq_126"
|
|
17
18
|
};
|
|
18
19
|
let h = h$1.styled(styles);
|
|
19
20
|
Object.assign(h, styles);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.module.sass.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -105,7 +105,7 @@ function generateColumnSpec(data, options = {}) {
|
|
|
105
105
|
return postprocessColumnSpec(improvedSpec);
|
|
106
106
|
}
|
|
107
107
|
function postprocessColumnSpec(columnSpec) {
|
|
108
|
-
return columnSpec.map((col) => {
|
|
108
|
+
return columnSpec.filter((col) => !col.hidden).map((col) => {
|
|
109
109
|
return {
|
|
110
110
|
...col,
|
|
111
111
|
filters: postprocessColumnFilters(col),
|
|
@@ -113,6 +113,12 @@ function postprocessColumnSpec(columnSpec) {
|
|
|
113
113
|
};
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
+
function isColumnWritable(col, tableEditable = true) {
|
|
117
|
+
if (col == null) return false;
|
|
118
|
+
if (!tableEditable) return false;
|
|
119
|
+
if (col.derived) return false;
|
|
120
|
+
return col.editable !== false;
|
|
121
|
+
}
|
|
116
122
|
function postprocessColumnFilters(col) {
|
|
117
123
|
const { filterable = true, filters = [] } = col;
|
|
118
124
|
if (!filterable) {
|
|
@@ -122,5 +128,6 @@ function postprocessColumnFilters(col) {
|
|
|
122
128
|
}
|
|
123
129
|
exports.generateColumnSpec = generateColumnSpec;
|
|
124
130
|
exports.generateDefaultColumnSpec = generateDefaultColumnSpec;
|
|
131
|
+
exports.isColumnWritable = isColumnWritable;
|
|
125
132
|
exports.postprocessColumnSpec = postprocessColumnSpec;
|
|
126
133
|
//# sourceMappingURL=column-spec.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.cjs","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc.\n */\n return columnSpec.map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":["enhanceColumnFilter"],"mappings":";;;AAGA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAyKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AA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C3C;AAEO,SAAS,sBAAsB,YAA0B;AAI9D,SAAO,WAAW,IAAI,CAAC,QAAQ;AAC7B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,yBAAyB,GAAG;AAAA,MACrC,SAAS,IAAI,WAAW,CAAA;AAAA,IAAC;AAAA,EAE7B,CAAC;AACH;AAEA,SAAS,yBAAyB,KAA4C;AAC5E,QAAM,EAAE,aAAa,MAAM,UAAU,CAAA,MAAO;AAC5C,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI,CAAC,MAAMA,aAAAA,oBAAoB,KAAK,CAAC,CAAC;AACvD;;;;"}
|
|
1
|
+
{"version":3,"file":"column-spec.cjs","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport type { Placement } from \"@blueprintjs/core\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n \"text\" | \"string\" | \"number\" | \"integer\" | \"boolean\" | \"object\" | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /**\n * When the surface stands for several cells at once (the row editor over a\n * multi-row selection), the cells it stands for. `value` is then the value\n * they share, or `undefined` when they differ (`mixed`), and `onChange`\n * writes every one of them. Only offered to a column that declares\n * `multiCell`; absent for a single cell.\n */\n cells?: CellSelectionEntry<T>[];\n /** True when `cells` hold differing values. */\n mixed?: boolean;\n /** Where the surface is drawn: `\"cell\"`, the grid's own popover, modal or\n * in-cell surface; `\"row-editor\"`, a field of the sheet's row editor; or\n * `\"editor\"`, a field of a standalone `DataEditor` — so a surface can lay\n * itself out to suit (a picker nesting its own popovers only where it has\n * room). */\n surface?: \"cell\" | \"row-editor\" | \"editor\";\n /** Commit a new value for this cell — for every cell, when the surface\n * stands for several. */\n onChange: (value: any) => void;\n /** With `cells`, commit a value for each cell, aligned with them — for a\n * surface that changes each cell's own value (adding a tag to every row's\n * list) rather than setting them all to one. */\n onChangeCells?: (values: any[]) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** One of the cells a multi-cell surface stands for. */\nexport interface CellSelectionEntry<T = any> {\n rowIndex: number;\n row: T | null | undefined;\n value: any;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /**\n * Whether this column's `cellDetail` can stand for several cells at once —\n * read the shared value (or `ctx.mixed`) and write every cell in\n * `ctx.cells` through one `onChange`. A surface that doesn't declare this\n * is shown read-only over a multi-row selection, with \"Multiple values\"\n * where they differ. The default editors (an input by `dataType`) always\n * can, since setting one value on every cell is what they do.\n */\n multiCell?: boolean;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n /** What one cell of the column is called, for the selection indicator\n * (\"1 lithology\", \"3 lithologies\"). Defaults to the column's name. */\n cellLabel?: string;\n /** Where a popover `cellDetail` opens against its cell. Defaults to\n * `\"right-start\"`; a wide surface (a tag picker) reads better below, at\n * `\"bottom-start\"`. */\n detailPlacement?: Placement;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n /**\n * A **derived** column holds values computed from other data — a total, an\n * age that follows from an interval and a proportion — rather than values\n * anyone types. It is never writable, whatever `editable` or the table\n * says, and every write path (inline editing, fill, paste, the row editor)\n * leaves it alone; it is drawn dimmed so a reader can tell what is a record\n * and what is a restatement of one. Use it instead of `editable: false` when\n * the read-only-ness is a property of the *data* rather than of the view.\n */\n derived?: boolean;\n /**\n * A **hidden** column stays in the spec but is left out of the working\n * spec the table is built from: it isn't rendered, isn't part of a\n * selection, and isn't written by a fill or a paste. A consumer keeps one\n * spec and toggles this flag (\"show absolute ages\", \"show generated ids\")\n * rather than maintaining two arrays. Resolved by `postprocessColumnSpec`.\n */\n hidden?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc. Hidden columns are dropped here, so everything\n * downstream — the renderer, the selection, the edit paths — works with the\n * visible columns only and indexes into one array.\n */\n return columnSpec\n .filter((col) => !col.hidden)\n .map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\n/**\n * Whether a column takes writes at all: the table is editable, the column\n * isn't locked (`editable: false`) and it isn't `derived`. This is the one\n * rule every write path consults — the inline editor, `onSelectionEdited`,\n * fill, clear, clipboard paste and the row editor — so a locked column is\n * locked however the edit arrives, not only when it is typed into.\n */\nexport function isColumnWritable(\n col: ColumnSpec | null | undefined,\n tableEditable: boolean = true,\n): boolean {\n if (col == null) return false;\n if (!tableEditable) return false;\n if (col.derived) return false;\n return col.editable !== false;\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":["enhanceColumnFilter"],"mappings":";;;AAIA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAiOpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,Q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EACtB,CAAC;AACD,SAAO,sBAAsB,YAAY;AAC3C;AAEO,SAAS,sBAAsB,YAA0B;AAM9D,SAAO,WACJ,OAAO,CAAC,QAAQ,CAAC,IAAI,MAAM,EAC3B,IAAI,CAAC,QAAQ;AACZ,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,yBAAyB,GAAG;AAAA,MACrC,SAAS,IAAI,WAAW,CAAA;AAAA,IAAC;AAAA,EAE7B,CAAC;AACL;AASO,SAAS,iBACd,KACA,gBAAyB,MAChB;AACT,MAAI,OAAO,KAAM,QAAO;AACxB,MAAI,CAAC,cAAe,QAAO;AAC3B,MAAI,IAAI,QAAS,QAAO;AACxB,SAAO,IAAI,aAAa;AAC1B;AAEA,SAAS,yBAAyB,KAA4C;AAC5E,QAAM,EAAE,aAAa,MAAM,UAAU,CAAA,MAAO;AAC5C,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI,CAAC,MAAMA,aAAAA,oBAAoB,KAAK,CAAC,CAAC;AACvD;;;;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { Placement } from '@blueprintjs/core';
|
|
2
3
|
import { TableFilter } from '../actions';
|
|
3
4
|
interface ColumnSpecGenerateOptions {
|
|
4
5
|
calculateWidths?: boolean;
|
|
@@ -66,13 +67,40 @@ export interface CellEditors {
|
|
|
66
67
|
export interface CellDetailContext<T = any> extends CellRenderContext<T> {
|
|
67
68
|
/** Whether this cell is editable (column × table × not-deleted). */
|
|
68
69
|
editable: boolean;
|
|
69
|
-
/**
|
|
70
|
+
/**
|
|
71
|
+
* When the surface stands for several cells at once (the row editor over a
|
|
72
|
+
* multi-row selection), the cells it stands for. `value` is then the value
|
|
73
|
+
* they share, or `undefined` when they differ (`mixed`), and `onChange`
|
|
74
|
+
* writes every one of them. Only offered to a column that declares
|
|
75
|
+
* `multiCell`; absent for a single cell.
|
|
76
|
+
*/
|
|
77
|
+
cells?: CellSelectionEntry<T>[];
|
|
78
|
+
/** True when `cells` hold differing values. */
|
|
79
|
+
mixed?: boolean;
|
|
80
|
+
/** Where the surface is drawn: `"cell"`, the grid's own popover, modal or
|
|
81
|
+
* in-cell surface; `"row-editor"`, a field of the sheet's row editor; or
|
|
82
|
+
* `"editor"`, a field of a standalone `DataEditor` — so a surface can lay
|
|
83
|
+
* itself out to suit (a picker nesting its own popovers only where it has
|
|
84
|
+
* room). */
|
|
85
|
+
surface?: "cell" | "row-editor" | "editor";
|
|
86
|
+
/** Commit a new value for this cell — for every cell, when the surface
|
|
87
|
+
* stands for several. */
|
|
70
88
|
onChange: (value: any) => void;
|
|
89
|
+
/** With `cells`, commit a value for each cell, aligned with them — for a
|
|
90
|
+
* surface that changes each cell's own value (adding a tag to every row's
|
|
91
|
+
* list) rather than setting them all to one. */
|
|
92
|
+
onChangeCells?: (values: any[]) => void;
|
|
71
93
|
/** Reset this cell (and selection) to its base value. */
|
|
72
94
|
resetValue: () => void;
|
|
73
95
|
/** Close the surface and return focus to the table. */
|
|
74
96
|
close: () => void;
|
|
75
97
|
}
|
|
98
|
+
/** One of the cells a multi-cell surface stands for. */
|
|
99
|
+
export interface CellSelectionEntry<T = any> {
|
|
100
|
+
rowIndex: number;
|
|
101
|
+
row: T | null | undefined;
|
|
102
|
+
value: any;
|
|
103
|
+
}
|
|
76
104
|
/** How a cell's detail surface is presented. Orthogonal to what it renders. */
|
|
77
105
|
export type DetailPresentation = "popover" | "modal" | "inline";
|
|
78
106
|
export interface ColumnSpec {
|
|
@@ -119,11 +147,45 @@ export interface ColumnSpec {
|
|
|
119
147
|
* same component works in any container.
|
|
120
148
|
*/
|
|
121
149
|
cellDetail?: (ctx: CellDetailContext) => React.ReactNode;
|
|
150
|
+
/**
|
|
151
|
+
* Whether this column's `cellDetail` can stand for several cells at once —
|
|
152
|
+
* read the shared value (or `ctx.mixed`) and write every cell in
|
|
153
|
+
* `ctx.cells` through one `onChange`. A surface that doesn't declare this
|
|
154
|
+
* is shown read-only over a multi-row selection, with "Multiple values"
|
|
155
|
+
* where they differ. The default editors (an input by `dataType`) always
|
|
156
|
+
* can, since setting one value on every cell is what they do.
|
|
157
|
+
*/
|
|
158
|
+
multiCell?: boolean;
|
|
122
159
|
/** How `cellDetail` is presented. Defaults to `"popover"`. */
|
|
123
160
|
detailPresentation?: DetailPresentation;
|
|
161
|
+
/** What one cell of the column is called, for the selection indicator
|
|
162
|
+
* ("1 lithology", "3 lithologies"). Defaults to the column's name. */
|
|
163
|
+
cellLabel?: string;
|
|
164
|
+
/** Where a popover `cellDetail` opens against its cell. Defaults to
|
|
165
|
+
* `"right-start"`; a wide surface (a tag picker) reads better below, at
|
|
166
|
+
* `"bottom-start"`. */
|
|
167
|
+
detailPlacement?: Placement;
|
|
124
168
|
cellComponent?: any;
|
|
125
169
|
category?: string;
|
|
126
170
|
editable?: boolean;
|
|
171
|
+
/**
|
|
172
|
+
* A **derived** column holds values computed from other data — a total, an
|
|
173
|
+
* age that follows from an interval and a proportion — rather than values
|
|
174
|
+
* anyone types. It is never writable, whatever `editable` or the table
|
|
175
|
+
* says, and every write path (inline editing, fill, paste, the row editor)
|
|
176
|
+
* leaves it alone; it is drawn dimmed so a reader can tell what is a record
|
|
177
|
+
* and what is a restatement of one. Use it instead of `editable: false` when
|
|
178
|
+
* the read-only-ness is a property of the *data* rather than of the view.
|
|
179
|
+
*/
|
|
180
|
+
derived?: boolean;
|
|
181
|
+
/**
|
|
182
|
+
* A **hidden** column stays in the spec but is left out of the working
|
|
183
|
+
* spec the table is built from: it isn't rendered, isn't part of a
|
|
184
|
+
* selection, and isn't written by a fill or a paste. A consumer keeps one
|
|
185
|
+
* spec and toggles this flag ("show absolute ages", "show generated ids")
|
|
186
|
+
* rather than maintaining two arrays. Resolved by `postprocessColumnSpec`.
|
|
187
|
+
*/
|
|
188
|
+
hidden?: boolean;
|
|
127
189
|
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
128
190
|
style?: React.CSSProperties;
|
|
129
191
|
width?: number;
|
|
@@ -204,11 +266,45 @@ export declare function postprocessColumnSpec(columnSpec: ColumnSpec[]): {
|
|
|
204
266
|
* same component works in any container.
|
|
205
267
|
*/
|
|
206
268
|
cellDetail?: (ctx: CellDetailContext) => React.ReactNode;
|
|
269
|
+
/**
|
|
270
|
+
* Whether this column's `cellDetail` can stand for several cells at once —
|
|
271
|
+
* read the shared value (or `ctx.mixed`) and write every cell in
|
|
272
|
+
* `ctx.cells` through one `onChange`. A surface that doesn't declare this
|
|
273
|
+
* is shown read-only over a multi-row selection, with "Multiple values"
|
|
274
|
+
* where they differ. The default editors (an input by `dataType`) always
|
|
275
|
+
* can, since setting one value on every cell is what they do.
|
|
276
|
+
*/
|
|
277
|
+
multiCell?: boolean;
|
|
207
278
|
/** How `cellDetail` is presented. Defaults to `"popover"`. */
|
|
208
279
|
detailPresentation?: DetailPresentation;
|
|
280
|
+
/** What one cell of the column is called, for the selection indicator
|
|
281
|
+
* ("1 lithology", "3 lithologies"). Defaults to the column's name. */
|
|
282
|
+
cellLabel?: string;
|
|
283
|
+
/** Where a popover `cellDetail` opens against its cell. Defaults to
|
|
284
|
+
* `"right-start"`; a wide surface (a tag picker) reads better below, at
|
|
285
|
+
* `"bottom-start"`. */
|
|
286
|
+
detailPlacement?: Placement;
|
|
209
287
|
cellComponent?: any;
|
|
210
288
|
category?: string;
|
|
211
289
|
editable?: boolean;
|
|
290
|
+
/**
|
|
291
|
+
* A **derived** column holds values computed from other data — a total, an
|
|
292
|
+
* age that follows from an interval and a proportion — rather than values
|
|
293
|
+
* anyone types. It is never writable, whatever `editable` or the table
|
|
294
|
+
* says, and every write path (inline editing, fill, paste, the row editor)
|
|
295
|
+
* leaves it alone; it is drawn dimmed so a reader can tell what is a record
|
|
296
|
+
* and what is a restatement of one. Use it instead of `editable: false` when
|
|
297
|
+
* the read-only-ness is a property of the *data* rather than of the view.
|
|
298
|
+
*/
|
|
299
|
+
derived?: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* A **hidden** column stays in the spec but is left out of the working
|
|
302
|
+
* spec the table is built from: it isn't rendered, isn't part of a
|
|
303
|
+
* selection, and isn't written by a fill or a paste. A consumer keeps one
|
|
304
|
+
* spec and toggles this flag ("show absolute ages", "show generated ids")
|
|
305
|
+
* rather than maintaining two arrays. Resolved by `postprocessColumnSpec`.
|
|
306
|
+
*/
|
|
307
|
+
hidden?: boolean;
|
|
212
308
|
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
213
309
|
style?: React.CSSProperties;
|
|
214
310
|
width?: number;
|
|
@@ -228,4 +324,12 @@ export declare function postprocessColumnSpec(columnSpec: ColumnSpec[]): {
|
|
|
228
324
|
* header renderer (requires table-level `enableColumnReordering`). */
|
|
229
325
|
reorderable?: boolean;
|
|
230
326
|
}[];
|
|
327
|
+
/**
|
|
328
|
+
* Whether a column takes writes at all: the table is editable, the column
|
|
329
|
+
* isn't locked (`editable: false`) and it isn't `derived`. This is the one
|
|
330
|
+
* rule every write path consults — the inline editor, `onSelectionEdited`,
|
|
331
|
+
* fill, clear, clipboard paste and the row editor — so a locked column is
|
|
332
|
+
* locked however the edit arrives, not only when it is typed into.
|
|
333
|
+
*/
|
|
334
|
+
export declare function isColumnWritable(col: ColumnSpec | null | undefined, tableEditable?: boolean): boolean;
|
|
231
335
|
export {};
|
|
@@ -103,7 +103,7 @@ function generateColumnSpec(data, options = {}) {
|
|
|
103
103
|
return postprocessColumnSpec(improvedSpec);
|
|
104
104
|
}
|
|
105
105
|
function postprocessColumnSpec(columnSpec) {
|
|
106
|
-
return columnSpec.map((col) => {
|
|
106
|
+
return columnSpec.filter((col) => !col.hidden).map((col) => {
|
|
107
107
|
return {
|
|
108
108
|
...col,
|
|
109
109
|
filters: postprocessColumnFilters(col),
|
|
@@ -111,6 +111,12 @@ function postprocessColumnSpec(columnSpec) {
|
|
|
111
111
|
};
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
+
function isColumnWritable(col, tableEditable = true) {
|
|
115
|
+
if (col == null) return false;
|
|
116
|
+
if (!tableEditable) return false;
|
|
117
|
+
if (col.derived) return false;
|
|
118
|
+
return col.editable !== false;
|
|
119
|
+
}
|
|
114
120
|
function postprocessColumnFilters(col) {
|
|
115
121
|
const { filterable = true, filters = [] } = col;
|
|
116
122
|
if (!filterable) {
|
|
@@ -121,6 +127,7 @@ function postprocessColumnFilters(col) {
|
|
|
121
127
|
export {
|
|
122
128
|
generateColumnSpec,
|
|
123
129
|
generateDefaultColumnSpec,
|
|
130
|
+
isColumnWritable,
|
|
124
131
|
postprocessColumnSpec
|
|
125
132
|
};
|
|
126
133
|
//# sourceMappingURL=column-spec.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.js","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc.\n */\n return columnSpec.map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":[],"mappings":";AAGA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAyKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,YAAI,QAAQ,iBAAiB,GAAG;AAChC,YAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,uBAAa,IAAI,KAAK,KAAK,IAAI,OAAO,aAAa,IAAI,GAAG,KAAK,CAAC,CAAC;AAAA,QACnE;AAAA,MACF;AAEA,UAAI,OAAe,OAAO;A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IAAI,aAAa,mBAAmB;AAEpE,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,QAAM,eAAe,aAAa,IAAI,CAAC,QAAQ;AAC7C,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACD,SAAO,sBAAsB,YAAY;AAC3C;AAEO,SAAS,sBAAsB,YAA0B;AAI9D,SAAO,WAAW,IAAI,CAAC,QAAQ;AAC7B,WAAO;AAAA,MACL,GAAG;AAAA,MACH,SAAS,yBAAyB,GAAG;AAAA,MACrC,SAAS,IAAI,WAAW,CAAA;AAAA,IAAC;AAAA,EAE7B,CAAC;AACH;AAEA,SAAS,yBAAyB,KAA4C;AAC5E,QAAM,EAAE,aAAa,MAAM,UAAU,CAAA,MAAO;AAC5C,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,IAAI,CAAC,MAAM,oBAAoB,KAAK,CAAC,CAAC;AACvD;"}
|
|
1
|
+
{"version":3,"file":"column-spec.js","sources":["../../src/provider/column-spec.ts"],"sourcesContent":["import React from \"react\";\nimport type { Placement } from \"@blueprintjs/core\";\nimport { enhanceColumnFilter, TableFilter } from \"../actions\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n \"text\" | \"string\" | \"number\" | \"integer\" | \"boolean\" | \"object\" | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | null | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /**\n * When the surface stands for several cells at once (the row editor over a\n * multi-row selection), the cells it stands for. `value` is then the value\n * they share, or `undefined` when they differ (`mixed`), and `onChange`\n * writes every one of them. Only offered to a column that declares\n * `multiCell`; absent for a single cell.\n */\n cells?: CellSelectionEntry<T>[];\n /** True when `cells` hold differing values. */\n mixed?: boolean;\n /** Where the surface is drawn: `\"cell\"`, the grid's own popover, modal or\n * in-cell surface; `\"row-editor\"`, a field of the sheet's row editor; or\n * `\"editor\"`, a field of a standalone `DataEditor` — so a surface can lay\n * itself out to suit (a picker nesting its own popovers only where it has\n * room). */\n surface?: \"cell\" | \"row-editor\" | \"editor\";\n /** Commit a new value for this cell — for every cell, when the surface\n * stands for several. */\n onChange: (value: any) => void;\n /** With `cells`, commit a value for each cell, aligned with them — for a\n * surface that changes each cell's own value (adding a tag to every row's\n * list) rather than setting them all to one. */\n onChangeCells?: (values: any[]) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** One of the cells a multi-cell surface stands for. */\nexport interface CellSelectionEntry<T = any> {\n rowIndex: number;\n row: T | null | undefined;\n value: any;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any, ctx?: CellRenderContext) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /**\n * Whether this column's `cellDetail` can stand for several cells at once —\n * read the shared value (or `ctx.mixed`) and write every cell in\n * `ctx.cells` through one `onChange`. A surface that doesn't declare this\n * is shown read-only over a multi-row selection, with \"Multiple values\"\n * where they differ. The default editors (an input by `dataType`) always\n * can, since setting one value on every cell is what they do.\n */\n multiCell?: boolean;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n /** What one cell of the column is called, for the selection indicator\n * (\"1 lithology\", \"3 lithologies\"). Defaults to the column's name. */\n cellLabel?: string;\n /** Where a popover `cellDetail` opens against its cell. Defaults to\n * `\"right-start\"`; a wide surface (a tag picker) reads better below, at\n * `\"bottom-start\"`. */\n detailPlacement?: Placement;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n /**\n * A **derived** column holds values computed from other data — a total, an\n * age that follows from an interval and a proportion — rather than values\n * anyone types. It is never writable, whatever `editable` or the table\n * says, and every write path (inline editing, fill, paste, the row editor)\n * leaves it alone; it is drawn dimmed so a reader can tell what is a record\n * and what is a restatement of one. Use it instead of `editable: false` when\n * the read-only-ness is a property of the *data* rather than of the view.\n */\n derived?: boolean;\n /**\n * A **hidden** column stays in the spec but is left out of the working\n * spec the table is built from: it isn't rendered, isn't part of a\n * selection, and isn't written by a fill or a paste. A consumer keeps one\n * spec and toggles this flag (\"show absolute ages\", \"show generated ids\")\n * rather than maintaining two arrays. Resolved by `postprocessColumnSpec`.\n */\n hidden?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec: ColumnSpec[] = [];\n for (const key of keys) {\n let width: number | undefined = undefined;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: Partial<ColumnSpecOptions<T>> = {},\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n const improvedSpec = filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n return postprocessColumnSpec(improvedSpec);\n}\n\nexport function postprocessColumnSpec(columnSpec: ColumnSpec[]) {\n /** Postprocess column spec to make sure that, e.g., column filters are\n * properly established, etc. Hidden columns are dropped here, so everything\n * downstream — the renderer, the selection, the edit paths — works with the\n * visible columns only and indexes into one array.\n */\n return columnSpec\n .filter((col) => !col.hidden)\n .map((col) => {\n return {\n ...col,\n filters: postprocessColumnFilters(col),\n actions: col.actions ?? [],\n };\n });\n}\n\n/**\n * Whether a column takes writes at all: the table is editable, the column\n * isn't locked (`editable: false`) and it isn't `derived`. This is the one\n * rule every write path consults — the inline editor, `onSelectionEdited`,\n * fill, clear, clipboard paste and the row editor — so a locked column is\n * locked however the edit arrives, not only when it is typed into.\n */\nexport function isColumnWritable(\n col: ColumnSpec | null | undefined,\n tableEditable: boolean = true,\n): boolean {\n if (col == null) return false;\n if (!tableEditable) return false;\n if (col.derived) return false;\n return col.editable !== false;\n}\n\nfunction postprocessColumnFilters(col: ColumnSpec): TableFilter[] | undefined {\n const { filterable = true, filters = [] } = col;\n if (!filterable) {\n return undefined;\n }\n return filters.map((f) => enhanceColumnFilter(col, f));\n}\n"],"names":[],"mappings":";AAIA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAiOpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,YAAI,QAAQ,iBAAiB,GAAG;AAChC,YAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,uBAAa,IAAI,KAAK,KAAK,IAAI,OAAO,aAAa,IAAI,GAAG,KAAK,CAAC,CAAC;AAAA,QACnE;AAAA,MACF;AAEA,UAAI,OAA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