@vonaffenfels/slate-editor 1.1.69 → 1.1.71

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 (94) hide show
  1. package/.babelrc +43 -43
  2. package/README.md +5 -5
  3. package/componentLoader.js +93 -93
  4. package/dist/BlockEditor.css +1871 -4
  5. package/dist/BlockEditor.js +3960 -336
  6. package/dist/Renderer.js +2081 -2
  7. package/dist/fromHTML.js +78 -1
  8. package/dist/index.css +1871 -4
  9. package/dist/index.js +4037 -336
  10. package/dist/toHTML.js +1689 -2
  11. package/dist/toText.js +1689 -2
  12. package/package.json +2 -2
  13. package/postcss.config.js +6 -6
  14. package/scss/demo.scss +148 -148
  15. package/scss/sidebarEditor.scss +181 -181
  16. package/scss/toolbar.scss +161 -161
  17. package/src/Blocks/EmptyBlock.js +11 -11
  18. package/src/Blocks/EmptyWrapper.js +4 -4
  19. package/src/Blocks/ErrorBoundary.js +40 -40
  20. package/src/Blocks/LayoutBlock.js +274 -274
  21. package/src/Blocks/LayoutSlot.js +90 -90
  22. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  23. package/src/Context/StorybookContext.js +6 -6
  24. package/src/ElementAutocomplete.js +133 -133
  25. package/src/Loader.js +137 -137
  26. package/src/Nodes/Default.js +158 -158
  27. package/src/Nodes/Leaf.js +54 -54
  28. package/src/Nodes/Text.js +97 -97
  29. package/src/ObjectId.js +3 -3
  30. package/src/Renderer.js +73 -73
  31. package/src/Serializer/Html.js +42 -42
  32. package/src/Serializer/Serializer.js +371 -371
  33. package/src/Serializer/Text.js +17 -17
  34. package/src/Serializer/ads.js +174 -174
  35. package/src/Serializer/index.js +3 -3
  36. package/src/SidebarEditor/AssetList.js +181 -181
  37. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  38. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  39. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  40. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  41. package/src/SidebarEditor/Fields/MVP.js +66 -66
  42. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  43. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  44. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  45. package/src/SidebarEditor/Fields/Select.js +47 -47
  46. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  47. package/src/SidebarEditor/Fields/Switch.js +34 -34
  48. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  49. package/src/SidebarEditor/Resizable.js +85 -85
  50. package/src/Storybook.js +151 -151
  51. package/src/Toolbar/Align.js +64 -64
  52. package/src/Toolbar/Anchor.js +94 -94
  53. package/src/Toolbar/Block.js +135 -135
  54. package/src/Toolbar/Element.js +44 -44
  55. package/src/Toolbar/Formats.js +71 -71
  56. package/src/Toolbar/Insert.js +28 -28
  57. package/src/Toolbar/Layout.js +399 -399
  58. package/src/Toolbar/Link.js +164 -164
  59. package/src/Toolbar/Toolbar.js +235 -235
  60. package/src/Tools/Margin.js +51 -51
  61. package/src/Translation/TranslationToolbarButton.js +115 -115
  62. package/src/dev/draftToSlate.json +3147 -3147
  63. package/src/dev/index.css +2 -2
  64. package/src/dev/index.html +10 -10
  65. package/src/dev/index.js +4 -4
  66. package/src/dev/sampleValue1.json +4294 -4294
  67. package/src/dev/sampleValueValid.json +410 -410
  68. package/src/dev/testComponents/TestStory.js +74 -74
  69. package/src/dev/testComponents/TestStory.stories.js +216 -216
  70. package/src/dev/testComponents/TestStory2.js +74 -74
  71. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  72. package/src/dev/testComponents/TestStory3.js +74 -74
  73. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  74. package/src/dev/testSampleValue.json +746 -746
  75. package/src/fromHTML.js +4 -4
  76. package/src/helper/array.js +8 -8
  77. package/src/index.js +10 -10
  78. package/src/plugins/ListItem.js +48 -48
  79. package/src/plugins/SoftBreak.js +23 -23
  80. package/src/toHTML.js +6 -6
  81. package/src/toText.js +6 -6
  82. package/src/util/reduceContentfulResponse.js +64 -64
  83. package/src/util.js +19 -19
  84. package/storyLoader.js +47 -47
  85. package/tailwind.config.js +4 -4
  86. package/webpack.config.build.js +55 -55
  87. package/webpack.config.dev.js +60 -60
  88. package/webpack.config.js +130 -130
  89. package/webpack.config.watch.js +4 -4
  90. package/dist/BlockEditor.js.LICENSE.txt +0 -61
  91. package/dist/Renderer.js.LICENSE.txt +0 -15
  92. package/dist/index.js.LICENSE.txt +0 -69
  93. package/dist/toHTML.js.LICENSE.txt +0 -23
  94. package/dist/toText.js.LICENSE.txt +0 -23
@@ -1,40 +1,40 @@
1
- import {renderFieldSelectOptions} from "./Select";
2
- import {
3
- useEffect, useState,
4
- } from "react";
5
-
6
- export const RemoteSelect = ({
7
- value,
8
- field,
9
- onChange,
10
- onOptionsChange,
11
- }) => {
12
- const [options, setOptions] = useState([]);
13
-
14
- const reloadOptions = async () => {
15
- let opts = await fetch(field.control.url).then(res => res.json());
16
-
17
- if (onOptionsChange) {
18
- onOptionsChange(opts);
19
- }
20
-
21
- setOptions(opts);
22
- };
23
-
24
- useEffect(() => {
25
- reloadOptions();
26
- }, [field]);
27
-
28
- return <select
29
- value={value || ""}
30
- onChange={onChange}>
31
- <option value="">Auswählen</option>
32
- {renderFieldSelectOptions({
33
- ...field,
34
- control: {
35
- ...field.control,
36
- options,
37
- },
38
- })}
39
- </select>;
1
+ import {renderFieldSelectOptions} from "./Select";
2
+ import {
3
+ useEffect, useState,
4
+ } from "react";
5
+
6
+ export const RemoteSelect = ({
7
+ value,
8
+ field,
9
+ onChange,
10
+ onOptionsChange,
11
+ }) => {
12
+ const [options, setOptions] = useState([]);
13
+
14
+ const reloadOptions = async () => {
15
+ let opts = await fetch(field.control.url).then(res => res.json());
16
+
17
+ if (onOptionsChange) {
18
+ onOptionsChange(opts);
19
+ }
20
+
21
+ setOptions(opts);
22
+ };
23
+
24
+ useEffect(() => {
25
+ reloadOptions();
26
+ }, [field]);
27
+
28
+ return <select
29
+ value={value || ""}
30
+ onChange={onChange}>
31
+ <option value="">Auswählen</option>
32
+ {renderFieldSelectOptions({
33
+ ...field,
34
+ control: {
35
+ ...field.control,
36
+ options,
37
+ },
38
+ })}
39
+ </select>;
40
40
  };
@@ -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
  };