@yoltra/devtools-ui 0.3.0 → 0.5.0

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.
@@ -0,0 +1,885 @@
1
+ import Re, { createContext as ve, useState as k, useRef as A, useCallback as O, useEffect as M, useContext as be, useMemo as Oe } from "react";
2
+ import { DevtoolsRole as b, PROTOCOL_VERSION as K } from "@yoltra/devtools-protocol";
3
+ const H = () => {
4
+ }, de = ve({
5
+ status: "disconnected",
6
+ extensionId: "",
7
+ send: H,
8
+ subscribe: () => H,
9
+ disconnect: H,
10
+ reconnect: H
11
+ });
12
+ var X = { exports: {} }, L = {};
13
+ /**
14
+ * @license React
15
+ * react-jsx-runtime.production.js
16
+ *
17
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ */
22
+ var ie;
23
+ function ye() {
24
+ if (ie) return L;
25
+ ie = 1;
26
+ var e = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
27
+ function r(o, t, c) {
28
+ var i = null;
29
+ if (c !== void 0 && (i = "" + c), t.key !== void 0 && (i = "" + t.key), "key" in t) {
30
+ c = {};
31
+ for (var a in t)
32
+ a !== "key" && (c[a] = t[a]);
33
+ } else c = t;
34
+ return t = c.ref, {
35
+ $$typeof: e,
36
+ type: o,
37
+ key: i,
38
+ ref: t !== void 0 ? t : null,
39
+ props: c
40
+ };
41
+ }
42
+ return L.Fragment = s, L.jsx = r, L.jsxs = r, L;
43
+ }
44
+ var U = {};
45
+ /**
46
+ * @license React
47
+ * react-jsx-runtime.development.js
48
+ *
49
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
50
+ *
51
+ * This source code is licensed under the MIT license found in the
52
+ * LICENSE file in the root directory of this source tree.
53
+ */
54
+ var ae;
55
+ function _e() {
56
+ return ae || (ae = 1, process.env.NODE_ENV !== "production" && (function() {
57
+ function e(n) {
58
+ if (n == null) return null;
59
+ if (typeof n == "function")
60
+ return n.$$typeof === he ? null : n.displayName || n.name || null;
61
+ if (typeof n == "string") return n;
62
+ switch (n) {
63
+ case N:
64
+ return "Fragment";
65
+ case R:
66
+ return "Profiler";
67
+ case E:
68
+ return "StrictMode";
69
+ case d:
70
+ return "Suspense";
71
+ case w:
72
+ return "SuspenseList";
73
+ case Se:
74
+ return "Activity";
75
+ }
76
+ if (typeof n == "object")
77
+ switch (typeof n.tag == "number" && console.error(
78
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
79
+ ), n.$$typeof) {
80
+ case T:
81
+ return "Portal";
82
+ case g:
83
+ return (n.displayName || "Context") + ".Provider";
84
+ case x:
85
+ return (n._context.displayName || "Context") + ".Consumer";
86
+ case I:
87
+ var f = n.render;
88
+ return n = n.displayName, n || (n = f.displayName || f.name || "", n = n !== "" ? "ForwardRef(" + n + ")" : "ForwardRef"), n;
89
+ case C:
90
+ return f = n.displayName || null, f !== null ? f : e(n.type) || "Memo";
91
+ case V:
92
+ f = n._payload, n = n._init;
93
+ try {
94
+ return e(n(f));
95
+ } catch {
96
+ }
97
+ }
98
+ return null;
99
+ }
100
+ function s(n) {
101
+ return "" + n;
102
+ }
103
+ function r(n) {
104
+ try {
105
+ s(n);
106
+ var f = !1;
107
+ } catch {
108
+ f = !0;
109
+ }
110
+ if (f) {
111
+ f = console;
112
+ var p = f.error, y = typeof Symbol == "function" && Symbol.toStringTag && n[Symbol.toStringTag] || n.constructor.name || "Object";
113
+ return p.call(
114
+ f,
115
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
116
+ y
117
+ ), s(n);
118
+ }
119
+ }
120
+ function o(n) {
121
+ if (n === N) return "<>";
122
+ if (typeof n == "object" && n !== null && n.$$typeof === V)
123
+ return "<...>";
124
+ try {
125
+ var f = e(n);
126
+ return f ? "<" + f + ">" : "<...>";
127
+ } catch {
128
+ return "<...>";
129
+ }
130
+ }
131
+ function t() {
132
+ var n = J.A;
133
+ return n === null ? null : n.getOwner();
134
+ }
135
+ function c() {
136
+ return Error("react-stack-top-frame");
137
+ }
138
+ function i(n) {
139
+ if (te.call(n, "key")) {
140
+ var f = Object.getOwnPropertyDescriptor(n, "key").get;
141
+ if (f && f.isReactWarning) return !1;
142
+ }
143
+ return n.key !== void 0;
144
+ }
145
+ function a(n, f) {
146
+ function p() {
147
+ re || (re = !0, console.error(
148
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
149
+ f
150
+ ));
151
+ }
152
+ p.isReactWarning = !0, Object.defineProperty(n, "key", {
153
+ get: p,
154
+ configurable: !0
155
+ });
156
+ }
157
+ function u() {
158
+ var n = e(this.type);
159
+ return ne[n] || (ne[n] = !0, console.error(
160
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
161
+ )), n = this.props.ref, n !== void 0 ? n : null;
162
+ }
163
+ function S(n, f, p, y, D, P, W, G) {
164
+ return p = P.ref, n = {
165
+ $$typeof: v,
166
+ type: n,
167
+ key: f,
168
+ props: P,
169
+ _owner: D
170
+ }, (p !== void 0 ? p : null) !== null ? Object.defineProperty(n, "ref", {
171
+ enumerable: !1,
172
+ get: u
173
+ }) : Object.defineProperty(n, "ref", { enumerable: !1, value: null }), n._store = {}, Object.defineProperty(n._store, "validated", {
174
+ configurable: !1,
175
+ enumerable: !1,
176
+ writable: !0,
177
+ value: 0
178
+ }), Object.defineProperty(n, "_debugInfo", {
179
+ configurable: !1,
180
+ enumerable: !1,
181
+ writable: !0,
182
+ value: null
183
+ }), Object.defineProperty(n, "_debugStack", {
184
+ configurable: !1,
185
+ enumerable: !1,
186
+ writable: !0,
187
+ value: W
188
+ }), Object.defineProperty(n, "_debugTask", {
189
+ configurable: !1,
190
+ enumerable: !1,
191
+ writable: !0,
192
+ value: G
193
+ }), Object.freeze && (Object.freeze(n.props), Object.freeze(n)), n;
194
+ }
195
+ function l(n, f, p, y, D, P, W, G) {
196
+ var _ = f.children;
197
+ if (_ !== void 0)
198
+ if (y)
199
+ if (Te(_)) {
200
+ for (y = 0; y < _.length; y++)
201
+ h(_[y]);
202
+ Object.freeze && Object.freeze(_);
203
+ } else
204
+ console.error(
205
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
206
+ );
207
+ else h(_);
208
+ if (te.call(f, "key")) {
209
+ _ = e(n);
210
+ var Y = Object.keys(f).filter(function(me) {
211
+ return me !== "key";
212
+ });
213
+ y = 0 < Y.length ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}", ce[_ + y] || (Y = 0 < Y.length ? "{" + Y.join(": ..., ") + ": ...}" : "{}", console.error(
214
+ `A props object containing a "key" prop is being spread into JSX:
215
+ let props = %s;
216
+ <%s {...props} />
217
+ React keys must be passed directly to JSX without using spread:
218
+ let props = %s;
219
+ <%s key={someKey} {...props} />`,
220
+ y,
221
+ _,
222
+ Y,
223
+ _
224
+ ), ce[_ + y] = !0);
225
+ }
226
+ if (_ = null, p !== void 0 && (r(p), _ = "" + p), i(f) && (r(f.key), _ = "" + f.key), "key" in f) {
227
+ p = {};
228
+ for (var B in f)
229
+ B !== "key" && (p[B] = f[B]);
230
+ } else p = f;
231
+ return _ && a(
232
+ p,
233
+ typeof n == "function" ? n.displayName || n.name || "Unknown" : n
234
+ ), S(
235
+ n,
236
+ _,
237
+ P,
238
+ D,
239
+ t(),
240
+ p,
241
+ W,
242
+ G
243
+ );
244
+ }
245
+ function h(n) {
246
+ typeof n == "object" && n !== null && n.$$typeof === v && n._store && (n._store.validated = 1);
247
+ }
248
+ var m = Re, v = Symbol.for("react.transitional.element"), T = Symbol.for("react.portal"), N = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), R = Symbol.for("react.profiler"), x = Symbol.for("react.consumer"), g = Symbol.for("react.context"), I = Symbol.for("react.forward_ref"), d = Symbol.for("react.suspense"), w = Symbol.for("react.suspense_list"), C = Symbol.for("react.memo"), V = Symbol.for("react.lazy"), Se = Symbol.for("react.activity"), he = Symbol.for("react.client.reference"), J = m.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, te = Object.prototype.hasOwnProperty, Te = Array.isArray, q = console.createTask ? console.createTask : function() {
249
+ return null;
250
+ };
251
+ m = {
252
+ react_stack_bottom_frame: function(n) {
253
+ return n();
254
+ }
255
+ };
256
+ var re, ne = {}, se = m.react_stack_bottom_frame.bind(
257
+ m,
258
+ c
259
+ )(), oe = q(o(c)), ce = {};
260
+ U.Fragment = N, U.jsx = function(n, f, p, y, D) {
261
+ var P = 1e4 > J.recentlyCreatedOwnerStacks++;
262
+ return l(
263
+ n,
264
+ f,
265
+ p,
266
+ !1,
267
+ y,
268
+ D,
269
+ P ? Error("react-stack-top-frame") : se,
270
+ P ? q(o(n)) : oe
271
+ );
272
+ }, U.jsxs = function(n, f, p, y, D) {
273
+ var P = 1e4 > J.recentlyCreatedOwnerStacks++;
274
+ return l(
275
+ n,
276
+ f,
277
+ p,
278
+ !0,
279
+ y,
280
+ D,
281
+ P ? Error("react-stack-top-frame") : se,
282
+ P ? q(o(n)) : oe
283
+ );
284
+ };
285
+ })()), U;
286
+ }
287
+ var ue;
288
+ function Ne() {
289
+ return ue || (ue = 1, process.env.NODE_ENV === "production" ? X.exports = ye() : X.exports = _e()), X.exports;
290
+ }
291
+ var Ie = Ne();
292
+ const Ae = {
293
+ timeTravel: !0,
294
+ eventReplay: !0,
295
+ stateExplorer: !0,
296
+ eventEmit: !0,
297
+ performanceMetrics: !0
298
+ }, ke = 750, xe = 3e4;
299
+ function Le({
300
+ config: e,
301
+ children: s
302
+ }) {
303
+ const [r, o] = k("disconnected"), t = A(null), c = A(/* @__PURE__ */ new Set()), i = A(0), a = A(null), u = A(crypto.randomUUID()), S = A(e);
304
+ S.current = e;
305
+ const l = O(() => {
306
+ const E = S.current, x = `ws://${E.host ?? "localhost"}:${E.port}`, g = E.WebSocket ?? (typeof globalThis.WebSocket < "u" ? globalThis.WebSocket : void 0);
307
+ if (!g) {
308
+ console.error(
309
+ "[Yoltra DevTools] No WebSocket implementation available. In Node.js, pass { WebSocket } from 'ws' via config.WebSocket."
310
+ );
311
+ return;
312
+ }
313
+ o("connecting");
314
+ try {
315
+ const I = new g(x);
316
+ t.current = I, I.onopen = () => {
317
+ i.current = 0;
318
+ const d = JSON.stringify({
319
+ type: "HANDSHAKE_REQUEST",
320
+ protocolVersion: K,
321
+ role: b.EXTENSION,
322
+ extension: {
323
+ id: u.current,
324
+ name: E.extensionName ?? "DevTools UI",
325
+ capabilities: Ae
326
+ }
327
+ });
328
+ I.send(d);
329
+ }, I.onmessage = (d) => {
330
+ try {
331
+ const w = typeof d.data == "string" ? d.data : String(d.data), C = JSON.parse(w);
332
+ if (C.type === "HANDSHAKE_RESPONSE") {
333
+ C.success ? o("connected") : I.close();
334
+ return;
335
+ }
336
+ c.current.forEach((V) => V(C));
337
+ } catch {
338
+ }
339
+ }, I.onclose = () => {
340
+ t.current = null, o("disconnected");
341
+ const d = E.autoReconnect ?? !0, w = E.maxReconnectAttempts ?? 1 / 0;
342
+ if (d && i.current < w) {
343
+ const C = i.current++, V = Math.min(
344
+ ke * Math.pow(2, C) + Math.random() * 500,
345
+ xe
346
+ );
347
+ a.current = setTimeout(l, V);
348
+ }
349
+ }, I.onerror = () => {
350
+ };
351
+ } catch {
352
+ o("disconnected");
353
+ }
354
+ }, []), h = O(() => {
355
+ a.current && (clearTimeout(a.current), a.current = null), i.current = 1 / 0, t.current?.close(), t.current = null, o("disconnected");
356
+ }, []), m = O(() => {
357
+ i.current = 0, t.current?.close(), t.current = null, l();
358
+ }, [l]), v = O((E) => {
359
+ const R = t.current;
360
+ R && R.readyState === 1 && R.send(JSON.stringify(E));
361
+ }, []), T = O((E) => (c.current.add(E), () => {
362
+ c.current.delete(E);
363
+ }), []);
364
+ M(() => (l(), () => {
365
+ a.current && clearTimeout(a.current), i.current = 1 / 0, t.current?.close();
366
+ }), [l]);
367
+ const N = {
368
+ status: r,
369
+ extensionId: u.current,
370
+ send: v,
371
+ subscribe: T,
372
+ disconnect: h,
373
+ reconnect: m
374
+ };
375
+ return /* @__PURE__ */ Ie.jsx(de.Provider, { value: N, children: s });
376
+ }
377
+ function j() {
378
+ return be(de);
379
+ }
380
+ function Ue(e) {
381
+ const { send: s, extensionId: r } = j();
382
+ return { emit: O(
383
+ (t, c, i) => {
384
+ e && s({
385
+ type: "EMIT_TO_STORE",
386
+ storeId: e,
387
+ event: { channel: t, type: c, payload: i },
388
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
389
+ sourceId: r,
390
+ sourceRole: b.EXTENSION
391
+ });
392
+ },
393
+ [e, s, r]
394
+ ) };
395
+ }
396
+ const we = 2e3;
397
+ function Fe(e, s) {
398
+ const { subscribe: r } = j(), o = s?.maxEntries ?? we, t = A(/* @__PURE__ */ new Map()), c = A(o);
399
+ c.current = o;
400
+ const [, i] = k(0);
401
+ M(() => r((l) => {
402
+ if (l.type !== "STORE_EVENT") return;
403
+ const h = l.storeId, m = {
404
+ event: l.event,
405
+ storeId: h,
406
+ patches: l.patches,
407
+ snapshotVersion: l.snapshotVersion,
408
+ committed: l.committed,
409
+ timestamp: l.timestamp
410
+ }, T = [...t.current.get(h) ?? [], m];
411
+ t.current.set(
412
+ h,
413
+ T.length > c.current ? T.slice(T.length - c.current) : T
414
+ ), i((N) => N + 1);
415
+ }), [r]);
416
+ const a = O(() => {
417
+ e && (t.current.delete(e), i((S) => S + 1));
418
+ }, [e]);
419
+ return { entries: e ? t.current.get(e) ?? [] : [], clear: a };
420
+ }
421
+ function He(e) {
422
+ const { send: s, extensionId: r } = j();
423
+ return { replay: O(
424
+ (t, c) => {
425
+ e && s({
426
+ type: "EVENT_REPLAY",
427
+ storeId: e,
428
+ snapshot: t,
429
+ events: c.map((i) => ({
430
+ id: i.event.id,
431
+ channel: i.event.channel,
432
+ type: i.event.type,
433
+ payload: i.event.payload
434
+ })),
435
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
436
+ sourceId: r,
437
+ sourceRole: b.EXTENSION
438
+ });
439
+ },
440
+ [e, s, r]
441
+ ) };
442
+ }
443
+ function Xe(e, s) {
444
+ const { send: r, subscribe: o, extensionId: t } = j(), [c, i] = k(null), [a, u] = k(!1), S = s?.refreshIntervalMs ?? 2e3, l = A(null), h = O(() => {
445
+ e && (u(!0), r({
446
+ type: "REQUEST_METRICS",
447
+ storeId: e,
448
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
449
+ sourceId: t,
450
+ sourceRole: b.EXTENSION
451
+ }));
452
+ }, [e, r, t]);
453
+ return M(() => {
454
+ if (!e) {
455
+ i(null);
456
+ return;
457
+ }
458
+ h();
459
+ const m = o((v) => {
460
+ v.type === "STORE_METRICS" && v.storeId === e && (i(v.metrics), u(!1));
461
+ });
462
+ return S > 0 && (l.current = setInterval(h, S)), () => {
463
+ m(), l.current && (clearInterval(l.current), l.current = null);
464
+ };
465
+ }, [e, o, h, S]), { metrics: c, loading: a, refresh: h };
466
+ }
467
+ function $e() {
468
+ const { subscribe: e } = j(), [s, r] = k([]);
469
+ return M(() => e((t) => {
470
+ switch (t.type) {
471
+ case "STORE_REGISTRY":
472
+ r(t.stores);
473
+ break;
474
+ case "STORE_CONNECTED":
475
+ r((c) => c.some((a) => a.id === t.store.id) ? c.map(
476
+ (a) => a.id === t.store.id ? { ...a, status: "connected" } : a
477
+ ) : [
478
+ ...c,
479
+ {
480
+ id: t.store.id,
481
+ name: t.store.name,
482
+ status: "connected",
483
+ capabilities: t.store.capabilities,
484
+ connectedAt: t.timestamp
485
+ }
486
+ ]);
487
+ break;
488
+ case "STORE_DISCONNECTED":
489
+ r(
490
+ (c) => c.map(
491
+ (i) => i.id === t.storeId ? { ...i, status: "disconnected" } : i
492
+ )
493
+ );
494
+ break;
495
+ }
496
+ }), [e]), s;
497
+ }
498
+ function Z(e, s) {
499
+ let r = e;
500
+ for (const o of s) {
501
+ const t = Ce(o.path);
502
+ switch (o.op) {
503
+ case "add":
504
+ r = ee(r, t, o.value, !0);
505
+ break;
506
+ case "replace":
507
+ r = ee(r, t, o.value, !1);
508
+ break;
509
+ case "remove":
510
+ r = pe(r, t);
511
+ break;
512
+ }
513
+ }
514
+ return r;
515
+ }
516
+ function Ce(e) {
517
+ return e === "" || e === "/" ? [] : e.slice(1).split("/").map((s) => s.replace(/~1/g, "/").replace(/~0/g, "~"));
518
+ }
519
+ const Ee = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
520
+ function ee(e, s, r, o) {
521
+ if (s.length === 0) return r;
522
+ const t = Array.isArray(e) ? [...e] : { ...e }, [c, ...i] = s;
523
+ if (Ee.has(c)) return t;
524
+ if (i.length === 0)
525
+ if (o && Array.isArray(t)) {
526
+ const a = c === "-" ? t.length : Number(c);
527
+ Number.isInteger(a) && a >= 0 && a <= t.length ? t.splice(a, 0, r) : t[c] = r;
528
+ } else
529
+ t[c] = r;
530
+ else
531
+ t[c] = ee(t[c] ?? {}, i, r, o);
532
+ return t;
533
+ }
534
+ function pe(e, s) {
535
+ if (s.length === 0) return;
536
+ const r = Array.isArray(e) ? [...e] : { ...e }, [o, ...t] = s;
537
+ return Ee.has(o) || (t.length === 0 ? Array.isArray(r) ? r.splice(Number(o), 1) : delete r[o] : r[o] = pe(r[o], t)), r;
538
+ }
539
+ function ge(e) {
540
+ const s = e.scheduler ?? {
541
+ setInterval: (t, c) => setInterval(t, c),
542
+ clearInterval: (t) => clearInterval(t)
543
+ };
544
+ let r = s.setInterval(() => {
545
+ if (e.isSettled()) {
546
+ o();
547
+ return;
548
+ }
549
+ e.request();
550
+ }, e.intervalMs);
551
+ function o() {
552
+ r !== null && (s.clearInterval(r), r = null);
553
+ }
554
+ return o;
555
+ }
556
+ const Pe = 1500;
557
+ function Je(e) {
558
+ const { send: s, subscribe: r, extensionId: o } = j(), [t, c] = k(null), [i, a] = k(0), [u, S] = k(!1), l = A(0), h = A([]), m = A(null), v = O(() => {
559
+ m.current?.(), m.current = null;
560
+ }, []), T = O(() => {
561
+ e && (S(!0), s({
562
+ type: "REQUEST_STATE",
563
+ storeId: e,
564
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
565
+ sourceId: o,
566
+ sourceRole: b.EXTENSION
567
+ }));
568
+ }, [e, s, o]);
569
+ return M(() => {
570
+ if (!e) {
571
+ c(null), a(0), l.current = 0;
572
+ return;
573
+ }
574
+ T(), m.current = ge({
575
+ request: T,
576
+ isSettled: () => l.current !== 0,
577
+ intervalMs: Pe
578
+ });
579
+ const N = r((E) => {
580
+ if (E.type === "STATE_SNAPSHOT" && E.storeId === e) {
581
+ v(), c(E.state), a(E.version), l.current = E.version, S(!1);
582
+ const R = h.current.filter((x) => x.version > E.version).sort((x, g) => x.version - g.version);
583
+ if (h.current = [], R.length > 0) {
584
+ c((g) => {
585
+ let I = g;
586
+ for (const d of R)
587
+ I = Z(I, d.patches);
588
+ return I;
589
+ });
590
+ const x = R[R.length - 1].version;
591
+ a(x), l.current = x;
592
+ }
593
+ return;
594
+ }
595
+ if (E.type === "STORE_EVENT" && E.storeId === e && E.committed) {
596
+ if (l.current === 0) {
597
+ h.current.push({
598
+ patches: E.patches,
599
+ version: E.snapshotVersion
600
+ });
601
+ return;
602
+ }
603
+ if (E.snapshotVersion <= l.current)
604
+ return;
605
+ c((R) => Z(R, E.patches)), a(E.snapshotVersion), l.current = E.snapshotVersion;
606
+ }
607
+ });
608
+ return () => {
609
+ N(), v(), h.current = [];
610
+ };
611
+ }, [e, r, T, v]), { state: t, version: i, loading: u, refresh: T };
612
+ }
613
+ function qe(e) {
614
+ const { send: s, subscribe: r, extensionId: o } = j(), [t, c] = k(null), [i, a] = k(!1), u = O(() => {
615
+ e && (a(!0), s({
616
+ type: "REQUEST_SUBSCRIPTIONS",
617
+ storeId: e,
618
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
619
+ sourceId: o,
620
+ sourceRole: b.EXTENSION
621
+ }));
622
+ }, [e, s, o]);
623
+ return M(() => {
624
+ if (!e) {
625
+ c(null);
626
+ return;
627
+ }
628
+ return u(), r((l) => {
629
+ l.type === "STORE_SUBSCRIPTIONS" && l.storeId === e && (c({
630
+ atomic: l.atomic,
631
+ event: l.event,
632
+ coarse: l.coarse,
633
+ effects: l.effects,
634
+ middleware: l.middleware,
635
+ reducers: l.reducers
636
+ }), a(!1));
637
+ });
638
+ }, [e, r, u]), { data: t, loading: i, refresh: u };
639
+ }
640
+ function le(e, s) {
641
+ const { isTimeTraveling: r, currentIndex: o, entryCount: t } = s, c = t - 1;
642
+ if (e === "back") {
643
+ const u = (r ? o : c) - 1;
644
+ return u >= 0 ? { kind: "jump", index: u } : { kind: "none" };
645
+ }
646
+ if (!r) return { kind: "none" };
647
+ const i = o + 1;
648
+ return i > c ? { kind: "resume" } : { kind: "jump", index: i };
649
+ }
650
+ function De(e) {
651
+ const { baseline: s, entries: r, index: o, cache: t } = e;
652
+ if (s === null) return { state: null, cache: null };
653
+ let c = 0, i = s.state;
654
+ t !== null && t.index <= o && r[t.index] === t.marker && (c = t.index + 1, i = t.state);
655
+ for (let u = c; u <= o; u++) {
656
+ const S = r[u];
657
+ if (S === void 0) break;
658
+ S.snapshotVersion <= s.version || (i = Z(i, S.patches));
659
+ }
660
+ const a = r[o];
661
+ return {
662
+ state: i,
663
+ cache: o >= 0 && a !== void 0 ? { index: o, state: i, marker: a } : null
664
+ };
665
+ }
666
+ function We(e, s, r = !0) {
667
+ const { send: o, subscribe: t, extensionId: c } = j(), [i, a] = k(-1), [u, S] = k(!1), [l, h] = k(null), m = A(null), v = A(null);
668
+ M(() => {
669
+ if (m.current = null, v.current = null, h(null), !!e)
670
+ return t((d) => {
671
+ d.type === "STATE_SNAPSHOT" && d.storeId === e && m.current === null && (m.current = { state: d.state, version: d.version });
672
+ });
673
+ }, [e, t]);
674
+ const T = O(
675
+ (d) => {
676
+ const { state: w, cache: C } = De({
677
+ baseline: m.current,
678
+ entries: s,
679
+ index: d,
680
+ cache: v.current
681
+ });
682
+ return v.current = C, w;
683
+ },
684
+ [s]
685
+ ), N = O(
686
+ (d) => {
687
+ if (!e || !r || d < 0 || d >= s.length) return;
688
+ h((C) => C ?? s.length), a(d), S(!0);
689
+ const w = s[d];
690
+ o({
691
+ type: "TIME_TRAVEL",
692
+ storeId: e,
693
+ state: T(d),
694
+ snapshotVersion: w.snapshotVersion,
695
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
696
+ sourceId: c,
697
+ sourceRole: b.EXTENSION
698
+ });
699
+ },
700
+ [e, s, o, T, r, c]
701
+ ), E = O(() => {
702
+ if (S(!1), a(-1), h(null), r && e && s.length > 0) {
703
+ const d = s.length - 1, w = s[d];
704
+ o({
705
+ type: "TIME_TRAVEL",
706
+ storeId: e,
707
+ state: T(d),
708
+ snapshotVersion: w.snapshotVersion,
709
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
710
+ sourceId: c,
711
+ sourceRole: b.EXTENSION
712
+ });
713
+ }
714
+ }, [e, s, o, T, r, c]), R = l ?? s.length, x = O(() => {
715
+ const d = le("back", {
716
+ isTimeTraveling: u,
717
+ currentIndex: i,
718
+ entryCount: R
719
+ });
720
+ d.kind === "jump" && N(d.index);
721
+ }, [u, i, R, N]), g = O(() => {
722
+ const d = le("forward", {
723
+ isTimeTraveling: u,
724
+ currentIndex: i,
725
+ entryCount: R
726
+ });
727
+ d.kind === "jump" ? N(d.index) : d.kind === "resume" && E();
728
+ }, [u, i, R, N, E]), I = Oe(
729
+ () => T(u ? i : s.length - 1),
730
+ [T, u, i, s.length]
731
+ );
732
+ return {
733
+ currentIndex: i,
734
+ isTimeTraveling: u,
735
+ previewState: I,
736
+ frameCount: l,
737
+ jumpTo: N,
738
+ stepBack: x,
739
+ stepForward: g,
740
+ resume: E
741
+ };
742
+ }
743
+ const z = 0, Q = 1, je = 2, F = 3;
744
+ function $() {
745
+ return {
746
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
747
+ sourceId: "loopback-hub",
748
+ sourceRole: b.HUB
749
+ };
750
+ }
751
+ function fe(e) {
752
+ return e.split(".")[0] ?? "0";
753
+ }
754
+ class Me {
755
+ constructor() {
756
+ this.peers = /* @__PURE__ */ new Set();
757
+ }
758
+ add(s) {
759
+ const r = { role: null, id: null, deliver: s, closed: !1 };
760
+ return this.peers.add(r), r;
761
+ }
762
+ remove(s) {
763
+ if (this.peers.delete(s) && (s.closed = !0, s.role === b.STORE && s.id)) {
764
+ const r = JSON.stringify({
765
+ type: "STORE_DISCONNECTED",
766
+ storeId: s.id,
767
+ reason: "disconnected",
768
+ ...$()
769
+ });
770
+ this.eachExtension((o) => o.deliver(r));
771
+ }
772
+ }
773
+ receive(s, r) {
774
+ if (s.closed) return;
775
+ let o;
776
+ try {
777
+ o = JSON.parse(r);
778
+ } catch {
779
+ return;
780
+ }
781
+ if (!(o === null || typeof o != "object" || typeof o.type != "string")) {
782
+ if (s.role === null) {
783
+ this.handshake(s, o);
784
+ return;
785
+ }
786
+ if (s.role === b.STORE)
787
+ this.eachExtension((t) => t.deliver(r));
788
+ else if (typeof o.storeId == "string")
789
+ for (const t of this.peers)
790
+ t.role === b.STORE && t.id === o.storeId && t.deliver(r);
791
+ }
792
+ }
793
+ handshake(s, r) {
794
+ if (r.type !== "HANDSHAKE_REQUEST") return;
795
+ const o = r.role, t = o === b.STORE ? r.store?.id : o === b.EXTENSION ? r.extension?.id : void 0, i = fe(String(r.protocolVersion ?? "")) === fe(K) && typeof t == "string";
796
+ if (s.deliver(
797
+ JSON.stringify({
798
+ type: "HANDSHAKE_RESPONSE",
799
+ success: i,
800
+ // `negotiatedVersion`, the name the interface and the real hub use. This sent
801
+ // `protocolVersion` instead — harmless only for as long as nothing reads it, and the
802
+ // moment something did, the embedded panel would have failed where the real hub worked,
803
+ // in the one path with no server to inspect.
804
+ negotiatedVersion: K,
805
+ ...$(),
806
+ ...i ? {} : { error: "Loopback handshake rejected (version or id mismatch)" }
807
+ })
808
+ ), !!i)
809
+ if (s.role = o, s.id = t, o === b.STORE) {
810
+ s.storeInfo = { name: r.store?.name ?? t, capabilities: r.store?.capabilities };
811
+ const a = JSON.stringify({
812
+ type: "STORE_CONNECTED",
813
+ store: { id: t, name: s.storeInfo.name, capabilities: s.storeInfo.capabilities },
814
+ ...$()
815
+ });
816
+ this.eachExtension((u) => u.deliver(a));
817
+ } else {
818
+ const a = [...this.peers].filter((u) => u.role === b.STORE && u.storeInfo).map((u) => ({
819
+ id: u.id,
820
+ name: u.storeInfo.name,
821
+ status: "connected",
822
+ capabilities: u.storeInfo.capabilities,
823
+ connectedAt: (/* @__PURE__ */ new Date()).toISOString()
824
+ }));
825
+ s.deliver(JSON.stringify({ type: "STORE_REGISTRY", stores: a, ...$() }));
826
+ }
827
+ }
828
+ eachExtension(s) {
829
+ for (const r of this.peers) r.role === b.EXTENSION && s(r);
830
+ }
831
+ }
832
+ function Ge() {
833
+ const e = new Me(), s = (t, c) => {
834
+ let i = z;
835
+ const a = e.add((u) => c.onMessage(u));
836
+ return queueMicrotask(() => {
837
+ i = Q, c.onOpen();
838
+ }), {
839
+ get readyState() {
840
+ return i;
841
+ },
842
+ send: (u) => e.receive(a, u),
843
+ close: () => {
844
+ i !== F && (i = F, e.remove(a), c.onClose());
845
+ },
846
+ dispose: () => {
847
+ a.closed = !0;
848
+ }
849
+ };
850
+ }, o = class o {
851
+ constructor(c) {
852
+ this.onopen = null, this.onmessage = null, this.onclose = null, this.onerror = null, this.readyState = z, this.peer = e.add((i) => this.onmessage?.({ data: i })), queueMicrotask(() => {
853
+ this.readyState = Q, this.onopen?.();
854
+ });
855
+ }
856
+ send(c) {
857
+ e.receive(this.peer, c);
858
+ }
859
+ close() {
860
+ this.readyState !== F && (this.readyState = F, e.remove(this.peer), this.onclose?.());
861
+ }
862
+ };
863
+ o.CONNECTING = z, o.OPEN = Q, o.CLOSING = je, o.CLOSED = F;
864
+ let r = o;
865
+ return {
866
+ agentSocketFactory: s,
867
+ WebSocket: r
868
+ };
869
+ }
870
+ export {
871
+ de as HubContext,
872
+ Le as HubProvider,
873
+ Z as applyPatches,
874
+ Ge as createLoopbackHub,
875
+ Ue as useEventEmitter,
876
+ Fe as useEventLog,
877
+ He as useEventReplay,
878
+ j as useHubConnection,
879
+ Xe as useStoreMetrics,
880
+ $e as useStoreRegistry,
881
+ Je as useStoreState,
882
+ qe as useStoreSubscriptions,
883
+ We as useTimeTravel
884
+ };
885
+ //# sourceMappingURL=devtools-ui.mjs.map