From 44ff5fb257f91cbd666d47e4aacc69d8c95a9f8d Mon Sep 17 00:00:00 2001 From: Nivekithan S Date: Tue, 30 Mar 2021 22:46:20 +0530 Subject: [PATCH 1/4] replace IS_FIREFOX with IS_FIREFOX_LEGACY in HAS_BEFORE_INPUT_SUPPORT --- packages/slate-react/src/components/editable.tsx | 3 ++- packages/slate-react/src/utils/environment.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index ebac078c09..e6398128e6 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -20,6 +20,7 @@ import { IS_SAFARI, IS_EDGE_LEGACY, IS_CHROME_LEGACY, + IS_FIREFOX_LEGACY, } from '../utils/environment' import { ReactEditor } from '..' import { ReadOnlyContext } from '../hooks/use-read-only' @@ -49,7 +50,7 @@ import { // COMPAT: Firefox/Edge Legacy don't support the `beforeinput` event // Chrome Legacy doesn't support `beforeinput` correctly const HAS_BEFORE_INPUT_SUPPORT = !( - IS_FIREFOX || + IS_FIREFOX_LEGACY || IS_EDGE_LEGACY || IS_CHROME_LEGACY ) diff --git a/packages/slate-react/src/utils/environment.ts b/packages/slate-react/src/utils/environment.ts index a12cdbcaac..407a08073b 100644 --- a/packages/slate-react/src/utils/environment.ts +++ b/packages/slate-react/src/utils/environment.ts @@ -24,3 +24,10 @@ export const IS_EDGE_LEGACY = export const IS_CHROME_LEGACY = typeof navigator !== 'undefined' && /Chrome?\/(?:[0-7][0-5]|[0-6][0-9])/i.test(navigator.userAgent) + +// beforeInput event was not supported till 87.x +export const IS_FIREFOX_LEGACY = + typeof navigator !== 'undefined' && + /^(?!.*Seamonkey)(?=.*Firefox\/(?:[0-7][0-9]|[0-8][0-6])).*/i.test( + navigator.userAgent + ) From 0430d4f21e73812c21fe8d496c7775aea5ef034a Mon Sep 17 00:00:00 2001 From: Nivekithan S Date: Tue, 30 Mar 2021 23:25:05 +0530 Subject: [PATCH 2/4] fix linting errors --- docs/concepts/11-typescript.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/concepts/11-typescript.md b/docs/concepts/11-typescript.md index 87af6731c4..1662bbb78b 100644 --- a/docs/concepts/11-typescript.md +++ b/docs/concepts/11-typescript.md @@ -4,7 +4,6 @@ Slate supports typing of one Slate document model (ie. one set of custom `Editor **Warning:** You must define `CustomTypes` when using TypeScript or Slate will display typing errors. - ## Defining `Editor`, `Element` and `Text` Types To define a custom `Element` or `Text` type, extend the `CustomTypes` interface in the `slate` module like this. From fafe782398b7e795cf95916d4d61a4879d359013 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 31 Mar 2021 17:22:13 -0400 Subject: [PATCH 3/4] Create afraid-donuts-flow.md --- .changeset/afraid-donuts-flow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/afraid-donuts-flow.md diff --git a/.changeset/afraid-donuts-flow.md b/.changeset/afraid-donuts-flow.md new file mode 100644 index 0000000000..31d90c47a4 --- /dev/null +++ b/.changeset/afraid-donuts-flow.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Added support for using the new `beforeInput` events in the latest Firefox. From ad8e557bd38cca3f51f31dde1660de862c82cdeb Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 31 Mar 2021 17:50:05 -0400 Subject: [PATCH 4/4] Update environment.ts --- packages/slate-react/src/utils/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/slate-react/src/utils/environment.ts b/packages/slate-react/src/utils/environment.ts index 1f681948f9..d11c8d245c 100644 --- a/packages/slate-react/src/utils/environment.ts +++ b/packages/slate-react/src/utils/environment.ts @@ -23,7 +23,7 @@ export const IS_EDGE_LEGACY = export const IS_CHROME = typeof navigator !== 'undefined' && /Chrome/i.test(navigator.userAgent) -// Native `beforeInput` events don't work well with react on Chrome 75 +// 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 = typeof navigator !== 'undefined' &&