@progress/kendo-react-conversational-ui 7.0.0-develop.8 → 7.0.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.
@@ -2,4 +2,4 @@
2
2
  * Copyright © 2023 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(o,c){typeof exports=="object"&&typeof module<"u"?c(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")):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"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.KendoReactConversationalUi={},o.React,o.KendoReactCommon,o.KendoReactIntl,o.PropTypes,o.KendoSvgIcons,o.KendoReactButtons,o.KendoReactLayout))})(this,function(o,c,a,p,D,m,u,M){"use strict";function v(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const s=v(c),l=v(D);class g extends s.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class d extends g{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},p.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")}}d.defaultProps={dateFormat:"g",tabIndex:-1},p.registerForIntl(d);const S=(i,e)=>i&&e.author&&i.id===e.author.id,I=i=>i[i.length-1],B=(i,e)=>i&&e&&(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()),K=(i,e)=>{const t=e.timestamp,r=I(i);if(t&&(!r||B(t,r.timestamp))){const n={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(n)}},F=(i,e,t)=>{const r=I(i);let n;e.typing&&!t||(r&&r.type==="message-group"&&(n=r.messages),n&&S(e.author,I(n))?n.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},V=i=>(e,t,r)=>{const n=r===i-1;return K(e,t),F(e,t,n),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&n&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function G(i){let e=0;i.forEach(t=>{t.type==="message-group"?t.messages.forEach(r=>{r.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),i.lastSelectionIndex=e-1}const A=i=>{const t=i.slice().reduce(V(i.length),[]);return G(t),t};class q extends g{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 N 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,r,n;this.isKeyboardNavigationLeftRight?(r=a.Keys.left,n=a.Keys.right):(r=a.Keys.up,n=a.Keys.down),e.keyCode===r?t=this.navigate(!1):e.keyCode===n&&(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 r=null,n=this.state.selectedItemIndex;return e?n===null?r=t:n<this.getLastSelectionIndex()&&(r=n+1):n===null?r=0:n>0&&(r=n-1),r!==null&&this.setState({selectedItemIndex:r}),r}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 O extends N{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,r)=>s.createElement(q,{item:t,onActionExecute:this.props.onActionExecute,selected:r===this.state.selectedItemIndex,isFirstItemInGroup:r===0,isLastItemInGroup:r===e,key:r})))}getClassNames(){return a.classNames("k-quick-replies")}}class T extends g{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 P extends N{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((r,n)=>s.createElement(T,{item:r,template:this.props.itemTemplate,selected:n===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(n),key:n})));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(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=s.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 a.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class C extends s.Component{render(){const e=this.props.item;return s.createElement("div",{className:"k-timestamp"},p.provideIntlService(this).formatDate(e.timestamp,"D"))}}p.registerForIntl(C);const f="newMessage.sendButton",y="newMessage.optionsButton",k="newMessage.messageInput",E="avatar.alt",x="messageList.ariaLabel",h={[f]:"Send",[y]:"Options",[k]:"Message",[E]:"Avatar",[x]:"Message list"};class R extends s.Component{render(){const{avatarUrl:e,avatarAltText:t,name:r}=this.props.group.author,n=p.provideLocalizationService(this);return s.createElement("div",{className:this.getMsgGroupClassNames()},r&&s.createElement("p",{className:"k-author"},r),e&&s.createElement(M.Avatar,{type:"image"},s.createElement("img",{src:e,alt:t!==void 0?t:n.toLanguageString(E,h[E])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return a.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":S(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,r)=>{const n=[s.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:r===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:r===0,isLastItemInGroup:r===e,isOnlyItemInGroup:e===0,key:r})];return t.attachments&&t.attachments.length===1&&n.push(s.createElement(T,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${r}`})),n})}}class U extends s.Component{render(){return s.createElement("div",{className:"k-toolbar-box"},s.createElement("div",{className:"k-button-list"},this.props.children))}}class W 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 r={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(r,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=p.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:w=>this.inputEl=w,"aria-label":e.toLanguageString(k,h[k])}),r=s.createElement(u.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:m.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(f,h[f]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),n=s.createElement(u.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:m.moreHorizontalIcon,onClick:w=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,w),"aria-label":e.toLanguageString(y,h[y])});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:r,toolbarButton:n}):s.createElement(s.Fragment,null,t,s.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&n,r))),this.props.showToolbar&&s.createElement(U,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return a.classNames("k-input-inner",{"k-focus":this.state.focused})}}const z={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/"},L=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,r=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===a.Keys.up?r===null?t=0:r>0&&(t=r-1):e.keyCode===a.Keys.down&&(r===null?t=0:r<this.viewItems.lastSelectionIndex&&(t=r+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(z),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const i=p.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(x,h[x]),"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(W,{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(C,{item:e,key:t});if(e.type==="message-group")return s.createElement(R,{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||L.defaultProps.message});if(e.type==="attachment-group")return s.createElement(P,{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(O,{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?A(i):[]}};let b=L;b.propTypes={messages:l.arrayOf(l.object),user:l.object,messageTemplate:l.any,attachmentTemplate:l.any,width:l.oneOfType([l.string,l.number]),onMessageSend:l.func,onActionExecute:l.func,dir:l.string,messageBox:l.any},b.defaultProps={messages:[],dateFormat:"g",message:d};class j 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(u.Button,{fillMode:"flat",onClick:r=>this.onBtnClick(e,r)},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}}o.Chat=b,o.ChatMessage=d,o.HeroCard=j,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
5
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?c(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")):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"],c):(o=typeof globalThis<"u"?globalThis:o||self,c(o.KendoReactConversationalUi={},o.React,o.KendoReactCommon,o.KendoReactIntl,o.PropTypes,o.KendoSvgIcons,o.KendoReactButtons,o.KendoReactLayout))})(this,function(o,c,a,p,D,m,u,M){"use strict";"use client";function v(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const s=v(c),l=v(D);class g extends s.Component{componentDidUpdate(e){!e.selected&&this.props.selected&&this.elementToFocus.focus()}}class d extends g{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},p.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")}}d.defaultProps={dateFormat:"g",tabIndex:-1},p.registerForIntl(d);const S=(i,e)=>i&&e.author&&i.id===e.author.id,I=i=>i[i.length-1],B=(i,e)=>i&&e&&(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()),K=(i,e)=>{const t=e.timestamp,r=I(i);if(t&&(!r||B(t,r.timestamp))){const n={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(n)}},F=(i,e,t)=>{const r=I(i);let n;e.typing&&!t||(r&&r.type==="message-group"&&(n=r.messages),n&&S(e.author,I(n))?n.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},V=i=>(e,t,r)=>{const n=r===i-1;return K(e,t),F(e,t,n),t.attachments&&t.attachments.length>1&&e.push({type:"attachment-group",attachments:t.attachments,attachmentLayout:t.attachmentLayout,timestamp:t.timestamp,trackBy:t}),t.suggestedActions&&n&&e.push({type:"action-group",actions:t.suggestedActions,timestamp:t.timestamp,trackBy:t}),e};function G(i){let e=0;i.forEach(t=>{t.type==="message-group"?t.messages.forEach(r=>{r.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),i.lastSelectionIndex=e-1}const A=i=>{const t=i.slice().reduce(V(i.length),[]);return G(t),t};class q extends g{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 N 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,r,n;this.isKeyboardNavigationLeftRight?(r=a.Keys.left,n=a.Keys.right):(r=a.Keys.up,n=a.Keys.down),e.keyCode===r?t=this.navigate(!1):e.keyCode===n&&(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 r=null,n=this.state.selectedItemIndex;return e?n===null?r=t:n<this.getLastSelectionIndex()&&(r=n+1):n===null?r=0:n>0&&(r=n-1),r!==null&&this.setState({selectedItemIndex:r}),r}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 O extends N{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,r)=>s.createElement(q,{item:t,onActionExecute:this.props.onActionExecute,selected:r===this.state.selectedItemIndex,isFirstItemInGroup:r===0,isLastItemInGroup:r===e,key:r})))}getClassNames(){return a.classNames("k-quick-replies")}}class T extends g{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 P extends N{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((r,n)=>s.createElement(T,{item:r,template:this.props.itemTemplate,selected:n===this.state.selectedItemIndex,tabbable:this.props.isLastGroup&&n===this.state.selectedItemIndex,isFirstItemInGroup:n===0,isLastItemInGroup:n===this.getLastItemIndex(),onClick:()=>this.onAttachmentClick(n),key:n})));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(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=s.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 a.classNames({"k-card-list":this.props.group.attachmentLayout,"k-card-deck":this.isCardDeckLayout(this.props)})}}class C extends s.Component{render(){const e=this.props.item;return s.createElement("div",{className:"k-timestamp"},p.provideIntlService(this).formatDate(e.timestamp,"D"))}}p.registerForIntl(C);const f="newMessage.sendButton",y="newMessage.optionsButton",k="newMessage.messageInput",E="avatar.alt",x="messageList.ariaLabel",h={[f]:"Send",[y]:"Options",[k]:"Message",[E]:"Avatar",[x]:"Message list"};class R extends s.Component{render(){const{avatarUrl:e,avatarAltText:t,name:r}=this.props.group.author,n=p.provideLocalizationService(this);return s.createElement("div",{className:this.getMsgGroupClassNames()},r&&s.createElement("p",{className:"k-author"},r),e&&s.createElement(M.Avatar,{type:"image"},s.createElement("img",{src:e,alt:t!==void 0?t:n.toLanguageString(E,h[E])})),this.getGroupMessagesView())}getMsgGroupClassNames(){return a.classNames("k-message-group",{"k-no-avatar":!this.props.group.author.avatarUrl,"k-alt":S(this.props.user,this.props.group.messages[0])})}getGroupMessagesView(){const e=this.props.group.messages.length-1;return this.props.group.messages.map((t,r)=>{const n=[s.createElement(this.props.message,{item:t,template:this.props.itemTemplate,selected:t.selectionIndex===this.props.selectedItemIndex,onRequestSelection:this.props.onRequestSelection,tabIndex:r===e&&this.props.isLastGroup?0:-1,isFirstItemInGroup:r===0,isLastItemInGroup:r===e,isOnlyItemInGroup:e===0,key:r})];return t.attachments&&t.attachments.length===1&&n.push(s.createElement(T,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${r}`})),n})}}class U extends s.Component{render(){return s.createElement("div",{className:"k-toolbar-box"},s.createElement("div",{className:"k-button-list"},this.props.children))}}class W 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 r={author:this.props.user,text:t,timestamp:new Date};this.props.onMessageSend(r,e)}}this.inputEl!==null&&(this.inputEl.value=null)}}render(){const e=p.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:w=>this.inputEl=w,"aria-label":e.toLanguageString(k,h[k])}),r=s.createElement(u.Button,{fillMode:"flat",themeColor:"base",className:"k-chat-send",icon:"paper-plane",svgIcon:m.paperPlaneIcon,onClick:this.sendMessage,"aria-label":e.toLanguageString(f,h[f]),dir:this.props.isDirectionRightToLeft?"rtl":void 0}),n=s.createElement(u.Button,{fillMode:"flat",themeColor:"base",rounded:null,className:"k-button-toggle",icon:"more-horizontal",svgIcon:m.moreHorizontalIcon,onClick:w=>this.props.onToolbarActionButtonClick(!this.props.showToolbar,w),"aria-label":e.toLanguageString(y,h[y])});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:r,toolbarButton:n}):s.createElement(s.Fragment,null,t,s.createElement("span",{className:"k-input-suffix"},this.props.toolbar&&n,r))),this.props.showToolbar&&s.createElement(U,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return a.classNames("k-input-inner",{"k-focus":this.state.focused})}}const z={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/"},L=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,r=this.state.selectedItemIndex!==null?this.state.selectedItemIndex:this.viewItems.lastSelectionIndex;e.keyCode===a.Keys.up?r===null?t=0:r>0&&(t=r-1):e.keyCode===a.Keys.down&&(r===null?t=0:r<this.viewItems.lastSelectionIndex&&(t=r+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(z),this.state={selectedItemIndex:null,isFirstRender:!0}}render(){this.viewItems=this.getViewItemsFromMsgs(this.props.messages),this.isDirectionRightToLeft=this.checkIsDirectionRightToLeft(this.props);const i=p.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(x,h[x]),"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(W,{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(C,{item:e,key:t});if(e.type==="message-group")return s.createElement(R,{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||L.defaultProps.message});if(e.type==="attachment-group")return s.createElement(P,{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(O,{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?A(i):[]}};let b=L;b.propTypes={messages:l.arrayOf(l.object),user:l.object,messageTemplate:l.any,attachmentTemplate:l.any,width:l.oneOfType([l.string,l.number]),onMessageSend:l.func,onActionExecute:l.func,dir:l.string,messageBox:l.any},b.defaultProps={messages:[],dateFormat:"g",message:d};class j 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(u.Button,{fillMode:"flat",onClick:r=>this.onBtnClick(e,r)},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}}o.Chat=b,o.ChatMessage=d,o.HeroCard=j,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/index.js CHANGED
@@ -2,4 +2,4 @@
2
2
  * Copyright © 2023 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 strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),a=require("@progress/kendo-react-common"),l=require("@progress/kendo-react-intl"),L=require("prop-types"),u=require("@progress/kendo-svg-icons"),p=require("@progress/kendo-react-buttons"),D=require("@progress/kendo-react-layout");function b(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=b(T),r=b(L);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 x=(i,e)=>i&&e.author&&i.id===e.author.id,d=i=>i[i.length-1],M=(i,e)=>i&&e&&(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()),B=(i,e)=>{const t=e.timestamp,n=d(i);if(t&&(!n||M(t,n.timestamp))){const o={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(o)}},R=(i,e,t)=>{const n=d(i);let o;e.typing&&!t||(n&&n.type==="message-group"&&(o=n.messages),o&&x(e.author,d(o))?o.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},F=i=>(e,t,n)=>{const o=n===i-1;return B(e,t),R(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 K(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 V=i=>{const t=i.slice().reduce(F(i.length),[]);return K(t),t};class G 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 w 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 A extends w{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(G,{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 S 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 q extends w{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(S,{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 v 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(v);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 O 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(D.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":x(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(S,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),o})}}class P extends s.Component{render(){return s.createElement("div",{className:"k-toolbar-box"},s.createElement("div",{className:"k-button-list"},this.props.children))}}class W 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(P,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return a.classNames("k-input-inner",{"k-focus":this.state.focused})}}const U={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/"},N=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(U),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(W,{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(v,{item:e,key:t});if(e.type==="message-group")return s.createElement(O,{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||N.defaultProps.message});if(e.type==="attachment-group")return s.createElement(q,{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(A,{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?V(i):[]}};let C=N;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 z 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=z;
5
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("react"),a=require("@progress/kendo-react-common"),l=require("@progress/kendo-react-intl"),L=require("prop-types"),u=require("@progress/kendo-svg-icons"),p=require("@progress/kendo-react-buttons"),D=require("@progress/kendo-react-layout");function b(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=b(T),r=b(L);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 x=(i,e)=>i&&e.author&&i.id===e.author.id,d=i=>i[i.length-1],M=(i,e)=>i&&e&&(e.getDate()!==i.getDate()||e.getMonth()!==i.getMonth()||e.getFullYear()!==i.getFullYear()),B=(i,e)=>{const t=e.timestamp,n=d(i);if(t&&(!n||M(t,n.timestamp))){const o={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(o)}},R=(i,e,t)=>{const n=d(i);let o;e.typing&&!t||(n&&n.type==="message-group"&&(o=n.messages),o&&x(e.author,d(o))?o.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},F=i=>(e,t,n)=>{const o=n===i-1;return B(e,t),R(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 K(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 V=i=>{const t=i.slice().reduce(F(i.length),[]);return K(t),t};class G 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 w 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 A extends w{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(G,{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 S 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 q extends w{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(S,{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 v 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(v);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 O 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(D.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":x(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(S,{item:t.attachments[0],template:this.props.attachmentTemplate,selected:!1,key:`att-${n}`})),o})}}class P extends s.Component{render(){return s.createElement("div",{className:"k-toolbar-box"},s.createElement("div",{className:"k-button-list"},this.props.children))}}class W 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(P,null,this.props.toolbar))}focusInput(){this.inputEl!==null&&this.inputEl.focus()}getClassNames(){return a.classNames("k-input-inner",{"k-focus":this.state.focused})}}const U={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/"},N=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(U),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(W,{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(v,{item:e,key:t});if(e.type==="message-group")return s.createElement(O,{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||N.defaultProps.message});if(e.type==="attachment-group")return s.createElement(q,{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(A,{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?V(i):[]}};let C=N;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 z 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=z;
package/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  * Copyright © 2023 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";
5
6
  import * as s from "react";
6
7
  import { classNames as l, Keys as r, dispatchEvent as m, validatePackage as D } from "@progress/kendo-react-common";
7
8
  import { provideIntlService as C, registerForIntl as w, provideLocalizationService as y } from "@progress/kendo-react-intl";
@@ -445,7 +446,7 @@ const _ = {
445
446
  name: "@progress/kendo-react-conversational-ui",
446
447
  productName: "KendoReact",
447
448
  productCodes: ["KENDOUIREACT", "KENDOUICOMPLETE"],
448
- publishDate: 1701260588,
449
+ publishDate: 1702305171,
449
450
  version: "",
450
451
  licensingDocsUrl: "https://www.telerik.com/kendo-react-ui/components/my-license/"
451
452
  }, N = class extends s.Component {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@progress/kendo-react-conversational-ui",
3
- "version": "7.0.0-develop.8",
3
+ "version": "7.0.0",
4
4
  "description": "React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components",
5
5
  "author": "Progress",
6
6
  "license": "SEE LICENSE IN LICENSE.md",
7
7
  "homepage": "https://www.telerik.com/kendo-react-ui",
8
8
  "main": "./index.js",
9
+ "module": "./index.mjs",
9
10
  "types": "./index.d.ts",
10
11
  "exports": {
11
12
  ".": {
@@ -16,9 +17,9 @@
16
17
  "sideEffects": false,
17
18
  "peerDependencies": {
18
19
  "@progress/kendo-licensing": "^1.3.0",
19
- "@progress/kendo-react-buttons": "7.0.0-develop.8",
20
- "@progress/kendo-react-common": "7.0.0-develop.8",
21
- "@progress/kendo-react-intl": "7.0.0-develop.8",
20
+ "@progress/kendo-react-buttons": "7.0.0",
21
+ "@progress/kendo-react-common": "7.0.0",
22
+ "@progress/kendo-react-intl": "7.0.0",
22
23
  "@progress/kendo-svg-icons": "^2.0.0",
23
24
  "react": "^16.8.2 || ^17.0.0 || ^18.0.0",
24
25
  "react-dom": "^16.8.2 || ^17.0.0 || ^18.0.0"