@vonaffenfels/slate-editor 1.1.71 → 1.2.10

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