From 0ae8075f61b0484ae9eda52501c3ee16d8a8cb80 Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 11 Mar 2026 19:56:18 -0700 Subject: [PATCH] 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 ddf47896..740a7a22 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 17aa0f2d..2605911e 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.