@macrostrat/data-sheet 3.0.4 → 4.0.0-dev1
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 +20 -1
- package/dist/actions/builtin.cjs +56 -0
- package/dist/actions/builtin.cjs.map +1 -0
- package/dist/actions/builtin.d.ts +15 -0
- package/dist/actions/builtin.js +56 -0
- package/dist/actions/builtin.js.map +1 -0
- package/dist/actions/clipboard.cjs +250 -0
- package/dist/actions/clipboard.cjs.map +1 -0
- package/dist/actions/clipboard.d.ts +42 -0
- package/dist/actions/clipboard.js +250 -0
- package/dist/actions/clipboard.js.map +1 -0
- package/dist/actions/filters.cjs +123 -0
- package/dist/actions/filters.cjs.map +1 -0
- package/dist/actions/filters.d.ts +6 -0
- package/dist/actions/filters.js +123 -0
- package/dist/actions/filters.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/selection.cjs +194 -0
- package/dist/actions/selection.cjs.map +1 -0
- package/dist/actions/selection.d.ts +40 -0
- package/dist/actions/selection.js +192 -0
- package/dist/actions/selection.js.map +1 -0
- package/dist/actions/toolbar.cjs +171 -0
- package/dist/actions/toolbar.cjs.map +1 -0
- package/dist/actions/toolbar.d.ts +10 -0
- package/dist/actions/toolbar.js +171 -0
- package/dist/actions/toolbar.js.map +1 -0
- package/dist/actions/toolbar.module.sass.cjs +22 -0
- package/dist/actions/toolbar.module.sass.cjs.map +1 -0
- package/dist/actions/toolbar.module.sass.js +20 -0
- package/dist/actions/toolbar.module.sass.js.map +1 -0
- package/dist/actions/types.d.ts +143 -0
- package/dist/cell-renderer.cjs +165 -0
- package/dist/cell-renderer.cjs.map +1 -0
- package/dist/cell-renderer.d.ts +3 -0
- package/dist/cell-renderer.js +165 -0
- package/dist/cell-renderer.js.map +1 -0
- package/dist/components/actions.module.sass.cjs +3 -3
- package/dist/components/actions.module.sass.js +2 -2
- package/dist/components/colors.cjs +20 -16
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.d.ts +4 -3
- package/dist/components/colors.js +20 -16
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +4 -3
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +4 -3
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/main.module.sass.cjs +12 -12
- package/dist/components/main.module.sass.js +11 -11
- package/dist/components/text-areas.cjs +23 -18
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +8 -4
- package/dist/components/text-areas.js +20 -13
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +18 -0
- package/dist/components/view-info.cjs.map +1 -0
- package/dist/components/view-info.d.ts +1 -0
- package/dist/components/view-info.js +18 -0
- package/dist/components/view-info.js.map +1 -0
- package/dist/core.cjs +201 -300
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +18 -10
- package/dist/core.js +204 -299
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +190 -52
- package/dist/index.cjs +47 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +48 -9
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +15 -14
- 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/notifications.cjs +19 -0
- package/dist/notifications.cjs.map +1 -0
- package/dist/notifications.d.ts +9 -0
- package/dist/notifications.js +19 -0
- package/dist/notifications.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +181 -104
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -28
- package/dist/postgrest-table/data-loaders.js +181 -104
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +205 -79
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +14 -17
- package/dist/postgrest-table/index.js +186 -58
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
- package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
- package/dist/postgrest-table/lazy-loader-table.js +17 -14
- package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +16 -0
- package/dist/postgrest-table/loading-utils.cjs.map +1 -0
- package/dist/postgrest-table/loading-utils.d.ts +13 -0
- package/dist/postgrest-table/loading-utils.js +16 -0
- package/dist/postgrest-table/loading-utils.js.map +1 -0
- package/dist/postgrest-table/main.module.sass.cjs +18 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +18 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +96 -344
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +96 -343
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
- package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
- package/dist/renderers/column-header-cell-postgrest.js +216 -0
- package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +103 -0
- package/dist/renderers/column-header-cell.cjs.map +1 -0
- package/dist/renderers/column-header-cell.d.ts +30 -0
- package/dist/renderers/column-header-cell.js +101 -0
- package/dist/renderers/column-header-cell.js.map +1 -0
- package/dist/renderers/index.d.ts +2 -0
- package/dist/table-updates/data-parameter.d.ts +14 -0
- package/dist/table-updates/filter.d.ts +16 -0
- package/dist/table-updates/index.d.ts +19 -0
- package/dist/types.cjs +9 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/column-spec.cjs +9 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +21 -0
- package/dist/utils/column-spec.js +9 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/key-handling.cjs +161 -47
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +3 -3
- package/dist/utils/key-handling.js +161 -47
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +485 -0
- package/dist/zustand-store.cjs.map +1 -0
- package/dist/zustand-store.d.ts +6 -0
- package/dist/zustand-store.js +483 -0
- package/dist/zustand-store.js.map +1 -0
- package/package.json +6 -5
- package/src/actions/builtin.ts +65 -0
- package/src/actions/clipboard.ts +350 -0
- package/src/actions/filters.ts +150 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/selection.ts +271 -0
- package/src/actions/toolbar.module.sass +30 -0
- package/src/actions/toolbar.ts +212 -0
- package/src/actions/types.ts +159 -0
- package/src/cell-renderer.ts +221 -0
- package/src/components/colors.ts +22 -19
- package/src/components/editor-popup.ts +3 -2
- package/src/components/index.ts +1 -0
- package/src/components/main.module.sass +1 -0
- package/src/components/text-areas.ts +34 -19
- package/src/components/view-info.ts +17 -0
- package/src/core.ts +273 -360
- package/src/index.ts +4 -0
- package/src/main.module.sass +14 -2
- package/src/notifications.ts +22 -0
- package/src/postgrest-table/data-loaders.ts +300 -201
- package/src/postgrest-table/index.ts +260 -86
- package/src/postgrest-table/lazy-loader-table.ts +18 -17
- package/src/postgrest-table/loading-utils.ts +49 -0
- package/src/postgrest-table/main.module.sass +16 -0
- package/src/provider.ts +110 -487
- package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
- package/src/renderers/column-header-cell-postgrest.ts +282 -0
- package/src/renderers/column-header-cell.ts +388 -0
- package/src/renderers/index.ts +2 -0
- package/src/table-updates/data-parameter.ts +44 -0
- package/src/table-updates/filter.ts +124 -0
- package/src/table-updates/index.ts +239 -0
- package/src/types.ts +121 -0
- package/src/utils/column-spec.ts +47 -0
- package/src/utils/key-handling.ts +201 -66
- package/src/zustand-store.ts +582 -0
- package/dist/provider.d.ts +0 -69
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { ColumnSpec, editorKeyHandlerAtom } from "./utils";
|
|
2
|
+
import { DataSheetStore, TableElementStatus } from "./types.ts";
|
|
3
|
+
import h from "./main.module.sass";
|
|
4
|
+
import { ReactNode, useEffect, useState } from "react";
|
|
5
|
+
import { EditorPopup } from "./components";
|
|
6
|
+
import { singleFocusedCell } from "./zustand-store.ts";
|
|
7
|
+
import { Cell } from "@blueprintjs/table";
|
|
8
|
+
import { ctx, useSelector } from "./provider.ts";
|
|
9
|
+
|
|
10
|
+
export function basicCellRenderer<T>(
|
|
11
|
+
rowIndex: number,
|
|
12
|
+
colIndex: number,
|
|
13
|
+
columnSpec: ColumnSpec,
|
|
14
|
+
state: DataSheetStore<T>,
|
|
15
|
+
autoFocusEditor = true,
|
|
16
|
+
filteredRowIndices?: number[] | null,
|
|
17
|
+
): any {
|
|
18
|
+
// When filters are active, `rowIndex` is the visible row position.
|
|
19
|
+
// Map it to the actual data index for data access.
|
|
20
|
+
const dataRowIndex =
|
|
21
|
+
filteredRowIndices != null
|
|
22
|
+
? (filteredRowIndices[rowIndex] ?? rowIndex)
|
|
23
|
+
: rowIndex;
|
|
24
|
+
|
|
25
|
+
const data = state.data;
|
|
26
|
+
const updatedData = state.updatedData;
|
|
27
|
+
|
|
28
|
+
const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;
|
|
29
|
+
|
|
30
|
+
const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
|
|
31
|
+
const loading = row == null;
|
|
32
|
+
const col = columnSpec;
|
|
33
|
+
|
|
34
|
+
const _topLeftCell = state.topLeftCell;
|
|
35
|
+
const onCellEdited = state.onCellEdited;
|
|
36
|
+
|
|
37
|
+
const value: T | undefined =
|
|
38
|
+
updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];
|
|
39
|
+
const isEmpty = value == null || value === "";
|
|
40
|
+
const _renderedValue = isEmpty ? null : (col.valueRenderer?.(value) ?? value);
|
|
41
|
+
|
|
42
|
+
let style = col.style ?? {};
|
|
43
|
+
|
|
44
|
+
if (isDeleted) {
|
|
45
|
+
style.opacity = 0.5;
|
|
46
|
+
style.textDecoration = "line-through";
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
50
|
+
|
|
51
|
+
// topLeftCell stores visible row indices, so compare with the visible rowIndex
|
|
52
|
+
const topLeft =
|
|
53
|
+
_topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
54
|
+
|
|
55
|
+
const tableIsEditable = state.editable;
|
|
56
|
+
|
|
57
|
+
const edited =
|
|
58
|
+
updatedData[dataRowIndex]?.[col.key] != null ||
|
|
59
|
+
state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
|
|
60
|
+
let intent = edited ? "success" : undefined;
|
|
61
|
+
if (isDeleted) {
|
|
62
|
+
intent = "danger";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const _Cell = col.cellComponent ?? Cell;
|
|
66
|
+
|
|
67
|
+
let inlineEditor = editable ? (col.inlineEditor ?? true) : false;
|
|
68
|
+
|
|
69
|
+
if (!topLeft) {
|
|
70
|
+
return h(
|
|
71
|
+
_Cell,
|
|
72
|
+
{
|
|
73
|
+
intent,
|
|
74
|
+
loading,
|
|
75
|
+
value,
|
|
76
|
+
style,
|
|
77
|
+
disabled: tableIsEditable && !editable,
|
|
78
|
+
interactive: false,
|
|
79
|
+
},
|
|
80
|
+
_renderedValue,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// The rest is for the top-left cell of a selection or the focused cell
|
|
85
|
+
|
|
86
|
+
let cellContents: ReactNode = _renderedValue;
|
|
87
|
+
|
|
88
|
+
let _dataEditor = null;
|
|
89
|
+
let className = null;
|
|
90
|
+
|
|
91
|
+
if (col.dataEditor != null) {
|
|
92
|
+
_dataEditor = h(
|
|
93
|
+
EditorPopup,
|
|
94
|
+
{
|
|
95
|
+
autoFocus: autoFocusEditor,
|
|
96
|
+
valueViewer: _renderedValue,
|
|
97
|
+
},
|
|
98
|
+
[
|
|
99
|
+
h(col.dataEditor, {
|
|
100
|
+
value,
|
|
101
|
+
editable,
|
|
102
|
+
isEdited: edited,
|
|
103
|
+
onChange(value) {
|
|
104
|
+
if (!editable) return;
|
|
105
|
+
state.onSelectionEdited(value);
|
|
106
|
+
},
|
|
107
|
+
resetValue() {
|
|
108
|
+
state.resetChanges();
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
],
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (!editable) {
|
|
116
|
+
if (_dataEditor != null) {
|
|
117
|
+
cellContents = _dataEditor;
|
|
118
|
+
}
|
|
119
|
+
const className = "value-viewer-cell";
|
|
120
|
+
|
|
121
|
+
return h(
|
|
122
|
+
_Cell,
|
|
123
|
+
{
|
|
124
|
+
intent,
|
|
125
|
+
value,
|
|
126
|
+
style,
|
|
127
|
+
className,
|
|
128
|
+
interactive: false,
|
|
129
|
+
},
|
|
130
|
+
cellContents,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* The remaining logic covers cells that are focused and editable */
|
|
135
|
+
|
|
136
|
+
const onChange = (e) => {
|
|
137
|
+
if (!editable) return;
|
|
138
|
+
if (_renderedValue === e.target.value) return;
|
|
139
|
+
// Use dataRowIndex for the actual data mutation
|
|
140
|
+
onCellEdited(dataRowIndex, col.key, e.target.value);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const isSingleCellSelection = singleFocusedCell(state.selection) != null;
|
|
144
|
+
|
|
145
|
+
let _inlineEditor: ReactNode = null;
|
|
146
|
+
if (typeof inlineEditor == "boolean") {
|
|
147
|
+
let _value = value;
|
|
148
|
+
if (
|
|
149
|
+
typeof _renderedValue === "string" ||
|
|
150
|
+
typeof _renderedValue === "number" ||
|
|
151
|
+
_renderedValue == null
|
|
152
|
+
) {
|
|
153
|
+
_value = _renderedValue;
|
|
154
|
+
}
|
|
155
|
+
_inlineEditor = h(EditorInput, {
|
|
156
|
+
className: "main-editor",
|
|
157
|
+
value: _value ?? "",
|
|
158
|
+
autoFocus: autoFocusEditor,
|
|
159
|
+
onChange,
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
// If inlineEditor is a ReactNode, we use it directly
|
|
163
|
+
_inlineEditor = inlineEditor as ReactNode;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let hiddenInput: React.ReactNode = h(EditorInput, {
|
|
167
|
+
className: "hidden-input",
|
|
168
|
+
autoFocus: true,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
if (_dataEditor != null) {
|
|
172
|
+
className = "editor-cell";
|
|
173
|
+
cellContents = _dataEditor;
|
|
174
|
+
hiddenInput = null;
|
|
175
|
+
} else if (_inlineEditor != null) {
|
|
176
|
+
cellContents = _inlineEditor;
|
|
177
|
+
className = "input-cell";
|
|
178
|
+
hiddenInput = null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Hidden html input
|
|
182
|
+
return h(
|
|
183
|
+
_Cell,
|
|
184
|
+
{
|
|
185
|
+
intent,
|
|
186
|
+
value,
|
|
187
|
+
className,
|
|
188
|
+
style,
|
|
189
|
+
interactive: true,
|
|
190
|
+
//truncated: false,
|
|
191
|
+
},
|
|
192
|
+
[
|
|
193
|
+
cellContents,
|
|
194
|
+
h.if(editable && isSingleCellSelection)(DragHandle),
|
|
195
|
+
//hiddenInput,
|
|
196
|
+
],
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function EditorInput(props) {
|
|
201
|
+
const { value, onChange, ...rest } = props;
|
|
202
|
+
const onKeyDown = ctx.useValue(editorKeyHandlerAtom);
|
|
203
|
+
const [_value, setValue] = useState(value);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
setValue(value);
|
|
206
|
+
}, [value]);
|
|
207
|
+
return h("input", {
|
|
208
|
+
onKeyDown,
|
|
209
|
+
onBlur: onChange,
|
|
210
|
+
value: _value ?? value,
|
|
211
|
+
onChange: (e) => setValue(e.target.value),
|
|
212
|
+
...rest,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function DragHandle() {
|
|
217
|
+
// TODO: we might want to drag multiple columns in some cases
|
|
218
|
+
// This should be on the last cell of a selection
|
|
219
|
+
const onMouseDown = useSelector((state) => state.onDragValue);
|
|
220
|
+
return h("div.corner-drag-handle", { onMouseDown });
|
|
221
|
+
}
|
package/src/components/colors.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { getLuminanceAdjustedColorScheme } from "@macrostrat/color-utils";
|
|
|
5
5
|
import { memoize } from "underscore";
|
|
6
6
|
import classNames from "classnames";
|
|
7
7
|
import { ColorPicker2 } from "@macrostrat/ui-components";
|
|
8
|
+
import { useMemo } from "react";
|
|
8
9
|
|
|
9
10
|
export const ColorPicker = ColorPicker2;
|
|
10
11
|
|
|
@@ -18,25 +19,31 @@ export function ColorCell({
|
|
|
18
19
|
...rest
|
|
19
20
|
}) {
|
|
20
21
|
const darkMode = useInDarkMode();
|
|
21
|
-
|
|
22
22
|
const _className = classNames(className, "color-cell");
|
|
23
|
+
const _style = useMemo(() => {
|
|
24
|
+
let mainColor = "var(--text-color)";
|
|
25
|
+
let backgroundColor = value;
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
if (adjustLuminance) {
|
|
28
|
+
// If adjustLuminance is true, get the color scheme based on the value
|
|
29
|
+
let colors = colorCombo(value, darkMode, 0.05);
|
|
30
|
+
if (colors != null) {
|
|
31
|
+
mainColor = colors.mainColor;
|
|
32
|
+
backgroundColor = colors.backgroundColor;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (colors != null) {
|
|
31
|
-
mainColor = colors.mainColor;
|
|
32
|
-
backgroundColor = colors.backgroundColor;
|
|
36
|
+
if (intent != null) {
|
|
37
|
+
// If an intent is specified, override the main color
|
|
38
|
+
mainColor = undefined;
|
|
33
39
|
}
|
|
34
|
-
}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
return {
|
|
42
|
+
...style,
|
|
43
|
+
color: mainColor,
|
|
44
|
+
backgroundColor,
|
|
45
|
+
};
|
|
46
|
+
}, [value, intent, adjustLuminance, darkMode, style]);
|
|
40
47
|
|
|
41
48
|
return h(
|
|
42
49
|
Cell,
|
|
@@ -44,11 +51,7 @@ export function ColorCell({
|
|
|
44
51
|
intent,
|
|
45
52
|
className: _className,
|
|
46
53
|
...rest,
|
|
47
|
-
style:
|
|
48
|
-
color: mainColor,
|
|
49
|
-
backgroundColor,
|
|
50
|
-
...style,
|
|
51
|
-
},
|
|
54
|
+
style: _style,
|
|
52
55
|
},
|
|
53
56
|
children,
|
|
54
57
|
);
|
|
@@ -53,6 +53,7 @@ export function EditorPopup(props) {
|
|
|
53
53
|
enforceFocus: false,
|
|
54
54
|
autoFocus: false,
|
|
55
55
|
animation: "minimal",
|
|
56
|
+
//arrow: false,
|
|
56
57
|
lazy: true,
|
|
57
58
|
// modifiers: {
|
|
58
59
|
// offset: { enabled: true, options: { offset: [0, 8] } },
|
|
@@ -61,10 +62,10 @@ export function EditorPopup(props) {
|
|
|
61
62
|
interactionKind: "hover-target",
|
|
62
63
|
isOpen,
|
|
63
64
|
// Portal must be used to avoid issues with the editor being clipped to the bounds of the cell
|
|
64
|
-
usePortal: true,
|
|
65
|
+
//usePortal: true,
|
|
65
66
|
},
|
|
66
67
|
h(
|
|
67
|
-
"span.editor-popup-target
|
|
68
|
+
"span.editor-popup-target",
|
|
68
69
|
{
|
|
69
70
|
className: targetClassName,
|
|
70
71
|
onClick: () => setIsOpen(!isOpen),
|
package/src/components/index.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import
|
|
2
|
-
import styles from "./main.module.sass";
|
|
1
|
+
import h from "./main.module.sass";
|
|
3
2
|
import { Button } from "@blueprintjs/core";
|
|
4
|
-
import { useEffect, useRef } from "react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
5
4
|
import { multiLineTextKeyHandler } from "../utils";
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
export type DataEditorProps = {
|
|
7
|
+
value: string;
|
|
8
|
+
editable: boolean;
|
|
9
|
+
onChange: (value: string) => void;
|
|
10
|
+
isEdited?: boolean;
|
|
11
|
+
resetValue?: () => void;
|
|
12
|
+
};
|
|
8
13
|
|
|
9
|
-
export function EditableTextArea({
|
|
14
|
+
export function EditableTextArea({
|
|
15
|
+
value,
|
|
16
|
+
onChange,
|
|
17
|
+
isEdited,
|
|
18
|
+
resetValue,
|
|
19
|
+
}: DataEditorProps) {
|
|
10
20
|
const ref = useRef(null);
|
|
11
21
|
|
|
22
|
+
// const [_value, setValue] = useState(value);
|
|
23
|
+
//
|
|
24
|
+
// useEffect(() => {
|
|
25
|
+
// setValue(value);
|
|
26
|
+
// }, [value]);
|
|
27
|
+
|
|
12
28
|
useEffect(() => {
|
|
13
29
|
if (ref.current == null) return;
|
|
14
30
|
ref.current.focus();
|
|
@@ -21,26 +37,25 @@ export function EditableTextArea({ value, onChange }) {
|
|
|
21
37
|
return h("div.editable-text-area", [
|
|
22
38
|
h("textarea.bp6-input", {
|
|
23
39
|
ref,
|
|
24
|
-
|
|
25
|
-
onChange: (evt) =>
|
|
40
|
+
defaultValue: value ?? "",
|
|
41
|
+
//onChange: (evt) => setValue(evt.target.value),
|
|
42
|
+
onBlur: (evt) => {
|
|
43
|
+
if (evt.target.value !== value) {
|
|
44
|
+
onChange(evt.target.value);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
26
47
|
onKeyDown: multiLineTextKeyHandler,
|
|
27
48
|
}),
|
|
28
49
|
h("div.tools", [
|
|
50
|
+
// Tool to reset the value to the default
|
|
29
51
|
h(Button, {
|
|
30
|
-
icon: "
|
|
52
|
+
icon: "undo",
|
|
31
53
|
minimal: true,
|
|
32
54
|
small: true,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const cursorPos = ref.current.selectionStart ?? _value.length;
|
|
38
|
-
// Insert a newline at the cursor position
|
|
39
|
-
onChange(_value.slice(0, cursorPos) + "\n" + _value.slice(cursorPos));
|
|
40
|
-
// Re-focus the textarea
|
|
41
|
-
ref.current.focus();
|
|
42
|
-
// Move the cursor to the end of the line
|
|
43
|
-
ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);
|
|
55
|
+
intent: isEdited ? "success" : "none",
|
|
56
|
+
disabled: !isEdited,
|
|
57
|
+
onClick(evt) {
|
|
58
|
+
resetValue?.();
|
|
44
59
|
},
|
|
45
60
|
}),
|
|
46
61
|
]),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import h from "../postgrest-table/main.module.sass";
|
|
2
|
+
import { ViewInfo, viewInfoAtom } from "../postgrest-table";
|
|
3
|
+
import { ctx } from "../provider.ts";
|
|
4
|
+
|
|
5
|
+
function ViewInfoControl() {
|
|
6
|
+
const viewInfo: ViewInfo = ctx.useValue(viewInfoAtom);
|
|
7
|
+
|
|
8
|
+
return h("p", [
|
|
9
|
+
`Rows ${viewInfo.visibleRegion.rowIndexStart}–${viewInfo.visibleRegion.rowIndexEnd}`,
|
|
10
|
+
" of ",
|
|
11
|
+
h("span.total-count", viewInfo.totalCount),
|
|
12
|
+
]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function InfoBar() {
|
|
16
|
+
return h("div.info-bar", [h(ViewInfoControl)]);
|
|
17
|
+
}
|