@macrostrat/data-sheet 2.2.2 → 2.2.4

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 (85) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/esm/data-sheet.186dcac8.js +86 -0
  3. package/dist/esm/data-sheet.186dcac8.js.map +1 -0
  4. package/dist/esm/{data-sheet.ce2a3218.js → data-sheet.2e11f097.js} +5 -5
  5. package/dist/esm/{data-sheet.ce2a3218.js.map → data-sheet.2e11f097.js.map} +1 -1
  6. package/dist/esm/data-sheet.37e35216.js.map +1 -1
  7. package/dist/esm/{data-sheet.ce24dcf9.js → data-sheet.403b9693.js} +104 -130
  8. package/dist/esm/data-sheet.403b9693.js.map +1 -0
  9. package/dist/esm/{data-sheet.b5946d6b.js → data-sheet.40866550.js} +6 -27
  10. package/dist/esm/data-sheet.40866550.js.map +1 -0
  11. package/dist/esm/{data-sheet.6021b6c9.js → data-sheet.53ee5bf7.js} +25 -15
  12. package/dist/esm/data-sheet.53ee5bf7.js.map +1 -0
  13. package/dist/esm/{data-sheet.a0d5d18d.js → data-sheet.560943e5.js} +4 -4
  14. package/dist/esm/{data-sheet.a0d5d18d.js.map → data-sheet.560943e5.js.map} +1 -1
  15. package/dist/esm/{data-sheet.ae6daf58.js → data-sheet.8dbfccef.js} +4 -2
  16. package/dist/esm/data-sheet.8dbfccef.js.map +1 -0
  17. package/dist/esm/{data-sheet.1d6ac6c6.js → data-sheet.9a4e4e01.js} +13 -24
  18. package/dist/esm/data-sheet.9a4e4e01.js.map +1 -0
  19. package/dist/esm/{data-sheet.91223ec6.css → data-sheet.a7230b2f.css} +3 -3
  20. package/dist/esm/data-sheet.a7230b2f.css.map +1 -0
  21. package/dist/esm/{data-sheet.45e8d3b0.js → data-sheet.c9b6b6f2.js} +66 -8
  22. package/dist/esm/data-sheet.c9b6b6f2.js.map +1 -0
  23. package/dist/esm/{data-sheet.aa2b4902.js → data-sheet.d2160988.js} +2 -1
  24. package/dist/esm/data-sheet.d2160988.js.map +1 -0
  25. package/dist/esm/index.d.ts +59 -40
  26. package/dist/esm/index.d.ts.map +1 -1
  27. package/dist/esm/index.js +6 -6
  28. package/dist/node/data-sheet.3c728e09.js +2 -0
  29. package/dist/node/data-sheet.3c728e09.js.map +1 -0
  30. package/dist/node/data-sheet.474755ec.js +2 -0
  31. package/dist/node/data-sheet.474755ec.js.map +1 -0
  32. package/dist/node/{data-sheet.846d5f8f.js → data-sheet.648db7af.js} +2 -2
  33. package/dist/node/data-sheet.648db7af.js.map +1 -0
  34. package/dist/node/data-sheet.97ac1b50.js +2 -0
  35. package/dist/node/data-sheet.97ac1b50.js.map +1 -0
  36. package/dist/node/data-sheet.ae543670.js +2 -0
  37. package/dist/node/data-sheet.ae543670.js.map +1 -0
  38. package/dist/node/data-sheet.afb25a47.js +2 -0
  39. package/dist/node/data-sheet.afb25a47.js.map +1 -0
  40. package/dist/node/{data-sheet.2f64274d.css → data-sheet.c90cb14b.css} +2 -2
  41. package/dist/node/data-sheet.c90cb14b.css.map +1 -0
  42. package/dist/node/data-sheet.d971095a.js +2 -0
  43. package/dist/node/data-sheet.d971095a.js.map +1 -0
  44. package/dist/node/data-sheet.dffdda71.js +2 -0
  45. package/dist/node/data-sheet.dffdda71.js.map +1 -0
  46. package/dist/node/data-sheet.e472411d.js +2 -0
  47. package/dist/node/data-sheet.e472411d.js.map +1 -0
  48. package/dist/node/{data-sheet.d40ac2ae.js → data-sheet.ef0c95f4.js} +2 -2
  49. package/dist/node/{data-sheet.d40ac2ae.js.map → data-sheet.ef0c95f4.js.map} +1 -1
  50. package/dist/node/index.js +1 -1
  51. package/dist/node/index.js.map +1 -1
  52. package/package.json +5 -6
  53. package/src/components/colors.ts +25 -12
  54. package/src/components/editor-popup.ts +13 -24
  55. package/src/components/main.module.sass +3 -7
  56. package/src/components/text-areas.ts +2 -43
  57. package/src/core.ts +136 -155
  58. package/src/postgrest-table/data-loaders.ts +1 -0
  59. package/src/provider.ts +82 -9
  60. package/src/utils/index.ts +1 -0
  61. package/src/utils/key-handling.ts +132 -0
  62. package/dist/esm/data-sheet.1d6ac6c6.js.map +0 -1
  63. package/dist/esm/data-sheet.45e8d3b0.js.map +0 -1
  64. package/dist/esm/data-sheet.6021b6c9.js.map +0 -1
  65. package/dist/esm/data-sheet.91223ec6.css.map +0 -1
  66. package/dist/esm/data-sheet.aa2b4902.js.map +0 -1
  67. package/dist/esm/data-sheet.ae6daf58.js.map +0 -1
  68. package/dist/esm/data-sheet.b5946d6b.js.map +0 -1
  69. package/dist/esm/data-sheet.ce24dcf9.js.map +0 -1
  70. package/dist/node/data-sheet.171105c1.js +0 -2
  71. package/dist/node/data-sheet.171105c1.js.map +0 -1
  72. package/dist/node/data-sheet.1a487c3c.js +0 -2
  73. package/dist/node/data-sheet.1a487c3c.js.map +0 -1
  74. package/dist/node/data-sheet.2f64274d.css.map +0 -1
  75. package/dist/node/data-sheet.4a8fd8a7.js +0 -2
  76. package/dist/node/data-sheet.4a8fd8a7.js.map +0 -1
  77. package/dist/node/data-sheet.846d5f8f.js.map +0 -1
  78. package/dist/node/data-sheet.86550c41.js +0 -2
  79. package/dist/node/data-sheet.86550c41.js.map +0 -1
  80. package/dist/node/data-sheet.a65463ef.js +0 -2
  81. package/dist/node/data-sheet.a65463ef.js.map +0 -1
  82. package/dist/node/data-sheet.bfbba3fc.js +0 -2
  83. package/dist/node/data-sheet.bfbba3fc.js.map +0 -1
  84. package/dist/node/data-sheet.f3404ed5.js +0 -2
  85. package/dist/node/data-sheet.f3404ed5.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. The format
4
4
  is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
5
5
  project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [2.2.4] - 2026-01-20
8
+
9
+ - Modernize `react-color` dependency
10
+ - Modernize data editor handling
11
+
12
+ ## [2.2.3] - 2026-01-17
13
+
14
+ - Fix issue with column resizing
15
+ - Refactored key handlers
16
+ - Reduced rendering overhead with `useCallback` and `useMemo`
17
+
7
18
  ## [2.2.2] - 2025-12-13
8
19
 
9
20
  Small typing fixes
