@vonaffenfels/slate-editor 1.1.70 → 1.1.71

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 +1871 -4
  5. package/dist/BlockEditor.js +3960 -336
  6. package/dist/Renderer.js +2081 -2
  7. package/dist/fromHTML.js +78 -1
  8. package/dist/index.css +1871 -4
  9. package/dist/index.js +4037 -336
  10. package/dist/toHTML.js +1689 -2
  11. package/dist/toText.js +1689 -2
  12. package/package.json +2 -2
  13. package/postcss.config.js +6 -6
  14. package/scss/demo.scss +148 -148
  15. package/scss/sidebarEditor.scss +181 -181
  16. package/scss/toolbar.scss +161 -161
  17. package/src/Blocks/EmptyBlock.js +11 -11
  18. package/src/Blocks/EmptyWrapper.js +4 -4
  19. package/src/Blocks/ErrorBoundary.js +40 -40
  20. package/src/Blocks/LayoutBlock.js +274 -274
  21. package/src/Blocks/LayoutSlot.js +90 -90
  22. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  23. package/src/Context/StorybookContext.js +6 -6
  24. package/src/ElementAutocomplete.js +133 -133
  25. package/src/Loader.js +137 -137
  26. package/src/Nodes/Default.js +158 -158
  27. package/src/Nodes/Leaf.js +54 -54
  28. package/src/Nodes/Text.js +97 -97
  29. package/src/ObjectId.js +3 -3
  30. package/src/Renderer.js +73 -73
  31. package/src/Serializer/Html.js +42 -42
  32. package/src/Serializer/Serializer.js +371 -371
  33. package/src/Serializer/Text.js +17 -17
  34. package/src/Serializer/ads.js +174 -174
  35. package/src/Serializer/index.js +3 -3
  36. package/src/SidebarEditor/AssetList.js +181 -181
  37. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  38. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  39. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  40. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  41. package/src/SidebarEditor/Fields/MVP.js +66 -66
  42. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  43. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  44. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  45. package/src/SidebarEditor/Fields/Select.js +47 -47
  46. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  47. package/src/SidebarEditor/Fields/Switch.js +34 -34
  48. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  49. package/src/SidebarEditor/Resizable.js +85 -85
  50. package/src/Storybook.js +151 -151
  51. package/src/Toolbar/Align.js +64 -64
  52. package/src/Toolbar/Anchor.js +94 -94
  53. package/src/Toolbar/Block.js +135 -135
  54. package/src/Toolbar/Element.js +44 -44
  55. package/src/Toolbar/Formats.js +71 -71
  56. package/src/Toolbar/Insert.js +28 -28
  57. package/src/Toolbar/Layout.js +399 -399
  58. package/src/Toolbar/Link.js +164 -164
  59. package/src/Toolbar/Toolbar.js +235 -235
  60. package/src/Tools/Margin.js +51 -51
  61. package/src/Translation/TranslationToolbarButton.js +115 -115
  62. package/src/dev/draftToSlate.json +3147 -3147
  63. package/src/dev/index.css +2 -2
  64. package/src/dev/index.html +10 -10
  65. package/src/dev/index.js +4 -4
  66. package/src/dev/sampleValue1.json +4294 -4294
  67. package/src/dev/sampleValueValid.json +410 -410
  68. package/src/dev/testComponents/TestStory.js +74 -74
  69. package/src/dev/testComponents/TestStory.stories.js +216 -216
  70. package/src/dev/testComponents/TestStory2.js +74 -74
  71. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  72. package/src/dev/testComponents/TestStory3.js +74 -74
  73. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  74. package/src/dev/testSampleValue.json +746 -746
  75. package/src/fromHTML.js +4 -4
  76. package/src/helper/array.js +8 -8
  77. package/src/index.js +10 -10
  78. package/src/plugins/ListItem.js +48 -48
  79. package/src/plugins/SoftBreak.js +23 -23
  80. package/src/toHTML.js +6 -6
  81. package/src/toText.js +6 -6
  82. package/src/util/reduceContentfulResponse.js +64 -64
  83. package/src/util.js +19 -19
  84. package/storyLoader.js +47 -47
  85. package/tailwind.config.js +4 -4
  86. package/webpack.config.build.js +55 -55
  87. package/webpack.config.dev.js +60 -60
  88. package/webpack.config.js +130 -130
  89. package/webpack.config.watch.js +4 -4
  90. package/dist/BlockEditor.js.LICENSE.txt +0 -61
  91. package/dist/Renderer.js.LICENSE.txt +0 -15
  92. package/dist/index.js.LICENSE.txt +0 -69
  93. package/dist/toHTML.js.LICENSE.txt +0 -23
  94. package/dist/toText.js.LICENSE.txt +0 -23
