mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-31 10:51:44 +02:00
Add pass
option to Editor.nodes
(#5843)
This commit is contained in:
@@ -15,6 +15,7 @@ export function* nodes<T extends Node>(
|
||||
universal = false,
|
||||
reverse = false,
|
||||
voids = false,
|
||||
pass,
|
||||
ignoreNonSelectable = false,
|
||||
} = options
|
||||
let { match } = options
|
||||
@@ -44,7 +45,8 @@ export function* nodes<T extends Node>(
|
||||
reverse,
|
||||
from,
|
||||
to,
|
||||
pass: ([node]) => {
|
||||
pass: ([node, path]) => {
|
||||
if (pass && pass([node, path])) return true
|
||||
if (!Element.isElement(node)) return false
|
||||
if (
|
||||
!voids &&
|
||||
|
@@ -244,6 +244,7 @@ export interface EditorNodesOptions<T extends Node> {
|
||||
universal?: boolean
|
||||
reverse?: boolean
|
||||
voids?: boolean
|
||||
pass?: (entry: NodeEntry) => boolean
|
||||
ignoreNonSelectable?: boolean
|
||||
}
|
||||
|
||||
|
35
packages/slate/test/interfaces/Editor/nodes/pass/block.tsx
Normal file
35
packages/slate/test/interfaces/Editor/nodes/pass/block.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
/** @jsx jsx */
|
||||
import { Editor } from 'slate'
|
||||
import { jsx } from '../../../..'
|
||||
|
||||
export const input = (
|
||||
<editor>
|
||||
<block pass>
|
||||
<block match>one</block>
|
||||
</block>
|
||||
<block>
|
||||
<block match>two</block>
|
||||
<block pass match>
|
||||
three
|
||||
</block>
|
||||
</block>
|
||||
</editor>
|
||||
)
|
||||
export const test = editor => {
|
||||
return Array.from(
|
||||
Editor.nodes(editor, {
|
||||
at: [],
|
||||
match: n => !!n.match,
|
||||
pass: ([n]) => !!n.pass,
|
||||
})
|
||||
)
|
||||
}
|
||||
export const output = [
|
||||
[<block match>two</block>, [1, 0]],
|
||||
[
|
||||
<block pass match>
|
||||
three
|
||||
</block>,
|
||||
[1, 1],
|
||||
],
|
||||
]
|
@@ -5,27 +5,27 @@ import { jsx } from 'slate-hyperscript'
|
||||
export const input = (
|
||||
<editor>
|
||||
<element>
|
||||
<element>
|
||||
<element pass>
|
||||
<text key="a" />
|
||||
</element>
|
||||
</element>
|
||||
</editor>
|
||||
)
|
||||
export const test = value => {
|
||||
return Array.from(Node.nodes(value, { pass: ([n, p]) => p.length > 1 }))
|
||||
return Array.from(Node.nodes(value, { pass: ([n]) => !!n.pass }))
|
||||
}
|
||||
export const output = [
|
||||
[input, []],
|
||||
[
|
||||
<element>
|
||||
<element>
|
||||
<element pass>
|
||||
<text key="a" />
|
||||
</element>
|
||||
</element>,
|
||||
[0],
|
||||
],
|
||||
[
|
||||
<element>
|
||||
<element pass>
|
||||
<text key="a" />
|
||||
</element>,
|
||||
[0, 0],
|
||||
|
Reference in New Issue
Block a user