1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-07 06:20:07 +01:00

update docs

This commit is contained in:
Ian Storm Taylor 2017-10-18 08:58:23 -07:00
parent 63855ed15c
commit c442e52ca6

@ -120,20 +120,24 @@ The `editor.change()` method will create a new [`Change`](../reference/slate/cha
### 3. From Schema Rules
The third place you may perform change operations for more complex use cases is from inside a custom [rule](../references/slate/schema.md#rules) in your editor's [`Schema`](../references/slate/schema.md). For example...
The third place you may perform change operations—for more complex use cases—is from inside a custom [rule](../references/slate/schema.md#rules) in your editor's [`Schema`](../references/slate/schema.md). For example...
```js
{
match: (object) => object.kind === 'block' && object.type === 'quote',
validate: (node) => {
const invalidChildren = node.filterDescendants(child => child.kind === 'block');
return invalidChildren.size ? invalidChildren : null;
match(obj) {
return obj.kind == 'block' && obj.type == 'quote',
},
normalize (change, node, invalidChildren) {
invalidChildren.forEach(child => {
change.removeNodeByKey(child.key);
});
validate(quote) {
const invalidChildren = quote.nodes.filter(n => n.kind != 'block')
if (!invalidChildren.size) return
return invalidChildren
},
normalize(change, quote, invalidChildren) {
invalidChildren.forEach((node) => {
change.removeNodeByKey(node.key)
})
},
}
```
When a rule's validation fails, Slate passes a [`Change`](../reference/slate/change.md) object to the `normalize()` method on the rule. You can use this object to apply the changes necessary to make your document valid on the next normalization pass.