@vonaffenfels/slate-editor 1.2.19 → 1.2.23

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