@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
10 lines (9 loc) • 2.92 kB
JavaScript
/**
* @license
*-------------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the package root for more information
*-------------------------------------------------------------------------------------------
*/
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),F=require("../AIPromptContent.js"),j=require("../AIPromptFooter.js"),A=require("@progress/kendo-react-buttons"),d=require("@progress/kendo-react-inputs"),z=require("@progress/kendo-svg-icons"),I=require("@progress/kendo-react-common"),G=require("./AIPromptViewRender.js"),O=require("../AIPromptExpander.js"),M=require("../AIPromptContext.js"),H=require("../../chat/components/SuggestionsGroup.js"),W=require("./constants.js"),D=S=>{const{promptInput:q=d.TextArea,generateButton:C=A.Button,enableSpeechToText:o=!1,promptValue:E,promptSuggestions:m}=S,[r,u]=e.useState(E||""),[s]=M.useAIPromptContext(),[R,h]=I.useCustomComponent(C),[T,f]=I.useCustomComponent(q),w=()=>{s.onPromptRequest&&s.onPromptRequest.call(null,r),u("")},l=e.useRef(null),V=t=>{u(t)};e.useEffect(()=>{var t,n;(n=(t=l.current)==null?void 0:t.element)!=null&&n.current&&requestAnimationFrame(()=>{var c,i;if((i=(c=l.current)==null?void 0:c.element)!=null&&i.current){const a=l.current.element.current;a.style.height="auto",a.style.height=`${a.scrollHeight}px`}})},[r]);const k=t=>{u(t.target.value)},b={title:"Generate",children:"Generate",svgIcon:z.sparklesIcon},y={placeholder:"Ask or generate content with AI ...",rows:2},x=Object.keys(h).length>0?h:b,v=Object.keys(f).length>0?f:y,P=t=>{const{isFinal:n,alternatives:c}=t;if(n&&c.length>0){const i=c[0].transcript,a=(()=>{const p=r,B=p&&!p.endsWith(" ")&&!p.endsWith(`
`);return p+(B?" ":"")+i})();u(a)}};let g;return o&&(typeof o=="object"?g={...o,onResult:o.onResult||P}:g={onResult:P}),e.createElement(G.AIPromptViewRender,{name:W.promptViewDefaults.name},e.createElement(F.AIPromptContent,{streaming:s.streaming,onCancel:s.onCancel},e.createElement(T,{ref:l,value:r,flow:"vertical",textareaStyle:{maxHeight:"110px"},autoSize:!0,suffix:o?e.createElement(e.Fragment,null,e.createElement(d.InputSeparator,{orientation:"horizontal"}),e.createElement(d.InputSuffix,{orientation:"horizontal"},e.createElement(A.SpeechToTextButton,{fillMode:"flat",...g}))):void 0,onChange:k,...v}),m&&m.length>0&&e.createElement(O.AIPromptExpander,{title:"Prompt Suggestions"},e.createElement(H.SuggestionGroup,{suggestionsView:s.suggestionsView,suggestions:m.map((t,n)=>({id:n,text:t,description:t})),onSuggestionClick:t=>{V(t.text)}}))),e.createElement(j.AIPromptFooter,null,e.createElement(R,{themeColor:"primary",fillMode:"solid",rounded:"full",size:"medium",onClick:w,disabled:!r.trim(),...x},x.children)))};exports.AIPromptView=D;