Skip to content

Commit 83d2d9d

Browse files
authored
Merge pull request #35 from editor-js/feature/read-only-mode
Add read-only mode support
2 parents 8b74d1b + dae258e commit 83d2d9d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

dist/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/code",
3-
"version": "2.5.0",
3+
"version": "2.6.0",
44
"keywords": [
55
"codex editor",
66
"code",

src/index.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ require('./index.css').toString();
1818
* Code Tool for the Editor.js allows to include code examples in your articles.
1919
*/
2020
class CodeTool {
21+
22+
/**
23+
* Notify core that read-only mode is supported
24+
*
25+
* @returns {boolean}
26+
*/
27+
static get isReadOnlySupported() {
28+
return true;
29+
}
30+
2131
/**
2232
* Allow to press Enter inside the CodeTool textarea
2333
*
@@ -40,9 +50,11 @@ class CodeTool {
4050
* @param {CodeData} options.data — previously saved plugin code
4151
* @param {object} options.config - user config for Tool
4252
* @param {object} options.api - Editor.js API
53+
* @param {boolean} options.readOnly - read only mode flag
4354
*/
44-
constructor({ data, config, api }) {
55+
constructor({ data, config, api, readOnly }) {
4556
this.api = api;
57+
this.readOnly = readOnly;
4658

4759
this.placeholder = this.api.i18n.t(config.placeholder || CodeTool.DEFAULT_PLACEHOLDER);
4860

@@ -81,6 +93,10 @@ class CodeTool {
8193

8294
textarea.placeholder = this.placeholder;
8395

96+
if (this.readOnly) {
97+
textarea.disabled = true;
98+
}
99+
84100
wrapper.appendChild(textarea);
85101

86102
this.nodes.textarea = textarea;

0 commit comments

Comments
 (0)