Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jalners committed Oct 11, 2022
2 parents a67361f + 6ffd79d commit 281d9e1
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 14 additions & 2 deletions src/wproofreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export default class WProofreader extends Plugin {
'RealTimeCollaborativeComments',
'RealTimeCollaborationClient'
];

this._restrictedEditingName = 'RestrictedEditingMode';
}

/**
Expand Down Expand Up @@ -168,7 +170,8 @@ 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();
}

Expand All @@ -194,14 +197,23 @@ 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._restrictedEditingName);
}

/**
* Creates options for the {@code WEBSPELLCHECKER} initialization.
* @private
*/
_createOptions() {
return {
appType: 'proofreader_ck5',
disableDialog: this._isMultiRoot || this._isCollaboration,
disableDialog: this._isMultiRoot || this._isCollaborationMode,
restrictedEditingMode: this._isRestrictedEditingMode,
hideStaticActions: true,
disableBadgePulsing: true,
onCommitOptions: this._onCommitOptions.bind(this),
Expand Down
34 changes: 27 additions & 7 deletions src/wproofreaderediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ export default class WProofreaderEditing extends Plugin {
*/
init() {
this._addCommands();
this._enableInTrackChanges();
}

/**
* Initializes the {@code WProofreaderEditing} plugin in the third initialization stage.
* @public
*/
afterInit() {
this._enableInModes([
{ modeName: 'TrackChanges', editingName: 'TrackChangesEditing' },
{ modeName: 'RestrictedEditingMode', editingName: 'RestrictedEditingModeEditing' }
]);
}

/**
Expand All @@ -34,17 +44,27 @@ 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 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
*/
_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));
}
}
}
37 changes: 37 additions & 0 deletions tests/mocks/mock-restricted-editing-mode.js
Original file line number Diff line number Diff line change
@@ -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() { }
}
21 changes: 21 additions & 0 deletions tests/wproofreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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, {
Expand Down
11 changes: 9 additions & 2 deletions tests/wproofreaderediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@ 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');
document.body.appendChild(element);

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');
});
});

afterEach(() => {
element.remove();
wproofreaderEditing = null;
trackChangesEditing = null;
restrictedEditingModeEditing = null;

return testEditor.destroy();
});
Expand All @@ -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);
});
});

0 comments on commit 281d9e1

Please sign in to comment.