@macrostrat/data-sheet 4.1.1 → 4.2.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.
Files changed (303) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/actions/builtin.cjs +1 -1
  3. package/dist/actions/builtin.cjs.map +1 -1
  4. package/dist/actions/builtin.d.ts +0 -2
  5. package/dist/actions/builtin.js +1 -1
  6. package/dist/actions/builtin.js.map +1 -1
  7. package/dist/actions/clipboard.cjs +1 -1
  8. package/dist/actions/clipboard.cjs.map +1 -1
  9. package/dist/actions/clipboard.d.ts +3 -2
  10. package/dist/actions/clipboard.js +1 -1
  11. package/dist/actions/clipboard.js.map +1 -1
  12. package/dist/actions/column-controls.cjs +7 -196
  13. package/dist/actions/column-controls.cjs.map +1 -1
  14. package/dist/actions/column-controls.d.ts +1 -1
  15. package/dist/actions/column-controls.js +5 -194
  16. package/dist/actions/column-controls.js.map +1 -1
  17. package/dist/actions/column-filter.cjs +24 -73
  18. package/dist/actions/column-filter.cjs.map +1 -1
  19. package/dist/actions/column-filter.d.ts +6 -4
  20. package/dist/actions/column-filter.js +25 -74
  21. package/dist/actions/column-filter.js.map +1 -1
  22. package/dist/actions/context.cjs +147 -0
  23. package/dist/actions/context.cjs.map +1 -0
  24. package/dist/actions/context.d.ts +93 -0
  25. package/dist/actions/context.js +145 -0
  26. package/dist/actions/context.js.map +1 -0
  27. package/dist/actions/edit-actions.cjs.map +1 -1
  28. package/dist/actions/edit-actions.d.ts +3 -1
  29. package/dist/actions/edit-actions.js.map +1 -1
  30. package/dist/actions/index.d.ts +2 -3
  31. package/dist/actions/selection.cjs +70 -115
  32. package/dist/actions/selection.cjs.map +1 -1
  33. package/dist/actions/selection.d.ts +22 -12
  34. package/dist/actions/selection.js +71 -114
  35. package/dist/actions/selection.js.map +1 -1
  36. package/dist/actions/table-actions.cjs +41 -0
  37. package/dist/actions/table-actions.cjs.map +1 -0
  38. package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
  39. package/dist/actions/{table-controls.js → table-actions.js} +2 -23
  40. package/dist/actions/table-actions.js.map +1 -0
  41. package/dist/actions/types.d.ts +11 -89
  42. package/dist/components/cell-detail.cjs +6 -6
  43. package/dist/components/cell-detail.cjs.map +1 -1
  44. package/dist/components/cell-detail.js +1 -1
  45. package/dist/components/colors.cjs.map +1 -1
  46. package/dist/components/colors.js.map +1 -1
  47. package/dist/components/editor-popup.cjs +7 -7
  48. package/dist/components/editor-popup.cjs.map +1 -1
  49. package/dist/components/editor-popup.js +1 -1
  50. package/dist/components/index.d.ts +2 -1
  51. package/dist/components/indicators/filter-and-sort.cjs +378 -0
  52. package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
  53. package/dist/components/indicators/filter-and-sort.d.ts +59 -0
  54. package/dist/components/indicators/filter-and-sort.js +376 -0
  55. package/dist/components/indicators/filter-and-sort.js.map +1 -0
  56. package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
  57. package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
  58. package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
  59. package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
  60. package/dist/components/indicators/index.d.ts +4 -0
  61. package/dist/components/indicators/selection.cjs +113 -0
  62. package/dist/components/indicators/selection.cjs.map +1 -0
  63. package/dist/components/indicators/selection.d.ts +3 -0
  64. package/dist/components/indicators/selection.js +111 -0
  65. package/dist/components/indicators/selection.js.map +1 -0
  66. package/dist/components/indicators/selection.module.sass.cjs +19 -0
  67. package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
  68. package/dist/components/indicators/selection.module.sass.js +17 -0
  69. package/dist/components/indicators/selection.module.sass.js.map +1 -0
  70. package/dist/components/indicators/unified-filters.cjs +130 -0
  71. package/dist/components/indicators/unified-filters.cjs.map +1 -0
  72. package/dist/components/indicators/unified-filters.d.ts +10 -0
  73. package/dist/components/indicators/unified-filters.js +130 -0
  74. package/dist/components/indicators/unified-filters.js.map +1 -0
  75. package/dist/components/indicators/view-info.cjs +59 -0
  76. package/dist/components/indicators/view-info.cjs.map +1 -0
  77. package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
  78. package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
  79. package/dist/components/indicators/view-info.js.map +1 -0
  80. package/dist/components/text-areas.cjs +5 -5
  81. package/dist/components/text-areas.cjs.map +1 -1
  82. package/dist/components/text-areas.js +1 -1
  83. package/dist/components/toolbars/actions-toolbar.cjs +185 -0
  84. package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
  85. package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
  86. package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
  87. package/dist/components/toolbars/actions-toolbar.js.map +1 -0
  88. package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
  89. package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
  90. package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
  91. package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
  92. package/dist/components/toolbars/active-filters.cjs +120 -0
  93. package/dist/components/toolbars/active-filters.cjs.map +1 -0
  94. package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
  95. package/dist/components/toolbars/active-filters.js +120 -0
  96. package/dist/components/toolbars/active-filters.js.map +1 -0
  97. package/dist/components/toolbars/index.d.ts +2 -0
  98. package/dist/data-panel.cjs +291 -0
  99. package/dist/data-panel.cjs.map +1 -0
  100. package/dist/data-panel.d.ts +110 -0
  101. package/dist/data-panel.js +289 -0
  102. package/dist/data-panel.js.map +1 -0
  103. package/dist/data-panel.module.sass.cjs +40 -0
  104. package/dist/data-panel.module.sass.cjs.map +1 -0
  105. package/dist/data-panel.module.sass.js +38 -0
  106. package/dist/data-panel.module.sass.js.map +1 -0
  107. package/dist/{core.cjs → data-sheet.cjs} +123 -190
  108. package/dist/data-sheet.cjs.map +1 -0
  109. package/dist/data-sheet.css +241 -13
  110. package/dist/data-sheet.d.ts +16 -0
  111. package/dist/{core.js → data-sheet.js} +92 -159
  112. package/dist/data-sheet.js.map +1 -0
  113. package/dist/data-view.cjs +47 -0
  114. package/dist/data-view.cjs.map +1 -0
  115. package/dist/data-view.d.ts +15 -0
  116. package/dist/data-view.js +45 -0
  117. package/dist/data-view.js.map +1 -0
  118. package/dist/filters/operators.cjs +19 -2
  119. package/dist/filters/operators.cjs.map +1 -1
  120. package/dist/filters/operators.d.ts +4 -3
  121. package/dist/filters/operators.js +19 -2
  122. package/dist/filters/operators.js.map +1 -1
  123. package/dist/index.cjs +106 -47
  124. package/dist/index.cjs.map +1 -1
  125. package/dist/index.d.ts +4 -3
  126. package/dist/index.js +76 -17
  127. package/dist/index.js.map +1 -1
  128. package/dist/notifications.cjs +4 -4
  129. package/dist/notifications.cjs.map +1 -1
  130. package/dist/notifications.js +1 -1
  131. package/dist/postgrest-table/data-loaders.cjs +128 -95
  132. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  133. package/dist/postgrest-table/data-loaders.d.ts +52 -82
  134. package/dist/postgrest-table/data-loaders.js +109 -76
  135. package/dist/postgrest-table/data-loaders.js.map +1 -1
  136. package/dist/postgrest-table/index.cjs +18 -17
  137. package/dist/postgrest-table/index.cjs.map +1 -1
  138. package/dist/postgrest-table/index.d.ts +4 -3
  139. package/dist/postgrest-table/index.js +9 -8
  140. package/dist/postgrest-table/index.js.map +1 -1
  141. package/dist/{utils → provider}/column-spec.cjs +23 -9
  142. package/dist/provider/column-spec.cjs.map +1 -0
  143. package/dist/{utils → provider}/column-spec.d.ts +73 -2
  144. package/dist/{utils → provider}/column-spec.js +24 -10
  145. package/dist/provider/column-spec.js.map +1 -0
  146. package/dist/provider/core.cjs +382 -0
  147. package/dist/provider/core.cjs.map +1 -0
  148. package/dist/provider/core.d.ts +74 -0
  149. package/dist/provider/core.js +380 -0
  150. package/dist/provider/core.js.map +1 -0
  151. package/dist/provider/index.d.ts +7 -0
  152. package/dist/provider/interactions.cjs +128 -0
  153. package/dist/provider/interactions.cjs.map +1 -0
  154. package/dist/provider/interactions.d.ts +39 -0
  155. package/dist/provider/interactions.js +128 -0
  156. package/dist/provider/interactions.js.map +1 -0
  157. package/dist/provider/selection.cjs +29 -0
  158. package/dist/provider/selection.cjs.map +1 -0
  159. package/dist/provider/selection.d.ts +9 -0
  160. package/dist/provider/selection.js +29 -0
  161. package/dist/provider/selection.js.map +1 -0
  162. package/dist/provider/table-data.cjs +92 -0
  163. package/dist/provider/table-data.cjs.map +1 -0
  164. package/dist/provider/table-data.d.ts +81 -0
  165. package/dist/provider/table-data.js +92 -0
  166. package/dist/provider/table-data.js.map +1 -0
  167. package/dist/provider/types.cjs +22 -0
  168. package/dist/provider/types.cjs.map +1 -0
  169. package/dist/provider/types.d.ts +256 -0
  170. package/dist/provider/types.js +22 -0
  171. package/dist/provider/types.js.map +1 -0
  172. package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
  173. package/dist/provider/zustand-store.cjs.map +1 -0
  174. package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
  175. package/dist/provider/zustand-store.js.map +1 -0
  176. package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
  177. package/dist/renderers/cell-renderer.cjs.map +1 -0
  178. package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
  179. package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
  180. package/dist/renderers/cell-renderer.js.map +1 -0
  181. package/dist/renderers/column-header-cell.cjs +21 -13
  182. package/dist/renderers/column-header-cell.cjs.map +1 -1
  183. package/dist/renderers/column-header-cell.d.ts +3 -2
  184. package/dist/renderers/column-header-cell.js +20 -12
  185. package/dist/renderers/column-header-cell.js.map +1 -1
  186. package/dist/renderers/index.d.ts +1 -0
  187. package/dist/types.cjs +7 -19
  188. package/dist/types.cjs.map +1 -1
  189. package/dist/types.d.ts +117 -229
  190. package/dist/types.js +7 -19
  191. package/dist/types.js.map +1 -1
  192. package/dist/utils/atoms.cjs +24 -0
  193. package/dist/utils/atoms.cjs.map +1 -0
  194. package/dist/utils/atoms.d.ts +4 -0
  195. package/dist/utils/atoms.js +24 -0
  196. package/dist/utils/atoms.js.map +1 -0
  197. package/dist/utils/debug-overlay.cjs.map +1 -1
  198. package/dist/utils/debug-overlay.js.map +1 -1
  199. package/dist/utils/index.d.ts +2 -3
  200. package/dist/utils/key-handling.cjs +140 -139
  201. package/dist/utils/key-handling.cjs.map +1 -1
  202. package/dist/utils/key-handling.d.ts +4 -2
  203. package/dist/utils/key-handling.js +136 -135
  204. package/dist/utils/key-handling.js.map +1 -1
  205. package/dist/utils/validation.cjs +6 -1
  206. package/dist/utils/validation.cjs.map +1 -1
  207. package/dist/utils/validation.d.ts +1 -1
  208. package/dist/utils/validation.js +6 -1
  209. package/dist/utils/validation.js.map +1 -1
  210. package/package.json +4 -3
  211. package/src/actions/builtin.ts +1 -4
  212. package/src/actions/clipboard.ts +4 -3
  213. package/src/actions/column-controls.ts +12 -245
  214. package/src/actions/column-filter.ts +28 -92
  215. package/src/actions/context.ts +299 -0
  216. package/src/actions/edit-actions.ts +3 -1
  217. package/src/actions/index.ts +2 -3
  218. package/src/actions/selection.ts +109 -156
  219. package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
  220. package/src/actions/types.ts +17 -101
  221. package/src/components/colors.ts +1 -1
  222. package/src/components/index.ts +2 -1
  223. package/src/components/indicators/filter-and-sort.module.sass +13 -0
  224. package/src/components/indicators/filter-and-sort.ts +478 -0
  225. package/src/components/indicators/index.ts +4 -0
  226. package/src/components/indicators/selection.module.sass +22 -0
  227. package/src/components/indicators/selection.ts +141 -0
  228. package/src/components/indicators/unified-filters.ts +161 -0
  229. package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
  230. package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
  231. package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
  232. package/src/components/toolbars/active-filters.ts +150 -0
  233. package/src/components/toolbars/index.ts +2 -0
  234. package/src/data-panel.module.sass +185 -0
  235. package/src/data-panel.ts +556 -0
  236. package/src/{core.ts → data-sheet.ts} +145 -330
  237. package/src/data-view.ts +70 -0
  238. package/src/filters/operators.ts +33 -3
  239. package/src/index.ts +4 -3
  240. package/src/postgrest-table/data-loaders.ts +244 -171
  241. package/src/postgrest-table/index.ts +10 -9
  242. package/src/{utils → provider}/column-spec.ts +30 -15
  243. package/src/provider/core.ts +585 -0
  244. package/src/provider/index.ts +7 -0
  245. package/src/provider/interactions.ts +161 -0
  246. package/src/provider/selection.ts +31 -0
  247. package/src/provider/table-data.ts +178 -0
  248. package/src/provider/types.ts +273 -0
  249. package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
  250. package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
  251. package/src/renderers/column-header-cell.ts +21 -14
  252. package/src/renderers/index.ts +1 -0
  253. package/src/types.ts +137 -239
  254. package/src/utils/atoms.ts +28 -0
  255. package/src/utils/debug-overlay.ts +1 -1
  256. package/src/utils/index.ts +2 -8
  257. package/src/utils/key-handling.ts +170 -164
  258. package/src/utils/validation.ts +7 -2
  259. package/dist/actions/filters.cjs +0 -139
  260. package/dist/actions/filters.cjs.map +0 -1
  261. package/dist/actions/filters.js +0 -139
  262. package/dist/actions/filters.js.map +0 -1
  263. package/dist/actions/table-controls.cjs +0 -62
  264. package/dist/actions/table-controls.cjs.map +0 -1
  265. package/dist/actions/table-controls.js.map +0 -1
  266. package/dist/actions/toolbar.cjs +0 -260
  267. package/dist/actions/toolbar.cjs.map +0 -1
  268. package/dist/actions/toolbar.js.map +0 -1
  269. package/dist/actions/toolbar.module.sass.cjs +0 -27
  270. package/dist/actions/toolbar.module.sass.cjs.map +0 -1
  271. package/dist/actions/toolbar.module.sass.js +0 -25
  272. package/dist/actions/toolbar.module.sass.js.map +0 -1
  273. package/dist/cell-renderer.cjs.map +0 -1
  274. package/dist/cell-renderer.js.map +0 -1
  275. package/dist/components/view-info.cjs +0 -55
  276. package/dist/components/view-info.cjs.map +0 -1
  277. package/dist/components/view-info.js.map +0 -1
  278. package/dist/core.cjs.map +0 -1
  279. package/dist/core.d.ts +0 -117
  280. package/dist/core.js.map +0 -1
  281. package/dist/provider.cjs +0 -197
  282. package/dist/provider.cjs.map +0 -1
  283. package/dist/provider.d.ts +0 -26
  284. package/dist/provider.js +0 -195
  285. package/dist/provider.js.map +0 -1
  286. package/dist/table-updates/data-parameter.d.ts +0 -14
  287. package/dist/table-updates/filter.d.ts +0 -16
  288. package/dist/table-updates/index.d.ts +0 -19
  289. package/dist/utils/column-spec.cjs.map +0 -1
  290. package/dist/utils/column-spec.js.map +0 -1
  291. package/dist/utils/index.cjs +0 -9
  292. package/dist/utils/index.cjs.map +0 -1
  293. package/dist/utils/index.js +0 -9
  294. package/dist/utils/index.js.map +0 -1
  295. package/dist/zustand-store.cjs.map +0 -1
  296. package/dist/zustand-store.js.map +0 -1
  297. package/src/actions/filters.ts +0 -176
  298. package/src/components/actions.module.sass +0 -8
  299. package/src/provider.ts +0 -267
  300. package/src/table-updates/data-parameter.ts +0 -44
  301. package/src/table-updates/filter.ts +0 -124
  302. package/src/table-updates/index.ts +0 -239
  303. /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
