mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 01:33:58 +02:00
Fix child_min_invalid checks (#3219)
This commit is contained in:
committed by
Ian Storm Taylor
parent
b5fe096844
commit
f355f8a6f0
@@ -130,7 +130,6 @@ export const checkAncestor = (
|
|||||||
let g = 0
|
let g = 0
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
count++
|
|
||||||
const group = groups[g] as ChildValidation | undefined
|
const group = groups[g] as ChildValidation | undefined
|
||||||
const child = parent.children[index] as Descendant | undefined
|
const child = parent.children[index] as Descendant | undefined
|
||||||
const childPath = parentPath.concat(index)
|
const childPath = parentPath.concat(index)
|
||||||
@@ -172,6 +171,12 @@ export const checkAncestor = (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
child &&
|
||||||
|
Editor.isMatch(editor, [child, childPath], group.match || {})
|
||||||
|
) {
|
||||||
|
count++
|
||||||
|
}
|
||||||
// Since we want to report overflow on last matching child we don't
|
// Since we want to report overflow on last matching child we don't
|
||||||
// immediately v for count > max, but instead do so once we find
|
// immediately v for count > max, but instead do so once we find
|
||||||
// a child that doesn't match.
|
// a child that doesn't match.
|
||||||
@@ -197,7 +202,7 @@ export const checkAncestor = (
|
|||||||
// If there's no child, we're either done, we're in an optional group, or
|
// If there's no child, we're either done, we're in an optional group, or
|
||||||
// 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,
|
rule,
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,26 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
|
||||||
|
import { jsx } from 'slate-hyperscript'
|
||||||
|
|
||||||
|
export const schema = [
|
||||||
|
{
|
||||||
|
for: 'node',
|
||||||
|
match: { a: true },
|
||||||
|
validate: {
|
||||||
|
children: [
|
||||||
|
{ match: { b: true }, min: 1 },
|
||||||
|
{ match: { c: true }, min: 0 },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<element a>
|
||||||
|
<element c>one</element>
|
||||||
|
</element>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = <editor />
|
@@ -15,7 +15,8 @@ const schema = [
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
normalize: (editor, error) => {
|
normalize: (editor, error) => {
|
||||||
const { code, path, index } = error
|
const { code, path } = error
|
||||||
|
const [index] = path
|
||||||
const type = index === 0 ? 'title' : 'paragraph'
|
const type = index === 0 ? 'title' : 'paragraph'
|
||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@@ -25,11 +26,11 @@ const schema = [
|
|||||||
}
|
}
|
||||||
case 'child_min_invalid': {
|
case 'child_min_invalid': {
|
||||||
const block = { type, children: [{ text: '', marks: [] }] }
|
const block = { type, children: [{ text: '', marks: [] }] }
|
||||||
Editor.insertNodes(editor, block, { at: path.concat(index) })
|
Editor.insertNodes(editor, block, { at: path })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'child_max_invalid': {
|
case 'child_max_invalid': {
|
||||||
Editor.setNodes(editor, { type }, { at: path.concat(index) })
|
Editor.setNodes(editor, { type }, { at: path })
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user