From 11000670f93c9490ef152fb83196dec774ebab70 Mon Sep 17 00:00:00 2001 From: Max Stoiber Date: Tue, 12 Feb 2019 13:51:03 +0100 Subject: [PATCH 01/35] Create first prototype thread renderer --- shared/clients/draft-js/thread/renderer.js | 64 ++++++++++++++++++++++ src/components/composer/index.js | 12 ++-- 2 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 shared/clients/draft-js/thread/renderer.js diff --git a/shared/clients/draft-js/thread/renderer.js b/shared/clients/draft-js/thread/renderer.js new file mode 100644 index 0000000000..393a2b6c42 --- /dev/null +++ b/shared/clients/draft-js/thread/renderer.js @@ -0,0 +1,64 @@ +// @flow +import React from 'react'; +import { Line, Paragraph, BlockQuote } from 'src/components/message/style'; +import type { Node } from 'react'; +import type { KeyObj, KeysObj, DataObj } from '../message/types'; + +const threadRenderer = { + inline: { + BOLD: (children: Array, { key }: KeyObj) => ( + + {children} + + ), + ITALIC: (children: Array, { key }: KeyObj) => ( + {children} + ), + CODE: (children: Array, { key }: KeyObj) => ( + {children} + ), + }, + blocks: { + unstyled: (children: Array, { keys }: KeysObj) => + children.map((child, index) => ( + {child} + )), + 'code-block': (children: Array, { keys }: KeysObj) => ( + + {children.map((child, i) => [child,
])} +
+ ), + blockquote: (children: Array, { keys }: KeysObj) => + children.map((child, index) => ( +
{child}
+ )), + 'header-one': (children: Array) => + children.map(child =>

{child}

), + 'header-two': (children: Array) => + children.map(child =>

{child}

), + 'unordered-list-item': (children: Array, { depth, keys }) => ( +
    + {children.map((child, index) => ( +
  • {child}
  • + ))} +
+ ), + 'ordered-list-item': (children: Array, { depth, keys }) => ( +
    + {children.map((child, index) => ( +
  1. {child}
  2. + ))} +
+ ), + }, + entities: { + LINK: (children: Array, data: DataObj, { key }: KeyObj) => ( + + {children} + + ), + }, + // decorators: [mentionsDecorator, linksDecorator], +}; + +export default threadRenderer; diff --git a/src/components/composer/index.js b/src/components/composer/index.js index 76ca385564..8d1ea7d56e 100644 --- a/src/components/composer/index.js +++ b/src/components/composer/index.js @@ -9,6 +9,7 @@ import debounce from 'debounce'; import queryString from 'query-string'; import { KeyBindingUtil } from 'draft-js'; import Dropzone from 'react-dropzone'; +import redraft from 'redraft'; import Icon from '../icons'; import processThreadContent from 'shared/draft-utils/process-thread-content'; import { ThreadHeading } from 'src/views/thread/style'; @@ -64,6 +65,7 @@ import { sortChannels, getDefaultActiveChannel, } from './utils'; +import threadRenderer from 'shared/clients/draft-js/thread/renderer'; import { events, track } from 'src/helpers/analytics'; import { ESC, ENTER } from 'src/helpers/keycodes'; @@ -701,12 +703,12 @@ class ComposerWithData extends Component { /* $FlowFixMe */
{this.state.title} - {/* $FlowFixMe */} - + {redraft( + JSON.parse(processThreadContent('TEXT', this.state.body)), + threadRenderer )} - /> +
) : ( Date: Tue, 12 Feb 2019 14:02:46 +0100 Subject: [PATCH 02/35] Create ThreadRenderer component --- src/components/composer/index.js | 12 +++++------- src/components/threadRenderer/index.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 src/components/threadRenderer/index.js diff --git a/src/components/composer/index.js b/src/components/composer/index.js index 8d1ea7d56e..2a2886c46a 100644 --- a/src/components/composer/index.js +++ b/src/components/composer/index.js @@ -9,13 +9,13 @@ import debounce from 'debounce'; import queryString from 'query-string'; import { KeyBindingUtil } from 'draft-js'; import Dropzone from 'react-dropzone'; -import redraft from 'redraft'; import Icon from '../icons'; import processThreadContent from 'shared/draft-utils/process-thread-content'; import { ThreadHeading } from 'src/views/thread/style'; import Editor from 'src/components/rich-text-editor'; import Image from 'src/components/rich-text-editor/Image'; import { SegmentedControl, Segment } from 'src/components/segmentedControl'; +import ThreadRenderer from '../threadRenderer'; import { closeComposer } from '../../actions/composer'; import { changeActiveThread } from '../../actions/dashboardFeed'; import { addToastWithTimeout } from '../../actions/toasts'; @@ -65,7 +65,6 @@ import { sortChannels, getDefaultActiveChannel, } from './utils'; -import threadRenderer from 'shared/clients/draft-js/thread/renderer'; import { events, track } from 'src/helpers/analytics'; import { ESC, ENTER } from 'src/helpers/keycodes'; @@ -703,12 +702,11 @@ class ComposerWithData extends Component { /* $FlowFixMe */
{this.state.title} -
- {redraft( - JSON.parse(processThreadContent('TEXT', this.state.body)), - threadRenderer + + />
) : ( ( +
{redraft(props.body, threadRenderer)}
+); From 1e1f16792faabf09e0923671d069f23512bba6ca Mon Sep 17 00:00:00 2001 From: Max Stoiber Date: Tue, 12 Feb 2019 14:17:00 +0100 Subject: [PATCH 03/35] Add embed support to thread renderer --- shared/clients/draft-js/thread/renderer.js | 68 +++++++++++++++++++--- src/components/threadRenderer/index.js | 7 ++- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/shared/clients/draft-js/thread/renderer.js b/shared/clients/draft-js/thread/renderer.js index 393a2b6c42..e691302caa 100644 --- a/shared/clients/draft-js/thread/renderer.js +++ b/shared/clients/draft-js/thread/renderer.js @@ -1,9 +1,56 @@ // @flow import React from 'react'; import { Line, Paragraph, BlockQuote } from 'src/components/message/style'; +import { + AspectRatio, + EmbedContainer, + EmbedComponent, +} from 'src/components/rich-text-editor/style'; import type { Node } from 'react'; import type { KeyObj, KeysObj, DataObj } from '../message/types'; +type EmbedProps = { + aspectRatio?: string, + src: string, + width?: string | number, + height?: string | number, +}; + +const Embed = (props: EmbedProps) => { + const { aspectRatio, src, width = '100%', height = 200 } = props; + + if (!src) return null; + + // if an aspect ratio is passed in, we need to use the EmbedComponent which does some trickery with padding to force an aspect ratio. Otherwise we should just use a regular iFrame + if (aspectRatio && aspectRatio !== undefined) { + return ( + + + + ); + } else { + return ( + +