1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-16 12:14:14 +02:00

Fix errors accessing globalThis in browsers that do not implement it (#4272)

This commit is contained in:
Claudéric Demers
2021-05-20 11:49:29 -04:00
committed by GitHub
parent cb1db7fca9
commit 294d5120ae
3 changed files with 17 additions and 11 deletions

View File

@@ -17,11 +17,10 @@ import scrollIntoView from 'scroll-into-view-if-needed'
import useChildren from '../hooks/use-children'
import Hotkeys from '../utils/hotkeys'
import {
HAS_BEFORE_INPUT_SUPPORT,
IS_FIREFOX,
IS_FIREFOX_LEGACY,
IS_SAFARI,
IS_EDGE_LEGACY,
IS_CHROME_LEGACY,
} from '../utils/environment'
import { ReactEditor } from '..'
import { ReadOnlyContext } from '../hooks/use-read-only'
@@ -48,15 +47,6 @@ import {
EDITOR_TO_WINDOW,
} from '../utils/weak-maps'
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
// Chrome Legacy doesn't support `beforeinput` correctly
const HAS_BEFORE_INPUT_SUPPORT =
!IS_CHROME_LEGACY &&
!IS_EDGE_LEGACY &&
globalThis.InputEvent &&
// @ts-ignore The `getTargetRanges` property isn't recognized.
typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'
/**
* `RenderElementProps` are passed to the `renderElement` handler.
*/

View File

@@ -46,3 +46,14 @@ export const CAN_USE_DOM = !!(
typeof window.document !== 'undefined' &&
typeof window.document.createElement !== 'undefined'
)
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
// Chrome Legacy doesn't support `beforeinput` correctly
export const HAS_BEFORE_INPUT_SUPPORT =
!IS_CHROME_LEGACY &&
!IS_EDGE_LEGACY &&
// globalThis is undefined in older browsers
typeof globalThis !== 'undefined' &&
globalThis.InputEvent &&
// @ts-ignore The `getTargetRanges` property isn't recognized.
typeof globalThis.InputEvent.prototype.getTargetRanges === 'function'