@frigade/react 2.4.19 → 2.4.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,7 +53,7 @@ var Vo=Object.defineProperty,Fr=Object.defineProperties;var vr=Object.getOwnProp
|
|
|
53
53
|
to {
|
|
54
54
|
opacity: 1;
|
|
55
55
|
}
|
|
56
|
-
`;function ir(e){return e instanceof HTMLElement?!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length):!1}function N(s){var d=s,{anchor:e,children:o,className:t,spotlight:n=!1,style:r}=d,a=m(d,["anchor","children","className","spotlight","style"]);let{node:c,rect:u,ref:g}=to(),{node:f,rect:x,ref:h}=to(),ia=rr(a,u),{contentProps:F,otherProps:wr}=ia,Ao=wr,{part:S}=Ao,T=m(Ao,["part"]),{rootProps:v}=ia,[k,E]=useState(F.align),[B,w]=useState(F.side),[O,D]=useState(0),[X,V]=useState(0);if(c!==null){let q=c.getAttribute("data-align"),ce=c.getAttribute("data-side");k!==q&&E(q),B!==ce&&w(ce);}let j=useRef(null);if(useEffect(()=>{let q=document.querySelector(e);q!=null?(h(q),j.current=q):console.debug(`[frigade] Tooltip: No anchor found for query: ${e}`);},[e]),useEffect(()=>{function q(be){if(be.matches(e))return ir(be)?be:null;let ue=be.querySelectorAll(e);return ue.length>0&&ir(ue[0])?ue[0]:null}let ce=new MutationObserver(be=>{for(let ue of be)if(ue.type==="childList"){for(let ke of ue.addedNodes){if(ke.nodeType!==Node.ELEMENT_NODE)continue;let me=q(ke);if(me!=null){h(me),j.current=me,console.debug("[frigade] Tooltip: MutationObserver added anchor: ",me);break}}for(let ke of ue.removedNodes){if(ke.nodeType!==Node.ELEMENT_NODE)continue;let me=q(ke);if(me!=null){h(null),j.current=null,console.debug("[frigade] Tooltip: MutationObserver removed anchor: ",me);break}}}});return ce.observe(document.querySelector("body"),{childList:!0,subtree:!0}),()=>ce.disconnect()},[]),useEffect(()=>{let{scrollX:q,scrollY:ce}=window;D(x.left+q),V(x.top+ce);},[x.left,x.top]),f==null)return null;let le="0";typeof window!="undefined"&&(le=window.getComputedStyle(f).borderRadius);let Ne=tr({props:a,alignAttr:k,sideAttr:B});return jsxs(ee.Root,l(i({defaultOpen:!0},v),{children:[jsx(ee.Anchor,{virtualRef:j}),jsx(ee.Portal,{children:jsxs(Fragment,{children:[n&&jsx(y,i({animation:`${nr} 300ms ease-out`,boxShadow:"0 0 0 20000px rgb(0 0 0 / 0.5)",part:"tooltip-spotlight",pointerEvents:"none",position:"absolute",style:{borderRadius:le,height:x.height,left:O,top:X,width:x.width}},a.zIndex!=null?{zIndex:a.zIndex}:{})),jsx(ee.Content,l(i({asChild:!0},F),{ref:g,children:jsxs(b,l(i({animation:`${nr} 300ms ease-out`,boxShadow:"md",position:"relative",className:t,maxWidth:"min(360px, calc(100vw - 25px))",part:["tooltip",S],pointerEvents:"auto",style:r},T),{children:[jsx(er,{style:Ne}),o]}))}))]})})]}))}N.Close=e=>jsx(ee.Close,{"aria-label":"Close",asChild:!0,children:jsx(I.Plain,l(i({css:{top:"0px",right:"-6px"},part:"close",position:"absolute"},e),{children:jsx(Pe,{height:"20",fill:"currentColor"})}))});N.Media=t=>{var n=t,{src:e}=n,o=m(n,["src"]);return e==null?null:jsx(de,i({aspectRatio:"2",borderRadius:"md md 0 0",borderWidth:"0",margin:"-5 -5 0",objectFit:"cover",overflowClipMargin:"unset",src:e,transform:"translate3d(0, 0, 1px)"},o))};N.Primary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null?null:jsx(I.Primary,i({title:o,onClick:e},t))};N.Progress=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({part:"progress"},o),{children:e}))};N.Secondary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null?null:jsx(I.Secondary,i({title:o,onClick:e},t))};N.Subtitle=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({part:"subtitle"},o),{children:e}))};N.Title=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.H4,l(i({part:"title"},o),{children:e}))};function ar(c){var u=c,{dismissible:e=!0,flow:o,onDismiss:t,onEscapeKeyDown:n,onPrimary:r,onSecondary:a,step:s}=u,d=m(u,["dismissible","flow","onDismiss","onEscapeKeyDown","onPrimary","onSecondary","step"]);var v,k,E,B,w,O;let{handleDismiss:g}=xe(o,{onDismiss:t}),{handlePrimary:f,handleSecondary:x}=ne(s,{onPrimary:r,onSecondary:a}),h=(v=s.props)!=null?v:{},F=(E=(k=s.primaryButton)==null?void 0:k.title)!=null?E:s.primaryButtonTitle,S=(w=(B=s.secondaryButton)==null?void 0:B.title)!=null?w:s.secondaryButtonTitle,T=s.$state.blocked;return jsxs(N,l(i(i({anchor:s.selector,collisionPadding:12,onOpenAutoFocus:D=>D.preventDefault(),onPointerDownOutside:D=>D.preventDefault(),onInteractOutside:D=>D.preventDefault()},d),h),{onEscapeKeyDown:D=>{typeof n=="function"&&n(D),D.defaultPrevented||g(D);},children:[e&&jsx(N.Close,{onClick:g}),jsx(N.Media,{src:(O=s.videoUri)!=null?O:s.imageUri,type:s.videoUri?"video":"image"}),jsxs(P.Column,{gap:1,part:"tooltip-header",children:[jsx(N.Title,{children:s.title}),jsx(N.Subtitle,{color:"neutral.400",children:s.subtitle})]}),jsxs(P.Row,{alignItems:"center",gap:3,justifyContent:"flex-end",part:"tooltip-footer",children:[o.getNumberOfAvailableSteps()>1&&jsx(N.Progress,{marginRight:"auto",transform:"translateY(1px)",children:`${o.getCurrentStepOrder()+1}/${o.getNumberOfAvailableSteps()}`}),jsx(N.Secondary,{disabled:T,onClick:x,title:S}),jsx(N.Primary,{disabled:T,onClick:f,title:F})]})]}),s.id)}function Le(e,o=!0){let{currentModal:t,modals:n,setModals:r}=useContext(M),[a,s]=useState(!1);useEffect(()=>{o&&(e!=null&&e.isVisible)&&e&&!n.has(e.id)&&r(c=>new Set(c).add(e.id));},[e==null?void 0:e.id,e==null?void 0:e.isVisible]),useEffect(()=>{let c=t===(e==null?void 0:e.id);o&&(e==null?void 0:e.id)!=null&&c!==a&&s(c);},[e==null?void 0:e.id,t]);function d(){o&&n.has(e==null?void 0:e.id)&&r(c=>{let u=new Set(c);return u.delete(e==null?void 0:e.id),u});}return {isCurrentModal:a||!o,removeModal:d}}function Oo(a){var s=a,{flowId:e,onComplete:o,variables:t,part:n}=s,r=m(s,["flowId","onComplete","variables","part"]);let[d,c]=useState(!1),{flow:u}=ae(e,{variables:t}),{hasInitialized:g,registerComponent:f,unregisterComponent:x}=useContext(M);xe(u,{onComplete:o});let{isCurrentModal:h,removeModal:F}=Le(u);if(useEffect(()=>{!(u!=null&&u.isVisible)&&h&&F();},[u==null?void 0:u.isVisible,h]),useEffect(()=>()=>{x(e);},[]),u==null||u.isVisible===!1||!h||(f(e,()=>{d||c(!0);}),!g||!d))return null;let S=u.getCurrentStep();return S==null||S.start(),jsx(ar,i({"data-flow-id":u.id,flow:u,part:["tour",n],step:S},r))}function pr(e){var u,g,f;let{frigade:o}=useContext(M),[,t]=useState(!1),n,r=useCallback(x=>{o.getCollection(e).then(()=>{x();});let h=()=>{clearTimeout(n),n=setTimeout(()=>{t(F=>!F),x();},100);};return o.onStateChange(h),()=>{o.removeStateChangeHandler(h);}},[e]),a=useSyncExternalStore(r,()=>{let x;try{x=o.getCollectionSync(e);}catch(h){}return x}),d=(f=((g=(u=a==null?void 0:a.flows)==null?void 0:u.map(x=>l(i({},x),{flow:o.getFlowSync(x.flowId)})))!=null?g:[]).find(({flow:x})=>x.isVisible))==null?void 0:f.flowId,{flow:c}=ae(d);return {collection:a,currentFlow:c}}function Io(n){var r=n,{collectionId:e,part:o}=r,t=m(r,["collectionId","part"]);var c,u,g;let a={ANNOUNCEMENT:Ho,BANNER:xo,CARD:b,CHECKLIST:Xe,EMBEDDED_TIP:b,FORM:Re,NPS_SURVEY:Ae,SURVEY:Ae,TOUR:Oo},{currentFlow:s}=pr(e),d=(u=a[(c=s==null?void 0:s.rawData)==null?void 0:c.flowType])!=null?u:null;return s==null||d==null?null:((g=s==null?void 0:s.rawData)==null?void 0:g.flowType)===FlowType.FORM?jsx(y,l(i({part:["collection",o],"data-collection-id":e},t),{children:jsx(Re,{flowId:s.id,as:H},s.id)})):jsx(y,l(i({part:["collection",o],"data-collection-id":e},t),{children:jsx(d,{flowId:s.id},s.id)}))}function Ve(){let{frigade:e}=useContext(M);return {frigade:e,isLoading:!(e!=null&&e.isReady())}}function dr(){let[e,o]=useState(),{frigade:t}=Ve();return useEffect(()=>{t.getCollections().then(n=>{n==null||n.forEach((r,a)=>{r.collectionType==="DEFAULT"&&o(a);});});},[]),e==null?null:jsx(Io,{as:null,collectionId:e})}var M=createContext({apiKey:"",modals:new Set,setModals:()=>{},currentModal:null,navigate:()=>{},hasInitialized:!1,registerComponent:()=>{},unregisterComponent:()=>{}});function cr(){let{frigade:e}=Ve();return useEffect(()=>{$(this,null,function*(){(yield e.getFlows()).forEach(t=>{t.steps.forEach(n=>{if(n.imageUri){let r=new Image;r.src=n.imageUri;}});});});},[]),null}function yr(s){var d=s,{children:e,css:o={},defaultCollection:t=!0,navigate:n,theme:r}=d,a=m(d,["children","css","defaultCollection","navigate","theme"]);let c=r?co(r):{},[u,g]=useState(new Set),f=useRef(new Map),x=useRef(),[h,F]=useState(!1),S=useMemo(()=>(F(!1),x.current=void 0,g(new Set),new Frigade(a.apiKey,{apiKey:a.apiKey,apiUrl:a.apiUrl,userId:a.userId,groupId:a.groupId,userProperties:a.userProperties,groupProperties:a.groupProperties,generateGuestId:a.generateGuestId,syncOnWindowUpdates:a.syncOnWindowUpdates,__readOnly:a.__readOnly,__flowStateOverrides:a.__flowStateOverrides})),[a.userId,a.groupId,a.apiKey]);useEffect(()=>{if(a.__flowStateOverrides){let w=S.getConfig();w.__flowStateOverrides=a.__flowStateOverrides,S.reload(w);}},[a.__flowStateOverrides]);function T(){let w=[...f.current.entries()].map(([O,D])=>[O,D.callback]);S.batchRegister(w),F(!0);}function v(w,O){if(x.current&&clearTimeout(x.current),h){f.current.has(w)?S.getFlow(w).then(D=>O(D.isVisible)):(S.getFlow(w).then(D=>D.register(O)),f.current.set(w,{callback:O}));return}f.current.has(w)||f.current.set(w,{callback:O}),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>T(),0);}function k(w){f.current.has(w)&&S.getFlow(w).then(O=>{f.current.delete(w),O==null||O.unregister();});}let E=n!=null?n:(w,O="_self")=>{window.open(w,O);};useEffect(()=>()=>{S.destroy();},[]);let B=u.size>0?u.values().next().value:null;return jsxs(M.Provider,{value:l(i({modals:u,setModals:g,currentModal:B,navigate:E},a),{frigade:S,registerComponent:v,unregisterComponent:k,hasInitialized:h}),children:[jsx(Global,{styles:{":root":i(i(i({},uo),c),o)}}),jsxs(ThemeProvider,{theme:R,children:[t&&jsx(dr,{}),e]}),a.preloadImages!==!1&&jsx(cr,{})]})}function ae(e,o){let{frigade:t}=useContext(M),[,n]=useState(!1),r=useCallback(s=>{t==null||t.getFlow(e).then(()=>{s();});let d=c=>{c.id===e&&setTimeout(()=>{n(u=>!u),s();},0);};return t==null||t.onStateChange(d),()=>{t.removeStateChangeHandler(d);}},[e]),a=useSyncExternalStore(r,()=>t==null?void 0:t.getFlowSync(e));return a!=null&&(o!=null&&o.variables)&&a.applyVariables(o.variables),{flow:a}}function U(u){var g=u,{as:e,children:o,flowId:t,onComplete:n,onDismiss:r,onPrimary:a,onSecondary:s,variables:d}=g,c=m(g,["as","children","flowId","onComplete","onDismiss","onPrimary","onSecondary","variables"]);var j,Ne;let{flow:f}=ae(t,{variables:d}),le=i(i({},(j=f==null?void 0:f.props)!=null?j:{}),c),{dismissible:x=!1,forceMount:h=!1,modal:F=!1}=le,S=m(le,["dismissible","forceMount","modal"]),T=f==null?void 0:f.getCurrentStep(),{handleDismiss:v}=xe(f,{onComplete:n,onDismiss:r}),{handlePrimary:k,handleSecondary:E}=ne(T,{onPrimary:a,onSecondary:s}),B=F||typeof e=="function"&&(e==null?void 0:e.displayName)==="Dialog"||[FlowType.ANNOUNCEMENT,FlowType.TOUR].includes((Ne=f==null?void 0:f.rawData)==null?void 0:Ne.flowType),{isCurrentModal:w,removeModal:O}=Le(f,B);useEffect(()=>{!(f!=null&&f.isVisible)&&w&&O();},[f==null?void 0:f.isVisible,w]);let D=h&&((f==null?void 0:f.isCompleted)||(f==null?void 0:f.isSkipped));if(!f||!D&&!w||!f.isVisible&&!D)return null;(D||!f.isCompleted&&!f.isSkipped)&&T.start();let X=e===null?Fragment$1:e!=null?e:y,V=l(i({},S),{"data-flow-id":f.id});return jsx(X,l(i({},e===null?{}:V),{children:o({flow:f,handleDismiss:v,handlePrimary:k,handleSecondary:E,parentProps:{dismissible:x,flowId:t,variables:d,containerProps:V},step:T})}))}function br(t){var n=t,{part:e}=n,o=m(n,["part"]);return jsx(U,l(i({as:b,gap:5,borderColor:"neutral.border",borderStyle:"solid",borderWidth:"md",part:["card",e]},o),{children:({handleDismiss:r,handlePrimary:a,handleSecondary:s,parentProps:{dismissible:d},step:c})=>{var f,x,h,F;let u=(x=(f=c.primaryButton)==null?void 0:f.title)!=null?x:c.primaryButtonTitle,g=(F=(h=c.secondaryButton)==null?void 0:h.title)!=null?F:c.secondaryButtonTitle;return jsxs(Fragment,{children:[jsx(b.Header,{dismissible:d,handleDismiss:r,subtitle:c.subtitle,title:c.title}),jsx(b.Media,{src:c.imageUri,css:{objectFit:"contain",width:"100%"}}),jsxs(P.Row,{gap:3,justifyContent:"flex-end",part:"card-footer",children:[jsx(b.Secondary,{title:g,onClick:s}),jsx(b.Primary,{title:u,onClick:a})]})]})}}))}var b=yo.forwardRef((r,n)=>{var a=r,{children:e,flowId:o}=a,t=m(a,["children","flowId"]);var d;if(o!=null)return jsx(br,i({flowId:o},t));let s=(d=t.as)!=null?d:P.Column;return jsx(s,l(i({backgroundColor:"neutral.background",borderColor:"neutral.border",borderStyle:"solid",borderRadius:"md",borderWidth:"0",gap:5,p:5},t),{ref:n,children:e}))});b.Dismiss=e=>jsx(I.Plain,l(i({part:"dismiss",padding:0},e),{children:jsx(Pe,{height:"20",fill:"currentColor"})}));b.Header=a=>{var s=a,{dismissible:e,handleDismiss:o,subtitle:t,title:n}=s,r=m(s,["dismissible","handleDismiss","subtitle","title"]);return jsxs(P.Row,l(i({alignItems:"flex-start",flexWrap:"wrap",gap:1,part:"card-header"},r),{children:[jsx(b.Title,{maxWidth:"calc(100% - 32px)",children:n}),e&&jsx(b.Dismiss,{onClick:o,marginLeft:"auto"}),jsx(b.Subtitle,{color:"neutral.400",flexBasis:"100%",children:t})]}))};b.Media=t=>{var n=t,{src:e}=n,o=m(n,["src"]);return e==null||(e==null?void 0:e.length)===0?null:jsx(de,i({borderRadius:"md",src:e},o))};b.Primary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null||(o==null?void 0:o.length)===0?null:jsx(I.Primary,i({title:o,onClick:e},t))};b.Secondary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null||(o==null?void 0:o.length)===0?null:jsx(I.Secondary,i({title:o,onClick:e},t))};b.Subtitle=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({display:"block",color:"neutral.400",part:"subtitle"},o),{children:e}))};b.Title=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.H4,l(i({display:"block",part:"title"},o),{children:e}))};var lo={content:["onOpenAutoFocus","onCloseAutoFocus","onEscapeKeyDown","onPointerDownOutside","onInteractOutside"],root:["defaultOpen","modal","onOpenChange","open"]};function Cr(e){let o=Object.fromEntries(lo.content.map(r=>[r,e[r]]).filter(r=>r[1]!==void 0)),t=Object.fromEntries(lo.root.map(r=>[r,e[r]]).filter(r=>r[1]!==void 0)),n={};for(let r of Object.keys(e))!lo.content.some(a=>a===r)&&!lo.root.some(a=>a===r)&&(n[r]=e[r]);return {contentProps:o,otherProps:n,rootProps:t}}var Zi=keyframes`
|
|
56
|
+
`;function ir(e){return e instanceof HTMLElement?!!(e.offsetWidth||e.offsetHeight||e.getClientRects().length):!1}function N(s){var d=s,{anchor:e,children:o,className:t,spotlight:n=!1,style:r}=d,a=m(d,["anchor","children","className","spotlight","style"]);let{node:c,rect:u,ref:g}=to(),{node:f,rect:x,ref:h}=to(),ia=rr(a,u),{contentProps:F,otherProps:wr}=ia,Ao=wr,{part:S}=Ao,T=m(Ao,["part"]),{rootProps:v}=ia,[k,E]=useState(F.align),[B,w]=useState(F.side),[O,D]=useState(0),[X,V]=useState(0);if(c!==null){let q=c.getAttribute("data-align"),ce=c.getAttribute("data-side");k!==q&&E(q),B!==ce&&w(ce);}let j=useRef(null);if(useEffect(()=>{let q=document.querySelector(e);q!=null?(h(q),j.current=q):console.debug(`[frigade] Tooltip: No anchor found for query: ${e}`);},[e]),useEffect(()=>{function q(be){if(be.matches(e))return ir(be)?be:null;let ue=be.querySelectorAll(e);return ue.length>0&&ir(ue[0])?ue[0]:null}let ce=new MutationObserver(be=>{for(let ue of be)if(ue.type==="childList"){for(let ke of ue.addedNodes){if(ke.nodeType!==Node.ELEMENT_NODE)continue;let me=q(ke);if(me!=null){h(me),j.current=me,console.debug("[frigade] Tooltip: MutationObserver added anchor: ",me);break}}for(let ke of ue.removedNodes){if(ke.nodeType!==Node.ELEMENT_NODE)continue;let me=q(ke);if(me!=null){h(null),j.current=null,console.debug("[frigade] Tooltip: MutationObserver removed anchor: ",me);break}}}});return ce.observe(document.querySelector("body"),{childList:!0,subtree:!0}),()=>ce.disconnect()},[]),useEffect(()=>{let{scrollX:q,scrollY:ce}=window;D(x.left+q),V(x.top+ce);},[x.left,x.top]),f==null)return null;let le="0";typeof window!="undefined"&&(le=window.getComputedStyle(f).borderRadius);let Ne=tr({props:a,alignAttr:k,sideAttr:B});return jsxs(ee.Root,l(i({defaultOpen:!0},v),{children:[jsx(ee.Anchor,{virtualRef:j}),jsx(ee.Portal,{children:jsxs(Fragment,{children:[n&&jsx(y,i({animation:`${nr} 300ms ease-out`,boxShadow:"0 0 0 20000px rgb(0 0 0 / 0.5)",part:"tooltip-spotlight",pointerEvents:"none",position:"absolute",style:{borderRadius:le,height:x.height,left:O,top:X,width:x.width}},a.zIndex!=null?{zIndex:a.zIndex}:{})),jsx(ee.Content,l(i({asChild:!0},F),{ref:g,children:jsxs(b,l(i({animation:`${nr} 300ms ease-out`,boxShadow:"md",position:"relative",className:t,maxWidth:"min(360px, calc(100vw - 25px))",part:["tooltip",S],pointerEvents:"auto",style:r},T),{children:[jsx(er,{style:Ne}),o]}))}))]})})]}))}N.Close=e=>jsx(ee.Close,{"aria-label":"Close",asChild:!0,children:jsx(I.Plain,l(i({css:{top:"0px",right:"-6px"},part:"close",position:"absolute"},e),{children:jsx(Pe,{height:"20",fill:"currentColor"})}))});N.Media=t=>{var n=t,{src:e}=n,o=m(n,["src"]);return e==null?null:jsx(de,i({aspectRatio:"2",borderRadius:"md md 0 0",borderWidth:"0",margin:"-5 -5 0",objectFit:"cover",overflowClipMargin:"unset",src:e,transform:"translate3d(0, 0, 1px)"},o))};N.Primary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null?null:jsx(I.Primary,i({title:o,onClick:e},t))};N.Progress=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({part:"progress"},o),{children:e}))};N.Secondary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null?null:jsx(I.Secondary,i({title:o,onClick:e},t))};N.Subtitle=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({part:"subtitle"},o),{children:e}))};N.Title=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.H4,l(i({part:"title"},o),{children:e}))};function ar(c){var u=c,{dismissible:e=!0,flow:o,onDismiss:t,onEscapeKeyDown:n,onPrimary:r,onSecondary:a,step:s}=u,d=m(u,["dismissible","flow","onDismiss","onEscapeKeyDown","onPrimary","onSecondary","step"]);var v,k,E,B,w,O;let{handleDismiss:g}=xe(o,{onDismiss:t}),{handlePrimary:f,handleSecondary:x}=ne(s,{onPrimary:r,onSecondary:a}),h=(v=s.props)!=null?v:{},F=(E=(k=s.primaryButton)==null?void 0:k.title)!=null?E:s.primaryButtonTitle,S=(w=(B=s.secondaryButton)==null?void 0:B.title)!=null?w:s.secondaryButtonTitle,T=s.$state.blocked;return jsxs(N,l(i(i({anchor:s.selector,collisionPadding:12,onOpenAutoFocus:D=>D.preventDefault(),onPointerDownOutside:D=>D.preventDefault(),onInteractOutside:D=>D.preventDefault()},d),h),{onEscapeKeyDown:D=>{typeof n=="function"&&n(D),D.defaultPrevented||g(D);},children:[e&&jsx(N.Close,{onClick:g}),jsx(N.Media,{src:(O=s.videoUri)!=null?O:s.imageUri,type:s.videoUri?"video":"image"}),jsxs(P.Column,{gap:1,part:"tooltip-header",children:[jsx(N.Title,{children:s.title}),jsx(N.Subtitle,{color:"neutral.400",children:s.subtitle})]}),jsxs(P.Row,{alignItems:"center",gap:3,justifyContent:"flex-end",part:"tooltip-footer",children:[o.getNumberOfAvailableSteps()>1&&jsx(N.Progress,{marginRight:"auto",transform:"translateY(1px)",children:`${o.getCurrentStepOrder()+1}/${o.getNumberOfAvailableSteps()}`}),jsx(N.Secondary,{disabled:T,onClick:x,title:S}),jsx(N.Primary,{disabled:T,onClick:f,title:F})]})]}),s.id)}function Le(e,o=!0){let{currentModal:t,modals:n,setModals:r}=useContext(M),[a,s]=useState(!1);useEffect(()=>{o&&(e!=null&&e.isVisible)&&e&&!n.has(e.id)&&r(c=>new Set(c).add(e.id));},[e==null?void 0:e.id,e==null?void 0:e.isVisible]),useEffect(()=>{let c=t===(e==null?void 0:e.id);o&&(e==null?void 0:e.id)!=null&&c!==a&&s(c);},[e==null?void 0:e.id,t]);function d(){o&&n.has(e==null?void 0:e.id)&&r(c=>{let u=new Set(c);return u.delete(e==null?void 0:e.id),u});}return {isCurrentModal:a||!o,removeModal:d}}function Oo(a){var s=a,{flowId:e,onComplete:o,variables:t,part:n}=s,r=m(s,["flowId","onComplete","variables","part"]);let[d,c]=useState(!1),{flow:u}=ae(e,{variables:t}),{hasInitialized:g,registerComponent:f,unregisterComponent:x}=useContext(M);xe(u,{onComplete:o});let{isCurrentModal:h,removeModal:F}=Le(u);if(useEffect(()=>{!(u!=null&&u.isVisible)&&h&&F();},[u==null?void 0:u.isVisible,h]),useEffect(()=>()=>{x(e);},[]),u==null||u.isVisible===!1||!h||(f(e,()=>{d||c(!0);}),!g||!d))return null;let S=u.getCurrentStep();return S==null||S.start(),jsx(ar,i({"data-flow-id":u.id,flow:u,part:["tour",n],step:S},r))}function pr(e){var u,g,f;let{frigade:o}=useContext(M),[,t]=useState(!1),n,r=useCallback(x=>{o.getCollection(e).then(()=>{x();});let h=()=>{clearTimeout(n),n=setTimeout(()=>{t(F=>!F),x();},100);};return o.onStateChange(h),()=>{o.removeStateChangeHandler(h);}},[e]),a=useSyncExternalStore(r,()=>{let x;try{x=o.getCollectionSync(e);}catch(h){}return x},()=>{let x;try{x=o.getCollectionSync(e);}catch(h){}return x}),d=(f=((g=(u=a==null?void 0:a.flows)==null?void 0:u.map(x=>l(i({},x),{flow:o.getFlowSync(x.flowId)})))!=null?g:[]).find(({flow:x})=>x.isVisible))==null?void 0:f.flowId,{flow:c}=ae(d);return {collection:a,currentFlow:c}}function Io(n){var r=n,{collectionId:e,part:o}=r,t=m(r,["collectionId","part"]);var c,u,g;let a={ANNOUNCEMENT:Ho,BANNER:xo,CARD:b,CHECKLIST:Xe,EMBEDDED_TIP:b,FORM:Re,NPS_SURVEY:Ae,SURVEY:Ae,TOUR:Oo},{currentFlow:s}=pr(e),d=(u=a[(c=s==null?void 0:s.rawData)==null?void 0:c.flowType])!=null?u:null;return s==null||d==null?null:((g=s==null?void 0:s.rawData)==null?void 0:g.flowType)===FlowType.FORM?jsx(y,l(i({part:["collection",o],"data-collection-id":e},t),{children:jsx(Re,{flowId:s.id,as:H},s.id)})):jsx(y,l(i({part:["collection",o],"data-collection-id":e},t),{children:jsx(d,{flowId:s.id},s.id)}))}function Ve(){let{frigade:e}=useContext(M);return {frigade:e,isLoading:!(e!=null&&e.isReady())}}function dr(){let[e,o]=useState(),{frigade:t}=Ve();return useEffect(()=>{t.getCollections().then(n=>{n==null||n.forEach((r,a)=>{r.collectionType==="DEFAULT"&&o(a);});});},[]),e==null?null:jsx(Io,{as:null,collectionId:e})}var M=createContext({apiKey:"",modals:new Set,setModals:()=>{},currentModal:null,navigate:()=>{},hasInitialized:!1,registerComponent:()=>{},unregisterComponent:()=>{}});function cr(){let{frigade:e}=Ve();return useEffect(()=>{$(this,null,function*(){(yield e.getFlows()).forEach(t=>{t.steps.forEach(n=>{if(n.imageUri){let r=new Image;r.src=n.imageUri;}});});});},[]),null}function yr(s){var d=s,{children:e,css:o={},defaultCollection:t=!0,navigate:n,theme:r}=d,a=m(d,["children","css","defaultCollection","navigate","theme"]);let c=r?co(r):{},[u,g]=useState(new Set),f=useRef(new Map),x=useRef(),[h,F]=useState(!1),S=useMemo(()=>(F(!1),x.current=void 0,g(new Set),new Frigade(a.apiKey,{apiKey:a.apiKey,apiUrl:a.apiUrl,userId:a.userId,groupId:a.groupId,userProperties:a.userProperties,groupProperties:a.groupProperties,generateGuestId:a.generateGuestId,syncOnWindowUpdates:a.syncOnWindowUpdates,__readOnly:a.__readOnly,__flowStateOverrides:a.__flowStateOverrides})),[a.userId,a.groupId,a.apiKey]);useEffect(()=>{if(a.__flowStateOverrides){let w=S.getConfig();w.__flowStateOverrides=a.__flowStateOverrides,S.reload(w);}},[a.__flowStateOverrides]);function T(){let w=[...f.current.entries()].map(([O,D])=>[O,D.callback]);S.batchRegister(w),F(!0);}function v(w,O){if(x.current&&clearTimeout(x.current),h){f.current.has(w)?S.getFlow(w).then(D=>O(D.isVisible)):(S.getFlow(w).then(D=>D.register(O)),f.current.set(w,{callback:O}));return}f.current.has(w)||f.current.set(w,{callback:O}),x.current&&clearTimeout(x.current),x.current=setTimeout(()=>T(),0);}function k(w){f.current.has(w)&&S.getFlow(w).then(O=>{f.current.delete(w),O==null||O.unregister();});}let E=n!=null?n:(w,O="_self")=>{window.open(w,O);};useEffect(()=>()=>{S.destroy();},[]);let B=u.size>0?u.values().next().value:null;return jsxs(M.Provider,{value:l(i({modals:u,setModals:g,currentModal:B,navigate:E},a),{frigade:S,registerComponent:v,unregisterComponent:k,hasInitialized:h}),children:[jsx(Global,{styles:{":root":i(i(i({},uo),c),o)}}),jsxs(ThemeProvider,{theme:R,children:[t&&jsx(dr,{}),e]}),a.preloadImages!==!1&&jsx(cr,{})]})}function ae(e,o){let{frigade:t}=useContext(M),[,n]=useState(!1),r=useCallback(s=>{t==null||t.getFlow(e).then(()=>{s();});let d=c=>{c.id===e&&setTimeout(()=>{n(u=>!u),s();},0);};return t==null||t.onStateChange(d),()=>{t.removeStateChangeHandler(d);}},[e]),a=useSyncExternalStore(r,()=>t==null?void 0:t.getFlowSync(e),()=>t==null?void 0:t.getFlowSync(e));return a!=null&&(o!=null&&o.variables)&&a.applyVariables(o.variables),{flow:a}}function U(u){var g=u,{as:e,children:o,flowId:t,onComplete:n,onDismiss:r,onPrimary:a,onSecondary:s,variables:d}=g,c=m(g,["as","children","flowId","onComplete","onDismiss","onPrimary","onSecondary","variables"]);var j,Ne;let{flow:f}=ae(t,{variables:d}),le=i(i({},(j=f==null?void 0:f.props)!=null?j:{}),c),{dismissible:x=!1,forceMount:h=!1,modal:F=!1}=le,S=m(le,["dismissible","forceMount","modal"]),T=f==null?void 0:f.getCurrentStep(),{handleDismiss:v}=xe(f,{onComplete:n,onDismiss:r}),{handlePrimary:k,handleSecondary:E}=ne(T,{onPrimary:a,onSecondary:s}),B=F||typeof e=="function"&&(e==null?void 0:e.displayName)==="Dialog"||[FlowType.ANNOUNCEMENT,FlowType.TOUR].includes((Ne=f==null?void 0:f.rawData)==null?void 0:Ne.flowType),{isCurrentModal:w,removeModal:O}=Le(f,B);useEffect(()=>{!(f!=null&&f.isVisible)&&w&&O();},[f==null?void 0:f.isVisible,w]);let D=h&&((f==null?void 0:f.isCompleted)||(f==null?void 0:f.isSkipped));if(!f||!D&&!w||!f.isVisible&&!D)return null;(D||!f.isCompleted&&!f.isSkipped)&&T.start();let X=e===null?Fragment$1:e!=null?e:y,V=l(i({},S),{"data-flow-id":f.id});return jsx(X,l(i({},e===null?{}:V),{children:o({flow:f,handleDismiss:v,handlePrimary:k,handleSecondary:E,parentProps:{dismissible:x,flowId:t,variables:d,containerProps:V},step:T})}))}function br(t){var n=t,{part:e}=n,o=m(n,["part"]);return jsx(U,l(i({as:b,gap:5,borderColor:"neutral.border",borderStyle:"solid",borderWidth:"md",part:["card",e]},o),{children:({handleDismiss:r,handlePrimary:a,handleSecondary:s,parentProps:{dismissible:d},step:c})=>{var f,x,h,F;let u=(x=(f=c.primaryButton)==null?void 0:f.title)!=null?x:c.primaryButtonTitle,g=(F=(h=c.secondaryButton)==null?void 0:h.title)!=null?F:c.secondaryButtonTitle;return jsxs(Fragment,{children:[jsx(b.Header,{dismissible:d,handleDismiss:r,subtitle:c.subtitle,title:c.title}),jsx(b.Media,{src:c.imageUri,css:{objectFit:"contain",width:"100%"}}),jsxs(P.Row,{gap:3,justifyContent:"flex-end",part:"card-footer",children:[jsx(b.Secondary,{title:g,onClick:s}),jsx(b.Primary,{title:u,onClick:a})]})]})}}))}var b=yo.forwardRef((r,n)=>{var a=r,{children:e,flowId:o}=a,t=m(a,["children","flowId"]);var d;if(o!=null)return jsx(br,i({flowId:o},t));let s=(d=t.as)!=null?d:P.Column;return jsx(s,l(i({backgroundColor:"neutral.background",borderColor:"neutral.border",borderStyle:"solid",borderRadius:"md",borderWidth:"0",gap:5,p:5},t),{ref:n,children:e}))});b.Dismiss=e=>jsx(I.Plain,l(i({part:"dismiss",padding:0},e),{children:jsx(Pe,{height:"20",fill:"currentColor"})}));b.Header=a=>{var s=a,{dismissible:e,handleDismiss:o,subtitle:t,title:n}=s,r=m(s,["dismissible","handleDismiss","subtitle","title"]);return jsxs(P.Row,l(i({alignItems:"flex-start",flexWrap:"wrap",gap:1,part:"card-header"},r),{children:[jsx(b.Title,{maxWidth:"calc(100% - 32px)",children:n}),e&&jsx(b.Dismiss,{onClick:o,marginLeft:"auto"}),jsx(b.Subtitle,{color:"neutral.400",flexBasis:"100%",children:t})]}))};b.Media=t=>{var n=t,{src:e}=n,o=m(n,["src"]);return e==null||(e==null?void 0:e.length)===0?null:jsx(de,i({borderRadius:"md",src:e},o))};b.Primary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null||(o==null?void 0:o.length)===0?null:jsx(I.Primary,i({title:o,onClick:e},t))};b.Secondary=n=>{var r=n,{onClick:e,title:o}=r,t=m(r,["onClick","title"]);return o==null||(o==null?void 0:o.length)===0?null:jsx(I.Secondary,i({title:o,onClick:e},t))};b.Subtitle=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.Body2,l(i({display:"block",color:"neutral.400",part:"subtitle"},o),{children:e}))};b.Title=t=>{var n=t,{children:e}=n,o=m(n,["children"]);return e==null?null:jsx(C.H4,l(i({display:"block",part:"title"},o),{children:e}))};var lo={content:["onOpenAutoFocus","onCloseAutoFocus","onEscapeKeyDown","onPointerDownOutside","onInteractOutside"],root:["defaultOpen","modal","onOpenChange","open"]};function Cr(e){let o=Object.fromEntries(lo.content.map(r=>[r,e[r]]).filter(r=>r[1]!==void 0)),t=Object.fromEntries(lo.root.map(r=>[r,e[r]]).filter(r=>r[1]!==void 0)),n={};for(let r of Object.keys(e))!lo.content.some(a=>a===r)&&!lo.root.some(a=>a===r)&&(n[r]=e[r]);return {contentProps:o,otherProps:n,rootProps:t}}var Zi=keyframes`
|
|
57
57
|
from {
|
|
58
58
|
opacity: 0;
|
|
59
59
|
}
|