Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"name": "Spectrum",
"version": "2.4.30",
"version": "2.4.29",
"license": "BSD-3-Clause",
"devDependencies": {
Expand Down Expand Up @@ -161,6 +160,7 @@
"react-router-dom": "^4.3.1",
"react-stripe-checkout": "^2.2.5",
"react-stripe-elements": "^1.4.1",
"react-text-selection-popover": "^1.1.0",
"react-textarea-autosize": "^6.1.0",
"react-transition-group": "^2.4.0",
"react-trend": "^1.2.4",
Expand All @@ -182,6 +182,7 @@
"slate": "^0.20.1",
"slate-markdown": "0.1.1",
"slugg": "^1.1.0",
"spectrum-draft-js-inline-toolbar": "^0.2.2",
"stopword": "^0.1.9",
"string-replace-to-array": "^1.0.3",
"string-similarity": "^1.2.0",
Expand Down
42 changes: 36 additions & 6 deletions src/components/rich-text-editor/container.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @flow
import React from 'react';
import React, { Fragment } from 'react';
import DraftEditor from '../draft-js-plugins-editor';
import { composeDecorators } from 'draft-js-plugins-editor';
import createImagePlugin from 'draft-js-image-plugin';
import createFocusPlugin from 'draft-js-focus-plugin';
import createBlockDndPlugin from 'draft-js-drag-n-drop-plugin';
import createMarkdownPlugin from 'draft-js-markdown-plugin';
import createEmbedPlugin from 'draft-js-embed-plugin';
import _InlineToolbar from 'spectrum-draft-js-inline-toolbar';
import createLinkifyPlugin from 'draft-js-linkify-plugin';
import Prism from 'prismjs';
import 'prismjs/components/prism-java';
Expand All @@ -32,6 +33,7 @@ import { LinkPreview, LinkPreviewLoading } from 'src/components/linkPreview';
import Image from './Image';
import Embed, { addEmbed, parseEmbedUrl } from './Embed';
import { renderLanguageSelect } from './LanguageSelect';
import styled from 'styled-components';
import SideToolbar from './toolbar';
import {
Wrapper,
Expand All @@ -43,6 +45,10 @@ import {
customStyleMap,
} from './style';

const InlineToolbar = styled(_InlineToolbar)`
z-index: 9999;
`;

type Props = {
state: Object,
onChange: Function,
Expand All @@ -68,12 +74,16 @@ type State = {

class Editor extends React.Component<Props, State> {
editor: any;
editorWrapper: { current: ?Element };

constructor(props: Props) {
super(props);

const pluginState = this.getPluginState(props);

// $FlowFixMe
this.editorWrapper = React.createRef();

this.state = {
...pluginState,
inserting: false,
Expand Down Expand Up @@ -213,6 +223,7 @@ class Editor extends React.Component<Props, State> {
if (version === 2) {
return (
<ComposerBase
innerRef={this.editorWrapper}
data-cy="rich-text-editor"
className={`markdown ${className || ''}`}
focus={focus}
Expand All @@ -225,6 +236,9 @@ class Editor extends React.Component<Props, State> {
handleDroppedFiles={this.handleDroppedFiles}
editorRef={editor => {
this.editor = editor;
this.editorWrapper = {
current: editor != null ? editor.editor.editorContainer : null,
};
if (editorRef) editorRef(editor);
}}
readOnly={readOnly}
Expand Down Expand Up @@ -294,6 +308,11 @@ class Editor extends React.Component<Props, State> {
margin={'16px 0 24px 0'}
/>
)}
<InlineToolbar
editorState={state}
selectionRef={this.editorWrapper}
onChange={onChange}
/>
</ComposerBase>
);
} else {
Expand All @@ -311,6 +330,10 @@ class Editor extends React.Component<Props, State> {
handleDroppedFiles={this.handleDroppedFiles}
editorRef={editor => {
this.editor = editor;
this.editorWrapper = {
current:
editor != null ? editor.editor.editorContainer : null,
};
if (editorRef) editorRef(editor);
}}
readOnly={readOnly}
Expand Down Expand Up @@ -343,11 +366,18 @@ class Editor extends React.Component<Props, State> {
/>
)}
{!readOnly && (
<MediaRow>
<MediaInput onChange={this.addImage} multiple>
Add
</MediaInput>
</MediaRow>
<Fragment>
<MediaRow>
<MediaInput onChange={this.addImage} multiple>
Add
</MediaInput>
</MediaRow>
<InlineToolbar
editorState={state}
selectionRef={this.editorWrapper}
onChange={onChange}
/>
</Fragment>
)}
</div>
);
Expand Down
84 changes: 82 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
core-js "^2.5.7"
regenerator-runtime "^0.12.0"

"@babel/runtime@^7.0.0-beta.42":
version "7.0.0-beta.56"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.56.tgz#cda612dffd5b1719a7b8e91e3040bd6ae64de8b0"
dependencies:
regenerator-runtime "^0.12.0"

"@babel/template@7.0.0-beta.44":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0-beta.44.tgz#f8832f4fdcee5d59bf515e595fc5106c529b394f"
Expand Down Expand Up @@ -3751,6 +3757,10 @@ draft-js-plugins-editor@^2.1.1:
prop-types "^15.5.8"
union-class-names "^1.0.0"

draft-js-plugins-utils@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/draft-js-plugins-utils/-/draft-js-plugins-utils-2.0.3.tgz#ba76c780bd097e05c4a4a02dfb2f72d1e238ab07"

draft-js-prism-plugin@0.1.3, draft-js-prism-plugin@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/draft-js-prism-plugin/-/draft-js-prism-plugin-0.1.3.tgz#b33669bae009749d876986c6b19b0d6936f311fd"
Expand All @@ -3769,7 +3779,7 @@ draft-js-utils@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/draft-js-utils/-/draft-js-utils-1.2.0.tgz#f5cb23eb167325ffed3d79882fdc317721d2fd12"

draft-js@0.x, draft-js@^0.10.4, "draft-js@npm:draft-js-fork-mxstbr", draft-js@~0.10.0:
draft-js@0.x, draft-js@^0.10.4, draft-js@^0.10.5, "draft-js@npm:draft-js-fork-mxstbr", draft-js@~0.10.0:
version "0.10.4"
resolved "https://registry.yarnpkg.com/draft-js-fork-mxstbr/-/draft-js-fork-mxstbr-0.10.4.tgz#4c8258799280f7cf66a2aa54fb094965389348ab"
dependencies:
Expand Down Expand Up @@ -4875,7 +4885,7 @@ from@~0:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"

fs-extra@3.0.1:
fs-extra@3.0.1, fs-extra@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-3.0.1.tgz#3794f378c58b342ea7dbbb23095109c4b3b62291"
dependencies:
Expand Down Expand Up @@ -4974,6 +4984,10 @@ get-document@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/get-document/-/get-document-1.0.0.tgz#4821bce66f1c24cb0331602be6cb6b12c4f01c4b"

get-node-dimensions@^1.2.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/get-node-dimensions/-/get-node-dimensions-1.2.1.tgz#fb7b4bb57060fb4247dd51c9d690dfbec56b0823"

get-stdin@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
Expand Down Expand Up @@ -9050,6 +9064,14 @@ react-error-overlay@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"

react-event-listener@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/react-event-listener/-/react-event-listener-0.6.1.tgz#41c7a80a66b398c27dd511e22712b02f3d4eccca"
dependencies:
"@babel/runtime" "^7.0.0-beta.42"
prop-types "^15.6.0"
warning "^4.0.1"

react-flip-move@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/react-flip-move/-/react-flip-move-3.0.2.tgz#2f6f16ca6cb0a8490fba15a98b3440a76127e825"
Expand Down Expand Up @@ -9100,6 +9122,14 @@ react-loadable@^5.4.0:
dependencies:
prop-types "^15.5.0"

react-measure@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/react-measure/-/react-measure-2.1.2.tgz#2fa690cc657d1e7a1271902b7a5937e0055338d5"
dependencies:
get-node-dimensions "^1.2.0"
prop-types "^15.5.10"
resize-observer-polyfill "^1.4.2"

react-modal@3.x:
version "3.5.1"
resolved "https://registry.yarnpkg.com/react-modal/-/react-modal-3.5.1.tgz#33d38527def90ea324848f7d63e53acc4468a451"
Expand All @@ -9109,6 +9139,10 @@ react-modal@3.x:
react-lifecycles-compat "^3.0.0"
warning "^3.0.0"

react-onclickoutside@^6.7.1:
version "6.7.1"
resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.7.1.tgz#6a5b5b8b4eae6b776259712c89c8a2b36b17be93"

react-popper@^1.0.0-beta.5:
version "1.0.0"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-1.0.0.tgz#b99452144e8fe4acc77fa3d959a8c79e07a65084"
Expand Down Expand Up @@ -9215,6 +9249,27 @@ react-stripe-elements@^1.4.1:
dependencies:
prop-types "^15.5.10"

react-text-selection-popover@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-text-selection-popover/-/react-text-selection-popover-1.1.0.tgz#45563f1d6a118affe60493884e9e2699310e046c"
dependencies:
lodash.debounce "^4.0.8"
react-event-listener "^0.6.1"
react-measure "^2.1.2"
react-window-dimensions "^1.0.2"
rollup-plugin-copy "^0.2.3"

react-text-selection-popover@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-text-selection-popover/-/react-text-selection-popover-1.2.0.tgz#7fe870d372f7e5994cb32931738bf4de77c2e9df"
dependencies:
invariant "^2.2.4"
lodash.debounce "^4.0.8"
react-event-listener "^0.6.1"
react-measure "^2.1.2"
react-window-dimensions "^1.0.2"
rollup-plugin-copy "^0.2.3"

react-textarea-autosize@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-6.1.0.tgz#df91387f8a8f22020b77e3833c09829d706a09a5"
Expand Down Expand Up @@ -9243,6 +9298,10 @@ react-visibility-sensor@^3.11.0:
create-react-class "^15.5.1"
prop-types "^15.5.4"

react-window-dimensions@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/react-window-dimensions/-/react-window-dimensions-1.0.2.tgz#94f9cd24e96152b4c706fc0590e87a0ece27d2a3"

react@*, react@^16.4.0:
version "16.4.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.4.1.tgz#de51ba5764b5dbcd1f9079037b862bd26b82fe32"
Expand Down Expand Up @@ -9648,6 +9707,10 @@ requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"

resize-observer-polyfill@^1.4.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/resize-observer-polyfill/-/resize-observer-polyfill-1.5.0.tgz#660ff1d9712a2382baa2cad450a4716209f9ca69"

resolve-cwd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-2.0.0.tgz#00a9f7387556e27038eae232caa372a6a59b665a"
Expand Down Expand Up @@ -9774,6 +9837,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"

rollup-plugin-copy@^0.2.3:
version "0.2.3"
resolved "https://registry.yarnpkg.com/rollup-plugin-copy/-/rollup-plugin-copy-0.2.3.tgz#dac1ab81d1f220baeb98e5c4c0108252e1edbb98"
dependencies:
colors "^1.1.2"
fs-extra "^3.0.0"

rsvp@^3.3.3:
version "3.6.2"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a"
Expand Down Expand Up @@ -10243,6 +10313,16 @@ spdy@^3.4.1:
select-hose "^2.0.0"
spdy-transport "^2.0.18"

spectrum-draft-js-inline-toolbar@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/spectrum-draft-js-inline-toolbar/-/spectrum-draft-js-inline-toolbar-0.2.2.tgz#f46550a55af947ec2e2545c1efdfc09a043c8a1c"
dependencies:
draft-js "^0.10.5"
draft-js-plugins-utils "^2.0.3"
prop-types "^15.6.2"
react-onclickoutside "^6.7.1"
react-text-selection-popover "^1.2.0"

split-lines@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/split-lines/-/split-lines-1.1.0.tgz#3abba8f598614142f9db8d27ab6ab875662a1e09"
Expand Down