@macrostrat/data-sheet 4.0.0-dev2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +44 -0
- package/dist/actions/builtin.cjs +36 -5
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +3 -2
- package/dist/actions/builtin.js +36 -5
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/column-controls.cjs +149 -0
- package/dist/actions/column-controls.cjs.map +1 -0
- package/dist/actions/column-controls.d.ts +11 -0
- package/dist/actions/column-controls.js +147 -0
- package/dist/actions/column-controls.js.map +1 -0
- package/dist/actions/column-filter.cjs +68 -0
- package/dist/actions/column-filter.cjs.map +1 -0
- package/dist/actions/column-filter.d.ts +11 -0
- package/dist/actions/column-filter.js +66 -0
- package/dist/actions/column-filter.js.map +1 -0
- package/dist/actions/edit-actions.cjs +42 -0
- package/dist/actions/edit-actions.cjs.map +1 -0
- package/dist/actions/edit-actions.d.ts +14 -0
- package/dist/actions/edit-actions.js +42 -0
- package/dist/actions/edit-actions.js.map +1 -0
- package/dist/actions/filters.cjs +39 -23
- package/dist/actions/filters.cjs.map +1 -1
- package/dist/actions/filters.d.ts +6 -3
- package/dist/actions/filters.js +41 -25
- package/dist/actions/filters.js.map +1 -1
- package/dist/actions/index.d.ts +4 -0
- package/dist/actions/selection.cjs +39 -30
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +3 -7
- package/dist/actions/selection.js +39 -30
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-controls.cjs +41 -0
- package/dist/actions/table-controls.cjs.map +1 -0
- package/dist/actions/table-controls.d.ts +4 -0
- package/dist/actions/table-controls.js +39 -0
- package/dist/actions/table-controls.js.map +1 -0
- package/dist/actions/toolbar.cjs +69 -10
- package/dist/actions/toolbar.cjs.map +1 -1
- package/dist/actions/toolbar.d.ts +9 -6
- package/dist/actions/toolbar.js +69 -10
- package/dist/actions/toolbar.js.map +1 -1
- package/dist/actions/toolbar.module.sass.cjs +12 -7
- package/dist/actions/toolbar.module.sass.cjs.map +1 -1
- package/dist/actions/toolbar.module.sass.js +12 -7
- package/dist/actions/toolbar.module.sass.js.map +1 -1
- package/dist/actions/types.d.ts +49 -4
- package/dist/cell-renderer.cjs +150 -14
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.d.ts +1 -1
- package/dist/cell-renderer.js +151 -15
- package/dist/cell-renderer.js.map +1 -1
- package/dist/components/cell-detail.cjs +24 -0
- package/dist/components/cell-detail.cjs.map +1 -0
- package/dist/components/cell-detail.d.ts +12 -0
- package/dist/components/cell-detail.js +24 -0
- package/dist/components/cell-detail.js.map +1 -0
- package/dist/components/editor-popup.cjs +28 -24
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +29 -25
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/text-areas.cjs +51 -7
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +4 -1
- package/dist/components/text-areas.js +51 -7
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +46 -9
- package/dist/components/view-info.cjs.map +1 -1
- package/dist/components/view-info.d.ts +5 -1
- package/dist/components/view-info.js +47 -10
- package/dist/components/view-info.js.map +1 -1
- package/dist/core.cjs +167 -73
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +53 -6
- package/dist/core.js +169 -75
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +72 -123
- package/dist/filters/operators.cjs +91 -0
- package/dist/filters/operators.cjs.map +1 -0
- package/dist/filters/operators.d.ts +17 -0
- package/dist/filters/operators.js +91 -0
- package/dist/filters/operators.js.map +1 -0
- package/dist/index.cjs +38 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +44 -16
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +13 -12
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +13 -12
- package/dist/main.module.sass.js.map +1 -1
- package/dist/postgrest-table/data-loaders.cjs +255 -146
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +144 -46
- package/dist/postgrest-table/data-loaders.js +259 -150
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +58 -169
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +5 -2
- package/dist/postgrest-table/index.js +63 -174
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +0 -4
- package/dist/postgrest-table/loading-utils.cjs.map +1 -1
- package/dist/postgrest-table/loading-utils.js +1 -5
- package/dist/postgrest-table/loading-utils.js.map +1 -1
- package/dist/postgrest-table/main.module.sass.cjs +14 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +14 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +68 -11
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.ts +25 -0
- package/dist/provider.js +68 -11
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell.cjs +95 -75
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -18
- package/dist/renderers/column-header-cell.js +98 -78
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +0 -1
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +84 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +101 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/debug-overlay.cjs +24 -0
- package/dist/utils/debug-overlay.cjs.map +1 -0
- package/dist/utils/debug-overlay.d.ts +4 -0
- package/dist/utils/debug-overlay.js +24 -0
- package/dist/utils/debug-overlay.js.map +1 -0
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/key-handling.cjs +52 -6
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.js +52 -6
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +41 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/validation.d.ts +26 -0
- package/dist/utils/validation.js +41 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/zustand-store.cjs +119 -61
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +121 -63
- package/dist/zustand-store.js.map +1 -1
- package/package.json +6 -6
- package/src/actions/builtin.ts +62 -7
- package/src/actions/column-controls.ts +185 -0
- package/src/actions/column-filter.ts +104 -0
- package/src/actions/edit-actions.ts +67 -0
- package/src/actions/filters.ts +54 -28
- package/src/actions/index.ts +4 -0
- package/src/actions/selection.ts +59 -52
- package/src/actions/table-controls.ts +46 -0
- package/src/actions/toolbar.module.sass +22 -2
- package/src/actions/toolbar.ts +113 -16
- package/src/actions/types.ts +49 -4
- package/src/cell-renderer.ts +211 -16
- package/src/components/cell-detail.ts +30 -0
- package/src/components/editor-popup.ts +39 -25
- package/src/components/index.ts +2 -2
- package/src/components/text-areas.ts +80 -16
- package/src/components/view-info.ts +63 -4
- package/src/core.ts +321 -103
- package/src/filters/operators.ts +127 -0
- package/src/index.ts +2 -0
- package/src/main.module.sass +6 -0
- package/src/postgrest-table/data-loaders.ts +459 -209
- package/src/postgrest-table/index.ts +81 -254
- package/src/postgrest-table/main.module.sass +11 -0
- package/src/provider.ts +109 -12
- package/src/renderers/column-header-cell.ts +60 -272
- package/src/renderers/index.ts +0 -1
- package/src/types.ts +76 -2
- package/src/utils/column-spec.ts +112 -1
- package/src/utils/debug-overlay.ts +22 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/key-handling.ts +70 -6
- package/src/utils/validation.ts +72 -0
- package/src/zustand-store.ts +167 -60
- package/dist/components/actions.cjs +0 -12
- package/dist/components/actions.cjs.map +0 -1
- package/dist/components/actions.d.ts +0 -2
- package/dist/components/actions.js +0 -12
- package/dist/components/actions.js.map +0 -1
- package/dist/components/actions.module.sass.cjs +0 -12
- package/dist/components/actions.module.sass.cjs.map +0 -1
- package/dist/components/actions.module.sass.js +0 -11
- package/dist/components/actions.module.sass.js.map +0 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +0 -27
- package/dist/postgrest-table/lazy-loader-table.cjs.map +0 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +0 -3
- package/dist/postgrest-table/lazy-loader-table.js +0 -27
- package/dist/postgrest-table/lazy-loader-table.js.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +0 -216
- package/dist/renderers/column-header-cell-postgrest.cjs.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.d.ts +0 -13
- package/dist/renderers/column-header-cell-postgrest.js +0 -216
- package/dist/renderers/column-header-cell-postgrest.js.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +0 -23
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +0 -1
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +0 -22
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +0 -1
- package/src/components/actions.ts +0 -9
- package/src/postgrest-table/lazy-loader-table.ts +0 -25
- package/src/renderers/column-header-cell-postgrest.ts +0 -282
package/dist/cell-renderer.cjs
CHANGED
|
@@ -6,9 +6,12 @@ const react = require("react");
|
|
|
6
6
|
const zustandStore = require("./zustand-store.cjs");
|
|
7
7
|
const table = require("@blueprintjs/table");
|
|
8
8
|
const provider = require("./provider.cjs");
|
|
9
|
+
const validation = require("./utils/validation.cjs");
|
|
10
|
+
const cellDetail = require("./components/cell-detail.cjs");
|
|
9
11
|
const editorPopup = require("./components/editor-popup.cjs");
|
|
10
12
|
const keyHandling = require("./utils/key-handling.cjs");
|
|
11
|
-
function basicCellRenderer(rowIndex, colIndex, columnSpec, state,
|
|
13
|
+
function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowIndices) {
|
|
14
|
+
const focusOnOpen = state.cellSurfaceOpen;
|
|
12
15
|
const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
|
|
13
16
|
const data = state.data;
|
|
14
17
|
const updatedData = state.updatedData;
|
|
@@ -20,8 +23,20 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
20
23
|
const onCellEdited = state.onCellEdited;
|
|
21
24
|
const value = updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
|
|
22
25
|
const isEmpty = value == null || value === "";
|
|
23
|
-
const
|
|
24
|
-
|
|
26
|
+
const edited = updatedData[dataRowIndex]?.[col.key] != null || state.rowStatus[dataRowIndex] === types.TableElementStatus.ADDED;
|
|
27
|
+
const validation$1 = isDeleted ? null : validation.validateCell(col, value, row, dataRowIndex);
|
|
28
|
+
const cellContext = {
|
|
29
|
+
value,
|
|
30
|
+
rowIndex: dataRowIndex,
|
|
31
|
+
colIndex,
|
|
32
|
+
column: col,
|
|
33
|
+
row,
|
|
34
|
+
isEdited: edited,
|
|
35
|
+
isDeleted,
|
|
36
|
+
validation: validation$1
|
|
37
|
+
};
|
|
38
|
+
const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
|
|
39
|
+
let style = { ...col.style ?? {} };
|
|
25
40
|
if (isDeleted) {
|
|
26
41
|
style.opacity = 0.5;
|
|
27
42
|
style.textDecoration = "line-through";
|
|
@@ -29,14 +44,52 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
29
44
|
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
30
45
|
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
31
46
|
const tableIsEditable = state.editable;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
47
|
+
let intent;
|
|
48
|
+
if (validation$1?.severity === "error") {
|
|
49
|
+
intent = "danger";
|
|
50
|
+
} else if (validation$1?.severity === "warning") {
|
|
51
|
+
intent = "warning";
|
|
52
|
+
} else if (isDeleted) {
|
|
35
53
|
intent = "danger";
|
|
54
|
+
} else if (edited) {
|
|
55
|
+
intent = "success";
|
|
36
56
|
}
|
|
37
57
|
const _Cell = col.cellComponent ?? table.Cell;
|
|
38
|
-
|
|
58
|
+
const cellComponentProps = col.cellComponent != null ? { cellContext } : {};
|
|
59
|
+
const perCellEditors = col.editorForCell?.(cellContext);
|
|
60
|
+
const dataEditorSpec = perCellEditors != null && "dataEditor" in perCellEditors ? perCellEditors.dataEditor : col.dataEditor;
|
|
61
|
+
const inlineEditorSpec = perCellEditors != null && "inlineEditor" in perCellEditors ? perCellEditors.inlineEditor : col.inlineEditor;
|
|
62
|
+
let inlineEditor = editable ? inlineEditorSpec ?? true : false;
|
|
63
|
+
const makeDetailCtx = (editableFlag) => ({
|
|
64
|
+
...cellContext,
|
|
65
|
+
editable: editableFlag,
|
|
66
|
+
onChange(v) {
|
|
67
|
+
if (editableFlag) onCellEdited(dataRowIndex, col.key, v);
|
|
68
|
+
},
|
|
69
|
+
resetValue() {
|
|
70
|
+
state.resetChanges();
|
|
71
|
+
},
|
|
72
|
+
close() {
|
|
73
|
+
state.closeCellSurface();
|
|
74
|
+
state.tableElement?.focus?.();
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const detailPresentation = col.cellDetail != null ? col.detailPresentation ?? "popover" : null;
|
|
39
78
|
if (!topLeft) {
|
|
79
|
+
if (detailPresentation === "inline") {
|
|
80
|
+
return main_module.default(
|
|
81
|
+
_Cell,
|
|
82
|
+
{
|
|
83
|
+
intent,
|
|
84
|
+
value,
|
|
85
|
+
style,
|
|
86
|
+
className: "value-viewer-cell",
|
|
87
|
+
interactive: false,
|
|
88
|
+
...cellComponentProps
|
|
89
|
+
},
|
|
90
|
+
col.cellDetail(makeDetailCtx(false))
|
|
91
|
+
);
|
|
92
|
+
}
|
|
40
93
|
return main_module.default(
|
|
41
94
|
_Cell,
|
|
42
95
|
{
|
|
@@ -45,23 +98,92 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
45
98
|
value,
|
|
46
99
|
style,
|
|
47
100
|
disabled: tableIsEditable && !editable,
|
|
48
|
-
interactive: false
|
|
101
|
+
interactive: false,
|
|
102
|
+
...cellComponentProps
|
|
49
103
|
},
|
|
50
104
|
_renderedValue
|
|
51
105
|
);
|
|
52
106
|
}
|
|
107
|
+
if (col.cellDetail != null) {
|
|
108
|
+
const content = col.cellDetail(makeDetailCtx(editable));
|
|
109
|
+
if (detailPresentation === "inline") {
|
|
110
|
+
return main_module.default(
|
|
111
|
+
_Cell,
|
|
112
|
+
{
|
|
113
|
+
intent,
|
|
114
|
+
value,
|
|
115
|
+
style,
|
|
116
|
+
className: editable ? "input-cell" : "value-viewer-cell",
|
|
117
|
+
interactive: editable,
|
|
118
|
+
...cellComponentProps
|
|
119
|
+
},
|
|
120
|
+
content
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
if (detailPresentation === "modal") {
|
|
124
|
+
return main_module.default(
|
|
125
|
+
_Cell,
|
|
126
|
+
{
|
|
127
|
+
intent,
|
|
128
|
+
value,
|
|
129
|
+
style,
|
|
130
|
+
className: "value-viewer-cell",
|
|
131
|
+
interactive: false,
|
|
132
|
+
...cellComponentProps
|
|
133
|
+
},
|
|
134
|
+
main_module.default(
|
|
135
|
+
cellDetail.CellDetailModal,
|
|
136
|
+
{ title: col.name, valueViewer: _renderedValue },
|
|
137
|
+
content
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
const panel = main_module.default(editorPopup.EditorPopup, { valueViewer: _renderedValue }, content);
|
|
142
|
+
return main_module.default(
|
|
143
|
+
_Cell,
|
|
144
|
+
{
|
|
145
|
+
intent,
|
|
146
|
+
value,
|
|
147
|
+
style,
|
|
148
|
+
className: "editor-cell",
|
|
149
|
+
interactive: editable,
|
|
150
|
+
...cellComponentProps
|
|
151
|
+
},
|
|
152
|
+
panel
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (col.detailRenderer != null) {
|
|
156
|
+
const panel = main_module.default(
|
|
157
|
+
editorPopup.EditorPopup,
|
|
158
|
+
{ valueViewer: _renderedValue },
|
|
159
|
+
col.detailRenderer(cellContext)
|
|
160
|
+
);
|
|
161
|
+
return main_module.default(
|
|
162
|
+
_Cell,
|
|
163
|
+
{
|
|
164
|
+
intent,
|
|
165
|
+
value,
|
|
166
|
+
style,
|
|
167
|
+
// Use the editor-cell popover layout so the target fills the cell
|
|
168
|
+
// without the double-padding offset of `value-viewer-cell`.
|
|
169
|
+
className: "editor-cell",
|
|
170
|
+
interactive: false,
|
|
171
|
+
...cellComponentProps
|
|
172
|
+
},
|
|
173
|
+
panel
|
|
174
|
+
);
|
|
175
|
+
}
|
|
53
176
|
let cellContents = _renderedValue;
|
|
54
177
|
let _dataEditor = null;
|
|
55
178
|
let className = null;
|
|
56
|
-
if (
|
|
179
|
+
if (dataEditorSpec != null) {
|
|
57
180
|
_dataEditor = main_module.default(
|
|
58
181
|
editorPopup.EditorPopup,
|
|
59
182
|
{
|
|
60
|
-
autoFocus: autoFocusEditor,
|
|
61
183
|
valueViewer: _renderedValue
|
|
62
184
|
},
|
|
63
185
|
[
|
|
64
|
-
main_module.default(
|
|
186
|
+
main_module.default(dataEditorSpec, {
|
|
65
187
|
value,
|
|
66
188
|
editable,
|
|
67
189
|
isEdited: edited,
|
|
@@ -88,7 +210,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
88
210
|
value,
|
|
89
211
|
style,
|
|
90
212
|
className: className2,
|
|
91
|
-
interactive: false
|
|
213
|
+
interactive: false,
|
|
214
|
+
...cellComponentProps
|
|
92
215
|
},
|
|
93
216
|
cellContents
|
|
94
217
|
);
|
|
@@ -108,7 +231,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
108
231
|
_inlineEditor = main_module.default(EditorInput, {
|
|
109
232
|
className: "main-editor",
|
|
110
233
|
value: _value ?? "",
|
|
111
|
-
autoFocus:
|
|
234
|
+
autoFocus: focusOnOpen,
|
|
112
235
|
onChange
|
|
113
236
|
});
|
|
114
237
|
} else {
|
|
@@ -132,7 +255,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
132
255
|
value,
|
|
133
256
|
className,
|
|
134
257
|
style,
|
|
135
|
-
interactive: true
|
|
258
|
+
interactive: true,
|
|
259
|
+
...cellComponentProps
|
|
136
260
|
//truncated: false,
|
|
137
261
|
},
|
|
138
262
|
[
|
|
@@ -145,11 +269,23 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
145
269
|
function EditorInput(props) {
|
|
146
270
|
const { value, onChange, ...rest } = props;
|
|
147
271
|
const onKeyDown = provider.ctx.useValue(keyHandling.editorKeyHandlerAtom);
|
|
272
|
+
const navDirection = provider.useSelector((s) => s.lastNavDirection);
|
|
273
|
+
const surfaceOpen = provider.useSelector((s) => s.cellSurfaceOpen);
|
|
274
|
+
const inputRef = react.useRef(null);
|
|
148
275
|
const [_value, setValue] = react.useState(value);
|
|
149
276
|
react.useEffect(() => {
|
|
150
277
|
setValue(value);
|
|
151
278
|
}, [value]);
|
|
279
|
+
react.useEffect(() => {
|
|
280
|
+
const el = inputRef.current;
|
|
281
|
+
if (el == null || !surfaceOpen) return;
|
|
282
|
+
el.focus();
|
|
283
|
+
const atStart = navDirection === "up" || navDirection === "left";
|
|
284
|
+
const pos = atStart ? 0 : el.value?.length ?? 0;
|
|
285
|
+
el.setSelectionRange(pos, pos);
|
|
286
|
+
}, [surfaceOpen]);
|
|
152
287
|
return main_module.default("input", {
|
|
288
|
+
ref: inputRef,
|
|
153
289
|
onKeyDown,
|
|
154
290
|
onBlur: onChange,
|
|
155
291
|
value: _value ?? value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import { ColumnSpec, editorKeyHandlerAtom } from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useState } from \"react\";\nimport { EditorPopup } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n autoFocusEditor = true,\n filteredRowIndices?: number[] | null,\n): any {\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n const _renderedValue = isEmpty ? null : (col.valueRenderer?.(value) ?? value);\n\n let style = col.style ?? {};\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n let intent = edited ? \"success\" : undefined;\n if (isDeleted) {\n intent = \"danger\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n let inlineEditor = editable ? (col.inlineEditor ?? true) : false;\n\n if (!topLeft) {\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (col.dataEditor != null) {\n _dataEditor = h(\n EditorPopup,\n {\n autoFocus: autoFocusEditor,\n valueViewer: _renderedValue,\n },\n [\n h(col.dataEditor, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: autoFocusEditor,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n return h(\"input\", {\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","Cell","h","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useState","useEffect","useSelector"],"mappings":";;;;;;;;;;AASO,SAAS,kBACd,UACA,UACA,YACA,OACA,kBAAkB,MAClB,oBACK;AAGL,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY,KAAKA,MAAAA,mBAAmB;AAEtE,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAA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AG,YAAY,qBAAqB,EAAE,UAAU;AAAA;AAAA,IAAA;AAAA,EAEpD;AAEJ;AAEA,SAAS,YAAY,OAAO;AAC1B,QAAM,EAAE,OAAO,UAAU,GAAG,SAAS;AACrC,QAAM,YAAYK,SAAAA,IAAI,SAASC,gCAAoB;AACnD,QAAM,CAAC,QAAQ,QAAQ,IAAIC,MAAAA,SAAS,KAAK;AACzCC,QAAAA,UAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACV,SAAOR,YAAAA,QAAE,SAAS;AAAA,IAChB;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcS,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOT,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
|
|
1
|
+
{"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object\n let style = { ...(col.style ?? {}) };\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > deleted > edited. Validation state\n // overrides the edited-green so an edited-but-invalid cell reads as invalid.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (isDeleted) {\n intent = \"danger\";\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","validation","validateCell","Cell","h","CellDetailModal","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useSelector","useRef","useState","useEffect"],"mappings":";;;;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY,KAAKA,MAAAA,mBAAmB;AAEtE,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,QACxC,MAAM,UAAU,YAAY,MAAMA,MAAAA,mBAAmB;AAGvD,QAAMC,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AA,YAAY,CAAC,MAAM,EAAE,eAAe;AACxD,QAAM,WAAWC,MAAAA,OAAyB,IAAI;AAC9C,QAAM,CAAC,QAAQ,QAAQ,IAAIC,MAAAA,SAAS,KAAK;AACzCC,QAAAA,UAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACVA,QAAAA,UAAU,MAAM;AAId,UAAM,KAAK,SAAS;AACpB,QAAI,MAAM,QAAQ,CAAC,YAAa;AAChC,OAAG,MAAA;AACH,UAAM,UAAU,iBAAiB,QAAQ,iBAAiB;AAC1D,UAAM,MAAM,UAAU,IAAK,GAAG,OAAO,UAAU;AAC/C,OAAG,kBAAkB,KAAK,GAAG;AAAA,EAE/B,GAAG,CAAC,WAAW,CAAC;AAChB,SAAOX,YAAAA,QAAE,SAAS;AAAA,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcQ,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOR,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
|
package/dist/cell-renderer.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ColumnSpec } from './utils';
|
|
2
2
|
import { DataSheetStore } from './types.ts';
|
|
3
|
-
export declare function basicCellRenderer<T>(rowIndex: number, colIndex: number, columnSpec: ColumnSpec, state: DataSheetStore<T>,
|
|
3
|
+
export declare function basicCellRenderer<T>(rowIndex: number, colIndex: number, columnSpec: ColumnSpec, state: DataSheetStore<T>, filteredRowIndices?: number[] | null): any;
|
package/dist/cell-renderer.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { TableElementStatus } from "./types.js";
|
|
2
2
|
import h from "./main.module.sass.js";
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
3
|
+
import { useRef, useState, useEffect } from "react";
|
|
4
4
|
import { singleFocusedCell } from "./zustand-store.js";
|
|
5
5
|
import { Cell } from "@blueprintjs/table";
|
|
6
6
|
import { ctx, useSelector } from "./provider.js";
|
|
7
|
+
import { validateCell } from "./utils/validation.js";
|
|
8
|
+
import { CellDetailModal } from "./components/cell-detail.js";
|
|
7
9
|
import { EditorPopup } from "./components/editor-popup.js";
|
|
8
10
|
import { editorKeyHandlerAtom } from "./utils/key-handling.js";
|
|
9
|
-
function basicCellRenderer(rowIndex, colIndex, columnSpec, state,
|
|
11
|
+
function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowIndices) {
|
|
12
|
+
const focusOnOpen = state.cellSurfaceOpen;
|
|
10
13
|
const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
|
|
11
14
|
const data = state.data;
|
|
12
15
|
const updatedData = state.updatedData;
|
|
@@ -18,8 +21,20 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
18
21
|
const onCellEdited = state.onCellEdited;
|
|
19
22
|
const value = updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
|
|
20
23
|
const isEmpty = value == null || value === "";
|
|
21
|
-
const
|
|
22
|
-
|
|
24
|
+
const edited = updatedData[dataRowIndex]?.[col.key] != null || state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
|
|
25
|
+
const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);
|
|
26
|
+
const cellContext = {
|
|
27
|
+
value,
|
|
28
|
+
rowIndex: dataRowIndex,
|
|
29
|
+
colIndex,
|
|
30
|
+
column: col,
|
|
31
|
+
row,
|
|
32
|
+
isEdited: edited,
|
|
33
|
+
isDeleted,
|
|
34
|
+
validation
|
|
35
|
+
};
|
|
36
|
+
const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
|
|
37
|
+
let style = { ...col.style ?? {} };
|
|
23
38
|
if (isDeleted) {
|
|
24
39
|
style.opacity = 0.5;
|
|
25
40
|
style.textDecoration = "line-through";
|
|
@@ -27,14 +42,52 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
27
42
|
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
28
43
|
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
29
44
|
const tableIsEditable = state.editable;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
let intent;
|
|
46
|
+
if (validation?.severity === "error") {
|
|
47
|
+
intent = "danger";
|
|
48
|
+
} else if (validation?.severity === "warning") {
|
|
49
|
+
intent = "warning";
|
|
50
|
+
} else if (isDeleted) {
|
|
33
51
|
intent = "danger";
|
|
52
|
+
} else if (edited) {
|
|
53
|
+
intent = "success";
|
|
34
54
|
}
|
|
35
55
|
const _Cell = col.cellComponent ?? Cell;
|
|
36
|
-
|
|
56
|
+
const cellComponentProps = col.cellComponent != null ? { cellContext } : {};
|
|
57
|
+
const perCellEditors = col.editorForCell?.(cellContext);
|
|
58
|
+
const dataEditorSpec = perCellEditors != null && "dataEditor" in perCellEditors ? perCellEditors.dataEditor : col.dataEditor;
|
|
59
|
+
const inlineEditorSpec = perCellEditors != null && "inlineEditor" in perCellEditors ? perCellEditors.inlineEditor : col.inlineEditor;
|
|
60
|
+
let inlineEditor = editable ? inlineEditorSpec ?? true : false;
|
|
61
|
+
const makeDetailCtx = (editableFlag) => ({
|
|
62
|
+
...cellContext,
|
|
63
|
+
editable: editableFlag,
|
|
64
|
+
onChange(v) {
|
|
65
|
+
if (editableFlag) onCellEdited(dataRowIndex, col.key, v);
|
|
66
|
+
},
|
|
67
|
+
resetValue() {
|
|
68
|
+
state.resetChanges();
|
|
69
|
+
},
|
|
70
|
+
close() {
|
|
71
|
+
state.closeCellSurface();
|
|
72
|
+
state.tableElement?.focus?.();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
const detailPresentation = col.cellDetail != null ? col.detailPresentation ?? "popover" : null;
|
|
37
76
|
if (!topLeft) {
|
|
77
|
+
if (detailPresentation === "inline") {
|
|
78
|
+
return h(
|
|
79
|
+
_Cell,
|
|
80
|
+
{
|
|
81
|
+
intent,
|
|
82
|
+
value,
|
|
83
|
+
style,
|
|
84
|
+
className: "value-viewer-cell",
|
|
85
|
+
interactive: false,
|
|
86
|
+
...cellComponentProps
|
|
87
|
+
},
|
|
88
|
+
col.cellDetail(makeDetailCtx(false))
|
|
89
|
+
);
|
|
90
|
+
}
|
|
38
91
|
return h(
|
|
39
92
|
_Cell,
|
|
40
93
|
{
|
|
@@ -43,23 +96,92 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
43
96
|
value,
|
|
44
97
|
style,
|
|
45
98
|
disabled: tableIsEditable && !editable,
|
|
46
|
-
interactive: false
|
|
99
|
+
interactive: false,
|
|
100
|
+
...cellComponentProps
|
|
47
101
|
},
|
|
48
102
|
_renderedValue
|
|
49
103
|
);
|
|
50
104
|
}
|
|
105
|
+
if (col.cellDetail != null) {
|
|
106
|
+
const content = col.cellDetail(makeDetailCtx(editable));
|
|
107
|
+
if (detailPresentation === "inline") {
|
|
108
|
+
return h(
|
|
109
|
+
_Cell,
|
|
110
|
+
{
|
|
111
|
+
intent,
|
|
112
|
+
value,
|
|
113
|
+
style,
|
|
114
|
+
className: editable ? "input-cell" : "value-viewer-cell",
|
|
115
|
+
interactive: editable,
|
|
116
|
+
...cellComponentProps
|
|
117
|
+
},
|
|
118
|
+
content
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (detailPresentation === "modal") {
|
|
122
|
+
return h(
|
|
123
|
+
_Cell,
|
|
124
|
+
{
|
|
125
|
+
intent,
|
|
126
|
+
value,
|
|
127
|
+
style,
|
|
128
|
+
className: "value-viewer-cell",
|
|
129
|
+
interactive: false,
|
|
130
|
+
...cellComponentProps
|
|
131
|
+
},
|
|
132
|
+
h(
|
|
133
|
+
CellDetailModal,
|
|
134
|
+
{ title: col.name, valueViewer: _renderedValue },
|
|
135
|
+
content
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);
|
|
140
|
+
return h(
|
|
141
|
+
_Cell,
|
|
142
|
+
{
|
|
143
|
+
intent,
|
|
144
|
+
value,
|
|
145
|
+
style,
|
|
146
|
+
className: "editor-cell",
|
|
147
|
+
interactive: editable,
|
|
148
|
+
...cellComponentProps
|
|
149
|
+
},
|
|
150
|
+
panel
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
if (col.detailRenderer != null) {
|
|
154
|
+
const panel = h(
|
|
155
|
+
EditorPopup,
|
|
156
|
+
{ valueViewer: _renderedValue },
|
|
157
|
+
col.detailRenderer(cellContext)
|
|
158
|
+
);
|
|
159
|
+
return h(
|
|
160
|
+
_Cell,
|
|
161
|
+
{
|
|
162
|
+
intent,
|
|
163
|
+
value,
|
|
164
|
+
style,
|
|
165
|
+
// Use the editor-cell popover layout so the target fills the cell
|
|
166
|
+
// without the double-padding offset of `value-viewer-cell`.
|
|
167
|
+
className: "editor-cell",
|
|
168
|
+
interactive: false,
|
|
169
|
+
...cellComponentProps
|
|
170
|
+
},
|
|
171
|
+
panel
|
|
172
|
+
);
|
|
173
|
+
}
|
|
51
174
|
let cellContents = _renderedValue;
|
|
52
175
|
let _dataEditor = null;
|
|
53
176
|
let className = null;
|
|
54
|
-
if (
|
|
177
|
+
if (dataEditorSpec != null) {
|
|
55
178
|
_dataEditor = h(
|
|
56
179
|
EditorPopup,
|
|
57
180
|
{
|
|
58
|
-
autoFocus: autoFocusEditor,
|
|
59
181
|
valueViewer: _renderedValue
|
|
60
182
|
},
|
|
61
183
|
[
|
|
62
|
-
h(
|
|
184
|
+
h(dataEditorSpec, {
|
|
63
185
|
value,
|
|
64
186
|
editable,
|
|
65
187
|
isEdited: edited,
|
|
@@ -86,7 +208,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
86
208
|
value,
|
|
87
209
|
style,
|
|
88
210
|
className: className2,
|
|
89
|
-
interactive: false
|
|
211
|
+
interactive: false,
|
|
212
|
+
...cellComponentProps
|
|
90
213
|
},
|
|
91
214
|
cellContents
|
|
92
215
|
);
|
|
@@ -106,7 +229,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
106
229
|
_inlineEditor = h(EditorInput, {
|
|
107
230
|
className: "main-editor",
|
|
108
231
|
value: _value ?? "",
|
|
109
|
-
autoFocus:
|
|
232
|
+
autoFocus: focusOnOpen,
|
|
110
233
|
onChange
|
|
111
234
|
});
|
|
112
235
|
} else {
|
|
@@ -130,7 +253,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
130
253
|
value,
|
|
131
254
|
className,
|
|
132
255
|
style,
|
|
133
|
-
interactive: true
|
|
256
|
+
interactive: true,
|
|
257
|
+
...cellComponentProps
|
|
134
258
|
//truncated: false,
|
|
135
259
|
},
|
|
136
260
|
[
|
|
@@ -143,11 +267,23 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEdito
|
|
|
143
267
|
function EditorInput(props) {
|
|
144
268
|
const { value, onChange, ...rest } = props;
|
|
145
269
|
const onKeyDown = ctx.useValue(editorKeyHandlerAtom);
|
|
270
|
+
const navDirection = useSelector((s) => s.lastNavDirection);
|
|
271
|
+
const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);
|
|
272
|
+
const inputRef = useRef(null);
|
|
146
273
|
const [_value, setValue] = useState(value);
|
|
147
274
|
useEffect(() => {
|
|
148
275
|
setValue(value);
|
|
149
276
|
}, [value]);
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
const el = inputRef.current;
|
|
279
|
+
if (el == null || !surfaceOpen) return;
|
|
280
|
+
el.focus();
|
|
281
|
+
const atStart = navDirection === "up" || navDirection === "left";
|
|
282
|
+
const pos = atStart ? 0 : el.value?.length ?? 0;
|
|
283
|
+
el.setSelectionRange(pos, pos);
|
|
284
|
+
}, [surfaceOpen]);
|
|
150
285
|
return h("input", {
|
|
286
|
+
ref: inputRef,
|
|
151
287
|
onKeyDown,
|
|
152
288
|
onBlur: onChange,
|
|
153
289
|
value: _value ?? value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import { ColumnSpec, editorKeyHandlerAtom } from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useState } from \"react\";\nimport { EditorPopup } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n autoFocusEditor = true,\n filteredRowIndices?: number[] | null,\n): any {\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n const _renderedValue = isEmpty ? null : (col.valueRenderer?.(value) ?? value);\n\n let style = col.style ?? {};\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n let intent = edited ? \"success\" : undefined;\n if (isDeleted) {\n intent = \"danger\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n let inlineEditor = editable ? (col.inlineEditor ?? true) : false;\n\n if (!topLeft) {\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (col.dataEditor != null) {\n _dataEditor = h(\n EditorPopup,\n {\n autoFocus: autoFocusEditor,\n valueViewer: _renderedValue,\n },\n [\n h(col.dataEditor, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: autoFocusEditor,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n return h(\"input\", {\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["value","className"],"mappings":";;;;;;;;AASO,SAAS,kBACd,UACA,UACA,YACA,OACA,kBAAkB,MAClB,oBACK;AAGL,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY,KAAK,mBAAmB;AAEtE,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ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EA,SAAS,YAAY,OAAO;AAC1B,QAAM,EAAE,OAAO,UAAU,GAAG,SAAS;AACrC,QAAM,YAAY,IAAI,SAAS,oBAAoB;AACnD,QAAM,CAAC,QAAQ,QAAQ,IAAI,SAAS,KAAK;AACzC,YAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACV,SAAO,EAAE,SAAS;AAAA,IAChB;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAc,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAO,EAAE,0BAA0B,EAAE,aAAa;AACpD;"}
|
|
1
|
+
{"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object\n let style = { ...(col.style ?? {}) };\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > deleted > edited. Validation state\n // overrides the edited-green so an edited-but-invalid cell reads as invalid.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (isDeleted) {\n intent = \"danger\";\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["value","className"],"mappings":";;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY,KAAK,mBAAmB;AAEtE,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,QACxC,MAAM,UAAU,YAAY,MAAM,mBAAmB;AAGvD,QAAM,aAAa,YAAY,OAAO,aAAa,KAAK,OAAO,KAAK,YAAY;AAKhF,QAAM,cAAoC;AAAA,IACxC;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,EAAA;AAGF,QAAM,iBAAiB,UACnB,OACC,IAAI,gBAAgB,OA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B,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAc,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAO,EAAE,0BAA0B,EAAE,aAAa;AACpD;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const core = require("@blueprintjs/core");
|
|
4
|
+
const main_module = require("./main.module.sass.cjs");
|
|
5
|
+
const provider = require("../provider.cjs");
|
|
6
|
+
function CellDetailModal({ title, valueViewer, children }) {
|
|
7
|
+
const isOpen = provider.useSelector((s) => s.cellSurfaceOpen);
|
|
8
|
+
const closeCellSurface = provider.useSelector((s) => s.closeCellSurface);
|
|
9
|
+
const tableElement = provider.useSelector((s) => s.tableElement);
|
|
10
|
+
const onClose = () => {
|
|
11
|
+
closeCellSurface?.();
|
|
12
|
+
tableElement?.focus?.();
|
|
13
|
+
};
|
|
14
|
+
return main_module.default([
|
|
15
|
+
valueViewer,
|
|
16
|
+
main_module.default(
|
|
17
|
+
core.Dialog,
|
|
18
|
+
{ isOpen, onClose, title, canEscapeKeyClose: true, canOutsideClickClose: true },
|
|
19
|
+
main_module.default("div.bp6-dialog-body", children)
|
|
20
|
+
)
|
|
21
|
+
]);
|
|
22
|
+
}
|
|
23
|
+
exports.CellDetailModal = CellDetailModal;
|
|
24
|
+
//# sourceMappingURL=cell-detail.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-detail.cjs","sources":["../../src/components/cell-detail.ts"],"sourcesContent":["import { Dialog } from \"@blueprintjs/core\";\nimport h from \"./main.module.sass\";\nimport { useSelector } from \"../provider\";\n\n/**\n * Modal presentation for a cell's `cellDetail` surface. Subscribes to the\n * store's `cellSurfaceOpen` so the dialog opens/closes reactively (Escape,\n * the close button, and outside-click all route through `closeCellSurface`).\n * Rendering the dialog from a plain render snapshot would leave it unable to\n * close, since the cell renderer isn't re-invoked on every store change.\n */\nexport function CellDetailModal({ title, valueViewer, children }) {\n const isOpen = useSelector((s) => s.cellSurfaceOpen);\n const closeCellSurface = useSelector((s) => s.closeCellSurface);\n const tableElement = useSelector((s) => s.tableElement);\n\n const onClose = () => {\n closeCellSurface?.();\n tableElement?.focus?.();\n };\n\n return h([\n valueViewer,\n h(\n Dialog,\n { isOpen, onClose, title, canEscapeKeyClose: true, canOutsideClickClose: true },\n h(\"div.bp6-dialog-body\", children),\n ),\n ]);\n}\n"],"names":["useSelector","h","Dialog"],"mappings":";;;;;AAWO,SAAS,gBAAgB,EAAE,OAAO,aAAa,YAAY;AAChE,QAAM,SAASA,SAAAA,YAAY,CAAC,MAAM,EAAE,eAAe;AACnD,QAAM,mBAAmBA,SAAAA,YAAY,CAAC,MAAM,EAAE,gBAAgB;AAC9D,QAAM,eAAeA,SAAAA,YAAY,CAAC,MAAM,EAAE,YAAY;AAEtD,QAAM,UAAU,MAAM;AACpB,uBAAA;AACA,kBAAc,QAAA;AAAA,EAChB;AAEA,SAAOC,oBAAE;AAAA,IACP;AAAA,IACAA,YAAAA;AAAAA,MACEC,KAAAA;AAAAA,MACA,EAAE,QAAQ,SAAS,OAAO,mBAAmB,MAAM,sBAAsB,KAAA;AAAA,MACzED,YAAAA,QAAE,uBAAuB,QAAQ;AAAA,IAAA;AAAA,EACnC,CACD;AACH;;"}
|