UNPKG

@progress/kendo-react-conversational-ui

Version:

React Chat component allows the user to participate in chat sessions with users or chat bots. KendoReact Conversational UI components

9 lines (8 loc) 1.63 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./utils.js"),o=s=>s[s.length-1],r=(s,e)=>s&&e&&(e.getDate()!==s.getDate()||e.getMonth()!==s.getMonth()||e.getFullYear()!==s.getFullYear()),u=(s,e)=>{const t=e.timestamp,a=o(s);if(t&&(!a||r(t,a.timestamp))){const n={type:"date-marker",timestamp:t,trackBy:t.getTime()};s.push(n)}},c=(s,e,t)=>{const a=o(s);let n;e.typing&&!t||(a&&a.type==="message-group"&&(n=a.messages),n&&i.isAuthor(e.author,o(n))?n.push(e):s.push({type:"message-group",messages:[e],author:e.author,timestamp:e.timestamp,trackBy:e}))},p=s=>(e,t,a)=>{const n=a===s-1;return u(e,t),c(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 l(s){let e=0;s.forEach(t=>{t.type==="message-group"?t.messages.forEach(a=>{a.selectionIndex=e++}):(t.type==="attachment-group"||t.type==="action-group")&&(t.selectionIndex=e++)}),s.lastSelectionIndex=e-1}const h=s=>{const t=s.slice().reduce(p(s.length),[]);return l(t),t};exports.convertMsgsToViewItems=h;