@@ -0,0 +1,86 @@
1
+ function $953dc094ec21e2f0$export$b010a8fb240edb5e(e, state) {
2
+ // General key event
3
+ if (e.key === "Escape") {
4
+ // Clear selection on Escape
5
+ state.setSelection([]);
6
+ e.preventDefault();
7
+ e.stopPropagation();
8
+ }
9
+ // Clear selection on Backspace or Delete
10
+ if (e.key === "Backspace" || e.key === "Delete") {
11
+ // Clear selection on Backspace or Delete
12
+ state.clearSelection();
13
+ e.preventDefault();
14
+ }
15
+ // Handle arrow keys for navigation
16
+ if (e.key in $953dc094ec21e2f0$var$directionMap) {
17
+ // Handle arrow key navigation
18
+ const direction = $953dc094ec21e2f0$var$directionMap[e.key];
19
+ state.moveFocusedCell(direction);
20
+ // Prevent default scrolling behavior
21
+ e.preventDefault();
22
+ }
23
+ if (e.key === "Tab") {
24
+ state.moveFocusedCell(e.shiftKey ? "left" : "right");
25
+ e.preventDefault();
26
+ }
27
+ if (e.key === "Enter") {
28
+ state.moveFocusedCell("down");
29
+ e.preventDefault();
30
+ }
31
+ }
32
+ const $953dc094ec21e2f0$var$directionMap = {
33
+ ArrowUp: "up",
34
+ ArrowDown: "down",
35
+ ArrowLeft: "left",
36
+ ArrowRight: "right"
37
+ };
38
+ function $953dc094ec21e2f0$export$1ebdb7ea82507aae(e, isSingleCellSelection) {
39
+ /** Get a key handler for inline cell editing */ // if (e.key == "Enter" || e.key == "Tab") {
40
+ // e.target.blur();
41
+ // return;
42
+ // }
43
+ let shouldCaptureEventForInlineEditing = true;
44
+ if (e.key == "Enter") shouldCaptureEventForInlineEditing = e.shiftKey;
45
+ if (e.key == "Escape" || e.key == "Tab") shouldCaptureEventForInlineEditing = false;
46
+ if (e.key == "Backspace" || e.key == "Delete") /** Clear selection on Backspace or Delete on a multi-cell selection
47
+ * (if shift is held, we allow deletion in a single cell)
48
+ */ shouldCaptureEventForInlineEditing = isSingleCellSelection && !e.shiftKey;
49
+ if (!shouldCaptureEventForInlineEditing) {
50
+ e.target.blur();
51
+ e.preventDefault();
52
+ return;
53
+ }
54
+ const shouldPropagate = $953dc094ec21e2f0$var$handleSpecialKeys(e);
55
+ if (!shouldPropagate) e.stopPropagation();
56
+ else e.target.blur();
57
+ }
58
+ function $953dc094ec21e2f0$export$eb6970f6c0d44205(evt) {
59
+ if (evt.key === "Enter") {
60
+ //evt.preventDefault();
61
+ evt.stopPropagation();
62
+ return;
63
+ }
64
+ if (evt.key === "Escape") {
65
+ evt.preventDefault();
66
+ return;
67
+ }
68
+ const shouldPropagate = $953dc094ec21e2f0$var$handleSpecialKeys(evt);
69
+ if (!shouldPropagate) evt.stopPropagation();
70
+ }
71
+ function $953dc094ec21e2f0$var$handleSpecialKeys(evt) {
72
+ const target = evt.target;
73
+ if ((evt.key === "ArrowLeft" || evt.key === "ArrowUp" || evt.key === "ArrowDown") && target.selectionStart === 0) {
74
+ target.blur();
75
+ return true;
76
+ }
77
+ if ((evt.key === "ArrowRight" || evt.key === "ArrowUp" || evt.key === "Tab" || evt.key === "Enter" || evt.key === "ArrowDown") && target.selectionStart === evt.target.value.length) {
78
+ target.blur();
79
+ return true;
80
+ }
81
+ return false;
82
+ }
83
+
84
+
85
+ export {$953dc094ec21e2f0$export$b010a8fb240edb5e as tableKeyHandler, $953dc094ec21e2f0$export$1ebdb7ea82507aae as editorKeyHandler, $953dc094ec21e2f0$export$eb6970f6c0d44205 as multiLineTextKeyHandler};
86
+ //# sourceMappingURL=data-sheet.186dcac8.js.map
@@ -0,0 +1 @@
1
+ {"mappings":"AAGO,SAAS,0CACd,CAAgB,EAChB,KAA4B;IAE5B,oBAAoB;IACpB,IAAI,EAAE,GAAG,KAAK,UAAU;QACtB,4BAA4B;QAC5B,MAAM,YAAY,CAAC,EAAE;QACrB,EAAE,cAAc;QAChB,EAAE,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AI,eAAe;QACnB;IACF;IAEA,IAAI,IAAI,GAAG,KAAK,UAAU;QACxB,IAAI,cAAc;QAClB;IACF;IAEA,MAAM,kBAAkB,wCAAkB;IAC1C,IAAI,CAAC,iBACH,IAAI,eAAe;AAEvB;AAEA,SAAS,wCAAkB,GAAkB;IAC3C,MAAM,SAAS,IAAI,MAAM;IACzB,IACE,AAAC,CAAA,IAAI,GAAG,KAAK,eACX,IAAI,GAAG,KAAK,aACZ,IAAI,GAAG,KAAK,WAAU,KACxB,OAAO,cAAc,KAAK,GAC1B;QACA,OAAO,IAAI;QACX,OAAO;IACT;IAEA,IACE,AAAC,CAAA,IAAI,GAAG,KAAK,gBACX,IAAI,GAAG,KAAK,aACZ,IAAI,GAAG,KAAK,SACZ,IAAI,GAAG,KAAK,WACZ,IAAI,GAAG,KAAK,WAAU,KACxB,OAAO,cAAc,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EACjD;QACA,OAAO,IAAI;QACX,OAAO;IACT;IAEA,OAAO;AACT","sources":["packages/data-sheet/src/utils/key-handling.ts"],"sourcesContent":["import type { KeyboardEvent } from \"react\";\nimport { DataSheetStoreMain } from \"@macrostrat/data-sheet\";\n\nexport function tableKeyHandler<T>(\n e: KeyboardEvent,\n state: DataSheetStoreMain<T>,\n) {\n // General key event\n if (e.key === \"Escape\") {\n // Clear selection on Escape\n state.setSelection([]);\n e.preventDefault();\n e.stopPropagation();\n }\n // Clear selection on Backspace or Delete\n if (e.key === \"Backspace\" || e.key === \"Delete\") {\n // Clear selection on Backspace or Delete\n state.clearSelection();\n e.preventDefault();\n }\n // Handle arrow keys for navigation\n if (e.key in directionMap) {\n // Handle arrow key navigation\n const direction = directionMap[e.key];\n state.moveFocusedCell(direction);\n // Prevent default scrolling behavior\n e.preventDefault();\n }\n if (e.key === \"Tab\") {\n state.moveFocusedCell(e.shiftKey ? \"left\" : \"right\");\n e.preventDefault();\n }\n if (e.key === \"Enter\") {\n state.moveFocusedCell(\"down\");\n e.preventDefault();\n }\n}\n\nconst directionMap = {\n ArrowUp: \"up\",\n ArrowDown: \"down\",\n ArrowLeft: \"left\",\n ArrowRight: \"right\",\n};\n\nexport function editorKeyHandler(\n e: KeyboardEvent,\n isSingleCellSelection: boolean,\n) {\n /** Get a key handler for inline cell editing */\n\n // if (e.key == \"Enter\" || e.key == \"Tab\") {\n // e.target.blur();\n // return;\n // }\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 e.target.blur();\n e.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(e);\n if (!shouldPropagate) {\n e.stopPropagation();\n } else {\n e.target.blur();\n //e.target.parentNode.dispatchEvent(new KeyboardEvent(\"keydown\", e));\n }\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 = handleSpecialKeys(evt);\n if (!shouldPropagate) {\n evt.stopPropagation();\n }\n}\n\nfunction handleSpecialKeys(evt: KeyboardEvent): boolean {\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 target.blur();\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 target.blur();\n return true;\n }\n\n return false;\n}\n"],"names":[],"version":3,"file":"data-sheet.186dcac8.js.map"}
@@ -1,6 +1,6 @@
1
- import {EditorPopup as $88e63ff6e4eea209$export$2a7e60c8443c1751} from "./data-sheet.1d6ac6c6.js";
2
- import {ColorCell as $423bf54b4879ebeb$export$24aecfe8a925020d, colorSwatchRenderer as $423bf54b4879ebeb$export$e5f546a5ba915f1c, ColorPicker as $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3} from "./data-sheet.6021b6c9.js";
3
- import {EditableTextArea as $0aa421c11d2af971$export$b8e68c321a6269f1, handleSpecialKeys as $0aa421c11d2af971$export$52c8c5a1aad17e2a} from "./data-sheet.b5946d6b.js";
1
+ import {EditorPopup as $88e63ff6e4eea209$export$2a7e60c8443c1751} from "./data-sheet.9a4e4e01.js";
2
+ import {ColorCell as $423bf54b4879ebeb$export$24aecfe8a925020d, colorSwatchRenderer as $423bf54b4879ebeb$export$e5f546a5ba915f1c, ColorPicker as $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3} from "./data-sheet.53ee5bf7.js";
3
+ import {EditableTextArea as $0aa421c11d2af971$export$b8e68c321a6269f1} from "./data-sheet.40866550.js";
4
4
  import {DataSheetActionsRow as $a36e736abd533bdf$export$b215fe4466d8f847, DataSheetAction as $a36e736abd533bdf$export$c2c7070a9fc246e1} from "./data-sheet.a3eb6088.js";
