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