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<string, SanitizerConfig>
to match the runtime behavior already handled by cleanObject() in
src/components/utils/sanitizer.ts.

Fixes #2957
This commit is contained in:
John Costa 2026-03-11 19:56:18 -07:00
commit 0ae8075f61
No known key found for this signature in database
2 changed files with 13 additions and 4 deletions

View file

@ -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<string, SanitizerConfig>;
/**
* Process Tool's element in DOM and return raw data

View file

@ -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<string, SanitizerConfig>;
/**
* Title of Inline Tool.