@macrostrat/data-sheet 3.1.0 → 4.0.0-dev2
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 +19 -0
- 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 +44 -41
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.d.ts +1 -6
- package/dist/cell-renderer.js +45 -42
- package/dist/cell-renderer.js.map +1 -1
- 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 +3 -2
- 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 +184 -156
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +14 -1
- package/dist/core.js +187 -157
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +181 -43
- package/dist/index.cjs +43 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -10
- 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 +13 -16
- 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 +58 -26
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +57 -23
- 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 +58 -4
- 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 +141 -52
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +2 -3
- package/dist/utils/key-handling.js +142 -53
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +216 -51
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +197 -32
- package/dist/zustand-store.js.map +1 -1
- package/package.json +5 -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 +55 -51
- 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 +243 -170
- package/src/index.ts +1 -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 +258 -84
- 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 +63 -20
- 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 +58 -3
- package/src/utils/column-spec.ts +47 -0
- package/src/utils/key-handling.ts +181 -72
- package/src/zustand-store.ts +241 -36
- package/dist/provider.d.ts +0 -15
package/src/cell-renderer.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ColumnSpec, editorKeyHandlerAtom } from "./utils";
|
|
2
|
-
import { DataSheetStore } from "./types.ts";
|
|
2
|
+
import { DataSheetStore, TableElementStatus } from "./types.ts";
|
|
3
3
|
import h from "./main.module.sass";
|
|
4
|
-
import { ReactNode } from "react";
|
|
4
|
+
import { ReactNode, useEffect, useState } from "react";
|
|
5
5
|
import { EditorPopup } from "./components";
|
|
6
6
|
import { singleFocusedCell } from "./zustand-store.ts";
|
|
7
7
|
import { Cell } from "@blueprintjs/table";
|
|
8
|
-
import {
|
|
8
|
+
import { ctx, useSelector } from "./provider.ts";
|
|
9
9
|
|
|
10
10
|
export function basicCellRenderer<T>(
|
|
11
11
|
rowIndex: number,
|
|
@@ -13,58 +13,60 @@ export function basicCellRenderer<T>(
|
|
|
13
13
|
columnSpec: ColumnSpec,
|
|
14
14
|
state: DataSheetStore<T>,
|
|
15
15
|
autoFocusEditor = true,
|
|
16
|
+
filteredRowIndices?: number[] | null,
|
|
16
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
|
+
|
|
17
25
|
const data = state.data;
|
|
18
26
|
const updatedData = state.updatedData;
|
|
19
27
|
|
|
20
|
-
const isDeleted = state.
|
|
28
|
+
const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;
|
|
21
29
|
|
|
22
|
-
const row = data[
|
|
30
|
+
const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
|
|
23
31
|
const loading = row == null;
|
|
24
32
|
const col = columnSpec;
|
|
25
33
|
|
|
26
34
|
const _topLeftCell = state.topLeftCell;
|
|
27
35
|
const onCellEdited = state.onCellEdited;
|
|
28
36
|
|
|
29
|
-
const value
|
|
30
|
-
|
|
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);
|
|
31
41
|
|
|
32
42
|
let style = col.style ?? {};
|
|
43
|
+
|
|
33
44
|
if (isDeleted) {
|
|
34
|
-
style =
|
|
35
|
-
|
|
36
|
-
opacity: 0.5,
|
|
37
|
-
textDecoration: "line-through",
|
|
38
|
-
};
|
|
45
|
+
style.opacity = 0.5;
|
|
46
|
+
style.textDecoration = "line-through";
|
|
39
47
|
}
|
|
40
48
|
|
|
41
|
-
//const focused =
|
|
42
|
-
// focusedCell?.col === colIndex && focusedCell?.row === rowIndex;
|
|
43
|
-
|
|
44
49
|
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
45
50
|
|
|
46
|
-
//
|
|
51
|
+
// topLeftCell stores visible row indices, so compare with the visible rowIndex
|
|
47
52
|
const topLeft =
|
|
48
53
|
_topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
// If the cell is not editable but the sheet is editable, we want to differentiate
|
|
52
|
-
// between editable and non-editable cells.
|
|
53
|
-
style.color = "var(--secondary-color)";
|
|
54
|
-
}
|
|
55
|
+
const tableIsEditable = state.editable;
|
|
55
56
|
|
|
56
|
-
const edited =
|
|
57
|
+
const edited =
|
|
58
|
+
updatedData[dataRowIndex]?.[col.key] != null ||
|
|
59
|
+
state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;
|
|
57
60
|
let intent = edited ? "success" : undefined;
|
|
58
61
|
if (isDeleted) {
|
|
59
62
|
intent = "danger";
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
const _Cell = col.cellComponent ??
|
|
65
|
+
const _Cell = col.cellComponent ?? Cell;
|
|
63
66
|
|
|
64
67
|
let inlineEditor = editable ? (col.inlineEditor ?? true) : false;
|
|
65
68
|
|
|
66
69
|
if (!topLeft) {
|
|
67
|
-
// This should be the case for every cell except the focused one
|
|
68
70
|
return h(
|
|
69
71
|
_Cell,
|
|
70
72
|
{
|
|
@@ -72,7 +74,8 @@ export function basicCellRenderer<T>(
|
|
|
72
74
|
loading,
|
|
73
75
|
value,
|
|
74
76
|
style,
|
|
75
|
-
|
|
77
|
+
disabled: tableIsEditable && !editable,
|
|
78
|
+
interactive: false,
|
|
76
79
|
},
|
|
77
80
|
_renderedValue,
|
|
78
81
|
);
|
|
@@ -80,12 +83,6 @@ export function basicCellRenderer<T>(
|
|
|
80
83
|
|
|
81
84
|
// The rest is for the top-left cell of a selection or the focused cell
|
|
82
85
|
|
|
83
|
-
// Hidden input to capture key events
|
|
84
|
-
let hiddenInput = h(EditorInput, {
|
|
85
|
-
className: "hidden-input",
|
|
86
|
-
autoFocus: true,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
86
|
let cellContents: ReactNode = _renderedValue;
|
|
90
87
|
|
|
91
88
|
let _dataEditor = null;
|
|
@@ -102,22 +99,24 @@ export function basicCellRenderer<T>(
|
|
|
102
99
|
h(col.dataEditor, {
|
|
103
100
|
value,
|
|
104
101
|
editable,
|
|
102
|
+
isEdited: edited,
|
|
105
103
|
onChange(value) {
|
|
106
104
|
if (!editable) return;
|
|
107
105
|
state.onSelectionEdited(value);
|
|
108
106
|
},
|
|
107
|
+
resetValue() {
|
|
108
|
+
state.resetChanges();
|
|
109
|
+
},
|
|
109
110
|
}),
|
|
110
111
|
],
|
|
111
112
|
);
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
if (!editable) {
|
|
115
|
-
// Most cells are not focused and don't need to be editable.
|
|
116
|
-
// This will be the rendering logic for almost all cells
|
|
117
|
-
|
|
118
116
|
if (_dataEditor != null) {
|
|
119
117
|
cellContents = _dataEditor;
|
|
120
118
|
}
|
|
119
|
+
const className = "value-viewer-cell";
|
|
121
120
|
|
|
122
121
|
return h(
|
|
123
122
|
_Cell,
|
|
@@ -125,18 +124,20 @@ export function basicCellRenderer<T>(
|
|
|
125
124
|
intent,
|
|
126
125
|
value,
|
|
127
126
|
style,
|
|
127
|
+
className,
|
|
128
|
+
interactive: false,
|
|
128
129
|
},
|
|
129
130
|
cellContents,
|
|
130
131
|
);
|
|
131
|
-
// Could probably put the hidden input elsewhere,
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/* The remaining logic covers cells that are focused and editable */
|
|
135
135
|
|
|
136
136
|
const onChange = (e) => {
|
|
137
137
|
if (!editable) return;
|
|
138
|
-
if (
|
|
139
|
-
|
|
138
|
+
if (_renderedValue === e.target.value) return;
|
|
139
|
+
// Use dataRowIndex for the actual data mutation
|
|
140
|
+
onCellEdited(dataRowIndex, col.key, e.target.value);
|
|
140
141
|
};
|
|
141
142
|
|
|
142
143
|
const isSingleCellSelection = singleFocusedCell(state.selection) != null;
|
|
@@ -162,6 +163,11 @@ export function basicCellRenderer<T>(
|
|
|
162
163
|
_inlineEditor = inlineEditor as ReactNode;
|
|
163
164
|
}
|
|
164
165
|
|
|
166
|
+
let hiddenInput: React.ReactNode = h(EditorInput, {
|
|
167
|
+
className: "hidden-input",
|
|
168
|
+
autoFocus: true,
|
|
169
|
+
});
|
|
170
|
+
|
|
165
171
|
if (_dataEditor != null) {
|
|
166
172
|
className = "editor-cell";
|
|
167
173
|
cellContents = _dataEditor;
|
|
@@ -180,21 +186,30 @@ export function basicCellRenderer<T>(
|
|
|
180
186
|
value,
|
|
181
187
|
className,
|
|
182
188
|
style,
|
|
189
|
+
interactive: true,
|
|
183
190
|
//truncated: false,
|
|
184
191
|
},
|
|
185
192
|
[
|
|
186
193
|
cellContents,
|
|
187
194
|
h.if(editable && isSingleCellSelection)(DragHandle),
|
|
188
|
-
hiddenInput,
|
|
195
|
+
//hiddenInput,
|
|
189
196
|
],
|
|
190
197
|
);
|
|
191
198
|
}
|
|
192
199
|
|
|
193
200
|
function EditorInput(props) {
|
|
194
|
-
const
|
|
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]);
|
|
195
207
|
return h("input", {
|
|
196
208
|
onKeyDown,
|
|
197
|
-
|
|
209
|
+
onBlur: onChange,
|
|
210
|
+
value: _value ?? value,
|
|
211
|
+
onChange: (e) => setValue(e.target.value),
|
|
212
|
+
...rest,
|
|
198
213
|
});
|
|
199
214
|
}
|
|
200
215
|
|
|
@@ -204,14 +219,3 @@ function DragHandle() {
|
|
|
204
219
|
const onMouseDown = useSelector((state) => state.onDragValue);
|
|
205
220
|
return h("div.corner-drag-handle", { onMouseDown });
|
|
206
221
|
}
|
|
207
|
-
|
|
208
|
-
export function BaseCell({ children, value, ...rest }) {
|
|
209
|
-
return h(
|
|
210
|
-
Cell,
|
|
211
|
-
{
|
|
212
|
-
interactive: true,
|
|
213
|
-
...rest,
|
|
214
|
-
},
|
|
215
|
-
children,
|
|
216
|
-
);
|
|
217
|
-
}
|
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
|
+
}
|