mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-03-06 13:59:47 +01:00
* rename state to value in slate core, as deprecation * rename all references to state to value in slate core * migrate slate-base64-serializer * migrate slate-html-serializer * migrate slate-hyperscript * migrate slate-plain-serializer * migrate slate-prop-types * migrate slate-simulator * fix change.setState compat * deprecate references to state in slate-react * remove all references to state in slate-react * remove `value` and `schema` from props to all components * fix default renderPlaceholder * fix tests * update examples * update walkthroughs * update guides * update reference
92 lines
1.5 KiB
JavaScript
92 lines
1.5 KiB
JavaScript
|
|
import { Editor } from 'slate-react'
|
|
import { Value } from 'slate'
|
|
|
|
import React from 'react'
|
|
import initialValue from './value.json'
|
|
|
|
/**
|
|
* The plain text example.
|
|
*
|
|
* @type {Component}
|
|
*/
|
|
|
|
class RTL 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 key down, if it's <shift-enter> add a soft break.
|
|
*
|
|
* @param {Event} event
|
|
* @param {Change} change
|
|
*/
|
|
|
|
onKeyDown = (event, change) => {
|
|
if (event.key == 'Enter' && event.shiftKey) {
|
|
event.preventDefault()
|
|
change.insertText('\n')
|
|
return true
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Render the editor.
|
|
*
|
|
* @return {Component} component
|
|
*/
|
|
|
|
render() {
|
|
return (
|
|
<div className="editor">
|
|
<Editor
|
|
placeholder="Enter some plain text..."
|
|
value={this.state.value}
|
|
onChange={this.onChange}
|
|
onKeyDown={this.onKeyDown}
|
|
renderNode={this.renderNode}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Render a Slate node.
|
|
*
|
|
* @param {Object} props
|
|
* @return {Element}
|
|
*/
|
|
|
|
renderNode = (props) => {
|
|
const { attributes, children, node } = props
|
|
switch (node.type) {
|
|
case 'block-quote': return <blockquote {...attributes}>{children}</blockquote>
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* Export.
|
|
*/
|
|
|
|
export default RTL
|