// @flow import React from 'react'; import { Link } from 'react-router-dom'; import Highlight, { defaultProps } from 'prism-react-renderer'; import { Line, Paragraph, BlockQuote } from 'src/components/message/style'; import { AspectRatio, EmbedContainer, EmbedComponent, } from 'src/components/rich-text-editor/style'; import ThreadAttachment from 'src/components/message/threadAttachment'; import { getStringElements } from '../utils/getStringElements'; import { hasStringElements } from '../utils/hasStringElements'; import mentionsDecorator from '../mentions-decorator'; import linksDecorator from '../links-decorator'; import type { Node } from 'react'; import { SPECTRUM_URLS } from 'shared/regexps'; import type { KeyObj, KeysObj, DataObj } from '../message/types'; import type { EmbedData, ExternalEmbedData, InternalEmbedData, } from '../../../draft-utils/add-embeds-to-draft-js'; const ExternalEmbed = (props: { ...ExternalEmbedData, src?: string }) => { let { aspectRatio, url, src, width = '100%', height = 200 } = props; if (!src && url) src = url; if (typeof src !== 'string') 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 ( ); } }; const InternalEmbed = (props: InternalEmbedData) => { if (props.entity !== 'thread') return null; return ; }; const Embed = (props: EmbedData) => { if (props.type === 'internal') { return ; } return ; }; const EMPTY_THEME = { plain: {}, styles: [], }; type Options = { headings: boolean, }; export const createRenderer = (options: Options) => { return { 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) => { // If the children are text, render a paragraph if (hasStringElements(children)) { return children.map((child, index) => ( {child} )); } return children; }, 'code-block': (children: Array, { keys, data }: KeysObj) => { return children.map((child, index) => ( {({ className, style, tokens, getLineProps, getTokenProps }) => ( {tokens.map((line, i) => ( {line.map((token, key) => ( ))} ))} )} )); }, blockquote: (children: Array, { keys }: KeysObj) => children.map((child, index) => ( {child} )), ...(!options.headings ? {} : { 'header-one': (children: Array, { keys }: KeysObj) => children.map((child, index) => ( {child} )), 'header-two': (children: Array, { keys }: KeysObj) => children.map((child, index) => ( {child} )), 'header-three': (children: Array, { keys }: KeysObj) => children.map((child, index) => ( {child} )), }), 'unordered-list-item': (children: Array, { keys }: KeysObj) => ( {children.map((child, index) => ( {child} ))} ), 'ordered-list-item': (children: Array, { keys }: KeysObj) => ( {children.map((child, index) => ( {child} ))} ), }, entities: { LINK: (children: Array, data: DataObj, { key }: KeyObj) => { const link = data.url || data.href; if (link) { const regexp = new RegExp(SPECTRUM_URLS, 'ig'); const match = regexp.exec(link); if (match && match[0] && match[1]) { return {children}; } } return ( {children} ); }, IMAGE: ( children: Array, data: { src?: string, alt?: string }, { key }: KeyObj ) => , embed: (children: Array, data: Object, { key }: KeyObj) => ( ), }, decorators: [mentionsDecorator, linksDecorator], }; };
{children}
{child}