From 0ae8075f61b0484ae9eda52501c3ee16d8a8cb80 Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 11 Mar 2026 19:56:18 -0700 Subject: [PATCH 1/2] Fix sanitize type to accept per-field SanitizerConfig The sanitize property on BlockTool and BaseToolConstructable was typed as SanitizerConfig, which only allows tag-name keys with SanitizerRule values. In practice, Block Tools return an object mapping data field names to their own SanitizerConfig (as documented and used by official plugins like Paragraph and Quote). This caused TypeScript errors when using functions as sanitizer rules within per-field configs, since the type system tried to match the function against TagConfig's { [attr: string]: boolean | string }. Widen the type to SanitizerConfig | Record to match the runtime behavior already handled by cleanObject() in src/components/utils/sanitizer.ts. Fixes #2957 --- types/tools/block-tool.d.ts | 10 ++++++++-- types/tools/tool.d.ts | 7 +++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/types/tools/block-tool.d.ts b/types/tools/block-tool.d.ts index ddf478968..740a7a22d 100644 --- a/types/tools/block-tool.d.ts +++ b/types/tools/block-tool.d.ts @@ -13,9 +13,15 @@ import { MenuConfig } from './menu-config'; */ export interface BlockTool extends BaseTool { /** - * Sanitizer rules description + * Sanitizer rules description. + * + * @example Flat config (tag-level rules applied to all output) + * { b: true, a: { href: true } } + * + * @example Per-field config + * { text: { br: true, b: true }, caption: { b: true, i: true } } */ - sanitize?: SanitizerConfig; + sanitize?: SanitizerConfig | Record; /** * Process Tool's element in DOM and return raw data diff --git a/types/tools/tool.d.ts b/types/tools/tool.d.ts index 17aa0f2d9..2605911e1 100644 --- a/types/tools/tool.d.ts +++ b/types/tools/tool.d.ts @@ -37,9 +37,12 @@ export interface BaseToolConstructable { isInline?: boolean; /** - * Tool`s sanitizer configuration + * Tool`s sanitizer configuration. + * + * For Block Tools, can be a Record mapping data field names to their SanitizerConfig. + * For Inline Tools, should be a flat SanitizerConfig with tag names as keys. */ - sanitize?: SanitizerConfig; + sanitize?: SanitizerConfig | Record; /** * Title of Inline Tool. From 2bfe2e51770a7e8d8634a691fa17500795e308cf Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 16 Mar 2026 07:41:49 -0700 Subject: [PATCH 2/2] Bump version to 2.31.6 and add changelog entry --- docs/CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3367bec6a..bca6f9236 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2.31.6 + +- `Fix` - Widen `sanitize` type on `BlockTool` and `BaseToolConstructable` to accept per-field `SanitizerConfig` + ### 2.31.5 - `Fix` - Handle __Ctrl + click__ on links with inline styles applied (e.g., bold, italic) diff --git a/package.json b/package.json index ee5f1499e..3d964610b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@editorjs/editorjs", - "version": "2.31.5", + "version": "2.31.6", "description": "Editor.js — open source block-style WYSIWYG editor with JSON output", "main": "dist/editorjs.umd.js", "module": "dist/editorjs.mjs",