@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.
- package/.babelrc +43 -43
- package/README.md +5 -5
- package/componentLoader.js +93 -93
- package/dist/BlockEditor.css +4 -1871
- package/dist/BlockEditor.js +336 -3960
- package/dist/BlockEditor.js.LICENSE.txt +61 -0
- package/dist/Renderer.js +2 -2081
- package/dist/Renderer.js.LICENSE.txt +15 -0
- package/dist/fromHTML.js +1 -78
- package/dist/index.css +4 -1871
- package/dist/index.js +336 -4037
- package/dist/index.js.LICENSE.txt +69 -0
- package/dist/toHTML.js +2 -1689
- package/dist/toHTML.js.LICENSE.txt +23 -0
- package/dist/toText.js +2 -1689
- package/dist/toText.js.LICENSE.txt +23 -0
- package/package.json +2 -2
- package/postcss.config.js +6 -6
- package/scss/demo.scss +148 -148
- package/scss/editor.scss +17 -5
- package/scss/sidebarEditor.scss +185 -181
- package/scss/toolbar.scss +161 -161
- package/src/BlockEditor.js +6 -3
- package/src/Blocks/EmptyBlock.js +11 -11
- package/src/Blocks/EmptyWrapper.js +4 -4
- package/src/Blocks/ErrorBoundary.js +40 -40
- package/src/Blocks/LayoutBlock.js +274 -274
- package/src/Blocks/LayoutSlot.js +90 -90
- package/src/CollapsableMenu/CollapsableMenu.js +48 -48
- package/src/Context/StorybookContext.js +6 -6
- package/src/ElementAutocomplete.js +133 -133
- package/src/Loader.js +137 -137
- package/src/Nodes/Default.js +158 -158
- package/src/Nodes/Leaf.js +54 -54
- package/src/Nodes/Text.js +97 -97
- package/src/ObjectId.js +3 -3
- package/src/Renderer.js +73 -73
- package/src/Serializer/Html.js +42 -42
- package/src/Serializer/Serializer.js +371 -371
- package/src/Serializer/Text.js +17 -17
- package/src/Serializer/ads.js +174 -174
- package/src/Serializer/index.js +3 -3
- package/src/SidebarEditor/AssetList.js +181 -181
- package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
- package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
- package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
- package/src/SidebarEditor/Fields/DateTime.js +55 -55
- package/src/SidebarEditor/Fields/MVP.js +66 -66
- package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
- package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
- package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
- package/src/SidebarEditor/Fields/Select.js +47 -47
- package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
- package/src/SidebarEditor/Fields/Switch.js +34 -34
- package/src/SidebarEditor/Fields/Textarea.js +21 -21
- package/src/SidebarEditor/Resizable.js +85 -85
- package/src/Storybook.js +151 -151
- package/src/Toolbar/Align.js +64 -64
- package/src/Toolbar/Anchor.js +94 -94
- package/src/Toolbar/Block.js +135 -135
- package/src/Toolbar/Element.js +44 -44
- package/src/Toolbar/Formats.js +71 -71
- package/src/Toolbar/Insert.js +28 -28
- package/src/Toolbar/Layout.js +399 -399
- package/src/Toolbar/Link.js +164 -164
- package/src/Toolbar/Toolbar.js +235 -235
- package/src/Tools/Margin.js +51 -51
- package/src/Translation/TranslationToolbarButton.js +119 -115
- package/src/dev/draftToSlate.json +3147 -3147
- package/src/dev/index.css +2 -2
- package/src/dev/index.html +10 -10
- package/src/dev/index.js +4 -4
- package/src/dev/sampleValue1.json +4294 -4294
- package/src/dev/sampleValueValid.json +410 -410
- package/src/dev/testComponents/TestStory.js +74 -74
- package/src/dev/testComponents/TestStory.stories.js +216 -216
- package/src/dev/testComponents/TestStory2.js +74 -74
- package/src/dev/testComponents/TestStory2.stories.js +197 -197
- package/src/dev/testComponents/TestStory3.js +74 -74
- package/src/dev/testComponents/TestStory3.stories.js +197 -197
- package/src/dev/testSampleValue.json +746 -746
- package/src/fromHTML.js +4 -4
- package/src/helper/array.js +8 -8
- package/src/index.js +10 -10
- package/src/plugins/ListItem.js +48 -48
- package/src/plugins/SoftBreak.js +23 -23
- package/src/toHTML.js +6 -6
- package/src/toText.js +6 -6
- package/src/util/reduceContentfulResponse.js +64 -64
- package/src/util.js +19 -19
- package/storyLoader.js +47 -47
- package/tailwind.config.js +4 -4
- package/webpack.config.build.js +55 -55
- package/webpack.config.dev.js +60 -60
- package/webpack.config.js +130 -130
- package/webpack.config.watch.js +4 -4
|
@@ -1,116 +1,120 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useEffect, useState,
|
|
3
|
-
} from "react";
|
|
4
|
-
import {Modal} from '@contentful/f36-components';
|
|
5
|
-
import {
|
|
6
|
-
Select, Button, Paragraph,
|
|
7
|
-
} from '@contentful/f36-components';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect, useState,
|
|
3
|
+
} from "react";
|
|
4
|
+
import {Modal} from '@contentful/f36-components';
|
|
5
|
+
import {
|
|
6
|
+
Select, Button, Paragraph,
|
|
7
|
+
} from '@contentful/f36-components';
|
|
8
|
+
import classNames from "classnames";
|
|
9
|
+
|
|
10
|
+
export const TranslationToolbarButton = ({
|
|
11
|
+
sdk,
|
|
12
|
+
setEditorValue,
|
|
13
|
+
locale,
|
|
14
|
+
setLocale,
|
|
15
|
+
translateFromLocale = "de",
|
|
16
|
+
className,
|
|
17
|
+
}) => {
|
|
18
|
+
const [loading, setLoading] = useState(false);
|
|
19
|
+
const [error, setError] = useState(null);
|
|
20
|
+
const enabled = sdk?.parameters?.installation?.usersWithTranslation?.includes(sdk?.user?.email) && sdk?.parameters?.installation?.translationService;
|
|
21
|
+
|
|
22
|
+
if (sdk.locales.available.length < 2 || !enabled) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const handleOnChange = (e) => {
|
|
27
|
+
setLocale(e.target.value);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const translateEditorValue = async (editorContent, targetLanguage) => {
|
|
31
|
+
if (!sdk?.parameters?.installation?.translationService) {
|
|
32
|
+
console.error(`no translation service configured!`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
setLoading(true);
|
|
38
|
+
const response = await fetch(sdk?.parameters?.installation?.translationService, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
editorContent,
|
|
42
|
+
targetLanguage,
|
|
43
|
+
sourceLanguage: translateFromLocale,
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const translatedValue = await response.json();
|
|
48
|
+
setLoading(false);
|
|
49
|
+
|
|
50
|
+
if (translatedValue?.translation) {
|
|
51
|
+
setEditorValue(translatedValue.translation);
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
console.error(e);
|
|
55
|
+
setLoading(false);
|
|
56
|
+
setError({
|
|
57
|
+
title: "Error",
|
|
58
|
+
message: "Übersetzunggservice nicht erreichbar",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const onAutoTranslateClick = () => {
|
|
64
|
+
const translateFromValue = sdk.entry.fields?.[sdk.parameters.instance.contentField]?.getForLocale(translateFromLocale)?.getValue();
|
|
65
|
+
const currentValue = sdk.entry.fields?.[sdk.parameters.instance.contentField]?.getForLocale(locale)?.getValue();
|
|
66
|
+
|
|
67
|
+
if (!translateFromValue) {
|
|
68
|
+
console.error(`No value for field ${sdk.parameters.instance.contentField} in locale ${translateFromLocale}`);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (currentValue) {
|
|
73
|
+
// ask for overwrite?
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
translateEditorValue(translateFromValue, locale);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
return <div className={classNames("flex gap-2", className)}>
|
|
80
|
+
{!!error && <ErrorOverlay title={error.title} message={error.message} />}
|
|
81
|
+
{locale !== sdk.locales.default &&
|
|
82
|
+
<Button
|
|
83
|
+
variant="secondary"
|
|
84
|
+
className="shrink-0"
|
|
85
|
+
onClick={onAutoTranslateClick}
|
|
86
|
+
size="small">{loading ? "Wird übersetzt..." : "Automatisch Übersetzen"}</Button>}
|
|
87
|
+
<Select
|
|
88
|
+
value={locale}
|
|
89
|
+
onChange={handleOnChange}
|
|
90
|
+
className="shrink-0"
|
|
91
|
+
>
|
|
92
|
+
{Object.keys(sdk?.locales?.names || {}).map((locale) => {
|
|
93
|
+
return <Select.Option key={locale} value={locale}>{sdk.locales.names[locale]}</Select.Option>;
|
|
94
|
+
})}
|
|
95
|
+
</Select>
|
|
96
|
+
</div>;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const ErrorOverlay = ({
|
|
100
|
+
title,
|
|
101
|
+
subtitle,
|
|
102
|
+
message,
|
|
103
|
+
}) => {
|
|
104
|
+
const [isShown, setShown] = useState(true);
|
|
105
|
+
|
|
106
|
+
return <Modal onClose={() => setShown(false)} isShown={isShown}>
|
|
107
|
+
{() => (
|
|
108
|
+
<>
|
|
109
|
+
<Modal.Header
|
|
110
|
+
title={title}
|
|
111
|
+
subtitle={subtitle}
|
|
112
|
+
onClose={() => setShown(false)}
|
|
113
|
+
/>
|
|
114
|
+
<Modal.Content>
|
|
115
|
+
<Paragraph>{message}</Paragraph>
|
|
116
|
+
</Modal.Content>
|
|
117
|
+
</>
|
|
118
|
+
)}
|
|
119
|
+
</Modal>;
|
|
116
120
|
};
|