From c691bb3aae254116982cb2c9bddc5fa753a7c59f Mon Sep 17 00:00:00 2001 From: Ravi Lamkoti <44892121+RavenColEvol@users.noreply.github.com> Date: Thu, 26 Jan 2023 05:05:46 +0530 Subject: [PATCH] fix: isVoid, isBlock, isInline types (#5254) * fix: isVoid, isBlock, isInline types * fix: remove isElement check with isEditor --- .../slate-react/src/components/editable.tsx | 16 +++++--- .../slate-react/src/plugin/react-editor.ts | 5 ++- packages/slate-react/src/plugin/with-react.ts | 3 +- packages/slate-react/src/utils/diff-text.ts | 13 ++++++- packages/slate/src/interfaces/editor.ts | 38 +++++++++++-------- packages/slate/src/transforms/node.ts | 26 +++++++------ packages/slate/src/transforms/text.ts | 14 +++---- .../interfaces/Editor/above/block-highest.tsx | 4 +- .../interfaces/Editor/above/block-lowest.tsx | 4 +- .../test/interfaces/Editor/above/inline.tsx | 4 +- .../test/interfaces/Editor/above/range.tsx | 4 +- .../test/interfaces/Editor/isBlock/block.tsx | 4 +- .../test/interfaces/Editor/isBlock/inline.tsx | 4 +- .../test/interfaces/Editor/next/block.tsx | 4 +- .../Editor/nodes/match-function/block.tsx | 4 +- .../Editor/nodes/match-function/inline.tsx | 4 +- .../test/interfaces/Editor/previous/block.tsx | 4 +- .../mergeNodes/depth-block/block.tsx | 6 ++- .../selection/block-nested-after.tsx | 4 +- .../selection/block-nested-before.tsx | 4 +- .../selection/block-siblings-after.tsx | 4 +- .../selection/block-siblings-before.tsx | 4 +- .../transforms/moveNodes/selection/block.tsx | 4 +- .../setNodes/block/block-across.tsx | 4 +- .../setNodes/block/block-hanging.tsx | 4 +- .../setNodes/block/block-nested.tsx | 4 +- .../transforms/setNodes/block/block-void.tsx | 4 +- .../test/transforms/setNodes/block/block.tsx | 4 +- .../setNodes/inline/inline-across.tsx | 4 +- .../setNodes/inline/inline-block-hanging.tsx | 4 +- .../setNodes/inline/inline-hanging.tsx | 4 +- .../setNodes/inline/inline-nested.tsx | 4 +- .../setNodes/inline/inline-void-2.tsx | 4 +- .../setNodes/inline/inline-void.tsx | 4 +- .../transforms/setNodes/inline/inline.tsx | 4 +- .../splitNodes/always/after-inline-void.tsx | 4 +- .../splitNodes/always/after-inline.tsx | 4 +- .../splitNodes/always/before-inline.tsx | 4 +- .../splitNodes/always/block-end.tsx | 4 +- .../splitNodes/always/block-start.tsx | 4 +- .../block-middle-multiple-texts.tsx | 6 ++- .../splitNodes/match-block/block-middle.tsx | 6 ++- .../splitNodes/match-block/inline-middle.tsx | 6 ++- .../splitNodes/match-inline/inline-middle.js | 6 ++- .../transforms/splitNodes/point/inline.tsx | 4 +- site/examples/markdown-shortcuts.tsx | 8 ++-- 46 files changed, 159 insertions(+), 126 deletions(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index 963ad023d..09d6598a9 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -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 diff --git a/packages/slate-react/src/plugin/react-editor.ts b/packages/slate-react/src/plugin/react-editor.ts index 13339ead2..c47a2fd8c 100644 --- a/packages/slate-react/src/plugin/react-editor.ts +++ b/packages/slate-react/src/plugin/react-editor.ts @@ -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) }, /** diff --git a/packages/slate-react/src/plugin/with-react.ts b/packages/slate-react/src/plugin/with-react.ts index a70517511..7bf1364a3 100644 --- a/packages/slate-react/src/plugin/with-react.ts +++ b/packages/slate-react/src/plugin/with-react.ts @@ -8,6 +8,7 @@ import { Point, Range, Transforms, + Element, } from 'slate' import { TextDiff, @@ -91,7 +92,7 @@ export const withReact = (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, }) diff --git a/packages/slate-react/src/utils/diff-text.ts b/packages/slate-react/src/utils/diff-text.ts index a5dc92a42..ad72be4b9 100644 --- a/packages/slate-react/src/utils/diff-text.ts +++ b/packages/slate-react/src/utils/diff-text.ts @@ -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, }) diff --git a/packages/slate/src/interfaces/editor.ts b/packages/slate/src/interfaces/editor.ts index 6e1f39aea..274e96bfc 100644 --- a/packages/slate/src/interfaces/editor.ts +++ b/packages/slate/src/interfaces/editor.ts @@ -243,15 +243,15 @@ export interface EditorInterface { insertFragment: (editor: Editor, fragment: Node[]) => void insertNode: (editor: Editor, node: Node) => void insertText: (editor: Editor, text: string) => void - isBlock: (editor: Editor, value: any) => value is Element + isBlock: (editor: Editor, value: Element) => boolean isEditor: (value: any) => value is Editor isEnd: (editor: Editor, point: Point, at: Location) => boolean isEdge: (editor: Editor, point: Point, at: Location) => boolean isEmpty: (editor: Editor, element: Element) => boolean - isInline: (editor: Editor, value: any) => value is Element + isInline: (editor: Editor, value: Element) => boolean isNormalizing: (editor: Editor) => boolean isStart: (editor: Editor, point: Point, at: Location) => boolean - isVoid: (editor: Editor, value: any) => value is Element + isVoid: (editor: Editor, value: Element) => boolean last: (editor: Editor, at: Location) => NodeEntry leaf: ( editor: Editor, @@ -530,7 +530,9 @@ export const Editor: EditorInterface = { */ hasBlocks(editor: Editor, element: Element): boolean { - return element.children.some(n => Editor.isBlock(editor, n)) + return element.children.some( + n => Element.isElement(n) && Editor.isBlock(editor, n) + ) }, /** @@ -605,8 +607,8 @@ export const Editor: EditorInterface = { * Check if a value is a block `Element` object. */ - isBlock(editor: Editor, value: any): value is Element { - return Element.isElement(value) && !editor.isInline(value) + isBlock(editor: Editor, value: Element): boolean { + return !editor.isInline(value) }, /** @@ -685,8 +687,8 @@ export const Editor: EditorInterface = { * Check if a value is an inline `Element` object. */ - isInline(editor: Editor, value: any): value is Element { - return Element.isElement(value) && editor.isInline(value) + isInline(editor: Editor, value: Element): boolean { + return editor.isInline(value) }, /** @@ -716,8 +718,8 @@ export const Editor: EditorInterface = { * Check if a value is a void `Element` object. */ - isVoid(editor: Editor, value: any): value is Element { - return Element.isElement(value) && editor.isVoid(value) + isVoid(editor: Editor, value: Element): boolean { + return editor.isVoid(value) }, /** @@ -772,7 +774,7 @@ export const Editor: EditorInterface = { levels.push([n, p]) - if (!voids && Editor.isVoid(editor, n)) { + if (!voids && Element.isElement(n) && Editor.isVoid(editor, n)) { break } } @@ -818,11 +820,14 @@ export const Editor: EditorInterface = { if (anchor.offset === 0) { const prev = Editor.previous(editor, { at: path, match: Text.isText }) const markedVoid = Editor.above(editor, { - match: n => Editor.isVoid(editor, n) && editor.markableVoid(n), + match: n => + Element.isElement(n) && + Editor.isVoid(editor, n) && + editor.markableVoid(n), }) if (!markedVoid) { const block = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), }) if (prev && block) { @@ -936,7 +941,8 @@ export const Editor: EditorInterface = { reverse, from, to, - pass: ([n]) => (voids ? false : Editor.isVoid(editor, n)), + pass: ([n]) => + voids ? false : Element.isElement(n) && Editor.isVoid(editor, n), }) const matches: NodeEntry[] = [] @@ -1649,7 +1655,7 @@ export const Editor: EditorInterface = { const endBlock = Editor.above(editor, { at: end, - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), voids, }) const blockPath = endBlock ? endBlock[1] : [] @@ -1687,7 +1693,7 @@ export const Editor: EditorInterface = { ): NodeEntry | undefined { return Editor.above(editor, { ...options, - match: n => Editor.isVoid(editor, n), + match: n => Element.isElement(n) && Editor.isVoid(editor, n), }) }, diff --git a/packages/slate/src/transforms/node.ts b/packages/slate/src/transforms/node.ts index 881c1503e..8cd63f4c8 100644 --- a/packages/slate/src/transforms/node.ts +++ b/packages/slate/src/transforms/node.ts @@ -201,7 +201,7 @@ export const NodeTransforms: NodeTransforms = { } else if (editor.isInline(node)) { match = n => Text.isText(n) || Editor.isInline(editor, n) } else { - match = n => Editor.isBlock(editor, n) + match = n => Element.isElement(n) && Editor.isBlock(editor, n) } } @@ -270,7 +270,7 @@ export const NodeTransforms: NodeTransforms = { if (match == null) { match = Path.isPath(at) ? matchPath(editor, at) - : n => Editor.isBlock(editor, n) + : n => Element.isElement(n) && Editor.isBlock(editor, n) } if (!at) { @@ -341,7 +341,7 @@ export const NodeTransforms: NodeTransforms = { const [parent] = Editor.parent(editor, at) match = n => parent.children.includes(n) } else { - match = n => Editor.isBlock(editor, n) + match = n => Element.isElement(n) && Editor.isBlock(editor, n) } } @@ -484,7 +484,7 @@ export const NodeTransforms: NodeTransforms = { if (match == null) { match = Path.isPath(at) ? matchPath(editor, at) - : n => Editor.isBlock(editor, n) + : n => Element.isElement(n) && Editor.isBlock(editor, n) } const toRef = Editor.pathRef(editor, to) @@ -540,7 +540,7 @@ export const NodeTransforms: NodeTransforms = { if (match == null) { match = Path.isPath(at) ? matchPath(editor, at) - : n => Editor.isBlock(editor, n) + : n => Element.isElement(n) && Editor.isBlock(editor, n) } if (!hanging && Range.isRange(at)) { @@ -595,7 +595,7 @@ export const NodeTransforms: NodeTransforms = { if (match == null) { match = Path.isPath(at) ? matchPath(editor, at) - : n => Editor.isBlock(editor, n) + : n => Element.isElement(n) && Editor.isBlock(editor, n) } if (!hanging && Range.isRange(at)) { @@ -707,7 +707,7 @@ export const NodeTransforms: NodeTransforms = { let { match, at = editor.selection, height = 0, always = false } = options if (match == null) { - match = n => Editor.isBlock(editor, n) + match = n => Element.isElement(n) && Editor.isBlock(editor, n) } if (Range.isRange(at)) { @@ -782,7 +782,7 @@ export const NodeTransforms: NodeTransforms = { if ( path.length < highestPath.length || path.length === 0 || - (!voids && Editor.isVoid(editor, node)) + (!voids && Element.isElement(node) && Editor.isVoid(editor, node)) ) { break } @@ -870,7 +870,7 @@ export const NodeTransforms: NodeTransforms = { if (match == null) { match = Path.isPath(at) ? matchPath(editor, at) - : n => Editor.isBlock(editor, n) + : n => Element.isElement(n) && Editor.isBlock(editor, n) } if (Path.isPath(at)) { @@ -937,9 +937,11 @@ export const NodeTransforms: NodeTransforms = { if (Path.isPath(at)) { match = matchPath(editor, at) } else if (editor.isInline(element)) { - match = n => Editor.isInline(editor, n) || Text.isText(n) + match = n => + (Element.isElement(n) && Editor.isInline(editor, n)) || + Text.isText(n) } else { - match = n => Editor.isBlock(editor, n) + match = n => Element.isElement(n) && Editor.isBlock(editor, n) } } @@ -961,7 +963,7 @@ export const NodeTransforms: NodeTransforms = { Editor.nodes(editor, { at, match: editor.isInline(element) - ? n => Editor.isBlock(editor, n) + ? n => Element.isElement(n) && Editor.isBlock(editor, n) : n => Editor.isEditor(n), mode: 'lowest', voids, diff --git a/packages/slate/src/transforms/text.ts b/packages/slate/src/transforms/text.ts index 177784b9d..4833b04c9 100644 --- a/packages/slate/src/transforms/text.ts +++ b/packages/slate/src/transforms/text.ts @@ -108,12 +108,12 @@ export const TextTransforms: TextTransforms = { let [start, end] = Range.edges(at) const startBlock = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), at: start, voids, }) const endBlock = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), at: end, voids, }) @@ -161,7 +161,7 @@ export const TextTransforms: TextTransforms = { } if ( - (!voids && Editor.isVoid(editor, node)) || + (!voids && Element.isElement(node) && Editor.isVoid(editor, node)) || (!Path.isCommon(path, start.path) && !Path.isCommon(path, end.path)) ) { matches.push(entry) @@ -293,7 +293,7 @@ export const TextTransforms: TextTransforms = { // instead since it will need to be split otherwise. const inlineElementMatch = Editor.above(editor, { at, - match: n => Editor.isInline(editor, n), + match: n => Element.isElement(n) && Editor.isInline(editor, n), mode: 'highest', voids, }) @@ -311,7 +311,7 @@ export const TextTransforms: TextTransforms = { } const blockMatch = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), at, voids, })! @@ -410,7 +410,7 @@ export const TextTransforms: TextTransforms = { at, match: n => hasBlocks - ? Editor.isBlock(editor, n) + ? Element.isElement(n) && Editor.isBlock(editor, n) : Text.isText(n) || Editor.isInline(editor, n), mode: hasBlocks ? 'lowest' : 'highest', always: @@ -440,7 +440,7 @@ export const TextTransforms: TextTransforms = { Transforms.insertNodes(editor, middles, { at: middleRef.current!, - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), mode: 'lowest', voids, }) diff --git a/packages/slate/test/interfaces/Editor/above/block-highest.tsx b/packages/slate/test/interfaces/Editor/above/block-highest.tsx index 2d0f4911e..a0bddb4f9 100644 --- a/packages/slate/test/interfaces/Editor/above/block-highest.tsx +++ b/packages/slate/test/interfaces/Editor/above/block-highest.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -12,7 +12,7 @@ export const input = ( export const test = editor => { return Editor.above(editor, { at: [0, 0, 0], - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), mode: 'highest', }) } diff --git a/packages/slate/test/interfaces/Editor/above/block-lowest.tsx b/packages/slate/test/interfaces/Editor/above/block-lowest.tsx index fd2bb9d55..b4b75239c 100644 --- a/packages/slate/test/interfaces/Editor/above/block-lowest.tsx +++ b/packages/slate/test/interfaces/Editor/above/block-lowest.tsx @@ -1,6 +1,6 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -14,7 +14,7 @@ export const input = ( export const test = editor => { return Editor.above(editor, { at: [0, 0, 0], - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), mode: 'lowest', }) } diff --git a/packages/slate/test/interfaces/Editor/above/inline.tsx b/packages/slate/test/interfaces/Editor/above/inline.tsx index 28dc13805..3391673ad 100644 --- a/packages/slate/test/interfaces/Editor/above/inline.tsx +++ b/packages/slate/test/interfaces/Editor/above/inline.tsx @@ -1,6 +1,6 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -14,7 +14,7 @@ export const input = ( export const test = editor => { return Editor.above(editor, { at: [0, 1, 0], - match: n => Editor.isInline(editor, n), + match: n => Element.isElement(n) && Editor.isInline(editor, n), }) } diff --git a/packages/slate/test/interfaces/Editor/above/range.tsx b/packages/slate/test/interfaces/Editor/above/range.tsx index 0d93b6d3e..e368410c1 100644 --- a/packages/slate/test/interfaces/Editor/above/range.tsx +++ b/packages/slate/test/interfaces/Editor/above/range.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -19,7 +19,7 @@ const range = { export const test = editor => { return Editor.above(editor, { at: range, - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), }) } export const output = [ diff --git a/packages/slate/test/interfaces/Editor/isBlock/block.tsx b/packages/slate/test/interfaces/Editor/isBlock/block.tsx index c0093aa2f..874bbdbfa 100644 --- a/packages/slate/test/interfaces/Editor/isBlock/block.tsx +++ b/packages/slate/test/interfaces/Editor/isBlock/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -9,6 +9,6 @@ export const input = ( ) export const test = editor => { const block = editor.children[0] - return Editor.isBlock(editor, block) + return Element.isElement(block) && Editor.isBlock(editor, block) } export const output = true diff --git a/packages/slate/test/interfaces/Editor/isBlock/inline.tsx b/packages/slate/test/interfaces/Editor/isBlock/inline.tsx index cac96b785..0c5f950df 100644 --- a/packages/slate/test/interfaces/Editor/isBlock/inline.tsx +++ b/packages/slate/test/interfaces/Editor/isBlock/inline.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -11,6 +11,6 @@ export const input = ( ) export const test = editor => { const inline = editor.children[0].children[1] - return Editor.isBlock(editor, inline) + return Element.isElement(inline) && Editor.isBlock(editor, inline) } export const output = false diff --git a/packages/slate/test/interfaces/Editor/next/block.tsx b/packages/slate/test/interfaces/Editor/next/block.tsx index 9894a20f6..78b9f84f2 100644 --- a/packages/slate/test/interfaces/Editor/next/block.tsx +++ b/packages/slate/test/interfaces/Editor/next/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -11,7 +11,7 @@ export const input = ( export const test = editor => { return Editor.next(editor, { at: [0], - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), }) } export const output = [two, [1]] diff --git a/packages/slate/test/interfaces/Editor/nodes/match-function/block.tsx b/packages/slate/test/interfaces/Editor/nodes/match-function/block.tsx index 794c1022d..f6ac19990 100644 --- a/packages/slate/test/interfaces/Editor/nodes/match-function/block.tsx +++ b/packages/slate/test/interfaces/Editor/nodes/match-function/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../../..' export const input = ( @@ -11,7 +11,7 @@ export const test = editor => { return Array.from( Editor.nodes(editor, { at: [], - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), }) ) } diff --git a/packages/slate/test/interfaces/Editor/nodes/match-function/inline.tsx b/packages/slate/test/interfaces/Editor/nodes/match-function/inline.tsx index e261e57a6..865878c02 100644 --- a/packages/slate/test/interfaces/Editor/nodes/match-function/inline.tsx +++ b/packages/slate/test/interfaces/Editor/nodes/match-function/inline.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../../..' export const input = ( @@ -13,7 +13,7 @@ export const test = editor => { return Array.from( Editor.nodes(editor, { at: [], - match: n => Editor.isInline(editor, n), + match: n => Element.isElement(n) && Editor.isInline(editor, n), }) ) } diff --git a/packages/slate/test/interfaces/Editor/previous/block.tsx b/packages/slate/test/interfaces/Editor/previous/block.tsx index bf7f651a2..8d8093330 100644 --- a/packages/slate/test/interfaces/Editor/previous/block.tsx +++ b/packages/slate/test/interfaces/Editor/previous/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor } from 'slate' +import { Editor, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -11,7 +11,7 @@ export const input = ( export const test = editor => { return Editor.previous(editor, { at: [1], - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), }) } export const output = [one, [0]] diff --git a/packages/slate/test/transforms/mergeNodes/depth-block/block.tsx b/packages/slate/test/transforms/mergeNodes/depth-block/block.tsx index 41ed58347..d0776738e 100644 --- a/packages/slate/test/transforms/mergeNodes/depth-block/block.tsx +++ b/packages/slate/test/transforms/mergeNodes/depth-block/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -12,7 +12,9 @@ export const input = ( ) export const run = editor => { - Transforms.mergeNodes(editor, { match: n => Editor.isBlock(editor, n) }) + Transforms.mergeNodes(editor, { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + }) } export const output = ( diff --git a/packages/slate/test/transforms/moveNodes/selection/block-nested-after.tsx b/packages/slate/test/transforms/moveNodes/selection/block-nested-after.tsx index 2b35f1055..c801fa102 100644 --- a/packages/slate/test/transforms/moveNodes/selection/block-nested-after.tsx +++ b/packages/slate/test/transforms/moveNodes/selection/block-nested-after.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.moveNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), to: [1], }) } diff --git a/packages/slate/test/transforms/moveNodes/selection/block-nested-before.tsx b/packages/slate/test/transforms/moveNodes/selection/block-nested-before.tsx index ede4f0056..2d2c8f243 100644 --- a/packages/slate/test/transforms/moveNodes/selection/block-nested-before.tsx +++ b/packages/slate/test/transforms/moveNodes/selection/block-nested-before.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.moveNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), to: [0], }) } diff --git a/packages/slate/test/transforms/moveNodes/selection/block-siblings-after.tsx b/packages/slate/test/transforms/moveNodes/selection/block-siblings-after.tsx index 37a6135fd..da0d8e6e9 100644 --- a/packages/slate/test/transforms/moveNodes/selection/block-siblings-after.tsx +++ b/packages/slate/test/transforms/moveNodes/selection/block-siblings-after.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.moveNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), to: [2], }) } diff --git a/packages/slate/test/transforms/moveNodes/selection/block-siblings-before.tsx b/packages/slate/test/transforms/moveNodes/selection/block-siblings-before.tsx index 7a6c478d8..509d3953f 100644 --- a/packages/slate/test/transforms/moveNodes/selection/block-siblings-before.tsx +++ b/packages/slate/test/transforms/moveNodes/selection/block-siblings-before.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.moveNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), to: [0], }) } diff --git a/packages/slate/test/transforms/moveNodes/selection/block.tsx b/packages/slate/test/transforms/moveNodes/selection/block.tsx index 98aa39f1f..098f3d65a 100644 --- a/packages/slate/test/transforms/moveNodes/selection/block.tsx +++ b/packages/slate/test/transforms/moveNodes/selection/block.tsx @@ -1,5 +1,5 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const input = ( @@ -13,7 +13,7 @@ export const input = ( ) export const run = editor => { Transforms.moveNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), to: [1], }) } diff --git a/packages/slate/test/transforms/setNodes/block/block-across.tsx b/packages/slate/test/transforms/setNodes/block/block-across.tsx index 014666a92..6d1d4fe8b 100644 --- a/packages/slate/test/transforms/setNodes/block/block-across.tsx +++ b/packages/slate/test/transforms/setNodes/block/block-across.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/block/block-hanging.tsx b/packages/slate/test/transforms/setNodes/block/block-hanging.tsx index 144398113..1082056ba 100644 --- a/packages/slate/test/transforms/setNodes/block/block-hanging.tsx +++ b/packages/slate/test/transforms/setNodes/block/block-hanging.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/block/block-nested.tsx b/packages/slate/test/transforms/setNodes/block/block-nested.tsx index 57af04159..ea407635c 100644 --- a/packages/slate/test/transforms/setNodes/block/block-nested.tsx +++ b/packages/slate/test/transforms/setNodes/block/block-nested.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/block/block-void.tsx b/packages/slate/test/transforms/setNodes/block/block-void.tsx index ca831a8c1..47cd23f6d 100644 --- a/packages/slate/test/transforms/setNodes/block/block-void.tsx +++ b/packages/slate/test/transforms/setNodes/block/block-void.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/block/block.tsx b/packages/slate/test/transforms/setNodes/block/block.tsx index 249e2023a..20ec25348 100644 --- a/packages/slate/test/transforms/setNodes/block/block.tsx +++ b/packages/slate/test/transforms/setNodes/block/block.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isBlock(editor, n) } + { match: n => Element.isElement(n) && Editor.isBlock(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-across.tsx b/packages/slate/test/transforms/setNodes/inline/inline-across.tsx index 949104a5d..21f026b03 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-across.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-across.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-block-hanging.tsx b/packages/slate/test/transforms/setNodes/inline/inline-block-hanging.tsx index 17b0ebc34..4ca8a2a44 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-block-hanging.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-block-hanging.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-hanging.tsx b/packages/slate/test/transforms/setNodes/inline/inline-hanging.tsx index e5da649d9..dabfcbe52 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-hanging.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-hanging.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-nested.tsx b/packages/slate/test/transforms/setNodes/inline/inline-nested.tsx index 0fb6df106..1ab6c6361 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-nested.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-nested.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-void-2.tsx b/packages/slate/test/transforms/setNodes/inline/inline-void-2.tsx index 11899a79a..a63a991e2 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-void-2.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-void-2.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline-void.tsx b/packages/slate/test/transforms/setNodes/inline/inline-void.tsx index 29bdbbd74..1437e4f8b 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline-void.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline-void.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/setNodes/inline/inline.tsx b/packages/slate/test/transforms/setNodes/inline/inline.tsx index 6a6722c76..3273789ba 100644 --- a/packages/slate/test/transforms/setNodes/inline/inline.tsx +++ b/packages/slate/test/transforms/setNodes/inline/inline.tsx @@ -1,12 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.setNodes( editor, { someKey: true }, - { match: n => Editor.isInline(editor, n) } + { match: n => Element.isElement(n) && Editor.isInline(editor, n) } ) } export const input = ( diff --git a/packages/slate/test/transforms/splitNodes/always/after-inline-void.tsx b/packages/slate/test/transforms/splitNodes/always/after-inline-void.tsx index 64ea93d1d..afc36c3b3 100644 --- a/packages/slate/test/transforms/splitNodes/always/after-inline-void.tsx +++ b/packages/slate/test/transforms/splitNodes/always/after-inline-void.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), always: true, }) } diff --git a/packages/slate/test/transforms/splitNodes/always/after-inline.tsx b/packages/slate/test/transforms/splitNodes/always/after-inline.tsx index ac37097a1..c37ee974f 100644 --- a/packages/slate/test/transforms/splitNodes/always/after-inline.tsx +++ b/packages/slate/test/transforms/splitNodes/always/after-inline.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), always: true, }) } diff --git a/packages/slate/test/transforms/splitNodes/always/before-inline.tsx b/packages/slate/test/transforms/splitNodes/always/before-inline.tsx index 85f3e4ce6..6fd1456bf 100644 --- a/packages/slate/test/transforms/splitNodes/always/before-inline.tsx +++ b/packages/slate/test/transforms/splitNodes/always/before-inline.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), always: true, }) } diff --git a/packages/slate/test/transforms/splitNodes/always/block-end.tsx b/packages/slate/test/transforms/splitNodes/always/block-end.tsx index 35b0fbcf5..23977f0d8 100644 --- a/packages/slate/test/transforms/splitNodes/always/block-end.tsx +++ b/packages/slate/test/transforms/splitNodes/always/block-end.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), always: true, }) } diff --git a/packages/slate/test/transforms/splitNodes/always/block-start.tsx b/packages/slate/test/transforms/splitNodes/always/block-start.tsx index 5d33a8101..a9aad690a 100644 --- a/packages/slate/test/transforms/splitNodes/always/block-start.tsx +++ b/packages/slate/test/transforms/splitNodes/always/block-start.tsx @@ -1,10 +1,10 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { - match: n => Editor.isBlock(editor, n), + match: n => Element.isElement(n) && Editor.isBlock(editor, n), always: true, }) } diff --git a/packages/slate/test/transforms/splitNodes/match-block/block-middle-multiple-texts.tsx b/packages/slate/test/transforms/splitNodes/match-block/block-middle-multiple-texts.tsx index b809229ed..7fad09d4b 100644 --- a/packages/slate/test/transforms/splitNodes/match-block/block-middle-multiple-texts.tsx +++ b/packages/slate/test/transforms/splitNodes/match-block/block-middle-multiple-texts.tsx @@ -1,9 +1,11 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { - Transforms.splitNodes(editor, { match: n => Editor.isBlock(editor, n) }) + Transforms.splitNodes(editor, { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + }) } export const input = ( diff --git a/packages/slate/test/transforms/splitNodes/match-block/block-middle.tsx b/packages/slate/test/transforms/splitNodes/match-block/block-middle.tsx index f519d826b..05f36898f 100644 --- a/packages/slate/test/transforms/splitNodes/match-block/block-middle.tsx +++ b/packages/slate/test/transforms/splitNodes/match-block/block-middle.tsx @@ -1,9 +1,11 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { - Transforms.splitNodes(editor, { match: n => Editor.isBlock(editor, n) }) + Transforms.splitNodes(editor, { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + }) } export const input = ( diff --git a/packages/slate/test/transforms/splitNodes/match-block/inline-middle.tsx b/packages/slate/test/transforms/splitNodes/match-block/inline-middle.tsx index cdf6ea3e9..d8d5ffcb3 100644 --- a/packages/slate/test/transforms/splitNodes/match-block/inline-middle.tsx +++ b/packages/slate/test/transforms/splitNodes/match-block/inline-middle.tsx @@ -1,9 +1,11 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { - Transforms.splitNodes(editor, { match: n => Editor.isBlock(editor, n) }) + Transforms.splitNodes(editor, { + match: n => Element.isElement(n) && Editor.isBlock(editor, n), + }) } export const input = ( diff --git a/packages/slate/test/transforms/splitNodes/match-inline/inline-middle.js b/packages/slate/test/transforms/splitNodes/match-inline/inline-middle.js index 62581a2ff..bcb034b90 100644 --- a/packages/slate/test/transforms/splitNodes/match-inline/inline-middle.js +++ b/packages/slate/test/transforms/splitNodes/match-inline/inline-middle.js @@ -1,10 +1,12 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { - Transforms.splitNodes(editor, { match: n => Editor.isInline(editor, n) }) + Transforms.splitNodes(editor, { + match: n => Element.isElement(n) && Editor.isInline(editor, n), + }) } export const input = ( diff --git a/packages/slate/test/transforms/splitNodes/point/inline.tsx b/packages/slate/test/transforms/splitNodes/point/inline.tsx index 8e2acc971..f958d6e86 100644 --- a/packages/slate/test/transforms/splitNodes/point/inline.tsx +++ b/packages/slate/test/transforms/splitNodes/point/inline.tsx @@ -1,11 +1,11 @@ /** @jsx jsx */ -import { Editor, Transforms } from 'slate' +import { Editor, Transforms, Element } from 'slate' import { jsx } from '../../..' export const run = editor => { Transforms.splitNodes(editor, { at: { path: [0, 1, 0], offset: 2 }, - match: n => Editor.isInline(editor, n), + match: n => Element.isElement(n) && Editor.isInline(editor, n), }) } export const input = ( diff --git a/site/examples/markdown-shortcuts.tsx b/site/examples/markdown-shortcuts.tsx index 9b5452a0d..86217d63e 100644 --- a/site/examples/markdown-shortcuts.tsx +++ b/site/examples/markdown-shortcuts.tsx @@ -50,7 +50,7 @@ const MarkdownShortcutsExample = () => { const blockEntry = Editor.above(editor, { at: path, - match: n => Editor.isBlock(editor, n), + match: n => SlateElement.isElement(n) && Editor.isBlock(editor, n), }) if (!blockEntry) { return false @@ -88,7 +88,7 @@ const withShortcuts = editor => { if (text.endsWith(' ') && selection && Range.isCollapsed(selection)) { const { anchor } = selection const block = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => SlateElement.isElement(n) && Editor.isBlock(editor, n), }) const path = block ? block[1] : [] const start = Editor.start(editor, path) @@ -107,7 +107,7 @@ const withShortcuts = editor => { type, } Transforms.setNodes(editor, newProperties, { - match: n => Editor.isBlock(editor, n), + match: n => SlateElement.isElement(n) && Editor.isBlock(editor, n), }) if (type === 'list-item') { @@ -135,7 +135,7 @@ const withShortcuts = editor => { if (selection && Range.isCollapsed(selection)) { const match = Editor.above(editor, { - match: n => Editor.isBlock(editor, n), + match: n => SlateElement.isElement(n) && Editor.isBlock(editor, n), }) if (match) {