Skip to content

Commit

Permalink
Merge pull request #106 from editor-js/feature/read-only-mode
Browse files Browse the repository at this point in the history
Add read-only mode support
  • Loading branch information
neSpecc committed Sep 29, 2020
2 parents 33c25a4 + 2d0dcf6 commit a983c4e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/image",
"version": "2.5.0",
"version": "2.6.0",
"keywords": [
"codex editor",
"tool",
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ import Uploader from './uploader';
* @property {string} file.url - [Required] image source URL
*/
export default class ImageTool {
/**
* Notify core that read-only mode is supported
*
* @returns {boolean}
*/
static get isReadOnlySupported() {
return true;
}

/**
* Get Tool toolbox settings
* icon - Tool icon's SVG
Expand All @@ -94,9 +103,11 @@ export default class ImageTool {
* @param {ImageToolData} tool.data - previously saved data
* @param {ImageConfig} tool.config - user config for Tool
* @param {object} tool.api - Editor.js API
* @param {boolean} tool.readOnly - read-only mode flag
*/
constructor({ data, config, api }) {
constructor({ data, config, api, readOnly }) {
this.api = api;
this.readOnly = readOnly;

/**
* Tool's initial config
Expand Down Expand Up @@ -135,6 +146,7 @@ export default class ImageTool {
},
});
},
readOnly,
});

/**
Expand Down
6 changes: 4 additions & 2 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ export default class Ui {
* @param {object} ui.api - Editor.js API
* @param {ImageConfig} ui.config - user config
* @param {Function} ui.onSelectFile - callback for clicks on Select file button
* @param {boolean} ui.readOnly - read-only mode flag
*/
constructor({ api, config, onSelectFile }) {
constructor({ api, config, onSelectFile, readOnly }) {
this.api = api;
this.config = config;
this.onSelectFile = onSelectFile;
this.readOnly = readOnly;
this.nodes = {
wrapper: make('div', [this.CSS.baseClass, this.CSS.wrapper]),
imageContainer: make('div', [ this.CSS.imageContainer ]),
fileButton: this.createFileButton(),
imageEl: undefined,
imagePreloader: make('div', this.CSS.imagePreloader),
caption: make('div', [this.CSS.input, this.CSS.caption], {
contentEditable: true,
contentEditable: !this.readOnly,
}),
};

Expand Down

0 comments on commit a983c4e

Please sign in to comment.