import { IResolvedRichTextHtmlResult , IRichTextHtmlResolverInput } from '../rich-text-resolver.models' ; import { browserParser , IParser , parserConfiguration } from '../../../parser' ; import { BaseRichTextResolver } from '../base/base-rich-text-resolver' ; export class RichTextHtmlResolver extends BaseRichTextResolver < IRichTextHtmlResolverInput , IResolvedRichTextHtmlResult > { constructor ( parser ? ) { super ( browserParser , parser ) ; } resolveRichText ( input ) { return this . resolveRichTextInternal ( input . element . value , input ) ; } private resolveRichTextInternal ( html , input ) { const parsedResult = super . getParser ( ) . parse ( html , input . element , { elementResolver : ( element ) => { } , contentItemResolver : ( element , itemCodename , linkedItemIndex , linkedItem ) => { const parentElement = element . parentElement ; if ( parentElement ) { const resolvedItemHtml = input . contentItemResolver ? input . contentItemResolver ( itemCodename , linkedItem ) . contentItemHtml ?? '' : '' ; const innerHtml = this . resolveRichTextInternal ( resolvedItemHtml , input ) . html ; element . setInnerHtml ( innerHtml ) ; } } , genericElementResolver : ( element ) => { } , imageResolver : ( element , imageId , image ) => { const imageResult = input . imageResolver ? input . imageResolver ( imageId , image ) : undefined ; if ( imageResult ?. imageHtml ) { element . setOuterHtml ( imageResult . imageHtml ) ; } else if ( imageResult ?. imageUrl ) { element . setAttribute ( parserConfiguration . imageElementData . srcAttribute , imageResult . imageUrl ) ; } } , urlResolver : ( element , linkId , linkText , link ) => { if ( input . urlResolver ) { const urlResult = input . urlResolver ( linkId , linkText , link ) ; if ( urlResult ?. linkHtml ) { element . setOuterHtml ( urlResult . linkHtml ) ; } else if ( urlResult ?. linkUrl ) { element . setAttribute ( 'href' , urlResult . linkUrl ) ; } } } } , input . linkedItems ?? [ ] ) ; return { componentCodenames : parsedResult . componentCodenames , linkedItemCodenames : parsedResult . linkedItemCodenames , html : parsedResult . result } ; } } export const createRichTextHtmlResolver = ( parser ? ) => new RichTextHtmlResolver ( parser ) ;