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