@vonaffenfels/slate-editor 1.1.71 → 1.2.0

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