mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 20:24:01 +02:00
Fix errors accessing globalThis
in browsers that do not implement it (#4272)
This commit is contained in:
5
.changeset/fix-globalthis-errors.md
Normal file
5
.changeset/fix-globalthis-errors.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'slate-react': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix errors accessing `globalThis` in browsers that do not implement it
|
@@ -17,11 +17,10 @@ import scrollIntoView from 'scroll-into-view-if-needed'
|
|||||||
import useChildren from '../hooks/use-children'
|
import useChildren from '../hooks/use-children'
|
||||||
import Hotkeys from '../utils/hotkeys'
|
import Hotkeys from '../utils/hotkeys'
|
||||||
import {
|
import {
|
||||||
|
HAS_BEFORE_INPUT_SUPPORT,
|
||||||
IS_FIREFOX,
|
IS_FIREFOX,
|
||||||
IS_FIREFOX_LEGACY,
|
IS_FIREFOX_LEGACY,
|
||||||
IS_SAFARI,
|
IS_SAFARI,
|
||||||
IS_EDGE_LEGACY,
|
|
||||||
IS_CHROME_LEGACY,
|
|
||||||
} from '../utils/environment'
|
} from '../utils/environment'
|
||||||
import { ReactEditor } from '..'
|
import { ReactEditor } from '..'
|
||||||
import { ReadOnlyContext } from '../hooks/use-read-only'
|
import { ReadOnlyContext } from '../hooks/use-read-only'
|
||||||
@@ -48,15 +47,6 @@ import {
|
|||||||
EDITOR_TO_WINDOW,
|
EDITOR_TO_WINDOW,
|
||||||
} from '../utils/weak-maps'
|
} 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.
|
* `RenderElementProps` are passed to the `renderElement` handler.
|
||||||
*/
|
*/
|
||||||
|
@@ -46,3 +46,14 @@ export const CAN_USE_DOM = !!(
|
|||||||
typeof window.document !== 'undefined' &&
|
typeof window.document !== 'undefined' &&
|
||||||
typeof window.document.createElement !== '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