import { Value } from 'slate' import { Editor } from 'slate-react' import React from 'react' import initialValue from './value.json' /** * Toolbar button component. * * @type {Function} */ const ToolbarButton = props => ( {props.icon} ) /** * The history example. * * @type {Component} */ class History extends React.Component { /** * Deserialize the initial editor value. * * @type {Object} */ state = { value: Value.fromJSON(initialValue) } /** * On change. * * @param {Change} change */ onChange = ({ value }) => { this.setState({ value }) } /** * On redo in history. * */ onClickRedo = (event) => { event.preventDefault() const { value } = this.state const change = value.change().redo() this.onChange(change) } /** * On undo in history. * */ onClickUndo = (event) => { event.preventDefault() const { value } = this.state const change = value.change().undo() this.onChange(change) } /** * Render the editor. * * @return {Component} component */ render() { return (
{this.renderToolbar()} {this.renderEditor()}
) } /** * Render the toolbar. * * @return {Element} */ renderToolbar = () => { const { value } = this.state return (
Undos: {value.history.undos.size} Redos: {value.history.redos.size}
) } /** * Render the Slate editor. * * @return {Element} */ renderEditor = () => { return (
) } } /** * Export. */ export default History