This repository was archived by the owner on May 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add undo example #45
Merged
Merged
Add undo example #45
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1eb6e7a
add example for undo and redo
freedomlang 4cb24a6
add flowtype and fix lint error
freedomlang ea901bc
style: remove unnecessary styles
freedomlang 2d54161
chore(undo-example): bump version and update homepage in package.json
freedomlang 78d89ba
optimize structure for undo-example
freedomlang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "@djsp/undo-example", | ||
| "homepage": "https://github.com/draft-js-plugins/next#readme", | ||
| "version": "0.1.5", | ||
| "private": true, | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "@djsp/core": "^0.1.5", | ||
| "react": "^16.2.0", | ||
| "react-dom": "^16.2.0", | ||
| "react-scripts": "^1.1.1" | ||
| }, | ||
| "scripts": { | ||
| "start": "react-scripts start", | ||
| "build": "react-scripts build", | ||
| "test": "react-scripts test --env=jsdom", | ||
| "eject": "react-scripts eject" | ||
| }, | ||
| "devDependencies": { | ||
| "draft-js": "^0.10.5" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
| <meta name="theme-color" content="#000000"> | ||
|
|
||
| <link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
|
|
||
| <title>@djsp/suggestions</title> | ||
| </head> | ||
|
|
||
| <body> | ||
| <noscript> | ||
| You need to enable JavaScript to run this app. | ||
| </noscript> | ||
|
|
||
| <div id="root"></div> | ||
| </body> | ||
| </html> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // @flow | ||
|
|
||
| import React, { Component } from 'react' | ||
| import { EditorState } from 'draft-js' | ||
|
|
||
| type Props = { | ||
| editorState: EditorState, | ||
| setEditorState: EditorState => void, | ||
| } | ||
|
|
||
| class Redo extends Component<Props> { | ||
| onClick = event => { | ||
| event.stopPropagation() | ||
| this.props.setEditorState(EditorState.redo(this.props.editorState)) | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <button | ||
| disabled={ | ||
| !this.props.editorState || | ||
| this.props.editorState.getRedoStack().isEmpty() | ||
| } | ||
| type="button" | ||
| onClick={this.onClick}> | ||
| redo | ||
| </button> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Redo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // @flow | ||
|
|
||
| import React, { Component } from 'react' | ||
| import { EditorState } from 'draft-js' | ||
|
|
||
| type Props = { | ||
| editorState: EditorState, | ||
| setEditorState: EditorState => void, | ||
| } | ||
|
|
||
| class Undo extends Component<Props> { | ||
| onClick = event => { | ||
| event.stopPropagation() | ||
| this.props.setEditorState(EditorState.undo(this.props.editorState)) | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <button | ||
| disabled={ | ||
| !this.props.editorState || | ||
| this.props.editorState.getUndoStack().isEmpty() | ||
| } | ||
| type="button" | ||
| onClick={this.onClick}> | ||
| undo | ||
| </button> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| export default Undo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import React from 'react' | ||
| import { Plugin } from '@djsp/core' | ||
| import Redo from './components/Redo' | ||
| import Undo from './components/Undo' | ||
|
|
||
| const RedoButton = () => ( | ||
| <Plugin> | ||
| {({ editorState, setEditorState }) => ( | ||
| <Redo editorState={editorState} setEditorState={setEditorState} /> | ||
| )} | ||
| </Plugin> | ||
| ) | ||
|
|
||
| const UndoButton = () => ( | ||
| <Plugin> | ||
| {({ editorState, setEditorState }) => ( | ||
| <Undo editorState={editorState} setEditorState={setEditorState} /> | ||
| )} | ||
| </Plugin> | ||
| ) | ||
|
|
||
| export { RedoButton, UndoButton } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import React, { Component } from 'react' | ||
| import ReactDOM from 'react-dom' | ||
|
|
||
| import { EditorState, ContentState } from 'draft-js' | ||
| import { EditorContainer, Editor } from '@djsp/core' | ||
| import { RedoButton, UndoButton } from './Undo' | ||
| import './styles.css' | ||
|
|
||
| class App extends Component { | ||
| state = { | ||
| editorState: EditorState.createWithContent( | ||
| ContentState.createFromText( | ||
| 'Just type something and click the undo and redo button!' | ||
| ) | ||
| ), | ||
| } | ||
|
|
||
| onChange = editorState => this.setState({ editorState }) | ||
|
|
||
| render() { | ||
| return ( | ||
| <div> | ||
| <EditorContainer | ||
| editorState={this.state.editorState} | ||
| onChange={this.onChange}> | ||
| <RedoButton /> | ||
| <UndoButton /> | ||
| <Editor /> | ||
| </EditorContainer> | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| ReactDOM.render(<App />, document.getElementById('root')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| body { | ||
| font-family: sans-serif; | ||
| font-size: 1.8em; | ||
| padding: 1em; | ||
| background: #12312e; | ||
| } | ||
|
|
||
| .public-DraftEditor-content { | ||
| padding: 2em; | ||
| border-radius: 5px; | ||
| color: #fff; | ||
| border: #555; | ||
| background: #244a46; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes that'd be good to change :)