1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 05:49:47 +01:00
slate/examples/rtl/index.js

87 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-07-29 12:05:01 -07:00
import { Editor, Raw } from '../..'
import React from 'react'
import initialState from './state.json'
/**
2016-08-14 13:21:46 -07:00
* Define a schema.
2016-07-29 12:05:01 -07:00
*
* @type {Object}
*/
2016-08-14 13:21:46 -07:00
const schema = {
nodes: {
2017-02-25 10:13:21 -08:00
'block-quote': props => <blockquote {...props.attributes}>{props.children}</blockquote>,
2016-08-14 13:21:46 -07:00
}
2016-07-29 12:05:01 -07:00
}
/**
* The plain text example.
*
* @type {Component}
*/
class PlainText extends React.Component {
/**
* Deserialize the initial editor state.
*
* @type {Object}
*/
state = {
state: Raw.deserialize(initialState, { terse: true })
};
/**
* On change.
*
* @param {Change} change
2016-07-29 12:05:01 -07:00
*/
onChange = ({ state }) => {
2016-07-29 12:05:01 -07:00
this.setState({ state })
}
/**
* On key down, if it's <shift-enter> add a soft break.
*
* @param {Event} e
* @param {Object} data
* @param {Change} change
*/
onKeyDown = (e, data, change) => {
if (data.key == 'enter' && data.isShift) {
e.preventDefault()
change.insertText('\n')
return true
}
}
2016-07-29 12:05:01 -07:00
/**
* Render the editor.
*
* @return {Component} component
*/
2017-08-02 18:36:33 +02:00
render() {
2016-07-29 12:05:01 -07:00
return (
<Editor
placeholder={'Enter some plain text...'}
2016-08-14 13:21:46 -07:00
schema={schema}
state={this.state.state}
2016-07-29 12:05:01 -07:00
onChange={this.onChange}
onKeyDown={this.onKeyDown}
2016-07-29 12:05:01 -07:00
/>
)
}
}
/**
* Export.
*/
export default PlainText