@vonaffenfels/slate-editor 1.2.19 → 1.2.29

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