mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-15 11:44:05 +02:00
fix: check isContentEditable of target element in ReactEditor.hasDOMNode (#3389)
* fix ReactEditor.hasDOMNode * make ReactEditor.hasDOMNode variables more clear
This commit is contained in:
@@ -149,15 +149,17 @@ export const ReactEditor = {
|
|||||||
options: { editable?: boolean } = {}
|
options: { editable?: boolean } = {}
|
||||||
): boolean {
|
): boolean {
|
||||||
const { editable = false } = options
|
const { editable = false } = options
|
||||||
const el = ReactEditor.toDOMNode(editor, editor)
|
const editorEl = ReactEditor.toDOMNode(editor, editor)
|
||||||
let element
|
let targetEl
|
||||||
|
|
||||||
// COMPAT: In Firefox, reading `target.nodeType` will throw an error if
|
// COMPAT: In Firefox, reading `target.nodeType` will throw an error if
|
||||||
// target is originating from an internal "restricted" element (e.g. a
|
// target is originating from an internal "restricted" element (e.g. a
|
||||||
// stepper arrow on a number input). (2018/05/04)
|
// stepper arrow on a number input). (2018/05/04)
|
||||||
// https://github.com/ianstormtaylor/slate/issues/1819
|
// https://github.com/ianstormtaylor/slate/issues/1819
|
||||||
try {
|
try {
|
||||||
element = isDOMElement(target) ? target : target.parentElement
|
targetEl = (isDOMElement(target)
|
||||||
|
? target
|
||||||
|
: target.parentElement) as HTMLElement
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (
|
||||||
!err.message.includes('Permission denied to access property "nodeType"')
|
!err.message.includes('Permission denied to access property "nodeType"')
|
||||||
@@ -166,13 +168,13 @@ export const ReactEditor = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!element) {
|
if (!targetEl) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
element.closest(`[data-slate-editor]`) === el &&
|
targetEl.closest(`[data-slate-editor]`) === editorEl &&
|
||||||
(!editable || el.isContentEditable)
|
(!editable || targetEl.isContentEditable)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user