@piedata/pieui 1.1.3 → 1.1.4

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 CHANGED
@@ -361308,19 +361308,15 @@ var initCommand = () => {
361308
361308
  console.log("[pieui] piecomponents directory already exists");
361309
361309
  }
361310
361310
  const registryPath = import_path.default.join(pieComponentsDir, "registry.ts");
361311
- const registryContent = `
361312
- "use client"
361313
- import { registerPieComponent, initializePieComponents, isPieComponentsInitialized } from "pieui";
361311
+ const registryContent = `"use client"
361312
+
361313
+ import { registerPieComponent } from "@piedata/pieui";
361314
361314
 
361315
361315
  // Import your custom components here
361316
361316
  // Example:
361317
361317
  // import MyCustomCard from "./MyCustomCard/ui/MyCustomCard";
361318
361318
 
361319
- // Initialize and register components
361320
- if (!isPieComponentsInitialized()) {
361321
- // Initialize PieUI built-in components
361322
- initializePieComponents();
361323
-
361319
+ export const initializePieUI = () => {
361324
361320
  // Register your custom components here
361325
361321
  // Example:
361326
361322
  // registerPieComponent({
@@ -361335,10 +361331,51 @@ if (!isPieComponentsInitialized()) {
361335
361331
  } else {
361336
361332
  console.log("[pieui] registry.ts already exists");
361337
361333
  }
361334
+ const tailwindConfigPath = import_path.default.join(process.cwd(), "tailwind.config.js");
361335
+ const tailwindConfigTsPath = import_path.default.join(process.cwd(), "tailwind.config.ts");
361336
+ const pieuiContentPath = "./node_modules/@piedata/pieui/dist/**/*.{js,mjs,ts,jsx,tsx}";
361337
+ let configPath = null;
361338
+ if (import_fs2.default.existsSync(tailwindConfigPath)) {
361339
+ configPath = tailwindConfigPath;
361340
+ } else if (import_fs2.default.existsSync(tailwindConfigTsPath)) {
361341
+ configPath = tailwindConfigTsPath;
361342
+ }
361343
+ if (configPath) {
361344
+ console.log("[pieui] Updating Tailwind config...");
361345
+ try {
361346
+ let configContent = import_fs2.default.readFileSync(configPath, "utf8");
361347
+ if (!configContent.includes(pieuiContentPath)) {
361348
+ const contentMatch = configContent.match(/content\s*:\s*\[([^\]]*)\]/s);
361349
+ if (contentMatch) {
361350
+ const contentArray = contentMatch[1];
361351
+ const newContentArray = contentArray.trim() ? `${contentArray.trim()},
361352
+ "${pieuiContentPath}"` : `
361353
+ "${pieuiContentPath}"
361354
+ `;
361355
+ configContent = configContent.replace(contentMatch[0], `content: [${newContentArray}]`);
361356
+ import_fs2.default.writeFileSync(configPath, configContent, "utf8");
361357
+ console.log("[pieui] Added PieUI path to Tailwind content configuration");
361358
+ } else {
361359
+ console.log("[pieui] Warning: Could not find content array in Tailwind config");
361360
+ console.log("[pieui] Please manually add the following to your Tailwind content array:");
361361
+ console.log(`[pieui] "${pieuiContentPath}"`);
361362
+ }
361363
+ } else {
361364
+ console.log("[pieui] PieUI path already exists in Tailwind config");
361365
+ }
361366
+ } catch (error) {
361367
+ console.error("[pieui] Error updating Tailwind config:", error);
361368
+ console.log("[pieui] Please manually add the following to your Tailwind content array:");
361369
+ console.log(`[pieui] "${pieuiContentPath}"`);
361370
+ }
361371
+ } else {
361372
+ console.log("[pieui] No Tailwind config found. If you use Tailwind CSS, add this to your content array:");
361373
+ console.log(`[pieui] "${pieuiContentPath}"`);
361374
+ }
361338
361375
  console.log("[pieui] Initialization complete!");
361339
361376
  console.log("[pieui] Next steps:");
361340
- console.log(' 1. Import { registerCustomComponents } from "./piecomponents/registry" in your app');
361341
- console.log(" 2. Call registerCustomComponents() before using PieRoot");
361377
+ console.log(' 1. Import { initializePieUI } from "./piecomponents/registry" in your app');
361378
+ console.log(" 2. Call initializePieUI() before using PieRoot");
361342
361379
  console.log(' 3. Use "pieui add <ComponentName>" to create new components');
361343
361380
  };
