1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-03 04:02:33 +02:00

Standardize node matching APIs (#3327)

* add lowest mode and universal flag to `Editor.nodes`

* add `mode` handling to all transforms

* add extra `Editor.is*` helpers

* change `Editor.previous` to make all optional

* change `Editor.next` to make all optional

* change `Editor.match` to make all optional

* add `Editor.void` helper

* remove non-function match arguments

* remove NodeMatch interface

* change to lowest match by default everywhere

* rename `Editor.match` to `Editor.above`

* use new helpers

* cleanup

* make NodeEntry generic, cleanup

* fix NodeEntry generics

* ensure only ancestors are returned from Editor.above

* add type-narrowing to `Editor.nodes`, remove extras

* remove other Node entry types

* cleanup

* remove `Editor.block` and `Editor.inline` helpers
This commit is contained in:
Ian Storm Taylor
2019-12-15 19:36:05 -05:00
committed by GitHub
parent b927fa3a11
commit 7d832b5e12
136 changed files with 894 additions and 1034 deletions

View File

@@ -147,7 +147,11 @@ const App = () => {
// Prevent the "`" from being inserted by default.
event.preventDefault()
// Otherwise, set the currently selected blocks type to "code".
Editor.setNodes(editor, { type: 'code' }, { match: 'block' })
Editor.setNodes(
editor,
{ type: 'code' },
{ match: n => Editor.isBlock(editor, n) }
)
}
}}
/>
@@ -200,12 +204,14 @@ const App = () => {
if (event.key === '`' && event.ctrlKey) {
event.preventDefault()
// Determine whether any of the currently selected blocks are code blocks.
const [match] = Editor.nodes(editor, { match: { type: 'code' } })
const [match] = Editor.nodes(editor, {
match: n => n.type === 'code',
})
// Toggle the block type depending on whether there's already a match.
Editor.setNodes(
editor,
{ type: match ? 'paragraph' : 'code' },
{ match: 'block' }
{ match: n => Editor.isBlock(editor, n) }
)
}
}}