1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-20 06:01:24 +02:00

replace IS_FIREFOX with IS_FIREFOX_LEGACY in HAS_BEFORE_INPUT_SUPPORT (#4150)

* replace IS_FIREFOX with IS_FIREFOX_LEGACY in HAS_BEFORE_INPUT_SUPPORT

* fix linting errors

* Create afraid-donuts-flow.md

* Update environment.ts

Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
This commit is contained in:
nivekithan
2021-04-01 03:39:46 +05:30
committed by GitHub
parent 165ac3c695
commit bbd7d9c330
3 changed files with 18 additions and 6 deletions

View File

@@ -0,0 +1,5 @@
---
'slate-react': patch
---
Added support for using the new `beforeInput` events in the latest Firefox.

View File

@@ -21,6 +21,7 @@ import {
IS_SAFARI, IS_SAFARI,
IS_EDGE_LEGACY, IS_EDGE_LEGACY,
IS_CHROME_LEGACY, IS_CHROME_LEGACY,
IS_FIREFOX_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'
@@ -49,7 +50,7 @@ import {
// COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event
// Chrome Legacy doesn't support `beforeinput` correctly // Chrome Legacy doesn't support `beforeinput` correctly
const HAS_BEFORE_INPUT_SUPPORT = !( const HAS_BEFORE_INPUT_SUPPORT = !(
IS_FIREFOX || IS_FIREFOX_LEGACY ||
IS_EDGE_LEGACY || IS_EDGE_LEGACY ||
IS_CHROME_LEGACY IS_CHROME_LEGACY
) )

View File

@@ -23,15 +23,21 @@ export const IS_EDGE_LEGACY =
export const IS_CHROME = export const IS_CHROME =
typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent) typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent)
// Native beforeInput events don't work well with react on Chrome 75 and older, Chrome 76+ can use beforeInput // Native `beforeInput` events don't work well with react on Chrome 75
// and older, Chrome 76+ can use `beforeInput` though.
export const IS_CHROME_LEGACY = export const IS_CHROME_LEGACY =
typeof navigator !== 'undefined' && typeof navigator !== 'undefined' &&
/Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent) /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent)
/** // Firefox did not support `beforeInput` until `v87`.
* Check if DOM is available as React does internally. export const IS_FIREFOX_LEGACY =
* @see https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js typeof navigator !== 'undefined' &&
*/ /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test(
navigator.userAgent
)
// Check if DOM is available as React does internally.
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
export const CAN_USE_DOM = !!( export const CAN_USE_DOM = !!(
typeof window !== 'undefined' && typeof window !== 'undefined' &&
typeof window.document !== 'undefined' && typeof window.document !== 'undefined' &&