@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.
Files changed (185) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/actions/builtin.cjs +56 -0
  3. package/dist/actions/builtin.cjs.map +1 -0
  4. package/dist/actions/builtin.d.ts +15 -0
  5. package/dist/actions/builtin.js +56 -0
  6. package/dist/actions/builtin.js.map +1 -0
  7. package/dist/actions/clipboard.cjs +250 -0
  8. package/dist/actions/clipboard.cjs.map +1 -0
  9. package/dist/actions/clipboard.d.ts +42 -0
  10. package/dist/actions/clipboard.js +250 -0
  11. package/dist/actions/clipboard.js.map +1 -0
  12. package/dist/actions/filters.cjs +123 -0
  13. package/dist/actions/filters.cjs.map +1 -0
  14. package/dist/actions/filters.d.ts +6 -0
  15. package/dist/actions/filters.js +123 -0
  16. package/dist/actions/filters.js.map +1 -0
  17. package/dist/actions/index.d.ts +6 -0
  18. package/dist/actions/selection.cjs +194 -0
  19. package/dist/actions/selection.cjs.map +1 -0
  20. package/dist/actions/selection.d.ts +40 -0
  21. package/dist/actions/selection.js +192 -0
  22. package/dist/actions/selection.js.map +1 -0
  23. package/dist/actions/toolbar.cjs +171 -0
  24. package/dist/actions/toolbar.cjs.map +1 -0
  25. package/dist/actions/toolbar.d.ts +10 -0
  26. package/dist/actions/toolbar.js +171 -0
  27. package/dist/actions/toolbar.js.map +1 -0
  28. package/dist/actions/toolbar.module.sass.cjs +22 -0
  29. package/dist/actions/toolbar.module.sass.cjs.map +1 -0
  30. package/dist/actions/toolbar.module.sass.js +20 -0
  31. package/dist/actions/toolbar.module.sass.js.map +1 -0
  32. package/dist/actions/types.d.ts +143 -0
  33. package/dist/cell-renderer.cjs +165 -0
  34. package/dist/cell-renderer.cjs.map +1 -0
  35. package/dist/cell-renderer.d.ts +3 -0
  36. package/dist/cell-renderer.js +165 -0
  37. package/dist/cell-renderer.js.map +1 -0
  38. package/dist/components/actions.module.sass.cjs +3 -3
  39. package/dist/components/actions.module.sass.js +2 -2
  40. package/dist/components/colors.cjs +20 -16
  41. package/dist/components/colors.cjs.map +1 -1
  42. package/dist/components/colors.d.ts +4 -3
  43. package/dist/components/colors.js +20 -16
  44. package/dist/components/colors.js.map +1 -1
  45. package/dist/components/editor-popup.cjs +4 -3
  46. package/dist/components/editor-popup.cjs.map +1 -1
  47. package/dist/components/editor-popup.js +4 -3
  48. package/dist/components/editor-popup.js.map +1 -1
  49. package/dist/components/index.d.ts +1 -0
  50. package/dist/components/main.module.sass.cjs +12 -12
  51. package/dist/components/main.module.sass.js +11 -11
  52. package/dist/components/text-areas.cjs +23 -18
  53. package/dist/components/text-areas.cjs.map +1 -1
  54. package/dist/components/text-areas.d.ts +8 -4
  55. package/dist/components/text-areas.js +20 -13
  56. package/dist/components/text-areas.js.map +1 -1
  57. package/dist/components/view-info.cjs +18 -0
  58. package/dist/components/view-info.cjs.map +1 -0
  59. package/dist/components/view-info.d.ts +1 -0
  60. package/dist/components/view-info.js +18 -0
  61. package/dist/components/view-info.js.map +1 -0
  62. package/dist/core.cjs +201 -300
  63. package/dist/core.cjs.map +1 -1
  64. package/dist/core.d.ts +18 -10
  65. package/dist/core.js +204 -299
  66. package/dist/core.js.map +1 -1
  67. package/dist/data-sheet.css +190 -52
  68. package/dist/index.cjs +47 -8
  69. package/dist/index.cjs.map +1 -1
  70. package/dist/index.d.ts +3 -0
  71. package/dist/index.js +48 -9
  72. package/dist/index.js.map +1 -1
  73. package/dist/main.module.sass.cjs +15 -14
  74. package/dist/main.module.sass.cjs.map +1 -1
  75. package/dist/main.module.sass.js +14 -13
  76. package/dist/main.module.sass.js.map +1 -1
  77. package/dist/notifications.cjs +19 -0
  78. package/dist/notifications.cjs.map +1 -0
  79. package/dist/notifications.d.ts +9 -0
  80. package/dist/notifications.js +19 -0
  81. package/dist/notifications.js.map +1 -0
  82. package/dist/postgrest-table/data-loaders.cjs +181 -104
  83. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  84. package/dist/postgrest-table/data-loaders.d.ts +52 -28
  85. package/dist/postgrest-table/data-loaders.js +181 -104
  86. package/dist/postgrest-table/data-loaders.js.map +1 -1
  87. package/dist/postgrest-table/index.cjs +205 -79
  88. package/dist/postgrest-table/index.cjs.map +1 -1
  89. package/dist/postgrest-table/index.d.ts +14 -17
  90. package/dist/postgrest-table/index.js +186 -58
  91. package/dist/postgrest-table/index.js.map +1 -1
  92. package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
  93. package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
  94. package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
  95. package/dist/postgrest-table/lazy-loader-table.js +17 -14
  96. package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
  97. package/dist/postgrest-table/loading-utils.cjs +16 -0
  98. package/dist/postgrest-table/loading-utils.cjs.map +1 -0
  99. package/dist/postgrest-table/loading-utils.d.ts +13 -0
  100. package/dist/postgrest-table/loading-utils.js +16 -0
  101. package/dist/postgrest-table/loading-utils.js.map +1 -0
  102. package/dist/postgrest-table/main.module.sass.cjs +18 -13
  103. package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
  104. package/dist/postgrest-table/main.module.sass.js +18 -13
  105. package/dist/postgrest-table/main.module.sass.js.map +1 -1
  106. package/dist/provider.cjs +96 -344
  107. package/dist/provider.cjs.map +1 -1
  108. package/dist/provider.js +96 -343
  109. package/dist/provider.js.map +1 -1
  110. package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
  111. package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
  112. package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
  113. package/dist/renderers/column-header-cell-postgrest.js +216 -0
  114. package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
  115. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
  116. package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
  117. package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
  118. package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
  119. package/dist/renderers/column-header-cell.cjs +103 -0
  120. package/dist/renderers/column-header-cell.cjs.map +1 -0
  121. package/dist/renderers/column-header-cell.d.ts +30 -0
  122. package/dist/renderers/column-header-cell.js +101 -0
  123. package/dist/renderers/column-header-cell.js.map +1 -0
  124. package/dist/renderers/index.d.ts +2 -0
  125. package/dist/table-updates/data-parameter.d.ts +14 -0
  126. package/dist/table-updates/filter.d.ts +16 -0
  127. package/dist/table-updates/index.d.ts +19 -0
  128. package/dist/types.cjs +9 -0
  129. package/dist/types.cjs.map +1 -0
  130. package/dist/types.d.ts +108 -0
  131. package/dist/types.js +9 -0
  132. package/dist/types.js.map +1 -0
  133. package/dist/utils/column-spec.cjs +9 -1
  134. package/dist/utils/column-spec.cjs.map +1 -1
  135. package/dist/utils/column-spec.d.ts +21 -0
  136. package/dist/utils/column-spec.js +9 -1
  137. package/dist/utils/column-spec.js.map +1 -1
  138. package/dist/utils/key-handling.cjs +161 -47
  139. package/dist/utils/key-handling.cjs.map +1 -1
  140. package/dist/utils/key-handling.d.ts +3 -3
  141. package/dist/utils/key-handling.js +161 -47
  142. package/dist/utils/key-handling.js.map +1 -1
  143. package/dist/zustand-store.cjs +485 -0
  144. package/dist/zustand-store.cjs.map +1 -0
  145. package/dist/zustand-store.d.ts +6 -0
  146. package/dist/zustand-store.js +483 -0
  147. package/dist/zustand-store.js.map +1 -0
  148. package/package.json +6 -5
  149. package/src/actions/builtin.ts +65 -0
  150. package/src/actions/clipboard.ts +350 -0
  151. package/src/actions/filters.ts +150 -0
  152. package/src/actions/index.ts +6 -0
  153. package/src/actions/selection.ts +271 -0
  154. package/src/actions/toolbar.module.sass +30 -0
  155. package/src/actions/toolbar.ts +212 -0
  156. package/src/actions/types.ts +159 -0
  157. package/src/cell-renderer.ts +221 -0
  158. package/src/components/colors.ts +22 -19
  159. package/src/components/editor-popup.ts +3 -2
  160. package/src/components/index.ts +1 -0
  161. package/src/components/main.module.sass +1 -0
  162. package/src/components/text-areas.ts +34 -19
  163. package/src/components/view-info.ts +17 -0
  164. package/src/core.ts +273 -360
  165. package/src/index.ts +4 -0
  166. package/src/main.module.sass +14 -2
  167. package/src/notifications.ts +22 -0
  168. package/src/postgrest-table/data-loaders.ts +300 -201
  169. package/src/postgrest-table/index.ts +260 -86
  170. package/src/postgrest-table/lazy-loader-table.ts +18 -17
  171. package/src/postgrest-table/loading-utils.ts +49 -0
  172. package/src/postgrest-table/main.module.sass +16 -0
  173. package/src/provider.ts +110 -487
  174. package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
  175. package/src/renderers/column-header-cell-postgrest.ts +282 -0
  176. package/src/renderers/column-header-cell.ts +388 -0
  177. package/src/renderers/index.ts +2 -0
  178. package/src/table-updates/data-parameter.ts +44 -0
  179. package/src/table-updates/filter.ts +124 -0
  180. package/src/table-updates/index.ts +239 -0
  181. package/src/types.ts +121 -0
  182. package/src/utils/column-spec.ts +47 -0
  183. package/src/utils/key-handling.ts +201 -66
  184. package/src/zustand-store.ts +582 -0
  185. package/dist/provider.d.ts +0 -69