@@ -1,169 +1,170 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const provider = require("../provider.cjs");
4
3
  const jotai = require("jotai");
5
- const zustandStore = require("../zustand-store.cjs");
6
4
  const notifications = require("../notifications.cjs");
7
- const toolbar = require("../actions/toolbar.cjs");
5
+ const core = require("../provider/core.cjs");
6
+ const context = require("../actions/context.cjs");
7
+ const zustandStore = require("../provider/zustand-store.cjs");
8
8
  const isEditableAtom = jotai.atom((get) => {
9
- const store = get(provider.storeAtom);
9
+ const store = get(core.storeAtom);
10
10
  return store?.editable ?? false;
11
11
  });
12
12
  jotai.atom((get) => {
13
- const store = get(provider.storeAtom);
13
+ const store = get(core.storeAtom);
14
14
  const selection = store?.selection ?? [];
15
15
  return selection.length > 0;
16
16
  });
17
- const tableHotkeysAtom = jotai.atom((get) => {
18
- const store = get(provider.storeAPIAtom);
19
- const toaster = get(notifications.toasterAtom);
20
- const editable = get(isEditableAtom);
21
- const tableActions = get(provider.tableActionsAtom);
22
- if (store == null) return [];
23
- const keyHandler = (actionRunner) => {
24
- return (e) => {
25
- const state = store.getState();
26
- const setState = store.setState;
27
- try {
28
- const res = actionRunner(e, state, setState);
29
- if (res instanceof Promise) {
30
- res.then(() => {
31
- }).catch((err) => {
32
- console.error(err);
33
- handleError(toaster, err);
34
- });
35
- }
36
- } catch (err) {
37
- handleError(toaster, err);
38
- }
39
- };
40
- };
41
- function handleError(toaster2, err) {
42
- toaster2.show({
43
- message: `${err}`,
44
- intent: "danger"
45
- });
46
- }
47
- const directionCombos = ["up", "down", "left", "right"].map((dir) => {
48
- return {
49
- combo: dir,
50
- group: "Navigation",
51
- label: "Move focus " + dir,
52
- preventDefault: true,
53
- onKeyDown: keyHandler((e, state) => {
54
- state.moveFocusedCell(dir);
55
- })
56
- };
57
- });
58
- const actionsCombos = tableActions.map((action) => {
59
- if (action.hotkey == null) return null;
60
- return {
61
- combo: action.hotkey,
62
- label: action.name,
63
- group: action.group ?? "Actions",
64
- preventDefault: true,
65
- disabled: action.requiresEditable !== false && !editable,
66
- onKeyDown(event) {
17
+ const tableHotkeysAtom = jotai.atom(
18
+ null,
19
+ (get, set) => {
20
+ const store = get(core.storeAPIAtom);
21
+ const toaster = get(notifications.toasterAtom);
22
+ const editable = get(isEditableAtom);
23
+ const tableActions = get(core.tableActionsAtom);
24
+ if (store == null) return [];
25
+ const keyHandler = (actionRunner) => {
26
+ return (e) => {
67
27
  const state = store.getState();
68
28
  const setState = store.setState;
69
- toolbar.runActionWrapper(action, state, setState, toaster);
70
- }
29
+ try {
30
+ const res = actionRunner(e, state, setState);
31
+ if (res instanceof Promise) {
32
+ res.then(() => {
33
+ }).catch((err) => {
34
+ console.error(err);
35
+ handleError(toaster, err);
36
+ });
37
+ }
38
+ } catch (err) {
39
+ handleError(toaster, err);
40
+ }
41
+ };
71
42
  };
72
- }).filter(Boolean);
73
- const clearOrDeleteSelection = keyHandler((e, state) => {
74
- const sel = state.selection ?? [];
75
- const isRowSelection = sel.length > 0 && sel.every((r) => r.cols == null && r.rows != null);
76
- if (isRowSelection) {
77
- state.deleteSelectedRows();
78
- } else {
79
- state.clearSelection();
43
+ function handleError(toaster2, err) {
44
+ toaster2.show({
45
+ message: `${err}`,
46
+ intent: "danger"
47
+ });
80
48
  }
81
- });
82
- return [
83
- {
84
- combo: "esc",
85
- label: "Exit editing / clear selection",
86
- group: "Selection",
87
- allowInInput: true,
88
- onKeyDown: keyHandler((e, state) => {
89
- if (state.cellSurfaceOpen) {
90
- state.closeCellSurface();
49
+ const directionCombos = ["up", "down", "left", "right"].map((dir) => {
50
+ return {
51
+ combo: dir,
52
+ group: "Navigation",
53
+ label: "Move focus " + dir,
54
+ preventDefault: true,
55
+ onKeyDown: keyHandler((e, state) => {
56
+ state.moveFocusedCell(dir);
57
+ })
58
+ };
59
+ });
60
+ const actionsCombos = tableActions.map((action) => {
61
+ if (action.hotkey == null) return null;
62
+ return {
63
+ combo: action.hotkey,
64
+ label: action.name,
65
+ group: action.group ?? "Actions",
66
+ preventDefault: true,
67
+ disabled: action.requiresEditable !== false && !editable,
68
+ onKeyDown(event) {
69
+ context.runActionWrapper(action, get, set, toaster);
70
+ }
71
+ };
72
+ }).filter(Boolean);
73
+ const clearOrDeleteSelection = keyHandler((e, state) => {
74
+ const sel = state.selection ?? [];
75
+ const isRowSelection = sel.length > 0 && sel.every((r) => r.cols == null && r.rows != null);
76
+ if (isRowSelection) {
77
+ state.deleteSelectedRows();
78
+ } else {
79
+ state.clearSelection();
80
+ }
81
+ });
82
+ return [
83
+ {
84
+ combo: "esc",
85
+ label: "Exit editing / clear selection",
86
+ group: "Selection",
87
+ allowInInput: true,
88
+ onKeyDown: keyHandler((e, state) => {
89
+ if (state.cellSurfaceOpen) {
90
+ state.closeCellSurface();
91
+ e.preventDefault();
92
+ e.stopPropagation();
93
+ return;
94
+ }
95
+ if (state.selection.length == 0) {
96
+ return;
97
+ }
98
+ state.setSelection([]);
91
99
  e.preventDefault();
92
100
  e.stopPropagation();
93
- return;
94
- }
95
- if (state.selection.length == 0) {
96
- return;
97
- }
98
- state.setSelection([]);
99
- e.preventDefault();
100
- e.stopPropagation();
101
- })
102
- },
103
- {
104
- combo: "backspace",
105
- label: "Clear cells / delete rows",
106
- group: "Selection",
107
- allowInInput: true,
108
- disabled: !editable,
109
- onKeyDown: clearOrDeleteSelection
110
- },
111
- {
112
- combo: "del",
113
- label: "Clear cells / delete rows",
114
- group: "Selection",
115
- allowInInput: true,
116
- disabled: !editable,
117
- onKeyDown: clearOrDeleteSelection
118
- },
119
- {
120
- combo: "tab",
121
- label: "Move focus right (or left with shift)",
122
- group: "Navigation",
123
- allowInInput: true,
124
- onKeyDown: keyHandler((e, state) => {
125
- state.moveFocusedCell(e.shiftKey ? "left" : "right");
126
- })
127
- },
128
- {
129
- combo: "enter",
130
- label: "Edit cell / move focus down",
131
- group: "Navigation",
132
- allowInInput: true,
133
- onKeyDown: keyHandler((e, state) => {
134
- if (!state.cellSurfaceOpen) {
101
+ })
102
+ },
103
+ {
104
+ combo: "backspace",
105
+ label: "Clear cells / delete rows",
106
+ group: "Selection",
107
+ allowInInput: true,
108
+ disabled: !editable,
109
+ onKeyDown: clearOrDeleteSelection
110
+ },
111
+ {
112
+ combo: "del",
113
+ label: "Clear cells / delete rows",
114
+ group: "Selection",
115
+ allowInInput: true,
116
+ disabled: !editable,
117
+ onKeyDown: clearOrDeleteSelection
118
+ },
119
+ {
120
+ combo: "tab",
121
+ label: "Move focus right (or left with shift)",
122
+ group: "Navigation",
123
+ allowInInput: true,
124
+ onKeyDown: keyHandler((e, state) => {
125
+ state.moveFocusedCell(e.shiftKey ? "left" : "right");
126
+ })
127
+ },
128
+ {
129
+ combo: "enter",
130
+ label: "Edit cell / move focus down",
131
+ group: "Navigation",
132
+ allowInInput: true,
133
+ onKeyDown: keyHandler((e, state) => {
134
+ if (!state.cellSurfaceOpen) {
135
+ state.armAutoActivate();
136
+ state.openCellSurface();
137
+ e.preventDefault();
138
+ return;
139
+ }
140
+ state.moveFocusedCell("down");
141
+ })
142
+ },
143
+ {
144
+ combo: "f2",
145
+ label: "Edit / open cell",
146
+ group: "Editing",
147
+ onKeyDown: keyHandler((e, state) => {
135
148
  state.armAutoActivate();
136
149
  state.openCellSurface();
137
150
  e.preventDefault();
138
- return;
139
- }
140
- state.moveFocusedCell("down");
141
- })
142
- },
143
- {
144
- combo: "f2",
145
- label: "Edit / open cell",
146
- group: "Editing",
147
- onKeyDown: keyHandler((e, state) => {
148
- state.armAutoActivate();
149
- state.openCellSurface();
150
- e.preventDefault();
151
- })
152
- },
153
- ...directionCombos,
154
- ...actionsCombos
155
- ];
156
- });
151
+ })
152
+ },
153
+ ...directionCombos,
154
+ ...actionsCombos
155
+ ];
156
+ }
157
+ );
157
158
  const selectionAtom = jotai.atom((get) => {
158
- const store = get(provider.storeAtom);
159
- return store.selection;
159
+ const store = get(core.storeAtom);
160
+ return store?.selection ?? [];
160
161
  });
161
162
  const isSingleCellSelectionAtom = jotai.atom((get) => {
162
163
  const selection = get(selectionAtom);
163
164
  return zustandStore.singleFocusedCell(selection) != null;
164
165
  });
165
166
  const editorKeyHandlerAtom = jotai.atom((get) => {
166
- const store = get(provider.storeAPIAtom);
167
+ const store = get(core.storeAPIAtom);
167
168
  return (e) => {
168
169
  if (e.key === "Escape") {
169
170
  const state = store?.getState();
@@ -1 +1 @@
1
- {"version":3,"file":"key-handling.cjs","sources":["../../src/utils/key-handling.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\nimport { storeAPIAtom, storeAtom, tableActionsAtom } from \"../provider\";\nimport type { DataSheetStoreMain } from \"../types\";\nimport { atom } from \"jotai\";\nimport { singleFocusedCell } from \"../zustand-store.ts\";\nimport { buildActionContext, runActionWrapper } from \"../actions\";\nimport { HotkeyConfig } from \"@blueprintjs/core\";\nimport { toasterAtom } from \"../notifications.ts\";\n\ntype HotkeyActionRunner = (\n e: KeyboardEvent,\n state: DataSheetStoreMain<any>,\n setState: (state: Partial<DataSheetStoreMain<any>>) => void,\n) => void | Promise<void>;\n\nconst isEditableAtom = atom((get) => {\n const store = get(storeAtom);\n return store?.editable ?? false;\n});\n\nconst hasSelectionAtom = atom((get) => {\n const store = get(storeAtom);\n const selection = store?.selection ?? [];\n return selection.length > 0;\n});\n\nexport const tableHotkeysAtom = atom<HotkeyConfig[]>((get) => {\n const store = get(storeAPIAtom);\n const toaster = get(toasterAtom);\n const editable = get(isEditableAtom);\n\n /** Set up hotkeys for table actions */\n const tableActions = get(tableActionsAtom);\n\n if (store == null) return [];\n const keyHandler = (\n actionRunner: HotkeyActionRunner,\n ): HotkeyConfig[\"onKeyDown\"] => {\n return (e) => {\n // Kind of a ridiculous hack to get the store from the atom.\n const state = store.getState();\n const setState = store.setState;\n try {\n const res = actionRunner(e, state, setState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((err) => {\n console.error(err);\n handleError(toaster, err);\n });\n }\n } catch (err) {\n handleError(toaster, err);\n }\n };\n };\n\n function handleError(toaster, err) {\n toaster.show({\n message: `${err}`,\n intent: \"danger\",\n });\n }\n\n const directionCombos = [\"up\", \"down\", \"left\", \"right\"].map((dir) => {\n return {\n combo: dir,\n group: \"Navigation\",\n label: \"Move focus \" + dir,\n preventDefault: true,\n onKeyDown: keyHandler((e, state) => {\n state.moveFocusedCell(dir);\n }),\n };\n });\n\n /** TODO: merge a bit more with the actions config */\n\n const actionsCombos = tableActions\n .map((action) => {\n if (action.hotkey == null) return null;\n return {\n combo: action.hotkey,\n label: action.name,\n group: action.group ?? \"Actions\",\n preventDefault: true,\n disabled: action.requiresEditable !== false && !editable,\n onKeyDown(event: KeyboardEvent<any>): any {\n const state = store.getState();\n const setState = store.setState;\n runActionWrapper(action, state, setState, toaster);\n },\n } as any as HotkeyConfig;\n })\n .filter(Boolean) as HotkeyConfig[];\n\n // Backspace/Delete: on a whole-row selection, delete the row(s); otherwise\n // clear the selected cells.\n const clearOrDeleteSelection = keyHandler((e, state) => {\n const sel = state.selection ?? [];\n const isRowSelection =\n sel.length > 0 && sel.every((r) => r.cols == null && r.rows != null);\n if (isRowSelection) {\n state.deleteSelectedRows();\n } else {\n state.clearSelection();\n }\n });\n\n return [\n {\n combo: \"esc\",\n label: \"Exit editing / clear selection\",\n group: \"Selection\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n // First Escape closes the focused cell's open surface (editor/panel)\n // while keeping the selection, so arrow keys keep working — in both\n // auto and manual modes. A second Escape (nothing open) clears the\n // selection.\n if (state.cellSurfaceOpen) {\n state.closeCellSurface();\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (state.selection.length == 0) {\n // Focus goes back to parent\n return;\n }\n state.setSelection([]);\n e.preventDefault();\n e.stopPropagation();\n }),\n },\n {\n combo: \"backspace\",\n label: \"Clear cells / delete rows\",\n group: \"Selection\",\n allowInInput: true,\n disabled: !editable,\n onKeyDown: clearOrDeleteSelection,\n },\n {\n combo: \"del\",\n label: \"Clear cells / delete rows\",\n group: \"Selection\",\n allowInInput: true,\n disabled: !editable,\n onKeyDown: clearOrDeleteSelection,\n },\n {\n combo: \"tab\",\n label: \"Move focus right (or left with shift)\",\n group: \"Navigation\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n state.moveFocusedCell(e.shiftKey ? \"left\" : \"right\");\n }),\n },\n {\n combo: \"enter\",\n label: \"Edit cell / move focus down\",\n group: \"Navigation\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n // In navigation mode (no surface open), Enter enters edit mode —\n // opening and focusing the focused cell's surface (Google Sheets\n // style). While a surface is open, Enter advances downward as usual\n // (an inline editor blurs and this moves to the next row).\n if (!state.cellSurfaceOpen) {\n state.armAutoActivate();\n state.openCellSurface();\n e.preventDefault();\n return;\n }\n state.moveFocusedCell(\"down\");\n }),\n },\n {\n combo: \"f2\",\n label: \"Edit / open cell\",\n group: \"Editing\",\n onKeyDown: keyHandler((e, state) => {\n // Enter edit mode from the keyboard: re-arm auto-activation and open\n // the focused cell's surface (which focuses the editor).\n state.armAutoActivate();\n state.openCellSurface();\n e.preventDefault();\n }),\n },\n ...directionCombos,\n ...actionsCombos,\n ];\n});\n\nconst selectionAtom = atom((get) => {\n const store = get(storeAtom);\n return store.selection;\n});\n\nconst isSingleCellSelectionAtom = atom((get) => {\n const selection = get(selectionAtom);\n return singleFocusedCell(selection) != null;\n});\n\nexport const editorKeyHandlerAtom = atom((get) => {\n const store = get(storeAPIAtom);\n return (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n // Escape exits the inline editor: close the surface (which enters\n // navigation mode in auto), keep the selection, and return focus to the\n // table so arrow keys navigate. Stop propagation so the table's own\n // Escape hotkey doesn't also fire.\n const state = store?.getState();\n state?.closeCellSurface();\n state?.tableElement?.focus();\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n const isSingleCellSelection = get(isSingleCellSelectionAtom);\n editorKeyHandler(e, isSingleCellSelection);\n };\n});\n\nfunction editorKeyHandler(\n e: KeyboardEvent<HTMLInputElement>,\n isSingleCellSelection: boolean,\n) {\n /** Get a key handler for inline cell editing */\n\n const target = e.target as HTMLInputElement;\n\n let shouldCaptureEventForInlineEditing = true;\n\n if (e.key == \"Enter\") {\n shouldCaptureEventForInlineEditing = e.shiftKey;\n }\n\n if (e.key == \"Escape\" || e.key == \"Tab\") {\n shouldCaptureEventForInlineEditing = false;\n }\n\n if (e.key == \"Backspace\" || e.key == \"Delete\") {\n /** Clear selection on Backspace or Delete on a multi-cell selection\n * (if shift is held, we allow deletion in a single cell)\n */\n shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;\n }\n\n if (!shouldCaptureEventForInlineEditing) {\n target.blur();\n e.preventDefault();\n return;\n }\n\n const shouldPropagate = shouldPropagateKeystroke(e);\n if (!shouldPropagate) {\n e.stopPropagation();\n //e.preventDefault();\n } else {\n // we blur the editor and dispatch a keydown event on the parent to propagate the event to the table\n e.preventDefault();\n target.blur();\n //console.log(tableElement);\n //tableElement.focus();\n //target.parentNode?.dispatchEvent(e);\n target.parentNode?.dispatchEvent(new KeyboardEvent(\"keydown\", e));\n }\n}\n\nfunction shouldPropagateKeystroke(evt: KeyboardEvent): boolean {\n if (evt.target.selectionStart == evt.target.selectionEnd) {\n // We don't have anything selected, so we can propagate the event potentially\n // 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.\n if (evt.key === \"c\" || evt.key === \"v\" || evt.key === \"x\") {\n if (evt.ctrlKey || evt.metaKey) {\n return true;\n }\n }\n }\n\n if (evt.key === \"ArrowUp\" || evt.key === \"ArrowDown\") {\n return true;\n }\n\n const target = evt.target;\n if (\n (evt.key === \"ArrowLeft\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === 0\n ) {\n return true;\n }\n\n if (\n (evt.key === \"ArrowRight\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"Tab\" ||\n evt.key === \"Enter\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === evt.target.value.length\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function multiLineTextKeyHandler(evt: InputEvent) {\n if (evt.key === \"Enter\") {\n //evt.preventDefault();\n evt.stopPropagation();\n return;\n }\n\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n\n const shouldPropagate = shouldPropagateKeystroke(evt);\n if (!shouldPropagate) {\n evt.stopPropagation();\n } else {\n evt.target.blur();\n }\n}\n"],"names":["atom","storeAtom","storeAPIAtom","toasterAtom","tableActionsAtom","toaster","runActionWrapper","singleFocusedCell"],"mappings":";;;;;;;AAeA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,IAAI,QAAQ,aACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,GAC1B;AACA,WAAO;AAAA,EACT;AAEA,OACG,IAAI,QAAQ,gBACX,IAAI,QAAQ,aACZ,IAAI,QAAQ,SACZ,IAAI,QAAQ,WACZ,IAAI,QAAQ,gBACd,OAAO,mBAAmB,IAAI,OAAO,MAAM,QAC3C;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAEO,SAAS,wBAAwB,KAAiB;AACvD,MAAI,IAAI,QAAQ,SAAS;AAEvB,QAAI,gBAAA;AACJ;AAAA,EACF;AAEA,MAAI,IAAI,QAAQ,UAAU;AACxB,QAAI,eAAA;AACJ;AAAA,EACF;AAEA,QAAM,kBAAkB,yBAAyB,GAAG;AACpD,MAAI,CAAC,iBAAiB;AACpB,QAAI,gBAAA;AAAA,EACN,OAAO;AACL,QAAI,OAAO,KAAA;AAAA,EACb;AACF;;;;"}
1
+ {"version":3,"file":"key-handling.cjs","sources":["../../src/utils/key-handling.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\nimport {\n storeAPIAtom,\n storeAtom,\n tableActionsAtom,\n type DataSheetStoreMain,\n singleFocusedCell,\n ctx,\n} from \"../provider\";\nimport { atom } from \"jotai\";\nimport { runActionWrapper } from \"../actions\";\nimport { HotkeyConfig } from \"@blueprintjs/core\";\nimport { toasterAtom } from \"../notifications.ts\";\n\ntype HotkeyActionRunner = (\n e: KeyboardEvent,\n state: DataSheetStoreMain<any>,\n setState: (state: Partial<DataSheetStoreMain<any>>) => void,\n) => void | Promise<void>;\n\nconst isEditableAtom = atom((get) => {\n const store = get(storeAtom);\n return store?.editable ?? false;\n});\n\nconst hasSelectionAtom = atom((get) => {\n const store = get(storeAtom);\n const selection = store?.selection ?? [];\n return selection.length > 0;\n});\n\nexport const tableHotkeysAtom = atom<null, [], HotkeyConfig[]>(\n null,\n (get, set) => {\n const store = get(storeAPIAtom);\n const toaster = get(toasterAtom);\n const editable = get(isEditableAtom);\n\n /** Set up hotkeys for table actions */\n const tableActions = get(tableActionsAtom);\n\n if (store == null) return [];\n const keyHandler = (\n actionRunner: HotkeyActionRunner,\n ): HotkeyConfig[\"onKeyDown\"] => {\n return (e) => {\n // Kind of a ridiculous hack to get the store from the atom.\n const state = store.getState();\n const setState = store.setState;\n try {\n const res = actionRunner(e as any, state, setState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((err) => {\n console.error(err);\n handleError(toaster, err);\n });\n }\n } catch (err) {\n handleError(toaster, err);\n }\n };\n };\n\n function handleError(toaster, err) {\n toaster.show({\n message: `${err}`,\n intent: \"danger\",\n });\n }\n\n const directionCombos = [\"up\", \"down\", \"left\", \"right\"].map((dir) => {\n return {\n combo: dir,\n group: \"Navigation\",\n label: \"Move focus \" + dir,\n preventDefault: true,\n onKeyDown: keyHandler((e, state) => {\n state.moveFocusedCell(dir as any);\n }),\n };\n });\n\n /** TODO: merge a bit more with the actions config */\n\n const actionsCombos = tableActions\n .map((action) => {\n if (action.hotkey == null) return null;\n return {\n combo: action.hotkey,\n label: action.name,\n group: action.group ?? \"Actions\",\n preventDefault: true,\n disabled: action.requiresEditable !== false && !editable,\n onKeyDown(event: KeyboardEvent<any>): any {\n runActionWrapper(action, get, set, toaster);\n },\n } as any as HotkeyConfig;\n })\n .filter(Boolean) as HotkeyConfig[];\n\n // Backspace/Delete: on a whole-row selection, delete the row(s); otherwise\n // clear the selected cells.\n const clearOrDeleteSelection = keyHandler((e, state) => {\n const sel = state.selection ?? [];\n const isRowSelection =\n sel.length > 0 && sel.every((r) => r.cols == null && r.rows != null);\n if (isRowSelection) {\n state.deleteSelectedRows();\n } else {\n state.clearSelection();\n }\n });\n\n return [\n {\n combo: \"esc\",\n label: \"Exit editing / clear selection\",\n group: \"Selection\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n // First Escape closes the focused cell's open surface (editor/panel)\n // while keeping the selection, so arrow keys keep working — in both\n // auto and manual modes. A second Escape (nothing open) clears the\n // selection.\n if (state.cellSurfaceOpen) {\n state.closeCellSurface();\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n if (state.selection.length == 0) {\n // Focus goes back to parent\n return;\n }\n state.setSelection([]);\n e.preventDefault();\n e.stopPropagation();\n }),\n },\n {\n combo: \"backspace\",\n label: \"Clear cells / delete rows\",\n group: \"Selection\",\n allowInInput: true,\n disabled: !editable,\n onKeyDown: clearOrDeleteSelection,\n },\n {\n combo: \"del\",\n label: \"Clear cells / delete rows\",\n group: \"Selection\",\n allowInInput: true,\n disabled: !editable,\n onKeyDown: clearOrDeleteSelection,\n },\n {\n combo: \"tab\",\n label: \"Move focus right (or left with shift)\",\n group: \"Navigation\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n state.moveFocusedCell(e.shiftKey ? \"left\" : \"right\");\n }),\n },\n {\n combo: \"enter\",\n label: \"Edit cell / move focus down\",\n group: \"Navigation\",\n allowInInput: true,\n onKeyDown: keyHandler((e, state) => {\n // In navigation mode (no surface open), Enter enters edit mode —\n // opening and focusing the focused cell's surface (Google Sheets\n // style). While a surface is open, Enter advances downward as usual\n // (an inline editor blurs and this moves to the next row).\n if (!state.cellSurfaceOpen) {\n state.armAutoActivate();\n state.openCellSurface();\n e.preventDefault();\n return;\n }\n state.moveFocusedCell(\"down\");\n }),\n },\n {\n combo: \"f2\",\n label: \"Edit / open cell\",\n group: \"Editing\",\n onKeyDown: keyHandler((e, state) => {\n // Enter edit mode from the keyboard: re-arm auto-activation and open\n // the focused cell's surface (which focuses the editor).\n state.armAutoActivate();\n state.openCellSurface();\n e.preventDefault();\n }),\n },\n ...directionCombos,\n ...actionsCombos,\n ];\n },\n);\n\nconst selectionAtom = atom((get) => {\n const store = get(storeAtom);\n return store?.selection ?? [];\n});\n\nconst isSingleCellSelectionAtom = atom((get) => {\n const selection = get(selectionAtom);\n return singleFocusedCell(selection) != null;\n});\n\nexport const editorKeyHandlerAtom = atom((get) => {\n const store = get(storeAPIAtom);\n return (e: KeyboardEvent) => {\n if (e.key === \"Escape\") {\n // Escape exits the inline editor: close the surface (which enters\n // navigation mode in auto), keep the selection, and return focus to the\n // table so arrow keys navigate. Stop propagation so the table's own\n // Escape hotkey doesn't also fire.\n const state = store?.getState();\n state?.closeCellSurface();\n state?.tableElement?.focus();\n e.preventDefault();\n e.stopPropagation();\n return;\n }\n const isSingleCellSelection = get(isSingleCellSelectionAtom);\n editorKeyHandler(e as any, isSingleCellSelection);\n };\n});\n\nfunction editorKeyHandler(\n e: KeyboardEvent<HTMLInputElement>,\n isSingleCellSelection: boolean,\n) {\n /** Get a key handler for inline cell editing */\n\n const target = e.target as HTMLInputElement;\n\n let shouldCaptureEventForInlineEditing = true;\n\n if (e.key == \"Enter\") {\n shouldCaptureEventForInlineEditing = e.shiftKey;\n }\n\n if (e.key == \"Escape\" || e.key == \"Tab\") {\n shouldCaptureEventForInlineEditing = false;\n }\n\n if (e.key == \"Backspace\" || e.key == \"Delete\") {\n /** Clear selection on Backspace or Delete on a multi-cell selection\n * (if shift is held, we allow deletion in a single cell)\n */\n shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;\n }\n\n if (!shouldCaptureEventForInlineEditing) {\n target.blur();\n e.preventDefault();\n return;\n }\n\n const shouldPropagate = shouldPropagateKeystroke(e);\n if (!shouldPropagate) {\n e.stopPropagation();\n //e.preventDefault();\n } else {\n // we blur the editor and dispatch a keydown event on the parent to propagate the event to the table\n e.preventDefault();\n target.blur();\n //console.log(tableElement);\n //tableElement.focus();\n //target.parentNode?.dispatchEvent(e);\n target.parentNode?.dispatchEvent(new KeyboardEvent(\"keydown\", e as any));\n }\n}\n\nfunction shouldPropagateKeystroke(evt: any): boolean {\n if (evt.target.selectionStart == evt.target.selectionEnd) {\n // We don't have anything selected, so we can propagate the event potentially\n // 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.\n if (evt.key === \"c\" || evt.key === \"v\" || evt.key === \"x\") {\n if (evt.ctrlKey || evt.metaKey) {\n return true;\n }\n }\n }\n\n if (evt.key === \"ArrowUp\" || evt.key === \"ArrowDown\") {\n return true;\n }\n\n const target = evt.target;\n if (\n (evt.key === \"ArrowLeft\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === 0\n ) {\n return true;\n }\n\n if (\n (evt.key === \"ArrowRight\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"Tab\" ||\n evt.key === \"Enter\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === evt.target.value.length\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function multiLineTextKeyHandler(evt: any) {\n if (evt.key === \"Enter\") {\n //evt.preventDefault();\n evt.stopPropagation();\n return;\n }\n\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n\n const shouldPropagate = shouldPropagateKeystroke(evt);\n if (!shouldPropagate) {\n evt.stopPropagation();\n } else {\n evt.target.blur();\n }\n}\n"],"names":["atom","storeAtom","storeAPIAtom","toasterAtom","tableActionsAtom","toaster","runActionWrapper","singleFocusedCell"],"mappings":";;;;;;;AAoBA,MAAM,iBAAiBA,MAAAA,KAAK,CAAC,QAAQ;AACnC,QAAM,QAAQ,IAAIC,cAAS;AAC3B,SAAO,OAAO,YAAY;AAC5B,CAAC;AAEwBD,MAAAA,KAAK,CAAC,QAAQ;AACrC,QAAM,QAAQ,IAAIC,cAAS;AAC3B,QAAM,YAAY,OAAO,aAAa,CAAA;AACtC,SAAO,UAAU,SAAS;AAC5B,CAAC;AAEM,MAAM,mBAAmBD,MAAAA;AAAAA,EAC9B;AAAA,EACA,CAAC,KAAK,QAAQ;AACZ,UAAM,QAAQ,IAAIE,iBAAY;AAC9B,UAAM,UAAU,IAAIC,yBAAW;AAC/B,UAAM,WAAW,IAAI,cAAc;AAGnC,UAAM,eAAe,IAAIC,qBAAgB;AAEzC,QAAI,SAAS,KAAM,QAAO,CAAA;AAC1B,UAAM,aAAa,CACjB,iBAC8B;AAC9B,aAAO,CAAC,MAAM;AA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}
@@ -1,5 +1,7 @@
1
1
  import { KeyboardEvent } from 'react';
2
2
  import { HotkeyConfig } from '@blueprintjs/core';
3
- export declare const tableHotkeysAtom: import('jotai').Atom<HotkeyConfig[]>;
3
+ export declare const tableHotkeysAtom: import('jotai').WritableAtom<null, [], HotkeyConfig[]> & {
4
+ init: null;
5
+ };
4
6
  export declare const editorKeyHandlerAtom: import('jotai').Atom<(e: KeyboardEvent) => void>;
5
- export declare function multiLineTextKeyHandler(evt: InputEvent): void;
7
+ export declare function multiLineTextKeyHandler(evt: any): void;