5
5
 
6
6
 
@@ -9,5 +9,5 @@ import {DataSheetActionsRow as $a36e736abd533bdf$export$b215fe4466d8f847, DataSh
9
9
 
10
10
 
11
11
 
12
- export {$88e63ff6e4eea209$export$2a7e60c8443c1751 as EditorPopup, $423bf54b4879ebeb$export$24aecfe8a925020d as ColorCell, $423bf54b4879ebeb$export$e5f546a5ba915f1c as colorSwatchRenderer, $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3 as ColorPicker, $0aa421c11d2af971$export$b8e68c321a6269f1 as EditableTextArea, $0aa421c11d2af971$export$52c8c5a1aad17e2a as handleSpecialKeys, $a36e736abd533bdf$export$b215fe4466d8f847 as DataSheetActionsRow, $a36e736abd533bdf$export$c2c7070a9fc246e1 as DataSheetAction};
13
- //# sourceMappingURL=data-sheet.ce2a3218.js.map
12
+ export {$88e63ff6e4eea209$export$2a7e60c8443c1751 as EditorPopup, $423bf54b4879ebeb$export$24aecfe8a925020d as ColorCell, $423bf54b4879ebeb$export$e5f546a5ba915f1c as colorSwatchRenderer, $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3 as ColorPicker, $0aa421c11d2af971$export$b8e68c321a6269f1 as EditableTextArea, $a36e736abd533bdf$export$b215fe4466d8f847 as DataSheetActionsRow, $a36e736abd533bdf$export$c2c7070a9fc246e1 as DataSheetAction};
13
+ //# sourceMappingURL=data-sheet.2e11f097.js.map
@@ -1 +1 @@
1
- {"mappings":"","sources":["packages/data-sheet/src/components/index.ts"],"sourcesContent":["export * from \"./editor-popup\";\nexport * from \"./colors\";\nexport * from \"./text-areas\";\nexport * from \"./actions\";\n"],"names":[],"version":3,"file":"data-sheet.ce2a3218.js.map"}
1
+ {"mappings":"","sources":["packages/data-sheet/src/components/index.ts"],"sourcesContent":["export * from \"./editor-popup\";\nexport * from \"./colors\";\nexport * from \"./text-areas\";\nexport * from \"./actions\";\n"],"names":[],"version":3,"file":"data-sheet.2e11f097.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;AAAA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AATA,4CAAwC;AACxC,4CAAwC;AACxC,4CAAuC;AACvC,2CAA0B;AAC1B,4CAAkC;AAClC,4CAAiC;AACjC,4CAA2C;AAC3C,4CAAiC;AACjC,4CAA2C;AAC3C,4CAA+B","sources":["packages/data-sheet/src/components/main.module.sass"],"sourcesContent":[".interaction-barrier\n pointer-events: all\n\n.editor-popup-target\n position: absolute\n display: block\n top: 0\n left: 0\n width: 100%\n height: 100%\n\n.editable-text-area\n position: relative\n\n textarea\n min-width: var(--data-editor-width, 15em)\n min-height: var(--data-editor-height, 10em)\n font-family: inherit\n font-size: inherit\n\n .tools\n position: absolute\n top: 0.2em\n right: 0.2em\n transform: scale(0.8)\n\n.hidden-editor\n opacity: 0\n\n.editor-value\n position: absolute\n top: 0\n left: 0\n width: 100%\n height: 100%\n\n\n// Color picker\n.color-picker-container\n :global\n .react-colorful__saturation\n border-radius: 0\n\n .react-colorful__hue\n border-radius: 0\n\n\n.color-swatch\n width: 18px\n height: 18px\n display: inline-block\n margin-right: 0.5em\n\n.color-swatch-container\n position: absolute\n top: 0\n left: 0\n right: 0\n bottom: 0\n display: flex\n flex-direction: row\n align-items: center\n gap: 0.3em\n\n.color-name\n position: relative\n flex-grow: 1\n display: block\n"],"names":[],"version":3,"file":"data-sheet.37e35216.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;AAAA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AATA,4CAAwC;AACxC,4CAAwC;AACxC,4CAAuC;AACvC,2CAA0B;AAC1B,4CAAkC;AAClC,4CAAiC;AACjC,4CAA2C;AAC3C,4CAAiC;AACjC,4CAA2C;AAC3C,4CAA+B","sources":["packages/data-sheet/src/components/main.module.sass"],"sourcesContent":[".interaction-barrier\n pointer-events: all\n\n.editor-popup-target\n position: absolute\n display: block\n top: 0\n left: 0\n width: 100%\n height: 100%\n\n.editable-text-area\n position: relative\n\n textarea\n min-width: var(--data-editor-width, 15em)\n min-height: var(--data-editor-height, 10em)\n font-family: inherit\n font-size: inherit\n\n .tools\n position: absolute\n top: 0.2em\n right: 0.2em\n transform: scale(0.8)\n\n.hidden-editor\n opacity: 0\n\n.editor-value\n position: absolute\n top: 0\n left: 0\n width: 100%\n height: 100%\n\n\n// Color picker\n.color-picker-container\n :global .w-color-sketch\n --sketch-background: var(--secondary-background) !important\n\n.color-swatch\n width: 18px\n height: 18px\n display: inline-block\n margin-right: 0.5em\n\n.color-swatch-container\n position: absolute\n top: 0\n left: 0\n right: 0\n bottom: 0\n display: flex\n flex-direction: row\n align-items: center\n gap: 0.3em\n\n.color-name\n position: relative\n flex-grow: 1\n display: block\n\n"],"names":[],"version":3,"file":"data-sheet.37e35216.js.map"}
@@ -1,9 +1,9 @@
1
- import {DataSheetAction as $4KklY$DataSheetAction, EditorPopup as $4KklY$EditorPopup, handleSpecialKeys as $4KklY$handleSpecialKeys} from "./data-sheet.ce2a3218.js";
1
+ import {DataSheetAction as $4KklY$DataSheetAction, EditorPopup as $4KklY$EditorPopup} from "./data-sheet.2e11f097.js";
2
2
  import $4KklY$datasheetd570ef95js from "./data-sheet.d570ef95.js";
3
3
  import "./data-sheet.ef63e366.css";
4
- import {DataSheetProvider as $4b6643d78a77a8eb$export$135c527978291360, singleFocusedCell as $4b6643d78a77a8eb$export$de0bb697976d7dcb, useSelector as $4b6643d78a77a8eb$export$2105062e25df4afe, useStoreAPI as $4b6643d78a77a8eb$export$54fc6f5c8f914926} from "./data-sheet.45e8d3b0.js";
4
+ import {DataSheetProvider as $4b6643d78a77a8eb$export$135c527978291360, singleFocusedCell as $4b6643d78a77a8eb$export$de0bb697976d7dcb, useSelector as $4b6643d78a77a8eb$export$2105062e25df4afe, useStoreAPI as $4b6643d78a77a8eb$export$54fc6f5c8f914926} from "./data-sheet.c9b6b6f2.js";
5
5
  import {HotkeysProvider as $4KklY$HotkeysProvider, ButtonGroup as $4KklY$ButtonGroup, Button as $4KklY$Button, Intent as $4KklY$Intent, InputGroup as $4KklY$InputGroup} from "@blueprintjs/core";
6
- import {Table2 as $4KklY$Table2, RowHeaderCell as $4KklY$RowHeaderCell, Column as $4KklY$Column, Cell as $8bdde5bf56f8afde$import$5573889ca4ff9ca2$f6f0c3fe4ec306ea} from "@blueprintjs/table";
6
+ import {Column as $4KklY$Column, RowHeaderCell as $4KklY$RowHeaderCell, Table2 as $4KklY$Table2, Cell as $8bdde5bf56f8afde$import$5573889ca4ff9ca2$f6f0c3fe4ec306ea} from "@blueprintjs/table";
7
7
  import "@blueprintjs/table/lib/css/table.css";
8
8
  import $4KklY$macrostrathyper from "@macrostrat/hyper";
9
9
  import $4KklY$immutabilityhelper from "immutability-helper";
@@ -30,12 +30,13 @@ var $8bdde5bf56f8afde$export$b556effaa3ad7d4a = /*#__PURE__*/ function(DataSheet
30
30
  return DataSheetDensity;
31
31
  }({});
32
32
  function $8bdde5bf56f8afde$export$dea56b0125f0282d(props) {
33
- const { data: data, columnSpec: columnSpec, columnSpecOptions: columnSpecOptions, editable: editable = true, enableColumnReordering: enableColumnReordering = false, enableFocusedCell: enableFocusedCell = false, ...rest } = props;
33
+ const { data: data, columnSpec: columnSpec, columnSpecOptions: columnSpecOptions, editable: editable = true, enableColumnReordering: enableColumnReordering = false, enableFocusedCell: enableFocusedCell = false, defaultColumnWidth: defaultColumnWidth = 150, ...rest } = props;
34
34
  return $8bdde5bf56f8afde$var$h((0, $4KklY$HotkeysProvider), $8bdde5bf56f8afde$var$h((0, $4b6643d78a77a8eb$export$135c527978291360), {
35
35
  data: data,
36
36
  columnSpec: columnSpec,
37
37
  columnSpecOptions: columnSpecOptions,
38
38
  enableColumnReordering: enableColumnReordering,
39
+ defaultColumnWidth: defaultColumnWidth,
39
40
  editable: editable,
40
41
  ...rest
41
42
  }, $8bdde5bf56f8afde$var$h($8bdde5bf56f8afde$var$_DataSheet, {
@@ -52,7 +53,7 @@ function $8bdde5bf56f8afde$var$_DataSheet({ onVisibleCellsChange: onVisibleCells
52
53
  * @param columnSpecOptions: Options for generating a column spec from data
53
54
  */ // For now, we only consider a single cell "focused" when we have one cell selected.
54
55
  // Multi-cell selections have a different set of "bulk" actions.
55
- const selection = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.selection);
56
+ const selectedRegions = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.selection);
56
57
  const data = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.data);
57
58
  const editable = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.editable);
58
59
  const deletedRows = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.deletedRows);
@@ -101,10 +102,10 @@ function $8bdde5bf56f8afde$var$_DataSheet({ onVisibleCellsChange: onVisibleCells
101
102
  const deleteSelectedRows = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.deleteSelectedRows);
102
103
  const _onDeleteRows = (0, $4KklY$useCallback)(()=>{
103
104
  deleteSelectedRows();
104
- onDeleteRows?.(selection);
105
+ onDeleteRows?.(selectedRegions);
105
106
  }, [
106
107
  onDeleteRows,
107
- selection,
108
+ selectedRegions,
108
109
  deleteSelectedRows
109
110
  ]);
110
111
  (0, $4KklY$useEffect)(()=>{
@@ -122,12 +123,14 @@ function $8bdde5bf56f8afde$var$_DataSheet({ onVisibleCellsChange: onVisibleCells
122
123
  ]);
123
124
  (0, $4KklY$useEffect)(()=>{
124
125
  if (!verbose) return;
125
- console.log("Selection", selection);
126
+ console.log("Selected regions", selectedRegions);
126
127
  }, [
127
- selection
128
+ selectedRegions
128
129
  ]);
129
- if (data == null) return null;
130
- const nDeletionCandidates = $8bdde5bf56f8afde$export$222fa1b971ddc36(selection).length;
130
+ const nDeletionCandidates = (0, $4KklY$useMemo)(()=>$8bdde5bf56f8afde$export$222fa1b971ddc36(selectedRegions).length, [
131
+ selectedRegions
132
+ ]);
133
+ const columnWidths = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.columnWidths);
131
134
  const numRows = Math.max(updatedData.length, data.length);
132
135
  let className = `${density}-density`;
133
136
  let rowHeight = 20;
@@ -149,6 +152,36 @@ function $8bdde5bf56f8afde$var$_DataSheet({ onVisibleCellsChange: onVisibleCells
149
152
  "--data-sheet-font-size": "18px"
150
153
  };
151
154
  }
155
+ const children = (0, $4KklY$useMemo)(()=>columnSpec.map((col, colIndex)=>{
156
+ return $8bdde5bf56f8afde$var$h((0, $4KklY$Column), {
157
+ name: col.name,
158
+ cellRenderer: (rowIndex)=>{
159
+ const state = storeAPI.getState();
160
+ return $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, col, state, autoFocusEditor);
161
+ }
162
+ });
163
+ }), [
164
+ columnSpec,
165
+ storeAPI,
166
+ autoFocusEditor
167
+ ]);
168
+ const onColumnWidthChanged = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.onColumnWidthChanged);
169
+ const rowHeaderCellRenderer = (0, $4KklY$useCallback)((rowIndex)=>{
170
+ let style = null;
171
+ if (deletedRows.has(rowIndex)) style = {
172
+ opacity: 0.5,
173
+ textDecoration: "line-through"
174
+ };
175
+ return $8bdde5bf56f8afde$var$h((0, $4KklY$RowHeaderCell), {
176
+ index: rowIndex,
177
+ name: `${rowIndex + 1}`,
178
+ style: style
179
+ });
180
+ }, [
181
+ deletedRows
182
+ ]);
183
+ const onKeyDown = (0, $4b6643d78a77a8eb$export$2105062e25df4afe)((state)=>state.tableKeyHandler);
184
+ if (data == null) return null;
152
185
  return $8bdde5bf56f8afde$var$h("div.data-sheet-container", {
153
186
  className: className,
154
187
  style: style
@@ -159,76 +192,33 @@ function $8bdde5bf56f8afde$var$_DataSheet({ onVisibleCellsChange: onVisibleCells
159
192
  }),
160
193
  dataSheetActions,
161
194
  $8bdde5bf56f8afde$var$h("div.data-sheet-holder", {
162
- onKeyDown (e) {
163
- // General key event
164
- if (e.key === "Escape") {
165
- // Clear selection on Escape
166
- storeAPI.getState().setSelection([]);
167
- e.preventDefault();
168
- }
169
- // Clear selection on Backspace or Delete
170
- if (e.key === "Backspace" || e.key === "Delete") {
171
- // Clear selection on Backspace or Delete
172
- storeAPI.getState().clearSelection();
173
- e.preventDefault();
174
- }
175
- // Handle arrow keys for navigation
176
- if (e.key.startsWith("Arrow")) {
177
- // Handle arrow key navigation
178
- const direction = e.key.replace("Arrow", "").toLowerCase();
179
- const state = storeAPI.getState();
180
- state.moveFocusedCell(direction);
181
- // Prevent default scrolling behavior
182
- e.preventDefault();
183
- }
184
- }
185
- }, [
186
- $8bdde5bf56f8afde$var$h(// @ts-expect-error
187
- (0, $4KklY$Table2), {
188
- ref: ref,
189
- numRows: numRows,
190
- className: "data-sheet",
191
- enableFocusedCell: enableFocusedCell,
192
- enableColumnReordering: enableColumnReordering,
193
- focusedCell: //onColumnsReordered,
195
+ onKeyDown: onKeyDown
196
+ }, $8bdde5bf56f8afde$var$h(// @ts-expect-error
197
+ (0, $4KklY$Table2), {
198
+ ref: ref,
199
+ numRows: numRows,
200
+ className: "data-sheet",
201
+ enableFocusedCell: enableFocusedCell,
202
+ enableColumnReordering: enableColumnReordering,
203
+ focusedCell: //onColumnsReordered,
204
+ focusedCell,
205
+ selectedRegions: selectedRegions,
206
+ defaultRowHeight: rowHeight,
207
+ minRowHeight: rowHeight,
208
+ columnWidths: columnWidths,
209
+ onColumnWidthChanged: onColumnWidthChanged,
210
+ onSelection: onSelection,
211
+ // The cell renderer is memoized internally based on these data dependencies
212
+ cellRendererDependencies: [
213
+ data,
214
+ //selection,
215
+ updatedData,
194
216
  focusedCell,
195
- selectedRegions: selection,
196
- defaultRowHeight: rowHeight,
197
- minRowHeight: rowHeight,
198
- columnWidths: columnSpec.map((col)=>col.width ?? defaultColumnWidth),
199
- onSelection: onSelection,
200
- // The cell renderer is memoized internally based on these data dependencies
201
- cellRendererDependencies: [
202
- data,
203
- selection,
204
- updatedData,
205
- focusedCell,
206
- deletedRows
207
- ],
208
- onVisibleCellsChange: _onVisibleCellsChange,
209
- rowHeaderCellRenderer: (rowIndex)=>{
210
- let style = null;
211
- let intent = undefined;
212
- if (deletedRows.has(rowIndex)) style = {
213
- opacity: 0.5,
214
- textDecoration: "line-through"
215
- };
216
- return $8bdde5bf56f8afde$var$h((0, $4KklY$RowHeaderCell), {
217
- index: rowIndex,
218
- name: `${rowIndex + 1}`,
219
- style: style
220
- });
221
- }
222
- }, columnSpec.map((col, colIndex)=>{
223
- return $8bdde5bf56f8afde$var$h((0, $4KklY$Column), {
224
- name: col.name,
225
- cellRenderer: (rowIndex)=>{
226
- const state = storeAPI.getState();
227
- return $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, col, state, autoFocusEditor);
228
- }
229
- });
230
- }))
231
- ])
217
+ deletedRows
218
+ ],
219
+ onVisibleCellsChange: _onVisibleCellsChange,
220
+ rowHeaderCellRenderer: rowHeaderCellRenderer
221
+ }, children))
232
222
  ]);
