From d220401d5be1087f38a9ad6858f3bdc75ed9054f Mon Sep 17 00:00:00 2001 From: Ahmed Atigui <98113546+ahmedatigui@users.noreply.github.com> Date: Sat, 30 Nov 2024 16:23:02 +0100 Subject: [PATCH 1/3] fix: type mismatch --- package.json | 2 +- src/index.ts | 27 ++++++++++++++------------- yarn.lock | 8 ++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 2a928c5..8dc0d63 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,6 @@ }, "dependencies": { "@codexteam/icons": "^0.0.5", - "@editorjs/editorjs": "^2.29.1" + "@editorjs/editorjs": "^2.30.7" } } diff --git a/src/index.ts b/src/index.ts index e36face..e03e8d9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,8 @@ import './index.css'; import { IconH1, IconH2, IconH3, IconH4, IconH5, IconH6, IconHeading } from '@codexteam/icons'; -import { API, BlockTune, PasteEvent } from '@editorjs/editorjs'; +import { API, BlockTool, PasteEvent } from '@editorjs/editorjs'; +import type { MenuConfig } from '@editorjs/editorjs/types/tools'; /** * @description Tool's input and output data format @@ -47,7 +48,7 @@ interface ConstructorArgs { /** Previously saved data */ data: HeaderData | {}; /** User config for the tool */ - config: HeaderConfig; + config?: HeaderConfig; /** Editor.js API */ api: API; /** Read-only mode flag */ @@ -62,7 +63,7 @@ interface ConstructorArgs { * @license MIT * @version 2.0.0 */ -export default class Header { +export default class Header implements BlockTool { /** * Render plugin`s main Element and fill it with saved data * @@ -86,7 +87,7 @@ export default class Header { * Tool's settings passed from Editor * @private */ - private _settings: HeaderConfig; + private _config: HeaderConfig | null; /** * Block's data * @private @@ -108,7 +109,7 @@ export default class Header { * @type {HeaderConfig} * @private */ - this._settings = config; + this._config = config ?? null; /** * Block's data @@ -184,7 +185,7 @@ export default class Header { * * @returns {Array} */ - renderSettings(): BlockTune[] { + renderSettings(): MenuConfig { return this.levels.map(level => ({ icon: level.svg, label: this.api.i18n.t(`Heading ${level.number}`), @@ -366,7 +367,7 @@ export default class Header { /** * Add Placeholder */ - tag.dataset.placeholder = this.api.i18n.t(this._settings.placeholder || ''); + tag.dataset.placeholder = this.api.i18n.t(this?._config?.placeholder || ''); return tag; } @@ -395,9 +396,9 @@ export default class Header { /** * User can specify own default level value */ - if (this._settings.defaultLevel) { + if (this?._config?.defaultLevel) { const userSpecified = this.levels.find(levelItem => { - return levelItem.number === this._settings.defaultLevel; + return levelItem.number === this?._config?.defaultLevel; }); if (userSpecified) { @@ -461,8 +462,8 @@ export default class Header { }, ]; - return this._settings.levels ? availableLevels.filter( - l => this._settings.levels!.includes(l.number) + return this?._config?.levels ? availableLevels.filter( + l => this?._config?.levels!.includes(l.number) ) : availableLevels; } @@ -504,9 +505,9 @@ export default class Header { break; } - if (this._settings.levels) { + if (this?._config?.levels) { // Fallback to nearest level when specified not available - level = this._settings.levels.reduce((prevLevel, currLevel) => { + level = this?._config?.levels.reduce((prevLevel, currLevel) => { return Math.abs(currLevel - level) < Math.abs(prevLevel - level) ? currLevel : prevLevel; }); } diff --git a/yarn.lock b/yarn.lock index ec74aea..b706801 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12,10 +12,10 @@ resolved "https://registry.yarnpkg.com/@codexteam/icons/-/icons-0.0.5.tgz#d17f39b6a0497c6439f57dd42711817a3dd3679c" integrity sha512-s6H2KXhLz2rgbMZSkRm8dsMJvyUNZsEjxobBEg9ztdrb1B2H3pEzY6iTwI4XUPJWJ3c3qRKwV4TrO3J5jUdoQA== -"@editorjs/editorjs@^2.29.1": - version "2.29.1" - resolved "https://registry.yarnpkg.com/@editorjs/editorjs/-/editorjs-2.29.1.tgz#d7c644c5c3fc1ea1022373cbf2c8c3ac9f990b7b" - integrity sha512-WRT2pCfikMsvySQJqpCU21LfTZaPuxUWsDO8aFGrPx4MKzOR9D+Ur4mNb3jq0FXx2EMqvIWfTyFixJxtjGHTyQ== +"@editorjs/editorjs@^2.30.7": + version "2.30.7" + resolved "https://registry.yarnpkg.com/@editorjs/editorjs/-/editorjs-2.30.7.tgz#6ba210490c1040c55ef7e5ef040c4c6e3dc722e7" + integrity sha512-FfdeUqrgcKWC+Cy2GW6Dxup6s2TaRKokR4FL+HKXshu6h9Y//rrx4SQkURgkZOCSbV77t9btbmAXdFXWGB+diw== "@esbuild/android-arm64@0.18.20": version "0.18.20" From 50bb6da7a76122c9c4923f755585f8d62eaa53a6 Mon Sep 17 00:00:00 2001 From: Ahmed Atigui <98113546+ahmedatigui@users.noreply.github.com> Date: Sat, 30 Nov 2024 17:03:54 +0100 Subject: [PATCH 2/3] 2.8.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8dc0d63..b007483 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/header", - "version": "2.8.8", + "version": "2.8.9", "keywords": [ "codex editor", "header", From d2065543af90cfe1536de730b58a64f89f55f1a4 Mon Sep 17 00:00:00 2001 From: Ahmed Atigui <98113546+ahmedatigui@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:58:39 +0100 Subject: [PATCH 3/3] fix: rm ? in this?. --- src/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index e03e8d9..313c4a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -367,7 +367,7 @@ export default class Header implements BlockTool { /** * Add Placeholder */ - tag.dataset.placeholder = this.api.i18n.t(this?._config?.placeholder || ''); + tag.dataset.placeholder = this.api.i18n.t(this._config?.placeholder || ''); return tag; } @@ -396,9 +396,9 @@ export default class Header implements BlockTool { /** * User can specify own default level value */ - if (this?._config?.defaultLevel) { + if (this._config?.defaultLevel) { const userSpecified = this.levels.find(levelItem => { - return levelItem.number === this?._config?.defaultLevel; + return levelItem.number === this._config?.defaultLevel; }); if (userSpecified) { @@ -462,8 +462,8 @@ export default class Header implements BlockTool { }, ]; - return this?._config?.levels ? availableLevels.filter( - l => this?._config?.levels!.includes(l.number) + return this._config?.levels ? availableLevels.filter( + l => this._config?.levels!.includes(l.number) ) : availableLevels; } @@ -505,9 +505,9 @@ export default class Header implements BlockTool { break; } - if (this?._config?.levels) { + if (this._config?.levels) { // Fallback to nearest level when specified not available - level = this?._config?.levels.reduce((prevLevel, currLevel) => { + level = this._config?.levels.reduce((prevLevel, currLevel) => { return Math.abs(currLevel - level) < Math.abs(prevLevel - level) ? currLevel : prevLevel; }); }