@@ -1,236 +1,236 @@
1
- import ReactDOM from "react-dom";
2
- import React, {
3
- useEffect, useRef, useState,
4
- } from "react";
5
- import {ReactEditor} from "slate-react";
6
- import {Node} from "slate";
7
- import classNames from "classnames";
8
- // eslint-disable-next-line import/no-unresolved
9
- import "scss/toolbar.scss";
10
- import {
11
- FormatButtonBold, FormatButtonItalic, FormatButtonStrikethrough, FormatButtonSuperscriptUp, FormatButtonUnderline,
12
- } from "./Formats";
13
- import {
14
- AlignButtonLeft, AlignButtonCenter, AlignButtonRight,
15
- } from "./Align";
16
- import {
17
- BlockButtonHeading, BlockButtonUnorderedList, BlockButtonOrderedList, BlockButtonBlockquote, BlockButtonArrowList,
18
- } from "./Block";
19
- import {StorybookButton} from "./Element";
20
- import {LinkButton} from "./Link";
21
- import {InsertDividerButton} from "./Insert";
22
- import {InsertGridButton} from "./Layout";
23
- import {
24
- Autocomplete, Spinner,
25
- } from "@contentful/forma-36-react-components";
26
- import {Transforms} from "slate";
27
- import {ElementAutocomplete} from "../ElementAutocomplete";
28
- import {AnchorButton} from "./Anchor";
29
-
30
- export const Portal = ({children}) => {
31
- return ReactDOM.createPortal(children, window.document.body);
32
- };
33
-
34
- export const Toolbar = ({
35
- hover,
36
- onSaveClick,
37
- storybookStories,
38
- isLoadingStories,
39
- editor,
40
- sdk,
41
- lastSelection,
42
- buttons,
43
- }) => {
44
- const ref = useRef();
45
-
46
- const portal = sdk?.entry?.fields?.portal.getValue();
47
-
48
- useEffect(() => {
49
- if (!hover) {
50
- return;
51
- }
52
-
53
- const el = ref.current;
54
- const {selection} = editor;
55
-
56
- if (!el) {
57
- return;
58
- }
59
-
60
- if (
61
- // !selection ||
62
- !ReactEditor.isFocused(editor) // ||
63
- // Range.isCollapsed(selection) ||
64
- // Editor.string(editor, selection) === ''
65
- ) {
66
- el.removeAttribute('style');
67
- el.classList.remove("active");
68
- return;
69
- }
70
-
71
- try {
72
- const domSelection = window.getSelection();
73
- const domRange = domSelection.getRangeAt(0);
74
- const rect = domRange.getBoundingClientRect();
75
-
76
- el.classList.add("active");
77
-
78
- let distanceToMouse = 10;
79
- let top = rect.top + window.pageYOffset - el.offsetHeight - distanceToMouse;
80
- let left = rect.left + window.pageXOffset - el.offsetWidth / 2 + rect.width / 2 + distanceToMouse;
81
-
82
- if (top < 0) {
83
- top = el.offsetHeight;
84
- }
85
-
86
- if (left < 0) {
87
- left = 0;
88
- }
89
-
90
- el.style.top = `${top}px`;
91
- el.style.left = `${left}px`;
92
- } catch (e) {
93
- el.removeAttribute('style');
94
- el.classList.remove("active");
95
- }
96
- }, [hover, ref, editor]);
97
-
98
- const handleAutocompleteChange = item => {
99
- let element = {
100
- children: [{text: ''}],
101
- type: item.type,
102
- block: item.value,
103
- attributes: {
104
- ...(item.attributes || {}),
105
- blockWidth: "site",
106
- },
107
- };
108
-
109
- if (lastSelection?.anchor?.path?.length) {
110
- lastSelection.anchor.path.forEach((p, i) => {
111
- let slicedPath = lastSelection.anchor.path.slice(0, i + 1);
112
- let node = Node.get(editor, slicedPath);
113
-
114
- // Wenn Paragraph, dann auf die Ebene des Paragraphen
115
- if (node.type === "paragraph") {
116
- Transforms.insertNodes(editor, [element], {at: slicedPath});
117
-
118
- return;
119
- }
120
-
121
- // Wenn vorletzter Anchor, dann einfügen (letzter ist column, keine row)
122
- if (i === lastSelection.anchor.path.length - 2) {
123
- Transforms.insertNodes(editor, [element], {at: slicedPath});
124
- }
125
- });
126
- } else {
127
- Transforms.insertNodes(editor, [element], {at: [0]});
128
- }
129
- };
130
-
131
- function renderMenu() {
132
- return <Menu
133
- ref={ref}
134
- className={classNames({
135
- active: !hover,
136
- "toolbar-static": !hover,
137
- toolbar: true,
138
- })}
139
- >
140
- <div className="toolbar-btns">
141
- <div className="flex grow items-center">
142
- <div className="flex">
143
- <FormatButtonBold/>
144
- <FormatButtonItalic/>
145
- <FormatButtonUnderline/>
146
- <FormatButtonStrikethrough/>
147
- <FormatButtonSuperscriptUp />
148
-
149
- <LinkButton/>
150
-
151
- <ToobarHoverExpandButton>
152
- <BlockButtonHeading level={1}/>
153
- <BlockButtonHeading level={2}/>
154
- <BlockButtonHeading level={3}/>
155
- <BlockButtonHeading level={4}/>
156
- </ToobarHoverExpandButton>
157
-
158
- <ToobarHoverExpandButton>
159
- <BlockButtonUnorderedList/>
160
- <BlockButtonOrderedList/>
161
- <BlockButtonArrowList/>
162
- </ToobarHoverExpandButton>
163
-
164
- <BlockButtonBlockquote/>
165
-
166
- <ToobarHoverExpandButton>
167
- <AlignButtonLeft/>
168
- <AlignButtonCenter/>
169
- <AlignButtonRight/>
170
- </ToobarHoverExpandButton>
171
-
172
- <AnchorButton />
173
-
174
- <ToobarHoverExpandButton>
175
- <InsertDividerButton/>
176
- <InsertGridButton/>
177
- </ToobarHoverExpandButton>
178
- </div>
179
-
180
- <div>
181
- <ElementAutocomplete
182
- isLoading={isLoadingStories}
183
- storybookStories={storybookStories}
184
- editor={editor}
185
- storyContext={sdk.parameters.instance.storyContext}
186
- portal={portal}
187
- lastSelection={lastSelection}
188
- onChange={handleAutocompleteChange}
189
- />
190
- </div>
191
- </div>
192
- {!!onSaveClick && <button
193
- className="!w-auto !border-0 !bg-green-600 !text-xs font-bold text-white hover:!bg-green-700"
194
- onClick={onSaveClick}>Änderungen speichern</button>}
195
- {buttons && (
196
- <div>{buttons}</div>
197
- )}
198
- </div>
199
- </Menu>;
200
- }
201
-
202
- if (hover) {
203
- return (
204
- <Portal>
205
- {renderMenu()}
206
- </Portal>
207
- );
208
- } else {
209
- return renderMenu();
210
- }
211
- };
212
-
213
- export const ToobarHoverExpandButton = ({children}) => {
214
- return <span
215
- className={
216
- classNames({"toolbar-btn-expand": true})
217
- }
218
- >
219
- <div className="toolbar-btn-expand-inner">
220
- {children}
221
- </div>
222
- </span>;
223
- };
224
-
225
- export const Menu = React.forwardRef(({
226
- className, ...props
227
- },
228
- ref) => (
229
- <div
230
- {...props}
231
- ref={ref}
232
- className={className}
233
- />
234
- ));
235
-
1
+ import ReactDOM from "react-dom";
2
+ import React, {
3
+ useEffect, useRef, useState,
4
+ } from "react";
5
+ import {ReactEditor} from "slate-react";
6
+ import {Node} from "slate";
7
+ import classNames from "classnames";
8
+ // eslint-disable-next-line import/no-unresolved
9
+ import "scss/toolbar.scss";
10
+ import {
11
+ FormatButtonBold, FormatButtonItalic, FormatButtonStrikethrough, FormatButtonSuperscriptUp, FormatButtonUnderline,
12
+ } from "./Formats";
13
+ import {
14
+ AlignButtonLeft, AlignButtonCenter, AlignButtonRight,
15
+ } from "./Align";
16
+ import {
17
+ BlockButtonHeading, BlockButtonUnorderedList, BlockButtonOrderedList, BlockButtonBlockquote, BlockButtonArrowList,
18
+ } from "./Block";
19
+ import {StorybookButton} from "./Element";
20
+ import {LinkButton} from "./Link";
21
+ import {InsertDividerButton} from "./Insert";
22
+ import {InsertGridButton} from "./Layout";
23
+ import {
24
+ Autocomplete, Spinner,
25
+ } from "@contentful/forma-36-react-components";
26
+ import {Transforms} from "slate";
27
+ import {ElementAutocomplete} from "../ElementAutocomplete";
28
+ import {AnchorButton} from "./Anchor";
29
+
30
+ export const Portal = ({children}) => {
31
+ return ReactDOM.createPortal(children, window.document.body);
32
+ };
33
+
34
+ export const Toolbar = ({
35
+ hover,
36
+ onSaveClick,
37
+ storybookStories,
38
+ isLoadingStories,
39
+ editor,
40
+ sdk,
41
+ lastSelection,
42
+ buttons,
43
+ }) => {
44
+ const ref = useRef();
45
+
46
+ const portal = sdk?.entry?.fields?.portal.getValue();
47
+
48
+ useEffect(() => {
49
+ if (!hover) {
50
+ return;
51
+ }
52
+
53
+ const el = ref.current;
54
+ const {selection} = editor;
55
+
56
+ if (!el) {
57
+ return;
58
+ }
59
+
60
+ if (
61
+ // !selection ||
62
+ !ReactEditor.isFocused(editor) // ||
63
+ // Range.isCollapsed(selection) ||
64
+ // Editor.string(editor, selection) === ''
65
+ ) {
66
+ el.removeAttribute('style');
67
+ el.classList.remove("active");
68
+ return;
69
+ }
70
+
71
+ try {
72
+ const domSelection = window.getSelection();
73
+ const domRange = domSelection.getRangeAt(0);
74
+ const rect = domRange.getBoundingClientRect();
75
+
76
+ el.classList.add("active");
77
+
78
+ let distanceToMouse = 10;
79
+ let top = rect.top + window.pageYOffset - el.offsetHeight - distanceToMouse;
80
+ let left = rect.left + window.pageXOffset - el.offsetWidth / 2 + rect.width / 2 + distanceToMouse;
81
+
82
+ if (top < 0) {
83
+ top = el.offsetHeight;
84
+ }
85
+
86
+ if (left < 0) {
87
+ left = 0;
88
+ }
89
+
90
+ el.style.top = `${top}px`;
91
+ el.style.left = `${left}px`;
92
+ } catch (e) {
93
+ el.removeAttribute('style');
94
+ el.classList.remove("active");
95
+ }
96
+ }, [hover, ref, editor]);
97
+
98
+ const handleAutocompleteChange = item => {
99
+ let element = {
100
+ children: [{text: ''}],
101
+ type: item.type,
102
+ block: item.value,
103
+ attributes: {
104
+ ...(item.attributes || {}),
105
+ blockWidth: "site",
106
+ },
107
+ };
108
+
109
+ if (lastSelection?.anchor?.path?.length) {
110
+ lastSelection.anchor.path.forEach((p, i) => {
111
+ let slicedPath = lastSelection.anchor.path.slice(0, i + 1);
112
+ let node = Node.get(editor, slicedPath);
113
+
114
+ // Wenn Paragraph, dann auf die Ebene des Paragraphen
115
+ if (node.type === "paragraph") {
116
+ Transforms.insertNodes(editor, [element], {at: slicedPath});
117
+
118
+ return;
119
+ }
120
+
121
+ // Wenn vorletzter Anchor, dann einfügen (letzter ist column, keine row)
122
+ if (i === lastSelection.anchor.path.length - 2) {
123
+ Transforms.insertNodes(editor, [element], {at: slicedPath});
124
+ }
125
+ });
126
+ } else {
127
+ Transforms.insertNodes(editor, [element], {at: [0]});
128
+ }
129
+ };
130
+
131
+ function renderMenu() {
132
+ return <Menu
133
+ ref={ref}
134
+ className={classNames({
135
+ active: !hover,
136
+ "toolbar-static": !hover,
137
+ toolbar: true,
138
+ })}
139
+ >
140
+ <div className="toolbar-btns">
141
+ <div className="flex grow items-center">
142
+ <div className="flex">
143
+ <FormatButtonBold/>
144
+ <FormatButtonItalic/>
145
+ <FormatButtonUnderline/>
146
+ <FormatButtonStrikethrough/>
147
+ <FormatButtonSuperscriptUp />
148
+
149
+ <LinkButton/>
150
+
151
+ <ToobarHoverExpandButton>
152
+ <BlockButtonHeading level={1}/>
153
+ <BlockButtonHeading level={2}/>
154
+ <BlockButtonHeading level={3}/>
155
+ <BlockButtonHeading level={4}/>
156
+ </ToobarHoverExpandButton>
157
+
158
+ <ToobarHoverExpandButton>
159
+ <BlockButtonUnorderedList/>
160
+ <BlockButtonOrderedList/>
161
+ <BlockButtonArrowList/>
162
+ </ToobarHoverExpandButton>
163
+
164
+ <BlockButtonBlockquote/>
165
+
166
+ <ToobarHoverExpandButton>
167
+ <AlignButtonLeft/>
168
+ <AlignButtonCenter/>
169
+ <AlignButtonRight/>
170
+ </ToobarHoverExpandButton>
171
+
172
+ <AnchorButton />
173
+
174
+ <ToobarHoverExpandButton>
175
+ <InsertDividerButton/>
176
+ <InsertGridButton/>
177
+ </ToobarHoverExpandButton>
178
+ </div>
179
+
180
+ <div>
181
+ <ElementAutocomplete
182
+ isLoading={isLoadingStories}
183
+ storybookStories={storybookStories}
184
+ editor={editor}
185
+ storyContext={sdk.parameters.instance.storyContext}
186
+ portal={portal}
187
+ lastSelection={lastSelection}
188
+ onChange={handleAutocompleteChange}
189
+ />
190
+ </div>
191
+ </div>
192
+ {!!onSaveClick && <button
193
+ className="!w-auto !border-0 !bg-green-600 !text-xs font-bold text-white hover:!bg-green-700"
194
+ onClick={onSaveClick}>Änderungen speichern</button>}
195
+ {buttons && (
196
+ <div>{buttons}</div>
197
+ )}
198
+ </div>
199
+ </Menu>;
200
+ }
201
+
202
+ if (hover) {
203
+ return (
204
+ <Portal>
205
+ {renderMenu()}
206
+ </Portal>
207
+ );
208
+ } else {
209
+ return renderMenu();
210
+ }
211
+ };
212
+
213
+ export const ToobarHoverExpandButton = ({children}) => {
214
+ return <span
215
+ className={
216
+ classNames({"toolbar-btn-expand": true})
217
+ }
218
+ >
219
+ <div className="toolbar-btn-expand-inner">
220
+ {children}
221
+ </div>
222
+ </span>;
223
+ };
224
+
225
+ export const Menu = React.forwardRef(({
226
+ className, ...props
227
+ },
228
+ ref) => (
229
+ <div
230
+ {...props}
231
+ ref={ref}
232
+ className={className}
233
+ />
234
+ ));
235
+
236
236
  Menu.displayName = "Menu";
