Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type mismatch #123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
},
"dependencies": {
"@codexteam/icons": "^0.0.5",
"@editorjs/editorjs": "^2.29.1"
"@editorjs/editorjs": "^2.30.7"
}
}
27 changes: 14 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand All @@ -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
*
Expand All @@ -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
Expand All @@ -108,7 +109,7 @@ export default class Header {
* @type {HeaderConfig}
* @private
*/
this._settings = config;
this._config = config ?? null;

/**
* Block's data
Expand Down Expand Up @@ -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}`),
Expand Down Expand Up @@ -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 || '');
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

return tag;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
});
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
version "0.18.20"
Expand Down