mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 23:42:56 +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:
@@ -512,7 +512,7 @@ export const Editable = (props: EditableProps) => {
|
||||
const path = ReactEditor.findPath(editor, node)
|
||||
const start = Editor.start(editor, path)
|
||||
|
||||
if (Editor.match(editor, start, 'void')) {
|
||||
if (Editor.void(editor, { at: start })) {
|
||||
const range = Editor.range(editor, start)
|
||||
Editor.select(editor, range)
|
||||
}
|
||||
@@ -591,7 +591,7 @@ export const Editable = (props: EditableProps) => {
|
||||
// default, and calling `preventDefault` hides the cursor.
|
||||
const node = ReactEditor.toSlateNode(editor, event.target)
|
||||
|
||||
if (Element.isElement(node) && editor.isVoid(node)) {
|
||||
if (Editor.isVoid(editor, node)) {
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
@@ -606,7 +606,7 @@ export const Editable = (props: EditableProps) => {
|
||||
) {
|
||||
const node = ReactEditor.toSlateNode(editor, event.target)
|
||||
const path = ReactEditor.findPath(editor, node)
|
||||
const voidMatch = Editor.match(editor, path, 'void')
|
||||
const voidMatch = Editor.void(editor, { at: path })
|
||||
|
||||
// If starting a drag on a void node, make sure it is selected
|
||||
// so that it shows up in the selection's fragment.
|
||||
@@ -989,8 +989,8 @@ const setFragmentData = (dataTransfer: DataTransfer, editor: Editor): void => {
|
||||
}
|
||||
|
||||
const [start, end] = Range.edges(selection)
|
||||
const startVoid = Editor.match(editor, start.path, 'void')
|
||||
const endVoid = Editor.match(editor, end.path, 'void')
|
||||
const startVoid = Editor.void(editor, { at: start.path })
|
||||
const endVoid = Editor.void(editor, { at: end.path })
|
||||
|
||||
if (Range.isCollapsed(selection) && !startVoid) {
|
||||
return
|
||||
|
@@ -83,7 +83,7 @@ const Element = (props: {
|
||||
}
|
||||
|
||||
// If it's a void node, wrap the children in extra void-specific elements.
|
||||
if (editor.isVoid(element)) {
|
||||
if (Editor.isVoid(editor, element)) {
|
||||
attributes['data-slate-void'] = true
|
||||
|
||||
if (!readOnly && isInline) {
|
||||
|
@@ -199,8 +199,7 @@ export const ReactEditor = {
|
||||
|
||||
// If we're inside a void node, force the offset to 0, otherwise the zero
|
||||
// width spacing character will result in an incorrect offset of 1
|
||||
const [match] = Editor.nodes(editor, { at: point, match: 'void' })
|
||||
if (match) {
|
||||
if (Editor.void(editor, { at: point })) {
|
||||
point = { path: point.path, offset: 0 }
|
||||
}
|
||||
|
||||
@@ -301,7 +300,7 @@ export const ReactEditor = {
|
||||
// If the drop target is inside a void node, move it into either the
|
||||
// next or previous node, depending on which side the `x` and `y`
|
||||
// coordinates are closest to.
|
||||
if (Element.isElement(node) && editor.isVoid(node)) {
|
||||
if (Editor.isVoid(editor, node)) {
|
||||
const rect = target.getBoundingClientRect()
|
||||
const isPrev = editor.isInline(node)
|
||||
? x - rect.left < rect.left + rect.width - x
|
||||
|
Reference in New Issue
Block a user