@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
package/src/Nodes/Leaf.js CHANGED
@@ -1,55 +1,55 @@
1
- import React from "react";
2
- import {
3
- Bold, Italic, Text, Underlined, Strikethrough, Small, SuperscriptUp,
4
- } from "./Text";
5
-
6
- export const Leaf = ({
7
- attributes,
8
- children,
9
- leaf,
10
- isRenderer,
11
- typeProps,
12
- ...props
13
- }) => {
14
- if (leaf.bold) {
15
- children = <Bold typeProps={typeProps} attributes={attributes}><Text
16
- attributes={attributes}
17
- typeProps={typeProps}
18
- isRenderer={isRenderer}>{children}</Text></Bold>;
19
- }
20
-
21
- if (leaf.italic) {
22
- children =
23
- <Italic typeProps={typeProps} attributes={attributes}><Text attributes={attributes} typeProps={typeProps} isRenderer={isRenderer}>{children}</Text></Italic>;
24
- }
25
-
26
- if (leaf.underlined) {
27
- children = <Underlined typeProps={typeProps} attributes={attributes}><Text
28
- attributes={attributes}
29
- typeProps={typeProps}
30
- isRenderer={isRenderer}>{children}</Text></Underlined>;
31
- }
32
-
33
- if (leaf.strikethrough) {
34
- children = <Strikethrough typeProps={typeProps} attributes={attributes}><Text
35
- attributes={attributes}
36
- typeProps={typeProps}
37
- isRenderer={isRenderer}>{children}</Text></Strikethrough>;
38
- }
39
-
40
- if (leaf.small) {
41
- children = <Small typeProps={typeProps} attributes={attributes}><Text
42
- attributes={attributes}
43
- typeProps={typeProps}
44
- isRenderer={isRenderer}>{children}</Text></Small>;
45
- }
46
-
47
- if (leaf.superscriptUp) {
48
- children = <SuperscriptUp typeProps={typeProps} attributes={attributes}><Text
49
- attributes={attributes}
50
- typeProps={typeProps}
51
- isRenderer={isRenderer}>{children}</Text></SuperscriptUp>;
52
- }
53
-
54
- return <Text attributes={attributes} typeProps={typeProps} isRenderer={isRenderer}>{children}</Text>;
1
+ import React from "react";
2
+ import {
3
+ Bold, Italic, Text, Underlined, Strikethrough, Small, SuperscriptUp,
4
+ } from "./Text";
5
+
6
+ export const Leaf = ({
7
+ attributes,
8
+ children,
9
+ leaf,
10
+ isRenderer,
11
+ typeProps,
12
+ ...props
13
+ }) => {
14
+ if (leaf.bold) {
15
+ children = <Bold typeProps={typeProps} attributes={attributes}><Text
16
+ attributes={attributes}
17
+ typeProps={typeProps}
18
+ isRenderer={isRenderer}>{children}</Text></Bold>;
19
+ }
20
+
21
+ if (leaf.italic) {
22
+ children =
23
+ <Italic typeProps={typeProps} attributes={attributes}><Text attributes={attributes} typeProps={typeProps} isRenderer={isRenderer}>{children}</Text></Italic>;
24
+ }
25
+
26
+ if (leaf.underlined) {
27
+ children = <Underlined typeProps={typeProps} attributes={attributes}><Text
28
+ attributes={attributes}
29
+ typeProps={typeProps}
30
+ isRenderer={isRenderer}>{children}</Text></Underlined>;
31
+ }
32
+
33
+ if (leaf.strikethrough) {
34
+ children = <Strikethrough typeProps={typeProps} attributes={attributes}><Text
35
+ attributes={attributes}
36
+ typeProps={typeProps}
37
+ isRenderer={isRenderer}>{children}</Text></Strikethrough>;
38
+ }
39
+
40
+ if (leaf.small) {
41
+ children = <Small typeProps={typeProps} attributes={attributes}><Text
42
+ attributes={attributes}
43
+ typeProps={typeProps}
44
+ isRenderer={isRenderer}>{children}</Text></Small>;
45
+ }
46
+
47
+ if (leaf.superscriptUp) {
48
+ children = <SuperscriptUp typeProps={typeProps} attributes={attributes}><Text
49
+ attributes={attributes}
50
+ typeProps={typeProps}
51
+ isRenderer={isRenderer}>{children}</Text></SuperscriptUp>;
52
+ }
53
+
54
+ return <Text attributes={attributes} typeProps={typeProps} isRenderer={isRenderer}>{children}</Text>;
55
55
  };
package/src/Nodes/Text.js CHANGED
@@ -1,98 +1,98 @@
1
- import React, {Fragment} from "react";
2
-
3
- const EmptyWrapper = ({children}) => <>{children}</>;
4
-
5
- export const Text = ({
6
- isRenderer,
7
- attributes,
8
- children,
9
- typeProps,
10
- }) => {
11
- if (isRenderer) {
12
- if (!children) {
13
- return null;
14
- }
15
-
16
- if (typeof children === "string") {
17
- const breakParts = children.split("\n");
18
-
19
- return <Fragment>
20
- {breakParts.length > 1 ? breakParts.map((v, i) => {
21
- return <Fragment key={i}>
22
- {renderTextLine(v, typeProps)}{i !== breakParts.length - 1 ? <br/> : null}
23
- </Fragment>;
24
- }) : renderTextLine(children, typeProps)}
25
- </Fragment>;
26
- } else {
27
- return <Fragment>
28
- {children}
29
- </Fragment>;
30
- }
31
- }
32
-
33
- return <span {...attributes}>{children}</span>;
34
- };
35
-
36
- function renderTextLine(text, typeProps) {
37
- if (!typeProps || !text || typeof text !== "string") {
38
- return text;
39
- }
40
-
41
- if (typeProps.line_transform) {
42
- for (let startsWithStr in typeProps.line_transform) {
43
- if (text.startsWith(startsWithStr)) {
44
- const WrapperComponent = typeProps.line_transform[startsWithStr];
45
- return <WrapperComponent>{text.substr(startsWithStr.length).trim()}</WrapperComponent>;
46
- }
47
- }
48
- }
49
-
50
- return text;
51
- }
52
-
53
- export const Bold = ({
54
- attributes,
55
- children,
56
- }) => {
57
- return <strong {...attributes}>{children}</strong>;
58
- };
59
-
60
- export const Italic = ({
61
- attributes,
62
- children,
63
- }) => {
64
- return <i {...attributes}>{children}</i>;
65
- };
66
-
67
- export const Underlined = ({
68
- attributes,
69
- children,
70
- }) => {
71
- return <u {...attributes}>{children}</u>;
72
- };
73
-
74
- export const Strikethrough = ({
75
- attributes,
76
- children,
77
- }) => {
78
- return <del {...attributes}>{children}</del>;
79
- };
80
-
81
- export const Small = ({
82
- attributes,
83
- children,
84
- }) => {
85
- return <small {...attributes}>{children}</small>;
86
- };
87
-
88
- export const SuperscriptUp = ({
89
- attributes,
90
- children,
91
- }) => {
92
- return <span
93
- style={{
94
- fontSize: "60%",
95
- verticalAlign: "top",
96
- }}
97
- {...attributes}>{children}</span>;
1
+ import React, {Fragment} from "react";
2
+
3
+ const EmptyWrapper = ({children}) => <>{children}</>;
4
+
5
+ export const Text = ({
6
+ isRenderer,
7
+ attributes,
8
+ children,
9
+ typeProps,
10
+ }) => {
11
+ if (isRenderer) {
12
+ if (!children) {
13
+ return null;
14
+ }
15
+
16
+ if (typeof children === "string") {
17
+ const breakParts = children.split("\n");
18
+
19
+ return <Fragment>
20
+ {breakParts.length > 1 ? breakParts.map((v, i) => {
21
+ return <Fragment key={i}>
22
+ {renderTextLine(v, typeProps)}{i !== breakParts.length - 1 ? <br/> : null}
23
+ </Fragment>;
24
+ }) : renderTextLine(children, typeProps)}
25
+ </Fragment>;
26
+ } else {
27
+ return <Fragment>
28
+ {children}
29
+ </Fragment>;
30
+ }
31
+ }
32
+
33
+ return <span {...attributes}>{children}</span>;
34
+ };
35
+
36
+ function renderTextLine(text, typeProps) {
37
+ if (!typeProps || !text || typeof text !== "string") {
38
+ return text;
39
+ }
40
+
41
+ if (typeProps.line_transform) {
42
+ for (let startsWithStr in typeProps.line_transform) {
43
+ if (text.startsWith(startsWithStr)) {
44
+ const WrapperComponent = typeProps.line_transform[startsWithStr];
45
+ return <WrapperComponent>{text.substr(startsWithStr.length).trim()}</WrapperComponent>;
46
+ }
47
+ }
48
+ }
49
+
50
+ return text;
51
+ }
52
+
53
+ export const Bold = ({
54
+ attributes,
55
+ children,
56
+ }) => {
57
+ return <strong {...attributes}>{children}</strong>;
58
+ };
59
+
60
+ export const Italic = ({
61
+ attributes,
62
+ children,
63
+ }) => {
64
+ return <i {...attributes}>{children}</i>;
65
+ };
66
+
67
+ export const Underlined = ({
68
+ attributes,
69
+ children,
70
+ }) => {
71
+ return <u {...attributes}>{children}</u>;
72
+ };
73
+
74
+ export const Strikethrough = ({
75
+ attributes,
76
+ children,
77
+ }) => {
78
+ return <del {...attributes}>{children}</del>;
79
+ };
80
+
81
+ export const Small = ({
82
+ attributes,
83
+ children,
84
+ }) => {
85
+ return <small {...attributes}>{children}</small>;
86
+ };
87
+
88
+ export const SuperscriptUp = ({
89
+ attributes,
90
+ children,
91
+ }) => {
92
+ return <span
93
+ style={{
94
+ fontSize: "60%",
95
+ verticalAlign: "top",
96
+ }}
97
+ {...attributes}>{children}</span>;
98
98
  };
package/src/ObjectId.js CHANGED
@@ -1,4 +1,4 @@
1
- export const ObjectId = (
2
- m = Math, d = Date, h = 16, s = s => m.floor(s).toString(h),
3
- ) =>
1
+ export const ObjectId = (
2
+ m = Math, d = Date, h = 16, s = s => m.floor(s).toString(h),
3
+ ) =>
4
4
  s(d.now() / 1000) + ' '.repeat(h).replace(/./g, () => s(m.random() * h));
package/src/Renderer.js CHANGED
@@ -1,74 +1,74 @@
1
- import React, {memo} from 'react';
2
- import {StorybookContext} from "./Context/StorybookContext";
3
- import {Serializer} from "./Serializer";
4
-
5
- const Renderer = memo(function RendererInner({
6
- value,
7
- modifyElementFunc,
8
- specialClassMap,
9
- elementPropsMap,
10
- transformAttributes,
11
- storybookComponentLoader,
12
- storybookComponentDataLoader,
13
- filterContent,
14
- fixedPositions,
15
- fixedPositionTypes,
16
- adDefinitionDesktop,
17
- adDefinitionMobile,
18
- defaultComponentReplacement,
19
- onStorybookElementClick,
20
- }) {
21
- return <Serializer
22
- elementPropsMap={elementPropsMap}
23
- specialClassMap={specialClassMap}
24
- defaultComponentReplacement={defaultComponentReplacement}
25
- transformAttributes={transformAttributes}
26
- value={value}
27
- filterContent={filterContent}
28
- modifyElementFunc={modifyElementFunc}
29
- storybookComponentLoader={storybookComponentLoader}
30
- storybookComponentDataLoader={storybookComponentDataLoader}
31
- fixedPositions={fixedPositions}
32
- fixedPositionTypes={fixedPositionTypes}
33
- adDefinitionDesktop={adDefinitionDesktop}
34
- adDefinitionMobile={adDefinitionMobile}
35
- isRenderer={true}
36
- onStorybookElementClick={onStorybookElementClick}/>
37
- }, (prevProps, nextProps) => {
38
- let allKeys = Array.from(new Set([...Object.keys(nextProps), ...Object.keys(prevProps)]));
39
-
40
- for (let i = 0; i < allKeys.length; i++) {
41
- const key = allKeys[i];
42
- const oldValue = prevProps[key];
43
- const newValue = nextProps[key];
44
-
45
- if (oldValue === newValue) {
46
- continue;
47
- }
48
-
49
- if (!oldValue && !newValue) {
50
- console.warn(`Renderer :: ${key} :: Both empty but type changed?`, {oldValue, newValue});
51
- continue;
52
- }
53
-
54
- if (typeof oldValue === "object" && typeof newValue === "object" && oldValue && newValue) {
55
- try {
56
- if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
57
- continue;
58
- }
59
- } catch (e) {
60
- return false;
61
- }
62
- }
63
-
64
- return false;
65
- }
66
-
67
- return true;
68
- })
69
-
70
- const RendererMemo = memo(Renderer);
71
-
72
- export default RendererMemo;
73
-
1
+ import React, {memo} from 'react';
2
+ import {StorybookContext} from "./Context/StorybookContext";
3
+ import {Serializer} from "./Serializer";
4
+
5
+ const Renderer = memo(function RendererInner({
6
+ value,
7
+ modifyElementFunc,
8
+ specialClassMap,
9
+ elementPropsMap,
10
+ transformAttributes,
11
+ storybookComponentLoader,
12
+ storybookComponentDataLoader,
13
+ filterContent,
14
+ fixedPositions,
15
+ fixedPositionTypes,
16
+ adDefinitionDesktop,
17
+ adDefinitionMobile,
18
+ defaultComponentReplacement,
19
+ onStorybookElementClick,
20
+ }) {
21
+ return <Serializer
22
+ elementPropsMap={elementPropsMap}
23
+ specialClassMap={specialClassMap}
24
+ defaultComponentReplacement={defaultComponentReplacement}
25
+ transformAttributes={transformAttributes}
26
+ value={value}
27
+ filterContent={filterContent}
28
+ modifyElementFunc={modifyElementFunc}
29
+ storybookComponentLoader={storybookComponentLoader}
30
+ storybookComponentDataLoader={storybookComponentDataLoader}
31
+ fixedPositions={fixedPositions}
32
+ fixedPositionTypes={fixedPositionTypes}
33
+ adDefinitionDesktop={adDefinitionDesktop}
34
+ adDefinitionMobile={adDefinitionMobile}
35
+ isRenderer={true}
36
+ onStorybookElementClick={onStorybookElementClick}/>
37
+ }, (prevProps, nextProps) => {
38
+ let allKeys = Array.from(new Set([...Object.keys(nextProps), ...Object.keys(prevProps)]));
39
+
40
+ for (let i = 0; i < allKeys.length; i++) {
41
+ const key = allKeys[i];
42
+ const oldValue = prevProps[key];
43
+ const newValue = nextProps[key];
44
+
45
+ if (oldValue === newValue) {
46
+ continue;
47
+ }
48
+
49
+ if (!oldValue && !newValue) {
50
+ console.warn(`Renderer :: ${key} :: Both empty but type changed?`, {oldValue, newValue});
51
+ continue;
52
+ }
53
+
54
+ if (typeof oldValue === "object" && typeof newValue === "object" && oldValue && newValue) {
55
+ try {
56
+ if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
57
+ continue;
58
+ }
59
+ } catch (e) {
60
+ return false;
61
+ }
62
+ }
63
+
64
+ return false;
65
+ }
66
+
67
+ return true;
68
+ })
69
+
70
+ const RendererMemo = memo(Renderer);
71
+
72
+ export default RendererMemo;
73
+
74
74
  export {StorybookContext};
