UNPKG

@logaflow/next

Version:

This library was generated with [Nx](https://nx.dev).

2 lines (1 loc) 1.57 kB
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),e=require("react");var g={VITE_CJS_IGNORE_WARNING:"true",BASE_URL:"/",MODE:"production",DEV:!1,PROD:!0,SSR:!1};const{VITE_ENVRIOMENT:w}=g,p="logaflow-webcomponent-js",m=w==="development"?"http://localhost:4001":"https://widget.logaflow.com";function E({projectKey:t,useCustomTrigger:n,userId:o,name:i,email:a,avatar:r,triggerText:c}){const[d,l]=e.useState(!1),u=e.useCallback(()=>{if(document.querySelector("#"+p)){l(!0);return}const s=document.createElement("script");s.crossOrigin="true",s.async=!0,s.type="module",s.src=`${m}/addons/logaflow-widget.es.js?version=3.0.0`,s.onload=function(){l(!0)},document.head.appendChild(s)},[]);return e.useEffect(()=>{t&&u()},[u,t]),d?f.jsx("logaflow-widget",{"project-key":t,"use-custom-trigger":n,avatar:r,email:a,name:i,"user-id":o,"trigger-text":c}):null}function L(){const[t,n]=e.useState(!1),o=e.useCallback(a=>{const{data:r}=a;r.from==="logaflowwidget"&&r.state&&n(r.state.open)},[]),i=e.useCallback(()=>{const a={from:"logaflowlib",action:"open"};window.postMessage(a,window.location.origin)},[]);return e.useEffect(()=>(window.removeEventListener("message",o),window.addEventListener("message",o),()=>{window.removeEventListener("message",o)}),[o]),{isOpen:t,open:i}}function _(){return{setUser:e.useCallback(n=>{window.postMessage({from:"logaflowlib",action:"setuser",payload:{user:n}},window.location.origin)},[])}}exports.LogaflowWidget=E;exports.useLogaflowPopup=L;exports.useLogaflowUser=_;