@progress/kendo-react-conversational-ui 7.1.1-develop.7 → 7.2.0-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ export interface AIPromptProps {
22
22
  /**
23
23
  * Collection with items that will override the default Toolbar items.
24
24
  */
25
- toolbarItems?: AIPromptToolbarItemInterface[];
25
+ toolbarItems?: (AIPromptToolbarItemInterface | React.ReactNode)[];
26
26
  /**
27
27
  * The collection of generated prompt outputs that will be rendered in the Output view.
28
28
  */
@@ -35,6 +35,10 @@ export interface AIPromptProps {
35
35
  * The placeholder text for the Prompt view textarea.
36
36
  */
37
37
  promptPlaceholder?: string;
38
+ /**
39
+ * Represents the `dir` HTML attribute.
40
+ */
41
+ dir?: string;
38
42
  /**
39
43
  * The onActiveViewChange event handler of the KendoReact AIPrompt component.
40
44
  * Fires when active view is changed. Exposes the name of the new active view as event data.
@@ -6,7 +6,7 @@ import React from 'react';
6
6
  /**
7
7
  * The props of the AIPromptContent component.
8
8
  */
9
- interface PromptContentProps {
9
+ interface AIPromptContentProps {
10
10
  /**
11
11
  * Specifies the AIPromptContent children elements.
12
12
  */
@@ -15,5 +15,5 @@ interface PromptContentProps {
15
15
  /**
16
16
  * Represents the KendoReact AIPromptContent component.
17
17
  */
18
- export declare const AIPromptContent: (props: PromptContentProps) => import("react/jsx-runtime").JSX.Element;
18
+ export declare const AIPromptContent: React.ForwardRefExoticComponent<AIPromptContentProps & React.RefAttributes<HTMLDivElement>>;
19
19
  export {};
@@ -2,6 +2,7 @@
2
2
  * Copyright © 2024 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the package root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
+ import React from 'react';
5
6
  import { SVGIcon } from '@progress/kendo-svg-icons';
6
7
  /**
7
8
  * An interface for the AIPromptToolbarItem.
@@ -25,8 +26,8 @@ export interface AIPromptToolbarItemInterface {
25
26
  */
26
27
  interface AIPromptHeaderProps {
27
28
  activeView: string;
28
- toolbarItems: AIPromptToolbarItemInterface[];
29
- activeViewChange?: (event: any) => void;
29
+ toolbarItems: (AIPromptToolbarItemInterface | React.ReactNode)[];
30
+ activeViewChange?: (viewName: string) => void;
30
31
  }
31
32
  /**
32
33
  * @hidden
@@ -2,4 +2,4 @@
2
2
  * Copyright © 2024 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the package root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- (function(l,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("react"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl"),require("prop-types"),require("@progress/kendo-svg-icons"),require("@progress/kendo-react-buttons"),require("@progress/kendo-react-layout"),require("@progress/kendo-react-inputs")):typeof define=="function"&&define.amd?define(["exports","react","@progress/kendo-react-common","@progress/kendo-react-intl","prop-types","@progress/kendo-svg-icons","@progress/kendo-react-buttons","@progress/kendo-react-layout","@progress/kendo-react-inputs"],i):(l=typeof globalThis!="undefined"?globalThis:l||self,i(l.KendoReactConversationalUi={},l.React,l.KendoReactCommon,l.KendoReactIntl,l.PropTypes,l.KendoSvgIcons,l.KendoReactButtons,l.KendoReactLayout,l.KendoReactInputs))})(this,function(l,i,p,y,h,m,u,d,Z){"use strict";"use client";function R(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const r=R(i);class A extends r.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class S extends A{render(){return r.createElement("div",{className:this.getClassNames(),tabIndex:this.props.tabIndex,onClick:()=>this.props.onRequestSelection(this.props.item.selectionIndex),onFocus:()=>this.props.onRequestSelection(this.props.item.selectionIndex),ref:e=>this.elementToFocus=e},this.getTimestampView(),this.getMainView(),this.getStatusView())}getMainView(){return this.props.item.typing?r.createElement("div",{className:"k-chat-bubble"},r.createElement("div",{className:"k-typing-indicator"},r.createElement("span",null),r.createElement("span",null),r.createElement("span",null))):this.props.template?r.createElement(this.props.template,{item:this.props.item}):this.props.item.text?r.createElement("div",{className:"k-chat-bubble"},this.props.item.text):null}getTimestampView(){let e=null;return this.props.item.timestamp&&(e=r.createElement("time",{className:"k-message-time","aria-hidden":!this.props.selected},y.provideIntlService(this).formatDate(this.props.item.timestamp,this.props.dateFormat))),e}getStatusView(){let e=null;return this.props.item.status&&(e=r.createElement("span",{className:"k-message-status"},this.props.item.status)),e}getClassNames(){return p.classNames({"k-only":this.props.isOnlyItemInGroup},{"k-first":this.props.isFirstItemInGroup&&!this.props.isOnlyItemInGroup},{"k-last":this.props.isLastItemInGroup&&!this.props.isOnlyItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected},"k-message")}}S.defaultProps={dateFormat:"g",tabIndex:-1},y.registerForIntl(S);const U=(s,e)=>s&&e.author&&s.id===e.author.id,L=s=>s[s.length-1],ee=(s,e)=>s&&e&&(e.getDate()!==s.getDate()||e.getMonth()!==s.getMonth()||e.getFullYear()!==s.getFullYear()),te=(s,e)=>{const t=e.timestamp,n=L(s);if(t&&(!n||ee(t,n.timestamp))){const o={type:"date-marker",timestamp:t,trackBy:t.getTime()};s.push(o)}},se=(s,e,t)=>{const n=L(s);let o;e.typing&&!t||(n&&n.type==="message-group"&&(o=n.messages),o&&U(e.author,L(o))?o.push(e):s.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},ne=s=>(e,t,n)=>{const o=n===s-1;return te(e,t),se(e,t,o),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&o&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function re(s){let e=0;s.forEach(t=>{t.type==="message-group"?t.messages.forEach(n=>{n.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),s.lastSelectionIndex=e-1}const ie=s=>{const t=s.slice().reduce(ne(s.length),[]);return re(t),t};class oe extends A{constructor(){super(...arguments),this.onKeyDown=e=>{e.keyCode===p.Keys.enter&&this.props.onActionExecute(this.props.item,e)}}render(){return r.createElement("span",{role:"button",className:this.getClassNames(),onClick:e=>this.props.onActionExecute(this.props.item,e),ref:e=>this.elementToFocus=e,onKeyDown:this.onKeyDown,tabIndex:0},this.props.item.title||this.props.item.value)}getClassNames(){return p.classNames("k-quick-reply",{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected})}}class W extends r.Component{constructor(){super(...arguments),this.state={selectedItemIndex:null},this.onRequestContainerSelection=()=>this.props.onRequestSelection(this.props.group.selectionIndex),this.onKeyDown=e=>{let t=null,n,o;this.isKeyboardNavigationLeftRight?(n=p.Keys.left,o=p.Keys.right):(n=p.Keys.up,o=p.Keys.down),e.keyCode===n?t=this.navigate(!1):e.keyCode===o&&(t=this.navigate(!0)),t!==null&&(e.preventDefault(),e.stopPropagation())}}static getDerivedStateFromProps(e,t){return!e.selected&&t.selectedItemIndex!==null?{selectedItemIndex:null}:e.selected&&t.selectedItemIndex===null?{selectedItemIndex:0}:null}navigate(e,t=0){let n=null,o=this.state.selectedItemIndex;return e?o===null?n=t:o<this.getLastSelectionIndex()&&(n=o+1):o===null?n=0:o>0&&(n=o-1),n!==null&&this.setState({selectedItemIndex:n}),n}get isKeyboardNavigationLeftRight(){return!0}getLastSelectionIndex(){let e=-1;if(this.props.group.type==="action-group"){const t=this.props.group;e=t.actions?t.actions.length-1:-1}else if(this.props.group.type==="attachment-group"){const t=this.props.group;e=t.attachments?t.attachments.length-1:-1}return e}}class ae extends W{constructor(e){super(e)}render(){const e=this.props.group.actions?this.props.group.actions.length-1:0;return r.createElement("div",{className:this.getClassNames(),onClick:this.onRequestContainerSelection,onKeyDown:this.onKeyDown},this.props.group.actions&&this.props.group.actions.map((t,n)=>r.createElement(oe,{item:t,onActionExecute:this.props.onActionExecute,selected:n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,key:n})))}getClassNames(){return p.classNames("k-quick-replies")}}class H extends A{render(){return r.createElement("div",{className:this.getClassNames(),tabIndex:this.getTabIndexValue(),onClick:this.props.onClick,ref:e=>this.elementToFocus=e},this.props.template?r.createElement(this.props.template,{item:this.props.item}):r.createElement("div",{className:"k-card"},r.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView(),this.getContentView())))}getTabIndexValue(){if(this.props.tabbable!==void 0)return this.props.tabbable?0:-1}getClassNames(){return p.classNames({"k-selected":this.props.selected},{"k-focus":this.props.selected},{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup})}getTitleView(){return this.props.item.title?r.createElement("h5",{className:"k-card-title"},this.props.item.title):null}getSubtitleView(){return this.props.item.subtitle?r.createElement("h6",{className:"k-card-subtitle"},this.props.item.subtitle):null}getContentView(){return this.props.item.contentType.indexOf("image/")===0?r.createElement("img",{src:this.props.item.content}):this.props.item.content}}class le extends W{render(){const e=this.isCardDeckLayout(this.props),t=r.createElement("div",{className:this.getClassNames(),onKeyDown:e?void 0:this.onKeyDown},this.props.group.attachments.map((n,o)=>r.createElement(H,{item:n,template:this.props.itemTemplate,selected:o===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&o===this.state.selectedItemIndex,isFirstItemInGroup:o===0,isLastItemInGroup:o===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(o),key:o})));return e?r.createElement("div",{className:"k-card-deck-scrollwrap",onKeyDown:this.onKeyDown},this.getLeftScrollBtn(),t,this.getRightScrollBtn()):t}get isKeyboardNavigationLeftRight(){return this.isCardDeckLayout(this.props)}getLastItemIndex(){return this.props.group.attachments.length-1}getLeftScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex&&(e=r.createElement(u.Button,{icon:"chevron-left",onClick:()=>this.onNavigateBtnClick(!1),svgIcon:m.chevronLeftIcon})),e}getRightScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex!==this.getLastItemIndex()&&(e=r.createElement(u.Button,{icon:"chevron-right",onClick:()=>this.onNavigateBtnClick(!0),svgIcon:m.chevronRightIcon})),e}onAttachmentClick(e){this.onRequestContainerSelection(),this.setState({selectedItemIndex:e})}onNavigateBtnClick(e){this.onRequestContainerSelection(),this.navigate(e,1)}isCardDeckLayout(e){return e.group.attachmentLayout!=="list"}getClassNames(){return p.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class j extends r.Component{render(){const e=this.props.item;return r.createElement("div",{className:"k-timestamp"},y.provideIntlService(this).formatDate(e.timestamp,"D"))}}y.registerForIntl(j);const V="newMessage.sendButton",B="newMessage.optionsButton",P="newMessage.messageInput",F="avatar.alt",K="messageList.ariaLabel",q="aIPrompt.noOutputs",k={[V]:"Send",[B]:"Options",[P]:"Message",[F]:"Avatar",[K]:"Message list",[q]:"No output from AI available"};class ce extends r.Component{render(){const{avatarUrl:e,avatarAltText:t,name:n}=this.props.group.author,o=y.provideLocalizationService(this);return r.createElement("div",{className:this.getMsgGroupClassNames()},n&&r.createElement("p",{className:"k-author"},n),e&&r.createElement(d.Avatar,{type:"image"},r.createElement("img",{src:e,alt:t!==void 0?t:o.toLanguageString(F,k[F])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return p.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":U(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,n)=>{const o=[r.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:n===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,isOnlyItemInGroup:e===0,key:n})];return t.attachments&&t.attachments.length===1&&o.push(r.createElement(H,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),o})}}class pe extends r.Component{render(){return r.createElement("div",{className:"k-toolbar-box"},r.createElement("div",{className:"k-button-list"},this.props.children))}}class me extends r.Component{constructor(){super(...arguments),this.state={focused:!1},this.inputEl=null,this.onInputKeyDown=e=>{e.keyCode===p.Keys.enter&&this.sendMessage(e)},this.sendMessage=e=>{if(this.props.onMessageSend&&this.inputEl!==null){const t=this.inputEl.value;if(t){const n={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(n,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=y.provideLocalizationService(this),t=r.createElement("input",{type:"text",className:this.getClassNames(),placeholder:this.props.placeholder,onKeyDown:this.onInputKeyDown,onFocus:()=>this.setState({focused:!0}),onBlur:()=>this.setState({focused:!1}),ref:c=>this.inputEl=c,"aria-label":e.toLanguageString(P,k[P])}),n=r.createElement(u.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:m.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(V,k[V]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),o=r.createElement(u.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:m.moreHorizontalIcon,onClick:c=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,c),"aria-label":e.toLanguageString(B,k[B])});return r.createElement(r.Fragment,null,r.createElement("span",{className:"k-message-box k-textbox k-input k-input-md k-rounded-md k-input-solid"},this.props.MessageBox?r.createElement(this.props.MessageBox,{messageInput:t,sendButton:n,toolbarButton:o}):r.createElement(r.Fragment,null,t,r.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&o,n))),this.props.showToolbar&&r.createElement(pe,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return p.classNames("k-input-inner",{"k-focus":this.state.focused})}}const ue={name:"@progress/kendo-react-conversational-ui",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},_=class extends r.Component{constructor(s){super(s),this.viewItems=[],this.isDirectionRightToLeft=!1,this.scrollToBottomOnLoadingData=!0,this.onFocus=()=>{clearTimeout(this.timeoutIdForChatLosingFocus)},this.onBlur=()=>{this.timeoutIdForChatLosingFocus=window.setTimeout(()=>{this.setState({selectedItemIndex:null})},0)},this.onSelectionRequested=e=>{this.setState({selectedItemIndex:e})},this.onKeyDown=e=>{let t=null,n=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===p.Keys.up?n===null?t=0:n>0&&(t=n-1):e.keyCode===p.Keys.down&&(n===null?t=0:n<this.viewItems.lastSelectionIndex&&(t=n+1)),t!==null&&(this.setState({selectedItemIndex:t}),e.preventDefault())},this.onMessageSend=(e,t)=>{p.dispatchEvent(this.props.onMessageSend,t,this,{message:e})},this.onActionExecute=(e,t)=>{if(p.dispatchEvent(this.props.onActionExecute,t,this,{action:e}),!t.isDefaultPrevented()){switch(e.type){case"reply":this.onMessageSend({author:this.props.user,text:e.value,timestamp:new Date},t);break;case"call":window.open("tel:"+e.value);break;case"openUrl":window.open(e.value);break}this.newMsgComp.focusInput()}},p.validatePackage(ue),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const s=y.provideLocalizationService(this);return r.createElement("div",{style:{width:this.props.width},onKeyDown:this.onKeyDown,className:this.getClassNames(),ref:e=>this.chatWrapperEl=e},r.createElement("div",{className:"k-message-list k-avatars",onBlur:this.onBlur,onFocus:this.onFocus,role:"log","aria-label":s.toLanguageString(K,k[K]),"aria-live":"polite",onScroll:e=>{this.scrollToBottomOnLoadingData=e.currentTarget.scrollTop===e.currentTarget.scrollHeight-e.currentTarget.clientHeight},ref:e=>this.viewItemsWrapperEl=e},r.createElement("div",{className:"k-message-list-content"},this.renderViewItems())),r.createElement(me,{user:this.props.user,onMessageSend:this.onMessageSend,isDirectionRightToLeft:this.isDirectionRightToLeft,ref:e=>this.newMsgComp=e,placeholder:this.props.placeholder,MessageBox:this.props.messageBox,toolbar:this.props.toolbar,onToolbarActionButtonClick:this.props.onToolbarActionExecute,showToolbar:this.props.showToolbar}))}componentDidMount(){this.setState({isFirstRender:!1},()=>{this.nextTickId=window.setTimeout(()=>this.scrollViewItemsToBottom(),250)})}componentWillUnmount(){clearTimeout(this.nextTickId)}componentDidUpdate(s){s.messages.length!==this.props.messages.length&&this.scrollToBottomOnLoadingData&&this.scrollViewItemsToBottom()}getClassNames(){return p.classNames("k-chat",this.props.className,{"k-rtl":this.isDirectionRightToLeft})}checkIsDirectionRightToLeft(s){return!!(s.dir!==void 0?s.dir==="rtl":this.chatWrapperEl&&getComputedStyle(this.chatWrapperEl).direction==="rtl")}renderViewItems(){const s=this.viewItems.length-1;return this.viewItems.map((e,t)=>{if(e.type==="date-marker")return r.createElement(j,{item:e,key:t});if(e.type==="message-group")return r.createElement(ce,{group:e,itemTemplate:this.props.messageTemplate,attachmentTemplate:this.props.attachmentTemplate,user:this.props.user,selectedItemIndex:this.state.selectedItemIndex,onRequestSelection:this.onSelectionRequested,isLastGroup:t===s,key:t,message:this.props.message||_.defaultProps.message});if(e.type==="attachment-group")return r.createElement(le,{group:e,itemTemplate:this.props.attachmentTemplate,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t});if(e.type==="action-group")return r.createElement(ae,{group:e,onActionExecute:this.onActionExecute,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t})})}scrollViewItemsToBottom(){this.viewItemsWrapperEl&&(this.viewItemsWrapperEl.scrollTop=this.viewItemsWrapperEl.scrollHeight-this.viewItemsWrapperEl.clientHeight)}getViewItemsFromMsgs(s){return s.length>0?ie(s):[]}};let O=_;O.propTypes={messages:h.arrayOf(h.object),user:h.object,messageTemplate:h.any,attachmentTemplate:h.any,width:h.oneOfType([h.string,h.number]),onMessageSend:h.func,onActionExecute:h.func,dir:h.string,messageBox:h.any},O.defaultProps={messages:[],dateFormat:"g",message:S};class he extends r.Component{constructor(){super(...arguments),this.onBtnClick=(e,t)=>{p.dispatchEvent(this.props.onActionExecute,t,this,{action:e})}}render(){return r.createElement("div",{className:"k-card"},r.createElement("img",{className:"k-card-image",src:this.props.imageUrl,style:{maxWidth:this.props.imageMaxWidth}}),r.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView()),r.createElement("div",{className:"k-card-actions k-card-actions-vertical"},this.getActionsView()))}getActionsView(){return this.props.actions.map((e,t)=>r.createElement("span",{className:"k-card-action",key:t},r.createElement(u.Button,{fillMode:"flat",onClick:n=>this.onBtnClick(e,n)},e.title)))}getTitleView(){let e=null;return this.props.title&&(e=r.createElement("h5",{className:"k-card-title"},this.props.title)),e}getSubtitleView(){let e=null;return this.props.subtitle&&(e=r.createElement("h6",{className:"k-card-subtitle"},this.props.subtitle)),e}}const $=s=>{const{activeView:e,toolbarItems:t,activeViewChange:n}=s,o=c=>{n==null||n.call(null,c)};return i.createElement("div",{className:"k-prompt-header"},i.createElement(u.Toolbar,{keyboardNavigation:!1,role:"toolbar",className:"k-toolbar-flat"},t.map(c=>i.createElement(u.Button,{key:c.name,className:e===c.name?"k-selected":"",size:"medium",themeColor:"primary",fillMode:"flat",rounded:"full",title:c.buttonText,svgIcon:c.buttonIcon,"aria-hidden":"true",onClick:()=>o(c.name)},c.buttonText))))},T=s=>{const{children:e}=s;return i.createElement("div",{className:"k-prompt-content"},i.createElement("div",{className:"k-prompt-view"},e))},Y=s=>{const{children:e}=s;return i.createElement("div",{className:"k-prompt-footer"},i.createElement("div",{className:"k-actions k-actions-start k-actions-horizontal k-prompt-actions"},e))},J=i.createContext([{},()=>{}]),D=()=>i.useContext(J),M=s=>{const[e]=D();return e.activeView===s.name?s.children:null},de=s=>{const[e,t]=i.useState(!0),{children:n,title:o}=s;return i.createElement("div",{className:"k-prompt-expander"},i.createElement(u.Button,{fillMode:"flat",svgIcon:e?m.chevronUpIcon:m.chevronDownIcon,title:o,onClick:()=>t(!e)},o),e&&i.createElement("div",{className:"k-prompt-expander-content"},n))},G={name:"prompt-view",buttonText:"Ask AI",buttonIcon:m.sparklesIcon},ge=s=>{const e="Generate",{promptInput:t=Z.TextArea,generateButton:n=u.Button,promptValue:o,promptSuggestions:c}=s,[I,g]=i.useState(o||""),[f]=D(),[x,E]=p.useCustomComponent(n),[w,b]=p.useCustomComponent(t),v=()=>{f.onPromptRequest&&f.onPromptRequest.call(null,I),g("")},a=C=>{g(C)},N=C=>{g(C.target.value)},ye={title:"Generate",svgIcon:m.sparklesIcon},Ce={placeholder:"Ask or generate content with AI ...",rows:2},ke=Object.keys(E).length>0?E:ye,we=Object.keys(b).length>0?b:Ce;return i.createElement(M,{name:G.name},i.createElement(T,null,i.createElement(w,{value:I,onChange:N,...we}),c&&c.length>0&&i.createElement(de,{title:"Prompt Suggestions"},c.map(C=>i.createElement("div",{key:C,className:"k-prompt-suggestion",onClick:()=>a(C)},C)))),i.createElement(Y,null,i.createElement(x,{themeColor:"primary",fillMode:"solid","aria-hidden":"true",rounded:"full",size:"medium",onClick:v,...ke},e)))},z={name:"Output view",buttonText:"Output",buttonIcon:m.commentIcon},Ie=s=>{const[e,t]=i.useState(m.copyIcon),{outputs:n,showOutputRating:o,outputCard:c}=s,{header:I,body:g,actions:f}=c||{},x=y.useLocalization(),[E]=D(),w=a=>{E.onPromptRequest&&E.onPromptRequest.call(null,a.prompt,{...a,isRetry:!0})},b=a=>{a!=null&&a.responseContent&&navigator.clipboard.writeText(a.responseContent),t(m.checkIcon),setTimeout(()=>{t(m.copyIcon)},1e3)},v=(a,N)=>{E.onPromptRequest&&E.onPromptRequest.call(null,a.prompt,{...a,ratingType:N,isRetry:!1})};return i.createElement(M,{name:z.name},i.createElement(T,null,i.createElement("div",{className:"k-card-list"},n&&n.length>0?n.map((a,N)=>i.createElement(d.Card,{key:`${a.id}_${N}`},i.createElement(d.CardHeader,null,I?I(a):i.createElement(i.Fragment,null,a.title&&i.createElement(d.CardTitle,null,a.title),a.subTitle&&i.createElement(d.CardSubtitle,null,a.subTitle))),i.createElement(d.CardBody,null,g?g(a):a.responseContent),i.createElement(d.CardActions,null,f?f(a):i.createElement(i.Fragment,null,i.createElement(u.Button,{size:"medium",themeColor:"primary",fillMode:"flat",rounded:"medium",title:"Copy",svgIcon:e,"aria-hidden":"true",onClick:()=>b(a)},"Copy"),i.createElement(u.Button,{size:"medium",themeColor:"base",fillMode:"flat",rounded:"medium",title:"Retry",svgIcon:m.rotateIcon,"aria-hidden":"true",onClick:()=>w(a)},"Retry"),o&&i.createElement(i.Fragment,null,i.createElement("span",{className:"k-spacer"}),i.createElement(u.Button,{size:"medium",themeColor:a.ratingType==="positive"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate up",svgIcon:m.thumbUpOutlineIcon,"aria-hidden":"true",onClick:()=>v(a,"positive")}),i.createElement(u.Button,{size:"medium",themeColor:a.ratingType==="negative"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate down",svgIcon:m.thumbDownOutlineIcon,"aria-hidden":"true",onClick:()=>v(a,"negative")})))))):i.createElement(d.Card,null,i.createElement(d.CardBody,null,x.toLanguageString(q,k[q]))))))},fe=s=>{const{activeView:e,toolbarItems:t,children:n,onActiveViewChange:o,onPromptRequest:c,onCommandExecute:I,style:g}=s,f=t||[G,z],[x,E]=i.useState({activeView:e}),w={...x,activeView:e,onActiveViewChange:o,onPromptRequest:c,onCommandExecute:I},b=v=>{E(v)};return i.createElement(J.Provider,{value:[w,b]},i.createElement("div",{className:"k-prompt",style:g},i.createElement($,{activeView:w.activeView,toolbarItems:f,activeViewChange:o}),n))},Q={name:"Commands view",buttonIcon:m.moreHorizontalIcon},X=s=>s==null?void 0:s.map(e=>i.createElement(d.PanelBarItem,{title:e.text,key:e.id,svgIcon:e.svgIcon,data:e},e.children&&X(e.children||[]))),Ee=s=>{const{commands:e}=s,[t]=D(),n=o=>{var I,g,f;const c=(g=(I=o.target)==null?void 0:I.props)==null?void 0:g.data;(f=c.children)!=null&&f.length||t.onCommandExecute&&t.onCommandExecute.call(null,c)};return i.createElement(M,{name:Q.name},i.createElement(T,null,i.createElement("div",{className:"k-prompt-view"},i.createElement(d.PanelBar,{onSelect:n,selected:""},X(e!=null?e:[])))))};l.AIPrompt=fe,l.AIPromptCommandsView=Ee,l.AIPromptContent=T,l.AIPromptFooter=Y,l.AIPromptOutputView=Ie,l.AIPromptView=ge,l.AIPromptViewRender=M,l.Chat=O,l.ChatMessage=S,l.HeroCard=he,l.PromptHeader=$,l.commandsViewDefaults=Q,l.outputViewDefaults=z,l.promptViewDefaults=G,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
5
+ (function(l,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("react"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl"),require("prop-types"),require("@progress/kendo-svg-icons"),require("@progress/kendo-react-buttons"),require("@progress/kendo-react-layout"),require("@progress/kendo-react-inputs")):typeof define=="function"&&define.amd?define(["exports","react","@progress/kendo-react-common","@progress/kendo-react-intl","prop-types","@progress/kendo-svg-icons","@progress/kendo-react-buttons","@progress/kendo-react-layout","@progress/kendo-react-inputs"],i):(l=typeof globalThis!="undefined"?globalThis:l||self,i(l.KendoReactConversationalUi={},l.React,l.KendoReactCommon,l.KendoReactIntl,l.PropTypes,l.KendoSvgIcons,l.KendoReactButtons,l.KendoReactLayout,l.KendoReactInputs))})(this,function(l,i,p,E,h,m,u,d,ee){"use strict";"use client";function te(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const r=te(i);class V extends r.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class D extends V{render(){return r.createElement("div",{className:this.getClassNames(),tabIndex:this.props.tabIndex,onClick:()=>this.props.onRequestSelection(this.props.item.selectionIndex),onFocus:()=>this.props.onRequestSelection(this.props.item.selectionIndex),ref:e=>this.elementToFocus=e},this.getTimestampView(),this.getMainView(),this.getStatusView())}getMainView(){return this.props.item.typing?r.createElement("div",{className:"k-chat-bubble"},r.createElement("div",{className:"k-typing-indicator"},r.createElement("span",null),r.createElement("span",null),r.createElement("span",null))):this.props.template?r.createElement(this.props.template,{item:this.props.item}):this.props.item.text?r.createElement("div",{className:"k-chat-bubble"},this.props.item.text):null}getTimestampView(){let e=null;return this.props.item.timestamp&&(e=r.createElement("time",{className:"k-message-time","aria-hidden":!this.props.selected},E.provideIntlService(this).formatDate(this.props.item.timestamp,this.props.dateFormat))),e}getStatusView(){let e=null;return this.props.item.status&&(e=r.createElement("span",{className:"k-message-status"},this.props.item.status)),e}getClassNames(){return p.classNames({"k-only":this.props.isOnlyItemInGroup},{"k-first":this.props.isFirstItemInGroup&&!this.props.isOnlyItemInGroup},{"k-last":this.props.isLastItemInGroup&&!this.props.isOnlyItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected},"k-message")}}D.defaultProps={dateFormat:"g",tabIndex:-1},E.registerForIntl(D);const H=(s,e)=>s&&e.author&&s.id===e.author.id,B=s=>s[s.length-1],se=(s,e)=>s&&e&&(e.getDate()!==s.getDate()||e.getMonth()!==s.getMonth()||e.getFullYear()!==s.getFullYear()),ne=(s,e)=>{const t=e.timestamp,n=B(s);if(t&&(!n||se(t,n.timestamp))){const o={type:"date-marker",timestamp:t,trackBy:t.getTime()};s.push(o)}},re=(s,e,t)=>{const n=B(s);let o;e.typing&&!t||(n&&n.type==="message-group"&&(o=n.messages),o&&H(e.author,B(o))?o.push(e):s.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},ie=s=>(e,t,n)=>{const o=n===s-1;return ne(e,t),re(e,t,o),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&o&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function oe(s){let e=0;s.forEach(t=>{t.type==="message-group"?t.messages.forEach(n=>{n.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),s.lastSelectionIndex=e-1}const ae=s=>{const t=s.slice().reduce(ie(s.length),[]);return oe(t),t};class le extends V{constructor(){super(...arguments),this.onKeyDown=e=>{e.keyCode===p.Keys.enter&&this.props.onActionExecute(this.props.item,e)}}render(){return r.createElement("span",{role:"button",className:this.getClassNames(),onClick:e=>this.props.onActionExecute(this.props.item,e),ref:e=>this.elementToFocus=e,onKeyDown:this.onKeyDown,tabIndex:0},this.props.item.title||this.props.item.value)}getClassNames(){return p.classNames("k-quick-reply",{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected})}}class j extends r.Component{constructor(){super(...arguments),this.state={selectedItemIndex:null},this.onRequestContainerSelection=()=>this.props.onRequestSelection(this.props.group.selectionIndex),this.onKeyDown=e=>{let t=null,n,o;this.isKeyboardNavigationLeftRight?(n=p.Keys.left,o=p.Keys.right):(n=p.Keys.up,o=p.Keys.down),e.keyCode===n?t=this.navigate(!1):e.keyCode===o&&(t=this.navigate(!0)),t!==null&&(e.preventDefault(),e.stopPropagation())}}static getDerivedStateFromProps(e,t){return!e.selected&&t.selectedItemIndex!==null?{selectedItemIndex:null}:e.selected&&t.selectedItemIndex===null?{selectedItemIndex:0}:null}navigate(e,t=0){let n=null,o=this.state.selectedItemIndex;return e?o===null?n=t:o<this.getLastSelectionIndex()&&(n=o+1):o===null?n=0:o>0&&(n=o-1),n!==null&&this.setState({selectedItemIndex:n}),n}get isKeyboardNavigationLeftRight(){return!0}getLastSelectionIndex(){let e=-1;if(this.props.group.type==="action-group"){const t=this.props.group;e=t.actions?t.actions.length-1:-1}else if(this.props.group.type==="attachment-group"){const t=this.props.group;e=t.attachments?t.attachments.length-1:-1}return e}}class ce extends j{constructor(e){super(e)}render(){const e=this.props.group.actions?this.props.group.actions.length-1:0;return r.createElement("div",{className:this.getClassNames(),onClick:this.onRequestContainerSelection,onKeyDown:this.onKeyDown},this.props.group.actions&&this.props.group.actions.map((t,n)=>r.createElement(le,{item:t,onActionExecute:this.props.onActionExecute,selected:n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,key:n})))}getClassNames(){return p.classNames("k-quick-replies")}}class _ extends V{render(){return r.createElement("div",{className:this.getClassNames(),tabIndex:this.getTabIndexValue(),onClick:this.props.onClick,ref:e=>this.elementToFocus=e},this.props.template?r.createElement(this.props.template,{item:this.props.item}):r.createElement("div",{className:"k-card"},r.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView(),this.getContentView())))}getTabIndexValue(){if(this.props.tabbable!==void 0)return this.props.tabbable?0:-1}getClassNames(){return p.classNames({"k-selected":this.props.selected},{"k-focus":this.props.selected},{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup})}getTitleView(){return this.props.item.title?r.createElement("h5",{className:"k-card-title"},this.props.item.title):null}getSubtitleView(){return this.props.item.subtitle?r.createElement("h6",{className:"k-card-subtitle"},this.props.item.subtitle):null}getContentView(){return this.props.item.contentType.indexOf("image/")===0?r.createElement("img",{src:this.props.item.content}):this.props.item.content}}class pe extends j{render(){const e=this.isCardDeckLayout(this.props),t=r.createElement("div",{className:this.getClassNames(),onKeyDown:e?void 0:this.onKeyDown},this.props.group.attachments.map((n,o)=>r.createElement(_,{item:n,template:this.props.itemTemplate,selected:o===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&o===this.state.selectedItemIndex,isFirstItemInGroup:o===0,isLastItemInGroup:o===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(o),key:o})));return e?r.createElement("div",{className:"k-card-deck-scrollwrap",onKeyDown:this.onKeyDown},this.getLeftScrollBtn(),t,this.getRightScrollBtn()):t}get isKeyboardNavigationLeftRight(){return this.isCardDeckLayout(this.props)}getLastItemIndex(){return this.props.group.attachments.length-1}getLeftScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex&&(e=r.createElement(u.Button,{icon:"chevron-left",onClick:()=>this.onNavigateBtnClick(!1),svgIcon:m.chevronLeftIcon})),e}getRightScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex!==this.getLastItemIndex()&&(e=r.createElement(u.Button,{icon:"chevron-right",onClick:()=>this.onNavigateBtnClick(!0),svgIcon:m.chevronRightIcon})),e}onAttachmentClick(e){this.onRequestContainerSelection(),this.setState({selectedItemIndex:e})}onNavigateBtnClick(e){this.onRequestContainerSelection(),this.navigate(e,1)}isCardDeckLayout(e){return e.group.attachmentLayout!=="list"}getClassNames(){return p.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class $ extends r.Component{render(){const e=this.props.item;return r.createElement("div",{className:"k-timestamp"},E.provideIntlService(this).formatDate(e.timestamp,"D"))}}E.registerForIntl($);const P="newMessage.sendButton",K="newMessage.optionsButton",F="newMessage.messageInput",q="avatar.alt",O="messageList.ariaLabel",G="aIPrompt.noOutputs",k={[P]:"Send",[K]:"Options",[F]:"Message",[q]:"Avatar",[O]:"Message list",[G]:"No output from AI available"};class me extends r.Component{render(){const{avatarUrl:e,avatarAltText:t,name:n}=this.props.group.author,o=E.provideLocalizationService(this);return r.createElement("div",{className:this.getMsgGroupClassNames()},n&&r.createElement("p",{className:"k-author"},n),e&&r.createElement(d.Avatar,{type:"image"},r.createElement("img",{src:e,alt:t!==void 0?t:o.toLanguageString(q,k[q])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return p.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":H(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,n)=>{const o=[r.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:n===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,isOnlyItemInGroup:e===0,key:n})];return t.attachments&&t.attachments.length===1&&o.push(r.createElement(_,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),o})}}class ue extends r.Component{render(){return r.createElement("div",{className:"k-toolbar-box"},r.createElement("div",{className:"k-button-list"},this.props.children))}}class he extends r.Component{constructor(){super(...arguments),this.state={focused:!1},this.inputEl=null,this.onInputKeyDown=e=>{e.keyCode===p.Keys.enter&&this.sendMessage(e)},this.sendMessage=e=>{if(this.props.onMessageSend&&this.inputEl!==null){const t=this.inputEl.value;if(t){const n={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(n,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=E.provideLocalizationService(this),t=r.createElement("input",{type:"text",className:this.getClassNames(),placeholder:this.props.placeholder,onKeyDown:this.onInputKeyDown,onFocus:()=>this.setState({focused:!0}),onBlur:()=>this.setState({focused:!1}),ref:c=>this.inputEl=c,"aria-label":e.toLanguageString(F,k[F])}),n=r.createElement(u.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:m.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(P,k[P]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),o=r.createElement(u.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:m.moreHorizontalIcon,onClick:c=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,c),"aria-label":e.toLanguageString(K,k[K])});return r.createElement(r.Fragment,null,r.createElement("span",{className:"k-message-box k-textbox k-input k-input-md k-rounded-md k-input-solid"},this.props.MessageBox?r.createElement(this.props.MessageBox,{messageInput:t,sendButton:n,toolbarButton:o}):r.createElement(r.Fragment,null,t,r.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&o,n))),this.props.showToolbar&&r.createElement(ue,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return p.classNames("k-input-inner",{"k-focus":this.state.focused})}}const de={name:"@progress/kendo-react-conversational-ui",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},Y=class extends r.Component{constructor(s){super(s),this.viewItems=[],this.isDirectionRightToLeft=!1,this.scrollToBottomOnLoadingData=!0,this.onFocus=()=>{clearTimeout(this.timeoutIdForChatLosingFocus)},this.onBlur=()=>{this.timeoutIdForChatLosingFocus=window.setTimeout(()=>{this.setState({selectedItemIndex:null})},0)},this.onSelectionRequested=e=>{this.setState({selectedItemIndex:e})},this.onKeyDown=e=>{let t=null,n=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===p.Keys.up?n===null?t=0:n>0&&(t=n-1):e.keyCode===p.Keys.down&&(n===null?t=0:n<this.viewItems.lastSelectionIndex&&(t=n+1)),t!==null&&(this.setState({selectedItemIndex:t}),e.preventDefault())},this.onMessageSend=(e,t)=>{p.dispatchEvent(this.props.onMessageSend,t,this,{message:e})},this.onActionExecute=(e,t)=>{if(p.dispatchEvent(this.props.onActionExecute,t,this,{action:e}),!t.isDefaultPrevented()){switch(e.type){case"reply":this.onMessageSend({author:this.props.user,text:e.value,timestamp:new Date},t);break;case"call":window.open("tel:"+e.value);break;case"openUrl":window.open(e.value);break}this.newMsgComp.focusInput()}},p.validatePackage(de),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const s=E.provideLocalizationService(this);return r.createElement("div",{style:{width:this.props.width},onKeyDown:this.onKeyDown,className:this.getClassNames(),ref:e=>this.chatWrapperEl=e},r.createElement("div",{className:"k-message-list k-avatars",onBlur:this.onBlur,onFocus:this.onFocus,role:"log","aria-label":s.toLanguageString(O,k[O]),"aria-live":"polite",onScroll:e=>{this.scrollToBottomOnLoadingData=e.currentTarget.scrollTop===e.currentTarget.scrollHeight-e.currentTarget.clientHeight},ref:e=>this.viewItemsWrapperEl=e},r.createElement("div",{className:"k-message-list-content"},this.renderViewItems())),r.createElement(he,{user:this.props.user,onMessageSend:this.onMessageSend,isDirectionRightToLeft:this.isDirectionRightToLeft,ref:e=>this.newMsgComp=e,placeholder:this.props.placeholder,MessageBox:this.props.messageBox,toolbar:this.props.toolbar,onToolbarActionButtonClick:this.props.onToolbarActionExecute,showToolbar:this.props.showToolbar}))}componentDidMount(){this.setState({isFirstRender:!1},()=>{this.nextTickId=window.setTimeout(()=>this.scrollViewItemsToBottom(),250)})}componentWillUnmount(){clearTimeout(this.nextTickId)}componentDidUpdate(s){s.messages.length!==this.props.messages.length&&this.scrollToBottomOnLoadingData&&this.scrollViewItemsToBottom()}getClassNames(){return p.classNames("k-chat",this.props.className,{"k-rtl":this.isDirectionRightToLeft})}checkIsDirectionRightToLeft(s){return!!(s.dir!==void 0?s.dir==="rtl":this.chatWrapperEl&&getComputedStyle(this.chatWrapperEl).direction==="rtl")}renderViewItems(){const s=this.viewItems.length-1;return this.viewItems.map((e,t)=>{if(e.type==="date-marker")return r.createElement($,{item:e,key:t});if(e.type==="message-group")return r.createElement(me,{group:e,itemTemplate:this.props.messageTemplate,attachmentTemplate:this.props.attachmentTemplate,user:this.props.user,selectedItemIndex:this.state.selectedItemIndex,onRequestSelection:this.onSelectionRequested,isLastGroup:t===s,key:t,message:this.props.message||Y.defaultProps.message});if(e.type==="attachment-group")return r.createElement(pe,{group:e,itemTemplate:this.props.attachmentTemplate,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t});if(e.type==="action-group")return r.createElement(ce,{group:e,onActionExecute:this.onActionExecute,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t})})}scrollViewItemsToBottom(){this.viewItemsWrapperEl&&(this.viewItemsWrapperEl.scrollTop=this.viewItemsWrapperEl.scrollHeight-this.viewItemsWrapperEl.clientHeight)}getViewItemsFromMsgs(s){return s.length>0?ae(s):[]}};let z=Y;z.propTypes={messages:h.arrayOf(h.object),user:h.object,messageTemplate:h.any,attachmentTemplate:h.any,width:h.oneOfType([h.string,h.number]),onMessageSend:h.func,onActionExecute:h.func,dir:h.string,messageBox:h.any},z.defaultProps={messages:[],dateFormat:"g",message:D};class ge extends r.Component{constructor(){super(...arguments),this.onBtnClick=(e,t)=>{p.dispatchEvent(this.props.onActionExecute,t,this,{action:e})}}render(){return r.createElement("div",{className:"k-card"},r.createElement("img",{className:"k-card-image",src:this.props.imageUrl,style:{maxWidth:this.props.imageMaxWidth}}),r.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView()),r.createElement("div",{className:"k-card-actions k-card-actions-vertical"},this.getActionsView()))}getActionsView(){return this.props.actions.map((e,t)=>r.createElement("span",{className:"k-card-action",key:t},r.createElement(u.Button,{fillMode:"flat",onClick:n=>this.onBtnClick(e,n)},e.title)))}getTitleView(){let e=null;return this.props.title&&(e=r.createElement("h5",{className:"k-card-title"},this.props.title)),e}getSubtitleView(){let e=null;return this.props.subtitle&&(e=r.createElement("h6",{className:"k-card-subtitle"},this.props.subtitle)),e}}const J=s=>{const{activeView:e,toolbarItems:t,activeViewChange:n}=s,o=c=>{n==null||n.call(null,c)};return i.createElement("div",{className:"k-prompt-header"},i.createElement(u.Toolbar,{keyboardNavigation:!1,role:"toolbar",className:"k-toolbar-flat"},t.map(c=>i.isValidElement(c)?c:i.createElement(u.Button,{key:c.name,className:e===c.name?"k-selected":"",size:"medium",themeColor:"primary",fillMode:"flat",rounded:"full",title:c.buttonText,svgIcon:c.buttonIcon,"aria-hidden":"true",onClick:()=>o(c.name)},c.buttonText))))},x=i.forwardRef((s,e)=>{const{children:t}=s;return i.createElement("div",{className:"k-prompt-content",ref:e},i.createElement("div",{className:"k-prompt-view"},t))});x.displayName="KendoReactAIPromptContent";const Q=s=>{const{children:e}=s;return i.createElement("div",{className:"k-prompt-footer"},i.createElement("div",{className:"k-actions k-actions-start k-actions-horizontal k-prompt-actions"},e))},X=i.createContext([{},()=>{}]),M=()=>i.useContext(X),A=s=>{const[e]=M();return e.activeView===s.name?s.children:null},Ie=s=>{const[e,t]=i.useState(!0),{children:n,title:o}=s;return i.createElement("div",{className:"k-prompt-expander"},i.createElement(u.Button,{fillMode:"flat",svgIcon:e?m.chevronUpIcon:m.chevronDownIcon,title:o,onClick:()=>t(!e)},o),e&&i.createElement("div",{className:"k-prompt-expander-content"},n))},U={name:"prompt-view",buttonText:"Ask AI",buttonIcon:m.sparklesIcon},fe=s=>{const e="Generate",{promptInput:t=ee.TextArea,generateButton:n=u.Button,promptValue:o,promptSuggestions:c}=s,[f,g]=i.useState(o||""),[I]=M(),[w,y]=p.useCustomComponent(n),[N,C]=p.useCustomComponent(t),T=()=>{I.onPromptRequest&&I.onPromptRequest.call(null,f),g("")},v=b=>{g(b)},L=b=>{g(b.target.value)},a={title:"Generate",svgIcon:m.sparklesIcon},S={placeholder:"Ask or generate content with AI ...",rows:2},be=Object.keys(y).length>0?y:a,ke=Object.keys(C).length>0?C:S;return i.createElement(A,{name:U.name},i.createElement(x,null,i.createElement(N,{value:f,onChange:L,...ke}),c&&c.length>0&&i.createElement(Ie,{title:"Prompt Suggestions"},c.map(b=>i.createElement("div",{key:b,className:"k-prompt-suggestion",onClick:()=>v(b)},b)))),i.createElement(Q,null,i.createElement(w,{themeColor:"primary",fillMode:"solid","aria-hidden":"true",rounded:"full",size:"medium",onClick:T,...be},e)))},W={name:"Output view",buttonText:"Output",buttonIcon:m.commentIcon},Ee=s=>{const[e,t]=i.useState(""),n=i.useRef(null),[o]=M(),{outputs:c,showOutputRating:f,outputCard:g}=s,{header:I,body:w,actions:y}=g||{},N=E.useLocalization(),C=a=>{o.onPromptRequest&&o.onPromptRequest.call(null,a.prompt,{...a,isRetry:!0}),L()},T=a=>{a!=null&&a.responseContent&&navigator.clipboard.writeText(a.responseContent),t(a.id),setTimeout(()=>{t("")},1e3)},v=(a,S)=>{o.onPromptRequest&&o.onPromptRequest.call(null,a.prompt,{...a,ratingType:S,isRetry:!1}),L()},L=()=>{n&&n.current&&n.current.scrollTo({top:0,behavior:"smooth"})};return i.createElement(A,{name:W.name},i.createElement(x,{ref:n},i.createElement("div",{className:"k-card-list"},c&&c.length>0?c.map((a,S)=>i.createElement(d.Card,{key:`${a.id}_${S}`},i.createElement(d.CardHeader,null,I?I(a):i.createElement(i.Fragment,null,a.title&&i.createElement(d.CardTitle,null,a.title),a.subTitle&&i.createElement(d.CardSubtitle,null,a.subTitle))),i.createElement(d.CardBody,null,w?w(a):a.responseContent),i.createElement(d.CardActions,null,y?y(a):i.createElement(i.Fragment,null,i.createElement(u.Button,{size:"medium",themeColor:"primary",fillMode:"flat",rounded:"medium",title:"Copy",svgIcon:e===a.id?m.copyIcon:m.checkIcon,"aria-hidden":"true",onClick:()=>T(a)},"Copy"),i.createElement(u.Button,{size:"medium",themeColor:"base",fillMode:"flat",rounded:"medium",title:"Retry",svgIcon:m.rotateIcon,"aria-hidden":"true",onClick:()=>C(a)},"Retry"),f&&i.createElement(i.Fragment,null,i.createElement("span",{className:"k-spacer"}),i.createElement(u.Button,{size:"medium",themeColor:a.ratingType==="positive"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate up",svgIcon:m.thumbUpOutlineIcon,"aria-hidden":"true",onClick:()=>v(a,"positive")}),i.createElement(u.Button,{size:"medium",themeColor:a.ratingType==="negative"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate down",svgIcon:m.thumbDownOutlineIcon,"aria-hidden":"true",onClick:()=>v(a,"negative")})))))):i.createElement(d.Card,null,i.createElement(d.CardBody,null,N.toLanguageString(G,k[G]))))))},ye=s=>{const{activeView:e,toolbarItems:t,children:n,onActiveViewChange:o,onPromptRequest:c,onCommandExecute:f,style:g,dir:I}=s,w=t||[U,W],[y,N]=i.useState({activeView:e}),C={...y,activeView:e,onActiveViewChange:o,onPromptRequest:c,onCommandExecute:f},T=v=>{N(v)};return i.createElement(X.Provider,{value:[C,T]},i.createElement("div",{className:"k-prompt",style:g,dir:I},i.createElement(J,{activeView:C.activeView,toolbarItems:w,activeViewChange:o}),n))},Z={name:"Commands view",buttonIcon:m.moreHorizontalIcon},R=s=>s==null?void 0:s.map(e=>i.createElement(d.PanelBarItem,{title:e.text,key:e.id,svgIcon:e.svgIcon,data:e},e.children&&R(e.children||[]))),Ce=s=>{const{commands:e}=s,[t]=M(),n=o=>{var f,g,I;const c=(g=(f=o.target)==null?void 0:f.props)==null?void 0:g.data;(I=c.children)!=null&&I.length||t.onCommandExecute&&t.onCommandExecute.call(null,c)};return i.createElement(A,{name:Z.name},i.createElement(x,null,i.createElement("div",{className:"k-prompt-view"},i.createElement(d.PanelBar,{onSelect:n,selected:""},R(e!=null?e:[])))))};l.AIPrompt=ye,l.AIPromptCommandsView=Ce,l.AIPromptContent=x,l.AIPromptFooter=Q,l.AIPromptOutputView=Ee,l.AIPromptView=fe,l.AIPromptViewRender=A,l.Chat=z,l.ChatMessage=D,l.HeroCard=ge,l.PromptHeader=J,l.commandsViewDefaults=Z,l.outputViewDefaults=W,l.promptViewDefaults=U,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
package/index.js CHANGED
@@ -2,4 +2,4 @@
2
2
  * Copyright © 2024 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the package root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),c=require("@progress/kendo-react-common"),f=require("@progress/kendo-react-intl"),u=require("prop-types"),p=require("@progress/kendo-svg-icons"),m=require("@progress/kendo-react-buttons"),d=require("@progress/kendo-react-layout"),te=require("@progress/kendo-react-inputs");function se(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const o=se(a);class F extends o.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class S extends F{render(){return o.createElement("div",{className:this.getClassNames(),tabIndex:this.props.tabIndex,onClick:()=>this.props.onRequestSelection(this.props.item.selectionIndex),onFocus:()=>this.props.onRequestSelection(this.props.item.selectionIndex),ref:e=>this.elementToFocus=e},this.getTimestampView(),this.getMainView(),this.getStatusView())}getMainView(){return this.props.item.typing?o.createElement("div",{className:"k-chat-bubble"},o.createElement("div",{className:"k-typing-indicator"},o.createElement("span",null),o.createElement("span",null),o.createElement("span",null))):this.props.template?o.createElement(this.props.template,{item:this.props.item}):this.props.item.text?o.createElement("div",{className:"k-chat-bubble"},this.props.item.text):null}getTimestampView(){let e=null;return this.props.item.timestamp&&(e=o.createElement("time",{className:"k-message-time","aria-hidden":!this.props.selected},f.provideIntlService(this).formatDate(this.props.item.timestamp,this.props.dateFormat))),e}getStatusView(){let e=null;return this.props.item.status&&(e=o.createElement("span",{className:"k-message-status"},this.props.item.status)),e}getClassNames(){return c.classNames({"k-only":this.props.isOnlyItemInGroup},{"k-first":this.props.isFirstItemInGroup&&!this.props.isOnlyItemInGroup},{"k-last":this.props.isLastItemInGroup&&!this.props.isOnlyItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected},"k-message")}}S.defaultProps={dateFormat:"g",tabIndex:-1};f.registerForIntl(S);const K=(s,e)=>s&&e.author&&s.id===e.author.id,L=s=>s[s.length-1],ne=(s,e)=>s&&e&&(e.getDate()!==s.getDate()||e.getMonth()!==s.getMonth()||e.getFullYear()!==s.getFullYear()),oe=(s,e)=>{const t=e.timestamp,n=L(s);if(t&&(!n||ne(t,n.timestamp))){const r={type:"date-marker",timestamp:t,trackBy:t.getTime()};s.push(r)}},ae=(s,e,t)=>{const n=L(s);let r;e.typing&&!t||(n&&n.type==="message-group"&&(r=n.messages),r&&K(e.author,L(r))?r.push(e):s.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},re=s=>(e,t,n)=>{const r=n===s-1;return oe(e,t),ae(e,t,r),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&r&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function ie(s){let e=0;s.forEach(t=>{t.type==="message-group"?t.messages.forEach(n=>{n.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),s.lastSelectionIndex=e-1}const le=s=>{const t=s.slice().reduce(re(s.length),[]);return ie(t),t};class ce extends F{constructor(){super(...arguments),this.onKeyDown=e=>{e.keyCode===c.Keys.enter&&this.props.onActionExecute(this.props.item,e)}}render(){return o.createElement("span",{role:"button",className:this.getClassNames(),onClick:e=>this.props.onActionExecute(this.props.item,e),ref:e=>this.elementToFocus=e,onKeyDown:this.onKeyDown,tabIndex:0},this.props.item.title||this.props.item.value)}getClassNames(){return c.classNames("k-quick-reply",{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected})}}class z extends o.Component{constructor(){super(...arguments),this.state={selectedItemIndex:null},this.onRequestContainerSelection=()=>this.props.onRequestSelection(this.props.group.selectionIndex),this.onKeyDown=e=>{let t=null,n,r;this.isKeyboardNavigationLeftRight?(n=c.Keys.left,r=c.Keys.right):(n=c.Keys.up,r=c.Keys.down),e.keyCode===n?t=this.navigate(!1):e.keyCode===r&&(t=this.navigate(!0)),t!==null&&(e.preventDefault(),e.stopPropagation())}}static getDerivedStateFromProps(e,t){return!e.selected&&t.selectedItemIndex!==null?{selectedItemIndex:null}:e.selected&&t.selectedItemIndex===null?{selectedItemIndex:0}:null}navigate(e,t=0){let n=null,r=this.state.selectedItemIndex;return e?r===null?n=t:r<this.getLastSelectionIndex()&&(n=r+1):r===null?n=0:r>0&&(n=r-1),n!==null&&this.setState({selectedItemIndex:n}),n}get isKeyboardNavigationLeftRight(){return!0}getLastSelectionIndex(){let e=-1;if(this.props.group.type==="action-group"){const t=this.props.group;e=t.actions?t.actions.length-1:-1}else if(this.props.group.type==="attachment-group"){const t=this.props.group;e=t.attachments?t.attachments.length-1:-1}return e}}class pe extends z{constructor(e){super(e)}render(){const e=this.props.group.actions?this.props.group.actions.length-1:0;return o.createElement("div",{className:this.getClassNames(),onClick:this.onRequestContainerSelection,onKeyDown:this.onKeyDown},this.props.group.actions&&this.props.group.actions.map((t,n)=>o.createElement(ce,{item:t,onActionExecute:this.props.onActionExecute,selected:n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,key:n})))}getClassNames(){return c.classNames("k-quick-replies")}}class U extends F{render(){return o.createElement("div",{className:this.getClassNames(),tabIndex:this.getTabIndexValue(),onClick:this.props.onClick,ref:e=>this.elementToFocus=e},this.props.template?o.createElement(this.props.template,{item:this.props.item}):o.createElement("div",{className:"k-card"},o.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView(),this.getContentView())))}getTabIndexValue(){if(this.props.tabbable!==void 0)return this.props.tabbable?0:-1}getClassNames(){return c.classNames({"k-selected":this.props.selected},{"k-focus":this.props.selected},{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup})}getTitleView(){return this.props.item.title?o.createElement("h5",{className:"k-card-title"},this.props.item.title):null}getSubtitleView(){return this.props.item.subtitle?o.createElement("h6",{className:"k-card-subtitle"},this.props.item.subtitle):null}getContentView(){return this.props.item.contentType.indexOf("image/")===0?o.createElement("img",{src:this.props.item.content}):this.props.item.content}}class me extends z{render(){const e=this.isCardDeckLayout(this.props),t=o.createElement("div",{className:this.getClassNames(),onKeyDown:e?void 0:this.onKeyDown},this.props.group.attachments.map((n,r)=>o.createElement(U,{item:n,template:this.props.itemTemplate,selected:r===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&r===this.state.selectedItemIndex,isFirstItemInGroup:r===0,isLastItemInGroup:r===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(r),key:r})));return e?o.createElement("div",{className:"k-card-deck-scrollwrap",onKeyDown:this.onKeyDown},this.getLeftScrollBtn(),t,this.getRightScrollBtn()):t}get isKeyboardNavigationLeftRight(){return this.isCardDeckLayout(this.props)}getLastItemIndex(){return this.props.group.attachments.length-1}getLeftScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex&&(e=o.createElement(m.Button,{icon:"chevron-left",onClick:()=>this.onNavigateBtnClick(!1),svgIcon:p.chevronLeftIcon})),e}getRightScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex!==this.getLastItemIndex()&&(e=o.createElement(m.Button,{icon:"chevron-right",onClick:()=>this.onNavigateBtnClick(!0),svgIcon:p.chevronRightIcon})),e}onAttachmentClick(e){this.onRequestContainerSelection(),this.setState({selectedItemIndex:e})}onNavigateBtnClick(e){this.onRequestContainerSelection(),this.navigate(e,1)}isCardDeckLayout(e){return e.group.attachmentLayout!=="list"}getClassNames(){return c.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class W extends o.Component{render(){const e=this.props.item;return o.createElement("div",{className:"k-timestamp"},f.provideIntlService(this).formatDate(e.timestamp,"D"))}}f.registerForIntl(W);const M="newMessage.sendButton",B="newMessage.optionsButton",R="newMessage.messageInput",A="avatar.alt",P="messageList.ariaLabel",V="aIPrompt.noOutputs",b={[M]:"Send",[B]:"Options",[R]:"Message",[A]:"Avatar",[P]:"Message list",[V]:"No output from AI available"};class ue extends o.Component{render(){const{avatarUrl:e,avatarAltText:t,name:n}=this.props.group.author,r=f.provideLocalizationService(this);return o.createElement("div",{className:this.getMsgGroupClassNames()},n&&o.createElement("p",{className:"k-author"},n),e&&o.createElement(d.Avatar,{type:"image"},o.createElement("img",{src:e,alt:t!==void 0?t:r.toLanguageString(A,b[A])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return c.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":K(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,n)=>{const r=[o.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:n===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,isOnlyItemInGroup:e===0,key:n})];return t.attachments&&t.attachments.length===1&&r.push(o.createElement(U,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),r})}}class he extends o.Component{render(){return o.createElement("div",{className:"k-toolbar-box"},o.createElement("div",{className:"k-button-list"},this.props.children))}}class de extends o.Component{constructor(){super(...arguments),this.state={focused:!1},this.inputEl=null,this.onInputKeyDown=e=>{e.keyCode===c.Keys.enter&&this.sendMessage(e)},this.sendMessage=e=>{if(this.props.onMessageSend&&this.inputEl!==null){const t=this.inputEl.value;if(t){const n={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(n,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=f.provideLocalizationService(this),t=o.createElement("input",{type:"text",className:this.getClassNames(),placeholder:this.props.placeholder,onKeyDown:this.onInputKeyDown,onFocus:()=>this.setState({focused:!0}),onBlur:()=>this.setState({focused:!1}),ref:l=>this.inputEl=l,"aria-label":e.toLanguageString(R,b[R])}),n=o.createElement(m.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:p.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(M,b[M]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),r=o.createElement(m.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:p.moreHorizontalIcon,onClick:l=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,l),"aria-label":e.toLanguageString(B,b[B])});return o.createElement(o.Fragment,null,o.createElement("span",{className:"k-message-box k-textbox k-input k-input-md k-rounded-md k-input-solid"},this.props.MessageBox?o.createElement(this.props.MessageBox,{messageInput:t,sendButton:n,toolbarButton:r}):o.createElement(o.Fragment,null,t,o.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&r,n))),this.props.showToolbar&&o.createElement(he,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return c.classNames("k-input-inner",{"k-focus":this.state.focused})}}const ge={name:"@progress/kendo-react-conversational-ui",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},H=class extends o.Component{constructor(s){super(s),this.viewItems=[],this.isDirectionRightToLeft=!1,this.scrollToBottomOnLoadingData=!0,this.onFocus=()=>{clearTimeout(this.timeoutIdForChatLosingFocus)},this.onBlur=()=>{this.timeoutIdForChatLosingFocus=window.setTimeout(()=>{this.setState({selectedItemIndex:null})},0)},this.onSelectionRequested=e=>{this.setState({selectedItemIndex:e})},this.onKeyDown=e=>{let t=null,n=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===c.Keys.up?n===null?t=0:n>0&&(t=n-1):e.keyCode===c.Keys.down&&(n===null?t=0:n<this.viewItems.lastSelectionIndex&&(t=n+1)),t!==null&&(this.setState({selectedItemIndex:t}),e.preventDefault())},this.onMessageSend=(e,t)=>{c.dispatchEvent(this.props.onMessageSend,t,this,{message:e})},this.onActionExecute=(e,t)=>{if(c.dispatchEvent(this.props.onActionExecute,t,this,{action:e}),!t.isDefaultPrevented()){switch(e.type){case"reply":this.onMessageSend({author:this.props.user,text:e.value,timestamp:new Date},t);break;case"call":window.open("tel:"+e.value);break;case"openUrl":window.open(e.value);break}this.newMsgComp.focusInput()}},c.validatePackage(ge),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const s=f.provideLocalizationService(this);return o.createElement("div",{style:{width:this.props.width},onKeyDown:this.onKeyDown,className:this.getClassNames(),ref:e=>this.chatWrapperEl=e},o.createElement("div",{className:"k-message-list k-avatars",onBlur:this.onBlur,onFocus:this.onFocus,role:"log","aria-label":s.toLanguageString(P,b[P]),"aria-live":"polite",onScroll:e=>{this.scrollToBottomOnLoadingData=e.currentTarget.scrollTop===e.currentTarget.scrollHeight-e.currentTarget.clientHeight},ref:e=>this.viewItemsWrapperEl=e},o.createElement("div",{className:"k-message-list-content"},this.renderViewItems())),o.createElement(de,{user:this.props.user,onMessageSend:this.onMessageSend,isDirectionRightToLeft:this.isDirectionRightToLeft,ref:e=>this.newMsgComp=e,placeholder:this.props.placeholder,MessageBox:this.props.messageBox,toolbar:this.props.toolbar,onToolbarActionButtonClick:this.props.onToolbarActionExecute,showToolbar:this.props.showToolbar}))}componentDidMount(){this.setState({isFirstRender:!1},()=>{this.nextTickId=window.setTimeout(()=>this.scrollViewItemsToBottom(),250)})}componentWillUnmount(){clearTimeout(this.nextTickId)}componentDidUpdate(s){s.messages.length!==this.props.messages.length&&this.scrollToBottomOnLoadingData&&this.scrollViewItemsToBottom()}getClassNames(){return c.classNames("k-chat",this.props.className,{"k-rtl":this.isDirectionRightToLeft})}checkIsDirectionRightToLeft(s){return!!(s.dir!==void 0?s.dir==="rtl":this.chatWrapperEl&&getComputedStyle(this.chatWrapperEl).direction==="rtl")}renderViewItems(){const s=this.viewItems.length-1;return this.viewItems.map((e,t)=>{if(e.type==="date-marker")return o.createElement(W,{item:e,key:t});if(e.type==="message-group")return o.createElement(ue,{group:e,itemTemplate:this.props.messageTemplate,attachmentTemplate:this.props.attachmentTemplate,user:this.props.user,selectedItemIndex:this.state.selectedItemIndex,onRequestSelection:this.onSelectionRequested,isLastGroup:t===s,key:t,message:this.props.message||H.defaultProps.message});if(e.type==="attachment-group")return o.createElement(me,{group:e,itemTemplate:this.props.attachmentTemplate,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t});if(e.type==="action-group")return o.createElement(pe,{group:e,onActionExecute:this.onActionExecute,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t})})}scrollViewItemsToBottom(){this.viewItemsWrapperEl&&(this.viewItemsWrapperEl.scrollTop=this.viewItemsWrapperEl.scrollHeight-this.viewItemsWrapperEl.clientHeight)}getViewItemsFromMsgs(s){return s.length>0?le(s):[]}};let q=H;q.propTypes={messages:u.arrayOf(u.object),user:u.object,messageTemplate:u.any,attachmentTemplate:u.any,width:u.oneOfType([u.string,u.number]),onMessageSend:u.func,onActionExecute:u.func,dir:u.string,messageBox:u.any};q.defaultProps={messages:[],dateFormat:"g",message:S};class Ie extends o.Component{constructor(){super(...arguments),this.onBtnClick=(e,t)=>{c.dispatchEvent(this.props.onActionExecute,t,this,{action:e})}}render(){return o.createElement("div",{className:"k-card"},o.createElement("img",{className:"k-card-image",src:this.props.imageUrl,style:{maxWidth:this.props.imageMaxWidth}}),o.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView()),o.createElement("div",{className:"k-card-actions k-card-actions-vertical"},this.getActionsView()))}getActionsView(){return this.props.actions.map((e,t)=>o.createElement("span",{className:"k-card-action",key:t},o.createElement(m.Button,{fillMode:"flat",onClick:n=>this.onBtnClick(e,n)},e.title)))}getTitleView(){let e=null;return this.props.title&&(e=o.createElement("h5",{className:"k-card-title"},this.props.title)),e}getSubtitleView(){let e=null;return this.props.subtitle&&(e=o.createElement("h6",{className:"k-card-subtitle"},this.props.subtitle)),e}}const j=s=>{const{activeView:e,toolbarItems:t,activeViewChange:n}=s,r=l=>{n==null||n.call(null,l)};return a.createElement("div",{className:"k-prompt-header"},a.createElement(m.Toolbar,{keyboardNavigation:!1,role:"toolbar",className:"k-toolbar-flat"},t.map(l=>a.createElement(m.Button,{key:l.name,className:e===l.name?"k-selected":"",size:"medium",themeColor:"primary",fillMode:"flat",rounded:"full",title:l.buttonText,svgIcon:l.buttonIcon,"aria-hidden":"true",onClick:()=>r(l.name)},l.buttonText))))},T=s=>{const{children:e}=s;return a.createElement("div",{className:"k-prompt-content"},a.createElement("div",{className:"k-prompt-view"},e))},_=s=>{const{children:e}=s;return a.createElement("div",{className:"k-prompt-footer"},a.createElement("div",{className:"k-actions k-actions-start k-actions-horizontal k-prompt-actions"},e))},$=a.createContext([{},()=>{}]),N=()=>a.useContext($),D=s=>{const[e]=N();return e.activeView===s.name?s.children:null},ke=s=>{const[e,t]=a.useState(!0),{children:n,title:r}=s;return a.createElement("div",{className:"k-prompt-expander"},a.createElement(m.Button,{fillMode:"flat",svgIcon:e?p.chevronUpIcon:p.chevronDownIcon,title:r,onClick:()=>t(!e)},r),e&&a.createElement("div",{className:"k-prompt-expander-content"},n))},O={name:"prompt-view",buttonText:"Ask AI",buttonIcon:p.sparklesIcon},fe=s=>{const e="Generate",{promptInput:t=te.TextArea,generateButton:n=m.Button,promptValue:r,promptSuggestions:l}=s,[g,h]=a.useState(r||""),[I]=N(),[x,k]=c.useCustomComponent(n),[y,C]=c.useCustomComponent(t),v=()=>{I.onPromptRequest&&I.onPromptRequest.call(null,g),h("")},i=E=>{h(E)},w=E=>{h(E.target.value)},Q={title:"Generate",svgIcon:p.sparklesIcon},X={placeholder:"Ask or generate content with AI ...",rows:2},Z=Object.keys(k).length>0?k:Q,ee=Object.keys(C).length>0?C:X;return a.createElement(D,{name:O.name},a.createElement(T,null,a.createElement(y,{value:g,onChange:w,...ee}),l&&l.length>0&&a.createElement(ke,{title:"Prompt Suggestions"},l.map(E=>a.createElement("div",{key:E,className:"k-prompt-suggestion",onClick:()=>i(E)},E)))),a.createElement(_,null,a.createElement(x,{themeColor:"primary",fillMode:"solid","aria-hidden":"true",rounded:"full",size:"medium",onClick:v,...Z},e)))},G={name:"Output view",buttonText:"Output",buttonIcon:p.commentIcon},Ee=s=>{const[e,t]=a.useState(p.copyIcon),{outputs:n,showOutputRating:r,outputCard:l}=s,{header:g,body:h,actions:I}=l||{},x=f.useLocalization(),[k]=N(),y=i=>{k.onPromptRequest&&k.onPromptRequest.call(null,i.prompt,{...i,isRetry:!0})},C=i=>{i!=null&&i.responseContent&&navigator.clipboard.writeText(i.responseContent),t(p.checkIcon),setTimeout(()=>{t(p.copyIcon)},1e3)},v=(i,w)=>{k.onPromptRequest&&k.onPromptRequest.call(null,i.prompt,{...i,ratingType:w,isRetry:!1})};return a.createElement(D,{name:G.name},a.createElement(T,null,a.createElement("div",{className:"k-card-list"},n&&n.length>0?n.map((i,w)=>a.createElement(d.Card,{key:`${i.id}_${w}`},a.createElement(d.CardHeader,null,g?g(i):a.createElement(a.Fragment,null,i.title&&a.createElement(d.CardTitle,null,i.title),i.subTitle&&a.createElement(d.CardSubtitle,null,i.subTitle))),a.createElement(d.CardBody,null,h?h(i):i.responseContent),a.createElement(d.CardActions,null,I?I(i):a.createElement(a.Fragment,null,a.createElement(m.Button,{size:"medium",themeColor:"primary",fillMode:"flat",rounded:"medium",title:"Copy",svgIcon:e,"aria-hidden":"true",onClick:()=>C(i)},"Copy"),a.createElement(m.Button,{size:"medium",themeColor:"base",fillMode:"flat",rounded:"medium",title:"Retry",svgIcon:p.rotateIcon,"aria-hidden":"true",onClick:()=>y(i)},"Retry"),r&&a.createElement(a.Fragment,null,a.createElement("span",{className:"k-spacer"}),a.createElement(m.Button,{size:"medium",themeColor:i.ratingType==="positive"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate up",svgIcon:p.thumbUpOutlineIcon,"aria-hidden":"true",onClick:()=>v(i,"positive")}),a.createElement(m.Button,{size:"medium",themeColor:i.ratingType==="negative"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate down",svgIcon:p.thumbDownOutlineIcon,"aria-hidden":"true",onClick:()=>v(i,"negative")})))))):a.createElement(d.Card,null,a.createElement(d.CardBody,null,x.toLanguageString(V,b[V]))))))},ye=s=>{const{activeView:e,toolbarItems:t,children:n,onActiveViewChange:r,onPromptRequest:l,onCommandExecute:g,style:h}=s,I=t||[O,G],[x,k]=a.useState({activeView:e}),y={...x,activeView:e,onActiveViewChange:r,onPromptRequest:l,onCommandExecute:g},C=v=>{k(v)};return a.createElement($.Provider,{value:[y,C]},a.createElement("div",{className:"k-prompt",style:h},a.createElement(j,{activeView:y.activeView,toolbarItems:I,activeViewChange:r}),n))},Y={name:"Commands view",buttonIcon:p.moreHorizontalIcon},J=s=>s==null?void 0:s.map(e=>a.createElement(d.PanelBarItem,{title:e.text,key:e.id,svgIcon:e.svgIcon,data:e},e.children&&J(e.children||[]))),Ce=s=>{const{commands:e}=s,[t]=N(),n=r=>{var g,h,I;const l=(h=(g=r.target)==null?void 0:g.props)==null?void 0:h.data;(I=l.children)!=null&&I.length||t.onCommandExecute&&t.onCommandExecute.call(null,l)};return a.createElement(D,{name:Y.name},a.createElement(T,null,a.createElement("div",{className:"k-prompt-view"},a.createElement(d.PanelBar,{onSelect:n,selected:""},J(e!=null?e:[])))))};exports.AIPrompt=ye;exports.AIPromptCommandsView=Ce;exports.AIPromptContent=T;exports.AIPromptFooter=_;exports.AIPromptOutputView=Ee;exports.AIPromptView=fe;exports.AIPromptViewRender=D;exports.Chat=q;exports.ChatMessage=S;exports.HeroCard=Ie;exports.PromptHeader=j;exports.commandsViewDefaults=Y;exports.outputViewDefaults=G;exports.promptViewDefaults=O;
5
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),c=require("@progress/kendo-react-common"),k=require("@progress/kendo-react-intl"),u=require("prop-types"),p=require("@progress/kendo-svg-icons"),m=require("@progress/kendo-react-buttons"),h=require("@progress/kendo-react-layout"),te=require("@progress/kendo-react-inputs");function se(s){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>s[t]})}}return e.default=s,Object.freeze(e)}const o=se(a);class O extends o.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class D extends O{render(){return o.createElement("div",{className:this.getClassNames(),tabIndex:this.props.tabIndex,onClick:()=>this.props.onRequestSelection(this.props.item.selectionIndex),onFocus:()=>this.props.onRequestSelection(this.props.item.selectionIndex),ref:e=>this.elementToFocus=e},this.getTimestampView(),this.getMainView(),this.getStatusView())}getMainView(){return this.props.item.typing?o.createElement("div",{className:"k-chat-bubble"},o.createElement("div",{className:"k-typing-indicator"},o.createElement("span",null),o.createElement("span",null),o.createElement("span",null))):this.props.template?o.createElement(this.props.template,{item:this.props.item}):this.props.item.text?o.createElement("div",{className:"k-chat-bubble"},this.props.item.text):null}getTimestampView(){let e=null;return this.props.item.timestamp&&(e=o.createElement("time",{className:"k-message-time","aria-hidden":!this.props.selected},k.provideIntlService(this).formatDate(this.props.item.timestamp,this.props.dateFormat))),e}getStatusView(){let e=null;return this.props.item.status&&(e=o.createElement("span",{className:"k-message-status"},this.props.item.status)),e}getClassNames(){return c.classNames({"k-only":this.props.isOnlyItemInGroup},{"k-first":this.props.isFirstItemInGroup&&!this.props.isOnlyItemInGroup},{"k-last":this.props.isLastItemInGroup&&!this.props.isOnlyItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected},"k-message")}}D.defaultProps={dateFormat:"g",tabIndex:-1};k.registerForIntl(D);const U=(s,e)=>s&&e.author&&s.id===e.author.id,M=s=>s[s.length-1],ne=(s,e)=>s&&e&&(e.getDate()!==s.getDate()||e.getMonth()!==s.getMonth()||e.getFullYear()!==s.getFullYear()),oe=(s,e)=>{const t=e.timestamp,n=M(s);if(t&&(!n||ne(t,n.timestamp))){const r={type:"date-marker",timestamp:t,trackBy:t.getTime()};s.push(r)}},ae=(s,e,t)=>{const n=M(s);let r;e.typing&&!t||(n&&n.type==="message-group"&&(r=n.messages),r&&U(e.author,M(r))?r.push(e):s.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},re=s=>(e,t,n)=>{const r=n===s-1;return oe(e,t),ae(e,t,r),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&r&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function ie(s){let e=0;s.forEach(t=>{t.type==="message-group"?t.messages.forEach(n=>{n.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),s.lastSelectionIndex=e-1}const le=s=>{const t=s.slice().reduce(re(s.length),[]);return ie(t),t};class ce extends O{constructor(){super(...arguments),this.onKeyDown=e=>{e.keyCode===c.Keys.enter&&this.props.onActionExecute(this.props.item,e)}}render(){return o.createElement("span",{role:"button",className:this.getClassNames(),onClick:e=>this.props.onActionExecute(this.props.item,e),ref:e=>this.elementToFocus=e,onKeyDown:this.onKeyDown,tabIndex:0},this.props.item.title||this.props.item.value)}getClassNames(){return c.classNames("k-quick-reply",{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup},{"k-selected":this.props.selected},{"k-focus":this.props.selected})}}class W extends o.Component{constructor(){super(...arguments),this.state={selectedItemIndex:null},this.onRequestContainerSelection=()=>this.props.onRequestSelection(this.props.group.selectionIndex),this.onKeyDown=e=>{let t=null,n,r;this.isKeyboardNavigationLeftRight?(n=c.Keys.left,r=c.Keys.right):(n=c.Keys.up,r=c.Keys.down),e.keyCode===n?t=this.navigate(!1):e.keyCode===r&&(t=this.navigate(!0)),t!==null&&(e.preventDefault(),e.stopPropagation())}}static getDerivedStateFromProps(e,t){return!e.selected&&t.selectedItemIndex!==null?{selectedItemIndex:null}:e.selected&&t.selectedItemIndex===null?{selectedItemIndex:0}:null}navigate(e,t=0){let n=null,r=this.state.selectedItemIndex;return e?r===null?n=t:r<this.getLastSelectionIndex()&&(n=r+1):r===null?n=0:r>0&&(n=r-1),n!==null&&this.setState({selectedItemIndex:n}),n}get isKeyboardNavigationLeftRight(){return!0}getLastSelectionIndex(){let e=-1;if(this.props.group.type==="action-group"){const t=this.props.group;e=t.actions?t.actions.length-1:-1}else if(this.props.group.type==="attachment-group"){const t=this.props.group;e=t.attachments?t.attachments.length-1:-1}return e}}class pe extends W{constructor(e){super(e)}render(){const e=this.props.group.actions?this.props.group.actions.length-1:0;return o.createElement("div",{className:this.getClassNames(),onClick:this.onRequestContainerSelection,onKeyDown:this.onKeyDown},this.props.group.actions&&this.props.group.actions.map((t,n)=>o.createElement(ce,{item:t,onActionExecute:this.props.onActionExecute,selected:n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,key:n})))}getClassNames(){return c.classNames("k-quick-replies")}}class H extends O{render(){return o.createElement("div",{className:this.getClassNames(),tabIndex:this.getTabIndexValue(),onClick:this.props.onClick,ref:e=>this.elementToFocus=e},this.props.template?o.createElement(this.props.template,{item:this.props.item}):o.createElement("div",{className:"k-card"},o.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView(),this.getContentView())))}getTabIndexValue(){if(this.props.tabbable!==void 0)return this.props.tabbable?0:-1}getClassNames(){return c.classNames({"k-selected":this.props.selected},{"k-focus":this.props.selected},{"k-first":this.props.isFirstItemInGroup},{"k-last":this.props.isLastItemInGroup})}getTitleView(){return this.props.item.title?o.createElement("h5",{className:"k-card-title"},this.props.item.title):null}getSubtitleView(){return this.props.item.subtitle?o.createElement("h6",{className:"k-card-subtitle"},this.props.item.subtitle):null}getContentView(){return this.props.item.contentType.indexOf("image/")===0?o.createElement("img",{src:this.props.item.content}):this.props.item.content}}class me extends W{render(){const e=this.isCardDeckLayout(this.props),t=o.createElement("div",{className:this.getClassNames(),onKeyDown:e?void 0:this.onKeyDown},this.props.group.attachments.map((n,r)=>o.createElement(H,{item:n,template:this.props.itemTemplate,selected:r===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&r===this.state.selectedItemIndex,isFirstItemInGroup:r===0,isLastItemInGroup:r===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(r),key:r})));return e?o.createElement("div",{className:"k-card-deck-scrollwrap",onKeyDown:this.onKeyDown},this.getLeftScrollBtn(),t,this.getRightScrollBtn()):t}get isKeyboardNavigationLeftRight(){return this.isCardDeckLayout(this.props)}getLastItemIndex(){return this.props.group.attachments.length-1}getLeftScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex&&(e=o.createElement(m.Button,{icon:"chevron-left",onClick:()=>this.onNavigateBtnClick(!1),svgIcon:p.chevronLeftIcon})),e}getRightScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex!==this.getLastItemIndex()&&(e=o.createElement(m.Button,{icon:"chevron-right",onClick:()=>this.onNavigateBtnClick(!0),svgIcon:p.chevronRightIcon})),e}onAttachmentClick(e){this.onRequestContainerSelection(),this.setState({selectedItemIndex:e})}onNavigateBtnClick(e){this.onRequestContainerSelection(),this.navigate(e,1)}isCardDeckLayout(e){return e.group.attachmentLayout!=="list"}getClassNames(){return c.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class j extends o.Component{render(){const e=this.props.item;return o.createElement("div",{className:"k-timestamp"},k.provideIntlService(this).formatDate(e.timestamp,"D"))}}k.registerForIntl(j);const A="newMessage.sendButton",B="newMessage.optionsButton",P="newMessage.messageInput",V="avatar.alt",F="messageList.ariaLabel",q="aIPrompt.noOutputs",b={[A]:"Send",[B]:"Options",[P]:"Message",[V]:"Avatar",[F]:"Message list",[q]:"No output from AI available"};class ue extends o.Component{render(){const{avatarUrl:e,avatarAltText:t,name:n}=this.props.group.author,r=k.provideLocalizationService(this);return o.createElement("div",{className:this.getMsgGroupClassNames()},n&&o.createElement("p",{className:"k-author"},n),e&&o.createElement(h.Avatar,{type:"image"},o.createElement("img",{src:e,alt:t!==void 0?t:r.toLanguageString(V,b[V])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return c.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":U(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,n)=>{const r=[o.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:n===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,isOnlyItemInGroup:e===0,key:n})];return t.attachments&&t.attachments.length===1&&r.push(o.createElement(H,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),r})}}class he extends o.Component{render(){return o.createElement("div",{className:"k-toolbar-box"},o.createElement("div",{className:"k-button-list"},this.props.children))}}class de extends o.Component{constructor(){super(...arguments),this.state={focused:!1},this.inputEl=null,this.onInputKeyDown=e=>{e.keyCode===c.Keys.enter&&this.sendMessage(e)},this.sendMessage=e=>{if(this.props.onMessageSend&&this.inputEl!==null){const t=this.inputEl.value;if(t){const n={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(n,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=k.provideLocalizationService(this),t=o.createElement("input",{type:"text",className:this.getClassNames(),placeholder:this.props.placeholder,onKeyDown:this.onInputKeyDown,onFocus:()=>this.setState({focused:!0}),onBlur:()=>this.setState({focused:!1}),ref:l=>this.inputEl=l,"aria-label":e.toLanguageString(P,b[P])}),n=o.createElement(m.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:p.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(A,b[A]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),r=o.createElement(m.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:p.moreHorizontalIcon,onClick:l=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,l),"aria-label":e.toLanguageString(B,b[B])});return o.createElement(o.Fragment,null,o.createElement("span",{className:"k-message-box k-textbox k-input k-input-md k-rounded-md k-input-solid"},this.props.MessageBox?o.createElement(this.props.MessageBox,{messageInput:t,sendButton:n,toolbarButton:r}):o.createElement(o.Fragment,null,t,o.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&r,n))),this.props.showToolbar&&o.createElement(he,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return c.classNames("k-input-inner",{"k-focus":this.state.focused})}}const ge={name:"@progress/kendo-react-conversational-ui",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},_=class extends o.Component{constructor(s){super(s),this.viewItems=[],this.isDirectionRightToLeft=!1,this.scrollToBottomOnLoadingData=!0,this.onFocus=()=>{clearTimeout(this.timeoutIdForChatLosingFocus)},this.onBlur=()=>{this.timeoutIdForChatLosingFocus=window.setTimeout(()=>{this.setState({selectedItemIndex:null})},0)},this.onSelectionRequested=e=>{this.setState({selectedItemIndex:e})},this.onKeyDown=e=>{let t=null,n=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===c.Keys.up?n===null?t=0:n>0&&(t=n-1):e.keyCode===c.Keys.down&&(n===null?t=0:n<this.viewItems.lastSelectionIndex&&(t=n+1)),t!==null&&(this.setState({selectedItemIndex:t}),e.preventDefault())},this.onMessageSend=(e,t)=>{c.dispatchEvent(this.props.onMessageSend,t,this,{message:e})},this.onActionExecute=(e,t)=>{if(c.dispatchEvent(this.props.onActionExecute,t,this,{action:e}),!t.isDefaultPrevented()){switch(e.type){case"reply":this.onMessageSend({author:this.props.user,text:e.value,timestamp:new Date},t);break;case"call":window.open("tel:"+e.value);break;case"openUrl":window.open(e.value);break}this.newMsgComp.focusInput()}},c.validatePackage(ge),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const s=k.provideLocalizationService(this);return o.createElement("div",{style:{width:this.props.width},onKeyDown:this.onKeyDown,className:this.getClassNames(),ref:e=>this.chatWrapperEl=e},o.createElement("div",{className:"k-message-list k-avatars",onBlur:this.onBlur,onFocus:this.onFocus,role:"log","aria-label":s.toLanguageString(F,b[F]),"aria-live":"polite",onScroll:e=>{this.scrollToBottomOnLoadingData=e.currentTarget.scrollTop===e.currentTarget.scrollHeight-e.currentTarget.clientHeight},ref:e=>this.viewItemsWrapperEl=e},o.createElement("div",{className:"k-message-list-content"},this.renderViewItems())),o.createElement(de,{user:this.props.user,onMessageSend:this.onMessageSend,isDirectionRightToLeft:this.isDirectionRightToLeft,ref:e=>this.newMsgComp=e,placeholder:this.props.placeholder,MessageBox:this.props.messageBox,toolbar:this.props.toolbar,onToolbarActionButtonClick:this.props.onToolbarActionExecute,showToolbar:this.props.showToolbar}))}componentDidMount(){this.setState({isFirstRender:!1},()=>{this.nextTickId=window.setTimeout(()=>this.scrollViewItemsToBottom(),250)})}componentWillUnmount(){clearTimeout(this.nextTickId)}componentDidUpdate(s){s.messages.length!==this.props.messages.length&&this.scrollToBottomOnLoadingData&&this.scrollViewItemsToBottom()}getClassNames(){return c.classNames("k-chat",this.props.className,{"k-rtl":this.isDirectionRightToLeft})}checkIsDirectionRightToLeft(s){return!!(s.dir!==void 0?s.dir==="rtl":this.chatWrapperEl&&getComputedStyle(this.chatWrapperEl).direction==="rtl")}renderViewItems(){const s=this.viewItems.length-1;return this.viewItems.map((e,t)=>{if(e.type==="date-marker")return o.createElement(j,{item:e,key:t});if(e.type==="message-group")return o.createElement(ue,{group:e,itemTemplate:this.props.messageTemplate,attachmentTemplate:this.props.attachmentTemplate,user:this.props.user,selectedItemIndex:this.state.selectedItemIndex,onRequestSelection:this.onSelectionRequested,isLastGroup:t===s,key:t,message:this.props.message||_.defaultProps.message});if(e.type==="attachment-group")return o.createElement(me,{group:e,itemTemplate:this.props.attachmentTemplate,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t});if(e.type==="action-group")return o.createElement(pe,{group:e,onActionExecute:this.onActionExecute,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===s,key:t})})}scrollViewItemsToBottom(){this.viewItemsWrapperEl&&(this.viewItemsWrapperEl.scrollTop=this.viewItemsWrapperEl.scrollHeight-this.viewItemsWrapperEl.clientHeight)}getViewItemsFromMsgs(s){return s.length>0?le(s):[]}};let K=_;K.propTypes={messages:u.arrayOf(u.object),user:u.object,messageTemplate:u.any,attachmentTemplate:u.any,width:u.oneOfType([u.string,u.number]),onMessageSend:u.func,onActionExecute:u.func,dir:u.string,messageBox:u.any};K.defaultProps={messages:[],dateFormat:"g",message:D};class Ie extends o.Component{constructor(){super(...arguments),this.onBtnClick=(e,t)=>{c.dispatchEvent(this.props.onActionExecute,t,this,{action:e})}}render(){return o.createElement("div",{className:"k-card"},o.createElement("img",{className:"k-card-image",src:this.props.imageUrl,style:{maxWidth:this.props.imageMaxWidth}}),o.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView()),o.createElement("div",{className:"k-card-actions k-card-actions-vertical"},this.getActionsView()))}getActionsView(){return this.props.actions.map((e,t)=>o.createElement("span",{className:"k-card-action",key:t},o.createElement(m.Button,{fillMode:"flat",onClick:n=>this.onBtnClick(e,n)},e.title)))}getTitleView(){let e=null;return this.props.title&&(e=o.createElement("h5",{className:"k-card-title"},this.props.title)),e}getSubtitleView(){let e=null;return this.props.subtitle&&(e=o.createElement("h6",{className:"k-card-subtitle"},this.props.subtitle)),e}}const $=s=>{const{activeView:e,toolbarItems:t,activeViewChange:n}=s,r=l=>{n==null||n.call(null,l)};return a.createElement("div",{className:"k-prompt-header"},a.createElement(m.Toolbar,{keyboardNavigation:!1,role:"toolbar",className:"k-toolbar-flat"},t.map(l=>a.isValidElement(l)?l:a.createElement(m.Button,{key:l.name,className:e===l.name?"k-selected":"",size:"medium",themeColor:"primary",fillMode:"flat",rounded:"full",title:l.buttonText,svgIcon:l.buttonIcon,"aria-hidden":"true",onClick:()=>r(l.name)},l.buttonText))))},T=a.forwardRef((s,e)=>{const{children:t}=s;return a.createElement("div",{className:"k-prompt-content",ref:e},a.createElement("div",{className:"k-prompt-view"},t))});T.displayName="KendoReactAIPromptContent";const Y=s=>{const{children:e}=s;return a.createElement("div",{className:"k-prompt-footer"},a.createElement("div",{className:"k-actions k-actions-start k-actions-horizontal k-prompt-actions"},e))},J=a.createContext([{},()=>{}]),L=()=>a.useContext(J),R=s=>{const[e]=L();return e.activeView===s.name?s.children:null},ke=s=>{const[e,t]=a.useState(!0),{children:n,title:r}=s;return a.createElement("div",{className:"k-prompt-expander"},a.createElement(m.Button,{fillMode:"flat",svgIcon:e?p.chevronUpIcon:p.chevronDownIcon,title:r,onClick:()=>t(!e)},r),e&&a.createElement("div",{className:"k-prompt-expander-content"},n))},G={name:"prompt-view",buttonText:"Ask AI",buttonIcon:p.sparklesIcon},fe=s=>{const e="Generate",{promptInput:t=te.TextArea,generateButton:n=m.Button,promptValue:r,promptSuggestions:l}=s,[I,d]=a.useState(r||""),[g]=L(),[y,f]=c.useCustomComponent(n),[w,E]=c.useCustomComponent(t),x=()=>{g.onPromptRequest&&g.onPromptRequest.call(null,I),d("")},v=C=>{d(C)},N=C=>{d(C.target.value)},i={title:"Generate",svgIcon:p.sparklesIcon},S={placeholder:"Ask or generate content with AI ...",rows:2},Z=Object.keys(f).length>0?f:i,ee=Object.keys(E).length>0?E:S;return a.createElement(R,{name:G.name},a.createElement(T,null,a.createElement(w,{value:I,onChange:N,...ee}),l&&l.length>0&&a.createElement(ke,{title:"Prompt Suggestions"},l.map(C=>a.createElement("div",{key:C,className:"k-prompt-suggestion",onClick:()=>v(C)},C)))),a.createElement(Y,null,a.createElement(y,{themeColor:"primary",fillMode:"solid","aria-hidden":"true",rounded:"full",size:"medium",onClick:x,...Z},e)))},z={name:"Output view",buttonText:"Output",buttonIcon:p.commentIcon},Ee=s=>{const[e,t]=a.useState(""),n=a.useRef(null),[r]=L(),{outputs:l,showOutputRating:I,outputCard:d}=s,{header:g,body:y,actions:f}=d||{},w=k.useLocalization(),E=i=>{r.onPromptRequest&&r.onPromptRequest.call(null,i.prompt,{...i,isRetry:!0}),N()},x=i=>{i!=null&&i.responseContent&&navigator.clipboard.writeText(i.responseContent),t(i.id),setTimeout(()=>{t("")},1e3)},v=(i,S)=>{r.onPromptRequest&&r.onPromptRequest.call(null,i.prompt,{...i,ratingType:S,isRetry:!1}),N()},N=()=>{n&&n.current&&n.current.scrollTo({top:0,behavior:"smooth"})};return a.createElement(R,{name:z.name},a.createElement(T,{ref:n},a.createElement("div",{className:"k-card-list"},l&&l.length>0?l.map((i,S)=>a.createElement(h.Card,{key:`${i.id}_${S}`},a.createElement(h.CardHeader,null,g?g(i):a.createElement(a.Fragment,null,i.title&&a.createElement(h.CardTitle,null,i.title),i.subTitle&&a.createElement(h.CardSubtitle,null,i.subTitle))),a.createElement(h.CardBody,null,y?y(i):i.responseContent),a.createElement(h.CardActions,null,f?f(i):a.createElement(a.Fragment,null,a.createElement(m.Button,{size:"medium",themeColor:"primary",fillMode:"flat",rounded:"medium",title:"Copy",svgIcon:e===i.id?p.copyIcon:p.checkIcon,"aria-hidden":"true",onClick:()=>x(i)},"Copy"),a.createElement(m.Button,{size:"medium",themeColor:"base",fillMode:"flat",rounded:"medium",title:"Retry",svgIcon:p.rotateIcon,"aria-hidden":"true",onClick:()=>E(i)},"Retry"),I&&a.createElement(a.Fragment,null,a.createElement("span",{className:"k-spacer"}),a.createElement(m.Button,{size:"medium",themeColor:i.ratingType==="positive"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate up",svgIcon:p.thumbUpOutlineIcon,"aria-hidden":"true",onClick:()=>v(i,"positive")}),a.createElement(m.Button,{size:"medium",themeColor:i.ratingType==="negative"?"primary":"base",fillMode:"flat",rounded:"medium",title:"Rate down",svgIcon:p.thumbDownOutlineIcon,"aria-hidden":"true",onClick:()=>v(i,"negative")})))))):a.createElement(h.Card,null,a.createElement(h.CardBody,null,w.toLanguageString(q,b[q]))))))},Ce=s=>{const{activeView:e,toolbarItems:t,children:n,onActiveViewChange:r,onPromptRequest:l,onCommandExecute:I,style:d,dir:g}=s,y=t||[G,z],[f,w]=a.useState({activeView:e}),E={...f,activeView:e,onActiveViewChange:r,onPromptRequest:l,onCommandExecute:I},x=v=>{w(v)};return a.createElement(J.Provider,{value:[E,x]},a.createElement("div",{className:"k-prompt",style:d,dir:g},a.createElement($,{activeView:E.activeView,toolbarItems:y,activeViewChange:r}),n))},Q={name:"Commands view",buttonIcon:p.moreHorizontalIcon},X=s=>s==null?void 0:s.map(e=>a.createElement(h.PanelBarItem,{title:e.text,key:e.id,svgIcon:e.svgIcon,data:e},e.children&&X(e.children||[]))),ye=s=>{const{commands:e}=s,[t]=L(),n=r=>{var I,d,g;const l=(d=(I=r.target)==null?void 0:I.props)==null?void 0:d.data;(g=l.children)!=null&&g.length||t.onCommandExecute&&t.onCommandExecute.call(null,l)};return a.createElement(R,{name:Q.name},a.createElement(T,null,a.createElement("div",{className:"k-prompt-view"},a.createElement(h.PanelBar,{onSelect:n,selected:""},X(e!=null?e:[])))))};exports.AIPrompt=Ce;exports.AIPromptCommandsView=ye;exports.AIPromptContent=T;exports.AIPromptFooter=Y;exports.AIPromptOutputView=Ee;exports.AIPromptView=fe;exports.AIPromptViewRender=R;exports.Chat=K;exports.ChatMessage=D;exports.HeroCard=Ie;exports.PromptHeader=$;exports.commandsViewDefaults=Q;exports.outputViewDefaults=z;exports.promptViewDefaults=G;