@swarm.ing/pieui 3.0.10 → 3.0.11
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/cli.js +115 -65
- package/dist/components/PieMaxRoot/index.d.ts.map +1 -1
- package/dist/components/PieRoot/index.d.ts.map +1 -1
- package/dist/components/PieRoot/types/index.d.ts +19 -0
- package/dist/components/PieRoot/types/index.d.ts.map +1 -1
- package/dist/components/PieTelegramRoot/index.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.js +2 -2
- package/dist/max/index.esm.js +1 -1
- package/dist/max/index.js +1 -1
- package/dist/native/index.esm.js +2 -2
- package/dist/native/index.js +2 -2
- package/dist/telegram/index.esm.js +1 -1
- package/dist/telegram/index.js +1 -1
- package/dist/tests/contentRequest.test.d.ts +16 -0
- package/dist/tests/contentRequest.test.d.ts.map +1 -0
- package/dist/util/contentRequest.d.ts +62 -0
- package/dist/util/contentRequest.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useContext as MZ,useEffect as GZ,useRef as PZ}from"react";import{createContext as
|
|
3
|
-
`);y=vZ.pop()??"";for(let hU of vZ){let KZ=hU.trim();if(!KZ)continue;try{let gU=JSON.parse(KZ);Z([gU])}catch{if(J)console.warn("Failed to parse streamed line:",KZ)}}}if(y.trim())try{let DZ=JSON.parse(y);Z([DZ])}catch{if(J)console.warn("Failed to parse final streamed line:",y)}return{}}else{let u=await Y.json();return Z(u),u}}catch(Y){if(A)clearTimeout(A);if(w=Y,D<X)continue;if(J)console.error("AJAX request failed:",Y);return Z(null),Y}}if(J)console.error("AJAX request failed after retries:",w);return Z(null),w}},W$=(Z,U={},$=[],z,H)=>{let{apiServer:J,enableRenderingLog:T}=g(),G=JSON.stringify(U),X=JSON.stringify($),B=JSON.stringify(H);return eZ(()=>JU(Z,U,$,z,{apiServer:J,renderingLogEnabled:T,timeout:H?.timeout,retryPolicy:H?.retryPolicy,fetchOptions:H?.fetchOptions}),[Z,G,X,z,J,T,B])},TU=(Z={})=>{let U=[];for(let $ of Object.keys(Z??{})){let z=null;if($==="pathname")z="default";else if($.endsWith("Pathname"))z=$.slice(0,-8);if(z===null)continue;let H=z==="default"?"":z;U.push({key:z,pathname:Z[$],depsNames:Z[H?`${H}DepsNames`:"depsNames"]??[],kwargs:Z[H?`${H}Kwargs`:"kwargs"]??{}})}return U},q$=(Z={},U,$)=>{let{apiServer:z,enableRenderingLog:H}=g(),J=JSON.stringify(Z??{}),T=JSON.stringify($);return eZ(()=>{let G={};for(let X of TU(Z??{}))G[X.key]=JU(U,X.kwargs,X.depsNames,X.pathname,{apiServer:z,renderingLogEnabled:H,timeout:$?.timeout,retryPolicy:$?.retryPolicy,fetchOptions:$?.fetchOptions});return G},[J,U,z,H,T])};import{jsx as V$,jsxs as D$,Fragment as _$}from"react/jsx-runtime";var Q$=({card:Z,data:U,children:$,useSocketioSupport:z=!1,useCentrifugeSupport:H=!1,useMittSupport:J=!1,centrifugeChannel:T=void 0,methods:G=void 0,stored:X=void 0,onResync:B=void 0})=>{let _=hZ(),W=PZ(G);W.current=G;let V=PZ(B);V.current=B;let Q=PZ(X);Q.current=X;let q=typeof X==="function";if(GZ(()=>{if(!q)return;let P=U.name;return ZU(P,()=>[JSON.stringify(Q.current())]),()=>UU(P)},[q,U.name]),_)console.log("[PieCard] Rendering card:",Z),console.log("[PieCard] Card data:",U),console.log("[PieCard] Component name:",U?.name),console.log("[PieCard] Real-time support:",{socketio:z,centrifuge:H,mitt:J,centrifugeChannel:T}),console.log("[PieCard] Methods:",G?Object.keys(G):"none"),console.log("[PieCard] Has children:",!!$);let F=MZ(m),w=MZ(S),D=MZ(v);if(GZ(()=>{if(!F||!z||!W.current||!U.name){if(_&&z)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!F,useSocketioSupport:z,hasMethods:!!W.current,hasDataName:!!U?.name});return}let A=Object.keys(W.current??{}).map((Y)=>{let K=`pie${Y}_${U.name}`;if(_)console.log(`[PieCard] Socket.IO registering event: ${K}`);let R=(h)=>{W.current?.[Y]?.(h)};return F.on(K,R),[K,R]});return()=>{A.forEach(([Y,K])=>{if(_)console.log(`[PieCard] Socket.IO unregistering event: ${Y}`);F.off(Y,K)})}},[F,U.name,z]),GZ(()=>{if(!w||!H||!T||!U.name){if(_&&H)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!w,useCentrifugeSupport:H,hasCentrifugeChannel:!!T,hasMethods:!!W.current,hasDataName:!!U?.name});return}let A=Object.keys(W.current??{}).map((Y)=>{let K=`pie${Y}_${U.name}_${T}`;if(_)console.log(`[PieCard] Centrifuge subscribing to channel: ${K}`);let{subscription:R,createdHere:h}=oZ(w,K,{recoverable:!0,positioned:!0}),u=(y)=>{if(_)console.log(`[PieCard] Centrifuge received data on ${K}:`,y.data);W.current?.[Y]?.(y.data)},$Z=(y)=>{if(lZ(y))console.warn(`[PieCard] Centrifuge channel ${K} is not `+"recoverable — enable history on the server "+"namespace for exact replay; relying on resync fallback only.");if(cZ(y)){if(_)console.log(`[PieCard] Centrifuge recovery gap on ${K}; requesting resync`);V.current?.({channel:K,reason:"gap"})}};return R.on("publication",u),R.on("subscribed",$Z),R.subscribe(),{subscription:R,createdHere:h,onPublication:u,onSubscribed:$Z}});return()=>{A.forEach(({subscription:Y,createdHere:K,onPublication:R,onSubscribed:h})=>{if(_)console.log("[PieCard] Centrifuge unsubscribing from channel");if(Y.off("publication",R),Y.off("subscribed",h),K)Y.unsubscribe(),w.removeSubscription(Y)})}},[w,T,U.name,H]),GZ(()=>{if(!D||!J||!U.name){if(_&&J)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!D,useMittSupport:J,hasMethods:!!W.current,hasDataName:!!U?.name});return}let P=Object.keys(W.current??{}),A={};return P.forEach((Y)=>{let K=`pie${Y}_${U.name}`,R=(h)=>{if(_)console.log(`[PieCard] Mitt registering event: ${K}`);W.current?.[Y]?.(h)};A[K]=R,D.on(K,R)}),()=>{Object.entries(A).forEach(([Y,K])=>{if(_)console.log(`[PieCard] Mitt unregistering event: ${Y}`);D.off(Y,K)})}},[D,U.name,J]),_)console.log("[PieCard] Rendering complete, returning children");if(X!==void 0&&!q)return D$(_$,{children:[V$("input",{type:"hidden",name:U.name,value:JSON.stringify(X)}),$]});return $},M=Q$;import{lazy as K$}from"react";var l=new Map;function XU(Z,U){return U.catch(()=>{if(l.get(Z)===U)l.delete(Z)}),l.set(Z,U),U}function AZ(Z,U){return K$(()=>{if(l.has(U))return l.get(U);return XU(U,Z().then(($)=>$))})}var GU=async(Z,U)=>{if(!U)return;if(l.has(Z))return l.get(Z);return XU(Z,U().then(($)=>$))};var f=I("@swarm.ing/pieui:component-registry",()=>new Map),F$=(Z)=>{if(!Z.name)throw Error("Component registration requires a name");if(!Z.component&&!Z.loader)throw Error(`Component "${Z.name}" requires component or loader`);let U={name:Z.name,component:Z.component,loader:Z.loader,metadata:Z.metadata,fallback:Z.fallback,isLazy:!1};if(!U.component&&U.loader)U.component=AZ(U.loader,Z.name),U.isLazy=!0;return U};function O(Z){let U=F$(Z);return f.set(U.name,U),U.component}var O$=(Z)=>{Z.forEach((U)=>O(U))},I$=(Z)=>{f.delete(Z)},M$=(Z)=>{return f.has(Z)},P$=(Z)=>{return f.get(Z)?.metadata},ZZ=(Z)=>{return f.get(Z)},A$=()=>{return Array.from(f.keys())},w$=()=>{return f.size},BU=()=>Array.from(f.values()).filter((Z)=>Z.isLazy&&typeof Z.loader==="function").map((Z)=>Z.name),WU=(Z)=>{let U=f.get(Z);if(!U?.isLazy||typeof U.loader!=="function")return;return GU(Z,U.loader)},YU=!1,N$=()=>{if(YU||typeof window>"u")return;YU=!0;let Z=navigator.connection;if(Z?.saveData)return;if(Z?.effectiveType&&["slow-2g","2g"].includes(Z.effectiveType))return;let U=BU(),$="requestIdleCallback"in window?(H)=>window.requestIdleCallback(H,{timeout:2000}):(H)=>window.setTimeout(H,300),z=(H)=>{if(H>=U.length)return;$(()=>{Promise.resolve().then(()=>WU(U[H])).catch(()=>{}).finally(()=>z(H+1))})};z(0)};import{useContext as qU,memo as m$}from"react";import{createContext as L$}from"react";import{jsx as E$,Fragment as j$}from"react/jsx-runtime";var R$=I("@swarm.ing/pieui:context:fallback",()=>L$(E$(j$,{}))),E=R$;import{createContext as C$}from"react";var x$=I("@swarm.ing/pieui:context:lazyError",()=>C$(void 0)),d=x$;import{Component as y$,Suspense as f$}from"react";import{jsx as S$}from"react/jsx-runtime";var b$=2,k$=400;class s extends y${state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(Z){if(this.props.onError?.(Z),this.state.attempt<b$){let U=k$*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState(($)=>({failed:!1,attempt:$.attempt+1}))},U)}}componentDidUpdate(Z){if(Z.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return S$(f$,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}import{jsx as wZ}from"react/jsx-runtime";function v$({uiConfig:Z,setUiAjaxConfiguration:U}){let $=qU(E),z=qU(d),H=k();if(H)console.log("[UI] Rendering component:",Z.card),console.log("[UI] Component data:",Z.data),console.log("[UI] Component content:",Z.content),console.log("[UI] Has setUiAjaxConfiguration:",!!U);let J=ZZ(Z.card);if(!J?.component){if(H)console.warn(`[UI] Component not found in registry: ${Z.card}`),console.log("[UI] Returning fallback component");return $}if(H)console.log("[UI] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata});let T=J.component,G=wZ(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:U});if(J.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",J.name);return wZ(s,{name:J.name,fallback:J.fallback?wZ(J.fallback,{}):$,onError:z,children:G})}if(H)console.log("[UI] Rendering component directly:",J.name);return G}var j=m$(v$);import{useContext as QU}from"react";import{createContext as h$}from"react";var g$=I("@swarm.ing/pieui:context:uiRenderer",()=>h$(null)),C=g$;import{jsx as YZ}from"react/jsx-runtime";function _U({uiConfig:Z,setUiAjaxConfiguration:U}){let $=QU(E),z=QU(d),H=k();if(H)console.log("[UILoading] Rendering fallback for:",Z.card),console.log("[UILoading] Component data:",Z.data),console.log("[UILoading] Component content:",Z.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!U);let J=ZZ(Z.card);if(!J?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${Z.card}`),console.log("[UILoading] Returning fallback component");return $}if(H)console.log("[UILoading] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata,hasFallback:!!J.fallback});if(J.fallback){if(H)console.log("[UILoading] Rendering fallback for:",J.name);let X=J.fallback;return YZ(X,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",J.name);let T=J.component,G=YZ(C.Provider,{value:_U,children:YZ(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:U})});if(J.isLazy)return YZ(s,{name:J.name,fallback:$,onError:z,children:G});return G}var NZ=_U;import{useContext as p$}from"react";import{jsx as LZ}from"react/jsx-runtime";var d$=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,sx:H}=Z,J=p$(C)??j;return LZ(M,{card:z,data:Z,children:LZ("div",{style:H,id:z,children:U.map((T,G)=>{return LZ(J,{uiConfig:T,setUiAjaxConfiguration:$},`children-${G}`)})})})},VU=d$;var u$=O({name:"SequenceCard",component:VU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as c$}from"react";import{jsx as DU}from"react/jsx-runtime";var l$=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z}=Z,H=c$(C)??j;return DU(M,{card:z,data:Z,children:U.map((J,T)=>{return DU(H,{uiConfig:J,setUiAjaxConfiguration:$},`children-${T}`)})})},KU=l$;var o$=O({name:"UnionCard",component:KU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});import{useEffect as a$,useState as n$}from"react";import t$ from"html-react-parser";import{useCallback as BZ,useEffect as s$,useRef as RZ,useState as i$}from"react";function r$(){let Z=new AudioContext,U=Z.createOscillator(),$=U.connect(Z.createMediaStreamDestination());U.start();let z=$.stream.getAudioTracks()[0];return z.enabled=!1,z}function jZ(Z=null,U){let[$,z]=i$(!1),H=RZ(null),J=RZ(null),T=RZ(null),G=BZ(async(W,V=!0)=>{if(H.current)X();let Q=new RTCPeerConnection;if(Q.onconnectionstatechange=()=>{if(Q.connectionState==="connected")z(!0);else if(["disconnected","failed","closed"].includes(Q.connectionState))z(!1)},Q.ontrack=(Y)=>{if(Z)Z.srcObject=Y.streams[0]},V){let Y=await navigator.mediaDevices.getUserMedia({audio:!0});Q.addTrack(Y.getTracks()[0],Y)}else{let Y=r$();Q.addTrack(Y)}let q=Q.createDataChannel("oai-events");J.current=q,T.current=new Promise((Y)=>{q.addEventListener("open",()=>{Y()})});let F=await Q.createOffer();await Q.setLocalDescription(F);let A=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:F.sdp,headers:{Authorization:`Bearer ${W}`,"Content-Type":"application/sdp"}})).text();await Q.setRemoteDescription({type:"answer",sdp:A}),H.current=Q,await T.current},[Z]),X=BZ(()=>{let W=J.current;if(W)W.close();H.current?.getSenders()?.forEach((V)=>V.track?.stop()),H.current?.close(),z(!1),H.current=null,J.current=null,T.current=null},[Z]),B=BZ((W)=>{let V=J.current;if(!V){console.error("Data channel is not ready",W);return}let Q=new Date().toLocaleTimeString();if(W.event_id=W.event_id||crypto.randomUUID(),V.send(JSON.stringify(W)),!W.timestamp)W.timestamp=Q;U?.(W)},[U,Z]),_=BZ((W)=>{if(!J.current){console.error("Data channel is not ready");return}let Q=()=>{B({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:W}]}}),B({type:"response.create"})};if(T.current)T.current.then(Q);else Q()},[U,Z]);return s$(()=>{let W=J.current;if(!W)return;let V=(Q)=>{let q=JSON.parse(Q.data);if(!q.timestamp)q.timestamp=new Date().toLocaleTimeString();U?.(q)};return W.addEventListener("message",V),()=>{W.removeEventListener("message",V)}},[U,Z]),{isSessionActive:$,startSession:G,stopSession:X,sendTextMessage:_}}import{jsx as Zz}from"react/jsx-runtime";var e$=({data:Z})=>{let{html:U,useSocketioSupport:$,useCentrifugeSupport:z,useMittSupport:H,centrifugeChannel:J}=Z,[T,G]=n$(U),{isSessionActive:X,startSession:B,sendTextMessage:_}=jZ(null,(q)=>{if(console.log(q.type,q.type==="response.output_text.delta"&&q.delta),q.type==="response.output_text.delta"&&q.delta)G((F)=>F+q.delta)});return a$(()=>{G(U)},[U]),Zz(M,{card:"HTMLEmbedCard",data:Z,methods:{update:(q)=>{G(q.value)},generateUsingAI:async(q)=>{try{if(!X&&q.token)await B(q.token,!1);_(q.prompt)}catch(F){console.error("Failed to generate using AI",F)}},initializeAI:async(q)=>{if(!X&&q.token)await B(q.token,!1)}},useCentrifugeSupport:z,useSocketioSupport:$,useMittSupport:H,centrifugeChannel:J,children:t$(T)})},FU=e$;var Uz=O({name:"HTMLEmbedCard",component:FU,metadata:{author:"Swarm.ing"}});import{useEffect as $z,useState as zz}from"react";import{jsx as OU}from"react/jsx-runtime";var Hz=({data:Z})=>{let{name:U,value:$,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T}=Z,[G,X]=zz($);return $z(()=>{X($)},[$]),OU(M,{card:"HiddenCard",data:Z,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T,methods:{update:({value:B})=>{X(B)}},children:OU("input",{type:"hidden",id:U,name:U,value:G})})},IU=Hz;var Jz=O({name:"HiddenCard",component:IU,metadata:{author:"Swarm.ing"}});import{useContext as MU,useEffect as Gz}from"react";import{createContext as Tz}from"react";var Xz=I("@swarm.ing/pieui:context:navigate",()=>Tz(void 0)),b=Xz;import{jsx as Wz,Fragment as Bz}from"react/jsx-runtime";var Yz=({data:Z})=>{let{url:U}=Z,$=MU(b),z=MU(E);return Gz(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else $?.(U)},[U,$]),Wz(Bz,{children:z})},PU=Yz;var qz=O({name:"AutoRedirectCard",component:PU,metadata:{author:"Swarm.ing"}});import{Bounce as Qz,Slide as _z,Zoom as Vz,Flip as Dz}from"react-toastify";import{toast as Kz,ToastContainer as Fz}from"react-toastify";import{useContext as Oz,useMemo as Iz,useRef as Mz}from"react";import{jsx as EZ,Fragment as Rz}from"react/jsx-runtime";var Pz={bounce:Qz,slide:_z,zoom:Vz,flip:Dz},Az=(Z)=>{let U={...Z,type:Z.alertType,transition:Z.transition?Pz[Z.transition]:void 0,position:Z.position??"bottom-right",autoClose:Z.autoClose??3000,style:{backgroundColor:"black",...Z.sx}};Kz(Z.message,U)},wz=(Z)=>{console.log("Log event",Z)},Nz=(Z)=>{if(typeof window>"u"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let U=()=>{try{new window.Notification(Z.title,{body:Z.message??Z.subtitle,icon:Z.icon,silent:Z.silent})}catch(z){console.error("[IOEventsCard] Failed to show notification",z)}},$=window.Notification.permission;if($==="granted"){U();return}if($==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((z)=>{if(z==="granted")U()})},Lz=({data:Z})=>{let{useCentrifugeSupport:U,useSocketioSupport:$,useMittSupport:z,centrifugeChannel:H}=Z,J=Oz(b),T=Mz(J);T.current=J;let G=Iz(()=>({alert:Az,log:wz,push:Nz,redirect:(X)=>{if(X.to){let B=X.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()},reload:(X)=>{if(X.to){let B=X.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()}}),[]);return EZ(Rz,{children:EZ(M,{card:"IOEventsCard",data:Z,useCentrifugeSupport:U,useSocketioSupport:$,useMittSupport:z,centrifugeChannel:H,methods:G,children:EZ(Fz,{})})})},AU=Lz;var jz=O({name:"IOEventsCard",component:AU,metadata:{author:"Swarm.ing"}});import{useEffect as wU,useState as Ez}from"react";import{jsx as NU}from"react/jsx-runtime";var Cz=({data:Z})=>{let{name:U,key:$,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G}=Z,[X,B]=Ez(z);return wU(()=>{B(z)},[z]),wU(()=>{if(typeof window>"u")return;sessionStorage.setItem($,X)},[$,X]),NU(M,{card:"SessionStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G,methods:{update:({value:_})=>{B(_)},remove:()=>{sessionStorage.removeItem($),B("")}},children:NU("input",{type:"hidden",id:U,name:U,value:X})})},LU=Cz;var xz=O({name:"SessionStorageCard",component:LU,metadata:{author:"PieData"}});import{useEffect as RU,useState as yz}from"react";import{jsx as jU}from"react/jsx-runtime";var fz=({data:Z})=>{let{name:U,key:$,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G}=Z,[X,B]=yz(z);return RU(()=>{B(z)},[z]),RU(()=>{if(typeof window>"u")return;localStorage.setItem($,X)},[$,X]),jU(M,{card:"DeviceStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G,methods:{update:({value:_})=>{B(_)},remove:()=>{localStorage.removeItem($),B("")}},children:jU("input",{type:"hidden",id:U,name:U,value:X})})},EU=fz;var bz=O({name:"DeviceStorageCard",component:EU,metadata:{author:"PieData"}});import{useCallback as CZ,useContext as xZ,useEffect as kz,useRef as Sz,useState as CU}from"react";import{jsx as xU}from"react/jsx-runtime";var mz=({data:Z,content:U})=>{let{useLoader:$,noReturn:z,returnType:H,useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:G,centrifugeChannel:X}=Z,B=xZ(E),_=xZ(C)??j,[W,V]=CU(!1),[Q,q]=CU(null),F=Sz(U),w=xZ(v),D=CZ((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)F.current=Y;if(!z)q(Y)},[z]),P=CZ((Y)=>{F.current=Y.content,q(Y.content)},[]),A=CZ((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)for(let K of Y)w?.emit(K.name,K.data)},[z,w]);if(kz(()=>{q(U),V(!1)},[U]),!Q&&$)return B;return xU(M,{card:"AjaxGroupCard",data:Z,methods:{changeContent:P},useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:G,centrifugeChannel:X,children:xU(_,{uiConfig:Q??F.current,setUiAjaxConfiguration:H==="events"?A:D})})},yU=mz;var vz=O({name:"AjaxGroupCard",component:yU,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});import{useContext as fU}from"react";import{jsx as yZ}from"react/jsx-runtime";var hz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,url:H,sx:J}=Z,T=fU(b),G=fU(C)??j;return yZ(M,{card:z,data:Z,children:yZ("div",{style:J,id:z,onClick:(B)=>{if(H)if(B.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(H))window.location.href=H;else T?.(H)},children:yZ(G,{setUiAjaxConfiguration:$,uiConfig:U})})})},bU=hz;var gz=O({name:"BoxCard",component:bU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as pz}from"react";import{jsx as fZ}from"react/jsx-runtime";var dz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,sx:H}=Z,J=pz(C)??j;return fZ(M,{card:z,data:Z,children:fZ("div",{style:H,id:z,children:U.map((T,G)=>{return fZ(J,{uiConfig:T,setUiAjaxConfiguration:$},`children-${G}`)})})})},kU=dz;var uz=O({name:"OneOfCard",component:kU,metadata:{author:"Swarm.ing",description:"Different variants"}});import{useMemo as UZ}from"react";import{QueryClient as ez,QueryClientProvider as Z0,useQuery as U0}from"@tanstack/react-query";import{useContext as oz,useEffect as sz,useRef as bZ}from"react";import{useEffect as cz,useState as lz}from"react";var WZ=new Map,qZ=new Map;function QZ(Z,U){let $=`${Z}::${U}`,z=Z?WZ.get($):void 0,[H,J]=lz(z??null);return cz(()=>{if(!Z)return;if(WZ.has($)){J(WZ.get($));return}let T=qZ.get($);if(!T)T=fetch(Z+`api/support/${U}`,{method:"GET"}).then((X)=>X.json()).then((X)=>{return WZ.set($,X),qZ.delete($),X}).catch((X)=>{throw qZ.delete($),X}),qZ.set($,T);let G=!1;return T.then((X)=>{if(!G)J(X)}).catch(()=>{}),()=>{G=!0}},[Z,U,$]),H}function i(Z,U){if(U==="up")return{state:"up",signal:Z==="down"?"restored":null};return{state:"down",signal:Z==="up"?"lost":null}}var iz=({children:Z})=>{let U=oz(m),$=zZ(),z=QZ($,"socketIO"),H=a(),J=n(),T=bZ(H);T.current=H;let G=bZ(J);G.current=J;let X=bZ("initial"),B=(_)=>{if(N.isClient())N.setSid(_.sid),tZ(),console.log(`SocketIO initialized: ${N.readSid()}`)};return sz(()=>{if(!U||!z)return;let _=()=>{let{state:V,signal:Q}=i(X.current,"up");if(X.current=V,Q==="restored")G.current?.("socketio");console.log("SocketIO connected")},W=(V)=>{if(console.log(`SocketIO disconnected: ${V}`),U.connect(),V==="io client disconnect")return;let{state:Q,signal:q}=i(X.current,"down");if(X.current=Q,q==="lost")T.current?.("socketio",V)};return U.on("pieinit",B),U.on("connect",_),U.on("disconnect",W),U.connect(),()=>{U.off("pieinit",B),U.off("connect",_),U.off("disconnect",W),U.disconnect()}},[U,z]),Z},_Z=iz;import{useContext as rz,useEffect as az,useRef as kZ}from"react";var nz=({children:Z})=>{let U=rz(S),$=zZ(),z=QZ($,"centrifuge"),H=a(),J=n(),T=kZ(H);T.current=H;let G=kZ(J);G.current=J;let X=kZ("initial");return az(()=>{if(!U||!z)return;let B=(V)=>{let{state:Q,signal:q}=i(X.current,"down");if(X.current=Q,q==="lost")T.current?.("centrifuge",V)},_=()=>{let{state:V,signal:Q}=i(X.current,"up");if(X.current=V,Q==="restored")G.current?.("centrifuge");console.log("Centrifuge connected")},W=(V)=>{console.log("Centrifuge disconnected:",V),B(V)};return U.on("connecting",B),U.on("connected",_),U.on("disconnected",W),U.connect(),()=>{U.off("connecting",B),U.off("connected",_),U.off("disconnected",W),U.disconnect()}},[U,z]),Z},VZ=nz;import{createAxiosDateTransformer as $0}from"axios-date-transformer";import{jsx as tz}from"react/jsx-runtime";function SU(Z,U,$){if(!U)return $;let z=Z.replace(/^\//,""),H=U[z];if(!H)return $;return tz(NZ,{uiConfig:H})}import{jsx as L,Fragment as J0}from"react/jsx-runtime";var z0=({location:Z,fallback:U,piecache:$,onError:z,queryOptions:H,disableGlobalForm:J})=>{let T=r(),G=HZ(),X=k(),B=UZ(()=>$0({baseURL:T||""}),[T]),_=UZ(()=>p(),[]),W=UZ(()=>T?TZ(T):null,[T]),V=UZ(()=>T?JZ(T,G):null,[T,G]),{data:Q,isLoading:q,error:F}=U0({queryKey:["uiConfig",Z.pathname+Z.search,T],enabled:!!T,queryFn:async()=>{let D=new URLSearchParams(Z.search);D.set("__pieroot","web");let P="/api/content"+Z.pathname+"?"+D.toString();if(X)console.log("[PieRoot] Fetching UI configuration from:",P);let A=await B.get(P,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(X)console.log("[PieRoot] Received UI configuration:",A.data);return A.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(D)=>Math.min(1000*2**D,30000),...H}),w=SU(Z.pathname,$,U);if(!T)return w??null;if(X)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",T),console.log("[PieRoot] CENTRIFUGE_SERVER:",G),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!$);if(F){if(X)console.error("[PieRoot] Error fetching UI configuration:",F),console.error("[PieRoot] Error details:",{message:F.message,status:F.response?.status,data:F.response?.data});return z?.(F),w}if(q||!Q){if(X)console.log("[PieRoot] Loading state:",{isLoading:q,hasUiConfiguration:!!Q});return w}if(X)console.log("[PieRoot] UI configuration loaded successfully:",Q),console.log("[PieRoot] Rendering UI with configuration");return L(v.Provider,{value:_,children:L(m.Provider,{value:W,children:L(S.Provider,{value:V,children:L(E.Provider,{value:U??L(J0,{}),children:L(_Z,{children:L(VZ,{children:J?L(j,{uiConfig:Q}):L("form",{id:"piedata_global_form",action:T+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:L(j,{uiConfig:Q})})})})})})})})},H0=(Z)=>{let U=UZ(()=>new ez,[]),$=Z.queryClient??U;return L(b.Provider,{value:Z.onNavigate,children:L(o.Provider,{value:Z.config,children:L(d.Provider,{value:Z.onError,children:L(Z0,{client:$,children:L(z0,{...Z})})})})})},SZ=H0;import{useMemo as mZ,useState as T0}from"react";import{QueryClient as X0,QueryClientProvider as G0}from"@tanstack/react-query";import{jsx as x,Fragment as W0}from"react/jsx-runtime";var Y0=({location:Z,fallback:U,children:$,disableGlobalForm:z})=>{let H=r(),J=HZ(),T=k(),G=mZ(()=>p(),[]),X=mZ(()=>H?TZ(H):null,[H]),B=mZ(()=>H?JZ(H,J):null,[H,J]);if(T)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",J),console.log("[PieRoot] Fallback provided:",!!U);return x(v.Provider,{value:G,children:x(m.Provider,{value:X,children:x(S.Provider,{value:B,children:x(E.Provider,{value:U??x(W0,{}),children:x(_Z,{children:x(VZ,{children:z?$:x("form",{id:"piedata_global_form",action:H+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:$})})})})})})})},B0=(Z)=>{let[U]=T0(()=>new X0),$=Z.queryClient??U;return x(b.Provider,{value:Z.onNavigate,children:x(o.Provider,{value:Z.config,children:x(d.Provider,{value:Z.onError,children:x(G0,{client:$,children:x(Y0,{...Z})})})})})},q0=B0;import{useEffect as Q0,useMemo as _0}from"react";import{jsx as mU}from"react/jsx-runtime";var V0=mU("div",{style:{padding:16,fontFamily:"system-ui, sans-serif",color:"#888"},children:"Loading card…"}),D0=({apiServer:Z,pathname:U="/",search:$="",centrifugeServer:z,previewEvents:H=!1,fallback:J,enableRenderingLog:T=!1})=>{let G=Z??(typeof process<"u"?process.env.PIE_API_SERVER:void 0)??"";Q0(()=>{if(!H||!G||typeof window>"u"||typeof EventSource>"u")return;let _=G.endsWith("/")?G:`${G}/`,W=new EventSource(`${_}api/preview/events`),V=p();return W.onmessage=(Q)=>{try{let q=JSON.parse(Q.data);if(q&&typeof q.name==="string")V.emit(q.name,q.payload)}catch{}},()=>W.close()},[H,G]);let X=_0(()=>({apiServer:G,centrifugeServer:z,enableRenderingLog:T,pageProcessor:"web"}),[G,z,T]);return mU(SZ,{location:{pathname:U,search:$},config:X,fallback:J??V0,onNavigate:(_)=>{if(typeof window<"u")window.history.pushState(null,"",_)}})},K0=D0;import{clsx as F0}from"clsx";import{twMerge as O0}from"tailwind-merge";function I0(...Z){return O0(F0(Z))}var M0=()=>{$U(),N.submitGlobalForm()};var P0=(Z,U)=>`${Z}${OZ}${U}`;export{tU as usePieEmit,n as useOnLinkRestored,a as useOnLinkLost,q$ as useAjaxSubmits,W$ as useAjaxSubmit,I$ as unregisterComponent,AZ as trackLazy,M0 as submitGlobalForm,f as registry,O as registerPieComponent,O$ as registerMultipleComponents,HU as readAjaxKeyAsync,zU as readAjaxKey,WU as preloadComponent,N$ as prefetchLazyComponents,P0 as pieName,XZ as parseDepName,M$ as hasComponent,w$ as getRegistrySize,ZZ as getRegistryEntry,BU as getLazyComponentNames,p as getEmitter,P$ as getComponentMeta,A$ as getAllRegisteredComponents,TU as discoverAjaxEndpoints,I0 as cn,o$ as UnionCard,C as UIRendererContext,NZ as UILoading,j as UI,m as SocketIOContext,xz as SessionStorageCard,u$ as SequenceCard,SZ as PieRoot,K0 as PiePreviewRoot,o as PieConfigContext,M as PieCard,q0 as PieBaseRoot,OZ as PIEBREAK,uz as OneOfCard,v as MittContext,jz as IOEventsCard,Jz as HiddenCard,Uz as HTMLEmbedCard,E as FallbackContext,bz as DeviceStorageCard,S as CentrifugeIOContext,gz as BoxCard,qz as AutoRedirectCard,vz as AjaxGroupCard};
|
|
2
|
+
import{useContext as MZ,useEffect as GZ,useRef as PZ}from"react";import{createContext as u$,useContext as c$}from"react";var FZ=globalThis,I=(Z,$)=>{let U=Symbol.for(Z);if(!(U in FZ))FZ[U]=$();return FZ[U]};var o=I("@swarm.ing/pieui:context:pieConfig",()=>u$(null)),g=()=>{let Z=c$(o);if(!Z)throw Error("usePieConfig must be used within PieConfigProvider");return Z},r=()=>{let{apiServer:Z}=g();return Z},zZ=r,HZ=()=>{let{centrifugeServer:Z}=g();return Z};var f=()=>{let{enableRenderingLog:Z}=g();return Z},pZ=f;var a=()=>{let{onLinkLost:Z}=g();return Z},n=()=>{let{onLinkRestored:Z}=g();return Z},OZ="__piedemo__";import{createContext as l$}from"react";import{Centrifuge as dZ}from"centrifuge";var uZ=I("@swarm.ing/pieui:centrifuge-cache",()=>new Map),JZ=(Z,$)=>{if(!$)return null;let U=`${Z}::${$}`,z=uZ.get(U);if(z)return z;async function H(){let T=await fetch(Z+"api/centrifuge/gen_token",{credentials:"include"});if(!T.ok){if(T.status===401||T.status===403)throw new dZ.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${T.status}`)}return(await T.json()).token}let J=new dZ($,{getToken:H});return uZ.set(U,J),J},o$=I("@swarm.ing/pieui:context:centrifuge",()=>l$(null)),S=o$;import{io as s$}from"socket.io-client";import{createContext as i$}from"react";var cZ=I("@swarm.ing/pieui:socket-cache",()=>new Map),TZ=(Z)=>{let $=cZ.get(Z);if($)return $;let U=s$(Z,{autoConnect:!1,transports:["websocket"]});return cZ.set(Z,U),U},r$=I("@swarm.ing/pieui:context:socket",()=>i$(null)),m=r$;import a$ from"mitt";import{createContext as n$,useCallback as t$,useContext as e$}from"react";function p(){return I("@swarm.ing/pieui:mitt-emitter",()=>a$())}var lZ=I("@swarm.ing/pieui:context:mitt",()=>n$(null));function ZU(Z){let $=e$(lZ);return t$((U,z)=>{($??p()).emit(`pie${U}_${Z}`,z)},[Z,$])}var v=lZ;function oZ(Z){return Z.wasRecovering===!0&&Z.recovered===!1}function sZ(Z){return Z.recoverable===!1}function iZ(Z,$,U){let z=Z.getSubscription($);if(z)return{subscription:z,createdHere:!1};return{subscription:Z.newSubscription($,U),createdHere:!0}}var $U=(Z)=>{let $=document.cookie?document.cookie.split(";"):[];for(let U of $){let z=U.indexOf("=");if((z===-1?U:U.slice(0,z)).trim()===Z){let J=z===-1?"":U.slice(z+1).trim();try{return decodeURIComponent(J)}catch{return J}}}return null},UU={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(Z){if(typeof window<"u")window.sid=Z},readWebStorage(Z,$){return(Z==="local"?window.localStorage:window.sessionStorage).getItem($)},readCookie:$U,readUrlParams(Z){return new URLSearchParams(window.location.search).getAll(Z)},readDomInput(Z){let $=document.getElementsByName(Z);if(!$.length)return null;let U=$[0];if(U instanceof HTMLInputElement){if(U.type==="file"&&U.files)return Array.from(U.files);return[U.value]}if(U instanceof HTMLTextAreaElement)return[U.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let Z=document.getElementById("piedata_global_form");Z&&Z.submit()}},rZ=UU;var zU={};function c(){return zU}var aZ=new Map;var nZ=(Z)=>{return aZ.has(Z)?aZ.get(Z):null};var tZ,HU={isClient(){return!0},readSid(){return tZ},setSid(Z){tZ=Z},readWebStorage(Z,$){let U=c(),z=Z==="local"?U.storage:U.sessionStorage;return z?z.getItem($):null},async readWebStorageAsync(Z,$){let U=c(),z=Z==="local"?U.asyncStorage:U.asyncSessionStorage;if(z)return z.getItem($);let H=Z==="local"?U.storage:U.sessionStorage;return H?H.getItem($):null},readCookie(Z){let $=c();return $.getCookie?$.getCookie(Z):null},readUrlParams(Z){let $=c();return $.getRouteParams?$.getRouteParams(Z):[]},readDomInput(Z){let $=c();return $.getInput?$.getInput(Z):nZ(Z)},submitGlobalForm(){c().submitForm?.()}},eZ=HU;var JU=typeof navigator<"u"&&navigator.product==="ReactNative",TU=JU?eZ:rZ,N=TU;var t=I("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function Z$(){t.resolve?.()}function IZ(){if(!N.isClient())return Promise.resolve();if(N.readSid()!==void 0)return Promise.resolve();if(!t.promise)t.promise=new Promise((Z)=>{t.resolve=()=>{Z()}});return t.promise}import{useMemo as $$}from"react";var XU=["localStorage","sessionStorage","cookie","url","telegram:cloud","telegram:secure"],GU=new Set(["telegram:cloud","telegram:secure"]),e=new Map,U$=(Z,$)=>{e.set(Z,$)},z$=(Z)=>{e.delete(Z)},H$=(Z="piedata_global_form")=>{let $;if(typeof Z==="string"){if(typeof document>"u")return;$=document.getElementById(Z)}else $=Z;if(!$)return;let U=$.ownerDocument;for(let z of Array.from($.getElementsByTagName("input")))if(z.getAttribute("data-pie-stored")!==null)z.remove();for(let[z,H]of e){let J=H();if(J instanceof Promise)continue;for(let T of J){if(typeof T!=="string")continue;let X=U.createElement("input");X.type="hidden",X.name=z,X.value=T,X.setAttribute("data-pie-stored","1"),$.appendChild(X)}}},XZ=(Z)=>{if(Z==="sid")return{source:"sid",key:"sid"};for(let $ of XU){let U=$+":";if(Z.startsWith(U))return{source:$,key:Z.slice(U.length)}}return{source:"dom",key:Z}},J$=(Z,$=!1)=>{let{source:U,key:z}=XZ(Z);if(U==="sid"){let T=N.readSid();if(!T)throw Error("SocketIO isn't initialized properly");return[T]}if(U==="localStorage"||U==="sessionStorage")try{let T=N.readWebStorage(U==="localStorage"?"local":"session",z);if(T===null){if($)console.warn(`No ${U} value found for key ${z}`);return[]}return[T]}catch(T){if($)console.warn(`Failed to read ${U} key ${z}:`,T);return[]}if(U==="cookie"){let T=N.readCookie(z);if(T===null){if($)console.warn(`No cookie found for key ${z}`);return[]}return[T]}if(U==="url"){let T=N.readUrlParams(z);if(!T.length&&$)console.warn(`No URL query param found for key ${z}`);return T}if(GU.has(U)){if($)console.warn(`Source ${U} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}let H=e.get(z);if(H){let T=H();if(T instanceof Promise){if($)console.warn(`stored resolver for ${z} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}return T}let J=N.readDomInput(z);if(J===null){if($)console.warn(`No input found with name ${z}`);return[]}return J},YU=(Z,$,U)=>{let z=window.Telegram?.WebApp,H=Z==="telegram:cloud"?z?.CloudStorage:z?.SecureStorage,J=Z==="telegram:cloud"?"Telegram CloudStorage":"Telegram SecureStorage";if(!H){if(U)console.warn(`${J} is not available`);return Promise.resolve([])}return new Promise((T)=>{try{H.getItem($,(X,G)=>{if(X){if(U)console.warn(`Failed to read ${J} key ${$}:`,X);T([]);return}if(G==null||G===""){if(U)console.warn(`No ${J} value found for key ${$}`);T([]);return}T([G])})}catch(X){if(U)console.warn(`Failed to read ${J} key ${$}:`,X);T([])}})},T$=async(Z,$=!1)=>{let{source:U,key:z}=XZ(Z);if(U==="telegram:cloud"||U==="telegram:secure")return YU(U,z,$);if((U==="localStorage"||U==="sessionStorage")&&N.readWebStorageAsync)try{let H=await N.readWebStorageAsync(U==="localStorage"?"local":"session",z);if(H===null){if($)console.warn(`No ${U} value found for key ${z}`);return[]}return[H]}catch(H){if($)console.warn(`Failed to read ${U} key ${z}:`,H);return[]}if(U==="dom"){let H=e.get(z);if(H)return H()}return J$(Z,$)},BU=(Z)=>{if(!Z)return[];if(Array.isArray(Z))return Z.map(([$,U])=>[String($),String(U)]);if(typeof Z.forEach==="function"){let $=[];return Z.forEach((U,z)=>$.push([z,U])),$}return Object.entries(Z)},WU=(Z)=>{let $=Z.filter(Boolean);if($.length===0)return;if($.length===1)return $[0];let U=AbortSignal.any;if(typeof U==="function")return U.call(AbortSignal,$);let z=new AbortController;for(let H of $){if(H.aborted){z.abort(H.reason);break}H.addEventListener("abort",()=>z.abort(H.reason),{once:!0})}return z.signal},QU=(Z,$,U)=>{let z={method:"POST",credentials:"include"},H={},J=[$];for(let X of U){if(!X)continue;let{headers:G,signal:B,body:q,...Q}=X;Object.assign(z,Q);for(let[V,_]of BU(G))H[V.toLowerCase()]=_;J.push(B)}if(z.body=Z,Object.keys(H).length>0)z.headers=H;let T=WU(J);if(T)z.signal=T;return z},X$=(Z,$={},U=[],z,H)=>{let J=H?.renderingLogEnabled??!1,T=H?.timeout,X=H?.retryPolicy,G=X?.maxRetries??0,B=X?.baseDelay??1000,q=X?.retryOn??[502,503,504];if(J)console.log("Registering AJAX: ",z,$,U);return async(Q={},V)=>{if(!N.isClient()){if(J)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let _=H?.apiServer;if(!_){if(J)console.warn("AJAX skipped: apiServer is missing");return}if(!z||!Z){if(J)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(U.includes("sid"))await IZ();let W=new FormData;for(let[K,O]of Object.entries({...$,...Q}))W.append(K,O);for(let K of U){let{key:O}=XZ(K);for(let w of await T$(K,J))W.append(O,w)}let M=_+"api/ajax_content"+z;Z(null);let P;for(let K=0;K<=G;K++){if(K>0){let Y=B*2**(K-1);if(J)console.log(`AJAX retry ${K}/${G} after ${Y}ms`);await new Promise((D)=>setTimeout(D,Y))}let O=T!=null?new AbortController:null,w=O&&setTimeout(()=>O.abort(),T);try{let Y=await fetch(M,QU(W,O?.signal,[H?.fetchOptions,V]));if(w)clearTimeout(w);if(!Y.ok&&q.includes(Y.status)&&K<G){P=Error(`HTTP ${Y.status}`);continue}let R=(Y.headers.get("content-type")||"").includes("application/json");if(!!Y.body?.getReader&&!R){let u=Y.body.getReader(),UZ=new TextDecoder,y="";while(!0){let{done:DZ,value:g$}=await u.read();if(DZ)break;y+=UZ.decode(g$,{stream:!0});let gZ=y.split(`
|
|
3
|
+
`);y=gZ.pop()??"";for(let p$ of gZ){let KZ=p$.trim();if(!KZ)continue;try{let d$=JSON.parse(KZ);Z([d$])}catch{if(J)console.warn("Failed to parse streamed line:",KZ)}}}if(y.trim())try{let DZ=JSON.parse(y);Z([DZ])}catch{if(J)console.warn("Failed to parse final streamed line:",y)}return{}}else{let u=await Y.json();return Z(u),u}}catch(Y){if(w)clearTimeout(w);if(P=Y,K<G)continue;if(J)console.error("AJAX request failed:",Y);return Z(null),Y}}if(J)console.error("AJAX request failed after retries:",P);return Z(null),P}},qU=(Z,$={},U=[],z,H)=>{let{apiServer:J,enableRenderingLog:T}=g(),X=JSON.stringify($),G=JSON.stringify(U),B=JSON.stringify(H);return $$(()=>X$(Z,$,U,z,{apiServer:J,renderingLogEnabled:T,timeout:H?.timeout,retryPolicy:H?.retryPolicy,fetchOptions:H?.fetchOptions}),[Z,X,G,z,J,T,B])},G$=(Z={})=>{let $=[];for(let U of Object.keys(Z??{})){let z=null;if(U==="pathname")z="default";else if(U.endsWith("Pathname"))z=U.slice(0,-8);if(z===null)continue;let H=z==="default"?"":z;$.push({key:z,pathname:Z[U],depsNames:Z[H?`${H}DepsNames`:"depsNames"]??[],kwargs:Z[H?`${H}Kwargs`:"kwargs"]??{}})}return $},_U=(Z={},$,U)=>{let{apiServer:z,enableRenderingLog:H}=g(),J=JSON.stringify(Z??{}),T=JSON.stringify(U);return $$(()=>{let X={};for(let G of G$(Z??{}))X[G.key]=X$($,G.kwargs,G.depsNames,G.pathname,{apiServer:z,renderingLogEnabled:H,timeout:U?.timeout,retryPolicy:U?.retryPolicy,fetchOptions:U?.fetchOptions});return X},[J,$,z,H,T])};import{jsx as KU,jsxs as FU,Fragment as DU}from"react/jsx-runtime";var VU=({card:Z,data:$,children:U,useSocketioSupport:z=!1,useCentrifugeSupport:H=!1,useMittSupport:J=!1,centrifugeChannel:T=void 0,methods:X=void 0,stored:G=void 0,onResync:B=void 0})=>{let q=pZ(),Q=PZ(X);Q.current=X;let V=PZ(B);V.current=B;let _=PZ(G);_.current=G;let W=typeof G==="function";if(GZ(()=>{if(!W)return;let O=$.name;return U$(O,()=>[JSON.stringify(_.current())]),()=>z$(O)},[W,$.name]),q)console.log("[PieCard] Rendering card:",Z),console.log("[PieCard] Card data:",$),console.log("[PieCard] Component name:",$?.name),console.log("[PieCard] Real-time support:",{socketio:z,centrifuge:H,mitt:J,centrifugeChannel:T}),console.log("[PieCard] Methods:",X?Object.keys(X):"none"),console.log("[PieCard] Has children:",!!U);let M=MZ(m),P=MZ(S),K=MZ(v);if(GZ(()=>{if(!M||!z||!Q.current||!$.name){if(q&&z)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!M,useSocketioSupport:z,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let w=Object.keys(Q.current??{}).map((Y)=>{let D=`pie${Y}_${$.name}`;if(q)console.log(`[PieCard] Socket.IO registering event: ${D}`);let R=(h)=>{Q.current?.[Y]?.(h)};return M.on(D,R),[D,R]});return()=>{w.forEach(([Y,D])=>{if(q)console.log(`[PieCard] Socket.IO unregistering event: ${Y}`);M.off(Y,D)})}},[M,$.name,z]),GZ(()=>{if(!P||!H||!T||!$.name){if(q&&H)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!P,useCentrifugeSupport:H,hasCentrifugeChannel:!!T,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let w=Object.keys(Q.current??{}).map((Y)=>{let D=`pie${Y}_${$.name}_${T}`;if(q)console.log(`[PieCard] Centrifuge subscribing to channel: ${D}`);let{subscription:R,createdHere:h}=iZ(P,D,{recoverable:!0,positioned:!0}),u=(y)=>{if(q)console.log(`[PieCard] Centrifuge received data on ${D}:`,y.data);Q.current?.[Y]?.(y.data)},UZ=(y)=>{if(sZ(y))console.warn(`[PieCard] Centrifuge channel ${D} is not `+"recoverable — enable history on the server "+"namespace for exact replay; relying on resync fallback only.");if(oZ(y)){if(q)console.log(`[PieCard] Centrifuge recovery gap on ${D}; requesting resync`);V.current?.({channel:D,reason:"gap"})}};return R.on("publication",u),R.on("subscribed",UZ),R.subscribe(),{subscription:R,createdHere:h,onPublication:u,onSubscribed:UZ}});return()=>{w.forEach(({subscription:Y,createdHere:D,onPublication:R,onSubscribed:h})=>{if(q)console.log("[PieCard] Centrifuge unsubscribing from channel");if(Y.off("publication",R),Y.off("subscribed",h),D)Y.unsubscribe(),P.removeSubscription(Y)})}},[P,T,$.name,H]),GZ(()=>{if(!K||!J||!$.name){if(q&&J)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!K,useMittSupport:J,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let O=Object.keys(Q.current??{}),w={};return O.forEach((Y)=>{let D=`pie${Y}_${$.name}`,R=(h)=>{if(q)console.log(`[PieCard] Mitt registering event: ${D}`);Q.current?.[Y]?.(h)};w[D]=R,K.on(D,R)}),()=>{Object.entries(w).forEach(([Y,D])=>{if(q)console.log(`[PieCard] Mitt unregistering event: ${Y}`);K.off(Y,D)})}},[K,$.name,J]),q)console.log("[PieCard] Rendering complete, returning children");if(G!==void 0&&!W)return FU(DU,{children:[KU("input",{type:"hidden",name:$.name,value:JSON.stringify(G)}),U]});return U},A=VU;import{lazy as OU}from"react";var l=new Map;function Y$(Z,$){return $.catch(()=>{if(l.get(Z)===$)l.delete(Z)}),l.set(Z,$),$}function AZ(Z,$){return OU(()=>{if(l.has($))return l.get($);return Y$($,Z().then((U)=>U))})}var B$=async(Z,$)=>{if(!$)return;if(l.has(Z))return l.get(Z);return Y$(Z,$().then((U)=>U))};var b=I("@swarm.ing/pieui:component-registry",()=>new Map),IU=(Z)=>{if(!Z.name)throw Error("Component registration requires a name");if(!Z.component&&!Z.loader)throw Error(`Component "${Z.name}" requires component or loader`);let $={name:Z.name,component:Z.component,loader:Z.loader,metadata:Z.metadata,fallback:Z.fallback,isLazy:!1};if(!$.component&&$.loader)$.component=AZ($.loader,Z.name),$.isLazy=!0;return $};function F(Z){let $=IU(Z);return b.set($.name,$),$.component}var MU=(Z)=>{Z.forEach(($)=>F($))},PU=(Z)=>{b.delete(Z)},AU=(Z)=>{return b.has(Z)},wU=(Z)=>{return b.get(Z)?.metadata},ZZ=(Z)=>{return b.get(Z)},NU=()=>{return Array.from(b.keys())},LU=()=>{return b.size},Q$=()=>Array.from(b.values()).filter((Z)=>Z.isLazy&&typeof Z.loader==="function").map((Z)=>Z.name),q$=(Z)=>{let $=b.get(Z);if(!$?.isLazy||typeof $.loader!=="function")return;return B$(Z,$.loader)},W$=!1,RU=()=>{if(W$||typeof window>"u")return;W$=!0;let Z=navigator.connection;if(Z?.saveData)return;if(Z?.effectiveType&&["slow-2g","2g"].includes(Z.effectiveType))return;let $=Q$(),U="requestIdleCallback"in window?(H)=>window.requestIdleCallback(H,{timeout:2000}):(H)=>window.setTimeout(H,300),z=(H)=>{if(H>=$.length)return;U(()=>{Promise.resolve().then(()=>q$($[H])).catch(()=>{}).finally(()=>z(H+1))})};z(0)};import{useContext as _$,memo as hU}from"react";import{createContext as jU}from"react";import{jsx as xU,Fragment as CU}from"react/jsx-runtime";var EU=I("@swarm.ing/pieui:context:fallback",()=>jU(xU(CU,{}))),E=EU;import{createContext as yU}from"react";var bU=I("@swarm.ing/pieui:context:lazyError",()=>yU(void 0)),d=bU;import{Component as kU,Suspense as fU}from"react";import{jsx as vU}from"react/jsx-runtime";var SU=2,mU=400;class s extends kU{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(Z){if(this.props.onError?.(Z),this.state.attempt<SU){let $=mU*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((U)=>({failed:!1,attempt:U.attempt+1}))},$)}}componentDidUpdate(Z){if(Z.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return vU(fU,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}import{jsx as wZ}from"react/jsx-runtime";function gU({uiConfig:Z,setUiAjaxConfiguration:$}){let U=_$(E),z=_$(d),H=f();if(H)console.log("[UI] Rendering component:",Z.card),console.log("[UI] Component data:",Z.data),console.log("[UI] Component content:",Z.content),console.log("[UI] Has setUiAjaxConfiguration:",!!$);let J=ZZ(Z.card);if(!J?.component){if(H)console.warn(`[UI] Component not found in registry: ${Z.card}`),console.log("[UI] Returning fallback component");return U}if(H)console.log("[UI] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata});let T=J.component,X=wZ(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:$});if(J.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",J.name);return wZ(s,{name:J.name,fallback:J.fallback?wZ(J.fallback,{}):U,onError:z,children:X})}if(H)console.log("[UI] Rendering component directly:",J.name);return X}var j=hU(gU);import{useContext as V$}from"react";import{createContext as pU}from"react";var dU=I("@swarm.ing/pieui:context:uiRenderer",()=>pU(null)),C=dU;import{jsx as YZ}from"react/jsx-runtime";function D$({uiConfig:Z,setUiAjaxConfiguration:$}){let U=V$(E),z=V$(d),H=f();if(H)console.log("[UILoading] Rendering fallback for:",Z.card),console.log("[UILoading] Component data:",Z.data),console.log("[UILoading] Component content:",Z.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!$);let J=ZZ(Z.card);if(!J?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${Z.card}`),console.log("[UILoading] Returning fallback component");return U}if(H)console.log("[UILoading] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata,hasFallback:!!J.fallback});if(J.fallback){if(H)console.log("[UILoading] Rendering fallback for:",J.name);let G=J.fallback;return YZ(G,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",J.name);let T=J.component,X=YZ(C.Provider,{value:D$,children:YZ(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:$})});if(J.isLazy)return YZ(s,{name:J.name,fallback:U,onError:z,children:X});return X}var NZ=D$;import{useContext as uU}from"react";import{jsx as LZ}from"react/jsx-runtime";var cU=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,sx:H}=Z,J=uU(C)??j;return LZ(A,{card:z,data:Z,children:LZ("div",{style:H,id:z,children:$.map((T,X)=>{return LZ(J,{uiConfig:T,setUiAjaxConfiguration:U},`children-${X}`)})})})},K$=cU;var lU=F({name:"SequenceCard",component:K$,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as oU}from"react";import{jsx as F$}from"react/jsx-runtime";var sU=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z}=Z,H=oU(C)??j;return F$(A,{card:z,data:Z,children:$.map((J,T)=>{return F$(H,{uiConfig:J,setUiAjaxConfiguration:U},`children-${T}`)})})},O$=sU;var iU=F({name:"UnionCard",component:O$,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});import{useEffect as tU,useState as eU}from"react";import Zz from"html-react-parser";import{useCallback as BZ,useEffect as rU,useRef as RZ,useState as aU}from"react";function nU(){let Z=new AudioContext,$=Z.createOscillator(),U=$.connect(Z.createMediaStreamDestination());$.start();let z=U.stream.getAudioTracks()[0];return z.enabled=!1,z}function jZ(Z=null,$){let[U,z]=aU(!1),H=RZ(null),J=RZ(null),T=RZ(null),X=BZ(async(Q,V=!0)=>{if(H.current)G();let _=new RTCPeerConnection;if(_.onconnectionstatechange=()=>{if(_.connectionState==="connected")z(!0);else if(["disconnected","failed","closed"].includes(_.connectionState))z(!1)},_.ontrack=(Y)=>{if(Z)Z.srcObject=Y.streams[0]},V){let Y=await navigator.mediaDevices.getUserMedia({audio:!0});_.addTrack(Y.getTracks()[0],Y)}else{let Y=nU();_.addTrack(Y)}let W=_.createDataChannel("oai-events");J.current=W,T.current=new Promise((Y)=>{W.addEventListener("open",()=>{Y()})});let M=await _.createOffer();await _.setLocalDescription(M);let w=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:M.sdp,headers:{Authorization:`Bearer ${Q}`,"Content-Type":"application/sdp"}})).text();await _.setRemoteDescription({type:"answer",sdp:w}),H.current=_,await T.current},[Z]),G=BZ(()=>{let Q=J.current;if(Q)Q.close();H.current?.getSenders()?.forEach((V)=>V.track?.stop()),H.current?.close(),z(!1),H.current=null,J.current=null,T.current=null},[Z]),B=BZ((Q)=>{let V=J.current;if(!V){console.error("Data channel is not ready",Q);return}let _=new Date().toLocaleTimeString();if(Q.event_id=Q.event_id||crypto.randomUUID(),V.send(JSON.stringify(Q)),!Q.timestamp)Q.timestamp=_;$?.(Q)},[$,Z]),q=BZ((Q)=>{if(!J.current){console.error("Data channel is not ready");return}let _=()=>{B({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:Q}]}}),B({type:"response.create"})};if(T.current)T.current.then(_);else _()},[$,Z]);return rU(()=>{let Q=J.current;if(!Q)return;let V=(_)=>{let W=JSON.parse(_.data);if(!W.timestamp)W.timestamp=new Date().toLocaleTimeString();$?.(W)};return Q.addEventListener("message",V),()=>{Q.removeEventListener("message",V)}},[$,Z]),{isSessionActive:U,startSession:X,stopSession:G,sendTextMessage:q}}import{jsx as Uz}from"react/jsx-runtime";var $z=({data:Z})=>{let{html:$,useSocketioSupport:U,useCentrifugeSupport:z,useMittSupport:H,centrifugeChannel:J}=Z,[T,X]=eU($),{isSessionActive:G,startSession:B,sendTextMessage:q}=jZ(null,(W)=>{if(console.log(W.type,W.type==="response.output_text.delta"&&W.delta),W.type==="response.output_text.delta"&&W.delta)X((M)=>M+W.delta)});return tU(()=>{X($)},[$]),Uz(A,{card:"HTMLEmbedCard",data:Z,methods:{update:(W)=>{X(W.value)},generateUsingAI:async(W)=>{try{if(!G&&W.token)await B(W.token,!1);q(W.prompt)}catch(M){console.error("Failed to generate using AI",M)}},initializeAI:async(W)=>{if(!G&&W.token)await B(W.token,!1)}},useCentrifugeSupport:z,useSocketioSupport:U,useMittSupport:H,centrifugeChannel:J,children:Zz(T)})},I$=$z;var zz=F({name:"HTMLEmbedCard",component:I$,metadata:{author:"Swarm.ing"}});import{useEffect as Hz,useState as Jz}from"react";import{jsx as M$}from"react/jsx-runtime";var Tz=({data:Z})=>{let{name:$,value:U,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T}=Z,[X,G]=Jz(U);return Hz(()=>{G(U)},[U]),M$(A,{card:"HiddenCard",data:Z,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T,methods:{update:({value:B})=>{G(B)}},children:M$("input",{type:"hidden",id:$,name:$,value:X})})},P$=Tz;var Xz=F({name:"HiddenCard",component:P$,metadata:{author:"Swarm.ing"}});import{useContext as A$,useEffect as Bz}from"react";import{createContext as Gz}from"react";var Yz=I("@swarm.ing/pieui:context:navigate",()=>Gz(void 0)),k=Yz;import{jsx as qz,Fragment as Qz}from"react/jsx-runtime";var Wz=({data:Z})=>{let{url:$}=Z,U=A$(k),z=A$(E);return Bz(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test($))window.location.href=$;else U?.($)},[$,U]),qz(Qz,{children:z})},w$=Wz;var _z=F({name:"AutoRedirectCard",component:w$,metadata:{author:"Swarm.ing"}});import{Bounce as Vz,Slide as Dz,Zoom as Kz,Flip as Fz}from"react-toastify";import{toast as Oz,ToastContainer as Iz}from"react-toastify";import{useContext as Mz,useMemo as Pz,useRef as Az}from"react";import{jsx as EZ,Fragment as Ez}from"react/jsx-runtime";var wz={bounce:Vz,slide:Dz,zoom:Kz,flip:Fz},Nz=(Z)=>{let $={...Z,type:Z.alertType,transition:Z.transition?wz[Z.transition]:void 0,position:Z.position??"bottom-right",autoClose:Z.autoClose??3000,style:{backgroundColor:"black",...Z.sx}};Oz(Z.message,$)},Lz=(Z)=>{console.log("Log event",Z)},Rz=(Z)=>{if(typeof window>"u"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let $=()=>{try{new window.Notification(Z.title,{body:Z.message??Z.subtitle,icon:Z.icon,silent:Z.silent})}catch(z){console.error("[IOEventsCard] Failed to show notification",z)}},U=window.Notification.permission;if(U==="granted"){$();return}if(U==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((z)=>{if(z==="granted")$()})},jz=({data:Z})=>{let{useCentrifugeSupport:$,useSocketioSupport:U,useMittSupport:z,centrifugeChannel:H}=Z,J=Mz(k),T=Az(J);T.current=J;let X=Pz(()=>({alert:Nz,log:Lz,push:Rz,redirect:(G)=>{if(G.to){let B=G.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()},reload:(G)=>{if(G.to){let B=G.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()}}),[]);return EZ(Ez,{children:EZ(A,{card:"IOEventsCard",data:Z,useCentrifugeSupport:$,useSocketioSupport:U,useMittSupport:z,centrifugeChannel:H,methods:X,children:EZ(Iz,{})})})},N$=jz;var Cz=F({name:"IOEventsCard",component:N$,metadata:{author:"Swarm.ing"}});import{useEffect as L$,useState as xz}from"react";import{jsx as R$}from"react/jsx-runtime";var yz=({data:Z})=>{let{name:$,key:U,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X}=Z,[G,B]=xz(z);return L$(()=>{B(z)},[z]),L$(()=>{if(typeof window>"u")return;sessionStorage.setItem(U,G)},[U,G]),R$(A,{card:"SessionStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X,methods:{update:({value:q})=>{B(q)},remove:()=>{sessionStorage.removeItem(U),B("")}},children:R$("input",{type:"hidden",id:$,name:$,value:G})})},j$=yz;var bz=F({name:"SessionStorageCard",component:j$,metadata:{author:"PieData"}});import{useEffect as E$,useState as kz}from"react";import{jsx as C$}from"react/jsx-runtime";var fz=({data:Z})=>{let{name:$,key:U,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X}=Z,[G,B]=kz(z);return E$(()=>{B(z)},[z]),E$(()=>{if(typeof window>"u")return;localStorage.setItem(U,G)},[U,G]),C$(A,{card:"DeviceStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X,methods:{update:({value:q})=>{B(q)},remove:()=>{localStorage.removeItem(U),B("")}},children:C$("input",{type:"hidden",id:$,name:$,value:G})})},x$=fz;var Sz=F({name:"DeviceStorageCard",component:x$,metadata:{author:"PieData"}});import{useCallback as CZ,useContext as xZ,useEffect as mz,useRef as vz,useState as y$}from"react";import{jsx as b$}from"react/jsx-runtime";var hz=({data:Z,content:$})=>{let{useLoader:U,noReturn:z,returnType:H,useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:X,centrifugeChannel:G}=Z,B=xZ(E),q=xZ(C)??j,[Q,V]=y$(!1),[_,W]=y$(null),M=vz($),P=xZ(v),K=CZ((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)M.current=Y;if(!z)W(Y)},[z]),O=CZ((Y)=>{M.current=Y.content,W(Y.content)},[]),w=CZ((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)for(let D of Y)P?.emit(D.name,D.data)},[z,P]);if(mz(()=>{W($),V(!1)},[$]),!_&&U)return B;return b$(A,{card:"AjaxGroupCard",data:Z,methods:{changeContent:O},useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:X,centrifugeChannel:G,children:b$(q,{uiConfig:_??M.current,setUiAjaxConfiguration:H==="events"?w:K})})},k$=hz;var gz=F({name:"AjaxGroupCard",component:k$,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});import{useContext as f$}from"react";import{jsx as yZ}from"react/jsx-runtime";var pz=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,url:H,sx:J}=Z,T=f$(k),X=f$(C)??j;return yZ(A,{card:z,data:Z,children:yZ("div",{style:J,id:z,onClick:(B)=>{if(H)if(B.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(H))window.location.href=H;else T?.(H)},children:yZ(X,{setUiAjaxConfiguration:U,uiConfig:$})})})},S$=pz;var dz=F({name:"BoxCard",component:S$,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});import{useContext as uz}from"react";import{jsx as bZ}from"react/jsx-runtime";var cz=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,sx:H}=Z,J=uz(C)??j;return bZ(A,{card:z,data:Z,children:bZ("div",{style:H,id:z,children:$.map((T,X)=>{return bZ(J,{uiConfig:T,setUiAjaxConfiguration:U},`children-${X}`)})})})},m$=cz;var lz=F({name:"OneOfCard",component:m$,metadata:{author:"Swarm.ing",description:"Different variants"}});import{useMemo as $Z}from"react";import{QueryClient as $0,QueryClientProvider as U0,useQuery as z0}from"@tanstack/react-query";import{useContext as iz,useEffect as rz,useRef as kZ}from"react";import{useEffect as oz,useState as sz}from"react";var WZ=new Map,QZ=new Map;function qZ(Z,$){let U=`${Z}::${$}`,z=Z?WZ.get(U):void 0,[H,J]=sz(z??null);return oz(()=>{if(!Z)return;if(WZ.has(U)){J(WZ.get(U));return}let T=QZ.get(U);if(!T)T=fetch(Z+`api/support/${$}`,{method:"GET"}).then((G)=>G.json()).then((G)=>{return WZ.set(U,G),QZ.delete(U),G}).catch((G)=>{throw QZ.delete(U),G}),QZ.set(U,T);let X=!1;return T.then((G)=>{if(!X)J(G)}).catch(()=>{}),()=>{X=!0}},[Z,$,U]),H}function i(Z,$){if($==="up")return{state:"up",signal:Z==="down"?"restored":null};return{state:"down",signal:Z==="up"?"lost":null}}var az=({children:Z})=>{let $=iz(m),U=zZ(),z=qZ(U,"socketIO"),H=a(),J=n(),T=kZ(H);T.current=H;let X=kZ(J);X.current=J;let G=kZ("initial"),B=(q)=>{if(N.isClient())N.setSid(q.sid),Z$(),console.log(`SocketIO initialized: ${N.readSid()}`)};return rz(()=>{if(!$||!z)return;let q=()=>{let{state:V,signal:_}=i(G.current,"up");if(G.current=V,_==="restored")X.current?.("socketio");console.log("SocketIO connected")},Q=(V)=>{if(console.log(`SocketIO disconnected: ${V}`),$.connect(),V==="io client disconnect")return;let{state:_,signal:W}=i(G.current,"down");if(G.current=_,W==="lost")T.current?.("socketio",V)};return $.on("pieinit",B),$.on("connect",q),$.on("disconnect",Q),$.connect(),()=>{$.off("pieinit",B),$.off("connect",q),$.off("disconnect",Q),$.disconnect()}},[$,z]),Z},_Z=az;import{useContext as nz,useEffect as tz,useRef as fZ}from"react";var ez=({children:Z})=>{let $=nz(S),U=zZ(),z=qZ(U,"centrifuge"),H=a(),J=n(),T=fZ(H);T.current=H;let X=fZ(J);X.current=J;let G=fZ("initial");return tz(()=>{if(!$||!z)return;let B=(V)=>{let{state:_,signal:W}=i(G.current,"down");if(G.current=_,W==="lost")T.current?.("centrifuge",V)},q=()=>{let{state:V,signal:_}=i(G.current,"up");if(G.current=V,_==="restored")X.current?.("centrifuge");console.log("Centrifuge connected")},Q=(V)=>{console.log("Centrifuge disconnected:",V),B(V)};return $.on("connecting",B),$.on("connected",q),$.on("disconnected",Q),$.connect(),()=>{$.off("connecting",B),$.off("connected",q),$.off("disconnected",Q),$.disconnect()}},[$,z]),Z},VZ=ez;import{createAxiosDateTransformer as H0}from"axios-date-transformer";import{jsx as Z0}from"react/jsx-runtime";function v$(Z,$,U){if(!$)return U;let z=Z.replace(/^\//,""),H=$[z];if(!H)return U;return Z0(NZ,{uiConfig:H})}function SZ({apiServer:Z,pathname:$,search:U,root:z,initData:H}){let J=new URLSearchParams(U);if(J.set("__pieroot",z),H)J.set("initData",H);return`${Z.replace(/\/$/,"")}/api/content${$}?${J.toString()}`}async function mZ(Z,$){if(!Z||Z.used||Z.url!==$)return null;Z.used=!0;try{return await Z.promise}catch{return null}}import{jsx as L,Fragment as X0}from"react/jsx-runtime";var J0=({location:Z,fallback:$,piecache:U,onError:z,queryOptions:H,configPrefetch:J,disableGlobalForm:T})=>{let X=r(),G=HZ(),B=f(),q=$Z(()=>H0({baseURL:X||""}),[X]),Q=$Z(()=>p(),[]),V=$Z(()=>X?TZ(X):null,[X]),_=$Z(()=>X?JZ(X,G):null,[X,G]),{data:W,isLoading:M,error:P}=z0({queryKey:["uiConfig",Z.pathname+Z.search,X],enabled:!!X,queryFn:async()=>{let O=SZ({apiServer:X,pathname:Z.pathname,search:Z.search,root:"web"}),w=await mZ(J,O);if(w){if(B)console.log("[PieRoot] Using prefetched UI configuration");return w}if(B)console.log("[PieRoot] Fetching UI configuration from:",O);let Y=await q.get(O,{withCredentials:!0});if(B)console.log("[PieRoot] Received UI configuration:",Y.data);return Y.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(O)=>Math.min(1000*2**O,30000),...H}),K=v$(Z.pathname,U,$);if(!X)return K??null;if(B)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] CENTRIFUGE_SERVER:",G),console.log("[PieRoot] Fallback provided:",!!$),console.log("[PieRoot] Piecache provided:",!!U);if(P){if(B)console.error("[PieRoot] Error fetching UI configuration:",P),console.error("[PieRoot] Error details:",{message:P.message,status:P.response?.status,data:P.response?.data});return z?.(P),K}if(M||!W){if(B)console.log("[PieRoot] Loading state:",{isLoading:M,hasUiConfiguration:!!W});return K}if(B)console.log("[PieRoot] UI configuration loaded successfully:",W),console.log("[PieRoot] Rendering UI with configuration");return L(v.Provider,{value:Q,children:L(m.Provider,{value:V,children:L(S.Provider,{value:_,children:L(E.Provider,{value:$??L(X0,{}),children:L(_Z,{children:L(VZ,{children:T?L(j,{uiConfig:W}):L("form",{id:"piedata_global_form",action:X+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:L(j,{uiConfig:W})})})})})})})})},T0=(Z)=>{let $=$Z(()=>new $0,[]),U=Z.queryClient??$;return L(k.Provider,{value:Z.onNavigate,children:L(o.Provider,{value:Z.config,children:L(d.Provider,{value:Z.onError,children:L(U0,{client:U,children:L(J0,{...Z})})})})})},vZ=T0;import{useMemo as hZ,useState as G0}from"react";import{QueryClient as Y0,QueryClientProvider as B0}from"@tanstack/react-query";import{jsx as x,Fragment as q0}from"react/jsx-runtime";var W0=({location:Z,fallback:$,children:U,disableGlobalForm:z})=>{let H=r(),J=HZ(),T=f(),X=hZ(()=>p(),[]),G=hZ(()=>H?TZ(H):null,[H]),B=hZ(()=>H?JZ(H,J):null,[H,J]);if(T)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",J),console.log("[PieRoot] Fallback provided:",!!$);return x(v.Provider,{value:X,children:x(m.Provider,{value:G,children:x(S.Provider,{value:B,children:x(E.Provider,{value:$??x(q0,{}),children:x(_Z,{children:x(VZ,{children:z?U:x("form",{id:"piedata_global_form",action:H+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:U})})})})})})})},Q0=(Z)=>{let[$]=G0(()=>new Y0),U=Z.queryClient??$;return x(k.Provider,{value:Z.onNavigate,children:x(o.Provider,{value:Z.config,children:x(d.Provider,{value:Z.onError,children:x(B0,{client:U,children:x(W0,{...Z})})})})})},_0=Q0;import{useEffect as V0,useMemo as D0}from"react";import{jsx as h$}from"react/jsx-runtime";var K0=h$("div",{style:{padding:16,fontFamily:"system-ui, sans-serif",color:"#888"},children:"Loading card…"}),F0=({apiServer:Z,pathname:$="/",search:U="",centrifugeServer:z,previewEvents:H=!1,fallback:J,enableRenderingLog:T=!1})=>{let X=Z??(typeof process<"u"?process.env.PIE_API_SERVER:void 0)??"";V0(()=>{if(!H||!X||typeof window>"u"||typeof EventSource>"u")return;let q=X.endsWith("/")?X:`${X}/`,Q=new EventSource(`${q}api/preview/events`),V=p();return Q.onmessage=(_)=>{try{let W=JSON.parse(_.data);if(W&&typeof W.name==="string")V.emit(W.name,W.payload)}catch{}},()=>Q.close()},[H,X]);let G=D0(()=>({apiServer:X,centrifugeServer:z,enableRenderingLog:T,pageProcessor:"web"}),[X,z,T]);return h$(vZ,{location:{pathname:$,search:U},config:G,fallback:J??K0,onNavigate:(q)=>{if(typeof window<"u")window.history.pushState(null,"",q)}})},O0=F0;import{clsx as I0}from"clsx";import{twMerge as M0}from"tailwind-merge";function P0(...Z){return M0(I0(Z))}var A0=()=>{H$(),N.submitGlobalForm()};var w0=(Z,$)=>`${Z}${OZ}${$}`;export{ZU as usePieEmit,n as useOnLinkRestored,a as useOnLinkLost,_U as useAjaxSubmits,qU as useAjaxSubmit,PU as unregisterComponent,AZ as trackLazy,A0 as submitGlobalForm,b as registry,F as registerPieComponent,MU as registerMultipleComponents,T$ as readAjaxKeyAsync,J$ as readAjaxKey,q$ as preloadComponent,RU as prefetchLazyComponents,w0 as pieName,XZ as parseDepName,AU as hasComponent,LU as getRegistrySize,ZZ as getRegistryEntry,Q$ as getLazyComponentNames,p as getEmitter,wU as getComponentMeta,NU as getAllRegisteredComponents,G$ as discoverAjaxEndpoints,mZ as consumeConfigPrefetch,P0 as cn,SZ as buildContentUrl,iU as UnionCard,C as UIRendererContext,NZ as UILoading,j as UI,m as SocketIOContext,bz as SessionStorageCard,lU as SequenceCard,vZ as PieRoot,O0 as PiePreviewRoot,o as PieConfigContext,A as PieCard,_0 as PieBaseRoot,OZ as PIEBREAK,lz as OneOfCard,v as MittContext,Cz as IOEventsCard,Xz as HiddenCard,zz as HTMLEmbedCard,E as FallbackContext,Sz as DeviceStorageCard,S as CentrifugeIOContext,dz as BoxCard,_z as AutoRedirectCard,gz as AjaxGroupCard};
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var s$=Object.create;var{getPrototypeOf:i$,defineProperty:WZ,getOwnPropertyNames:KU,getOwnPropertyDescriptor:r$}=Object,FU=Object.prototype.hasOwnProperty;var OU=(Z,U,$)=>{$=Z!=null?s$(i$(Z)):{};let z=U||!Z||!Z.__esModule?WZ($,"default",{value:Z,enumerable:!0}):$;for(let H of KU(Z))if(!FU.call(z,H))WZ(z,H,{get:()=>Z[H],enumerable:!0});return z},DU=new WeakMap,a$=(Z)=>{var U=DU.get(Z),$;if(U)return U;if(U=WZ({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function")KU(Z).map((z)=>!FU.call(U,z)&&WZ(U,z,{get:()=>Z[z],enumerable:!($=r$(Z,z))||$.enumerable}));return DU.set(Z,U),U};var n$=(Z,U)=>{for(var $ in U)WZ(Z,$,{get:U[$],enumerable:!0,configurable:!0,set:(z)=>U[$]=()=>z})};var lz={};n$(lz,{usePieEmit:()=>jU,useOnLinkRestored:()=>ZZ,useOnLinkLost:()=>e,useAjaxSubmits:()=>uU,useAjaxSubmit:()=>dU,unregisterComponent:()=>rU,trackLazy:()=>jZ,submitGlobalForm:()=>d$,registry:()=>S,registerPieComponent:()=>O,registerMultipleComponents:()=>iU,readAjaxKeyAsync:()=>$U,readAjaxKey:()=>UU,preloadComponent:()=>JU,prefetchLazyComponents:()=>Z$,pieName:()=>u$,parseDepName:()=>VZ,hasComponent:()=>aU,getRegistrySize:()=>eU,getRegistryEntry:()=>zZ,getLazyComponentNames:()=>HU,getEmitter:()=>d,getComponentMeta:()=>nU,getAllRegisteredComponents:()=>tU,discoverAjaxEndpoints:()=>zU,cn:()=>p$,UnionCard:()=>W$,UIRendererContext:()=>y,UILoading:()=>yZ,UI:()=>j,SocketIOContext:()=>v,SessionStorageCard:()=>w$,SequenceCard:()=>G$,PieRoot:()=>oZ,PiePreviewRoot:()=>v$,PieConfigContext:()=>a,PieCard:()=>M,PieBaseRoot:()=>m$,PIEBREAK:()=>NZ,OneOfCard:()=>f$,MittContext:()=>h,IOEventsCard:()=>P$,HiddenCard:()=>K$,HTMLEmbedCard:()=>V$,FallbackContext:()=>x,DeviceStorageCard:()=>L$,CentrifugeIOContext:()=>m,BoxCard:()=>C$,AutoRedirectCard:()=>I$,AjaxGroupCard:()=>j$});module.exports=a$(lz);var f=require("react");var PZ=require("react");var nZ=globalThis,I=(Z,U)=>{let $=Symbol.for(Z);if(!($ in nZ))nZ[$]=U();return nZ[$]};var a=I("@swarm.ing/pieui:context:pieConfig",()=>PZ.createContext(null)),c=()=>{let Z=PZ.useContext(a);if(!Z)throw Error("usePieConfig must be used within PieConfigProvider");return Z},qZ=()=>{let{apiServer:Z}=c();return Z},AZ=qZ,wZ=()=>{let{centrifugeServer:Z}=c();return Z};var p=()=>{let{enableRenderingLog:Z}=c();return Z},IU=p;var e=()=>{let{onLinkLost:Z}=c();return Z},ZZ=()=>{let{onLinkRestored:Z}=c();return Z},NZ="__piedemo__";var PU=require("react"),tZ=require("centrifuge");var MU=I("@swarm.ing/pieui:centrifuge-cache",()=>new Map),LZ=(Z,U)=>{if(!U)return null;let $=`${Z}::${U}`,z=MU.get($);if(z)return z;async function H(){let T=await fetch(Z+"api/centrifuge/gen_token",{credentials:"include"});if(!T.ok){if(T.status===401||T.status===403)throw new tZ.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${T.status}`)}return(await T.json()).token}let J=new tZ.Centrifuge(U,{getToken:H});return MU.set($,J),J},t$=I("@swarm.ing/pieui:context:centrifuge",()=>PU.createContext(null)),m=t$;var wU=require("socket.io-client"),NU=require("react");var AU=I("@swarm.ing/pieui:socket-cache",()=>new Map),RZ=(Z)=>{let U=AU.get(Z);if(U)return U;let $=wU.io(Z,{autoConnect:!1,transports:["websocket"]});return AU.set(Z,$),$},e$=I("@swarm.ing/pieui:context:socket",()=>NU.createContext(null)),v=e$;var LU=OU(require("mitt")),UZ=require("react");function d(){return I("@swarm.ing/pieui:mitt-emitter",()=>LU.default())}var RU=I("@swarm.ing/pieui:context:mitt",()=>UZ.createContext(null));function jU(Z){let U=UZ.useContext(RU);return UZ.useCallback(($,z)=>{(U??d()).emit(`pie${$}_${Z}`,z)},[Z,U])}var h=RU;function EU(Z){return Z.wasRecovering===!0&&Z.recovered===!1}function CU(Z){return Z.recoverable===!1}function xU(Z,U,$){let z=Z.getSubscription(U);if(z)return{subscription:z,createdHere:!1};return{subscription:Z.newSubscription(U,$),createdHere:!0}}var Zz=(Z)=>{let U=document.cookie?document.cookie.split(";"):[];for(let $ of U){let z=$.indexOf("=");if((z===-1?$:$.slice(0,z)).trim()===Z){let J=z===-1?"":$.slice(z+1).trim();try{return decodeURIComponent(J)}catch{return J}}}return null},Uz={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(Z){if(typeof window<"u")window.sid=Z},readWebStorage(Z,U){return(Z==="local"?window.localStorage:window.sessionStorage).getItem(U)},readCookie:Zz,readUrlParams(Z){return new URLSearchParams(window.location.search).getAll(Z)},readDomInput(Z){let U=document.getElementsByName(Z);if(!U.length)return null;let $=U[0];if($ instanceof HTMLInputElement){if($.type==="file"&&$.files)return Array.from($.files);return[$.value]}if($ instanceof HTMLTextAreaElement)return[$.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let Z=document.getElementById("piedata_global_form");Z&&Z.submit()}},yU=Uz;var $z={};function n(){return $z}var fU=new Map;var bU=(Z)=>{return fU.has(Z)?fU.get(Z):null};var kU,zz={isClient(){return!0},readSid(){return kU},setSid(Z){kU=Z},readWebStorage(Z,U){let $=n(),z=Z==="local"?$.storage:$.sessionStorage;return z?z.getItem(U):null},async readWebStorageAsync(Z,U){let $=n(),z=Z==="local"?$.asyncStorage:$.asyncSessionStorage;if(z)return z.getItem(U);let H=Z==="local"?$.storage:$.sessionStorage;return H?H.getItem(U):null},readCookie(Z){let U=n();return U.getCookie?U.getCookie(Z):null},readUrlParams(Z){let U=n();return U.getRouteParams?U.getRouteParams(Z):[]},readDomInput(Z){let U=n();return U.getInput?U.getInput(Z):bU(Z)},submitGlobalForm(){n().submitForm?.()}},SU=zz;var Hz=typeof navigator<"u"&&navigator.product==="ReactNative",Jz=Hz?SU:yU,N=Jz;var QZ=I("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function mU(){QZ.resolve?.()}function eZ(){if(!N.isClient())return Promise.resolve();if(N.readSid()!==void 0)return Promise.resolve();if(!QZ.promise)QZ.promise=new Promise((Z)=>{QZ.resolve=()=>{Z()}});return QZ.promise}var ZU=require("react");var Tz=["localStorage","sessionStorage","cookie","url","telegram:cloud","telegram:secure"],Xz=new Set(["telegram:cloud","telegram:secure"]),_Z=new Map,vU=(Z,U)=>{_Z.set(Z,U)},hU=(Z)=>{_Z.delete(Z)},gU=(Z="piedata_global_form")=>{let U;if(typeof Z==="string"){if(typeof document>"u")return;U=document.getElementById(Z)}else U=Z;if(!U)return;let $=U.ownerDocument;for(let z of Array.from(U.getElementsByTagName("input")))if(z.getAttribute("data-pie-stored")!==null)z.remove();for(let[z,H]of _Z){let J=H();if(J instanceof Promise)continue;for(let T of J){if(typeof T!=="string")continue;let G=$.createElement("input");G.type="hidden",G.name=z,G.value=T,G.setAttribute("data-pie-stored","1"),U.appendChild(G)}}},VZ=(Z)=>{if(Z==="sid")return{source:"sid",key:"sid"};for(let U of Tz){let $=U+":";if(Z.startsWith($))return{source:U,key:Z.slice($.length)}}return{source:"dom",key:Z}},UU=(Z,U=!1)=>{let{source:$,key:z}=VZ(Z);if($==="sid"){let T=N.readSid();if(!T)throw Error("SocketIO isn't initialized properly");return[T]}if($==="localStorage"||$==="sessionStorage")try{let T=N.readWebStorage($==="localStorage"?"local":"session",z);if(T===null){if(U)console.warn(`No ${$} value found for key ${z}`);return[]}return[T]}catch(T){if(U)console.warn(`Failed to read ${$} key ${z}:`,T);return[]}if($==="cookie"){let T=N.readCookie(z);if(T===null){if(U)console.warn(`No cookie found for key ${z}`);return[]}return[T]}if($==="url"){let T=N.readUrlParams(z);if(!T.length&&U)console.warn(`No URL query param found for key ${z}`);return T}if(Xz.has($)){if(U)console.warn(`Source ${$} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}let H=_Z.get(z);if(H){let T=H();if(T instanceof Promise){if(U)console.warn(`stored resolver for ${z} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}return T}let J=N.readDomInput(z);if(J===null){if(U)console.warn(`No input found with name ${z}`);return[]}return J},Gz=(Z,U,$)=>{let z=window.Telegram?.WebApp,H=Z==="telegram:cloud"?z?.CloudStorage:z?.SecureStorage,J=Z==="telegram:cloud"?"Telegram CloudStorage":"Telegram SecureStorage";if(!H){if($)console.warn(`${J} is not available`);return Promise.resolve([])}return new Promise((T)=>{try{H.getItem(U,(G,X)=>{if(G){if($)console.warn(`Failed to read ${J} key ${U}:`,G);T([]);return}if(X==null||X===""){if($)console.warn(`No ${J} value found for key ${U}`);T([]);return}T([X])})}catch(G){if($)console.warn(`Failed to read ${J} key ${U}:`,G);T([])}})},$U=async(Z,U=!1)=>{let{source:$,key:z}=VZ(Z);if($==="telegram:cloud"||$==="telegram:secure")return Gz($,z,U);if(($==="localStorage"||$==="sessionStorage")&&N.readWebStorageAsync)try{let H=await N.readWebStorageAsync($==="localStorage"?"local":"session",z);if(H===null){if(U)console.warn(`No ${$} value found for key ${z}`);return[]}return[H]}catch(H){if(U)console.warn(`Failed to read ${$} key ${z}:`,H);return[]}if($==="dom"){let H=_Z.get(z);if(H)return H()}return UU(Z,U)},Yz=(Z)=>{if(!Z)return[];if(Array.isArray(Z))return Z.map(([U,$])=>[String(U),String($)]);if(typeof Z.forEach==="function"){let U=[];return Z.forEach(($,z)=>U.push([z,$])),U}return Object.entries(Z)},Bz=(Z)=>{let U=Z.filter(Boolean);if(U.length===0)return;if(U.length===1)return U[0];let $=AbortSignal.any;if(typeof $==="function")return $.call(AbortSignal,U);let z=new AbortController;for(let H of U){if(H.aborted){z.abort(H.reason);break}H.addEventListener("abort",()=>z.abort(H.reason),{once:!0})}return z.signal},Wz=(Z,U,$)=>{let z={method:"POST",credentials:"include"},H={},J=[U];for(let G of $){if(!G)continue;let{headers:X,signal:B,body:_,...W}=G;Object.assign(z,W);for(let[V,Q]of Yz(X))H[V.toLowerCase()]=Q;J.push(B)}if(z.body=Z,Object.keys(H).length>0)z.headers=H;let T=Bz(J);if(T)z.signal=T;return z},pU=(Z,U={},$=[],z,H)=>{let J=H?.renderingLogEnabled??!1,T=H?.timeout,G=H?.retryPolicy,X=G?.maxRetries??0,B=G?.baseDelay??1000,_=G?.retryOn??[502,503,504];if(J)console.log("Registering AJAX: ",z,U,$);return async(W={},V)=>{if(!N.isClient()){if(J)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let Q=H?.apiServer;if(!Q){if(J)console.warn("AJAX skipped: apiServer is missing");return}if(!z||!Z){if(J)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if($.includes("sid"))await eZ();let q=new FormData;for(let[D,P]of Object.entries({...U,...W}))q.append(D,P);for(let D of $){let{key:P}=VZ(D);for(let A of await $U(D,J))q.append(P,A)}let F=Q+"api/ajax_content"+z;Z(null);let w;for(let D=0;D<=X;D++){if(D>0){let Y=B*2**(D-1);if(J)console.log(`AJAX retry ${D}/${X} after ${Y}ms`);await new Promise((K)=>setTimeout(K,Y))}let P=T!=null?new AbortController:null,A=P&&setTimeout(()=>P.abort(),T);try{let Y=await fetch(F,Wz(q,P?.signal,[H?.fetchOptions,V]));if(A)clearTimeout(A);if(!Y.ok&&_.includes(Y.status)&&D<X){w=Error(`HTTP ${Y.status}`);continue}let C=(Y.headers.get("content-type")||"").includes("application/json");if(!!Y.body?.getReader&&!C){let r=Y.body.getReader(),MZ=new TextDecoder,k="";while(!0){let{done:rZ,value:c$}=await r.read();if(rZ)break;k+=MZ.decode(c$,{stream:!0});let VU=k.split(`
|
|
3
|
-
`);k=VU.pop()??"";for(let l$ of VU){let aZ=l$.trim();if(!aZ)continue;try{let o$=JSON.parse(aZ);Z([o$])}catch{if(J)console.warn("Failed to parse streamed line:",aZ)}}}if(k.trim())try{let rZ=JSON.parse(k);Z([rZ])}catch{if(J)console.warn("Failed to parse final streamed line:",k)}return{}}else{let r=await Y.json();return Z(r),r}}catch(Y){if(A)clearTimeout(A);if(w=Y,D<X)continue;if(J)console.error("AJAX request failed:",Y);return Z(null),Y}}if(J)console.error("AJAX request failed after retries:",w);return Z(null),w}},dU=(Z,U={},$=[],z,H)=>{let{apiServer:J,enableRenderingLog:T}=c(),G=JSON.stringify(U),X=JSON.stringify($),B=JSON.stringify(H);return ZU.useMemo(()=>pU(Z,U,$,z,{apiServer:J,renderingLogEnabled:T,timeout:H?.timeout,retryPolicy:H?.retryPolicy,fetchOptions:H?.fetchOptions}),[Z,G,X,z,J,T,B])},zU=(Z={})=>{let U=[];for(let $ of Object.keys(Z??{})){let z=null;if($==="pathname")z="default";else if($.endsWith("Pathname"))z=$.slice(0,-8);if(z===null)continue;let H=z==="default"?"":z;U.push({key:z,pathname:Z[$],depsNames:Z[H?`${H}DepsNames`:"depsNames"]??[],kwargs:Z[H?`${H}Kwargs`:"kwargs"]??{}})}return U},uU=(Z={},U,$)=>{let{apiServer:z,enableRenderingLog:H}=c(),J=JSON.stringify(Z??{}),T=JSON.stringify($);return ZU.useMemo(()=>{let G={};for(let X of zU(Z??{}))G[X.key]=pU(U,X.kwargs,X.depsNames,X.pathname,{apiServer:z,renderingLogEnabled:H,timeout:$?.timeout,retryPolicy:$?.retryPolicy,fetchOptions:$?.fetchOptions});return G},[J,U,z,H,T])};var $Z=require("react/jsx-runtime"),qz=({card:Z,data:U,children:$,useSocketioSupport:z=!1,useCentrifugeSupport:H=!1,useMittSupport:J=!1,centrifugeChannel:T=void 0,methods:G=void 0,stored:X=void 0,onResync:B=void 0})=>{let _=IU(),W=f.useRef(G);W.current=G;let V=f.useRef(B);V.current=B;let Q=f.useRef(X);Q.current=X;let q=typeof X==="function";if(f.useEffect(()=>{if(!q)return;let P=U.name;return vU(P,()=>[JSON.stringify(Q.current())]),()=>hU(P)},[q,U.name]),_)console.log("[PieCard] Rendering card:",Z),console.log("[PieCard] Card data:",U),console.log("[PieCard] Component name:",U?.name),console.log("[PieCard] Real-time support:",{socketio:z,centrifuge:H,mitt:J,centrifugeChannel:T}),console.log("[PieCard] Methods:",G?Object.keys(G):"none"),console.log("[PieCard] Has children:",!!$);let F=f.useContext(v),w=f.useContext(m),D=f.useContext(h);if(f.useEffect(()=>{if(!F||!z||!W.current||!U.name){if(_&&z)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!F,useSocketioSupport:z,hasMethods:!!W.current,hasDataName:!!U?.name});return}let A=Object.keys(W.current??{}).map((Y)=>{let K=`pie${Y}_${U.name}`;if(_)console.log(`[PieCard] Socket.IO registering event: ${K}`);let C=(u)=>{W.current?.[Y]?.(u)};return F.on(K,C),[K,C]});return()=>{A.forEach(([Y,K])=>{if(_)console.log(`[PieCard] Socket.IO unregistering event: ${Y}`);F.off(Y,K)})}},[F,U.name,z]),f.useEffect(()=>{if(!w||!H||!T||!U.name){if(_&&H)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!w,useCentrifugeSupport:H,hasCentrifugeChannel:!!T,hasMethods:!!W.current,hasDataName:!!U?.name});return}let A=Object.keys(W.current??{}).map((Y)=>{let K=`pie${Y}_${U.name}_${T}`;if(_)console.log(`[PieCard] Centrifuge subscribing to channel: ${K}`);let{subscription:C,createdHere:u}=xU(w,K,{recoverable:!0,positioned:!0}),r=(k)=>{if(_)console.log(`[PieCard] Centrifuge received data on ${K}:`,k.data);W.current?.[Y]?.(k.data)},MZ=(k)=>{if(CU(k))console.warn(`[PieCard] Centrifuge channel ${K} is not `+"recoverable — enable history on the server "+"namespace for exact replay; relying on resync fallback only.");if(EU(k)){if(_)console.log(`[PieCard] Centrifuge recovery gap on ${K}; requesting resync`);V.current?.({channel:K,reason:"gap"})}};return C.on("publication",r),C.on("subscribed",MZ),C.subscribe(),{subscription:C,createdHere:u,onPublication:r,onSubscribed:MZ}});return()=>{A.forEach(({subscription:Y,createdHere:K,onPublication:C,onSubscribed:u})=>{if(_)console.log("[PieCard] Centrifuge unsubscribing from channel");if(Y.off("publication",C),Y.off("subscribed",u),K)Y.unsubscribe(),w.removeSubscription(Y)})}},[w,T,U.name,H]),f.useEffect(()=>{if(!D||!J||!U.name){if(_&&J)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!D,useMittSupport:J,hasMethods:!!W.current,hasDataName:!!U?.name});return}let P=Object.keys(W.current??{}),A={};return P.forEach((Y)=>{let K=`pie${Y}_${U.name}`,C=(u)=>{if(_)console.log(`[PieCard] Mitt registering event: ${K}`);W.current?.[Y]?.(u)};A[K]=C,D.on(K,C)}),()=>{Object.entries(A).forEach(([Y,K])=>{if(_)console.log(`[PieCard] Mitt unregistering event: ${Y}`);D.off(Y,K)})}},[D,U.name,J]),_)console.log("[PieCard] Rendering complete, returning children");if(X!==void 0&&!q)return $Z.jsxs($Z.Fragment,{children:[$Z.jsx("input",{type:"hidden",name:U.name,value:JSON.stringify(X)}),$]});return $},M=qz;var cU=require("react"),t=new Map;function lU(Z,U){return U.catch(()=>{if(t.get(Z)===U)t.delete(Z)}),t.set(Z,U),U}function jZ(Z,U){return cU.lazy(()=>{if(t.has(U))return t.get(U);return lU(U,Z().then(($)=>$))})}var oU=async(Z,U)=>{if(!U)return;if(t.has(Z))return t.get(Z);return lU(Z,U().then(($)=>$))};var S=I("@swarm.ing/pieui:component-registry",()=>new Map),Qz=(Z)=>{if(!Z.name)throw Error("Component registration requires a name");if(!Z.component&&!Z.loader)throw Error(`Component "${Z.name}" requires component or loader`);let U={name:Z.name,component:Z.component,loader:Z.loader,metadata:Z.metadata,fallback:Z.fallback,isLazy:!1};if(!U.component&&U.loader)U.component=jZ(U.loader,Z.name),U.isLazy=!0;return U};function O(Z){let U=Qz(Z);return S.set(U.name,U),U.component}var iU=(Z)=>{Z.forEach((U)=>O(U))},rU=(Z)=>{S.delete(Z)},aU=(Z)=>{return S.has(Z)},nU=(Z)=>{return S.get(Z)?.metadata},zZ=(Z)=>{return S.get(Z)},tU=()=>{return Array.from(S.keys())},eU=()=>{return S.size},HU=()=>Array.from(S.values()).filter((Z)=>Z.isLazy&&typeof Z.loader==="function").map((Z)=>Z.name),JU=(Z)=>{let U=S.get(Z);if(!U?.isLazy||typeof U.loader!=="function")return;return oU(Z,U.loader)},sU=!1,Z$=()=>{if(sU||typeof window>"u")return;sU=!0;let Z=navigator.connection;if(Z?.saveData)return;if(Z?.effectiveType&&["slow-2g","2g"].includes(Z.effectiveType))return;let U=HU(),$="requestIdleCallback"in window?(H)=>window.requestIdleCallback(H,{timeout:2000}):(H)=>window.setTimeout(H,300),z=(H)=>{if(H>=U.length)return;$(()=>{Promise.resolve().then(()=>JU(U[H])).catch(()=>{}).finally(()=>z(H+1))})};z(0)};var DZ=require("react");var U$=require("react");var EZ=require("react/jsx-runtime"),_z=I("@swarm.ing/pieui:context:fallback",()=>U$.createContext(EZ.jsx(EZ.Fragment,{}))),x=_z;var $$=require("react");var Vz=I("@swarm.ing/pieui:context:lazyError",()=>$$.createContext(void 0)),l=Vz;var CZ=require("react"),z$=require("react/jsx-runtime"),Dz=2,Kz=400;class HZ extends CZ.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(Z){if(this.props.onError?.(Z),this.state.attempt<Dz){let U=Kz*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState(($)=>({failed:!1,attempt:$.attempt+1}))},U)}}componentDidUpdate(Z){if(Z.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return z$.jsx(CZ.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var xZ=require("react/jsx-runtime");function Fz({uiConfig:Z,setUiAjaxConfiguration:U}){let $=DZ.useContext(x),z=DZ.useContext(l),H=p();if(H)console.log("[UI] Rendering component:",Z.card),console.log("[UI] Component data:",Z.data),console.log("[UI] Component content:",Z.content),console.log("[UI] Has setUiAjaxConfiguration:",!!U);let J=zZ(Z.card);if(!J?.component){if(H)console.warn(`[UI] Component not found in registry: ${Z.card}`),console.log("[UI] Returning fallback component");return $}if(H)console.log("[UI] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata});let T=J.component,G=xZ.jsx(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:U});if(J.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",J.name);return xZ.jsx(HZ,{name:J.name,fallback:J.fallback?xZ.jsx(J.fallback,{}):$,onError:z,children:G})}if(H)console.log("[UI] Rendering component directly:",J.name);return G}var j=DZ.memo(Fz);var TU=require("react");var H$=require("react");var Oz=I("@swarm.ing/pieui:context:uiRenderer",()=>H$.createContext(null)),y=Oz;var KZ=require("react/jsx-runtime");function J$({uiConfig:Z,setUiAjaxConfiguration:U}){let $=TU.useContext(x),z=TU.useContext(l),H=p();if(H)console.log("[UILoading] Rendering fallback for:",Z.card),console.log("[UILoading] Component data:",Z.data),console.log("[UILoading] Component content:",Z.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!U);let J=zZ(Z.card);if(!J?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${Z.card}`),console.log("[UILoading] Returning fallback component");return $}if(H)console.log("[UILoading] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata,hasFallback:!!J.fallback});if(J.fallback){if(H)console.log("[UILoading] Rendering fallback for:",J.name);let X=J.fallback;return KZ.jsx(X,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",J.name);let T=J.component,G=KZ.jsx(y.Provider,{value:J$,children:KZ.jsx(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:U})});if(J.isLazy)return KZ.jsx(HZ,{name:J.name,fallback:$,onError:z,children:G});return G}var yZ=J$;var T$=require("react");var fZ=require("react/jsx-runtime"),Iz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,sx:H}=Z,J=T$.useContext(y)??j;return fZ.jsx(M,{card:z,data:Z,children:fZ.jsx("div",{style:H,id:z,children:U.map((T,G)=>{return fZ.jsx(J,{uiConfig:T,setUiAjaxConfiguration:$},`children-${G}`)})})})},X$=Iz;var G$=O({name:"SequenceCard",component:X$,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var Y$=require("react");var XU=require("react/jsx-runtime"),Mz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z}=Z,H=Y$.useContext(y)??j;return XU.jsx(M,{card:z,data:Z,children:U.map((J,T)=>{return XU.jsx(H,{uiConfig:J,setUiAjaxConfiguration:$},`children-${T}`)})})},B$=Mz;var W$=O({name:"UnionCard",component:B$,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var bZ=require("react"),q$=OU(require("html-react-parser"));var b=require("react");function Pz(){let Z=new AudioContext,U=Z.createOscillator(),$=U.connect(Z.createMediaStreamDestination());U.start();let z=$.stream.getAudioTracks()[0];return z.enabled=!1,z}function GU(Z=null,U){let[$,z]=b.useState(!1),H=b.useRef(null),J=b.useRef(null),T=b.useRef(null),G=b.useCallback(async(W,V=!0)=>{if(H.current)X();let Q=new RTCPeerConnection;if(Q.onconnectionstatechange=()=>{if(Q.connectionState==="connected")z(!0);else if(["disconnected","failed","closed"].includes(Q.connectionState))z(!1)},Q.ontrack=(Y)=>{if(Z)Z.srcObject=Y.streams[0]},V){let Y=await navigator.mediaDevices.getUserMedia({audio:!0});Q.addTrack(Y.getTracks()[0],Y)}else{let Y=Pz();Q.addTrack(Y)}let q=Q.createDataChannel("oai-events");J.current=q,T.current=new Promise((Y)=>{q.addEventListener("open",()=>{Y()})});let F=await Q.createOffer();await Q.setLocalDescription(F);let A=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:F.sdp,headers:{Authorization:`Bearer ${W}`,"Content-Type":"application/sdp"}})).text();await Q.setRemoteDescription({type:"answer",sdp:A}),H.current=Q,await T.current},[Z]),X=b.useCallback(()=>{let W=J.current;if(W)W.close();H.current?.getSenders()?.forEach((V)=>V.track?.stop()),H.current?.close(),z(!1),H.current=null,J.current=null,T.current=null},[Z]),B=b.useCallback((W)=>{let V=J.current;if(!V){console.error("Data channel is not ready",W);return}let Q=new Date().toLocaleTimeString();if(W.event_id=W.event_id||crypto.randomUUID(),V.send(JSON.stringify(W)),!W.timestamp)W.timestamp=Q;U?.(W)},[U,Z]),_=b.useCallback((W)=>{if(!J.current){console.error("Data channel is not ready");return}let Q=()=>{B({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:W}]}}),B({type:"response.create"})};if(T.current)T.current.then(Q);else Q()},[U,Z]);return b.useEffect(()=>{let W=J.current;if(!W)return;let V=(Q)=>{let q=JSON.parse(Q.data);if(!q.timestamp)q.timestamp=new Date().toLocaleTimeString();U?.(q)};return W.addEventListener("message",V),()=>{W.removeEventListener("message",V)}},[U,Z]),{isSessionActive:$,startSession:G,stopSession:X,sendTextMessage:_}}var _$=require("react/jsx-runtime"),Az=({data:Z})=>{let{html:U,useSocketioSupport:$,useCentrifugeSupport:z,useMittSupport:H,centrifugeChannel:J}=Z,[T,G]=bZ.useState(U),{isSessionActive:X,startSession:B,sendTextMessage:_}=GU(null,(q)=>{if(console.log(q.type,q.type==="response.output_text.delta"&&q.delta),q.type==="response.output_text.delta"&&q.delta)G((F)=>F+q.delta)});return bZ.useEffect(()=>{G(U)},[U]),_$.jsx(M,{card:"HTMLEmbedCard",data:Z,methods:{update:(q)=>{G(q.value)},generateUsingAI:async(q)=>{try{if(!X&&q.token)await B(q.token,!1);_(q.prompt)}catch(F){console.error("Failed to generate using AI",F)}},initializeAI:async(q)=>{if(!X&&q.token)await B(q.token,!1)}},useCentrifugeSupport:z,useSocketioSupport:$,useMittSupport:H,centrifugeChannel:J,children:q$.default(T)})},Q$=Az;var V$=O({name:"HTMLEmbedCard",component:Q$,metadata:{author:"Swarm.ing"}});var kZ=require("react");var YU=require("react/jsx-runtime"),wz=({data:Z})=>{let{name:U,value:$,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T}=Z,[G,X]=kZ.useState($);return kZ.useEffect(()=>{X($)},[$]),YU.jsx(M,{card:"HiddenCard",data:Z,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T,methods:{update:({value:B})=>{X(B)}},children:YU.jsx("input",{type:"hidden",id:U,name:U,value:G})})},D$=wz;var K$=O({name:"HiddenCard",component:D$,metadata:{author:"Swarm.ing"}});var FZ=require("react");var F$=require("react");var Nz=I("@swarm.ing/pieui:context:navigate",()=>F$.createContext(void 0)),g=Nz;var SZ=require("react/jsx-runtime"),Lz=({data:Z})=>{let{url:U}=Z,$=FZ.useContext(g),z=FZ.useContext(x);return FZ.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(U))window.location.href=U;else $?.(U)},[U,$]),SZ.jsx(SZ.Fragment,{children:z})},O$=Lz;var I$=O({name:"AutoRedirectCard",component:O$,metadata:{author:"Swarm.ing"}});var o=require("react-toastify"),mZ=require("react-toastify");var TZ=require("react");var JZ=require("react/jsx-runtime"),Rz={bounce:o.Bounce,slide:o.Slide,zoom:o.Zoom,flip:o.Flip},jz=(Z)=>{let U={...Z,type:Z.alertType,transition:Z.transition?Rz[Z.transition]:void 0,position:Z.position??"bottom-right",autoClose:Z.autoClose??3000,style:{backgroundColor:"black",...Z.sx}};mZ.toast(Z.message,U)},Ez=(Z)=>{console.log("Log event",Z)},Cz=(Z)=>{if(typeof window>"u"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let U=()=>{try{new window.Notification(Z.title,{body:Z.message??Z.subtitle,icon:Z.icon,silent:Z.silent})}catch(z){console.error("[IOEventsCard] Failed to show notification",z)}},$=window.Notification.permission;if($==="granted"){U();return}if($==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((z)=>{if(z==="granted")U()})},xz=({data:Z})=>{let{useCentrifugeSupport:U,useSocketioSupport:$,useMittSupport:z,centrifugeChannel:H}=Z,J=TZ.useContext(g),T=TZ.useRef(J);T.current=J;let G=TZ.useMemo(()=>({alert:jz,log:Ez,push:Cz,redirect:(X)=>{if(X.to){let B=X.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()},reload:(X)=>{if(X.to){let B=X.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()}}),[]);return JZ.jsx(JZ.Fragment,{children:JZ.jsx(M,{card:"IOEventsCard",data:Z,useCentrifugeSupport:U,useSocketioSupport:$,useMittSupport:z,centrifugeChannel:H,methods:G,children:JZ.jsx(mZ.ToastContainer,{})})})},M$=xz;var P$=O({name:"IOEventsCard",component:M$,metadata:{author:"Swarm.ing"}});var OZ=require("react");var BU=require("react/jsx-runtime"),yz=({data:Z})=>{let{name:U,key:$,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G}=Z,[X,B]=OZ.useState(z);return OZ.useEffect(()=>{B(z)},[z]),OZ.useEffect(()=>{if(typeof window>"u")return;sessionStorage.setItem($,X)},[$,X]),BU.jsx(M,{card:"SessionStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G,methods:{update:({value:_})=>{B(_)},remove:()=>{sessionStorage.removeItem($),B("")}},children:BU.jsx("input",{type:"hidden",id:U,name:U,value:X})})},A$=yz;var w$=O({name:"SessionStorageCard",component:A$,metadata:{author:"PieData"}});var IZ=require("react");var WU=require("react/jsx-runtime"),fz=({data:Z})=>{let{name:U,key:$,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G}=Z,[X,B]=IZ.useState(z);return IZ.useEffect(()=>{B(z)},[z]),IZ.useEffect(()=>{if(typeof window>"u")return;localStorage.setItem($,X)},[$,X]),WU.jsx(M,{card:"DeviceStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:G,methods:{update:({value:_})=>{B(_)},remove:()=>{localStorage.removeItem($),B("")}},children:WU.jsx("input",{type:"hidden",id:U,name:U,value:X})})},N$=fz;var L$=O({name:"DeviceStorageCard",component:N$,metadata:{author:"PieData"}});var E=require("react");var qU=require("react/jsx-runtime"),bz=({data:Z,content:U})=>{let{useLoader:$,noReturn:z,returnType:H,useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:G,centrifugeChannel:X}=Z,B=E.useContext(x),_=E.useContext(y)??j,[W,V]=E.useState(!1),[Q,q]=E.useState(null),F=E.useRef(U),w=E.useContext(h),D=E.useCallback((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)F.current=Y;if(!z)q(Y)},[z]),P=E.useCallback((Y)=>{F.current=Y.content,q(Y.content)},[]),A=E.useCallback((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)for(let K of Y)w?.emit(K.name,K.data)},[z,w]);if(E.useEffect(()=>{q(U),V(!1)},[U]),!Q&&$)return B;return qU.jsx(M,{card:"AjaxGroupCard",data:Z,methods:{changeContent:P},useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:G,centrifugeChannel:X,children:qU.jsx(_,{uiConfig:Q??F.current,setUiAjaxConfiguration:H==="events"?A:D})})},R$=bz;var j$=O({name:"AjaxGroupCard",component:R$,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var QU=require("react");var vZ=require("react/jsx-runtime"),kz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,url:H,sx:J}=Z,T=QU.useContext(g),G=QU.useContext(y)??j;return vZ.jsx(M,{card:z,data:Z,children:vZ.jsx("div",{style:J,id:z,onClick:(B)=>{if(H)if(B.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(H))window.location.href=H;else T?.(H)},children:vZ.jsx(G,{setUiAjaxConfiguration:$,uiConfig:U})})})},E$=kz;var C$=O({name:"BoxCard",component:E$,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var x$=require("react");var hZ=require("react/jsx-runtime"),Sz=({data:Z,content:U,setUiAjaxConfiguration:$})=>{let{name:z,sx:H}=Z,J=x$.useContext(y)??j;return hZ.jsx(M,{card:z,data:Z,children:hZ.jsx("div",{style:H,id:z,children:U.map((T,G)=>{return hZ.jsx(J,{uiConfig:T,setUiAjaxConfiguration:$},`children-${G}`)})})})},y$=Sz;var f$=O({name:"OneOfCard",component:y$,metadata:{author:"Swarm.ing",description:"Different variants"}});var GZ=require("react"),YZ=require("@tanstack/react-query");var s=require("react");var dZ=require("react"),gZ=new Map,pZ=new Map;function uZ(Z,U){let $=`${Z}::${U}`,z=Z?gZ.get($):void 0,[H,J]=dZ.useState(z??null);return dZ.useEffect(()=>{if(!Z)return;if(gZ.has($)){J(gZ.get($));return}let T=pZ.get($);if(!T)T=fetch(Z+`api/support/${U}`,{method:"GET"}).then((X)=>X.json()).then((X)=>{return gZ.set($,X),pZ.delete($),X}).catch((X)=>{throw pZ.delete($),X}),pZ.set($,T);let G=!1;return T.then((X)=>{if(!G)J(X)}).catch(()=>{}),()=>{G=!0}},[Z,U,$]),H}function XZ(Z,U){if(U==="up")return{state:"up",signal:Z==="down"?"restored":null};return{state:"down",signal:Z==="up"?"lost":null}}var mz=({children:Z})=>{let U=s.useContext(v),$=AZ(),z=uZ($,"socketIO"),H=e(),J=ZZ(),T=s.useRef(H);T.current=H;let G=s.useRef(J);G.current=J;let X=s.useRef("initial"),B=(_)=>{if(N.isClient())N.setSid(_.sid),mU(),console.log(`SocketIO initialized: ${N.readSid()}`)};return s.useEffect(()=>{if(!U||!z)return;let _=()=>{let{state:V,signal:Q}=XZ(X.current,"up");if(X.current=V,Q==="restored")G.current?.("socketio");console.log("SocketIO connected")},W=(V)=>{if(console.log(`SocketIO disconnected: ${V}`),U.connect(),V==="io client disconnect")return;let{state:Q,signal:q}=XZ(X.current,"down");if(X.current=Q,q==="lost")T.current?.("socketio",V)};return U.on("pieinit",B),U.on("connect",_),U.on("disconnect",W),U.connect(),()=>{U.off("pieinit",B),U.off("connect",_),U.off("disconnect",W),U.disconnect()}},[U,z]),Z},cZ=mz;var i=require("react");var vz=({children:Z})=>{let U=i.useContext(m),$=AZ(),z=uZ($,"centrifuge"),H=e(),J=ZZ(),T=i.useRef(H);T.current=H;let G=i.useRef(J);G.current=J;let X=i.useRef("initial");return i.useEffect(()=>{if(!U||!z)return;let B=(V)=>{let{state:Q,signal:q}=XZ(X.current,"down");if(X.current=Q,q==="lost")T.current?.("centrifuge",V)},_=()=>{let{state:V,signal:Q}=XZ(X.current,"up");if(X.current=V,Q==="restored")G.current?.("centrifuge");console.log("Centrifuge connected")},W=(V)=>{console.log("Centrifuge disconnected:",V),B(V)};return U.on("connecting",B),U.on("connected",_),U.on("disconnected",W),U.connect(),()=>{U.off("connecting",B),U.off("connected",_),U.off("disconnected",W),U.disconnect()}},[U,z]),Z},lZ=vz;var S$=require("axios-date-transformer");var k$=require("react/jsx-runtime");function b$(Z,U,$){if(!U)return $;let z=Z.replace(/^\//,""),H=U[z];if(!H)return $;return k$.jsx(yZ,{uiConfig:H})}var L=require("react/jsx-runtime"),hz=({location:Z,fallback:U,piecache:$,onError:z,queryOptions:H,disableGlobalForm:J})=>{let T=qZ(),G=wZ(),X=p(),B=GZ.useMemo(()=>S$.createAxiosDateTransformer({baseURL:T||""}),[T]),_=GZ.useMemo(()=>d(),[]),W=GZ.useMemo(()=>T?RZ(T):null,[T]),V=GZ.useMemo(()=>T?LZ(T,G):null,[T,G]),{data:Q,isLoading:q,error:F}=YZ.useQuery({queryKey:["uiConfig",Z.pathname+Z.search,T],enabled:!!T,queryFn:async()=>{let D=new URLSearchParams(Z.search);D.set("__pieroot","web");let P="/api/content"+Z.pathname+"?"+D.toString();if(X)console.log("[PieRoot] Fetching UI configuration from:",P);let A=await B.get(P,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(X)console.log("[PieRoot] Received UI configuration:",A.data);return A.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(D)=>Math.min(1000*2**D,30000),...H}),w=b$(Z.pathname,$,U);if(!T)return w??null;if(X)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",T),console.log("[PieRoot] CENTRIFUGE_SERVER:",G),console.log("[PieRoot] Fallback provided:",!!U),console.log("[PieRoot] Piecache provided:",!!$);if(F){if(X)console.error("[PieRoot] Error fetching UI configuration:",F),console.error("[PieRoot] Error details:",{message:F.message,status:F.response?.status,data:F.response?.data});return z?.(F),w}if(q||!Q){if(X)console.log("[PieRoot] Loading state:",{isLoading:q,hasUiConfiguration:!!Q});return w}if(X)console.log("[PieRoot] UI configuration loaded successfully:",Q),console.log("[PieRoot] Rendering UI with configuration");return L.jsx(h.Provider,{value:_,children:L.jsx(v.Provider,{value:W,children:L.jsx(m.Provider,{value:V,children:L.jsx(x.Provider,{value:U??L.jsx(L.Fragment,{}),children:L.jsx(cZ,{children:L.jsx(lZ,{children:J?L.jsx(j,{uiConfig:Q}):L.jsx("form",{id:"piedata_global_form",action:T+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:L.jsx(j,{uiConfig:Q})})})})})})})})},gz=(Z)=>{let U=GZ.useMemo(()=>new YZ.QueryClient,[]),$=Z.queryClient??U;return L.jsx(g.Provider,{value:Z.onNavigate,children:L.jsx(a.Provider,{value:Z.config,children:L.jsx(l.Provider,{value:Z.onError,children:L.jsx(YZ.QueryClientProvider,{client:$,children:L.jsx(hz,{...Z})})})})})},oZ=gz;var BZ=require("react"),sZ=require("@tanstack/react-query");var R=require("react/jsx-runtime"),pz=({location:Z,fallback:U,children:$,disableGlobalForm:z})=>{let H=qZ(),J=wZ(),T=p(),G=BZ.useMemo(()=>d(),[]),X=BZ.useMemo(()=>H?RZ(H):null,[H]),B=BZ.useMemo(()=>H?LZ(H,J):null,[H,J]);if(T)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",J),console.log("[PieRoot] Fallback provided:",!!U);return R.jsx(h.Provider,{value:G,children:R.jsx(v.Provider,{value:X,children:R.jsx(m.Provider,{value:B,children:R.jsx(x.Provider,{value:U??R.jsx(R.Fragment,{}),children:R.jsx(cZ,{children:R.jsx(lZ,{children:z?$:R.jsx("form",{id:"piedata_global_form",action:H+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:$})})})})})})})},dz=(Z)=>{let[U]=BZ.useState(()=>new sZ.QueryClient),$=Z.queryClient??U;return R.jsx(g.Provider,{value:Z.onNavigate,children:R.jsx(a.Provider,{value:Z.config,children:R.jsx(l.Provider,{value:Z.onError,children:R.jsx(sZ.QueryClientProvider,{client:$,children:R.jsx(pz,{...Z})})})})})},m$=dz;var iZ=require("react");var _U=require("react/jsx-runtime"),uz=_U.jsx("div",{style:{padding:16,fontFamily:"system-ui, sans-serif",color:"#888"},children:"Loading card…"}),cz=({apiServer:Z,pathname:U="/",search:$="",centrifugeServer:z,previewEvents:H=!1,fallback:J,enableRenderingLog:T=!1})=>{let G=Z??(typeof process<"u"?process.env.PIE_API_SERVER:void 0)??"";iZ.useEffect(()=>{if(!H||!G||typeof window>"u"||typeof EventSource>"u")return;let _=G.endsWith("/")?G:`${G}/`,W=new EventSource(`${_}api/preview/events`),V=d();return W.onmessage=(Q)=>{try{let q=JSON.parse(Q.data);if(q&&typeof q.name==="string")V.emit(q.name,q.payload)}catch{}},()=>W.close()},[H,G]);let X=iZ.useMemo(()=>({apiServer:G,centrifugeServer:z,enableRenderingLog:T,pageProcessor:"web"}),[G,z,T]);return _U.jsx(oZ,{location:{pathname:U,search:$},config:X,fallback:J??uz,onNavigate:(_)=>{if(typeof window<"u")window.history.pushState(null,"",_)}})},v$=cz;var h$=require("clsx"),g$=require("tailwind-merge");function p$(...Z){return g$.twMerge(h$.clsx(Z))}var d$=()=>{gU(),N.submitGlobalForm()};var u$=(Z,U)=>`${Z}${NZ}${U}`;
|
|
2
|
+
var rU=Object.create;var{getPrototypeOf:aU,defineProperty:WZ,getOwnPropertyNames:O$,getOwnPropertyDescriptor:nU}=Object,I$=Object.prototype.hasOwnProperty;var M$=(Z,$,U)=>{U=Z!=null?rU(aU(Z)):{};let z=$||!Z||!Z.__esModule?WZ(U,"default",{value:Z,enumerable:!0}):U;for(let H of O$(Z))if(!I$.call(z,H))WZ(z,H,{get:()=>Z[H],enumerable:!0});return z},F$=new WeakMap,tU=(Z)=>{var $=F$.get(Z),U;if($)return $;if($=WZ({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function")O$(Z).map((z)=>!I$.call($,z)&&WZ($,z,{get:()=>Z[z],enumerable:!(U=nU(Z,z))||U.enumerable}));return F$.set(Z,$),$};var eU=(Z,$)=>{for(var U in $)WZ(Z,U,{get:$[U],enumerable:!0,configurable:!0,set:(z)=>$[U]=()=>z})};var sz={};eU(sz,{usePieEmit:()=>C$,useOnLinkRestored:()=>ZZ,useOnLinkLost:()=>e,useAjaxSubmits:()=>l$,useAjaxSubmit:()=>c$,unregisterComponent:()=>n$,trackLazy:()=>jZ,submitGlobalForm:()=>cU,registry:()=>S,registerPieComponent:()=>F,registerMultipleComponents:()=>a$,readAjaxKeyAsync:()=>H$,readAjaxKey:()=>z$,preloadComponent:()=>X$,prefetchLazyComponents:()=>UU,pieName:()=>lU,parseDepName:()=>VZ,hasComponent:()=>t$,getRegistrySize:()=>$U,getRegistryEntry:()=>zZ,getLazyComponentNames:()=>T$,getEmitter:()=>d,getComponentMeta:()=>e$,getAllRegisteredComponents:()=>ZU,discoverAjaxEndpoints:()=>J$,consumeConfigPrefetch:()=>sZ,cn:()=>uU,buildContentUrl:()=>oZ,UnionCard:()=>qU,UIRendererContext:()=>y,UILoading:()=>yZ,UI:()=>j,SocketIOContext:()=>v,SessionStorageCard:()=>LU,SequenceCard:()=>BU,PieRoot:()=>iZ,PiePreviewRoot:()=>gU,PieConfigContext:()=>a,PieCard:()=>M,PieBaseRoot:()=>hU,PIEBREAK:()=>NZ,OneOfCard:()=>fU,MittContext:()=>h,IOEventsCard:()=>wU,HiddenCard:()=>OU,HTMLEmbedCard:()=>KU,FallbackContext:()=>x,DeviceStorageCard:()=>jU,CentrifugeIOContext:()=>m,BoxCard:()=>yU,AutoRedirectCard:()=>PU,AjaxGroupCard:()=>CU});module.exports=tU(sz);var b=require("react");var PZ=require("react");var eZ=globalThis,I=(Z,$)=>{let U=Symbol.for(Z);if(!(U in eZ))eZ[U]=$();return eZ[U]};var a=I("@swarm.ing/pieui:context:pieConfig",()=>PZ.createContext(null)),c=()=>{let Z=PZ.useContext(a);if(!Z)throw Error("usePieConfig must be used within PieConfigProvider");return Z},QZ=()=>{let{apiServer:Z}=c();return Z},AZ=QZ,wZ=()=>{let{centrifugeServer:Z}=c();return Z};var p=()=>{let{enableRenderingLog:Z}=c();return Z},P$=p;var e=()=>{let{onLinkLost:Z}=c();return Z},ZZ=()=>{let{onLinkRestored:Z}=c();return Z},NZ="__piedemo__";var w$=require("react"),Z$=require("centrifuge");var A$=I("@swarm.ing/pieui:centrifuge-cache",()=>new Map),LZ=(Z,$)=>{if(!$)return null;let U=`${Z}::${$}`,z=A$.get(U);if(z)return z;async function H(){let T=await fetch(Z+"api/centrifuge/gen_token",{credentials:"include"});if(!T.ok){if(T.status===401||T.status===403)throw new Z$.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${T.status}`)}return(await T.json()).token}let J=new Z$.Centrifuge($,{getToken:H});return A$.set(U,J),J},Zz=I("@swarm.ing/pieui:context:centrifuge",()=>w$.createContext(null)),m=Zz;var L$=require("socket.io-client"),R$=require("react");var N$=I("@swarm.ing/pieui:socket-cache",()=>new Map),RZ=(Z)=>{let $=N$.get(Z);if($)return $;let U=L$.io(Z,{autoConnect:!1,transports:["websocket"]});return N$.set(Z,U),U},$z=I("@swarm.ing/pieui:context:socket",()=>R$.createContext(null)),v=$z;var j$=M$(require("mitt")),$Z=require("react");function d(){return I("@swarm.ing/pieui:mitt-emitter",()=>j$.default())}var E$=I("@swarm.ing/pieui:context:mitt",()=>$Z.createContext(null));function C$(Z){let $=$Z.useContext(E$);return $Z.useCallback((U,z)=>{($??d()).emit(`pie${U}_${Z}`,z)},[Z,$])}var h=E$;function x$(Z){return Z.wasRecovering===!0&&Z.recovered===!1}function y$(Z){return Z.recoverable===!1}function b$(Z,$,U){let z=Z.getSubscription($);if(z)return{subscription:z,createdHere:!1};return{subscription:Z.newSubscription($,U),createdHere:!0}}var Uz=(Z)=>{let $=document.cookie?document.cookie.split(";"):[];for(let U of $){let z=U.indexOf("=");if((z===-1?U:U.slice(0,z)).trim()===Z){let J=z===-1?"":U.slice(z+1).trim();try{return decodeURIComponent(J)}catch{return J}}}return null},zz={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(Z){if(typeof window<"u")window.sid=Z},readWebStorage(Z,$){return(Z==="local"?window.localStorage:window.sessionStorage).getItem($)},readCookie:Uz,readUrlParams(Z){return new URLSearchParams(window.location.search).getAll(Z)},readDomInput(Z){let $=document.getElementsByName(Z);if(!$.length)return null;let U=$[0];if(U instanceof HTMLInputElement){if(U.type==="file"&&U.files)return Array.from(U.files);return[U.value]}if(U instanceof HTMLTextAreaElement)return[U.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let Z=document.getElementById("piedata_global_form");Z&&Z.submit()}},k$=zz;var Hz={};function n(){return Hz}var f$=new Map;var S$=(Z)=>{return f$.has(Z)?f$.get(Z):null};var m$,Jz={isClient(){return!0},readSid(){return m$},setSid(Z){m$=Z},readWebStorage(Z,$){let U=n(),z=Z==="local"?U.storage:U.sessionStorage;return z?z.getItem($):null},async readWebStorageAsync(Z,$){let U=n(),z=Z==="local"?U.asyncStorage:U.asyncSessionStorage;if(z)return z.getItem($);let H=Z==="local"?U.storage:U.sessionStorage;return H?H.getItem($):null},readCookie(Z){let $=n();return $.getCookie?$.getCookie(Z):null},readUrlParams(Z){let $=n();return $.getRouteParams?$.getRouteParams(Z):[]},readDomInput(Z){let $=n();return $.getInput?$.getInput(Z):S$(Z)},submitGlobalForm(){n().submitForm?.()}},v$=Jz;var Tz=typeof navigator<"u"&&navigator.product==="ReactNative",Xz=Tz?v$:k$,N=Xz;var qZ=I("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function h$(){qZ.resolve?.()}function $$(){if(!N.isClient())return Promise.resolve();if(N.readSid()!==void 0)return Promise.resolve();if(!qZ.promise)qZ.promise=new Promise((Z)=>{qZ.resolve=()=>{Z()}});return qZ.promise}var U$=require("react");var Gz=["localStorage","sessionStorage","cookie","url","telegram:cloud","telegram:secure"],Yz=new Set(["telegram:cloud","telegram:secure"]),_Z=new Map,g$=(Z,$)=>{_Z.set(Z,$)},p$=(Z)=>{_Z.delete(Z)},d$=(Z="piedata_global_form")=>{let $;if(typeof Z==="string"){if(typeof document>"u")return;$=document.getElementById(Z)}else $=Z;if(!$)return;let U=$.ownerDocument;for(let z of Array.from($.getElementsByTagName("input")))if(z.getAttribute("data-pie-stored")!==null)z.remove();for(let[z,H]of _Z){let J=H();if(J instanceof Promise)continue;for(let T of J){if(typeof T!=="string")continue;let X=U.createElement("input");X.type="hidden",X.name=z,X.value=T,X.setAttribute("data-pie-stored","1"),$.appendChild(X)}}},VZ=(Z)=>{if(Z==="sid")return{source:"sid",key:"sid"};for(let $ of Gz){let U=$+":";if(Z.startsWith(U))return{source:$,key:Z.slice(U.length)}}return{source:"dom",key:Z}},z$=(Z,$=!1)=>{let{source:U,key:z}=VZ(Z);if(U==="sid"){let T=N.readSid();if(!T)throw Error("SocketIO isn't initialized properly");return[T]}if(U==="localStorage"||U==="sessionStorage")try{let T=N.readWebStorage(U==="localStorage"?"local":"session",z);if(T===null){if($)console.warn(`No ${U} value found for key ${z}`);return[]}return[T]}catch(T){if($)console.warn(`Failed to read ${U} key ${z}:`,T);return[]}if(U==="cookie"){let T=N.readCookie(z);if(T===null){if($)console.warn(`No cookie found for key ${z}`);return[]}return[T]}if(U==="url"){let T=N.readUrlParams(z);if(!T.length&&$)console.warn(`No URL query param found for key ${z}`);return T}if(Yz.has(U)){if($)console.warn(`Source ${U} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}let H=_Z.get(z);if(H){let T=H();if(T instanceof Promise){if($)console.warn(`stored resolver for ${z} is async; use readAjaxKeyAsync (readAjaxKey returns [])`);return[]}return T}let J=N.readDomInput(z);if(J===null){if($)console.warn(`No input found with name ${z}`);return[]}return J},Bz=(Z,$,U)=>{let z=window.Telegram?.WebApp,H=Z==="telegram:cloud"?z?.CloudStorage:z?.SecureStorage,J=Z==="telegram:cloud"?"Telegram CloudStorage":"Telegram SecureStorage";if(!H){if(U)console.warn(`${J} is not available`);return Promise.resolve([])}return new Promise((T)=>{try{H.getItem($,(X,G)=>{if(X){if(U)console.warn(`Failed to read ${J} key ${$}:`,X);T([]);return}if(G==null||G===""){if(U)console.warn(`No ${J} value found for key ${$}`);T([]);return}T([G])})}catch(X){if(U)console.warn(`Failed to read ${J} key ${$}:`,X);T([])}})},H$=async(Z,$=!1)=>{let{source:U,key:z}=VZ(Z);if(U==="telegram:cloud"||U==="telegram:secure")return Bz(U,z,$);if((U==="localStorage"||U==="sessionStorage")&&N.readWebStorageAsync)try{let H=await N.readWebStorageAsync(U==="localStorage"?"local":"session",z);if(H===null){if($)console.warn(`No ${U} value found for key ${z}`);return[]}return[H]}catch(H){if($)console.warn(`Failed to read ${U} key ${z}:`,H);return[]}if(U==="dom"){let H=_Z.get(z);if(H)return H()}return z$(Z,$)},Wz=(Z)=>{if(!Z)return[];if(Array.isArray(Z))return Z.map(([$,U])=>[String($),String(U)]);if(typeof Z.forEach==="function"){let $=[];return Z.forEach((U,z)=>$.push([z,U])),$}return Object.entries(Z)},Qz=(Z)=>{let $=Z.filter(Boolean);if($.length===0)return;if($.length===1)return $[0];let U=AbortSignal.any;if(typeof U==="function")return U.call(AbortSignal,$);let z=new AbortController;for(let H of $){if(H.aborted){z.abort(H.reason);break}H.addEventListener("abort",()=>z.abort(H.reason),{once:!0})}return z.signal},qz=(Z,$,U)=>{let z={method:"POST",credentials:"include"},H={},J=[$];for(let X of U){if(!X)continue;let{headers:G,signal:B,body:q,...Q}=X;Object.assign(z,Q);for(let[V,_]of Wz(G))H[V.toLowerCase()]=_;J.push(B)}if(z.body=Z,Object.keys(H).length>0)z.headers=H;let T=Qz(J);if(T)z.signal=T;return z},u$=(Z,$={},U=[],z,H)=>{let J=H?.renderingLogEnabled??!1,T=H?.timeout,X=H?.retryPolicy,G=X?.maxRetries??0,B=X?.baseDelay??1000,q=X?.retryOn??[502,503,504];if(J)console.log("Registering AJAX: ",z,$,U);return async(Q={},V)=>{if(!N.isClient()){if(J)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}let _=H?.apiServer;if(!_){if(J)console.warn("AJAX skipped: apiServer is missing");return}if(!z||!Z){if(J)console.warn("AJAX skipped: pathname or setUiAjaxConfiguration is missing");return}if(U.includes("sid"))await $$();let W=new FormData;for(let[K,O]of Object.entries({...$,...Q}))W.append(K,O);for(let K of U){let{key:O}=VZ(K);for(let w of await H$(K,J))W.append(O,w)}let P=_+"api/ajax_content"+z;Z(null);let A;for(let K=0;K<=G;K++){if(K>0){let Y=B*2**(K-1);if(J)console.log(`AJAX retry ${K}/${G} after ${Y}ms`);await new Promise((D)=>setTimeout(D,Y))}let O=T!=null?new AbortController:null,w=O&&setTimeout(()=>O.abort(),T);try{let Y=await fetch(P,qz(W,O?.signal,[H?.fetchOptions,V]));if(w)clearTimeout(w);if(!Y.ok&&q.includes(Y.status)&&K<G){A=Error(`HTTP ${Y.status}`);continue}let C=(Y.headers.get("content-type")||"").includes("application/json");if(!!Y.body?.getReader&&!C){let r=Y.body.getReader(),MZ=new TextDecoder,f="";while(!0){let{done:nZ,value:oU}=await r.read();if(nZ)break;f+=MZ.decode(oU,{stream:!0});let K$=f.split(`
|
|
3
|
+
`);f=K$.pop()??"";for(let sU of K$){let tZ=sU.trim();if(!tZ)continue;try{let iU=JSON.parse(tZ);Z([iU])}catch{if(J)console.warn("Failed to parse streamed line:",tZ)}}}if(f.trim())try{let nZ=JSON.parse(f);Z([nZ])}catch{if(J)console.warn("Failed to parse final streamed line:",f)}return{}}else{let r=await Y.json();return Z(r),r}}catch(Y){if(w)clearTimeout(w);if(A=Y,K<G)continue;if(J)console.error("AJAX request failed:",Y);return Z(null),Y}}if(J)console.error("AJAX request failed after retries:",A);return Z(null),A}},c$=(Z,$={},U=[],z,H)=>{let{apiServer:J,enableRenderingLog:T}=c(),X=JSON.stringify($),G=JSON.stringify(U),B=JSON.stringify(H);return U$.useMemo(()=>u$(Z,$,U,z,{apiServer:J,renderingLogEnabled:T,timeout:H?.timeout,retryPolicy:H?.retryPolicy,fetchOptions:H?.fetchOptions}),[Z,X,G,z,J,T,B])},J$=(Z={})=>{let $=[];for(let U of Object.keys(Z??{})){let z=null;if(U==="pathname")z="default";else if(U.endsWith("Pathname"))z=U.slice(0,-8);if(z===null)continue;let H=z==="default"?"":z;$.push({key:z,pathname:Z[U],depsNames:Z[H?`${H}DepsNames`:"depsNames"]??[],kwargs:Z[H?`${H}Kwargs`:"kwargs"]??{}})}return $},l$=(Z={},$,U)=>{let{apiServer:z,enableRenderingLog:H}=c(),J=JSON.stringify(Z??{}),T=JSON.stringify(U);return U$.useMemo(()=>{let X={};for(let G of J$(Z??{}))X[G.key]=u$($,G.kwargs,G.depsNames,G.pathname,{apiServer:z,renderingLogEnabled:H,timeout:U?.timeout,retryPolicy:U?.retryPolicy,fetchOptions:U?.fetchOptions});return X},[J,$,z,H,T])};var UZ=require("react/jsx-runtime"),_z=({card:Z,data:$,children:U,useSocketioSupport:z=!1,useCentrifugeSupport:H=!1,useMittSupport:J=!1,centrifugeChannel:T=void 0,methods:X=void 0,stored:G=void 0,onResync:B=void 0})=>{let q=P$(),Q=b.useRef(X);Q.current=X;let V=b.useRef(B);V.current=B;let _=b.useRef(G);_.current=G;let W=typeof G==="function";if(b.useEffect(()=>{if(!W)return;let O=$.name;return g$(O,()=>[JSON.stringify(_.current())]),()=>p$(O)},[W,$.name]),q)console.log("[PieCard] Rendering card:",Z),console.log("[PieCard] Card data:",$),console.log("[PieCard] Component name:",$?.name),console.log("[PieCard] Real-time support:",{socketio:z,centrifuge:H,mitt:J,centrifugeChannel:T}),console.log("[PieCard] Methods:",X?Object.keys(X):"none"),console.log("[PieCard] Has children:",!!U);let P=b.useContext(v),A=b.useContext(m),K=b.useContext(h);if(b.useEffect(()=>{if(!P||!z||!Q.current||!$.name){if(q&&z)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!P,useSocketioSupport:z,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let w=Object.keys(Q.current??{}).map((Y)=>{let D=`pie${Y}_${$.name}`;if(q)console.log(`[PieCard] Socket.IO registering event: ${D}`);let C=(u)=>{Q.current?.[Y]?.(u)};return P.on(D,C),[D,C]});return()=>{w.forEach(([Y,D])=>{if(q)console.log(`[PieCard] Socket.IO unregistering event: ${Y}`);P.off(Y,D)})}},[P,$.name,z]),b.useEffect(()=>{if(!A||!H||!T||!$.name){if(q&&H)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!A,useCentrifugeSupport:H,hasCentrifugeChannel:!!T,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let w=Object.keys(Q.current??{}).map((Y)=>{let D=`pie${Y}_${$.name}_${T}`;if(q)console.log(`[PieCard] Centrifuge subscribing to channel: ${D}`);let{subscription:C,createdHere:u}=b$(A,D,{recoverable:!0,positioned:!0}),r=(f)=>{if(q)console.log(`[PieCard] Centrifuge received data on ${D}:`,f.data);Q.current?.[Y]?.(f.data)},MZ=(f)=>{if(y$(f))console.warn(`[PieCard] Centrifuge channel ${D} is not `+"recoverable — enable history on the server "+"namespace for exact replay; relying on resync fallback only.");if(x$(f)){if(q)console.log(`[PieCard] Centrifuge recovery gap on ${D}; requesting resync`);V.current?.({channel:D,reason:"gap"})}};return C.on("publication",r),C.on("subscribed",MZ),C.subscribe(),{subscription:C,createdHere:u,onPublication:r,onSubscribed:MZ}});return()=>{w.forEach(({subscription:Y,createdHere:D,onPublication:C,onSubscribed:u})=>{if(q)console.log("[PieCard] Centrifuge unsubscribing from channel");if(Y.off("publication",C),Y.off("subscribed",u),D)Y.unsubscribe(),A.removeSubscription(Y)})}},[A,T,$.name,H]),b.useEffect(()=>{if(!K||!J||!$.name){if(q&&J)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!K,useMittSupport:J,hasMethods:!!Q.current,hasDataName:!!$?.name});return}let O=Object.keys(Q.current??{}),w={};return O.forEach((Y)=>{let D=`pie${Y}_${$.name}`,C=(u)=>{if(q)console.log(`[PieCard] Mitt registering event: ${D}`);Q.current?.[Y]?.(u)};w[D]=C,K.on(D,C)}),()=>{Object.entries(w).forEach(([Y,D])=>{if(q)console.log(`[PieCard] Mitt unregistering event: ${Y}`);K.off(Y,D)})}},[K,$.name,J]),q)console.log("[PieCard] Rendering complete, returning children");if(G!==void 0&&!W)return UZ.jsxs(UZ.Fragment,{children:[UZ.jsx("input",{type:"hidden",name:$.name,value:JSON.stringify(G)}),U]});return U},M=_z;var o$=require("react"),t=new Map;function s$(Z,$){return $.catch(()=>{if(t.get(Z)===$)t.delete(Z)}),t.set(Z,$),$}function jZ(Z,$){return o$.lazy(()=>{if(t.has($))return t.get($);return s$($,Z().then((U)=>U))})}var i$=async(Z,$)=>{if(!$)return;if(t.has(Z))return t.get(Z);return s$(Z,$().then((U)=>U))};var S=I("@swarm.ing/pieui:component-registry",()=>new Map),Vz=(Z)=>{if(!Z.name)throw Error("Component registration requires a name");if(!Z.component&&!Z.loader)throw Error(`Component "${Z.name}" requires component or loader`);let $={name:Z.name,component:Z.component,loader:Z.loader,metadata:Z.metadata,fallback:Z.fallback,isLazy:!1};if(!$.component&&$.loader)$.component=jZ($.loader,Z.name),$.isLazy=!0;return $};function F(Z){let $=Vz(Z);return S.set($.name,$),$.component}var a$=(Z)=>{Z.forEach(($)=>F($))},n$=(Z)=>{S.delete(Z)},t$=(Z)=>{return S.has(Z)},e$=(Z)=>{return S.get(Z)?.metadata},zZ=(Z)=>{return S.get(Z)},ZU=()=>{return Array.from(S.keys())},$U=()=>{return S.size},T$=()=>Array.from(S.values()).filter((Z)=>Z.isLazy&&typeof Z.loader==="function").map((Z)=>Z.name),X$=(Z)=>{let $=S.get(Z);if(!$?.isLazy||typeof $.loader!=="function")return;return i$(Z,$.loader)},r$=!1,UU=()=>{if(r$||typeof window>"u")return;r$=!0;let Z=navigator.connection;if(Z?.saveData)return;if(Z?.effectiveType&&["slow-2g","2g"].includes(Z.effectiveType))return;let $=T$(),U="requestIdleCallback"in window?(H)=>window.requestIdleCallback(H,{timeout:2000}):(H)=>window.setTimeout(H,300),z=(H)=>{if(H>=$.length)return;U(()=>{Promise.resolve().then(()=>X$($[H])).catch(()=>{}).finally(()=>z(H+1))})};z(0)};var DZ=require("react");var zU=require("react");var EZ=require("react/jsx-runtime"),Dz=I("@swarm.ing/pieui:context:fallback",()=>zU.createContext(EZ.jsx(EZ.Fragment,{}))),x=Dz;var HU=require("react");var Kz=I("@swarm.ing/pieui:context:lazyError",()=>HU.createContext(void 0)),l=Kz;var CZ=require("react"),JU=require("react/jsx-runtime"),Fz=2,Oz=400;class HZ extends CZ.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(Z){if(this.props.onError?.(Z),this.state.attempt<Fz){let $=Oz*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((U)=>({failed:!1,attempt:U.attempt+1}))},$)}}componentDidUpdate(Z){if(Z.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return JU.jsx(CZ.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var xZ=require("react/jsx-runtime");function Iz({uiConfig:Z,setUiAjaxConfiguration:$}){let U=DZ.useContext(x),z=DZ.useContext(l),H=p();if(H)console.log("[UI] Rendering component:",Z.card),console.log("[UI] Component data:",Z.data),console.log("[UI] Component content:",Z.content),console.log("[UI] Has setUiAjaxConfiguration:",!!$);let J=zZ(Z.card);if(!J?.component){if(H)console.warn(`[UI] Component not found in registry: ${Z.card}`),console.log("[UI] Returning fallback component");return U}if(H)console.log("[UI] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata});let T=J.component,X=xZ.jsx(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:$});if(J.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",J.name);return xZ.jsx(HZ,{name:J.name,fallback:J.fallback?xZ.jsx(J.fallback,{}):U,onError:z,children:X})}if(H)console.log("[UI] Rendering component directly:",J.name);return X}var j=DZ.memo(Iz);var G$=require("react");var TU=require("react");var Mz=I("@swarm.ing/pieui:context:uiRenderer",()=>TU.createContext(null)),y=Mz;var KZ=require("react/jsx-runtime");function XU({uiConfig:Z,setUiAjaxConfiguration:$}){let U=G$.useContext(x),z=G$.useContext(l),H=p();if(H)console.log("[UILoading] Rendering fallback for:",Z.card),console.log("[UILoading] Component data:",Z.data),console.log("[UILoading] Component content:",Z.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!$);let J=zZ(Z.card);if(!J?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${Z.card}`),console.log("[UILoading] Returning fallback component");return U}if(H)console.log("[UILoading] Found component in registry:",{name:J.name,isLazy:J.isLazy,hasMetadata:!!J.metadata,hasFallback:!!J.fallback});if(J.fallback){if(H)console.log("[UILoading] Rendering fallback for:",J.name);let G=J.fallback;return KZ.jsx(G,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",J.name);let T=J.component,X=KZ.jsx(y.Provider,{value:XU,children:KZ.jsx(T,{data:Z.data,content:Z.content,setUiAjaxConfiguration:$})});if(J.isLazy)return KZ.jsx(HZ,{name:J.name,fallback:U,onError:z,children:X});return X}var yZ=XU;var GU=require("react");var bZ=require("react/jsx-runtime"),Pz=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,sx:H}=Z,J=GU.useContext(y)??j;return bZ.jsx(M,{card:z,data:Z,children:bZ.jsx("div",{style:H,id:z,children:$.map((T,X)=>{return bZ.jsx(J,{uiConfig:T,setUiAjaxConfiguration:U},`children-${X}`)})})})},YU=Pz;var BU=F({name:"SequenceCard",component:YU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var WU=require("react");var Y$=require("react/jsx-runtime"),Az=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z}=Z,H=WU.useContext(y)??j;return Y$.jsx(M,{card:z,data:Z,children:$.map((J,T)=>{return Y$.jsx(H,{uiConfig:J,setUiAjaxConfiguration:U},`children-${T}`)})})},QU=Az;var qU=F({name:"UnionCard",component:QU,metadata:{author:"Swarm.ing",description:"Renders one of many components"}});var kZ=require("react"),_U=M$(require("html-react-parser"));var k=require("react");function wz(){let Z=new AudioContext,$=Z.createOscillator(),U=$.connect(Z.createMediaStreamDestination());$.start();let z=U.stream.getAudioTracks()[0];return z.enabled=!1,z}function B$(Z=null,$){let[U,z]=k.useState(!1),H=k.useRef(null),J=k.useRef(null),T=k.useRef(null),X=k.useCallback(async(Q,V=!0)=>{if(H.current)G();let _=new RTCPeerConnection;if(_.onconnectionstatechange=()=>{if(_.connectionState==="connected")z(!0);else if(["disconnected","failed","closed"].includes(_.connectionState))z(!1)},_.ontrack=(Y)=>{if(Z)Z.srcObject=Y.streams[0]},V){let Y=await navigator.mediaDevices.getUserMedia({audio:!0});_.addTrack(Y.getTracks()[0],Y)}else{let Y=wz();_.addTrack(Y)}let W=_.createDataChannel("oai-events");J.current=W,T.current=new Promise((Y)=>{W.addEventListener("open",()=>{Y()})});let P=await _.createOffer();await _.setLocalDescription(P);let w=await(await fetch(`${"https://api.openai.com/v1/realtime/calls"}?model=${"gpt-realtime"}`,{method:"POST",body:P.sdp,headers:{Authorization:`Bearer ${Q}`,"Content-Type":"application/sdp"}})).text();await _.setRemoteDescription({type:"answer",sdp:w}),H.current=_,await T.current},[Z]),G=k.useCallback(()=>{let Q=J.current;if(Q)Q.close();H.current?.getSenders()?.forEach((V)=>V.track?.stop()),H.current?.close(),z(!1),H.current=null,J.current=null,T.current=null},[Z]),B=k.useCallback((Q)=>{let V=J.current;if(!V){console.error("Data channel is not ready",Q);return}let _=new Date().toLocaleTimeString();if(Q.event_id=Q.event_id||crypto.randomUUID(),V.send(JSON.stringify(Q)),!Q.timestamp)Q.timestamp=_;$?.(Q)},[$,Z]),q=k.useCallback((Q)=>{if(!J.current){console.error("Data channel is not ready");return}let _=()=>{B({type:"conversation.item.create",item:{type:"message",role:"user",content:[{type:"input_text",text:Q}]}}),B({type:"response.create"})};if(T.current)T.current.then(_);else _()},[$,Z]);return k.useEffect(()=>{let Q=J.current;if(!Q)return;let V=(_)=>{let W=JSON.parse(_.data);if(!W.timestamp)W.timestamp=new Date().toLocaleTimeString();$?.(W)};return Q.addEventListener("message",V),()=>{Q.removeEventListener("message",V)}},[$,Z]),{isSessionActive:U,startSession:X,stopSession:G,sendTextMessage:q}}var DU=require("react/jsx-runtime"),Nz=({data:Z})=>{let{html:$,useSocketioSupport:U,useCentrifugeSupport:z,useMittSupport:H,centrifugeChannel:J}=Z,[T,X]=kZ.useState($),{isSessionActive:G,startSession:B,sendTextMessage:q}=B$(null,(W)=>{if(console.log(W.type,W.type==="response.output_text.delta"&&W.delta),W.type==="response.output_text.delta"&&W.delta)X((P)=>P+W.delta)});return kZ.useEffect(()=>{X($)},[$]),DU.jsx(M,{card:"HTMLEmbedCard",data:Z,methods:{update:(W)=>{X(W.value)},generateUsingAI:async(W)=>{try{if(!G&&W.token)await B(W.token,!1);q(W.prompt)}catch(P){console.error("Failed to generate using AI",P)}},initializeAI:async(W)=>{if(!G&&W.token)await B(W.token,!1)}},useCentrifugeSupport:z,useSocketioSupport:U,useMittSupport:H,centrifugeChannel:J,children:_U.default(T)})},VU=Nz;var KU=F({name:"HTMLEmbedCard",component:VU,metadata:{author:"Swarm.ing"}});var fZ=require("react");var W$=require("react/jsx-runtime"),Lz=({data:Z})=>{let{name:$,value:U,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T}=Z,[X,G]=fZ.useState(U);return fZ.useEffect(()=>{G(U)},[U]),W$.jsx(M,{card:"HiddenCard",data:Z,useSocketioSupport:z,useCentrifugeSupport:H,useMittSupport:J,centrifugeChannel:T,methods:{update:({value:B})=>{G(B)}},children:W$.jsx("input",{type:"hidden",id:$,name:$,value:X})})},FU=Lz;var OU=F({name:"HiddenCard",component:FU,metadata:{author:"Swarm.ing"}});var FZ=require("react");var IU=require("react");var Rz=I("@swarm.ing/pieui:context:navigate",()=>IU.createContext(void 0)),g=Rz;var SZ=require("react/jsx-runtime"),jz=({data:Z})=>{let{url:$}=Z,U=FZ.useContext(g),z=FZ.useContext(x);return FZ.useEffect(()=>{if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test($))window.location.href=$;else U?.($)},[$,U]),SZ.jsx(SZ.Fragment,{children:z})},MU=jz;var PU=F({name:"AutoRedirectCard",component:MU,metadata:{author:"Swarm.ing"}});var o=require("react-toastify"),mZ=require("react-toastify");var TZ=require("react");var JZ=require("react/jsx-runtime"),Ez={bounce:o.Bounce,slide:o.Slide,zoom:o.Zoom,flip:o.Flip},Cz=(Z)=>{let $={...Z,type:Z.alertType,transition:Z.transition?Ez[Z.transition]:void 0,position:Z.position??"bottom-right",autoClose:Z.autoClose??3000,style:{backgroundColor:"black",...Z.sx}};mZ.toast(Z.message,$)},xz=(Z)=>{console.log("Log event",Z)},yz=(Z)=>{if(typeof window>"u"||!window.Notification){console.warn("[IOEventsCard] Notifications API is not available");return}let $=()=>{try{new window.Notification(Z.title,{body:Z.message??Z.subtitle,icon:Z.icon,silent:Z.silent})}catch(z){console.error("[IOEventsCard] Failed to show notification",z)}},U=window.Notification.permission;if(U==="granted"){$();return}if(U==="denied"){console.warn("[IOEventsCard] Notification permission denied");return}window.Notification.requestPermission().then((z)=>{if(z==="granted")$()})},bz=({data:Z})=>{let{useCentrifugeSupport:$,useSocketioSupport:U,useMittSupport:z,centrifugeChannel:H}=Z,J=TZ.useContext(g),T=TZ.useRef(J);T.current=J;let X=TZ.useMemo(()=>({alert:Cz,log:xz,push:yz,redirect:(G)=>{if(G.to){let B=G.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()},reload:(G)=>{if(G.to){let B=G.to;if(/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(B))window.location.href=B;else T.current?.(B)}else window.location.reload()}}),[]);return JZ.jsx(JZ.Fragment,{children:JZ.jsx(M,{card:"IOEventsCard",data:Z,useCentrifugeSupport:$,useSocketioSupport:U,useMittSupport:z,centrifugeChannel:H,methods:X,children:JZ.jsx(mZ.ToastContainer,{})})})},AU=bz;var wU=F({name:"IOEventsCard",component:AU,metadata:{author:"Swarm.ing"}});var OZ=require("react");var Q$=require("react/jsx-runtime"),kz=({data:Z})=>{let{name:$,key:U,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X}=Z,[G,B]=OZ.useState(z);return OZ.useEffect(()=>{B(z)},[z]),OZ.useEffect(()=>{if(typeof window>"u")return;sessionStorage.setItem(U,G)},[U,G]),Q$.jsx(M,{card:"SessionStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X,methods:{update:({value:q})=>{B(q)},remove:()=>{sessionStorage.removeItem(U),B("")}},children:Q$.jsx("input",{type:"hidden",id:$,name:$,value:G})})},NU=kz;var LU=F({name:"SessionStorageCard",component:NU,metadata:{author:"PieData"}});var IZ=require("react");var q$=require("react/jsx-runtime"),fz=({data:Z})=>{let{name:$,key:U,value:z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X}=Z,[G,B]=IZ.useState(z);return IZ.useEffect(()=>{B(z)},[z]),IZ.useEffect(()=>{if(typeof window>"u")return;localStorage.setItem(U,G)},[U,G]),q$.jsx(M,{card:"DeviceStorageCard",data:Z,useSocketioSupport:H,useCentrifugeSupport:J,useMittSupport:T,centrifugeChannel:X,methods:{update:({value:q})=>{B(q)},remove:()=>{localStorage.removeItem(U),B("")}},children:q$.jsx("input",{type:"hidden",id:$,name:$,value:G})})},RU=fz;var jU=F({name:"DeviceStorageCard",component:RU,metadata:{author:"PieData"}});var E=require("react");var _$=require("react/jsx-runtime"),Sz=({data:Z,content:$})=>{let{useLoader:U,noReturn:z,returnType:H,useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:X,centrifugeChannel:G}=Z,B=E.useContext(x),q=E.useContext(y)??j,[Q,V]=E.useState(!1),[_,W]=E.useState(null),P=E.useRef($),A=E.useContext(h),K=E.useCallback((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)P.current=Y;if(!z)W(Y)},[z]),O=E.useCallback((Y)=>{P.current=Y.content,W(Y.content)},[]),w=E.useCallback((Y)=>{if(Y===null)V(!0);else if(V(!1),!z)for(let D of Y)A?.emit(D.name,D.data)},[z,A]);if(E.useEffect(()=>{W($),V(!1)},[$]),!_&&U)return B;return _$.jsx(M,{card:"AjaxGroupCard",data:Z,methods:{changeContent:O},useSocketioSupport:J,useCentrifugeSupport:T,useMittSupport:X,centrifugeChannel:G,children:_$.jsx(q,{uiConfig:_??P.current,setUiAjaxConfiguration:H==="events"?w:K})})},EU=Sz;var CU=F({name:"AjaxGroupCard",component:EU,metadata:{author:"Swarm.ing",description:"Group card with AJAX support"}});var V$=require("react");var vZ=require("react/jsx-runtime"),mz=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,url:H,sx:J}=Z,T=V$.useContext(g),X=V$.useContext(y)??j;return vZ.jsx(M,{card:z,data:Z,children:vZ.jsx("div",{style:J,id:z,onClick:(B)=>{if(H)if(B.stopPropagation(),/^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//.test(H))window.location.href=H;else T?.(H)},children:vZ.jsx(X,{setUiAjaxConfiguration:U,uiConfig:$})})})},xU=mz;var yU=F({name:"BoxCard",component:xU,metadata:{author:"Swarm.ing",description:"Simple div with styles joining few components"}});var bU=require("react");var hZ=require("react/jsx-runtime"),vz=({data:Z,content:$,setUiAjaxConfiguration:U})=>{let{name:z,sx:H}=Z,J=bU.useContext(y)??j;return hZ.jsx(M,{card:z,data:Z,children:hZ.jsx("div",{style:H,id:z,children:$.map((T,X)=>{return hZ.jsx(J,{uiConfig:T,setUiAjaxConfiguration:U},`children-${X}`)})})})},kU=vz;var fU=F({name:"OneOfCard",component:kU,metadata:{author:"Swarm.ing",description:"Different variants"}});var GZ=require("react"),YZ=require("@tanstack/react-query");var s=require("react");var dZ=require("react"),gZ=new Map,pZ=new Map;function uZ(Z,$){let U=`${Z}::${$}`,z=Z?gZ.get(U):void 0,[H,J]=dZ.useState(z??null);return dZ.useEffect(()=>{if(!Z)return;if(gZ.has(U)){J(gZ.get(U));return}let T=pZ.get(U);if(!T)T=fetch(Z+`api/support/${$}`,{method:"GET"}).then((G)=>G.json()).then((G)=>{return gZ.set(U,G),pZ.delete(U),G}).catch((G)=>{throw pZ.delete(U),G}),pZ.set(U,T);let X=!1;return T.then((G)=>{if(!X)J(G)}).catch(()=>{}),()=>{X=!0}},[Z,$,U]),H}function XZ(Z,$){if($==="up")return{state:"up",signal:Z==="down"?"restored":null};return{state:"down",signal:Z==="up"?"lost":null}}var hz=({children:Z})=>{let $=s.useContext(v),U=AZ(),z=uZ(U,"socketIO"),H=e(),J=ZZ(),T=s.useRef(H);T.current=H;let X=s.useRef(J);X.current=J;let G=s.useRef("initial"),B=(q)=>{if(N.isClient())N.setSid(q.sid),h$(),console.log(`SocketIO initialized: ${N.readSid()}`)};return s.useEffect(()=>{if(!$||!z)return;let q=()=>{let{state:V,signal:_}=XZ(G.current,"up");if(G.current=V,_==="restored")X.current?.("socketio");console.log("SocketIO connected")},Q=(V)=>{if(console.log(`SocketIO disconnected: ${V}`),$.connect(),V==="io client disconnect")return;let{state:_,signal:W}=XZ(G.current,"down");if(G.current=_,W==="lost")T.current?.("socketio",V)};return $.on("pieinit",B),$.on("connect",q),$.on("disconnect",Q),$.connect(),()=>{$.off("pieinit",B),$.off("connect",q),$.off("disconnect",Q),$.disconnect()}},[$,z]),Z},cZ=hz;var i=require("react");var gz=({children:Z})=>{let $=i.useContext(m),U=AZ(),z=uZ(U,"centrifuge"),H=e(),J=ZZ(),T=i.useRef(H);T.current=H;let X=i.useRef(J);X.current=J;let G=i.useRef("initial");return i.useEffect(()=>{if(!$||!z)return;let B=(V)=>{let{state:_,signal:W}=XZ(G.current,"down");if(G.current=_,W==="lost")T.current?.("centrifuge",V)},q=()=>{let{state:V,signal:_}=XZ(G.current,"up");if(G.current=V,_==="restored")X.current?.("centrifuge");console.log("Centrifuge connected")},Q=(V)=>{console.log("Centrifuge disconnected:",V),B(V)};return $.on("connecting",B),$.on("connected",q),$.on("disconnected",Q),$.connect(),()=>{$.off("connecting",B),$.off("connected",q),$.off("disconnected",Q),$.disconnect()}},[$,z]),Z},lZ=gz;var vU=require("axios-date-transformer");var mU=require("react/jsx-runtime");function SU(Z,$,U){if(!$)return U;let z=Z.replace(/^\//,""),H=$[z];if(!H)return U;return mU.jsx(yZ,{uiConfig:H})}function oZ({apiServer:Z,pathname:$,search:U,root:z,initData:H}){let J=new URLSearchParams(U);if(J.set("__pieroot",z),H)J.set("initData",H);return`${Z.replace(/\/$/,"")}/api/content${$}?${J.toString()}`}async function sZ(Z,$){if(!Z||Z.used||Z.url!==$)return null;Z.used=!0;try{return await Z.promise}catch{return null}}var L=require("react/jsx-runtime"),pz=({location:Z,fallback:$,piecache:U,onError:z,queryOptions:H,configPrefetch:J,disableGlobalForm:T})=>{let X=QZ(),G=wZ(),B=p(),q=GZ.useMemo(()=>vU.createAxiosDateTransformer({baseURL:X||""}),[X]),Q=GZ.useMemo(()=>d(),[]),V=GZ.useMemo(()=>X?RZ(X):null,[X]),_=GZ.useMemo(()=>X?LZ(X,G):null,[X,G]),{data:W,isLoading:P,error:A}=YZ.useQuery({queryKey:["uiConfig",Z.pathname+Z.search,X],enabled:!!X,queryFn:async()=>{let O=oZ({apiServer:X,pathname:Z.pathname,search:Z.search,root:"web"}),w=await sZ(J,O);if(w){if(B)console.log("[PieRoot] Using prefetched UI configuration");return w}if(B)console.log("[PieRoot] Fetching UI configuration from:",O);let Y=await q.get(O,{withCredentials:!0});if(B)console.log("[PieRoot] Received UI configuration:",Y.data);return Y.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(O)=>Math.min(1000*2**O,30000),...H}),K=SU(Z.pathname,U,$);if(!X)return K??null;if(B)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] CENTRIFUGE_SERVER:",G),console.log("[PieRoot] Fallback provided:",!!$),console.log("[PieRoot] Piecache provided:",!!U);if(A){if(B)console.error("[PieRoot] Error fetching UI configuration:",A),console.error("[PieRoot] Error details:",{message:A.message,status:A.response?.status,data:A.response?.data});return z?.(A),K}if(P||!W){if(B)console.log("[PieRoot] Loading state:",{isLoading:P,hasUiConfiguration:!!W});return K}if(B)console.log("[PieRoot] UI configuration loaded successfully:",W),console.log("[PieRoot] Rendering UI with configuration");return L.jsx(h.Provider,{value:Q,children:L.jsx(v.Provider,{value:V,children:L.jsx(m.Provider,{value:_,children:L.jsx(x.Provider,{value:$??L.jsx(L.Fragment,{}),children:L.jsx(cZ,{children:L.jsx(lZ,{children:T?L.jsx(j,{uiConfig:W}):L.jsx("form",{id:"piedata_global_form",action:X+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:L.jsx(j,{uiConfig:W})})})})})})})})},dz=(Z)=>{let $=GZ.useMemo(()=>new YZ.QueryClient,[]),U=Z.queryClient??$;return L.jsx(g.Provider,{value:Z.onNavigate,children:L.jsx(a.Provider,{value:Z.config,children:L.jsx(l.Provider,{value:Z.onError,children:L.jsx(YZ.QueryClientProvider,{client:U,children:L.jsx(pz,{...Z})})})})})},iZ=dz;var BZ=require("react"),rZ=require("@tanstack/react-query");var R=require("react/jsx-runtime"),uz=({location:Z,fallback:$,children:U,disableGlobalForm:z})=>{let H=QZ(),J=wZ(),T=p(),X=BZ.useMemo(()=>d(),[]),G=BZ.useMemo(()=>H?RZ(H):null,[H]),B=BZ.useMemo(()=>H?LZ(H,J):null,[H,J]);if(T)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",H),console.log("[PieRoot] CENTRIFUGE_SERVER:",J),console.log("[PieRoot] Fallback provided:",!!$);return R.jsx(h.Provider,{value:X,children:R.jsx(v.Provider,{value:G,children:R.jsx(m.Provider,{value:B,children:R.jsx(x.Provider,{value:$??R.jsx(R.Fragment,{}),children:R.jsx(cZ,{children:R.jsx(lZ,{children:z?U:R.jsx("form",{id:"piedata_global_form",action:H+"api/process"+Z.pathname,method:"post",encType:"multipart/form-data",children:U})})})})})})})},cz=(Z)=>{let[$]=BZ.useState(()=>new rZ.QueryClient),U=Z.queryClient??$;return R.jsx(g.Provider,{value:Z.onNavigate,children:R.jsx(a.Provider,{value:Z.config,children:R.jsx(l.Provider,{value:Z.onError,children:R.jsx(rZ.QueryClientProvider,{client:U,children:R.jsx(uz,{...Z})})})})})},hU=cz;var aZ=require("react");var D$=require("react/jsx-runtime"),lz=D$.jsx("div",{style:{padding:16,fontFamily:"system-ui, sans-serif",color:"#888"},children:"Loading card…"}),oz=({apiServer:Z,pathname:$="/",search:U="",centrifugeServer:z,previewEvents:H=!1,fallback:J,enableRenderingLog:T=!1})=>{let X=Z??(typeof process<"u"?process.env.PIE_API_SERVER:void 0)??"";aZ.useEffect(()=>{if(!H||!X||typeof window>"u"||typeof EventSource>"u")return;let q=X.endsWith("/")?X:`${X}/`,Q=new EventSource(`${q}api/preview/events`),V=d();return Q.onmessage=(_)=>{try{let W=JSON.parse(_.data);if(W&&typeof W.name==="string")V.emit(W.name,W.payload)}catch{}},()=>Q.close()},[H,X]);let G=aZ.useMemo(()=>({apiServer:X,centrifugeServer:z,enableRenderingLog:T,pageProcessor:"web"}),[X,z,T]);return D$.jsx(iZ,{location:{pathname:$,search:U},config:G,fallback:J??lz,onNavigate:(q)=>{if(typeof window<"u")window.history.pushState(null,"",q)}})},gU=oz;var pU=require("clsx"),dU=require("tailwind-merge");function uU(...Z){return dU.twMerge(pU.clsx(Z))}var cU=()=>{d$(),N.submitGlobalForm()};var lU=(Z,$)=>`${Z}${NZ}${$}`;
|
package/dist/max/index.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useMemo as P}from"react";import{QueryClient as XT,QueryClientProvider as qT,useQuery as DT}from"@tanstack/react-query";import EU from"mitt";import{createContext as jU,useCallback as AT,useContext as PT}from"react";var h=globalThis,Y=(U,T)=>{let z=Symbol.for(U);if(!(z in h))h[z]=T();return h[z]};function n(){return Y("@swarm.ing/pieui:mitt-emitter",()=>EU())}var IU=Y("@swarm.ing/pieui:context:mitt",()=>jU(null));var i=IU;import{io as OU}from"socket.io-client";import{createContext as MU}from"react";var t=Y("@swarm.ing/pieui:socket-cache",()=>new Map),e=(U)=>{let T=t.get(U);if(T)return T;let z=OU(U,{autoConnect:!1,transports:["websocket"]});return t.set(U,z),z},LU=Y("@swarm.ing/pieui:context:socket",()=>MU(null)),R=LU;import{createContext as AU}from"react";import{Centrifuge as UU}from"centrifuge";var TU=Y("@swarm.ing/pieui:centrifuge-cache",()=>new Map),zU=(U,T)=>{if(!T)return null;let z=`${U}::${T}`,Z=TU.get(z);if(Z)return Z;async function H(){let J=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!J.ok){if(J.status===401||J.status===403)throw new UU.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${J.status}`)}return(await J.json()).token}let $=new UU(T,{getToken:H});return TU.set(z,$),$},PU=Y("@swarm.ing/pieui:context:centrifuge",()=>AU(null)),y=PU;import{useContext as hU,useEffect as dU,useRef as u}from"react";import{useEffect as RU,useState as yU}from"react";var w=new Map,x=new Map;function b(U,T){let z=`${U}::${T}`,Z=U?w.get(z):void 0,[H,$]=yU(Z??null);return RU(()=>{if(!U)return;if(w.has(z)){$(w.get(z));return}let J=x.get(z);if(!J)J=fetch(U+`api/support/${T}`,{method:"GET"}).then((V)=>V.json()).then((V)=>{return w.set(z,V),x.delete(z),V}).catch((V)=>{throw x.delete(z),V}),x.set(z,J);let G=!1;return J.then((V)=>{if(!G)$(V)}).catch(()=>{}),()=>{G=!0}},[U,T,z]),H}import{createContext as wU,useContext as xU}from"react";var d=Y("@swarm.ing/pieui:context:pieConfig",()=>wU(null)),A=()=>{let U=xU(d);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},g=()=>{let{apiServer:U}=A();return U},C=g,$U=()=>{let{centrifugeServer:U}=A();return U};var N=()=>{let{enableRenderingLog:U}=A();return U};var m=()=>{let{onLinkLost:U}=A();return U},f=()=>{let{onLinkRestored:U}=A();return U};var bU=(U)=>{let T=document.cookie?document.cookie.split(";"):[];for(let z of T){let Z=z.indexOf("=");if((Z===-1?z:z.slice(0,Z)).trim()===U){let $=Z===-1?"":z.slice(Z+1).trim();try{return decodeURIComponent($)}catch{return $}}}return null},CU={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,T){return(U==="local"?window.localStorage:window.sessionStorage).getItem(T)},readCookie:bU,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let T=document.getElementsByName(U);if(!T.length)return null;let z=T[0];if(z instanceof HTMLInputElement){if(z.type==="file"&&z.files)return Array.from(z.files);return[z.value]}if(z instanceof HTMLTextAreaElement)return[z.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},JU=CU;var mU={};function B(){return mU}var HU=new Map;var ZU=(U)=>{return HU.has(U)?HU.get(U):null};var VU,fU={isClient(){return!0},readSid(){return VU},setSid(U){VU=U},readWebStorage(U,T){let z=B(),Z=U==="local"?z.storage:z.sessionStorage;return Z?Z.getItem(T):null},async readWebStorageAsync(U,T){let z=B(),Z=U==="local"?z.asyncStorage:z.asyncSessionStorage;if(Z)return Z.getItem(T);let H=U==="local"?z.storage:z.sessionStorage;return H?H.getItem(T):null},readCookie(U){let T=B();return T.getCookie?T.getCookie(U):null},readUrlParams(U){let T=B();return T.getRouteParams?T.getRouteParams(U):[]},readDomInput(U){let T=B();return T.getInput?T.getInput(U):ZU(U)},submitGlobalForm(){B().submitForm?.()}},YU=fU;var SU=typeof navigator<"u"&&navigator.product==="ReactNative",kU=SU?YU:JU,S=kU;var vU=Y("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function GU(){vU.resolve?.()}function E(U,T){if(T==="up")return{state:"up",signal:U==="down"?"restored":null};return{state:"down",signal:U==="up"?"lost":null}}var gU=({children:U})=>{let T=hU(R),z=C(),Z=b(z,"socketIO"),H=m(),$=f(),J=u(H);J.current=H;let G=u($);G.current=$;let V=u("initial"),q=(K)=>{if(S.isClient())S.setSid(K.sid),GU(),console.log(`SocketIO initialized: ${S.readSid()}`)};return dU(()=>{if(!T||!Z)return;let K=()=>{let{state:_,signal:F}=E(V.current,"up");if(V.current=_,F==="restored")G.current?.("socketio");console.log("SocketIO connected")},D=(_)=>{if(console.log(`SocketIO disconnected: ${_}`),T.connect(),_==="io client disconnect")return;let{state:F,signal:X}=E(V.current,"down");if(V.current=F,X==="lost")J.current?.("socketio",_)};return T.on("pieinit",q),T.on("connect",K),T.on("disconnect",D),T.connect(),()=>{T.off("pieinit",q),T.off("connect",K),T.off("disconnect",D),T.disconnect()}},[T,Z]),U},QU=gU;import{useContext as uU,useEffect as pU,useRef as p}from"react";var lU=({children:U})=>{let T=uU(y),z=C(),Z=b(z,"centrifuge"),H=m(),$=f(),J=p(H);J.current=H;let G=p($);G.current=$;let V=p("initial");return pU(()=>{if(!T||!Z)return;let q=(_)=>{let{state:F,signal:X}=E(V.current,"down");if(V.current=F,X==="lost")J.current?.("centrifuge",_)},K=()=>{let{state:_,signal:F}=E(V.current,"up");if(V.current=_,F==="restored")G.current?.("centrifuge");console.log("Centrifuge connected")},D=(_)=>{console.log("Centrifuge disconnected:",_),q(_)};return T.on("connecting",q),T.on("connected",K),T.on("disconnected",D),T.connect(),()=>{T.off("connecting",q),T.off("connected",K),T.off("disconnected",D),T.disconnect()}},[T,Z]),U},_U=lU;import{createContext as cU}from"react";import{jsx as aU,Fragment as sU}from"react/jsx-runtime";var oU=Y("@swarm.ing/pieui:context:fallback",()=>cU(aU(sU,{}))),j=oU;import{createContext as rU}from"react";var nU=Y("@swarm.ing/pieui:context:lazyError",()=>rU(void 0)),I=nU;var iU=Y("@swarm.ing/pieui:component-registry",()=>new Map);var k=(U)=>{return iU.get(U)};import{useContext as FU,memo as $T}from"react";import{Component as tU,Suspense as eU}from"react";import{jsx as zT}from"react/jsx-runtime";var UT=2,TT=400;class O extends tU{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<UT){let T=TT*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((z)=>({failed:!1,attempt:z.attempt+1}))},T)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return zT(eU,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}import{jsx as l}from"react/jsx-runtime";function JT({uiConfig:U,setUiAjaxConfiguration:T}){let z=FU(j),Z=FU(I),H=N();if(H)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!T);let $=k(U.card);if(!$?.component){if(H)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return z}if(H)console.log("[UI] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata});let J=$.component,G=l(J,{data:U.data,content:U.content,setUiAjaxConfiguration:T});if($.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",$.name);return l(O,{name:$.name,fallback:$.fallback?l($.fallback,{}):z,onError:Z,children:G})}if(H)console.log("[UI] Rendering component directly:",$.name);return G}var c=$T(JT);import{createAxiosDateTransformer as BT}from"axios-date-transformer";import{useEffect as KU,useState as HT}from"react";var M=()=>{let[U,T]=HT(null);return KU(()=>{if(typeof window>"u")return;let z=window.WebApp;if(!z)return;z.ready(),T(z)},[]),U},ZT=()=>{let U=M();return[U?.initDataUnsafe,U?.initData]},VT=(U)=>{let T=M();return KU(()=>{if(!T||!U)return;return T.BackButton.onClick(U),T.BackButton.show(),()=>{T.BackButton.offClick(U),T.BackButton.hide()}},[T,U]),T?.BackButton??null},YT=()=>{return M()?.HapticFeedback??null};import{createContext as GT}from"react";var QT=Y("@swarm.ing/pieui:context:navigate",()=>GT(void 0)),XU=QT;import{useContext as DU}from"react";import{createContext as _T}from"react";var FT=Y("@swarm.ing/pieui:context:uiRenderer",()=>_T(null)),qU=FT;import{jsx as v}from"react/jsx-runtime";function BU({uiConfig:U,setUiAjaxConfiguration:T}){let z=DU(j),Z=DU(I),H=N();if(H)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!T);let $=k(U.card);if(!$?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return z}if(H)console.log("[UILoading] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata,hasFallback:!!$.fallback});if($.fallback){if(H)console.log("[UILoading] Rendering fallback for:",$.name);let V=$.fallback;return v(V,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",$.name);let J=$.component,G=v(qU.Provider,{value:BU,children:v(J,{data:U.data,content:U.content,setUiAjaxConfiguration:T})});if($.isLazy)return v(O,{name:$.name,fallback:z,onError:Z,children:G});return G}var WU=BU;import{jsx as KT}from"react/jsx-runtime";function NU(U,T,z){if(!T)return z;let Z=U.replace(/^\//,""),H=T[Z];if(!H)return z;return KT(WU,{uiConfig:H})}import{jsx as Q,Fragment as ET}from"react/jsx-runtime";var WT=({location:U,fallback:T,piecache:z,onError:Z,queryOptions:H,disableGlobalForm:$})=>{let J=g(),G=$U(),V=N(),q=P(()=>BT({baseURL:J}),[J]),K=P(()=>n(),[]),D=P(()=>J?e(J):null,[J]),_=P(()=>J?zU(J,G):null,[J,G]),F=M(),{data:X,isLoading:o,error:W}=DT({queryKey:["uiConfig",U.pathname+U.search,F?.initData],queryFn:async()=>{let L=new URLSearchParams(U.search);if(L.set("__pieroot","max"),F?.initData)L.set("initData",F.initData);let a="/api/content"+U.pathname+"?"+L.toString();if(V)console.log("[PieRoot] Fetching UI configuration from:",a);let r=await q.get(a,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(V)console.log("[PieRoot] Received UI configuration:",r.data);return r.data},enabled:!!F?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(L)=>Math.min(1000*2**L,30000),...H}),s=NU(U.pathname,z,T);if(!J)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(W&&V)return console.error("[PieRoot] Error fetching UI configuration:",W),console.error("[PieRoot] Error details:",{message:W.message,status:W.response?.status,data:W.response?.data}),Z?.(W),s;if(o||!X){if(V)console.log("[PieRoot] Loading state:",{isLoading:o,hasUiConfiguration:!!X});return s}if(V)console.log("[PieRoot] UI configuration loaded successfully:",X),console.log("[PieRoot] Rendering UI with configuration");return Q(i.Provider,{value:K,children:Q(R.Provider,{value:D,children:Q(y.Provider,{value:_,children:Q(j.Provider,{value:T??Q(ET,{}),children:Q(QU,{children:Q(_U,{children:$?Q(c,{uiConfig:X}):Q("form",{id:"piedata_global_form",action:J+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:Q(c,{uiConfig:X})})})})})})})})},NT=(U)=>{let T=P(()=>new XT,[]),z=U.queryClient??T;return Q(XU.Provider,{value:U.onNavigate,children:Q(d.Provider,{value:U.config,children:Q(I.Provider,{value:U.onError,children:Q(qT,{client:z,children:Q(WT,{...U})})})})})},jT=NT;export{M as useMaxWebApp,ZT as useMaxInitData,YT as useMaxHapticFeedback,VT as useMaxBackButton,jT as PieMaxRoot};
|
|
2
|
+
import{useMemo as R}from"react";import{QueryClient as WT,QueryClientProvider as DT,useQuery as NT}from"@tanstack/react-query";import OU from"mitt";import{createContext as MU,useCallback as yT,useContext as wT}from"react";var h=globalThis,G=(U,T)=>{let z=Symbol.for(U);if(!(z in h))h[z]=T();return h[z]};function i(){return G("@swarm.ing/pieui:mitt-emitter",()=>OU())}var LU=G("@swarm.ing/pieui:context:mitt",()=>MU(null));var t=LU;import{io as AU}from"socket.io-client";import{createContext as PU}from"react";var e=G("@swarm.ing/pieui:socket-cache",()=>new Map),UU=(U)=>{let T=e.get(U);if(T)return T;let z=AU(U,{autoConnect:!1,transports:["websocket"]});return e.set(U,z),z},RU=G("@swarm.ing/pieui:context:socket",()=>PU(null)),y=RU;import{createContext as yU}from"react";import{Centrifuge as TU}from"centrifuge";var zU=G("@swarm.ing/pieui:centrifuge-cache",()=>new Map),$U=(U,T)=>{if(!T)return null;let z=`${U}::${T}`,H=zU.get(z);if(H)return H;async function J(){let V=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!V.ok){if(V.status===401||V.status===403)throw new TU.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${V.status}`)}return(await V.json()).token}let $=new TU(T,{getToken:J});return zU.set(z,$),$},wU=G("@swarm.ing/pieui:context:centrifuge",()=>yU(null)),w=wU;import{useContext as uU,useEffect as pU,useRef as p}from"react";import{useEffect as xU,useState as bU}from"react";var x=new Map,b=new Map;function C(U,T){let z=`${U}::${T}`,H=U?x.get(z):void 0,[J,$]=bU(H??null);return xU(()=>{if(!U)return;if(x.has(z)){$(x.get(z));return}let V=b.get(z);if(!V)V=fetch(U+`api/support/${T}`,{method:"GET"}).then((Y)=>Y.json()).then((Y)=>{return x.set(z,Y),b.delete(z),Y}).catch((Y)=>{throw b.delete(z),Y}),b.set(z,V);let Z=!1;return V.then((Y)=>{if(!Z)$(Y)}).catch(()=>{}),()=>{Z=!0}},[U,T,z]),J}import{createContext as CU,useContext as mU}from"react";var g=G("@swarm.ing/pieui:context:pieConfig",()=>CU(null)),P=()=>{let U=mU(g);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},u=()=>{let{apiServer:U}=P();return U},m=u,JU=()=>{let{centrifugeServer:U}=P();return U};var N=()=>{let{enableRenderingLog:U}=P();return U};var S=()=>{let{onLinkLost:U}=P();return U},k=()=>{let{onLinkRestored:U}=P();return U};var SU=(U)=>{let T=document.cookie?document.cookie.split(";"):[];for(let z of T){let H=z.indexOf("=");if((H===-1?z:z.slice(0,H)).trim()===U){let $=H===-1?"":z.slice(H+1).trim();try{return decodeURIComponent($)}catch{return $}}}return null},kU={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,T){return(U==="local"?window.localStorage:window.sessionStorage).getItem(T)},readCookie:SU,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let T=document.getElementsByName(U);if(!T.length)return null;let z=T[0];if(z instanceof HTMLInputElement){if(z.type==="file"&&z.files)return Array.from(z.files);return[z.value]}if(z instanceof HTMLTextAreaElement)return[z.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},HU=kU;var vU={};function W(){return vU}var ZU=new Map;var VU=(U)=>{return ZU.has(U)?ZU.get(U):null};var YU,fU={isClient(){return!0},readSid(){return YU},setSid(U){YU=U},readWebStorage(U,T){let z=W(),H=U==="local"?z.storage:z.sessionStorage;return H?H.getItem(T):null},async readWebStorageAsync(U,T){let z=W(),H=U==="local"?z.asyncStorage:z.asyncSessionStorage;if(H)return H.getItem(T);let J=U==="local"?z.storage:z.sessionStorage;return J?J.getItem(T):null},readCookie(U){let T=W();return T.getCookie?T.getCookie(U):null},readUrlParams(U){let T=W();return T.getRouteParams?T.getRouteParams(U):[]},readDomInput(U){let T=W();return T.getInput?T.getInput(U):VU(U)},submitGlobalForm(){W().submitForm?.()}},GU=fU;var dU=typeof navigator<"u"&&navigator.product==="ReactNative",hU=dU?GU:HU,v=hU;var gU=G("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function QU(){gU.resolve?.()}function E(U,T){if(T==="up")return{state:"up",signal:U==="down"?"restored":null};return{state:"down",signal:U==="up"?"lost":null}}var lU=({children:U})=>{let T=uU(y),z=m(),H=C(z,"socketIO"),J=S(),$=k(),V=p(J);V.current=J;let Z=p($);Z.current=$;let Y=p("initial"),F=(K)=>{if(v.isClient())v.setSid(K.sid),QU(),console.log(`SocketIO initialized: ${v.readSid()}`)};return pU(()=>{if(!T||!H)return;let K=()=>{let{state:_,signal:X}=E(Y.current,"up");if(Y.current=_,X==="restored")Z.current?.("socketio");console.log("SocketIO connected")},q=(_)=>{if(console.log(`SocketIO disconnected: ${_}`),T.connect(),_==="io client disconnect")return;let{state:X,signal:B}=E(Y.current,"down");if(Y.current=X,B==="lost")V.current?.("socketio",_)};return T.on("pieinit",F),T.on("connect",K),T.on("disconnect",q),T.connect(),()=>{T.off("pieinit",F),T.off("connect",K),T.off("disconnect",q),T.disconnect()}},[T,H]),U},_U=lU;import{useContext as cU,useEffect as oU,useRef as l}from"react";var sU=({children:U})=>{let T=cU(w),z=m(),H=C(z,"centrifuge"),J=S(),$=k(),V=l(J);V.current=J;let Z=l($);Z.current=$;let Y=l("initial");return oU(()=>{if(!T||!H)return;let F=(_)=>{let{state:X,signal:B}=E(Y.current,"down");if(Y.current=X,B==="lost")V.current?.("centrifuge",_)},K=()=>{let{state:_,signal:X}=E(Y.current,"up");if(Y.current=_,X==="restored")Z.current?.("centrifuge");console.log("Centrifuge connected")},q=(_)=>{console.log("Centrifuge disconnected:",_),F(_)};return T.on("connecting",F),T.on("connected",K),T.on("disconnected",q),T.connect(),()=>{T.off("connecting",F),T.off("connected",K),T.off("disconnected",q),T.disconnect()}},[T,H]),U},FU=sU;import{createContext as aU}from"react";import{jsx as iU,Fragment as nU}from"react/jsx-runtime";var rU=G("@swarm.ing/pieui:context:fallback",()=>aU(iU(nU,{}))),j=rU;import{createContext as tU}from"react";var eU=G("@swarm.ing/pieui:context:lazyError",()=>tU(void 0)),I=eU;var UT=G("@swarm.ing/pieui:component-registry",()=>new Map);var f=(U)=>{return UT.get(U)};import{useContext as KU,memo as ZT}from"react";import{Component as TT,Suspense as zT}from"react";import{jsx as HT}from"react/jsx-runtime";var $T=2,JT=400;class O extends TT{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<$T){let T=JT*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((z)=>({failed:!1,attempt:z.attempt+1}))},T)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return HT(zT,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}import{jsx as c}from"react/jsx-runtime";function VT({uiConfig:U,setUiAjaxConfiguration:T}){let z=KU(j),H=KU(I),J=N();if(J)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!T);let $=f(U.card);if(!$?.component){if(J)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return z}if(J)console.log("[UI] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata});let V=$.component,Z=c(V,{data:U.data,content:U.content,setUiAjaxConfiguration:T});if($.isLazy){if(J)console.log("[UI] Rendering lazy component with Suspense:",$.name);return c(O,{name:$.name,fallback:$.fallback?c($.fallback,{}):z,onError:H,children:Z})}if(J)console.log("[UI] Rendering component directly:",$.name);return Z}var o=ZT(VT);import{createAxiosDateTransformer as ET}from"axios-date-transformer";import{useEffect as XU,useState as YT}from"react";var M=()=>{let[U,T]=YT(null);return XU(()=>{if(typeof window>"u")return;let z=window.WebApp;if(!z)return;z.ready(),T(z)},[]),U},GT=()=>{let U=M();return[U?.initDataUnsafe,U?.initData]},QT=(U)=>{let T=M();return XU(()=>{if(!T||!U)return;return T.BackButton.onClick(U),T.BackButton.show(),()=>{T.BackButton.offClick(U),T.BackButton.hide()}},[T,U]),T?.BackButton??null},_T=()=>{return M()?.HapticFeedback??null};import{createContext as FT}from"react";var KT=G("@swarm.ing/pieui:context:navigate",()=>FT(void 0)),qU=KT;import{useContext as WU}from"react";import{createContext as XT}from"react";var qT=G("@swarm.ing/pieui:context:uiRenderer",()=>XT(null)),BU=qT;import{jsx as d}from"react/jsx-runtime";function DU({uiConfig:U,setUiAjaxConfiguration:T}){let z=WU(j),H=WU(I),J=N();if(J)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!T);let $=f(U.card);if(!$?.component){if(J)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return z}if(J)console.log("[UILoading] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata,hasFallback:!!$.fallback});if($.fallback){if(J)console.log("[UILoading] Rendering fallback for:",$.name);let Y=$.fallback;return d(Y,{})}if(J)console.log("[UILoading] No fallback, rendering full component:",$.name);let V=$.component,Z=d(BU.Provider,{value:DU,children:d(V,{data:U.data,content:U.content,setUiAjaxConfiguration:T})});if($.isLazy)return d(O,{name:$.name,fallback:z,onError:H,children:Z});return Z}var NU=DU;import{jsx as BT}from"react/jsx-runtime";function EU(U,T,z){if(!T)return z;let H=U.replace(/^\//,""),J=T[H];if(!J)return z;return BT(NU,{uiConfig:J})}function jU({apiServer:U,pathname:T,search:z,root:H,initData:J}){let $=new URLSearchParams(z);if($.set("__pieroot",H),J)$.set("initData",J);return`${U.replace(/\/$/,"")}/api/content${T}?${$.toString()}`}async function IU(U,T){if(!U||U.used||U.url!==T)return null;U.used=!0;try{return await U.promise}catch{return null}}import{jsx as Q,Fragment as OT}from"react/jsx-runtime";var jT=({location:U,fallback:T,piecache:z,onError:H,queryOptions:J,configPrefetch:$,disableGlobalForm:V})=>{let Z=u(),Y=JU(),F=N(),K=R(()=>ET({baseURL:Z}),[Z]),q=R(()=>i(),[]),_=R(()=>Z?UU(Z):null,[Z]),X=R(()=>Z?$U(Z,Y):null,[Z,Y]),B=M(),{data:L,isLoading:s,error:D}=NT({queryKey:["uiConfig",U.pathname+U.search,B?.initData],queryFn:async()=>{let A=jU({apiServer:Z,pathname:U.pathname,search:U.search,root:"max",initData:B?.initData}),r=await IU($,A);if(r){if(F)console.log("[PieRoot] Using prefetched UI configuration");return r}if(F)console.log("[PieRoot] Fetching UI configuration from:",A);let n=await K.get(A,{withCredentials:!0});if(F)console.log("[PieRoot] Received UI configuration:",n.data);return n.data},enabled:!!B?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(A)=>Math.min(1000*2**A,30000),...J}),a=EU(U.pathname,z,T);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(D&&F)return console.error("[PieRoot] Error fetching UI configuration:",D),console.error("[PieRoot] Error details:",{message:D.message,status:D.response?.status,data:D.response?.data}),H?.(D),a;if(s||!L){if(F)console.log("[PieRoot] Loading state:",{isLoading:s,hasUiConfiguration:!!L});return a}if(F)console.log("[PieRoot] UI configuration loaded successfully:",L),console.log("[PieRoot] Rendering UI with configuration");return Q(t.Provider,{value:q,children:Q(y.Provider,{value:_,children:Q(w.Provider,{value:X,children:Q(j.Provider,{value:T??Q(OT,{}),children:Q(_U,{children:Q(FU,{children:V?Q(o,{uiConfig:L}):Q("form",{id:"piedata_global_form",action:Z+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:Q(o,{uiConfig:L})})})})})})})})},IT=(U)=>{let T=R(()=>new WT,[]),z=U.queryClient??T;return Q(qU.Provider,{value:U.onNavigate,children:Q(g.Provider,{value:U.config,children:Q(I.Provider,{value:U.onError,children:Q(DT,{client:z,children:Q(jT,{...U})})})})})},MT=IT;export{M as useMaxWebApp,GT as useMaxInitData,_T as useMaxHapticFeedback,QT as useMaxBackButton,MT as PieMaxRoot};
|
package/dist/max/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var cU=Object.create;var{getPrototypeOf:oU,defineProperty:w,getOwnPropertyNames:YU,getOwnPropertyDescriptor:sU}=Object,GU=Object.prototype.hasOwnProperty;var aU=(U,T,z)=>{z=U!=null?cU(oU(U)):{};let J=T||!U||!U.__esModule?w(z,"default",{value:U,enumerable:!0}):z;for(let H of YU(U))if(!GU.call(J,H))w(J,H,{get:()=>U[H],enumerable:!0});return J},VU=new WeakMap,rU=(U)=>{var T=VU.get(U),z;if(T)return T;if(T=w({},"__esModule",{value:!0}),U&&typeof U==="object"||typeof U==="function")YU(U).map((J)=>!GU.call(T,J)&&w(T,J,{get:()=>U[J],enumerable:!(z=sU(U,J))||z.enumerable}));return VU.set(U,T),T};var nU=(U,T)=>{for(var z in T)w(U,z,{get:T[z],enumerable:!0,configurable:!0,set:(J)=>T[z]=()=>J})};var NT={};nU(NT,{useMaxWebApp:()=>E,useMaxInitData:()=>bU,useMaxHapticFeedback:()=>mU,useMaxBackButton:()=>CU,PieMaxRoot:()=>lU});module.exports=rU(NT);var P=require("react"),R=require("@tanstack/react-query");var QU=aU(require("mitt")),f=require("react");var i=globalThis,Y=(U,T)=>{let z=Symbol.for(U);if(!(z in i))i[z]=T();return i[z]};function _U(){return Y("@swarm.ing/pieui:mitt-emitter",()=>QU.default())}var iU=Y("@swarm.ing/pieui:context:mitt",()=>f.createContext(null));var FU=iU;var XU=require("socket.io-client"),qU=require("react");var KU=Y("@swarm.ing/pieui:socket-cache",()=>new Map),DU=(U)=>{let T=KU.get(U);if(T)return T;let z=XU.io(U,{autoConnect:!1,transports:["websocket"]});return KU.set(U,z),z},tU=Y("@swarm.ing/pieui:context:socket",()=>qU.createContext(null)),S=tU;var WU=require("react"),t=require("centrifuge");var BU=Y("@swarm.ing/pieui:centrifuge-cache",()=>new Map),NU=(U,T)=>{if(!T)return null;let z=`${U}::${T}`,J=BU.get(z);if(J)return J;async function H(){let Z=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!Z.ok){if(Z.status===401||Z.status===403)throw new t.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${Z.status}`)}return(await Z.json()).token}let $=new t.Centrifuge(T,{getToken:H});return BU.set(z,$),$},eU=Y("@swarm.ing/pieui:context:centrifuge",()=>WU.createContext(null)),k=eU;var D=require("react");var d=require("react"),v=new Map,h=new Map;function g(U,T){let z=`${U}::${T}`,J=U?v.get(z):void 0,[H,$]=d.useState(J??null);return d.useEffect(()=>{if(!U)return;if(v.has(z)){$(v.get(z));return}let Z=h.get(z);if(!Z)Z=fetch(U+`api/support/${T}`,{method:"GET"}).then((V)=>V.json()).then((V)=>{return v.set(z,V),h.delete(z),V}).catch((V)=>{throw h.delete(z),V}),h.set(z,Z);let G=!1;return Z.then((V)=>{if(!G)$(V)}).catch(()=>{}),()=>{G=!0}},[U,T,z]),H}var u=require("react");var e=Y("@swarm.ing/pieui:context:pieConfig",()=>u.createContext(null)),x=()=>{let U=u.useContext(e);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},UU=()=>{let{apiServer:U}=x();return U},p=UU,EU=()=>{let{centrifugeServer:U}=x();return U};var I=()=>{let{enableRenderingLog:U}=x();return U};var l=()=>{let{onLinkLost:U}=x();return U},c=()=>{let{onLinkRestored:U}=x();return U};var UT=(U)=>{let T=document.cookie?document.cookie.split(";"):[];for(let z of T){let J=z.indexOf("=");if((J===-1?z:z.slice(0,J)).trim()===U){let $=J===-1?"":z.slice(J+1).trim();try{return decodeURIComponent($)}catch{return $}}}return null},TT={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,T){return(U==="local"?window.localStorage:window.sessionStorage).getItem(T)},readCookie:UT,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let T=document.getElementsByName(U);if(!T.length)return null;let z=T[0];if(z instanceof HTMLInputElement){if(z.type==="file"&&z.files)return Array.from(z.files);return[z.value]}if(z instanceof HTMLTextAreaElement)return[z.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},jU=TT;var zT={};function N(){return zT}var IU=new Map;var OU=(U)=>{return IU.has(U)?IU.get(U):null};var MU,$T={isClient(){return!0},readSid(){return MU},setSid(U){MU=U},readWebStorage(U,T){let z=N(),J=U==="local"?z.storage:z.sessionStorage;return J?J.getItem(T):null},async readWebStorageAsync(U,T){let z=N(),J=U==="local"?z.asyncStorage:z.asyncSessionStorage;if(J)return J.getItem(T);let H=U==="local"?z.storage:z.sessionStorage;return H?H.getItem(T):null},readCookie(U){let T=N();return T.getCookie?T.getCookie(U):null},readUrlParams(U){let T=N();return T.getRouteParams?T.getRouteParams(U):[]},readDomInput(U){let T=N();return T.getInput?T.getInput(U):OU(U)},submitGlobalForm(){N().submitForm?.()}},LU=$T;var JT=typeof navigator<"u"&&navigator.product==="ReactNative",HT=JT?LU:jU,o=HT;var ZT=Y("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function AU(){ZT.resolve?.()}function O(U,T){if(T==="up")return{state:"up",signal:U==="down"?"restored":null};return{state:"down",signal:U==="up"?"lost":null}}var VT=({children:U})=>{let T=D.useContext(S),z=p(),J=g(z,"socketIO"),H=l(),$=c(),Z=D.useRef(H);Z.current=H;let G=D.useRef($);G.current=$;let V=D.useRef("initial"),q=(K)=>{if(o.isClient())o.setSid(K.sid),AU(),console.log(`SocketIO initialized: ${o.readSid()}`)};return D.useEffect(()=>{if(!T||!J)return;let K=()=>{let{state:_,signal:F}=O(V.current,"up");if(V.current=_,F==="restored")G.current?.("socketio");console.log("SocketIO connected")},W=(_)=>{if(console.log(`SocketIO disconnected: ${_}`),T.connect(),_==="io client disconnect")return;let{state:F,signal:X}=O(V.current,"down");if(V.current=F,X==="lost")Z.current?.("socketio",_)};return T.on("pieinit",q),T.on("connect",K),T.on("disconnect",W),T.connect(),()=>{T.off("pieinit",q),T.off("connect",K),T.off("disconnect",W),T.disconnect()}},[T,J]),U},PU=VT;var B=require("react");var YT=({children:U})=>{let T=B.useContext(k),z=p(),J=g(z,"centrifuge"),H=l(),$=c(),Z=B.useRef(H);Z.current=H;let G=B.useRef($);G.current=$;let V=B.useRef("initial");return B.useEffect(()=>{if(!T||!J)return;let q=(_)=>{let{state:F,signal:X}=O(V.current,"down");if(V.current=F,X==="lost")Z.current?.("centrifuge",_)},K=()=>{let{state:_,signal:F}=O(V.current,"up");if(V.current=_,F==="restored")G.current?.("centrifuge");console.log("Centrifuge connected")},W=(_)=>{console.log("Centrifuge disconnected:",_),q(_)};return T.on("connecting",q),T.on("connected",K),T.on("disconnected",W),T.connect(),()=>{T.off("connecting",q),T.off("connected",K),T.off("disconnected",W),T.disconnect()}},[T,J]),U},RU=YT;var yU=require("react");var s=require("react/jsx-runtime"),GT=Y("@swarm.ing/pieui:context:fallback",()=>yU.createContext(s.jsx(s.Fragment,{}))),M=GT;var wU=require("react");var QT=Y("@swarm.ing/pieui:context:lazyError",()=>wU.createContext(void 0)),L=QT;var _T=Y("@swarm.ing/pieui:component-registry",()=>new Map);var a=(U)=>{return _T.get(U)};var b=require("react");var r=require("react"),xU=require("react/jsx-runtime"),FT=2,KT=400;class A extends r.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<FT){let T=KT*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((z)=>({failed:!1,attempt:z.attempt+1}))},T)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return xU.jsx(r.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var n=require("react/jsx-runtime");function XT({uiConfig:U,setUiAjaxConfiguration:T}){let z=b.useContext(M),J=b.useContext(L),H=I();if(H)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!T);let $=a(U.card);if(!$?.component){if(H)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return z}if(H)console.log("[UI] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata});let Z=$.component,G=n.jsx(Z,{data:U.data,content:U.content,setUiAjaxConfiguration:T});if($.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",$.name);return n.jsx(A,{name:$.name,fallback:$.fallback?n.jsx($.fallback,{}):z,onError:J,children:G})}if(H)console.log("[UI] Rendering component directly:",$.name);return G}var TU=b.memo(XT);var pU=require("axios-date-transformer");var C=require("react"),E=()=>{let[U,T]=C.useState(null);return C.useEffect(()=>{if(typeof window>"u")return;let z=window.WebApp;if(!z)return;z.ready(),T(z)},[]),U},bU=()=>{let U=E();return[U?.initDataUnsafe,U?.initData]},CU=(U)=>{let T=E();return C.useEffect(()=>{if(!T||!U)return;return T.BackButton.onClick(U),T.BackButton.show(),()=>{T.BackButton.offClick(U),T.BackButton.hide()}},[T,U]),T?.BackButton??null},mU=()=>{return E()?.HapticFeedback??null};var fU=require("react");var qT=Y("@swarm.ing/pieui:context:navigate",()=>fU.createContext(void 0)),SU=qT;var zU=require("react");var kU=require("react");var DT=Y("@swarm.ing/pieui:context:uiRenderer",()=>kU.createContext(null)),vU=DT;var m=require("react/jsx-runtime");function hU({uiConfig:U,setUiAjaxConfiguration:T}){let z=zU.useContext(M),J=zU.useContext(L),H=I();if(H)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!T);let $=a(U.card);if(!$?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return z}if(H)console.log("[UILoading] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata,hasFallback:!!$.fallback});if($.fallback){if(H)console.log("[UILoading] Rendering fallback for:",$.name);let V=$.fallback;return m.jsx(V,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",$.name);let Z=$.component,G=m.jsx(vU.Provider,{value:hU,children:m.jsx(Z,{data:U.data,content:U.content,setUiAjaxConfiguration:T})});if($.isLazy)return m.jsx(A,{name:$.name,fallback:z,onError:J,children:G});return G}var dU=hU;var uU=require("react/jsx-runtime");function gU(U,T,z){if(!T)return z;let J=U.replace(/^\//,""),H=T[J];if(!H)return z;return uU.jsx(dU,{uiConfig:H})}var Q=require("react/jsx-runtime"),BT=({location:U,fallback:T,piecache:z,onError:J,queryOptions:H,disableGlobalForm:$})=>{let Z=UU(),G=EU(),V=I(),q=P.useMemo(()=>pU.createAxiosDateTransformer({baseURL:Z}),[Z]),K=P.useMemo(()=>_U(),[]),W=P.useMemo(()=>Z?DU(Z):null,[Z]),_=P.useMemo(()=>Z?NU(Z,G):null,[Z,G]),F=E(),{data:X,isLoading:$U,error:j}=R.useQuery({queryKey:["uiConfig",U.pathname+U.search,F?.initData],queryFn:async()=>{let y=new URLSearchParams(U.search);if(y.set("__pieroot","max"),F?.initData)y.set("initData",F.initData);let HU="/api/content"+U.pathname+"?"+y.toString();if(V)console.log("[PieRoot] Fetching UI configuration from:",HU);let ZU=await q.get(HU,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(V)console.log("[PieRoot] Received UI configuration:",ZU.data);return ZU.data},enabled:!!F?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(y)=>Math.min(1000*2**y,30000),...H}),JU=gU(U.pathname,z,T);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(j&&V)return console.error("[PieRoot] Error fetching UI configuration:",j),console.error("[PieRoot] Error details:",{message:j.message,status:j.response?.status,data:j.response?.data}),J?.(j),JU;if($U||!X){if(V)console.log("[PieRoot] Loading state:",{isLoading:$U,hasUiConfiguration:!!X});return JU}if(V)console.log("[PieRoot] UI configuration loaded successfully:",X),console.log("[PieRoot] Rendering UI with configuration");return Q.jsx(FU.Provider,{value:K,children:Q.jsx(S.Provider,{value:W,children:Q.jsx(k.Provider,{value:_,children:Q.jsx(M.Provider,{value:T??Q.jsx(Q.Fragment,{}),children:Q.jsx(PU,{children:Q.jsx(RU,{children:$?Q.jsx(TU,{uiConfig:X}):Q.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:Q.jsx(TU,{uiConfig:X})})})})})})})})},WT=(U)=>{let T=P.useMemo(()=>new R.QueryClient,[]),z=U.queryClient??T;return Q.jsx(SU.Provider,{value:U.onNavigate,children:Q.jsx(e.Provider,{value:U.config,children:Q.jsx(L.Provider,{value:U.onError,children:Q.jsx(R.QueryClientProvider,{client:z,children:Q.jsx(BT,{...U})})})})})},lU=WT;
|
|
2
|
+
var aU=Object.create;var{getPrototypeOf:rU,defineProperty:x,getOwnPropertyNames:GU,getOwnPropertyDescriptor:nU}=Object,QU=Object.prototype.hasOwnProperty;var iU=(U,T,z)=>{z=U!=null?aU(rU(U)):{};let J=T||!U||!U.__esModule?x(z,"default",{value:U,enumerable:!0}):z;for(let H of GU(U))if(!QU.call(J,H))x(J,H,{get:()=>U[H],enumerable:!0});return J},YU=new WeakMap,tU=(U)=>{var T=YU.get(U),z;if(T)return T;if(T=x({},"__esModule",{value:!0}),U&&typeof U==="object"||typeof U==="function")GU(U).map((J)=>!QU.call(T,J)&&x(T,J,{get:()=>U[J],enumerable:!(z=nU(U,J))||z.enumerable}));return YU.set(U,T),T};var eU=(U,T)=>{for(var z in T)x(U,z,{get:T[z],enumerable:!0,configurable:!0,set:(J)=>T[z]=()=>J})};var IT={};eU(IT,{useMaxWebApp:()=>E,useMaxInitData:()=>CU,useMaxHapticFeedback:()=>SU,useMaxBackButton:()=>mU,PieMaxRoot:()=>sU});module.exports=tU(IT);var P=require("react"),R=require("@tanstack/react-query");var _U=iU(require("mitt")),k=require("react");var t=globalThis,G=(U,T)=>{let z=Symbol.for(U);if(!(z in t))t[z]=T();return t[z]};function FU(){return G("@swarm.ing/pieui:mitt-emitter",()=>_U.default())}var UT=G("@swarm.ing/pieui:context:mitt",()=>k.createContext(null));var KU=UT;var qU=require("socket.io-client"),BU=require("react");var XU=G("@swarm.ing/pieui:socket-cache",()=>new Map),WU=(U)=>{let T=XU.get(U);if(T)return T;let z=qU.io(U,{autoConnect:!1,transports:["websocket"]});return XU.set(U,z),z},TT=G("@swarm.ing/pieui:context:socket",()=>BU.createContext(null)),v=TT;var NU=require("react"),e=require("centrifuge");var DU=G("@swarm.ing/pieui:centrifuge-cache",()=>new Map),EU=(U,T)=>{if(!T)return null;let z=`${U}::${T}`,J=DU.get(z);if(J)return J;async function H(){let V=await fetch(U+"api/centrifuge/gen_token",{credentials:"include"});if(!V.ok){if(V.status===401||V.status===403)throw new e.Centrifuge.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${V.status}`)}return(await V.json()).token}let $=new e.Centrifuge(T,{getToken:H});return DU.set(z,$),$},zT=G("@swarm.ing/pieui:context:centrifuge",()=>NU.createContext(null)),f=zT;var q=require("react");var g=require("react"),d=new Map,h=new Map;function u(U,T){let z=`${U}::${T}`,J=U?d.get(z):void 0,[H,$]=g.useState(J??null);return g.useEffect(()=>{if(!U)return;if(d.has(z)){$(d.get(z));return}let V=h.get(z);if(!V)V=fetch(U+`api/support/${T}`,{method:"GET"}).then((Y)=>Y.json()).then((Y)=>{return d.set(z,Y),h.delete(z),Y}).catch((Y)=>{throw h.delete(z),Y}),h.set(z,V);let Z=!1;return V.then((Y)=>{if(!Z)$(Y)}).catch(()=>{}),()=>{Z=!0}},[U,T,z]),H}var p=require("react");var UU=G("@swarm.ing/pieui:context:pieConfig",()=>p.createContext(null)),b=()=>{let U=p.useContext(UU);if(!U)throw Error("usePieConfig must be used within PieConfigProvider");return U},TU=()=>{let{apiServer:U}=b();return U},l=TU,jU=()=>{let{centrifugeServer:U}=b();return U};var I=()=>{let{enableRenderingLog:U}=b();return U};var c=()=>{let{onLinkLost:U}=b();return U},o=()=>{let{onLinkRestored:U}=b();return U};var $T=(U)=>{let T=document.cookie?document.cookie.split(";"):[];for(let z of T){let J=z.indexOf("=");if((J===-1?z:z.slice(0,J)).trim()===U){let $=J===-1?"":z.slice(J+1).trim();try{return decodeURIComponent($)}catch{return $}}}return null},JT={isClient(){return typeof window<"u"&&typeof document<"u"},readSid(){return typeof window>"u"?void 0:window.sid},setSid(U){if(typeof window<"u")window.sid=U},readWebStorage(U,T){return(U==="local"?window.localStorage:window.sessionStorage).getItem(T)},readCookie:$T,readUrlParams(U){return new URLSearchParams(window.location.search).getAll(U)},readDomInput(U){let T=document.getElementsByName(U);if(!T.length)return null;let z=T[0];if(z instanceof HTMLInputElement){if(z.type==="file"&&z.files)return Array.from(z.files);return[z.value]}if(z instanceof HTMLTextAreaElement)return[z.value];return[]},submitGlobalForm(){if(typeof document>"u")return;let U=document.getElementById("piedata_global_form");U&&U.submit()}},IU=JT;var HT={};function N(){return HT}var OU=new Map;var MU=(U)=>{return OU.has(U)?OU.get(U):null};var LU,ZT={isClient(){return!0},readSid(){return LU},setSid(U){LU=U},readWebStorage(U,T){let z=N(),J=U==="local"?z.storage:z.sessionStorage;return J?J.getItem(T):null},async readWebStorageAsync(U,T){let z=N(),J=U==="local"?z.asyncStorage:z.asyncSessionStorage;if(J)return J.getItem(T);let H=U==="local"?z.storage:z.sessionStorage;return H?H.getItem(T):null},readCookie(U){let T=N();return T.getCookie?T.getCookie(U):null},readUrlParams(U){let T=N();return T.getRouteParams?T.getRouteParams(U):[]},readDomInput(U){let T=N();return T.getInput?T.getInput(U):MU(U)},submitGlobalForm(){N().submitForm?.()}},AU=ZT;var VT=typeof navigator<"u"&&navigator.product==="ReactNative",YT=VT?AU:IU,s=YT;var GT=G("@swarm.ing/pieui:sid-state",()=>({promise:null,resolve:null}));function PU(){GT.resolve?.()}function O(U,T){if(T==="up")return{state:"up",signal:U==="down"?"restored":null};return{state:"down",signal:U==="up"?"lost":null}}var QT=({children:U})=>{let T=q.useContext(v),z=l(),J=u(z,"socketIO"),H=c(),$=o(),V=q.useRef(H);V.current=H;let Z=q.useRef($);Z.current=$;let Y=q.useRef("initial"),F=(K)=>{if(s.isClient())s.setSid(K.sid),PU(),console.log(`SocketIO initialized: ${s.readSid()}`)};return q.useEffect(()=>{if(!T||!J)return;let K=()=>{let{state:_,signal:X}=O(Y.current,"up");if(Y.current=_,X==="restored")Z.current?.("socketio");console.log("SocketIO connected")},W=(_)=>{if(console.log(`SocketIO disconnected: ${_}`),T.connect(),_==="io client disconnect")return;let{state:X,signal:D}=O(Y.current,"down");if(Y.current=X,D==="lost")V.current?.("socketio",_)};return T.on("pieinit",F),T.on("connect",K),T.on("disconnect",W),T.connect(),()=>{T.off("pieinit",F),T.off("connect",K),T.off("disconnect",W),T.disconnect()}},[T,J]),U},RU=QT;var B=require("react");var _T=({children:U})=>{let T=B.useContext(f),z=l(),J=u(z,"centrifuge"),H=c(),$=o(),V=B.useRef(H);V.current=H;let Z=B.useRef($);Z.current=$;let Y=B.useRef("initial");return B.useEffect(()=>{if(!T||!J)return;let F=(_)=>{let{state:X,signal:D}=O(Y.current,"down");if(Y.current=X,D==="lost")V.current?.("centrifuge",_)},K=()=>{let{state:_,signal:X}=O(Y.current,"up");if(Y.current=_,X==="restored")Z.current?.("centrifuge");console.log("Centrifuge connected")},W=(_)=>{console.log("Centrifuge disconnected:",_),F(_)};return T.on("connecting",F),T.on("connected",K),T.on("disconnected",W),T.connect(),()=>{T.off("connecting",F),T.off("connected",K),T.off("disconnected",W),T.disconnect()}},[T,J]),U},yU=_T;var wU=require("react");var a=require("react/jsx-runtime"),FT=G("@swarm.ing/pieui:context:fallback",()=>wU.createContext(a.jsx(a.Fragment,{}))),M=FT;var xU=require("react");var KT=G("@swarm.ing/pieui:context:lazyError",()=>xU.createContext(void 0)),L=KT;var XT=G("@swarm.ing/pieui:component-registry",()=>new Map);var r=(U)=>{return XT.get(U)};var C=require("react");var n=require("react"),bU=require("react/jsx-runtime"),qT=2,BT=400;class A extends n.Component{state={failed:!1,attempt:0};timer;static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(U){if(this.props.onError?.(U),this.state.attempt<qT){let T=BT*(this.state.attempt+1);this.timer=setTimeout(()=>{this.setState((z)=>({failed:!1,attempt:z.attempt+1}))},T)}}componentDidUpdate(U){if(U.name!==this.props.name&&this.state.attempt!==0)this.setState({failed:!1,attempt:0})}componentWillUnmount(){if(this.timer)clearTimeout(this.timer)}render(){if(this.state.failed)return this.props.fallback;return bU.jsx(n.Suspense,{fallback:this.props.fallback,children:this.props.children},`${this.props.name}:${this.state.attempt}`)}}var i=require("react/jsx-runtime");function WT({uiConfig:U,setUiAjaxConfiguration:T}){let z=C.useContext(M),J=C.useContext(L),H=I();if(H)console.log("[UI] Rendering component:",U.card),console.log("[UI] Component data:",U.data),console.log("[UI] Component content:",U.content),console.log("[UI] Has setUiAjaxConfiguration:",!!T);let $=r(U.card);if(!$?.component){if(H)console.warn(`[UI] Component not found in registry: ${U.card}`),console.log("[UI] Returning fallback component");return z}if(H)console.log("[UI] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata});let V=$.component,Z=i.jsx(V,{data:U.data,content:U.content,setUiAjaxConfiguration:T});if($.isLazy){if(H)console.log("[UI] Rendering lazy component with Suspense:",$.name);return i.jsx(A,{name:$.name,fallback:$.fallback?i.jsx($.fallback,{}):z,onError:J,children:Z})}if(H)console.log("[UI] Rendering component directly:",$.name);return Z}var zU=C.memo(WT);var oU=require("axios-date-transformer");var m=require("react"),E=()=>{let[U,T]=m.useState(null);return m.useEffect(()=>{if(typeof window>"u")return;let z=window.WebApp;if(!z)return;z.ready(),T(z)},[]),U},CU=()=>{let U=E();return[U?.initDataUnsafe,U?.initData]},mU=(U)=>{let T=E();return m.useEffect(()=>{if(!T||!U)return;return T.BackButton.onClick(U),T.BackButton.show(),()=>{T.BackButton.offClick(U),T.BackButton.hide()}},[T,U]),T?.BackButton??null},SU=()=>{return E()?.HapticFeedback??null};var kU=require("react");var DT=G("@swarm.ing/pieui:context:navigate",()=>kU.createContext(void 0)),vU=DT;var $U=require("react");var fU=require("react");var NT=G("@swarm.ing/pieui:context:uiRenderer",()=>fU.createContext(null)),dU=NT;var S=require("react/jsx-runtime");function hU({uiConfig:U,setUiAjaxConfiguration:T}){let z=$U.useContext(M),J=$U.useContext(L),H=I();if(H)console.log("[UILoading] Rendering fallback for:",U.card),console.log("[UILoading] Component data:",U.data),console.log("[UILoading] Component content:",U.content),console.log("[UILoading] Has setUiAjaxConfiguration:",!!T);let $=r(U.card);if(!$?.component){if(H)console.warn(`[UILoading] Component not found in registry: ${U.card}`),console.log("[UILoading] Returning fallback component");return z}if(H)console.log("[UILoading] Found component in registry:",{name:$.name,isLazy:$.isLazy,hasMetadata:!!$.metadata,hasFallback:!!$.fallback});if($.fallback){if(H)console.log("[UILoading] Rendering fallback for:",$.name);let Y=$.fallback;return S.jsx(Y,{})}if(H)console.log("[UILoading] No fallback, rendering full component:",$.name);let V=$.component,Z=S.jsx(dU.Provider,{value:hU,children:S.jsx(V,{data:U.data,content:U.content,setUiAjaxConfiguration:T})});if($.isLazy)return S.jsx(A,{name:$.name,fallback:z,onError:J,children:Z});return Z}var gU=hU;var pU=require("react/jsx-runtime");function uU(U,T,z){if(!T)return z;let J=U.replace(/^\//,""),H=T[J];if(!H)return z;return pU.jsx(gU,{uiConfig:H})}function lU({apiServer:U,pathname:T,search:z,root:J,initData:H}){let $=new URLSearchParams(z);if($.set("__pieroot",J),H)$.set("initData",H);return`${U.replace(/\/$/,"")}/api/content${T}?${$.toString()}`}async function cU(U,T){if(!U||U.used||U.url!==T)return null;U.used=!0;try{return await U.promise}catch{return null}}var Q=require("react/jsx-runtime"),ET=({location:U,fallback:T,piecache:z,onError:J,queryOptions:H,configPrefetch:$,disableGlobalForm:V})=>{let Z=TU(),Y=jU(),F=I(),K=P.useMemo(()=>oU.createAxiosDateTransformer({baseURL:Z}),[Z]),W=P.useMemo(()=>FU(),[]),_=P.useMemo(()=>Z?WU(Z):null,[Z]),X=P.useMemo(()=>Z?EU(Z,Y):null,[Z,Y]),D=E(),{data:y,isLoading:JU,error:j}=R.useQuery({queryKey:["uiConfig",U.pathname+U.search,D?.initData],queryFn:async()=>{let w=lU({apiServer:Z,pathname:U.pathname,search:U.search,root:"max",initData:D?.initData}),ZU=await cU($,w);if(ZU){if(F)console.log("[PieRoot] Using prefetched UI configuration");return ZU}if(F)console.log("[PieRoot] Fetching UI configuration from:",w);let VU=await K.get(w,{withCredentials:!0});if(F)console.log("[PieRoot] Received UI configuration:",VU.data);return VU.data},enabled:!!D?.initData,staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(w)=>Math.min(1000*2**w,30000),...H}),HU=uU(U.pathname,z,T);if(!Z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");if(j&&F)return console.error("[PieRoot] Error fetching UI configuration:",j),console.error("[PieRoot] Error details:",{message:j.message,status:j.response?.status,data:j.response?.data}),J?.(j),HU;if(JU||!y){if(F)console.log("[PieRoot] Loading state:",{isLoading:JU,hasUiConfiguration:!!y});return HU}if(F)console.log("[PieRoot] UI configuration loaded successfully:",y),console.log("[PieRoot] Rendering UI with configuration");return Q.jsx(KU.Provider,{value:W,children:Q.jsx(v.Provider,{value:_,children:Q.jsx(f.Provider,{value:X,children:Q.jsx(M.Provider,{value:T??Q.jsx(Q.Fragment,{}),children:Q.jsx(RU,{children:Q.jsx(yU,{children:V?Q.jsx(zU,{uiConfig:y}):Q.jsx("form",{id:"piedata_global_form",action:Z+"api/process"+U.pathname,method:"post",encType:"multipart/form-data",children:Q.jsx(zU,{uiConfig:y})})})})})})})})},jT=(U)=>{let T=P.useMemo(()=>new R.QueryClient,[]),z=U.queryClient??T;return Q.jsx(vU.Provider,{value:U.onNavigate,children:Q.jsx(UU.Provider,{value:U.config,children:Q.jsx(L.Provider,{value:U.onError,children:Q.jsx(R.QueryClientProvider,{client:z,children:Q.jsx(ET,{...U})})})})})},sU=jT;
|