mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-14 11:14:04 +02:00
fix: use ownerDocument to create element (#4661)
* fix: use ownerDocument to create element * chore: add changeset
This commit is contained in:
5
.changeset/warm-dolphins-roll.md
Normal file
5
.changeset/warm-dolphins-roll.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
use ownerDocument to create element
|
@@ -168,7 +168,7 @@ export const withReact = <T extends Editor>(editor: T) => {
|
|||||||
// in the HTML, and can be used for intra-Slate pasting. If it's a text
|
// in the HTML, and can be used for intra-Slate pasting. If it's a text
|
||||||
// node, wrap it in a `<span>` so we have something to set an attribute on.
|
// node, wrap it in a `<span>` so we have something to set an attribute on.
|
||||||
if (isDOMText(attach)) {
|
if (isDOMText(attach)) {
|
||||||
const span = document.createElement('span')
|
const span = attach.ownerDocument.createElement('span')
|
||||||
// COMPAT: In Chrome and Safari, if we don't add the `white-space` style
|
// COMPAT: In Chrome and Safari, if we don't add the `white-space` style
|
||||||
// then leading and trailing spaces will be ignored. (2017/09/21)
|
// then leading and trailing spaces will be ignored. (2017/09/21)
|
||||||
span.style.whiteSpace = 'pre'
|
span.style.whiteSpace = 'pre'
|
||||||
@@ -184,13 +184,13 @@ export const withReact = <T extends Editor>(editor: T) => {
|
|||||||
data.setData('application/x-slate-fragment', encoded)
|
data.setData('application/x-slate-fragment', encoded)
|
||||||
|
|
||||||
// Add the content to a <div> so that we can get its inner HTML.
|
// Add the content to a <div> so that we can get its inner HTML.
|
||||||
const div = document.createElement('div')
|
const div = contents.ownerDocument.createElement('div')
|
||||||
div.appendChild(contents)
|
div.appendChild(contents)
|
||||||
div.setAttribute('hidden', 'true')
|
div.setAttribute('hidden', 'true')
|
||||||
document.body.appendChild(div)
|
contents.ownerDocument.body.appendChild(div)
|
||||||
data.setData('text/html', div.innerHTML)
|
data.setData('text/html', div.innerHTML)
|
||||||
data.setData('text/plain', getPlainText(div))
|
data.setData('text/plain', getPlainText(div))
|
||||||
document.body.removeChild(div)
|
contents.ownerDocument.body.removeChild(div)
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user