From 63e6db53d7e86189a812afc326f3fdac46dbf7c6 Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 9 Oct 2024 23:16:08 +0800 Subject: [PATCH 01/10] fix: undo event when not focused --- .../slate-react/src/components/editable.tsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index f1945d53ae..98ee43887a 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -1042,8 +1042,31 @@ export const Editable = forwardRef( op() } deferredOperations.current = [] + + // COMPAT: Since `beforeinput` doesn't fully `preventDefault`, + // there's a chance that content might be placed in the browser's undo stack. + // This means undo can be triggered even when the div is not focused, + // and it only triggers the input event for the node. (2024/10/09) + if (!ReactEditor.isFocused(editor)) { + const native = event.nativeEvent as InputEvent + const maybeHistoryEditor: any = editor + if ( + native.inputType === 'historyUndo' && + typeof maybeHistoryEditor.undo === 'function' + ) { + maybeHistoryEditor.undo() + return + } + if ( + native.inputType === 'historyRedo' && + typeof maybeHistoryEditor.redo === 'function' + ) { + maybeHistoryEditor.redo() + return + } + } }, - [attributes.onInput] + [attributes.onInput, editor] )} onBlur={useCallback( (event: React.FocusEvent) => { From 330be1cab453fab92d48c5bc861e654c2807748b Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 9 Oct 2024 23:24:17 +0800 Subject: [PATCH 02/10] chore: add changeset --- .changeset/curvy-seals-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-seals-attack.md diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md new file mode 100644 index 0000000000..aa574f471b --- /dev/null +++ b/.changeset/curvy-seals-attack.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +fix: sync built-in state on undo when editor is unfocused From c9d94711ccf4aed2751269f6299264e2c4c25f94 Mon Sep 17 00:00:00 2001 From: Ty Mick <5317080+TyMick@users.noreply.github.com> Date: Tue, 15 Oct 2024 12:29:29 -0700 Subject: [PATCH 03/10] Add `HistoryEditor.withMerging` to docs (#5738) --- docs/libraries/slate-history/history-editor.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/libraries/slate-history/history-editor.md b/docs/libraries/slate-history/history-editor.md index 425f76f4f3..304931b9c0 100644 --- a/docs/libraries/slate-history/history-editor.md +++ b/docs/libraries/slate-history/history-editor.md @@ -39,6 +39,11 @@ Undo to the previous saved state. ### Merging and Saving +#### `HistoryEditor.withMerging(editor: HistoryEditor, fn: () => void): void` + +Apply a series of changes inside a synchronous `fn`, These operations will +be merged into the previous history. + #### `HistoryEditor.withoutMerging(editor: HistoryEditor, fn: () => void): void` Apply a series of changes inside a synchronous `fn`, without merging any of From c94d3316e1cbf127eb113182b4afb49d9b1be771 Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 16 Oct 2024 09:03:23 +0800 Subject: [PATCH 04/10] chore: just trigger test:integration --- .changeset/curvy-seals-attack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md index aa574f471b..72fbf11dba 100644 --- a/.changeset/curvy-seals-attack.md +++ b/.changeset/curvy-seals-attack.md @@ -2,4 +2,4 @@ 'slate-react': patch --- -fix: sync built-in state on undo when editor is unfocused +fix: sync built-in state on undo when editor is unfocused From 05b601ccbc94dcc24fc47403f26bb3c11ebc387b Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 16 Oct 2024 09:06:08 +0800 Subject: [PATCH 05/10] chore: trigger test:integration --- .changeset/curvy-seals-attack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md index 72fbf11dba..aa574f471b 100644 --- a/.changeset/curvy-seals-attack.md +++ b/.changeset/curvy-seals-attack.md @@ -2,4 +2,4 @@ 'slate-react': patch --- -fix: sync built-in state on undo when editor is unfocused +fix: sync built-in state on undo when editor is unfocused From 97ffee47498defffd7e87d6ddec60579a549d0f3 Mon Sep 17 00:00:00 2001 From: Czy <651525974@qq.com> Date: Wed, 16 Oct 2024 22:54:14 +0800 Subject: [PATCH 06/10] fix: firefox test integration environment (#5742) * fix: fix firefox test integration env * chore: test ubuntu apt source * chore: IMMUTABLE_INSTALLS ? * fix: ubuntu version --- .github/workflows/ci.yml | 3 ++- package.json | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f421f8a537..549b4d2fcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,8 @@ permissions: jobs: ci: name: ${{ matrix.command }} - runs-on: ubuntu-latest + # Pin the version to avoid dependency installation issues + runs-on: ubuntu-22.04 strategy: matrix: command: diff --git a/package.json b/package.json index ba65c15db0..69b34f32a0 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "test": "yarn run test:mocha && yarn run test:jest", "test:custom": "mocha --require ./config/babel/register.cjs ./packages/slate/test/index.js", "test:inspect": "yarn test --inspect-brk", - "test:integration": "playwright install && run-p -r serve playwright", - "test:integration-local": "run-p -r serve playwright", + "test:integration": "playwright install --with-deps && run-p -r serve playwright", + "test:integration-local": "playwright install && run-p -r serve playwright", "test:mocha": "mocha --require ./config/babel/register.cjs ./packages/{slate,slate-history,slate-hyperscript}/test/**/*.{js,ts}", "test:jest": "jest --config jest.config.js", "tsc:examples": "tsc --project ./site/tsconfig.example.json", From 3d9f5ae88b63367ea74d4de582ade075cf352c61 Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 9 Oct 2024 23:16:08 +0800 Subject: [PATCH 07/10] fix: undo event when not focused --- .../slate-react/src/components/editable.tsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/slate-react/src/components/editable.tsx b/packages/slate-react/src/components/editable.tsx index f1945d53ae..98ee43887a 100644 --- a/packages/slate-react/src/components/editable.tsx +++ b/packages/slate-react/src/components/editable.tsx @@ -1042,8 +1042,31 @@ export const Editable = forwardRef( op() } deferredOperations.current = [] + + // COMPAT: Since `beforeinput` doesn't fully `preventDefault`, + // there's a chance that content might be placed in the browser's undo stack. + // This means undo can be triggered even when the div is not focused, + // and it only triggers the input event for the node. (2024/10/09) + if (!ReactEditor.isFocused(editor)) { + const native = event.nativeEvent as InputEvent + const maybeHistoryEditor: any = editor + if ( + native.inputType === 'historyUndo' && + typeof maybeHistoryEditor.undo === 'function' + ) { + maybeHistoryEditor.undo() + return + } + if ( + native.inputType === 'historyRedo' && + typeof maybeHistoryEditor.redo === 'function' + ) { + maybeHistoryEditor.redo() + return + } + } }, - [attributes.onInput] + [attributes.onInput, editor] )} onBlur={useCallback( (event: React.FocusEvent) => { From 4aaf39aa532af9990dbc51d1f26a9bb0e7074aee Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 9 Oct 2024 23:24:17 +0800 Subject: [PATCH 08/10] chore: add changeset --- .changeset/curvy-seals-attack.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-seals-attack.md diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md new file mode 100644 index 0000000000..aa574f471b --- /dev/null +++ b/.changeset/curvy-seals-attack.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +fix: sync built-in state on undo when editor is unfocused From d13cea32530c68f8dc8f2e7f570d2e1024d0a5bd Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 16 Oct 2024 09:03:23 +0800 Subject: [PATCH 09/10] chore: just trigger test:integration --- .changeset/curvy-seals-attack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md index aa574f471b..72fbf11dba 100644 --- a/.changeset/curvy-seals-attack.md +++ b/.changeset/curvy-seals-attack.md @@ -2,4 +2,4 @@ 'slate-react': patch --- -fix: sync built-in state on undo when editor is unfocused +fix: sync built-in state on undo when editor is unfocused From 574e45284767ba11d1cc3968725e572cc88bdd7a Mon Sep 17 00:00:00 2001 From: WindRunnerMax <651525974@qq.com> Date: Wed, 16 Oct 2024 09:06:08 +0800 Subject: [PATCH 10/10] chore: trigger test:integration --- .changeset/curvy-seals-attack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/curvy-seals-attack.md b/.changeset/curvy-seals-attack.md index 72fbf11dba..aa574f471b 100644 --- a/.changeset/curvy-seals-attack.md +++ b/.changeset/curvy-seals-attack.md @@ -2,4 +2,4 @@ 'slate-react': patch --- -fix: sync built-in state on undo when editor is unfocused +fix: sync built-in state on undo when editor is unfocused