1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 10:51:44 +02:00

Add support to iframe (#1396)

* pass window to util functions

* remove unused getWindow function

* fix findDOMNode in after plugin
This commit is contained in:
João Pereira
2017-11-13 19:42:09 +00:00
committed by Ian Storm Taylor
parent 5a6878bccf
commit 267800c26f
5 changed files with 11 additions and 16 deletions

View File

@@ -154,7 +154,7 @@ class Content extends React.Component {
// Otherwise, figure out which DOM nodes should be selected...
const current = !!rangeCount && native.getRangeAt(0)
const range = findDOMRange(selection)
const range = findDOMRange(selection, window)
if (!range) {
logger.error('Unable to find a native DOM range from the current selection.', { selection })

View File

@@ -172,7 +172,7 @@ function AfterPlugin() {
if (isVoid) {
const r = range.cloneRange()
const n = isVoidBlock ? endBlock : endInline
const node = findDOMNode(n)
const node = findDOMNode(n, window)
r.setEndAfter(node)
contents = r.cloneContents()
attach = contents.childNodes[contents.childNodes.length - 1].firstChild
@@ -190,7 +190,7 @@ function AfterPlugin() {
.size !== 0
if (hasMarks) {
const r = range.cloneRange()
const node = findDOMNode(startText)
const node = findDOMNode(startText, window)
r.setStartBefore(node)
contents = r.cloneContents()
attach = contents.childNodes[contents.childNodes.length - 1].firstChild
@@ -329,6 +329,7 @@ function AfterPlugin() {
const { value } = change
const { document, selection } = value
const window = getWindow(event.target)
let target = getEventRange(event, value)
if (!target) return
@@ -396,7 +397,7 @@ function AfterPlugin() {
// Until this is fixed in React, we dispatch a mouseup event on that
// DOM node, since that will make it go back to normal.
const focusNode = document.getNode(target.focusKey)
const el = findDOMNode(focusNode)
const el = findDOMNode(focusNode, window)
if (!el) return
el.dispatchEvent(new MouseEvent('mouseup', {

View File

@@ -8,7 +8,7 @@ import { Node } from 'slate'
* @return {Element}
*/
function findDOMNode(key) {
function findDOMNode(key, window) {
if (Node.isNode(key)) {
key = key.key
}

View File

@@ -1,6 +1,4 @@
import getWindow from 'get-window'
import findDOMNode from './find-dom-node'
/**
@@ -12,9 +10,8 @@ import findDOMNode from './find-dom-node'
* @return {Object}
*/
function findDOMPoint(key, offset) {
const el = findDOMNode(key)
const window = getWindow(el)
function findDOMPoint(key, offset, window) {
const el = findDOMNode(key, window)
let start = 0
let n

View File

@@ -1,6 +1,4 @@
import getWindow from 'get-window'
import findDOMPoint from './find-dom-point'
/**
@@ -10,13 +8,12 @@ import findDOMPoint from './find-dom-point'
* @return {Object|Null}
*/
function findDOMRange(range) {
function findDOMRange(range, window) {
const { anchorKey, anchorOffset, focusKey, focusOffset, isBackward, isCollapsed } = range
const anchor = findDOMPoint(anchorKey, anchorOffset)
const focus = isCollapsed ? anchor : findDOMPoint(focusKey, focusOffset)
const anchor = findDOMPoint(anchorKey, anchorOffset, window)
const focus = isCollapsed ? anchor : findDOMPoint(focusKey, focusOffset, window)
if (!anchor || !focus) return null
const window = getWindow(anchor.node)
const r = window.document.createRange()
const start = isBackward ? focus : anchor
const end = isBackward ? anchor : focus