@vonaffenfels/slate-editor 1.2.18 → 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 (81) 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 +371 -371
  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/AssetList.js +181 -181
  29. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  30. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  31. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  32. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  33. package/src/SidebarEditor/Fields/MVP.js +66 -66
  34. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  35. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  36. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  37. package/src/SidebarEditor/Fields/Select.js +47 -47
  38. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  39. package/src/SidebarEditor/Fields/Switch.js +34 -34
  40. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  41. package/src/SidebarEditor/Resizable.js +85 -85
  42. package/src/Storybook.js +151 -151
  43. package/src/Toolbar/Align.js +64 -64
  44. package/src/Toolbar/Anchor.js +94 -94
  45. package/src/Toolbar/Block.js +135 -135
  46. package/src/Toolbar/Element.js +44 -44
  47. package/src/Toolbar/Formats.js +71 -71
  48. package/src/Toolbar/Insert.js +28 -28
  49. package/src/Toolbar/Layout.js +399 -399
  50. package/src/Toolbar/Link.js +164 -164
  51. package/src/Toolbar/Toolbar.js +235 -235
  52. package/src/Tools/Margin.js +51 -51
  53. package/src/Translation/TranslationToolbarButton.js +119 -119
  54. package/src/dev/draftToSlate.json +3147 -3147
  55. package/src/dev/index.css +2 -2
  56. package/src/dev/index.html +10 -10
  57. package/src/dev/index.js +4 -4
  58. package/src/dev/sampleValue1.json +4294 -4294
  59. package/src/dev/sampleValueValid.json +410 -410
  60. package/src/dev/testComponents/TestStory.js +74 -74
  61. package/src/dev/testComponents/TestStory.stories.js +216 -216
  62. package/src/dev/testComponents/TestStory2.js +74 -74
  63. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  64. package/src/dev/testComponents/TestStory3.js +74 -74
  65. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  66. package/src/dev/testSampleValue.json +746 -746
  67. package/src/fromHTML.js +4 -4
  68. package/src/helper/array.js +8 -8
  69. package/src/index.js +10 -10
  70. package/src/plugins/ListItem.js +48 -48
  71. package/src/plugins/SoftBreak.js +23 -23
  72. package/src/toHTML.js +6 -6
  73. package/src/toText.js +6 -6
  74. package/src/util/reduceContentfulResponse.js +64 -64
  75. package/src/util.js +19 -19
  76. package/storyLoader.js +47 -47
  77. package/tailwind.config.js +4 -4
  78. package/webpack.config.build.js +55 -55
  79. package/webpack.config.dev.js +60 -60
  80. package/webpack.config.js +130 -130
  81. package/webpack.config.watch.js +4 -4
@@ -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="relative 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 className="shrink-0">
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 className="shink-0">{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="relative 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 className="shrink-0">
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 className="shink-0">{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
  };