@macrostrat/data-sheet 2.0.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 (79) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +19 -0
  3. package/dist/actions.5740e8e2.js +21 -0
  4. package/dist/actions.5740e8e2.js.map +1 -0
  5. package/dist/actions.module.6ec06797.css +11 -0
  6. package/dist/actions.module.6ec06797.css.map +1 -0
  7. package/dist/actions.module.ea96403b.js +16 -0
  8. package/dist/actions.module.ea96403b.js.map +1 -0
  9. package/dist/cell-renderers.de70f471.js +31 -0
  10. package/dist/cell-renderers.de70f471.js.map +1 -0
  11. package/dist/colors.41c3ed7a.js +83 -0
  12. package/dist/colors.41c3ed7a.js.map +1 -0
  13. package/dist/column-spec.4710da93.js +70 -0
  14. package/dist/column-spec.4710da93.js.map +1 -0
  15. package/dist/components.c3ad66e9.js +11 -0
  16. package/dist/components.c3ad66e9.js.map +1 -0
  17. package/dist/core.d8d80480.js +356 -0
  18. package/dist/core.d8d80480.js.map +1 -0
  19. package/dist/data-loaders.5302dedd.js +196 -0
  20. package/dist/data-loaders.5302dedd.js.map +1 -0
  21. package/dist/editor-popup.9259608f.js +68 -0
  22. package/dist/editor-popup.9259608f.js.map +1 -0
  23. package/dist/index.d.ts +202 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +9 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/main.module.846377cd.css +35 -0
  28. package/dist/main.module.846377cd.css.map +1 -0
  29. package/dist/main.module.914caa19.css +91 -0
  30. package/dist/main.module.914caa19.css.map +1 -0
  31. package/dist/main.module.93f91ad4.js +25 -0
  32. package/dist/main.module.93f91ad4.js.map +1 -0
  33. package/dist/main.module.dc8f6293.css +62 -0
  34. package/dist/main.module.dc8f6293.css.map +1 -0
  35. package/dist/main.module.de002429.js +43 -0
  36. package/dist/main.module.de002429.js.map +1 -0
  37. package/dist/main.module.ff717a08.js +37 -0
  38. package/dist/main.module.ff717a08.js.map +1 -0
  39. package/dist/postgrest-table.15ded3c1.js +173 -0
  40. package/dist/postgrest-table.15ded3c1.js.map +1 -0
  41. package/dist/provider.67e982b8.js +232 -0
  42. package/dist/provider.67e982b8.js.map +1 -0
  43. package/dist/text-areas.079e8b15.js +78 -0
  44. package/dist/text-areas.079e8b15.js.map +1 -0
  45. package/dist/utils.a37ed786.js +14 -0
  46. package/dist/utils.a37ed786.js.map +1 -0
  47. package/package.json +50 -0
  48. package/src/__archive/base.ts +55 -0
  49. package/src/__archive/components/column-utils.ts +126 -0
  50. package/src/__archive/components/index.ts +115 -0
  51. package/src/__archive/components/toolbar.ts +79 -0
  52. package/src/__archive/editors/index.ts +78 -0
  53. package/src/__archive/editors/styles.module.scss +10 -0
  54. package/src/__archive/enhancers.ts +36 -0
  55. package/src/__archive/index.ts +8 -0
  56. package/src/__archive/main.ts +180 -0
  57. package/src/__archive/provider.ts +179 -0
  58. package/src/__archive/styles.module.scss +56 -0
  59. package/src/__archive/test-sheet/attitude-sheet.old.styl +53 -0
  60. package/src/__archive/test-sheet/attitude-sheet.scss +60 -0
  61. package/src/__archive/test-sheet/index.ts +210 -0
  62. package/src/__archive/virtualized.ts +82 -0
  63. package/src/components/actions.module.sass +8 -0
  64. package/src/components/actions.ts +11 -0
  65. package/src/components/colors.ts +90 -0
  66. package/src/components/editor-popup.ts +69 -0
  67. package/src/components/index.ts +3 -0
  68. package/src/components/main.module.sass +35 -0
  69. package/src/components/text-areas.ts +88 -0
  70. package/src/core.ts +481 -0
  71. package/src/index.ts +2 -0
  72. package/src/main.module.sass +77 -0
  73. package/src/postgrest-table/cell-renderers.ts +24 -0
  74. package/src/postgrest-table/data-loaders.ts +287 -0
  75. package/src/postgrest-table/index.ts +172 -0
  76. package/src/postgrest-table/main.module.sass +52 -0
  77. package/src/provider.ts +282 -0
  78. package/src/utils/column-spec.ts +97 -0
  79. package/src/utils/index.ts +7 -0
