mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-12 02:03:59 +02:00
Merge branch 'master' of github.com:ianstormtaylor/slate
This commit is contained in:
@@ -9,19 +9,19 @@ This is the full reference documentation for all of the pieces of Slate, broken
|
|||||||
- **Models**
|
- **Models**
|
||||||
- [Block](./models/block.md)
|
- [Block](./models/block.md)
|
||||||
- [Character](./models/character.md)
|
- [Character](./models/character.md)
|
||||||
- [Data](./data.md)
|
- [Data](./models/data.md)
|
||||||
- [Document](./models/document.md)
|
- [Document](./models/document.md)
|
||||||
- [Inline](./models/inline.md)
|
- [Inline](./models/inline.md)
|
||||||
- [Mark](./models/mark.md)
|
- [Mark](./models/mark.md)
|
||||||
- [Node](./models/node.md)
|
- [Node](./models/node.md)
|
||||||
- [Selection](./models/selection.md)
|
- [Selection](./models/selection.md)
|
||||||
- [State](./models/state.md)
|
- [State](./models/state.md)
|
||||||
- [Text](./text.md)
|
- [Text](./models/text.md)
|
||||||
- [Transform](./models/transform.md)
|
- [Transform](./models/transform.md)
|
||||||
- **Serializers**
|
- **Serializers**
|
||||||
- [Html](./html.md)
|
- [Html](./serializers/html.md)
|
||||||
- [Plain](./plain.md)
|
- [Plain](./serializers/plain.md)
|
||||||
- [Raw](./raw.md)
|
- [Raw](./serializers/raw.md)
|
||||||
- **Plugins**
|
- **Plugins**
|
||||||
- [Plugins](./plugins/plugins.md)
|
- [Plugins](./plugins/plugins.md)
|
||||||
- [Core](./plugins/core.md)
|
- [Core](./plugins/core.md)
|
||||||
|
@@ -17,7 +17,7 @@ const DEFAULT_NODE = 'paragraph'
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const NODES = {
|
const NODES = {
|
||||||
'block-quote': props => <blockquote {...props.attributes}>{props.children}</blockquote>,
|
'block-quote': (props) => <blockquote {...props.attributes}>{props.children}</blockquote>,
|
||||||
'bulleted-list': props => <ul {...props.attributes}>{props.children}</ul>,
|
'bulleted-list': props => <ul {...props.attributes}>{props.children}</ul>,
|
||||||
'heading-one': props => <h1 {...props.attributes}>{props.children}</h1>,
|
'heading-one': props => <h1 {...props.attributes}>{props.children}</h1>,
|
||||||
'heading-two': props => <h2 {...props.attributes}>{props.children}</h2>,
|
'heading-two': props => <h2 {...props.attributes}>{props.children}</h2>,
|
||||||
|
@@ -824,16 +824,40 @@ const Node = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map all children nodes, updating them in their parents.
|
* Map all child nodes, updating them in their parents. This method is
|
||||||
|
* optimized to not return a new node if no changes are made.
|
||||||
|
*
|
||||||
|
* @param {Function} iterator
|
||||||
|
* @return {Node} node
|
||||||
|
*/
|
||||||
|
|
||||||
|
mapChildren(iterator) {
|
||||||
|
let nodes = this.nodes
|
||||||
|
|
||||||
|
nodes.forEach((node, i) => {
|
||||||
|
let ret = iterator(node, i, this.nodes)
|
||||||
|
if (ret != node) nodes = nodes.set(ret.key, ret)
|
||||||
|
})
|
||||||
|
|
||||||
|
return this.merge({ nodes })
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map all descendant nodes, updating them in their parents. This method is
|
||||||
|
* optimized to not return a new node if no changes are made.
|
||||||
*
|
*
|
||||||
* @param {Function} iterator
|
* @param {Function} iterator
|
||||||
* @return {Node} node
|
* @return {Node} node
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mapDescendants(iterator) {
|
mapDescendants(iterator) {
|
||||||
const nodes = this.nodes.map((node, i, original) => {
|
let nodes = this.nodes
|
||||||
if (node.kind != 'text') node = node.mapDescendants(iterator)
|
|
||||||
return iterator(node, i, original)
|
nodes.forEach((node, i) => {
|
||||||
|
let ret = node
|
||||||
|
if (ret.kind != 'text') ret = ret.mapDescendants(iterator)
|
||||||
|
ret = iterator(ret, i, this.nodes)
|
||||||
|
if (ret != node) nodes = nodes.set(ret.key, ret)
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.merge({ nodes })
|
return this.merge({ nodes })
|
||||||
@@ -952,12 +976,7 @@ const Node = {
|
|||||||
return this.merge({ nodes })
|
return this.merge({ nodes })
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodes = this.nodes.map((node) => {
|
const nodes = this.mapChildren(n => n.kind == 'text' ? n : n.removeDescendant(key))
|
||||||
return node.kind == 'text'
|
|
||||||
? node
|
|
||||||
: node.removeDescendant(key)
|
|
||||||
})
|
|
||||||
|
|
||||||
return this.merge({ nodes })
|
return this.merge({ nodes })
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -970,19 +989,7 @@ const Node = {
|
|||||||
|
|
||||||
updateDescendant(node) {
|
updateDescendant(node) {
|
||||||
this.assertHasDescendant(node)
|
this.assertHasDescendant(node)
|
||||||
|
return this.mapDescendants(d => d.key == node.key ? node : d)
|
||||||
if (this.hasChild(node)) {
|
|
||||||
const nodes = this.nodes.map(child => child.key == node.key ? node : child)
|
|
||||||
return this.merge({ nodes })
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodes = this.nodes.map((child) => {
|
|
||||||
if (child.kind == 'text') return child
|
|
||||||
if (!child.hasDescendant(node)) return child
|
|
||||||
return child.updateDescendant(node)
|
|
||||||
})
|
|
||||||
|
|
||||||
return this.merge({ nodes })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -38,6 +38,13 @@ function Plugin(options = {}) {
|
|||||||
state: React.PropTypes.object.isRequired
|
state: React.PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
shouldComponentUpdate = (props, state) => {
|
||||||
|
return (
|
||||||
|
props.node != this.props.node ||
|
||||||
|
props.state.selection.hasEdgeIn(props.node)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
const { attributes, children } = this.props
|
const { attributes, children } = this.props
|
||||||
return (
|
return (
|
||||||
@@ -80,6 +87,13 @@ function Plugin(options = {}) {
|
|||||||
state: React.PropTypes.object.isRequired
|
state: React.PropTypes.object.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
shouldComponentUpdate = (props, state) => {
|
||||||
|
return (
|
||||||
|
props.node != this.props.node ||
|
||||||
|
props.state.selection.hasEdgeIn(props.node)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
const { attributes, children } = this.props
|
const { attributes, children } = this.props
|
||||||
return <span {...attributes}>{children}</span>
|
return <span {...attributes}>{children}</span>
|
||||||
|
Reference in New Issue
Block a user