233
223
  }
234
224
  function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEditor = true) {
@@ -244,8 +234,6 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
244
234
  const clearSelection = state.clearSelection;
245
235
  const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];
246
236
  const _renderedValue = col.valueRenderer?.(value) ?? value;
247
- let cellContents = _renderedValue;
248
- const editable = (col.editable ?? state.editable) && !isDeleted;
249
237
  let style = col.style ?? {};
250
238
  if (isDeleted) style = {
251
239
  ...style,
@@ -253,6 +241,7 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
253
241
  textDecoration: "line-through"
254
242
  };
255
243
  const focused = focusedCell?.col === colIndex && focusedCell?.row === rowIndex;
244
+ const editable = (col.editable ?? state.editable) && !isDeleted;
256
245
  // Top left cell of a ranged selection
257
246
  const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
258
247
  if (!editable && state.editable) // If the cell is not editable but the sheet is editable, we want to differentiate
@@ -270,32 +259,38 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
270
259
  value: value,
271
260
  style: style,
272
261
  isDeleted: isDeleted
273
- }, cellContents);
262
+ }, _renderedValue);
274
263
  // The rest is for the top-left cell of a selection or the focused cell
264
+ // Hidden input to capture key events
265
+ let hiddenInput = $8bdde5bf56f8afde$var$h("input.hidden-input", {
266
+ autoFocus: true,
267
+ onKeyDown: state.editorKeyHandler
268
+ });
269
+ let cellContents = _renderedValue;
270
+ let _dataEditor = null;
271
+ let className = null;
272
+ if (col.dataEditor != null) _dataEditor = $8bdde5bf56f8afde$var$h((0, $4KklY$EditorPopup), {
273
+ autoFocus: autoFocusEditor,
274
+ valueViewer: _renderedValue
275
+ }, [
276
+ $8bdde5bf56f8afde$var$h(col.dataEditor, {
277
+ value: value,
278
+ editable: editable,
279
+ onChange (value) {
280
+ if (!editable) return;
281
+ state.onSelectionEdited(value);
282
+ }
283
+ })
284
+ ]);
275
285
  if (!editable) {
276
286
  // Most cells are not focused and don't need to be editable.
277
287
  // This will be the rendering logic for almost all cells
278
- if (col.dataEditor != null) cellContents = $8bdde5bf56f8afde$var$h((0, $4KklY$EditorPopup), {
279
- autoFocus: autoFocusEditor,
280
- content: $8bdde5bf56f8afde$var$h(col.dataEditor, {
281
- value: value
282
- }),
283
- valueViewer: _renderedValue
284
- });
288
+ if (_dataEditor != null) cellContents = _dataEditor;
285
289
  return $8bdde5bf56f8afde$var$h(_Cell, {
286
290
  intent: intent,
287
291
  value: value,
288
292
  style: style
289
- }, [
290
- $8bdde5bf56f8afde$var$h.if(!focused)("input.hidden-input", {
291
- autoFocus: true,
292
- onKeyDown (e) {
293
- if (e.key == "Backspace" || e.key == "Delete") clearSelection();
294
- e.preventDefault();
295
- }
296
- }),
297
- cellContents
298
- ]);
293
+ }, cellContents);
299
294
  // Could probably put the hidden input elsewhere,
