How to use the draft-js.EditorState.createWithContent function in draft-js

To help you get started, we’ve selected a few draft-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github assembl / assembl / assembl / static2 / workspaces / assembl-test-editor-utils / src / index.js View on Github external
id: '1',
      mimeType: 'image/png',
      src: imgSrc,
      title: 'My image'
    });
    const imgEntityKey = contentState.getLastCreatedEntityKey();
    // $FlowFixMe DraftEntityType is too restrictive in DraftJS (see https://github.com/facebook/draft-js/issues/868 )
    contentState = contentState.createEntity(ENTITY_TYPES.document, ENTITY_MUTABILITY.immutable, {
      id: '2',
      mimeType: 'application/pdf',
      src: fileSrc,
      title: 'My document'
    });
    const docEntityKey = contentState.getLastCreatedEntityKey();

    let editorState = EditorState.createWithContent(contentState);
    editorState = AtomicBlockUtils.insertAtomicBlock(editorState, imgEntityKey, ' ');
    editorState = AtomicBlockUtils.insertAtomicBlock(editorState, docEntityKey, ' ');
    return editorState;
  },
github strues / boldr / packages / frontend / BoldrText / BoldrText.js View on Github external
contentFormat = contentFormat || 'raw';
    initialContent = initialContent || '';

    if (!initialContent) {
      initialEditorState = EditorState.createEmpty(editorDecorators);
    } else {
      let convertedContent;

      if (contentFormat === 'html') {
        convertedContent = convertFromHTML(getFromHTMLConfig())(initialContent);
      } else if (contentFormat === 'raw') {
        convertedContent = convertFromRaw(initialContent);
      }

      initialEditorState = EditorState.createWithContent(convertedContent, editorDecorators);
    }
    // $FlowIssue
    this.readyForSync = true;

    this.state = {
      editorState: initialEditorState,
      editorProps: {},
    };
  }
  state: State;
github LessWrong2 / Lesswrong2 / .draft-js-plugins / docs / client / components / pages / Video / CustomVideoEditor / index.js View on Github external
{
      "key": "7bvko",
      "text": "",
      "type": "unstyled",
      "depth": 0,
      "inlineStyleRanges": [],
      "entityRanges": [],
      "data": {}
    }
  ]
};
/* eslint-enable */
export default class CustomVideoEditor extends Component {

  state = {
    editorState: EditorState.createWithContent(convertFromRaw(initialState)),
  };

  onChange = (editorState) => {
    this.setState({
      editorState,
    });
  };

  focus = () => {
    this.editor.focus();
  };

  render() {
    return (
      <div>
        </div>
github bbc / react-transcript-editor / src / lib / TranscriptEditor / TimedTextEditor / TimedTextEditor.js View on Github external
const entityRanges = blocks.map(block => block.entityRanges);
      const flatEntityRanges = flatten(entityRanges);
      
      const entityMap = {};

      flatEntityRanges.forEach((data) => {
        entityMap[data.key] = {
            type: "WORD",
            mutability: "MUTABLE",
            data
          }
      });
     
      const contentState = convertFromRaw({ blocks, entityMap });

      const editorState = EditorState.createWithContent(
        contentState,
        decorator
      );

      this.setState({ editorState });
    }
  }
github NDLANO / learningpath-frontend / src / common / editors / OneLineEditor.js View on Github external
constructor(props) {
    super(props);

    const { maxlength, input: { value } } = props;
    const editorState = value ? EditorState.createWithContent(ContentState.createFromText(value)) : EditorState.createEmpty();
    this.state = { editorState };

    this.handleReturn = () => {
      this.editor.blur();
      return true;
    };
    this.handleReturn = this.handleReturn.bind(this);

    this.handleBeforeInput = () => false;

    if (maxlength >= 0) {
      this.handleBeforeInput = () => {
        const plainText = this.state.editorState.getCurrentContent().getPlainText();
        return plainText.length >= maxlength;
      };
    }
github gzwgq222 / blog-admin / src / pages / admin / article / item.js View on Github external
async getDetail (id) {
    const {code, data} = await api.get('/article/item', {id})
    if (code !== 1000) return false
    const { title, author, summary, category, tag, content } = data
    this.props.form.setFieldsValue({title, author, summary, category, tag})
    const contentBlock = htmlToDraft(content)
    const contentState = ContentState.createFromBlockArray(contentBlock.contentBlocks)
    const editorState = EditorState.createWithContent(contentState)
    this.setState({ editorState })
  }
github idyll-lang / idyll / packages / idyll-editor / src / editor.js View on Github external
constructor(props) {
    super(props);
    this.state = {
      editorState: EditorState.createWithContent(ContentState.createFromText(props.initialValue))
    }
    this.handleChange = this.handleChange.bind(this);
  }
github Kozea / formol / src / utils / html.js View on Github external
export const HTMLToEditor = html =>
  EditorState.createWithContent(fromHTML(html))
github projectOpenRAP / OpenRAP / devmgmtui / src / components / captive / Captive.js View on Github external
this.props.getCurrentCaptivePortal((res) => {
        let newHtmlBlock = convertFromHTML(res);
        let newHtmlContent = ContentState.createFromBlockArray(newHtmlBlock.contentBlocks, newHtmlBlock.entityMap);
        this.setState({editorState : EditorState.createWithContent(newHtmlContent)});
      })
    }