@vonaffenfels/slate-editor 1.1.71 → 1.2.10

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 (96) 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/editor.scss +17 -5
  21. package/scss/sidebarEditor.scss +185 -181
  22. package/scss/toolbar.scss +161 -161
  23. package/src/BlockEditor.js +6 -3
  24. package/src/Blocks/EmptyBlock.js +11 -11
  25. package/src/Blocks/EmptyWrapper.js +4 -4
  26. package/src/Blocks/ErrorBoundary.js +40 -40
  27. package/src/Blocks/LayoutBlock.js +274 -274
  28. package/src/Blocks/LayoutSlot.js +90 -90
  29. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  30. package/src/Context/StorybookContext.js +6 -6
  31. package/src/ElementAutocomplete.js +133 -133
  32. package/src/Loader.js +137 -137
  33. package/src/Nodes/Default.js +158 -158
  34. package/src/Nodes/Leaf.js +54 -54
  35. package/src/Nodes/Text.js +97 -97
  36. package/src/ObjectId.js +3 -3
  37. package/src/Renderer.js +73 -73
  38. package/src/Serializer/Html.js +42 -42
  39. package/src/Serializer/Serializer.js +371 -371
  40. package/src/Serializer/Text.js +17 -17
  41. package/src/Serializer/ads.js +174 -174
  42. package/src/Serializer/index.js +3 -3
  43. package/src/SidebarEditor/AssetList.js +181 -181
  44. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  45. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  46. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  47. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  48. package/src/SidebarEditor/Fields/MVP.js +66 -66
  49. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  50. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  51. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  52. package/src/SidebarEditor/Fields/Select.js +47 -47
  53. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  54. package/src/SidebarEditor/Fields/Switch.js +34 -34
  55. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  56. package/src/SidebarEditor/Resizable.js +85 -85
  57. package/src/Storybook.js +151 -151
  58. package/src/Toolbar/Align.js +64 -64
  59. package/src/Toolbar/Anchor.js +94 -94
  60. package/src/Toolbar/Block.js +135 -135
  61. package/src/Toolbar/Element.js +44 -44
  62. package/src/Toolbar/Formats.js +71 -71
  63. package/src/Toolbar/Insert.js +28 -28
  64. package/src/Toolbar/Layout.js +399 -399
  65. package/src/Toolbar/Link.js +164 -164
  66. package/src/Toolbar/Toolbar.js +235 -235
  67. package/src/Tools/Margin.js +51 -51
  68. package/src/Translation/TranslationToolbarButton.js +119 -115
  69. package/src/dev/draftToSlate.json +3147 -3147
  70. package/src/dev/index.css +2 -2
  71. package/src/dev/index.html +10 -10
  72. package/src/dev/index.js +4 -4
  73. package/src/dev/sampleValue1.json +4294 -4294
  74. package/src/dev/sampleValueValid.json +410 -410
  75. package/src/dev/testComponents/TestStory.js +74 -74
  76. package/src/dev/testComponents/TestStory.stories.js +216 -216
  77. package/src/dev/testComponents/TestStory2.js +74 -74
  78. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  79. package/src/dev/testComponents/TestStory3.js +74 -74
  80. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  81. package/src/dev/testSampleValue.json +746 -746
  82. package/src/fromHTML.js +4 -4
  83. package/src/helper/array.js +8 -8
  84. package/src/index.js +10 -10
  85. package/src/plugins/ListItem.js +48 -48
  86. package/src/plugins/SoftBreak.js +23 -23
  87. package/src/toHTML.js +6 -6
  88. package/src/toText.js +6 -6
  89. package/src/util/reduceContentfulResponse.js +64 -64
  90. package/src/util.js +19 -19
  91. package/storyLoader.js +47 -47
  92. package/tailwind.config.js +4 -4
  93. package/webpack.config.build.js +55 -55
  94. package/webpack.config.dev.js +60 -60
  95. package/webpack.config.js +130 -130
  96. package/webpack.config.watch.js +4 -4
