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