How to use the draft-js.convertToRaw 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 LessWrong2 / Lesswrong2 / packages / lesswrong / components / async / EditorFormContainer.jsx View on Github external
onChange = (editorState) => {
    const {document, name} = this.props
    const currentContent = this.state.editorState.getCurrentContent()
    const newContent = editorState.getCurrentContent()

    if (currentContent !== newContent) {
      // Only save to localStorage on every 30th content change
      // TODO: Consider debouncing rather than saving every 30th change
      // TODO: Consider saving on blur
      this.changeCount = this.changeCount + 1;
      if (this.changeCount % 30 === 0) {
        const rawContent = convertToRaw(newContent);
        this.getStorageHandlers().set({state: rawContent, doc: document, name})
      }
    }
    this.setState({editorState: editorState})
    return editorState;
  }
github geosolutions-it / MapStore2 / web / client / components / geostory / contents / enhancers / editableText.jsx View on Github external
componentWillUnmount() {
                    const {editorState, save = () => {}} = this.props;
                    const blocks = convertToRaw(editorState.getCurrentContent()).blocks;
                    // it can happen that first block is empty, i.e. there is a carriage return
                    const rawText = blocks.length === 1 ? convertToRaw(editorState.getCurrentContent()).blocks[0].text : true;
                    const html = draftToHtml(convertToRaw(editorState.getCurrentContent()));
                    // when text written inside editor is "" then return EMPTY_CONTENT to manage placeholder outside
                    save(rawText ? html : EMPTY_CONTENT);
                }
            }),
github danielmahon / gatsby-starter-procyon / src / components / EditableMarkdown.js View on Github external
handleSave = ({ updateNode }) => () => {
    const { editorState } = this.state;
    const { node = {} } = this.props;
    const markdown = draftToMarkdown(
      convertToRaw(editorState.getCurrentContent())
    );
    this.setState({ source: markdown, originalEditorState: editorState });
    updateNode({ variables: { id: node.id, content: markdown } });
    console.log('Synced to GraphCMS');
  };
  render() {
github gkpty / torus_cms / src / Components / AddArticle.js View on Github external
handleAlternate(event) {
		var { editorState } = this.state;
		var html_body = editorState ? draftToHtml(convertToRaw(editorState.getCurrentContent())) : null;
		const section = 'articles'
		const articleVars = {
			sourceRoute: `public/${section}`,
			sourceObject: `${this.state.title}.html`,
			destRoute: `${section}`,
			delete: false,
		};
		//console.log(this.state.itemProps)	
		if (this.state.title === this.state.itemProps.title && this.state.itemProps.body_html ===  html_body) {
			publishArticle(articleVars);
		}
		else {
			alert('Error. Please Save your changes before publishing')
		}
		event.preventDefault();
	}
github LessWrong2 / Lesswrong2 / packages / lesswrong / components / async / AsyncCommentEditor.jsx View on Github external
const submitRawContentState = (data) => {
      data.content = convertToRaw(this.state.editorState.getCurrentContent())
      return data;
    }
    this.context.addToSubmitForm(submitRawContentState);
github plone / volto / src / components / manage / Blocks / Text / Edit.jsx View on Github external
onChange(editorState) {
    const shouldFilterPaste =
      editorState.getLastChangeType() === 'insert-fragment';

    if (
      !isEqual(
        convertToRaw(editorState.getCurrentContent()),
        convertToRaw(this.state.editorState.getCurrentContent()),
      )
    ) {
      if (shouldFilterPaste) {
        let filteredState = editorState;
        filteredState = filterEditorState(
          {
            blocks: [],
            styles: [],
            entities: [
              {
                type: 'LINK',
                attributes: ['url'],
              },
            ],
            whitespacedCharacters: [],
github fred8617 / react-form-builder-antd / src / component / FormBuilder / EditingContent / LabelEditor / index.jsx View on Github external
@action onEditorStateChange=(editorState)=>{
    const {
      store,
      store:{
        editingData:data,
        setEditingData
      }
    }=this.props;
    const label=draftToHtml(convertToRaw(editorState.getCurrentContent()))
    setEditingData(`label`,label);
    store.editorState=editorState;
  }
  render(){
github juliantrueflynn / slack_clone / frontend / util / editorUtil.jsx View on Github external
export const convertForSubmit = (editorState) => {
  const currentContent = editorState.getCurrentContent();
  const messageBody = convertToRaw(currentContent);
  return JSON.stringify(messageBody);
};
github fatman- / learn-draftjs / src / components / Examples / RichEditor / Editor.js View on Github external
onClick: () => {
								const contentState = this.state.editorState.getCurrentContent();
								this.props.consoleLog(JSON.stringify(convertToRaw(contentState), null, 4));
							},
							text: "Log Raw ContentState",
github plone / volto / src / components / manage / Blocks / Text / Edit.jsx View on Github external
onChange(editorState) {
    if (
      !isEqual(
        convertToRaw(editorState.getCurrentContent()),
        convertToRaw(this.state.editorState.getCurrentContent()),
      )
    ) {
      this.props.onChangeBlock(this.props.block, {
        ...this.props.data,
        text: convertToRaw(editorState.getCurrentContent()),
      });
    }
    this.setState({ editorState });
  }