@@ -1,43 +1,43 @@
1
- import escapeHtml from 'escape-html';
2
- import {Text} from 'slate';
3
-
4
- export const HtmlSerializer = (slateValue) => {
5
- if (!Array.isArray(slateValue)) {
6
- return "";
7
- }
8
-
9
- const html = slateValue.map(serializeNode).join('');
10
-
11
- return html;
12
- };
13
-
14
- export const serializeNode = (node) => {
15
- if (Text.isText(node)) {
16
- return escapeHtml(node.text);
17
- }
18
-
19
- const children = (node.children || []).map(n => serializeNode(n)).join('');
20
-
21
- switch (node.type) {
22
- case 'blockquote':
23
- return `<blockquote>${children}</blockquote>`;
24
- case 'heading':
25
- return `<h3>${children}</h3>`;
26
- case 'paragraph':
27
- return `<p>${children}</p>`;
28
- case 'unordered-list':
29
- return `<ul>${children}</ul>`;
30
- case 'ordered-list':
31
- return `<ol>${children}</ol>`;
32
- case 'arrow-list':
33
- return `<ul>${children}</ul>`;
34
- case 'list-item':
35
- return `<li>${children}</li>`;
36
- case 'link':
37
- return `<a href="${escapeHtml(node?.attributes?.href)}" target="${node?.attributes?.target || ''}">${children}</a>`;
38
- case 'storybook':
39
- return ``;
40
- default:
41
- return children;
42
- }
1
+ import escapeHtml from 'escape-html';
2
+ import {Text} from 'slate';
3
+
4
+ export const HtmlSerializer = (slateValue) => {
5
+ if (!Array.isArray(slateValue)) {
6
+ return "";
7
+ }
8
+
9
+ const html = slateValue.map(serializeNode).join('');
10
+
11
+ return html;
12
+ };
13
+
14
+ export const serializeNode = (node) => {
15
+ if (Text.isText(node)) {
16
+ return escapeHtml(node.text);
17
+ }
18
+
19
+ const children = (node.children || []).map(n => serializeNode(n)).join('');
20
+
21
+ switch (node.type) {
22
+ case 'blockquote':
23
+ return `<blockquote>${children}</blockquote>`;
24
+ case 'heading':
25
+ return `<h3>${children}</h3>`;
26
+ case 'paragraph':
27
+ return `<p>${children}</p>`;
28
+ case 'unordered-list':
29
+ return `<ul>${children}</ul>`;
30
+ case 'ordered-list':
31
+ return `<ol>${children}</ol>`;
32
+ case 'arrow-list':
33
+ return `<ul>${children}</ul>`;
34
+ case 'list-item':
35
+ return `<li>${children}</li>`;
36
+ case 'link':
37
+ return `<a href="${escapeHtml(node?.attributes?.href)}" target="${node?.attributes?.target || ''}">${children}</a>`;
38
+ case 'storybook':
39
+ return ``;
40
+ default:
41
+ return children;
42
+ }
43
43
  };