This repository was archived by the owner on May 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +55
-27
lines changed
examples/undo-example/src Expand file tree Collapse file tree 3 files changed +55
-27
lines changed Original file line number Diff line number Diff line change 1+ // @flow
2+
13import React , { Component } from 'react'
24import { EditorState } from 'draft-js'
35
4- class RedoButton extends Component {
6+ type Props = {
7+ editorState : EditorState ,
8+ setEditorState : EditorState => void ,
9+ }
510
6- onClick = ( event ) => {
7- event . stopPropagation ( ) ;
8- this . props . setEditorState ( EditorState . redo ( this . props . editorState ) ) ;
9- } ;
11+ class RedoButton extends Component < Props > {
12+ onClick = event => {
13+ event . stopPropagation ( )
14+ this . props . setEditorState ( EditorState . redo ( this . props . editorState ) )
15+ }
1016
1117 render ( ) {
1218 return (
13- < button
14- disabled = { ! this . props . editorState || this . props . editorState . getRedoStack ( ) . isEmpty ( ) }
19+ < button
20+ disabled = {
21+ ! this . props . editorState ||
22+ this . props . editorState . getRedoStack ( ) . isEmpty ( )
23+ }
1524 type = "button"
16- onClick = { this . onClick }
17- > redo</ button >
25+ onClick = { this . onClick } >
26+ redo
27+ </ button >
1828 )
1929 }
2030}
2131
22- export default RedoButton
32+ export default RedoButton
Original file line number Diff line number Diff line change 1+ // @flow
2+
13import React , { Component } from 'react'
24import { EditorState } from 'draft-js'
35
4- class UndoButton extends Component {
6+ type Props = {
7+ editorState : EditorState ,
8+ setEditorState : EditorState => void ,
9+ }
510
6- onClick = ( event ) => {
7- event . stopPropagation ( ) ;
8- this . props . setEditorState ( EditorState . undo ( this . props . editorState ) ) ;
9- } ;
11+ class UndoButton extends Component < Props > {
12+ onClick = event => {
13+ event . stopPropagation ( )
14+ this . props . setEditorState ( EditorState . undo ( this . props . editorState ) )
15+ }
1016
1117 render ( ) {
1218 return (
13- < button
14- disabled = { ! this . props . editorState || this . props . editorState . getUndoStack ( ) . isEmpty ( ) }
19+ < button
20+ disabled = {
21+ ! this . props . editorState ||
22+ this . props . editorState . getUndoStack ( ) . isEmpty ( )
23+ }
1524 type = "button"
16- onClick = { this . onClick }
17- > undo</ button >
25+ onClick = { this . onClick } >
26+ undo
27+ </ button >
1828 )
1929 }
2030}
2131
22- export default UndoButton
32+ export default UndoButton
Original file line number Diff line number Diff line change 11import React , { Component , Fragment } from 'react'
22import ReactDOM from 'react-dom'
33
4- import { EditorState , ContentState } from 'draft-js'
4+ import { EditorState , ContentState } from 'draft-js'
55import { EditorContainer , Editor , Plugin } from '@djsp/core'
66import UndoButton from './UndoButton.js'
77import RedoButton from './RedoButton.js'
@@ -24,12 +24,20 @@ class App extends Component {
2424 < EditorContainer
2525 editorState = { this . state . editorState }
2626 onChange = { this . onChange } >
27- < Plugin > { ( { editorState, setEditorState } ) => (
28- < Fragment >
29- < UndoButton editorState = { editorState } setEditorState = { setEditorState } />
30- < RedoButton editorState = { editorState } setEditorState = { setEditorState } />
31- </ Fragment >
32- ) } </ Plugin >
27+ < Plugin >
28+ { ( { editorState, setEditorState } ) => (
29+ < Fragment >
30+ < UndoButton
31+ editorState = { editorState }
32+ setEditorState = { setEditorState }
33+ />
34+ < RedoButton
35+ editorState = { editorState }
36+ setEditorState = { setEditorState }
37+ />
38+ </ Fragment >
39+ ) }
40+ </ Plugin >
3341 < Editor />
3442 </ EditorContainer >
3543 </ div >
You can’t perform that action at this time.
0 commit comments