@progress/kendo-react-conversational-ui 7.1.0-develop.8 → 7.1.0

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.
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 N=require("react"),a=require("@progress/kendo-react-common"),l=require("@progress/kendo-react-intl"),r=require("prop-types"),u=require("@progress/kendo-svg-icons"),p=require("@progress/kendo-react-buttons"),T=require("@progress/kendo-react-layout");function L(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const s=L(N);class E extends s.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class h extends E{render(){return s.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?s.createElement("div",{className:"k-chat-bubble"},s.createElement("div",{className:"k-typing-indicator"},s.createElement("span",null),s.createElement("span",null),s.createElement("span",null))):this.props.template?s.createElement(this.props.template,{item:this.props.item}):this.props.item.text?s.createElement("div",{className:"k-chat-bubble"},this.props.item.text):null}getTimestampView(){let e=null;return this.props.item.timestamp&&(e=s.createElement("time",{className:"k-message-time","aria-hidden":!this.props.selected},l.provideIntlService(this).formatDate(this.props.item.timestamp,this.props.dateFormat))),e}getStatusView(){let e=null;return this.props.item.status&&(e=s.createElement("span",{className:"k-message-status"},this.props.item.status)),e}getClassNames(){return a.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")}}h.defaultProps={dateFormat:"g",tabIndex:-1};l.registerForIntl(h);const b=(i,e)=>i&&e.author&&i.id===e.author.id,d=i=>i[i.length-1],D=(i,e)=>i&&e&&(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()),M=(i,e)=>{const t=e.timestamp,n=d(i);if(t&&(!n||D(t,n.timestamp))){const o={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(o)}},B=(i,e,t)=>{const n=d(i);let o;e.typing&&!t||(n&&n.type==="message-group"&&(o=n.messages),o&&b(e.author,d(o))?o.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},R=i=>(e,t,n)=>{const o=n===i-1;return M(e,t),B(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 F(i){let e=0;i.forEach(t=>{t.type==="message-group"?t.messages.forEach(n=>{n.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),i.lastSelectionIndex=e-1}const K=i=>{const t=i.slice().reduce(R(i.length),[]);return F(t),t};class V extends E{constructor(){super(...arguments),this.onKeyDown=e=>{e.keyCode===a.Keys.enter&&this.props.onActionExecute(this.props.item,e)}}render(){return s.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 a.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 x extends s.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=a.Keys.left,o=a.Keys.right):(n=a.Keys.up,o=a.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 G extends x{constructor(e){super(e)}render(){const e=this.props.group.actions?this.props.group.actions.length-1:0;return s.createElement("div",{className:this.getClassNames(),onClick:this.onRequestContainerSelection,onKeyDown:this.onKeyDown},this.props.group.actions&&this.props.group.actions.map((t,n)=>s.createElement(V,{item:t,onActionExecute:this.props.onActionExecute,selected:n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===e,key:n})))}getClassNames(){return a.classNames("k-quick-replies")}}class w extends E{render(){return s.createElement("div",{className:this.getClassNames(),tabIndex:this.getTabIndexValue(),onClick:this.props.onClick,ref:e=>this.elementToFocus=e},this.props.template?s.createElement(this.props.template,{item:this.props.item}):s.createElement("div",{className:"k-card"},s.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 a.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?s.createElement("h5",{className:"k-card-title"},this.props.item.title):null}getSubtitleView(){return this.props.item.subtitle?s.createElement("h6",{className:"k-card-subtitle"},this.props.item.subtitle):null}getContentView(){return this.props.item.contentType.indexOf("image/")===0?s.createElement("img",{src:this.props.item.content}):this.props.item.content}}class A extends x{render(){const e=this.isCardDeckLayout(this.props),t=s.createElement("div",{className:this.getClassNames(),onKeyDown:e?void 0:this.onKeyDown},this.props.group.attachments.map((n,o)=>s.createElement(w,{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?s.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=s.createElement(p.Button,{icon:"chevron-left",onClick:()=>this.onNavigateBtnClick(!1),svgIcon:u.chevronLeftIcon})),e}getRightScrollBtn(){let e=null;return this.isCardDeckLayout(this.props)&&this.state.selectedItemIndex!==this.getLastItemIndex()&&(e=s.createElement(p.Button,{icon:"chevron-right",onClick:()=>this.onNavigateBtnClick(!0),svgIcon:u.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 a.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class S extends s.Component{render(){const e=this.props.item;return s.createElement("div",{className:"k-timestamp"},l.provideIntlService(this).formatDate(e.timestamp,"D"))}}l.registerForIntl(S);const g="newMessage.sendButton",I="newMessage.optionsButton",f="newMessage.messageInput",k="avatar.alt",y="messageList.ariaLabel",c={[g]:"Send",[I]:"Options",[f]:"Message",[k]:"Avatar",[y]:"Message list"};class q extends s.Component{render(){const{avatarUrl:e,avatarAltText:t,name:n}=this.props.group.author,o=l.provideLocalizationService(this);return s.createElement("div",{className:this.getMsgGroupClassNames()},n&&s.createElement("p",{className:"k-author"},n),e&&s.createElement(T.Avatar,{type:"image"},s.createElement("img",{src:e,alt:t!==void 0?t:o.toLanguageString(k,c[k])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return a.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":b(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=[s.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(s.createElement(w,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),o})}}class O extends s.Component{render(){return s.createElement("div",{className:"k-toolbar-box"},s.createElement("div",{className:"k-button-list"},this.props.children))}}class P extends s.Component{constructor(){super(...arguments),this.state={focused:!1},this.inputEl=null,this.onInputKeyDown=e=>{e.keyCode===a.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=l.provideLocalizationService(this),t=s.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:m=>this.inputEl=m,"aria-label":e.toLanguageString(f,c[f])}),n=s.createElement(p.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:u.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(g,c[g]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),o=s.createElement(p.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:u.moreHorizontalIcon,onClick:m=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,m),"aria-label":e.toLanguageString(I,c[I])});return s.createElement(s.Fragment,null,s.createElement("span",{className:"k-message-box k-textbox k-input k-input-md k-rounded-md k-input-solid"},this.props.MessageBox?s.createElement(this.props.MessageBox,{messageInput:t,sendButton:n,toolbarButton:o}):s.createElement(s.Fragment,null,t,s.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&o,n))),this.props.showToolbar&&s.createElement(O,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return a.classNames("k-input-inner",{"k-focus":this.state.focused})}}const W={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/"},v=class extends s.Component{constructor(i){super(i),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===a.Keys.up?n===null?t=0:n>0&&(t=n-1):e.keyCode===a.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)=>{a.dispatchEvent(this.props.onMessageSend,t,this,{message:e})},this.onActionExecute=(e,t)=>{if(a.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()}},a.validatePackage(W),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const i=l.provideLocalizationService(this);return s.createElement("div",{style:{width:this.props.width},onKeyDown:this.onKeyDown,className:this.getClassNames(),ref:e=>this.chatWrapperEl=e},s.createElement("div",{className:"k-message-list k-avatars",onBlur:this.onBlur,onFocus:this.onFocus,role:"log","aria-label":i.toLanguageString(y,c[y]),"aria-live":"polite",onScroll:e=>{this.scrollToBottomOnLoadingData=e.currentTarget.scrollTop===e.currentTarget.scrollHeight-e.currentTarget.clientHeight},ref:e=>this.viewItemsWrapperEl=e},s.createElement("div",{className:"k-message-list-content"},this.renderViewItems())),s.createElement(P,{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(i){i.messages.length!==this.props.messages.length&&this.scrollToBottomOnLoadingData&&this.scrollViewItemsToBottom()}getClassNames(){return a.classNames("k-chat",this.props.className,{"k-rtl":this.isDirectionRightToLeft})}checkIsDirectionRightToLeft(i){return!!(i.dir!==void 0?i.dir==="rtl":this.chatWrapperEl&&getComputedStyle(this.chatWrapperEl).direction==="rtl")}renderViewItems(){const i=this.viewItems.length-1;return this.viewItems.map((e,t)=>{if(e.type==="date-marker")return s.createElement(S,{item:e,key:t});if(e.type==="message-group")return s.createElement(q,{group:e,itemTemplate:this.props.messageTemplate,attachmentTemplate:this.props.attachmentTemplate,user:this.props.user,selectedItemIndex:this.state.selectedItemIndex,onRequestSelection:this.onSelectionRequested,isLastGroup:t===i,key:t,message:this.props.message||v.defaultProps.message});if(e.type==="attachment-group")return s.createElement(A,{group:e,itemTemplate:this.props.attachmentTemplate,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===i,key:t});if(e.type==="action-group")return s.createElement(G,{group:e,onActionExecute:this.onActionExecute,onRequestSelection:this.onSelectionRequested,selected:e.selectionIndex===this.state.selectedItemIndex,isLastGroup:t===i,key:t})})}scrollViewItemsToBottom(){this.viewItemsWrapperEl&&(this.viewItemsWrapperEl.scrollTop=this.viewItemsWrapperEl.scrollHeight-this.viewItemsWrapperEl.clientHeight)}getViewItemsFromMsgs(i){return i.length>0?K(i):[]}};let C=v;C.propTypes={messages:r.arrayOf(r.object),user:r.object,messageTemplate:r.any,attachmentTemplate:r.any,width:r.oneOfType([r.string,r.number]),onMessageSend:r.func,onActionExecute:r.func,dir:r.string,messageBox:r.any};C.defaultProps={messages:[],dateFormat:"g",message:h};class U extends s.Component{constructor(){super(...arguments),this.onBtnClick=(e,t)=>{a.dispatchEvent(this.props.onActionExecute,t,this,{action:e})}}render(){return s.createElement("div",{className:"k-card"},s.createElement("img",{className:"k-card-image",src:this.props.imageUrl,style:{maxWidth:this.props.imageMaxWidth}}),s.createElement("div",{className:"k-card-body"},this.getTitleView(),this.getSubtitleView()),s.createElement("div",{className:"k-card-actions k-card-actions-vertical"},this.getActionsView()))}getActionsView(){return this.props.actions.map((e,t)=>s.createElement("span",{className:"k-card-action",key:t},s.createElement(p.Button,{fillMode:"flat",onClick:n=>this.onBtnClick(e,n)},e.title)))}getTitleView(){let e=null;return this.props.title&&(e=s.createElement("h5",{className:"k-card-title"},this.props.title)),e}getSubtitleView(){let e=null;return this.props.subtitle&&(e=s.createElement("h6",{className:"k-card-subtitle"},this.props.subtitle)),e}}exports.Chat=C;exports.ChatMessage=h;exports.HeroCard=U;
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;