@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,182 +1,182 @@
1
- import {
2
- useEffect, useState,
3
- } from "react";
4
- import {IconButton} from "../SidebarEditor";
5
- import {swapArrayElements} from "../helper/array";
6
-
7
- // Hallo :)
8
- export const AssetList = ({
9
- assets,
10
- onChange,
11
- sdk,
12
- cloudinary = false,
13
- onAddClick,
14
- }) => {
15
- const renderAssets = assets.filter(Boolean).map((asset, index) => (
16
- <>
17
- <Asset
18
- key={asset.sys?.id}
19
- asset={asset}
20
- index={index}
21
- sdk={sdk}
22
- cloudinary={cloudinary}
23
- assetsLength={assets.length}
24
- onMoveClick={(direction) => handleMoveClick(direction, index)}
25
- onDeleteClick={() => handleDeleteClick(index)}
26
- onChange={handleChange}
27
- />
28
- <hr className="my-2" style={{borderColor: "#cfd9e0"}}/>
29
- {onAddClick && index === assets.length - 1 && <button onClick={onAddClick} className="button button--secondary">Hinzufügen</button>}
30
- </>
31
- ));
32
-
33
- const handleMoveClick = (direction, index) => {
34
- let newIndex = direction === "up" ? index - 1 : index + 1;
35
-
36
- if (direction === "up" && index === 0) {
37
- return;
38
- } else if (direction === "down" && index === assets.length - 1) {
39
- return;
40
- }
41
-
42
- onChange(swapArrayElements(assets, index, newIndex));
43
- };
44
-
45
- const handleDeleteClick = (index) => {
46
- let newAssets = assets;
47
-
48
- newAssets.splice(index, 1);
49
-
50
- onChange(newAssets);
51
- };
52
-
53
- const handleChange = (newAsset) => {
54
- let newAssets = assets.map(asset => {
55
- if (asset?.sys?.id === newAsset?.sys?.id) {
56
- return newAsset;
57
- }
58
-
59
- return asset;
60
- });
61
-
62
- onChange(newAssets);
63
- };
64
-
65
- return (
66
- <div>{renderAssets}</div>
67
- );
68
- };
69
-
70
- export const Asset = ({
71
- asset,
72
- index,
73
- assetsLength,
74
- onDeleteClick,
75
- onMoveClick,
76
- onChange,
77
- sdk,
78
- cloudinary = false,
79
- }) => {
80
- const [mediaUrl, setMediaUrl] = useState(null);
81
-
82
- let id = asset?.sys?.id;
83
- let title = asset?.fields?.title?.["en-US"] || asset?.fields?.title?.["de"] || asset?.fields?.title?.toString() || asset?.title?.toString();
84
- let mediaAssetId = asset?.fields?.media?.["en-US"]?.sys?.id || asset?.fields?.media?.["de"]?.sys?.id || asset?.fields?.media?.sys?.id;
85
-
86
- if (cloudinary) {
87
- title = asset.public_id || asset.title;
88
- }
89
-
90
- useEffect(() => {
91
- if (cloudinary) {
92
- setMediaUrl(asset.url || asset?.media?.url);
93
-
94
- return;
95
- }
96
-
97
- if (!mediaAssetId) {
98
- if (asset?.media?.url) {
99
- let params = new URLSearchParams({
100
- w: "512",
101
- q: "80",
102
- });
103
-
104
- setMediaUrl(`${asset?.media?.url}?${params}`);
105
- }
106
-
107
- return;
108
- }
109
-
110
- sdk.space.getAsset(mediaAssetId)
111
- .then(a => {
112
- let url = a?.fields?.file?.["en-US"]?.url || a?.fields?.file?.["de"]?.url;
113
-
114
- if (url) {
115
- let params = new URLSearchParams({
116
- w: "512",
117
- q: "80",
118
- });
119
-
120
- setMediaUrl(`${url}?${params}`);
121
- }
122
- });
123
- }, [mediaAssetId, sdk, asset, cloudinary]);
124
-
125
- if (!asset) {
126
- return null;
127
- }
128
-
129
- let assetType = "image";
130
-
131
- if (mediaUrl?.endsWith(".mp3")) {
132
- assetType = "audio";
133
- }
134
-
135
- if (mediaUrl?.endsWith(".mp4") || mediaUrl?.endsWith(".mov")) {
136
- assetType = "video";
137
- }
138
-
139
- const renderMedia = () => {
140
- switch (assetType) {
141
- case "audio":
142
- return <audio src={mediaUrl} className="mt-2 w-full" controls />;
143
- case "video":
144
- return <video src={mediaUrl} className="mt-2 w-full rounded-md" controls />;
145
- case "image":
146
- default:
147
- return <img src={mediaUrl} width="100%" className="mt-2 rounded-md" />;
148
- }
149
- };
150
-
151
- return (
152
- <div className="flex flex-col">
153
- <div className="flex">
154
- <div className="grow">
155
- <b className="mt-[3px] block" style={{wordBreak: "break-word"}}>{title}</b>
156
- </div>
157
- <div className="ml-2 shrink-0">
158
- {!!onMoveClick && (
159
- <div className="icon-button-group mr-1">
160
- <IconButton size="small" onClick={() => onMoveClick("up")} disabled={index === 0}>↑</IconButton>
161
- <IconButton size="small" onClick={() => onMoveClick("down")} disabled={index === assetsLength - 1}>↓</IconButton>
162
- </div>
163
- )}
164
- {!cloudinary && (
165
- <IconButton
166
- size="small"
167
- className="mr-1"
168
- onClick={() => {
169
- sdk.navigator.openEntry(id, {slideIn: {waitForClose: true}}).then(({entity}) => {
170
- if (onChange) {
171
- onChange(entity);
172
- }
173
- });
174
- }}>✎</IconButton>
175
- )}
176
- <IconButton size="small" onClick={onDeleteClick}>⨯</IconButton>
177
- </div>
178
- </div>
179
- {!!mediaUrl && renderMedia()}
180
- </div>
181
- );
1
+ import {
2
+ useEffect, useState,
3
+ } from "react";
4
+ import {IconButton} from "../SidebarEditor";
5
+ import {swapArrayElements} from "../helper/array";
6
+
7
+ // Hallo :)
8
+ export const AssetList = ({
9
+ assets,
10
+ onChange,
11
+ sdk,
12
+ cloudinary = false,
13
+ onAddClick,
14
+ }) => {
15
+ const renderAssets = assets.filter(Boolean).map((asset, index) => (
16
+ <>
17
+ <Asset
18
+ key={asset.sys?.id}
19
+ asset={asset}
20
+ index={index}
21
+ sdk={sdk}
22
+ cloudinary={cloudinary}
23
+ assetsLength={assets.length}
24
+ onMoveClick={(direction) => handleMoveClick(direction, index)}
25
+ onDeleteClick={() => handleDeleteClick(index)}
26
+ onChange={handleChange}
27
+ />
28
+ <hr className="my-2" style={{borderColor: "#cfd9e0"}}/>
29
+ {onAddClick && index === assets.length - 1 && <button onClick={onAddClick} className="button button--secondary">Hinzufügen</button>}
30
+ </>
31
+ ));
32
+
33
+ const handleMoveClick = (direction, index) => {
34
+ let newIndex = direction === "up" ? index - 1 : index + 1;
35
+
36
+ if (direction === "up" && index === 0) {
37
+ return;
38
+ } else if (direction === "down" && index === assets.length - 1) {
39
+ return;
40
+ }
41
+
42
+ onChange(swapArrayElements(assets, index, newIndex));
43
+ };
44
+
45
+ const handleDeleteClick = (index) => {
46
+ let newAssets = assets;
47
+
48
+ newAssets.splice(index, 1);
49
+
50
+ onChange(newAssets);
51
+ };
52
+
53
+ const handleChange = (newAsset) => {
54
+ let newAssets = assets.map(asset => {
55
+ if (asset?.sys?.id === newAsset?.sys?.id) {
56
+ return newAsset;
57
+ }
58
+
59
+ return asset;
60
+ });
61
+
62
+ onChange(newAssets);
63
+ };
64
+
65
+ return (
66
+ <div>{renderAssets}</div>
67
+ );
68
+ };
69
+
70
+ export const Asset = ({
71
+ asset,
72
+ index,
73
+ assetsLength,
74
+ onDeleteClick,
75
+ onMoveClick,
76
+ onChange,
77
+ sdk,
78
+ cloudinary = false,
79
+ }) => {
80
+ const [mediaUrl, setMediaUrl] = useState(null);
81
+
82
+ let id = asset?.sys?.id;
83
+ let title = asset?.fields?.title?.["en-US"] || asset?.fields?.title?.["de"] || asset?.fields?.title?.toString() || asset?.title?.toString();
84
+ let mediaAssetId = asset?.fields?.media?.["en-US"]?.sys?.id || asset?.fields?.media?.["de"]?.sys?.id || asset?.fields?.media?.sys?.id;
85
+
86
+ if (cloudinary) {
87
+ title = asset.public_id || asset.title;
88
+ }
89
+
90
+ useEffect(() => {
91
+ if (cloudinary) {
92
+ setMediaUrl(asset.url || asset?.media?.url);
93
+
94
+ return;
95
+ }
96
+
97
+ if (!mediaAssetId) {
98
+ if (asset?.media?.url) {
99
+ let params = new URLSearchParams({
100
+ w: "512",
101
+ q: "80",
102
+ });
103
+
104
+ setMediaUrl(`${asset?.media?.url}?${params}`);
105
+ }
106
+
107
+ return;
108
+ }
109
+
110
+ sdk.space.getAsset(mediaAssetId)
111
+ .then(a => {
112
+ let url = a?.fields?.file?.["en-US"]?.url || a?.fields?.file?.["de"]?.url;
113
+
114
+ if (url) {
115
+ let params = new URLSearchParams({
116
+ w: "512",
117
+ q: "80",
118
+ });
119
+
120
+ setMediaUrl(`${url}?${params}`);
121
+ }
122
+ });
123
+ }, [mediaAssetId, sdk, asset, cloudinary]);
124
+
125
+ if (!asset) {
126
+ return null;
127
+ }
128
+
129
+ let assetType = "image";
130
+
131
+ if (mediaUrl?.endsWith(".mp3")) {
132
+ assetType = "audio";
133
+ }
134
+
135
+ if (mediaUrl?.endsWith(".mp4") || mediaUrl?.endsWith(".mov")) {
136
+ assetType = "video";
137
+ }
138
+
139
+ const renderMedia = () => {
140
+ switch (assetType) {
141
+ case "audio":
142
+ return <audio src={mediaUrl} className="mt-2 w-full" controls />;
143
+ case "video":
144
+ return <video src={mediaUrl} className="mt-2 w-full rounded-md" controls />;
145
+ case "image":
146
+ default:
147
+ return <img src={mediaUrl} width="100%" className="mt-2 rounded-md" />;
148
+ }
149
+ };
150
+
151
+ return (
152
+ <div className="flex flex-col">
153
+ <div className="flex">
154
+ <div className="grow">
155
+ <b className="mt-[3px] block" style={{wordBreak: "break-word"}}>{title}</b>
156
+ </div>
157
+ <div className="ml-2 shrink-0">
158
+ {!!onMoveClick && (
159
+ <div className="icon-button-group mr-1">
160
+ <IconButton size="small" onClick={() => onMoveClick("up")} disabled={index === 0}>↑</IconButton>
161
+ <IconButton size="small" onClick={() => onMoveClick("down")} disabled={index === assetsLength - 1}>↓</IconButton>
162
+ </div>
163
+ )}
164
+ {!cloudinary && (
165
+ <IconButton
166
+ size="small"
167
+ className="mr-1"
168
+ onClick={() => {
169
+ sdk.navigator.openEntry(id, {slideIn: {waitForClose: true}}).then(({entity}) => {
170
+ if (onChange) {
171
+ onChange(entity);
172
+ }
173
+ });
174
+ }}>✎</IconButton>
175
+ )}
176
+ <IconButton size="small" onClick={onDeleteClick}>⨯</IconButton>
177
+ </div>
178
+ </div>
179
+ {!!mediaUrl && renderMedia()}
180
+ </div>
181
+ );
182
182
  };
@@ -1,90 +1,90 @@
1
- import {Asset} from "@contentful/forma-36-react-components";
2
- import {AssetList} from "../AssetList";
3
-
4
- export const CloudinaryContentSelect = ({
5
- value,
6
- onChange,
7
- multiple,
8
- sdk,
9
- }) => {
10
- if (multiple) {
11
- return (
12
- <>
13
- {value && value.length > 0 && (
14
- <details className="mb-2">
15
- <summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
16
- <div className="mt-4">
17
- <AssetList
18
- cloudinary
19
- assets={value}
20
- sdk={sdk}
21
- onChange={onChange}
22
- onAddClick={() => {
23
- sdk.dialogs.openCurrentApp({
24
- width: "fullWidth",
25
- title: "Select Images",
26
- shouldCloseOnOverlayClick: true,
27
- shouldCloseOnEscapePress: true,
28
- parameters: {
29
- type: "cloudinary",
30
- multiple: true,
31
- portal: sdk?.entry?.fields?.portal?.getValue(),
32
- },
33
- }).then((data) => {
34
- onChange([...value, ...(data?.assets || [])]);
35
- });
36
- }}/>
37
- </div>
38
- </details>
39
- )}
40
- <button
41
- className="button"
42
- onClick={() => {
43
- sdk.dialogs.openCurrentApp({
44
- width: "fullWidth",
45
- title: "Select Images",
46
- shouldCloseOnOverlayClick: true,
47
- shouldCloseOnEscapePress: true,
48
- parameters: {
49
- type: "cloudinary",
50
- multiple: true,
51
- portal: sdk?.entry?.fields?.portal?.getValue(),
52
- },
53
- }).then((data) => {
54
- onChange(data?.assets);
55
- });
56
- }}
57
- >Auswählen
58
- </button>
59
- </>
60
- );
61
- }
62
-
63
- return (
64
- <>
65
- {!!value && <div className="mb-2"><Asset
66
- cloudinary
67
- sdk={sdk}
68
- asset={value}
69
- onDeleteClick={() => onChange(null)}/></div>}
70
- <button
71
- className="button"
72
- onClick={() => {
73
- sdk.dialogs.openCurrentApp({
74
- width: "fullWidth",
75
- title: "Select Image",
76
- shouldCloseOnOverlayClick: true,
77
- shouldCloseOnEscapePress: true,
78
- parameters: {
79
- type: "cloudinary",
80
- portal: sdk?.entry?.fields?.portal?.getValue(),
81
- },
82
- }).then((data) => {
83
- onChange(data?.assets?.[0]);
84
- });
85
- }}
86
- >Auswählen
87
- </button>
88
- </>
89
- );
1
+ import {Asset} from "@contentful/forma-36-react-components";
2
+ import {AssetList} from "../AssetList";
3
+
4
+ export const CloudinaryContentSelect = ({
5
+ value,
6
+ onChange,
7
+ multiple,
8
+ sdk,
9
+ }) => {
10
+ if (multiple) {
11
+ return (
12
+ <>
13
+ {value && value.length > 0 && (
14
+ <details className="mb-2">
15
+ <summary>{value.length || 0} {value.length === 1 ? "Element" : "Elemente"}</summary>
16
+ <div className="mt-4">
17
+ <AssetList
18
+ cloudinary
19
+ assets={value}
20
+ sdk={sdk}
21
+ onChange={onChange}
22
+ onAddClick={() => {
23
+ sdk.dialogs.openCurrentApp({
24
+ width: "fullWidth",
25
+ title: "Select Images",
26
+ shouldCloseOnOverlayClick: true,
27
+ shouldCloseOnEscapePress: true,
28
+ parameters: {
29
+ type: "cloudinary",
30
+ multiple: true,
31
+ portal: sdk?.entry?.fields?.portal?.getValue(),
32
+ },
33
+ }).then((data) => {
34
+ onChange([...value, ...(data?.assets || [])]);
35
+ });
36
+ }}/>
37
+ </div>
38
+ </details>
39
+ )}
40
+ <button
41
+ className="button"
42
+ onClick={() => {
43
+ sdk.dialogs.openCurrentApp({
44
+ width: "fullWidth",
45
+ title: "Select Images",
46
+ shouldCloseOnOverlayClick: true,
47
+ shouldCloseOnEscapePress: true,
48
+ parameters: {
49
+ type: "cloudinary",
50
+ multiple: true,
51
+ portal: sdk?.entry?.fields?.portal?.getValue(),
52
+ },
53
+ }).then((data) => {
54
+ onChange(data?.assets);
55
+ });
56
+ }}
57
+ >Auswählen
58
+ </button>
59
+ </>
60
+ );
61
+ }
62
+
63
+ return (
64
+ <>
65
+ {!!value && <div className="mb-2"><Asset
66
+ cloudinary
67
+ sdk={sdk}
68
+ asset={value}
69
+ onDeleteClick={() => onChange(null)}/></div>}
70
+ <button
71
+ className="button"
72
+ onClick={() => {
73
+ sdk.dialogs.openCurrentApp({
74
+ width: "fullWidth",
75
+ title: "Select Image",
76
+ shouldCloseOnOverlayClick: true,
77
+ shouldCloseOnEscapePress: true,
78
+ parameters: {
79
+ type: "cloudinary",
80
+ portal: sdk?.entry?.fields?.portal?.getValue(),
81
+ },
82
+ }).then((data) => {
83
+ onChange(data?.assets?.[0]);
84
+ });
85
+ }}
86
+ >Auswählen
87
+ </button>
88
+ </>
89
+ );
90
90
  };