@@ -1,136 +1,136 @@
1
- import {useSlate} from "slate-react";
2
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
- import React from "react";
4
- import classNames from "classnames";
5
- import {
6
- Editor, Transforms, Element as SlateElement,
7
- } from "slate";
8
- import {
9
- faListUl, faListOl, faHeading, faQuoteLeft, faArrowRight,
10
- } from "@fortawesome/free-solid-svg-icons";
11
-
12
- const LIST_TYPES = ['unordered-list', 'ordered-list', 'arrow-list'];
13
-
14
- export const BlockButton = ({
15
- block,
16
- icon,
17
- children,
18
- attributes,
19
- }) => {
20
- const editor = useSlate();
21
- const onClick = (event) => {
22
- event.preventDefault();
23
- toggleBlock(editor, block, attributes);
24
- };
25
-
26
- return (
27
- <span
28
- onMouseDown={onClick}
29
- className={
30
- classNames({
31
- "toolbar-btn": true,
32
- "active": isBlockActive(editor, block, attributes),
33
- })
34
- }>
35
- {!!icon && <FontAwesomeIcon icon={icon} />}
36
- {children}
37
- </span>
38
- );
39
- };
40
-
41
- export const toggleBlock = (editor, format, attributes) => {
42
- const isActive = isBlockActive(editor, format, attributes);
43
- const isList = LIST_TYPES.includes(format);
44
-
45
- Transforms.unwrapNodes(editor, {
46
- match: n => {
47
- return LIST_TYPES.includes(!Editor.isEditor(n) && SlateElement.isElement(n) && n.type);
48
- },
49
- split: true,
50
- });
51
-
52
- let newFormat = isActive ? "paragraph" : format;
53
-
54
- if (!isActive && isList) {
55
- newFormat = "list-item";
56
- }
57
-
58
- Transforms.setNodes(editor,
59
- {
60
- type: newFormat,
61
- attributes: attributes,
62
- });
63
-
64
- if (!isActive && isList) {
65
- const block = {
66
- type: format,
67
- children: [],
68
- };
69
-
70
- Transforms.wrapNodes(editor, block);
71
- }
72
- };
73
-
74
- export const isBlockActive = (editor, format, attributes) => {
75
- const {selection} = editor;
76
-
77
- if (selection) {
78
- let selected = editor;
79
-
80
- let reducedPath = selection.anchor.path.slice(0, -1);
81
-
82
- for (let i = 0; i < reducedPath.length; i++) {
83
- let path = reducedPath[i];
84
-
85
- selected = selected.children[path];
86
-
87
- if (LIST_TYPES.includes(selected.type)) {
88
- break;
89
- }
90
- }
91
-
92
- const selectedNodes = [selected];
93
-
94
- return !!selectedNodes.find(v => {
95
- if (Editor.isEditor(v)) {
96
- return false;
97
- }
98
-
99
- if (!SlateElement.isElement(v)) {
100
- return false;
101
- }
102
-
103
- if (v.type !== format) {
104
- return false;
105
- }
106
-
107
- if (format === "heading") {
108
- return attributes.level === v.attributes.level;
109
- }
110
-
111
- return true;
112
- });
113
- } else {
114
- return false;
115
- }
116
- };
117
-
118
- export const BlockButtonHeading = ({level}) => {
119
- return <BlockButton block="heading" attributes={{level: level}} icon={faHeading}><small>{level}</small></BlockButton>;
120
- };
121
-
122
- export const BlockButtonBlockquote = () => {
123
- return <BlockButton block="blockquote" icon={faQuoteLeft}/>;
124
- };
125
-
126
- export const BlockButtonUnorderedList = () => {
127
- return <BlockButton block="unordered-list" icon={faListUl}/>;
128
- };
129
-
130
- export const BlockButtonOrderedList = () => {
131
- return <BlockButton block="ordered-list" icon={faListOl}/>;
132
- };
133
-
134
- export const BlockButtonArrowList = () => {
135
- return <BlockButton block="arrow-list" icon={faArrowRight}/>;
1
+ import {useSlate} from "slate-react";
2
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
+ import React from "react";
4
+ import classNames from "classnames";
5
+ import {
6
+ Editor, Transforms, Element as SlateElement,
7
+ } from "slate";
8
+ import {
9
+ faListUl, faListOl, faHeading, faQuoteLeft, faArrowRight,
10
+ } from "@fortawesome/free-solid-svg-icons";
11
+
12
+ const LIST_TYPES = ['unordered-list', 'ordered-list', 'arrow-list'];
13
+
14
+ export const BlockButton = ({
15
+ block,
16
+ icon,
17
+ children,
18
+ attributes,
19
+ }) => {
20
+ const editor = useSlate();
21
+ const onClick = (event) => {
22
+ event.preventDefault();
23
+ toggleBlock(editor, block, attributes);
24
+ };
25
+
26
+ return (
27
+ <span
28
+ onMouseDown={onClick}
29
+ className={
30
+ classNames({
31
+ "toolbar-btn": true,
32
+ "active": isBlockActive(editor, block, attributes),
33
+ })
34
+ }>
35
+ {!!icon && <FontAwesomeIcon icon={icon} />}
36
+ {children}
37
+ </span>
38
+ );
39
+ };
40
+
41
+ export const toggleBlock = (editor, format, attributes) => {
42
+ const isActive = isBlockActive(editor, format, attributes);
43
+ const isList = LIST_TYPES.includes(format);
44
+
45
+ Transforms.unwrapNodes(editor, {
46
+ match: n => {
47
+ return LIST_TYPES.includes(!Editor.isEditor(n) && SlateElement.isElement(n) && n.type);
48
+ },
49
+ split: true,
50
+ });
51
+
52
+ let newFormat = isActive ? "paragraph" : format;
53
+
54
+ if (!isActive && isList) {
55
+ newFormat = "list-item";
56
+ }
57
+
58
+ Transforms.setNodes(editor,
59
+ {
60
+ type: newFormat,
61
+ attributes: attributes,
62
+ });
63
+
64
+ if (!isActive && isList) {
65
+ const block = {
66
+ type: format,
67
+ children: [],
68
+ };
69
+
70
+ Transforms.wrapNodes(editor, block);
71
+ }
72
+ };
73
+
74
+ export const isBlockActive = (editor, format, attributes) => {
75
+ const {selection} = editor;
76
+
77
+ if (selection) {
78
+ let selected = editor;
79
+
80
+ let reducedPath = selection.anchor.path.slice(0, -1);
81
+
82
+ for (let i = 0; i < reducedPath.length; i++) {
83
+ let path = reducedPath[i];
84
+
85
+ selected = selected.children[path];
86
+
87
+ if (LIST_TYPES.includes(selected.type)) {
88
+ break;
89
+ }
90
+ }
91
+
92
+ const selectedNodes = [selected];
93
+
94
+ return !!selectedNodes.find(v => {
95
+ if (Editor.isEditor(v)) {
96
+ return false;
97
+ }
98
+
99
+ if (!SlateElement.isElement(v)) {
100
+ return false;
101
+ }
102
+
103
+ if (v.type !== format) {
104
+ return false;
105
+ }
106
+
107
+ if (format === "heading") {
108
+ return attributes.level === v.attributes.level;
109
+ }
110
+
111
+ return true;
112
+ });
113
+ } else {
114
+ return false;
115
+ }
116
+ };
117
+
118
+ export const BlockButtonHeading = ({level}) => {
119
+ return <BlockButton block="heading" attributes={{level: level}} icon={faHeading}><small>{level}</small></BlockButton>;
120
+ };
121
+
122
+ export const BlockButtonBlockquote = () => {
123
+ return <BlockButton block="blockquote" icon={faQuoteLeft}/>;
124
+ };
125
+
126
+ export const BlockButtonUnorderedList = () => {
127
+ return <BlockButton block="unordered-list" icon={faListUl}/>;
128
+ };
129
+
130
+ export const BlockButtonOrderedList = () => {
131
+ return <BlockButton block="ordered-list" icon={faListOl}/>;
132
+ };
133
+
134
+ export const BlockButtonArrowList = () => {
135
+ return <BlockButton block="arrow-list" icon={faArrowRight}/>;
136
136
  };
@@ -1,45 +1,45 @@
1
- import {useSlate} from "slate-react";
2
- import {Transforms} from "slate";
3
- import React, {
4
- useContext, useState,
5
- } from "react";
6
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
7
- import {faPlus} from "@fortawesome/free-solid-svg-icons";
8
- import {Storybook} from "../Storybook";
9
- import {StorybookContext} from "../Context/StorybookContext";
10
-
11
- export const StorybookButton = () => {
12
- const editor = useSlate();
13
-
14
- const onClick = (e) => {
15
- e.preventDefault();
16
- Transforms.insertNodes(editor, [
17
- {
18
- children: [{text: ''}],
19
- block: "Blocks/Empty",
20
- attributes: {blockWidth: "site"},
21
- isEmpty: true,
22
- type: "storybook",
23
- },
24
- ]);
25
- };
26
-
27
- const onClickInline = (e) => {
28
- e.preventDefault();
29
- Transforms.insertNodes(editor, {
30
- children: [{text: ''}],
31
- block: "Blocks/Empty",
32
- attributes: {},
33
- isInline: true,
34
- isEmpty: true,
35
- type: "storybook",
36
- }, {select: true});
37
- };
38
-
39
- return <>
40
- <span className={"toolbar-btn"} onMouseDown={onClick}>
41
- <FontAwesomeIcon icon={faPlus} />
42
- <span> Element hinzufügen</span>
43
- </span>
44
- </>;
1
+ import {useSlate} from "slate-react";
2
+ import {Transforms} from "slate";
3
+ import React, {
4
+ useContext, useState,
5
+ } from "react";
6
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
7
+ import {faPlus} from "@fortawesome/free-solid-svg-icons";
8
+ import {Storybook} from "../Storybook";
9
+ import {StorybookContext} from "../Context/StorybookContext";
10
+
11
+ export const StorybookButton = () => {
12
+ const editor = useSlate();
13
+
14
+ const onClick = (e) => {
15
+ e.preventDefault();
16
+ Transforms.insertNodes(editor, [
17
+ {
18
+ children: [{text: ''}],
19
+ block: "Blocks/Empty",
20
+ attributes: {blockWidth: "site"},
21
+ isEmpty: true,
22
+ type: "storybook",
23
+ },
24
+ ]);
25
+ };
26
+
27
+ const onClickInline = (e) => {
28
+ e.preventDefault();
29
+ Transforms.insertNodes(editor, {
30
+ children: [{text: ''}],
31
+ block: "Blocks/Empty",
32
+ attributes: {},
33
+ isInline: true,
34
+ isEmpty: true,
35
+ type: "storybook",
36
+ }, {select: true});
37
+ };
38
+
39
+ return <>
40
+ <span className={"toolbar-btn"} onMouseDown={onClick}>
41
+ <FontAwesomeIcon icon={faPlus} />
42
+ <span> Element hinzufügen</span>
43
+ </span>
44
+ </>;
45
45
  };
@@ -1,72 +1,72 @@
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, Text, Transforms,
7
- } from "slate";
8
- import {
9
- faBold, faItalic, faUnderline, faStrikethrough, faSuperscript,
10
- } from "@fortawesome/free-solid-svg-icons";
11
-
12
- export const FormatButton = ({
13
- format,
14
- icon,
15
- children,
16
- }) => {
17
- const editor = useSlate();
18
- const onClick = (event) => {
19
- event.preventDefault();
20
- toggleFormat(editor, format);
21
- };
22
-
23
- return (
24
- <span
25
- onMouseDown={onClick}
26
- className={
27
- classNames({
28
- "toolbar-btn": true,
29
- "active": isFormatActive(editor, format),
30
- })
31
- }>
32
- {!!icon && <FontAwesomeIcon icon={icon} />}
33
- {children}
34
- </span>
35
- );
36
- };
37
-
38
- export const toggleFormat = (editor, format) => {
39
- const isActive = isFormatActive(editor, format);
40
- Editor.addMark(editor, format, !isActive);
41
- };
42
-
43
- export const isFormatActive = (editor, format) => {
44
- try {
45
- const marks = Editor.marks(editor);
46
- return marks ? marks[format] === true : false;
47
- } catch (e) {
48
- console.error(e);
49
- }
50
-
51
- return false;
52
- };
53
-
54
- export const FormatButtonBold = () => {
55
- return <FormatButton format="bold" icon={faBold}/>;
56
- };
57
-
58
- export const FormatButtonItalic = () => {
59
- return <FormatButton format="italic" icon={faItalic}/>;
60
- };
61
-
62
- export const FormatButtonUnderline = () => {
63
- return <FormatButton format="underlined" icon={faUnderline}/>;
64
- };
65
-
66
- export const FormatButtonStrikethrough = () => {
67
- return <FormatButton format="strikethrough" icon={faStrikethrough}/>;
68
- };
69
-
70
- export const FormatButtonSuperscriptUp = () => {
71
- return <FormatButton format="superscriptUp" icon={faSuperscript}/>;
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, Text, Transforms,
7
+ } from "slate";
8
+ import {
9
+ faBold, faItalic, faUnderline, faStrikethrough, faSuperscript,
10
+ } from "@fortawesome/free-solid-svg-icons";
11
+
12
+ export const FormatButton = ({
13
+ format,
14
+ icon,
15
+ children,
16
+ }) => {
17
+ const editor = useSlate();
18
+ const onClick = (event) => {
19
+ event.preventDefault();
20
+ toggleFormat(editor, format);
21
+ };
22
+
23
+ return (
24
+ <span
25
+ onMouseDown={onClick}
26
+ className={
27
+ classNames({
28
+ "toolbar-btn": true,
29
+ "active": isFormatActive(editor, format),
30
+ })
31
+ }>
32
+ {!!icon && <FontAwesomeIcon icon={icon} />}
33
+ {children}
34
+ </span>
35
+ );
36
+ };
37
+
38
+ export const toggleFormat = (editor, format) => {
39
+ const isActive = isFormatActive(editor, format);
40
+ Editor.addMark(editor, format, !isActive);
41
+ };
42
+
43
+ export const isFormatActive = (editor, format) => {
44
+ try {
45
+ const marks = Editor.marks(editor);
46
+ return marks ? marks[format] === true : false;
47
+ } catch (e) {
48
+ console.error(e);
49
+ }
50
+
51
+ return false;
52
+ };
53
+
54
+ export const FormatButtonBold = () => {
55
+ return <FormatButton format="bold" icon={faBold}/>;
56
+ };
57
+
58
+ export const FormatButtonItalic = () => {
59
+ return <FormatButton format="italic" icon={faItalic}/>;
60
+ };
61
+
62
+ export const FormatButtonUnderline = () => {
63
+ return <FormatButton format="underlined" icon={faUnderline}/>;
64
+ };
65
+
66
+ export const FormatButtonStrikethrough = () => {
67
+ return <FormatButton format="strikethrough" icon={faStrikethrough}/>;
68
+ };
69
+
70
+ export const FormatButtonSuperscriptUp = () => {
71
+ return <FormatButton format="superscriptUp" icon={faSuperscript}/>;
72
72
  };
@@ -1,29 +1,29 @@
1
- import {useSlate} from "slate-react";
2
- import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
- import React from "react";
4
- import {Transforms} from "slate";
5
-
6
- export const InsertButton = ({insert, icon, children}) => {
7
- const editor = useSlate();
8
- const onClick = (event) => {
9
- event.preventDefault();
10
- Transforms.insertNodes(editor, [insert]);
11
- };
12
-
13
- return (
14
- <span onMouseDown={onClick} className="toolbar-btn">
15
- {!!icon && <FontAwesomeIcon icon={icon} />}
16
- {children}
17
- </span>
18
- );
19
- };
20
-
21
-
22
- export const InsertDividerButton = () => {
23
- return <InsertButton insert={{
24
- "type": "divider",
25
- "children": [{"text": ""}],
26
- }}>
27
- <span>Trennlinie einfügen</span>
28
- </InsertButton>;
1
+ import {useSlate} from "slate-react";
2
+ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
3
+ import React from "react";
4
+ import {Transforms} from "slate";
5
+
6
+ export const InsertButton = ({insert, icon, children}) => {
7
+ const editor = useSlate();
8
+ const onClick = (event) => {
9
+ event.preventDefault();
10
+ Transforms.insertNodes(editor, [insert]);
11
+ };
12
+
13
+ return (
14
+ <span onMouseDown={onClick} className="toolbar-btn">
15
+ {!!icon && <FontAwesomeIcon icon={icon} />}
16
+ {children}
17
+ </span>
18
+ );
19
+ };
20
+
21
+
22
+ export const InsertDividerButton = () => {
23
+ return <InsertButton insert={{
24
+ "type": "divider",
25
+ "children": [{"text": ""}],
26
+ }}>
27
+ <span>Trennlinie einfügen</span>
28
+ </InsertButton>;
29
29
  };