1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 06:53:25 +02:00

fix: isVoid, isBlock, isInline types (#5254)

* fix: isVoid, isBlock, isInline types

* fix: remove isElement check with isEditor
This commit is contained in:
Ravi Lamkoti
2023-01-26 05:05:46 +05:30
committed by GitHub
parent e9c9d9f4db
commit c691bb3aae
46 changed files with 159 additions and 126 deletions

View File

@@ -521,7 +521,7 @@ export const Editable = (props: EditableProps) => {
) {
const block = Editor.above(editor, {
at: anchor.path,
match: n => Editor.isBlock(editor, n),
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
})
if (block && Node.string(block[0]).includes('\t')) {
@@ -1009,9 +1009,12 @@ export const Editable = (props: EditableProps) => {
if (event.detail === TRIPLE_CLICK && path.length >= 1) {
let blockPath = path
if (!Editor.isBlock(editor, node)) {
if (
!(Element.isElement(node) && Editor.isBlock(editor, node))
) {
const block = Editor.above(editor, {
match: n => Editor.isBlock(editor, n),
match: n =>
Element.isElement(n) && Editor.isBlock(editor, n),
at: path,
})
@@ -1131,7 +1134,8 @@ export const Editable = (props: EditableProps) => {
return
}
const inline = Editor.above(editor, {
match: n => Editor.isInline(editor, n),
match: n =>
Element.isElement(n) && Editor.isInline(editor, n),
mode: 'highest',
})
if (inline) {
@@ -1205,7 +1209,7 @@ export const Editable = (props: EditableProps) => {
// default, and calling `preventDefault` hides the cursor.
const node = ReactEditor.toSlateNode(editor, event.target)
if (Editor.isVoid(editor, node)) {
if (Element.isElement(node) && Editor.isVoid(editor, node)) {
event.preventDefault()
}
}
@@ -1222,7 +1226,7 @@ export const Editable = (props: EditableProps) => {
const node = ReactEditor.toSlateNode(editor, event.target)
const path = ReactEditor.findPath(editor, node)
const voidMatch =
Editor.isVoid(editor, node) ||
(Element.isElement(node) && Editor.isVoid(editor, node)) ||
Editor.void(editor, { at: path, voids: true })
// If starting a drag on a void node, make sure it is selected

View File

@@ -7,6 +7,7 @@ import {
Range,
Scrubber,
Transforms,
Element,
} from 'slate'
import { Key } from '../utils/key'
@@ -477,7 +478,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 (Editor.isVoid(editor, node)) {
if (Element.isElement(node) && Editor.isVoid(editor, node)) {
const rect = target.getBoundingClientRect()
const isPrev = editor.isInline(node)
? x - rect.left < rect.left + rect.width - x
@@ -844,7 +845,7 @@ export const ReactEditor = {
const slateNode =
ReactEditor.hasTarget(editor, target) &&
ReactEditor.toSlateNode(editor, target)
return Editor.isVoid(editor, slateNode)
return Element.isElement(slateNode) && Editor.isVoid(editor, slateNode)
},
/**

View File

@@ -8,6 +8,7 @@ import {
Point,
Range,
Transforms,
Element,
} from 'slate'
import {
TextDiff,
@@ -91,7 +92,7 @@ export const withReact = <T extends BaseEditor>(editor: T): T & ReactEditor => {
if (e.selection && Range.isCollapsed(e.selection)) {
const parentBlockEntry = Editor.above(e, {
match: n => Editor.isBlock(e, n),
match: n => Element.isElement(n) && Editor.isBlock(e, n),
at: e.selection,
})

View File

@@ -1,4 +1,13 @@
import { Editor, Node, Operation, Path, Point, Range, Text } from 'slate'
import {
Editor,
Node,
Operation,
Path,
Point,
Range,
Text,
Element,
} from 'slate'
import { EDITOR_TO_PENDING_DIFFS } from './weak-maps'
export type StringDiff = {
@@ -166,7 +175,7 @@ export function normalizePoint(editor: Editor, point: Point): Point | null {
}
const parentBlock = Editor.above(editor, {
match: n => Editor.isBlock(editor, n),
match: n => Element.isElement(n) && Editor.isBlock(editor, n),
at: path,
})