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:
@@ -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.
|
||||
*/
|
||||
|
@@ -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'
|
||||
|
Reference in New Issue
Block a user