@progress/kendo-react-conversational-ui 7.0.3-develop.9 → 7.1.0-develop.1
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 © 2024 Progress Software Corporation. All rights reserved.
|
|
3
3
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
4
4
|
*-------------------------------------------------------------------------------------------*/
|
|
5
|
-
(function(o,p){typeof exports=="object"&&typeof module<"u"?p(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"],p):(o=typeof globalThis<"u"?globalThis:o||self,p(o.KendoReactConversationalUi={},o.React,o.KendoReactCommon,o.KendoReactIntl,o.PropTypes,o.KendoSvgIcons,o.KendoReactButtons,o.KendoReactLayout))})(this,function(o,p,a,c,l,m,u,T){"use strict";"use client";function D(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=D(p);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},c.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},c.registerForIntl(d);const v=(i,e)=>i&&e.author&&i.id===e.author.id,I=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,r=I(i);if(t&&(!r||M(t,r.timestamp))){const n={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(n)}},K=(i,e,t)=>{const r=I(i);let n;e.typing&&!t||(r&&r.type==="message-group"&&(n=r.messages),n&&v(e.author,I(n))?n.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},F=i=>(e,t,r)=>{const n=r===i-1;return B(e,t),K(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 V(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 G=i=>{const t=i.slice().reduce(F(i.length),[]);return V(t),t};class A 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 S 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 q extends S{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(A,{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 N 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 O extends S{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(N,{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"},c.provideIntlService(this).formatDate(e.timestamp,"D"))}}c.registerForIntl(C);const f="newMessage.sendButton",k="newMessage.optionsButton",y="newMessage.messageInput",E="avatar.alt",x="messageList.ariaLabel",h={[f]:"Send",[k]:"Options",[y]:"Message",[E]:"Avatar",[x]:"Message list"};class R extends s.Component{render(){const{avatarUrl:e,avatarAltText:t,name:r}=this.props.group.author,n=c.provideLocalizationService(this);return s.createElement("div",{className:this.getMsgGroupClassNames()},r&&s.createElement("p",{className:"k-author"},r),e&&s.createElement(T.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":v(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(N,{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=c.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(y,h[y])}),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(k,h[k])});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=c.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(O,{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(q,{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?G(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,p){typeof exports=="object"&&typeof module!="undefined"?p(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"],p):(o=typeof globalThis!="undefined"?globalThis:o||self,p(o.KendoReactConversationalUi={},o.React,o.KendoReactCommon,o.KendoReactIntl,o.PropTypes,o.KendoSvgIcons,o.KendoReactButtons,o.KendoReactLayout))})(this,function(o,p,a,c,l,m,u,T){"use strict";"use client";function D(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=D(p);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},c.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},c.registerForIntl(d);const v=(i,e)=>i&&e.author&&i.id===e.author.id,I=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,r=I(i);if(t&&(!r||M(t,r.timestamp))){const n={type:"date-marker",timestamp:t,trackBy:t.getTime()};i.push(n)}},K=(i,e,t)=>{const r=I(i);let n;e.typing&&!t||(r&&r.type==="message-group"&&(n=r.messages),n&&v(e.author,I(n))?n.push(e):i.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},F=i=>(e,t,r)=>{const n=r===i-1;return B(e,t),K(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 V(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 G=i=>{const t=i.slice().reduce(F(i.length),[]);return V(t),t};class A 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 S 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 q extends S{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(A,{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 N 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 O extends S{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(N,{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"},c.provideIntlService(this).formatDate(e.timestamp,"D"))}}c.registerForIntl(C);const f="newMessage.sendButton",k="newMessage.optionsButton",y="newMessage.messageInput",E="avatar.alt",x="messageList.ariaLabel",h={[f]:"Send",[k]:"Options",[y]:"Message",[E]:"Avatar",[x]:"Message list"};class R extends s.Component{render(){const{avatarUrl:e,avatarAltText:t,name:r}=this.props.group.author,n=c.provideLocalizationService(this);return s.createElement("div",{className:this.getMsgGroupClassNames()},r&&s.createElement("p",{className:"k-author"},r),e&&s.createElement(T.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":v(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(N,{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=c.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(y,h[y])}),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(k,h[k])});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=c.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(O,{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(q,{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?G(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.mjs
CHANGED
|
@@ -446,7 +446,7 @@ const _ = {
|
|
|
446
446
|
name: "@progress/kendo-react-conversational-ui",
|
|
447
447
|
productName: "KendoReact",
|
|
448
448
|
productCodes: ["KENDOUIREACT", "KENDOUICOMPLETE"],
|
|
449
|
-
publishDate:
|
|
449
|
+
publishDate: 1705312925,
|
|
450
450
|
version: "",
|
|
451
451
|
licensingDocsUrl: "https://www.telerik.com/kendo-react-ui/components/my-license/"
|
|
452
452
|
}, N = class extends s.Component {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progress/kendo-react-conversational-ui",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0-develop.1",
|
|
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",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@progress/kendo-licensing": "^1.3.4",
|
|
26
|
-
"@progress/kendo-react-buttons": "7.0
|
|
27
|
-
"@progress/kendo-react-common": "7.0
|
|
28
|
-
"@progress/kendo-react-intl": "7.0
|
|
26
|
+
"@progress/kendo-react-buttons": "7.1.0-develop.1",
|
|
27
|
+
"@progress/kendo-react-common": "7.1.0-develop.1",
|
|
28
|
+
"@progress/kendo-react-intl": "7.1.0-develop.1",
|
|
29
29
|
"@progress/kendo-svg-icons": "^2.1.0",
|
|
30
30
|
"react": "^16.8.2 || ^17.0.0 || ^18.0.0",
|
|
31
31
|
"react-dom": "^16.8.2 || ^17.0.0 || ^18.0.0"
|