@vonaffenfels/slate-editor 1.2.15 → 1.2.19

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