From dbd81db4a363d6559a24191bd7961f929564a71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngela=20Coelho?= Date: Fri, 17 Nov 2023 16:26:34 +0000 Subject: [PATCH 1/3] Add name to block tunes --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 3e15171..a777efa 100644 --- a/src/index.js +++ b/src/index.js @@ -116,6 +116,7 @@ export default class Header { renderSettings() { return this.levels.map(level => ({ icon: level.svg, + name: level.tag, label: this.api.i18n.t(`Heading ${level.number}`), onActivate: () => this.setLevel(level.number), closeOnActivate: true, From 6f9e57ec1a969ebde0af18fae182f25d903796ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngela=20Coelho?= Date: Fri, 12 Jan 2024 16:54:11 +0000 Subject: [PATCH 2/3] Revert "Add name to block tunes" This reverts commit dbd81db4a363d6559a24191bd7961f929564a71e. --- src/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.js b/src/index.js index a777efa..3e15171 100644 --- a/src/index.js +++ b/src/index.js @@ -116,7 +116,6 @@ export default class Header { renderSettings() { return this.levels.map(level => ({ icon: level.svg, - name: level.tag, label: this.api.i18n.t(`Heading ${level.number}`), onActivate: () => this.setLevel(level.number), closeOnActivate: true, From 4de2d8117cf4a55f4e9b4426aba499b2d2292efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngela=20Coelho?= Date: Fri, 12 Jan 2024 17:23:23 +0000 Subject: [PATCH 3/3] Add preserveBlank config param --- README.md | 1 + src/index.js | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e0d5d9a..bc4fb19 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ All properties are optional. | placeholder | `string` | header's placeholder string | | levels | `number[]` | enabled heading levels | | defaultLevel | `number` | default heading level | +| preserveBlank | `boolean` | (default: `false`) Whether or not to keep blank headers when saving editor data | ```javascript var editor = EditorJS({ diff --git a/src/index.js b/src/index.js index 3e15171..75d99cb 100644 --- a/src/index.js +++ b/src/index.js @@ -18,6 +18,7 @@ import { IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconHeading } from '@co * @property {string} placeholder — Block's placeholder * @property {number[]} levels — Heading levels * @property {number} defaultLevel — default level + * @property {boolean} preserveBlank - Whether or not to keep blank headers when saving editor data */ /** @@ -160,7 +161,11 @@ export default class Header { * @public */ validate(blockData) { - return blockData.text.trim() !== ''; + if (blockData.text.trim() === '' && !this.preserveBlank) { + return false; + } + + return true; } /** @@ -399,6 +404,17 @@ export default class Header { ) : availableLevels; } + /** + * Get preserveBlank + * + * @returns {preserveBlank} + */ + get preserveBlank() { + let preserveBlank = this._settings.preserveBlank || false; + + return preserveBlank; + } + /** * Handle H1-H6 tags on paste to substitute it with header Tool *