@@ -80,6 +80,7 @@ import DOMText = globalThis.Text
80
80
import DOMRange = globalThis . Range
81
81
import DOMSelection = globalThis . Selection
82
82
import DOMStaticRange = globalThis . StaticRange
83
+ import { isHTMLElement , isSelection } from './check'
83
84
export { DOMNode , DOMComment , DOMElement , DOMText , DOMRange , DOMSelection , DOMStaticRange }
84
85
85
86
export type DOMPoint = [ Node , number ]
@@ -109,20 +110,15 @@ export const isDOMElement = (value: any): value is DOMElement => {
109
110
* Check if a value is a DOM node.
110
111
*/
111
112
export 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'
118
114
}
119
115
120
116
/**
121
117
* Check if a value is a DOM selection.
122
118
*/
123
119
export const isDOMSelection = ( value : any ) : value is DOMSelection => {
124
120
const window = value && value . anchorNode && getDefaultView ( value . anchorNode )
125
- return ! ! window && value instanceof window . Selection
121
+ return ! ! window && isSelection ( value )
126
122
}
127
123
128
124
/**
@@ -343,7 +339,7 @@ export function walkTextNodes(
343
339
handler : ( textNode : DOMNode , parent : DOMElement ) => void
344
340
) {
345
341
// void elem 内部的 text 不处理
346
- if ( elem instanceof HTMLElement && elem . dataset . slateVoid === 'true' ) return
342
+ if ( isHTMLElement ( elem ) && elem . dataset . slateVoid === 'true' ) return
347
343
348
344
for ( let nodes = elem . childNodes , i = nodes . length ; i -- ; ) {
349
345
const node = nodes [ i ]
0 commit comments