fix(readonly): crash with readonly property (#1969)

* fix(readonly): fix readonly property

Resolves #1968

* changelog added

* Update CHANGELOG.md
This commit is contained in:
Peter Savchenko 2022-02-09 20:46:26 +03:00 committed by GitHub
parent c1bca10d12
commit 640b1a2d7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 4 deletions

View file

@ -1,5 +1,9 @@
# Changelog
### 2.23.2
`Fix` — Crash on initialization in the read-only mode [#1968](https://github.com/codex-team/editor.js/issues/1968)
### 2.23.1
`Fix` — Incorrect release tag fixed

View file

@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.23.1",
"version": "2.23.2",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",

View file

@ -376,7 +376,6 @@ export default class RectangleSelection extends Module {
this.inverseSelection();
SelectionUtils.get().removeAllRanges();
event.preventDefault();
}
/**

View file

@ -227,7 +227,6 @@ export default class Toolbar extends Module<ToolbarNodes> {
this.enableModuleBindings();
} else {
this.destroy();
this.toolboxInstance.destroy();
this.Editor.BlockSettings.destroy();
this.disableModuleBindings();
}
@ -295,6 +294,10 @@ export default class Toolbar extends Module<ToolbarNodes> {
* Close the Toolbar
*/
public close(): void {
if (this.Editor.ReadOnly.isEnabled) {
return;
}
this.nodes.wrapper.classList.remove(this.CSS.toolbarOpened);
/** Close components */
@ -551,7 +554,9 @@ export default class Toolbar extends Module<ToolbarNodes> {
*/
private destroy(): void {
this.removeAllNodes();
this.toolboxInstance.destroy();
if (this.toolboxInstance) {
this.toolboxInstance.destroy();
}
this.tooltip.destroy();
}
}

View file

@ -25,4 +25,26 @@ describe('Editor basic initialization', () => {
.should('be.visible');
});
});
describe('Configuration', () => {
describe('readOnly', () => {
beforeEach(() => {
if (this && this.editorInstance) {
this.editorInstance.destroy();
}
});
it('should create editor without editing ability when true passed', () => {
cy.createEditor({
readOnly: true,
}).as('editorInstance');
cy.get('[data-cy=editorjs]')
.get('div.codex-editor')
.get('div.ce-paragraph')
.invoke('attr', 'contenteditable')
.should('eq', 'false');
});
});
});
});