mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
fix child_* schema errors to reference child, closes #3197
This commit is contained in:
@@ -181,9 +181,8 @@ export const checkAncestor = (
|
||||
} else {
|
||||
return {
|
||||
code: 'child_max_invalid',
|
||||
node: parent,
|
||||
path: parentPath,
|
||||
index,
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
max: group.max,
|
||||
}
|
||||
@@ -196,9 +195,8 @@ export const checkAncestor = (
|
||||
if (group.min != null && count <= group.min) {
|
||||
return {
|
||||
code: 'child_min_invalid',
|
||||
node: parent,
|
||||
path: parentPath,
|
||||
index,
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
}
|
||||
@@ -233,16 +231,15 @@ export const checkAncestor = (
|
||||
if (nc && Editor.isMatch(editor, [child, childPath], nc.match || {})) {
|
||||
return {
|
||||
code: 'child_min_invalid',
|
||||
node: parent,
|
||||
path: parentPath,
|
||||
index,
|
||||
node: child,
|
||||
path: childPath,
|
||||
count,
|
||||
min: group.min,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { code: 'child_invalid', node: child, path: childPath, index }
|
||||
return { code: 'child_invalid', node: child, path: childPath }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,34 +4,24 @@ export interface ChildInvalidError {
|
||||
code: 'child_invalid'
|
||||
node: Descendant
|
||||
path: Path
|
||||
index: number
|
||||
}
|
||||
|
||||
export interface ChildMaxInvalidError {
|
||||
code: 'child_max_invalid'
|
||||
node: Descendant
|
||||
path: Path
|
||||
index: number
|
||||
count: number
|
||||
max: number
|
||||
}
|
||||
|
||||
export interface ChildMinInvalidError {
|
||||
code: 'child_min_invalid'
|
||||
node: Descendant
|
||||
node: Descendant | undefined
|
||||
path: Path
|
||||
index: number
|
||||
count: number
|
||||
min: number
|
||||
}
|
||||
|
||||
export interface ChildUnexpectedError {
|
||||
code: 'child_unexpected'
|
||||
node: Descendant
|
||||
path: Path
|
||||
index: number
|
||||
}
|
||||
|
||||
export interface FirstChildInvalidError {
|
||||
code: 'first_child_invalid'
|
||||
node: Descendant
|
||||
@@ -102,7 +92,6 @@ export type NodeError =
|
||||
| ChildInvalidError
|
||||
| ChildMaxInvalidError
|
||||
| ChildMinInvalidError
|
||||
| ChildUnexpectedError
|
||||
| FirstChildInvalidError
|
||||
| LastChildInvalidError
|
||||
| MarkInvalidError
|
||||
|
@@ -92,12 +92,13 @@ export const withSchema = (
|
||||
}
|
||||
|
||||
case 'child_max_invalid': {
|
||||
const { node, path, index } = error
|
||||
const { path } = error
|
||||
const [parent, parentPath] = Editor.parent(editor, path)
|
||||
|
||||
if (node.children.length === 1 && path.length !== 0) {
|
||||
Editor.removeNodes(editor, { at: path })
|
||||
if (parent.children.length === 1 && parentPath.length !== 0) {
|
||||
Editor.removeNodes(editor, { at: parentPath })
|
||||
} else {
|
||||
Editor.removeNodes(editor, { at: path.concat(index) })
|
||||
Editor.removeNodes(editor, { at: path })
|
||||
}
|
||||
|
||||
break
|
||||
@@ -105,22 +106,22 @@ export const withSchema = (
|
||||
|
||||
case 'child_min_invalid': {
|
||||
const { path } = error
|
||||
const [, parentPath] = Editor.parent(editor, path)
|
||||
|
||||
if (path.length === 0) {
|
||||
const range = Editor.range(editor, path)
|
||||
if (parentPath.length === 0) {
|
||||
const range = Editor.range(editor, parentPath)
|
||||
Editor.removeNodes(editor, {
|
||||
at: range,
|
||||
match: ([, p]) => p.length === 1,
|
||||
})
|
||||
} else {
|
||||
Editor.removeNodes(editor, { at: path })
|
||||
Editor.removeNodes(editor, { at: parentPath })
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case 'child_invalid':
|
||||
case 'child_unexpected':
|
||||
case 'next_sibling_invalid':
|
||||
case 'node_property_invalid':
|
||||
case 'node_text_invalid':
|
||||
|
Reference in New Issue
Block a user