@sentinel-js/react 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -14,6 +14,31 @@ pnpm add @sentinel-js/react
14
14
 
15
15
  **Peer dependencies:** `react` and `react-dom` (>=16.8.0). You must have them installed in your app.
16
16
 
17
+ ### Vite Configuration (Required)
18
+
19
+ Add the following to your `vite.config.ts` to ensure a single React instance:
20
+
21
+ ```typescript
22
+ import { defineConfig } from 'vite';
23
+ import react from '@vitejs/plugin-react';
24
+ import sentinelPlugin from '@sentinel-js/vite-plugin';
25
+
26
+ export default defineConfig({
27
+ plugins: [
28
+ react(),
29
+ sentinelPlugin(),
30
+ ],
31
+ resolve: {
32
+ dedupe: ['react', 'react-dom'],
33
+ },
34
+ optimizeDeps: {
35
+ include: ['@sentinel-js/react'],
36
+ },
37
+ });
38
+ ```
39
+
40
+ Without `dedupe` and `optimizeDeps.include`, you may encounter React hook errors in development mode.
41
+
17
42
  ## Usage
18
43
 
19
44
  ### Option A: Standard UI (Toast Banner)
package/dist/index.es.js CHANGED
@@ -1,689 +1,64 @@
1
- import je, { useState as vr, useRef as Ce, useEffect as Z, useCallback as pr } from "react";
2
- var re = { exports: {} }, $ = {};
3
- /**
4
- * @license React
5
- * react-jsx-runtime.production.min.js
6
- *
7
- * Copyright (c) Facebook, Inc. and its affiliates.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE file in the root directory of this source tree.
11
- */
12
- var Oe;
13
- function hr() {
14
- if (Oe) return $;
15
- Oe = 1;
16
- var d = je, E = Symbol.for("react.element"), R = Symbol.for("react.fragment"), y = Object.prototype.hasOwnProperty, C = d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, k = { key: !0, ref: !0, __self: !0, __source: !0 };
17
- function _(w, c, m) {
18
- var f, S = {}, v = null, T = null;
19
- m !== void 0 && (v = "" + m), c.key !== void 0 && (v = "" + c.key), c.ref !== void 0 && (T = c.ref);
20
- for (f in c) y.call(c, f) && !k.hasOwnProperty(f) && (S[f] = c[f]);
21
- if (w && w.defaultProps) for (f in c = w.defaultProps, c) S[f] === void 0 && (S[f] = c[f]);
22
- return { $$typeof: E, type: w, key: v, ref: T, props: S, _owner: C.current };
23
- }
24
- return $.Fragment = R, $.jsx = _, $.jsxs = _, $;
25
- }
26
- var W = {};
27
- /**
28
- * @license React
29
- * react-jsx-runtime.development.js
30
- *
31
- * Copyright (c) Facebook, Inc. and its affiliates.
32
- *
33
- * This source code is licensed under the MIT license found in the
34
- * LICENSE file in the root directory of this source tree.
35
- */
36
- var Pe;
37
- function yr() {
38
- return Pe || (Pe = 1, process.env.NODE_ENV !== "production" && function() {
39
- var d = je, E = Symbol.for("react.element"), R = Symbol.for("react.portal"), y = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), _ = Symbol.for("react.provider"), w = Symbol.for("react.context"), c = Symbol.for("react.forward_ref"), m = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), S = Symbol.for("react.memo"), v = Symbol.for("react.lazy"), T = Symbol.for("react.offscreen"), O = Symbol.iterator, M = "@@iterator";
40
- function ke(e) {
41
- if (e === null || typeof e != "object")
42
- return null;
43
- var r = O && e[O] || e[M];
44
- return typeof r == "function" ? r : null;
45
- }
46
- var F = d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
47
- function p(e) {
48
- {
49
- for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
50
- t[n - 1] = arguments[n];
51
- Fe("error", e, t);
52
- }
53
- }
54
- function Fe(e, r, t) {
55
- {
56
- var n = F.ReactDebugCurrentFrame, i = n.getStackAddendum();
57
- i !== "" && (r += "%s", t = t.concat([i]));
58
- var u = t.map(function(o) {
59
- return String(o);
60
- });
61
- u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u);
62
- }
63
- }
64
- var De = !1, Ie = !1, Ae = !1, Ve = !1, $e = !1, te;
65
- te = Symbol.for("react.module.reference");
66
- function We(e) {
67
- return !!(typeof e == "string" || typeof e == "function" || e === y || e === k || $e || e === C || e === m || e === f || Ve || e === T || De || Ie || Ae || typeof e == "object" && e !== null && (e.$$typeof === v || e.$$typeof === S || e.$$typeof === _ || e.$$typeof === w || e.$$typeof === c || // This needs to include all possible module reference object
68
- // types supported by any Flight configuration anywhere since
69
- // we don't know which Flight build this will end up being used
70
- // with.
71
- e.$$typeof === te || e.getModuleId !== void 0));
72
- }
73
- function Le(e, r, t) {
74
- var n = e.displayName;
75
- if (n)
76
- return n;
77
- var i = r.displayName || r.name || "";
78
- return i !== "" ? t + "(" + i + ")" : t;
79
- }
80
- function ne(e) {
81
- return e.displayName || "Context";
82
- }
83
- function x(e) {
84
- if (e == null)
85
- return null;
86
- if (typeof e.tag == "number" && p("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
87
- return e.displayName || e.name || null;
88
- if (typeof e == "string")
89
- return e;
90
- switch (e) {
91
- case y:
92
- return "Fragment";
93
- case R:
94
- return "Portal";
95
- case k:
96
- return "Profiler";
97
- case C:
98
- return "StrictMode";
99
- case m:
100
- return "Suspense";
101
- case f:
102
- return "SuspenseList";
103
- }
104
- if (typeof e == "object")
105
- switch (e.$$typeof) {
106
- case w:
107
- var r = e;
108
- return ne(r) + ".Consumer";
109
- case _:
110
- var t = e;
111
- return ne(t._context) + ".Provider";
112
- case c:
113
- return Le(e, e.render, "ForwardRef");
114
- case S:
115
- var n = e.displayName || null;
116
- return n !== null ? n : x(e.type) || "Memo";
117
- case v: {
118
- var i = e, u = i._payload, o = i._init;
119
- try {
120
- return x(o(u));
121
- } catch {
122
- return null;
123
- }
124
- }
125
- }
126
- return null;
127
- }
128
- var P = Object.assign, A = 0, ae, oe, ie, ue, se, le, ce;
129
- function fe() {
130
- }
131
- fe.__reactDisabledLog = !0;
132
- function Ne() {
133
- {
134
- if (A === 0) {
135
- ae = console.log, oe = console.info, ie = console.warn, ue = console.error, se = console.group, le = console.groupCollapsed, ce = console.groupEnd;
136
- var e = {
137
- configurable: !0,
138
- enumerable: !0,
139
- value: fe,
140
- writable: !0
141
- };
142
- Object.defineProperties(console, {
143
- info: e,
144
- log: e,
145
- warn: e,
146
- error: e,
147
- group: e,
148
- groupCollapsed: e,
149
- groupEnd: e
150
- });
151
- }
152
- A++;
153
- }
154
- }
155
- function Ye() {
156
- {
157
- if (A--, A === 0) {
158
- var e = {
159
- configurable: !0,
160
- enumerable: !0,
161
- writable: !0
162
- };
163
- Object.defineProperties(console, {
164
- log: P({}, e, {
165
- value: ae
166
- }),
167
- info: P({}, e, {
168
- value: oe
169
- }),
170
- warn: P({}, e, {
171
- value: ie
172
- }),
173
- error: P({}, e, {
174
- value: ue
175
- }),
176
- group: P({}, e, {
177
- value: se
178
- }),
179
- groupCollapsed: P({}, e, {
180
- value: le
181
- }),
182
- groupEnd: P({}, e, {
183
- value: ce
184
- })
185
- });
186
- }
187
- A < 0 && p("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
188
- }
189
- }
190
- var B = F.ReactCurrentDispatcher, J;
191
- function L(e, r, t) {
192
- {
193
- if (J === void 0)
194
- try {
195
- throw Error();
196
- } catch (i) {
197
- var n = i.stack.trim().match(/\n( *(at )?)/);
198
- J = n && n[1] || "";
199
- }
200
- return `
201
- ` + J + e;
202
- }
203
- }
204
- var q = !1, N;
205
- {
206
- var Ue = typeof WeakMap == "function" ? WeakMap : Map;
207
- N = new Ue();
208
- }
209
- function de(e, r) {
210
- if (!e || q)
211
- return "";
212
- {
213
- var t = N.get(e);
214
- if (t !== void 0)
215
- return t;
216
- }
217
- var n;
218
- q = !0;
219
- var i = Error.prepareStackTrace;
220
- Error.prepareStackTrace = void 0;
221
- var u;
222
- u = B.current, B.current = null, Ne();
223
- try {
224
- if (r) {
225
- var o = function() {
226
- throw Error();
227
- };
228
- if (Object.defineProperty(o.prototype, "props", {
229
- set: function() {
230
- throw Error();
231
- }
232
- }), typeof Reflect == "object" && Reflect.construct) {
233
- try {
234
- Reflect.construct(o, []);
235
- } catch (g) {
236
- n = g;
237
- }
238
- Reflect.construct(e, [], o);
239
- } else {
240
- try {
241
- o.call();
242
- } catch (g) {
243
- n = g;
244
- }
245
- e.call(o.prototype);
246
- }
247
- } else {
248
- try {
249
- throw Error();
250
- } catch (g) {
251
- n = g;
252
- }
253
- e();
254
- }
255
- } catch (g) {
256
- if (g && n && typeof g.stack == "string") {
257
- for (var a = g.stack.split(`
258
- `), h = n.stack.split(`
259
- `), s = a.length - 1, l = h.length - 1; s >= 1 && l >= 0 && a[s] !== h[l]; )
260
- l--;
261
- for (; s >= 1 && l >= 0; s--, l--)
262
- if (a[s] !== h[l]) {
263
- if (s !== 1 || l !== 1)
264
- do
265
- if (s--, l--, l < 0 || a[s] !== h[l]) {
266
- var b = `
267
- ` + a[s].replace(" at new ", " at ");
268
- return e.displayName && b.includes("<anonymous>") && (b = b.replace("<anonymous>", e.displayName)), typeof e == "function" && N.set(e, b), b;
269
- }
270
- while (s >= 1 && l >= 0);
271
- break;
272
- }
273
- }
274
- } finally {
275
- q = !1, B.current = u, Ye(), Error.prepareStackTrace = i;
276
- }
277
- var I = e ? e.displayName || e.name : "", j = I ? L(I) : "";
278
- return typeof e == "function" && N.set(e, j), j;
279
- }
280
- function Me(e, r, t) {
281
- return de(e, !1);
282
- }
283
- function Be(e) {
284
- var r = e.prototype;
285
- return !!(r && r.isReactComponent);
286
- }
287
- function Y(e, r, t) {
288
- if (e == null)
289
- return "";
290
- if (typeof e == "function")
291
- return de(e, Be(e));
292
- if (typeof e == "string")
293
- return L(e);
294
- switch (e) {
295
- case m:
296
- return L("Suspense");
297
- case f:
298
- return L("SuspenseList");
299
- }
300
- if (typeof e == "object")
301
- switch (e.$$typeof) {
302
- case c:
303
- return Me(e.render);
304
- case S:
305
- return Y(e.type, r, t);
306
- case v: {
307
- var n = e, i = n._payload, u = n._init;
308
- try {
309
- return Y(u(i), r, t);
310
- } catch {
311
- }
312
- }
313
- }
314
- return "";
315
- }
316
- var V = Object.prototype.hasOwnProperty, ve = {}, pe = F.ReactDebugCurrentFrame;
317
- function U(e) {
318
- if (e) {
319
- var r = e._owner, t = Y(e.type, e._source, r ? r.type : null);
320
- pe.setExtraStackFrame(t);
321
- } else
322
- pe.setExtraStackFrame(null);
323
- }
324
- function Je(e, r, t, n, i) {
325
- {
326
- var u = Function.call.bind(V);
327
- for (var o in e)
328
- if (u(e, o)) {
329
- var a = void 0;
330
- try {
331
- if (typeof e[o] != "function") {
332
- var h = Error((n || "React class") + ": " + t + " type `" + o + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[o] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
333
- throw h.name = "Invariant Violation", h;
334
- }
335
- a = e[o](r, o, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
336
- } catch (s) {
337
- a = s;
338
- }
339
- a && !(a instanceof Error) && (U(i), p("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, o, typeof a), U(null)), a instanceof Error && !(a.message in ve) && (ve[a.message] = !0, U(i), p("Failed %s type: %s", t, a.message), U(null));
340
- }
341
- }
342
- }
343
- var qe = Array.isArray;
344
- function z(e) {
345
- return qe(e);
346
- }
347
- function ze(e) {
348
- {
349
- var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
350
- return t;
351
- }
352
- }
353
- function Ke(e) {
354
- try {
355
- return he(e), !1;
356
- } catch {
357
- return !0;
358
- }
359
- }
360
- function he(e) {
361
- return "" + e;
362
- }
363
- function ye(e) {
364
- if (Ke(e))
365
- return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", ze(e)), he(e);
366
- }
367
- var ge = F.ReactCurrentOwner, Ge = {
368
- key: !0,
369
- ref: !0,
370
- __self: !0,
371
- __source: !0
372
- }, Ee, be;
373
- function Xe(e) {
374
- if (V.call(e, "ref")) {
375
- var r = Object.getOwnPropertyDescriptor(e, "ref").get;
376
- if (r && r.isReactWarning)
377
- return !1;
378
- }
379
- return e.ref !== void 0;
380
- }
381
- function He(e) {
382
- if (V.call(e, "key")) {
383
- var r = Object.getOwnPropertyDescriptor(e, "key").get;
384
- if (r && r.isReactWarning)
385
- return !1;
386
- }
387
- return e.key !== void 0;
388
- }
389
- function Ze(e, r) {
390
- typeof e.ref == "string" && ge.current;
391
- }
392
- function Qe(e, r) {
393
- {
394
- var t = function() {
395
- Ee || (Ee = !0, p("%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://reactjs.org/link/special-props)", r));
396
- };
397
- t.isReactWarning = !0, Object.defineProperty(e, "key", {
398
- get: t,
399
- configurable: !0
400
- });
401
- }
402
- }
403
- function er(e, r) {
404
- {
405
- var t = function() {
406
- be || (be = !0, p("%s: `ref` 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://reactjs.org/link/special-props)", r));
407
- };
408
- t.isReactWarning = !0, Object.defineProperty(e, "ref", {
409
- get: t,
410
- configurable: !0
411
- });
412
- }
413
- }
414
- var rr = function(e, r, t, n, i, u, o) {
415
- var a = {
416
- // This tag allows us to uniquely identify this as a React Element
417
- $$typeof: E,
418
- // Built-in properties that belong on the element
419
- type: e,
420
- key: r,
421
- ref: t,
422
- props: o,
423
- // Record the component responsible for creating this element.
424
- _owner: u
425
- };
426
- return a._store = {}, Object.defineProperty(a._store, "validated", {
427
- configurable: !1,
428
- enumerable: !1,
429
- writable: !0,
430
- value: !1
431
- }), Object.defineProperty(a, "_self", {
432
- configurable: !1,
433
- enumerable: !1,
434
- writable: !1,
435
- value: n
436
- }), Object.defineProperty(a, "_source", {
437
- configurable: !1,
438
- enumerable: !1,
439
- writable: !1,
440
- value: i
441
- }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
442
- };
443
- function tr(e, r, t, n, i) {
444
- {
445
- var u, o = {}, a = null, h = null;
446
- t !== void 0 && (ye(t), a = "" + t), He(r) && (ye(r.key), a = "" + r.key), Xe(r) && (h = r.ref, Ze(r, i));
447
- for (u in r)
448
- V.call(r, u) && !Ge.hasOwnProperty(u) && (o[u] = r[u]);
449
- if (e && e.defaultProps) {
450
- var s = e.defaultProps;
451
- for (u in s)
452
- o[u] === void 0 && (o[u] = s[u]);
453
- }
454
- if (a || h) {
455
- var l = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
456
- a && Qe(o, l), h && er(o, l);
457
- }
458
- return rr(e, a, h, i, n, ge.current, o);
459
- }
460
- }
461
- var K = F.ReactCurrentOwner, _e = F.ReactDebugCurrentFrame;
462
- function D(e) {
463
- if (e) {
464
- var r = e._owner, t = Y(e.type, e._source, r ? r.type : null);
465
- _e.setExtraStackFrame(t);
466
- } else
467
- _e.setExtraStackFrame(null);
468
- }
469
- var G;
470
- G = !1;
471
- function X(e) {
472
- return typeof e == "object" && e !== null && e.$$typeof === E;
473
- }
474
- function Re() {
475
- {
476
- if (K.current) {
477
- var e = x(K.current.type);
478
- if (e)
479
- return `
480
-
481
- Check the render method of \`` + e + "`.";
482
- }
483
- return "";
484
- }
485
- }
486
- function nr(e) {
487
- return "";
488
- }
489
- var me = {};
490
- function ar(e) {
491
- {
492
- var r = Re();
493
- if (!r) {
494
- var t = typeof e == "string" ? e : e.displayName || e.name;
495
- t && (r = `
496
-
497
- Check the top-level render call using <` + t + ">.");
498
- }
499
- return r;
500
- }
501
- }
502
- function Se(e, r) {
503
- {
504
- if (!e._store || e._store.validated || e.key != null)
505
- return;
506
- e._store.validated = !0;
507
- var t = ar(r);
508
- if (me[t])
509
- return;
510
- me[t] = !0;
511
- var n = "";
512
- e && e._owner && e._owner !== K.current && (n = " It was passed a child from " + x(e._owner.type) + "."), D(e), p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), D(null);
513
- }
514
- }
515
- function we(e, r) {
516
- {
517
- if (typeof e != "object")
518
- return;
519
- if (z(e))
520
- for (var t = 0; t < e.length; t++) {
521
- var n = e[t];
522
- X(n) && Se(n, r);
523
- }
524
- else if (X(e))
525
- e._store && (e._store.validated = !0);
526
- else if (e) {
527
- var i = ke(e);
528
- if (typeof i == "function" && i !== e.entries)
529
- for (var u = i.call(e), o; !(o = u.next()).done; )
530
- X(o.value) && Se(o.value, r);
531
- }
532
- }
533
- }
534
- function or(e) {
535
- {
536
- var r = e.type;
537
- if (r == null || typeof r == "string")
538
- return;
539
- var t;
540
- if (typeof r == "function")
541
- t = r.propTypes;
542
- else if (typeof r == "object" && (r.$$typeof === c || // Note: Memo only checks outer props here.
543
- // Inner props are checked in the reconciler.
544
- r.$$typeof === S))
545
- t = r.propTypes;
546
- else
547
- return;
548
- if (t) {
549
- var n = x(r);
550
- Je(t, e.props, "prop", n, e);
551
- } else if (r.PropTypes !== void 0 && !G) {
552
- G = !0;
553
- var i = x(r);
554
- p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", i || "Unknown");
555
- }
556
- typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
557
- }
558
- }
559
- function ir(e) {
560
- {
561
- for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
562
- var n = r[t];
563
- if (n !== "children" && n !== "key") {
564
- D(e), p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), D(null);
565
- break;
566
- }
567
- }
568
- e.ref !== null && (D(e), p("Invalid attribute `ref` supplied to `React.Fragment`."), D(null));
569
- }
570
- }
571
- var Te = {};
572
- function xe(e, r, t, n, i, u) {
573
- {
574
- var o = We(e);
575
- if (!o) {
576
- var a = "";
577
- (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
578
- var h = nr();
579
- h ? a += h : a += Re();
580
- var s;
581
- e === null ? s = "null" : z(e) ? s = "array" : e !== void 0 && e.$$typeof === E ? (s = "<" + (x(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : s = typeof e, p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", s, a);
582
- }
583
- var l = tr(e, r, t, i, u);
584
- if (l == null)
585
- return l;
586
- if (o) {
587
- var b = r.children;
588
- if (b !== void 0)
589
- if (n)
590
- if (z(b)) {
591
- for (var I = 0; I < b.length; I++)
592
- we(b[I], e);
593
- Object.freeze && Object.freeze(b);
594
- } else
595
- p("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
596
- else
597
- we(b, e);
598
- }
599
- if (V.call(r, "key")) {
600
- var j = x(e), g = Object.keys(r).filter(function(dr) {
601
- return dr !== "key";
602
- }), H = g.length > 0 ? "{key: someKey, " + g.join(": ..., ") + ": ...}" : "{key: someKey}";
603
- if (!Te[j + H]) {
604
- var fr = g.length > 0 ? "{" + g.join(": ..., ") + ": ...}" : "{}";
605
- p(`A props object containing a "key" prop is being spread into JSX:
606
- let props = %s;
607
- <%s {...props} />
608
- React keys must be passed directly to JSX without using spread:
609
- let props = %s;
610
- <%s key={someKey} {...props} />`, H, j, fr, j), Te[j + H] = !0;
611
- }
612
- }
613
- return e === y ? ir(l) : or(l), l;
614
- }
615
- }
616
- function ur(e, r, t) {
617
- return xe(e, r, t, !0);
618
- }
619
- function sr(e, r, t) {
620
- return xe(e, r, t, !1);
621
- }
622
- var lr = sr, cr = ur;
623
- W.Fragment = y, W.jsx = lr, W.jsxs = cr;
624
- }()), W;
625
- }
626
- process.env.NODE_ENV === "production" ? re.exports = hr() : re.exports = yr();
627
- var Q = re.exports;
628
- const gr = (d) => {
629
- const E = history.pushState, R = history.replaceState;
630
- return history.pushState = function(...y) {
631
- E.apply(history, y), d();
632
- }, history.replaceState = function(...y) {
633
- R.apply(history, y), d();
634
- }, window.addEventListener("popstate", d), () => {
635
- window.removeEventListener("popstate", d);
1
+ import { jsxs as g, jsx as h } from "react/jsx-runtime";
2
+ import { useState as m, useRef as S, useEffect as d, useCallback as v } from "react";
3
+ const b = (e) => {
4
+ const o = history.pushState, r = history.replaceState;
5
+ return history.pushState = function(...t) {
6
+ o.apply(history, t), e();
7
+ }, history.replaceState = function(...t) {
8
+ r.apply(history, t), e();
9
+ }, window.addEventListener("popstate", e), () => {
10
+ window.removeEventListener("popstate", e);
636
11
  };
637
- }, Er = ({
638
- pollingInterval: d = 6e4,
639
- versionFileUrl: E = "/version.json",
640
- silent: R = !1,
641
- onUpdateAvailable: y,
642
- checkOnFocus: C = !0
12
+ }, E = ({
13
+ pollingInterval: e = 6e4,
14
+ versionFileUrl: o = "/version.json",
15
+ silent: r = !1,
16
+ onUpdateAvailable: t,
17
+ checkOnFocus: p = !0
643
18
  } = {}) => {
644
- const k = typeof __SENTINEL_VERSION__ < "u" ? __SENTINEL_VERSION__ : "unknown", [_, w] = vr({
19
+ const w = typeof __SENTINEL_VERSION__ < "u" ? __SENTINEL_VERSION__ : "unknown", [s, x] = m({
645
20
  hasUpdate: !1,
646
- currentVersion: k,
21
+ currentVersion: w,
647
22
  remoteVersion: null
648
- }), c = Ce(!1), m = Ce(y);
649
- Z(() => {
650
- m.current = y;
651
- }, [y]);
652
- const f = pr(async () => {
23
+ }), u = S(!1), l = S(t);
24
+ d(() => {
25
+ l.current = t;
26
+ }, [t]);
27
+ const i = v(async () => {
653
28
  try {
654
- const v = await fetch(`${E}?t=${Date.now()}`);
655
- if (!v.ok) return;
656
- const O = (await v.json()).version;
657
- if (O && O !== _.currentVersion) {
658
- if (c.current) return;
659
- c.current = !0, w((M) => ({ ...M, hasUpdate: !0, remoteVersion: O })), m.current && m.current(O);
660
- }
661
- } catch (v) {
662
- console.error("[Sentinel] Failed to check version:", v);
663
- }
664
- }, [E, _.currentVersion]);
665
- return Z(() => {
666
- _.currentVersion === "unknown" && console.warn("[Sentinel] Current version is unknown. Ensure @sentinel/vite-plugin is installed."), f();
667
- const v = setInterval(f, d), T = () => {
668
- C && f();
29
+ const n = await fetch(`${o}?t=${Date.now()}`);
30
+ if (!n.ok) return;
31
+ const c = (await n.json()).version;
32
+ if (c && c !== s.currentVersion) {
33
+ if (u.current) return;
34
+ u.current = !0, x((y) => ({ ...y, hasUpdate: !0, remoteVersion: c })), l.current && l.current(c);
35
+ }
36
+ } catch (n) {
37
+ console.error("[Sentinel] Failed to check version:", n);
38
+ }
39
+ }, [o, s.currentVersion]);
40
+ return d(() => {
41
+ s.currentVersion === "unknown" && console.warn("[Sentinel] Current version is unknown. Ensure @sentinel/vite-plugin is installed."), i();
42
+ const n = setInterval(i, e), a = () => {
43
+ p && i();
669
44
  };
670
- return window.addEventListener("focus", T), () => {
671
- clearInterval(v), window.removeEventListener("focus", T);
45
+ return window.addEventListener("focus", a), () => {
46
+ clearInterval(n), window.removeEventListener("focus", a);
672
47
  };
673
- }, [f, d, C, _.currentVersion]), Z(() => R ? gr(() => {
674
- c.current && (console.log("[Sentinel] Silent update: Route changed, reloading app..."), window.location.reload());
675
- }) : void 0, [R]), {
676
- ..._,
48
+ }, [i, e, p, s.currentVersion]), d(() => r ? b(() => {
49
+ u.current && (console.log("[Sentinel] Silent update: Route changed, reloading app..."), window.location.reload());
50
+ }) : void 0, [r]), {
51
+ ...s,
677
52
  reload: () => window.location.reload(),
678
- checkNow: f
53
+ checkNow: i
679
54
  };
680
- }, _r = (d) => {
681
- const { hasUpdate: E, reload: R } = Er(d);
682
- return !E || d.silent ? null : /* @__PURE__ */ Q.jsxs("div", { style: { ...ee.toast, ...d.style }, className: d.className, children: [
683
- /* @__PURE__ */ Q.jsx("span", { style: ee.text, children: "New version available" }),
684
- /* @__PURE__ */ Q.jsx("button", { style: ee.button, onClick: R, children: "Refresh" })
55
+ }, _ = (e) => {
56
+ const { hasUpdate: o, reload: r } = E(e);
57
+ return !o || e.silent ? null : /* @__PURE__ */ g("div", { style: { ...f.toast, ...e.style }, className: e.className, children: [
58
+ /* @__PURE__ */ h("span", { style: f.text, children: "New version available" }),
59
+ /* @__PURE__ */ h("button", { style: f.button, onClick: r, children: "Refresh" })
685
60
  ] });
686
- }, ee = {
61
+ }, f = {
687
62
  toast: {
688
63
  position: "fixed",
689
64
  bottom: "24px",
@@ -717,6 +92,6 @@ const gr = (d) => {
717
92
  }
718
93
  };
719
94
  export {
720
- _r as SentinelToast,
721
- Er as useSentinel
95
+ _ as SentinelToast,
96
+ E as useSentinel
722
97
  };
package/dist/index.umd.js CHANGED
@@ -1,30 +1 @@
1
- (function(O,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],E):(O=typeof globalThis<"u"?globalThis:O||self,E(O.SentinelReact={},O.React))})(this,function(O,E){"use strict";var $={exports:{}},W={};/**
2
- * @license React
3
- * react-jsx-runtime.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var ne;function ke(){if(ne)return W;ne=1;var d=E,b=Symbol.for("react.element"),m=Symbol.for("react.fragment"),y=Object.prototype.hasOwnProperty,P=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,D={key:!0,ref:!0,__self:!0,__source:!0};function _(T,f,S){var c,w={},v=null,x=null;S!==void 0&&(v=""+S),f.key!==void 0&&(v=""+f.key),f.ref!==void 0&&(x=f.ref);for(c in f)y.call(f,c)&&!D.hasOwnProperty(c)&&(w[c]=f[c]);if(T&&T.defaultProps)for(c in f=T.defaultProps,f)w[c]===void 0&&(w[c]=f[c]);return{$$typeof:b,type:T,key:v,ref:x,props:w,_owner:P.current}}return W.Fragment=m,W.jsx=_,W.jsxs=_,W}var L={};/**
10
- * @license React
11
- * react-jsx-runtime.development.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var ae;function Fe(){return ae||(ae=1,process.env.NODE_ENV!=="production"&&function(){var d=E,b=Symbol.for("react.element"),m=Symbol.for("react.portal"),y=Symbol.for("react.fragment"),P=Symbol.for("react.strict_mode"),D=Symbol.for("react.profiler"),_=Symbol.for("react.provider"),T=Symbol.for("react.context"),f=Symbol.for("react.forward_ref"),S=Symbol.for("react.suspense"),c=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),v=Symbol.for("react.lazy"),x=Symbol.for("react.offscreen"),j=Symbol.iterator,G="@@iterator";function Ae(e){if(e===null||typeof e!="object")return null;var r=j&&e[j]||e[G];return typeof r=="function"?r:null}var I=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function p(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ve("error",e,t)}}function Ve(e,r,t){{var n=I.ReactDebugCurrentFrame,i=n.getStackAddendum();i!==""&&(r+="%s",t=t.concat([i]));var s=t.map(function(o){return String(o)});s.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,s)}}var We=!1,Le=!1,Ne=!1,Ye=!1,Ue=!1,ie;ie=Symbol.for("react.module.reference");function Me(e){return!!(typeof e=="string"||typeof e=="function"||e===y||e===D||Ue||e===P||e===S||e===c||Ye||e===x||We||Le||Ne||typeof e=="object"&&e!==null&&(e.$$typeof===v||e.$$typeof===w||e.$$typeof===_||e.$$typeof===T||e.$$typeof===f||e.$$typeof===ie||e.getModuleId!==void 0))}function Be(e,r,t){var n=e.displayName;if(n)return n;var i=r.displayName||r.name||"";return i!==""?t+"("+i+")":t}function se(e){return e.displayName||"Context"}function C(e){if(e==null)return null;if(typeof e.tag=="number"&&p("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case y:return"Fragment";case m:return"Portal";case D:return"Profiler";case P:return"StrictMode";case S:return"Suspense";case c:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case T:var r=e;return se(r)+".Consumer";case _:var t=e;return se(t._context)+".Provider";case f:return Be(e,e.render,"ForwardRef");case w:var n=e.displayName||null;return n!==null?n:C(e.type)||"Memo";case v:{var i=e,s=i._payload,o=i._init;try{return C(o(s))}catch{return null}}}return null}var k=Object.assign,N=0,ue,le,fe,ce,de,ve,pe;function he(){}he.__reactDisabledLog=!0;function Je(){{if(N===0){ue=console.log,le=console.info,fe=console.warn,ce=console.error,de=console.group,ve=console.groupCollapsed,pe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:he,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}N++}}function $e(){{if(N--,N===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:k({},e,{value:ue}),info:k({},e,{value:le}),warn:k({},e,{value:fe}),error:k({},e,{value:ce}),group:k({},e,{value:de}),groupCollapsed:k({},e,{value:ve}),groupEnd:k({},e,{value:pe})})}N<0&&p("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var X=I.ReactCurrentDispatcher,H;function U(e,r,t){{if(H===void 0)try{throw Error()}catch(i){var n=i.stack.trim().match(/\n( *(at )?)/);H=n&&n[1]||""}return`
18
- `+H+e}}var Z=!1,M;{var ze=typeof WeakMap=="function"?WeakMap:Map;M=new ze}function ye(e,r){if(!e||Z)return"";{var t=M.get(e);if(t!==void 0)return t}var n;Z=!0;var i=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var s;s=X.current,X.current=null,Je();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(g){n=g}Reflect.construct(e,[],o)}else{try{o.call()}catch(g){n=g}e.call(o.prototype)}}else{try{throw Error()}catch(g){n=g}e()}}catch(g){if(g&&n&&typeof g.stack=="string"){for(var a=g.stack.split(`
19
- `),h=n.stack.split(`
20
- `),u=a.length-1,l=h.length-1;u>=1&&l>=0&&a[u]!==h[l];)l--;for(;u>=1&&l>=0;u--,l--)if(a[u]!==h[l]){if(u!==1||l!==1)do if(u--,l--,l<0||a[u]!==h[l]){var R=`
21
- `+a[u].replace(" at new "," at ");return e.displayName&&R.includes("<anonymous>")&&(R=R.replace("<anonymous>",e.displayName)),typeof e=="function"&&M.set(e,R),R}while(u>=1&&l>=0);break}}}finally{Z=!1,X.current=s,$e(),Error.prepareStackTrace=i}var V=e?e.displayName||e.name:"",F=V?U(V):"";return typeof e=="function"&&M.set(e,F),F}function Ke(e,r,t){return ye(e,!1)}function Ge(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function B(e,r,t){if(e==null)return"";if(typeof e=="function")return ye(e,Ge(e));if(typeof e=="string")return U(e);switch(e){case S:return U("Suspense");case c:return U("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case f:return Ke(e.render);case w:return B(e.type,r,t);case v:{var n=e,i=n._payload,s=n._init;try{return B(s(i),r,t)}catch{}}}return""}var Y=Object.prototype.hasOwnProperty,ge={},Ee=I.ReactDebugCurrentFrame;function J(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}function Xe(e,r,t,n,i){{var s=Function.call.bind(Y);for(var o in e)if(s(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var h=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw h.name="Invariant Violation",h}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(u){a=u}a&&!(a instanceof Error)&&(J(i),p("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),J(null)),a instanceof Error&&!(a.message in ge)&&(ge[a.message]=!0,J(i),p("Failed %s type: %s",t,a.message),J(null))}}}var He=Array.isArray;function q(e){return He(e)}function Ze(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function qe(e){try{return be(e),!1}catch{return!0}}function be(e){return""+e}function Re(e){if(qe(e))return p("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ze(e)),be(e)}var _e=I.ReactCurrentOwner,Qe={key:!0,ref:!0,__self:!0,__source:!0},me,Se;function er(e){if(Y.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function rr(e){if(Y.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function tr(e,r){typeof e.ref=="string"&&_e.current}function nr(e,r){{var t=function(){me||(me=!0,p("%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://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function ar(e,r){{var t=function(){Se||(Se=!0,p("%s: `ref` 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://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var or=function(e,r,t,n,i,s,o){var a={$$typeof:b,type:e,key:r,ref:t,props:o,_owner:s};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:i}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ir(e,r,t,n,i){{var s,o={},a=null,h=null;t!==void 0&&(Re(t),a=""+t),rr(r)&&(Re(r.key),a=""+r.key),er(r)&&(h=r.ref,tr(r,i));for(s in r)Y.call(r,s)&&!Qe.hasOwnProperty(s)&&(o[s]=r[s]);if(e&&e.defaultProps){var u=e.defaultProps;for(s in u)o[s]===void 0&&(o[s]=u[s])}if(a||h){var l=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&nr(o,l),h&&ar(o,l)}return or(e,a,h,i,n,_e.current,o)}}var Q=I.ReactCurrentOwner,we=I.ReactDebugCurrentFrame;function A(e){if(e){var r=e._owner,t=B(e.type,e._source,r?r.type:null);we.setExtraStackFrame(t)}else we.setExtraStackFrame(null)}var ee;ee=!1;function re(e){return typeof e=="object"&&e!==null&&e.$$typeof===b}function Te(){{if(Q.current){var e=C(Q.current.type);if(e)return`
22
-
23
- Check the render method of \``+e+"`."}return""}}function sr(e){return""}var xe={};function ur(e){{var r=Te();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
24
-
25
- Check the top-level render call using <`+t+">.")}return r}}function Oe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ur(r);if(xe[t])return;xe[t]=!0;var n="";e&&e._owner&&e._owner!==Q.current&&(n=" It was passed a child from "+C(e._owner.type)+"."),A(e),p('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),A(null)}}function Ce(e,r){{if(typeof e!="object")return;if(q(e))for(var t=0;t<e.length;t++){var n=e[t];re(n)&&Oe(n,r)}else if(re(e))e._store&&(e._store.validated=!0);else if(e){var i=Ae(e);if(typeof i=="function"&&i!==e.entries)for(var s=i.call(e),o;!(o=s.next()).done;)re(o.value)&&Oe(o.value,r)}}}function lr(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===f||r.$$typeof===w))t=r.propTypes;else return;if(t){var n=C(r);Xe(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!ee){ee=!0;var i=C(r);p("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",i||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&p("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function fr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){A(e),p("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),A(null);break}}e.ref!==null&&(A(e),p("Invalid attribute `ref` supplied to `React.Fragment`."),A(null))}}var Pe={};function je(e,r,t,n,i,s){{var o=Me(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var h=sr();h?a+=h:a+=Te();var u;e===null?u="null":q(e)?u="array":e!==void 0&&e.$$typeof===b?(u="<"+(C(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):u=typeof e,p("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",u,a)}var l=ir(e,r,t,i,s);if(l==null)return l;if(o){var R=r.children;if(R!==void 0)if(n)if(q(R)){for(var V=0;V<R.length;V++)Ce(R[V],e);Object.freeze&&Object.freeze(R)}else p("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ce(R,e)}if(Y.call(r,"key")){var F=C(e),g=Object.keys(r).filter(function(yr){return yr!=="key"}),te=g.length>0?"{key: someKey, "+g.join(": ..., ")+": ...}":"{key: someKey}";if(!Pe[F+te]){var hr=g.length>0?"{"+g.join(": ..., ")+": ...}":"{}";p(`A props object containing a "key" prop is being spread into JSX:
26
- let props = %s;
27
- <%s {...props} />
28
- React keys must be passed directly to JSX without using spread:
29
- let props = %s;
30
- <%s key={someKey} {...props} />`,te,F,hr,F),Pe[F+te]=!0}}return e===y?fr(l):lr(l),l}}function cr(e,r,t){return je(e,r,t,!0)}function dr(e,r,t){return je(e,r,t,!1)}var vr=dr,pr=cr;L.Fragment=y,L.jsx=vr,L.jsxs=pr}()),L}process.env.NODE_ENV==="production"?$.exports=ke():$.exports=Fe();var z=$.exports;const De=d=>{const b=history.pushState,m=history.replaceState;return history.pushState=function(...y){b.apply(history,y),d()},history.replaceState=function(...y){m.apply(history,y),d()},window.addEventListener("popstate",d),()=>{window.removeEventListener("popstate",d)}},oe=({pollingInterval:d=6e4,versionFileUrl:b="/version.json",silent:m=!1,onUpdateAvailable:y,checkOnFocus:P=!0}={})=>{const D=typeof __SENTINEL_VERSION__<"u"?__SENTINEL_VERSION__:"unknown",[_,T]=E.useState({hasUpdate:!1,currentVersion:D,remoteVersion:null}),f=E.useRef(!1),S=E.useRef(y);E.useEffect(()=>{S.current=y},[y]);const c=E.useCallback(async()=>{try{const v=await fetch(`${b}?t=${Date.now()}`);if(!v.ok)return;const j=(await v.json()).version;if(j&&j!==_.currentVersion){if(f.current)return;f.current=!0,T(G=>({...G,hasUpdate:!0,remoteVersion:j})),S.current&&S.current(j)}}catch(v){console.error("[Sentinel] Failed to check version:",v)}},[b,_.currentVersion]);return E.useEffect(()=>{_.currentVersion==="unknown"&&console.warn("[Sentinel] Current version is unknown. Ensure @sentinel/vite-plugin is installed."),c();const v=setInterval(c,d),x=()=>{P&&c()};return window.addEventListener("focus",x),()=>{clearInterval(v),window.removeEventListener("focus",x)}},[c,d,P,_.currentVersion]),E.useEffect(()=>m?De(()=>{f.current&&(console.log("[Sentinel] Silent update: Route changed, reloading app..."),window.location.reload())}):void 0,[m]),{..._,reload:()=>window.location.reload(),checkNow:c}},Ie=d=>{const{hasUpdate:b,reload:m}=oe(d);return!b||d.silent?null:z.jsxs("div",{style:{...K.toast,...d.style},className:d.className,children:[z.jsx("span",{style:K.text,children:"New version available"}),z.jsx("button",{style:K.button,onClick:m,children:"Refresh"})]})},K={toast:{position:"fixed",bottom:"24px",right:"24px",backgroundColor:"#1f1f1f",color:"#ffffff",padding:"12px 20px",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",display:"flex",alignItems:"center",gap:"16px",zIndex:9999,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',border:"1px solid #333"},text:{fontSize:"14px",fontWeight:500},button:{backgroundColor:"#3b82f6",border:"none",color:"white",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontWeight:600,fontSize:"13px",transition:"background-color 0.2s"}};O.SentinelToast=Ie,O.useSentinel=oe,Object.defineProperty(O,Symbol.toStringTag,{value:"Module"})});
1
+ (function(t,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.SentinelReact={},t.jsxRuntime,t.React))})(this,function(t,n,o){"use strict";const y=e=>{const i=history.pushState,a=history.replaceState;return history.pushState=function(...r){i.apply(history,r),e()},history.replaceState=function(...r){a.apply(history,r),e()},window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},S=({pollingInterval:e=6e4,versionFileUrl:i="/version.json",silent:a=!1,onUpdateAvailable:r,checkOnFocus:x=!0}={})=>{const g=typeof __SENTINEL_VERSION__<"u"?__SENTINEL_VERSION__:"unknown",[u,m]=o.useState({hasUpdate:!1,currentVersion:g,remoteVersion:null}),p=o.useRef(!1),h=o.useRef(r);o.useEffect(()=>{h.current=r},[r]);const c=o.useCallback(async()=>{try{const s=await fetch(`${i}?t=${Date.now()}`);if(!s.ok)return;const l=(await s.json()).version;if(l&&l!==u.currentVersion){if(p.current)return;p.current=!0,m(v=>({...v,hasUpdate:!0,remoteVersion:l})),h.current&&h.current(l)}}catch(s){console.error("[Sentinel] Failed to check version:",s)}},[i,u.currentVersion]);return o.useEffect(()=>{u.currentVersion==="unknown"&&console.warn("[Sentinel] Current version is unknown. Ensure @sentinel/vite-plugin is installed."),c();const s=setInterval(c,e),d=()=>{x&&c()};return window.addEventListener("focus",d),()=>{clearInterval(s),window.removeEventListener("focus",d)}},[c,e,x,u.currentVersion]),o.useEffect(()=>a?y(()=>{p.current&&(console.log("[Sentinel] Silent update: Route changed, reloading app..."),window.location.reload())}):void 0,[a]),{...u,reload:()=>window.location.reload(),checkNow:c}},w=e=>{const{hasUpdate:i,reload:a}=S(e);return!i||e.silent?null:n.jsxs("div",{style:{...f.toast,...e.style},className:e.className,children:[n.jsx("span",{style:f.text,children:"New version available"}),n.jsx("button",{style:f.button,onClick:a,children:"Refresh"})]})},f={toast:{position:"fixed",bottom:"24px",right:"24px",backgroundColor:"#1f1f1f",color:"#ffffff",padding:"12px 20px",borderRadius:"8px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",display:"flex",alignItems:"center",gap:"16px",zIndex:9999,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',border:"1px solid #333"},text:{fontSize:"14px",fontWeight:500},button:{backgroundColor:"#3b82f6",border:"none",color:"white",padding:"8px 16px",borderRadius:"6px",cursor:"pointer",fontWeight:600,fontSize:"13px",transition:"background-color 0.2s"}};t.SentinelToast=w,t.useSentinel=S,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentinel-js/react",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.umd.js",
6
6
  "module": "./dist/index.es.js",