Skip to content
This repository was archived by the owner on May 31, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,164 changes: 2,164 additions & 0 deletions examples/undo-example/README.md

Large diffs are not rendered by default.

12,113 changes: 12,113 additions & 0 deletions examples/undo-example/package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions examples/undo-example/package.json
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"
}
}
20 changes: 20 additions & 0 deletions examples/undo-example/public/index.html
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>
Copy link
Member

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 :)

</head>

<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>

<div id="root"></div>
</body>
</html>
32 changes: 32 additions & 0 deletions examples/undo-example/src/Undo/components/Redo.js
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
32 changes: 32 additions & 0 deletions examples/undo-example/src/Undo/components/Undo.js
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
22 changes: 22 additions & 0 deletions examples/undo-example/src/Undo/index.js
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 }
35 changes: 35 additions & 0 deletions examples/undo-example/src/index.js
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'))
14 changes: 14 additions & 0 deletions examples/undo-example/src/styles.css
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;
}