300
295
  }
301
296
  /* The remaining logic covers cells that are focused and editable */ const onChange = (e)=>{
@@ -303,6 +298,7 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
303
298
  if (value === e.target.value) return;
304
299
  onCellEdited(rowIndex, col.key, e.target.value);
305
300
  };
301
+ const isSingleCellSelection = (0, $4b6643d78a77a8eb$export$de0bb697976d7dcb)(state.selection) != null;
306
302
  let _inlineEditor = null;
307
303
  if (typeof inlineEditor == "boolean") {
308
304
  let _value = value;
@@ -311,42 +307,19 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
311
307
  value: _value ?? "",
312
308
  autoFocus: autoFocusEditor,
313
309
  onChange: onChange,
314
- onKeyDown (e) {
315
- console.log("Key down in inline editor", e.key);
316
- if (e.key == "Enter") e.target.blur();
317
- if (e.key == "Escape") {
318
- e.target.blur();
319
- e.preventDefault();
320
- return;
321
- }
322
- const shouldPropagate = (0, $4KklY$handleSpecialKeys)(e, e.target);
323
- if (!shouldPropagate) e.stopPropagation();
324
- else e.target.blur();
325
- }
310
+ onKeyDown: state.editorKeyHandler
326
311
  });
327
312
  } else // If inlineEditor is a ReactNode, we use it directly
328
313
  _inlineEditor = inlineEditor;
329
- let className = null;
330
- if (col.dataEditor != null) {
314
+ if (_dataEditor != null) {
331
315
  className = "editor-cell";
332
- cellContents = $8bdde5bf56f8afde$var$h([
333
- $8bdde5bf56f8afde$var$h((0, $4KklY$EditorPopup), {
334
- autoFocus: autoFocusEditor,
335
- content: $8bdde5bf56f8afde$var$h(col.dataEditor, {
336
- value: value,
337
- onChange (value) {
338
- if (!editable) return;
339
- onCellEdited(rowIndex, col.key, value);
340
- }
341
- }),
342
- valueViewer: _renderedValue
343
- })
344
- ]);
316
+ cellContents = _dataEditor;
317
+ hiddenInput = null;
345
318
  } else if (_inlineEditor != null) {
346
319
  cellContents = _inlineEditor;
347
320
  className = "input-cell";
321
+ hiddenInput = null;
348
322
  }
349
- const isSingleCellSelection = (0, $4b6643d78a77a8eb$export$de0bb697976d7dcb)(state.selection) != null;
350
323
  // Hidden html input
351
324
  return $8bdde5bf56f8afde$var$h(_Cell, {
352
325
  intent: intent,
@@ -357,7 +330,8 @@ function $8bdde5bf56f8afde$var$basicCellRenderer(rowIndex, colIndex, columnSpec,
357
330
  cellContents,
358
331
  $8bdde5bf56f8afde$var$h.if(editable && isSingleCellSelection)($8bdde5bf56f8afde$var$DragHandle, {
359
332
  focusedCell: focusedCell
360
- })
333
+ }),
334
+ hiddenInput
361
335
  ]);
