@@ -80,6 +80,7 @@ import DOMText = globalThis.Text
8080import DOMRange = globalThis . Range
8181import DOMSelection = globalThis . Selection
8282import DOMStaticRange = globalThis . StaticRange
83+ import { isHTMLElement , isSelection } from './check'
8384export { DOMNode , DOMComment , DOMElement , DOMText , DOMRange , DOMSelection , DOMStaticRange }
8485
8586export type DOMPoint = [ Node , number ]
@@ -109,20 +110,15 @@ export const isDOMElement = (value: any): value is DOMElement => {
109110 * Check if a value is a DOM node.
110111 */
111112export const isDOMNode = ( value : any ) : value is DOMNode => {
112- const window = getDefaultView ( value )
113- return (
114- ! ! window &&
115- // @ts -ignore
116- value instanceof window . Node
117- )
113+ return value != null && typeof value . nodeType === 'number'
118114}
119115
120116/**
121117 * Check if a value is a DOM selection.
122118 */
123119export const isDOMSelection = ( value : any ) : value is DOMSelection => {
124120 const window = value && value . anchorNode && getDefaultView ( value . anchorNode )
125- return ! ! window && value instanceof window . Selection
121+ return ! ! window && isSelection ( value )
126122}
127123
128124/**
@@ -343,7 +339,7 @@ export function walkTextNodes(
343339 handler : ( textNode : DOMNode , parent : DOMElement ) => void
344340) {
345341 // void elem 内部的 text 不处理
346- if ( elem instanceof HTMLElement && elem . dataset . slateVoid === 'true' ) return
342+ if ( isHTMLElement ( elem ) && elem . dataset . slateVoid === 'true' ) return
347343
348344 for ( let nodes = elem . childNodes , i = nodes . length ; i -- ; ) {
349345 const node = nodes [ i ]
0 commit comments