@@ -1,58 +1,173 @@
1
1
  import type { KeyboardEvent } from "react";
2
- import { DataSheetStoreMain } from "@macrostrat/data-sheet";
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
- export function tableKeyHandler<T>(
10
+ type HotkeyActionRunner = (
5
11
  e: KeyboardEvent,
6
- state: DataSheetStoreMain<T>,
7
- ) {
8
- // General key event
9
- if (e.key === "Escape") {
10
- // Clear selection on Escape
11
- state.setSelection([]);
12
- e.preventDefault();
13
- e.stopPropagation();
14
- }
15
- // Clear selection on Backspace or Delete
16
- if (e.key === "Backspace" || e.key === "Delete") {
17
- // Clear selection on Backspace or Delete
18
- state.clearSelection();
19
- e.preventDefault();
20
- }
21
- // Handle arrow keys for navigation
22
- if (e.key in directionMap) {
23
- // Handle arrow key navigation
24
- const direction = directionMap[e.key];
25
- state.moveFocusedCell(direction);
26
- // Prevent default scrolling behavior
27
- e.preventDefault();
28
- }
29
- if (e.key === "Tab") {
30
- state.moveFocusedCell(e.shiftKey ? "left" : "right");
31
- e.preventDefault();
32
- }
33
- if (e.key === "Enter") {
34
- state.moveFocusedCell("down");
35
- e.preventDefault();
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 directionMap = {
40
- ArrowUp: "up",
41
- ArrowDown: "down",
42
- ArrowLeft: "left",
43
- ArrowRight: "right",
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
- export function editorKeyHandler(
47
- e: KeyboardEvent,
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
- // if (e.key == "Enter" || e.key == "Tab") {
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
- e.target.blur();
190
+ target.blur();
76
191
  e.preventDefault();
77
192
  return;
78
193
  }
79
194
 
80
- const shouldPropagate = handleSpecialKeys(e);
195
+ const shouldPropagate = shouldPropagateKeystroke(e);
81
196
  if (!shouldPropagate) {
82
197
  e.stopPropagation();
198
+ //e.preventDefault();
83
199
  } else {
84
- e.target.blur();
85
- //e.target.parentNode.dispatchEvent(new KeyboardEvent("keydown", e));
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
- export function multiLineTextKeyHandler(evt: InputEvent) {
90
- if (evt.key === "Enter") {
91
- //evt.preventDefault();
92
- evt.stopPropagation();
93
- return;
94
- }
95
-
96
- if (evt.key === "Escape") {
97
- evt.preventDefault();
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
- const shouldPropagate = handleSpecialKeys(evt);
102
- if (!shouldPropagate) {
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
+ }