@mcp-fe/react-event-tracker 0.0.12 → 0.0.14
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.
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { WorkerClientInitOptions } from '@mcp-fe/event-tracker';
|
|
2
|
+
export declare function useReactRouterEventTracker(initOptions?: WorkerClientInitOptions): {
|
|
3
|
+
setAuthToken: (token: string) => void;
|
|
4
|
+
};
|
|
2
5
|
//# sourceMappingURL=useReactRouterEventTracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactRouterEventTracker.d.ts","sourceRoot":"","sources":["../../../../libs/react-event-tracker/src/hooks/useReactRouterEventTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useReactRouterEventTracker.d.ts","sourceRoot":"","sources":["../../../../libs/react-event-tracker/src/hooks/useReactRouterEventTracker.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,uBAAuB,EAC7B,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,0BAA0B,CAAC,WAAW,CAAC,EAAE,uBAAuB,GAAG;IAAE,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CA2F3H"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { WorkerClientInitOptions } from '@mcp-fe/event-tracker';
|
|
2
|
+
export declare function useTanstackRouterEventTracker(initOptions?: WorkerClientInitOptions): {
|
|
3
|
+
setAuthToken: (token: string) => void;
|
|
4
|
+
};
|
|
2
5
|
//# sourceMappingURL=useTanstackRouterEventTracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTanstackRouterEventTracker.d.ts","sourceRoot":"","sources":["../../../../libs/react-event-tracker/src/hooks/useTanstackRouterEventTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTanstackRouterEventTracker.d.ts","sourceRoot":"","sources":["../../../../libs/react-event-tracker/src/hooks/useTanstackRouterEventTracker.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,uBAAuB,EAC7B,MAAM,uBAAuB,CAAC;AAE/B,wBAAgB,6BAA6B,CAAC,WAAW,CAAC,EAAE,uBAAuB,GAAG;IAAE,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CA2F9H"}
|
package/index.mjs
CHANGED
|
@@ -1,360 +1,365 @@
|
|
|
1
1
|
import * as S from "react";
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
function
|
|
2
|
+
import L, { useRef as R, useState as Z, useEffect as _ } from "react";
|
|
3
|
+
const ce = Object.prototype.hasOwnProperty;
|
|
4
|
+
function ee(t, e, r = 0) {
|
|
5
5
|
if (t === e)
|
|
6
6
|
return t;
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
12
|
-
const
|
|
13
|
-
if (!
|
|
14
|
-
const
|
|
15
|
-
let
|
|
16
|
-
for (let
|
|
17
|
-
const p =
|
|
18
|
-
if (
|
|
19
|
-
s[p] =
|
|
7
|
+
if (r > 500) return e;
|
|
8
|
+
const o = e, n = K(t) && K(o);
|
|
9
|
+
if (!n && !(z(t) && z(o))) return o;
|
|
10
|
+
const l = n ? t : V(t);
|
|
11
|
+
if (!l) return o;
|
|
12
|
+
const a = n ? o : V(o);
|
|
13
|
+
if (!a) return o;
|
|
14
|
+
const c = l.length, i = a.length, s = n ? new Array(i) : {};
|
|
15
|
+
let h = 0;
|
|
16
|
+
for (let v = 0; v < i; v++) {
|
|
17
|
+
const p = n ? v : a[v], u = t[p], f = o[p];
|
|
18
|
+
if (u === f) {
|
|
19
|
+
s[p] = u, (n ? v < c : ce.call(t, p)) && h++;
|
|
20
20
|
continue;
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
22
|
+
if (u === null || f === null || typeof u != "object" || typeof f != "object") {
|
|
23
23
|
s[p] = f;
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
|
-
const d =
|
|
27
|
-
s[p] = d, d ===
|
|
26
|
+
const d = ee(u, f, r + 1);
|
|
27
|
+
s[p] = d, d === u && h++;
|
|
28
28
|
}
|
|
29
|
-
return
|
|
29
|
+
return c === i && h === c ? t : s;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
const e = [],
|
|
33
|
-
for (const
|
|
34
|
-
if (!Object.prototype.propertyIsEnumerable.call(t,
|
|
35
|
-
e.push(
|
|
31
|
+
function V(t) {
|
|
32
|
+
const e = [], r = Object.getOwnPropertyNames(t);
|
|
33
|
+
for (const n of r) {
|
|
34
|
+
if (!Object.prototype.propertyIsEnumerable.call(t, n)) return !1;
|
|
35
|
+
e.push(n);
|
|
36
36
|
}
|
|
37
|
-
const
|
|
38
|
-
for (const
|
|
39
|
-
if (!Object.prototype.propertyIsEnumerable.call(t,
|
|
40
|
-
e.push(
|
|
37
|
+
const o = Object.getOwnPropertySymbols(t);
|
|
38
|
+
for (const n of o) {
|
|
39
|
+
if (!Object.prototype.propertyIsEnumerable.call(t, n)) return !1;
|
|
40
|
+
e.push(n);
|
|
41
41
|
}
|
|
42
42
|
return e;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
if (!
|
|
44
|
+
function z(t) {
|
|
45
|
+
if (!G(t))
|
|
46
46
|
return !1;
|
|
47
47
|
const e = t.constructor;
|
|
48
48
|
if (typeof e > "u")
|
|
49
49
|
return !0;
|
|
50
|
-
const
|
|
51
|
-
return !(!
|
|
50
|
+
const r = e.prototype;
|
|
51
|
+
return !(!G(r) || !r.hasOwnProperty("isPrototypeOf"));
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function G(t) {
|
|
54
54
|
return Object.prototype.toString.call(t) === "[object Object]";
|
|
55
55
|
}
|
|
56
|
-
function
|
|
56
|
+
function K(t) {
|
|
57
57
|
return Array.isArray(t) && t.length === Object.keys(t).length;
|
|
58
58
|
}
|
|
59
|
-
var
|
|
60
|
-
function
|
|
61
|
-
if (!
|
|
59
|
+
var ue = process.env.NODE_ENV === "production";
|
|
60
|
+
function le(t, e) {
|
|
61
|
+
if (!ue) {
|
|
62
62
|
if (t)
|
|
63
63
|
return;
|
|
64
|
-
var
|
|
65
|
-
typeof console < "u" && console.warn(
|
|
64
|
+
var r = "Warning: " + e;
|
|
65
|
+
typeof console < "u" && console.warn(r);
|
|
66
66
|
try {
|
|
67
|
-
throw Error(
|
|
67
|
+
throw Error(r);
|
|
68
68
|
} catch {
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
var C = { exports: {} },
|
|
73
|
-
var
|
|
74
|
-
function
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
var t =
|
|
78
|
-
function e(
|
|
79
|
-
return
|
|
72
|
+
var C = { exports: {} }, A = {}, N = { exports: {} }, b = {};
|
|
73
|
+
var H;
|
|
74
|
+
function fe() {
|
|
75
|
+
if (H) return b;
|
|
76
|
+
H = 1;
|
|
77
|
+
var t = L;
|
|
78
|
+
function e(v, p) {
|
|
79
|
+
return v === p && (v !== 0 || 1 / v === 1 / p) || v !== v && p !== p;
|
|
80
80
|
}
|
|
81
|
-
var
|
|
82
|
-
function
|
|
83
|
-
var
|
|
84
|
-
return
|
|
81
|
+
var r = typeof Object.is == "function" ? Object.is : e, o = t.useState, n = t.useEffect, l = t.useLayoutEffect, a = t.useDebugValue;
|
|
82
|
+
function c(v, p) {
|
|
83
|
+
var u = p(), f = o({ inst: { value: u, getSnapshot: p } }), d = f[0].inst, k = f[1];
|
|
84
|
+
return l(
|
|
85
85
|
function() {
|
|
86
|
-
d.value =
|
|
86
|
+
d.value = u, d.getSnapshot = p, i(d) && k({ inst: d });
|
|
87
87
|
},
|
|
88
|
-
[
|
|
89
|
-
),
|
|
88
|
+
[v, u, p]
|
|
89
|
+
), n(
|
|
90
90
|
function() {
|
|
91
|
-
return
|
|
92
|
-
|
|
91
|
+
return i(d) && k({ inst: d }), v(function() {
|
|
92
|
+
i(d) && k({ inst: d });
|
|
93
93
|
});
|
|
94
94
|
},
|
|
95
|
-
[
|
|
96
|
-
),
|
|
95
|
+
[v]
|
|
96
|
+
), a(u), u;
|
|
97
97
|
}
|
|
98
|
-
function
|
|
99
|
-
var p =
|
|
100
|
-
|
|
98
|
+
function i(v) {
|
|
99
|
+
var p = v.getSnapshot;
|
|
100
|
+
v = v.value;
|
|
101
101
|
try {
|
|
102
|
-
var
|
|
103
|
-
return !
|
|
102
|
+
var u = p();
|
|
103
|
+
return !r(v, u);
|
|
104
104
|
} catch {
|
|
105
105
|
return !0;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
function s(
|
|
108
|
+
function s(v, p) {
|
|
109
109
|
return p();
|
|
110
110
|
}
|
|
111
|
-
var
|
|
112
|
-
return
|
|
111
|
+
var h = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? s : c;
|
|
112
|
+
return b.useSyncExternalStore = t.useSyncExternalStore !== void 0 ? t.useSyncExternalStore : h, b;
|
|
113
113
|
}
|
|
114
|
-
var
|
|
114
|
+
var I = {};
|
|
115
115
|
var F;
|
|
116
|
-
function
|
|
116
|
+
function de() {
|
|
117
117
|
return F || (F = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
118
|
-
function t(
|
|
119
|
-
return
|
|
118
|
+
function t(u, f) {
|
|
119
|
+
return u === f && (u !== 0 || 1 / u === 1 / f) || u !== u && f !== f;
|
|
120
120
|
}
|
|
121
|
-
function e(
|
|
122
|
-
|
|
121
|
+
function e(u, f) {
|
|
122
|
+
h || n.startTransition === void 0 || (h = !0, console.error(
|
|
123
123
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
124
124
|
));
|
|
125
125
|
var d = f();
|
|
126
|
-
if (!
|
|
126
|
+
if (!v) {
|
|
127
127
|
var k = f();
|
|
128
|
-
|
|
128
|
+
l(d, k) || (console.error(
|
|
129
129
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
130
|
-
),
|
|
130
|
+
), v = !0);
|
|
131
131
|
}
|
|
132
|
-
k =
|
|
132
|
+
k = a({
|
|
133
133
|
inst: { value: d, getSnapshot: f }
|
|
134
134
|
});
|
|
135
|
-
var g = k[0].inst,
|
|
136
|
-
return
|
|
135
|
+
var g = k[0].inst, y = k[1];
|
|
136
|
+
return i(
|
|
137
137
|
function() {
|
|
138
|
-
g.value = d, g.getSnapshot = f,
|
|
138
|
+
g.value = d, g.getSnapshot = f, r(g) && y({ inst: g });
|
|
139
139
|
},
|
|
140
|
-
[
|
|
141
|
-
),
|
|
140
|
+
[u, d, f]
|
|
141
|
+
), c(
|
|
142
142
|
function() {
|
|
143
|
-
return
|
|
144
|
-
|
|
143
|
+
return r(g) && y({ inst: g }), u(function() {
|
|
144
|
+
r(g) && y({ inst: g });
|
|
145
145
|
});
|
|
146
146
|
},
|
|
147
|
-
[
|
|
147
|
+
[u]
|
|
148
148
|
), s(d), d;
|
|
149
149
|
}
|
|
150
|
-
function
|
|
151
|
-
var f =
|
|
152
|
-
|
|
150
|
+
function r(u) {
|
|
151
|
+
var f = u.getSnapshot;
|
|
152
|
+
u = u.value;
|
|
153
153
|
try {
|
|
154
154
|
var d = f();
|
|
155
|
-
return !
|
|
155
|
+
return !l(u, d);
|
|
156
156
|
} catch {
|
|
157
157
|
return !0;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
function
|
|
160
|
+
function o(u, f) {
|
|
161
161
|
return f();
|
|
162
162
|
}
|
|
163
163
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
})()),
|
|
167
|
-
}
|
|
168
|
-
var G;
|
|
169
|
-
function ee() {
|
|
170
|
-
return G || (G = 1, process.env.NODE_ENV === "production" ? N.exports = le() : N.exports = fe()), N.exports;
|
|
164
|
+
var n = L, l = typeof Object.is == "function" ? Object.is : t, a = n.useState, c = n.useEffect, i = n.useLayoutEffect, s = n.useDebugValue, h = !1, v = !1, p = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? o : e;
|
|
165
|
+
I.useSyncExternalStore = n.useSyncExternalStore !== void 0 ? n.useSyncExternalStore : p, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
166
|
+
})()), I;
|
|
171
167
|
}
|
|
172
168
|
var q;
|
|
173
|
-
function
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
169
|
+
function te() {
|
|
170
|
+
return q || (q = 1, process.env.NODE_ENV === "production" ? N.exports = fe() : N.exports = de()), N.exports;
|
|
171
|
+
}
|
|
172
|
+
var X;
|
|
173
|
+
function he() {
|
|
174
|
+
if (X) return A;
|
|
175
|
+
X = 1;
|
|
176
|
+
var t = L, e = te();
|
|
177
|
+
function r(s, h) {
|
|
178
|
+
return s === h && (s !== 0 || 1 / s === 1 / h) || s !== s && h !== h;
|
|
179
179
|
}
|
|
180
|
-
var
|
|
181
|
-
return
|
|
182
|
-
var f =
|
|
180
|
+
var o = typeof Object.is == "function" ? Object.is : r, n = e.useSyncExternalStore, l = t.useRef, a = t.useEffect, c = t.useMemo, i = t.useDebugValue;
|
|
181
|
+
return A.useSyncExternalStoreWithSelector = function(s, h, v, p, u) {
|
|
182
|
+
var f = l(null);
|
|
183
183
|
if (f.current === null) {
|
|
184
184
|
var d = { hasValue: !1, value: null };
|
|
185
185
|
f.current = d;
|
|
186
186
|
} else d = f.current;
|
|
187
|
-
f =
|
|
187
|
+
f = c(
|
|
188
188
|
function() {
|
|
189
189
|
function g(m) {
|
|
190
|
-
if (!
|
|
191
|
-
if (
|
|
190
|
+
if (!y) {
|
|
191
|
+
if (y = !0, T = m, m = p(m), u !== void 0 && d.hasValue) {
|
|
192
192
|
var E = d.value;
|
|
193
|
-
if (
|
|
193
|
+
if (u(E, m))
|
|
194
194
|
return O = E;
|
|
195
195
|
}
|
|
196
196
|
return O = m;
|
|
197
197
|
}
|
|
198
|
-
if (E = O,
|
|
199
|
-
var
|
|
200
|
-
return
|
|
198
|
+
if (E = O, o(T, m)) return E;
|
|
199
|
+
var w = p(m);
|
|
200
|
+
return u !== void 0 && u(E, w) ? (T = m, E) : (T = m, O = w);
|
|
201
201
|
}
|
|
202
|
-
var
|
|
202
|
+
var y = !1, T, O, W = v === void 0 ? null : v;
|
|
203
203
|
return [
|
|
204
204
|
function() {
|
|
205
|
-
return g(
|
|
205
|
+
return g(h());
|
|
206
206
|
},
|
|
207
|
-
|
|
208
|
-
return g(
|
|
207
|
+
W === null ? void 0 : function() {
|
|
208
|
+
return g(W());
|
|
209
209
|
}
|
|
210
210
|
];
|
|
211
211
|
},
|
|
212
|
-
[
|
|
212
|
+
[h, v, p, u]
|
|
213
213
|
);
|
|
214
|
-
var k =
|
|
215
|
-
return
|
|
214
|
+
var k = n(s, f[0], f[1]);
|
|
215
|
+
return a(
|
|
216
216
|
function() {
|
|
217
217
|
d.hasValue = !0, d.value = k;
|
|
218
218
|
},
|
|
219
219
|
[k]
|
|
220
|
-
),
|
|
221
|
-
},
|
|
220
|
+
), i(k), k;
|
|
221
|
+
}, A;
|
|
222
222
|
}
|
|
223
|
-
var
|
|
224
|
-
var
|
|
225
|
-
function
|
|
226
|
-
return
|
|
227
|
-
function t(s,
|
|
228
|
-
return s ===
|
|
223
|
+
var P = {};
|
|
224
|
+
var $;
|
|
225
|
+
function ve() {
|
|
226
|
+
return $ || ($ = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
227
|
+
function t(s, h) {
|
|
228
|
+
return s === h && (s !== 0 || 1 / s === 1 / h) || s !== s && h !== h;
|
|
229
229
|
}
|
|
230
230
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
231
|
-
var e =
|
|
232
|
-
|
|
233
|
-
var f =
|
|
231
|
+
var e = L, r = te(), o = typeof Object.is == "function" ? Object.is : t, n = r.useSyncExternalStore, l = e.useRef, a = e.useEffect, c = e.useMemo, i = e.useDebugValue;
|
|
232
|
+
P.useSyncExternalStoreWithSelector = function(s, h, v, p, u) {
|
|
233
|
+
var f = l(null);
|
|
234
234
|
if (f.current === null) {
|
|
235
235
|
var d = { hasValue: !1, value: null };
|
|
236
236
|
f.current = d;
|
|
237
237
|
} else d = f.current;
|
|
238
|
-
f =
|
|
238
|
+
f = c(
|
|
239
239
|
function() {
|
|
240
240
|
function g(m) {
|
|
241
|
-
if (!
|
|
242
|
-
if (
|
|
241
|
+
if (!y) {
|
|
242
|
+
if (y = !0, T = m, m = p(m), u !== void 0 && d.hasValue) {
|
|
243
243
|
var E = d.value;
|
|
244
|
-
if (
|
|
244
|
+
if (u(E, m))
|
|
245
245
|
return O = E;
|
|
246
246
|
}
|
|
247
247
|
return O = m;
|
|
248
248
|
}
|
|
249
|
-
if (E = O,
|
|
249
|
+
if (E = O, o(T, m))
|
|
250
250
|
return E;
|
|
251
|
-
var
|
|
252
|
-
return
|
|
251
|
+
var w = p(m);
|
|
252
|
+
return u !== void 0 && u(E, w) ? (T = m, E) : (T = m, O = w);
|
|
253
253
|
}
|
|
254
|
-
var
|
|
254
|
+
var y = !1, T, O, W = v === void 0 ? null : v;
|
|
255
255
|
return [
|
|
256
256
|
function() {
|
|
257
|
-
return g(
|
|
257
|
+
return g(h());
|
|
258
258
|
},
|
|
259
|
-
|
|
260
|
-
return g(
|
|
259
|
+
W === null ? void 0 : function() {
|
|
260
|
+
return g(W());
|
|
261
261
|
}
|
|
262
262
|
];
|
|
263
263
|
},
|
|
264
|
-
[
|
|
264
|
+
[h, v, p, u]
|
|
265
265
|
);
|
|
266
|
-
var k =
|
|
267
|
-
return
|
|
266
|
+
var k = n(s, f[0], f[1]);
|
|
267
|
+
return a(
|
|
268
268
|
function() {
|
|
269
269
|
d.hasValue = !0, d.value = k;
|
|
270
270
|
},
|
|
271
271
|
[k]
|
|
272
|
-
),
|
|
272
|
+
), i(k), k;
|
|
273
273
|
}, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
274
|
-
})()),
|
|
274
|
+
})()), P;
|
|
275
275
|
}
|
|
276
|
-
var
|
|
276
|
+
var j;
|
|
277
277
|
function pe() {
|
|
278
|
-
return
|
|
278
|
+
return j || (j = 1, process.env.NODE_ENV === "production" ? C.exports = he() : C.exports = ve()), C.exports;
|
|
279
279
|
}
|
|
280
|
-
var
|
|
281
|
-
function
|
|
282
|
-
const
|
|
283
|
-
return
|
|
280
|
+
var ke = pe();
|
|
281
|
+
function me(t, e = (o) => o, r = {}) {
|
|
282
|
+
const o = r.equal ?? ge;
|
|
283
|
+
return ke.useSyncExternalStoreWithSelector(
|
|
284
284
|
t.subscribe,
|
|
285
285
|
() => t.state,
|
|
286
286
|
() => t.state,
|
|
287
287
|
e,
|
|
288
|
-
|
|
288
|
+
o
|
|
289
289
|
);
|
|
290
290
|
}
|
|
291
|
-
function
|
|
291
|
+
function ge(t, e) {
|
|
292
292
|
if (Object.is(t, e))
|
|
293
293
|
return !0;
|
|
294
294
|
if (typeof t != "object" || t === null || typeof e != "object" || e === null)
|
|
295
295
|
return !1;
|
|
296
296
|
if (t instanceof Map && e instanceof Map) {
|
|
297
297
|
if (t.size !== e.size) return !1;
|
|
298
|
-
for (const [
|
|
299
|
-
if (!e.has(
|
|
298
|
+
for (const [o, n] of t)
|
|
299
|
+
if (!e.has(o) || !Object.is(n, e.get(o))) return !1;
|
|
300
300
|
return !0;
|
|
301
301
|
}
|
|
302
302
|
if (t instanceof Set && e instanceof Set) {
|
|
303
303
|
if (t.size !== e.size) return !1;
|
|
304
|
-
for (const
|
|
305
|
-
if (!e.has(
|
|
304
|
+
for (const o of t)
|
|
305
|
+
if (!e.has(o)) return !1;
|
|
306
306
|
return !0;
|
|
307
307
|
}
|
|
308
308
|
if (t instanceof Date && e instanceof Date)
|
|
309
309
|
return t.getTime() === e.getTime();
|
|
310
|
-
const
|
|
311
|
-
if (
|
|
310
|
+
const r = Y(t);
|
|
311
|
+
if (r.length !== Y(e).length)
|
|
312
312
|
return !1;
|
|
313
|
-
for (let
|
|
314
|
-
if (!Object.prototype.hasOwnProperty.call(e,
|
|
313
|
+
for (let o = 0; o < r.length; o++)
|
|
314
|
+
if (!Object.prototype.hasOwnProperty.call(e, r[o]) || !Object.is(t[r[o]], e[r[o]]))
|
|
315
315
|
return !1;
|
|
316
316
|
return !0;
|
|
317
317
|
}
|
|
318
|
-
function
|
|
318
|
+
function Y(t) {
|
|
319
319
|
return Object.keys(t).concat(
|
|
320
320
|
Object.getOwnPropertySymbols(t)
|
|
321
321
|
);
|
|
322
322
|
}
|
|
323
|
-
const
|
|
324
|
-
function
|
|
325
|
-
return typeof document > "u" ?
|
|
323
|
+
const U = S.createContext(null);
|
|
324
|
+
function Ee() {
|
|
325
|
+
return typeof document > "u" ? U : window.__TSR_ROUTER_CONTEXT__ ? window.__TSR_ROUTER_CONTEXT__ : (window.__TSR_ROUTER_CONTEXT__ = U, U);
|
|
326
326
|
}
|
|
327
|
-
function
|
|
328
|
-
const e = S.useContext(
|
|
329
|
-
return
|
|
327
|
+
function Se(t) {
|
|
328
|
+
const e = S.useContext(Ee());
|
|
329
|
+
return le(
|
|
330
330
|
!((t?.warn ?? !0) && !e),
|
|
331
331
|
"useRouter must be used inside a <RouterProvider> component!"
|
|
332
332
|
), e;
|
|
333
333
|
}
|
|
334
|
-
function
|
|
335
|
-
const e =
|
|
334
|
+
function _e(t) {
|
|
335
|
+
const e = Se({
|
|
336
336
|
warn: t?.router === void 0
|
|
337
|
-
}),
|
|
338
|
-
return
|
|
337
|
+
}), r = t?.router || e, o = R(void 0);
|
|
338
|
+
return me(r.__store, (n) => {
|
|
339
339
|
if (t?.select) {
|
|
340
|
-
if (t.structuralSharing ??
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
t.select(
|
|
340
|
+
if (t.structuralSharing ?? r.options.defaultStructuralSharing) {
|
|
341
|
+
const l = ee(
|
|
342
|
+
o.current,
|
|
343
|
+
t.select(n)
|
|
344
344
|
);
|
|
345
|
-
return
|
|
345
|
+
return o.current = l, l;
|
|
346
346
|
}
|
|
347
|
-
return t.select(
|
|
347
|
+
return t.select(n);
|
|
348
348
|
}
|
|
349
|
-
return
|
|
349
|
+
return n;
|
|
350
350
|
});
|
|
351
351
|
}
|
|
352
|
-
function
|
|
353
|
-
return
|
|
352
|
+
function ye(t) {
|
|
353
|
+
return _e({
|
|
354
354
|
select: (e) => e.location
|
|
355
355
|
});
|
|
356
356
|
}
|
|
357
357
|
class Te {
|
|
358
|
+
// Configurable worker script URLs (defaults kept for backward compatibility)
|
|
359
|
+
sharedWorkerUrl = "/mcp-shared-worker.js";
|
|
360
|
+
serviceWorkerUrl = "/mcp-service-worker.js";
|
|
361
|
+
// Backend websocket URL to pass into the worker(s)
|
|
362
|
+
backendWsUrl = "ws://localhost:3001";
|
|
358
363
|
serviceWorkerRegistration = null;
|
|
359
364
|
sharedWorker = null;
|
|
360
365
|
sharedWorkerPort = null;
|
|
@@ -362,197 +367,236 @@ class Te {
|
|
|
362
367
|
pendingAuthToken = null;
|
|
363
368
|
// connection status subscribers
|
|
364
369
|
connectionStatusCallbacks = /* @__PURE__ */ new Set();
|
|
365
|
-
serviceWorkerMessageHandler = null;
|
|
366
370
|
// Mutex/promise to prevent concurrent init runs
|
|
367
371
|
initPromise = null;
|
|
368
372
|
// Initialize and choose worker implementation (prefer SharedWorker)
|
|
373
|
+
// Accept either a ServiceWorkerRegistration OR WorkerInitOptions to configure URLs
|
|
369
374
|
async init(e) {
|
|
375
|
+
let r;
|
|
376
|
+
const o = e;
|
|
377
|
+
if (o && typeof o.scope == "string")
|
|
378
|
+
r = e;
|
|
379
|
+
else if (e) {
|
|
380
|
+
const n = e;
|
|
381
|
+
n.sharedWorkerUrl && (this.sharedWorkerUrl = n.sharedWorkerUrl), n.serviceWorkerUrl && (this.serviceWorkerUrl = n.serviceWorkerUrl), n.backendWsUrl && (this.backendWsUrl = n.backendWsUrl);
|
|
382
|
+
}
|
|
370
383
|
return this.initPromise ? this.initPromise.then(async () => {
|
|
371
|
-
|
|
384
|
+
r && this.workerType !== "service" && await this.init(r);
|
|
372
385
|
}) : (this.initPromise = (async () => {
|
|
373
386
|
try {
|
|
374
|
-
if (
|
|
375
|
-
this.serviceWorkerRegistration =
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
if (typeof SharedWorker < "u")
|
|
387
|
+
if (r) {
|
|
388
|
+
this.serviceWorkerRegistration = r, this.workerType = "service", console.log(
|
|
389
|
+
"[WorkerClient] Using ServiceWorker (explicit registration)"
|
|
390
|
+
);
|
|
379
391
|
try {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
} catch (r) {
|
|
384
|
-
console.warn("[WorkerClient] Immediate postMessage to SharedWorker failed (will retry after init):", r);
|
|
385
|
-
}
|
|
386
|
-
this.sharedWorker.onerror = (r) => {
|
|
387
|
-
console.error("[WorkerClient] SharedWorker error:", r.message || r.error || r), this.workerType !== "shared" && this.initServiceWorkerFallback().catch((o) => {
|
|
388
|
-
console.error("[WorkerClient] Failed to initialize ServiceWorker fallback:", o);
|
|
389
|
-
});
|
|
390
|
-
}, await new Promise((r, o) => {
|
|
391
|
-
let i = !1;
|
|
392
|
-
const c = setTimeout(() => {
|
|
393
|
-
if (!i) {
|
|
394
|
-
const a = this.sharedWorkerPort;
|
|
395
|
-
a && (a.onmessage = null), o(new Error("SharedWorker initialization timeout"));
|
|
396
|
-
}
|
|
397
|
-
}, 2e3), u = this.sharedWorkerPort;
|
|
398
|
-
if (!u)
|
|
399
|
-
return clearTimeout(c), o(new Error("SharedWorker port not available"));
|
|
400
|
-
u.onmessage = (a) => {
|
|
401
|
-
try {
|
|
402
|
-
const s = a.data;
|
|
403
|
-
s && s.type === "CONNECTION_STATUS" && (clearTimeout(c), i = !0, this.workerType = "shared", u.onmessage = null, r());
|
|
404
|
-
} catch {
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
|
-
});
|
|
408
|
-
const n = this.sharedWorkerPort;
|
|
409
|
-
if (this.pendingAuthToken && n)
|
|
410
|
-
try {
|
|
411
|
-
n.postMessage({ type: "SET_AUTH_TOKEN", token: this.pendingAuthToken }), this.pendingAuthToken = null;
|
|
412
|
-
} catch (r) {
|
|
413
|
-
console.error("[WorkerClient] Failed to send pending auth token to SharedWorker:", r);
|
|
414
|
-
}
|
|
415
|
-
n && (n.onmessage = (r) => {
|
|
416
|
-
try {
|
|
417
|
-
const o = r.data;
|
|
418
|
-
if (o && o.type === "CONNECTION_STATUS") {
|
|
419
|
-
const i = !!o.connected;
|
|
420
|
-
this.connectionStatusCallbacks.forEach((c) => {
|
|
421
|
-
try {
|
|
422
|
-
c(i);
|
|
423
|
-
} catch {
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
} catch {
|
|
428
|
-
}
|
|
429
|
-
}), console.log("[WorkerClient] Using SharedWorker");
|
|
430
|
-
return;
|
|
431
|
-
} catch (n) {
|
|
432
|
-
console.warn("[WorkerClient] SharedWorker not available, falling back to ServiceWorker:", n);
|
|
392
|
+
const l = { type: "INIT", backendUrl: this.backendWsUrl };
|
|
393
|
+
this.pendingAuthToken && (l.token = this.pendingAuthToken), this.serviceWorkerRegistration.active ? this.serviceWorkerRegistration.active.postMessage(l) : "serviceWorker" in navigator && navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage(l);
|
|
394
|
+
} catch {
|
|
433
395
|
}
|
|
434
|
-
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (await this.initSharedWorker()) return;
|
|
399
|
+
await this.initServiceWorkerFallback();
|
|
435
400
|
} finally {
|
|
436
401
|
this.initPromise = null;
|
|
437
402
|
}
|
|
438
403
|
})(), this.initPromise);
|
|
439
404
|
}
|
|
440
|
-
async
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
405
|
+
async initSharedWorker() {
|
|
406
|
+
if (typeof SharedWorker > "u")
|
|
407
|
+
return !1;
|
|
408
|
+
try {
|
|
409
|
+
this.sharedWorker = new SharedWorker(this.sharedWorkerUrl, {
|
|
410
|
+
type: "module"
|
|
411
|
+
}), this.sharedWorkerPort = this.sharedWorker.port, this.sharedWorkerPort.start(), await new Promise((r, o) => {
|
|
412
|
+
let n = !1;
|
|
413
|
+
const l = setTimeout(() => {
|
|
414
|
+
if (!n) {
|
|
415
|
+
const c = this.sharedWorkerPort;
|
|
416
|
+
c && (c.onmessage = null), o(new Error("SharedWorker initialization timeout"));
|
|
417
|
+
}
|
|
418
|
+
}, 2e3), a = this.sharedWorkerPort;
|
|
419
|
+
if (!a)
|
|
420
|
+
return clearTimeout(l), o(new Error("SharedWorker port not available"));
|
|
421
|
+
a.onmessage = (c) => {
|
|
422
|
+
try {
|
|
423
|
+
const i = c.data;
|
|
424
|
+
i && i.type === "CONNECTION_STATUS" && (clearTimeout(l), n = !0, this.workerType = "shared", a.onmessage = null, r());
|
|
425
|
+
} catch {
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
const e = this.sharedWorkerPort;
|
|
430
|
+
if (e) {
|
|
431
|
+
try {
|
|
432
|
+
const r = { type: "INIT", backendUrl: this.backendWsUrl };
|
|
433
|
+
this.pendingAuthToken && (r.token = this.pendingAuthToken), e.postMessage(r), this.pendingAuthToken = null;
|
|
434
|
+
} catch (r) {
|
|
435
|
+
console.warn("[WorkerClient] Failed to send INIT to SharedWorker port:", r);
|
|
447
436
|
}
|
|
448
|
-
|
|
449
|
-
this.serviceWorkerRegistration = n, this.workerType = "service", console.log("[WorkerClient] Using ServiceWorker (fallback)"), this.serviceWorkerMessageHandler && (navigator.serviceWorker.removeEventListener("message", this.serviceWorkerMessageHandler), this.serviceWorkerMessageHandler = null), this.serviceWorkerMessageHandler = (r) => {
|
|
437
|
+
e.onmessage = (r) => {
|
|
450
438
|
try {
|
|
451
439
|
const o = r.data;
|
|
452
440
|
if (o && o.type === "CONNECTION_STATUS") {
|
|
453
|
-
const
|
|
454
|
-
this.connectionStatusCallbacks.forEach((
|
|
441
|
+
const n = !!o.connected;
|
|
442
|
+
this.connectionStatusCallbacks.forEach((l) => {
|
|
455
443
|
try {
|
|
456
|
-
|
|
444
|
+
l(n);
|
|
457
445
|
} catch {
|
|
458
446
|
}
|
|
459
447
|
});
|
|
460
448
|
}
|
|
461
449
|
} catch {
|
|
462
450
|
}
|
|
463
|
-
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return console.log("[WorkerClient] Using SharedWorker"), !0;
|
|
454
|
+
} catch (e) {
|
|
455
|
+
return console.warn(
|
|
456
|
+
"[WorkerClient] SharedWorker not available, falling back to ServiceWorker:",
|
|
457
|
+
e
|
|
458
|
+
), !1;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
async initServiceWorkerFallback() {
|
|
462
|
+
if ("serviceWorker" in navigator)
|
|
463
|
+
try {
|
|
464
|
+
const e = await navigator.serviceWorker.getRegistration();
|
|
465
|
+
if (e) {
|
|
466
|
+
this.serviceWorkerRegistration = e, this.workerType = "service", console.log(
|
|
467
|
+
"[WorkerClient] Using existing ServiceWorker registration"
|
|
468
|
+
);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this.serviceWorkerRegistration = await navigator.serviceWorker.register(
|
|
472
|
+
this.serviceWorkerUrl
|
|
473
|
+
), this.workerType = "service", console.log("[WorkerClient] Using MCP ServiceWorker (fallback)");
|
|
474
|
+
try {
|
|
475
|
+
const r = { type: "INIT", backendUrl: this.backendWsUrl };
|
|
476
|
+
this.pendingAuthToken && (r.token = this.pendingAuthToken), this.serviceWorkerRegistration.active ? this.serviceWorkerRegistration.active.postMessage(r) : "serviceWorker" in navigator && navigator.serviceWorker.controller && navigator.serviceWorker.controller.postMessage(r), this.pendingAuthToken = null;
|
|
477
|
+
} catch {
|
|
478
|
+
}
|
|
464
479
|
} catch (e) {
|
|
465
|
-
throw console.error(
|
|
480
|
+
throw console.error(
|
|
481
|
+
"[WorkerClient] Failed to register ServiceWorker:",
|
|
482
|
+
e
|
|
483
|
+
), e;
|
|
466
484
|
}
|
|
467
485
|
else
|
|
468
486
|
throw new Error("Neither SharedWorker nor ServiceWorker is supported");
|
|
469
487
|
}
|
|
470
488
|
// Low-level request that expects a reply via MessageChannel
|
|
471
|
-
async request(e,
|
|
489
|
+
async request(e, r, o = 5e3) {
|
|
472
490
|
if (this.workerType === "shared" && this.sharedWorkerPort)
|
|
473
|
-
return new Promise((
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
},
|
|
477
|
-
|
|
478
|
-
clearTimeout(
|
|
491
|
+
return new Promise((n, l) => {
|
|
492
|
+
const a = new MessageChannel(), c = setTimeout(() => {
|
|
493
|
+
a.port1.onmessage = null, l(new Error("Request timeout"));
|
|
494
|
+
}, o);
|
|
495
|
+
a.port1.onmessage = (i) => {
|
|
496
|
+
clearTimeout(c), i.data && i.data.success ? n(i.data) : i.data && i.data.success === !1 ? l(new Error(i.data.error || "Worker error")) : n(i.data);
|
|
479
497
|
};
|
|
480
498
|
try {
|
|
481
|
-
const
|
|
482
|
-
if (!
|
|
483
|
-
return clearTimeout(
|
|
484
|
-
|
|
485
|
-
} catch (
|
|
486
|
-
clearTimeout(
|
|
499
|
+
const i = this.sharedWorkerPort;
|
|
500
|
+
if (!i)
|
|
501
|
+
return clearTimeout(c), l(new Error("SharedWorker port not available"));
|
|
502
|
+
i.postMessage({ type: e, ...r || {} }, [a.port2]);
|
|
503
|
+
} catch (i) {
|
|
504
|
+
clearTimeout(c), l(i instanceof Error ? i : new Error(String(i)));
|
|
487
505
|
}
|
|
488
506
|
});
|
|
489
507
|
if (this.workerType === "service" && this.serviceWorkerRegistration) {
|
|
490
|
-
const
|
|
491
|
-
if (!
|
|
492
|
-
if (!
|
|
508
|
+
const n = this.serviceWorkerRegistration;
|
|
509
|
+
if (!n) throw new Error("Service worker registration missing");
|
|
510
|
+
if (!n.active && (await navigator.serviceWorker.ready, !n.active))
|
|
493
511
|
throw new Error("Service worker not active");
|
|
494
|
-
return new Promise((
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
},
|
|
498
|
-
|
|
499
|
-
clearTimeout(
|
|
512
|
+
return new Promise((l, a) => {
|
|
513
|
+
const c = new MessageChannel(), i = setTimeout(() => {
|
|
514
|
+
c.port1.onmessage = null, a(new Error("Request timeout"));
|
|
515
|
+
}, o);
|
|
516
|
+
c.port1.onmessage = (s) => {
|
|
517
|
+
clearTimeout(i), s.data && s.data.success ? l(s.data) : s.data && s.data.success === !1 ? a(new Error(s.data.error || "Worker error")) : l(s.data);
|
|
500
518
|
};
|
|
501
519
|
try {
|
|
502
|
-
const s =
|
|
520
|
+
const s = n.active;
|
|
503
521
|
if (!s)
|
|
504
|
-
return clearTimeout(
|
|
505
|
-
|
|
522
|
+
return clearTimeout(i), a(
|
|
523
|
+
new Error("Service worker active instance not available")
|
|
524
|
+
);
|
|
525
|
+
s.postMessage({ type: e, ...r || {} }, [c.port2]);
|
|
506
526
|
} catch (s) {
|
|
507
|
-
clearTimeout(
|
|
527
|
+
clearTimeout(i), a(s instanceof Error ? s : new Error(String(s)));
|
|
508
528
|
}
|
|
509
529
|
});
|
|
510
530
|
}
|
|
511
531
|
throw new Error("No worker registered");
|
|
512
532
|
}
|
|
513
533
|
// Fire-and-forget postMessage (no response expected)
|
|
514
|
-
async post(e,
|
|
534
|
+
async post(e, r) {
|
|
515
535
|
if (this.workerType === "shared" && this.sharedWorkerPort) {
|
|
516
536
|
try {
|
|
517
|
-
this.sharedWorkerPort.postMessage({ type: e, ...
|
|
518
|
-
} catch (
|
|
519
|
-
console.error("[WorkerClient] Failed to post to SharedWorker:",
|
|
537
|
+
this.sharedWorkerPort.postMessage({ type: e, ...r || {} });
|
|
538
|
+
} catch (o) {
|
|
539
|
+
console.error("[WorkerClient] Failed to post to SharedWorker:", o);
|
|
520
540
|
}
|
|
521
541
|
return;
|
|
522
542
|
}
|
|
523
543
|
if (this.workerType === "service" && this.serviceWorkerRegistration?.active) {
|
|
524
544
|
try {
|
|
525
|
-
this.serviceWorkerRegistration.active.postMessage({
|
|
526
|
-
|
|
527
|
-
|
|
545
|
+
this.serviceWorkerRegistration.active.postMessage({
|
|
546
|
+
type: e,
|
|
547
|
+
...r || {}
|
|
548
|
+
});
|
|
549
|
+
} catch (o) {
|
|
550
|
+
console.error(
|
|
551
|
+
"[WorkerClient] Failed to post to ServiceWorker (active):",
|
|
552
|
+
o
|
|
553
|
+
);
|
|
528
554
|
}
|
|
529
555
|
return;
|
|
530
556
|
}
|
|
531
557
|
if ("serviceWorker" in navigator && navigator.serviceWorker.controller) {
|
|
532
558
|
try {
|
|
533
|
-
navigator.serviceWorker.controller.postMessage({
|
|
534
|
-
|
|
535
|
-
|
|
559
|
+
navigator.serviceWorker.controller.postMessage({
|
|
560
|
+
type: e,
|
|
561
|
+
...r || {}
|
|
562
|
+
});
|
|
563
|
+
} catch (o) {
|
|
564
|
+
console.error(
|
|
565
|
+
"[WorkerClient] Failed to post to ServiceWorker.controller:",
|
|
566
|
+
o
|
|
567
|
+
);
|
|
536
568
|
}
|
|
537
569
|
return;
|
|
538
570
|
}
|
|
539
|
-
if (e === "SET_AUTH_TOKEN" &&
|
|
540
|
-
const
|
|
541
|
-
typeof
|
|
571
|
+
if (e === "SET_AUTH_TOKEN" && r) {
|
|
572
|
+
const o = r.token;
|
|
573
|
+
typeof o == "string" && (this.pendingAuthToken = o);
|
|
542
574
|
}
|
|
543
575
|
}
|
|
544
576
|
sendAuthTokenToServiceWorker(e) {
|
|
545
577
|
if (this.serviceWorkerRegistration?.active)
|
|
546
578
|
try {
|
|
547
|
-
this.serviceWorkerRegistration.active.postMessage({
|
|
548
|
-
|
|
549
|
-
|
|
579
|
+
this.serviceWorkerRegistration.active.postMessage({
|
|
580
|
+
type: "SET_AUTH_TOKEN",
|
|
581
|
+
token: e
|
|
582
|
+
});
|
|
583
|
+
} catch (r) {
|
|
584
|
+
console.error(
|
|
585
|
+
"[WorkerClient] Failed to send auth token to ServiceWorker:",
|
|
586
|
+
r
|
|
587
|
+
);
|
|
550
588
|
}
|
|
551
589
|
else if ("serviceWorker" in navigator && navigator.serviceWorker.controller)
|
|
552
590
|
try {
|
|
553
|
-
navigator.serviceWorker.controller.postMessage({
|
|
554
|
-
|
|
555
|
-
|
|
591
|
+
navigator.serviceWorker.controller.postMessage({
|
|
592
|
+
type: "SET_AUTH_TOKEN",
|
|
593
|
+
token: e
|
|
594
|
+
});
|
|
595
|
+
} catch (r) {
|
|
596
|
+
console.error(
|
|
597
|
+
"[WorkerClient] Failed to send auth token to ServiceWorker.controller:",
|
|
598
|
+
r
|
|
599
|
+
);
|
|
556
600
|
}
|
|
557
601
|
else
|
|
558
602
|
this.pendingAuthToken = e;
|
|
@@ -566,8 +610,12 @@ class Te {
|
|
|
566
610
|
}
|
|
567
611
|
async getConnectionStatus() {
|
|
568
612
|
try {
|
|
569
|
-
const e = await this.request(
|
|
570
|
-
|
|
613
|
+
const e = await this.request(
|
|
614
|
+
"GET_CONNECTION_STATUS",
|
|
615
|
+
void 0,
|
|
616
|
+
2e3
|
|
617
|
+
);
|
|
618
|
+
return e && typeof e == "object" && "connected" in e ? !!e.connected : !!e?.connected;
|
|
571
619
|
} catch {
|
|
572
620
|
return !1;
|
|
573
621
|
}
|
|
@@ -576,182 +624,192 @@ class Te {
|
|
|
576
624
|
if (this.pendingAuthToken = e, this.workerType === "shared" && this.sharedWorkerPort)
|
|
577
625
|
try {
|
|
578
626
|
this.sharedWorkerPort.postMessage({ type: "SET_AUTH_TOKEN", token: e }), this.pendingAuthToken = null;
|
|
579
|
-
} catch (
|
|
580
|
-
console.error(
|
|
627
|
+
} catch (r) {
|
|
628
|
+
console.error(
|
|
629
|
+
"[WorkerClient] Failed to set auth token on SharedWorker:",
|
|
630
|
+
r
|
|
631
|
+
);
|
|
581
632
|
}
|
|
582
633
|
else this.workerType === "service" && (this.sendAuthTokenToServiceWorker(e), this.pendingAuthToken = null);
|
|
583
634
|
}
|
|
584
635
|
}
|
|
585
|
-
const
|
|
636
|
+
const D = new Te();
|
|
586
637
|
async function re(t) {
|
|
587
|
-
return
|
|
638
|
+
return D.init(t);
|
|
588
639
|
}
|
|
589
|
-
async function
|
|
640
|
+
async function x(t) {
|
|
590
641
|
const e = { ...t, timestamp: Date.now() };
|
|
591
|
-
await
|
|
642
|
+
await D.request("STORE_EVENT", { event: e });
|
|
592
643
|
}
|
|
593
|
-
|
|
594
|
-
|
|
644
|
+
function ne(t) {
|
|
645
|
+
D.setAuthToken(t);
|
|
595
646
|
}
|
|
596
|
-
async function oe(t, e,
|
|
597
|
-
|
|
598
|
-
|
|
647
|
+
async function oe(t, e, r) {
|
|
648
|
+
return x({ type: "navigation", from: t, to: e, path: r || e });
|
|
649
|
+
}
|
|
650
|
+
async function ie(t, e, r) {
|
|
651
|
+
const o = t.id || void 0, n = t.className || void 0, l = t.textContent?.trim().substring(0, 100) || void 0, a = t.tagName.toLowerCase();
|
|
652
|
+
return x({
|
|
599
653
|
type: "click",
|
|
600
|
-
element:
|
|
601
|
-
elementId:
|
|
602
|
-
elementClass:
|
|
603
|
-
elementText:
|
|
654
|
+
element: a,
|
|
655
|
+
elementId: o,
|
|
656
|
+
elementClass: n,
|
|
657
|
+
elementText: l,
|
|
604
658
|
path: e || window.location.pathname,
|
|
605
|
-
metadata:
|
|
659
|
+
metadata: r
|
|
606
660
|
});
|
|
607
661
|
}
|
|
608
|
-
async function
|
|
609
|
-
const
|
|
610
|
-
return
|
|
662
|
+
async function se(t, e, r) {
|
|
663
|
+
const o = t.id || void 0, n = t.className || void 0, l = t.tagName.toLowerCase();
|
|
664
|
+
return x({
|
|
611
665
|
type: "input",
|
|
612
|
-
element:
|
|
613
|
-
elementId:
|
|
614
|
-
elementClass:
|
|
615
|
-
path:
|
|
666
|
+
element: l,
|
|
667
|
+
elementId: o,
|
|
668
|
+
elementClass: n,
|
|
669
|
+
path: r || window.location.pathname,
|
|
616
670
|
metadata: {
|
|
617
671
|
valueLength: e?.length || 0,
|
|
618
672
|
value: e
|
|
619
673
|
}
|
|
620
674
|
});
|
|
621
675
|
}
|
|
622
|
-
function
|
|
623
|
-
const
|
|
624
|
-
_(() => {
|
|
625
|
-
|
|
626
|
-
}, [
|
|
627
|
-
re().then(() =>
|
|
628
|
-
console.error("Worker initialization failed:",
|
|
676
|
+
function Pe(t) {
|
|
677
|
+
const e = ye(), [r, o] = Z(!1), n = R(e.pathname), l = R(null);
|
|
678
|
+
return _(() => {
|
|
679
|
+
n.current !== e.pathname && (l.current = n.current, n.current = e.pathname);
|
|
680
|
+
}, [e.pathname]), _(() => {
|
|
681
|
+
re(t).then(() => o(!0)).catch((a) => {
|
|
682
|
+
console.error("Worker initialization failed:", a);
|
|
629
683
|
});
|
|
630
|
-
}, []), _(() => {
|
|
631
|
-
if (!
|
|
632
|
-
const
|
|
633
|
-
|
|
634
|
-
console.error("Failed to track navigation:",
|
|
684
|
+
}, [t]), _(() => {
|
|
685
|
+
if (!r) return;
|
|
686
|
+
const a = l.current, c = n.current;
|
|
687
|
+
a && a !== c && oe(a, c, c).catch((i) => {
|
|
688
|
+
console.error("Failed to track navigation:", i);
|
|
635
689
|
});
|
|
636
|
-
}, [
|
|
637
|
-
if (!
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
if (!
|
|
641
|
-
|
|
642
|
-
console.error("Failed to track click:",
|
|
690
|
+
}, [e.pathname, r]), _(() => {
|
|
691
|
+
if (!r) return;
|
|
692
|
+
const a = (c) => {
|
|
693
|
+
const i = c.target;
|
|
694
|
+
if (!i) return;
|
|
695
|
+
i.tagName === "BUTTON" || i.tagName === "A" || i.closest("button") || i.closest("a") || ie(i, n.current).catch((h) => {
|
|
696
|
+
console.error("Failed to track click:", h);
|
|
643
697
|
});
|
|
644
698
|
};
|
|
645
|
-
return document.addEventListener("click",
|
|
646
|
-
}, [
|
|
647
|
-
if (!
|
|
648
|
-
let
|
|
649
|
-
const c = (
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
(
|
|
654
|
-
console.error("Failed to track input:",
|
|
699
|
+
return document.addEventListener("click", a, !0), () => document.removeEventListener("click", a, !0);
|
|
700
|
+
}, [r]), _(() => {
|
|
701
|
+
if (!r) return;
|
|
702
|
+
let a;
|
|
703
|
+
const c = (i) => {
|
|
704
|
+
const s = i.target;
|
|
705
|
+
s && (s.tagName === "INPUT" || s.tagName === "TEXTAREA") && (clearTimeout(a), a = setTimeout(() => {
|
|
706
|
+
se(s, s.value, n.current).catch(
|
|
707
|
+
(h) => {
|
|
708
|
+
console.error("Failed to track input:", h);
|
|
655
709
|
}
|
|
656
710
|
);
|
|
657
711
|
}, 1e3));
|
|
658
712
|
};
|
|
659
713
|
return document.addEventListener("input", c, !0), () => {
|
|
660
|
-
clearTimeout(
|
|
714
|
+
clearTimeout(a), document.removeEventListener("input", c, !0);
|
|
661
715
|
};
|
|
662
|
-
}, [
|
|
716
|
+
}, [r]), {
|
|
717
|
+
setAuthToken: ne
|
|
718
|
+
};
|
|
663
719
|
}
|
|
664
|
-
var
|
|
720
|
+
var B;
|
|
665
721
|
(function(t) {
|
|
666
722
|
t.Pop = "POP", t.Push = "PUSH", t.Replace = "REPLACE";
|
|
667
|
-
})(
|
|
668
|
-
function
|
|
723
|
+
})(B || (B = {}));
|
|
724
|
+
function J(t, e) {
|
|
669
725
|
throw new Error(e);
|
|
670
726
|
}
|
|
671
|
-
var
|
|
727
|
+
var Q;
|
|
672
728
|
(function(t) {
|
|
673
729
|
t.data = "data", t.deferred = "deferred", t.redirect = "redirect", t.error = "error";
|
|
674
|
-
})(
|
|
730
|
+
})(Q || (Q = {}));
|
|
675
731
|
const ae = ["post", "put", "patch", "delete"];
|
|
676
732
|
new Set(ae);
|
|
677
|
-
const
|
|
678
|
-
new Set(
|
|
679
|
-
const
|
|
680
|
-
process.env.NODE_ENV !== "production" && (
|
|
733
|
+
const Oe = ["get", ...ae];
|
|
734
|
+
new Set(Oe);
|
|
735
|
+
const We = /* @__PURE__ */ S.createContext(null);
|
|
736
|
+
process.env.NODE_ENV !== "production" && (We.displayName = "DataRouter");
|
|
681
737
|
const we = /* @__PURE__ */ S.createContext(null);
|
|
682
738
|
process.env.NODE_ENV !== "production" && (we.displayName = "DataRouterState");
|
|
683
|
-
const We = /* @__PURE__ */ S.createContext(null);
|
|
684
|
-
process.env.NODE_ENV !== "production" && (We.displayName = "Await");
|
|
685
739
|
const Re = /* @__PURE__ */ S.createContext(null);
|
|
686
|
-
process.env.NODE_ENV !== "production" && (Re.displayName = "
|
|
687
|
-
const
|
|
688
|
-
process.env.NODE_ENV !== "production" && (
|
|
689
|
-
const
|
|
740
|
+
process.env.NODE_ENV !== "production" && (Re.displayName = "Await");
|
|
741
|
+
const Ce = /* @__PURE__ */ S.createContext(null);
|
|
742
|
+
process.env.NODE_ENV !== "production" && (Ce.displayName = "Navigation");
|
|
743
|
+
const M = /* @__PURE__ */ S.createContext(null);
|
|
744
|
+
process.env.NODE_ENV !== "production" && (M.displayName = "Location");
|
|
745
|
+
const Ne = /* @__PURE__ */ S.createContext({
|
|
690
746
|
outlet: null,
|
|
691
747
|
matches: [],
|
|
692
748
|
isDataRoute: !1
|
|
693
749
|
});
|
|
694
|
-
process.env.NODE_ENV !== "production" && (
|
|
695
|
-
const
|
|
696
|
-
process.env.NODE_ENV !== "production" && (
|
|
750
|
+
process.env.NODE_ENV !== "production" && (Ne.displayName = "Route");
|
|
751
|
+
const Le = /* @__PURE__ */ S.createContext(null);
|
|
752
|
+
process.env.NODE_ENV !== "production" && (Le.displayName = "RouteError");
|
|
697
753
|
function Ae() {
|
|
698
|
-
return S.useContext(
|
|
754
|
+
return S.useContext(M) != null;
|
|
699
755
|
}
|
|
700
|
-
function
|
|
701
|
-
return Ae() || (process.env.NODE_ENV !== "production" ?
|
|
756
|
+
function be() {
|
|
757
|
+
return Ae() || (process.env.NODE_ENV !== "production" ? J(
|
|
702
758
|
!1,
|
|
703
759
|
// TODO: This error is probably because they somehow have 2 versions of the
|
|
704
760
|
// router loaded. We can help them understand how to avoid that.
|
|
705
761
|
"useLocation() may be used only in the context of a <Router> component."
|
|
706
|
-
) :
|
|
762
|
+
) : J()), S.useContext(M).location;
|
|
707
763
|
}
|
|
708
764
|
new Promise(() => {
|
|
709
765
|
});
|
|
710
|
-
function
|
|
711
|
-
const
|
|
712
|
-
_(() => {
|
|
713
|
-
|
|
714
|
-
}, [
|
|
715
|
-
re().then(() => {
|
|
716
|
-
|
|
717
|
-
}).catch((
|
|
718
|
-
console.error("Worker initialization failed:",
|
|
766
|
+
function Ue(t) {
|
|
767
|
+
const e = be(), [r, o] = Z(!1), n = R(e.pathname), l = R(null);
|
|
768
|
+
return _(() => {
|
|
769
|
+
l.current = n.current, n.current = e.pathname;
|
|
770
|
+
}, [e.pathname]), _(() => {
|
|
771
|
+
re(t).then(() => {
|
|
772
|
+
o(!0);
|
|
773
|
+
}).catch((a) => {
|
|
774
|
+
console.error("Worker initialization failed:", a);
|
|
719
775
|
});
|
|
720
|
-
}, []), _(() => {
|
|
721
|
-
if (!
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
console.error("Failed to track navigation:",
|
|
776
|
+
}, [t]), _(() => {
|
|
777
|
+
if (!r) return;
|
|
778
|
+
const a = l.current, c = n.current;
|
|
779
|
+
a && a !== c && oe(a, c, c).catch((i) => {
|
|
780
|
+
console.error("Failed to track navigation:", i);
|
|
725
781
|
});
|
|
726
|
-
}, [
|
|
727
|
-
if (!
|
|
728
|
-
const
|
|
729
|
-
const
|
|
730
|
-
if (!
|
|
731
|
-
|
|
732
|
-
console.error("Failed to track click:",
|
|
782
|
+
}, [e.pathname, r]), _(() => {
|
|
783
|
+
if (!r) return;
|
|
784
|
+
const a = (c) => {
|
|
785
|
+
const i = c.target;
|
|
786
|
+
if (!i) return;
|
|
787
|
+
i.tagName === "BUTTON" || i.tagName === "A" || i.closest("button") || i.closest("a") || ie(i, n.current).catch((h) => {
|
|
788
|
+
console.error("Failed to track click:", h);
|
|
733
789
|
});
|
|
734
790
|
};
|
|
735
|
-
return document.addEventListener("click",
|
|
736
|
-
}, [
|
|
737
|
-
if (!
|
|
738
|
-
let
|
|
739
|
-
const c = (
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
(
|
|
744
|
-
console.error("Failed to track input:",
|
|
791
|
+
return document.addEventListener("click", a, !0), () => document.removeEventListener("click", a, !0);
|
|
792
|
+
}, [r]), _(() => {
|
|
793
|
+
if (!r) return;
|
|
794
|
+
let a;
|
|
795
|
+
const c = (i) => {
|
|
796
|
+
const s = i.target;
|
|
797
|
+
s && (s.tagName === "INPUT" || s.tagName === "TEXTAREA") && (clearTimeout(a), a = setTimeout(() => {
|
|
798
|
+
se(s, s.value, n.current).catch(
|
|
799
|
+
(h) => {
|
|
800
|
+
console.error("Failed to track input:", h);
|
|
745
801
|
}
|
|
746
802
|
);
|
|
747
803
|
}, 1e3));
|
|
748
804
|
};
|
|
749
805
|
return document.addEventListener("input", c, !0), () => {
|
|
750
|
-
clearTimeout(
|
|
806
|
+
clearTimeout(a), document.removeEventListener("input", c, !0);
|
|
751
807
|
};
|
|
752
|
-
}, [
|
|
808
|
+
}, [r]), {
|
|
809
|
+
setAuthToken: ne
|
|
810
|
+
};
|
|
753
811
|
}
|
|
754
812
|
export {
|
|
755
|
-
|
|
756
|
-
|
|
813
|
+
Ue as useReactRouterEventTracker,
|
|
814
|
+
Pe as useTanstackRouterEventTracker
|
|
757
815
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-fe/react-event-tracker",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"types": "./index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -11,7 +11,13 @@
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@mcp-fe/event-tracker": "0.0.
|
|
14
|
+
"@mcp-fe/event-tracker": "0.0.14"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": ">=19.0.0",
|
|
18
|
+
"react-dom": ">=19.0.0",
|
|
19
|
+
"react-router-dom": ">=6.0.0",
|
|
20
|
+
"@tanstack/react-router": ">=1.0.0"
|
|
15
21
|
},
|
|
16
22
|
"publishConfig": {
|
|
17
23
|
"access": "public"
|