From a67e699991d0326f3a5d0f6b723607d49adf80bf Mon Sep 17 00:00:00 2001 From: Tomoyuki Hata Date: Tue, 2 Mar 2021 22:34:23 +0900 Subject: [PATCH] Fix SanitizerConfig type definition (#1456) * Fix SanitizerConfig type definition * Update docs/CHANGELOG.md Co-authored-by: Peter Savchenko * Fix CHANGELOG * Add JSDoc to TagConfig * yarn lint:fix Co-authored-by: Peter Savchenko Co-authored-by: George Berezhnoy --- docs/CHANGELOG.md | 1 + src/types-internal/html-janitor.d.ts | 8 +++++++- types/configs/sanitizer-config.d.ts | 8 +++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index db93b36f..cb13dce3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -13,6 +13,7 @@ - `Fix` - Fix an unstable block cut process [#1489](https://github.com/codex-team/editor.js/issues/1489). - `Fix` - Type definition of the Sanitizer config: the sanitize function now contains param definition [#1491](https://github.com/codex-team/editor.js/pull/1491). - `Fix` - Fix unexpected behavior on an empty link pasting [#1348](https://github.com/codex-team/editor.js/issues/1348). +- `Fix` - Fix SanitizerConfig type definition [#1513](https://github.com/codex-team/editor.js/issues/1513) - `Refactoring` - The Listeners module now is a util. - `Fix` - Editor Config now immutable [#1552](https://github.com/codex-team/editor.js/issues/1552). diff --git a/src/types-internal/html-janitor.d.ts b/src/types-internal/html-janitor.d.ts index 6f9cc035..66f1c6a3 100644 --- a/src/types-internal/html-janitor.d.ts +++ b/src/types-internal/html-janitor.d.ts @@ -3,9 +3,15 @@ * After that we can use it at the TS modules */ declare module 'html-janitor' { + /** + * Sanitizer config of each HTML element + * @see {@link https://github.com/guardian/html-janitor#options} + */ + type TagConfig = boolean | { [attr: string]: boolean | string }; + interface Config { tags: { - [key: string]: boolean|{[attr: string]: boolean|string}|(() => any) + [key: string]: TagConfig | ((el: Element) => TagConfig) }; } diff --git a/types/configs/sanitizer-config.d.ts b/types/configs/sanitizer-config.d.ts index dad68927..e15df7f3 100644 --- a/types/configs/sanitizer-config.d.ts +++ b/types/configs/sanitizer-config.d.ts @@ -1,3 +1,9 @@ +/** + * Sanitizer config of each HTML element + * @see {@link https://github.com/guardian/html-janitor#options} + */ +type TagConfig = boolean | { [attr: string]: boolean | string }; + export interface SanitizerConfig { /** * Tag name and params not to be stripped off @@ -31,5 +37,5 @@ export interface SanitizerConfig { * } * } */ - [key: string]: boolean|{[attr: string]: boolean|string}|((el?: Element) => any); + [key: string]: TagConfig | ((el: Element) => TagConfig); }