@docshound/chat-react
Version:
React component library for integrating the DocsHound chat widget into React and Next.js applications.
3 lines (2 loc) • 1.48 kB
JavaScript
import{jsx as e}from"react/jsx-runtime";import{useEffect as t,useCallback as o}from"react";const n=({src:o,agentName:n,agentAvatarUrl:r,accentColor:c,platform:s,position:a,theme:d,triggerLabel:i,userAvatarUrl:u,userId:m,userEmail:l,userName:h,firstMessage:p,token:g})=>{const f="__DH_CHAT_SCRIPT__";return t((()=>{if(!customElements.get("docshound-chat")){if(!document.getElementById(f)){let e="";e=o.endsWith("/-/chat.js")?o:o.endsWith("/")?`${o}-/chat.js`:`${o}/-/chat.js`;const t=document.createElement("script");t.src=e,t.id=f,t.type="text/javascript",t.async=!0,t.defer=!0,document.head.appendChild(t)}}}),[]),e("docshound-chat",{"agent-name":n,"agent-avatar-url":r,"accent-color":c,platform:s,position:a,theme:d,"trigger-label":i,"user-id":m,"user-email":l,"user-name":h,"user-avatar-url":u,"first-message":p,token:g})};function r(...e){"development"===process.env.NODE_ENV&&console.warn(...e)}function c(){return{show:o((e=>{const t=document.querySelector("docshound-chat");t&&t.show?t.show(e):r("DocsHound Chat component not mounted or not initialized")}),[]),clear:o((()=>{const e=document.querySelector("docshound-chat");e&&e.clear?e.clear():r("DocsHound Chat component not mounted or not initialized")}),[]),sendQuestion:o((e=>{const t=document.querySelector("docshound-chat");t&&t.sendQuestion?t.sendQuestion(e):r("DocsHound Chat component not mounted or not initialized")}),[])}}export{n as DocsHoundChat,c as useDocsHoundChat};
//# sourceMappingURL=index.esm.js.map