diff --git a/packages/strapi-admin/admin/src/translations/de.json b/packages/strapi-admin/admin/src/translations/de.json
index 04a8c9e9a6..d3ae7c06d3 100644
--- a/packages/strapi-admin/admin/src/translations/de.json
+++ b/packages/strapi-admin/admin/src/translations/de.json
@@ -110,6 +110,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Switch to markdown",
"components.Wysiwyg.ToggleMode.preview": "Switch to preview",
"components.WysiwygBottomControls.charactersIndicators": "characters",
+ "components.WysiwygBottomControls.uploadFiles": "Attach files by dragging & dropping, {browse}, or pasting from the clipboard.",
+ "components.WysiwygBottomControls.uploadFiles.browse": "selecting them",
"components.WysiwygBottomControls.fullscreen": "Expand",
"notification.error": "Ein Fehler ist aufgetreten",
diff --git a/packages/strapi-admin/admin/src/translations/en.json b/packages/strapi-admin/admin/src/translations/en.json
index 864f6c9953..17d6774711 100755
--- a/packages/strapi-admin/admin/src/translations/en.json
+++ b/packages/strapi-admin/admin/src/translations/en.json
@@ -116,6 +116,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Switch to markdown",
"components.Wysiwyg.ToggleMode.preview": "Switch to preview",
"components.WysiwygBottomControls.charactersIndicators": "characters",
+ "components.WysiwygBottomControls.uploadFiles": "Attach files by dragging & dropping, {browse}, or pasting from the clipboard.",
+ "components.WysiwygBottomControls.uploadFiles.browse": "selecting them",
"components.WysiwygBottomControls.fullscreen": "Expand",
"notification.error": "An error occurred",
diff --git a/packages/strapi-admin/admin/src/translations/fr.json b/packages/strapi-admin/admin/src/translations/fr.json
index 28754b4da0..c5a3d19955 100755
--- a/packages/strapi-admin/admin/src/translations/fr.json
+++ b/packages/strapi-admin/admin/src/translations/fr.json
@@ -116,6 +116,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Retour au markdown",
"components.Wysiwyg.ToggleMode.preview": "Voir la preview",
"components.WysiwygBottomControls.charactersIndicators": "charactères",
+ "components.WysiwygBottomControls.uploadFiles": "Ajouter des fichiers en les 'droppant', {browse}, ou en les collant depuis le presse-papier",
+ "components.WysiwygBottomControls.uploadFiles.browse": "en les selectionnant",
"components.WysiwygBottomControls.fullscreen": "Plein écran",
"notification.error": "Une erreur est survenue",
diff --git a/packages/strapi-admin/admin/src/translations/pl.json b/packages/strapi-admin/admin/src/translations/pl.json
index 47e925c292..652ab76bac 100644
--- a/packages/strapi-admin/admin/src/translations/pl.json
+++ b/packages/strapi-admin/admin/src/translations/pl.json
@@ -113,6 +113,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Switch to markdown",
"components.Wysiwyg.ToggleMode.preview": "Switch to preview",
"components.WysiwygBottomControls.charactersIndicators": "characters",
+ "components.WysiwygBottomControls.uploadFiles": "Attach files by dragging & dropping, {browse}, or pasting from the clipboard.",
+ "components.WysiwygBottomControls.uploadFiles.browse": "selecting them",
"components.WysiwygBottomControls.fullscreen": "Expand",
"notification.error": "Wystąpił błąd",
diff --git a/packages/strapi-admin/admin/src/translations/tr.json b/packages/strapi-admin/admin/src/translations/tr.json
index b071f49b2b..aa5a7677f5 100755
--- a/packages/strapi-admin/admin/src/translations/tr.json
+++ b/packages/strapi-admin/admin/src/translations/tr.json
@@ -114,6 +114,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Switch to markdown",
"components.Wysiwyg.ToggleMode.preview": "Switch to preview",
"components.WysiwygBottomControls.charactersIndicators": "characters",
+ "components.WysiwygBottomControls.uploadFiles": "Attach files by dragging & dropping, {browse}, or pasting from the clipboard.",
+ "components.WysiwygBottomControls.uploadFiles.browse": "selecting them",
"components.WysiwygBottomControls.fullscreen": "Expand",
"notification.error": "Bir hata oluştu",
diff --git a/packages/strapi-admin/admin/src/translations/zh.json b/packages/strapi-admin/admin/src/translations/zh.json
index ae9cad1db7..c944bde748 100755
--- a/packages/strapi-admin/admin/src/translations/zh.json
+++ b/packages/strapi-admin/admin/src/translations/zh.json
@@ -118,6 +118,8 @@
"components.Wysiwyg.ToggleMode.markdown": "Switch to markdown",
"components.Wysiwyg.ToggleMode.preview": "Switch to preview",
"components.WysiwygBottomControls.charactersIndicators": "characters",
+ "components.WysiwygBottomControls.uploadFiles": "Attach files by dragging & dropping, {browse}, or pasting from the clipboard.",
+ "components.WysiwygBottomControls.uploadFiles.browse": "selecting them",
"components.WysiwygBottomControls.fullscreen": "Expand",
"notification.error": "有錯誤發生了",
diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/componentsStyles.scss b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/componentsStyles.scss
index cce7ea0960..ce93584b0c 100644
--- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/componentsStyles.scss
+++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/componentsStyles.scss
@@ -56,9 +56,9 @@
}
// NOTE: we might need this later
- // span {
- // white-space: pre-line;
- // }
+ span {
+ white-space: pre-line;
+ }
}
h1+.editorParagraph{
diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js
index 5685959983..add582f9bc 100644
--- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js
+++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js
@@ -369,28 +369,8 @@ class Wysiwyg extends React.Component {
return this.setState({ isDraging: false });
}
- const { dataTransfer: { files } } = e;
- const formData = new FormData();
- formData.append('files', files[0]);
- const headers = {
- 'X-Forwarded-Host': 'strapi',
- };
-
- return request('/upload', { method: 'POST', headers, body: formData }, false, false)
- .then(response => {
- const newContentState = this.createNewContentStateFromBlock(
- createNewBlock(``),
- );
- const newEditorState = EditorState.push(this.getEditorState(), newContentState);
- this.setState({ editorState: newEditorState });
- this.sendData(newEditorState);
- })
- .catch(err => {
- console.log('error', err.response);
- })
- .finally(() => {
- this.setState({ isDraging: false });
- });
+ const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
+ return this.uploadFile(files);
};
handleKeyCommand = (command, editorState) => {
@@ -410,6 +390,8 @@ class Wysiwyg extends React.Component {
return false;
};
+ handlePastedFiles = files => this.uploadFile(files);
+
handleReturn = (e, editorState) => {
const selection = editorState.getSelection();
const currentBlock = editorState.getCurrentContent().getBlockForKey(selection.getStartKey());
@@ -474,6 +456,37 @@ class Wysiwyg extends React.Component {
});
};
+ uploadFile = (files) => {
+ const formData = new FormData();
+ formData.append('files', files[0]);
+ const headers = {
+ 'X-Forwarded-Host': 'strapi',
+ };
+
+ const newContentState = this.createNewContentStateFromBlock(
+ createNewBlock(`![Uploading ${files[0].name}]()`),
+ );
+ const newEditorState = EditorState.push(this.getEditorState(), newContentState);
+ this.setState({ editorState: newEditorState });
+
+ return request('/upload', { method: 'POST', headers, body: formData }, false, false)
+ .then(response => {
+ const lastBlock = this.getEditorState().getCurrentContent().getLastBlock();
+ const newContentState = this.createNewContentStateFromBlock(
+ createNewBlock(``, 'unstyled', lastBlock.getKey()),
+ );
+ const newEditorState = EditorState.push(this.getEditorState(), newContentState);
+ this.setState({ editorState: EditorState.moveFocusToEnd(newEditorState) });
+ this.sendData(newEditorState);
+ })
+ .catch(() => {
+ this.setState({ editorState: EditorState.undo(this.getEditorState()) });
+ })
+ .finally(() => {
+ this.setState({ isDraging: false });
+ });
+ }
+
componentDidCatch(error, info) {
console.log('err', error);
console.log('info', info);
@@ -549,6 +562,7 @@ class Wysiwyg extends React.Component {
blockStyleFn={getBlockStyle}
editorState={editorState}
handleKeyCommand={this.handleKeyCommand}
+ handlePastedFiles={this.handlePastedFiles}
handleReturn={this.handleReturn}
keyBindingFn={this.mapKeyToEditorCommand}
onBlur={this.handleBlur}
@@ -563,8 +577,9 @@ class Wysiwyg extends React.Component {
)}
{!isFullscreen && (