From e98e91e39bb0162eab2a2e2ab123e1b5b4a03151 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Mon, 6 Aug 2018 14:42:05 -0700 Subject: [PATCH] 3/n Splitting PR #1828: updates to the Rich Text Editor example (#1828) Summary: Splitting up this PR and updating it as I do. This piece was an update to the Rich Text Editor example. This is directly taken from mitermayer 's fork, props to him Pull Request resolved: https://github.com/facebook/draft-js/pull/1828 Reviewed By: mitermayer Differential Revision: D9181983 Pulled By: mitermayer fbshipit-source-id: aa2b66cb87123f96c3cd9cde19eb0fa86ff47c51 --- .../playground/src/DraftJsRichEditorExample.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/draft-0-10-0/playground/src/DraftJsRichEditorExample.js b/examples/draft-0-10-0/playground/src/DraftJsRichEditorExample.js index 6c05ca8b3e..9dc16d42fb 100644 --- a/examples/draft-0-10-0/playground/src/DraftJsRichEditorExample.js +++ b/examples/draft-0-10-0/playground/src/DraftJsRichEditorExample.js @@ -9,8 +9,15 @@ import React, {Component} from 'react'; import {Editor, RichUtils, getDefaultKeyBinding} from 'draft-js'; +import gkx from 'draft-js/lib/gkx'; +import NestedRichTextEditorUtil from 'draft-js/lib/NestedRichTextEditorUtil'; + import './DraftJsRichEditorExample.css'; +const RichTextUtils = gkx('draft_tree_data_support') + ? NestedRichTextEditorUtil + : RichUtils; + class DraftJsRichEditorExample extends Component { constructor(props) { super(props); @@ -23,7 +30,7 @@ class DraftJsRichEditorExample extends Component { } _handleKeyCommand(command, editorState) { - const newState = RichUtils.handleKeyCommand(editorState, command); + const newState = RichTextUtils.handleKeyCommand(editorState, command); if (newState) { this.onChange(newState); return true; @@ -33,7 +40,7 @@ class DraftJsRichEditorExample extends Component { _mapKeyToEditorCommand(e) { if (e.keyCode === 9 /* TAB */) { - const newEditorState = RichUtils.onTab( + const newEditorState = RichTextUtils.onTab( e, this.props.editorState, 4 /* maxDepth */, @@ -47,12 +54,14 @@ class DraftJsRichEditorExample extends Component { } _toggleBlockType(blockType) { - this.onChange(RichUtils.toggleBlockType(this.props.editorState, blockType)); + this.onChange( + RichTextUtils.toggleBlockType(this.props.editorState, blockType), + ); } _toggleInlineStyle(inlineStyle) { this.onChange( - RichUtils.toggleInlineStyle(this.props.editorState, inlineStyle), + RichTextUtils.toggleInlineStyle(this.props.editorState, inlineStyle), ); }