{"version":3,"file":"igniteui-angular-chat.mjs","names":[],"sources":["../../../projects/igniteui-angular/chat/src/chat.component.ts","../../../projects/igniteui-angular/chat/src/chat.component.html"],"sourcesContent":["import {\n    ChangeDetectionStrategy,\n    Component,\n    CUSTOM_ELEMENTS_SCHEMA,\n    Directive,\n    effect,\n    inject,\n    input,\n    OnInit,\n    output,\n    signal,\n    TemplateRef,\n    ViewContainerRef,\n    OnDestroy,\n    ViewRef,\n    computed,\n} from '@angular/core';\nimport {\n    IgcChatComponent,\n    type IgcChatMessageAttachment,\n    type IgcChatMessage,\n    type IgcChatOptions,\n    type ChatRenderContext,\n    type ChatRenderers,\n    type ChatAttachmentRenderContext,\n    type ChatInputRenderContext,\n    type ChatMessageRenderContext,\n    type IgcChatMessageReaction,\n} from 'igniteui-webcomponents';\n\ntype ChatContextUnion =\n    | ChatAttachmentRenderContext\n    | ChatMessageRenderContext\n    | ChatInputRenderContext\n    | ChatRenderContext;\n\ntype ChatContextType<T extends ChatContextUnion> =\n    T extends ChatAttachmentRenderContext\n    ? IgcChatMessageAttachment\n    : T extends ChatMessageRenderContext\n    ? IgcChatMessage\n    : T extends ChatInputRenderContext\n    ? string\n    : T extends ChatRenderContext\n    ? { instance: IgcChatComponent }\n    : never;\n\ntype ExtractChatContext<T> = T extends (ctx: infer R) => any ? R : never;\n\ntype ChatTemplatesContextMap = {\n    [K in keyof ChatRenderers]: {\n        $implicit: ChatContextType<\n            ExtractChatContext<NonNullable<ChatRenderers[K]>> & ChatContextUnion\n        >;\n    };\n};\n\n/**\n * Template references for customizing chat component rendering.\n * Each property corresponds to a specific part of the chat UI that can be customized.\n *\n * @example\n * ```typescript\n * templates = {\n *   messageContent: this.customMessageTemplate,\n *   attachment: this.customAttachmentTemplate\n * }\n * ```\n */\nexport type IgxChatTemplates = {\n    [K in keyof Omit<ChatRenderers, 'typingIndicator'>]?: TemplateRef<ChatTemplatesContextMap[K]>;\n};\n\n/**\n * Configuration options for the chat component.\n */\nexport type IgxChatOptions = Omit<IgcChatOptions, 'renderers'>;\n\n\n/**\n * Angular wrapper component for the Ignite UI Web Components Chat component.\n *\n * This component provides an Angular-friendly interface to the igc-chat web component,\n * including support for Angular templates, signals, and change detection.\n *\n * Uses OnPush change detection strategy for optimal performance. All inputs are signals,\n * so changes are automatically tracked and propagated to the underlying web component.\n *\n * @example\n * ```typescript\n * <igx-chat\n *   [messages]=\"messages\"\n *   [draftMessage]=\"draft\"\n *   [options]=\"chatOptions\"\n *   [templates]=\"chatTemplates\"\n *   (messageCreated)=\"onMessageCreated($event)\"\n * />\n * ```\n */\n@Component({\n    selector: 'igx-chat',\n    standalone: true,\n    changeDetection: ChangeDetectionStrategy.OnPush,\n    schemas: [CUSTOM_ELEMENTS_SCHEMA],\n    templateUrl: './chat.component.html'\n})\nexport class IgxChatComponent implements OnInit, OnDestroy {\n    //#region Internal state\n\n    private readonly _view = inject(ViewContainerRef);\n    private readonly _templateViewRefs = new Map<TemplateRef<any>, Set<ViewRef>>();\n    private _oldTemplates: IgxChatTemplates = {};\n\n    protected readonly _transformedTemplates = signal<ChatRenderers>({});\n\n    protected readonly _mergedOptions = computed<IgcChatOptions>(() => {\n        const options = this.options();\n        const transformedTemplates = this._transformedTemplates();\n        return {\n            ...options,\n            renderers: transformedTemplates\n        };\n    });\n\n    //#endregion\n\n    //#region Inputs\n\n    /** Array of chat messages to display */\n    public readonly messages = input<IgcChatMessage[]>([]);\n\n    /** Draft message with text and optional attachments */\n    public readonly draftMessage = input<\n        { text: string; attachments?: IgcChatMessageAttachment[] } | undefined\n    >({ text: '' });\n\n    /** Configuration options for the chat component */\n    public readonly options = input<IgxChatOptions>({});\n\n    /** Custom templates for rendering chat elements */\n    public readonly templates = input<IgxChatTemplates>({});\n\n    //#endregion\n\n    //#region Outputs\n\n    /** Emitted when a new message is created */\n    public readonly messageCreated = output<IgcChatMessage>();\n\n    /** Emitted when a user reacts to a message */\n    public readonly messageReact = output<IgcChatMessageReaction>();\n\n    /** Emitted when an attachment is clicked */\n    public readonly attachmentClick = output<IgcChatMessageAttachment>();\n\n    /** Emitted when attachment drag starts */\n    public readonly attachmentDrag = output<void>();\n\n    /** Emitted when attachment is dropped */\n    public readonly attachmentDrop = output<void>();\n\n    /** Emitted when typing indicator state changes */\n    public readonly typingChange = output<boolean>();\n\n    /** Emitted when the input receives focus */\n    public readonly inputFocus = output<void>();\n\n    /** Emitted when the input loses focus */\n    public readonly inputBlur = output<void>();\n\n    /** Emitted when the input value changes */\n    public readonly inputChange = output<string>();\n\n    //#endregion\n\n    /** @internal */\n    public ngOnInit(): void {\n        IgcChatComponent.register();\n    }\n\n    /** @internal */\n    public ngOnDestroy(): void {\n        for (const viewSet of this._templateViewRefs.values()) {\n            viewSet.forEach(viewRef => viewRef.destroy());\n        }\n        this._templateViewRefs.clear();\n    }\n\n    constructor() {\n        // Templates changed - update transformed templates and viewRefs\n        effect(() => {\n            const templates = this.templates();\n            this._setTemplates(templates ?? {});\n        });\n    }\n\n    private _setTemplates(newTemplates: IgxChatTemplates): void {\n        const templateCopies: ChatRenderers = {};\n        const newTemplateKeys = Object.keys(newTemplates) as Array<keyof IgxChatTemplates>;\n\n        const oldTemplates = this._oldTemplates;\n        const oldTemplateKeys = Object.keys(oldTemplates) as Array<keyof IgxChatTemplates>;\n\n        for (const key of oldTemplateKeys) {\n            const oldRef = oldTemplates[key];\n            const newRef = newTemplates[key];\n\n            if (oldRef && oldRef !== newRef) {\n                const obsolete = this._templateViewRefs.get(oldRef);\n                if (obsolete) {\n                    obsolete.forEach(viewRef => viewRef.destroy());\n                    this._templateViewRefs.delete(oldRef);\n                }\n            }\n        }\n\n        this._oldTemplates = {};\n\n        for (const key of newTemplateKeys) {\n            const ref = newTemplates[key];\n            if (ref) {\n                (this._oldTemplates as Record<string, TemplateRef<unknown>>)[key] = ref;\n                templateCopies[key] = this._createTemplateRenderer(ref);\n            }\n        }\n\n        this._transformedTemplates.set(templateCopies);\n    }\n\n    private _createTemplateRenderer<K extends keyof IgxChatTemplates>(ref: NonNullable<IgxChatTemplates[K]>) {\n        type ChatContext = ExtractChatContext<NonNullable<ChatRenderers[K]>>;\n\n        if (!this._templateViewRefs.has(ref)) {\n            this._templateViewRefs.set(ref, new Set<ViewRef>());\n        }\n\n        const viewSet = this._templateViewRefs.get(ref)!;\n\n        return (ctx: ChatContext) => {\n            const context = ctx as ChatContextUnion;\n            let angularContext: any;\n\n            if ('message' in context && 'attachment' in context) {\n                angularContext = { $implicit: context.attachment };\n            } else if ('message' in context) {\n                angularContext = { $implicit: context.message };\n            } else if ('value' in context) {\n                angularContext = {\n                    $implicit: context.value,\n                    attachments: context.attachments\n                };\n            } else {\n                angularContext = { $implicit: { instance: context.instance } };\n            }\n\n            const viewRef = this._view.createEmbeddedView(ref, angularContext);\n            viewSet.add(viewRef);\n\n            return viewRef.rootNodes;\n        }\n    }\n}\n\n/**\n * Context provided to the chat input template.\n */\nexport interface ChatInputContext {\n    /** The current input value */\n    $implicit: string;\n    /** Array of attachments associated with the input */\n    attachments: IgcChatMessageAttachment[];\n}\n\n/**\n * Directive providing type information for chat message template contexts.\n * Use this directive on ng-template elements that render chat messages.\n *\n * @example\n * ```html\n * <ng-template igxChatMessageContext let-message>\n *   <div>{{ message.text }}</div>\n * </ng-template>\n * ```\n */\n@Directive({ selector: '[igxChatMessageContext]', standalone: true })\nexport class IgxChatMessageContextDirective {\n\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    public static ngTemplateContextGuard(_: IgxChatMessageContextDirective, ctx: unknown): ctx is { $implicit: IgcChatMessage } {\n        return true;\n    }\n}\n\n/**\n * Directive providing type information for chat attachment template contexts.\n * Use this directive on ng-template elements that render message attachments.\n *\n * @example\n * ```html\n * <ng-template igxChatAttachmentContext let-attachment>\n *   <img [src]=\"attachment.url\" />\n * </ng-template>\n * ```\n */\n@Directive({ selector: '[igxChatAttachmentContext]', standalone: true })\nexport class IgxChatAttachmentContextDirective {\n\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    public static ngTemplateContextGuard(_: IgxChatAttachmentContextDirective, ctx: unknown): ctx is { $implicit: IgcChatMessageAttachment } {\n        return true;\n    }\n}\n\n/**\n * Directive providing type information for chat input template contexts.\n * Use this directive on ng-template elements that render the chat input.\n *\n * @example\n * ```html\n * <ng-template igxChatInputContext let-value let-attachments=\"attachments\">\n *   <input [value]=\"value\" />\n * </ng-template>\n * ```\n */\n@Directive({ selector: '[igxChatInputContext]', standalone: true })\nexport class IgxChatInputContextDirective {\n\n    // eslint-disable-next-line @typescript-eslint/no-unused-vars\n    public static ngTemplateContextGuard(_: IgxChatInputContextDirective, ctx: unknown): ctx is ChatInputContext {\n        return true;\n    }\n}\n","<igc-chat\n  [messages]=\"messages()\"\n  [draftMessage]=\"draftMessage()\"\n  [options]=\"_mergedOptions()\"\n  (igcMessageCreated)=\"messageCreated.emit($event.detail)\"\n  (igcMessageReact)=\"messageReact.emit($event.detail)\"\n  (igcAttachmentClick)=\"attachmentClick.emit($event.detail)\"\n  (igcAttachmentDrag)=\"attachmentDrag.emit()\"\n  (igcAttachmentDrop)=\"attachmentDrop.emit()\"\n  (igcTypingChange)=\"typingChange.emit($event.detail)\"\n  (igcInputFocus)=\"inputFocus.emit()\"\n  (igcInputBlur)=\"inputBlur.emit()\"\n  (igcInputChange)=\"inputChange.emit($event.detail)\"\n>\n    <ng-content></ng-content>\n</igc-chat>\n"],"mappings":";;;AA0GA,IAAa,mBAAb,MAAa,iBAAgB;CAsElB,WAAQ;EACX,iBAAiB,SAAQ;CAC7B;CAGO,cAAW;EACd,KAAK,MAAM,WAAW,KAAK,kBAAkB,OAAM,GAC/C,QAAQ,SAAQ,YAAW,QAAQ,QAAO,CAAE;EAEhD,KAAK,kBAAkB,MAAK;CAChC;CAEA,cAAA;EA/EiB,KAAA,QAAQ,OAAO,gBAAgB;EAC/B,KAAA,oCAAoB,IAAI,IAAG;EACpC,KAAA,gBAAkC,CAAA;EAEvB,KAAA,wBAAwB,OAAsB,CAAA,GAAG,GAAA,YAAA,C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