@@ -1,52 +1,52 @@
1
- import classNames from "classnames";
2
-
3
- export const ToolMargin = ({
4
- margin,
5
- onChange,
6
- }) => {
7
- const onMarginClick = (e, direction) => {
8
- onChange({
9
- ...(margin || {}),
10
- [direction]: !margin?.[direction],
11
- });
12
- };
13
-
14
- return <span className="layout-slot-option-padding">
15
- <span
16
- className={classNames({
17
- "layout-slot-option-padding-item layout-slot-option-padding-top": true,
18
- "active": margin?.top,
19
- })}
20
- contentEditable={false}
21
- onClick={(e) => {
22
- onMarginClick(e, "top");
23
- }} />
24
- <span
25
- className={classNames({
26
- "layout-slot-option-padding-item layout-slot-option-padding-right": true,
27
- "active": margin?.right,
28
- })}
29
- contentEditable={false}
30
- onClick={(e) => {
31
- onMarginClick(e, "right");
32
- }} />
33
- <span
34
- className={classNames({
35
- "layout-slot-option-padding-item layout-slot-option-padding-bottom": true,
36
- "active": margin?.bottom,
37
- })}
38
- contentEditable={false}
39
- onClick={(e) => {
40
- onMarginClick(e, "bottom");
41
- }} />
42
- <span
43
- className={classNames({
44
- "layout-slot-option-padding-item layout-slot-option-padding-left": true,
45
- "active": margin?.left,
46
- })}
47
- contentEditable={false}
48
- onClick={(e) => {
49
- onMarginClick(e, "left");
50
- }} />
51
- </span>;
1
+ import classNames from "classnames";
2
+
3
+ export const ToolMargin = ({
4
+ margin,
5
+ onChange,
6
+ }) => {
7
+ const onMarginClick = (e, direction) => {
8
+ onChange({
9
+ ...(margin || {}),
10
+ [direction]: !margin?.[direction],
11
+ });
12
+ };
13
+
14
+ return <span className="layout-slot-option-padding">
15
+ <span
16
+ className={classNames({
17
+ "layout-slot-option-padding-item layout-slot-option-padding-top": true,
18
+ "active": margin?.top,
19
+ })}
20
+ contentEditable={false}
21
+ onClick={(e) => {
22
+ onMarginClick(e, "top");
23
+ }} />
24
+ <span
25
+ className={classNames({
26
+ "layout-slot-option-padding-item layout-slot-option-padding-right": true,
27
+ "active": margin?.right,
28
+ })}
29
+ contentEditable={false}
30
+ onClick={(e) => {
31
+ onMarginClick(e, "right");
32
+ }} />
33
+ <span
34
+ className={classNames({
35
+ "layout-slot-option-padding-item layout-slot-option-padding-bottom": true,
36
+ "active": margin?.bottom,
37
+ })}
38
+ contentEditable={false}
39
+ onClick={(e) => {
40
+ onMarginClick(e, "bottom");
41
+ }} />
42
+ <span
43
+ className={classNames({
44
+ "layout-slot-option-padding-item layout-slot-option-padding-left": true,
45
+ "active": margin?.left,
46
+ })}
47
+ contentEditable={false}
48
+ onClick={(e) => {
49
+ onMarginClick(e, "left");
50
+ }} />
51
+ </span>;
52
52
  };