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(`![text](${response[0].url})`), - ); - 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(`![text](${response[0].url})`, '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 && ( )} diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js index c40b1b0016..95a1af45d9 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/previewWysiwyg.js @@ -12,10 +12,12 @@ import { isEmpty } from 'lodash'; import WysiwygEditor from 'components/WysiwygEditor'; import converter from './converter'; -import { findLinkEntities, findImageEntities } from './strategies'; +import { findLinkEntities, findImageEntities, findVideoEntities } from './strategies'; import Image from './image'; import Link from './link'; +import Video from './video'; + import styles from './componentsStyles.scss'; function getBlockStyle(block) { @@ -61,6 +63,10 @@ class PreviewWysiwyg extends React.Component { strategy: findImageEntities, component: Image, }, + { + strategy: findVideoEntities, + component: Video, + }, ]); const blocksFromHTML = convertFromHTML(html); diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/strategies.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/strategies.js index 36ae8701b4..92760a2fea 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/strategies.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/strategies.js @@ -8,8 +8,19 @@ function findLinkEntities(contentBlock, callback, contentState) { function findImageEntities(contentBlock, callback, contentState) { contentBlock.findEntityRanges(character => { const entityKey = character.getEntity(); - return entityKey !== null && contentState.getEntity(entityKey).getType() === 'IMAGE'; + + return entityKey !== null && contentState.getEntity(entityKey).getType() === 'IMAGE' && !isVideoType(contentState.getEntity(entityKey).getData().src); }, callback); } -export { findLinkEntities, findImageEntities }; +function findVideoEntities(contentBlock, cb, contentState) { + contentBlock.findEntityRanges(character => { + const entityKey = character.getEntity(); + + return entityKey !== null && contentState.getEntity(entityKey).getType() === 'IMAGE' && isVideoType(contentState.getEntity(entityKey).getData().src); + }, cb); +} + +const isVideoType = (fileName) => /\.(mp4|mpg|mpeg|mov|avi)$/i.test(fileName); + +export { findLinkEntities, findImageEntities, findVideoEntities }; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/video.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/video.js new file mode 100644 index 0000000000..3cdbdaa9bb --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/video.js @@ -0,0 +1,26 @@ +/** + * + * Video + * + */ + +import React from 'react'; +import PropTypes from 'prop-types'; + +/* eslint-disable jsx-a11y/media-has-caption */ +const Video = props => { + const { height, src, width } = props.contentState.getEntity(props.entityKey).getData(); + + return ( + + ); +}; + +Video.propTypes = { + contentState: PropTypes.object.isRequired, + entityKey: PropTypes.string.isRequired, +}; + +export default Video; diff --git a/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/index.js b/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/index.js index 4330364d99..bad94258d0 100644 --- a/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/index.js @@ -9,13 +9,31 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import styles from './styles.scss'; +/* eslint-disable jsx-a11y/label-has-for */ +const WysiwygBottomControls = ({ isPreviewMode, onChange, onClick }) => { + const browse = ( + + {(message) => {message}} + + ); -const WysiwygBottomControls = ({ charactersNumber, onClick }) => { return (
- {charactersNumber}  - +
@@ -25,12 +43,14 @@ const WysiwygBottomControls = ({ charactersNumber, onClick }) => { }; WysiwygBottomControls.defaultProps = { - charactersNumber: 0, + isPreviewMode: false, + onChange: () => {}, onClick: () => {}, }; WysiwygBottomControls.propTypes = { - charactersNumber: PropTypes.number, + isPreviewMode: PropTypes.bool, + onChange: PropTypes.func, onClick: PropTypes.func, }; diff --git a/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/styles.scss b/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/styles.scss index 8c036e58f8..fc50166686 100644 --- a/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/styles.scss +++ b/packages/strapi-helper-plugin/lib/src/components/WysiwygBottomControls/styles.scss @@ -25,3 +25,15 @@ font-size: 12px; } } + +.underline { + color: #1C5DE7; + text-decoration: underline; + cursor: pointer; +} + +.dropLabel { + > input { + display: none; + } +} diff --git a/packages/strapi-plugin-upload/admin/src/components/Li/index.js b/packages/strapi-plugin-upload/admin/src/components/Li/index.js index ed4b9fef09..e602c7ea77 100644 --- a/packages/strapi-plugin-upload/admin/src/components/Li/index.js +++ b/packages/strapi-plugin-upload/admin/src/components/Li/index.js @@ -31,21 +31,27 @@ class Li extends React.Component { getUnit = (value) => { let unit; + let divider; + switch (true) { case value > 10000: unit = 'GB'; + divider = 1000; break; case value < 1: unit = 'B'; + divider = 1; break; case value > 1000: unit = 'MB'; + divider = 1000; break; default: unit = 'KB'; + divider = 1; } - return unit; + return { divider, unit }; } handleClick = (e) => { @@ -111,10 +117,11 @@ class Li extends React.Component { } if (value === 'size') { - const unit = this.getUnit(item[value]); + const { divider, unit } = this.getUnit(item[value]); + const size = item[value]/divider; return ( -
{item[value]} {unit}
+
{Math.round(size * 100) / 100 } {unit}
); }