1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-13 18:53:59 +02:00

fix: use ownerDocument to create element (#4661)

* fix: use ownerDocument to create element

* chore: add changeset
This commit is contained in:
Leo
2021-11-21 03:24:53 +09:00
committed by GitHub
parent 3ad3aaccad
commit 0f194a86a0
2 changed files with 9 additions and 4 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
use ownerDocument to create element

View File

@@ -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
// node, wrap it in a `<span>` so we have something to set an attribute on.
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
// then leading and trailing spaces will be ignored. (2017/09/21)
span.style.whiteSpace = 'pre'
@@ -184,13 +184,13 @@ export const withReact = <T extends Editor>(editor: T) => {
data.setData('application/x-slate-fragment', encoded)
// 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.setAttribute('hidden', 'true')
document.body.appendChild(div)
contents.ownerDocument.body.appendChild(div)
data.setData('text/html', div.innerHTML)
data.setData('text/plain', getPlainText(div))
document.body.removeChild(div)
contents.ownerDocument.body.removeChild(div)
return data
}