mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-25 09:43:21 +01:00
update schema
This commit is contained in:
parent
2ed1efbdd4
commit
bd26153dfb
@ -94,7 +94,7 @@ export function deleteAtRange(transform, range) {
|
||||
|
||||
const lonely = document.getFurthest(endBlock, p => p.nodes.size == 1) || endBlock
|
||||
transform.removeNodeByKey(lonely.key)
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -269,7 +269,7 @@ export function insertBlockAtRange(transform, range, block) {
|
||||
transform.insertNodeByKey(parent.key, index + 1, block)
|
||||
}
|
||||
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -352,7 +352,7 @@ export function insertFragmentAtRange(transform, range, fragment) {
|
||||
})
|
||||
}
|
||||
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -386,7 +386,7 @@ export function insertInlineAtRange(transform, range, inline) {
|
||||
|
||||
transform.splitNodeByKey(startKey, startOffset)
|
||||
transform.insertNodeByKey(parent.key, index + 1, inline)
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -523,7 +523,7 @@ export function splitBlockAtRange(transform, range, height = 1) {
|
||||
}
|
||||
|
||||
transform.splitNodeByKey(node.key, offset)
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -672,7 +672,7 @@ export function unwrapBlockAtRange(transform, range, properties) {
|
||||
}
|
||||
})
|
||||
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -714,7 +714,7 @@ export function unwrapInlineAtRange(transform, range, properties) {
|
||||
})
|
||||
})
|
||||
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
@ -879,7 +879,7 @@ export function wrapInlineAtRange(transform, range, inline) {
|
||||
})
|
||||
}
|
||||
|
||||
transform.normalizeDocument()
|
||||
transform.normalize()
|
||||
return transform
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,7 @@ import {
|
||||
*/
|
||||
|
||||
import {
|
||||
normalize,
|
||||
normalizeDocument,
|
||||
normalizeSelection,
|
||||
} from './normalize'
|
||||
@ -282,6 +283,7 @@ export default {
|
||||
* Normalize.
|
||||
*/
|
||||
|
||||
normalize,
|
||||
normalizeDocument,
|
||||
normalizeSelection,
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
import Schema from '../models/schema'
|
||||
|
||||
/**
|
||||
* Only allow block nodes in documents.
|
||||
*
|
||||
@ -60,18 +62,51 @@ const INLINE_CHILDREN_RULE = {
|
||||
}
|
||||
|
||||
/**
|
||||
* The default schema.
|
||||
* Join adjacent text nodes.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
|
||||
const SCHEMA = {
|
||||
const NO_ADJACENT_TEXT_RULE = {
|
||||
match: (object) => {
|
||||
return object.kind == 'block' || object.kind == 'inline'
|
||||
},
|
||||
validate: (node) => {
|
||||
const { nodes } = node
|
||||
const invalids = nodes
|
||||
.filter((n, i) => {
|
||||
const next = nodes.get(i + 1)
|
||||
return n.kind == 'text' && next && next.kind == 'text'
|
||||
})
|
||||
.map((n, i) => {
|
||||
const next = nodes.get(i + 1)
|
||||
return [n, next]
|
||||
})
|
||||
|
||||
return invalids.size ? invalids : null
|
||||
},
|
||||
normalize: (transform, node, pairs) => {
|
||||
return pairs.reduce((t, pair) => {
|
||||
const [ first, second ] = pair
|
||||
return t.joinNodeByKey(first.key, second.key)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The internal normalizing schema.
|
||||
*
|
||||
* @type {Schema}
|
||||
*/
|
||||
|
||||
const SCHEMA = Schema.create({
|
||||
rules: [
|
||||
DOCUMENT_CHILDREN_RULE,
|
||||
BLOCK_CHILDREN_RULE,
|
||||
INLINE_CHILDREN_RULE,
|
||||
NO_ADJACENT_TEXT_RULE,
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Normalize the state.
|
||||
|
Loading…
x
Reference in New Issue
Block a user