UNPKG

@progress/kendo-angular-conversational-ui

Version:

Kendo UI for Angular Conversational UI components

215 lines (214 loc) 9.29 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Component, HostBinding, Input } from '@angular/core'; import { NgIf } from '@angular/common'; import { LocalizationService } from '@progress/kendo-angular-l10n'; import { guid, isPresent } from '@progress/kendo-angular-common'; import { ButtonComponent } from "@progress/kendo-angular-buttons"; import { arrowRotateCwIcon, copyIcon, thumbDownIcon, thumbDownOutlineIcon, thumbUpIcon, thumbUpOutlineIcon } from '@progress/kendo-svg-icons'; import { AIPromptService } from './aiprompt.service'; import * as i0 from "@angular/core"; import * as i1 from "@progress/kendo-angular-l10n"; import * as i2 from "./aiprompt.service"; /** * @hidden */ export class AIPromptOutputCardComponent { localization; service; hostClass = true; listItemRole = 'listitem'; tabIndex = 0; get ariaDescribedBy() { return this.titleId; } ariaKeyShortcuts = 'Enter'; promptOutput; constructor(localization, service) { this.localization = localization; this.service = service; } ngOnInit() { if (this.promptOutput?.rating === 'positive') { this.positiveRatingIcon = thumbUpIcon; this.negativeRatingIcon = thumbDownOutlineIcon; } else if (this.promptOutput?.rating === 'negative') { this.negativeRatingIcon = thumbDownIcon; this.positiveRatingIcon = thumbUpOutlineIcon; } } copyIcon = copyIcon; retryIcon = arrowRotateCwIcon; positiveRatingIcon = thumbUpOutlineIcon; negativeRatingIcon = thumbDownOutlineIcon; titleId = `k-output-card-${guid()}`; messageFor(text) { return this.localization.get(text); } get showRating() { return this.service.showOutputRating; } get outputTitle() { if (isPresent(this.promptOutput.title)) { return this.promptOutput.title; } else { const titleMessage = this.promptOutput.isRetry ? 'outputRetryTitle' : 'outputTitle'; return this.messageFor(titleMessage); } } handleRetry() { if (this.promptOutput.commandId) { const eventArgs = { command: this.service.getFlattenPromptCommands().find(c => c.id === this.promptOutput.commandId), sender: this.service.aiPrompt, isRetry: true }; this.service.executeEvent.next(eventArgs); } else { const eventArgs = { prompt: this.promptOutput.prompt, sender: this.service.aiPrompt, isRetry: true }; this.service.requestEvent.next(eventArgs); } } handleCopy() { navigator.clipboard.writeText(this.promptOutput.output); this.service.outputCopyEvent.next(this.promptOutput); } handleRating(ratingType) { const eventArgs = { promptOutput: this.promptOutput, rating: ratingType }; this.service.outputRatingChangeEvent.next(eventArgs); if (ratingType === 'positive') { this.positiveRatingIcon = thumbUpIcon; this.negativeRatingIcon = thumbDownOutlineIcon; } else { this.negativeRatingIcon = thumbDownIcon; this.positiveRatingIcon = thumbUpOutlineIcon; } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AIPromptOutputCardComponent, deps: [{ token: i1.LocalizationService }, { token: i2.AIPromptService }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: AIPromptOutputCardComponent, isStandalone: true, selector: "[kendoAIPromptOutputCard]", inputs: { promptOutput: "promptOutput" }, host: { properties: { "class.k-card": "this.hostClass", "attr.role": "this.listItemRole", "attr.tabindex": "this.tabIndex", "attr.aria-describedby": "this.ariaDescribedBy", "attr.aria-keyshortcuts": "this.ariaKeyShortcuts" } }, ngImport: i0, template: ` <div class="k-card-header"> <div class="k-card-title" [attr.id]="titleId">{{outputTitle}} </div> <div class="k-card-subtitle">{{promptOutput.prompt}}</div> </div> <div class="k-card-body"> <p>{{promptOutput.output}}</p> </div> <div class="k-actions k-actions-start k-actions-horizontal k-card-actions"> <button kendoButton fillMode="flat" themeColor="primary" rounded="full" icon="copy" [svgIcon]="copyIcon" (click)="handleCopy()" >{{messageFor('copyOutput')}}</button> <button kendoButton fillMode="flat" rounded="full" icon="arrow-rotate-cw" [svgIcon]="retryIcon" (click)="handleRetry()" >{{messageFor('retryGeneration')}}</button> <ng-container *ngIf="showRating"> <span class="k-spacer"></span> <button kendoButton fillMode="flat" icon="thumb-up-outline" [svgIcon]="positiveRatingIcon" (click)="handleRating('positive')"> </button> <button kendoButton fillMode="flat" icon="thumb-down-outline" [svgIcon]="negativeRatingIcon" (click)="handleRating('negative')"> </button> </ng-container> </div> `, isInline: true, dependencies: [{ kind: "component", type: ButtonComponent, selector: "button[kendoButton]", inputs: ["arrowIcon", "toggleable", "togglable", "selected", "tabIndex", "imageUrl", "iconClass", "icon", "disabled", "size", "rounded", "fillMode", "themeColor", "svgIcon", "primary", "look"], outputs: ["selectedChange", "click"], exportAs: ["kendoButton"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AIPromptOutputCardComponent, decorators: [{ type: Component, args: [{ selector: '[kendoAIPromptOutputCard]', template: ` <div class="k-card-header"> <div class="k-card-title" [attr.id]="titleId">{{outputTitle}} </div> <div class="k-card-subtitle">{{promptOutput.prompt}}</div> </div> <div class="k-card-body"> <p>{{promptOutput.output}}</p> </div> <div class="k-actions k-actions-start k-actions-horizontal k-card-actions"> <button kendoButton fillMode="flat" themeColor="primary" rounded="full" icon="copy" [svgIcon]="copyIcon" (click)="handleCopy()" >{{messageFor('copyOutput')}}</button> <button kendoButton fillMode="flat" rounded="full" icon="arrow-rotate-cw" [svgIcon]="retryIcon" (click)="handleRetry()" >{{messageFor('retryGeneration')}}</button> <ng-container *ngIf="showRating"> <span class="k-spacer"></span> <button kendoButton fillMode="flat" icon="thumb-up-outline" [svgIcon]="positiveRatingIcon" (click)="handleRating('positive')"> </button> <button kendoButton fillMode="flat" icon="thumb-down-outline" [svgIcon]="negativeRatingIcon" (click)="handleRating('negative')"> </button> </ng-container> </div> `, standalone: true, imports: [ButtonComponent, NgIf] }] }], ctorParameters: function () { return [{ type: i1.LocalizationService }, { type: i2.AIPromptService }]; }, propDecorators: { hostClass: [{ type: HostBinding, args: ['class.k-card'] }], listItemRole: [{ type: HostBinding, args: ['attr.role'] }], tabIndex: [{ type: HostBinding, args: ['attr.tabindex'] }], ariaDescribedBy: [{ type: HostBinding, args: ['attr.aria-describedby'] }], ariaKeyShortcuts: [{ type: HostBinding, args: ['attr.aria-keyshortcuts'] }], promptOutput: [{ type: Input }] } });