@vonaffenfels/slate-editor 1.2.39 → 1.2.41

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/.babelrc +43 -43
  2. package/README.md +5 -5
  3. package/componentLoader.js +93 -93
  4. package/package.json +2 -2
  5. package/postcss.config.js +6 -6
  6. package/scss/demo.scss +148 -148
  7. package/scss/sidebarEditor.scss +185 -185
  8. package/scss/toolbar.scss +162 -162
  9. package/src/Blocks/EmptyBlock.js +11 -11
  10. package/src/Blocks/EmptyWrapper.js +4 -4
  11. package/src/Blocks/ErrorBoundary.js +40 -40
  12. package/src/Blocks/LayoutBlock.js +274 -274
  13. package/src/Blocks/LayoutSlot.js +90 -90
  14. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  15. package/src/Context/StorybookContext.js +6 -6
  16. package/src/ElementAutocomplete.js +134 -134
  17. package/src/Loader.js +137 -137
  18. package/src/Nodes/Default.js +162 -162
  19. package/src/Nodes/Leaf.js +54 -54
  20. package/src/Nodes/Text.js +97 -97
  21. package/src/ObjectId.js +3 -3
  22. package/src/Renderer.js +73 -73
  23. package/src/Serializer/Html.js +42 -42
  24. package/src/Serializer/Serializer.js +374 -374
  25. package/src/Serializer/Text.js +17 -17
  26. package/src/Serializer/ads.js +187 -187
  27. package/src/Serializer/index.js +3 -3
  28. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  29. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  30. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  31. package/src/SidebarEditor/Fields/MVP.js +66 -66
  32. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  33. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  34. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  35. package/src/SidebarEditor/Fields/Select.js +47 -47
  36. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  37. package/src/SidebarEditor/Fields/Switch.js +34 -34
  38. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  39. package/src/SidebarEditor/Resizable.js +85 -85
  40. package/src/Storybook.js +151 -151
  41. package/src/Toolbar/Align.js +64 -64
  42. package/src/Toolbar/Anchor.js +94 -94
  43. package/src/Toolbar/Block.js +135 -135
  44. package/src/Toolbar/Element.js +44 -44
  45. package/src/Toolbar/Formats.js +71 -71
  46. package/src/Toolbar/Insert.js +28 -28
  47. package/src/Toolbar/Layout.js +399 -399
  48. package/src/Toolbar/Link.js +164 -164
  49. package/src/Toolbar/Toolbar.js +235 -235
  50. package/src/Tools/Margin.js +51 -51
  51. package/src/Translation/TranslationToolbarButton.js +119 -119
  52. package/src/dev/draftToSlate.json +3147 -3147
  53. package/src/dev/index.css +2 -2
  54. package/src/dev/index.html +10 -10
  55. package/src/dev/index.js +4 -4
  56. package/src/dev/sampleValue1.json +4294 -4294
  57. package/src/dev/sampleValueValid.json +410 -410
  58. package/src/dev/testComponents/TestStory.js +74 -74
  59. package/src/dev/testComponents/TestStory.stories.js +216 -216
  60. package/src/dev/testComponents/TestStory2.js +74 -74
  61. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  62. package/src/dev/testComponents/TestStory3.js +74 -74
  63. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  64. package/src/dev/testSampleValue.json +746 -746
  65. package/src/fromHTML.js +4 -4
  66. package/src/helper/array.js +8 -8
  67. package/src/index.js +10 -10
  68. package/src/plugins/ListItem.js +48 -48
  69. package/src/plugins/SoftBreak.js +23 -23
  70. package/src/toHTML.js +6 -6
  71. package/src/toText.js +6 -6
  72. package/src/util/reduceContentfulResponse.js +64 -64
  73. package/src/util.js +19 -19
  74. package/storyLoader.js +47 -47
  75. package/tailwind.config.js +4 -4
  76. package/webpack.config.build.js +55 -55
  77. package/webpack.config.dev.js +60 -60
  78. package/webpack.config.js +130 -130
  79. package/webpack.config.watch.js +4 -4
