From 766ace64dbeb433fa8c8aa3dace259b5e7f1d8b0 Mon Sep 17 00:00:00 2001 From: Alexey Neretin Date: Tue, 6 Sep 2022 16:11:29 +0300 Subject: [PATCH 1/5] Add support to the restricted editing mode --- src/wproofreader.js | 12 +++++++ src/wproofreaderediting.js | 22 ++++++++---- tests/mocks/mock-restricted-editing-mode.js | 37 +++++++++++++++++++++ tests/wproofreader.js | 21 ++++++++++++ tests/wproofreaderediting.js | 11 ++++-- 5 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 tests/mocks/mock-restricted-editing-mode.js diff --git a/src/wproofreader.js b/src/wproofreader.js index adf602a..1760d17 100644 --- a/src/wproofreader.js +++ b/src/wproofreader.js @@ -46,6 +46,8 @@ export default class WProofreader extends Plugin { 'RealTimeCollaborativeComments', 'RealTimeCollaborationClient' ]; + + this._restrictedEditingMode = 'RestrictedEditingMode'; } /** @@ -169,6 +171,7 @@ export default class WProofreader extends Plugin { _setFields() { this._isMultiRoot = this._checkMultiRoot(); this._isCollaboration = this._checkCollaborationMode(); + this._isRestrictedEditingMode = this._checkRestrictedEditingMode(); this._options = this._createOptions(); } @@ -194,6 +197,14 @@ export default class WProofreader extends Plugin { return false; } + /** + * Checks if the current editor in the restricted editing mode. + * @private + */ + _checkRestrictedEditingMode() { + return this.editor.plugins.has(this._restrictedEditingMode); + } + /** * Creates options for the {@code WEBSPELLCHECKER} initialization. * @private @@ -202,6 +213,7 @@ export default class WProofreader extends Plugin { return { appType: 'proofreader_ck5', disableDialog: this._isMultiRoot || this._isCollaboration, + restrictedEditingMode: this._isRestrictedEditingMode, hideStaticActions: true, disableBadgePulsing: true, onCommitOptions: this._onCommitOptions.bind(this), diff --git a/src/wproofreaderediting.js b/src/wproofreaderediting.js index f47431f..8bad624 100644 --- a/src/wproofreaderediting.js +++ b/src/wproofreaderediting.js @@ -20,7 +20,15 @@ export default class WProofreaderEditing extends Plugin { */ init() { this._addCommands(); - this._enableInTrackChanges(); + } + + /** + * Initializes the {@code WProofreaderEditing} plugin in the third initialization stage. + * @public + */ + afterInit() { + this._enableInMode('TrackChanges', 'TrackChangesEditing'); + this._enableInMode('RestrictedEditingMode', 'RestrictedEditingModeEditing'); } /** @@ -34,17 +42,17 @@ export default class WProofreaderEditing extends Plugin { } /** - * Enables the {@code WProofreader} commands in the Track Changes mode. + * Enables the {@code WProofreader} commands in a certain CKEditor 5 mode. * @private */ - _enableInTrackChanges() { - const isTrackChangesLoaded = this.editor.plugins.has('TrackChanges'); + _enableInMode(modeName, editingName) { + const isModeLoaded = this.editor.plugins.has(modeName); - if (isTrackChangesLoaded) { - const trackChangesEditing = this.editor.plugins.get('TrackChangesEditing'); + if (isModeLoaded) { + const editing = this.editor.plugins.get(editingName); const commands = ['WProofreaderToggle', 'WProofreaderSettings', 'WProofreaderDialog']; - commands.forEach((command) => trackChangesEditing.enableCommand(command)); + commands.forEach((command) => editing.enableCommand(command)); } } } diff --git a/tests/mocks/mock-restricted-editing-mode.js b/tests/mocks/mock-restricted-editing-mode.js new file mode 100644 index 0000000..7a96038 --- /dev/null +++ b/tests/mocks/mock-restricted-editing-mode.js @@ -0,0 +1,37 @@ +import Plugin from '@ckeditor/ckeditor5-core/src/plugin'; + +export class RestrictedEditingMode extends Plugin { + + static get pluginName() { + return 'RestrictedEditingMode'; + } + + static get requires() { + return [RestrictedEditingModeEditing]; + } + + init() { } + + destroy() { } +} + +export class RestrictedEditingModeEditing extends Plugin { + + static get pluginName() { + return 'RestrictedEditingModeEditing'; + } + + constructor() { + super(); + + this.counter = 0; + } + + init() { } + + enableCommand() { + this.counter++; + } + + destroy() { } +} diff --git a/tests/wproofreader.js b/tests/wproofreader.js index 993252d..fb13c73 100644 --- a/tests/wproofreader.js +++ b/tests/wproofreader.js @@ -6,6 +6,7 @@ import { RealTimeCollaborativeEditing } from './mocks/mock-collaboration-editing import { RealTimeCollaborativeTrackChanges } from './mocks/mock-collaboration-editing'; import { RealTimeCollaborativeComments } from './mocks/mock-collaboration-editing'; import { RealTimeCollaborationClient } from './mocks/mock-collaboration-editing'; +import { RestrictedEditingMode } from './mocks/mock-restricted-editing-mode'; describe('WProofreader', () => { const WPROOFREADER_CONFIG = { @@ -80,6 +81,10 @@ describe('WProofreader', () => { expect(wproofreader._options.disableDialog).to.be.false; }); + it('should contain restrictedEditingMode option', () => { + expect(wproofreader._options.restrictedEditingMode).to.be.false; + }); + it('should hide static actions', () => { expect(wproofreader._options.hideStaticActions).to.be.true; }); @@ -493,6 +498,22 @@ describe('WProofreader', () => { }); }); + describe('in CKEditor 5 restricted editing mode', () => { + it('should enable the restrictedEditingMode option of the WEBSPELLCHECKER because of RestrictedEditingMode plugin', () => { + return ClassicEditor + .create(element, { + plugins: [WProofreader, RestrictedEditingMode], + wproofreader: WPROOFREADER_CONFIG + }) + .then((editor) => { + const wproofreader = editor.plugins.get('WProofreader'); + + expect(editor.plugins.has('RestrictedEditingMode')).to.be.true; + expect(wproofreader._options.restrictedEditingMode).to.be.true; + }); + }); + }); + describe('for multi root environment', () => { it('should disable the dialog option of the WEBSPELLCHECKER', () => { const editor = new ClassicEditor(element, { diff --git a/tests/wproofreaderediting.js b/tests/wproofreaderediting.js index 67768fb..a8af234 100644 --- a/tests/wproofreaderediting.js +++ b/tests/wproofreaderediting.js @@ -4,9 +4,10 @@ import WProofreaderToggleCommand from '../src/wproofreadertogglecommand'; import WProofreaderSettingsCommand from '../src/wproofreadersettingscommand'; import WProofreaderDialogCommand from '../src/wproofreaderdialogcommand'; import { TrackChanges } from './mocks/mock-track-changes-editing'; +import { RestrictedEditingMode } from './mocks/mock-restricted-editing-mode'; describe('WProofreaderEditing', () => { - let element, wproofreaderEditing, trackChangesEditing, testEditor; + let element, wproofreaderEditing, trackChangesEditing, restrictedEditingModeEditing, testEditor; beforeEach(() => { element = document.createElement('div'); @@ -14,12 +15,13 @@ describe('WProofreaderEditing', () => { return ClassicEditor .create(element, { - plugins: [WProofreaderEditing, TrackChanges] + plugins: [WProofreaderEditing, TrackChanges, RestrictedEditingMode] }) .then((editor) => { testEditor = editor; wproofreaderEditing = testEditor.plugins.get('WProofreaderEditing'); trackChangesEditing = testEditor.plugins.get('TrackChangesEditing'); + restrictedEditingModeEditing = testEditor.plugins.get('RestrictedEditingModeEditing'); }); }); @@ -27,6 +29,7 @@ describe('WProofreaderEditing', () => { element.remove(); wproofreaderEditing = null; trackChangesEditing = null; + restrictedEditingModeEditing = null; return testEditor.destroy(); }); @@ -51,4 +54,8 @@ describe('WProofreaderEditing', () => { it('should enable WProofreader commands in the Track Changes mode', () => { expect(trackChangesEditing.counter).to.be.equal(3); }); + + it('should enable WProofreader commands in the Restricted Editing mode', () => { + expect(restrictedEditingModeEditing.counter).to.be.equal(3); + }); }); From 4c26cb4b0180ae6b70a3b34b6f461238985c1a1c Mon Sep 17 00:00:00 2001 From: Alexey Neretin Date: Tue, 6 Sep 2022 16:42:57 +0300 Subject: [PATCH 2/5] Rename the restricted editing mode variable --- src/wproofreader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wproofreader.js b/src/wproofreader.js index 1760d17..74e4d34 100644 --- a/src/wproofreader.js +++ b/src/wproofreader.js @@ -47,7 +47,7 @@ export default class WProofreader extends Plugin { 'RealTimeCollaborationClient' ]; - this._restrictedEditingMode = 'RestrictedEditingMode'; + this._restrictedEditingName = 'RestrictedEditingMode'; } /** @@ -202,7 +202,7 @@ export default class WProofreader extends Plugin { * @private */ _checkRestrictedEditingMode() { - return this.editor.plugins.has(this._restrictedEditingMode); + return this.editor.plugins.has(this._restrictedEditingName); } /** From db4c4fb89a0927dc02f34a289f5132c3840d04ef Mon Sep 17 00:00:00 2001 From: Alexey Neretin Date: Tue, 6 Sep 2022 17:01:39 +0300 Subject: [PATCH 3/5] Update the enableInMode functionality in the wproofreaderediting plugin --- src/wproofreaderediting.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wproofreaderediting.js b/src/wproofreaderediting.js index 8bad624..0ab18d6 100644 --- a/src/wproofreaderediting.js +++ b/src/wproofreaderediting.js @@ -27,8 +27,10 @@ export default class WProofreaderEditing extends Plugin { * @public */ afterInit() { - this._enableInMode('TrackChanges', 'TrackChangesEditing'); - this._enableInMode('RestrictedEditingMode', 'RestrictedEditingModeEditing'); + this._enableInModes([ + { modeName: 'TrackChanges', editingName: 'TrackChangesEditing' }, + { modeName: 'RestrictedEditingMode', editingName: 'RestrictedEditingModeEditing' } + ]); } /** @@ -41,6 +43,16 @@ export default class WProofreaderEditing extends Plugin { this.editor.commands.add('WProofreaderDialog', new WProofreaderDialogCommand(this.editor)); } + /** + * Enables the {@code WProofreader} commands in a certain CKEditor 5 modes. + * @private + */ + _enableInModes(modes) { + modes.forEach((mode) => { + this._enableInMode(mode.modeName, mode.editingName); + }); + } + /** * Enables the {@code WProofreader} commands in a certain CKEditor 5 mode. * @private From 18be3e8f2ea1381dfddeff691a79141cf0a71d69 Mon Sep 17 00:00:00 2001 From: Alexey Neretin Date: Tue, 6 Sep 2022 17:13:17 +0300 Subject: [PATCH 4/5] Rename the isCollaboration variable in the wproofreader plugin --- src/wproofreader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wproofreader.js b/src/wproofreader.js index 74e4d34..7de2b1a 100644 --- a/src/wproofreader.js +++ b/src/wproofreader.js @@ -170,7 +170,7 @@ export default class WProofreader extends Plugin { */ _setFields() { this._isMultiRoot = this._checkMultiRoot(); - this._isCollaboration = this._checkCollaborationMode(); + this._isCollaborationMode = this._checkCollaborationMode(); this._isRestrictedEditingMode = this._checkRestrictedEditingMode(); this._options = this._createOptions(); } @@ -212,7 +212,7 @@ export default class WProofreader extends Plugin { _createOptions() { return { appType: 'proofreader_ck5', - disableDialog: this._isMultiRoot || this._isCollaboration, + disableDialog: this._isMultiRoot || this._isCollaborationMode, restrictedEditingMode: this._isRestrictedEditingMode, hideStaticActions: true, disableBadgePulsing: true, From 49f96b4501bd00e762d8ca7ba24b482e90502505 Mon Sep 17 00:00:00 2001 From: Alexey Neretin Date: Tue, 11 Oct 2022 09:49:02 +0300 Subject: [PATCH 5/5] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6aa458..a8e3509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # WProofreader plugin for CKEditor 5 Changelog +## 2.2.0 – 2022-10-11 + +* Make WProofreader work with Restricted Editing mode. [#31](https://github.com/WebSpellChecker/wproofreader/issues/31). + +The new version of the plugin is compatible with WebSpellChecker v5.25.0 and higher. + ## 2.1.0 – 2022-05-04 * Added functionality that properly disables the plugin for certain editor's modes. diff --git a/package-lock.json b/package-lock.json index 6c85eba..d4c374b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@webspellchecker/wproofreader-ckeditor5", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 91651e1..c323f20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webspellchecker/wproofreader-ckeditor5", - "version": "2.1.0", + "version": "2.2.0", "description": "Multilingual spelling and grammar checking plugin for CKEditor 5", "repository": { "type": "git",