@nivaro/react 0.3.137 → 0.3.139

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.
Files changed (50) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +95 -4
  4. package/dist/index.js +748 -743
  5. package/dist/shared/components/CollectionBrowserView.js +392 -389
  6. package/dist/shared/components/DelegateCoverLine.js +80 -87
  7. package/dist/shared/components/ItemEditForm.js +589 -588
  8. package/dist/shared/components/MyWorkView.js +284 -286
  9. package/dist/shared/components/NotificationBell.js +251 -205
  10. package/dist/shared/components/ai/AiAnalyticsView.js +878 -417
  11. package/dist/shared/components/ai/AiPlanCard.js +164 -122
  12. package/dist/shared/components/ai/AiPlanUndo.js +291 -0
  13. package/dist/shared/components/ai/call-log/CallDrawer.js +357 -0
  14. package/dist/shared/components/ai/call-log/RawJson.js +126 -0
  15. package/dist/shared/components/ai/call-log/ThreadView.js +223 -0
  16. package/dist/shared/components/ai/call-log/TranscriptView.js +227 -0
  17. package/dist/shared/components/ai/call-log/controls.js +364 -0
  18. package/dist/shared/components/ai/call-log/format.js +46 -0
  19. package/dist/shared/components/ai/call-log/url.js +105 -0
  20. package/dist/shared/components/chat/chat-core.js +422 -346
  21. package/dist/shared/components/integrations/IntegrationObligationsView.js +98 -98
  22. package/dist/shared/components/integrations/RecordIntegrationPreview.js +102 -93
  23. package/dist/shared/components/integrations/console/api.js +11 -1
  24. package/dist/shared/components/item-edit/HeaderRollupExplainer.js +5 -1
  25. package/dist/shared/components/item-edit/RecordLiveSync.js +241 -229
  26. package/dist/shared/components/item-edit/RecordRecapChanges.js +166 -0
  27. package/dist/shared/components/item-edit/RecordRecapStrip.js +254 -84
  28. package/dist/shared/components/item-edit/live-related.js +34 -18
  29. package/dist/shared/components/panels/RevisionsPanel.js +735 -683
  30. package/dist/shared/components/queue/QueueWorklist.js +323 -316
  31. package/dist/shared/components/support/SupportRequestDialog.js +198 -181
  32. package/dist/shared/components/trackers/use-tracker-link.js +74 -65
  33. package/dist/shared/lib/activity-sentence.js +167 -151
  34. package/dist/shared/lib/config-update-refresh.js +34 -0
  35. package/dist/shared/lib/config-watch.js +17 -17
  36. package/dist/shared/lib/gap-refresh.js +49 -0
  37. package/dist/shared/lib/integration-dots.js +8 -8
  38. package/dist/shared/lib/live-ops.js +26 -23
  39. package/dist/shared/lib/live-pickers.js +1 -1
  40. package/dist/shared/lib/live-queries.js +223 -195
  41. package/dist/shared/lib/live.js +56 -51
  42. package/dist/shared/lib/obligation-banner.js +11 -10
  43. package/dist/shared/lib/obligation-filters.js +22 -18
  44. package/dist/shared/lib/obligation-reason-text.js +18 -8
  45. package/dist/shared/lib/presence-hooks.js +133 -132
  46. package/dist/shared/lib/reconnect-resync.js +90 -0
  47. package/dist/shared/lib/record-room-holds.js +43 -0
  48. package/dist/shared/lib/socket-realtime.js +116 -105
  49. package/dist/shared/lib/user-sync.js +1 -6
  50. package/package.json +1 -1
@@ -1,11 +1,12 @@
1
1
  import { useQuery as F } from "@tanstack/react-query";
2
- import { useState as C, useEffect as v, useCallback as R, useMemo as j, useRef as A } from "react";
2
+ import { useState as R, useEffect as v, useCallback as C, useMemo as A, useRef as U } from "react";
3
3
  import { useOptionalNivaroClient as q } from "../context.js";
4
4
  import { post as $, get as B } from "./commands.js";
5
5
  import { trackActivity as N, onIdleChange as W, idleState as z } from "./idle.js";
6
6
  import { useLiveEvent as E } from "./live.js";
