From aed37546ff585aa50b7c33ce6d1ef4ac63cb2f40 Mon Sep 17 00:00:00 2001 From: cyril lopez Date: Mon, 26 Mar 2018 11:14:07 +0200 Subject: [PATCH] Created components folder --- .../lib/src/components/Wysiwyg/components.js | 192 ------------------ .../Wysiwyg/components/customSelect.js | 42 ++++ .../components/Wysiwyg/components/image.js | 22 ++ .../components/Wysiwyg/components/index.js | 21 ++ .../src/components/Wysiwyg/components/link.js | 30 +++ .../Wysiwyg/components/previewControl.js | 36 ++++ .../Wysiwyg/components/previewWysiwyg.js | 82 ++++++++ .../components/Wysiwyg/components/styles.scss | 117 +++++++++++ .../Wysiwyg/components/toggleMode.js | 36 ++++ .../lib/src/components/Wysiwyg/helpers.js | 9 + .../lib/src/components/Wysiwyg/index.js | 2 +- .../lib/src/components/Wysiwyg/styles.scss | 72 ------- 12 files changed, 396 insertions(+), 265 deletions(-) delete mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/customSelect.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/image.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/index.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/link.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/previewControl.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/previewWysiwyg.js create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/styles.scss create mode 100644 packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/toggleMode.js diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components.js deleted file mode 100644 index d56a1c7898..0000000000 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components.js +++ /dev/null @@ -1,192 +0,0 @@ -/** - * - * Utils components for the WYSIWYG - * It includes decorators toggle buttons... - * - */ - -import React from 'react'; -import { CompositeDecorator, ContentState, convertFromHTML, EditorState } from 'draft-js'; -import { FormattedMessage } from 'react-intl'; -import PropTypes from 'prop-types'; -import cn from 'classnames'; -import { isEmpty } from 'lodash'; -import Select from 'components/InputSelect'; -import WysiwygEditor from 'components/WysiwygEditor'; - -import { SELECT_OPTIONS } from './constants'; -import converter from './converter'; -import { getBlockStyle } from './helpers'; -import { findLinkEntities, findImageEntities } from './strategies'; - -import styles from './styles.scss'; -/* eslint-disable react/no-multi-comp */ - -class CustomSelect extends React.Component { - render() { - const { isPreviewMode, headerValue, isFullscreen, handleChangeSelect } = this.context; - const selectClassName = isFullscreen ? styles.selectFullscreen : styles.editorSelect; - - return ( -
- -
- ); - } -} - -PreviewWysiwyg.contextTypes = { - editorState: PropTypes.func, - html: PropTypes.string, - isFullscreen: PropTypes.bool, - placeholder: PropTypes.string, -}; - -const ToggleMode = props => { - const label = props.isPreviewMode - ? 'components.Wysiwyg.ToggleMode.markdown' - : 'components.Wysiwyg.ToggleMode.preview'; - - return ( -
- -
- ); -}; - -ToggleMode.defaultProps = { - isPreviewMode: false, - onClick: () => {}, -}; - -ToggleMode.propTypes = { - isPreviewMode: PropTypes.bool, - onClick: PropTypes.func, -}; - -export { CustomSelect, Image, Link, PreviewControl, PreviewWysiwyg, ToggleMode }; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/customSelect.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/customSelect.js new file mode 100644 index 0000000000..157b930a5c --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/customSelect.js @@ -0,0 +1,42 @@ +/** + * + * + * CustomSelect + * + */ + +import React from 'react'; +import PropTypes from 'prop-types'; + +import Select from 'components/InputSelect'; +import { SELECT_OPTIONS } from '../constants'; + +import styles from './styles.scss'; + +class CustomSelect extends React.Component { + render() { + const { isPreviewMode, headerValue, isFullscreen, handleChangeSelect } = this.context; + const selectClassName = isFullscreen ? styles.selectFullscreen : styles.editorSelect; + + return ( +
+ +
+ ); + } +} + +PreviewWysiwyg.contextTypes = { + editorState: PropTypes.func, + html: PropTypes.string, + isFullscreen: PropTypes.bool, + placeholder: PropTypes.string, +}; + +export default PreviewWysiwyg; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/styles.scss b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/styles.scss new file mode 100644 index 0000000000..51258fe89d --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/styles.scss @@ -0,0 +1,117 @@ +.editor { + min-height: 303px; + padding: 10px 20px 0 20px; + font-size: 16px; + margin-top: 10px; + background-color: #fff; + line-height: 18px !important; + cursor: text; + // TODO define rules for header's margin + h1, h2, h3, h4, h5, h6 { + margin: 0; + line-height: 18px !important; + } + h1 { + margin-top: 13px !important; + margin-bottom: 22px; + } + > div { + > div { + > div { + margin-bottom: 32px; + } + } + } + li { + margin-top: 0; + } + ul, ol { + margin-bottom: 18px; + } + span { + white-space: pre-line; + } +} + +.editorFullScreen { + max-height: calc(100% - 100px) !important; + margin-bottom: 0; + overflow: auto; +} + +.editorInput { + height: 0; + width: 0; +} + +.editorSelect { + min-width: 161px; + margin-left: 15px; + margin-right: 5px; + > select { + box-shadow: 0 0 0 rgba(0,0,0,0)!important; + } +} + +.fullscreenPreviewEditor { + margin-top: 9px; + padding: 10px 20px; +} + +.previewControlsWrapper { + display: flex; + height: 49px; + width: 100%; + padding: 0 17px; + justify-content: space-between; + background-color: #FAFAFB; + line-height: 30px; + font-size: 12px; + font-family: Lato; + background-color: #fff; + border-bottom: 1px solid #F3F4F4; + line-height: 49px; + font-size: 13px; + >div:first-child { + >span:last-child { + font-size: 12px; + } + } +} + +.selectFullscreen { + min-width: 115px; + margin-left: 15px; + > select { + min-width: 110px !important; + box-shadow: 0 0 0 rgba(0,0,0,0)!important; + } +} + +.toggleModeButton { + height: 32px; + min-width: 32px; + padding-left: 10px; + padding-right: 10px; + border: 1px solid rgba(16,22,34,0.10); + border-radius: 3px; + background: #F3F4F4; + font-size: 13px; + font-weight: 500; + text-align: center; + cursor: pointer; +} + +.toggleModeWrapper { + margin-left: auto; + margin-right: 15px; + padding-top: 8px; +} + +.wysiwygCollapse { + &:after { + content: '\f066'; + font-family: FontAwesome; + margin-left: 8px; + } +} diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/toggleMode.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/toggleMode.js new file mode 100644 index 0000000000..b9c0326c89 --- /dev/null +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/components/toggleMode.js @@ -0,0 +1,36 @@ +/** + * + * + * ToggleMode + */ + +import React from 'react'; +import { FormattedMessage } from 'react-intl'; +import PropTypes from 'prop-types'; +import styles from './styles.scss'; + +const ToggleMode = props => { + const label = props.isPreviewMode + ? 'components.Wysiwyg.ToggleMode.markdown' + : 'components.Wysiwyg.ToggleMode.preview'; + + return ( +
+ +
+ ); +}; + +ToggleMode.defaultProps = { + isPreviewMode: false, + onClick: () => {}, +}; + +ToggleMode.propTypes = { + isPreviewMode: PropTypes.bool, + onClick: PropTypes.func, +}; + +export default ToggleMode; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js index 4bc865d4b5..72581e1138 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js @@ -12,6 +12,15 @@ export function getBlockStyle(block) { return styles.editorBlockquote; case 'code-block': return styles.editorCodeBlock; + case 'paragraph': + case 'unordered-list-item': + case 'ordered-list-item': + case 'header-one': + case 'header-two': + case 'header-three': + case 'header-four': + case 'header-five': + case 'header-six': default: return null; } 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 059e4423f7..befdbcb270 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js @@ -24,7 +24,7 @@ import Drop from 'components/WysiwygDropUpload'; import WysiwygBottomControls from 'components/WysiwygBottomControls'; import WysiwygEditor from 'components/WysiwygEditor'; import request from 'utils/request'; -import { CustomSelect, PreviewControl, PreviewWysiwyg, ToggleMode } from './components'; +import { CustomSelect, PreviewControl, PreviewWysiwyg, ToggleMode } from './components/index'; import { CONTROLS } from './constants'; import { getBlockContent, getBlockStyle, getDefaultSelectionOffsets, getOffSets } from './helpers'; import styles from './styles.scss'; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/styles.scss b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/styles.scss index f748f607e9..1c321e2436 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/styles.scss +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/styles.scss @@ -64,24 +64,6 @@ border-color: #ff203c !important; } -.editorSelect { - min-width: 161px; - margin-left: 15px; - margin-right: 5px; - > select { - box-shadow: 0 0 0 rgba(0,0,0,0)!important; - } -} - -.selectFullscreen { - min-width: 115px; - margin-left: 15px; - > select { - min-width: 110px !important; - box-shadow: 0 0 0 rgba(0,0,0,0)!important; - } -} - .editorInput { height: 0; width: 0; @@ -145,57 +127,3 @@ margin-bottom: 0; overflow: auto; } - -.previewControlsWrapper { - display: flex; - height: 49px; - width: 100%; - padding: 0 17px; - justify-content: space-between; - background-color: #FAFAFB; - line-height: 30px; - font-size: 12px; - font-family: Lato; - background-color: #fff; - border-bottom: 1px solid #F3F4F4; - line-height: 49px; - font-size: 13px; - >div:first-child { - >span:last-child { - font-size: 12px; - } - } -} - -.fullscreenPreviewEditor { - margin-top: 9px; - padding: 10px 20px; -} - -.toggleModeButton { - height: 32px; - min-width: 32px; - padding-left: 10px; - padding-right: 10px; - border: 1px solid rgba(16,22,34,0.10); - border-radius: 3px; - background: #F3F4F4; - font-size: 13px; - font-weight: 500; - text-align: center; - cursor: pointer; -} - -.toggleModeWrapper { - margin-left: auto; - margin-right: 15px; - padding-top: 8px; -} - -.wysiwygCollapse { - &:after { - content: '\f066'; - font-family: FontAwesome; - margin-left: 8px; - } -}