@@ -1,48 +1,48 @@
1
-
2
- export const Select = ({
3
- value,
4
- field,
5
- onChange,
6
- }) => {
7
- return <select
8
- value={value || ""}
9
- onChange={onChange}>
10
- <option value="">Auswählen</option>
11
- {renderFieldSelectOptions(field)}
12
- </select>;
13
- };
14
-
15
- export const renderFieldSelectOptions = field => {
16
- if (field.options) {
17
- field.control.options = field.options;
18
- }
19
-
20
- if (field?.control?.labels) {
21
- field.control.options = field.control.labels;
22
- }
23
-
24
- if (!field?.control?.options) {
25
- return;
26
- }
27
-
28
- if (Array.isArray(field.control.options)) {
29
- return field.control.options.map(option => {
30
- if (option && typeof option === "object") {
31
- return <option key={`select-option-${option.value}`} value={option.value}>{option.label}</option>;
32
- }
33
-
34
- return <option key={`select-option-${option}`} value={option}>{option}</option>;
35
- });
36
- } else {
37
- return Object.keys(field.control.options).map(key => {
38
- // Prevents false values being a string, e.g. "false"
39
- if (!field.control.options[key]) {
40
- field.control.options[key] = "";
41
- }
42
-
43
- return (
44
- <option key={`select-option-${key}`} value={field.control.options[key]}>{key}</option>
45
- );
46
- });
47
- }
1
+
2
+ export const Select = ({
3
+ value,
4
+ field,
5
+ onChange,
6
+ }) => {
7
+ return <select
8
+ value={value || ""}
9
+ onChange={onChange}>
10
+ <option value="">Auswählen</option>
11
+ {renderFieldSelectOptions(field)}
12
+ </select>;
13
+ };
14
+
15
+ export const renderFieldSelectOptions = field => {
16
+ if (field.options) {
17
+ field.control.options = field.options;
18
+ }
19
+
20
+ if (field?.control?.labels) {
21
+ field.control.options = field.control.labels;
22
+ }
23
+
24
+ if (!field?.control?.options) {
25
+ return;
26
+ }
27
+
28
+ if (Array.isArray(field.control.options)) {
29
+ return field.control.options.map(option => {
30
+ if (option && typeof option === "object") {
31
+ return <option key={`select-option-${option.value}`} value={option.value}>{option.label}</option>;
32
+ }
33
+
34
+ return <option key={`select-option-${option}`} value={option}>{option}</option>;
35
+ });
36
+ } else {
37
+ return Object.keys(field.control.options).map(key => {
38
+ // Prevents false values being a string, e.g. "false"
39
+ if (!field.control.options[key]) {
40
+ field.control.options[key] = "";
41
+ }
42
+
43
+ return (
44
+ <option key={`select-option-${key}`} value={field.control.options[key]}>{key}</option>
45
+ );
46
+ });
47
+ }
48
48
  };
@@ -1,16 +1,16 @@
1
- export const StreamSelect = ({
2
- value,
3
- onChange,
4
- field,
5
- }) => {
6
- return (
7
- <select
8
- value={value || ""}
9
- onChange={onChange}>
10
- <option value="">Auswählen</option>
11
- {(field?.control?.streams || []).map(stream => (
12
- <option key={`select-option-${stream.value}`} value={`$$_STREAM__${stream.value}__`}>{stream.label}</option>
13
- ))}
14
- </select>
15
- );
1
+ export const StreamSelect = ({
2
+ value,
3
+ onChange,
4
+ field,
5
+ }) => {
6
+ return (
7
+ <select
8
+ value={value || ""}
9
+ onChange={onChange}>
10
+ <option value="">Auswählen</option>
11
+ {(field?.control?.streams || []).map(stream => (
12
+ <option key={`select-option-${stream.value}`} value={`$$_STREAM__${stream.value}__`}>{stream.label}</option>
13
+ ))}
14
+ </select>
15
+ );
16
16
  };
@@ -1,35 +1,35 @@
1
- import React from "react";
2
- import classNames from "classnames";
3
-
4
- export const Switch = ({
5
- value,
6
- onClick,
7
- label,
8
- className,
9
- }) => {
10
- return (
11
- <div className={classNames(className, {"flex items-center": true})}>
12
- <button
13
- onClick={onClick}
14
- type="button"
15
- role="switch"
16
- aria-checked="false"
17
- className={classNames({
18
- "bg-green-500": value,
19
- "bg-gray-200": !value,
20
- },
21
- "relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition duration-100 ease-in-out focus:outline-none")}
22
- >
23
- <span
24
- aria-hidden="true"
25
- className={classNames({
26
- "translate-x-5": value,
27
- "translate-x-0": !value,
28
- },
29
- "pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow ring-0 transition duration-100 ease-in-out")}
30
- />
31
- </button>
32
- <span className="ml-2">{label}</span>
33
- </div>
34
- );
1
+ import React from "react";
2
+ import classNames from "classnames";
3
+
4
+ export const Switch = ({
5
+ value,
6
+ onClick,
7
+ label,
8
+ className,
9
+ }) => {
10
+ return (
11
+ <div className={classNames(className, {"flex items-center": true})}>
12
+ <button
13
+ onClick={onClick}
14
+ type="button"
15
+ role="switch"
16
+ aria-checked="false"
17
+ className={classNames({
18
+ "bg-green-500": value,
19
+ "bg-gray-200": !value,
20
+ },
21
+ "relative inline-flex h-6 w-11 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition duration-100 ease-in-out focus:outline-none")}
22
+ >
23
+ <span
24
+ aria-hidden="true"
25
+ className={classNames({
26
+ "translate-x-5": value,
27
+ "translate-x-0": !value,
28
+ },
29
+ "pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow ring-0 transition duration-100 ease-in-out")}
30
+ />
31
+ </button>
32
+ <span className="ml-2">{label}</span>
33
+ </div>
34
+ );
35
35
  };
@@ -1,22 +1,22 @@
1
- export const Textarea = ({
2
- value,
3
- onChange,
4
- }) => {
5
- return (
6
- <textarea
7
- value={typeof value === "object" ? JSON.stringify(value, null, 2) || "" : value}
8
- onChange={e => {
9
- onChange(e);
10
-
11
- e.target.style.height = "5px";
12
- e.target.style.height = e.target.scrollHeight + 2 + "px";
13
- }}
14
- onBlur={(e) => {
15
- e.target.style.height = "42px";
16
- }}
17
- onFocus={e => {
18
- e.target.style.height = "5px";
19
- e.target.style.height = e.target.scrollHeight + 2 + "px";
20
- }}/>
21
- );
1
+ export const Textarea = ({
2
+ value,
3
+ onChange,
4
+ }) => {
5
+ return (
6
+ <textarea
7
+ value={typeof value === "object" ? JSON.stringify(value, null, 2) || "" : value}
8
+ onChange={e => {
9
+ onChange(e);
10
+
11
+ e.target.style.height = "5px";
12
+ e.target.style.height = e.target.scrollHeight + 2 + "px";
13
+ }}
14
+ onBlur={(e) => {
15
+ e.target.style.height = "42px";
16
+ }}
17
+ onFocus={e => {
18
+ e.target.style.height = "5px";
19
+ e.target.style.height = e.target.scrollHeight + 2 + "px";
20
+ }}/>
21
+ );
22
22
  };
@@ -1,86 +1,86 @@
1
- import {
2
- useEffect, useRef,
3
- } from "react";
4
- import classNames from "classnames";
5
-
6
- export const Resizable = ({
7
- left,
8
- right,
9
- }) => {
10
- const containerRef = useRef();
11
- const leftRef = useRef();
12
- const handleRef = useRef();
13
- const rightRef = useRef();
14
-
15
- const checkWidth = (width) => {
16
- if (!containerRef.current || !width) {
17
- return width;
18
- }
19
-
20
- if (width < 300) {
21
- return 300;
22
- } else if (containerRef.current.getBoundingClientRect().width - width < 300) {
23
- return containerRef.current.getBoundingClientRect().width - 300;
24
- }
25
-
26
- return width;
27
- };
28
-
29
- useEffect(() => {
30
- if (rightRef.current) {
31
- const savedWidth = localStorage.getItem("slate-editor-resizable-width");
32
-
33
- if (checkWidth(savedWidth)) {
34
- rightRef.current.style.width = savedWidth + 'px';
35
- }
36
-
37
- const onMouseDown = (e) => {
38
- if (!rightRef.current) {
39
- return;
40
- }
41
- rightRef.current.resizingStartWidth = rightRef.current.getBoundingClientRect().width;
42
- rightRef.current.resizingStartMouseX = e.pageX;
43
- rightRef.current.resizing = true;
44
- };
45
- const onMouseMove = (e) => {
46
- if (!rightRef?.current?.resizing) {
47
- return;
48
- }
49
-
50
- let newWidth = rightRef.current.resizingStartWidth - (e.pageX - rightRef.current.resizingStartMouseX);
51
- newWidth = checkWidth(newWidth);
52
-
53
- localStorage.setItem("slate-editor-resizable-width", newWidth);
54
-
55
- rightRef.current.style.width = newWidth + 'px';
56
- };
57
- const onMouseUp = (e) => {
58
- if (rightRef.current) {
59
- rightRef.current.resizing = false;
60
- }
61
- };
62
-
63
- handleRef.current.addEventListener("mousedown", onMouseDown);
64
- document.addEventListener("mousemove", onMouseMove);
65
- document.addEventListener("mouseup", onMouseUp);
66
-
67
- return () => {
68
- if (rightRef.current) {
69
- handleRef.current.removeEventListener("mousedown", onMouseDown);
70
- }
71
- document.removeEventListener("mousemove", onMouseMove);
72
- document.removeEventListener("mouseup", onMouseUp);
73
- };
74
- }
75
- }, [right, left]);
76
-
77
- return <div
78
- className={classNames("resizable flex w-full", {"enabled": !!right})}
79
- ref={containerRef}>
80
- <div ref={leftRef} className="resizable-left grow">{left}</div>
81
- {right && <div ref={rightRef} className="resizable-right shrink-0">
82
- <div ref={handleRef} className="resizable-x-handle"/>
83
- {right}
84
- </div>}
85
- </div>;
1
+ import {
2
+ useEffect, useRef,
3
+ } from "react";
4
+ import classNames from "classnames";
5
+
6
+ export const Resizable = ({
7
+ left,
8
+ right,
9
+ }) => {
10
+ const containerRef = useRef();
11
+ const leftRef = useRef();
12
+ const handleRef = useRef();
13
+ const rightRef = useRef();
14
+
15
+ const checkWidth = (width) => {
16
+ if (!containerRef.current || !width) {
17
+ return width;
18
+ }
19
+
20
+ if (width < 300) {
21
+ return 300;
22
+ } else if (containerRef.current.getBoundingClientRect().width - width < 300) {
23
+ return containerRef.current.getBoundingClientRect().width - 300;
24
+ }
25
+
26
+ return width;
27
+ };
28
+
29
+ useEffect(() => {
30
+ if (rightRef.current) {
31
+ const savedWidth = localStorage.getItem("slate-editor-resizable-width");
32
+
33
+ if (checkWidth(savedWidth)) {
34
+ rightRef.current.style.width = savedWidth + 'px';
35
+ }
36
+
37
+ const onMouseDown = (e) => {
38
+ if (!rightRef.current) {
39
+ return;
40
+ }
41
+ rightRef.current.resizingStartWidth = rightRef.current.getBoundingClientRect().width;
42
+ rightRef.current.resizingStartMouseX = e.pageX;
43
+ rightRef.current.resizing = true;
44
+ };
45
+ const onMouseMove = (e) => {
46
+ if (!rightRef?.current?.resizing) {
47
+ return;
48
+ }
49
+
50
+ let newWidth = rightRef.current.resizingStartWidth - (e.pageX - rightRef.current.resizingStartMouseX);
51
+ newWidth = checkWidth(newWidth);
52
+
53
+ localStorage.setItem("slate-editor-resizable-width", newWidth);
54
+
55
+ rightRef.current.style.width = newWidth + 'px';
56
+ };
57
+ const onMouseUp = (e) => {
58
+ if (rightRef.current) {
59
+ rightRef.current.resizing = false;
60
+ }
61
+ };
62
+
63
+ handleRef.current.addEventListener("mousedown", onMouseDown);
64
+ document.addEventListener("mousemove", onMouseMove);
65
+ document.addEventListener("mouseup", onMouseUp);
66
+
67
+ return () => {
68
+ if (rightRef.current) {
69
+ handleRef.current.removeEventListener("mousedown", onMouseDown);
70
+ }
71
+ document.removeEventListener("mousemove", onMouseMove);
72
+ document.removeEventListener("mouseup", onMouseUp);
73
+ };
74
+ }
75
+ }, [right, left]);
76
+
77
+ return <div
78
+ className={classNames("resizable flex w-full", {"enabled": !!right})}
79
+ ref={containerRef}>
80
+ <div ref={leftRef} className="resizable-left grow">{left}</div>
81
+ {right && <div ref={rightRef} className="resizable-right shrink-0">
82
+ <div ref={handleRef} className="resizable-x-handle"/>
83
+ {right}
84
+ </div>}
85
+ </div>;
86
86
  };