mirror of
https://github.com/codex-team/editor.js
synced 2026-03-16 07:35:48 +01:00
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:
parent
530ec56bb8
commit
0ae8075f61
2 changed files with 13 additions and 4 deletions
10
types/tools/block-tool.d.ts
vendored
10
types/tools/block-tool.d.ts
vendored
|
|
@ -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
|
||||
|
|
|
|||
7
types/tools/tool.d.ts
vendored
7
types/tools/tool.d.ts
vendored
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue