From 0843b0c78adafdf937babd4a5c1afb9022fa87da Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Thu, 28 Nov 2024 19:07:17 +0300 Subject: [PATCH 1/7] update all submodules --- example/tools/checklist | 2 +- example/tools/code | 2 +- example/tools/delimiter | 2 +- example/tools/embed | 2 +- example/tools/header | 2 +- example/tools/image | 2 +- example/tools/inline-code | 2 +- example/tools/nested-list | 2 +- example/tools/quote | 2 +- example/tools/table | 2 +- example/tools/warning | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/example/tools/checklist b/example/tools/checklist index 1c116d5e0..0d1da4242 160000 --- a/example/tools/checklist +++ b/example/tools/checklist @@ -1 +1 @@ -Subproject commit 1c116d5e09e19951948d6166047aa2f30877aaf9 +Subproject commit 0d1da42428eda347c360408aa9e842010176dcd8 diff --git a/example/tools/code b/example/tools/code index f281996f8..82402cb86 160000 --- a/example/tools/code +++ b/example/tools/code @@ -1 +1 @@ -Subproject commit f281996f82c7ac676172757e45687cae27443427 +Subproject commit 82402cb86a327e3c64bef653d953533e2c3613dd diff --git a/example/tools/delimiter b/example/tools/delimiter index 4ca1c1c97..95a5eb90d 160000 --- a/example/tools/delimiter +++ b/example/tools/delimiter @@ -1 +1 @@ -Subproject commit 4ca1c1c972261f47dd34f6b8754763a4a79a4866 +Subproject commit 95a5eb90dd2e2e8ab153eb66b59a70cdafdf2d7f diff --git a/example/tools/embed b/example/tools/embed index f2585abb9..801580fbd 160000 --- a/example/tools/embed +++ b/example/tools/embed @@ -1 +1 @@ -Subproject commit f2585abb9019abf93c18f1dcfa63b07a3dd08318 +Subproject commit 801580fbdb7ab0ad1e975cfdaab38ada6625e301 diff --git a/example/tools/header b/example/tools/header index 477853c16..3e457cbac 160000 --- a/example/tools/header +++ b/example/tools/header @@ -1 +1 @@ -Subproject commit 477853c1646ae479867603847e49071438ffd80c +Subproject commit 3e457cbac2c5da53fff1b02b99ddaccaa577f401 diff --git a/example/tools/image b/example/tools/image index 25d46cd8d..c8236e576 160000 --- a/example/tools/image +++ b/example/tools/image @@ -1 +1 @@ -Subproject commit 25d46cd8d3930851b14ddc26ee80fb5b485e1496 +Subproject commit c8236e5765294f6b6590573910a68d3826671838 diff --git a/example/tools/inline-code b/example/tools/inline-code index dcd4c1774..31a086d7d 160000 --- a/example/tools/inline-code +++ b/example/tools/inline-code @@ -1 +1 @@ -Subproject commit dcd4c17740c9ba636140751596aff1e9f6ef6b01 +Subproject commit 31a086d7dc97169de34b9c191735cba7d63562d6 diff --git a/example/tools/nested-list b/example/tools/nested-list index 591bd2ca6..bbc46d557 160000 --- a/example/tools/nested-list +++ b/example/tools/nested-list @@ -1 +1 @@ -Subproject commit 591bd2ca6839f923e3d37a1ebaad6e5d15075a89 +Subproject commit bbc46d557bb5711dd27517272ae2754e1da04697 diff --git a/example/tools/quote b/example/tools/quote index 9377ca713..bb8cc9d1e 160000 --- a/example/tools/quote +++ b/example/tools/quote @@ -1 +1 @@ -Subproject commit 9377ca713f552576b8b11f77cf371b67261ec00b +Subproject commit bb8cc9d1e14bc9f3a36ebb4bbf44584c0b00bece diff --git a/example/tools/table b/example/tools/table index 2948cd759..5786daeab 160000 --- a/example/tools/table +++ b/example/tools/table @@ -1 +1 @@ -Subproject commit 2948cd7595e632f7555e2dc09e6bac050a2b87ea +Subproject commit 5786daeab68748b4b6842ceb784e4f2b9fde31d8 diff --git a/example/tools/warning b/example/tools/warning index e63e91aa8..0f3ec98b9 160000 --- a/example/tools/warning +++ b/example/tools/warning @@ -1 +1 @@ -Subproject commit e63e91aa833d774be9bf4a76013b1025a009989d +Subproject commit 0f3ec98b9a3b0ea8a9a71cffcb4e596e5c98aecb From 6bc4061232f5ea84360e80a82f0e0750bbac4a7a Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 14 Dec 2024 19:11:37 +0300 Subject: [PATCH 2/7] rm checklist and nested list submodule --- .gitmodules | 6 ------ example/tools/checklist | 1 - example/tools/nested-list | 1 - 3 files changed, 8 deletions(-) delete mode 160000 example/tools/checklist delete mode 160000 example/tools/nested-list diff --git a/.gitmodules b/.gitmodules index 66320775b..98e363c55 100644 --- a/.gitmodules +++ b/.gitmodules @@ -31,9 +31,6 @@ [submodule "example/tools/table"] path = example/tools/table url = https://github.com/editor-js/table -[submodule "example/tools/checklist"] - path = example/tools/checklist - url = https://github.com/editor-js/checklist [submodule "example/tools/link"] path = example/tools/link url = https://github.com/editor-js/link @@ -46,9 +43,6 @@ [submodule "example/tools/underline"] path = example/tools/underline url = https://github.com/editor-js/underline -[submodule "example/tools/nested-list"] - path = example/tools/nested-list - url = https://github.com/editor-js/nested-list [submodule "example/tools/text-variant-tune"] path = example/tools/text-variant-tune url = https://github.com/editor-js/text-variant-tune diff --git a/example/tools/checklist b/example/tools/checklist deleted file mode 160000 index 0d1da4242..000000000 --- a/example/tools/checklist +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0d1da42428eda347c360408aa9e842010176dcd8 diff --git a/example/tools/nested-list b/example/tools/nested-list deleted file mode 160000 index bbc46d557..000000000 --- a/example/tools/nested-list +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bbc46d557bb5711dd27517272ae2754e1da04697 From adb4d992cb05b4183ccb8793ace559e311d0faa3 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 14 Dec 2024 19:17:18 +0300 Subject: [PATCH 3/7] Update .gitmodules --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index 98e363c55..04d291147 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,6 +10,7 @@ [submodule "example/tools/list"] path = example/tools/list url = https://github.com/editor-js/list + branch = main [submodule "example/tools/quote"] path = example/tools/quote url = https://github.com/editor-js/quote From 6545e524262b88fb06b826ce70f9b89a3010da7b Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 14 Dec 2024 19:22:03 +0300 Subject: [PATCH 4/7] rm list submodule --- .gitmodules | 4 ---- example/tools/list | 1 - 2 files changed, 5 deletions(-) delete mode 160000 example/tools/list diff --git a/.gitmodules b/.gitmodules index 04d291147..b4f5e20de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,10 +7,6 @@ [submodule "example/tools/delimiter"] path = example/tools/delimiter url = https://github.com/editor-js/delimiter -[submodule "example/tools/list"] - path = example/tools/list - url = https://github.com/editor-js/list - branch = main [submodule "example/tools/quote"] path = example/tools/quote url = https://github.com/editor-js/quote diff --git a/example/tools/list b/example/tools/list deleted file mode 160000 index a6dc6a692..000000000 --- a/example/tools/list +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a6dc6a692b88c9eff3d87223b239e7517b160c67 From 891dad05abae2424418e14952f26f74d4f211c05 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 14 Dec 2024 19:23:59 +0300 Subject: [PATCH 5/7] add list submodule --- .gitmodules | 3 +++ example/tools/list | 1 + 2 files changed, 4 insertions(+) create mode 160000 example/tools/list diff --git a/.gitmodules b/.gitmodules index b4f5e20de..44e1a2ff4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -43,3 +43,6 @@ [submodule "example/tools/text-variant-tune"] path = example/tools/text-variant-tune url = https://github.com/editor-js/text-variant-tune +[submodule "example/tools/list"] + path = example/tools/list + url = https://github.com/editor-js/list diff --git a/example/tools/list b/example/tools/list new file mode 160000 index 000000000..bbc46d557 --- /dev/null +++ b/example/tools/list @@ -0,0 +1 @@ +Subproject commit bbc46d557bb5711dd27517272ae2754e1da04697 From 52134372405212752247d091b441eafe9c3a748f Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Sat, 14 Dec 2024 19:26:52 +0300 Subject: [PATCH 6/7] all submodules updated --- example/tools/quote | 2 +- example/tools/raw | 2 +- example/tools/table | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example/tools/quote b/example/tools/quote index bb8cc9d1e..78f70cf23 160000 --- a/example/tools/quote +++ b/example/tools/quote @@ -1 +1 @@ -Subproject commit bb8cc9d1e14bc9f3a36ebb4bbf44584c0b00bece +Subproject commit 78f70cf2391cc8aaf2d2e59615de3ad833d180c3 diff --git a/example/tools/raw b/example/tools/raw index cae470fde..84b7d56b2 160000 --- a/example/tools/raw +++ b/example/tools/raw @@ -1 +1 @@ -Subproject commit cae470fded570ef9a82a45734526ccf45959e204 +Subproject commit 84b7d56b26a66d121edb6682ca205bf995d39034 diff --git a/example/tools/table b/example/tools/table index 5786daeab..5a57621c4 160000 --- a/example/tools/table +++ b/example/tools/table @@ -1 +1 @@ -Subproject commit 5786daeab68748b4b6842ceb784e4f2b9fde31d8 +Subproject commit 5a57621c4e1abb884fd03e70862cb05b10bfe405 From 19f3c01e69e317d39993b6871bdd8868ff04dd31 Mon Sep 17 00:00:00 2001 From: Peter Savchenko Date: Thu, 19 Dec 2024 00:27:04 +0300 Subject: [PATCH 7/7] fix(inline-tools): inline tools shortcuts now works in read-only mode --- docs/CHANGELOG.md | 1 + src/components/modules/toolbar/inline.ts | 5 +- src/components/utils/shortcuts.ts | 2 +- test/cypress/tests/ui/InlineToolbar.cy.ts | 58 ++++++++++++++++++++++- test/cypress/tests/utils/popover.cy.ts | 4 +- 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4863ffbe0..5e7bffe1f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,6 +3,7 @@ ### 2.31.0 - `New` - Inline tools (those with `isReadOnlySupported` specified) can now be used in read-only mode +- `New` - Inline tools (those with `isReadOnlySupported` specified) shortcuts now work in read-only mode - `Improvement` - Block manager passes target tool config to the `conversionConfig.import` method on conversion - `Fix` - Fix selection of first block in read-only initialization with "autofocus=true" - `Fix` - Incorrect caret position after blocks merging in Safari diff --git a/src/components/modules/toolbar/inline.ts b/src/components/modules/toolbar/inline.ts index 2e596203a..5aa5f7dab 100644 --- a/src/components/modules/toolbar/inline.ts +++ b/src/components/modules/toolbar/inline.ts @@ -549,7 +549,10 @@ export default class InlineToolbar extends Module { this.popover?.activateItemByName(toolName); }, - on: this.Editor.UI.nodes.redactor, + /** + * We need to bind shortcut to the document to make it work in read-only mode + */ + on: document, }); } diff --git a/src/components/utils/shortcuts.ts b/src/components/utils/shortcuts.ts index 12adf10c1..8cf51ff93 100644 --- a/src/components/utils/shortcuts.ts +++ b/src/components/utils/shortcuts.ts @@ -28,7 +28,7 @@ export interface ShortcutData { /** * Element handler should be added for */ - on: HTMLElement; + on: HTMLElement | Document; } /** diff --git a/test/cypress/tests/ui/InlineToolbar.cy.ts b/test/cypress/tests/ui/InlineToolbar.cy.ts index eca588172..5c337b196 100644 --- a/test/cypress/tests/ui/InlineToolbar.cy.ts +++ b/test/cypress/tests/ui/InlineToolbar.cy.ts @@ -1,6 +1,6 @@ - import Header from '@editorjs/header'; -import type { MenuConfig } from '../../../../types/tools'; +import type { InlineTool, MenuConfig } from '../../../../types/tools'; +import { createEditorWithTextBlocks } from '../../support/utils/createEditorWithTextBlocks'; describe('Inline Toolbar', () => { describe('Separators', () => { @@ -174,4 +174,58 @@ describe('Inline Toolbar', () => { .should('have.attr', 'data-item-name', 'test-tool'); }); }); + + describe('Shortcuts', () => { + it('should work in read-only mode', () => { + const toolSurround = cy.stub().as('toolSurround'); + + /* eslint-disable jsdoc/require-jsdoc */ + class Marker implements InlineTool { + public static isInline = true; + public static shortcut = 'CMD+SHIFT+M'; + public static isReadOnlySupported = true; + public render(): MenuConfig { + return { + icon: 'm', + title: 'Marker', + onActivate: () => { + toolSurround(); + }, + }; + } + } + /* eslint-enable jsdoc/require-jsdoc */ + + createEditorWithTextBlocks([ + 'some text', + ], { + tools: { + marker: Marker, + }, + readOnly: true, + }); + + cy.get('[data-cy=editorjs]') + .find('.ce-paragraph') + .selectText('text'); + + cy.wait(300); + + cy.document().then((doc) => { + doc.dispatchEvent(new KeyboardEvent('keydown', { + bubbles: true, + cancelable: true, + key: 'M', + code: 'KeyM', + keyCode: 77, + which: 77, + metaKey: true, + shiftKey: true, + })); + }); + + cy.get('@toolSurround').should('have.been.called'); + }); + }); }); + diff --git a/test/cypress/tests/utils/popover.cy.ts b/test/cypress/tests/utils/popover.cy.ts index 28ae3001f..5d42a492f 100644 --- a/test/cypress/tests/utils/popover.cy.ts +++ b/test/cypress/tests/utils/popover.cy.ts @@ -881,7 +881,7 @@ describe('Popover', () => { .should('exist'); }); - it.only('shoould support i18n in nested popover', () => { + it('shoould support i18n in nested popover', () => { /** * */ @@ -1076,7 +1076,7 @@ describe('Popover', () => { .should('exist'); }); - it.only('should allow to reach nested popover via keyboard', () => { + it('should allow to reach nested popover via keyboard', () => { cy.createEditor({ tools: { header: {