@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
|
@@ -1,58 +1,173 @@
|
|
|
1
1
|
import type { KeyboardEvent } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { storeAPIAtom, storeAtom, tableActionsAtom } from "../provider";
|
|
3
|
+
import type { DataSheetStoreMain } from "../types";
|
|
4
|
+
import { atom } from "jotai";
|
|
5
|
+
import { singleFocusedCell } from "../zustand-store.ts";
|
|
6
|
+
import { buildActionContext, runActionWrapper } from "../actions";
|
|
7
|
+
import { HotkeyConfig } from "@blueprintjs/core";
|
|
8
|
+
import { toasterAtom } from "../notifications.ts";
|
|
3
9
|
|
|
4
|
-
|
|
10
|
+
type HotkeyActionRunner = (
|
|
5
11
|
e: KeyboardEvent,
|
|
6
|
-
state: DataSheetStoreMain<
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
state: DataSheetStoreMain<any>,
|
|
13
|
+
setState: (state: Partial<DataSheetStoreMain<any>>) => void,
|
|
14
|
+
) => void | Promise<void>;
|
|
15
|
+
|
|
16
|
+
const isEditableAtom = atom((get) => {
|
|
17
|
+
const store = get(storeAtom);
|
|
18
|
+
return store?.editable ?? false;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const hasSelectionAtom = atom((get) => {
|
|
22
|
+
const store = get(storeAtom);
|
|
23
|
+
const selection = store?.selection ?? [];
|
|
24
|
+
return selection.length > 0;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const tableHotkeysAtom = atom<HotkeyConfig[]>((get) => {
|
|
28
|
+
const store = get(storeAPIAtom);
|
|
29
|
+
const toaster = get(toasterAtom);
|
|
30
|
+
const editable = get(isEditableAtom);
|
|
31
|
+
|
|
32
|
+
/** Set up hotkeys for table actions */
|
|
33
|
+
const tableActions = get(tableActionsAtom);
|
|
34
|
+
|
|
35
|
+
if (store == null) return [];
|
|
36
|
+
const keyHandler = (
|
|
37
|
+
actionRunner: HotkeyActionRunner,
|
|
38
|
+
): HotkeyConfig["onKeyDown"] => {
|
|
39
|
+
return (e) => {
|
|
40
|
+
// Kind of a ridiculous hack to get the store from the atom.
|
|
41
|
+
const state = store.getState();
|
|
42
|
+
const setState = store.setState;
|
|
43
|
+
try {
|
|
44
|
+
const res = actionRunner(e, state, setState);
|
|
45
|
+
if (res instanceof Promise) {
|
|
46
|
+
res
|
|
47
|
+
.then(() => {})
|
|
48
|
+
.catch((err) => {
|
|
49
|
+
console.error(err);
|
|
50
|
+
handleError(toaster, err);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
handleError(toaster, err);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function handleError(toaster, err) {
|
|
60
|
+
toaster.show({
|
|
61
|
+
message: `${err}`,
|
|
62
|
+
intent: "danger",
|
|
63
|
+
});
|
|
36
64
|
}
|
|
37
|
-
}
|
|
38
65
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
const directionCombos = ["up", "down", "left", "right"].map((dir) => {
|
|
67
|
+
return {
|
|
68
|
+
combo: dir,
|
|
69
|
+
group: "Navigation",
|
|
70
|
+
label: "Move focus " + dir,
|
|
71
|
+
preventDefault: true,
|
|
72
|
+
onKeyDown: keyHandler((e, state) => {
|
|
73
|
+
state.moveFocusedCell(dir);
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
45
77
|
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
/** TODO: merge a bit more with the actions config */
|
|
79
|
+
|
|
80
|
+
const actionsCombos = tableActions
|
|
81
|
+
.map((action) => {
|
|
82
|
+
if (action.hotkey == null) return null;
|
|
83
|
+
return {
|
|
84
|
+
combo: action.hotkey,
|
|
85
|
+
label: action.name,
|
|
86
|
+
group: action.group ?? "Actions",
|
|
87
|
+
preventDefault: true,
|
|
88
|
+
disabled: action.requiresEditable !== false && !editable,
|
|
89
|
+
onKeyDown(event: KeyboardEvent<any>): any {
|
|
90
|
+
const state = store.getState();
|
|
91
|
+
const setState = store.setState;
|
|
92
|
+
runActionWrapper(action, state, setState, toaster);
|
|
93
|
+
},
|
|
94
|
+
} as any as HotkeyConfig;
|
|
95
|
+
})
|
|
96
|
+
.filter(Boolean) as HotkeyConfig[];
|
|
97
|
+
|
|
98
|
+
return [
|
|
99
|
+
{
|
|
100
|
+
combo: "esc",
|
|
101
|
+
label: "Clear selection",
|
|
102
|
+
group: "Selection",
|
|
103
|
+
allowInInput: true,
|
|
104
|
+
onKeyDown: keyHandler((e, state) => {
|
|
105
|
+
if (state.selection.length == 0) {
|
|
106
|
+
// Focus goes back to parent
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
state.setSelection([]);
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
}),
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
combo: "backspace",
|
|
116
|
+
label: "Clear selection",
|
|
117
|
+
group: "Selection",
|
|
118
|
+
allowInInput: true,
|
|
119
|
+
disabled: !editable,
|
|
120
|
+
onKeyDown: keyHandler((e, state) => {
|
|
121
|
+
state.clearSelection();
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
combo: "tab",
|
|
126
|
+
label: "Move focus right (or left with shift)",
|
|
127
|
+
group: "Navigation",
|
|
128
|
+
allowInInput: true,
|
|
129
|
+
onKeyDown: keyHandler((e, state) => {
|
|
130
|
+
state.moveFocusedCell(e.shiftKey ? "left" : "right");
|
|
131
|
+
}),
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
combo: "enter",
|
|
135
|
+
label: "Move focus down",
|
|
136
|
+
group: "Navigation",
|
|
137
|
+
allowInInput: true,
|
|
138
|
+
onKeyDown: keyHandler((e, state) => {
|
|
139
|
+
state.moveFocusedCell("down");
|
|
140
|
+
}),
|
|
141
|
+
},
|
|
142
|
+
...directionCombos,
|
|
143
|
+
...actionsCombos,
|
|
144
|
+
];
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const selectionAtom = atom((get) => {
|
|
148
|
+
const store = get(storeAtom);
|
|
149
|
+
return store.selection;
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const isSingleCellSelectionAtom = atom((get) => {
|
|
153
|
+
const selection = get(selectionAtom);
|
|
154
|
+
return singleFocusedCell(selection) != null;
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export const editorKeyHandlerAtom = atom((get) => {
|
|
158
|
+
return (e: KeyboardEvent) => {
|
|
159
|
+
const isSingleCellSelection = get(isSingleCellSelectionAtom);
|
|
160
|
+
editorKeyHandler(e, isSingleCellSelection);
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
function editorKeyHandler(
|
|
165
|
+
e: KeyboardEvent<HTMLInputElement>,
|
|
48
166
|
isSingleCellSelection: boolean,
|
|
49
167
|
) {
|
|
50
168
|
/** Get a key handler for inline cell editing */
|
|
51
169
|
|
|
52
|
-
|
|
53
|
-
// e.target.blur();
|
|
54
|
-
// return;
|
|
55
|
-
// }
|
|
170
|
+
const target = e.target as HTMLInputElement;
|
|
56
171
|
|
|
57
172
|
let shouldCaptureEventForInlineEditing = true;
|
|
58
173
|
|
|
@@ -72,39 +187,41 @@ export function editorKeyHandler(
|
|
|
72
187
|
}
|
|
73
188
|
|
|
74
189
|
if (!shouldCaptureEventForInlineEditing) {
|
|
75
|
-
|
|
190
|
+
target.blur();
|
|
76
191
|
e.preventDefault();
|
|
77
192
|
return;
|
|
78
193
|
}
|
|
79
194
|
|
|
80
|
-
const shouldPropagate =
|
|
195
|
+
const shouldPropagate = shouldPropagateKeystroke(e);
|
|
81
196
|
if (!shouldPropagate) {
|
|
82
197
|
e.stopPropagation();
|
|
198
|
+
//e.preventDefault();
|
|
83
199
|
} else {
|
|
84
|
-
|
|
85
|
-
|
|
200
|
+
// we blur the editor and dispatch a keydown event on the parent to propagate the event to the table
|
|
201
|
+
e.preventDefault();
|
|
202
|
+
target.blur();
|
|
203
|
+
//console.log(tableElement);
|
|
204
|
+
//tableElement.focus();
|
|
205
|
+
//target.parentNode?.dispatchEvent(e);
|
|
206
|
+
target.parentNode?.dispatchEvent(new KeyboardEvent("keydown", e));
|
|
86
207
|
}
|
|
87
208
|
}
|
|
88
209
|
|
|
89
|
-
|
|
90
|
-
if (evt.
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return;
|
|
210
|
+
function shouldPropagateKeystroke(evt: KeyboardEvent): boolean {
|
|
211
|
+
if (evt.target.selectionStart == evt.target.selectionEnd) {
|
|
212
|
+
// We don't have anything selected, so we can propagate the event potentially
|
|
213
|
+
// Propagate copy and paste events even if there is no selection, since they might want to copy/paste an entire row/column based on the focused cell.
|
|
214
|
+
if (evt.key === "c" || evt.key === "v" || evt.key === "x") {
|
|
215
|
+
if (evt.ctrlKey || evt.metaKey) {
|
|
216
|
+
return true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
99
219
|
}
|
|
100
220
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
evt.stopPropagation();
|
|
221
|
+
if (evt.key === "ArrowUp" || evt.key === "ArrowDown") {
|
|
222
|
+
return true;
|
|
104
223
|
}
|
|
105
|
-
}
|
|
106
224
|
|
|
107
|
-
function handleSpecialKeys(evt: KeyboardEvent): boolean {
|
|
108
225
|
const target = evt.target;
|
|
109
226
|
if (
|
|
110
227
|
(evt.key === "ArrowLeft" ||
|
|
@@ -112,7 +229,6 @@ function handleSpecialKeys(evt: KeyboardEvent): boolean {
|
|
|
112
229
|
evt.key === "ArrowDown") &&
|
|
113
230
|
target.selectionStart === 0
|
|
114
231
|
) {
|
|
115
|
-
target.blur();
|
|
116
232
|
return true;
|
|
117
233
|
}
|
|
118
234
|
|
|
@@ -124,9 +240,28 @@ function handleSpecialKeys(evt: KeyboardEvent): boolean {
|
|
|
124
240
|
evt.key === "ArrowDown") &&
|
|
125
241
|
target.selectionStart === evt.target.value.length
|
|
126
242
|
) {
|
|
127
|
-
target.blur();
|
|
128
243
|
return true;
|
|
129
244
|
}
|
|
130
245
|
|
|
131
246
|
return false;
|
|
132
247
|
}
|
|
248
|
+
|
|
249
|
+
export function multiLineTextKeyHandler(evt: InputEvent) {
|
|
250
|
+
if (evt.key === "Enter") {
|
|
251
|
+
//evt.preventDefault();
|
|
252
|
+
evt.stopPropagation();
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (evt.key === "Escape") {
|
|
257
|
+
evt.preventDefault();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const shouldPropagate = shouldPropagateKeystroke(evt);
|
|
262
|
+
if (!shouldPropagate) {
|
|
263
|
+
evt.stopPropagation();
|
|
264
|
+
} else {
|
|
265
|
+
evt.target.blur();
|
|
266
|
+
}
|
|
267
|
+
}
|