@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,165 +1,165 @@
1
- import {useSlate} from "slate-react";
2
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
- import React, {useState} from "react";
4
- import classNames from "classnames";
5
- import {
6
- Editor, Transforms, Element as SlateElement, Range,
7
- } from "slate";
8
- import {faLink} from "@fortawesome/free-solid-svg-icons";
9
-
10
- const initialLinkState = {
11
- href: "",
12
- title: "",
13
- noFollow: false,
14
- };
15
-
16
- export const LinkButtonElement = ({
17
- icon,
18
- children,
19
- }) => {
20
- const [savedSelection, setSavedSelection] = useState(null);
21
- const [linkState, setLinkState] = useState(initialLinkState);
22
- const editor = useSlate();
23
- const onClick = (event) => {
24
- event.preventDefault();
25
- editor.selection = savedSelection;
26
- toggleLink(
27
- editor, linkState.href, linkState.title, linkState.noFollow,
28
- );
29
- };
30
-
31
- const onInputChange = (name, value) => {
32
- setLinkState({
33
- ...linkState,
34
- [name]: value,
35
- });
36
- };
37
-
38
- const saveSelection = () => {
39
- if (editor.selection) {
40
- const activeLink = getActiveLink(editor);
41
- if (activeLink) {
42
- setLinkState({
43
- href: activeLink[0].attributes.href,
44
- title: activeLink[0].attributes.title,
45
- noFollow: activeLink[0].attributes.noFollow,
46
- });
47
- }
48
-
49
- setSavedSelection(editor.selection);
50
- }
51
- };
52
-
53
- const removeLink = () => {
54
- editor.selection = savedSelection;
55
- toggleLink(editor);
56
- };
57
-
58
- const resetLinkState = () => {
59
- setLinkState(initialLinkState);
60
- };
61
-
62
- const linkActive = isLinkActive(editor);
63
-
64
- return (
65
- <span
66
- className={
67
- classNames({
68
- "toolbar-btn": true,
69
- "active": linkActive,
70
- })
71
- }
72
- onMouseEnter={saveSelection}
73
- onMouseLeave={resetLinkState}
74
- >
75
- {!!icon && <FontAwesomeIcon icon={icon} />}
76
- {children}
77
- <span className="toolbar-btn-config">
78
- <span className="toolbar-btn-config-inner">
79
- <span className="toolbar-btn-config-row">
80
- <label className="toolbar-form-label">
81
- URL
82
- </label>
83
- <span className="toolbar-form-input">
84
- <input type="text" value={linkState.href} onChange={(e) => onInputChange("href", e.target.value)}/>
85
- </span>
86
- </span>
87
- <span className="toolbar-btn-config-row">
88
- <label className="toolbar-form-label">
89
- Titel
90
- </label>
91
- <span className="toolbar-form-input">
92
- <input type="text" value={linkState.title} onChange={(e) => onInputChange("title", e.target.value)}/>
93
- </span>
94
- </span>
95
- <span className="toolbar-btn-config-row">
96
- <label className="toolbar-form-label">
97
- noFollow
98
- </label>
99
- <span className="toolbar-form-input">
100
- <input type="checkbox" value="1" checked={linkState.noFollow} onChange={(e) => onInputChange("noFollow", e.target.checked)}/>
101
- </span>
102
- </span>
103
- <span className="toolbar-btn-config-row">
104
- <span className="toolbar-btn" onMouseDown={onClick}>Apply</span>
105
- {linkActive && <span className="toolbar-btn" onMouseDown={removeLink}>Remove</span>}
106
- </span>
107
- </span>
108
- </span>
109
- </span>
110
- );
111
- };
112
-
113
- export const getActiveLink = (editor) => {
114
- const [link] = Editor.nodes(editor, {
115
- match: n => {
116
- return !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === 'link';
117
- },
118
- });
119
- return link;
120
- };
121
-
122
- export const isLinkActive = (editor) => {
123
- return !!getActiveLink(editor);
124
- };
125
-
126
-
127
- const unwrapLink = editor => {
128
- Transforms.unwrapNodes(editor, {
129
- match: n =>
130
- !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === 'link',
131
- });
132
- };
133
-
134
- const toggleLink = (
135
- editor, href, title = "", nofollow = false,
136
- ) => {
137
- if (isLinkActive(editor)) {
138
- unwrapLink(editor);
139
- }
140
-
141
- if (href) {
142
- const {selection} = editor;
143
- const isCollapsed = selection && Range.isCollapsed(selection);
144
- const link = {
145
- type: 'link',
146
- attributes: {
147
- href: href,
148
- title: title,
149
- nofollow: !!nofollow,
150
- },
151
- children: isCollapsed ? [{text: href}] : [],
152
- };
153
-
154
- if (isCollapsed) {
155
- Transforms.insertNodes(editor, link);
156
- } else {
157
- Transforms.wrapNodes(editor, link, {split: true});
158
- Transforms.collapse(editor, {edge: 'end'});
159
- }
160
- }
161
- };
162
-
163
- export const LinkButton = () => {
164
- return <LinkButtonElement icon={faLink}/>;
1
+ import {useSlate} from "slate-react";
2
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
+ import React, {useState} from "react";
4
+ import classNames from "classnames";
5
+ import {
6
+ Editor, Transforms, Element as SlateElement, Range,
7
+ } from "slate";
8
+ import {faLink} from "@fortawesome/free-solid-svg-icons";
9
+
10
+ const initialLinkState = {
11
+ href: "",
12
+ title: "",
13
+ noFollow: false,
14
+ };
15
+
16
+ export const LinkButtonElement = ({
17
+ icon,
18
+ children,
19
+ }) => {
20
+ const [savedSelection, setSavedSelection] = useState(null);
21
+ const [linkState, setLinkState] = useState(initialLinkState);
22
+ const editor = useSlate();
23
+ const onClick = (event) => {
24
+ event.preventDefault();
25
+ editor.selection = savedSelection;
26
+ toggleLink(
27
+ editor, linkState.href, linkState.title, linkState.noFollow,
28
+ );
29
+ };
30
+
31
+ const onInputChange = (name, value) => {
32
+ setLinkState({
33
+ ...linkState,
34
+ [name]: value,
35
+ });
36
+ };
37
+
38
+ const saveSelection = () => {
39
+ if (editor.selection) {
40
+ const activeLink = getActiveLink(editor);
41
+ if (activeLink) {
42
+ setLinkState({
43
+ href: activeLink[0].attributes.href,
44
+ title: activeLink[0].attributes.title,
45
+ noFollow: activeLink[0].attributes.noFollow,
46
+ });
47
+ }
48
+
49
+ setSavedSelection(editor.selection);
50
+ }
51
+ };
52
+
53
+ const removeLink = () => {
54
+ editor.selection = savedSelection;
55
+ toggleLink(editor);
56
+ };
57
+
58
+ const resetLinkState = () => {
59
+ setLinkState(initialLinkState);
60
+ };
61
+
62
+ const linkActive = isLinkActive(editor);
63
+
64
+ return (
65
+ <span
66
+ className={
67
+ classNames({
68
+ "toolbar-btn": true,
69
+ "active": linkActive,
70
+ })
71
+ }
72
+ onMouseEnter={saveSelection}
73
+ onMouseLeave={resetLinkState}
74
+ >
75
+ {!!icon && <FontAwesomeIcon icon={icon} />}
76
+ {children}
77
+ <span className="toolbar-btn-config">
78
+ <span className="toolbar-btn-config-inner">
79
+ <span className="toolbar-btn-config-row">
80
+ <label className="toolbar-form-label">
81
+ URL
82
+ </label>
83
+ <span className="toolbar-form-input">
84
+ <input type="text" value={linkState.href} onChange={(e) => onInputChange("href", e.target.value)}/>
85
+ </span>
86
+ </span>
87
+ <span className="toolbar-btn-config-row">
88
+ <label className="toolbar-form-label">
89
+ Titel
90
+ </label>
91
+ <span className="toolbar-form-input">
92
+ <input type="text" value={linkState.title} onChange={(e) => onInputChange("title", e.target.value)}/>
93
+ </span>
94
+ </span>
95
+ <span className="toolbar-btn-config-row">
96
+ <label className="toolbar-form-label">
97
+ noFollow
98
+ </label>
99
+ <span className="toolbar-form-input">
100
+ <input type="checkbox" value="1" checked={linkState.noFollow} onChange={(e) => onInputChange("noFollow", e.target.checked)}/>
101
+ </span>
102
+ </span>
103
+ <span className="toolbar-btn-config-row">
104
+ <span className="toolbar-btn" onMouseDown={onClick}>Apply</span>
105
+ {linkActive && <span className="toolbar-btn" onMouseDown={removeLink}>Remove</span>}
106
+ </span>
107
+ </span>
108
+ </span>
109
+ </span>
110
+ );
111
+ };
112
+
113
+ export const getActiveLink = (editor) => {
114
+ const [link] = Editor.nodes(editor, {
115
+ match: n => {
116
+ return !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === 'link';
117
+ },
118
+ });
119
+ return link;
120
+ };
121
+
122
+ export const isLinkActive = (editor) => {
123
+ return !!getActiveLink(editor);
124
+ };
125
+
126
+
127
+ const unwrapLink = editor => {
128
+ Transforms.unwrapNodes(editor, {
129
+ match: n =>
130
+ !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === 'link',
131
+ });
132
+ };
133
+
134
+ const toggleLink = (
135
+ editor, href, title = "", nofollow = false,
136
+ ) => {
137
+ if (isLinkActive(editor)) {
138
+ unwrapLink(editor);
139
+ }
140
+
141
+ if (href) {
142
+ const {selection} = editor;
143
+ const isCollapsed = selection && Range.isCollapsed(selection);
144
+ const link = {
145
+ type: 'link',
146
+ attributes: {
147
+ href: href,
148
+ title: title,
149
+ nofollow: !!nofollow,
150
+ },
151
+ children: isCollapsed ? [{text: href}] : [],
152
+ };
153
+
154
+ if (isCollapsed) {
155
+ Transforms.insertNodes(editor, link);
156
+ } else {
157
+ Transforms.wrapNodes(editor, link, {split: true});
158
+ Transforms.collapse(editor, {edge: 'end'});
159
+ }
160
+ }
161
+ };
162
+
163
+ export const LinkButton = () => {
164
+ return <LinkButtonElement icon={faLink}/>;
165
165
  };