@vonaffenfels/slate-editor 1.2.41 → 1.2.42

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