1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +02:00
This commit is contained in:
Ian Storm Taylor
2016-08-14 13:21:46 -07:00
parent dbcb9e531f
commit ccac6102a5
34 changed files with 260 additions and 557 deletions

View File

@@ -7,20 +7,22 @@ import isImage from 'is-image'
import isUrl from 'is-url'
/**
* Define a set of node renderers.
* Define a schema.
*
* @type {Object}
*/
const NODES = {
image: (props) => {
const { node, state } = props
const isFocused = state.selection.hasEdgeIn(node)
const src = node.data.get('src')
const className = isFocused ? 'active' : null
return (
<img src={src} className={className} {...props.attributes} />
)
const schema = {
nodes: {
image: (props) => {
const { node, state } = props
const isFocused = state.selection.hasEdgeIn(node)
const src = node.data.get('src')
const className = isFocused ? 'active' : null
return (
<img src={src} className={className} {...props.attributes} />
)
}
}
}
@@ -83,8 +85,8 @@ class Images extends React.Component {
return (
<div className="editor">
<Editor
schema={schema}
state={this.state.state}
renderNode={this.renderNode}
onChange={this.onChange}
onDocumentChange={this.onDocumentChange}
onDrop={this.onDrop}
@@ -94,17 +96,6 @@ class Images extends React.Component {
)
}
/**
* Render a `node`.
*
* @param {Node} node
* @return {Element}
*/
renderNode = (node) => {
return NODES[node.type]
}
/**
* On change.
*