2016-07-28 15:38:17 -07:00
|
|
|
|
2017-09-11 18:11:45 -07:00
|
|
|
import { Editor } from 'slate-react'
|
2017-10-27 13:39:06 -07:00
|
|
|
import { Value } from 'slate'
|
2017-09-11 18:11:45 -07:00
|
|
|
|
2016-07-28 15:38:17 -07:00
|
|
|
import React from 'react'
|
|
|
|
import Video from './video'
|
2017-10-27 13:39:06 -07:00
|
|
|
import initialValue from './value.json'
|
2016-07-28 15:38:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The images example.
|
|
|
|
*
|
|
|
|
* @type {Component}
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Embeds extends React.Component {
|
|
|
|
|
|
|
|
/**
|
2017-10-27 13:39:06 -07:00
|
|
|
* Deserialize the raw initial value.
|
2016-07-28 15:38:17 -07:00
|
|
|
*
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
|
|
|
|
state = {
|
2017-10-27 13:39:06 -07:00
|
|
|
value: Value.fromJSON(initialValue)
|
2017-09-05 18:03:41 -07:00
|
|
|
}
|
2016-07-28 15:38:17 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On change.
|
|
|
|
*
|
2017-09-05 18:03:41 -07:00
|
|
|
* @param {Change} change
|
2016-07-28 15:38:17 -07:00
|
|
|
*/
|
|
|
|
|
2017-10-27 13:39:06 -07:00
|
|
|
onChange = ({ value }) => {
|
|
|
|
this.setState({ value })
|
2016-07-28 15:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Render the app.
|
|
|
|
*
|
|
|
|
* @return {Element} element
|
|
|
|
*/
|
|
|
|
|
2017-08-02 18:36:33 +02:00
|
|
|
render() {
|
2016-07-28 15:38:17 -07:00
|
|
|
return (
|
|
|
|
<div className="editor">
|
|
|
|
<Editor
|
2017-10-18 00:23:39 -07:00
|
|
|
placeholder="Enter some text..."
|
2017-10-27 13:39:06 -07:00
|
|
|
value={this.state.value}
|
2016-07-28 15:38:17 -07:00
|
|
|
onChange={this.onChange}
|
2017-10-25 17:32:29 -07:00
|
|
|
renderNode={this.renderNode}
|
2016-07-28 15:38:17 -07:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-10-25 17:32:29 -07:00
|
|
|
/**
|
|
|
|
* Render a Slate node.
|
|
|
|
*
|
|
|
|
* @param {Object} props
|
|
|
|
* @return {Element}
|
|
|
|
*/
|
|
|
|
|
|
|
|
renderNode = (props) => {
|
|
|
|
switch (props.node.type) {
|
|
|
|
case 'video': return <Video {...props} />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 15:38:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Export.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export default Embeds
|