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) 3.76 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 t=require("react"),m=require("@progress/kendo-react-layout"),P=require("@progress/kendo-react-buttons"),ie=require("@progress/kendo-react-inputs"),g=require("@progress/kendo-svg-icons"),d=require("@progress/kendo-react-common"),x=require("../package-metadata.js"),me=require("./InlineAIPromptPopup.js"),de=require("./InlineAIPromptInput.js"),pe=require("../ai-prompt/AIPromptContent.js"),ue=b=>{const S=!d.validatePackage(x.packageMetadata,{component:"InlineAIPrompt"}),q=d.getLicenseMessage(x.packageMetadata),{outputs:p=[],outputCard:w,promptInput:O=ie.TextArea,generateButton:R=P.Button,promptPlaceholder:A="Ask or generate content with AI...",promptValue:T,onPromptRequest:B,onCopy:u,onDiscard:C,outputActions:D,onOutputAction:I,enableSpeechToText:N=!1,streaming:s,onPromptCancel:r,show:F=!1,anchor:K,width:c,height:l,onOpen:W,onClose:i,animate:$=!0,appendTo:j,commands:k,onCommandExecute:y,style:z,className:V,popupOptions:_={},...G}=b,[H,E]=t.useState(""),[J,h]=t.useState(!1),[Q,U]=t.useState({left:0,top:0}),f=t.useRef(null),{body:M,actions:v}=w||{},X=[{id:"copy",text:"Copy",svgIcon:g.copyIcon,themeColor:"primary",title:"Copy"},{id:"discard",text:"Discard",svgIcon:g.cancelOutlineIcon,themeColor:"base",title:"Discard"}],Y=D||X,Z=e=>{e.responseContent&&(navigator.clipboard.writeText(e.responseContent),E(e.id),setTimeout(()=>E(""),1e3)),u==null||u(e)},L=e=>{C==null||C(e)},ee=(e,n)=>{switch(e.id){case"copy":Z(n);break;case"discard":L(n);break;default:I==null||I(e,n);break}},te=e=>{if(!f.current)return;const n=f.current.getBoundingClientRect();U({left:n.left,top:n.bottom}),h(!0)},ne=()=>{h(!1)},ae=e=>{h(!1),y&&y(e)},oe=e=>e==null?void 0:e.map(n=>({text:n.text,svgIcon:n.svgIcon,data:n,items:n.children?n.children.map(a=>({text:a.text,data:a})):void 0})),se=t.useCallback(e=>{e.key==="Escape"&&(s&&r?r():!s&&i&&i({target:null}))},[s,r,i]),re={...z,...c&&{width:c},...l&&{height:l}},ce={...c&&{width:c},...l&&{height:l}},le=t.createElement(t.Fragment,null,t.createElement("div",{className:d.classNames("k-prompt",V),style:re,onKeyDown:se,...G},t.createElement(pe.AIPromptContent,{ref:f},p&&p.length>0&&t.createElement("div",{className:"k-card-list"},p.map((e,n)=>t.createElement(m.Card,{key:`${e.id}_${n}`},t.createElement(m.CardBody,null,M?M(e):e.responseContent),t.createElement(m.CardActions,null,v?v(e):t.createElement(t.Fragment,null,Y.map(a=>{var o;return a.spacer?t.createElement("span",{key:a.id,className:"k-spacer"}):t.createElement(P.Button,{key:a.id,size:"medium",themeColor:a.themeColor||"primary",fillMode:"flat",rounded:"medium",title:(o=a.title)!=null?o:a.text,svgIcon:a.id==="copy"&&H===e.id?g.checkIcon:a.svgIcon,onClick:()=>ee(a,e)},a.text)})))))),t.createElement(de.InlineAIPromptInput,{promptValue:T,placeholder:A,onPromptRequest:B,onMenuClick:te,onPromptCancel:r,promptInput:O,generateButton:R,enableSpeechToText:N,streaming:s,commands:k}))),S&&t.createElement(d.WatermarkOverlay,{message:q}));return t.createElement(t.Fragment,null,t.createElement(me.InlineAIPromptPopup,{show:F,anchor:K,onOpen:W,onClose:i,animate:$,appendTo:j,popupOptions:_,style:ce},le),t.createElement(m.ContextMenu,{show:J,offset:Q,onClose:ne,items:oe(k),onSelect:e=>{var a,o;const n=(a=e.item)==null?void 0:a.data;n&&!((o=n.children)!=null&&o.length)&&ae(n)}}))};exports.InlineAIPrompt=ue;