@vonaffenfels/slate-editor 1.1.69 → 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,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
  };