UNPKG

@progress/kendo-angular-conversational-ui

Version:

Kendo UI for Angular Conversational UI components

86 lines (85 loc) 3.75 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 Inline AI Prompt components dynamically. * * @example * ```ts * import { InlineAIPromptService } from '@progress/kendo-angular-conversational-ui'; * * constructor(private inlineAIPromptService: InlineAIPromptService) {} * * openPrompt(anchor: ElementRef) { * const promptRef = this.inlineAIPromptService.open({ * anchor: anchor, * placeholder: 'Enter your prompt...' * }); * } * ``` */ export class InlineAIPromptService { popupService; 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: "16.2.12", ngImport: i0, type: InlineAIPromptService, deps: [{ token: i1.PopupService }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: InlineAIPromptService, providedIn: 'root' }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: InlineAIPromptService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: i1.PopupService }]; } });