UNPKG

@progress/kendo-angular-conversational-ui

Version:

Kendo UI for Angular Conversational UI components

93 lines (92 loc) 3.85 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Injectable, ViewContainerRef } from '@angular/core'; import { PopupService } from '@progress/kendo-angular-popup'; import { InlineAIPromptContentComponent } from './inlineaiprompt-content.component'; import { defaultPopupSettings } from './utils'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-popup"; /** * Provides a service for opening and configuring the Inline AI Prompt component dynamically. * * @example * ```ts * export class DemoComponent { * @ViewChild('anchor', { read: ElementRef }) anchor: ElementRef; * constructor(private promptService: InlineAIPromptService) {} * * open(): void { * this.promptService.open({ * popupSettings: { anchor: this.anchor }, * placeholder: 'Enter your prompt...' * }); * } * } * ``` * ```html * <button #anchor (click)="open()">Ask AI</button> * ``` */ export class InlineAIPromptService { popupService; /** * @hidden */ constructor(popupService) { this.popupService = popupService; } /** * Opens an Inline AI Prompt component in a popup. The popup appears near the specified anchor element or at the provided offset coordinates. * * @param {InlineAIPromptSettings} options The options for the InlineAIPromptComponent. * @returns {PopupRef} A reference to the popup. */ open(options) { const popupSettings = { ...defaultPopupSettings, ...options?.popupSettings }; const popupRef = this.popupService.open({ ...(options?.popupSettings?.anchor && { anchor: options.popupSettings.anchor }), popupClass: 'k-prompt-popup', ...popupSettings, content: InlineAIPromptContentComponent, }); const promptInstance = popupRef.content?.instance; if (promptInstance) { const popupViewContainer = popupRef.popup.injector.get(ViewContainerRef); promptInstance.appendTo = popupViewContainer; promptInstance.popupElement = popupRef.popupElement; this.projectComponentInputs(promptInstance, options); if (promptInstance.close) { promptInstance.close.subscribe(() => { popupRef.close(); }); } if (popupRef.content.changeDetectorRef) { popupRef.content.changeDetectorRef.detectChanges(); } } return popupRef; } /** * Projects the input options onto the component instance. */ projectComponentInputs(component, options) { if (!options) { return component; } Object.getOwnPropertyNames(options) .forEach((prop) => { component[prop] = options[prop]; }); return component; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InlineAIPromptService, deps: [{ token: i1.PopupService }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InlineAIPromptService, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: InlineAIPromptService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: () => [{ type: i1.PopupService }] });