packages/rich-text: fix tests

This commit is contained in:
b12f 2024-10-13 17:18:53 +02:00
parent 4fe03486eb
commit 2ea2444e84
Signed by: b12f
GPG key ID: 729956E1124F8F26
2 changed files with 12 additions and 5 deletions

View file

@ -24,8 +24,8 @@ export type RichTextFormatList = Array<RichTextFormat>;
*/ */
export interface RichTextValue { export interface RichTextValue {
text: string; text: string;
formats: Array< RichTextFormatList >; formats: Array<RichTextFormatList>;
replacements: Array< RichTextFormatList>; replacements: Array<RichTextFormatList>;
activeFormats?: RichTextFormatList; activeFormats?: RichTextFormatList;
start?: number; start?: number;
end?: number; end?: number;
@ -64,6 +64,7 @@ export interface RichTextFormat {
formatType?: RichTextFormatType; formatType?: RichTextFormatType;
attributes?: Record<string, any>; attributes?: Record<string, any>;
unregisteredAttributes?: Record<string, any>; unregisteredAttributes?: Record<string, any>;
innerHTML?: string;
} }
export interface SimpleRange { export interface SimpleRange {

View file

@ -31,16 +31,22 @@ export function useFormatTypes(): FormatTypeStore {
formatTypes.value = formatTypes.value.filter(({ name }) => { formatTypes.value = formatTypes.value.filter(({ name }) => {
if (isArray) { if (isArray) {
return !!typesToRemove.find((type) => type === name); return !typesToRemove.find((type) => type === name);
} else { } else {
return name === typesToRemove; return name !== typesToRemove;
} }
}); });
}; };
const findFormatType = (fn: (f:RichTextFormatType) => boolean) => formatTypes.value.find(type => fn(type)); const findFormatType = (fn: (f:RichTextFormatType) => boolean) => formatTypes.value.find(type => fn(type));
const getFormatTypeByName = (name: string) => formatTypes.value.find(type => type.name === name); 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); const getFormatTypeForBareElement = (name: string) => formatTypes.value.find(type => type.tagName === name);
return { return {