Skip to content

Commit 0ae8075

Browse files
committed
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
1 parent 530ec56 commit 0ae8075

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

types/tools/block-tool.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import { MenuConfig } from './menu-config';
1313
*/
1414
export interface BlockTool extends BaseTool {
1515
/**
16-
* Sanitizer rules description
16+
* Sanitizer rules description.
17+
*
18+
* @example Flat config (tag-level rules applied to all output)
19+
* { b: true, a: { href: true } }
20+
*
21+
* @example Per-field config
22+
* { text: { br: true, b: true }, caption: { b: true, i: true } }
1723
*/
18-
sanitize?: SanitizerConfig;
24+
sanitize?: SanitizerConfig | Record<string, SanitizerConfig>;
1925

2026
/**
2127
* Process Tool's element in DOM and return raw data

types/tools/tool.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ export interface BaseToolConstructable {
3737
isInline?: boolean;
3838

3939
/**
40-
* Tool`s sanitizer configuration
40+
* Tool`s sanitizer configuration.
41+
*
42+
* For Block Tools, can be a Record mapping data field names to their SanitizerConfig.
43+
* For Inline Tools, should be a flat SanitizerConfig with tag names as keys.
4144
*/
42-
sanitize?: SanitizerConfig;
45+
sanitize?: SanitizerConfig | Record<string, SanitizerConfig>;
4346

4447
/**
4548
* Title of Inline Tool.

0 commit comments

Comments
 (0)