MCPcopy Create free account
hub / github.com/editablejs/editable / hasDOMNode

Function hasDOMNode

packages/editor/src/plugin/editable.ts:375–396  ·  view source on GitHub ↗

* Check if a DOM node is within the editor.

(editor: Editor, target: DOMNode)

Source from the content-addressed store, hash-verified

373 * Check if a DOM node is within the editor.
374 */
375 hasDOMNode(editor: Editor, target: DOMNode): boolean {
376 const editorEl = Editable.toDOMNode(editor, editor)
377 let targetEl
378
379 // COMPAT: In Firefox, reading `target.nodeType` will throw an error if
380 // target is originating from an internal "restricted" element (e.g. a
381 // stepper arrow on a number input). (2018/05/04)
382 // https://github.com/ianstormtaylor/slate/issues/1819
383 try {
384 targetEl = (isDOMElement(target) ? target : target.parentElement) as HTMLElement
385 } catch (err: any) {
386 if (!err.message.includes('Permission denied to access property "nodeType"')) {
387 throw err
388 }
389 }
390
391 if (!targetEl) {
392 return false
393 }
394
395 return targetEl.closest(`[${DATA_EDITABLE_NODE}="editor"]`) === editorEl
396 },
397
398 /**
399 * Find the native DOM element from a Editor node.

Callers

nothing calls this directly

Calls 1

isDOMElementFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…