cogsbox-sync 0.0.1
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/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +61 -0
- package/dist/index.d.ts +903 -0
- package/dist/index.js +2755 -0
- package/package.json +36 -0
- package/templates/worker/.editorconfig +12 -0
- package/templates/worker/.prettierrc +6 -0
- package/templates/worker/bin/init.ts +53 -0
- package/templates/worker/package-lock.json +4087 -0
- package/templates/worker/package.json +30 -0
- package/templates/worker/schema-processor/Dockerfile +16 -0
- package/templates/worker/schema-processor/package.json +10 -0
- package/templates/worker/schema-processor/server.js +483 -0
- package/templates/worker/schema-processor/serverOldExpress.js +488 -0
- package/templates/worker/src/UserObject.ts +40 -0
- package/templates/worker/src/auth.ts +58 -0
- package/templates/worker/src/index.ts +1860 -0
- package/templates/worker/src/utility.ts +101 -0
- package/templates/worker/test/index.spec.ts +25 -0
- package/templates/worker/test/tsconfig.json +8 -0
- package/templates/worker/tsconfig.json +46 -0
- package/templates/worker/vitest.config.mts +11 -0
- package/templates/worker/worker-configuration.d.ts +7954 -0
- package/templates/worker/wrangler.jsonc +90 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,2755 @@
|
|
|
1
|
+
// src/useWebsocketConnection.ts
|
|
2
|
+
import { useRef, useCallback, useState, useEffect } from "react";
|
|
3
|
+
var connectionPool = /* @__PURE__ */ new Map();
|
|
4
|
+
function getOrCreateConnectionState(url) {
|
|
5
|
+
if (!connectionPool.has(url)) {
|
|
6
|
+
connectionPool.set(url, {
|
|
7
|
+
socket: null,
|
|
8
|
+
connected: false,
|
|
9
|
+
error: null,
|
|
10
|
+
reconnectAttempts: 0,
|
|
11
|
+
reconnectTimer: null,
|
|
12
|
+
refCount: 0
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return connectionPool.get(url);
|
|
16
|
+
}
|
|
17
|
+
function useWebSocketConnection(config) {
|
|
18
|
+
const [, forceUpdate] = useState({});
|
|
19
|
+
const shouldConnect = config.connect !== false;
|
|
20
|
+
const connectionState = getOrCreateConnectionState(config.url);
|
|
21
|
+
const currentUrlRef = useRef(config.url);
|
|
22
|
+
currentUrlRef.current = config.url;
|
|
23
|
+
const onConnectRef = useRef(config.onConnect);
|
|
24
|
+
const onMessageRef = useRef(config.onMessage);
|
|
25
|
+
const onDisconnectRef = useRef(config.onDisconnect);
|
|
26
|
+
const onErrorRef = useRef(config.onError);
|
|
27
|
+
const onRefreshTokenRef = useRef(config.onRefreshToken);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
onConnectRef.current = config.onConnect;
|
|
30
|
+
onMessageRef.current = config.onMessage;
|
|
31
|
+
onDisconnectRef.current = config.onDisconnect;
|
|
32
|
+
onErrorRef.current = config.onError;
|
|
33
|
+
onRefreshTokenRef.current = config.onRefreshToken;
|
|
34
|
+
});
|
|
35
|
+
const notifySubscribers = useCallback(() => {
|
|
36
|
+
forceUpdate({});
|
|
37
|
+
}, []);
|
|
38
|
+
const connect = useCallback(() => {
|
|
39
|
+
const state = getOrCreateConnectionState(config.url);
|
|
40
|
+
if (state.socket && state.socket.readyState === WebSocket.CLOSED) {
|
|
41
|
+
console.log("[WS] Cleaning up closed socket");
|
|
42
|
+
state.socket = null;
|
|
43
|
+
state.connected = false;
|
|
44
|
+
}
|
|
45
|
+
if (state.socket && (state.socket.readyState === WebSocket.CONNECTING || state.socket.readyState === WebSocket.OPEN)) {
|
|
46
|
+
console.log("[WS] Socket already connecting or connected");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (state.reconnectTimer) {
|
|
50
|
+
clearTimeout(state.reconnectTimer);
|
|
51
|
+
state.reconnectTimer = null;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
console.log(`[WS] Creating new WebSocket connection to ${config.url}`);
|
|
55
|
+
const socket = new WebSocket(config.url);
|
|
56
|
+
state.socket = socket;
|
|
57
|
+
socket.onopen = () => {
|
|
58
|
+
console.log("[WS] Socket opened successfully");
|
|
59
|
+
state.connected = true;
|
|
60
|
+
state.error = null;
|
|
61
|
+
state.reconnectAttempts = 0;
|
|
62
|
+
onConnectRef.current?.(socket);
|
|
63
|
+
notifySubscribers();
|
|
64
|
+
};
|
|
65
|
+
socket.onmessage = (event) => {
|
|
66
|
+
try {
|
|
67
|
+
const data = JSON.parse(event.data);
|
|
68
|
+
onMessageRef.current?.(data, state.socket);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error("Failed to parse message", err);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
socket.onclose = (event) => {
|
|
74
|
+
console.log(
|
|
75
|
+
`[WS] Socket closed - Code: ${event.code}, Reason: ${event.reason}`
|
|
76
|
+
);
|
|
77
|
+
state.connected = false;
|
|
78
|
+
state.socket = null;
|
|
79
|
+
onDisconnectRef.current?.();
|
|
80
|
+
notifySubscribers();
|
|
81
|
+
if (state.refCount > 0 && event.code !== 1e3) {
|
|
82
|
+
const attempts = state.reconnectAttempts || 0;
|
|
83
|
+
if (attempts < (config.maxReconnectAttempts || 5)) {
|
|
84
|
+
const delay = Math.min(1e3 * Math.pow(2, attempts), 1e4);
|
|
85
|
+
console.log(
|
|
86
|
+
`[WS] Scheduling reconnect in ${delay}ms (attempt ${attempts + 1})`
|
|
87
|
+
);
|
|
88
|
+
state.reconnectAttempts = attempts + 1;
|
|
89
|
+
state.reconnectTimer = setTimeout(() => {
|
|
90
|
+
if (state.refCount > 0) {
|
|
91
|
+
connect();
|
|
92
|
+
}
|
|
93
|
+
}, delay);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
socket.onerror = (error) => {
|
|
98
|
+
console.error("[WS] WebSocket error:", error);
|
|
99
|
+
state.error = "Connection error";
|
|
100
|
+
state.connected = false;
|
|
101
|
+
onErrorRef.current?.("Connection error");
|
|
102
|
+
notifySubscribers();
|
|
103
|
+
};
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.error("[WS] Connection error:", err);
|
|
106
|
+
const errorMsg = err instanceof Error ? err.message : "Failed to connect";
|
|
107
|
+
state.error = errorMsg;
|
|
108
|
+
onErrorRef.current?.(errorMsg);
|
|
109
|
+
notifySubscribers();
|
|
110
|
+
if (state.refCount > 0) {
|
|
111
|
+
const attempts = state.reconnectAttempts || 0;
|
|
112
|
+
if (attempts < (config.maxReconnectAttempts || 5)) {
|
|
113
|
+
const delay = Math.min(1e3 * Math.pow(2, attempts), 1e4);
|
|
114
|
+
state.reconnectAttempts = attempts + 1;
|
|
115
|
+
state.reconnectTimer = setTimeout(() => {
|
|
116
|
+
if (state.refCount > 0) {
|
|
117
|
+
connect();
|
|
118
|
+
}
|
|
119
|
+
}, delay);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}, [config.url, config.maxReconnectAttempts, notifySubscribers]);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (!shouldConnect) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const state = getOrCreateConnectionState(config.url);
|
|
129
|
+
state.refCount++;
|
|
130
|
+
if (state.reconnectTimer) {
|
|
131
|
+
clearTimeout(state.reconnectTimer);
|
|
132
|
+
state.reconnectTimer = null;
|
|
133
|
+
}
|
|
134
|
+
if (state.refCount === 1 || !state.socket || state.socket.readyState === WebSocket.CLOSED) {
|
|
135
|
+
console.log(
|
|
136
|
+
`[WS] Connecting to ${config.url} (refCount: ${state.refCount})`
|
|
137
|
+
);
|
|
138
|
+
connect();
|
|
139
|
+
} else if (state.socket && state.socket.readyState === WebSocket.OPEN) {
|
|
140
|
+
console.log(
|
|
141
|
+
`[WS] Reusing existing connection (refCount: ${state.refCount})`
|
|
142
|
+
);
|
|
143
|
+
notifySubscribers();
|
|
144
|
+
}
|
|
145
|
+
return () => {
|
|
146
|
+
const state2 = getOrCreateConnectionState(config.url);
|
|
147
|
+
state2.refCount--;
|
|
148
|
+
console.log(`[WS] Component unmounting (refCount: ${state2.refCount})`);
|
|
149
|
+
if (state2.reconnectTimer) {
|
|
150
|
+
clearTimeout(state2.reconnectTimer);
|
|
151
|
+
state2.reconnectTimer = null;
|
|
152
|
+
}
|
|
153
|
+
if (state2.refCount === 0) {
|
|
154
|
+
state2.reconnectTimer = setTimeout(() => {
|
|
155
|
+
if (state2.refCount === 0) {
|
|
156
|
+
if (state2.socket && (state2.socket.readyState === WebSocket.OPEN || state2.socket.readyState === WebSocket.CONNECTING)) {
|
|
157
|
+
console.log(
|
|
158
|
+
`[WS] Closing connection to ${config.url} due to no more references.`
|
|
159
|
+
);
|
|
160
|
+
state2.socket.close(1e3, "No more references");
|
|
161
|
+
}
|
|
162
|
+
console.log(
|
|
163
|
+
`[WS] Deleting connection state for ${config.url} from the pool.`
|
|
164
|
+
);
|
|
165
|
+
connectionPool.delete(config.url);
|
|
166
|
+
}
|
|
167
|
+
}, 500);
|
|
168
|
+
}
|
|
169
|
+
notifySubscribers();
|
|
170
|
+
};
|
|
171
|
+
}, [config.url, shouldConnect, connect, notifySubscribers]);
|
|
172
|
+
const sendMessage = useCallback(
|
|
173
|
+
(payload) => {
|
|
174
|
+
const state = getOrCreateConnectionState(currentUrlRef.current);
|
|
175
|
+
if (state.socket && state.socket.readyState === WebSocket.OPEN) {
|
|
176
|
+
state.socket.send(JSON.stringify(payload));
|
|
177
|
+
return true;
|
|
178
|
+
} else {
|
|
179
|
+
console.warn("WebSocket not ready, message NOT sent");
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
[]
|
|
184
|
+
// Remove config.url from dependencies since we're using the ref
|
|
185
|
+
);
|
|
186
|
+
const subscribe = useCallback((callback) => {
|
|
187
|
+
return () => {
|
|
188
|
+
};
|
|
189
|
+
}, []);
|
|
190
|
+
return {
|
|
191
|
+
connection: connectionState,
|
|
192
|
+
sendMessage,
|
|
193
|
+
subscribe
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ../../node_modules/.pnpm/cogsbox-shape@0.5.170_zod@4.3.6/node_modules/cogsbox-shape/dist/schema.js
|
|
198
|
+
import { z } from "zod";
|
|
199
|
+
var isFunction = (fn) => typeof fn === "function";
|
|
200
|
+
|
|
201
|
+
// src/SyncProvider.tsx
|
|
202
|
+
import {
|
|
203
|
+
createContext,
|
|
204
|
+
useCallback as useCallback2,
|
|
205
|
+
useContext,
|
|
206
|
+
useEffect as useEffect2,
|
|
207
|
+
useMemo,
|
|
208
|
+
useRef as useRef2,
|
|
209
|
+
useState as useState2
|
|
210
|
+
} from "react";
|
|
211
|
+
|
|
212
|
+
// src/vite/getRefreshtoken.ts
|
|
213
|
+
async function refreshSyncToken({
|
|
214
|
+
refreshToken,
|
|
215
|
+
clientId
|
|
216
|
+
}) {
|
|
217
|
+
const apiToken = import.meta.env.VITE_COGS_SYNC_API_TOKEN;
|
|
218
|
+
const serverUrl = import.meta.env.VITE_COGS_SYNC_SERVER_URL;
|
|
219
|
+
if (!apiToken) return null;
|
|
220
|
+
try {
|
|
221
|
+
const response = await fetch(`${serverUrl}/refresh-token`, {
|
|
222
|
+
method: "POST",
|
|
223
|
+
headers: {
|
|
224
|
+
"Content-Type": "application/json",
|
|
225
|
+
// Use the apiToken from Vite's env
|
|
226
|
+
Authorization: `Bearer ${apiToken}`
|
|
227
|
+
},
|
|
228
|
+
body: JSON.stringify({
|
|
229
|
+
refreshToken,
|
|
230
|
+
clientId
|
|
231
|
+
})
|
|
232
|
+
});
|
|
233
|
+
if (!response.ok) return null;
|
|
234
|
+
const { sessionToken } = await response.json();
|
|
235
|
+
return sessionToken;
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error("Token refresh failed:", error);
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/SyncProvider.tsx
|
|
243
|
+
import { create } from "zustand";
|
|
244
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
245
|
+
var useNotificationStore = create((set, get) => ({
|
|
246
|
+
isConnected: false,
|
|
247
|
+
notificationsByChannel: {},
|
|
248
|
+
channelSubscribers: /* @__PURE__ */ new Map(),
|
|
249
|
+
setConnectionStatus: (status) => set({ isConnected: status }),
|
|
250
|
+
addNotifications: (newNotifications) => {
|
|
251
|
+
set((state) => {
|
|
252
|
+
const updatedChannels = { ...state.notificationsByChannel };
|
|
253
|
+
for (const notification of newNotifications) {
|
|
254
|
+
const channel = notification.channel;
|
|
255
|
+
if (!channel) {
|
|
256
|
+
console.warn("Notification missing channel/type:", notification);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
const existing = updatedChannels[channel] || [];
|
|
260
|
+
updatedChannels[channel] = [...existing, notification.payload];
|
|
261
|
+
const subs = state.channelSubscribers.get(channel);
|
|
262
|
+
if (subs) {
|
|
263
|
+
subs.forEach((cb) => cb([notification.payload]));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return { notificationsByChannel: updatedChannels };
|
|
267
|
+
});
|
|
268
|
+
},
|
|
269
|
+
addSubscriber: (channel, callback) => {
|
|
270
|
+
const subs = get().channelSubscribers.get(channel) || /* @__PURE__ */ new Set();
|
|
271
|
+
subs.add(callback);
|
|
272
|
+
const updated = new Map(get().channelSubscribers);
|
|
273
|
+
updated.set(channel, subs);
|
|
274
|
+
set({ channelSubscribers: updated });
|
|
275
|
+
return () => {
|
|
276
|
+
const copy2 = new Map(get().channelSubscribers);
|
|
277
|
+
const current = copy2.get(channel);
|
|
278
|
+
if (current) {
|
|
279
|
+
current.delete(callback);
|
|
280
|
+
if (current.size === 0) copy2.delete(channel);
|
|
281
|
+
else copy2.set(channel, current);
|
|
282
|
+
set({ channelSubscribers: copy2 });
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
},
|
|
286
|
+
subscribeToPath: (path, callback) => get().addSubscriber(path, callback)
|
|
287
|
+
}));
|
|
288
|
+
var SyncContext = createContext({
|
|
289
|
+
token: null,
|
|
290
|
+
refreshToken: null,
|
|
291
|
+
socketUrl: null,
|
|
292
|
+
clientId: null,
|
|
293
|
+
sessionId: "",
|
|
294
|
+
refreshAccessToken: () => Promise.resolve(null)
|
|
295
|
+
});
|
|
296
|
+
var NotificationContext = createContext({
|
|
297
|
+
subscribe: () => () => {
|
|
298
|
+
},
|
|
299
|
+
isNotificationConnected: false
|
|
300
|
+
});
|
|
301
|
+
function SyncProvider({
|
|
302
|
+
children,
|
|
303
|
+
tokens
|
|
304
|
+
}) {
|
|
305
|
+
const sessionId = useRef2(crypto.randomUUID()).current;
|
|
306
|
+
const {
|
|
307
|
+
sessionToken,
|
|
308
|
+
refreshToken,
|
|
309
|
+
serverUrl: socketUrl,
|
|
310
|
+
clientId
|
|
311
|
+
} = tokens || {};
|
|
312
|
+
const [currentToken, setCurrentToken] = useState2(sessionToken);
|
|
313
|
+
const setConnectionStatus = useNotificationStore(
|
|
314
|
+
(state) => state.setConnectionStatus
|
|
315
|
+
);
|
|
316
|
+
const isNotificationConnected = useNotificationStore(
|
|
317
|
+
(state) => state.isConnected
|
|
318
|
+
);
|
|
319
|
+
const subscriptions = useRef2(
|
|
320
|
+
/* @__PURE__ */ new Map()
|
|
321
|
+
);
|
|
322
|
+
const addNotifications = useNotificationStore(
|
|
323
|
+
(state) => state.addNotifications
|
|
324
|
+
);
|
|
325
|
+
const refreshTokenRef = useRef2(refreshToken);
|
|
326
|
+
const isRefreshing = useRef2(false);
|
|
327
|
+
const refreshAccessToken = useCallback2(async () => {
|
|
328
|
+
if (!refreshTokenRef.current || isRefreshing.current) {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
isRefreshing.current = true;
|
|
332
|
+
try {
|
|
333
|
+
const newToken = await refreshSyncToken({
|
|
334
|
+
refreshToken: refreshTokenRef.current,
|
|
335
|
+
clientId
|
|
336
|
+
});
|
|
337
|
+
if (newToken) {
|
|
338
|
+
setCurrentToken(newToken);
|
|
339
|
+
return newToken;
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
console.error("Token refresh failed:", error);
|
|
344
|
+
return null;
|
|
345
|
+
} finally {
|
|
346
|
+
isRefreshing.current = false;
|
|
347
|
+
}
|
|
348
|
+
}, [clientId]);
|
|
349
|
+
useWebSocketConnection({
|
|
350
|
+
url: clientId && sessionToken ? `${socketUrl}/user-presence/${clientId}?token=${currentToken}&sessionId=${sessionId}` : "",
|
|
351
|
+
connect: Boolean(clientId && currentToken),
|
|
352
|
+
onConnect: (e) => {
|
|
353
|
+
setConnectionStatus(true);
|
|
354
|
+
},
|
|
355
|
+
onDisconnect: () => setConnectionStatus(false),
|
|
356
|
+
onMessage: (data) => {
|
|
357
|
+
if (data.type === "notifications_batch" && Array.isArray(data.payload)) {
|
|
358
|
+
console.log("data.payload ---------------------", data.payload);
|
|
359
|
+
addNotifications(data.payload);
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
const subscribe = useCallback2(
|
|
365
|
+
(channel, callback) => {
|
|
366
|
+
if (!subscriptions.current.has(channel)) {
|
|
367
|
+
subscriptions.current.set(channel, /* @__PURE__ */ new Set());
|
|
368
|
+
}
|
|
369
|
+
subscriptions.current.get(channel).add(callback);
|
|
370
|
+
return () => {
|
|
371
|
+
const callbacks = subscriptions.current.get(channel);
|
|
372
|
+
if (callbacks) {
|
|
373
|
+
callbacks.delete(callback);
|
|
374
|
+
if (callbacks.size === 0) {
|
|
375
|
+
subscriptions.current.delete(channel);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
[]
|
|
381
|
+
);
|
|
382
|
+
const notificationValue = useMemo(
|
|
383
|
+
() => ({
|
|
384
|
+
subscribe,
|
|
385
|
+
isNotificationConnected
|
|
386
|
+
}),
|
|
387
|
+
[subscribe, isNotificationConnected]
|
|
388
|
+
);
|
|
389
|
+
if (!sessionToken || !socketUrl) {
|
|
390
|
+
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
391
|
+
}
|
|
392
|
+
return /* @__PURE__ */ jsx(
|
|
393
|
+
SyncContext.Provider,
|
|
394
|
+
{
|
|
395
|
+
value: {
|
|
396
|
+
token: currentToken,
|
|
397
|
+
refreshToken,
|
|
398
|
+
socketUrl,
|
|
399
|
+
clientId,
|
|
400
|
+
sessionId,
|
|
401
|
+
refreshAccessToken
|
|
402
|
+
},
|
|
403
|
+
children: /* @__PURE__ */ jsx(NotificationContext.Provider, { value: notificationValue, children })
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
function useSync(options) {
|
|
408
|
+
const { token, socketUrl, clientId, sessionId, refreshAccessToken } = useContext(SyncContext);
|
|
409
|
+
const [clientActivity, setClientActivity] = useState2({});
|
|
410
|
+
const currentToken = useRef2(token);
|
|
411
|
+
useEffect2(() => {
|
|
412
|
+
currentToken.current = token;
|
|
413
|
+
}, [token]);
|
|
414
|
+
const determinedSyncId = isFunction(options.stateRoom) ? options.stateRoom({ clientId: clientId ?? "" }) : options.stateRoom;
|
|
415
|
+
const syncIdString = useMemo(() => {
|
|
416
|
+
let baseKey = `${options.stateKey}::${determinedSyncId}`;
|
|
417
|
+
if (options.apiParams && Object.keys(options.apiParams).length > 0) {
|
|
418
|
+
const paramString = Object.entries(options.apiParams).sort(([a2], [b3]) => a2.localeCompare(b3)).map(([key, value]) => `${key}:${value}`).join(",");
|
|
419
|
+
baseKey = `${options.stateKey}[${paramString}]::${determinedSyncId}`;
|
|
420
|
+
}
|
|
421
|
+
return baseKey;
|
|
422
|
+
}, [options.stateKey, determinedSyncId, JSON.stringify(options.apiParams)]);
|
|
423
|
+
const syndIdRef = useRef2(syncIdString);
|
|
424
|
+
syndIdRef.current = syncIdString;
|
|
425
|
+
const subScribers = useRef2([]);
|
|
426
|
+
const isInitialised = useRef2(false);
|
|
427
|
+
const eventHandlers = useRef2({
|
|
428
|
+
onInitialState: null,
|
|
429
|
+
onPatch: null,
|
|
430
|
+
onValidationError: null,
|
|
431
|
+
onStateRequest: null,
|
|
432
|
+
onSubscribersUpdate: null,
|
|
433
|
+
onClientActivity: null
|
|
434
|
+
});
|
|
435
|
+
const isReadyToConnect = Boolean(
|
|
436
|
+
token && socketUrl && sessionId && determinedSyncId
|
|
437
|
+
);
|
|
438
|
+
const { connection, sendMessage } = useWebSocketConnection({
|
|
439
|
+
url: `${socketUrl}/sync/${syndIdRef.current}?token=${currentToken.current}&sessionId=${sessionId}`,
|
|
440
|
+
connect: isReadyToConnect,
|
|
441
|
+
onDisconnect() {
|
|
442
|
+
console.log("useSync WebSocket disconnected");
|
|
443
|
+
isInitialised.current = false;
|
|
444
|
+
},
|
|
445
|
+
onConnect: async () => {
|
|
446
|
+
console.log("useSync WebSocket onConnect");
|
|
447
|
+
sendMessage({
|
|
448
|
+
type: "initialSend",
|
|
449
|
+
syncKey: syncIdString,
|
|
450
|
+
isArray: false,
|
|
451
|
+
inMemoryState: options?.inMemoryState,
|
|
452
|
+
apiParams: options.apiParams
|
|
453
|
+
});
|
|
454
|
+
},
|
|
455
|
+
onMessage: async (data, ws) => {
|
|
456
|
+
switch (data.type) {
|
|
457
|
+
case "auth_failed":
|
|
458
|
+
console.log("auth_failed", data);
|
|
459
|
+
const newToken = await refreshAccessToken();
|
|
460
|
+
if (newToken) {
|
|
461
|
+
currentToken.current = newToken;
|
|
462
|
+
}
|
|
463
|
+
break;
|
|
464
|
+
case "updateInitialState":
|
|
465
|
+
if (data.syncKey === syndIdRef.current) {
|
|
466
|
+
isInitialised.current = true;
|
|
467
|
+
console.log("Received initial state", data);
|
|
468
|
+
eventHandlers.current.onInitialState?.(data.data, data.version);
|
|
469
|
+
}
|
|
470
|
+
break;
|
|
471
|
+
case "requestInitialState":
|
|
472
|
+
if (data.syncKey === syndIdRef.current) {
|
|
473
|
+
const state = eventHandlers.current.onStateRequest?.();
|
|
474
|
+
if (state !== void 0) {
|
|
475
|
+
sendMessage({
|
|
476
|
+
type: "providingInitialState",
|
|
477
|
+
syncKey: syncIdString,
|
|
478
|
+
state
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
break;
|
|
483
|
+
case "clientActivity":
|
|
484
|
+
if (data.syncKey === syndIdRef.current) {
|
|
485
|
+
console.log("Received client activity:", data.activity);
|
|
486
|
+
eventHandlers.current.onClientActivity?.(data.activity);
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
case "subscribers":
|
|
490
|
+
if (data.syncKey === syndIdRef.current) {
|
|
491
|
+
console.log("Received subscriber list:", data.subscribers);
|
|
492
|
+
subScribers.current = data.subscribers;
|
|
493
|
+
eventHandlers.current.onSubscribersUpdate?.(data.subscribers);
|
|
494
|
+
}
|
|
495
|
+
break;
|
|
496
|
+
case "applyPatch":
|
|
497
|
+
if (data.syncKey === syndIdRef.current) {
|
|
498
|
+
console.log("applyPatch", data);
|
|
499
|
+
eventHandlers.current.onPatch?.(
|
|
500
|
+
data.data,
|
|
501
|
+
data.sessionId,
|
|
502
|
+
data.version
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
break;
|
|
506
|
+
case "validationError":
|
|
507
|
+
console.log("Sync validation error:", data.details, data.message);
|
|
508
|
+
eventHandlers.current.onValidationError?.(
|
|
509
|
+
data.details,
|
|
510
|
+
data.sessionId
|
|
511
|
+
);
|
|
512
|
+
break;
|
|
513
|
+
case "syncReady":
|
|
514
|
+
console.log("Sync ready for syncKey:", data.syncKey);
|
|
515
|
+
break;
|
|
516
|
+
case "fetchStateFromDb":
|
|
517
|
+
if (determinedSyncId) {
|
|
518
|
+
sendMessage({
|
|
519
|
+
type: "initialSend",
|
|
520
|
+
syncKey: syncIdString,
|
|
521
|
+
isArray: false,
|
|
522
|
+
inMemoryState: options?.inMemoryState,
|
|
523
|
+
apiParams: options.apiParams
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
break;
|
|
527
|
+
case "error":
|
|
528
|
+
console.error("Sync error:", data);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
useEffect2(() => {
|
|
534
|
+
if (connection.connected && syncIdString && options.apiParams) {
|
|
535
|
+
sendMessage({
|
|
536
|
+
type: "initialSend",
|
|
537
|
+
syncKey: syncIdString,
|
|
538
|
+
isArray: false,
|
|
539
|
+
inMemoryState: options?.inMemoryState,
|
|
540
|
+
apiParams: options.apiParams
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}, [JSON.stringify(options.apiParams), connection.connected]);
|
|
544
|
+
useEffect2(() => {
|
|
545
|
+
if (determinedSyncId && connection.connected && isInitialised.current) {
|
|
546
|
+
sendMessage({
|
|
547
|
+
type: "requestState",
|
|
548
|
+
syncKey: syncIdString
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
}, [determinedSyncId, connection.connected, syncIdString]);
|
|
552
|
+
return {
|
|
553
|
+
sessionId,
|
|
554
|
+
connected: connection.connected,
|
|
555
|
+
clientId,
|
|
556
|
+
subscribers: subScribers.current,
|
|
557
|
+
// Event handler setters
|
|
558
|
+
onInitialState: (handler) => {
|
|
559
|
+
eventHandlers.current.onInitialState = handler;
|
|
560
|
+
},
|
|
561
|
+
onPatch: (handler) => {
|
|
562
|
+
eventHandlers.current.onPatch = handler;
|
|
563
|
+
},
|
|
564
|
+
onValidationError: (handler) => {
|
|
565
|
+
eventHandlers.current.onValidationError = handler;
|
|
566
|
+
},
|
|
567
|
+
onStateRequest: (handler) => {
|
|
568
|
+
eventHandlers.current.onStateRequest = handler;
|
|
569
|
+
},
|
|
570
|
+
onSubscribersUpdate: (handler) => {
|
|
571
|
+
eventHandlers.current.onSubscribersUpdate = handler;
|
|
572
|
+
},
|
|
573
|
+
onClientActivity: (handler) => {
|
|
574
|
+
eventHandlers.current.onClientActivity = handler;
|
|
575
|
+
},
|
|
576
|
+
clientActivity,
|
|
577
|
+
// Actions
|
|
578
|
+
sendUpdate: (operation) => {
|
|
579
|
+
sendMessage({
|
|
580
|
+
type: "queueUpdate",
|
|
581
|
+
data: { operation }
|
|
582
|
+
});
|
|
583
|
+
},
|
|
584
|
+
reportClientActivity: (event) => {
|
|
585
|
+
console.log("reportClientActivity", event);
|
|
586
|
+
sendMessage({
|
|
587
|
+
type: "clientStatus",
|
|
588
|
+
syncKey: syncIdString,
|
|
589
|
+
status: {
|
|
590
|
+
// Create the wrapper object here
|
|
591
|
+
event,
|
|
592
|
+
// <-- Pass the event object directly into a property
|
|
593
|
+
timestamp: Date.now(),
|
|
594
|
+
sessionId
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
},
|
|
598
|
+
requestState: () => {
|
|
599
|
+
sendMessage({
|
|
600
|
+
type: "requestState",
|
|
601
|
+
syncKey: syncIdString
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function useNotifications(channel) {
|
|
607
|
+
const { subscribe, isNotificationConnected } = useContext(NotificationContext);
|
|
608
|
+
let notifications = null;
|
|
609
|
+
return { notifications, isConnected: isNotificationConnected };
|
|
610
|
+
}
|
|
611
|
+
function createNotificationHook(syncSchema) {
|
|
612
|
+
const useSyncNotifications = (type) => {
|
|
613
|
+
const [notifications, setNotifications] = useState2([]);
|
|
614
|
+
const isConnected = useNotificationStore((state) => state.isConnected);
|
|
615
|
+
useEffect2(() => {
|
|
616
|
+
const current = useNotificationStore.getState().notificationsByChannel[type] || [];
|
|
617
|
+
setNotifications(current);
|
|
618
|
+
const unsubscribe = useNotificationStore.getState().addSubscriber(type, (newOnes) => {
|
|
619
|
+
setNotifications(
|
|
620
|
+
(prev) => [...prev, ...newOnes]
|
|
621
|
+
);
|
|
622
|
+
});
|
|
623
|
+
return unsubscribe;
|
|
624
|
+
}, [type]);
|
|
625
|
+
return { notifications, isConnected };
|
|
626
|
+
};
|
|
627
|
+
return { useSyncNotifications };
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/CogsState.js
|
|
631
|
+
import { jsx as H, Fragment as pe } from "react/jsx-runtime";
|
|
632
|
+
|
|
633
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/pluginStore.js
|
|
634
|
+
import { create as l } from "zustand";
|
|
635
|
+
var b = l((u3, o2) => ({
|
|
636
|
+
stateHandlers: /* @__PURE__ */ new Map(),
|
|
637
|
+
registerStateHandler: (e, s2) => u3((n2) => {
|
|
638
|
+
const t = new Map(n2.stateHandlers);
|
|
639
|
+
return t.set(e, s2), console.log("addign handler", e, s2), { stateHandlers: t };
|
|
640
|
+
}),
|
|
641
|
+
registeredPlugins: [],
|
|
642
|
+
pluginOptions: /* @__PURE__ */ new Map(),
|
|
643
|
+
setRegisteredPlugins: (e) => u3({ registeredPlugins: e }),
|
|
644
|
+
setPluginOptionsForState: (e, s2) => u3((n2) => {
|
|
645
|
+
const t = new Map(n2.pluginOptions), r2 = /* @__PURE__ */ new Map();
|
|
646
|
+
return Object.entries(s2).forEach(([i2, p2]) => {
|
|
647
|
+
n2.registeredPlugins.some((a2) => a2.name === i2) && r2.set(i2, p2);
|
|
648
|
+
}), r2.size > 0 && t.set(e, r2), { pluginOptions: t };
|
|
649
|
+
}),
|
|
650
|
+
getPluginConfigsForState: (e) => {
|
|
651
|
+
const s2 = o2(), n2 = s2.pluginOptions.get(e);
|
|
652
|
+
return n2 ? s2.registeredPlugins.map((t) => {
|
|
653
|
+
const r2 = n2.get(t.name);
|
|
654
|
+
return r2 !== void 0 ? { plugin: t, options: r2 } : null;
|
|
655
|
+
}).filter(Boolean) : [];
|
|
656
|
+
},
|
|
657
|
+
updateSubscribers: /* @__PURE__ */ new Set(),
|
|
658
|
+
subscribeToUpdates: (e) => (o2().updateSubscribers.add(e), () => {
|
|
659
|
+
o2().updateSubscribers.delete(e);
|
|
660
|
+
}),
|
|
661
|
+
notifyUpdate: (e) => {
|
|
662
|
+
o2().updateSubscribers.forEach((s2) => s2(e));
|
|
663
|
+
},
|
|
664
|
+
formUpdateSubscribers: /* @__PURE__ */ new Set(),
|
|
665
|
+
subscribeToFormUpdates: (e) => (o2().formUpdateSubscribers.add(e), () => {
|
|
666
|
+
o2().formUpdateSubscribers.delete(e);
|
|
667
|
+
}),
|
|
668
|
+
notifyFormUpdate: (e) => {
|
|
669
|
+
o2().formUpdateSubscribers.forEach((s2) => s2(e));
|
|
670
|
+
},
|
|
671
|
+
hookResults: /* @__PURE__ */ new Map(),
|
|
672
|
+
setHookResult: (e, s2, n2) => u3((t) => {
|
|
673
|
+
const r2 = new Map(t.hookResults), i2 = new Map(r2.get(e) ?? /* @__PURE__ */ new Map());
|
|
674
|
+
return n2 === void 0 ? i2.delete(s2) : i2.set(s2, n2), i2.size > 0 ? r2.set(e, i2) : r2.delete(e), { hookResults: r2 };
|
|
675
|
+
}),
|
|
676
|
+
getHookResult: (e, s2) => o2().hookResults.get(e)?.get(s2),
|
|
677
|
+
removeHookResult: (e, s2) => u3((n2) => {
|
|
678
|
+
const t = new Map(n2.hookResults), r2 = new Map(t.get(e) ?? /* @__PURE__ */ new Map());
|
|
679
|
+
return r2.delete(s2), r2.size > 0 ? t.set(e, r2) : t.delete(e), { hookResults: t };
|
|
680
|
+
})
|
|
681
|
+
}));
|
|
682
|
+
|
|
683
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/CogsState.js
|
|
684
|
+
import { useState as ee, useRef as G, useCallback as Ae, useEffect as q, useLayoutEffect as Me, useMemo as ye, createElement as ue, startTransition as $e } from "react";
|
|
685
|
+
|
|
686
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/utility.js
|
|
687
|
+
var u = (e) => e && typeof e == "object" && !Array.isArray(e) && e !== null;
|
|
688
|
+
var y = (e) => Array.isArray(e);
|
|
689
|
+
var d = (e, n2, i2 = {}, r2 = []) => {
|
|
690
|
+
if (u(e) && u(n2)) {
|
|
691
|
+
const t = Object.keys(e), l3 = Object.keys(n2);
|
|
692
|
+
if (t.length !== l3.length)
|
|
693
|
+
return false;
|
|
694
|
+
for (let s2 of t) {
|
|
695
|
+
const o2 = e[s2], f3 = n2[s2];
|
|
696
|
+
if (!(s2 in e) || !(s2 in n2))
|
|
697
|
+
return false;
|
|
698
|
+
const c = [...r2, s2];
|
|
699
|
+
if (!d(o2, f3, i2, c))
|
|
700
|
+
return false;
|
|
701
|
+
}
|
|
702
|
+
return true;
|
|
703
|
+
} else if (y(e) && y(n2)) {
|
|
704
|
+
if (e.length !== n2.length)
|
|
705
|
+
return false;
|
|
706
|
+
for (let t = 0; t < e.length; t++)
|
|
707
|
+
if (!d(e[t], n2[t], i2, [
|
|
708
|
+
...r2,
|
|
709
|
+
t.toString()
|
|
710
|
+
]))
|
|
711
|
+
return false;
|
|
712
|
+
return true;
|
|
713
|
+
} else
|
|
714
|
+
return e === n2 || Number.isNaN(e) && Number.isNaN(n2);
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/Components.js
|
|
718
|
+
import { jsx as I2, Fragment as U } from "react/jsx-runtime";
|
|
719
|
+
|
|
720
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/plugins.js
|
|
721
|
+
import { z as l2 } from "zod";
|
|
722
|
+
|
|
723
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/store.js
|
|
724
|
+
import { create as A } from "zustand";
|
|
725
|
+
function O(u3, o2 = "zod4") {
|
|
726
|
+
if (!u3) return null;
|
|
727
|
+
let e = u3, t = false, a2 = false, n2, s2 = false;
|
|
728
|
+
for (let l3 = 0; l3 < 20; l3++) {
|
|
729
|
+
const f3 = e?.def || e?._def;
|
|
730
|
+
if (!f3) break;
|
|
731
|
+
const p2 = f3.typeName || f3.type || e._type;
|
|
732
|
+
if (p2 === "ZodUnion" || p2 === "union")
|
|
733
|
+
if (f3.options && f3.options.length > 0) {
|
|
734
|
+
e = f3.options[0];
|
|
735
|
+
continue;
|
|
736
|
+
} else
|
|
737
|
+
break;
|
|
738
|
+
if (p2 === "ZodOptional" || p2 === "optional")
|
|
739
|
+
a2 = true;
|
|
740
|
+
else if (p2 === "ZodNullable" || p2 === "nullable")
|
|
741
|
+
t = true;
|
|
742
|
+
else if (p2 === "ZodDefault" || p2 === "default")
|
|
743
|
+
s2 = true, n2 = typeof f3.defaultValue == "function" ? f3.defaultValue() : f3.defaultValue;
|
|
744
|
+
else if (p2 !== "ZodEffects" && p2 !== "effects")
|
|
745
|
+
break;
|
|
746
|
+
const y2 = f3.innerType || f3.schema || e._inner;
|
|
747
|
+
if (!y2 || y2 === e)
|
|
748
|
+
break;
|
|
749
|
+
e = y2;
|
|
750
|
+
}
|
|
751
|
+
const r2 = e, i2 = r2?.def || r2?._def, c = i2?.typeName || i2?.type || r2?._type;
|
|
752
|
+
return c === "ZodNumber" || c === "number" ? {
|
|
753
|
+
type: "number",
|
|
754
|
+
schema: u3,
|
|
755
|
+
source: o2,
|
|
756
|
+
default: s2 ? n2 : 0,
|
|
757
|
+
nullable: t,
|
|
758
|
+
optional: a2
|
|
759
|
+
} : c === "ZodString" || c === "string" ? {
|
|
760
|
+
type: "string",
|
|
761
|
+
schema: u3,
|
|
762
|
+
source: o2,
|
|
763
|
+
default: s2 ? n2 : "",
|
|
764
|
+
nullable: t,
|
|
765
|
+
optional: a2
|
|
766
|
+
} : c === "ZodBoolean" || c === "boolean" ? {
|
|
767
|
+
type: "boolean",
|
|
768
|
+
schema: u3,
|
|
769
|
+
source: o2,
|
|
770
|
+
default: s2 ? n2 : false,
|
|
771
|
+
nullable: t,
|
|
772
|
+
optional: a2
|
|
773
|
+
} : c === "ZodArray" || c === "array" ? {
|
|
774
|
+
type: "array",
|
|
775
|
+
schema: u3,
|
|
776
|
+
source: o2,
|
|
777
|
+
default: s2 ? n2 : [],
|
|
778
|
+
nullable: t,
|
|
779
|
+
optional: a2
|
|
780
|
+
} : c === "ZodObject" || c === "object" ? {
|
|
781
|
+
type: "object",
|
|
782
|
+
schema: u3,
|
|
783
|
+
source: o2,
|
|
784
|
+
default: s2 ? n2 : {},
|
|
785
|
+
nullable: t,
|
|
786
|
+
optional: a2
|
|
787
|
+
} : c === "ZodDate" || c === "date" ? {
|
|
788
|
+
type: "date",
|
|
789
|
+
schema: u3,
|
|
790
|
+
source: o2,
|
|
791
|
+
default: s2 ? n2 : /* @__PURE__ */ new Date(),
|
|
792
|
+
nullable: t,
|
|
793
|
+
optional: a2
|
|
794
|
+
} : null;
|
|
795
|
+
}
|
|
796
|
+
function E(u3) {
|
|
797
|
+
if (u3 === null)
|
|
798
|
+
return {
|
|
799
|
+
type: "unknown",
|
|
800
|
+
schema: null,
|
|
801
|
+
source: "default",
|
|
802
|
+
default: null,
|
|
803
|
+
nullable: true
|
|
804
|
+
};
|
|
805
|
+
if (u3 === void 0)
|
|
806
|
+
return {
|
|
807
|
+
type: "unknown",
|
|
808
|
+
schema: null,
|
|
809
|
+
source: "default",
|
|
810
|
+
default: void 0,
|
|
811
|
+
optional: true
|
|
812
|
+
};
|
|
813
|
+
const o2 = typeof u3;
|
|
814
|
+
return o2 === "number" ? { type: "number", schema: null, source: "runtime", default: u3 } : o2 === "string" ? { type: "string", schema: null, source: "runtime", default: u3 } : o2 === "boolean" ? { type: "boolean", schema: null, source: "runtime", default: u3 } : Array.isArray(u3) ? { type: "array", schema: null, source: "runtime", default: [] } : u3 instanceof Date ? { type: "date", schema: null, source: "runtime", default: u3 } : o2 === "object" ? { type: "object", schema: null, source: "runtime", default: {} } : { type: "unknown", schema: null, source: "runtime", default: u3 };
|
|
815
|
+
}
|
|
816
|
+
function _(u3, o2, e) {
|
|
817
|
+
if (o2 == null || typeof o2 != "object") {
|
|
818
|
+
const t = { _meta: { value: o2 } };
|
|
819
|
+
return t._meta.typeInfo = I(o2, e), t;
|
|
820
|
+
}
|
|
821
|
+
if (Array.isArray(o2)) {
|
|
822
|
+
const t = { _meta: { arrayKeys: [] } };
|
|
823
|
+
return t._meta.typeInfo = I(o2, e), o2.forEach((a2, n2) => {
|
|
824
|
+
const s2 = M(), r2 = e ? {
|
|
825
|
+
...e,
|
|
826
|
+
path: [...e.path, n2.toString()]
|
|
827
|
+
} : void 0;
|
|
828
|
+
t[s2] = _(u3, a2, r2), t._meta.arrayKeys.push(s2);
|
|
829
|
+
}), t;
|
|
830
|
+
}
|
|
831
|
+
if (o2.constructor === Object) {
|
|
832
|
+
const t = { _meta: {} };
|
|
833
|
+
t._meta.typeInfo = I(o2, e);
|
|
834
|
+
for (const a2 in o2)
|
|
835
|
+
if (Object.prototype.hasOwnProperty.call(o2, a2)) {
|
|
836
|
+
const n2 = e ? {
|
|
837
|
+
...e,
|
|
838
|
+
path: [...e.path, a2]
|
|
839
|
+
} : void 0;
|
|
840
|
+
t[a2] = _(u3, o2[a2], n2);
|
|
841
|
+
}
|
|
842
|
+
return t;
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
_meta: {
|
|
846
|
+
value: o2,
|
|
847
|
+
typeInfo: E(o2)
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
function I(u3, o2) {
|
|
852
|
+
if (o2) {
|
|
853
|
+
let e = null;
|
|
854
|
+
if (o2.schemas.zodV4) {
|
|
855
|
+
const t = o2.path.length === 0 ? o2.schemas.zodV4 : j(o2.schemas.zodV4, o2.path);
|
|
856
|
+
t && (e = O(t, "zod4"));
|
|
857
|
+
}
|
|
858
|
+
if (!e && o2.schemas.zodV3) {
|
|
859
|
+
const t = o2.path.length === 0 ? o2.schemas.zodV3 : j(o2.schemas.zodV3, o2.path);
|
|
860
|
+
t && (e = O(t, "zod3"));
|
|
861
|
+
}
|
|
862
|
+
if (!e && o2.schemas.sync?.[o2.stateKey] && (e = E(u3), e.source = "sync"), e) return e;
|
|
863
|
+
}
|
|
864
|
+
return E(u3);
|
|
865
|
+
}
|
|
866
|
+
function N(u3, o2, e) {
|
|
867
|
+
const t = h.get(u3) || h.get(`[${u3}`);
|
|
868
|
+
if (!t) return;
|
|
869
|
+
function a2(n2, s2) {
|
|
870
|
+
if (!n2 || typeof n2 != "object") return;
|
|
871
|
+
const r2 = j(o2, s2);
|
|
872
|
+
if (r2) {
|
|
873
|
+
const i2 = O(r2, e);
|
|
874
|
+
i2 && (n2._meta || (n2._meta = {}), n2._meta.typeInfo = {
|
|
875
|
+
...i2,
|
|
876
|
+
schema: r2
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
n2._meta?.arrayKeys ? n2._meta.arrayKeys.forEach((i2) => {
|
|
880
|
+
n2[i2] && a2(n2[i2], [...s2, "0"]);
|
|
881
|
+
}) : n2._meta?.hasOwnProperty("value") || Object.keys(n2).forEach((i2) => {
|
|
882
|
+
i2 !== "_meta" && a2(n2[i2], [...s2, i2]);
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
a2(t, []);
|
|
886
|
+
}
|
|
887
|
+
function z2(u3) {
|
|
888
|
+
let o2 = u3;
|
|
889
|
+
for (; o2; ) {
|
|
890
|
+
const e = o2.def || o2._def, t = e?.typeName || e?.type || o2._type;
|
|
891
|
+
if (t === "ZodOptional" || t === "optional" || t === "ZodNullable" || t === "nullable" || t === "ZodDefault" || t === "default" || t === "ZodEffects" || t === "effects")
|
|
892
|
+
o2 = e.innerType || e.schema || o2._inner || o2.unwrap?.();
|
|
893
|
+
else
|
|
894
|
+
break;
|
|
895
|
+
}
|
|
896
|
+
return o2;
|
|
897
|
+
}
|
|
898
|
+
function j(u3, o2) {
|
|
899
|
+
if (!u3) return null;
|
|
900
|
+
if (o2.length === 0) return u3;
|
|
901
|
+
let e = u3;
|
|
902
|
+
for (const t of o2) {
|
|
903
|
+
const a2 = z2(e);
|
|
904
|
+
if (!a2) return null;
|
|
905
|
+
const n2 = a2.def || a2._def, s2 = n2?.typeName || n2?.type || a2._type;
|
|
906
|
+
if (s2 === "ZodObject" || s2 === "object")
|
|
907
|
+
e = (n2?.shape || a2.shape || a2._shape)?.[t];
|
|
908
|
+
else if (s2 === "ZodArray" || s2 === "array")
|
|
909
|
+
e = a2.element || n2?.type;
|
|
910
|
+
else
|
|
911
|
+
return null;
|
|
912
|
+
if (!e)
|
|
913
|
+
return null;
|
|
914
|
+
}
|
|
915
|
+
return e;
|
|
916
|
+
}
|
|
917
|
+
var h = /* @__PURE__ */ new Map();
|
|
918
|
+
var D = 0;
|
|
919
|
+
var V = Date.now().toString(36);
|
|
920
|
+
function M(u3) {
|
|
921
|
+
return `id:local_${V}_${(D++).toString(36)}`;
|
|
922
|
+
}
|
|
923
|
+
var $ = A((u3, o2) => ({
|
|
924
|
+
getPluginMetaDataMap: (e, t) => o2().getShadowMetadata(e, t)?.pluginMetaData,
|
|
925
|
+
setPluginMetaData: (e, t, a2, n2) => {
|
|
926
|
+
const s2 = o2().getShadowMetadata(e, t) || {}, r2 = new Map(s2.pluginMetaData || []), i2 = r2.get(a2) || {};
|
|
927
|
+
r2.set(a2, { ...i2, ...n2 }), o2().setShadowMetadata(e, t, { ...s2, pluginMetaData: r2 }), o2().notifyPathSubscribers([e, ...t].join("."), {
|
|
928
|
+
type: "METADATA_UPDATE"
|
|
929
|
+
});
|
|
930
|
+
},
|
|
931
|
+
removePluginMetaData: (e, t, a2) => {
|
|
932
|
+
const n2 = o2().getShadowMetadata(e, t);
|
|
933
|
+
if (!n2?.pluginMetaData) return;
|
|
934
|
+
const s2 = new Map(n2.pluginMetaData);
|
|
935
|
+
s2.delete(a2), o2().setShadowMetadata(e, t, { ...n2, pluginMetaData: s2 });
|
|
936
|
+
},
|
|
937
|
+
setTransformCache: (e, t, a2, n2) => {
|
|
938
|
+
const s2 = o2().getShadowMetadata(e, t) || {};
|
|
939
|
+
s2.transformCaches || (s2.transformCaches = /* @__PURE__ */ new Map()), s2.transformCaches.set(a2, n2), o2().setShadowMetadata(e, t, {
|
|
940
|
+
transformCaches: s2.transformCaches
|
|
941
|
+
});
|
|
942
|
+
},
|
|
943
|
+
// Replace your entire `initializeAndMergeShadowState` function with this one.
|
|
944
|
+
initializeAndMergeShadowState: (e, t) => {
|
|
945
|
+
const n2 = t?._meta?.arrayKeys !== void 0 ? `[${e}` : e, s2 = h.get(n2) || h.get(e) || h.get(`[${e}`);
|
|
946
|
+
let r2 = {};
|
|
947
|
+
if (s2?._meta) {
|
|
948
|
+
const {
|
|
949
|
+
components: f3,
|
|
950
|
+
features: p2,
|
|
951
|
+
lastServerSync: y2,
|
|
952
|
+
stateSource: m4,
|
|
953
|
+
baseServerState: d3,
|
|
954
|
+
pathComponents: S2,
|
|
955
|
+
signals: b3,
|
|
956
|
+
validation: g2
|
|
957
|
+
} = s2._meta;
|
|
958
|
+
f3 && (r2.components = f3), p2 && (r2.features = p2), y2 && (r2.lastServerSync = y2), m4 && (r2.stateSource = m4), d3 && (r2.baseServerState = d3), S2 && (r2.pathComponents = S2), b3 && (r2.signals = b3), g2 && (r2.validation = g2);
|
|
959
|
+
}
|
|
960
|
+
function i2(f3, p2) {
|
|
961
|
+
if (p2._meta || f3._meta) {
|
|
962
|
+
const d3 = f3._meta || {}, S2 = p2._meta || {}, b3 = { ...d3, ...S2 };
|
|
963
|
+
d3.typeInfo?.schema && !S2.typeInfo?.schema && (b3.typeInfo = d3.typeInfo), d3.validation && !S2.validation && (b3.validation = d3.validation), d3.components && (b3.components = d3.components), f3._meta = b3;
|
|
964
|
+
}
|
|
965
|
+
if (p2._meta?.hasOwnProperty("value")) {
|
|
966
|
+
for (const d3 in f3)
|
|
967
|
+
d3 !== "_meta" && delete f3[d3];
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
const y2 = new Set(
|
|
971
|
+
Object.keys(p2).filter((d3) => d3 !== "_meta")
|
|
972
|
+
), m4 = new Set(
|
|
973
|
+
Object.keys(f3).filter((d3) => d3 !== "_meta")
|
|
974
|
+
);
|
|
975
|
+
for (const d3 of m4)
|
|
976
|
+
y2.has(d3) || delete f3[d3];
|
|
977
|
+
for (const d3 of y2) {
|
|
978
|
+
const S2 = p2[d3], b3 = f3[d3];
|
|
979
|
+
b3 && typeof b3 == "object" && S2 && typeof S2 == "object" ? i2(b3, S2) : f3[d3] = S2;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
s2 ? (i2(s2, t), s2._meta || (s2._meta = {}), Object.assign(s2._meta, r2), h.set(n2, s2)) : (r2 && Object.keys(r2).length > 0 && (t._meta || (t._meta = {}), Object.assign(t._meta, r2)), h.set(n2, t));
|
|
983
|
+
const c = o2().getInitialOptions(e);
|
|
984
|
+
(c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3) && (c.validation?.zodSchemaV4 ? N(e, c.validation.zodSchemaV4, "zod4") : c.validation?.zodSchemaV3 && N(e, c.validation.zodSchemaV3, "zod3")), n2 === e ? h.delete(`[${e}`) : h.delete(e);
|
|
985
|
+
},
|
|
986
|
+
initializeShadowState: (e, t) => {
|
|
987
|
+
const a2 = h.get(e) || h.get(`[${e}`);
|
|
988
|
+
let n2 = {};
|
|
989
|
+
if (a2?._meta) {
|
|
990
|
+
const {
|
|
991
|
+
components: f3,
|
|
992
|
+
features: p2,
|
|
993
|
+
lastServerSync: y2,
|
|
994
|
+
stateSource: m4,
|
|
995
|
+
baseServerState: d3
|
|
996
|
+
} = a2._meta;
|
|
997
|
+
f3 && (n2.components = f3), p2 && (n2.features = p2), y2 && (n2.lastServerSync = y2), m4 && (n2.stateSource = m4), d3 && (n2.baseServerState = d3);
|
|
998
|
+
}
|
|
999
|
+
h.delete(e), h.delete(`[${e}`);
|
|
1000
|
+
const s2 = o2().getInitialOptions(e), r2 = o2().getInitialOptions("__syncSchemas"), i2 = {
|
|
1001
|
+
stateKey: e,
|
|
1002
|
+
path: [],
|
|
1003
|
+
schemas: {
|
|
1004
|
+
sync: r2,
|
|
1005
|
+
zodV4: s2?.validation?.zodSchemaV4,
|
|
1006
|
+
zodV3: s2?.validation?.zodSchemaV3
|
|
1007
|
+
}
|
|
1008
|
+
}, c = _(e, t, i2);
|
|
1009
|
+
c._meta || (c._meta = {}), Object.assign(c._meta, n2);
|
|
1010
|
+
const l3 = Array.isArray(t) ? `[${e}` : e;
|
|
1011
|
+
h.set(l3, c);
|
|
1012
|
+
},
|
|
1013
|
+
getShadowNode: (e, t) => {
|
|
1014
|
+
let a2 = h.get(e) || h.get(`[${e}`);
|
|
1015
|
+
if (a2) {
|
|
1016
|
+
if (t.length === 0) return a2;
|
|
1017
|
+
for (const n2 of t)
|
|
1018
|
+
if (typeof a2 != "object" || a2 === null || (a2 = a2[n2], a2 === void 0)) return;
|
|
1019
|
+
return a2;
|
|
1020
|
+
}
|
|
1021
|
+
},
|
|
1022
|
+
getShadowMetadata: (e, t) => o2().getShadowNode(e, t)?._meta,
|
|
1023
|
+
setShadowMetadata: (e, t, a2) => {
|
|
1024
|
+
const n2 = h.has(`[${e}`) ? `[${e}` : e;
|
|
1025
|
+
let s2 = h.get(n2);
|
|
1026
|
+
if (!s2) {
|
|
1027
|
+
s2 = { _meta: a2 }, h.set(n2, s2);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
let r2 = s2;
|
|
1031
|
+
for (const i2 of t)
|
|
1032
|
+
r2[i2] || (r2[i2] = {}), r2 = r2[i2];
|
|
1033
|
+
r2._meta || (r2._meta = {}), Object.assign(r2._meta, a2);
|
|
1034
|
+
},
|
|
1035
|
+
getShadowValue: (e, t, a2) => {
|
|
1036
|
+
const n2 = o2().getShadowNode(e, t);
|
|
1037
|
+
if (!n2)
|
|
1038
|
+
return;
|
|
1039
|
+
const s2 = {}, r2 = [
|
|
1040
|
+
[n2, s2, "final"]
|
|
1041
|
+
];
|
|
1042
|
+
for (; r2.length > 0; ) {
|
|
1043
|
+
const [i2, c, l3] = r2.pop();
|
|
1044
|
+
if (i2._meta?.hasOwnProperty("value")) {
|
|
1045
|
+
c[l3] = i2._meta.value;
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
if (i2._meta?.arrayKeys) {
|
|
1049
|
+
const y2 = a2 || i2._meta.arrayKeys, m4 = [];
|
|
1050
|
+
c[l3] = m4;
|
|
1051
|
+
for (let d3 = y2.length - 1; d3 >= 0; d3--) {
|
|
1052
|
+
const S2 = y2[d3];
|
|
1053
|
+
i2[S2] && r2.push([i2[S2], m4, d3]);
|
|
1054
|
+
}
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
const f3 = {};
|
|
1058
|
+
c[l3] = f3;
|
|
1059
|
+
const p2 = Object.keys(i2);
|
|
1060
|
+
for (const y2 of p2)
|
|
1061
|
+
y2 !== "_meta" && r2.push([i2[y2], f3, y2]);
|
|
1062
|
+
}
|
|
1063
|
+
return s2.final;
|
|
1064
|
+
},
|
|
1065
|
+
updateShadowAtPath: (e, t, a2) => {
|
|
1066
|
+
const n2 = h.has(`[${e}`) ? `[${e}` : e;
|
|
1067
|
+
let s2 = h.get(n2);
|
|
1068
|
+
if (!s2) return;
|
|
1069
|
+
let r2 = s2;
|
|
1070
|
+
for (let l3 = 0; l3 < t.length - 1; l3++)
|
|
1071
|
+
r2[t[l3]] || (r2[t[l3]] = {}), r2 = r2[t[l3]];
|
|
1072
|
+
const i2 = t.length === 0 ? r2 : r2[t[t.length - 1]];
|
|
1073
|
+
function c(l3, f3, p2) {
|
|
1074
|
+
if (typeof f3 != "object" || f3 === null || f3 instanceof Date) {
|
|
1075
|
+
const m4 = l3._meta || {};
|
|
1076
|
+
for (const d3 in l3)
|
|
1077
|
+
d3 !== "_meta" && delete l3[d3];
|
|
1078
|
+
l3._meta = { ...m4, value: f3 };
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
if (Array.isArray(f3)) {
|
|
1082
|
+
l3._meta || (l3._meta = {}), l3._meta.arrayKeys || (l3._meta.arrayKeys = []);
|
|
1083
|
+
const m4 = l3._meta.arrayKeys, d3 = f3, S2 = [];
|
|
1084
|
+
for (let b3 = 0; b3 < d3.length; b3++) {
|
|
1085
|
+
const g2 = d3[b3];
|
|
1086
|
+
if (b3 < m4.length) {
|
|
1087
|
+
const w3 = m4[b3];
|
|
1088
|
+
c(l3[w3], g2, [
|
|
1089
|
+
...p2,
|
|
1090
|
+
w3
|
|
1091
|
+
]), S2.push(w3);
|
|
1092
|
+
} else {
|
|
1093
|
+
const w3 = M(), K2 = o2().getInitialOptions(e), v = {
|
|
1094
|
+
stateKey: e,
|
|
1095
|
+
path: [...p2, "0"],
|
|
1096
|
+
// Use '0' for array element schema lookup
|
|
1097
|
+
schemas: {
|
|
1098
|
+
zodV4: K2?.validation?.zodSchemaV4,
|
|
1099
|
+
zodV3: K2?.validation?.zodSchemaV3
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
l3[w3] = _(
|
|
1103
|
+
e,
|
|
1104
|
+
g2,
|
|
1105
|
+
v
|
|
1106
|
+
), S2.push(w3);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
m4.length > d3.length && m4.slice(d3.length).forEach((g2) => {
|
|
1110
|
+
delete l3[g2];
|
|
1111
|
+
}), l3._meta.arrayKeys = S2;
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
const y2 = new Set(Object.keys(f3));
|
|
1115
|
+
l3._meta?.hasOwnProperty("value") && delete l3._meta.value;
|
|
1116
|
+
for (const m4 of y2) {
|
|
1117
|
+
const d3 = f3[m4];
|
|
1118
|
+
if (l3[m4])
|
|
1119
|
+
c(l3[m4], d3, [
|
|
1120
|
+
...p2,
|
|
1121
|
+
m4
|
|
1122
|
+
]);
|
|
1123
|
+
else {
|
|
1124
|
+
const S2 = o2().getInitialOptions(e), b3 = {
|
|
1125
|
+
stateKey: e,
|
|
1126
|
+
path: [...p2, m4],
|
|
1127
|
+
schemas: {
|
|
1128
|
+
zodV4: S2?.validation?.zodSchemaV4,
|
|
1129
|
+
zodV3: S2?.validation?.zodSchemaV3
|
|
1130
|
+
}
|
|
1131
|
+
};
|
|
1132
|
+
l3[m4] = _(e, d3, b3);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
for (const m4 in l3)
|
|
1136
|
+
m4 === "_meta" || !Object.prototype.hasOwnProperty.call(l3, m4) || y2.has(m4) || delete l3[m4];
|
|
1137
|
+
}
|
|
1138
|
+
i2 ? c(i2, a2, t) : r2[t[t.length - 1]] = _(e, a2), o2().notifyPathSubscribers([e, ...t].join("."), {
|
|
1139
|
+
type: "UPDATE",
|
|
1140
|
+
newValue: a2
|
|
1141
|
+
});
|
|
1142
|
+
},
|
|
1143
|
+
addItemsToArrayNode: (e, t, a2) => {
|
|
1144
|
+
const n2 = h.has(`[${e}`) ? `[${e}` : e;
|
|
1145
|
+
let s2 = h.get(n2);
|
|
1146
|
+
if (!s2) {
|
|
1147
|
+
console.error("Root not found for state key:", e);
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
let r2 = s2;
|
|
1151
|
+
for (const i2 of t)
|
|
1152
|
+
r2[i2] || (r2[i2] = {}), r2 = r2[i2];
|
|
1153
|
+
Object.assign(r2, a2);
|
|
1154
|
+
},
|
|
1155
|
+
insertShadowArrayElement: (e, t, a2, n2, s2) => {
|
|
1156
|
+
const r2 = o2().getShadowNode(e, t);
|
|
1157
|
+
if (!r2?._meta?.arrayKeys)
|
|
1158
|
+
throw new Error(
|
|
1159
|
+
`Array not found at path: ${[e, ...t].join(".")}`
|
|
1160
|
+
);
|
|
1161
|
+
const i2 = s2 || `${M()}`;
|
|
1162
|
+
r2[i2] = _(e, a2);
|
|
1163
|
+
const c = r2._meta.arrayKeys, l3 = n2 !== void 0 && n2 >= 0 && n2 <= c.length ? n2 : c.length;
|
|
1164
|
+
l3 >= c.length ? c.push(i2) : c.splice(l3, 0, i2);
|
|
1165
|
+
const f3 = [e, ...t].join(".");
|
|
1166
|
+
return o2().notifyPathSubscribers(f3, {
|
|
1167
|
+
type: "INSERT",
|
|
1168
|
+
path: f3,
|
|
1169
|
+
itemKey: `${f3}.${i2}`,
|
|
1170
|
+
index: l3
|
|
1171
|
+
}), i2;
|
|
1172
|
+
},
|
|
1173
|
+
insertManyShadowArrayElements: (e, t, a2, n2) => {
|
|
1174
|
+
if (!a2 || a2.length === 0)
|
|
1175
|
+
return;
|
|
1176
|
+
const s2 = o2().getShadowNode(e, t);
|
|
1177
|
+
if (!s2?._meta?.arrayKeys) {
|
|
1178
|
+
console.error(
|
|
1179
|
+
`Array not found at path: ${[e, ...t].join(".")}`
|
|
1180
|
+
);
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
const r2 = [];
|
|
1184
|
+
a2.forEach((f3) => {
|
|
1185
|
+
const p2 = `${M()}`;
|
|
1186
|
+
r2.push(p2), s2[p2] = _(e, f3);
|
|
1187
|
+
});
|
|
1188
|
+
const i2 = s2._meta.arrayKeys, c = n2 !== void 0 && n2 >= 0 && n2 <= i2.length ? n2 : i2.length;
|
|
1189
|
+
c >= i2.length ? i2.push(...r2) : i2.splice(c, 0, ...r2);
|
|
1190
|
+
const l3 = [e, ...t].join(".");
|
|
1191
|
+
o2().notifyPathSubscribers(l3, {
|
|
1192
|
+
type: "INSERT_MANY",
|
|
1193
|
+
path: l3,
|
|
1194
|
+
count: a2.length,
|
|
1195
|
+
index: c
|
|
1196
|
+
});
|
|
1197
|
+
},
|
|
1198
|
+
removeShadowArrayElement: (e, t) => {
|
|
1199
|
+
if (t.length === 0) return;
|
|
1200
|
+
const a2 = t.slice(0, -1), n2 = t[t.length - 1];
|
|
1201
|
+
if (!n2?.startsWith("id:")) return;
|
|
1202
|
+
const s2 = o2().getShadowNode(e, a2);
|
|
1203
|
+
if (!s2?._meta?.arrayKeys) return;
|
|
1204
|
+
const r2 = s2._meta.arrayKeys, i2 = r2.indexOf(n2);
|
|
1205
|
+
if (i2 === -1) return;
|
|
1206
|
+
i2 === r2.length - 1 ? r2.pop() : i2 === 0 ? r2.shift() : r2.splice(i2, 1), delete s2[n2];
|
|
1207
|
+
const c = [e, ...a2].join(".");
|
|
1208
|
+
o2().notifyPathSubscribers(c, {
|
|
1209
|
+
type: "REMOVE",
|
|
1210
|
+
path: c,
|
|
1211
|
+
itemKey: `${c}.${n2}`
|
|
1212
|
+
});
|
|
1213
|
+
},
|
|
1214
|
+
registerComponent: (e, t, a2) => {
|
|
1215
|
+
const n2 = o2().getShadowMetadata(e, []) || {}, s2 = new Map(n2.components);
|
|
1216
|
+
s2.set(t, a2), o2().setShadowMetadata(e, [], { components: s2 });
|
|
1217
|
+
},
|
|
1218
|
+
unregisterComponent: (e, t) => {
|
|
1219
|
+
const a2 = o2().getShadowMetadata(e, []);
|
|
1220
|
+
if (!a2?.components) return;
|
|
1221
|
+
const n2 = new Map(a2.components);
|
|
1222
|
+
n2.delete(t) && o2().setShadowMetadata(e, [], { components: n2 });
|
|
1223
|
+
},
|
|
1224
|
+
addPathComponent: (e, t, a2) => {
|
|
1225
|
+
const n2 = o2().getShadowMetadata(e, t) || {}, s2 = new Set(n2.pathComponents);
|
|
1226
|
+
s2.add(a2), o2().setShadowMetadata(e, t, {
|
|
1227
|
+
pathComponents: s2
|
|
1228
|
+
});
|
|
1229
|
+
const r2 = o2().getShadowMetadata(e, []);
|
|
1230
|
+
if (r2?.components) {
|
|
1231
|
+
const i2 = r2.components.get(a2);
|
|
1232
|
+
if (i2) {
|
|
1233
|
+
const c = [e, ...t].join("."), l3 = new Set(i2.paths);
|
|
1234
|
+
l3.add(c);
|
|
1235
|
+
const f3 = { ...i2, paths: l3 }, p2 = new Map(r2.components);
|
|
1236
|
+
p2.set(a2, f3), o2().setShadowMetadata(e, [], { components: p2 });
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
},
|
|
1240
|
+
markAsDirty: (e, t, a2 = { bubble: true }) => {
|
|
1241
|
+
let n2 = o2().getShadowNode(e, []);
|
|
1242
|
+
if (!n2) return;
|
|
1243
|
+
let s2 = n2;
|
|
1244
|
+
for (const i2 of t)
|
|
1245
|
+
if (s2 = s2[i2], !s2) return;
|
|
1246
|
+
if (s2._meta || (s2._meta = {}), s2._meta.isDirty = true, !a2.bubble) return;
|
|
1247
|
+
let r2 = n2;
|
|
1248
|
+
for (let i2 = 0; i2 < t.length; i2++) {
|
|
1249
|
+
if (r2._meta?.isDirty)
|
|
1250
|
+
return;
|
|
1251
|
+
r2._meta || (r2._meta = {}), r2._meta.isDirty = true, r2 = r2[t[i2]];
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
// Keep these in Zustand as they need React reactivity
|
|
1255
|
+
serverStateUpdates: /* @__PURE__ */ new Map(),
|
|
1256
|
+
setServerStateUpdate: (e, t) => {
|
|
1257
|
+
u3((a2) => ({
|
|
1258
|
+
serverStateUpdates: new Map(a2.serverStateUpdates).set(
|
|
1259
|
+
e,
|
|
1260
|
+
t
|
|
1261
|
+
)
|
|
1262
|
+
})), o2().notifyPathSubscribers(e, {
|
|
1263
|
+
type: "SERVER_STATE_UPDATE",
|
|
1264
|
+
serverState: t
|
|
1265
|
+
});
|
|
1266
|
+
},
|
|
1267
|
+
pathSubscribers: /* @__PURE__ */ new Map(),
|
|
1268
|
+
subscribeToPath: (e, t) => {
|
|
1269
|
+
const a2 = o2().pathSubscribers, n2 = a2.get(e) || /* @__PURE__ */ new Set();
|
|
1270
|
+
return n2.add(t), a2.set(e, n2), () => {
|
|
1271
|
+
const s2 = o2().pathSubscribers.get(e);
|
|
1272
|
+
s2 && (s2.delete(t), s2.size === 0 && o2().pathSubscribers.delete(e));
|
|
1273
|
+
};
|
|
1274
|
+
},
|
|
1275
|
+
notifyPathSubscribers: (e, t) => {
|
|
1276
|
+
const n2 = o2().pathSubscribers.get(e);
|
|
1277
|
+
n2 && n2.forEach((s2) => s2(t));
|
|
1278
|
+
},
|
|
1279
|
+
selectedIndicesMap: /* @__PURE__ */ new Map(),
|
|
1280
|
+
getSelectedIndex: (e, t) => {
|
|
1281
|
+
const a2 = o2().selectedIndicesMap.get(e);
|
|
1282
|
+
if (!a2) return -1;
|
|
1283
|
+
const n2 = o2().getShadowMetadata(
|
|
1284
|
+
e.split(".")[0],
|
|
1285
|
+
e.split(".").slice(1)
|
|
1286
|
+
), s2 = t || n2?.arrayKeys;
|
|
1287
|
+
return s2 ? s2.indexOf(a2) : -1;
|
|
1288
|
+
},
|
|
1289
|
+
setSelectedIndex: (e, t) => {
|
|
1290
|
+
u3((a2) => {
|
|
1291
|
+
const n2 = new Map(a2.selectedIndicesMap);
|
|
1292
|
+
return t === void 0 ? n2.delete(e) : (n2.has(e) && o2().notifyPathSubscribers(n2.get(e), {
|
|
1293
|
+
type: "THIS_UNSELECTED"
|
|
1294
|
+
}), n2.set(e, t), o2().notifyPathSubscribers(t, { type: "THIS_SELECTED" })), o2().notifyPathSubscribers(e, { type: "GET_SELECTED" }), {
|
|
1295
|
+
...a2,
|
|
1296
|
+
selectedIndicesMap: n2
|
|
1297
|
+
};
|
|
1298
|
+
});
|
|
1299
|
+
},
|
|
1300
|
+
clearSelectedIndex: ({ arrayKey: e }) => {
|
|
1301
|
+
u3((t) => {
|
|
1302
|
+
const a2 = new Map(t.selectedIndicesMap), n2 = a2.get(e);
|
|
1303
|
+
return n2 && o2().notifyPathSubscribers(n2, {
|
|
1304
|
+
type: "CLEAR_SELECTION"
|
|
1305
|
+
}), a2.delete(e), o2().notifyPathSubscribers(e, {
|
|
1306
|
+
type: "CLEAR_SELECTION"
|
|
1307
|
+
}), {
|
|
1308
|
+
...t,
|
|
1309
|
+
selectedIndicesMap: a2
|
|
1310
|
+
};
|
|
1311
|
+
});
|
|
1312
|
+
},
|
|
1313
|
+
clearSelectedIndexesForState: (e) => {
|
|
1314
|
+
u3((t) => {
|
|
1315
|
+
const a2 = new Map(t.selectedIndicesMap);
|
|
1316
|
+
let n2 = false;
|
|
1317
|
+
for (const s2 of a2.keys())
|
|
1318
|
+
(s2 === e || s2.startsWith(e + ".")) && (a2.delete(s2), n2 = true);
|
|
1319
|
+
return n2 ? { selectedIndicesMap: a2 } : {};
|
|
1320
|
+
});
|
|
1321
|
+
},
|
|
1322
|
+
initialStateOptions: {},
|
|
1323
|
+
stateLog: /* @__PURE__ */ new Map(),
|
|
1324
|
+
initialStateGlobal: {},
|
|
1325
|
+
addStateLog: (e) => {
|
|
1326
|
+
!e || e.length === 0 || u3((t) => {
|
|
1327
|
+
const a2 = new Map(t.stateLog), n2 = /* @__PURE__ */ new Map();
|
|
1328
|
+
for (const s2 of e) {
|
|
1329
|
+
const r2 = n2.get(s2.stateKey) || [];
|
|
1330
|
+
r2.push(s2), n2.set(s2.stateKey, r2);
|
|
1331
|
+
}
|
|
1332
|
+
for (const [s2, r2] of n2.entries()) {
|
|
1333
|
+
const i2 = new Map(a2.get(s2));
|
|
1334
|
+
for (const c of r2)
|
|
1335
|
+
i2.set(JSON.stringify(c.path), { ...c });
|
|
1336
|
+
a2.set(s2, i2);
|
|
1337
|
+
}
|
|
1338
|
+
return { stateLog: a2 };
|
|
1339
|
+
});
|
|
1340
|
+
},
|
|
1341
|
+
getInitialOptions: (e) => o2().initialStateOptions[e],
|
|
1342
|
+
setInitialStateOptions: (e, t) => {
|
|
1343
|
+
u3((a2) => ({
|
|
1344
|
+
initialStateOptions: { ...a2.initialStateOptions, [e]: t }
|
|
1345
|
+
}));
|
|
1346
|
+
},
|
|
1347
|
+
updateInitialStateGlobal: (e, t) => {
|
|
1348
|
+
u3((a2) => ({
|
|
1349
|
+
initialStateGlobal: { ...a2.initialStateGlobal, [e]: t }
|
|
1350
|
+
}));
|
|
1351
|
+
},
|
|
1352
|
+
syncInfoStore: /* @__PURE__ */ new Map(),
|
|
1353
|
+
setSyncInfo: (e, t) => u3((a2) => {
|
|
1354
|
+
const n2 = new Map(a2.syncInfoStore);
|
|
1355
|
+
return n2.set(e, t), { syncInfoStore: n2 };
|
|
1356
|
+
}),
|
|
1357
|
+
getSyncInfo: (e) => o2().syncInfoStore.get(e) || null
|
|
1358
|
+
}));
|
|
1359
|
+
|
|
1360
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/plugins.js
|
|
1361
|
+
var f = () => l2.object({
|
|
1362
|
+
__key: l2.literal("keyed"),
|
|
1363
|
+
map: l2.any()
|
|
1364
|
+
});
|
|
1365
|
+
function m(e) {
|
|
1366
|
+
return {
|
|
1367
|
+
initialiseState: (t) => {
|
|
1368
|
+
e.$update(t);
|
|
1369
|
+
},
|
|
1370
|
+
initialiseShadowState: (t) => {
|
|
1371
|
+
e.$initializeAndMergeShadowState(t);
|
|
1372
|
+
},
|
|
1373
|
+
applyOperation: (t, a2) => e.$applyOperation(t, a2),
|
|
1374
|
+
addZodErrors: (t) => e.$addZodValidation(t),
|
|
1375
|
+
getState: () => e.$get(),
|
|
1376
|
+
setOptions: (t) => {
|
|
1377
|
+
e.$setOptions(t);
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
function S(e, t) {
|
|
1382
|
+
return {
|
|
1383
|
+
getPluginMetaData: () => $.getState().getPluginMetaDataMap(e, [])?.get(t),
|
|
1384
|
+
setPluginMetaData: (a2) => $.getState().setPluginMetaData(e, [], t, a2),
|
|
1385
|
+
removePluginMetaData: () => $.getState().removePluginMetaData(e, [], t),
|
|
1386
|
+
getFieldMetaData: (a2) => $.getState().getPluginMetaDataMap(e, a2)?.get(t),
|
|
1387
|
+
setFieldMetaData: (a2, i2) => $.getState().setPluginMetaData(e, a2, t, i2),
|
|
1388
|
+
removeFieldMetaData: (a2) => $.getState().removePluginMetaData(e, a2, t)
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
function O2(e, t, a2) {
|
|
1392
|
+
const i2 = S(
|
|
1393
|
+
e,
|
|
1394
|
+
t
|
|
1395
|
+
);
|
|
1396
|
+
return {
|
|
1397
|
+
// Return the global methods for plugin metadata
|
|
1398
|
+
...i2,
|
|
1399
|
+
// Override the field methods with new, path-scoped versions
|
|
1400
|
+
getFieldMetaData: () => i2.getFieldMetaData(a2),
|
|
1401
|
+
setFieldMetaData: (n2) => i2.setFieldMetaData(a2, n2),
|
|
1402
|
+
removeFieldMetaData: () => i2.removeFieldMetaData(a2)
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
function b2(e) {
|
|
1406
|
+
function t(a2) {
|
|
1407
|
+
const i2 = (o2, r2, g2, c) => ({
|
|
1408
|
+
name: a2,
|
|
1409
|
+
useHook: o2,
|
|
1410
|
+
transformState: r2,
|
|
1411
|
+
onUpdate: g2,
|
|
1412
|
+
onFormUpdate: c
|
|
1413
|
+
});
|
|
1414
|
+
function n2(o2, r2, g2, c) {
|
|
1415
|
+
const D2 = i2(
|
|
1416
|
+
o2,
|
|
1417
|
+
r2,
|
|
1418
|
+
g2,
|
|
1419
|
+
c
|
|
1420
|
+
), s2 = {};
|
|
1421
|
+
return r2 || (s2.transformState = (M3) => n2(o2, M3, g2, c)), g2 || (s2.onUpdate = (M3) => n2(o2, r2, M3, c)), c || (s2.onFormUpdate = (M3) => n2(
|
|
1422
|
+
o2,
|
|
1423
|
+
r2,
|
|
1424
|
+
g2,
|
|
1425
|
+
M3
|
|
1426
|
+
)), Object.assign(D2, s2);
|
|
1427
|
+
}
|
|
1428
|
+
return Object.assign(
|
|
1429
|
+
n2(),
|
|
1430
|
+
{
|
|
1431
|
+
useHook(o2) {
|
|
1432
|
+
return n2(o2);
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
return { createPlugin: t };
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/Components.js
|
|
1441
|
+
import O3, { memo as $2, useState as E2, useRef as P, useCallback as N2, useEffect as W, useLayoutEffect as Q, useMemo as X } from "react";
|
|
1442
|
+
|
|
1443
|
+
// ../../node_modules/.pnpm/react-intersection-observer@9.16.0_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/react-intersection-observer/dist/index.mjs
|
|
1444
|
+
import * as React from "react";
|
|
1445
|
+
import * as React2 from "react";
|
|
1446
|
+
var observerMap = /* @__PURE__ */ new Map();
|
|
1447
|
+
var RootIds = /* @__PURE__ */ new WeakMap();
|
|
1448
|
+
var rootId = 0;
|
|
1449
|
+
var unsupportedValue = void 0;
|
|
1450
|
+
function getRootId(root) {
|
|
1451
|
+
if (!root) return "0";
|
|
1452
|
+
if (RootIds.has(root)) return RootIds.get(root);
|
|
1453
|
+
rootId += 1;
|
|
1454
|
+
RootIds.set(root, rootId.toString());
|
|
1455
|
+
return RootIds.get(root);
|
|
1456
|
+
}
|
|
1457
|
+
function optionsToId(options) {
|
|
1458
|
+
return Object.keys(options).sort().filter(
|
|
1459
|
+
(key) => options[key] !== void 0
|
|
1460
|
+
).map((key) => {
|
|
1461
|
+
return `${key}_${key === "root" ? getRootId(options.root) : options[key]}`;
|
|
1462
|
+
}).toString();
|
|
1463
|
+
}
|
|
1464
|
+
function createObserver(options) {
|
|
1465
|
+
const id = optionsToId(options);
|
|
1466
|
+
let instance = observerMap.get(id);
|
|
1467
|
+
if (!instance) {
|
|
1468
|
+
const elements = /* @__PURE__ */ new Map();
|
|
1469
|
+
let thresholds;
|
|
1470
|
+
const observer = new IntersectionObserver((entries) => {
|
|
1471
|
+
entries.forEach((entry) => {
|
|
1472
|
+
var _a;
|
|
1473
|
+
const inView = entry.isIntersecting && thresholds.some((threshold) => entry.intersectionRatio >= threshold);
|
|
1474
|
+
if (options.trackVisibility && typeof entry.isVisible === "undefined") {
|
|
1475
|
+
entry.isVisible = inView;
|
|
1476
|
+
}
|
|
1477
|
+
(_a = elements.get(entry.target)) == null ? void 0 : _a.forEach((callback) => {
|
|
1478
|
+
callback(inView, entry);
|
|
1479
|
+
});
|
|
1480
|
+
});
|
|
1481
|
+
}, options);
|
|
1482
|
+
thresholds = observer.thresholds || (Array.isArray(options.threshold) ? options.threshold : [options.threshold || 0]);
|
|
1483
|
+
instance = {
|
|
1484
|
+
id,
|
|
1485
|
+
observer,
|
|
1486
|
+
elements
|
|
1487
|
+
};
|
|
1488
|
+
observerMap.set(id, instance);
|
|
1489
|
+
}
|
|
1490
|
+
return instance;
|
|
1491
|
+
}
|
|
1492
|
+
function observe(element, callback, options = {}, fallbackInView = unsupportedValue) {
|
|
1493
|
+
if (typeof window.IntersectionObserver === "undefined" && fallbackInView !== void 0) {
|
|
1494
|
+
const bounds = element.getBoundingClientRect();
|
|
1495
|
+
callback(fallbackInView, {
|
|
1496
|
+
isIntersecting: fallbackInView,
|
|
1497
|
+
target: element,
|
|
1498
|
+
intersectionRatio: typeof options.threshold === "number" ? options.threshold : 0,
|
|
1499
|
+
time: 0,
|
|
1500
|
+
boundingClientRect: bounds,
|
|
1501
|
+
intersectionRect: bounds,
|
|
1502
|
+
rootBounds: bounds
|
|
1503
|
+
});
|
|
1504
|
+
return () => {
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
const { id, observer, elements } = createObserver(options);
|
|
1508
|
+
const callbacks = elements.get(element) || [];
|
|
1509
|
+
if (!elements.has(element)) {
|
|
1510
|
+
elements.set(element, callbacks);
|
|
1511
|
+
}
|
|
1512
|
+
callbacks.push(callback);
|
|
1513
|
+
observer.observe(element);
|
|
1514
|
+
return function unobserve() {
|
|
1515
|
+
callbacks.splice(callbacks.indexOf(callback), 1);
|
|
1516
|
+
if (callbacks.length === 0) {
|
|
1517
|
+
elements.delete(element);
|
|
1518
|
+
observer.unobserve(element);
|
|
1519
|
+
}
|
|
1520
|
+
if (elements.size === 0) {
|
|
1521
|
+
observer.disconnect();
|
|
1522
|
+
observerMap.delete(id);
|
|
1523
|
+
}
|
|
1524
|
+
};
|
|
1525
|
+
}
|
|
1526
|
+
function useInView({
|
|
1527
|
+
threshold,
|
|
1528
|
+
delay,
|
|
1529
|
+
trackVisibility,
|
|
1530
|
+
rootMargin,
|
|
1531
|
+
root,
|
|
1532
|
+
triggerOnce,
|
|
1533
|
+
skip,
|
|
1534
|
+
initialInView,
|
|
1535
|
+
fallbackInView,
|
|
1536
|
+
onChange
|
|
1537
|
+
} = {}) {
|
|
1538
|
+
var _a;
|
|
1539
|
+
const [ref, setRef] = React2.useState(null);
|
|
1540
|
+
const callback = React2.useRef(onChange);
|
|
1541
|
+
const [state, setState] = React2.useState({
|
|
1542
|
+
inView: !!initialInView,
|
|
1543
|
+
entry: void 0
|
|
1544
|
+
});
|
|
1545
|
+
callback.current = onChange;
|
|
1546
|
+
React2.useEffect(
|
|
1547
|
+
() => {
|
|
1548
|
+
if (skip || !ref) return;
|
|
1549
|
+
let unobserve;
|
|
1550
|
+
unobserve = observe(
|
|
1551
|
+
ref,
|
|
1552
|
+
(inView, entry) => {
|
|
1553
|
+
setState({
|
|
1554
|
+
inView,
|
|
1555
|
+
entry
|
|
1556
|
+
});
|
|
1557
|
+
if (callback.current) callback.current(inView, entry);
|
|
1558
|
+
if (entry.isIntersecting && triggerOnce && unobserve) {
|
|
1559
|
+
unobserve();
|
|
1560
|
+
unobserve = void 0;
|
|
1561
|
+
}
|
|
1562
|
+
},
|
|
1563
|
+
{
|
|
1564
|
+
root,
|
|
1565
|
+
rootMargin,
|
|
1566
|
+
threshold,
|
|
1567
|
+
// @ts-ignore
|
|
1568
|
+
trackVisibility,
|
|
1569
|
+
// @ts-ignore
|
|
1570
|
+
delay
|
|
1571
|
+
},
|
|
1572
|
+
fallbackInView
|
|
1573
|
+
);
|
|
1574
|
+
return () => {
|
|
1575
|
+
if (unobserve) {
|
|
1576
|
+
unobserve();
|
|
1577
|
+
}
|
|
1578
|
+
};
|
|
1579
|
+
},
|
|
1580
|
+
// We break the rule here, because we aren't including the actual `threshold` variable
|
|
1581
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1582
|
+
[
|
|
1583
|
+
// If the threshold is an array, convert it to a string, so it won't change between renders.
|
|
1584
|
+
Array.isArray(threshold) ? threshold.toString() : threshold,
|
|
1585
|
+
ref,
|
|
1586
|
+
root,
|
|
1587
|
+
rootMargin,
|
|
1588
|
+
triggerOnce,
|
|
1589
|
+
skip,
|
|
1590
|
+
trackVisibility,
|
|
1591
|
+
fallbackInView,
|
|
1592
|
+
delay
|
|
1593
|
+
]
|
|
1594
|
+
);
|
|
1595
|
+
const entryTarget = (_a = state.entry) == null ? void 0 : _a.target;
|
|
1596
|
+
const previousEntryTarget = React2.useRef(void 0);
|
|
1597
|
+
if (!ref && entryTarget && !triggerOnce && !skip && previousEntryTarget.current !== entryTarget) {
|
|
1598
|
+
previousEntryTarget.current = entryTarget;
|
|
1599
|
+
setState({
|
|
1600
|
+
inView: !!initialInView,
|
|
1601
|
+
entry: void 0
|
|
1602
|
+
});
|
|
1603
|
+
}
|
|
1604
|
+
const result = [setRef, state.inView, state.entry];
|
|
1605
|
+
result.ref = result[0];
|
|
1606
|
+
result.inView = result[1];
|
|
1607
|
+
result.entry = result[2];
|
|
1608
|
+
return result;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/Components.js
|
|
1612
|
+
var {
|
|
1613
|
+
getInitialOptions: V2,
|
|
1614
|
+
getShadowMetadata: gt,
|
|
1615
|
+
setShadowMetadata: ft,
|
|
1616
|
+
getShadowValue: z3,
|
|
1617
|
+
registerComponent: K,
|
|
1618
|
+
unregisterComponent: tt,
|
|
1619
|
+
notifyPathSubscribers: pt,
|
|
1620
|
+
subscribeToPath: et
|
|
1621
|
+
} = $.getState();
|
|
1622
|
+
var { stateHandlers: St, notifyFormUpdate: L } = b.getState();
|
|
1623
|
+
var vt = $2(
|
|
1624
|
+
ot,
|
|
1625
|
+
(e, t) => e.itemPath.join(".") === t.itemPath.join(".") && e.stateKey === t.stateKey && e.itemComponentId === t.itemComponentId && e.localIndex === t.localIndex
|
|
1626
|
+
);
|
|
1627
|
+
function ot({
|
|
1628
|
+
stateKey: e,
|
|
1629
|
+
itemComponentId: t,
|
|
1630
|
+
itemPath: o2,
|
|
1631
|
+
localIndex: c,
|
|
1632
|
+
arraySetter: p2,
|
|
1633
|
+
rebuildStateShape: S2,
|
|
1634
|
+
renderFn: i2
|
|
1635
|
+
}) {
|
|
1636
|
+
const [, u3] = E2({}), { ref: m4, inView: M3 } = useInView(), D2 = P(null), r2 = [e, ...o2].join(".");
|
|
1637
|
+
B(e, t, u3);
|
|
1638
|
+
const l3 = N2(
|
|
1639
|
+
(s2) => {
|
|
1640
|
+
D2.current = s2, m4(s2);
|
|
1641
|
+
},
|
|
1642
|
+
[m4]
|
|
1643
|
+
);
|
|
1644
|
+
W(() => {
|
|
1645
|
+
const s2 = et(r2, (T2) => {
|
|
1646
|
+
u3({});
|
|
1647
|
+
});
|
|
1648
|
+
return () => s2();
|
|
1649
|
+
}, [r2]);
|
|
1650
|
+
const a2 = z3(e, o2);
|
|
1651
|
+
if (a2 === void 0) return null;
|
|
1652
|
+
const A3 = S2({
|
|
1653
|
+
currentState: a2,
|
|
1654
|
+
path: o2,
|
|
1655
|
+
componentId: t
|
|
1656
|
+
}), g2 = i2(A3, c, p2);
|
|
1657
|
+
return O3.isValidElement(g2) ? O3.cloneElement(g2, {
|
|
1658
|
+
ref: (s2) => {
|
|
1659
|
+
l3(s2);
|
|
1660
|
+
const { ref: T2 } = g2;
|
|
1661
|
+
typeof T2 == "function" ? T2(s2) : T2 && "current" in T2 && (T2.current = s2);
|
|
1662
|
+
}
|
|
1663
|
+
}) : /* @__PURE__ */ I2("div", { ref: l3, children: g2 });
|
|
1664
|
+
}
|
|
1665
|
+
function B(e, t, o2) {
|
|
1666
|
+
const c = `${e}////${t}`;
|
|
1667
|
+
Q(() => (K(e, c, {
|
|
1668
|
+
forceUpdate: () => o2({}),
|
|
1669
|
+
paths: /* @__PURE__ */ new Set(),
|
|
1670
|
+
reactiveType: ["component"]
|
|
1671
|
+
}), () => {
|
|
1672
|
+
tt(e, c);
|
|
1673
|
+
}), [e, c]);
|
|
1674
|
+
}
|
|
1675
|
+
$2(function({
|
|
1676
|
+
children: t,
|
|
1677
|
+
stateKey: o2,
|
|
1678
|
+
path: c,
|
|
1679
|
+
pluginName: p2,
|
|
1680
|
+
wrapperDepth: S2
|
|
1681
|
+
}) {
|
|
1682
|
+
const [, i2] = E2({});
|
|
1683
|
+
W(() => {
|
|
1684
|
+
const A3 = [o2, ...c].join(".");
|
|
1685
|
+
return $.getState().subscribeToPath(A3, () => {
|
|
1686
|
+
i2({});
|
|
1687
|
+
});
|
|
1688
|
+
}, [o2, c]);
|
|
1689
|
+
const u3 = b.getState().registeredPlugins.find((A3) => A3.name === p2), m4 = b.getState().stateHandlers.get(o2), M3 = $.getState().getShadowNode(o2, c)?._meta?.typeInfo, D2 = b.getState().pluginOptions.get(o2)?.get(p2), r2 = b.getState().getHookResult(o2, p2);
|
|
1690
|
+
if (!u3?.formWrapper || !m4)
|
|
1691
|
+
return /* @__PURE__ */ I2(U, { children: t });
|
|
1692
|
+
const l3 = m(m4), a2 = O2(
|
|
1693
|
+
o2,
|
|
1694
|
+
u3.name,
|
|
1695
|
+
c
|
|
1696
|
+
);
|
|
1697
|
+
return u3.formWrapper({
|
|
1698
|
+
element: t,
|
|
1699
|
+
path: c,
|
|
1700
|
+
stateKey: o2,
|
|
1701
|
+
pluginName: u3.name,
|
|
1702
|
+
...l3,
|
|
1703
|
+
...a2,
|
|
1704
|
+
options: D2,
|
|
1705
|
+
hookData: r2,
|
|
1706
|
+
fieldType: M3?.type,
|
|
1707
|
+
wrapperDepth: S2
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1711
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/double-indexed-kv.js
|
|
1712
|
+
var DoubleIndexedKV = class {
|
|
1713
|
+
constructor() {
|
|
1714
|
+
this.keyToValue = /* @__PURE__ */ new Map();
|
|
1715
|
+
this.valueToKey = /* @__PURE__ */ new Map();
|
|
1716
|
+
}
|
|
1717
|
+
set(key, value) {
|
|
1718
|
+
this.keyToValue.set(key, value);
|
|
1719
|
+
this.valueToKey.set(value, key);
|
|
1720
|
+
}
|
|
1721
|
+
getByKey(key) {
|
|
1722
|
+
return this.keyToValue.get(key);
|
|
1723
|
+
}
|
|
1724
|
+
getByValue(value) {
|
|
1725
|
+
return this.valueToKey.get(value);
|
|
1726
|
+
}
|
|
1727
|
+
clear() {
|
|
1728
|
+
this.keyToValue.clear();
|
|
1729
|
+
this.valueToKey.clear();
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
|
|
1733
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/registry.js
|
|
1734
|
+
var Registry = class {
|
|
1735
|
+
constructor(generateIdentifier) {
|
|
1736
|
+
this.generateIdentifier = generateIdentifier;
|
|
1737
|
+
this.kv = new DoubleIndexedKV();
|
|
1738
|
+
}
|
|
1739
|
+
register(value, identifier) {
|
|
1740
|
+
if (this.kv.getByValue(value)) {
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
if (!identifier) {
|
|
1744
|
+
identifier = this.generateIdentifier(value);
|
|
1745
|
+
}
|
|
1746
|
+
this.kv.set(identifier, value);
|
|
1747
|
+
}
|
|
1748
|
+
clear() {
|
|
1749
|
+
this.kv.clear();
|
|
1750
|
+
}
|
|
1751
|
+
getIdentifier(value) {
|
|
1752
|
+
return this.kv.getByValue(value);
|
|
1753
|
+
}
|
|
1754
|
+
getValue(identifier) {
|
|
1755
|
+
return this.kv.getByKey(identifier);
|
|
1756
|
+
}
|
|
1757
|
+
};
|
|
1758
|
+
|
|
1759
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/class-registry.js
|
|
1760
|
+
var ClassRegistry = class extends Registry {
|
|
1761
|
+
constructor() {
|
|
1762
|
+
super((c) => c.name);
|
|
1763
|
+
this.classToAllowedProps = /* @__PURE__ */ new Map();
|
|
1764
|
+
}
|
|
1765
|
+
register(value, options) {
|
|
1766
|
+
if (typeof options === "object") {
|
|
1767
|
+
if (options.allowProps) {
|
|
1768
|
+
this.classToAllowedProps.set(value, options.allowProps);
|
|
1769
|
+
}
|
|
1770
|
+
super.register(value, options.identifier);
|
|
1771
|
+
} else {
|
|
1772
|
+
super.register(value, options);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
getAllowedProps(value) {
|
|
1776
|
+
return this.classToAllowedProps.get(value);
|
|
1777
|
+
}
|
|
1778
|
+
};
|
|
1779
|
+
|
|
1780
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/util.js
|
|
1781
|
+
function valuesOfObj(record) {
|
|
1782
|
+
if ("values" in Object) {
|
|
1783
|
+
return Object.values(record);
|
|
1784
|
+
}
|
|
1785
|
+
const values = [];
|
|
1786
|
+
for (const key in record) {
|
|
1787
|
+
if (record.hasOwnProperty(key)) {
|
|
1788
|
+
values.push(record[key]);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
return values;
|
|
1792
|
+
}
|
|
1793
|
+
function find(record, predicate) {
|
|
1794
|
+
const values = valuesOfObj(record);
|
|
1795
|
+
if ("find" in values) {
|
|
1796
|
+
return values.find(predicate);
|
|
1797
|
+
}
|
|
1798
|
+
const valuesNotNever = values;
|
|
1799
|
+
for (let i2 = 0; i2 < valuesNotNever.length; i2++) {
|
|
1800
|
+
const value = valuesNotNever[i2];
|
|
1801
|
+
if (predicate(value)) {
|
|
1802
|
+
return value;
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
return void 0;
|
|
1806
|
+
}
|
|
1807
|
+
function forEach(record, run) {
|
|
1808
|
+
Object.entries(record).forEach(([key, value]) => run(value, key));
|
|
1809
|
+
}
|
|
1810
|
+
function includes(arr, value) {
|
|
1811
|
+
return arr.indexOf(value) !== -1;
|
|
1812
|
+
}
|
|
1813
|
+
function findArr(record, predicate) {
|
|
1814
|
+
for (let i2 = 0; i2 < record.length; i2++) {
|
|
1815
|
+
const value = record[i2];
|
|
1816
|
+
if (predicate(value)) {
|
|
1817
|
+
return value;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
return void 0;
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/custom-transformer-registry.js
|
|
1824
|
+
var CustomTransformerRegistry = class {
|
|
1825
|
+
constructor() {
|
|
1826
|
+
this.transfomers = {};
|
|
1827
|
+
}
|
|
1828
|
+
register(transformer) {
|
|
1829
|
+
this.transfomers[transformer.name] = transformer;
|
|
1830
|
+
}
|
|
1831
|
+
findApplicable(v) {
|
|
1832
|
+
return find(this.transfomers, (transformer) => transformer.isApplicable(v));
|
|
1833
|
+
}
|
|
1834
|
+
findByName(name) {
|
|
1835
|
+
return this.transfomers[name];
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
|
|
1839
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/is.js
|
|
1840
|
+
var getType = (payload) => Object.prototype.toString.call(payload).slice(8, -1);
|
|
1841
|
+
var isUndefined = (payload) => typeof payload === "undefined";
|
|
1842
|
+
var isNull = (payload) => payload === null;
|
|
1843
|
+
var isPlainObject = (payload) => {
|
|
1844
|
+
if (typeof payload !== "object" || payload === null)
|
|
1845
|
+
return false;
|
|
1846
|
+
if (payload === Object.prototype)
|
|
1847
|
+
return false;
|
|
1848
|
+
if (Object.getPrototypeOf(payload) === null)
|
|
1849
|
+
return true;
|
|
1850
|
+
return Object.getPrototypeOf(payload) === Object.prototype;
|
|
1851
|
+
};
|
|
1852
|
+
var isEmptyObject = (payload) => isPlainObject(payload) && Object.keys(payload).length === 0;
|
|
1853
|
+
var isArray = (payload) => Array.isArray(payload);
|
|
1854
|
+
var isString = (payload) => typeof payload === "string";
|
|
1855
|
+
var isNumber = (payload) => typeof payload === "number" && !isNaN(payload);
|
|
1856
|
+
var isBoolean = (payload) => typeof payload === "boolean";
|
|
1857
|
+
var isRegExp = (payload) => payload instanceof RegExp;
|
|
1858
|
+
var isMap = (payload) => payload instanceof Map;
|
|
1859
|
+
var isSet = (payload) => payload instanceof Set;
|
|
1860
|
+
var isSymbol = (payload) => getType(payload) === "Symbol";
|
|
1861
|
+
var isDate = (payload) => payload instanceof Date && !isNaN(payload.valueOf());
|
|
1862
|
+
var isError = (payload) => payload instanceof Error;
|
|
1863
|
+
var isNaNValue = (payload) => typeof payload === "number" && isNaN(payload);
|
|
1864
|
+
var isPrimitive = (payload) => isBoolean(payload) || isNull(payload) || isUndefined(payload) || isNumber(payload) || isString(payload) || isSymbol(payload);
|
|
1865
|
+
var isBigint = (payload) => typeof payload === "bigint";
|
|
1866
|
+
var isInfinite = (payload) => payload === Infinity || payload === -Infinity;
|
|
1867
|
+
var isTypedArray = (payload) => ArrayBuffer.isView(payload) && !(payload instanceof DataView);
|
|
1868
|
+
var isURL = (payload) => payload instanceof URL;
|
|
1869
|
+
|
|
1870
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/pathstringifier.js
|
|
1871
|
+
var escapeKey = (key) => key.replace(/\\/g, "\\\\").replace(/\./g, "\\.");
|
|
1872
|
+
var stringifyPath = (path) => path.map(String).map(escapeKey).join(".");
|
|
1873
|
+
var parsePath = (string, legacyPaths) => {
|
|
1874
|
+
const result = [];
|
|
1875
|
+
let segment = "";
|
|
1876
|
+
for (let i2 = 0; i2 < string.length; i2++) {
|
|
1877
|
+
let char = string.charAt(i2);
|
|
1878
|
+
if (!legacyPaths && char === "\\") {
|
|
1879
|
+
const escaped = string.charAt(i2 + 1);
|
|
1880
|
+
if (escaped === "\\") {
|
|
1881
|
+
segment += "\\";
|
|
1882
|
+
i2++;
|
|
1883
|
+
continue;
|
|
1884
|
+
} else if (escaped !== ".") {
|
|
1885
|
+
throw Error("invalid path");
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
const isEscapedDot = char === "\\" && string.charAt(i2 + 1) === ".";
|
|
1889
|
+
if (isEscapedDot) {
|
|
1890
|
+
segment += ".";
|
|
1891
|
+
i2++;
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1894
|
+
const isEndOfSegment = char === ".";
|
|
1895
|
+
if (isEndOfSegment) {
|
|
1896
|
+
result.push(segment);
|
|
1897
|
+
segment = "";
|
|
1898
|
+
continue;
|
|
1899
|
+
}
|
|
1900
|
+
segment += char;
|
|
1901
|
+
}
|
|
1902
|
+
const lastSegment = segment;
|
|
1903
|
+
result.push(lastSegment);
|
|
1904
|
+
return result;
|
|
1905
|
+
};
|
|
1906
|
+
|
|
1907
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/transformer.js
|
|
1908
|
+
function simpleTransformation(isApplicable, annotation, transform, untransform) {
|
|
1909
|
+
return {
|
|
1910
|
+
isApplicable,
|
|
1911
|
+
annotation,
|
|
1912
|
+
transform,
|
|
1913
|
+
untransform
|
|
1914
|
+
};
|
|
1915
|
+
}
|
|
1916
|
+
var simpleRules = [
|
|
1917
|
+
simpleTransformation(isUndefined, "undefined", () => null, () => void 0),
|
|
1918
|
+
simpleTransformation(isBigint, "bigint", (v) => v.toString(), (v) => {
|
|
1919
|
+
if (typeof BigInt !== "undefined") {
|
|
1920
|
+
return BigInt(v);
|
|
1921
|
+
}
|
|
1922
|
+
console.error("Please add a BigInt polyfill.");
|
|
1923
|
+
return v;
|
|
1924
|
+
}),
|
|
1925
|
+
simpleTransformation(isDate, "Date", (v) => v.toISOString(), (v) => new Date(v)),
|
|
1926
|
+
simpleTransformation(isError, "Error", (v, superJson) => {
|
|
1927
|
+
const baseError = {
|
|
1928
|
+
name: v.name,
|
|
1929
|
+
message: v.message
|
|
1930
|
+
};
|
|
1931
|
+
if ("cause" in v) {
|
|
1932
|
+
baseError.cause = v.cause;
|
|
1933
|
+
}
|
|
1934
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
1935
|
+
baseError[prop] = v[prop];
|
|
1936
|
+
});
|
|
1937
|
+
return baseError;
|
|
1938
|
+
}, (v, superJson) => {
|
|
1939
|
+
const e = new Error(v.message, { cause: v.cause });
|
|
1940
|
+
e.name = v.name;
|
|
1941
|
+
e.stack = v.stack;
|
|
1942
|
+
superJson.allowedErrorProps.forEach((prop) => {
|
|
1943
|
+
e[prop] = v[prop];
|
|
1944
|
+
});
|
|
1945
|
+
return e;
|
|
1946
|
+
}),
|
|
1947
|
+
simpleTransformation(isRegExp, "regexp", (v) => "" + v, (regex) => {
|
|
1948
|
+
const body = regex.slice(1, regex.lastIndexOf("/"));
|
|
1949
|
+
const flags = regex.slice(regex.lastIndexOf("/") + 1);
|
|
1950
|
+
return new RegExp(body, flags);
|
|
1951
|
+
}),
|
|
1952
|
+
simpleTransformation(
|
|
1953
|
+
isSet,
|
|
1954
|
+
"set",
|
|
1955
|
+
// (sets only exist in es6+)
|
|
1956
|
+
// eslint-disable-next-line es5/no-es6-methods
|
|
1957
|
+
(v) => [...v.values()],
|
|
1958
|
+
(v) => new Set(v)
|
|
1959
|
+
),
|
|
1960
|
+
simpleTransformation(isMap, "map", (v) => [...v.entries()], (v) => new Map(v)),
|
|
1961
|
+
simpleTransformation((v) => isNaNValue(v) || isInfinite(v), "number", (v) => {
|
|
1962
|
+
if (isNaNValue(v)) {
|
|
1963
|
+
return "NaN";
|
|
1964
|
+
}
|
|
1965
|
+
if (v > 0) {
|
|
1966
|
+
return "Infinity";
|
|
1967
|
+
} else {
|
|
1968
|
+
return "-Infinity";
|
|
1969
|
+
}
|
|
1970
|
+
}, Number),
|
|
1971
|
+
simpleTransformation((v) => v === 0 && 1 / v === -Infinity, "number", () => {
|
|
1972
|
+
return "-0";
|
|
1973
|
+
}, Number),
|
|
1974
|
+
simpleTransformation(isURL, "URL", (v) => v.toString(), (v) => new URL(v))
|
|
1975
|
+
];
|
|
1976
|
+
function compositeTransformation(isApplicable, annotation, transform, untransform) {
|
|
1977
|
+
return {
|
|
1978
|
+
isApplicable,
|
|
1979
|
+
annotation,
|
|
1980
|
+
transform,
|
|
1981
|
+
untransform
|
|
1982
|
+
};
|
|
1983
|
+
}
|
|
1984
|
+
var symbolRule = compositeTransformation((s2, superJson) => {
|
|
1985
|
+
if (isSymbol(s2)) {
|
|
1986
|
+
const isRegistered = !!superJson.symbolRegistry.getIdentifier(s2);
|
|
1987
|
+
return isRegistered;
|
|
1988
|
+
}
|
|
1989
|
+
return false;
|
|
1990
|
+
}, (s2, superJson) => {
|
|
1991
|
+
const identifier = superJson.symbolRegistry.getIdentifier(s2);
|
|
1992
|
+
return ["symbol", identifier];
|
|
1993
|
+
}, (v) => v.description, (_2, a2, superJson) => {
|
|
1994
|
+
const value = superJson.symbolRegistry.getValue(a2[1]);
|
|
1995
|
+
if (!value) {
|
|
1996
|
+
throw new Error("Trying to deserialize unknown symbol");
|
|
1997
|
+
}
|
|
1998
|
+
return value;
|
|
1999
|
+
});
|
|
2000
|
+
var constructorToName = [
|
|
2001
|
+
Int8Array,
|
|
2002
|
+
Uint8Array,
|
|
2003
|
+
Int16Array,
|
|
2004
|
+
Uint16Array,
|
|
2005
|
+
Int32Array,
|
|
2006
|
+
Uint32Array,
|
|
2007
|
+
Float32Array,
|
|
2008
|
+
Float64Array,
|
|
2009
|
+
Uint8ClampedArray
|
|
2010
|
+
].reduce((obj, ctor) => {
|
|
2011
|
+
obj[ctor.name] = ctor;
|
|
2012
|
+
return obj;
|
|
2013
|
+
}, {});
|
|
2014
|
+
var typedArrayRule = compositeTransformation(isTypedArray, (v) => ["typed-array", v.constructor.name], (v) => [...v], (v, a2) => {
|
|
2015
|
+
const ctor = constructorToName[a2[1]];
|
|
2016
|
+
if (!ctor) {
|
|
2017
|
+
throw new Error("Trying to deserialize unknown typed array");
|
|
2018
|
+
}
|
|
2019
|
+
return new ctor(v);
|
|
2020
|
+
});
|
|
2021
|
+
function isInstanceOfRegisteredClass(potentialClass, superJson) {
|
|
2022
|
+
if (potentialClass?.constructor) {
|
|
2023
|
+
const isRegistered = !!superJson.classRegistry.getIdentifier(potentialClass.constructor);
|
|
2024
|
+
return isRegistered;
|
|
2025
|
+
}
|
|
2026
|
+
return false;
|
|
2027
|
+
}
|
|
2028
|
+
var classRule = compositeTransformation(isInstanceOfRegisteredClass, (clazz, superJson) => {
|
|
2029
|
+
const identifier = superJson.classRegistry.getIdentifier(clazz.constructor);
|
|
2030
|
+
return ["class", identifier];
|
|
2031
|
+
}, (clazz, superJson) => {
|
|
2032
|
+
const allowedProps = superJson.classRegistry.getAllowedProps(clazz.constructor);
|
|
2033
|
+
if (!allowedProps) {
|
|
2034
|
+
return { ...clazz };
|
|
2035
|
+
}
|
|
2036
|
+
const result = {};
|
|
2037
|
+
allowedProps.forEach((prop) => {
|
|
2038
|
+
result[prop] = clazz[prop];
|
|
2039
|
+
});
|
|
2040
|
+
return result;
|
|
2041
|
+
}, (v, a2, superJson) => {
|
|
2042
|
+
const clazz = superJson.classRegistry.getValue(a2[1]);
|
|
2043
|
+
if (!clazz) {
|
|
2044
|
+
throw new Error(`Trying to deserialize unknown class '${a2[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);
|
|
2045
|
+
}
|
|
2046
|
+
return Object.assign(Object.create(clazz.prototype), v);
|
|
2047
|
+
});
|
|
2048
|
+
var customRule = compositeTransformation((value, superJson) => {
|
|
2049
|
+
return !!superJson.customTransformerRegistry.findApplicable(value);
|
|
2050
|
+
}, (value, superJson) => {
|
|
2051
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
2052
|
+
return ["custom", transformer.name];
|
|
2053
|
+
}, (value, superJson) => {
|
|
2054
|
+
const transformer = superJson.customTransformerRegistry.findApplicable(value);
|
|
2055
|
+
return transformer.serialize(value);
|
|
2056
|
+
}, (v, a2, superJson) => {
|
|
2057
|
+
const transformer = superJson.customTransformerRegistry.findByName(a2[1]);
|
|
2058
|
+
if (!transformer) {
|
|
2059
|
+
throw new Error("Trying to deserialize unknown custom value");
|
|
2060
|
+
}
|
|
2061
|
+
return transformer.deserialize(v);
|
|
2062
|
+
});
|
|
2063
|
+
var compositeRules = [classRule, symbolRule, customRule, typedArrayRule];
|
|
2064
|
+
var transformValue = (value, superJson) => {
|
|
2065
|
+
const applicableCompositeRule = findArr(compositeRules, (rule) => rule.isApplicable(value, superJson));
|
|
2066
|
+
if (applicableCompositeRule) {
|
|
2067
|
+
return {
|
|
2068
|
+
value: applicableCompositeRule.transform(value, superJson),
|
|
2069
|
+
type: applicableCompositeRule.annotation(value, superJson)
|
|
2070
|
+
};
|
|
2071
|
+
}
|
|
2072
|
+
const applicableSimpleRule = findArr(simpleRules, (rule) => rule.isApplicable(value, superJson));
|
|
2073
|
+
if (applicableSimpleRule) {
|
|
2074
|
+
return {
|
|
2075
|
+
value: applicableSimpleRule.transform(value, superJson),
|
|
2076
|
+
type: applicableSimpleRule.annotation
|
|
2077
|
+
};
|
|
2078
|
+
}
|
|
2079
|
+
return void 0;
|
|
2080
|
+
};
|
|
2081
|
+
var simpleRulesByAnnotation = {};
|
|
2082
|
+
simpleRules.forEach((rule) => {
|
|
2083
|
+
simpleRulesByAnnotation[rule.annotation] = rule;
|
|
2084
|
+
});
|
|
2085
|
+
var untransformValue = (json, type, superJson) => {
|
|
2086
|
+
if (isArray(type)) {
|
|
2087
|
+
switch (type[0]) {
|
|
2088
|
+
case "symbol":
|
|
2089
|
+
return symbolRule.untransform(json, type, superJson);
|
|
2090
|
+
case "class":
|
|
2091
|
+
return classRule.untransform(json, type, superJson);
|
|
2092
|
+
case "custom":
|
|
2093
|
+
return customRule.untransform(json, type, superJson);
|
|
2094
|
+
case "typed-array":
|
|
2095
|
+
return typedArrayRule.untransform(json, type, superJson);
|
|
2096
|
+
default:
|
|
2097
|
+
throw new Error("Unknown transformation: " + type);
|
|
2098
|
+
}
|
|
2099
|
+
} else {
|
|
2100
|
+
const transformation = simpleRulesByAnnotation[type];
|
|
2101
|
+
if (!transformation) {
|
|
2102
|
+
throw new Error("Unknown transformation: " + type);
|
|
2103
|
+
}
|
|
2104
|
+
return transformation.untransform(json, superJson);
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
|
|
2108
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/accessDeep.js
|
|
2109
|
+
var getNthKey = (value, n2) => {
|
|
2110
|
+
if (n2 > value.size)
|
|
2111
|
+
throw new Error("index out of bounds");
|
|
2112
|
+
const keys = value.keys();
|
|
2113
|
+
while (n2 > 0) {
|
|
2114
|
+
keys.next();
|
|
2115
|
+
n2--;
|
|
2116
|
+
}
|
|
2117
|
+
return keys.next().value;
|
|
2118
|
+
};
|
|
2119
|
+
function validatePath(path) {
|
|
2120
|
+
if (includes(path, "__proto__")) {
|
|
2121
|
+
throw new Error("__proto__ is not allowed as a property");
|
|
2122
|
+
}
|
|
2123
|
+
if (includes(path, "prototype")) {
|
|
2124
|
+
throw new Error("prototype is not allowed as a property");
|
|
2125
|
+
}
|
|
2126
|
+
if (includes(path, "constructor")) {
|
|
2127
|
+
throw new Error("constructor is not allowed as a property");
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
var getDeep = (object, path) => {
|
|
2131
|
+
validatePath(path);
|
|
2132
|
+
for (let i2 = 0; i2 < path.length; i2++) {
|
|
2133
|
+
const key = path[i2];
|
|
2134
|
+
if (isSet(object)) {
|
|
2135
|
+
object = getNthKey(object, +key);
|
|
2136
|
+
} else if (isMap(object)) {
|
|
2137
|
+
const row = +key;
|
|
2138
|
+
const type = +path[++i2] === 0 ? "key" : "value";
|
|
2139
|
+
const keyOfRow = getNthKey(object, row);
|
|
2140
|
+
switch (type) {
|
|
2141
|
+
case "key":
|
|
2142
|
+
object = keyOfRow;
|
|
2143
|
+
break;
|
|
2144
|
+
case "value":
|
|
2145
|
+
object = object.get(keyOfRow);
|
|
2146
|
+
break;
|
|
2147
|
+
}
|
|
2148
|
+
} else {
|
|
2149
|
+
object = object[key];
|
|
2150
|
+
}
|
|
2151
|
+
}
|
|
2152
|
+
return object;
|
|
2153
|
+
};
|
|
2154
|
+
var setDeep = (object, path, mapper) => {
|
|
2155
|
+
validatePath(path);
|
|
2156
|
+
if (path.length === 0) {
|
|
2157
|
+
return mapper(object);
|
|
2158
|
+
}
|
|
2159
|
+
let parent = object;
|
|
2160
|
+
for (let i2 = 0; i2 < path.length - 1; i2++) {
|
|
2161
|
+
const key = path[i2];
|
|
2162
|
+
if (isArray(parent)) {
|
|
2163
|
+
const index = +key;
|
|
2164
|
+
parent = parent[index];
|
|
2165
|
+
} else if (isPlainObject(parent)) {
|
|
2166
|
+
parent = parent[key];
|
|
2167
|
+
} else if (isSet(parent)) {
|
|
2168
|
+
const row = +key;
|
|
2169
|
+
parent = getNthKey(parent, row);
|
|
2170
|
+
} else if (isMap(parent)) {
|
|
2171
|
+
const isEnd = i2 === path.length - 2;
|
|
2172
|
+
if (isEnd) {
|
|
2173
|
+
break;
|
|
2174
|
+
}
|
|
2175
|
+
const row = +key;
|
|
2176
|
+
const type = +path[++i2] === 0 ? "key" : "value";
|
|
2177
|
+
const keyOfRow = getNthKey(parent, row);
|
|
2178
|
+
switch (type) {
|
|
2179
|
+
case "key":
|
|
2180
|
+
parent = keyOfRow;
|
|
2181
|
+
break;
|
|
2182
|
+
case "value":
|
|
2183
|
+
parent = parent.get(keyOfRow);
|
|
2184
|
+
break;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
const lastKey = path[path.length - 1];
|
|
2189
|
+
if (isArray(parent)) {
|
|
2190
|
+
parent[+lastKey] = mapper(parent[+lastKey]);
|
|
2191
|
+
} else if (isPlainObject(parent)) {
|
|
2192
|
+
parent[lastKey] = mapper(parent[lastKey]);
|
|
2193
|
+
}
|
|
2194
|
+
if (isSet(parent)) {
|
|
2195
|
+
const oldValue = getNthKey(parent, +lastKey);
|
|
2196
|
+
const newValue = mapper(oldValue);
|
|
2197
|
+
if (oldValue !== newValue) {
|
|
2198
|
+
parent.delete(oldValue);
|
|
2199
|
+
parent.add(newValue);
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
if (isMap(parent)) {
|
|
2203
|
+
const row = +path[path.length - 2];
|
|
2204
|
+
const keyToRow = getNthKey(parent, row);
|
|
2205
|
+
const type = +lastKey === 0 ? "key" : "value";
|
|
2206
|
+
switch (type) {
|
|
2207
|
+
case "key": {
|
|
2208
|
+
const newKey = mapper(keyToRow);
|
|
2209
|
+
parent.set(newKey, parent.get(keyToRow));
|
|
2210
|
+
if (newKey !== keyToRow) {
|
|
2211
|
+
parent.delete(keyToRow);
|
|
2212
|
+
}
|
|
2213
|
+
break;
|
|
2214
|
+
}
|
|
2215
|
+
case "value": {
|
|
2216
|
+
parent.set(keyToRow, mapper(parent.get(keyToRow)));
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
return object;
|
|
2222
|
+
};
|
|
2223
|
+
|
|
2224
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/plainer.js
|
|
2225
|
+
var enableLegacyPaths = (version) => version < 1;
|
|
2226
|
+
function traverse(tree, walker2, version, origin = []) {
|
|
2227
|
+
if (!tree) {
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
2231
|
+
if (!isArray(tree)) {
|
|
2232
|
+
forEach(tree, (subtree, key) => traverse(subtree, walker2, version, [
|
|
2233
|
+
...origin,
|
|
2234
|
+
...parsePath(key, legacyPaths)
|
|
2235
|
+
]));
|
|
2236
|
+
return;
|
|
2237
|
+
}
|
|
2238
|
+
const [nodeValue, children] = tree;
|
|
2239
|
+
if (children) {
|
|
2240
|
+
forEach(children, (child, key) => {
|
|
2241
|
+
traverse(child, walker2, version, [
|
|
2242
|
+
...origin,
|
|
2243
|
+
...parsePath(key, legacyPaths)
|
|
2244
|
+
]);
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
walker2(nodeValue, origin);
|
|
2248
|
+
}
|
|
2249
|
+
function applyValueAnnotations(plain, annotations, version, superJson) {
|
|
2250
|
+
traverse(annotations, (type, path) => {
|
|
2251
|
+
plain = setDeep(plain, path, (v) => untransformValue(v, type, superJson));
|
|
2252
|
+
}, version);
|
|
2253
|
+
return plain;
|
|
2254
|
+
}
|
|
2255
|
+
function applyReferentialEqualityAnnotations(plain, annotations, version) {
|
|
2256
|
+
const legacyPaths = enableLegacyPaths(version);
|
|
2257
|
+
function apply(identicalPaths, path) {
|
|
2258
|
+
const object = getDeep(plain, parsePath(path, legacyPaths));
|
|
2259
|
+
identicalPaths.map((path2) => parsePath(path2, legacyPaths)).forEach((identicalObjectPath) => {
|
|
2260
|
+
plain = setDeep(plain, identicalObjectPath, () => object);
|
|
2261
|
+
});
|
|
2262
|
+
}
|
|
2263
|
+
if (isArray(annotations)) {
|
|
2264
|
+
const [root, other] = annotations;
|
|
2265
|
+
root.forEach((identicalPath) => {
|
|
2266
|
+
plain = setDeep(plain, parsePath(identicalPath, legacyPaths), () => plain);
|
|
2267
|
+
});
|
|
2268
|
+
if (other) {
|
|
2269
|
+
forEach(other, apply);
|
|
2270
|
+
}
|
|
2271
|
+
} else {
|
|
2272
|
+
forEach(annotations, apply);
|
|
2273
|
+
}
|
|
2274
|
+
return plain;
|
|
2275
|
+
}
|
|
2276
|
+
var isDeep = (object, superJson) => isPlainObject(object) || isArray(object) || isMap(object) || isSet(object) || isError(object) || isInstanceOfRegisteredClass(object, superJson);
|
|
2277
|
+
function addIdentity(object, path, identities) {
|
|
2278
|
+
const existingSet = identities.get(object);
|
|
2279
|
+
if (existingSet) {
|
|
2280
|
+
existingSet.push(path);
|
|
2281
|
+
} else {
|
|
2282
|
+
identities.set(object, [path]);
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
function generateReferentialEqualityAnnotations(identitites, dedupe) {
|
|
2286
|
+
const result = {};
|
|
2287
|
+
let rootEqualityPaths = void 0;
|
|
2288
|
+
identitites.forEach((paths) => {
|
|
2289
|
+
if (paths.length <= 1) {
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
if (!dedupe) {
|
|
2293
|
+
paths = paths.map((path) => path.map(String)).sort((a2, b3) => a2.length - b3.length);
|
|
2294
|
+
}
|
|
2295
|
+
const [representativePath, ...identicalPaths] = paths;
|
|
2296
|
+
if (representativePath.length === 0) {
|
|
2297
|
+
rootEqualityPaths = identicalPaths.map(stringifyPath);
|
|
2298
|
+
} else {
|
|
2299
|
+
result[stringifyPath(representativePath)] = identicalPaths.map(stringifyPath);
|
|
2300
|
+
}
|
|
2301
|
+
});
|
|
2302
|
+
if (rootEqualityPaths) {
|
|
2303
|
+
if (isEmptyObject(result)) {
|
|
2304
|
+
return [rootEqualityPaths];
|
|
2305
|
+
} else {
|
|
2306
|
+
return [rootEqualityPaths, result];
|
|
2307
|
+
}
|
|
2308
|
+
} else {
|
|
2309
|
+
return isEmptyObject(result) ? void 0 : result;
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
var walker = (object, identities, superJson, dedupe, path = [], objectsInThisPath = [], seenObjects = /* @__PURE__ */ new Map()) => {
|
|
2313
|
+
const primitive = isPrimitive(object);
|
|
2314
|
+
if (!primitive) {
|
|
2315
|
+
addIdentity(object, path, identities);
|
|
2316
|
+
const seen = seenObjects.get(object);
|
|
2317
|
+
if (seen) {
|
|
2318
|
+
return dedupe ? {
|
|
2319
|
+
transformedValue: null
|
|
2320
|
+
} : seen;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
if (!isDeep(object, superJson)) {
|
|
2324
|
+
const transformed2 = transformValue(object, superJson);
|
|
2325
|
+
const result2 = transformed2 ? {
|
|
2326
|
+
transformedValue: transformed2.value,
|
|
2327
|
+
annotations: [transformed2.type]
|
|
2328
|
+
} : {
|
|
2329
|
+
transformedValue: object
|
|
2330
|
+
};
|
|
2331
|
+
if (!primitive) {
|
|
2332
|
+
seenObjects.set(object, result2);
|
|
2333
|
+
}
|
|
2334
|
+
return result2;
|
|
2335
|
+
}
|
|
2336
|
+
if (includes(objectsInThisPath, object)) {
|
|
2337
|
+
return {
|
|
2338
|
+
transformedValue: null
|
|
2339
|
+
};
|
|
2340
|
+
}
|
|
2341
|
+
const transformationResult = transformValue(object, superJson);
|
|
2342
|
+
const transformed = transformationResult?.value ?? object;
|
|
2343
|
+
const transformedValue = isArray(transformed) ? [] : {};
|
|
2344
|
+
const innerAnnotations = {};
|
|
2345
|
+
forEach(transformed, (value, index) => {
|
|
2346
|
+
if (index === "__proto__" || index === "constructor" || index === "prototype") {
|
|
2347
|
+
throw new Error(`Detected property ${index}. This is a prototype pollution risk, please remove it from your object.`);
|
|
2348
|
+
}
|
|
2349
|
+
const recursiveResult = walker(value, identities, superJson, dedupe, [...path, index], [...objectsInThisPath, object], seenObjects);
|
|
2350
|
+
transformedValue[index] = recursiveResult.transformedValue;
|
|
2351
|
+
if (isArray(recursiveResult.annotations)) {
|
|
2352
|
+
innerAnnotations[escapeKey(index)] = recursiveResult.annotations;
|
|
2353
|
+
} else if (isPlainObject(recursiveResult.annotations)) {
|
|
2354
|
+
forEach(recursiveResult.annotations, (tree, key) => {
|
|
2355
|
+
innerAnnotations[escapeKey(index) + "." + key] = tree;
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
});
|
|
2359
|
+
const result = isEmptyObject(innerAnnotations) ? {
|
|
2360
|
+
transformedValue,
|
|
2361
|
+
annotations: !!transformationResult ? [transformationResult.type] : void 0
|
|
2362
|
+
} : {
|
|
2363
|
+
transformedValue,
|
|
2364
|
+
annotations: !!transformationResult ? [transformationResult.type, innerAnnotations] : innerAnnotations
|
|
2365
|
+
};
|
|
2366
|
+
if (!primitive) {
|
|
2367
|
+
seenObjects.set(object, result);
|
|
2368
|
+
}
|
|
2369
|
+
return result;
|
|
2370
|
+
};
|
|
2371
|
+
|
|
2372
|
+
// ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/getType.js
|
|
2373
|
+
function getType2(payload) {
|
|
2374
|
+
return Object.prototype.toString.call(payload).slice(8, -1);
|
|
2375
|
+
}
|
|
2376
|
+
|
|
2377
|
+
// ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isArray.js
|
|
2378
|
+
function isArray2(payload) {
|
|
2379
|
+
return getType2(payload) === "Array";
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
// ../../node_modules/.pnpm/is-what@5.5.0/node_modules/is-what/dist/isPlainObject.js
|
|
2383
|
+
function isPlainObject2(payload) {
|
|
2384
|
+
if (getType2(payload) !== "Object")
|
|
2385
|
+
return false;
|
|
2386
|
+
const prototype = Object.getPrototypeOf(payload);
|
|
2387
|
+
return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
// ../../node_modules/.pnpm/copy-anything@4.0.5/node_modules/copy-anything/dist/index.js
|
|
2391
|
+
function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
|
|
2392
|
+
const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable";
|
|
2393
|
+
if (propType === "enumerable")
|
|
2394
|
+
carry[key] = newVal;
|
|
2395
|
+
if (includeNonenumerable && propType === "nonenumerable") {
|
|
2396
|
+
Object.defineProperty(carry, key, {
|
|
2397
|
+
value: newVal,
|
|
2398
|
+
enumerable: false,
|
|
2399
|
+
writable: true,
|
|
2400
|
+
configurable: true
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
function copy(target, options = {}) {
|
|
2405
|
+
if (isArray2(target)) {
|
|
2406
|
+
return target.map((item) => copy(item, options));
|
|
2407
|
+
}
|
|
2408
|
+
if (!isPlainObject2(target)) {
|
|
2409
|
+
return target;
|
|
2410
|
+
}
|
|
2411
|
+
const props = Object.getOwnPropertyNames(target);
|
|
2412
|
+
const symbols = Object.getOwnPropertySymbols(target);
|
|
2413
|
+
return [...props, ...symbols].reduce((carry, key) => {
|
|
2414
|
+
if (key === "__proto__")
|
|
2415
|
+
return carry;
|
|
2416
|
+
if (isArray2(options.props) && !options.props.includes(key)) {
|
|
2417
|
+
return carry;
|
|
2418
|
+
}
|
|
2419
|
+
const val = target[key];
|
|
2420
|
+
const newVal = copy(val, options);
|
|
2421
|
+
assignProp(carry, key, newVal, target, options.nonenumerable);
|
|
2422
|
+
return carry;
|
|
2423
|
+
}, {});
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
// ../../node_modules/.pnpm/superjson@2.2.6/node_modules/superjson/dist/index.js
|
|
2427
|
+
var SuperJSON = class {
|
|
2428
|
+
/**
|
|
2429
|
+
* @param dedupeReferentialEqualities If true, SuperJSON will make sure only one instance of referentially equal objects are serialized and the rest are replaced with `null`.
|
|
2430
|
+
*/
|
|
2431
|
+
constructor({ dedupe = false } = {}) {
|
|
2432
|
+
this.classRegistry = new ClassRegistry();
|
|
2433
|
+
this.symbolRegistry = new Registry((s2) => s2.description ?? "");
|
|
2434
|
+
this.customTransformerRegistry = new CustomTransformerRegistry();
|
|
2435
|
+
this.allowedErrorProps = [];
|
|
2436
|
+
this.dedupe = dedupe;
|
|
2437
|
+
}
|
|
2438
|
+
serialize(object) {
|
|
2439
|
+
const identities = /* @__PURE__ */ new Map();
|
|
2440
|
+
const output = walker(object, identities, this, this.dedupe);
|
|
2441
|
+
const res = {
|
|
2442
|
+
json: output.transformedValue
|
|
2443
|
+
};
|
|
2444
|
+
if (output.annotations) {
|
|
2445
|
+
res.meta = {
|
|
2446
|
+
...res.meta,
|
|
2447
|
+
values: output.annotations
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
const equalityAnnotations = generateReferentialEqualityAnnotations(identities, this.dedupe);
|
|
2451
|
+
if (equalityAnnotations) {
|
|
2452
|
+
res.meta = {
|
|
2453
|
+
...res.meta,
|
|
2454
|
+
referentialEqualities: equalityAnnotations
|
|
2455
|
+
};
|
|
2456
|
+
}
|
|
2457
|
+
if (res.meta)
|
|
2458
|
+
res.meta.v = 1;
|
|
2459
|
+
return res;
|
|
2460
|
+
}
|
|
2461
|
+
deserialize(payload, options) {
|
|
2462
|
+
const { json, meta } = payload;
|
|
2463
|
+
let result = options?.inPlace ? json : copy(json);
|
|
2464
|
+
if (meta?.values) {
|
|
2465
|
+
result = applyValueAnnotations(result, meta.values, meta.v ?? 0, this);
|
|
2466
|
+
}
|
|
2467
|
+
if (meta?.referentialEqualities) {
|
|
2468
|
+
result = applyReferentialEqualityAnnotations(result, meta.referentialEqualities, meta.v ?? 0);
|
|
2469
|
+
}
|
|
2470
|
+
return result;
|
|
2471
|
+
}
|
|
2472
|
+
stringify(object) {
|
|
2473
|
+
return JSON.stringify(this.serialize(object));
|
|
2474
|
+
}
|
|
2475
|
+
parse(string) {
|
|
2476
|
+
return this.deserialize(JSON.parse(string), { inPlace: true });
|
|
2477
|
+
}
|
|
2478
|
+
registerClass(v, options) {
|
|
2479
|
+
this.classRegistry.register(v, options);
|
|
2480
|
+
}
|
|
2481
|
+
registerSymbol(v, identifier) {
|
|
2482
|
+
this.symbolRegistry.register(v, identifier);
|
|
2483
|
+
}
|
|
2484
|
+
registerCustom(transformer, name) {
|
|
2485
|
+
this.customTransformerRegistry.register({
|
|
2486
|
+
name,
|
|
2487
|
+
...transformer
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
allowErrorProps(...props) {
|
|
2491
|
+
this.allowedErrorProps.push(...props);
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2494
|
+
SuperJSON.defaultInstance = new SuperJSON();
|
|
2495
|
+
SuperJSON.serialize = SuperJSON.defaultInstance.serialize.bind(SuperJSON.defaultInstance);
|
|
2496
|
+
SuperJSON.deserialize = SuperJSON.defaultInstance.deserialize.bind(SuperJSON.defaultInstance);
|
|
2497
|
+
SuperJSON.stringify = SuperJSON.defaultInstance.stringify.bind(SuperJSON.defaultInstance);
|
|
2498
|
+
SuperJSON.parse = SuperJSON.defaultInstance.parse.bind(SuperJSON.defaultInstance);
|
|
2499
|
+
SuperJSON.registerClass = SuperJSON.defaultInstance.registerClass.bind(SuperJSON.defaultInstance);
|
|
2500
|
+
SuperJSON.registerSymbol = SuperJSON.defaultInstance.registerSymbol.bind(SuperJSON.defaultInstance);
|
|
2501
|
+
SuperJSON.registerCustom = SuperJSON.defaultInstance.registerCustom.bind(SuperJSON.defaultInstance);
|
|
2502
|
+
SuperJSON.allowErrorProps = SuperJSON.defaultInstance.allowErrorProps.bind(SuperJSON.defaultInstance);
|
|
2503
|
+
var serialize = SuperJSON.serialize;
|
|
2504
|
+
var deserialize = SuperJSON.deserialize;
|
|
2505
|
+
var stringify = SuperJSON.stringify;
|
|
2506
|
+
var parse = SuperJSON.parse;
|
|
2507
|
+
var registerClass = SuperJSON.registerClass;
|
|
2508
|
+
var registerCustom = SuperJSON.registerCustom;
|
|
2509
|
+
var registerSymbol = SuperJSON.registerSymbol;
|
|
2510
|
+
var allowErrorProps = SuperJSON.allowErrorProps;
|
|
2511
|
+
|
|
2512
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/CogsStateClient.js
|
|
2513
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2514
|
+
import { createContext as s, useContext as i } from "react";
|
|
2515
|
+
var r = {
|
|
2516
|
+
sessionId: void 0
|
|
2517
|
+
};
|
|
2518
|
+
var o = s(r);
|
|
2519
|
+
|
|
2520
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/CogsState.js
|
|
2521
|
+
var {
|
|
2522
|
+
getInitialOptions: C,
|
|
2523
|
+
updateInitialStateGlobal: he,
|
|
2524
|
+
getShadowMetadata: V3,
|
|
2525
|
+
setShadowMetadata: B2,
|
|
2526
|
+
getShadowValue: I3,
|
|
2527
|
+
initializeShadowState: Z,
|
|
2528
|
+
initializeAndMergeShadowState: _e,
|
|
2529
|
+
updateShadowAtPath: Oe,
|
|
2530
|
+
insertShadowArrayElement: je,
|
|
2531
|
+
insertManyShadowArrayElements: ve,
|
|
2532
|
+
removeShadowArrayElement: Ne,
|
|
2533
|
+
setInitialStateOptions: de,
|
|
2534
|
+
setServerStateUpdate: ge,
|
|
2535
|
+
markAsDirty: ae,
|
|
2536
|
+
addPathComponent: Ue,
|
|
2537
|
+
clearSelectedIndexesForState: Fe,
|
|
2538
|
+
addStateLog: ze,
|
|
2539
|
+
clearSelectedIndex: Re,
|
|
2540
|
+
getSyncInfo: Le,
|
|
2541
|
+
notifyPathSubscribers: We,
|
|
2542
|
+
getPluginMetaDataMap: Be,
|
|
2543
|
+
setPluginMetaData: Ge,
|
|
2544
|
+
removePluginMetaData: qe
|
|
2545
|
+
} = $.getState();
|
|
2546
|
+
var { notifyUpdate: xe } = b.getState();
|
|
2547
|
+
|
|
2548
|
+
// ../../node_modules/.pnpm/cogsbox-state@0.5.476_@trpc+next@11.10.0_@tanstack+react-query@5.90.21_react@19.2.4__@t_2ea54f427ca0966c855f98d25ac3767f/node_modules/cogsbox-state/dist/PluginRunner.js
|
|
2549
|
+
import { jsxs as F, Fragment as C2, jsx as P2 } from "react/jsx-runtime";
|
|
2550
|
+
import T, { useState as R, useMemo as M2, useEffect as m2, useRef as x, useReducer as N3 } from "react";
|
|
2551
|
+
var { setHookResult: O5, removeHookResult: I4 } = b.getState();
|
|
2552
|
+
var $4 = T.memo(
|
|
2553
|
+
({
|
|
2554
|
+
stateKey: r2,
|
|
2555
|
+
plugin: e,
|
|
2556
|
+
options: t,
|
|
2557
|
+
stateHandler: d3
|
|
2558
|
+
}) => {
|
|
2559
|
+
const [b3, a2] = R(true), c = M2(
|
|
2560
|
+
() => S(r2, e.name),
|
|
2561
|
+
[r2, e.name]
|
|
2562
|
+
), o2 = M2(
|
|
2563
|
+
() => m(d3),
|
|
2564
|
+
[d3]
|
|
2565
|
+
), i2 = M2(
|
|
2566
|
+
() => ({
|
|
2567
|
+
stateKey: r2,
|
|
2568
|
+
pluginName: e.name,
|
|
2569
|
+
isInitialMount: b3,
|
|
2570
|
+
options: t,
|
|
2571
|
+
...o2,
|
|
2572
|
+
...c
|
|
2573
|
+
}),
|
|
2574
|
+
[
|
|
2575
|
+
r2,
|
|
2576
|
+
e.name,
|
|
2577
|
+
b3,
|
|
2578
|
+
t,
|
|
2579
|
+
o2,
|
|
2580
|
+
c
|
|
2581
|
+
]
|
|
2582
|
+
), s2 = e.useHook ? e.useHook(i2) : void 0;
|
|
2583
|
+
m2(() => {
|
|
2584
|
+
a2(false);
|
|
2585
|
+
}, []), m2(() => (e.useHook ? O5(r2, e.name, s2) : I4(r2, e.name), () => I4(r2, e.name)), [r2, e.name, !!e.useHook, s2]);
|
|
2586
|
+
const u3 = x(), [h3, D2] = R(true);
|
|
2587
|
+
m2(() => {
|
|
2588
|
+
e.transformState && (d(t, u3.current) || (e.transformState({
|
|
2589
|
+
stateKey: r2,
|
|
2590
|
+
pluginName: e.name,
|
|
2591
|
+
options: t,
|
|
2592
|
+
hookData: s2,
|
|
2593
|
+
isInitialTransform: h3,
|
|
2594
|
+
...o2,
|
|
2595
|
+
...c
|
|
2596
|
+
}), u3.current = t, D2(false)));
|
|
2597
|
+
}, [
|
|
2598
|
+
r2,
|
|
2599
|
+
e,
|
|
2600
|
+
t,
|
|
2601
|
+
s2,
|
|
2602
|
+
h3,
|
|
2603
|
+
o2,
|
|
2604
|
+
c
|
|
2605
|
+
]);
|
|
2606
|
+
const k = x(s2);
|
|
2607
|
+
return k.current = s2, m2(() => {
|
|
2608
|
+
if (!e.onUpdate) return;
|
|
2609
|
+
const S2 = (n2) => {
|
|
2610
|
+
if (n2.stateKey === r2) {
|
|
2611
|
+
const U2 = O2(
|
|
2612
|
+
r2,
|
|
2613
|
+
e.name,
|
|
2614
|
+
n2.path
|
|
2615
|
+
);
|
|
2616
|
+
e.onUpdate({
|
|
2617
|
+
stateKey: r2,
|
|
2618
|
+
pluginName: e.name,
|
|
2619
|
+
update: n2,
|
|
2620
|
+
path: n2.path,
|
|
2621
|
+
options: t,
|
|
2622
|
+
hookData: k.current,
|
|
2623
|
+
...o2,
|
|
2624
|
+
...U2
|
|
2625
|
+
// <-- Use the new scoped context
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
return b.getState().subscribeToUpdates(S2);
|
|
2630
|
+
}, [r2, e, t, o2]), m2(() => {
|
|
2631
|
+
if (!e.onFormUpdate) return;
|
|
2632
|
+
const S2 = (n2) => {
|
|
2633
|
+
if (n2.stateKey === r2) {
|
|
2634
|
+
const U2 = O2(
|
|
2635
|
+
r2,
|
|
2636
|
+
e.name,
|
|
2637
|
+
n2.path
|
|
2638
|
+
);
|
|
2639
|
+
e.onFormUpdate({
|
|
2640
|
+
stateKey: r2,
|
|
2641
|
+
pluginName: e.name,
|
|
2642
|
+
path: n2.path,
|
|
2643
|
+
event: n2,
|
|
2644
|
+
options: t,
|
|
2645
|
+
hookData: k.current,
|
|
2646
|
+
...o2,
|
|
2647
|
+
...U2
|
|
2648
|
+
// <-- Use the new scoped context
|
|
2649
|
+
});
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
return b.getState().subscribeToFormUpdates(S2);
|
|
2653
|
+
}, [r2, e, t, o2]), null;
|
|
2654
|
+
}
|
|
2655
|
+
);
|
|
2656
|
+
|
|
2657
|
+
// src/syncPlugin.ts
|
|
2658
|
+
import z4 from "zod";
|
|
2659
|
+
function createSyncPlugin(syncSchema) {
|
|
2660
|
+
const { createPlugin } = b2({
|
|
2661
|
+
options: z4.object({
|
|
2662
|
+
stateRoom: z4.string(),
|
|
2663
|
+
apiParams: f()
|
|
2664
|
+
}),
|
|
2665
|
+
pluginMetaData: z4.object({
|
|
2666
|
+
sessionId: z4.string(),
|
|
2667
|
+
stateVersion: z4.string()
|
|
2668
|
+
}),
|
|
2669
|
+
fieldMetaData: z4.any()
|
|
2670
|
+
});
|
|
2671
|
+
const syncPlugin = createPlugin("syncPlugin").useHook(
|
|
2672
|
+
({
|
|
2673
|
+
stateKey,
|
|
2674
|
+
options,
|
|
2675
|
+
setPluginMetaData,
|
|
2676
|
+
getPluginMetaData,
|
|
2677
|
+
setFieldMetaData,
|
|
2678
|
+
setOptions,
|
|
2679
|
+
initialiseShadowState,
|
|
2680
|
+
applyOperation,
|
|
2681
|
+
getState
|
|
2682
|
+
}) => {
|
|
2683
|
+
const schemaForKey = syncSchema.clientSchemas[stateKey];
|
|
2684
|
+
setOptions({
|
|
2685
|
+
validation: {
|
|
2686
|
+
zodSchemaV4: schemaForKey
|
|
2687
|
+
}
|
|
2688
|
+
});
|
|
2689
|
+
const {
|
|
2690
|
+
onStateRequest,
|
|
2691
|
+
reportClientActivity,
|
|
2692
|
+
onClientActivity,
|
|
2693
|
+
onInitialState,
|
|
2694
|
+
requestState,
|
|
2695
|
+
onPatch,
|
|
2696
|
+
sessionId,
|
|
2697
|
+
sendUpdate
|
|
2698
|
+
} = useSync({
|
|
2699
|
+
stateKey,
|
|
2700
|
+
stateRoom: options.stateRoom,
|
|
2701
|
+
apiParams: options.apiParams
|
|
2702
|
+
});
|
|
2703
|
+
setPluginMetaData({ sessionId });
|
|
2704
|
+
onInitialState((data, version) => {
|
|
2705
|
+
setPluginMetaData({ stateVersion: version });
|
|
2706
|
+
initialiseShadowState({ ...data });
|
|
2707
|
+
});
|
|
2708
|
+
onPatch((patch, patchSessionId, version) => {
|
|
2709
|
+
const { stateVersion: lastKnownVersion } = getPluginMetaData() || {};
|
|
2710
|
+
const lastCounter = Number((lastKnownVersion || ":0").split(":")[1]);
|
|
2711
|
+
const newCounter = Number((version || ":0").split(":")[1]);
|
|
2712
|
+
console.log(
|
|
2713
|
+
"onPatch",
|
|
2714
|
+
patch,
|
|
2715
|
+
patchSessionId,
|
|
2716
|
+
version,
|
|
2717
|
+
lastKnownVersion
|
|
2718
|
+
);
|
|
2719
|
+
if (newCounter === lastCounter + 1) {
|
|
2720
|
+
setPluginMetaData({ stateVersion: version });
|
|
2721
|
+
applyOperation(patch, { dontUpdate: true });
|
|
2722
|
+
} else {
|
|
2723
|
+
requestState();
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2726
|
+
onStateRequest(() => getState());
|
|
2727
|
+
onClientActivity(({ clientId, event, metaData }) => {
|
|
2728
|
+
if ("path" in event && event.path) {
|
|
2729
|
+
setFieldMetaData(event.path, {
|
|
2730
|
+
...metaData,
|
|
2731
|
+
clientActivity: event
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
});
|
|
2735
|
+
return {
|
|
2736
|
+
sessionId,
|
|
2737
|
+
updateState: sendUpdate,
|
|
2738
|
+
reportClientActivity
|
|
2739
|
+
};
|
|
2740
|
+
}
|
|
2741
|
+
).onUpdate(({ update, hookData }) => {
|
|
2742
|
+
hookData?.updateState?.(update);
|
|
2743
|
+
}).onFormUpdate(({ hookData, event }) => {
|
|
2744
|
+
hookData?.reportClientActivity?.(event);
|
|
2745
|
+
});
|
|
2746
|
+
return syncPlugin;
|
|
2747
|
+
}
|
|
2748
|
+
export {
|
|
2749
|
+
SyncProvider,
|
|
2750
|
+
createNotificationHook,
|
|
2751
|
+
createSyncPlugin,
|
|
2752
|
+
useNotificationStore,
|
|
2753
|
+
useNotifications,
|
|
2754
|
+
useSync
|
|
2755
|
+
};
|