7
- import { useMyUserId as M, useRecordSignalPeers as Q, useRecordSignalWhile as Y } from "./presence-signals.js";
8
- import { useOptionalRealtime as P, useRealtimeStatus as G } from "./realtime.js";
7
+ import { useMyUserId as M, useRecordSignalPeers as H, useRecordSignalWhile as Q } from "./presence-signals.js";
8
+ import { useOptionalRealtime as P, useRealtimeStatus as Y } from "./realtime.js";
9
+ import { newRecordRoomHolder as G } from "./record-room-holds.js";
9
10
  let O = null, I = !1;
10
11
  const T = /* @__PURE__ */ new Set();
11
12
  function L() {
@@ -14,123 +15,123 @@ function L() {
14
15
  function D() {
15
16
  if (I || typeof document > "u") return;
16
17
  I = !0, N(), O = L() ? Date.now() : null;
17
- const n = () => {
18
- const r = L();
19
- if (r !== (O != null)) {
20
- O = r ? Date.now() : null;
18
+ const r = () => {
19
+ const o = L();
20
+ if (o !== (O != null)) {
21
+ O = o ? Date.now() : null;
21
22
  for (const e of T)
22
23
  try {
23
- e(r);
24
+ e(o);
24
25
  } catch {
25
26
  }
26
27
  }
27
28
  };
28
- document.addEventListener("visibilitychange", n), W(n);
29
+ document.addEventListener("visibilitychange", r), W(r);
29
30
  }
30
31
  function K() {
31
32
  return D(), O != null;
32
33
  }
33
- function H(n) {
34
- return D(), T.add(n), () => T.delete(n);
34
+ function J(r) {
35
+ return D(), T.add(r), () => T.delete(r);
35
36
  }
36
- function _(n, r, e = Date.now()) {
37
+ function _(r, o, e = Date.now()) {
37
38
  return K() ? {
38
- collection: n,
39
- item: String(r),
39
+ collection: r,
40
+ item: String(o),
40
41
  hidden: !0,
41
42
  hidden_ms: Math.max(0, e - (O ?? e))
42
- } : { collection: n, item: String(r), hidden: !1 };
43
+ } : { collection: r, item: String(o), hidden: !1 };
43
44
  }
44
- function J(n, r) {
45
- const e = r ? String(r).toUpperCase() : null, i = /* @__PURE__ */ new Set(), s = [];
46
- for (const t of n ?? []) {
45
+ function X(r, o) {
46
+ const e = o ? String(o).toUpperCase() : null, i = /* @__PURE__ */ new Set(), s = [];
47
+ for (const t of r ?? []) {
47
48
  if (!t || t.id == null) continue;
48
49
  const u = String(t.id).toUpperCase();
49
50
  u === e || i.has(u) || (i.add(u), s.push(t));
50
51
  }
51
52
  return s;
52
53
  }
53
- function V(n, r) {
54
- const e = G(), i = A(!1), s = A(n);
55
- s.current = n, v(() => {
56
- r && ((e == null ? void 0 : e.state) === "reconnecting" ? i.current = !0 : i.current && (i.current = !1, s.current()));
57
- }, [e == null ? void 0 : e.state, r]);
54
+ function V(r, o) {
55
+ const e = Y(), i = U(!1), s = U(r);
56
+ s.current = r, v(() => {
57
+ o && ((e == null ? void 0 : e.state) === "reconnecting" ? i.current = !0 : i.current && (i.current = !1, s.current()));
58
+ }, [e == null ? void 0 : e.state, o]);
58
59
  }
59
- function le(n, r) {
60
- const e = P(), i = M(), s = r == null ? "" : String(r), t = !!e && !!n && !!s && s !== "new", [u, w] = C([]), h = R(() => {
61
- !t || !e || !n || (e.emit("record:join", { collection: n, item: s }), K() && e.emit("record:visibility", _(n, s)));
62
- }, [e, n, s, t]);
60
+ function ae(r, o) {
61
+ const e = P(), i = M(), s = o == null ? "" : String(o), t = !!e && !!r && !!s && s !== "new", [u, m] = R([]), y = A(() => G("p"), []), h = C(() => {
62
+ !t || !e || !r || (e.emit("record:join", { collection: r, item: s, holder: y }), K() && e.emit("record:visibility", _(r, s)));
63
+ }, [e, r, s, t, y]);
63
64
  return v(() => {
64
- if (w([]), !t) return;
65
+ if (m([]), !t) return;
65
66
  h();
66
- const l = H(() => {
67
- n && (e == null || e.emit("record:visibility", _(n, s)));
67
+ const n = J(() => {
68
+ r && (e == null || e.emit("record:visibility", _(r, s)));
68
69
  });
69
70
  return () => {
70
- l(), e == null || e.emit("record:leave", { collection: n, item: s });
71
+ n(), e == null || e.emit("record:leave", { collection: r, item: s, holder: y });
71
72
  };
72
- }, [e, n, s, t, h]), V(h, t), E(
73
+ }, [e, r, s, t, h, y]), V(h, t), E(
73
74
  "record:viewers",
74
- (l) => {
75
- Array.isArray(l == null ? void 0 : l.viewers) && w(l.viewers);
75
+ (n) => {
76
+ Array.isArray(n == null ? void 0 : n.viewers) && m(n.viewers);
76
77
  },
77
78
  {
78
79
  enabled: t,
79
80
  includeOwn: !0,
80
81
  // An older server names no record: accept, as the hosts' own hooks do.
81
- match: (l) => (l == null ? void 0 : l.collection) == null || (l == null ? void 0 : l.item) == null ? !0 : l.collection === n && String(l.item) === s
82
+ match: (n) => (n == null ? void 0 : n.collection) == null || (n == null ? void 0 : n.item) == null ? !0 : n.collection === r && String(n.item) === s
82
83
  }
83
- ), { viewers: j(() => J(u, i), [u, i]) };
84
+ ), { viewers: A(() => X(u, i), [u, i]) };
84
85
  }
85
- function fe(n, r, e = {}) {
86
- const i = P(), s = M(), t = r == null ? "" : String(r), u = !!i && !!n && !!t && t !== "new", [w, h] = C({});
87
- v(() => h({}), [n, t]), E(
86
+ function de(r, o, e = {}) {
87
+ const i = P(), s = M(), t = o == null ? "" : String(o), u = !!i && !!r && !!t && t !== "new", [m, y] = R({});
88
+ v(() => y({}), [r, t]), E(
88
89
  "field:editing",
89
- (o) => {
90
- typeof (o == null ? void 0 : o.field) == "string" && h((b) => {
91
- const p = { ...b }, m = o.user;
92
- return m && (!s || String(m.id).toUpperCase() !== s.toUpperCase()) ? p[o.field] = m : delete p[o.field], p;
90
+ (n) => {
91
+ typeof (n == null ? void 0 : n.field) == "string" && y((b) => {
92
+ const p = { ...b }, d = n.user;
93
+ return d && (!s || String(d.id).toUpperCase() !== s.toUpperCase()) ? p[n.field] = d : delete p[n.field], p;
93
94
  });
94
95
  },
95
96
  {
96
97
  enabled: u,
97
98
  includeOwn: !0,
98
- match: (o) => (o == null ? void 0 : o.collection) == null || (o == null ? void 0 : o.item) == null ? !0 : o.collection === n && String(o.item) === t
99
+ match: (n) => (n == null ? void 0 : n.collection) == null || (n == null ? void 0 : n.item) == null ? !0 : n.collection === r && String(n.item) === t
99
100
  }
100
101
  );
101
- const S = R(
102
- (o) => {
103
- u && o && (i == null || i.emit("field:focus", { field: o, collection: n, item: t }));
102
+ const h = C(
103
+ (n) => {
104
+ u && n && (i == null || i.emit("field:focus", { field: n, collection: r, item: t }));
104
105
  },
105
- [i, n, t, u]
106
- ), l = R(
107
- (o) => {
108
- u && o && (i == null || i.emit("field:blur", { field: o, collection: n, item: t }));
106
+ [i, r, t, u]
107
+ ), S = C(
108
+ (n) => {
109
+ u && n && (i == null || i.emit("field:blur", { field: n, collection: r, item: t }));
109
110
  },
110
- [i, n, t, u]
111
+ [i, r, t, u]
111
112
  );
112
113
  return v(() => {
113
114
  if (!u || !e.capture || typeof document > "u") return;
114
- const o = (m) => {
115
- var c, g, a;
116
- return (a = (g = (c = m.target) == null ? void 0 : c.closest) == null ? void 0 : g.call(c, "[data-field]")) == null ? void 0 : a.getAttribute("data-field");
117
- }, b = (m) => {
118
- const c = o(m);
115
+ const n = (d) => {
116
+ var c, g, f;
117
+ return (f = (g = (c = d.target) == null ? void 0 : c.closest) == null ? void 0 : g.call(c, "[data-field]")) == null ? void 0 : f.getAttribute("data-field");
118
+ }, b = (d) => {
119
+ const c = n(d);
120
+ c && h(c);
121
+ }, p = (d) => {
122
+ const c = n(d);
119
123
  c && S(c);
120
- }, p = (m) => {
121
- const c = o(m);
122
- c && l(c);
123
124
  };
124
125
  return document.addEventListener("focusin", b), document.addEventListener("focusout", p), () => {
125
126
  document.removeEventListener("focusin", b), document.removeEventListener("focusout", p);
126
127
  };
127
- }, [u, e.capture, S, l]), { editing: w, focus: S, blur: l };
128
+ }, [u, e.capture, h, S]), { editing: m, focus: h, blur: S };
128
129
  }
129
- function ae(n, r) {
130
- const e = Q(n, r, "note"), [i, s] = C(!1);
131
- Y(n, r, "note", i);
132
- const t = A(null), u = R((w) => {
133
- t.current && clearTimeout(t.current), t.current = null, s(w), w && (t.current = setTimeout(() => s(!1), 6e3));
130
+ function me(r, o) {
131
+ const e = H(r, o, "note"), [i, s] = R(!1);
132
+ Q(r, o, "note", i);
133
+ const t = U(null), u = C((m) => {
134
+ t.current && clearTimeout(t.current), t.current = null, s(m), m && (t.current = setTimeout(() => s(!1), 6e3));
134
135
  }, []);
135
136
  return v(
136
137
  () => () => {
@@ -139,124 +140,124 @@ function ae(n, r) {
139
140
  []
140
141
  ), { typing: e, setTyping: u };
141
142
  }
142
- const X = {};
143
- function k(n, r) {
144
- return `${n}:${r}`;
143
+ const Z = {};
144
+ function k(r, o) {
145
+ return `${r}:${o}`;
145
146
  }
146
- function Z(n) {
147
- const r = n;
148
- if (!(r != null && r.collection)) return [];
149
- const e = String(r.collection), i = (s) => Array.isArray(s) ? s.map(String) : [];
150
- return r.rows && typeof r.rows == "object" ? Object.entries(r.rows).map(([s, t]) => [
147
+ function ee(r) {
148
+ const o = r;
149
+ if (!(o != null && o.collection)) return [];
150
+ const e = String(o.collection), i = (s) => Array.isArray(s) ? s.map(String) : [];
151
+ return o.rows && typeof o.rows == "object" ? Object.entries(o.rows).map(([s, t]) => [
151
152
  k(e, s),
152
153
  i(t)
153
- ]) : r.item == null ? [] : [[k(e, String(r.item)), i(r.user_ids)]];
154
+ ]) : o.item == null ? [] : [[k(e, String(o.item)), i(o.user_ids)]];
154
155
  }
155
- function ee(n) {
156
- const r = q(), e = [...new Set(n.map((s) => s.toUpperCase()))].sort().join(","), { data: i } = F({
156
+ function te(r) {
157
+ const o = q(), e = [...new Set(r.map((s) => s.toUpperCase()))].sort().join(","), { data: i } = F({
157
158
  queryKey: ["presence-visible-people", e],
158
- queryFn: () => r.request(
159
+ queryFn: () => o.request(
159
160
  B(`/presence/people?ids=${encodeURIComponent(e.split(",").slice(0, 100).join(","))}`)
160
161
  ).then((s) => new Set((s.data ?? []).map((t) => String(t.user_id).toUpperCase()))).catch(() => /* @__PURE__ */ new Set()),
161
- enabled: !!r && e.length > 0,
162
+ enabled: !!o && e.length > 0,
162
163
  staleTime: 5 * 6e4
163
164
  });
164
165
  return e.length === 0 ? null : i ?? null;
165
166
  }
166
- function U(n) {
167
- const r = /* @__PURE__ */ new Map();
168
- for (const i of n) {
167
+ function j(r) {
168
+ const o = /* @__PURE__ */ new Map();
169
+ for (const i of r) {
169
170
  const s = i.indexOf(":");
170
171
  if (s <= 0) continue;
171
- const t = i.slice(0, s), u = r.get(t) ?? [];
172
- u.push(i.slice(s + 1)), r.set(t, u);
172
+ const t = i.slice(0, s), u = o.get(t) ?? [];
173
+ u.push(i.slice(s + 1)), o.set(t, u);
173
174
  }
174
175
  const e = [];
175
- for (const [i, s] of r)
176
+ for (const [i, s] of o)
176
177
  for (let t = 0; t < s.length; t += 100)
177
178
  e.push({ collection: i, items: s.slice(t, t + 100) });
178
179
  return e;
179
180
  }
180
- function de(n, r = {}) {
181
- const e = P(), i = q(), s = M(), t = r.enabled !== !1 && n.length > 0, u = n.filter((c) => c.collection && c.item != null).map((c) => k(c.collection, c.item)).join(""), [w, h] = C({}), [S, l] = C({}), o = A(/* @__PURE__ */ new Set()), b = R(() => {
181
+ function we(r, o = {}) {
182
+ const e = P(), i = q(), s = M(), t = o.enabled !== !1 && r.length > 0, u = r.filter((c) => c.collection && c.item != null).map((c) => k(c.collection, c.item)).join(""), [m, y] = R({}), [h, S] = R({}), n = U(/* @__PURE__ */ new Set()), b = C(() => {
182
183
  if (!(!e || !t))
183
- for (const c of U(o.current)) e.emit("presence:watch", c);
184
+ for (const c of j(n.current)) e.emit("presence:watch", c);
184
185
  }, [e, t]);
185
186
  v(() => {
186
187
  if (!e || !t) return;
187
- const c = new Set(u.split("").filter(Boolean)), g = [...c].filter((f) => !o.current.has(f)), a = [...o.current].filter((f) => !c.has(f));
188
- o.current = c;
189
- for (const f of U(g)) e.emit("presence:watch", f);
190
- if (a.length) {
191
- for (const f of U(a)) e.emit("presence:unwatch", f);
192
- h((f) => {
193
- const y = { ...f };
194
- for (const d of a) delete y[d];
195
- return y;
188
+ const c = new Set(u.split("").filter(Boolean)), g = [...c].filter((l) => !n.current.has(l)), f = [...n.current].filter((l) => !c.has(l));
189
+ n.current = c;
190
+ for (const l of j(g)) e.emit("presence:watch", l);
191
+ if (f.length) {
192
+ for (const l of j(f)) e.emit("presence:unwatch", l);
193
+ y((l) => {
194
+ const w = { ...l };
195
+ for (const a of f) delete w[a];
196
+ return w;
196
197
  });
197
198
  }
198
199
  }, [e, u, t]), v(() => {
199
200
  if (e)
200
201
  return () => {
201
- o.current.size && e.emit("presence:unwatch", {}), o.current = /* @__PURE__ */ new Set(), h({});
202
+ n.current.size && e.emit("presence:unwatch", {}), n.current = /* @__PURE__ */ new Set(), y({});
202
203
  };
203
204
  }, [e]), V(b, !!e && t), E(
204
205
  "presence:rows",
205
206
  (c) => {
206
- const g = Z(c);
207
- g.length !== 0 && h((a) => {
208
- const f = { ...a };
209
- for (const [y, d] of g)
210
- d.length ? f[y] = d : delete f[y];
211
- return f;
207
+ const g = ee(c);
208
+ g.length !== 0 && y((f) => {
209
+ const l = { ...f };
210
+ for (const [w, a] of g)
211
+ a.length ? l[w] = a : delete l[w];
212
+ return l;
212
213
  });
213
214
  },
214
215
  { enabled: !!e && t, includeOwn: !0 }
215
216
  ), v(() => {
216
217
  if (e || !i || !t) return;
217
- const c = r.pollMs ?? 3e4, g = u.split("").filter(Boolean).slice(0, 100).map((d) => {
218
- const x = d.indexOf(":");
219
- return { collection: d.slice(0, x), item_id: d.slice(x + 1) };
218
+ const c = o.pollMs ?? 3e4, g = u.split("").filter(Boolean).slice(0, 100).map((a) => {
219
+ const x = a.indexOf(":");
220
+ return { collection: a.slice(0, x), item_id: a.slice(x + 1) };
220
221
  });
221
- let a = !0;
222
- const f = () => {
223
- i.request($("/presence/record-viewers", { pairs: g })).then((d) => {
224
- a && l(d.data ?? {});
222
+ let f = !0;
223
+ const l = () => {
224
+ i.request($("/presence/record-viewers", { pairs: g })).then((a) => {
225
+ f && S(a.data ?? {});
225
226
  }).catch(() => {
226
227
  });
227
228
  };
228
- f();
229
- const y = c > 0 ? setInterval(f, c) : null;
229
+ l();
230
+ const w = c > 0 ? setInterval(l, c) : null;
230
231
  return () => {
231
- a = !1, y && clearInterval(y);
232
+ f = !1, w && clearInterval(w);
232
233
  };
233
- }, [e, i, u, t, r.pollMs]);
234
- const p = j(() => [...new Set(Object.values(w).flat())], [w]), m = ee(p);
235
- return j(() => {
236
- if (!t) return X;
234
+ }, [e, i, u, t, o.pollMs]);
235
+ const p = A(() => [...new Set(Object.values(m).flat())], [m]), d = te(p);
236
+ return A(() => {
237
+ if (!t) return Z;
237
238
  const c = {}, g = s == null ? void 0 : s.toUpperCase();
238
239
  if (e)
239
- for (const [a, f] of Object.entries(w)) {
240
- const y = f.filter((d) => d.toUpperCase() !== g);
241
- y.length !== 0 && (c[a] = {
242
- ids: m ? y.filter((d) => m.has(d.toUpperCase())) : [],
243
- count: y.length
240
+ for (const [f, l] of Object.entries(m)) {
241
+ const w = l.filter((a) => a.toUpperCase() !== g);
242
+ w.length !== 0 && (c[f] = {
243
+ ids: d ? w.filter((a) => d.has(a.toUpperCase())) : [],
244
+ count: w.length
244
245
  });
245
246
  }
246
247
  else
247
- for (const [a, f] of Object.entries(S)) f > 0 && (c[a] = { ids: [], count: f });
248
+ for (const [f, l] of Object.entries(h)) l > 0 && (c[f] = { ids: [], count: l });
248
249
  return c;
249
- }, [t, e, w, S, m, s]);
250
+ }, [t, e, m, h, d, s]);
250
251
  }
251
252
  export {
252
- J as distinctOtherViewers,
253
- H as onRecordTabAway,
253
+ X as distinctOtherViewers,
254
+ J as onRecordTabAway,
254
255
  K as recordTabAway,
255
256
  _ as recordVisibilityPayload,
256
257
  k as rowPresenceKey,
257
- Z as rowPresenceUpdates,
258
- fe as useFieldFocus,
259
- le as usePresence,
260
- de as useRowPresence,
261
- ae as useTyping
258
+ ee as rowPresenceUpdates,
259
+ de as useFieldFocus,
260
+ ae as usePresence,
261
+ we as useRowPresence,
262
+ me as useTyping
262
263
  };
@@ -0,0 +1,90 @@
1
+ import { useRef as S, useEffect as V } from "react";
2
+ import { getLiveMode as W } from "./live-preference.js";
3
+ import { useOptionalRealtime as _ } from "./realtime.js";
4
+ const j = "nvr:resync";
5
+ function C(n, e = {}) {
6
+ var p, x;
7
+ const s = Math.max(0, e.jitterMs ?? 4e3), o = Math.max(0, e.cooldownMs ?? 5e3), r = e.wakeGapMs ?? 15e4, f = e.wakeTickMs ?? 15e3, a = e.now ?? (() => Date.now()), L = e.random ?? Math.random, c = e.doc === void 0 ? typeof document > "u" ? null : document : e.doc, h = e.win === void 0 ? typeof window > "u" ? null : window : e.win, m = e.allowed ?? (() => W() !== "off"), l = /* @__PURE__ */ new Set();
8
+ let w = !1, i = null, d = null, k = Number.NEGATIVE_INFINITY, v = null;
9
+ const E = () => !!c && c.visibilityState === "hidden", g = (t) => {
10
+ if (!w) {
11
+ if (E()) {
12
+ d = d ?? t;
13
+ return;
14
+ }
15
+ if (d = null, !!m()) {
16
+ k = a();
17
+ for (const u of [...l])
18
+ try {
19
+ u(t);
20
+ } catch {
21
+ }
22
+ try {
23
+ h == null || h.dispatchEvent(new CustomEvent(j, { detail: { reason: t } }));
24
+ } catch {
25
+ }
26
+ }
27
+ }
28
+ }, y = (t) => {
29
+ if (w) return;
30
+ if (i) {
31
+ t === "reconnect" && (v = "reconnect");
32
+ return;
33
+ }
34
+ v = t;
35
+ const u = a() - k, D = Math.max(0, o - u) + Math.floor(L() * Math.max(0, s));
36
+ i = setTimeout(() => {
37
+ i = null;
38
+ const G = v ?? t;
39
+ v = null, g(G);
40
+ }, D);
41
+ };
42
+ let T = ((p = n == null ? void 0 : n.status) == null ? void 0 : p.call(n).state) !== "reconnecting";
43
+ const b = (x = n == null ? void 0 : n.onStatus) == null ? void 0 : x.call(n, (t) => {
44
+ const u = t.state === "live";
45
+ u && !T && t.resumed !== null && y("reconnect"), T = u;
46
+ });
47
+ let I = a();
48
+ const N = f > 0 ? setInterval(() => {
49
+ const t = a();
50
+ t - I > r && y("wake"), I = t;
51
+ }, f) : null, R = () => {
52
+ !E() && d && !i && g(d);
53
+ };
54
+ return c == null || c.addEventListener("visibilitychange", R), {
55
+ subscribe(t) {
56
+ return l.add(t), () => {
57
+ l.delete(t);
58
+ };
59
+ },
60
+ trigger: y,
61
+ listeners: () => l.size,
62
+ dispose() {
63
+ w || (w = !0, b == null || b(), N && clearInterval(N), i && clearTimeout(i), i = null, c == null || c.removeEventListener("visibilitychange", R), l.clear());
64
+ }
65
+ };
66
+ }
67
+ const M = /* @__PURE__ */ new WeakMap();
68
+ function O(n, e) {
69
+ let s = M.get(n);
70
+ s || (s = C(n), M.set(n, s));
71
+ const o = s, r = o.subscribe(e);
72
+ return () => {
73
+ r(), o.listeners() === 0 && (o.dispose(), M.get(n) === o && M.delete(n));
74
+ };
75
+ }
76
+ function B(n, e = {}) {
77
+ const s = _(), o = S(n);
78
+ o.current = n;
79
+ const r = e.enabled !== !1;
80
+ V(() => {
81
+ if (!(!s || !r))
82
+ return O(s, (f) => o.current(f));
83
+ }, [s, r]);
84
+ }
85
+ export {
86
+ j as RESYNC_WINDOW_EVENT,
87
+ C as createResyncDetector,
88
+ O as onResync,
89
+ B as useResync
90
+ };
@@ -0,0 +1,43 @@
1
+ function c(o) {
2
+ const e = o ?? {};
3
+ return typeof e.collection != "string" || !e.collection || e.item == null || e.item === "" ? null : {
4
+ collection: e.collection,
5
+ item: String(e.item),
6
+ holder: typeof e.holder == "string" ? e.holder : ""
7
+ };
8
+ }
9
+ const l = (o, e) => `${o}\0${e}`;
10
+ function s() {
11
+ const o = /* @__PURE__ */ new Map();
12
+ return {
13
+ join(e) {
14
+ const t = c(e);
15
+ if (!t) return null;
16
+ const n = l(t.collection, t.item), r = o.get(n) ?? {
17
+ ref: { collection: t.collection, item: t.item },
18
+ holders: /* @__PURE__ */ new Set()
19
+ };
20
+ return r.holders.add(t.holder), o.set(n, r), r.ref;
21
+ },
22
+ leave(e) {
23
+ const t = c(e);
24
+ if (!t) return null;
25
+ const n = l(t.collection, t.item), r = o.get(n);
26
+ return r ? (r.holders.delete(t.holder), r.holders.size > 0 ? null : (o.delete(n), r.ref)) : { collection: t.collection, item: t.item };
27
+ },
28
+ held() {
29
+ return [...o.values()].map((e) => e.ref);
30
+ },
31
+ has(e, t) {
32
+ return o.has(l(e, String(t)));
33
+ }
34
+ };
35
+ }
36
+ let i = 0;
37
+ function u(o = "h") {
38
+ return i += 1, `${o}${i}`;
39
+ }
40
+ export {
41
+ s as createRecordRoomHolds,
42
+ u as newRecordRoomHolder
43
+ };