From b2fd96c12e2b4b8ac5cb5670494d36e1641e6ade Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Thu, 16 Mar 2017 20:45:46 -0400 Subject: [PATCH] condense rich text functionality to static toolbar --- src/components/UI/theme.css | 9 +- .../MarkdownControlElements/BlockMenu.css | 135 ------------------ .../RawEditor/index.css | 4 + .../RawEditor/index.js | 64 ++++----- .../MarkdownControlElements/Toolbar.css | 24 ++-- .../MarkdownControlElements/Toolbar.js | 75 ++++------ .../ToolbarPlugins.css | 62 ++++++++ .../{BlockMenu.js => ToolbarPlugins.js} | 64 ++++----- .../VisualEditor/index.css | 12 +- .../VisualEditor/index.js | 80 +++++------ src/index.js | 3 +- 11 files changed, 211 insertions(+), 321 deletions(-) delete mode 100644 src/components/Widgets/MarkdownControlElements/BlockMenu.css create mode 100644 src/components/Widgets/MarkdownControlElements/ToolbarPlugins.css rename src/components/Widgets/MarkdownControlElements/{BlockMenu.js => ToolbarPlugins.js} (57%) diff --git a/src/components/UI/theme.css b/src/components/UI/theme.css index ee29dabb..63519df1 100644 --- a/src/components/UI/theme.css +++ b/src/components/UI/theme.css @@ -8,16 +8,23 @@ --successColor: #1c7; --warningColor: #fa0; --errorColor: #f52; + --textColor: #272e30; --borderRadius: 2px; --borderRadiusLarge: 10px; + --dropShadow: + 0 2px 2px 0 rgba(0, 0, 0, 0.14), + 0 3px 1px -2px rgba(0, 0, 0, 0.2), + 0 1px 5px 0 rgba(0, 0, 0, 0.12); --topmostZindex: 99999; --foregroundAltColor: #fff; --backgroundAltColor: #272e30; --textFieldBorderColor: #e7e7e7; --highlightFGColor: #fff; --highlightBGColor: #3ab7a5; - --controlLabelColor: #272e30; + --controlLabelColor: var(--textColor); --controlBGColor: #fff; + --backgroundTertiaryColor: #f2f5f4; + --backgroundTertiaryColorDark: color(var(--backgroundTertiaryColor) lightness(90%)); } .base { diff --git a/src/components/Widgets/MarkdownControlElements/BlockMenu.css b/src/components/Widgets/MarkdownControlElements/BlockMenu.css deleted file mode 100644 index 6f602ca7..00000000 --- a/src/components/Widgets/MarkdownControlElements/BlockMenu.css +++ /dev/null @@ -1,135 +0,0 @@ -.root { - position: absolute; - left: -18px; - display: none; - width: 100%; - z-index: 1000; -} - -.visible { - display: block; -} - -.button { - display: block; - width: 15px; - height: 15px; - border: 1px solid #444; - border-radius: 100%; - background: transparent; - line-height: 13px; -} - -.expanded { - display: block; -} - -.collapsed { - display: none; -} - -.pluginForm, -.menu { - margin-top: -20px; - margin-bottom: 30px; - margin-left: 20px; - border-radius: 4px; - background: #fff; - box-shadow: 1px 1px 20px; - - & h3 { - padding: 5px 20px; - border-bottom: 1px solid; - } -} - -.menu { - list-style: none; - - & li button { - display: block; - padding: 5px 20px; - min-width: 30%; - width: 100%; - border: none; - border-bottom: 1px solid; - background: #fff; - -webkit-appearance: none; - } - - & li:last-child button { - border-bottom: none; - } - - & li:hover button { - background: #efefef; - } -} - -.menu.expanded { - display: inline-block; -} - -.control { - position: relative; - padding: 20px 20px; - color: #7c8382; - - & input, - & textarea, - & select { - display: block; - margin: 0; - padding: 0; - width: 100%; - outline: 0; - border: none; - background: 0 0; - box-shadow: none; - color: #7c8382; - font-size: 18px; - font-family: monospace; - } -} - -.label { - display: block; - margin-bottom: 18px; - color: #aab0af; - font-size: 12px; -} - -.widget { - position: relative; - border-bottom: 1px solid #aaa; - - &:after { - position: absolute; - bottom: -7px; - left: 42px; - z-index: 1; - width: 12px; - height: 12px; - border-right: 1px solid #aaa; - border-bottom: 1px solid #aaa; - background-color: #f2f5f4; - content: ''; - -webkit-transform: rotate(45deg); - transform: rotate(45deg); - } - - &:last-child { - border-bottom: none; - } - - &:last-child:after { - display: none; - } -} - -.footer { - padding: 10px 20px; - border-top: 1px solid #eee; - background: #fff; - text-align: right; -} diff --git a/src/components/Widgets/MarkdownControlElements/RawEditor/index.css b/src/components/Widgets/MarkdownControlElements/RawEditor/index.css index f158b7f8..bb96c586 100644 --- a/src/components/Widgets/MarkdownControlElements/RawEditor/index.css +++ b/src/components/Widgets/MarkdownControlElements/RawEditor/index.css @@ -2,6 +2,10 @@ position: relative; } +.editorControlBar { + composes: editorControlBar from "../VisualEditor/index.css"; +} + .dragging { } .shim { diff --git a/src/components/Widgets/MarkdownControlElements/RawEditor/index.js b/src/components/Widgets/MarkdownControlElements/RawEditor/index.js index 21782571..fc06192b 100644 --- a/src/components/Widgets/MarkdownControlElements/RawEditor/index.js +++ b/src/components/Widgets/MarkdownControlElements/RawEditor/index.js @@ -6,7 +6,7 @@ import CaretPosition from 'textarea-caret-position'; import registry from '../../../../lib/registry'; import { createAssetProxy } from '../../../../valueObjects/AssetProxy'; import Toolbar from '../Toolbar'; -import BlockMenu from '../BlockMenu'; +import ToolbarPlugins from '../ToolbarPlugins'; import styles from './index.css'; const HAS_LINE_BREAK = /\n/m; @@ -18,7 +18,7 @@ function processUrl(url) { if (url.match(/^(https?:\/\/|mailto:|\/)/)) { return url; } - if (url.match(/^[^\/]+\.[^\/]+/)) { + if (url.match(/^[^/]+\.[^/]+/)) { return `https://${ url }`; } return `/${ url }`; @@ -44,7 +44,9 @@ function getCleanPaste(e) { // Handle complex pastes by stealing focus with a contenteditable div const div = document.createElement('div'); div.contentEditable = true; - div.setAttribute('style', 'opacity: 0; overflow: hidden; width: 1px; height: 1px; position: fixed; top: 50%; left: 0;'); + div.setAttribute( + 'style', 'opacity: 0; overflow: hidden; width: 1px; height: 1px; position: fixed; top: 50%; left: 0;' + ); document.body.appendChild(div); div.focus(); setTimeout(() => { @@ -194,7 +196,7 @@ export default class RawEditor extends React.Component { }; handleLink = () => { - const url = prompt('URL:'); + const url = prompt('URL:'); // eslint-disable-line no-alert const selection = this.getSelection(); this.replaceSelection(`[${ selection.selected }](${ processUrl(url) })`); }; @@ -205,9 +207,9 @@ export default class RawEditor extends React.Component { if (selection.start !== selection.end && !HAS_LINE_BREAK.test(selection.selected)) { try { const selectionPosition = this.caretPosition.get(selection.start, selection.end); - this.setState({ showToolbar: true, showBlockMenu: false, selectionPosition }); + this.setState({ selectionPosition }); } catch (e) { - this.setState({ showToolbar: false, showBlockMenu: false }); + console.log(e); // eslint-disable-line no-console } } else if (selection.start === selection.end) { const newBlock = @@ -222,12 +224,8 @@ export default class RawEditor extends React.Component { if (newBlock) { const position = this.caretPosition.get(selection.start, selection.end); - this.setState({ showToolbar: false, showBlockMenu: true, selectionPosition: position }); - } else { - this.setState({ showToolbar: false, showBlockMenu: false }); + this.setState({ selectionPosition: position }); } - } else { - this.setState({ showToolbar: false, showBlockMenu: false }); } }; @@ -236,10 +234,9 @@ export default class RawEditor extends React.Component { this.updateHeight(); }; - handleBlock = (plugin, data) => { + handlePlugin = (plugin, data) => { const toBlock = plugin.get('toBlock'); this.replaceSelection(toBlock.call(toBlock, data.toJS())); - this.setState({ showBlockMenu: false }); }; handleHeader(header) { @@ -309,7 +306,7 @@ export default class RawEditor extends React.Component { render() { const { onAddAsset, onRemoveAsset, getAsset } = this.props; - const { showToolbar, showBlockMenu, plugins, selectionPosition, dragging } = this.state; + const { plugins, selectionPosition, dragging } = this.state; const classNames = [styles.root]; if (dragging) { classNames.push(styles.dragging); @@ -322,25 +319,26 @@ export default class RawEditor extends React.Component { onDragOver={this.handleDragOver} onDrop={this.handleDrop} > - - +
+ + +