@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,91 +1,91 @@
1
- import React, {
2
- createContext, forwardRef, Fragment,
3
- } from "react";
4
- import {Transforms} from "slate";
5
- import {ReactEditor} from "slate-react";
6
- import classNames from "classnames";
7
- import {ToolMargin} from "../Tools/Margin";
8
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
9
- import {faStickyNote} from "@fortawesome/free-solid-svg-icons";
10
-
11
- export const LayoutSlotContext = createContext({isInSlot: false});
12
-
13
- export const LayoutSlot = ({
14
- editor,
15
- children,
16
- element,
17
- attributes,
18
- onElementClick = () => {},
19
- }) => {
20
- const onMarginChange = (value) => {
21
- let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
22
- let path = ReactEditor.findPath(editor, node);
23
-
24
- Transforms.setNodes(editor, {
25
- type: "layout-slot",
26
- attributes: {
27
- ...(element.attributes || {}),
28
- margin: value,
29
- },
30
- }, {at: path});
31
- };
32
-
33
- const switchSticky = () => {
34
- let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
35
- let path = ReactEditor.findPath(editor, node);
36
- let stickyTop = element?.attributes?.stickyTop;
37
-
38
- if (!element.attributes.sticky) {
39
- stickyTop = prompt("Abstand nach oben, wenn sticky", element?.attributes?.stickyTop || 0);
40
- }
41
-
42
- Transforms.setNodes(editor, {
43
- type: "layout-slot",
44
- attributes: {
45
- ...(element.attributes || {}),
46
- sticky: !element.attributes.sticky,
47
- stickyTop: stickyTop || 0,
48
- },
49
- }, {at: path});
50
- };
51
-
52
- return <div
53
- className={classNames({
54
- ["layout-slot layout-slot-" + element.attributes.name]: true,
55
- "editor-mt-4": element?.attributes?.margin?.top,
56
- "editor-mr-4": element?.attributes?.margin?.right,
57
- "editor-mb-4": element?.attributes?.margin?.bottom,
58
- "editor-ml-4": element?.attributes?.margin?.left,
59
- })}
60
- onClick={() => onElementClick(element)}
61
- {...attributes}
62
- >
63
- <LayoutSlotContext.Provider value={{isInSlot : true}}>
64
- <div
65
- className="layout-slot-options"
66
- contentEditable={false}
67
- >
68
- <span
69
- className="layout-slot-name"
70
- contentEditable={false}
71
- >
72
- {element.attributes.name}
73
- </span>
74
-
75
- <div className="flex items-center">
76
- {!element?.attributes?.sticky ? (
77
- <FontAwesomeIcon icon={faStickyNote} color="#000000" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
78
- ) : (
79
- <FontAwesomeIcon icon={faStickyNote} color="#3490f3" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
80
- )}
81
- <ToolMargin margin={element?.attributes?.margin} onChange={onMarginChange}/>
82
- </div>
83
- </div>
84
- <div className="layout-slot-content">
85
- <div className={classNames({"sticky top-[80px]": element?.attributes?.sticky})}>
86
- {children}
87
- </div>
88
- </div>
89
- </LayoutSlotContext.Provider>
90
- </div>;
1
+ import React, {
2
+ createContext, forwardRef, Fragment,
3
+ } from "react";
4
+ import {Transforms} from "slate";
5
+ import {ReactEditor} from "slate-react";
6
+ import classNames from "classnames";
7
+ import {ToolMargin} from "../Tools/Margin";
8
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
9
+ import {faStickyNote} from "@fortawesome/free-solid-svg-icons";
10
+
11
+ export const LayoutSlotContext = createContext({isInSlot: false});
12
+
13
+ export const LayoutSlot = ({
14
+ editor,
15
+ children,
16
+ element,
17
+ attributes,
18
+ onElementClick = () => {},
19
+ }) => {
20
+ const onMarginChange = (value) => {
21
+ let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
22
+ let path = ReactEditor.findPath(editor, node);
23
+
24
+ Transforms.setNodes(editor, {
25
+ type: "layout-slot",
26
+ attributes: {
27
+ ...(element.attributes || {}),
28
+ margin: value,
29
+ },
30
+ }, {at: path});
31
+ };
32
+
33
+ const switchSticky = () => {
34
+ let node = ReactEditor.toSlateNode(editor, attributes.ref.current);
35
+ let path = ReactEditor.findPath(editor, node);
36
+ let stickyTop = element?.attributes?.stickyTop;
37
+
38
+ if (!element.attributes.sticky) {
39
+ stickyTop = prompt("Abstand nach oben, wenn sticky", element?.attributes?.stickyTop || 0);
40
+ }
41
+
42
+ Transforms.setNodes(editor, {
43
+ type: "layout-slot",
44
+ attributes: {
45
+ ...(element.attributes || {}),
46
+ sticky: !element.attributes.sticky,
47
+ stickyTop: stickyTop || 0,
48
+ },
49
+ }, {at: path});
50
+ };
51
+
52
+ return <div
53
+ className={classNames({
54
+ ["layout-slot layout-slot-" + element.attributes.name]: true,
55
+ "editor-mt-4": element?.attributes?.margin?.top,
56
+ "editor-mr-4": element?.attributes?.margin?.right,
57
+ "editor-mb-4": element?.attributes?.margin?.bottom,
58
+ "editor-ml-4": element?.attributes?.margin?.left,
59
+ })}
60
+ onClick={() => onElementClick(element)}
61
+ {...attributes}
62
+ >
63
+ <LayoutSlotContext.Provider value={{isInSlot : true}}>
64
+ <div
65
+ className="layout-slot-options"
66
+ contentEditable={false}
67
+ >
68
+ <span
69
+ className="layout-slot-name"
70
+ contentEditable={false}
71
+ >
72
+ {element.attributes.name}
73
+ </span>
74
+
75
+ <div className="flex items-center">
76
+ {!element?.attributes?.sticky ? (
77
+ <FontAwesomeIcon icon={faStickyNote} color="#000000" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
78
+ ) : (
79
+ <FontAwesomeIcon icon={faStickyNote} color="#3490f3" size="md" className="mr-2 cursor-pointer" onClick={switchSticky} />
80
+ )}
81
+ <ToolMargin margin={element?.attributes?.margin} onChange={onMarginChange}/>
82
+ </div>
83
+ </div>
84
+ <div className="layout-slot-content">
85
+ <div className={classNames({"sticky top-[80px]": element?.attributes?.sticky})}>
86
+ {children}
87
+ </div>
88
+ </div>
89
+ </LayoutSlotContext.Provider>
90
+ </div>;
91
91
  };
@@ -1,49 +1,49 @@
1
- import {useState} from "react";
2
-
3
- export const CollapsableMenu = ({
4
- button,
5
- children,
6
- ...props
7
- }) => {
8
- const [collapsed, setCollapsed] = useState(true);
9
-
10
- children = children.map(child => ({
11
- ...child,
12
- props: {
13
- ...child.props,
14
- onClick: () => {
15
- if (child.props.onClick) {
16
- child.props.onClick();
17
-
18
- setCollapsed(true);
19
- }
20
- },
21
- },
22
- }));
23
-
24
- return (
25
- <div className="relative">
26
- <div className="relative">
27
- <div onClick={() => setCollapsed(!collapsed)}>
28
- {button}
29
- </div>
30
- </div>
31
- {!collapsed && (
32
- <div className="collapsable-menu absolute right-0 mt-2 w-52">
33
- {children}
34
- </div>
35
- )}
36
- </div>
37
- );
38
- };
39
-
40
- export const CollapsableMenuItem = ({
41
- children,
42
- onClick,
43
- }) => {
44
- return (
45
- <div className="collapsable-menu-item cursor-pointer px-4 py-2" onClick={onClick}>
46
- {children}
47
- </div>
48
- );
1
+ import {useState} from "react";
2
+
3
+ export const CollapsableMenu = ({
4
+ button,
5
+ children,
6
+ ...props
7
+ }) => {
8
+ const [collapsed, setCollapsed] = useState(true);
9
+
10
+ children = children.map(child => ({
11
+ ...child,
12
+ props: {
13
+ ...child.props,
14
+ onClick: () => {
15
+ if (child.props.onClick) {
16
+ child.props.onClick();
17
+
18
+ setCollapsed(true);
19
+ }
20
+ },
21
+ },
22
+ }));
23
+
24
+ return (
25
+ <div className="relative">
26
+ <div className="relative">
27
+ <div onClick={() => setCollapsed(!collapsed)}>
28
+ {button}
29
+ </div>
30
+ </div>
31
+ {!collapsed && (
32
+ <div className="collapsable-menu absolute right-0 mt-2 w-52">
33
+ {children}
34
+ </div>
35
+ )}
36
+ </div>
37
+ );
38
+ };
39
+
40
+ export const CollapsableMenuItem = ({
41
+ children,
42
+ onClick,
43
+ }) => {
44
+ return (
45
+ <div className="collapsable-menu-item cursor-pointer px-4 py-2" onClick={onClick}>
46
+ {children}
47
+ </div>
48
+ );
49
49
  };
@@ -1,7 +1,7 @@
1
- import {createContext} from "react";
2
-
3
- export const StorybookContext = createContext({
4
- storybookUrl: null,
5
- storybookTarget: null,
6
- activeStorybook: null,
1
+ import {createContext} from "react";
2
+
3
+ export const StorybookContext = createContext({
4
+ storybookUrl: null,
5
+ storybookTarget: null,
6
+ activeStorybook: null,
7
7
  });
@@ -1,134 +1,134 @@
1
- import {Autocomplete} from "@contentful/f36-components";
2
- import {
3
- useEffect, useState,
4
- } from "react";
5
-
6
- const devMode = localStorage.getItem("dev-mode") === "true";
7
-
8
- export const ElementAutocomplete = ({
9
- storybookStories,
10
- isLoading,
11
- editor,
12
- storyContext = "",
13
- portal,
14
- lastSelection,
15
- onChange,
16
- ...props
17
- }) => {
18
- const items = ([...(storybookStories.map(story => ({
19
- ...story,
20
- type: "storybook",
21
- })) || []), ...customStories]).map(story => {
22
- let storyTitleSplit = String(story.title || "").split("/");
23
- let storyName = story.label || storyTitleSplit.at(-1);
24
- let storyGroup = storyTitleSplit.length > 1 ? storyTitleSplit.slice(0, -1).join("/") : "Weitere Elemente";
25
-
26
- if (story.type === "storybook") {
27
- if (!story.id) {
28
- return;
29
- }
30
-
31
- let splitStoryContext = String(storyContext || "").split(",");
32
- let isItemInStoryContext = splitStoryContext.find(context => {
33
- return Array.isArray(story.storyContext) ? story.storyContext.includes(context) : context === story.storyContext;
34
- });
35
- let isItemInPortalContext = !story.portalContext || story.portalContext.includes(portal);
36
-
37
- if (!devMode && (!isItemInStoryContext || !isItemInPortalContext)) {
38
- return;
39
- }
40
- }
41
-
42
- return {
43
- value: story.id?.toLowerCase(),
44
- group: storyGroup,
45
- label: (storyName || "NameFehlerhaft").replace(/([^A-Z]*)([A-Z]+)([^A-Z]*)/g, '$1 $2$3').trim(),
46
- attributes: story?.stories?.[0]?.args || story?.stories?.[1]?.args || {},
47
- type: story.type,
48
- };
49
- }).filter(Boolean).sort(function (a, b) {
50
- if (a.label < b.label) {
51
- return -1;
52
- }
53
- if (a.label > b.label) {
54
- return 1;
55
- }
56
- return 0;
57
- });
58
-
59
- const [filteredItems, setFilteredItems] = useState(items);
60
-
61
- useEffect(() => {
62
- setFilteredItems(items);
63
- }, [storybookStories]);
64
-
65
- const handleQueryChange = (query) => {
66
- setFilteredItems(query ? items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase())) : items);
67
- };
68
-
69
- const handleOnChange = (item) => {
70
- onChange(item);
71
- };
72
-
73
- useEffect(() => {
74
- let autoCompleteElement = document.getElementsByClassName("element-autocomplete")[0];
75
-
76
- if (autoCompleteElement) {
77
- autoCompleteElement.value = "";
78
- }
79
- }, []);
80
-
81
-
82
- const groupedItemsObj = filteredItems.reduce((acc, item) => {
83
- if (!acc[item.group]) {
84
- acc[item.group] = [];
85
- }
86
-
87
- acc[item.group].push(item);
88
-
89
- return acc;
90
- }, {});
91
- const groupedItemsArr = Object.keys(groupedItemsObj).reduce((acc, key) => {
92
- const group = {
93
- groupTitle: key || "#",
94
- options: groupedItemsObj[key],
95
- };
96
-
97
- group.options.sort((a, b) => {
98
- return a.label.localeCompare(b.label);
99
- });
100
-
101
- acc.push(group);
102
-
103
- return acc;
104
- }, []);
105
-
106
- groupedItemsArr.sort((a, b) => {
107
- return a.groupTitle.localeCompare(b.groupTitle);
108
- });
109
-
110
- return (
111
- <Autocomplete
112
- items={groupedItemsArr}
113
- isGrouped={true}
114
- onInputValueChange={handleQueryChange}
115
- isLoading={isLoading}
116
- placeholder={'Element hinzufügen'}
117
- emptyListMessage={'Keine Elemente gefunden'}
118
- noMatchesMessage={'Keine Elemente gefunden'}
119
- listMaxHeight={500}
120
- onSelectItem={handleOnChange}
121
- width="medium"
122
- itemToString={(item) => ""}
123
- renderItem={(item) => `${item.label}`}
124
- {...props}
125
- />
126
- );
127
- };
128
-
129
- const customStories = [
130
- {
131
- type: "paragraph",
132
- label: "Text",
133
- },
1
+ import {Autocomplete} from "@contentful/f36-components";
2
+ import {
3
+ useEffect, useState,
4
+ } from "react";
5
+
6
+ const devMode = localStorage.getItem("dev-mode") === "true";
7
+
8
+ export const ElementAutocomplete = ({
9
+ storybookStories,
10
+ isLoading,
11
+ editor,
12
+ storyContext = "",
13
+ portal,
14
+ lastSelection,
15
+ onChange,
16
+ ...props
17
+ }) => {
18
+ const items = ([...(storybookStories.map(story => ({
19
+ ...story,
20
+ type: "storybook",
21
+ })) || []), ...customStories]).map(story => {
22
+ let storyTitleSplit = String(story.title || "").split("/");
23
+ let storyName = story.label || storyTitleSplit.at(-1);
24
+ let storyGroup = storyTitleSplit.length > 1 ? storyTitleSplit.slice(0, -1).join("/") : "Weitere Elemente";
25
+
26
+ if (story.type === "storybook") {
27
+ if (!story.id) {
28
+ return;
29
+ }
30
+
31
+ let splitStoryContext = String(storyContext || "").split(",");
32
+ let isItemInStoryContext = splitStoryContext.find(context => {
33
+ return Array.isArray(story.storyContext) ? story.storyContext.includes(context) : context === story.storyContext;
34
+ });
35
+ let isItemInPortalContext = !story.portalContext || story.portalContext.includes(portal);
36
+
37
+ if (!devMode && (!isItemInStoryContext || !isItemInPortalContext)) {
38
+ return;
39
+ }
40
+ }
41
+
42
+ return {
43
+ value: story.id?.toLowerCase(),
44
+ group: storyGroup,
45
+ label: (storyName || "NameFehlerhaft").replace(/([^A-Z]*)([A-Z]+)([^A-Z]*)/g, '$1 $2$3').trim(),
46
+ attributes: story?.stories?.[0]?.args || story?.stories?.[1]?.args || {},
47
+ type: story.type,
48
+ };
49
+ }).filter(Boolean).sort(function (a, b) {
50
+ if (a.label < b.label) {
51
+ return -1;
52
+ }
53
+ if (a.label > b.label) {
54
+ return 1;
55
+ }
56
+ return 0;
57
+ });
58
+
59
+ const [filteredItems, setFilteredItems] = useState(items);
60
+
61
+ useEffect(() => {
62
+ setFilteredItems(items);
63
+ }, [storybookStories]);
64
+
65
+ const handleQueryChange = (query) => {
66
+ setFilteredItems(query ? items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase())) : items);
67
+ };
68
+
69
+ const handleOnChange = (item) => {
70
+ onChange(item);
71
+ };
72
+
73
+ useEffect(() => {
74
+ let autoCompleteElement = document.getElementsByClassName("element-autocomplete")[0];
75
+
76
+ if (autoCompleteElement) {
77
+ autoCompleteElement.value = "";
78
+ }
79
+ }, []);
80
+
81
+
82
+ const groupedItemsObj = filteredItems.reduce((acc, item) => {
83
+ if (!acc[item.group]) {
84
+ acc[item.group] = [];
85
+ }
86
+
87
+ acc[item.group].push(item);
88
+
89
+ return acc;
90
+ }, {});
91
+ const groupedItemsArr = Object.keys(groupedItemsObj).reduce((acc, key) => {
92
+ const group = {
93
+ groupTitle: key || "#",
94
+ options: groupedItemsObj[key],
95
+ };
96
+
97
+ group.options.sort((a, b) => {
98
+ return a.label.localeCompare(b.label);
99
+ });
100
+
101
+ acc.push(group);
102
+
103
+ return acc;
104
+ }, []);
105
+
106
+ groupedItemsArr.sort((a, b) => {
107
+ return a.groupTitle.localeCompare(b.groupTitle);
108
+ });
109
+
110
+ return (
111
+ <Autocomplete
112
+ items={groupedItemsArr}
113
+ isGrouped={true}
114
+ onInputValueChange={handleQueryChange}
115
+ isLoading={isLoading}
116
+ placeholder={'Element hinzufügen'}
117
+ emptyListMessage={'Keine Elemente gefunden'}
118
+ noMatchesMessage={'Keine Elemente gefunden'}
119
+ listMaxHeight={500}
120
+ onSelectItem={handleOnChange}
121
+ width="medium"
122
+ itemToString={(item) => ""}
123
+ renderItem={(item) => `${item.label}`}
124
+ {...props}
125
+ />
126
+ );
127
+ };
128
+
129
+ const customStories = [
130
+ {
131
+ type: "paragraph",
132
+ label: "Text",
133
+ },
134
134
  ];