From 2ea2444e84be345319f32d050ba98c70f65885d2 Mon Sep 17 00:00:00 2001 From: b12f Date: Sun, 13 Oct 2024 17:18:53 +0200 Subject: [PATCH] packages/rich-text: fix tests --- packages/rich-text/lib/types.ts | 5 +++-- packages/rich-text/lib/use-format-types.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/rich-text/lib/types.ts b/packages/rich-text/lib/types.ts index 719cb27..3976d37 100644 --- a/packages/rich-text/lib/types.ts +++ b/packages/rich-text/lib/types.ts @@ -24,8 +24,8 @@ export type RichTextFormatList = Array; */ export interface RichTextValue { text: string; - formats: Array< RichTextFormatList >; - replacements: Array< RichTextFormatList>; + formats: Array; + replacements: Array; activeFormats?: RichTextFormatList; start?: number; end?: number; @@ -64,6 +64,7 @@ export interface RichTextFormat { formatType?: RichTextFormatType; attributes?: Record; unregisteredAttributes?: Record; + innerHTML?: string; } export interface SimpleRange { diff --git a/packages/rich-text/lib/use-format-types.ts b/packages/rich-text/lib/use-format-types.ts index 815ddf6..4b07367 100644 --- a/packages/rich-text/lib/use-format-types.ts +++ b/packages/rich-text/lib/use-format-types.ts @@ -31,16 +31,22 @@ export function useFormatTypes(): FormatTypeStore { formatTypes.value = formatTypes.value.filter(({ name }) => { if (isArray) { - return !!typesToRemove.find((type) => type === name); + return !typesToRemove.find((type) => type === name); } else { - return name === typesToRemove; + return name !== typesToRemove; } }); }; const findFormatType = (fn: (f:RichTextFormatType) => boolean) => formatTypes.value.find(type => fn(type)); const getFormatTypeByName = (name: string) => formatTypes.value.find(type => type.name === name); - const getFormatTypeForClassName = (name: string) => formatTypes.value.find(type => type.className === name); + const getFormatTypeForClassName = (name: string) => formatTypes.value.find(type => { + if ( type.className === null ) { + return false; + } + + return ` ${ name } `.indexOf( ` ${ type.className } ` ) >= 0; + } ); const getFormatTypeForBareElement = (name: string) => formatTypes.value.find(type => type.tagName === name); return {