361344
361381
  var addCommand = (componentName, componentType = "complex-container") => {
@@ -361523,26 +361560,54 @@ export default ${componentName}
361523
361560
  registryContent = registryContent.slice(0, insertPos) + `
361524
361561
  ` + importLine + registryContent.slice(insertPos);
361525
361562
  } else {
361526
- const pieuiImportEnd = registryContent.indexOf('";') + 2;
361527
- registryContent = registryContent.slice(0, pieuiImportEnd) + `
361563
+ const pieuiImportMatch = registryContent.match(/import .* from ["']@piedata\/pieui["'];/);
361564
+ if (pieuiImportMatch) {
361565
+ const pieuiImportEnd = registryContent.indexOf(pieuiImportMatch[0]) + pieuiImportMatch[0].length;
361566
+ registryContent = registryContent.slice(0, pieuiImportEnd) + `
361528
361567
 
361568
+ // Import your custom components here
361569
+ // Example:
361570
+ // import MyCustomCard from "./MyCustomCard/ui/MyCustomCard";
361529
361571
  ` + importLine + registryContent.slice(pieuiImportEnd);
361572
+ }
361530
361573
  }
361531
361574
  const registerLine = ` registerPieComponent({
361532
361575
  name: '${componentName}',
361533
361576
  component: ${componentName},
361534
361577
  });`;
361535
- const ifBlockEnd = registryContent.lastIndexOf(`
361536
- }`);
361537
- if (ifBlockEnd !== -1) {
361538
- registryContent = registryContent.slice(0, ifBlockEnd) + `
361539
-
361540
- ` + registerLine + registryContent.slice(ifBlockEnd);
361541
- } else {
361542
- registryContent = registryContent.trimEnd() + `
361578
+ const functionMatch = registryContent.match(/export const initializePieUI = \(\) => \{([\s\S]*?)\n\}/m);
361579
+ if (functionMatch) {
361580
+ const functionContent = functionMatch[1];
361581
+ if (functionContent.includes("registerPieComponent({")) {
361582
+ const lastRegisterMatch = functionContent.match(/registerPieComponent\([^)]+\);/g);
361583
+ if (lastRegisterMatch) {
361584
+ const lastRegister = lastRegisterMatch[lastRegisterMatch.length - 1];
361585
+ const lastRegisterPos = registryContent.lastIndexOf(lastRegister) + lastRegister.length;
361586
+ registryContent = registryContent.slice(0, lastRegisterPos) + `
361543
361587
 
361544
- ` + registerLine + `
361545
- }`;
361588
+ ` + registerLine + registryContent.slice(lastRegisterPos);
361589
+ }
361590
+ } else {
361591
+ const functionStart = registryContent.indexOf("export const initializePieUI = () => {");
361592
+ const openBracePos = registryContent.indexOf("{", functionStart) + 1;
361593
+ const commentStart = registryContent.indexOf("// Register your custom components here", openBracePos);
361594
+ if (commentStart !== -1 && commentStart < registryContent.indexOf("}", openBracePos)) {
361595
+ const lines = registryContent.substring(commentStart).split(`
361596
+ `);
361597
+ let commentEnd = commentStart;
361598
+ for (const line of lines) {
361599
+ if (line.trim() && !line.trim().startsWith("//")) {
361600
+ break;
361601
+ }
361602
+ commentEnd += line.length + 1;
361603
+ }
361604
+ registryContent = registryContent.slice(0, commentStart) + registerLine + `
361605
+ ` + registryContent.slice(commentEnd);
361606
+ } else {
361607
+ registryContent = registryContent.slice(0, openBracePos) + `
361608
+ ` + registerLine + registryContent.slice(openBracePos);
361609
+ }
361610
+ }
361546
361611
  }
361547
361612
  import_fs2.default.writeFileSync(registryPath, registryContent, "utf8");
361548
361613
  console.log(`[pieui] Component ${componentName} (${componentType}) created successfully!`);
package/dist/index.esm.js CHANGED
@@ -25,4 +25,4 @@ var EX=Object.create;var{getPrototypeOf:SX,defineProperty:R0,getOwnPropertyNames
25
25
  `)throw Error("size integer not terminated by '\\n'");let H=new VY;while(Q.haveBytes()){let z=Q.getInt(),U;switch(Q.getChar()){case"@":if(U=Q.getInt(),Q.haveBytes()&&Q.getChar()!==",")throw Error("copy command not terminated by ','");if(Y+=z,Y>W)throw Error("copy exceeds output file size");if(U+z>X)throw Error("copy extends past end of input");H.putArray(Z,U,U+z);break;case":":if(Y+=z,Y>W)throw Error("insert command gives an output larger than predicted");if(z>G)throw Error("insert count exceeds size of delta");H.putArray(Q.a,Q.pos,Q.pos+z),Q.pos+=z;break;case";":{let B=H.toByteArray(Z);if(z!==oB(B))throw Error("bad checksum");if(Y!==W)throw Error("generated size does not match predicted size");return B}default:throw Error("unknown delta operator")}}throw Error("unterminated delta")}class X9{name(){return"json"}encodeCommands(Z){return Z.map((J)=>JSON.stringify(J)).join(`
26
26
  `)}decodeReplies(Z){return Z.trim().split(`
27
27
  `).map((J)=>JSON.parse(J))}applyDeltaIfNeeded(Z,J){let Y,Q;if(Z.delta){let X=aB(J,new TextEncoder().encode(Z.data));Y=JSON.parse(new TextDecoder().decode(X)),Q=X}else Y=JSON.parse(Z.data),Q=new TextEncoder().encode(Z.data);return{newData:Y,newPrevValue:Q}}}var sB={headers:{},token:"",getToken:null,data:null,getData:null,debug:!1,name:"js",version:"",fetch:null,readableStream:null,websocket:null,eventsource:null,sockjs:null,sockjsOptions:{},emulationEndpoint:"/emulation",minReconnectDelay:500,maxReconnectDelay:20000,timeout:5000,maxServerPingDelay:1e4,networkEventTarget:null};class V1 extends Error{constructor(Z){super(Z);this.name=this.constructor.name}}class J0 extends UY{constructor(Z,J){super();if(this._reconnectTimeout=null,this._refreshTimeout=null,this._serverPingTimeout=null,this.state=h.Disconnected,this._transportIsOpen=!1,this._endpoint=Z,this._emulation=!1,this._transports=[],this._currentTransportIndex=0,this._triedAllTransports=!1,this._transportWasOpen=!1,this._transport=null,this._transportId=0,this._deviceWentOffline=!1,this._transportClosed=!0,this._codec=new X9,this._reconnecting=!1,this._reconnectTimeout=null,this._reconnectAttempts=0,this._client=null,this._session="",this._node="",this._subs={},this._serverSubs={},this._commandId=0,this._commands=[],this._batching=!1,this._refreshRequired=!1,this._refreshTimeout=null,this._callbacks={},this._token="",this._data=null,this._dispatchPromise=Promise.resolve(),this._serverPing=0,this._serverPingTimeout=null,this._sendPong=!1,this._promises={},this._promiseId=0,this._debugEnabled=!1,this._networkEventsSet=!1,this._config=Object.assign(Object.assign({},sB),J),this._configure(),this._debugEnabled)this.on("state",(Y)=>{this._debug("client state",Y.oldState,"->",Y.newState)}),this.on("error",(Y)=>{this._debug("client error",Y)});else this.on("error",function(){Function.prototype()})}newSubscription(Z,J){if(this.getSubscription(Z)!==null)throw Error("Subscription to the channel "+Z+" already exists");let Y=new KY(this,Z,J);return this._subs[Z]=Y,Y}getSubscription(Z){return this._getSub(Z)}removeSubscription(Z){if(!Z)return;if(Z.state!==o.Unsubscribed)Z.unsubscribe();this._removeSubscription(Z)}subscriptions(){return this._subs}ready(Z){return l(this,void 0,void 0,function*(){switch(this.state){case h.Disconnected:throw{code:_.clientDisconnected,message:"client disconnected"};case h.Connected:return;default:return new Promise((J,Y)=>{let Q={resolve:J,reject:Y};if(Z)Q.timeout=setTimeout(()=>{Y({code:_.timeout,message:"timeout"})},Z);this._promises[this._nextPromiseId()]=Q})}})}connect(){if(this._isConnected()){this._debug("connect called when already connected");return}if(this._isConnecting()){this._debug("connect called when already connecting");return}this._debug("connect called"),this._reconnectAttempts=0,this._startConnecting()}disconnect(){this._disconnect(l0.disconnectCalled,"disconnect called",!1)}setToken(Z){this._token=Z}setData(Z){this._data=Z}setHeaders(Z){this._config.headers=Z}send(Z){return l(this,void 0,void 0,function*(){let J={send:{data:Z}};if(yield this._methodCall(),!this._transportSendCommands([J]))throw this._createErrorObject(_.transportWriteError,"transport write error")})}rpc(Z,J){return l(this,void 0,void 0,function*(){let Y={rpc:{method:Z,data:J}};return yield this._methodCall(),{data:(yield this._callPromise(Y,(X)=>X.rpc)).data}})}publish(Z,J){return l(this,void 0,void 0,function*(){let Y={publish:{channel:Z,data:J}};return yield this._methodCall(),yield this._callPromise(Y,()=>({})),{}})}history(Z,J){return l(this,void 0,void 0,function*(){let Y={history:this._getHistoryRequest(Z,J)};yield this._methodCall();let Q=yield this._callPromise(Y,(G)=>G.history),X=[];if(Q.publications)for(let G=0;G<Q.publications.length;G++)X.push(this._getPublicationContext(Z,Q.publications[G]));return{publications:X,epoch:Q.epoch||"",offset:Q.offset||0}})}presence(Z){return l(this,void 0,void 0,function*(){let J={presence:{channel:Z}};yield this._methodCall();let Q=(yield this._callPromise(J,(X)=>X.presence)).presence;for(let X in Q)if(Object.prototype.hasOwnProperty.call(Q,X)){let G=Q[X],W=G.conn_info,H=G.chan_info;if(W)G.connInfo=W;if(H)G.chanInfo=H}return{clients:Q}})}presenceStats(Z){return l(this,void 0,void 0,function*(){let J={presence_stats:{channel:Z}};yield this._methodCall();let Y=yield this._callPromise(J,(Q)=>{return Q.presence_stats});return{numUsers:Y.num_users,numClients:Y.num_clients}})}startBatching(){this._batching=!0}stopBatching(){let Z=this;Promise.resolve().then(function(){Promise.resolve().then(function(){Z._batching=!1,Z._flush()})})}_debug(...Z){if(!this._debugEnabled)return;pB("debug",Z)}_codecName(){return this._codec.name()}_formatOverride(){return}_configure(){if(!("Promise"in globalThis))throw Error("Promise polyfill required");if(!this._endpoint)throw Error("endpoint configuration required");if(this._config.token!==null)this._token=this._config.token;if(this._config.data!==null)this._data=this._config.data;if(this._codec=new X9,this._formatOverride(),this._config.debug===!0||typeof localStorage<"u"&&typeof localStorage.getItem==="function"&&localStorage.getItem("centrifuge.debug"))this._debugEnabled=!0;if(this._debug("config",this._config),typeof this._endpoint==="string");else if(Array.isArray(this._endpoint)){this._transports=this._endpoint,this._emulation=!0;for(let Z in this._transports)if(this._transports.hasOwnProperty(Z)){let J=this._transports[Z];if(!J.endpoint||!J.transport)throw Error("malformed transport configuration");let Y=J.transport;if(["websocket","http_stream","sse","sockjs","webtransport"].indexOf(Y)<0)throw Error("unsupported transport name: "+Y)}}else throw Error("unsupported url configuration type: only string or array of objects are supported")}_setState(Z){if(this.state!==Z){this._reconnecting=!1;let J=this.state;return this.state=Z,this.emit("state",{newState:Z,oldState:J}),!0}return!1}_isDisconnected(){return this.state===h.Disconnected}_isConnecting(){return this.state===h.Connecting}_isConnected(){return this.state===h.Connected}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let Z=null;if(this._config.networkEventTarget!==null)Z=this._config.networkEventTarget;else if(typeof globalThis.addEventListener<"u")Z=globalThis;if(Z)Z.addEventListener("offline",()=>{if(this._debug("offline event triggered"),this.state===h.Connected||this.state===h.Connecting)this._disconnect(d1.transportClosed,"transport closed",!0),this._deviceWentOffline=!0}),Z.addEventListener("online",()=>{if(this._debug("online event triggered"),this.state!==h.Connecting)return;if(this._deviceWentOffline&&!this._transportClosed)this._deviceWentOffline=!1,this._transportClosed=!0;this._clearReconnectTimeout(),this._startReconnecting()}),this._networkEventsSet=!0}_getReconnectDelay(){let Z=d5(this._reconnectAttempts,this._config.minReconnectDelay,this._config.maxReconnectDelay);return this._reconnectAttempts+=1,Z}_clearOutgoingRequests(){for(let Z in this._callbacks)if(this._callbacks.hasOwnProperty(Z)){let J=this._callbacks[Z];clearTimeout(J.timeout);let Y=J.errback;if(!Y)continue;Y({error:this._createErrorObject(_.connectionClosed,"connection closed")})}this._callbacks={}}_clearConnectedState(){this._client=null,this._clearServerPingTimeout(),this._clearRefreshTimeout();for(let Z in this._subs){if(!this._subs.hasOwnProperty(Z))continue;let J=this._subs[Z];if(J.state===o.Subscribed)J._setSubscribing(m5.transportClosed,"transport closed")}for(let Z in this._serverSubs)if(this._serverSubs.hasOwnProperty(Z))this.emit("subscribing",{channel:Z})}_handleWriteError(Z){for(let J of Z){let Y=J.id;if(!(Y in this._callbacks))continue;let Q=this._callbacks[Y];clearTimeout(this._callbacks[Y].timeout),delete this._callbacks[Y];let X=Q.errback;X({error:this._createErrorObject(_.transportWriteError,"transport write error")})}}_transportSendCommands(Z){if(!Z.length)return!0;if(!this._transport)return!1;try{this._transport.send(this._codec.encodeCommands(Z),this._session,this._node)}catch(J){return this._debug("error writing commands",J),this._handleWriteError(Z),!1}return!0}_initializeTransport(){let Z;if(this._config.websocket!==null)Z=this._config.websocket;else if(!(typeof globalThis.WebSocket!=="function"&&typeof globalThis.WebSocket!=="object"))Z=globalThis.WebSocket;let J=null;if(this._config.sockjs!==null)J=this._config.sockjs;else if(typeof globalThis.SockJS<"u")J=globalThis.SockJS;let Y=null;if(this._config.eventsource!==null)Y=this._config.eventsource;else if(typeof globalThis.EventSource<"u")Y=globalThis.EventSource;let Q=null;if(this._config.fetch!==null)Q=this._config.fetch;else if(typeof globalThis.fetch<"u")Q=globalThis.fetch;let X=null;if(this._config.readableStream!==null)X=this._config.readableStream;else if(typeof globalThis.ReadableStream<"u")X=globalThis.ReadableStream;if(!this._emulation){if(cB(this._endpoint,"http"))throw Error("Provide explicit transport endpoints configuration in case of using HTTP (i.e. using array of TransportEndpoint instead of a single string), or use ws(s):// scheme in an endpoint if you aimed using WebSocket transport");else if(this._debug("client will use websocket"),this._transport=new Q9(this._endpoint,{websocket:Z}),!this._transport.supported())throw Error("WebSocket constructor not found, make sure it is available globally or passed as a dependency in Centrifuge options")}else{if(this._currentTransportIndex>=this._transports.length)this._triedAllTransports=!0,this._currentTransportIndex=0;let V=0;while(!0){if(V>=this._transports.length)throw Error("no supported transport found");let M=this._transports[this._currentTransportIndex],K=M.transport,F=M.endpoint;if(K==="websocket"){if(this._debug("trying websocket transport"),this._transport=new Q9(F,{websocket:Z}),!this._transport.supported()){this._debug("websocket transport not available"),this._currentTransportIndex++,V++;continue}}else if(K==="webtransport"){if(this._debug("trying webtransport transport"),this._transport=new $Y(F,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("webtransport transport not available"),this._currentTransportIndex++,V++;continue}}else if(K==="http_stream"){if(this._debug("trying http_stream transport"),this._transport=new MY(F,{fetch:Q,readableStream:X,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("http_stream transport not available"),this._currentTransportIndex++,V++;continue}}else if(K==="sse"){if(this._debug("trying sse transport"),this._transport=new FY(F,{eventsource:Y,fetch:Q,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug("sse transport not available"),this._currentTransportIndex++,V++;continue}}else if(K==="sockjs"){if(this._debug("trying sockjs"),this._transport=new LY(F,{sockjs:J,sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug("sockjs transport not available"),this._currentTransportIndex++,V++;continue}}else throw Error("unknown transport "+K);break}}let G=this,W=this._transport,H=this._nextTransportId();G._debug("id of transport",H);let z=!1,U=[];if(this._transport.emulation()){let V=G._sendConnect(!0);U.push(V)}this._setNetworkEvents();let B=this._codec.encodeCommands(U);this._transportClosed=!1;let L;L=setTimeout(function(){W.close()},this._config.timeout),this._transport.initialize(this._codecName(),{onOpen:function(){if(L)clearTimeout(L),L=null;if(G._transportId!=H){G._debug("open callback from non-actual transport"),W.close();return}if(z=!0,G._debug(W.subName(),"transport open"),W.emulation())return;G._transportIsOpen=!0,G._transportWasOpen=!0,G.startBatching(),G._sendConnect(!1),G._sendSubscribeCommands(),G.stopBatching(),G.emit("__centrifuge_debug:connect_frame_sent",{})},onError:function(V){if(G._transportId!=H){G._debug("error callback from non-actual transport");return}G._debug("transport level error",V)},onClose:function(V){if(L)clearTimeout(L),L=null;if(G._transportId!=H){G._debug("close callback from non-actual transport");return}G._debug(W.subName(),"transport closed"),G._transportClosed=!0,G._transportIsOpen=!1;let M="connection closed",K=!0,F=0;if(V&&"code"in V&&V.code)F=V.code;if(V&&V.reason)try{let O=JSON.parse(V.reason);M=O.reason,K=O.reconnect}catch(O){if(M=V.reason,F>=3500&&F<4000||F>=4500&&F<5000)K=!1}if(F<3000){if(F===1009)F=l0.messageSizeLimit,M="message size limit exceeded",K=!1;else F=d1.transportClosed,M="transport closed";if(G._emulation&&!G._transportWasOpen){if(G._currentTransportIndex++,G._currentTransportIndex>=G._transports.length)G._triedAllTransports=!0,G._currentTransportIndex=0}}else G._transportWasOpen=!0;if(G._isConnecting()&&!z)G.emit("error",{type:"transport",error:{code:_.transportClosed,message:"transport closed"},transport:W.name()});G._reconnecting=!1,G._disconnect(F,M,K)},onMessage:function(V){G._dataReceived(V)}},B),G.emit("__centrifuge_debug:transport_initialized",{})}_sendConnect(Z){let J=this._constructConnectCommand(),Y=this;return this._call(J,Z).then((Q)=>{let X=Q.reply.connect;if(Y._connectResponse(X),Q.next)Q.next()},(Q)=>{if(Y._connectError(Q.error),Q.next)Q.next()}),J}_startReconnecting(){if(this._debug("start reconnecting"),!this._isConnecting()){this._debug("stop reconnecting: client not in connecting state");return}if(this._reconnecting){this._debug("reconnect already in progress, return from reconnect routine");return}if(this._transportClosed===!1){this._debug("waiting for transport close");return}this._reconnecting=!0;let Z=this._token==="";if(!(this._refreshRequired||Z&&this._config.getToken!==null)){if(this._config.getData)this._config.getData().then((Q)=>{if(!this._isConnecting())return;this._data=Q,this._initializeTransport()}).catch((Q)=>this._handleGetDataError(Q));else this._initializeTransport();return}let Y=this;this._getToken().then(function(Q){if(!Y._isConnecting())return;if(Q==null||Q==null){Y._failUnauthorized();return}if(Y._token=Q,Y._debug("connection token refreshed"),Y._config.getData)Y._config.getData().then(function(X){if(!Y._isConnecting())return;Y._data=X,Y._initializeTransport()}).catch((X)=>Y._handleGetDataError(X));else Y._initializeTransport()}).catch(function(Q){if(!Y._isConnecting())return;if(Q instanceof V1){Y._failUnauthorized();return}Y.emit("error",{type:"connectToken",error:{code:_.clientConnectToken,message:Q!==void 0?Q.toString():""}});let X=Y._getReconnectDelay();Y._debug("error on getting connection token, reconnect after "+X+" milliseconds",Q),Y._reconnecting=!1,Y._reconnectTimeout=setTimeout(()=>{Y._startReconnecting()},X)})}_handleGetDataError(Z){if(Z instanceof V1){this._failUnauthorized();return}this.emit("error",{type:"connectData",error:{code:_.badConfiguration,message:(Z===null||Z===void 0?void 0:Z.toString())||""}});let J=this._getReconnectDelay();this._debug("error on getting connect data, reconnect after "+J+" milliseconds",Z),this._reconnecting=!1,this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},J)}_connectError(Z){if(this.state!==h.Connecting)return;if(Z.code===109)this._refreshRequired=!0;if(Z.code<100||Z.temporary===!0||Z.code===109)this.emit("error",{type:"connect",error:Z}),this._debug("closing transport due to connect error"),this._disconnect(Z.code,Z.message,!0);else this._disconnect(Z.code,Z.message,!1)}_scheduleReconnect(){if(!this._isConnecting())return;let Z=!1;if(this._emulation&&!this._transportWasOpen&&!this._triedAllTransports)Z=!0;let J=this._getReconnectDelay();if(Z)J=0;this._debug("reconnect after "+J+" milliseconds"),this._clearReconnectTimeout(),this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},J)}_constructConnectCommand(){let Z={};if(this._token)Z.token=this._token;if(this._data)Z.data=this._data;if(this._config.name)Z.name=this._config.name;if(this._config.version)Z.version=this._config.version;if(Object.keys(this._config.headers).length>0)Z.headers=this._config.headers;let J={},Y=!1;for(let Q in this._serverSubs)if(this._serverSubs.hasOwnProperty(Q)&&this._serverSubs[Q].recoverable){Y=!0;let X={recover:!0};if(this._serverSubs[Q].offset)X.offset=this._serverSubs[Q].offset;if(this._serverSubs[Q].epoch)X.epoch=this._serverSubs[Q].epoch;J[Q]=X}if(Y)Z.subs=J;return{connect:Z}}_getHistoryRequest(Z,J){let Y={channel:Z};if(J!==void 0){if(J.since){if(Y.since={offset:J.since.offset},J.since.epoch)Y.since.epoch=J.since.epoch}if(J.limit!==void 0)Y.limit=J.limit;if(J.reverse===!0)Y.reverse=!0}return Y}_methodCall(){if(this._isConnected())return Promise.resolve();return new Promise((Z,J)=>{let Y=setTimeout(function(){J({code:_.timeout,message:"timeout"})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:Y,resolve:Z,reject:J}})}_callPromise(Z,J){return new Promise((Y,Q)=>{this._call(Z,!1).then((X)=>{var G;let W=J(X.reply);Y(W),(G=X.next)===null||G===void 0||G.call(X)},(X)=>{var G;Q(X.error),(G=X.next)===null||G===void 0||G.call(X)})})}_dataReceived(Z){if(this._serverPing>0)this._waitServerPing();let J=this._codec.decodeReplies(Z);this._dispatchPromise=this._dispatchPromise.then(()=>{let Y;this._dispatchPromise=new Promise((Q)=>{Y=Q}),this._dispatchSynchronized(J,Y)})}_dispatchSynchronized(Z,J){let Y=Promise.resolve();for(let Q in Z)if(Z.hasOwnProperty(Q))Y=Y.then(()=>{return this._dispatchReply(Z[Q])});Y=Y.then(()=>{J()})}_dispatchReply(Z){let J,Y=new Promise((X)=>{J=X});if(Z===void 0||Z===null)return this._debug("dispatch: got undefined or null reply"),J(),Y;let Q=Z.id;if(Q&&Q>0)this._handleReply(Z,J);else if(!Z.push)this._handleServerPing(J);else this._handlePush(Z.push,J);return Y}_call(Z,J){return new Promise((Y,Q)=>{if(Z.id=this._nextCommandId(),this._registerCall(Z.id,Y,Q),!J)this._addCommand(Z)})}_startConnecting(){if(this._debug("start connecting"),this._setState(h.Connecting))this.emit("connecting",{code:d1.connectCalled,reason:"connect called"});this._client=null,this._startReconnecting()}_disconnect(Z,J,Y){if(this._isDisconnected())return;this._transportIsOpen=!1;let Q=this.state;this._reconnecting=!1;let X={code:Z,reason:J},G=!1;if(Y)G=this._setState(h.Connecting);else G=this._setState(h.Disconnected),this._rejectPromises({code:_.clientDisconnected,message:"disconnected"});if(this._clearOutgoingRequests(),Q===h.Connecting)this._clearReconnectTimeout();if(Q===h.Connected)this._clearConnectedState();if(G)if(this._isConnecting())this.emit("connecting",X);else this.emit("disconnected",X);if(this._transport){this._debug("closing existing transport");let W=this._transport;this._transport=null,W.close(),this._transportClosed=!0,this._nextTransportId()}else this._debug("no transport to close");this._scheduleReconnect()}_failUnauthorized(){this._disconnect(l0.unauthorized,"unauthorized",!1)}_getToken(){if(this._debug("get connection token"),!this._config.getToken)return this.emit("error",{type:"configuration",error:{code:_.badConfiguration,message:"token expired but no getToken function set in the configuration"}}),Promise.reject(new V1(""));return this._config.getToken({})}_refresh(){let Z=this._client,J=this;this._getToken().then(function(Y){if(Z!==J._client)return;if(!Y){J._failUnauthorized();return}if(J._token=Y,J._debug("connection token refreshed"),!J._isConnected())return;let Q={refresh:{token:J._token}};J._call(Q,!1).then((X)=>{let G=X.reply.refresh;if(J._refreshResponse(G),X.next)X.next()},(X)=>{if(J._refreshError(X.error),X.next)X.next()})}).catch(function(Y){if(!J._isConnected())return;if(Y instanceof V1){J._failUnauthorized();return}J.emit("error",{type:"refreshToken",error:{code:_.clientRefreshToken,message:Y!==void 0?Y.toString():""}}),J._refreshTimeout=setTimeout(()=>J._refresh(),J._getRefreshRetryDelay())})}_refreshError(Z){if(Z.code<100||Z.temporary===!0)this.emit("error",{type:"refresh",error:Z}),this._refreshTimeout=setTimeout(()=>this._refresh(),this._getRefreshRetryDelay());else this._disconnect(Z.code,Z.message,!1)}_getRefreshRetryDelay(){return d5(0,5000,1e4)}_refreshResponse(Z){if(this._refreshTimeout)clearTimeout(this._refreshTimeout),this._refreshTimeout=null;if(Z.expires)this._client=Z.client,this._refreshTimeout=setTimeout(()=>this._refresh(),c5(Z.ttl))}_removeSubscription(Z){if(Z===null)return;delete this._subs[Z.channel]}_unsubscribe(Z){if(!this._transportIsOpen)return Promise.resolve();let Y={unsubscribe:{channel:Z.channel}},Q=this;return new Promise((G,W)=>{this._call(Y,!1).then((H)=>{if(G(),H.next)H.next()},(H)=>{if(G(),H.next)H.next();Q._disconnect(d1.unsubscribeError,"unsubscribe error",!0)})})}_getSub(Z,J){if(J&&J>0){for(let Q in this._subs)if(this._subs.hasOwnProperty(Q)){let X=this._subs[Q];if(X._id===J)return X}return null}let Y=this._subs[Z];if(!Y)return null;return Y}_isServerSub(Z){return this._serverSubs[Z]!==void 0}_sendSubscribeCommands(){let Z=[];for(let J in this._subs){if(!this._subs.hasOwnProperty(J))continue;let Y=this._subs[J];if(Y._inflight===!0)continue;if(Y.state===o.Subscribing){let Q=Y._subscribe();if(Q)Z.push(Q)}}return Z}_connectResponse(Z){if(this._transportIsOpen=!0,this._transportWasOpen=!0,this._reconnectAttempts=0,this._refreshRequired=!1,this._isConnected())return;if(this._client=Z.client,this._setState(h.Connected),this._refreshTimeout)clearTimeout(this._refreshTimeout);if(Z.expires)this._refreshTimeout=setTimeout(()=>this._refresh(),c5(Z.ttl));this._session=Z.session,this._node=Z.node,this.startBatching(),this._sendSubscribeCommands(),this.stopBatching();let J={client:Z.client,transport:this._transport.subName()};if(Z.data)J.data=Z.data;if(this.emit("connected",J),this._resolvePromises(),this._processServerSubs(Z.subs||{}),Z.ping&&Z.ping>0)this._serverPing=Z.ping*1000,this._sendPong=Z.pong===!0,this._waitServerPing();else this._serverPing=0}_processServerSubs(Z){for(let J in Z){if(!Z.hasOwnProperty(J))continue;let Y=Z[J];this._serverSubs[J]={offset:Y.offset,epoch:Y.epoch,recoverable:Y.recoverable||!1};let Q=this._getSubscribeContext(J,Y);this.emit("subscribed",Q)}for(let J in Z){if(!Z.hasOwnProperty(J))continue;let Y=Z[J];if(Y.recovered){let Q=Y.publications;if(Q&&Q.length>0){for(let X in Q)if(Q.hasOwnProperty(X))this._handlePublication(J,Q[X])}}}for(let J in this._serverSubs){if(!this._serverSubs.hasOwnProperty(J))continue;if(!Z[J])this.emit("unsubscribed",{channel:J}),delete this._serverSubs[J]}}_clearRefreshTimeout(){if(this._refreshTimeout!==null)clearTimeout(this._refreshTimeout),this._refreshTimeout=null}_clearReconnectTimeout(){if(this._reconnectTimeout!==null)clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null}_clearServerPingTimeout(){if(this._serverPingTimeout!==null)clearTimeout(this._serverPingTimeout),this._serverPingTimeout=null}_waitServerPing(){if(this._config.maxServerPingDelay===0)return;if(!this._isConnected())return;this._clearServerPingTimeout(),this._serverPingTimeout=setTimeout(()=>{if(!this._isConnected())return;this._disconnect(d1.noPing,"no ping",!0)},this._serverPing+this._config.maxServerPingDelay)}_getSubscribeContext(Z,J){let Y={channel:Z,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1,hasRecoveredPublications:!1};if(J.recovered)Y.recovered=!0;if(J.positioned)Y.positioned=!0;if(J.recoverable)Y.recoverable=!0;if(J.was_recovering)Y.wasRecovering=!0;let Q="";if("epoch"in J)Q=J.epoch;let X=0;if("offset"in J)X=J.offset;if(Y.positioned||Y.recoverable)Y.streamPosition={offset:X,epoch:Q};if(Array.isArray(J.publications)&&J.publications.length>0)Y.hasRecoveredPublications=!0;if(J.data)Y.data=J.data;return Y}_handleReply(Z,J){let Y=Z.id;if(!(Y in this._callbacks)){J();return}let Q=this._callbacks[Y];if(clearTimeout(this._callbacks[Y].timeout),delete this._callbacks[Y],!iB(Z)){let X=Q.callback;if(!X)return;X({reply:Z,next:J})}else{let X=Q.errback;if(!X){J();return}let G={code:Z.error.code,message:Z.error.message||"",temporary:Z.error.temporary||!1};X({error:G,next:J})}}_handleJoin(Z,J,Y){let Q=this._getSub(Z,Y);if(!Q&&Z){if(this._isServerSub(Z)){let X={channel:Z,info:this._getJoinLeaveContext(J.info)};this.emit("join",X)}return}Q._handleJoin(J)}_handleLeave(Z,J,Y){let Q=this._getSub(Z,Y);if(!Q&&Z){if(this._isServerSub(Z)){let X={channel:Z,info:this._getJoinLeaveContext(J.info)};this.emit("leave",X)}return}Q._handleLeave(J)}_handleUnsubscribe(Z,J){let Y=this._getSub(Z,0);if(!Y&&Z){if(this._isServerSub(Z))delete this._serverSubs[Z],this.emit("unsubscribed",{channel:Z});return}if(J.code<2500)Y._setUnsubscribed(J.code,J.reason,!1);else Y._setSubscribing(J.code,J.reason)}_handleSubscribe(Z,J){this._serverSubs[Z]={offset:J.offset,epoch:J.epoch,recoverable:J.recoverable||!1},this.emit("subscribed",this._getSubscribeContext(Z,J))}_handleDisconnect(Z){let J=Z.code,Y=!0;if(J>=3500&&J<4000||J>=4500&&J<5000)Y=!1;this._disconnect(J,Z.reason,Y)}_getPublicationContext(Z,J){let Y={channel:Z,data:J.data};if(J.offset)Y.offset=J.offset;if(J.info)Y.info=this._getJoinLeaveContext(J.info);if(J.tags)Y.tags=J.tags;return Y}_getJoinLeaveContext(Z){let J={client:Z.client,user:Z.user},Y=Z.conn_info;if(Y)J.connInfo=Y;let Q=Z.chan_info;if(Q)J.chanInfo=Q;return J}_handlePublication(Z,J,Y){let Q=this._getSub(Z,Y);if(!Q&&Z){if(this._isServerSub(Z)){let X=this._getPublicationContext(Z,J);if(this.emit("publication",X),J.offset!==void 0)this._serverSubs[Z].offset=J.offset}return}Q._handlePublication(J)}_handleMessage(Z){this.emit("message",{data:Z.data})}_handleServerPing(Z){if(this._sendPong){let J={};this._transportSendCommands([J])}Z()}_handlePush(Z,J){let{channel:Y,id:Q}=Z;if(Z.pub)this._handlePublication(Y,Z.pub,Q);else if(Z.message)this._handleMessage(Z.message);else if(Z.join)this._handleJoin(Y,Z.join,Q);else if(Z.leave)this._handleLeave(Y,Z.leave,Q);else if(Z.unsubscribe)this._handleUnsubscribe(Y,Z.unsubscribe);else if(Z.subscribe)this._handleSubscribe(Y,Z.subscribe);else if(Z.disconnect)this._handleDisconnect(Z.disconnect);J()}_flush(){let Z=this._commands.slice(0);this._commands=[],this._transportSendCommands(Z)}_createErrorObject(Z,J,Y){let Q={code:Z,message:J};if(Y)Q.temporary=!0;return Q}_registerCall(Z,J,Y){this._callbacks[Z]={callback:J,errback:Y,timeout:null},this._callbacks[Z].timeout=setTimeout(()=>{if(delete this._callbacks[Z],BY(Y))Y({error:this._createErrorObject(_.timeout,"timeout")})},this._config.timeout)}_addCommand(Z){if(this._batching)this._commands.push(Z);else this._transportSendCommands([Z])}_nextPromiseId(){return++this._promiseId}_nextTransportId(){return++this._transportId}_resolvePromises(){for(let Z in this._promises){if(!this._promises.hasOwnProperty(Z))continue;if(this._promises[Z].timeout)clearTimeout(this._promises[Z].timeout);this._promises[Z].resolve(),delete this._promises[Z]}}_rejectPromises(Z){for(let J in this._promises){if(!this._promises.hasOwnProperty(J))continue;if(this._promises[J].timeout)clearTimeout(this._promises[J].timeout);this._promises[J].reject(Z),delete this._promises[J]}}}J0.SubscriptionState=o;J0.State=h;J0.UnauthorizedError=V1;var l5=(Z,J)=>{async function Y(){let Q=await fetch(Z+"api/centrifuge/gen_token");if(!Q.ok){if(Q.status===403)throw new J0.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${Q.status}`)}return(await Q.json()).token}return J?new J0(J||"",{getToken:Y}):null},tB=rB(null),c1=tB;import{useContext as ZK,useEffect as JK}from"react";import{useEffect as eB,useState as IY}from"react";function i5(Z,J){let[Y,Q]=IY(null),[X,G]=IY(!1);return eB(()=>{if(!X)G(!0),fetch(Z+`api/support/${J}`,{method:"GET"}).then((W)=>W.json()).then((W)=>{Q(W)})},[]),Y}var YK=({children:Z})=>{let J=ZK(u1),Y=v1(),Q=i5(Y,"socketIO"),X=(G)=>{if(typeof window<"u")window.sid=G.sid,console.log(`SocketIO initialized: ${window.sid}`)};return JK(()=>{if(!J)return;let G=()=>{console.log("SocketIO connected")},W=(H)=>{console.log(`SocketIO disconnected: ${H}`),J.connect()};if(Q)J.on("pieinit",X),J.on("connect",G),J.on("disconnect",W),J.connect();return()=>{if(Q)J.off("pieinit",X),J.off("connect",G),J.off("disconnect",W),J.disconnect()}},[J,Q]),Z},n5=YK;import{useContext as QK,useEffect as XK}from"react";var GK=({children:Z})=>{let J=QK(c1),Y=v1(),Q=i5(Y,"centrifuge");return XK(()=>{if(!J)return;let X=()=>{console.log("Centrifuge connected")},G=(W)=>{console.log("Centrifuge disconnected:",W)};if(Q)J.on("connected",X),J.on("disconnected",G),J.connect();return()=>{if(Q)J.disconnect()}},[J,Q]),Z},o5=GK;var PX=S(P9(),1);import{useContext as T9,useEffect as w9}from"react";var sL=({card:Z,data:J,children:Y,useSocketioSupport:Q=!1,useCentrifugeSupport:X=!1,useMittSupport:G=!1,centrifugeChannel:W=void 0,methods:H=void 0})=>{let z=k1();if(z)console.log("[PieCard] Rendering card:",Z),console.log("[PieCard] Card data:",J),console.log("[PieCard] Component name:",J?.name),console.log("[PieCard] Real-time support:",{socketio:Q,centrifuge:X,mitt:G,centrifugeChannel:W}),console.log("[PieCard] Methods:",H?Object.keys(H):"none"),console.log("[PieCard] Has children:",!!Y);let U=T9(u1),B=T9(c1),L=T9(y1);if(w9(()=>{if(!U||!Q||!H||!J.name){if(z&&Q)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!U,useSocketioSupport:Q,hasMethods:!!H,hasDataName:!!J?.name});return}return Object.entries(H).forEach(([V,M])=>{let K=`pie${V}_${J.name}`;if(z)console.log(`[PieCard] Socket.IO registering event: ${K}`);U.on(K,M)}),()=>{Object.entries(H).forEach(([V,M])=>{let K=`pie${V}_${J.name}`;if(z)console.log(`[PieCard] Socket.IO unregistering event: ${K}`);U.off(K,M)})}},[U,H,J.name]),w9(()=>{if(!B||!X||!W||!H||!J.name){if(z&&X)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!B,useCentrifugeSupport:X,hasCentrifugeChannel:!!W,hasMethods:!!H,hasDataName:!!J?.name});return}let V=Object.entries(H).map(([M,K])=>{let F=`pie${M}_${J.name}_${W}`;if(z)console.log(`[PieCard] Centrifuge subscribing to channel: ${F}`);let O=B.newSubscription(F);return O.on("publication",(D)=>{if(z)console.log(`[PieCard] Centrifuge received data on ${F}:`,D.data);K(D.data)}),O.subscribe(),O});return()=>{V.forEach((M)=>{if(z)console.log("[PieCard] Centrifuge unsubscribing from channel");M.unsubscribe(),B.removeSubscription(M)})}},[B,W,H,J.name]),w9(()=>{if(!L||!G||!H||!J.name){if(z&&G)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!L,useMittSupport:G,hasMethods:!!H,hasDataName:!!J?.name});return}return Object.entries(H).forEach(([V,M])=>{let K=`pie${V}_${J.name}`;if(z)console.log(`[PieCard] Mitt registering event: ${K}`);L.on(K,M)}),()=>{Object.entries(H).forEach(([V,M])=>{let K=`pie${V}_${J.name}`;if(z)console.log(`[PieCard] Mitt unregistering event: ${K}`);L.off(K,M)})}},[L,H,J.name]),z)console.log("[PieCard] Rendering complete, returning children");return Y},F1=sL;function U6(Z){if(!Z)return{};let J={...Z};if("animationName"in J&&typeof J.animationName==="object"){let Y="radiumAnimation_"+Math.random().toString(36).substring(2,8);J.animationName=H1.keyframes(J.animationName,Y)}return J}import{jsx as E9}from"react/jsx-runtime";var rL=({data:Z,content:J,setUiAjaxConfiguration:Y})=>{let{name:Q,sx:X}=Z;return E9(F1,{card:Q,data:Z,children:E9("div",{style:U6(X),id:Q,children:J.map((G,W)=>{return E9(Z1,{uiConfig:G,setUiAjaxConfiguration:Y},`children-${W}`)})})})},bQ=H1(rL);import{jsx as gQ}from"react/jsx-runtime";var tL=({data:Z,content:J,setUiAjaxConfiguration:Y})=>{let{name:Q}=Z;return gQ(F1,{card:Q,data:Z,children:J.map((X,G)=>{return gQ(Z1,{uiConfig:X,setUiAjaxConfiguration:Y},`children-${G}`)})})},yQ=tL;import{useContext as mQ,useEffect as eL,useRef as ZM,useState as uQ}from"react";import{jsx as dQ}from"react/jsx-runtime";var JM=({data:Z,content:J})=>{let{useLoader:Y,noReturn:Q,returnType:X,useSocketioSupport:G,useCentrifugeSupport:W,useMittSupport:H,centrifugeChannel:z}=Z,U=mQ(_1),[B,L]=uQ(!1),[V,M]=uQ(null),K=ZM(J),F=mQ(y1),O=(N)=>{if(N===null)L(!0);else if(L(!1),!Q)K.current=N;if(!Q)M(N)},D=(N)=>{K.current=N.content,M(N.content)},P=(N)=>{if(N===null)L(!0);else if(L(!1),!Q)for(let q of N)F.emit(q.name,q.data)};if(eL(()=>{M(J),L(!1)},[J]),!V&&Y)return U;return dQ(F1,{card:"AjaxGroupCard",data:Z,methods:{changeContent:D},useSocketioSupport:G,useCentrifugeSupport:W,useMittSupport:H,centrifugeChannel:z,children:dQ(Z1,{uiConfig:V??K.current,setUiAjaxConfiguration:X==="events"?P:O})})},cQ=H1(JM);function S9(Z=1000){return new Promise((J)=>{if(typeof window>"u"){J();return}let Y=()=>{if(typeof window.sid<"u")J();else setTimeout(Y,Z)};Y()})}import{useMemo as YM}from"react";var QM=(Z,J={},Y=[],Q,X)=>{let G=X?.renderingLogEnabled??!1,W=X?.apiServer??"";if(G)console.log("Registering AJAX: ",Q,J,Y);if(!Q||!Z){if(G)console.warn("Registration FAILED: pathname or setUiAjaxConfiguration is missing!");return()=>{}}return async(H={})=>{if(typeof window>"u"||typeof document>"u"){if(G)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}if(Y.includes("sid"))await S9();let z=new FormData;for(let[B,L]of Object.entries({...J,...H}))z.append(B,L);for(let B of Y)if(B==="sid"){if(!window.sid)throw Error("SocketIO isn't initialized properly");z.append("sid",window.sid)}else{let L=document.getElementsByName(B);if(!L.length){if(G)console.warn(`No input found with name ${B}`);continue}let V=L[0];if(V instanceof HTMLInputElement)if(V.type==="file"&&V.files)Array.from(V.files).forEach((M)=>z.append(B,M));else z.append(B,V.value);else if(V instanceof HTMLTextAreaElement)z.append(B,V.value)}let U=W+"api/ajax_content"+Q;return Z(null),await fetch(U,{method:"POST",body:z}).then(async(B)=>{let V=(B.headers.get("content-type")||"").includes("application/json");if(!!B.body?.getReader&&!V){let K=B.body.getReader(),F=new TextDecoder,O="";while(!0){let{done:D,value:P}=await K.read();if(D)break;O+=F.decode(P,{stream:!0});let N=O.split(`
28
- `);O=N.pop()??"";for(let q of N){let T=q.trim();if(!T)continue;try{let C=JSON.parse(T);Z([C])}catch(C){if(G)console.warn("Failed to parse streamed line:",T)}}}if(O.trim())try{let D=JSON.parse(O);Z([D])}catch(D){if(G)console.warn("Failed to parse final streamed line:",O)}return{}}else{let K=await B.json();return Z(K),K}}).catch((B)=>{if(G)console.error("AJAX request failed:",B);return Z(null),B})}},B6=(Z,J={},Y=[],Q)=>{let{apiServer:X,enableRenderingLog:G}=H0();return YM(()=>QM(Z,J,Y,Q,{apiServer:X,renderingLogEnabled:G}),[Z,J,Y,Q,X,G])};var a9=S(o9(),1),G0=S(o9(),1),I6=a9.default.default||a9.default;import{jsx as s9,jsxs as e2}from"react/jsx-runtime";var t2=({data:Z,setUiAjaxConfiguration:J})=>{let{name:Y,title:Q,iconUrl:X,iconPosition:G,sx:W,pathname:H,kwargs:z,depsNames:U}=Z,B=B6(J,z,U,H);return s9(F1,{card:"AjaxButtonCard",data:Z,children:e2("button",{id:Y,className:"box-border flex min-h-12 w-full min-w-min cursor-pointer items-center justify-center rounded-[16px] border border-[#080318] bg-white text-center font-[TTForsTrial] text-[#080318] hover:bg-neutral-300",value:Y,onClick:()=>B(),style:U6(W),type:"button",children:[X&&G==="start"&&s9("img",{src:X,alt:""}),I6(Q),X&&G==="end"&&s9("img",{src:X,alt:""})]})})},s3=H1(t2);import{forwardRef as NF,useEffect as LX,useImperativeHandle as AF,useRef as RF,useState as A6}from"react";import{useRef as ZF,useState as JF}from"react";import{jsx as YF}from"react/jsx-runtime";function r9(Z){let[J,Y]=JF(!1),Q=ZF(null);return YF("textarea",{ref:Q,...Z,onKeyUp:()=>{Y(!1)},onKeyDown:(H)=>{if(H.key==="Enter"&&H.shiftKey){if(Y(!0),Q.current&&typeof window<"u"){let z=window.getComputedStyle(Q.current),U=parseFloat(z.lineHeight);Q.current.style.height=Q.current.scrollHeight+U+"px"}}if(H.key==="Backspace"){if(Y(!0),Q.current&&typeof window<"u"){let z=window.getComputedStyle(Q.current),U=parseFloat(z.lineHeight);if(Q.current.scrollHeight>U)Q.current.style.height=Q.current.scrollHeight-U+"px"}}Z.onKeyDown&&Z.onKeyDown(H)},onBlur:(H)=>{Y(!1),Z.onBlur&&Z.onBlur(H)},style:{resize:J?"vertical":"none",overflowY:"auto",...Z.style}})}import{useRef as XF,useCallback as GF}from"react";import{jsx as r3}from"react/jsx-runtime";var QF=()=>r3("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:r3("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})}),t3=QF;import{jsx as t9}from"react/jsx-runtime";var WF=({type:Z="button",onClick:J,icons:Y})=>{let Q=XF(null),X=GF(()=>{let W=Q.current;if(W)W.style.transform="scale(0.8)",setTimeout(()=>{W.style.transform="scale(1)"},600)},[]);return t9("button",{ref:Q,type:Z,onClick:(W)=>{if(J)J(W);X()},className:"mr-1.5 rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",style:{transition:"transform 300ms ease"},children:Y.sendIcon?t9("img",{src:Y.sendIcon,alt:""}):t9(t3,{})})},e3=WF;import{jsx as ZX}from"react/jsx-runtime";var HF=()=>ZX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:ZX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"})}),JX=HF;import{jsx as q6,jsxs as BF,Fragment as UF}from"react/jsx-runtime";var zF=({name:Z,accept:J,fileInputRef:Y,onSelectFile:Q,icons:X})=>{return BF(UF,{children:[q6("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:()=>{if(Y.current)Y.current.click()},children:X.attachFileIcon?q6("img",{src:X.attachFileIcon,alt:""}):q6(JX,{})}),q6("input",{id:Z+"__pie__file",name:Z+"__pie__file",className:"hidden",type:"file",accept:J,ref:Y,onChange:(G)=>{if(G.target.files)Q(G.target.files[0])}})]})},YX=zF;import{jsx as QX}from"react/jsx-runtime";var KF=()=>QX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5 text-gray-500",children:QX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),XX=KF;import{jsx as GX}from"react/jsx-runtime";var LF=()=>GX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:GX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),D6=LF;import{jsx as W5,jsxs as FF}from"react/jsx-runtime";var MF=({name:Z,selectedFile:J,onDropFile:Y})=>{return FF("div",{className:"flex w-full cursor-default flex-row items-center gap-2",children:[W5(XX,{}),W5("span",{className:"flex-1",children:J.name}),W5("input",{type:"hidden",name:Z,value:""}),W5("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:Y,children:W5(D6,{})})]})},WX=MF;import{jsx as HX,jsxs as OF}from"react/jsx-runtime";var $F=()=>OF("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:[HX("path",{d:"M8 5C8 2.79086 9.79086 1 12 1C14.2091 1 16 2.79086 16 5V12C16 14.2091 14.2091 16 12 16C9.79086 16 8 14.2091 8 12V5Z"}),HX("path",{d:"M6.25 11.8438V12C6.25 13.525 6.8558 14.9875 7.93414 16.0659C9.01247 17.1442 10.475 17.75 12 17.75C13.525 17.75 14.9875 17.1442 16.0659 16.0659C17.1442 14.9875 17.75 13.525 17.75 12V11.8438C17.75 11.2915 18.1977 10.8438 18.75 10.8438H19.25C19.8023 10.8438 20.25 11.2915 20.25 11.8437V12C20.25 14.188 19.3808 16.2865 17.8336 17.8336C16.5842 19.0831 14.9753 19.8903 13.25 20.1548V22C13.25 22.5523 12.8023 23 12.25 23H11.75C11.1977 23 10.75 22.5523 10.75 22V20.1548C9.02471 19.8903 7.41579 19.0831 6.16637 17.8336C4.61919 16.2865 3.75 14.188 3.75 12V11.8438C3.75 11.2915 4.19772 10.8438 4.75 10.8438H5.25C5.80228 10.8438 6.25 11.2915 6.25 11.8438Z"})]}),zX=$F;import{jsx as H5}from"react/jsx-runtime";var VF=({isListening:Z,toggleListening:J,icons:Y})=>{return H5("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:J,children:Z?Y.cancelIcon?H5("img",{src:Y.cancelIcon,alt:""}):H5(D6,{}):Y.voiceRecordingIcon?H5("img",{src:Y.voiceRecordingIcon,alt:""}):H5(zX,{})})},UX=VF;import{jsx as BX,jsxs as qF}from"react/jsx-runtime";var IF=({option:Z,onClickOption:J})=>{return qF("div",{className:"flex w-fit cursor-pointer flex-row place-content-center items-center gap-1 rounded-md border border-black bg-white px-2 py-1 text-black",onClick:()=>{J(Z.title)},style:Z.sx,children:[Z.iconPosition==="start"&&BX("img",{src:Z.iconUrl,alt:""}),Z.title,Z.iconPosition==="end"&&BX("img",{src:Z.iconUrl,alt:""})]})},N6=IF;import{jsx as KX}from"react/jsx-runtime";var DF=({options:Z,handleOptionClick:J})=>{return KX("div",{className:"flex w-full flex-row flex-wrap justify-start gap-[5px]",children:Z.map((Y,Q)=>{return KX(N6,{option:Y,onClickOption:J},Q)})})},e9=DF;import{jsx as E1,jsxs as MX}from"react/jsx-runtime";var PF=NF(({name:Z,defaultValue:J,defaultOptions:Y,isArea:Q,placeholder:X,fileAccept:G,optionsPosition:W,icons:H,handleOptionClick:z,handleSendMessage:U,sx:B},L)=>{let V=RF(null),[M,K]=A6(null),[F,O]=A6(J),[D,P]=A6(Y),[N,q]=A6(!1);AF(L,()=>({clear:()=>{if(O(""),K(null),V.current)V.current.value=""},setValue:(C)=>O(C),setOptions:(C)=>P(C)})),LX(()=>{O(J)},[J]),LX(()=>{},[]);let T=()=>{};return MX("div",{className:"flex flex-col items-center gap-[0.1rem]",id:Z+"_chat_input",style:B,children:[D&&W==="top"&&E1(e9,{options:D,handleOptionClick:z}),E1("div",{className:"stretch relative flex size-full flex-1 flex-row items-stretch gap-3 last:mb-2 md:mx-4 md:flex-col md:last:mb-6 lg:mx-auto",children:MX("div",{className:"flex w-full grow flex-row items-center rounded-md bg-transparent",children:[M?E1(WX,{name:Z,selectedFile:M,onDropFile:()=>{if(K(null),V.current)V.current.value=""}}):!Q?E1("input",{name:Z,value:F,onChange:(C)=>O(C.target.value),onKeyDown:(C)=>{if(C.key==="Enter")C.preventDefault(),U()},tabIndex:0,placeholder:X,className:"m-0 w-full resize-none border-0 bg-transparent outline-none",style:{maxHeight:200,height:"100%",overflowY:"hidden"}}):E1(r9,{name:Z,value:F,onChange:(C)=>O(C.target.value),onKeyDown:(C)=>{if(C.key==="Enter"&&!C.shiftKey)C.preventDefault(),U()},tabIndex:0,rows:2,placeholder:X,className:"m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 outline-none md:pl-0",style:{maxHeight:200,height:"100%",minHeight:24}}),E1(UX,{isListening:N,toggleListening:T,icons:H}),E1(YX,{name:Z,fileInputRef:V,accept:G,onSelectFile:K,icons:H}),E1(e3,{onClick:U,icons:H})]})}),D&&W==="bottom"&&E1(e9,{options:D,handleOptionClick:z})]})}),FX=PF;import{useState as fF,useEffect as jF}from"react";import{useEffect as TF,useState as wF}from"react";import{jsx as SF}from"react/jsx-runtime";function EF({children:Z}){let[J,Y]=wF(Z);return TF(()=>{Y(Z)},[Z]),SF("div",{className:"max-w-full first:mt-0",children:J})}var $X=EF;import{jsx as OX}from"react/jsx-runtime";var xF=()=>OX("svg",{width:"30",height:"30",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:OX("path",{d:"m 8 1 c -1.65625 0 -3 1.34375 -3 3 s 1.34375 3 3 3 s 3 -1.34375 3 -3 s -1.34375 -3 -3 -3 z m -1.5 7 c -2.492188 0 -4.5 2.007812 -4.5 4.5 v 0.5 c 0 1.109375 0.890625 2 2 2 h 8 c 1.109375 0 2 -0.890625 2 -2 v -0.5 c 0 -2.492188 -2.007812 -4.5 -4.5 -4.5 z m 0 0",fill:"#2e3436"})}),VX=xF;import{jsx as R6}from"react/jsx-runtime";function CF({username:Z,avatar:J}){return R6("div",{className:"w-[30px]",children:R6("div",{className:"relative flex size-[30px] items-center justify-center rounded-sm p-1 text-white",children:J?R6("img",{src:J,className:"absolute inset-0 rounded",alt:Z}):R6(VX,{})})})}var Z7=CF;import{jsx as D1,jsxs as IX}from"react/jsx-runtime";var _F=({message:Z,handleOptionClick:J,setUiAjaxConfiguration:Y})=>{let[Q,X]=fF(!1);return jF(()=>{let G=setTimeout(()=>{if(Q)X(!1)},1000);return()=>clearTimeout(G)},[Q]),D1("div",{className:"group w-full border-b border-black/10",id:Z.id,children:IX("div",{className:`flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-3xl xl:max-w-5xl ${Z.align==="center"?"m-auto":""} ${Z.align==="right"?"ml-auto justify-end":""} ${Z.align==="left"?"mr-auto":""} `,children:[(Z.align==="left"||Z.align==="center")&&D1("div",{className:"relative flex shrink-0 flex-col items-end",children:D1(Z7,{username:Z.username,avatar:Z.avatar})}),IX("div",{className:"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]",children:[D1("div",{className:`markdown light prose w-full break-words dark:prose-invert first:mt-0 ${Z.align==="right"?"flex justify-end self-end":""}`,children:typeof Z.content==="string"?Z.parseMode.toLowerCase()==="markdown"?D1($X,{children:Z.content},Date.now()+Math.random()):Z.parseMode.toLowerCase()==="html"?I6(Z.content):Z.content:D1(Z1,{uiConfig:Z.content,setUiAjaxConfiguration:Y})}),D1("div",{className:"flex flex-row flex-wrap justify-start gap-1",children:Z.options.map((G,W)=>D1(N6,{onClickOption:J,option:G},W))})]}),Z.align==="right"&&D1("div",{className:"relative flex shrink-0 flex-col items-end",children:D1(Z7,{username:Z.username,avatar:Z.avatar})})]})})},qX=_F;import{forwardRef as vF,useEffect as kF,useImperativeHandle as hF,useRef as bF,useState as gF}from"react";import{jsx as DX}from"react/jsx-runtime";var yF=vF(({name:Z,handleOptionClick:J,defaultMessages:Y,sx:Q,setUiAjaxConfiguration:X},G)=>{let[W,H]=gF(Y),z=bF(null),U=()=>{if(z.current)z.current.scrollTop=z.current.scrollHeight};return kF(()=>{U()},[W]),hF(G,()=>({setMessages:(B)=>H(B),addMessage:(B)=>H((L)=>[...L,B]),scrollToBottom:U})),DX("div",{id:Z+"_messages",className:"flex flex-col items-center overflow-y-scroll",style:Q,ref:z,children:W.map((B)=>DX(qX,{message:B,handleOptionClick:J,setUiAjaxConfiguration:X},B.id))})}),NX=yF;import{useEffect as mF,useRef as AX,useState as uF}from"react";import{jsx as J7,jsxs as cF}from"react/jsx-runtime";var dF=({data:Z,setUiAjaxConfiguration:J})=>{let{name:Y,defaultValue:Q,defaultMessages:X,defaultOptions:G,isArea:W,fileAccept:H,placeholder:z,icons:U,optionsPosition:B,sxMap:L={container:{},chatInput:{},messages:{}},depsNames:V,pathname:M,kwargs:K,useSocketioSupport:F,useCentrifugeSupport:O,centrifugeChannel:D}=Z,P=AX(null),N=AX(null),[q,T]=uF(!1),C=B6(J,K,V,M);mF(()=>{if(q)requestAnimationFrame(()=>{C(),T(!1)})},[q]);let m=(c)=>{if(P.current)P.current.setValue(c),T(!0)},i1=()=>{if(P.current)P.current.clear()},x1=(c)=>{if(P.current)P.current.setOptions(c.options)},C1=(c)=>{if(N.current)N.current.addMessage(c.message)},v=(c)=>{if(N.current)N.current.setMessages(c.messages)},N1=()=>{T(!0)};return J7(F1,{card:"ChatCard",data:Z,methods:{clearInput:i1,setOptions:x1,addMessage:C1,setMessages:v},useSocketioSupport:F,useCentrifugeSupport:O,centrifugeChannel:D,children:cF("div",{className:"flex size-full flex-col",style:L.container,children:[J7(NX,{ref:N,name:Y,defaultMessages:X,sx:L.messages,handleOptionClick:m,setUiAjaxConfiguration:J}),J7(FX,{ref:P,name:Y,isArea:W,defaultOptions:G,placeholder:z,defaultValue:Q,fileAccept:H,sx:L.chatInput,handleSendMessage:N1,handleOptionClick:m,optionsPosition:B,icons:U})]})})},RX=dF;var Y7=!1;function z5(){if(Y7)return;n1({name:"SequenceCard",component:bQ,metadata:{author:"PieData",description:"Simple div with styles joining few components"}}),n1({name:"UnionCard",component:yQ,metadata:{author:"PieData",description:"Renders one of many components"}}),n1({name:"AjaxGroupCard",component:cQ,metadata:{author:"PieData",description:"Group card with AJAX support"}}),n1({name:"AjaxButtonCard",component:s3,metadata:{author:"PieData",description:"Button with AJAX support"}}),n1({name:"ChatCard",component:RX,metadata:{author:"PieData"}}),Y7=!0}function S1(){return Y7}import{jsx as z1,Fragment as rF}from"react/jsx-runtime";var aF=({location:Z,fallback:J,onError:Y,initializePie:Q})=>{let X=v1(),G=B5(),W=k1();pF(()=>{if(S1())return;z5(),Q()},[]);let H=lF(()=>PX.createAxiosDateTransformer({baseURL:X||""}),[X]),{data:z,isLoading:U,error:B}=oF({queryKey:["uiConfig",Z.pathname+Z.search,S1(),X],queryFn:async()=>{if(!X||!S1())return;let L="/api/content"+Z.pathname+Z.search;if(W)console.log("[PieRoot] Fetching UI configuration from:",L);let V=await H.get(L,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(W)console.log("[PieRoot] Received UI configuration:",V.data);return V.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(L)=>Math.min(1000*2**L,30000)});if(!X)return J??null;if(W)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] Fallback provided:",!!J);if(B){if(W)console.error("[PieRoot] Error fetching UI configuration:",B),console.error("[PieRoot] Error details:",{message:B.message,status:B.response?.status,data:B.response?.data});return Y?.(),J}if(U||!z){if(W)console.log("[PieRoot] Loading state:",{isLoading:U,hasUiConfiguration:!!z});return J}if(W)console.log("[PieRoot] UI configuration loaded successfully:",z),console.log("[PieRoot] Rendering UI with configuration");return z1(y1.Provider,{value:f0,children:z1(u1.Provider,{value:g5(X),children:z1(c1.Provider,{value:l5(X,G),children:z1(_1.Provider,{value:J??z1(rF,{}),children:z1(n5,{children:z1(o5,{children:z1(H1.StyleRoot,{children:z1(Z1,{uiConfig:z})})})})})})})})},sF=(Z)=>{let J=new iF;return z1(P0.Provider,{value:Z.config,children:z1(nF,{client:J,children:z1(aF,{...Z})})})},tF=sF;import{useEffect as J$,useMemo as Y$}from"react";import{QueryClient as Q$,QueryClientProvider as X$,useQuery as G$}from"@tanstack/react-query";var wX=S(P9(),1);import{useEffect as eF,useState as Z$}from"react";var TX=()=>{let[Z,J]=Z$(null),Y=L7();return eF(()=>{if(typeof window>"u")return;let Q=window.Telegram.WebApp;if(Q.ready(),Y==="telegram_expanded"&&(Q.platform==="ios"||Q.platform==="android"))Q.expand();J(Q)},[]),Z};import{jsx as U1,Fragment as z$}from"react/jsx-runtime";var W$=({location:Z,fallback:J,onError:Y,initializePie:Q})=>{let X=v1(),G=B5(),W=k1();J$(()=>{if(S1())return;z5(),Q()},[]);let H=Y$(()=>wX.createAxiosDateTransformer({baseURL:X}),[]);if(W)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] Fallback provided:",!!J);if(!X)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");let z=TX(),{data:U,isLoading:B,error:L}=G$({queryKey:["uiConfig",Z.pathname+Z.search,z?.initData,S1()],queryFn:async()=>{if(!S1())return;let V=Z.search?"&":"?",M=z?.initData?`${V}initData=${encodeURIComponent(z.initData)}`:"",K="/api/content"+Z.pathname+Z.search+M;if(W)console.log("[PieRoot] Fetching UI configuration from:",K);let F=await H.get(K,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(W)console.log("[PieRoot] Received UI configuration:",F.data);return F.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(V)=>Math.min(1000*2**V,30000)});if(L&&W)return console.error("[PieRoot] Error fetching UI configuration:",L),console.error("[PieRoot] Error details:",{message:L.message,status:L.response?.status,data:L.response?.data}),Y?.(),J;if(B||!U){if(W)console.log("[PieRoot] Loading state:",{isLoading:B,hasUiConfiguration:!!U});return J}if(W)console.log("[PieRoot] UI configuration loaded successfully:",U),console.log("[PieRoot] Rendering UI with configuration");return U1(y1.Provider,{value:f0,children:U1(u1.Provider,{value:g5(X),children:U1(c1.Provider,{value:l5(X,G),children:U1(_1.Provider,{value:J??U1(z$,{}),children:U1(n5,{children:U1(o5,{children:U1(H1.StyleRoot,{children:U1(Z1,{uiConfig:U})})})})})})})})},H$=(Z)=>{let J=new Q$;return U1(P0.Provider,{value:Z.config,children:U1(X$,{client:J,children:U1(W$,{...Z})})})},U$=H$;export{n1 as registerPieComponent,S1 as isPieComponentsInitialized,z5 as initializePieComponents,Z1 as UI,U$ as PieTelegramRoot,tF as PieRoot,F1 as PieCard};
28
+ `);O=N.pop()??"";for(let q of N){let T=q.trim();if(!T)continue;try{let C=JSON.parse(T);Z([C])}catch(C){if(G)console.warn("Failed to parse streamed line:",T)}}}if(O.trim())try{let D=JSON.parse(O);Z([D])}catch(D){if(G)console.warn("Failed to parse final streamed line:",O)}return{}}else{let K=await B.json();return Z(K),K}}).catch((B)=>{if(G)console.error("AJAX request failed:",B);return Z(null),B})}},B6=(Z,J={},Y=[],Q)=>{let{apiServer:X,enableRenderingLog:G}=H0();return YM(()=>QM(Z,J,Y,Q,{apiServer:X,renderingLogEnabled:G}),[Z,J,Y,Q,X,G])};var a9=S(o9(),1),G0=S(o9(),1),I6=a9.default.default||a9.default;import{jsx as s9,jsxs as e2}from"react/jsx-runtime";var t2=({data:Z,setUiAjaxConfiguration:J})=>{let{name:Y,title:Q,iconUrl:X,iconPosition:G,sx:W,pathname:H,kwargs:z,depsNames:U}=Z,B=B6(J,z,U,H);return s9(F1,{card:"AjaxButtonCard",data:Z,children:e2("button",{id:Y,className:"box-border flex min-h-12 w-full min-w-min cursor-pointer items-center justify-center rounded-[16px] border border-[#080318] bg-white text-center font-[TTForsTrial] text-[#080318] hover:bg-neutral-300",value:Y,onClick:()=>B(),style:U6(W),type:"button",children:[X&&G==="start"&&s9("img",{src:X,alt:""}),I6(Q),X&&G==="end"&&s9("img",{src:X,alt:""})]})})},s3=H1(t2);import{forwardRef as NF,useEffect as LX,useImperativeHandle as AF,useRef as RF,useState as A6}from"react";import{useRef as ZF,useState as JF}from"react";import{jsx as YF}from"react/jsx-runtime";function r9(Z){let[J,Y]=JF(!1),Q=ZF(null);return YF("textarea",{ref:Q,...Z,onKeyUp:()=>{Y(!1)},onKeyDown:(H)=>{if(H.key==="Enter"&&H.shiftKey){if(Y(!0),Q.current&&typeof window<"u"){let z=window.getComputedStyle(Q.current),U=parseFloat(z.lineHeight);Q.current.style.height=Q.current.scrollHeight+U+"px"}}if(H.key==="Backspace"){if(Y(!0),Q.current&&typeof window<"u"){let z=window.getComputedStyle(Q.current),U=parseFloat(z.lineHeight);if(Q.current.scrollHeight>U)Q.current.style.height=Q.current.scrollHeight-U+"px"}}Z.onKeyDown&&Z.onKeyDown(H)},onBlur:(H)=>{Y(!1),Z.onBlur&&Z.onBlur(H)},style:{resize:J?"vertical":"none",overflowY:"auto",...Z.style}})}import{useRef as XF,useCallback as GF}from"react";import{jsx as r3}from"react/jsx-runtime";var QF=()=>r3("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:r3("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})}),t3=QF;import{jsx as t9}from"react/jsx-runtime";var WF=({type:Z="button",onClick:J,icons:Y})=>{let Q=XF(null),X=GF(()=>{let W=Q.current;if(W)W.style.transform="scale(0.8)",setTimeout(()=>{W.style.transform="scale(1)"},600)},[]);return t9("button",{ref:Q,type:Z,onClick:(W)=>{if(J)J(W);X()},className:"mr-1.5 rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",style:{transition:"transform 300ms ease"},children:Y.sendIcon?t9("img",{src:Y.sendIcon,alt:""}):t9(t3,{})})},e3=WF;import{jsx as ZX}from"react/jsx-runtime";var HF=()=>ZX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:ZX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"})}),JX=HF;import{jsx as q6,jsxs as BF,Fragment as UF}from"react/jsx-runtime";var zF=({name:Z,accept:J,fileInputRef:Y,onSelectFile:Q,icons:X})=>{return BF(UF,{children:[q6("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:()=>{if(Y.current)Y.current.click()},children:X.attachFileIcon?q6("img",{src:X.attachFileIcon,alt:""}):q6(JX,{})}),q6("input",{id:Z+"__pie__file",name:Z+"__pie__file",className:"hidden",type:"file",accept:J,ref:Y,onChange:(G)=>{if(G.target.files)Q(G.target.files[0])}})]})},YX=zF;import{jsx as QX}from"react/jsx-runtime";var KF=()=>QX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5 text-gray-500",children:QX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),XX=KF;import{jsx as GX}from"react/jsx-runtime";var LF=()=>GX("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:GX("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),D6=LF;import{jsx as W5,jsxs as FF}from"react/jsx-runtime";var MF=({name:Z,selectedFile:J,onDropFile:Y})=>{return FF("div",{className:"flex w-full cursor-default flex-row items-center gap-2",children:[W5(XX,{}),W5("span",{className:"flex-1",children:J.name}),W5("input",{type:"hidden",name:Z,value:""}),W5("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:Y,children:W5(D6,{})})]})},WX=MF;import{jsx as HX,jsxs as OF}from"react/jsx-runtime";var $F=()=>OF("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:[HX("path",{d:"M8 5C8 2.79086 9.79086 1 12 1C14.2091 1 16 2.79086 16 5V12C16 14.2091 14.2091 16 12 16C9.79086 16 8 14.2091 8 12V5Z"}),HX("path",{d:"M6.25 11.8438V12C6.25 13.525 6.8558 14.9875 7.93414 16.0659C9.01247 17.1442 10.475 17.75 12 17.75C13.525 17.75 14.9875 17.1442 16.0659 16.0659C17.1442 14.9875 17.75 13.525 17.75 12V11.8438C17.75 11.2915 18.1977 10.8438 18.75 10.8438H19.25C19.8023 10.8438 20.25 11.2915 20.25 11.8437V12C20.25 14.188 19.3808 16.2865 17.8336 17.8336C16.5842 19.0831 14.9753 19.8903 13.25 20.1548V22C13.25 22.5523 12.8023 23 12.25 23H11.75C11.1977 23 10.75 22.5523 10.75 22V20.1548C9.02471 19.8903 7.41579 19.0831 6.16637 17.8336C4.61919 16.2865 3.75 14.188 3.75 12V11.8438C3.75 11.2915 4.19772 10.8438 4.75 10.8438H5.25C5.80228 10.8438 6.25 11.2915 6.25 11.8438Z"})]}),zX=$F;import{jsx as H5}from"react/jsx-runtime";var VF=({isListening:Z,toggleListening:J,icons:Y})=>{return H5("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:J,children:Z?Y.cancelIcon?H5("img",{src:Y.cancelIcon,alt:""}):H5(D6,{}):Y.voiceRecordingIcon?H5("img",{src:Y.voiceRecordingIcon,alt:""}):H5(zX,{})})},UX=VF;import{jsx as BX,jsxs as qF}from"react/jsx-runtime";var IF=({option:Z,onClickOption:J})=>{return qF("div",{className:"flex w-fit cursor-pointer flex-row place-content-center items-center gap-1 rounded-md border border-black bg-white px-2 py-1 text-black",onClick:()=>{J(Z.title)},style:Z.sx,children:[Z.iconPosition==="start"&&BX("img",{src:Z.iconUrl,alt:""}),Z.title,Z.iconPosition==="end"&&BX("img",{src:Z.iconUrl,alt:""})]})},N6=IF;import{jsx as KX}from"react/jsx-runtime";var DF=({options:Z,handleOptionClick:J})=>{return KX("div",{className:"flex w-full flex-row flex-wrap justify-start gap-[5px]",children:Z.map((Y,Q)=>{return KX(N6,{option:Y,onClickOption:J},Q)})})},e9=DF;import{jsx as E1,jsxs as MX}from"react/jsx-runtime";var PF=NF(({name:Z,defaultValue:J,defaultOptions:Y,isArea:Q,placeholder:X,fileAccept:G,optionsPosition:W,icons:H,handleOptionClick:z,handleSendMessage:U,sx:B},L)=>{let V=RF(null),[M,K]=A6(null),[F,O]=A6(J),[D,P]=A6(Y),[N,q]=A6(!1);AF(L,()=>({clear:()=>{if(O(""),K(null),V.current)V.current.value=""},setValue:(C)=>O(C),setOptions:(C)=>P(C)})),LX(()=>{O(J)},[J]),LX(()=>{},[]);let T=()=>{};return MX("div",{className:"flex flex-col items-center gap-[0.1rem]",id:Z+"_chat_input",style:B,children:[D&&W==="top"&&E1(e9,{options:D,handleOptionClick:z}),E1("div",{className:"stretch relative flex size-full flex-1 flex-row items-stretch gap-3 last:mb-2 md:mx-4 md:flex-col md:last:mb-6 lg:mx-auto",children:MX("div",{className:"flex w-full grow flex-row items-center rounded-md bg-transparent",children:[M?E1(WX,{name:Z,selectedFile:M,onDropFile:()=>{if(K(null),V.current)V.current.value=""}}):!Q?E1("input",{name:Z,value:F,onChange:(C)=>O(C.target.value),onKeyDown:(C)=>{if(C.key==="Enter")C.preventDefault(),U()},tabIndex:0,placeholder:X,className:"m-0 w-full resize-none border-0 bg-transparent outline-none",style:{maxHeight:200,height:"100%",overflowY:"hidden"}}):E1(r9,{name:Z,value:F,onChange:(C)=>O(C.target.value),onKeyDown:(C)=>{if(C.key==="Enter"&&!C.shiftKey)C.preventDefault(),U()},tabIndex:0,rows:2,placeholder:X,className:"m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 outline-none md:pl-0",style:{maxHeight:200,height:"100%",minHeight:24}}),E1(UX,{isListening:N,toggleListening:T,icons:H}),E1(YX,{name:Z,fileInputRef:V,accept:G,onSelectFile:K,icons:H}),E1(e3,{onClick:U,icons:H})]})}),D&&W==="bottom"&&E1(e9,{options:D,handleOptionClick:z})]})}),FX=PF;import{useState as fF,useEffect as jF}from"react";import{useEffect as TF,useState as wF}from"react";import{jsx as SF}from"react/jsx-runtime";function EF({children:Z}){let[J,Y]=wF(Z);return TF(()=>{Y(Z)},[Z]),SF("div",{className:"max-w-full first:mt-0",children:J})}var $X=EF;import{jsx as OX}from"react/jsx-runtime";var xF=()=>OX("svg",{width:"30",height:"30",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:OX("path",{d:"m 8 1 c -1.65625 0 -3 1.34375 -3 3 s 1.34375 3 3 3 s 3 -1.34375 3 -3 s -1.34375 -3 -3 -3 z m -1.5 7 c -2.492188 0 -4.5 2.007812 -4.5 4.5 v 0.5 c 0 1.109375 0.890625 2 2 2 h 8 c 1.109375 0 2 -0.890625 2 -2 v -0.5 c 0 -2.492188 -2.007812 -4.5 -4.5 -4.5 z m 0 0",fill:"#2e3436"})}),VX=xF;import{jsx as R6}from"react/jsx-runtime";function CF({username:Z,avatar:J}){return R6("div",{className:"w-[30px]",children:R6("div",{className:"relative flex size-[30px] items-center justify-center rounded-sm p-1 text-white",children:J?R6("img",{src:J,className:"absolute inset-0 rounded",alt:Z}):R6(VX,{})})})}var Z7=CF;import{jsx as D1,jsxs as IX}from"react/jsx-runtime";var _F=({message:Z,handleOptionClick:J,setUiAjaxConfiguration:Y})=>{let[Q,X]=fF(!1);return jF(()=>{let G=setTimeout(()=>{if(Q)X(!1)},1000);return()=>clearTimeout(G)},[Q]),D1("div",{className:"group w-full border-b border-black/10",id:Z.id,children:IX("div",{className:`flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-3xl xl:max-w-5xl ${Z.align==="center"?"m-auto":""} ${Z.align==="right"?"ml-auto justify-end":""} ${Z.align==="left"?"mr-auto":""} `,children:[(Z.align==="left"||Z.align==="center")&&D1("div",{className:"relative flex shrink-0 flex-col items-end",children:D1(Z7,{username:Z.username,avatar:Z.avatar})}),IX("div",{className:"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]",children:[D1("div",{className:`markdown light prose w-full break-words dark:prose-invert first:mt-0 ${Z.align==="right"?"flex justify-end self-end":""}`,children:typeof Z.content==="string"?Z.parseMode.toLowerCase()==="markdown"?D1($X,{children:Z.content},Date.now()+Math.random()):Z.parseMode.toLowerCase()==="html"?I6(Z.content):Z.content:D1(Z1,{uiConfig:Z.content,setUiAjaxConfiguration:Y})}),D1("div",{className:"flex flex-row flex-wrap justify-start gap-1",children:Z.options.map((G,W)=>D1(N6,{onClickOption:J,option:G},W))})]}),Z.align==="right"&&D1("div",{className:"relative flex shrink-0 flex-col items-end",children:D1(Z7,{username:Z.username,avatar:Z.avatar})})]})})},qX=_F;import{forwardRef as vF,useEffect as kF,useImperativeHandle as hF,useRef as bF,useState as gF}from"react";import{jsx as DX}from"react/jsx-runtime";var yF=vF(({name:Z,handleOptionClick:J,defaultMessages:Y,sx:Q,setUiAjaxConfiguration:X},G)=>{let[W,H]=gF(Y),z=bF(null),U=()=>{if(z.current)z.current.scrollTop=z.current.scrollHeight};return kF(()=>{U()},[W]),hF(G,()=>({setMessages:(B)=>H(B),addMessage:(B)=>H((L)=>[...L,B]),scrollToBottom:U})),DX("div",{id:Z+"_messages",className:"flex flex-col items-center overflow-y-scroll",style:Q,ref:z,children:W.map((B)=>DX(qX,{message:B,handleOptionClick:J,setUiAjaxConfiguration:X},B.id))})}),NX=yF;import{useEffect as mF,useRef as AX,useState as uF}from"react";import{jsx as J7,jsxs as cF}from"react/jsx-runtime";var dF=({data:Z,setUiAjaxConfiguration:J})=>{let{name:Y,defaultValue:Q,defaultMessages:X,defaultOptions:G,isArea:W,fileAccept:H,placeholder:z,icons:U,optionsPosition:B,sxMap:L={container:{},chatInput:{},messages:{}},depsNames:V,pathname:M,kwargs:K,useSocketioSupport:F,useCentrifugeSupport:O,centrifugeChannel:D}=Z,P=AX(null),N=AX(null),[q,T]=uF(!1),C=B6(J,K,V,M);mF(()=>{if(q)requestAnimationFrame(()=>{C(),T(!1)})},[q]);let m=(c)=>{if(P.current)P.current.setValue(c),T(!0)},i1=()=>{if(P.current)P.current.clear()},x1=(c)=>{if(P.current)P.current.setOptions(c.options)},C1=(c)=>{if(N.current)N.current.addMessage(c.message)},v=(c)=>{if(N.current)N.current.setMessages(c.messages)},N1=()=>{T(!0)};return J7(F1,{card:"ChatCard",data:Z,methods:{clearInput:i1,setOptions:x1,addMessage:C1,setMessages:v},useSocketioSupport:F,useCentrifugeSupport:O,centrifugeChannel:D,children:cF("div",{className:"flex size-full flex-col",style:L.container,children:[J7(NX,{ref:N,name:Y,defaultMessages:X,sx:L.messages,handleOptionClick:m,setUiAjaxConfiguration:J}),J7(FX,{ref:P,name:Y,isArea:W,defaultOptions:G,placeholder:z,defaultValue:Q,fileAccept:H,sx:L.chatInput,handleSendMessage:N1,handleOptionClick:m,optionsPosition:B,icons:U})]})})},RX=dF;var Y7=!1;function z5(){if(Y7)return;n1({name:"SequenceCard",component:bQ,metadata:{author:"PieData",description:"Simple div with styles joining few components"}}),n1({name:"UnionCard",component:yQ,metadata:{author:"PieData",description:"Renders one of many components"}}),n1({name:"AjaxGroupCard",component:cQ,metadata:{author:"PieData",description:"Group card with AJAX support"}}),n1({name:"AjaxButtonCard",component:s3,metadata:{author:"PieData",description:"Button with AJAX support"}}),n1({name:"ChatCard",component:RX,metadata:{author:"PieData"}}),Y7=!0}function S1(){return Y7}import{jsx as z1,Fragment as rF}from"react/jsx-runtime";var aF=({location:Z,fallback:J,onError:Y,initializePie:Q})=>{let X=v1(),G=B5(),W=k1();pF(()=>{if(S1())return;z5(),Q()},[]);let H=lF(()=>PX.createAxiosDateTransformer({baseURL:X||""}),[X]),{data:z,isLoading:U,error:B}=oF({queryKey:["uiConfig",Z.pathname+Z.search,S1(),X],queryFn:async()=>{if(!X||!S1())return;let L="/api/content"+Z.pathname+Z.search;if(W)console.log("[PieRoot] Fetching UI configuration from:",L);let V=await H.get(L,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(W)console.log("[PieRoot] Received UI configuration:",V.data);return V.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(L)=>Math.min(1000*2**L,30000)});if(!X)return J??null;if(W)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] Fallback provided:",!!J);if(B){if(W)console.error("[PieRoot] Error fetching UI configuration:",B),console.error("[PieRoot] Error details:",{message:B.message,status:B.response?.status,data:B.response?.data});return Y?.(),J}if(U||!z){if(W)console.log("[PieRoot] Loading state:",{isLoading:U,hasUiConfiguration:!!z});return J}if(W)console.log("[PieRoot] UI configuration loaded successfully:",z),console.log("[PieRoot] Rendering UI with configuration");return z1(y1.Provider,{value:f0,children:z1(u1.Provider,{value:g5(X),children:z1(c1.Provider,{value:l5(X,G),children:z1(_1.Provider,{value:J??z1(rF,{}),children:z1(n5,{children:z1(o5,{children:z1(H1.StyleRoot,{style:{display:"contents"},children:z1(Z1,{uiConfig:z})})})})})})})})},sF=(Z)=>{let J=new iF;return z1(P0.Provider,{value:Z.config,children:z1(nF,{client:J,children:z1(aF,{...Z})})})},tF=sF;import{useEffect as J$,useMemo as Y$}from"react";import{QueryClient as Q$,QueryClientProvider as X$,useQuery as G$}from"@tanstack/react-query";var wX=S(P9(),1);import{useEffect as eF,useState as Z$}from"react";var TX=()=>{let[Z,J]=Z$(null),Y=L7();return eF(()=>{if(typeof window>"u")return;let Q=window.Telegram.WebApp;if(Q.ready(),Y==="telegram_expanded"&&(Q.platform==="ios"||Q.platform==="android"))Q.expand();J(Q)},[]),Z};import{jsx as U1,Fragment as z$}from"react/jsx-runtime";var W$=({location:Z,fallback:J,onError:Y,initializePie:Q})=>{let X=v1(),G=B5(),W=k1();J$(()=>{if(S1())return;z5(),Q()},[]);let H=Y$(()=>wX.createAxiosDateTransformer({baseURL:X}),[]);if(W)console.log("[PieRoot] Rendering with location:",Z),console.log("[PieRoot] API_SERVER:",X),console.log("[PieRoot] Fallback provided:",!!J);if(!X)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");let z=TX(),{data:U,isLoading:B,error:L}=G$({queryKey:["uiConfig",Z.pathname+Z.search,z?.initData,S1()],queryFn:async()=>{if(!S1())return;let V=Z.search?"&":"?",M=z?.initData?`${V}initData=${encodeURIComponent(z.initData)}`:"",K="/api/content"+Z.pathname+Z.search+M;if(W)console.log("[PieRoot] Fetching UI configuration from:",K);let F=await H.get(K,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(W)console.log("[PieRoot] Received UI configuration:",F.data);return F.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(V)=>Math.min(1000*2**V,30000)});if(L&&W)return console.error("[PieRoot] Error fetching UI configuration:",L),console.error("[PieRoot] Error details:",{message:L.message,status:L.response?.status,data:L.response?.data}),Y?.(),J;if(B||!U){if(W)console.log("[PieRoot] Loading state:",{isLoading:B,hasUiConfiguration:!!U});return J}if(W)console.log("[PieRoot] UI configuration loaded successfully:",U),console.log("[PieRoot] Rendering UI with configuration");return U1(y1.Provider,{value:f0,children:U1(u1.Provider,{value:g5(X),children:U1(c1.Provider,{value:l5(X,G),children:U1(_1.Provider,{value:J??U1(z$,{}),children:U1(n5,{children:U1(o5,{children:U1(H1.StyleRoot,{children:U1(Z1,{uiConfig:U})})})})})})})})},H$=(Z)=>{let J=new Q$;return U1(P0.Provider,{value:Z.config,children:U1(X$,{client:J,children:U1(W$,{...Z})})})},U$=H$;export{n1 as registerPieComponent,S1 as isPieComponentsInitialized,z5 as initializePieComponents,Z1 as UI,U$ as PieTelegramRoot,tF as PieRoot,F1 as PieCard};
package/dist/index.js CHANGED
@@ -49,4 +49,4 @@ var pm=Object.create;var{getPrototypeOf:Km,defineProperty:t1,getOwnPropertyNames
49
49
  `)throw Error("size integer not terminated by '\\n'");let Y=new xX;while(v.haveBytes()){let G=v.getInt(),X;switch(v.getChar()){case"@":if(X=v.getInt(),v.haveBytes()&&v.getChar()!==",")throw Error("copy command not terminated by ','");if(x+=G,x>J)throw Error("copy exceeds output file size");if(X+G>z)throw Error("copy extends past end of input");Y.putArray(i,X,X+G);break;case":":if(x+=G,x>J)throw Error("insert command gives an output larger than predicted");if(G>Z)throw Error("insert count exceeds size of delta");Y.putArray(v.a,v.pos,v.pos+G),v.pos+=G;break;case";":{let Q=Y.toByteArray(i);if(G!==Hq(Q))throw Error("bad checksum");if(x!==J)throw Error("generated size does not match predicted size");return Q}default:throw Error("unknown delta operator")}}throw Error("unterminated delta")}class p4{name(){return"json"}encodeCommands(i){return i.map((c)=>JSON.stringify(c)).join(`
50
50
  `)}decodeReplies(i){return i.trim().split(`
51
51
  `).map((c)=>JSON.parse(c))}applyDeltaIfNeeded(i,c){let x,v;if(i.delta){let z=Uq(c,new TextEncoder().encode(i.data));x=JSON.parse(new TextDecoder().decode(z)),v=z}else x=JSON.parse(i.data),v=new TextEncoder().encode(i.data);return{newData:x,newPrevValue:v}}}var Vq={headers:{},token:"",getToken:null,data:null,getData:null,debug:!1,name:"js",version:"",fetch:null,readableStream:null,websocket:null,eventsource:null,sockjs:null,sockjsOptions:{},emulationEndpoint:"/emulation",minReconnectDelay:500,maxReconnectDelay:20000,timeout:5000,maxServerPingDelay:1e4,networkEventTarget:null};class uc extends Error{constructor(i){super(i);this.name=this.constructor.name}}class Cx extends dG{constructor(i,c){super();if(this._reconnectTimeout=null,this._refreshTimeout=null,this._serverPingTimeout=null,this.state=Xi.Disconnected,this._transportIsOpen=!1,this._endpoint=i,this._emulation=!1,this._transports=[],this._currentTransportIndex=0,this._triedAllTransports=!1,this._transportWasOpen=!1,this._transport=null,this._transportId=0,this._deviceWentOffline=!1,this._transportClosed=!0,this._codec=new p4,this._reconnecting=!1,this._reconnectTimeout=null,this._reconnectAttempts=0,this._client=null,this._session="",this._node="",this._subs={},this._serverSubs={},this._commandId=0,this._commands=[],this._batching=!1,this._refreshRequired=!1,this._refreshTimeout=null,this._callbacks={},this._token="",this._data=null,this._dispatchPromise=Promise.resolve(),this._serverPing=0,this._serverPingTimeout=null,this._sendPong=!1,this._promises={},this._promiseId=0,this._debugEnabled=!1,this._networkEventsSet=!1,this._config=Object.assign(Object.assign({},Vq),c),this._configure(),this._debugEnabled)this.on("state",(x)=>{this._debug("client state",x.oldState,"->",x.newState)}),this.on("error",(x)=>{this._debug("client error",x)});else this.on("error",function(){Function.prototype()})}newSubscription(i,c){if(this.getSubscription(i)!==null)throw Error("Subscription to the channel "+i+" already exists");let x=new oG(this,i,c);return this._subs[i]=x,x}getSubscription(i){return this._getSub(i)}removeSubscription(i){if(!i)return;if(i.state!==ji.Unsubscribed)i.unsubscribe();this._removeSubscription(i)}subscriptions(){return this._subs}ready(i){return ni(this,void 0,void 0,function*(){switch(this.state){case Xi.Disconnected:throw{code:t.clientDisconnected,message:"client disconnected"};case Xi.Connected:return;default:return new Promise((c,x)=>{let v={resolve:c,reject:x};if(i)v.timeout=setTimeout(()=>{x({code:t.timeout,message:"timeout"})},i);this._promises[this._nextPromiseId()]=v})}})}connect(){if(this._isConnected()){this._debug("connect called when already connected");return}if(this._isConnecting()){this._debug("connect called when already connecting");return}this._debug("connect called"),this._reconnectAttempts=0,this._startConnecting()}disconnect(){this._disconnect(u0.disconnectCalled,"disconnect called",!1)}setToken(i){this._token=i}setData(i){this._data=i}setHeaders(i){this._config.headers=i}send(i){return ni(this,void 0,void 0,function*(){let c={send:{data:i}};if(yield this._methodCall(),!this._transportSendCommands([c]))throw this._createErrorObject(t.transportWriteError,"transport write error")})}rpc(i,c){return ni(this,void 0,void 0,function*(){let x={rpc:{method:i,data:c}};return yield this._methodCall(),{data:(yield this._callPromise(x,(z)=>z.rpc)).data}})}publish(i,c){return ni(this,void 0,void 0,function*(){let x={publish:{channel:i,data:c}};return yield this._methodCall(),yield this._callPromise(x,()=>({})),{}})}history(i,c){return ni(this,void 0,void 0,function*(){let x={history:this._getHistoryRequest(i,c)};yield this._methodCall();let v=yield this._callPromise(x,(Z)=>Z.history),z=[];if(v.publications)for(let Z=0;Z<v.publications.length;Z++)z.push(this._getPublicationContext(i,v.publications[Z]));return{publications:z,epoch:v.epoch||"",offset:v.offset||0}})}presence(i){return ni(this,void 0,void 0,function*(){let c={presence:{channel:i}};yield this._methodCall();let v=(yield this._callPromise(c,(z)=>z.presence)).presence;for(let z in v)if(Object.prototype.hasOwnProperty.call(v,z)){let Z=v[z],J=Z.conn_info,Y=Z.chan_info;if(J)Z.connInfo=J;if(Y)Z.chanInfo=Y}return{clients:v}})}presenceStats(i){return ni(this,void 0,void 0,function*(){let c={presence_stats:{channel:i}};yield this._methodCall();let x=yield this._callPromise(c,(v)=>{return v.presence_stats});return{numUsers:x.num_users,numClients:x.num_clients}})}startBatching(){this._batching=!0}stopBatching(){let i=this;Promise.resolve().then(function(){Promise.resolve().then(function(){i._batching=!1,i._flush()})})}_debug(...i){if(!this._debugEnabled)return;pq("debug",i)}_codecName(){return this._codec.name()}_formatOverride(){return}_configure(){if(!("Promise"in globalThis))throw Error("Promise polyfill required");if(!this._endpoint)throw Error("endpoint configuration required");if(this._config.token!==null)this._token=this._config.token;if(this._config.data!==null)this._data=this._config.data;if(this._codec=new p4,this._formatOverride(),this._config.debug===!0||typeof localStorage<"u"&&typeof localStorage.getItem==="function"&&localStorage.getItem("centrifuge.debug"))this._debugEnabled=!0;if(this._debug("config",this._config),typeof this._endpoint==="string");else if(Array.isArray(this._endpoint)){this._transports=this._endpoint,this._emulation=!0;for(let i in this._transports)if(this._transports.hasOwnProperty(i)){let c=this._transports[i];if(!c.endpoint||!c.transport)throw Error("malformed transport configuration");let x=c.transport;if(["websocket","http_stream","sse","sockjs","webtransport"].indexOf(x)<0)throw Error("unsupported transport name: "+x)}}else throw Error("unsupported url configuration type: only string or array of objects are supported")}_setState(i){if(this.state!==i){this._reconnecting=!1;let c=this.state;return this.state=i,this.emit("state",{newState:i,oldState:c}),!0}return!1}_isDisconnected(){return this.state===Xi.Disconnected}_isConnecting(){return this.state===Xi.Connecting}_isConnected(){return this.state===Xi.Connected}_nextCommandId(){return++this._commandId}_setNetworkEvents(){if(this._networkEventsSet)return;let i=null;if(this._config.networkEventTarget!==null)i=this._config.networkEventTarget;else if(typeof globalThis.addEventListener<"u")i=globalThis;if(i)i.addEventListener("offline",()=>{if(this._debug("offline event triggered"),this.state===Xi.Connected||this.state===Xi.Connecting)this._disconnect(Wx.transportClosed,"transport closed",!0),this._deviceWentOffline=!0}),i.addEventListener("online",()=>{if(this._debug("online event triggered"),this.state!==Xi.Connecting)return;if(this._deviceWentOffline&&!this._transportClosed)this._deviceWentOffline=!1,this._transportClosed=!0;this._clearReconnectTimeout(),this._startReconnecting()}),this._networkEventsSet=!0}_getReconnectDelay(){let i=Gv(this._reconnectAttempts,this._config.minReconnectDelay,this._config.maxReconnectDelay);return this._reconnectAttempts+=1,i}_clearOutgoingRequests(){for(let i in this._callbacks)if(this._callbacks.hasOwnProperty(i)){let c=this._callbacks[i];clearTimeout(c.timeout);let x=c.errback;if(!x)continue;x({error:this._createErrorObject(t.connectionClosed,"connection closed")})}this._callbacks={}}_clearConnectedState(){this._client=null,this._clearServerPingTimeout(),this._clearRefreshTimeout();for(let i in this._subs){if(!this._subs.hasOwnProperty(i))continue;let c=this._subs[i];if(c.state===ji.Subscribed)c._setSubscribing(Jv.transportClosed,"transport closed")}for(let i in this._serverSubs)if(this._serverSubs.hasOwnProperty(i))this.emit("subscribing",{channel:i})}_handleWriteError(i){for(let c of i){let x=c.id;if(!(x in this._callbacks))continue;let v=this._callbacks[x];clearTimeout(this._callbacks[x].timeout),delete this._callbacks[x];let z=v.errback;z({error:this._createErrorObject(t.transportWriteError,"transport write error")})}}_transportSendCommands(i){if(!i.length)return!0;if(!this._transport)return!1;try{this._transport.send(this._codec.encodeCommands(i),this._session,this._node)}catch(c){return this._debug("error writing commands",c),this._handleWriteError(i),!1}return!0}_initializeTransport(){let i;if(this._config.websocket!==null)i=this._config.websocket;else if(!(typeof globalThis.WebSocket!=="function"&&typeof globalThis.WebSocket!=="object"))i=globalThis.WebSocket;let c=null;if(this._config.sockjs!==null)c=this._config.sockjs;else if(typeof globalThis.SockJS<"u")c=globalThis.SockJS;let x=null;if(this._config.eventsource!==null)x=this._config.eventsource;else if(typeof globalThis.EventSource<"u")x=globalThis.EventSource;let v=null;if(this._config.fetch!==null)v=this._config.fetch;else if(typeof globalThis.fetch<"u")v=globalThis.fetch;let z=null;if(this._config.readableStream!==null)z=this._config.readableStream;else if(typeof globalThis.ReadableStream<"u")z=globalThis.ReadableStream;if(!this._emulation){if(Qq(this._endpoint,"http"))throw Error("Provide explicit transport endpoints configuration in case of using HTTP (i.e. using array of TransportEndpoint instead of a single string), or use ws(s):// scheme in an endpoint if you aimed using WebSocket transport");else if(this._debug("client will use websocket"),this._transport=new Q4(this._endpoint,{websocket:i}),!this._transport.supported())throw Error("WebSocket constructor not found, make sure it is available globally or passed as a dependency in Centrifuge options")}else{if(this._currentTransportIndex>=this._transports.length)this._triedAllTransports=!0,this._currentTransportIndex=0;let W=0;while(!0){if(W>=this._transports.length)throw Error("no supported transport found");let H=this._transports[this._currentTransportIndex],K=H.transport,m=H.endpoint;if(K==="websocket"){if(this._debug("trying websocket transport"),this._transport=new Q4(m,{websocket:i}),!this._transport.supported()){this._debug("websocket transport not available"),this._currentTransportIndex++,W++;continue}}else if(K==="webtransport"){if(this._debug("trying webtransport transport"),this._transport=new iX(m,{webtransport:globalThis.WebTransport,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("webtransport transport not available"),this._currentTransportIndex++,W++;continue}}else if(K==="http_stream"){if(this._debug("trying http_stream transport"),this._transport=new tG(m,{fetch:v,readableStream:z,emulationEndpoint:this._config.emulationEndpoint,decoder:this._codec,encoder:this._codec}),!this._transport.supported()){this._debug("http_stream transport not available"),this._currentTransportIndex++,W++;continue}}else if(K==="sse"){if(this._debug("trying sse transport"),this._transport=new eG(m,{eventsource:x,fetch:v,emulationEndpoint:this._config.emulationEndpoint}),!this._transport.supported()){this._debug("sse transport not available"),this._currentTransportIndex++,W++;continue}}else if(K==="sockjs"){if(this._debug("trying sockjs"),this._transport=new rG(m,{sockjs:c,sockjsOptions:this._config.sockjsOptions}),!this._transport.supported()){this._debug("sockjs transport not available"),this._currentTransportIndex++,W++;continue}}else throw Error("unknown transport "+K);break}}let Z=this,J=this._transport,Y=this._nextTransportId();Z._debug("id of transport",Y);let G=!1,X=[];if(this._transport.emulation()){let W=Z._sendConnect(!0);X.push(W)}this._setNetworkEvents();let Q=this._codec.encodeCommands(X);this._transportClosed=!1;let p;p=setTimeout(function(){J.close()},this._config.timeout),this._transport.initialize(this._codecName(),{onOpen:function(){if(p)clearTimeout(p),p=null;if(Z._transportId!=Y){Z._debug("open callback from non-actual transport"),J.close();return}if(G=!0,Z._debug(J.subName(),"transport open"),J.emulation())return;Z._transportIsOpen=!0,Z._transportWasOpen=!0,Z.startBatching(),Z._sendConnect(!1),Z._sendSubscribeCommands(),Z.stopBatching(),Z.emit("__centrifuge_debug:connect_frame_sent",{})},onError:function(W){if(Z._transportId!=Y){Z._debug("error callback from non-actual transport");return}Z._debug("transport level error",W)},onClose:function(W){if(p)clearTimeout(p),p=null;if(Z._transportId!=Y){Z._debug("close callback from non-actual transport");return}Z._debug(J.subName(),"transport closed"),Z._transportClosed=!0,Z._transportIsOpen=!1;let H="connection closed",K=!0,m=0;if(W&&"code"in W&&W.code)m=W.code;if(W&&W.reason)try{let U=JSON.parse(W.reason);H=U.reason,K=U.reconnect}catch(U){if(H=W.reason,m>=3500&&m<4000||m>=4500&&m<5000)K=!1}if(m<3000){if(m===1009)m=u0.messageSizeLimit,H="message size limit exceeded",K=!1;else m=Wx.transportClosed,H="transport closed";if(Z._emulation&&!Z._transportWasOpen){if(Z._currentTransportIndex++,Z._currentTransportIndex>=Z._transports.length)Z._triedAllTransports=!0,Z._currentTransportIndex=0}}else Z._transportWasOpen=!0;if(Z._isConnecting()&&!G)Z.emit("error",{type:"transport",error:{code:t.transportClosed,message:"transport closed"},transport:J.name()});Z._reconnecting=!1,Z._disconnect(m,H,K)},onMessage:function(W){Z._dataReceived(W)}},Q),Z.emit("__centrifuge_debug:transport_initialized",{})}_sendConnect(i){let c=this._constructConnectCommand(),x=this;return this._call(c,i).then((v)=>{let z=v.reply.connect;if(x._connectResponse(z),v.next)v.next()},(v)=>{if(x._connectError(v.error),v.next)v.next()}),c}_startReconnecting(){if(this._debug("start reconnecting"),!this._isConnecting()){this._debug("stop reconnecting: client not in connecting state");return}if(this._reconnecting){this._debug("reconnect already in progress, return from reconnect routine");return}if(this._transportClosed===!1){this._debug("waiting for transport close");return}this._reconnecting=!0;let i=this._token==="";if(!(this._refreshRequired||i&&this._config.getToken!==null)){if(this._config.getData)this._config.getData().then((v)=>{if(!this._isConnecting())return;this._data=v,this._initializeTransport()}).catch((v)=>this._handleGetDataError(v));else this._initializeTransport();return}let x=this;this._getToken().then(function(v){if(!x._isConnecting())return;if(v==null||v==null){x._failUnauthorized();return}if(x._token=v,x._debug("connection token refreshed"),x._config.getData)x._config.getData().then(function(z){if(!x._isConnecting())return;x._data=z,x._initializeTransport()}).catch((z)=>x._handleGetDataError(z));else x._initializeTransport()}).catch(function(v){if(!x._isConnecting())return;if(v instanceof uc){x._failUnauthorized();return}x.emit("error",{type:"connectToken",error:{code:t.clientConnectToken,message:v!==void 0?v.toString():""}});let z=x._getReconnectDelay();x._debug("error on getting connection token, reconnect after "+z+" milliseconds",v),x._reconnecting=!1,x._reconnectTimeout=setTimeout(()=>{x._startReconnecting()},z)})}_handleGetDataError(i){if(i instanceof uc){this._failUnauthorized();return}this.emit("error",{type:"connectData",error:{code:t.badConfiguration,message:(i===null||i===void 0?void 0:i.toString())||""}});let c=this._getReconnectDelay();this._debug("error on getting connect data, reconnect after "+c+" milliseconds",i),this._reconnecting=!1,this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},c)}_connectError(i){if(this.state!==Xi.Connecting)return;if(i.code===109)this._refreshRequired=!0;if(i.code<100||i.temporary===!0||i.code===109)this.emit("error",{type:"connect",error:i}),this._debug("closing transport due to connect error"),this._disconnect(i.code,i.message,!0);else this._disconnect(i.code,i.message,!1)}_scheduleReconnect(){if(!this._isConnecting())return;let i=!1;if(this._emulation&&!this._transportWasOpen&&!this._triedAllTransports)i=!0;let c=this._getReconnectDelay();if(i)c=0;this._debug("reconnect after "+c+" milliseconds"),this._clearReconnectTimeout(),this._reconnectTimeout=setTimeout(()=>{this._startReconnecting()},c)}_constructConnectCommand(){let i={};if(this._token)i.token=this._token;if(this._data)i.data=this._data;if(this._config.name)i.name=this._config.name;if(this._config.version)i.version=this._config.version;if(Object.keys(this._config.headers).length>0)i.headers=this._config.headers;let c={},x=!1;for(let v in this._serverSubs)if(this._serverSubs.hasOwnProperty(v)&&this._serverSubs[v].recoverable){x=!0;let z={recover:!0};if(this._serverSubs[v].offset)z.offset=this._serverSubs[v].offset;if(this._serverSubs[v].epoch)z.epoch=this._serverSubs[v].epoch;c[v]=z}if(x)i.subs=c;return{connect:i}}_getHistoryRequest(i,c){let x={channel:i};if(c!==void 0){if(c.since){if(x.since={offset:c.since.offset},c.since.epoch)x.since.epoch=c.since.epoch}if(c.limit!==void 0)x.limit=c.limit;if(c.reverse===!0)x.reverse=!0}return x}_methodCall(){if(this._isConnected())return Promise.resolve();return new Promise((i,c)=>{let x=setTimeout(function(){c({code:t.timeout,message:"timeout"})},this._config.timeout);this._promises[this._nextPromiseId()]={timeout:x,resolve:i,reject:c}})}_callPromise(i,c){return new Promise((x,v)=>{this._call(i,!1).then((z)=>{var Z;let J=c(z.reply);x(J),(Z=z.next)===null||Z===void 0||Z.call(z)},(z)=>{var Z;v(z.error),(Z=z.next)===null||Z===void 0||Z.call(z)})})}_dataReceived(i){if(this._serverPing>0)this._waitServerPing();let c=this._codec.decodeReplies(i);this._dispatchPromise=this._dispatchPromise.then(()=>{let x;this._dispatchPromise=new Promise((v)=>{x=v}),this._dispatchSynchronized(c,x)})}_dispatchSynchronized(i,c){let x=Promise.resolve();for(let v in i)if(i.hasOwnProperty(v))x=x.then(()=>{return this._dispatchReply(i[v])});x=x.then(()=>{c()})}_dispatchReply(i){let c,x=new Promise((z)=>{c=z});if(i===void 0||i===null)return this._debug("dispatch: got undefined or null reply"),c(),x;let v=i.id;if(v&&v>0)this._handleReply(i,c);else if(!i.push)this._handleServerPing(c);else this._handlePush(i.push,c);return x}_call(i,c){return new Promise((x,v)=>{if(i.id=this._nextCommandId(),this._registerCall(i.id,x,v),!c)this._addCommand(i)})}_startConnecting(){if(this._debug("start connecting"),this._setState(Xi.Connecting))this.emit("connecting",{code:Wx.connectCalled,reason:"connect called"});this._client=null,this._startReconnecting()}_disconnect(i,c,x){if(this._isDisconnected())return;this._transportIsOpen=!1;let v=this.state;this._reconnecting=!1;let z={code:i,reason:c},Z=!1;if(x)Z=this._setState(Xi.Connecting);else Z=this._setState(Xi.Disconnected),this._rejectPromises({code:t.clientDisconnected,message:"disconnected"});if(this._clearOutgoingRequests(),v===Xi.Connecting)this._clearReconnectTimeout();if(v===Xi.Connected)this._clearConnectedState();if(Z)if(this._isConnecting())this.emit("connecting",z);else this.emit("disconnected",z);if(this._transport){this._debug("closing existing transport");let J=this._transport;this._transport=null,J.close(),this._transportClosed=!0,this._nextTransportId()}else this._debug("no transport to close");this._scheduleReconnect()}_failUnauthorized(){this._disconnect(u0.unauthorized,"unauthorized",!1)}_getToken(){if(this._debug("get connection token"),!this._config.getToken)return this.emit("error",{type:"configuration",error:{code:t.badConfiguration,message:"token expired but no getToken function set in the configuration"}}),Promise.reject(new uc(""));return this._config.getToken({})}_refresh(){let i=this._client,c=this;this._getToken().then(function(x){if(i!==c._client)return;if(!x){c._failUnauthorized();return}if(c._token=x,c._debug("connection token refreshed"),!c._isConnected())return;let v={refresh:{token:c._token}};c._call(v,!1).then((z)=>{let Z=z.reply.refresh;if(c._refreshResponse(Z),z.next)z.next()},(z)=>{if(c._refreshError(z.error),z.next)z.next()})}).catch(function(x){if(!c._isConnected())return;if(x instanceof uc){c._failUnauthorized();return}c.emit("error",{type:"refreshToken",error:{code:t.clientRefreshToken,message:x!==void 0?x.toString():""}}),c._refreshTimeout=setTimeout(()=>c._refresh(),c._getRefreshRetryDelay())})}_refreshError(i){if(i.code<100||i.temporary===!0)this.emit("error",{type:"refresh",error:i}),this._refreshTimeout=setTimeout(()=>this._refresh(),this._getRefreshRetryDelay());else this._disconnect(i.code,i.message,!1)}_getRefreshRetryDelay(){return Gv(0,5000,1e4)}_refreshResponse(i){if(this._refreshTimeout)clearTimeout(this._refreshTimeout),this._refreshTimeout=null;if(i.expires)this._client=i.client,this._refreshTimeout=setTimeout(()=>this._refresh(),Xv(i.ttl))}_removeSubscription(i){if(i===null)return;delete this._subs[i.channel]}_unsubscribe(i){if(!this._transportIsOpen)return Promise.resolve();let x={unsubscribe:{channel:i.channel}},v=this;return new Promise((Z,J)=>{this._call(x,!1).then((Y)=>{if(Z(),Y.next)Y.next()},(Y)=>{if(Z(),Y.next)Y.next();v._disconnect(Wx.unsubscribeError,"unsubscribe error",!0)})})}_getSub(i,c){if(c&&c>0){for(let v in this._subs)if(this._subs.hasOwnProperty(v)){let z=this._subs[v];if(z._id===c)return z}return null}let x=this._subs[i];if(!x)return null;return x}_isServerSub(i){return this._serverSubs[i]!==void 0}_sendSubscribeCommands(){let i=[];for(let c in this._subs){if(!this._subs.hasOwnProperty(c))continue;let x=this._subs[c];if(x._inflight===!0)continue;if(x.state===ji.Subscribing){let v=x._subscribe();if(v)i.push(v)}}return i}_connectResponse(i){if(this._transportIsOpen=!0,this._transportWasOpen=!0,this._reconnectAttempts=0,this._refreshRequired=!1,this._isConnected())return;if(this._client=i.client,this._setState(Xi.Connected),this._refreshTimeout)clearTimeout(this._refreshTimeout);if(i.expires)this._refreshTimeout=setTimeout(()=>this._refresh(),Xv(i.ttl));this._session=i.session,this._node=i.node,this.startBatching(),this._sendSubscribeCommands(),this.stopBatching();let c={client:i.client,transport:this._transport.subName()};if(i.data)c.data=i.data;if(this.emit("connected",c),this._resolvePromises(),this._processServerSubs(i.subs||{}),i.ping&&i.ping>0)this._serverPing=i.ping*1000,this._sendPong=i.pong===!0,this._waitServerPing();else this._serverPing=0}_processServerSubs(i){for(let c in i){if(!i.hasOwnProperty(c))continue;let x=i[c];this._serverSubs[c]={offset:x.offset,epoch:x.epoch,recoverable:x.recoverable||!1};let v=this._getSubscribeContext(c,x);this.emit("subscribed",v)}for(let c in i){if(!i.hasOwnProperty(c))continue;let x=i[c];if(x.recovered){let v=x.publications;if(v&&v.length>0){for(let z in v)if(v.hasOwnProperty(z))this._handlePublication(c,v[z])}}}for(let c in this._serverSubs){if(!this._serverSubs.hasOwnProperty(c))continue;if(!i[c])this.emit("unsubscribed",{channel:c}),delete this._serverSubs[c]}}_clearRefreshTimeout(){if(this._refreshTimeout!==null)clearTimeout(this._refreshTimeout),this._refreshTimeout=null}_clearReconnectTimeout(){if(this._reconnectTimeout!==null)clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null}_clearServerPingTimeout(){if(this._serverPingTimeout!==null)clearTimeout(this._serverPingTimeout),this._serverPingTimeout=null}_waitServerPing(){if(this._config.maxServerPingDelay===0)return;if(!this._isConnected())return;this._clearServerPingTimeout(),this._serverPingTimeout=setTimeout(()=>{if(!this._isConnected())return;this._disconnect(Wx.noPing,"no ping",!0)},this._serverPing+this._config.maxServerPingDelay)}_getSubscribeContext(i,c){let x={channel:i,positioned:!1,recoverable:!1,wasRecovering:!1,recovered:!1,hasRecoveredPublications:!1};if(c.recovered)x.recovered=!0;if(c.positioned)x.positioned=!0;if(c.recoverable)x.recoverable=!0;if(c.was_recovering)x.wasRecovering=!0;let v="";if("epoch"in c)v=c.epoch;let z=0;if("offset"in c)z=c.offset;if(x.positioned||x.recoverable)x.streamPosition={offset:z,epoch:v};if(Array.isArray(c.publications)&&c.publications.length>0)x.hasRecoveredPublications=!0;if(c.data)x.data=c.data;return x}_handleReply(i,c){let x=i.id;if(!(x in this._callbacks)){c();return}let v=this._callbacks[x];if(clearTimeout(this._callbacks[x].timeout),delete this._callbacks[x],!Wq(i)){let z=v.callback;if(!z)return;z({reply:i,next:c})}else{let z=v.errback;if(!z){c();return}let Z={code:i.error.code,message:i.error.message||"",temporary:i.error.temporary||!1};z({error:Z,next:c})}}_handleJoin(i,c,x){let v=this._getSub(i,x);if(!v&&i){if(this._isServerSub(i)){let z={channel:i,info:this._getJoinLeaveContext(c.info)};this.emit("join",z)}return}v._handleJoin(c)}_handleLeave(i,c,x){let v=this._getSub(i,x);if(!v&&i){if(this._isServerSub(i)){let z={channel:i,info:this._getJoinLeaveContext(c.info)};this.emit("leave",z)}return}v._handleLeave(c)}_handleUnsubscribe(i,c){let x=this._getSub(i,0);if(!x&&i){if(this._isServerSub(i))delete this._serverSubs[i],this.emit("unsubscribed",{channel:i});return}if(c.code<2500)x._setUnsubscribed(c.code,c.reason,!1);else x._setSubscribing(c.code,c.reason)}_handleSubscribe(i,c){this._serverSubs[i]={offset:c.offset,epoch:c.epoch,recoverable:c.recoverable||!1},this.emit("subscribed",this._getSubscribeContext(i,c))}_handleDisconnect(i){let c=i.code,x=!0;if(c>=3500&&c<4000||c>=4500&&c<5000)x=!1;this._disconnect(c,i.reason,x)}_getPublicationContext(i,c){let x={channel:i,data:c.data};if(c.offset)x.offset=c.offset;if(c.info)x.info=this._getJoinLeaveContext(c.info);if(c.tags)x.tags=c.tags;return x}_getJoinLeaveContext(i){let c={client:i.client,user:i.user},x=i.conn_info;if(x)c.connInfo=x;let v=i.chan_info;if(v)c.chanInfo=v;return c}_handlePublication(i,c,x){let v=this._getSub(i,x);if(!v&&i){if(this._isServerSub(i)){let z=this._getPublicationContext(i,c);if(this.emit("publication",z),c.offset!==void 0)this._serverSubs[i].offset=c.offset}return}v._handlePublication(c)}_handleMessage(i){this.emit("message",{data:i.data})}_handleServerPing(i){if(this._sendPong){let c={};this._transportSendCommands([c])}i()}_handlePush(i,c){let{channel:x,id:v}=i;if(i.pub)this._handlePublication(x,i.pub,v);else if(i.message)this._handleMessage(i.message);else if(i.join)this._handleJoin(x,i.join,v);else if(i.leave)this._handleLeave(x,i.leave,v);else if(i.unsubscribe)this._handleUnsubscribe(x,i.unsubscribe);else if(i.subscribe)this._handleSubscribe(x,i.subscribe);else if(i.disconnect)this._handleDisconnect(i.disconnect);c()}_flush(){let i=this._commands.slice(0);this._commands=[],this._transportSendCommands(i)}_createErrorObject(i,c,x){let v={code:i,message:c};if(x)v.temporary=!0;return v}_registerCall(i,c,x){this._callbacks[i]={callback:c,errback:x,timeout:null},this._callbacks[i].timeout=setTimeout(()=>{if(delete this._callbacks[i],sG(x))x({error:this._createErrorObject(t.timeout,"timeout")})},this._config.timeout)}_addCommand(i){if(this._batching)this._commands.push(i);else this._transportSendCommands([i])}_nextPromiseId(){return++this._promiseId}_nextTransportId(){return++this._transportId}_resolvePromises(){for(let i in this._promises){if(!this._promises.hasOwnProperty(i))continue;if(this._promises[i].timeout)clearTimeout(this._promises[i].timeout);this._promises[i].resolve(),delete this._promises[i]}}_rejectPromises(i){for(let c in this._promises){if(!this._promises.hasOwnProperty(c))continue;if(this._promises[c].timeout)clearTimeout(this._promises[c].timeout);this._promises[c].reject(i),delete this._promises[c]}}}Cx.SubscriptionState=ji;Cx.State=Xi;Cx.UnauthorizedError=uc;var pv=(i,c)=>{async function x(){let v=await fetch(i+"api/centrifuge/gen_token");if(!v.ok){if(v.status===403)throw new Cx.UnauthorizedError("Backend is not answering");throw Error(`Unexpected status code ${v.status}`)}return(await v.json()).token}return c?new Cx(c||"",{getToken:x}):null},Bq=vX.createContext(null),mx=Bq;var Wv=require("react");var R0=require("react");function Kv(i,c){let[x,v]=R0.useState(null),[z,Z]=R0.useState(!1);return R0.useEffect(()=>{if(!z)Z(!0),fetch(i+`api/support/${c}`,{method:"GET"}).then((J)=>J.json()).then((J)=>{v(J)})},[]),x}var $q=({children:i})=>{let c=Wv.useContext(Kx),x=cx(),v=Kv(x,"socketIO"),z=(Z)=>{if(typeof window<"u")window.sid=Z.sid,console.log(`SocketIO initialized: ${window.sid}`)};return Wv.useEffect(()=>{if(!c)return;let Z=()=>{console.log("SocketIO connected")},J=(Y)=>{console.log(`SocketIO disconnected: ${Y}`),c.connect()};if(v)c.on("pieinit",z),c.on("connect",Z),c.on("disconnect",J),c.connect();return()=>{if(v)c.off("pieinit",z),c.off("connect",Z),c.off("disconnect",J),c.disconnect()}},[c,v]),i},mv=$q;var Hv=require("react");var Fq=({children:i})=>{let c=Hv.useContext(mx),x=cx(),v=Kv(x,"centrifuge");return Hv.useEffect(()=>{if(!c)return;let z=()=>{console.log("Centrifuge connected")},Z=(J)=>{console.log("Centrifuge disconnected:",J)};if(v)c.on("connected",z),c.on("disconnected",Z),c.connect();return()=>{if(v)c.disconnect()}},[c,v]),i},Uv=Fq;var Zm=_(p9(),1);var Vx=require("react");var gI=({card:i,data:c,children:x,useSocketioSupport:v=!1,useCentrifugeSupport:z=!1,useMittSupport:Z=!1,centrifugeChannel:J=void 0,methods:Y=void 0})=>{let G=xx();if(G)console.log("[PieCard] Rendering card:",i),console.log("[PieCard] Card data:",c),console.log("[PieCard] Component name:",c?.name),console.log("[PieCard] Real-time support:",{socketio:v,centrifuge:z,mitt:Z,centrifugeChannel:J}),console.log("[PieCard] Methods:",Y?Object.keys(Y):"none"),console.log("[PieCard] Has children:",!!x);let X=Vx.useContext(Kx),Q=Vx.useContext(mx),p=Vx.useContext(Jx);if(Vx.useEffect(()=>{if(!X||!v||!Y||!c.name){if(G&&v)console.log("[PieCard] Socket.IO setup skipped:",{hasSocket:!!X,useSocketioSupport:v,hasMethods:!!Y,hasDataName:!!c?.name});return}return Object.entries(Y).forEach(([W,H])=>{let K=`pie${W}_${c.name}`;if(G)console.log(`[PieCard] Socket.IO registering event: ${K}`);X.on(K,H)}),()=>{Object.entries(Y).forEach(([W,H])=>{let K=`pie${W}_${c.name}`;if(G)console.log(`[PieCard] Socket.IO unregistering event: ${K}`);X.off(K,H)})}},[X,Y,c.name]),Vx.useEffect(()=>{if(!Q||!z||!J||!Y||!c.name){if(G&&z)console.log("[PieCard] Centrifuge setup skipped:",{hasCentrifuge:!!Q,useCentrifugeSupport:z,hasCentrifugeChannel:!!J,hasMethods:!!Y,hasDataName:!!c?.name});return}let W=Object.entries(Y).map(([H,K])=>{let m=`pie${H}_${c.name}_${J}`;if(G)console.log(`[PieCard] Centrifuge subscribing to channel: ${m}`);let U=Q.newSubscription(m);return U.on("publication",(O)=>{if(G)console.log(`[PieCard] Centrifuge received data on ${m}:`,O.data);K(O.data)}),U.subscribe(),U});return()=>{W.forEach((H)=>{if(G)console.log("[PieCard] Centrifuge unsubscribing from channel");H.unsubscribe(),Q.removeSubscription(H)})}},[Q,J,Y,c.name]),Vx.useEffect(()=>{if(!p||!Z||!Y||!c.name){if(G&&Z)console.log("[PieCard] Mitt setup skipped:",{hasMitt:!!p,useMittSupport:Z,hasMethods:!!Y,hasDataName:!!c?.name});return}return Object.entries(Y).forEach(([W,H])=>{let K=`pie${W}_${c.name}`;if(G)console.log(`[PieCard] Mitt registering event: ${K}`);p.on(K,H)}),()=>{Object.entries(Y).forEach(([W,H])=>{let K=`pie${W}_${c.name}`;if(G)console.log(`[PieCard] Mitt unregistering event: ${K}`);p.off(K,H)})}},[p,Y,c.name]),G)console.log("[PieCard] Rendering complete, returning children");return x},Kc=gI;var lK=_(nx(),1);var yK=_(nx(),1);function hv(i){if(!i)return{};let c={...i};if("animationName"in c&&typeof c.animationName==="object"){let x="radiumAnimation_"+Math.random().toString(36).substring(2,8);c.animationName=yK.default.keyframes(c.animationName,x)}return c}var gv=require("react/jsx-runtime"),yI=({data:i,content:c,setUiAjaxConfiguration:x})=>{let{name:v,sx:z}=i;return gv.jsx(Kc,{card:v,data:i,children:gv.jsx("div",{style:hv(z),id:v,children:c.map((Z,J)=>{return gv.jsx(gi,{uiConfig:Z,setUiAjaxConfiguration:x},`children-${J}`)})})})},kK=lK.default(yI);var K9=require("react/jsx-runtime"),lI=({data:i,content:c,setUiAjaxConfiguration:x})=>{let{name:v}=i;return K9.jsx(Kc,{card:v,data:i,children:c.map((z,Z)=>{return K9.jsx(gi,{uiConfig:z,setUiAjaxConfiguration:x},`children-${Z}`)})})},dK=lI;var nc=require("react");var sK=_(nx(),1),W9=require("react/jsx-runtime"),kI=({data:i,content:c})=>{let{useLoader:x,noReturn:v,returnType:z,useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:Y,centrifugeChannel:G}=i,X=nc.useContext(ix),[Q,p]=nc.useState(!1),[W,H]=nc.useState(null),K=nc.useRef(c),m=nc.useContext(Jx),U=($)=>{if($===null)p(!0);else if(p(!1),!v)K.current=$;if(!v)H($)},O=($)=>{K.current=$.content,H($.content)},N=($)=>{if($===null)p(!0);else if(p(!1),!v)for(let M of $)m.emit(M.name,M.data)};if(nc.useEffect(()=>{H(c),p(!1)},[c]),!W&&x)return X;return W9.jsx(Kc,{card:"AjaxGroupCard",data:i,methods:{changeContent:O},useSocketioSupport:Z,useCentrifugeSupport:J,useMittSupport:Y,centrifugeChannel:G,children:W9.jsx(gi,{uiConfig:W??K.current,setUiAjaxConfiguration:z==="events"?N:U})})},oK=sK.default(kI);function m9(i=1000){return new Promise((c)=>{if(typeof window>"u"){c();return}let x=()=>{if(typeof window.sid<"u")c();else setTimeout(x,i)};x()})}var rK=require("react"),dI=(i,c={},x=[],v,z)=>{let Z=z?.renderingLogEnabled??!1,J=z?.apiServer??"";if(Z)console.log("Registering AJAX: ",v,c,x);if(!v||!i){if(Z)console.warn("Registration FAILED: pathname or setUiAjaxConfiguration is missing!");return()=>{}}return async(Y={})=>{if(typeof window>"u"||typeof document>"u"){if(Z)console.warn("getAjaxSubmit called on server, skipping DOM-dependent logic");return}if(x.includes("sid"))await m9();let G=new FormData;for(let[Q,p]of Object.entries({...c,...Y}))G.append(Q,p);for(let Q of x)if(Q==="sid"){if(!window.sid)throw Error("SocketIO isn't initialized properly");G.append("sid",window.sid)}else{let p=document.getElementsByName(Q);if(!p.length){if(Z)console.warn(`No input found with name ${Q}`);continue}let W=p[0];if(W instanceof HTMLInputElement)if(W.type==="file"&&W.files)Array.from(W.files).forEach((H)=>G.append(Q,H));else G.append(Q,W.value);else if(W instanceof HTMLTextAreaElement)G.append(Q,W.value)}let X=J+"api/ajax_content"+v;return i(null),await fetch(X,{method:"POST",body:G}).then(async(Q)=>{let W=(Q.headers.get("content-type")||"").includes("application/json");if(!!Q.body?.getReader&&!W){let K=Q.body.getReader(),m=new TextDecoder,U="";while(!0){let{done:O,value:N}=await K.read();if(O)break;U+=m.decode(N,{stream:!0});let $=U.split(`
52
- `);U=$.pop()??"";for(let M of $){let w=M.trim();if(!w)continue;try{let L=JSON.parse(w);i([L])}catch(L){if(Z)console.warn("Failed to parse streamed line:",w)}}}if(U.trim())try{let O=JSON.parse(U);i([O])}catch(O){if(Z)console.warn("Failed to parse final streamed line:",U)}return{}}else{let K=await Q.json();return i(K),K}}).catch((Q)=>{if(Z)console.error("AJAX request failed:",Q);return i(null),Q})}},yv=(i,c={},x=[],v)=>{let{apiServer:z,enableRenderingLog:Z}=J1();return rK.useMemo(()=>dI(i,c,x,v,{apiServer:z,renderingLogEnabled:Z}),[i,c,x,v,z,Z])};var Wz=_(Kz(),1),v1=_(Kz(),1),K6=Wz.default.default||Wz.default;var CW=_(nx(),1);var l1=require("react/jsx-runtime"),JP=({data:i,setUiAjaxConfiguration:c})=>{let{name:x,title:v,iconUrl:z,iconPosition:Z,sx:J,pathname:Y,kwargs:G,depsNames:X}=i,Q=yv(c,G,X,Y);return l1.jsx(Kc,{card:"AjaxButtonCard",data:i,children:l1.jsxs("button",{id:x,className:"box-border flex min-h-12 w-full min-w-min cursor-pointer items-center justify-center rounded-[16px] border border-[#080318] bg-white text-center font-[TTForsTrial] text-[#080318] hover:bg-neutral-300",value:x,onClick:()=>Q(),style:hv(J),type:"button",children:[z&&Z==="start"&&l1.jsx("img",{src:z,alt:""}),K6(v),z&&Z==="end"&&l1.jsx("img",{src:z,alt:""})]})})},bW=CW.default(JP);var ti=require("react");var W6=require("react"),_W=require("react/jsx-runtime");function mz(i){let[c,x]=W6.useState(!1),v=W6.useRef(null);return _W.jsx("textarea",{ref:v,...i,onKeyUp:()=>{x(!1)},onKeyDown:(Y)=>{if(Y.key==="Enter"&&Y.shiftKey){if(x(!0),v.current&&typeof window<"u"){let G=window.getComputedStyle(v.current),X=parseFloat(G.lineHeight);v.current.style.height=v.current.scrollHeight+X+"px"}}if(Y.key==="Backspace"){if(x(!0),v.current&&typeof window<"u"){let G=window.getComputedStyle(v.current),X=parseFloat(G.lineHeight);if(v.current.scrollHeight>X)v.current.style.height=v.current.scrollHeight-X+"px"}}i.onKeyDown&&i.onKeyDown(Y)},onBlur:(Y)=>{x(!1),i.onBlur&&i.onBlur(Y)},style:{resize:c?"vertical":"none",overflowY:"auto",...i.style}})}var H6=require("react");var Hz=require("react/jsx-runtime"),YP=()=>Hz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Hz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})}),hW=YP;var m6=require("react/jsx-runtime"),GP=({type:i="button",onClick:c,icons:x})=>{let v=H6.useRef(null),z=H6.useCallback(()=>{let J=v.current;if(J)J.style.transform="scale(0.8)",setTimeout(()=>{J.style.transform="scale(1)"},600)},[]);return m6.jsx("button",{ref:v,type:i,onClick:(J)=>{if(c)c(J);z()},className:"mr-1.5 rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",style:{transition:"transform 300ms ease"},children:x.sendIcon?m6.jsx("img",{src:x.sendIcon,alt:""}):m6.jsx(hW,{})})},gW=GP;var Uz=require("react/jsx-runtime"),XP=()=>Uz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Uz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"})}),yW=XP;var tc=require("react/jsx-runtime"),QP=({name:i,accept:c,fileInputRef:x,onSelectFile:v,icons:z})=>{return tc.jsxs(tc.Fragment,{children:[tc.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:()=>{if(x.current)x.current.click()},children:z.attachFileIcon?tc.jsx("img",{src:z.attachFileIcon,alt:""}):tc.jsx(yW,{})}),tc.jsx("input",{id:i+"__pie__file",name:i+"__pie__file",className:"hidden",type:"file",accept:c,ref:x,onChange:(Z)=>{if(Z.target.files)v(Z.target.files[0])}})]})},lW=QP;var Vz=require("react/jsx-runtime"),pP=()=>Vz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5 text-gray-500",children:Vz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),kW=pP;var Bz=require("react/jsx-runtime"),KP=()=>Bz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Bz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),U6=KP;var wx=require("react/jsx-runtime"),WP=({name:i,selectedFile:c,onDropFile:x})=>{return wx.jsxs("div",{className:"flex w-full cursor-default flex-row items-center gap-2",children:[wx.jsx(kW,{}),wx.jsx("span",{className:"flex-1",children:c.name}),wx.jsx("input",{type:"hidden",name:i,value:""}),wx.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:x,children:wx.jsx(U6,{})})]})},dW=WP;var v5=require("react/jsx-runtime"),mP=()=>v5.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:[v5.jsx("path",{d:"M8 5C8 2.79086 9.79086 1 12 1C14.2091 1 16 2.79086 16 5V12C16 14.2091 14.2091 16 12 16C9.79086 16 8 14.2091 8 12V5Z"}),v5.jsx("path",{d:"M6.25 11.8438V12C6.25 13.525 6.8558 14.9875 7.93414 16.0659C9.01247 17.1442 10.475 17.75 12 17.75C13.525 17.75 14.9875 17.1442 16.0659 16.0659C17.1442 14.9875 17.75 13.525 17.75 12V11.8438C17.75 11.2915 18.1977 10.8438 18.75 10.8438H19.25C19.8023 10.8438 20.25 11.2915 20.25 11.8437V12C20.25 14.188 19.3808 16.2865 17.8336 17.8336C16.5842 19.0831 14.9753 19.8903 13.25 20.1548V22C13.25 22.5523 12.8023 23 12.25 23H11.75C11.1977 23 10.75 22.5523 10.75 22V20.1548C9.02471 19.8903 7.41579 19.0831 6.16637 17.8336C4.61919 16.2865 3.75 14.188 3.75 12V11.8438C3.75 11.2915 4.19772 10.8438 4.75 10.8438H5.25C5.80228 10.8438 6.25 11.2915 6.25 11.8438Z"})]}),sW=mP;var k1=require("react/jsx-runtime"),HP=({isListening:i,toggleListening:c,icons:x})=>{return k1.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:c,children:i?x.cancelIcon?k1.jsx("img",{src:x.cancelIcon,alt:""}):k1.jsx(U6,{}):x.voiceRecordingIcon?k1.jsx("img",{src:x.voiceRecordingIcon,alt:""}):k1.jsx(sW,{})})},oW=HP;var z5=require("react/jsx-runtime"),UP=({option:i,onClickOption:c})=>{return z5.jsxs("div",{className:"flex w-fit cursor-pointer flex-row place-content-center items-center gap-1 rounded-md border border-black bg-white px-2 py-1 text-black",onClick:()=>{c(i.title)},style:i.sx,children:[i.iconPosition==="start"&&z5.jsx("img",{src:i.iconUrl,alt:""}),i.title,i.iconPosition==="end"&&z5.jsx("img",{src:i.iconUrl,alt:""})]})},V6=UP;var $z=require("react/jsx-runtime"),VP=({options:i,handleOptionClick:c})=>{return $z.jsx("div",{className:"flex w-full flex-row flex-wrap justify-start gap-[5px]",children:i.map((x,v)=>{return $z.jsx(V6,{option:x,onClickOption:c},v)})})},Fz=VP;var Yc=require("react/jsx-runtime"),BP=ti.forwardRef(({name:i,defaultValue:c,defaultOptions:x,isArea:v,placeholder:z,fileAccept:Z,optionsPosition:J,icons:Y,handleOptionClick:G,handleSendMessage:X,sx:Q},p)=>{let W=ti.useRef(null),[H,K]=ti.useState(null),[m,U]=ti.useState(c),[O,N]=ti.useState(x),[$,M]=ti.useState(!1);ti.useImperativeHandle(p,()=>({clear:()=>{if(U(""),K(null),W.current)W.current.value=""},setValue:(L)=>U(L),setOptions:(L)=>N(L)})),ti.useEffect(()=>{U(c)},[c]),ti.useEffect(()=>{},[]);let w=()=>{};return Yc.jsxs("div",{className:"flex flex-col items-center gap-[0.1rem]",id:i+"_chat_input",style:Q,children:[O&&J==="top"&&Yc.jsx(Fz,{options:O,handleOptionClick:G}),Yc.jsx("div",{className:"stretch relative flex size-full flex-1 flex-row items-stretch gap-3 last:mb-2 md:mx-4 md:flex-col md:last:mb-6 lg:mx-auto",children:Yc.jsxs("div",{className:"flex w-full grow flex-row items-center rounded-md bg-transparent",children:[H?Yc.jsx(dW,{name:i,selectedFile:H,onDropFile:()=>{if(K(null),W.current)W.current.value=""}}):!v?Yc.jsx("input",{name:i,value:m,onChange:(L)=>U(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter")L.preventDefault(),X()},tabIndex:0,placeholder:z,className:"m-0 w-full resize-none border-0 bg-transparent outline-none",style:{maxHeight:200,height:"100%",overflowY:"hidden"}}):Yc.jsx(mz,{name:i,value:m,onChange:(L)=>U(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter"&&!L.shiftKey)L.preventDefault(),X()},tabIndex:0,rows:2,placeholder:z,className:"m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 outline-none md:pl-0",style:{maxHeight:200,height:"100%",minHeight:24}}),Yc.jsx(oW,{isListening:$,toggleListening:w,icons:Y}),Yc.jsx(lW,{name:i,fileInputRef:W,accept:Z,onSelectFile:K,icons:Y}),Yc.jsx(gW,{onClick:X,icons:Y})]})}),O&&J==="bottom"&&Yc.jsx(Fz,{options:O,handleOptionClick:G})]})}),rW=BP;var $6=require("react");var B6=require("react"),eW=require("react/jsx-runtime");function $P({children:i}){let[c,x]=B6.useState(i);return B6.useEffect(()=>{x(i)},[i]),eW.jsx("div",{className:"max-w-full first:mt-0",children:c})}var tW=$P;var Mz=require("react/jsx-runtime"),FP=()=>Mz.jsx("svg",{width:"30",height:"30",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:Mz.jsx("path",{d:"m 8 1 c -1.65625 0 -3 1.34375 -3 3 s 1.34375 3 3 3 s 3 -1.34375 3 -3 s -1.34375 -3 -3 -3 z m -1.5 7 c -2.492188 0 -4.5 2.007812 -4.5 4.5 v 0.5 c 0 1.109375 0.890625 2 2 2 h 8 c 1.109375 0 2 -0.890625 2 -2 v -0.5 c 0 -2.492188 -2.007812 -4.5 -4.5 -4.5 z m 0 0",fill:"#2e3436"})}),im=FP;var Z5=require("react/jsx-runtime");function MP({username:i,avatar:c}){return Z5.jsx("div",{className:"w-[30px]",children:Z5.jsx("div",{className:"relative flex size-[30px] items-center justify-center rounded-sm p-1 text-white",children:c?Z5.jsx("img",{src:c,className:"absolute inset-0 rounded",alt:i}):Z5.jsx(im,{})})})}var Nz=MP;var ei=require("react/jsx-runtime"),NP=({message:i,handleOptionClick:c,setUiAjaxConfiguration:x})=>{let[v,z]=$6.useState(!1);return $6.useEffect(()=>{let Z=setTimeout(()=>{if(v)z(!1)},1000);return()=>clearTimeout(Z)},[v]),ei.jsx("div",{className:"group w-full border-b border-black/10",id:i.id,children:ei.jsxs("div",{className:`flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-3xl xl:max-w-5xl ${i.align==="center"?"m-auto":""} ${i.align==="right"?"ml-auto justify-end":""} ${i.align==="left"?"mr-auto":""} `,children:[(i.align==="left"||i.align==="center")&&ei.jsx("div",{className:"relative flex shrink-0 flex-col items-end",children:ei.jsx(Nz,{username:i.username,avatar:i.avatar})}),ei.jsxs("div",{className:"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]",children:[ei.jsx("div",{className:`markdown light prose w-full break-words dark:prose-invert first:mt-0 ${i.align==="right"?"flex justify-end self-end":""}`,children:typeof i.content==="string"?i.parseMode.toLowerCase()==="markdown"?ei.jsx(tW,{children:i.content},Date.now()+Math.random()):i.parseMode.toLowerCase()==="html"?K6(i.content):i.content:ei.jsx(gi,{uiConfig:i.content,setUiAjaxConfiguration:x})}),ei.jsx("div",{className:"flex flex-row flex-wrap justify-start gap-1",children:i.options.map((Z,J)=>ei.jsx(V6,{onClickOption:c,option:Z},J))})]}),i.align==="right"&&ei.jsx("div",{className:"relative flex shrink-0 flex-col items-end",children:ei.jsx(Nz,{username:i.username,avatar:i.avatar})})]})})},cm=NP;var Ec=require("react"),qz=require("react/jsx-runtime"),qP=Ec.forwardRef(({name:i,handleOptionClick:c,defaultMessages:x,sx:v,setUiAjaxConfiguration:z},Z)=>{let[J,Y]=Ec.useState(x),G=Ec.useRef(null),X=()=>{if(G.current)G.current.scrollTop=G.current.scrollHeight};return Ec.useEffect(()=>{X()},[J]),Ec.useImperativeHandle(Z,()=>({setMessages:(Q)=>Y(Q),addMessage:(Q)=>Y((p)=>[...p,Q]),scrollToBottom:X})),qz.jsx("div",{id:i+"_messages",className:"flex flex-col items-center overflow-y-scroll",style:v,ref:G,children:J.map((Q)=>qz.jsx(cm,{message:Q,handleOptionClick:c,setUiAjaxConfiguration:z},Q.id))})}),xm=qP;var z1=require("react"),d1=require("react/jsx-runtime"),OP=({data:i,setUiAjaxConfiguration:c})=>{let{name:x,defaultValue:v,defaultMessages:z,defaultOptions:Z,isArea:J,fileAccept:Y,placeholder:G,icons:X,optionsPosition:Q,sxMap:p={container:{},chatInput:{},messages:{}},depsNames:W,pathname:H,kwargs:K,useSocketioSupport:m,useCentrifugeSupport:U,centrifugeChannel:O}=i,N=z1.useRef(null),$=z1.useRef(null),[M,w]=z1.useState(!1),L=yv(c,K,W,H);z1.useEffect(()=>{if(M)requestAnimationFrame(()=>{L(),w(!1)})},[M]);let j=(h)=>{if(N.current)N.current.setValue(h),w(!0)},g=()=>{if(N.current)N.current.clear()},Yi=(h)=>{if(N.current)N.current.setOptions(h.options)},ui=(h)=>{if($.current)$.current.addMessage(h.message)},y=(h)=>{if($.current)$.current.setMessages(h.messages)},Ri=()=>{w(!0)};return d1.jsx(Kc,{card:"ChatCard",data:i,methods:{clearInput:g,setOptions:Yi,addMessage:ui,setMessages:y},useSocketioSupport:m,useCentrifugeSupport:U,centrifugeChannel:O,children:d1.jsxs("div",{className:"flex size-full flex-col",style:p.container,children:[d1.jsx(xm,{ref:$,name:x,defaultMessages:z,sx:p.messages,handleOptionClick:j,setUiAjaxConfiguration:c}),d1.jsx(rW,{ref:N,name:x,isArea:J,defaultOptions:Z,placeholder:G,defaultValue:v,fileAccept:Y,sx:p.chatInput,handleSendMessage:Ri,handleOptionClick:j,optionsPosition:Q,icons:X})]})})},vm=OP;var Oz=!1;function s1(){if(Oz)return;ec({name:"SequenceCard",component:kK,metadata:{author:"PieData",description:"Simple div with styles joining few components"}}),ec({name:"UnionCard",component:dK,metadata:{author:"PieData",description:"Renders one of many components"}}),ec({name:"AjaxGroupCard",component:oK,metadata:{author:"PieData",description:"Group card with AJAX support"}}),ec({name:"AjaxButtonCard",component:bW,metadata:{author:"PieData",description:"Button with AJAX support"}}),ec({name:"ChatCard",component:vm,metadata:{author:"PieData"}}),Oz=!0}function Sc(){return Oz}var bi=require("react/jsx-runtime"),LP=({location:i,fallback:c,onError:x,initializePie:v})=>{let z=cx(),Z=G5(),J=xx();F6.useEffect(()=>{if(Sc())return;s1(),v()},[]);let Y=F6.useMemo(()=>Zm.createAxiosDateTransformer({baseURL:z||""}),[z]),{data:G,isLoading:X,error:Q}=o1.useQuery({queryKey:["uiConfig",i.pathname+i.search,Sc(),z],queryFn:async()=>{if(!z||!Sc())return;let p="/api/content"+i.pathname+i.search;if(J)console.log("[PieRoot] Fetching UI configuration from:",p);let W=await Y.get(p,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(J)console.log("[PieRoot] Received UI configuration:",W.data);return W.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(p)=>Math.min(1000*2**p,30000)});if(!z)return c??null;if(J)console.log("[PieRoot] Rendering with location:",i),console.log("[PieRoot] API_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!c);if(Q){if(J)console.error("[PieRoot] Error fetching UI configuration:",Q),console.error("[PieRoot] Error details:",{message:Q.message,status:Q.response?.status,data:Q.response?.data});return x?.(),c}if(X||!G){if(J)console.log("[PieRoot] Loading state:",{isLoading:X,hasUiConfiguration:!!G});return c}if(J)console.log("[PieRoot] UI configuration loaded successfully:",G),console.log("[PieRoot] Rendering UI with configuration");return bi.jsx(Jx.Provider,{value:z0,children:bi.jsx(Kx.Provider,{value:zv(z),children:bi.jsx(mx.Provider,{value:pv(z,Z),children:bi.jsx(ix.Provider,{value:c??bi.jsx(bi.Fragment,{}),children:bi.jsx(mv,{children:bi.jsx(Uv,{children:bi.jsx(zm.default.StyleRoot,{children:bi.jsx(gi,{uiConfig:G})})})})})})})})},wP=(i)=>{let c=new o1.QueryClient;return bi.jsx(e1.Provider,{value:i.config,children:bi.jsx(o1.QueryClientProvider,{client:c,children:bi.jsx(LP,{...i})})})},Jm=wP;var N6=require("react"),r1=require("@tanstack/react-query"),Gm=_(nx(),1);var Xm=_(p9(),1);var M6=require("react");var Ym=()=>{let[i,c]=M6.useState(null),x=Tz();return M6.useEffect(()=>{if(typeof window>"u")return;let v=window.Telegram.WebApp;if(v.ready(),x==="telegram_expanded"&&(v.platform==="ios"||v.platform==="android"))v.expand();c(v)},[]),i};var _i=require("react/jsx-runtime"),IP=({location:i,fallback:c,onError:x,initializePie:v})=>{let z=cx(),Z=G5(),J=xx();N6.useEffect(()=>{if(Sc())return;s1(),v()},[]);let Y=N6.useMemo(()=>Xm.createAxiosDateTransformer({baseURL:z}),[]);if(J)console.log("[PieRoot] Rendering with location:",i),console.log("[PieRoot] API_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!c);if(!z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");let G=Ym(),{data:X,isLoading:Q,error:p}=r1.useQuery({queryKey:["uiConfig",i.pathname+i.search,G?.initData,Sc()],queryFn:async()=>{if(!Sc())return;let W=i.search?"&":"?",H=G?.initData?`${W}initData=${encodeURIComponent(G.initData)}`:"",K="/api/content"+i.pathname+i.search+H;if(J)console.log("[PieRoot] Fetching UI configuration from:",K);let m=await Y.get(K,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(J)console.log("[PieRoot] Received UI configuration:",m.data);return m.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000)});if(p&&J)return console.error("[PieRoot] Error fetching UI configuration:",p),console.error("[PieRoot] Error details:",{message:p.message,status:p.response?.status,data:p.response?.data}),x?.(),c;if(Q||!X){if(J)console.log("[PieRoot] Loading state:",{isLoading:Q,hasUiConfiguration:!!X});return c}if(J)console.log("[PieRoot] UI configuration loaded successfully:",X),console.log("[PieRoot] Rendering UI with configuration");return _i.jsx(Jx.Provider,{value:z0,children:_i.jsx(Kx.Provider,{value:zv(z),children:_i.jsx(mx.Provider,{value:pv(z,Z),children:_i.jsx(ix.Provider,{value:c??_i.jsx(_i.Fragment,{}),children:_i.jsx(mv,{children:_i.jsx(Uv,{children:_i.jsx(Gm.default.StyleRoot,{children:_i.jsx(gi,{uiConfig:X})})})})})})})})},AP=(i)=>{let c=new r1.QueryClient;return _i.jsx(e1.Provider,{value:i.config,children:_i.jsx(r1.QueryClientProvider,{client:c,children:_i.jsx(IP,{...i})})})},Qm=AP;
52
+ `);U=$.pop()??"";for(let M of $){let w=M.trim();if(!w)continue;try{let L=JSON.parse(w);i([L])}catch(L){if(Z)console.warn("Failed to parse streamed line:",w)}}}if(U.trim())try{let O=JSON.parse(U);i([O])}catch(O){if(Z)console.warn("Failed to parse final streamed line:",U)}return{}}else{let K=await Q.json();return i(K),K}}).catch((Q)=>{if(Z)console.error("AJAX request failed:",Q);return i(null),Q})}},yv=(i,c={},x=[],v)=>{let{apiServer:z,enableRenderingLog:Z}=J1();return rK.useMemo(()=>dI(i,c,x,v,{apiServer:z,renderingLogEnabled:Z}),[i,c,x,v,z,Z])};var Wz=_(Kz(),1),v1=_(Kz(),1),K6=Wz.default.default||Wz.default;var CW=_(nx(),1);var l1=require("react/jsx-runtime"),JP=({data:i,setUiAjaxConfiguration:c})=>{let{name:x,title:v,iconUrl:z,iconPosition:Z,sx:J,pathname:Y,kwargs:G,depsNames:X}=i,Q=yv(c,G,X,Y);return l1.jsx(Kc,{card:"AjaxButtonCard",data:i,children:l1.jsxs("button",{id:x,className:"box-border flex min-h-12 w-full min-w-min cursor-pointer items-center justify-center rounded-[16px] border border-[#080318] bg-white text-center font-[TTForsTrial] text-[#080318] hover:bg-neutral-300",value:x,onClick:()=>Q(),style:hv(J),type:"button",children:[z&&Z==="start"&&l1.jsx("img",{src:z,alt:""}),K6(v),z&&Z==="end"&&l1.jsx("img",{src:z,alt:""})]})})},bW=CW.default(JP);var ti=require("react");var W6=require("react"),_W=require("react/jsx-runtime");function mz(i){let[c,x]=W6.useState(!1),v=W6.useRef(null);return _W.jsx("textarea",{ref:v,...i,onKeyUp:()=>{x(!1)},onKeyDown:(Y)=>{if(Y.key==="Enter"&&Y.shiftKey){if(x(!0),v.current&&typeof window<"u"){let G=window.getComputedStyle(v.current),X=parseFloat(G.lineHeight);v.current.style.height=v.current.scrollHeight+X+"px"}}if(Y.key==="Backspace"){if(x(!0),v.current&&typeof window<"u"){let G=window.getComputedStyle(v.current),X=parseFloat(G.lineHeight);if(v.current.scrollHeight>X)v.current.style.height=v.current.scrollHeight-X+"px"}}i.onKeyDown&&i.onKeyDown(Y)},onBlur:(Y)=>{x(!1),i.onBlur&&i.onBlur(Y)},style:{resize:c?"vertical":"none",overflowY:"auto",...i.style}})}var H6=require("react");var Hz=require("react/jsx-runtime"),YP=()=>Hz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Hz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 12L3.269 3.126A59.768 59.768 0 0121.485 12 59.77 59.77 0 013.27 20.876L5.999 12zm0 0h7.5"})}),hW=YP;var m6=require("react/jsx-runtime"),GP=({type:i="button",onClick:c,icons:x})=>{let v=H6.useRef(null),z=H6.useCallback(()=>{let J=v.current;if(J)J.style.transform="scale(0.8)",setTimeout(()=>{J.style.transform="scale(1)"},600)},[]);return m6.jsx("button",{ref:v,type:i,onClick:(J)=>{if(c)c(J);z()},className:"mr-1.5 rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",style:{transition:"transform 300ms ease"},children:x.sendIcon?m6.jsx("img",{src:x.sendIcon,alt:""}):m6.jsx(hW,{})})},gW=GP;var Uz=require("react/jsx-runtime"),XP=()=>Uz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Uz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"})}),yW=XP;var tc=require("react/jsx-runtime"),QP=({name:i,accept:c,fileInputRef:x,onSelectFile:v,icons:z})=>{return tc.jsxs(tc.Fragment,{children:[tc.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:()=>{if(x.current)x.current.click()},children:z.attachFileIcon?tc.jsx("img",{src:z.attachFileIcon,alt:""}):tc.jsx(yW,{})}),tc.jsx("input",{id:i+"__pie__file",name:i+"__pie__file",className:"hidden",type:"file",accept:c,ref:x,onChange:(Z)=>{if(Z.target.files)v(Z.target.files[0])}})]})},lW=QP;var Vz=require("react/jsx-runtime"),pP=()=>Vz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5 text-gray-500",children:Vz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"})}),kW=pP;var Bz=require("react/jsx-runtime"),KP=()=>Bz.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:Bz.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})}),U6=KP;var wx=require("react/jsx-runtime"),WP=({name:i,selectedFile:c,onDropFile:x})=>{return wx.jsxs("div",{className:"flex w-full cursor-default flex-row items-center gap-2",children:[wx.jsx(kW,{}),wx.jsx("span",{className:"flex-1",children:c.name}),wx.jsx("input",{type:"hidden",name:i,value:""}),wx.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:x,children:wx.jsx(U6,{})})]})},dW=WP;var v5=require("react/jsx-runtime"),mP=()=>v5.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",className:"size-5",children:[v5.jsx("path",{d:"M8 5C8 2.79086 9.79086 1 12 1C14.2091 1 16 2.79086 16 5V12C16 14.2091 14.2091 16 12 16C9.79086 16 8 14.2091 8 12V5Z"}),v5.jsx("path",{d:"M6.25 11.8438V12C6.25 13.525 6.8558 14.9875 7.93414 16.0659C9.01247 17.1442 10.475 17.75 12 17.75C13.525 17.75 14.9875 17.1442 16.0659 16.0659C17.1442 14.9875 17.75 13.525 17.75 12V11.8438C17.75 11.2915 18.1977 10.8438 18.75 10.8438H19.25C19.8023 10.8438 20.25 11.2915 20.25 11.8437V12C20.25 14.188 19.3808 16.2865 17.8336 17.8336C16.5842 19.0831 14.9753 19.8903 13.25 20.1548V22C13.25 22.5523 12.8023 23 12.25 23H11.75C11.1977 23 10.75 22.5523 10.75 22V20.1548C9.02471 19.8903 7.41579 19.0831 6.16637 17.8336C4.61919 16.2865 3.75 14.188 3.75 12V11.8438C3.75 11.2915 4.19772 10.8438 4.75 10.8438H5.25C5.80228 10.8438 6.25 11.2915 6.25 11.8438Z"})]}),sW=mP;var k1=require("react/jsx-runtime"),HP=({isListening:i,toggleListening:c,icons:x})=>{return k1.jsx("button",{className:"rounded-md p-1 text-gray-500 ring-0 hover:bg-gray-100 disabled:opacity-40 disabled:hover:bg-transparent",type:"button",onClick:c,children:i?x.cancelIcon?k1.jsx("img",{src:x.cancelIcon,alt:""}):k1.jsx(U6,{}):x.voiceRecordingIcon?k1.jsx("img",{src:x.voiceRecordingIcon,alt:""}):k1.jsx(sW,{})})},oW=HP;var z5=require("react/jsx-runtime"),UP=({option:i,onClickOption:c})=>{return z5.jsxs("div",{className:"flex w-fit cursor-pointer flex-row place-content-center items-center gap-1 rounded-md border border-black bg-white px-2 py-1 text-black",onClick:()=>{c(i.title)},style:i.sx,children:[i.iconPosition==="start"&&z5.jsx("img",{src:i.iconUrl,alt:""}),i.title,i.iconPosition==="end"&&z5.jsx("img",{src:i.iconUrl,alt:""})]})},V6=UP;var $z=require("react/jsx-runtime"),VP=({options:i,handleOptionClick:c})=>{return $z.jsx("div",{className:"flex w-full flex-row flex-wrap justify-start gap-[5px]",children:i.map((x,v)=>{return $z.jsx(V6,{option:x,onClickOption:c},v)})})},Fz=VP;var Yc=require("react/jsx-runtime"),BP=ti.forwardRef(({name:i,defaultValue:c,defaultOptions:x,isArea:v,placeholder:z,fileAccept:Z,optionsPosition:J,icons:Y,handleOptionClick:G,handleSendMessage:X,sx:Q},p)=>{let W=ti.useRef(null),[H,K]=ti.useState(null),[m,U]=ti.useState(c),[O,N]=ti.useState(x),[$,M]=ti.useState(!1);ti.useImperativeHandle(p,()=>({clear:()=>{if(U(""),K(null),W.current)W.current.value=""},setValue:(L)=>U(L),setOptions:(L)=>N(L)})),ti.useEffect(()=>{U(c)},[c]),ti.useEffect(()=>{},[]);let w=()=>{};return Yc.jsxs("div",{className:"flex flex-col items-center gap-[0.1rem]",id:i+"_chat_input",style:Q,children:[O&&J==="top"&&Yc.jsx(Fz,{options:O,handleOptionClick:G}),Yc.jsx("div",{className:"stretch relative flex size-full flex-1 flex-row items-stretch gap-3 last:mb-2 md:mx-4 md:flex-col md:last:mb-6 lg:mx-auto",children:Yc.jsxs("div",{className:"flex w-full grow flex-row items-center rounded-md bg-transparent",children:[H?Yc.jsx(dW,{name:i,selectedFile:H,onDropFile:()=>{if(K(null),W.current)W.current.value=""}}):!v?Yc.jsx("input",{name:i,value:m,onChange:(L)=>U(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter")L.preventDefault(),X()},tabIndex:0,placeholder:z,className:"m-0 w-full resize-none border-0 bg-transparent outline-none",style:{maxHeight:200,height:"100%",overflowY:"hidden"}}):Yc.jsx(mz,{name:i,value:m,onChange:(L)=>U(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter"&&!L.shiftKey)L.preventDefault(),X()},tabIndex:0,rows:2,placeholder:z,className:"m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 outline-none md:pl-0",style:{maxHeight:200,height:"100%",minHeight:24}}),Yc.jsx(oW,{isListening:$,toggleListening:w,icons:Y}),Yc.jsx(lW,{name:i,fileInputRef:W,accept:Z,onSelectFile:K,icons:Y}),Yc.jsx(gW,{onClick:X,icons:Y})]})}),O&&J==="bottom"&&Yc.jsx(Fz,{options:O,handleOptionClick:G})]})}),rW=BP;var $6=require("react");var B6=require("react"),eW=require("react/jsx-runtime");function $P({children:i}){let[c,x]=B6.useState(i);return B6.useEffect(()=>{x(i)},[i]),eW.jsx("div",{className:"max-w-full first:mt-0",children:c})}var tW=$P;var Mz=require("react/jsx-runtime"),FP=()=>Mz.jsx("svg",{width:"30",height:"30",viewBox:"0 0 16 16",xmlns:"http://www.w3.org/2000/svg",children:Mz.jsx("path",{d:"m 8 1 c -1.65625 0 -3 1.34375 -3 3 s 1.34375 3 3 3 s 3 -1.34375 3 -3 s -1.34375 -3 -3 -3 z m -1.5 7 c -2.492188 0 -4.5 2.007812 -4.5 4.5 v 0.5 c 0 1.109375 0.890625 2 2 2 h 8 c 1.109375 0 2 -0.890625 2 -2 v -0.5 c 0 -2.492188 -2.007812 -4.5 -4.5 -4.5 z m 0 0",fill:"#2e3436"})}),im=FP;var Z5=require("react/jsx-runtime");function MP({username:i,avatar:c}){return Z5.jsx("div",{className:"w-[30px]",children:Z5.jsx("div",{className:"relative flex size-[30px] items-center justify-center rounded-sm p-1 text-white",children:c?Z5.jsx("img",{src:c,className:"absolute inset-0 rounded",alt:i}):Z5.jsx(im,{})})})}var Nz=MP;var ei=require("react/jsx-runtime"),NP=({message:i,handleOptionClick:c,setUiAjaxConfiguration:x})=>{let[v,z]=$6.useState(!1);return $6.useEffect(()=>{let Z=setTimeout(()=>{if(v)z(!1)},1000);return()=>clearTimeout(Z)},[v]),ei.jsx("div",{className:"group w-full border-b border-black/10",id:i.id,children:ei.jsxs("div",{className:`flex gap-4 p-4 text-base md:max-w-2xl md:gap-6 md:py-6 lg:max-w-3xl xl:max-w-5xl ${i.align==="center"?"m-auto":""} ${i.align==="right"?"ml-auto justify-end":""} ${i.align==="left"?"mr-auto":""} `,children:[(i.align==="left"||i.align==="center")&&ei.jsx("div",{className:"relative flex shrink-0 flex-col items-end",children:ei.jsx(Nz,{username:i.username,avatar:i.avatar})}),ei.jsxs("div",{className:"relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]",children:[ei.jsx("div",{className:`markdown light prose w-full break-words dark:prose-invert first:mt-0 ${i.align==="right"?"flex justify-end self-end":""}`,children:typeof i.content==="string"?i.parseMode.toLowerCase()==="markdown"?ei.jsx(tW,{children:i.content},Date.now()+Math.random()):i.parseMode.toLowerCase()==="html"?K6(i.content):i.content:ei.jsx(gi,{uiConfig:i.content,setUiAjaxConfiguration:x})}),ei.jsx("div",{className:"flex flex-row flex-wrap justify-start gap-1",children:i.options.map((Z,J)=>ei.jsx(V6,{onClickOption:c,option:Z},J))})]}),i.align==="right"&&ei.jsx("div",{className:"relative flex shrink-0 flex-col items-end",children:ei.jsx(Nz,{username:i.username,avatar:i.avatar})})]})})},cm=NP;var Ec=require("react"),qz=require("react/jsx-runtime"),qP=Ec.forwardRef(({name:i,handleOptionClick:c,defaultMessages:x,sx:v,setUiAjaxConfiguration:z},Z)=>{let[J,Y]=Ec.useState(x),G=Ec.useRef(null),X=()=>{if(G.current)G.current.scrollTop=G.current.scrollHeight};return Ec.useEffect(()=>{X()},[J]),Ec.useImperativeHandle(Z,()=>({setMessages:(Q)=>Y(Q),addMessage:(Q)=>Y((p)=>[...p,Q]),scrollToBottom:X})),qz.jsx("div",{id:i+"_messages",className:"flex flex-col items-center overflow-y-scroll",style:v,ref:G,children:J.map((Q)=>qz.jsx(cm,{message:Q,handleOptionClick:c,setUiAjaxConfiguration:z},Q.id))})}),xm=qP;var z1=require("react"),d1=require("react/jsx-runtime"),OP=({data:i,setUiAjaxConfiguration:c})=>{let{name:x,defaultValue:v,defaultMessages:z,defaultOptions:Z,isArea:J,fileAccept:Y,placeholder:G,icons:X,optionsPosition:Q,sxMap:p={container:{},chatInput:{},messages:{}},depsNames:W,pathname:H,kwargs:K,useSocketioSupport:m,useCentrifugeSupport:U,centrifugeChannel:O}=i,N=z1.useRef(null),$=z1.useRef(null),[M,w]=z1.useState(!1),L=yv(c,K,W,H);z1.useEffect(()=>{if(M)requestAnimationFrame(()=>{L(),w(!1)})},[M]);let j=(h)=>{if(N.current)N.current.setValue(h),w(!0)},g=()=>{if(N.current)N.current.clear()},Yi=(h)=>{if(N.current)N.current.setOptions(h.options)},ui=(h)=>{if($.current)$.current.addMessage(h.message)},y=(h)=>{if($.current)$.current.setMessages(h.messages)},Ri=()=>{w(!0)};return d1.jsx(Kc,{card:"ChatCard",data:i,methods:{clearInput:g,setOptions:Yi,addMessage:ui,setMessages:y},useSocketioSupport:m,useCentrifugeSupport:U,centrifugeChannel:O,children:d1.jsxs("div",{className:"flex size-full flex-col",style:p.container,children:[d1.jsx(xm,{ref:$,name:x,defaultMessages:z,sx:p.messages,handleOptionClick:j,setUiAjaxConfiguration:c}),d1.jsx(rW,{ref:N,name:x,isArea:J,defaultOptions:Z,placeholder:G,defaultValue:v,fileAccept:Y,sx:p.chatInput,handleSendMessage:Ri,handleOptionClick:j,optionsPosition:Q,icons:X})]})})},vm=OP;var Oz=!1;function s1(){if(Oz)return;ec({name:"SequenceCard",component:kK,metadata:{author:"PieData",description:"Simple div with styles joining few components"}}),ec({name:"UnionCard",component:dK,metadata:{author:"PieData",description:"Renders one of many components"}}),ec({name:"AjaxGroupCard",component:oK,metadata:{author:"PieData",description:"Group card with AJAX support"}}),ec({name:"AjaxButtonCard",component:bW,metadata:{author:"PieData",description:"Button with AJAX support"}}),ec({name:"ChatCard",component:vm,metadata:{author:"PieData"}}),Oz=!0}function Sc(){return Oz}var bi=require("react/jsx-runtime"),LP=({location:i,fallback:c,onError:x,initializePie:v})=>{let z=cx(),Z=G5(),J=xx();F6.useEffect(()=>{if(Sc())return;s1(),v()},[]);let Y=F6.useMemo(()=>Zm.createAxiosDateTransformer({baseURL:z||""}),[z]),{data:G,isLoading:X,error:Q}=o1.useQuery({queryKey:["uiConfig",i.pathname+i.search,Sc(),z],queryFn:async()=>{if(!z||!Sc())return;let p="/api/content"+i.pathname+i.search;if(J)console.log("[PieRoot] Fetching UI configuration from:",p);let W=await Y.get(p,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(J)console.log("[PieRoot] Received UI configuration:",W.data);return W.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(p)=>Math.min(1000*2**p,30000)});if(!z)return c??null;if(J)console.log("[PieRoot] Rendering with location:",i),console.log("[PieRoot] API_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!c);if(Q){if(J)console.error("[PieRoot] Error fetching UI configuration:",Q),console.error("[PieRoot] Error details:",{message:Q.message,status:Q.response?.status,data:Q.response?.data});return x?.(),c}if(X||!G){if(J)console.log("[PieRoot] Loading state:",{isLoading:X,hasUiConfiguration:!!G});return c}if(J)console.log("[PieRoot] UI configuration loaded successfully:",G),console.log("[PieRoot] Rendering UI with configuration");return bi.jsx(Jx.Provider,{value:z0,children:bi.jsx(Kx.Provider,{value:zv(z),children:bi.jsx(mx.Provider,{value:pv(z,Z),children:bi.jsx(ix.Provider,{value:c??bi.jsx(bi.Fragment,{}),children:bi.jsx(mv,{children:bi.jsx(Uv,{children:bi.jsx(zm.default.StyleRoot,{style:{display:"contents"},children:bi.jsx(gi,{uiConfig:G})})})})})})})})},wP=(i)=>{let c=new o1.QueryClient;return bi.jsx(e1.Provider,{value:i.config,children:bi.jsx(o1.QueryClientProvider,{client:c,children:bi.jsx(LP,{...i})})})},Jm=wP;var N6=require("react"),r1=require("@tanstack/react-query"),Gm=_(nx(),1);var Xm=_(p9(),1);var M6=require("react");var Ym=()=>{let[i,c]=M6.useState(null),x=Tz();return M6.useEffect(()=>{if(typeof window>"u")return;let v=window.Telegram.WebApp;if(v.ready(),x==="telegram_expanded"&&(v.platform==="ios"||v.platform==="android"))v.expand();c(v)},[]),i};var _i=require("react/jsx-runtime"),IP=({location:i,fallback:c,onError:x,initializePie:v})=>{let z=cx(),Z=G5(),J=xx();N6.useEffect(()=>{if(Sc())return;s1(),v()},[]);let Y=N6.useMemo(()=>Xm.createAxiosDateTransformer({baseURL:z}),[]);if(J)console.log("[PieRoot] Rendering with location:",i),console.log("[PieRoot] API_SERVER:",z),console.log("[PieRoot] Fallback provided:",!!c);if(!z)throw Error("Set PIE_API_SERVER and PIE_CENTRIFUGE_SERVER");let G=Ym(),{data:X,isLoading:Q,error:p}=r1.useQuery({queryKey:["uiConfig",i.pathname+i.search,G?.initData,Sc()],queryFn:async()=>{if(!Sc())return;let W=i.search?"&":"?",H=G?.initData?`${W}initData=${encodeURIComponent(G.initData)}`:"",K="/api/content"+i.pathname+i.search+H;if(J)console.log("[PieRoot] Fetching UI configuration from:",K);let m=await Y.get(K,{headers:{"Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,PUT,POST,DELETE,PATCH,OPTIONS","Content-type":"application/json"},withCredentials:!0});if(J)console.log("[PieRoot] Received UI configuration:",m.data);return m.data},staleTime:1/0,gcTime:1/0,refetchOnWindowFocus:!1,refetchOnMount:!1,refetchOnReconnect:!1,retry:!0,retryDelay:(W)=>Math.min(1000*2**W,30000)});if(p&&J)return console.error("[PieRoot] Error fetching UI configuration:",p),console.error("[PieRoot] Error details:",{message:p.message,status:p.response?.status,data:p.response?.data}),x?.(),c;if(Q||!X){if(J)console.log("[PieRoot] Loading state:",{isLoading:Q,hasUiConfiguration:!!X});return c}if(J)console.log("[PieRoot] UI configuration loaded successfully:",X),console.log("[PieRoot] Rendering UI with configuration");return _i.jsx(Jx.Provider,{value:z0,children:_i.jsx(Kx.Provider,{value:zv(z),children:_i.jsx(mx.Provider,{value:pv(z,Z),children:_i.jsx(ix.Provider,{value:c??_i.jsx(_i.Fragment,{}),children:_i.jsx(mv,{children:_i.jsx(Uv,{children:_i.jsx(Gm.default.StyleRoot,{children:_i.jsx(gi,{uiConfig:X})})})})})})})})},AP=(i)=>{let c=new r1.QueryClient;return _i.jsx(e1.Provider,{value:i.config,children:_i.jsx(r1.QueryClientProvider,{client:c,children:_i.jsx(IP,{...i})})})},Qm=AP;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piedata/pieui",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "A React component library featuring PieCard component",
5
5
  "repository": {
6
6
  "type": "git",