362
336
  }
363
337
  function $8bdde5bf56f8afde$var$DragHandle({ focusedCell: focusedCell }) {
@@ -452,4 +426,4 @@ function $8bdde5bf56f8afde$export$222fa1b971ddc36(selection) {
452
426
 
453
427
 
454
428
  export {$8bdde5bf56f8afde$export$b556effaa3ad7d4a as DataSheetDensity, $8bdde5bf56f8afde$export$dea56b0125f0282d as DataSheet, $8bdde5bf56f8afde$export$222fa1b971ddc36 as getRowsToDelete, $8bdde5bf56f8afde$export$41ad0bbfa4755cac as BaseCell, $8bdde5bf56f8afde$export$e7db3202e96fc463 as ScrollToRowControl, $8bdde5bf56f8afde$import$5573889ca4ff9ca2$f6f0c3fe4ec306ea as Cell};
455
- //# sourceMappingURL=data-sheet.ce24dcf9.js.map
429
+ //# sourceMappingURL=data-sheet.403b9693.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,qEAAK;AAOrB,IAAA,AAAK,mEAAA;;;;WAAA;;AAsBL,SAAS,0CAAa,KAAwB;IACnD,MAAM,QACJ,IAAI,cACJ,UAAU,qBACV,iBAAiB,YACjB,WAAW,8BACX,yBAAyB,0BACzB,oBAAoB,2BACpB,qBAAqB,KACrB,GAAG,MACJ,GAAG;IAEJ,OAAO,wBACL,CAAA,GAAA,sBAAc,GACd,wBACE,CAAA,GAAA,yCAAgB,GAChB;cACE;oBACA;QACA,mBAAmB;gCACnB;4BACA;kBACA;QACA,GAAG,IAAI;IACT,GACA,wBAAE,kCAAY;QACZ,GAAG,IAAI;kBACP;gCACA;2BACA;IACF;AAGN;AAEA,SAAS,iCAAc,wBACrB,oBAAoB,0BACpB,sBAAsB,cACtB,UAAU,gBACV,YAAY,gBACZ,YAAY,WACZ,UAAU,yBACV,mBAAm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SAAS;YACX,GACA;SAEH;KACF;AACH;AAEO,SAAS;IACd,MAAM,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACnC,MAAM,cAAc,CAAA,GAAA,yCAAU,EAAE,CAAC,QAAU,MAAM,WAAW;IAE5D,OAAO,wBAAE,CAAA,GAAA,sBAAc,GAAG;QACxB,wBAAE,CAAA,GAAA,iBAAS,GAAG;YACZ,MAAM;YACN,aAAa;mBACb;YACA,eAAc,KAAK;gBACjB,SAAS;YACX;QACF;QACA,wBACE,CAAA,GAAA,aAAK,GACL;YACE,MAAM;YACN;gBACE,MAAM,MAAM,SAAS;gBACrB,YAAY,MAAM;YACpB;QACF,GACA;KAEH;AACH;AAEA,SAAS;IACP,MAAM,SAAS,CAAA,GAAA,yCAAU,EAAE,CAAC,QAAU,MAAM,MAAM;IAClD,OAAO,wBACL,CAAA,GAAA,aAAK,GACL;QACE,MAAM;QACN,SAAS;IACX,GACA;AAEJ;AAEO,SAAS,0CAAS,YAAE,QAAQ,SAAE,KAAK,EAAE,GAAG,MAAM;IACnD,OAAO,wBACL,CAAA,GAAA,0DAAG,GACH;QACE,aAAa;QACb,GAAG,IAAI;IACT,GACA;AAEJ;AAIO,SAAS,yCAAgB,SAAS;IACvC,IAAI,aAAuB,EAAE;IAC7B,KAAK,MAAM,OAAO,UAAW;QAC3B,kCAAkC;QAClC,IAAI,IAAI,IAAI,IAAI,MAAM;QACtB,IAAI,IAAI,IAAI,IAAI,MAAM;QACtB,MAAM,CAAC,YAAY,SAAS,GAAG,IAAI,IAAI;QACvC,IAAK,IAAI,IAAI,YAAY,KAAK,UAAU,IACtC,WAAW,IAAI,CAAC;IAEpB;IACA,OAAO;AACT","sources":["packages/data-sheet/src/core.ts"],"sourcesContent":["import {\n Button,\n ButtonGroup,\n HotkeysProvider,\n InputGroup,\n Intent,\n} from \"@blueprintjs/core\";\nimport {\n Cell,\n Column,\n Region,\n RowHeaderCell,\n Table2,\n} from \"@blueprintjs/table\";\nimport \"@blueprintjs/table/lib/css/table.css\";\nimport hyper from \"@macrostrat/hyper\";\nimport update from \"immutability-helper\";\nimport { ReactNode, useCallback, useEffect, useMemo, useState } from \"react\";\nimport { EditorPopup, DataSheetAction } from \"./components\";\nimport styles from \"./main.module.sass\";\nimport {\n DataSheetProvider,\n DataSheetProviderProps,\n DataSheetStore,\n singleFocusedCell,\n useSelector,\n useStoreAPI,\n VisibleCells,\n} from \"./provider\";\nimport { ColumnSpec } from \"./utils\";\n\nconst h = hyper.styled(styles);\n\n// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args\n\n// TODO: add a \"copy to selection\" tool (the little square in the bottom right corner of a cell)\n// This should copy the value of a cell (or a set of cells in the same row) downwards.\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\ninterface DataSheetInternalProps<T> {\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onSaveData?: (updatedData: any[], data: T[]) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableFocusedCell?: boolean;\n dataSheetActions?: ReactNode | null;\n editable?: boolean;\n autoFocusEditor?: boolean;\n density?: DataSheetDensity;\n}\n\ntype DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;\n\nexport function DataSheet<T>(props: DataSheetProps<T>) {\n const {\n data,\n columnSpec,\n columnSpecOptions,\n editable = true,\n enableColumnReordering = false,\n enableFocusedCell = false,\n defaultColumnWidth = 150,\n ...rest\n } = props;\n\n return h(\n HotkeysProvider,\n h(\n DataSheetProvider<T>,\n {\n data,\n columnSpec,\n columnSpecOptions: columnSpecOptions,\n enableColumnReordering,\n defaultColumnWidth,\n editable,\n ...rest,\n },\n h(_DataSheet, {\n ...rest,\n editable,\n enableColumnReordering,\n enableFocusedCell,\n }),\n ),\n );\n}\n\nfunction _DataSheet<T>({\n onVisibleCellsChange,\n enableColumnReordering,\n onSaveData,\n onUpdateData,\n onDeleteRows,\n verbose = false,\n dataSheetActions = null,\n enableFocusedCell,\n autoFocusEditor = true,\n density = DataSheetDensity.HIGH,\n}: DataSheetInternalProps<T>) {\n /**\n * @param data: The data to be displayed in the table\n * @param columnSpec: The specification for all columns in the table. If not provided, the column spec will be generated from the data.\n * @param columnSpecOptions: Options for generating a column spec from data\n */\n\n // For now, we only consider a single cell \"focused\" when we have one cell selected.\n // Multi-cell selections have a different set of \"bulk\" actions.\n const selectedRegions = useSelector<T>((state) => state.selection);\n\n const data = useSelector((state) => state.data);\n const editable = useSelector((state) => state.editable);\n\n const deletedRows = useSelector((state) => state.deletedRows);\n\n const focusedCell = useSelector((state) => state.focusedCell);\n\n const ref = useSelector((state) => state.tableRef);\n\n const columnSpec = useSelector((state) => state.columnSpec);\n\n // A sparse array to hold updates\n // TODO: create a \"changeset\" concept to facilitate undo/redo\n const updatedData = useSelector((state) => state.updatedData);\n const setUpdatedData = useSelector((state) => state.setUpdatedData);\n\n const onSelection = useSelector((state) => state.onSelection);\n\n const storeAPI = useStoreAPI<T>();\n\n const _onSaveData = useMemo(() => {\n if (onSaveData == null) return null;\n return () => {\n onSaveData(updatedData, data);\n setUpdatedData([]);\n };\n }, [updatedData, data, onSaveData]);\n\n const setVisibleCells = useSelector((state) => state.setVisibleCells);\n\n const _onVisibleCellsChange = useCallback(\n (visibleCells: VisibleCells) => {\n setVisibleCells(visibleCells);\n onVisibleCellsChange?.(visibleCells);\n },\n [onVisibleCellsChange, setVisibleCells],\n );\n\n const onAddRow = useCallback(() => {\n setUpdatedData((updatedData: any[]): any[] => {\n const ix = Math.max(updatedData.length, data.length);\n const addRowSpec = { [ix]: { $set: {} } };\n const newUpdatedData = update(updatedData, addRowSpec);\n return newUpdatedData;\n });\n }, [setUpdatedData]);\n\n const deleteSelectedRows = useSelector((state) => state.deleteSelectedRows);\n const _onDeleteRows = useCallback(() => {\n deleteSelectedRows();\n onDeleteRows?.(selectedRegions);\n }, [onDeleteRows, selectedRegions, deleteSelectedRows]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Updated data\", updatedData);\n }, [updatedData]);\n\n useEffect(() => {\n onUpdateData?.(updatedData, data);\n }, [onUpdateData, data, updatedData]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Selected regions\", selectedRegions);\n }, [selectedRegions]);\n\n const nDeletionCandidates = useMemo(\n () => getRowsToDelete(selectedRegions).length,\n [selectedRegions],\n );\n\n const columnWidths = useSelector((state) => state.columnWidths);\n\n const numRows = Math.max(updatedData.length, data.length);\n\n let className = `${density}-density`;\n\n let rowHeight = 20;\n let defaultColumnWidth = 150;\n let style = {\n \"--data-sheet-row-height\": \"20px\",\n \"--data-sheet-font-size\": \"12px\",\n };\n if (density === DataSheetDensity.MEDIUM) {\n rowHeight = 24;\n style = {\n \"--data-sheet-row-height\": \"24px\",\n \"--data-sheet-font-size\": \"14px\",\n };\n } else if (density === DataSheetDensity.LOW) {\n rowHeight = 30;\n style = {\n \"--data-sheet-row-height\": \"30px\",\n \"--data-sheet-font-size\": \"18px\",\n };\n }\n\n const children = useMemo(\n () =>\n columnSpec.map((col, colIndex) => {\n return h(Column, {\n name: col.name,\n cellRenderer: (rowIndex) => {\n const state = storeAPI.getState();\n return basicCellRenderer<T>(\n rowIndex,\n colIndex,\n col,\n state,\n autoFocusEditor,\n );\n },\n });\n }),\n [columnSpec, storeAPI, autoFocusEditor],\n );\n\n const onColumnWidthChanged = useSelector(\n (state) => state.onColumnWidthChanged,\n );\n\n const rowHeaderCellRenderer = useCallback(\n (rowIndex: number) => {\n let style = null;\n if (deletedRows.has(rowIndex)) {\n style = {\n opacity: 0.5,\n textDecoration: \"line-through\",\n };\n }\n return h(RowHeaderCell, {\n index: rowIndex,\n name: `${rowIndex + 1}`,\n style,\n });\n },\n [deletedRows],\n );\n\n const onKeyDown = useSelector((state) => state.tableKeyHandler);\n\n if (data == null) return null;\n\n return h(\"div.data-sheet-container\", { className, style }, [\n h.if(editable)(DataSheetEditToolbar, {\n onSaveData: _onSaveData,\n onDeleteRows: nDeletionCandidates > 0 ? _onDeleteRows : null,\n }),\n dataSheetActions,\n h(\n \"div.data-sheet-holder\",\n { onKeyDown },\n h(\n // @ts-expect-error\n Table2,\n {\n ref,\n numRows,\n className: \"data-sheet\",\n enableFocusedCell,\n enableColumnReordering,\n //onColumnsReordered,\n focusedCell,\n selectedRegions,\n defaultRowHeight: rowHeight,\n minRowHeight: rowHeight,\n columnWidths,\n onColumnWidthChanged,\n onSelection,\n // The cell renderer is memoized internally based on these data dependencies\n cellRendererDependencies: [\n data,\n //selection,\n updatedData,\n focusedCell,\n deletedRows,\n ],\n onVisibleCellsChange: _onVisibleCellsChange,\n rowHeaderCellRenderer,\n },\n children,\n ),\n ),\n ]);\n}\n\nfunction basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n autoFocusEditor = true,\n): any {\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.deletedRows.has(rowIndex);\n\n const row = data[rowIndex] ?? updatedData[rowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const focusedCell = state.focusedCell;\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n const clearSelection = state.clearSelection;\n\n const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];\n const _renderedValue = col.valueRenderer?.(value) ?? value;\n\n let style = col.style ?? {};\n if (isDeleted) {\n style = {\n ...style,\n opacity: 0.5,\n textDecoration: \"line-through\",\n };\n }\n\n const focused =\n focusedCell?.col === colIndex && focusedCell?.row === rowIndex;\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // Top left cell of a ranged selection\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n if (!editable && state.editable) {\n // If the cell is not editable but the sheet is editable, we want to differentiate\n // between editable and non-editable cells.\n style.color = \"var(--secondary-color)\";\n }\n\n const edited = updatedData[rowIndex]?.[col.key] != null;\n let intent = edited ? \"success\" : undefined;\n if (isDeleted) {\n intent = \"danger\";\n }\n\n const _Cell = col.cellComponent ?? BaseCell;\n\n let inlineEditor = editable ? (col.inlineEditor ?? true) : false;\n\n if (!topLeft) {\n // This should be the case for every cell except the focused one\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n isDeleted,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Hidden input to capture key events\n let hiddenInput = h(\"input.hidden-input\", {\n autoFocus: true,\n onKeyDown: state.editorKeyHandler,\n });\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (col.dataEditor != null) {\n _dataEditor = h(\n EditorPopup,\n {\n autoFocus: autoFocusEditor,\n valueViewer: _renderedValue,\n },\n [\n h(col.dataEditor, {\n value,\n editable,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n // Most cells are not focused and don't need to be editable.\n // This will be the rendering logic for almost all cells\n\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n },\n cellContents,\n );\n // Could probably put the hidden input elsewhere,\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (value === e.target.value) return;\n onCellEdited(rowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(\"input.main-editor\", {\n value: _value ?? \"\",\n autoFocus: autoFocusEditor,\n onChange,\n onKeyDown: state.editorKeyHandler,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle, {\n focusedCell,\n }),\n hiddenInput,\n ],\n );\n}\n\nfunction DragHandle({ focusedCell }) {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onDragValue = useSelector((state) => state.onDragValue);\n\n return h(\"div.corner-drag-handle\", {\n onMouseDown(e) {\n onDragValue(focusedCell);\n e.preventDefault();\n },\n });\n}\n\nfunction DataSheetEditToolbar({ onSaveData, onDeleteRows }) {\n const selection = useSelector((state) => state.selection);\n const resetChanges = useSelector((state) => state.resetChanges);\n const hasUpdates = useSelector((state) => state.hasUpdates);\n\n return h(\"div.data-sheet-toolbar\", [\n h(ButtonGroup, { minimal: true }, [\n h(AddRowButton),\n h(\n Button,\n {\n intent: Intent.DANGER,\n disabled: onDeleteRows == null,\n onClick() {\n onDeleteRows?.();\n },\n },\n \"Delete\",\n ),\n ]),\n h(\"div.spacer\"),\n h(ButtonGroup, [\n h(\n Button,\n {\n intent: Intent.WARNING,\n disabled: !hasUpdates,\n onClick: resetChanges,\n },\n \"Reset\",\n ),\n h.if(onSaveData != null)(\n Button,\n {\n intent: Intent.SUCCESS,\n icon: \"floppy-disk\",\n disabled: !hasUpdates,\n onClick: onSaveData,\n },\n \"Save\",\n ),\n ]),\n ]);\n}\n\nexport function ScrollToRowControl() {\n const [value, setValue] = useState(\"\");\n const scrollToRow = useSelector((state) => state.scrollToRow);\n\n return h(DataSheetAction, [\n h(InputGroup, {\n type: \"number\",\n placeholder: \"Row number\",\n value,\n onValueChange(value) {\n setValue(value);\n },\n }),\n h(\n Button,\n {\n icon: \"arrow-right\",\n onClick() {\n const row = parseInt(value);\n scrollToRow(row - 1);\n },\n },\n \"Scroll to row\",\n ),\n ]);\n}\n\nfunction AddRowButton() {\n const addRow = useSelector((state) => state.addRow);\n return h(\n Button,\n {\n icon: \"plus\",\n onClick: addRow,\n },\n \"Add row\",\n );\n}\n\nexport function BaseCell({ children, value, ...rest }) {\n return h(\n Cell,\n {\n interactive: true,\n ...rest,\n },\n children,\n );\n}\n\nexport { Cell };\n\nexport function getRowsToDelete(selection) {\n let rowIndices: number[] = [];\n for (const sel of selection) {\n // This isn't a full-row selection\n if (sel.cols != null) continue;\n if (sel.rows == null) continue;\n const [startIndex, endIndex] = sel.rows;\n for (let i = startIndex; i <= endIndex; i++) {\n rowIndices.push(i);\n }\n }\n return rowIndices;\n}\n"],"names":[],"version":3,"file":"data-sheet.403b9693.js.map"}
@@ -1,5 +1,6 @@
1
1
  import $eBkqD$datasheet37e35216js from "./data-sheet.37e35216.js";
2
- import "./data-sheet.91223ec6.css";
2
+ import "./data-sheet.a7230b2f.css";
3
+ import {multiLineTextKeyHandler as $eBkqD$multiLineTextKeyHandler} from "./data-sheet.8dbfccef.js";
3
4
  import $eBkqD$macrostrathyper from "@macrostrat/hyper";
4
5
  import {Button as $eBkqD$Button} from "@blueprintjs/core";
5
6
  import {useRef as $eBkqD$useRef, useEffect as $eBkqD$useEffect} from "react";
@@ -12,6 +13,7 @@ function $parcel$interopDefault(a) {
12
13
 
13
14
 
14
15
 
16
+
15
17
  const $0aa421c11d2af971$var$h = (0, $eBkqD$macrostrathyper).styled((0, ($parcel$interopDefault($eBkqD$datasheet37e35216js))));
16
18
  function $0aa421c11d2af971$export$b8e68c321a6269f1({ value: value, onChange: onChange }) {
17
19
  const ref = (0, $eBkqD$useRef)(null);
@@ -28,19 +30,7 @@ function $0aa421c11d2af971$export$b8e68c321a6269f1({ value: value, onChange: onC
28
30
  ref: ref,
29
31
  value: value ?? "",
30
32
  onChange: (evt)=>onChange(evt.target.value),
31
- onKeyDown: (evt)=>{
32
- if (evt.key === "Enter") {
33
- //evt.preventDefault();
34
- evt.stopPropagation();
35
- return;
36
- }
37
- if (evt.key === "Escape") {
38
- evt.preventDefault();
39
- return;
40
- }
41
- const shouldPropagate = $0aa421c11d2af971$export$52c8c5a1aad17e2a(evt, evt.target);
42
- if (!shouldPropagate) evt.stopPropagation();
43
- }
33
+ onKeyDown: (0, $eBkqD$multiLineTextKeyHandler)
44
34
  }),
45
35
  $0aa421c11d2af971$var$h("div.tools", [
46
36
  $0aa421c11d2af971$var$h((0, $eBkqD$Button), {
@@ -62,18 +52,7 @@ function $0aa421c11d2af971$export$b8e68c321a6269f1({ value: value, onChange: onC
62
52
  ])
63
53
  ]);
64
54
  }
65
- function $0aa421c11d2af971$export$52c8c5a1aad17e2a(evt, target) {
66
- if ((evt.key === "ArrowLeft" || evt.key === "ArrowUp" || evt.key === "ArrowDown") && target.selectionStart === 0) {
67
- target.blur();
68
- return true;
69
- }
70
- if ((evt.key === "ArrowRight" || evt.key === "ArrowUp" || evt.key === "Tab" || evt.key === "Enter" || evt.key === "ArrowDown") && target.selectionStart === evt.target.value.length) {
71
- target.blur();
72
- return true;
73
- }
74
- return false;
75
- }
76
55
 
77
56
 
78
- export {$0aa421c11d2af971$export$b8e68c321a6269f1 as EditableTextArea, $0aa421c11d2af971$export$52c8c5a1aad17e2a as handleSpecialKeys};
79
- //# sourceMappingURL=data-sheet.b5946d6b.js.map
57
+ export {$0aa421c11d2af971$export$b8e68c321a6269f1 as EditableTextArea};
58
+ //# sourceMappingURL=data-sheet.40866550.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;AAMA,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,qEAAK;AAErB,SAAS,0CAAiB,SAAE,KAAK,YAAE,QAAQ,EAAE;IAClD,MAAM,MAAM,CAAA,GAAA,aAAK,EAAE;IAEnB,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,MAAM;QACzB,IAAI,OAAO,CAAC,KAAK;QACjB,wBAAwB;QACxB,MAAM,MAAM,IAAI,OAAO,CAAC,KAAK;QAC7B,yCAAyC;QACzC,IAAI,OAAO,CAAC,iBAAiB,CAAC,IAAI,MAAM,EAAE,IAAI,MAAM;IACtD,GAAG,EAAE;IAEL,OAAO,wBAAE,0BAA0B;QACjC,wBAAE,sBAAsB;iBACtB;YACA,OAAO,SAAS;YAChB,UAAU,CAAC,MAAQ,SAAS,IAAI,MAAM,CAAC,KAAK;YAC5C,WAAW,CAAA,GAAA,8BAAsB;QACnC;QACA,wBAAE,aAAa;YACb,wBAAE,CAAA,GAAA,aAAK,GAAG;gBACR,MAAM;gBACN,SAAS;gBACT,OAAO;gBACP;oBACE,sBAAsB;oBACtB,IAAI,SAAS,SAAS;oBAEtB,MAAM,YAAY,IAAI,OAAO,CAAC,cAAc,IAAI,OAAO,MAAM;oBAC7D,0CAA0C;oBAC1C,SAAS,OAAO,KAAK,CAAC,GAAG,aAAa,OAAO,OAAO,KAAK,CAAC;oBAC1D,wBAAwB;oBACxB,IAAI,OAAO,CAAC,KAAK;oBACjB,yCAAyC;oBACzC,IAAI,OAAO,CAAC,iBAAiB,CAAC,YAAY,GAAG,YAAY;gBAC3D;YACF;SACD;KACF;AACH","sources":["packages/data-sheet/src/components/text-areas.ts"],"sourcesContent":["import hyper from \"@macrostrat/hyper\";\nimport styles from \"./main.module.sass\";\nimport { Button } from \"@blueprintjs/core\";\nimport { useEffect, useRef } from \"react\";\nimport { multiLineTextKeyHandler } from \"../utils\";\n\nconst h = hyper.styled(styles);\n\nexport function EditableTextArea({ value, onChange }) {\n const ref = useRef(null);\n\n useEffect(() => {\n if (ref.current == null) return;\n ref.current.focus();\n // Get the current value\n const val = ref.current.value;\n // Move the cursor to the end of the text\n ref.current.setSelectionRange(val.length, val.length);\n }, []);\n\n return h(\"div.editable-text-area\", [\n h(\"textarea.bp5-input\", {\n ref,\n value: value ?? \"\",\n onChange: (evt) => onChange(evt.target.value),\n onKeyDown: multiLineTextKeyHandler,\n }),\n h(\"div.tools\", [\n h(Button, {\n icon: \"key-enter\",\n minimal: true,\n small: true,\n onClick() {\n // Get cursor position\n let _value = value ?? \"\";\n\n const cursorPos = ref.current.selectionStart ?? _value.length;\n // Insert a newline at the cursor position\n onChange(_value.slice(0, cursorPos) + \"\\n\" + _value.slice(cursorPos));\n // Re-focus the textarea\n ref.current.focus();\n // Move the cursor to the end of the line\n ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);\n },\n }),\n ]),\n ]);\n}\n"],"names":[],"version":3,"file":"data-sheet.40866550.js.map"}