@@ -0,0 +1,90 @@
1
+ import { Cell } from "@blueprintjs/table";
2
+ import { useInDarkMode } from "@macrostrat/ui-components";
3
+ import hyper from "@macrostrat/hyper";
4
+ import styles from "./main.module.sass";
5
+ import { asChromaColor } from "@macrostrat/color-utils";
6
+ import { HexColorPicker } from "react-colorful";
7
+ import { useEffect, useRef } from "react";
8
+ import { memoize } from "underscore";
9
+
10
+ const h = hyper.styled(styles);
11
+
12
+ export function ColorCell({ value, children, style, intent, ...rest }) {
13
+ const darkMode = useInDarkMode();
14
+
15
+ return h(
16
+ Cell,
17
+ {
18
+ ...rest,
19
+ style: {
20
+ ...style,
21
+ ...colorCombo(value, darkMode),
22
+ },
23
+ },
24
+ children
25
+ );
26
+ }
27
+
28
+ const colorCombo = memoize((color, darkMode) =>
29
+ pleasantCombination(color, { darkMode })
30
+ );
31
+
32
+ export function pleasantCombination(
33
+ color,
34
+ { luminance = null, backgroundAlpha = 0.2, darkMode = false } = {}
35
+ ) {
36
+ const brighten = luminance ?? darkMode ? 0.5 : 0.1;
37
+
38
+ // Check if is a chroma color
39
+ color = asChromaColor(color);
40
+ if (color == null) return {};
41
+ return {
42
+ color: color?.luminance?.(brighten).css(),
43
+ backgroundColor: color?.alpha?.(backgroundAlpha).css(),
44
+ };
45
+ }
46
+
47
+ enum ColorConversionType {
48
+ HEX = "hex",
49
+ RGB = "rgb",
50
+ HSL = "hsl",
51
+ CSS = "css",
52
+ }
53
+
54
+ export function ColorPicker({
55
+ value,
56
+ onChange,
57
+ type = ColorConversionType.CSS,
58
+ }) {
59
+ const ref = useRef(null);
60
+ useEffect(() => {
61
+ if (ref.current == null) return;
62
+ ref.current.focus();
63
+ }, []);
64
+
65
+ let color: any;
66
+ try {
67
+ color = asChromaColor(value).hex();
68
+ } catch {
69
+ color = "#aaaaaa";
70
+ }
71
+ return h(
72
+ "div.color-picker-container",
73
+ {
74
+ onKeyDown(evt) {
75
+ console.log(evt);
76
+ if (evt.key === "Escape") {
77
+ evt.preventDefault();
78
+ }
79
+ },
80
+ ref,
81
+ tabIndex: 0,
82
+ },
83
+ h(HexColorPicker, {
84
+ color,
85
+ onChange(color) {
86
+ onChange(asChromaColor(color)[type]());
87
+ },
88
+ })
89
+ );
90
+ }
@@ -0,0 +1,69 @@
1
+ import hyper from "@macrostrat/hyper";
2
+ import { ErrorBoundary } from "@macrostrat/ui-components";
3
+ import { Popover } from "@blueprintjs/core";
4
+ import styles from "./main.module.sass";
5
+ import { useRef, useState } from "react";
6
+
7
+ const h = hyper.styled(styles);
8
+
9
+ export function EditorPopup(props) {
10
+ const {
11
+ children,
12
+ content,
13
+ targetClassName,
14
+ autoFocus,
15
+ valueViewer,
16
+ inlineEditor,
17
+ } = props;
18
+
19
+ const [isOpen, setIsOpen] = useState(autoFocus);
20
+
21
+ const ref = useRef(null);
22
+
23
+ return h(
24
+ Popover,
25
+ {
26
+ content: h(
27
+ "div.interaction-barrier",
28
+ {
29
+ onMouseDown(evt) {
30
+ evt.nativeEvent.stopImmediatePropagation();
31
+ },
32
+ onKeyDown(evt) {
33
+ if (evt.key === "Escape") {
34
+ setIsOpen(false);
35
+ evt.preventDefault();
36
+ }
37
+ // Climb over the interaction barrier to propagate the key event to the table
38
+ ref.current.dispatchEvent(new KeyboardEvent("keydown", evt));
39
+ },
40
+ },
41
+ h(ErrorBoundary, null, content)
42
+ ),
43
+ enforceFocus: false,
44
+ autoFocus: false,
45
+ minimal: true,
46
+ modifiers: {
47
+ offset: { enabled: true, options: { offset: [0, 8] } },
48
+ },
49
+ interactionKind: "hover-target",
50
+ isOpen,
51
+ onClose(evt) {
52
+ //props.onKeyDown?.(evt);
53
+ //setIsOpen(false);
54
+ },
55
+ // Portal must be used to avoid issues with the editor being clipped to the bounds of the cell
56
+ usePortal: true,
57
+ },
58
+ h(
59
+ "span.editor-popup-target",
60
+ {
61
+ className: targetClassName,
62
+ onClick: () => setIsOpen(!isOpen),
63
+ ref,
64
+ },
65
+ // If the editor is open, show the inline editor, otherwise show the value viewer
66
+ isOpen ? valueViewer : inlineEditor ?? valueViewer
67
+ )
68
+ );
69
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./editor-popup";
2
+ export * from "./colors";
3
+ export * from "./text-areas";
@@ -0,0 +1,35 @@
1
+ .interaction-barrier
2
+ pointer-events: all
3
+
4
+ .editor-popup-target
5
+ position: absolute
6
+ display: block
7
+ top: 0
8
+ left: 0
9
+ width: 100%
10
+ height: 100%
11
+
12
+ .editable-text-area
13
+ position: relative
14
+
15
+ textarea
16
+ min-width: var(--data-editor-width, 15em)
17
+ min-height: var(--data-editor-height, 10em)
18
+ font-family: inherit
19
+ font-size: inherit
20
+
21
+ .tools
22
+ position: absolute
23
+ top: 0.2em
24
+ right: 0.2em
25
+ transform: scale(0.8)
26
+
27
+ // Color picker
28
+ .color-picker-container
29
+ :global
30
+ .react-colorful__saturation
31
+ border-radius: 0
32
+
33
+ .react-colorful__hue
34
+ border-radius: 0
35
+
@@ -0,0 +1,88 @@
1
+ import hyper from "@macrostrat/hyper";
2
+ import styles from "./main.module.sass";
3
+ import { Button } from "@blueprintjs/core";
4
+ import { useEffect, useRef } from "react";
5
+
6
+ const h = hyper.styled(styles);
7
+
8
+ export function EditableTextArea({ value, onChange }) {
9
+ const ref = useRef(null);
10
+
11
+ useEffect(() => {
12
+ if (ref.current == null) return;
13
+ ref.current.focus();
14
+ // Get the current value
15
+ const val = ref.current.value;
16
+ // Move the cursor to the end of the text
17
+ ref.current.setSelectionRange(val.length, val.length);
18
+ }, []);
19
+
20
+ return h("div.editable-text-area", [
21
+ h("textarea.bp5-input", {
22
+ ref,
23
+ value: value ?? "",
24
+ onChange: (evt) => onChange(evt.target.value),
25
+ onKeyDown: (evt) => {
26
+ if (evt.key === "Enter") {
27
+ evt.preventDefault();
28
+ return;
29
+ }
30
+
31
+ if (evt.key === "Escape") {
32
+ evt.preventDefault();
33
+ return;
34
+ }
35
+
36
+ const shouldPropagate = handleSpecialKeys(evt, evt.target);
37
+ if (!shouldPropagate) {
38
+ evt.stopPropagation();
39
+ }
40
+ },
41
+ }),
42
+ h("div.tools", [
43
+ h(Button, {
44
+ icon: "key-enter",
45
+ minimal: true,
46
+ small: true,
47
+ onClick() {
48
+ // Get cursor position
49
+ let _value = value ?? "";
50
+
51
+ const cursorPos = ref.current.selectionStart ?? _value.length;
52
+ // Insert a newline at the cursor position
53
+ onChange(_value.slice(0, cursorPos) + "\n" + _value.slice(cursorPos));
54
+ // Re-focus the textarea
55
+ ref.current.focus();
56
+ // Move the cursor to the end of the line
57
+ ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);
58
+ },
59
+ }),
60
+ ]),
61
+ ]);
62
+ }
63
+
64
+ export function handleSpecialKeys(evt, target): boolean {
65
+ if (
66
+ (evt.key === "ArrowLeft" ||
67
+ evt.key === "ArrowUp" ||
68
+ evt.key === "ArrowDown") &&
69
+ target.selectionStart === 0
70
+ ) {
71
+ target.blur();
72
+ return true;
73
+ }
74
+
75
+ if (
76
+ (evt.key === "ArrowRight" ||
77
+ evt.key === "ArrowUp" ||
78
+ evt.key === "Tab" ||
79
+ evt.key === "Enter" ||
80
+ evt.key === "ArrowDown") &&
81
+ target.selectionStart === evt.target.value.length
82
+ ) {
83
+ target.blur();
84
+ return true;
85
+ }
86
+
87
+ return false;
88
+ }