Skip to content

Commit 640b1a2

Browse files
authored
fix(readonly): crash with readonly property (#1969)
* fix(readonly): fix readonly property Resolves #1968 * changelog added * Update CHANGELOG.md
1 parent c1bca10 commit 640b1a2

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

docs/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
### 2.23.2
4+
5+
`Fix` — Crash on initialization in the read-only mode [#1968](https://github.com/codex-team/editor.js/issues/1968)
6+
37
### 2.23.1
48

59
`Fix` — Incorrect release tag fixed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/editorjs",
3-
"version": "2.23.1",
3+
"version": "2.23.2",
44
"description": "Editor.js — Native JS, based on API and Open Source",
55
"main": "dist/editor.js",
66
"types": "./types/index.d.ts",

src/components/modules/rectangleSelection.ts

-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ export default class RectangleSelection extends Module {
376376
this.inverseSelection();
377377

378378
SelectionUtils.get().removeAllRanges();
379-
event.preventDefault();
380379
}
381380

382381
/**

src/components/modules/toolbar/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ export default class Toolbar extends Module<ToolbarNodes> {
227227
this.enableModuleBindings();
228228
} else {
229229
this.destroy();
230-
this.toolboxInstance.destroy();
231230
this.Editor.BlockSettings.destroy();
232231
this.disableModuleBindings();
233232
}
@@ -295,6 +294,10 @@ export default class Toolbar extends Module<ToolbarNodes> {
295294
* Close the Toolbar
296295
*/
297296
public close(): void {
297+
if (this.Editor.ReadOnly.isEnabled) {
298+
return;
299+
}
300+
298301
this.nodes.wrapper.classList.remove(this.CSS.toolbarOpened);
299302

300303
/** Close components */
@@ -551,7 +554,9 @@ export default class Toolbar extends Module<ToolbarNodes> {
551554
*/
552555
private destroy(): void {
553556
this.removeAllNodes();
554-
this.toolboxInstance.destroy();
557+
if (this.toolboxInstance) {
558+
this.toolboxInstance.destroy();
559+
}
555560
this.tooltip.destroy();
556561
}
557562
}

test/cypress/tests/initialization.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,26 @@ describe('Editor basic initialization', () => {
2525
.should('be.visible');
2626
});
2727
});
28+
29+
describe('Configuration', () => {
30+
describe('readOnly', () => {
31+
beforeEach(() => {
32+
if (this && this.editorInstance) {
33+
this.editorInstance.destroy();
34+
}
35+
});
36+
37+
it('should create editor without editing ability when true passed', () => {
38+
cy.createEditor({
39+
readOnly: true,
40+
}).as('editorInstance');
41+
42+
cy.get('[data-cy=editorjs]')
43+
.get('div.codex-editor')
44+
.get('div.ce-paragraph')
45+
.invoke('attr', 'contenteditable')
46+
.should('eq', 'false');
47+
});
48+
});
49+
});
2850
});

0 commit comments

Comments
 (0)