mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 23:12:52 +02:00
fix parent schema rule normalization
This commit is contained in:
@@ -118,7 +118,7 @@ export const checkAncestor = (
|
||||
entry: AncestorEntry,
|
||||
rule: NodeRule,
|
||||
ancestorRules: NodeRule[]
|
||||
): NodeError | undefined => {
|
||||
): [NodeRule, NodeError] | undefined => {
|
||||
const { validate: v } = rule
|
||||
const [parent, parentPath] = entry
|
||||
const processed = new Set()
|
||||
@@ -144,7 +144,7 @@ export const checkAncestor = (
|
||||
const e = checkParent(editor, entry, index, rule, r)
|
||||
|
||||
if (e) {
|
||||
return e
|
||||
return [r, e]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,13 +180,16 @@ export const checkAncestor = (
|
||||
count = 0
|
||||
continue
|
||||
} else {
|
||||
return {
|
||||
code: 'child_max_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
max: group.max,
|
||||
}
|
||||
return [
|
||||
rule,
|
||||
{
|
||||
code: 'child_max_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
max: group.max,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,13 +197,16 @@ export const checkAncestor = (
|
||||
// we're missing a child in a group with a mininmum set.
|
||||
if (!child) {
|
||||
if (group.min != null && count <= group.min) {
|
||||
return {
|
||||
code: 'child_min_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
}
|
||||
return [
|
||||
rule,
|
||||
{
|
||||
code: 'child_min_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
},
|
||||
]
|
||||
} else {
|
||||
g++
|
||||
count = 0
|
||||
@@ -230,17 +236,20 @@ export const checkAncestor = (
|
||||
const nc = groups[g + 1]
|
||||
|
||||
if (nc && Editor.isMatch(editor, [child, childPath], nc.match || {})) {
|
||||
return {
|
||||
code: 'child_min_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
}
|
||||
return [
|
||||
rule,
|
||||
{
|
||||
code: 'child_min_invalid',
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
return { code: 'child_invalid', node: child, path: childPath }
|
||||
return [rule, { code: 'child_invalid', node: child, path: childPath }]
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -40,17 +40,22 @@ export const withSchema = (
|
||||
let rule: NodeRule | undefined
|
||||
|
||||
for (const r of nodeRules) {
|
||||
let e = checkNode(editor, entry, r, nodeRules)
|
||||
error = checkNode(editor, [n, p], r, nodeRules)
|
||||
|
||||
if (!e && !Text.isText(n)) {
|
||||
e = checkAncestor(editor, [n, p], r, ancestorRules)
|
||||
}
|
||||
|
||||
if (e) {
|
||||
error = e
|
||||
if (error) {
|
||||
rule = r
|
||||
break
|
||||
}
|
||||
|
||||
if (!Text.isText(n)) {
|
||||
const failure = checkAncestor(editor, [n, p], r, ancestorRules)
|
||||
|
||||
if (failure) {
|
||||
rule = failure[0]
|
||||
error = failure[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error == null) {
|
||||
|
Reference in New Issue
Block a user