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