Skip to content

Commit

Permalink
Merge pull request #29 from editor-js/read-only
Browse files Browse the repository at this point in the history
read only integration
  • Loading branch information
neSpecc committed Oct 1, 2020
2 parents 2fee2bb + 43e5ba9 commit 4832182
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/bundle.js

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": "@editorjs/paragraph",
"version": "2.7.0",
"version": "2.8.0",
"keywords": [
"codex editor",
"paragraph",
Expand Down
27 changes: 22 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ class Paragraph {
* @param {ParagraphData} params.data - previously saved data
* @param {ParagraphConfig} params.config - user config for Tool
* @param {object} params.api - editor.js api
* @param {boolean} readOnly - read only mode flag
*/
constructor({data, config, api}) {
constructor({data, config, api, readOnly}) {
this.api = api;
this.readOnly = readOnly;

this._CSS = {
block: this.api.styles.block,
wrapper: 'ce-paragraph'
};
this.onKeyUp = this.onKeyUp.bind(this);

if (!this.readOnly) {
this.onKeyUp = this.onKeyUp.bind(this);
}

/**
* Placeholder for paragraph if it is first Block
Expand Down Expand Up @@ -90,18 +95,21 @@ class Paragraph {
let div = document.createElement('DIV');

div.classList.add(this._CSS.wrapper, this._CSS.block);
div.contentEditable = true;
div.contentEditable = false;
div.dataset.placeholder = this.api.i18n.t(this._placeholder);

div.addEventListener('keyup', this.onKeyUp);
if (!this.readOnly) {
div.contentEditable = true;
div.addEventListener('keyup', this.onKeyUp);
}

return div;
}

/**
* Return Tool's view
*
* @returns {HTMLDivElement}
* @public
*/
render() {
return this._element;
Expand Down Expand Up @@ -183,6 +191,15 @@ class Paragraph {
};
}

/**
* Returns true to notify the core that read-only mode is supported
*
* @return {boolean}
*/
static get isReadOnlySupported() {
return true;
}

/**
* Get current Tools`s data
* @returns {ParagraphData} Current data
Expand Down

0 comments on commit 4832182

Please sign in to comment.