@nivaro/react 0.3.28 → 0.3.30

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,10 +1,10 @@
1
- import { bindClientChaosSocket as x } from "./client-chaos.js";
2
- import { onSignedIn as z, signedOutBackoff as F, isSignedOut as U } from "./signed-out.js";
3
- const j = 1, B = "nvr-realtime-worker";
4
- function N() {
1
+ import { bindClientChaosSocket as $ } from "./client-chaos.js";
2
+ import { onSignedIn as F, signedOutBackoff as q, isSignedOut as x } from "./signed-out.js";
3
+ const z = 1, B = "nvr-realtime-worker";
4
+ function j() {
5
5
  return typeof window < "u" && typeof window.SharedWorker == "function";
6
6
  }
7
- function Y() {
7
+ function N() {
8
8
  try {
9
9
  const o = localStorage.getItem(B);
10
10
  return o === "on" || o === "off" ? o : null;
@@ -12,190 +12,197 @@ function Y() {
12
12
  return null;
13
13
  }
14
14
  }
15
- function $(o) {
16
- if (!N() || Y() === "off") return !1;
15
+ function Y(o, s) {
16
+ const u = typeof s == "string" ? s.trim() : "";
17
+ return u ? `${o}${o.includes("?") ? "&" : "?"}b=${encodeURIComponent(u.slice(0, 64))}` : o;
18
+ }
19
+ function G(o) {
20
+ if (!j() || N() === "off") return !1;
17
21
  try {
18
22
  return new URL(o, window.location.href).origin === window.location.origin;
19
23
  } catch {
20
24
  return !1;
21
25
  }
22
26
  }
23
- function J(o) {
24
- const u = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set();
25
- let c = "pending", s = null, n = null, d = !1, T = null, K = 0;
27
+ function Q(o) {
28
+ const s = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Set();
29
+ let c = "pending", f = null, n = null, k = !1, T = null, K = 0;
26
30
  const E = /* @__PURE__ */ new Map(), M = [];
27
- let R = 0, k = null, p = null, m = !1, w = !1, b = 0, h = 0, v = null;
28
- const A = (e, t) => {
29
- for (const r of [...u.get(e) ?? []])
31
+ let R = 0, w = null, p = null, m = !1, g = !1, b = 0, h = 0, v = null;
32
+ const A = (t, e) => {
33
+ for (const r of [...s.get(t) ?? []])
30
34
  try {
31
- r(...t);
35
+ r(...e);
32
36
  } catch {
33
37
  }
34
- for (const r of [...g])
38
+ for (const r of [...u])
35
39
  try {
36
- r(e, ...t);
40
+ r(t, ...e);
37
41
  } catch {
38
42
  }
39
43
  }, C = () => {
40
- if (k && clearTimeout(k), k = null, p && clearInterval(p), p = null, s)
44
+ if (w && clearTimeout(w), w = null, p && clearInterval(p), p = null, f)
41
45
  try {
42
- s.postMessage({ t: "bye" }), s.close();
46
+ f.postMessage({ t: "bye" }), f.close();
43
47
  } catch {
44
48
  }
45
- s = null;
46
- }, l = (e) => {
49
+ f = null;
50
+ }, d = (t) => {
47
51
  var i, y, S;
48
52
  if (c === "fallback" || m) return;
49
- const t = d;
50
- C(), c = "fallback", d = !1;
53
+ const e = k;
54
+ C(), c = "fallback", k = !1;
51
55
  const r = o.fallback();
52
- n = r, w && ((i = r.disconnect) == null || i.call(r));
53
- for (const [O, W] of u) for (const q of W) r.on(O, q);
54
- g.size && ((y = r.onAny) == null || y.call(r, (O, ...W) => I(O, W))), t && A("disconnect", ["worker-fallback"]), (S = o.onMode) == null || S.call(o, "fallback", e);
56
+ n = r, g && ((i = r.disconnect) == null || i.call(r));
57
+ for (const [O, W] of s) for (const U of W) r.on(O, U);
58
+ u.size && ((y = r.onAny) == null || y.call(r, (O, ...W) => I(O, W))), e && A("disconnect", ["worker-fallback"]), (S = o.onMode) == null || S.call(o, "fallback", t);
55
59
  };
56
- function I(e, t) {
57
- for (const r of [...g])
60
+ function I(t, e) {
61
+ for (const r of [...u])
58
62
  try {
59
- r(e, ...t);
63
+ r(t, ...e);
60
64
  } catch {
61
65
  }
62
66
  }
63
- const D = () => a({
67
+ const D = () => l({
64
68
  t: "hello",
65
69
  app: o.app,
66
70
  features: o.features ?? [],
67
71
  version: o.version ?? {},
68
72
  active: typeof document > "u" || document.visibilityState === "visible"
69
- }), a = (e) => {
73
+ }), l = (t) => {
70
74
  try {
71
- s == null || s.postMessage(e);
75
+ f == null || f.postMessage(t);
72
76
  } catch {
73
- l("port-closed");
77
+ d("port-closed");
74
78
  }
75
- }, L = (e) => {
79
+ }, L = (t) => {
76
80
  var r;
77
- const t = e.data;
78
- if (!(!t || typeof t != "object" || m))
79
- switch (R = Date.now(), t.t) {
81
+ const e = t.data;
82
+ if (!(!e || typeof e != "object" || m))
83
+ switch (R = Date.now(), e.t) {
80
84
  case "ready": {
81
- if (k && clearTimeout(k), k = null, t.proto !== j) return l(`proto-${String(t.proto)}`);
82
- c = "worker", w || D(), p = setInterval(() => {
83
- Date.now() - R > (o.silentMs ?? 2e4) && l("worker-silent");
85
+ if (w && clearTimeout(w), w = null, e.proto !== z) return d(`proto-${String(e.proto)}`);
86
+ c = "worker", g || D(), p = setInterval(() => {
87
+ Date.now() - R > (o.silentMs ?? 2e4) && d("worker-silent");
84
88
  }, 5e3), (r = o.onMode) == null || r.call(o, "worker", "ready");
85
89
  return;
86
90
  }
87
91
  case "ping":
88
- a({ t: "pong" });
92
+ l({ t: "pong" });
89
93
  return;
90
94
  case "status": {
91
- d = !!t.connected;
92
- const i = typeof t.transport == "string" ? t.transport : null, y = i === "websocket" && T !== "websocket";
95
+ k = !!e.connected;
96
+ const i = typeof e.transport == "string" ? e.transport : null, y = i === "websocket" && T !== "websocket";
93
97
  if (T = i, y) for (const S of M.splice(0)) S();
94
98
  return;
95
99
  }
96
100
  case "need-token":
97
101
  P().then(
98
- (i) => a({ t: "token", req: t.req, token: i, ...i ? {} : { signedOut: U() } })
102
+ (i) => l({ t: "token", req: e.req, token: i, ...i ? {} : { signedOut: x() } })
99
103
  );
100
104
  return;
101
105
  case "ev": {
102
- if (w) return;
103
- t.event === "connect" && (d = !0), t.event === "disconnect" && (d = !1), A(String(t.event), Array.isArray(t.args) ? t.args : []);
106
+ if (g) return;
107
+ e.event === "connect" && (k = !0), e.event === "disconnect" && (k = !1), A(String(e.event), Array.isArray(e.args) ? e.args : []);
104
108
  return;
105
109
  }
106
110
  case "ack": {
107
- const i = E.get(t.id);
108
- E.delete(t.id), i == null || i(...Array.isArray(t.args) ? t.args : []);
111
+ const i = E.get(e.id);
112
+ E.delete(e.id), i == null || i(...Array.isArray(e.args) ? e.args : []);
109
113
  return;
110
114
  }
111
115
  case "fallback":
112
- l(String(t.reason ?? "worker"));
116
+ d(String(e.reason ?? "worker"));
113
117
  return;
114
118
  default:
115
119
  return;
116
120
  }
117
121
  }, P = async () => {
118
122
  if (Date.now() < h) return null;
119
- const e = await o.authToken().catch(() => null);
120
- return e ? (b = 0, h = 0, e) : (b += 1, h = Date.now() + F(b), null);
123
+ const t = await o.authToken().catch(() => null);
124
+ return t ? (b = 0, h = 0, t) : (b += 1, h = Date.now() + q(b), null);
121
125
  }, _ = () => {
122
- if (!$(o.url)) return l("unsupported");
126
+ var t;
127
+ if (!G(o.url)) return d("unsupported");
123
128
  try {
124
- const e = new SharedWorker(o.url, { name: o.name ?? o.app });
125
- s = e.port, s.onmessage = L, s.onmessageerror = () => l("message-error"), e.onerror = () => l("worker-error"), s.start(), k = setTimeout(() => l("no-greeting"), o.readyTimeoutMs ?? 15e3);
129
+ const e = new SharedWorker(Y(o.url, (t = o.version) == null ? void 0 : t.build), {
130
+ name: o.name ?? o.app
131
+ });
132
+ f = e.port, f.onmessage = L, f.onmessageerror = () => d("message-error"), e.onerror = () => d("worker-error"), f.start(), w = setTimeout(() => d("no-greeting"), o.readyTimeoutMs ?? 15e3);
126
133
  } catch {
127
- l("construct-failed");
134
+ d("construct-failed");
128
135
  }
129
136
  if (typeof window < "u") {
130
137
  const e = () => {
131
- c === "worker" && document.visibilityState === "visible" && a({ t: "active" });
138
+ c === "worker" && document.visibilityState === "visible" && l({ t: "active" });
132
139
  };
133
140
  document.addEventListener("visibilitychange", e), window.addEventListener("focus", e), window.addEventListener("pagehide", () => {
134
- c === "worker" && a({ t: "bye" });
141
+ c === "worker" && l({ t: "bye" });
135
142
  });
136
143
  }
137
- }, f = {
144
+ }, a = {
138
145
  get connected() {
139
- return w && c !== "fallback" ? !1 : c === "fallback" ? !!(n != null && n.connected) : d;
146
+ return g && c !== "fallback" ? !1 : c === "fallback" ? !!(n != null && n.connected) : k;
140
147
  },
141
- on(e, t) {
142
- const r = u.get(e) ?? /* @__PURE__ */ new Set();
143
- return u.set(e, r), r.add(t), c === "fallback" && (n == null || n.on(e, t)), f;
148
+ on(t, e) {
149
+ const r = s.get(t) ?? /* @__PURE__ */ new Set();
150
+ return s.set(t, r), r.add(e), c === "fallback" && (n == null || n.on(t, e)), a;
144
151
  },
145
- off(e, t) {
152
+ off(t, e) {
146
153
  var r;
147
- return t ? (r = u.get(e)) == null || r.delete(t) : u.delete(e), c === "fallback" && (n == null || n.off(e, t)), f;
154
+ return e ? (r = s.get(t)) == null || r.delete(e) : s.delete(t), c === "fallback" && (n == null || n.off(t, e)), a;
148
155
  },
149
- once(e, t) {
156
+ once(t, e) {
150
157
  const r = (...i) => {
151
- f.off(e, r), t(...i);
158
+ a.off(t, r), e(...i);
152
159
  };
153
- return f.on(e, r);
160
+ return a.on(t, r);
154
161
  },
155
- onAny(e) {
162
+ onAny(t) {
156
163
  var r;
157
- const t = g.size === 0;
158
- return g.add(e), c === "fallback" && t && ((r = n == null ? void 0 : n.onAny) == null || r.call(n, (i, ...y) => I(i, y))), f;
164
+ const e = u.size === 0;
165
+ return u.add(t), c === "fallback" && e && ((r = n == null ? void 0 : n.onAny) == null || r.call(n, (i, ...y) => I(i, y))), a;
159
166
  },
160
- offAny(e) {
161
- return g.delete(e), f;
167
+ offAny(t) {
168
+ return u.delete(t), a;
162
169
  },
163
- listeners(e) {
164
- return [...u.get(e) ?? []];
170
+ listeners(t) {
171
+ return [...s.get(t) ?? []];
165
172
  },
166
- emit(e, ...t) {
167
- if (c === "fallback") return n == null ? void 0 : n.emit(e, ...t);
168
- const r = t[t.length - 1];
169
- if (w)
170
- return typeof r == "function" && setTimeout(() => r(), 0), f;
173
+ emit(t, ...e) {
174
+ if (c === "fallback") return n == null ? void 0 : n.emit(t, ...e);
175
+ const r = e[e.length - 1];
176
+ if (g)
177
+ return typeof r == "function" && setTimeout(() => r(), 0), a;
171
178
  if (typeof r == "function") {
172
179
  const i = ++K;
173
- E.set(i, r), a({ t: "emit", event: e, payload: t[0], ack: i });
174
- } else a({ t: "emit", event: e, payload: t[0] });
175
- return f;
180
+ E.set(i, r), l({ t: "emit", event: t, payload: e[0], ack: i });
181
+ } else l({ t: "emit", event: t, payload: e[0] });
182
+ return a;
176
183
  },
177
184
  connect() {
178
- var e;
179
- c === "fallback" ? (e = n == null ? void 0 : n.connect) == null || e.call(n) : a({ t: "connect" });
185
+ var t;
186
+ c === "fallback" ? (t = n == null ? void 0 : n.connect) == null || t.call(n) : l({ t: "connect" });
180
187
  },
181
188
  disconnect() {
182
- var e;
183
- m = !0, v == null || v(), C(), (e = n == null ? void 0 : n.disconnect) == null || e.call(n);
189
+ var t;
190
+ m = !0, v == null || v(), C(), (t = n == null ? void 0 : n.disconnect) == null || t.call(n);
184
191
  },
185
192
  signedIn() {
186
- b = 0, h = 0, !(c !== "worker" || m) && (a({ t: "signed-in" }), (typeof document > "u" || document.visibilityState === "visible") && a({ t: "active" }));
193
+ b = 0, h = 0, !(c !== "worker" || m) && (l({ t: "signed-in" }), (typeof document > "u" || document.visibilityState === "visible") && l({ t: "active" }));
187
194
  },
188
195
  mode: () => c,
189
- chaosPause(e) {
190
- var t, r;
191
- if (!(e === w || m)) {
192
- if (w = e, c === "fallback") {
193
- e ? (t = n == null ? void 0 : n.disconnect) == null || t.call(n) : (r = n == null ? void 0 : n.connect) == null || r.call(n);
196
+ chaosPause(t) {
197
+ var e, r;
198
+ if (!(t === g || m)) {
199
+ if (g = t, c === "fallback") {
200
+ t ? (e = n == null ? void 0 : n.disconnect) == null || e.call(n) : (r = n == null ? void 0 : n.connect) == null || r.call(n);
194
201
  return;
195
202
  }
196
- if (e) {
197
- const i = d;
198
- d = !1, i && A("disconnect", ["transport close"]);
203
+ if (t) {
204
+ const i = k;
205
+ k = !1, i && A("disconnect", ["transport close"]);
199
206
  return;
200
207
  }
201
208
  c === "worker" && D(), typeof window < "u" && window.dispatchEvent(new CustomEvent("nvr:catchup-full"));
@@ -206,24 +213,25 @@ function J(o) {
206
213
  get transport() {
207
214
  return {
208
215
  get name() {
209
- var e, t, r;
210
- return c === "fallback" ? (r = (t = (e = n == null ? void 0 : n.io) == null ? void 0 : e.engine) == null ? void 0 : t.transport) == null ? void 0 : r.name : T ?? void 0;
216
+ var t, e, r;
217
+ return c === "fallback" ? (r = (e = (t = n == null ? void 0 : n.io) == null ? void 0 : t.engine) == null ? void 0 : e.transport) == null ? void 0 : r.name : T ?? void 0;
211
218
  }
212
219
  };
213
220
  },
214
- once(e, t) {
215
- e === "upgrade" && M.push(t);
221
+ once(t, e) {
222
+ t === "upgrade" && M.push(e);
216
223
  }
217
224
  }
218
225
  }
219
226
  };
220
- return v = z(() => f.signedIn()), _(), x(f), f;
227
+ return v = F(() => a.signedIn()), _(), $(a), a;
221
228
  }
222
229
  export {
223
230
  B as WORKER_SOCKET_PREF_KEY,
224
- j as WORKER_SOCKET_PROTO,
225
- J as createWorkerSocket,
226
- N as sharedWorkerSupported,
227
- $ as shouldUseWorkerSocket,
228
- Y as workerSocketPreference
231
+ z as WORKER_SOCKET_PROTO,
232
+ Q as createWorkerSocket,
233
+ j as sharedWorkerSupported,
234
+ G as shouldUseWorkerSocket,
235
+ N as workerSocketPreference,
236
+ Y as workerUrlForBuild
229
237
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.28",
3
+ "version": "0.3.30",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",