@nivaro/react 0.3.126 → 0.3.128

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 (40) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +20 -2
  4. package/dist/index.js +150 -147
  5. package/dist/shared/components/CollectionBrowserView.js +3259 -3211
  6. package/dist/shared/components/DataTable.js +406 -401
  7. package/dist/shared/components/ItemEditForm.js +4359 -4299
  8. package/dist/shared/components/MatrixEditor.js +548 -490
  9. package/dist/shared/components/MyWorkView.js +284 -274
  10. package/dist/shared/components/NotificationBell.js +264 -218
  11. package/dist/shared/components/RecordGridEditor.js +582 -472
  12. package/dist/shared/components/chat/chat-core.js +331 -346
  13. package/dist/shared/components/chat/chat-typing.js +25 -0
  14. package/dist/shared/components/command-center/CommandCenterView.js +1 -1
  15. package/dist/shared/components/command-center/PeekPanel.js +8 -1
  16. package/dist/shared/components/command-center/api.js +17 -9
  17. package/dist/shared/components/command-center/panels/AttentionPanel.js +4 -1
  18. package/dist/shared/components/command-center/panels/PartnersPanel.js +2 -1
  19. package/dist/shared/components/item-edit/GroupSection.js +1 -1
  20. package/dist/shared/components/item-edit/InlineTableField.js +432 -429
  21. package/dist/shared/components/item-edit/RecordLiveSync.js +115 -108
  22. package/dist/shared/components/item-edit/RecordViewersChip.js +17 -16
  23. package/dist/shared/components/item-edit/RowComments.js +33 -30
  24. package/dist/shared/components/item-edit/cascade-clear-notice.js +30 -28
  25. package/dist/shared/components/item-edit/live-related.js +29 -16
  26. package/dist/shared/components/item-edit/record-opened-live.js +86 -0
  27. package/dist/shared/components/item-edit/reimport-m2m.js +17 -0
  28. package/dist/shared/components/panels/OwnerOpenedLine.js +24 -23
  29. package/dist/shared/components/panels/RecordIntegrityBanner.js +1 -1
  30. package/dist/shared/components/pipeline/TeamSuggestions.js +1 -1
  31. package/dist/shared/components/queue/QueueItemSheet.js +171 -130
  32. package/dist/shared/components/record-grid-guard.js +85 -0
  33. package/dist/shared/components/support/TicketDetailSheet.js +168 -151
  34. package/dist/shared/lib/at-risk-fields.js +14 -0
  35. package/dist/shared/lib/live-queries.js +9 -8
  36. package/dist/shared/lib/live-screen.js +77 -76
  37. package/dist/shared/lib/presence-hooks.js +190 -127
  38. package/dist/shared/lib/user-sync.js +78 -65
  39. package/dist/shared/lib/waiting-count.js +40 -29
  40. package/package.json +1 -1
@@ -1,199 +1,262 @@
1
- import { useQuery as k } from "@tanstack/react-query";
2
- import { useState as C, useEffect as S, useCallback as O, useMemo as j, useRef as R } from "react";
3
- import { useOptionalNivaroClient as I } from "../context.js";
4
- import { post as L, get as _ } from "./commands.js";
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";
3
+ import { useOptionalNivaroClient as q } from "../context.js";
4
+ import { post as $, get as B } from "./commands.js";
5
+ import { trackActivity as N, onIdleChange as W, idleState as z } from "./idle.js";
5
6
  import { useLiveEvent as E } from "./live.js";
6
- import { useMyUserId as T, useRecordSignalPeers as q, useRecordSignalWhile as K } from "./presence-signals.js";
7
- import { useOptionalRealtime as A, useRealtimeStatus as F } from "./realtime.js";
8
- function P(i, c) {
9
- const e = F(), s = R(!1), r = R(i);
10
- r.current = i, S(() => {
11
- c && ((e == null ? void 0 : e.state) === "reconnecting" ? s.current = !0 : s.current && (s.current = !1, r.current()));
12
- }, [e == null ? void 0 : e.state, c]);
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";
9
+ let O = null, I = !1;
10
+ const T = /* @__PURE__ */ new Set();
11
+ function L() {
12
+ return typeof document > "u" ? !1 : z().is_idle;
13
13
  }
14
- function G(i, c) {
15
- const e = A(), s = T(), r = c == null ? "" : String(c), t = !!e && !!i && !!r && r !== "new", [l, g] = C([]), v = O(() => {
16
- t && (e == null || e.emit("record:join", { collection: i, item: r }));
17
- }, [e, i, r, t]);
18
- return S(() => {
19
- if (g([]), !!t)
20
- return v(), () => e == null ? void 0 : e.emit("record:leave", { collection: i, item: r });
21
- }, [e, i, r, t, v]), P(v, t), E(
14
+ function D() {
15
+ if (I || typeof document > "u") return;
16
+ 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;
21
+ for (const e of T)
22
+ try {
23
+ e(r);
24
+ } catch {
25
+ }
26
+ }
27
+ };
28
+ document.addEventListener("visibilitychange", n), W(n);
29
+ }
30
+ function K() {
31
+ return D(), O != null;
32
+ }
33
+ function H(n) {
34
+ return D(), T.add(n), () => T.delete(n);
35
+ }
36
+ function _(n, r, e = Date.now()) {
37
+ return K() ? {
38
+ collection: n,
39
+ item: String(r),
40
+ hidden: !0,
41
+ hidden_ms: Math.max(0, e - (O ?? e))
42
+ } : { collection: n, item: String(r), hidden: !1 };
43
+ }
44
+ function J(n, r) {
45
+ const e = r ? String(r).toUpperCase() : null, i = /* @__PURE__ */ new Set(), s = [];
46
+ for (const t of n ?? []) {
47
+ if (!t || t.id == null) continue;
48
+ const u = String(t.id).toUpperCase();
49
+ u === e || i.has(u) || (i.add(u), s.push(t));
50
+ }
51
+ return s;
52
+ }
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]);
58
+ }
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]);
63
+ return v(() => {
64
+ if (w([]), !t) return;
65
+ h();
66
+ const l = H(() => {
67
+ n && (e == null || e.emit("record:visibility", _(n, s)));
68
+ });
69
+ return () => {
70
+ l(), e == null || e.emit("record:leave", { collection: n, item: s });
71
+ };
72
+ }, [e, n, s, t, h]), V(h, t), E(
22
73
  "record:viewers",
23
- (u) => {
24
- Array.isArray(u == null ? void 0 : u.viewers) && g(u.viewers);
74
+ (l) => {
75
+ Array.isArray(l == null ? void 0 : l.viewers) && w(l.viewers);
25
76
  },
26
77
  {
27
78
  enabled: t,
28
79
  includeOwn: !0,
29
80
  // An older server names no record: accept, as the hosts' own hooks do.
30
- match: (u) => (u == null ? void 0 : u.collection) == null || (u == null ? void 0 : u.item) == null ? !0 : u.collection === i && String(u.item) === r
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
31
82
  }
32
- ), { viewers: j(
33
- () => l.filter((u) => !s || String(u.id).toUpperCase() !== s.toUpperCase()),
34
- [l, s]
35
- ) };
83
+ ), { viewers: j(() => J(u, i), [u, i]) };
36
84
  }
37
- function H(i, c, e = {}) {
38
- const s = A(), r = T(), t = c == null ? "" : String(c), l = !!s && !!i && !!t && t !== "new", [g, v] = C({});
39
- S(() => v({}), [i, t]), E(
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(
40
88
  "field:editing",
41
89
  (o) => {
42
- typeof (o == null ? void 0 : o.field) == "string" && v((b) => {
43
- const y = { ...b }, d = o.user;
44
- return d && (!r || String(d.id).toUpperCase() !== r.toUpperCase()) ? y[o.field] = d : delete y[o.field], y;
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;
45
93
  });
46
94
  },
47
95
  {
48
- enabled: l,
96
+ enabled: u,
49
97
  includeOwn: !0,
50
- match: (o) => (o == null ? void 0 : o.collection) == null || (o == null ? void 0 : o.item) == null ? !0 : o.collection === i && String(o.item) === t
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
51
99
  }
52
100
  );
53
- const p = O(
101
+ const S = R(
54
102
  (o) => {
55
- l && o && (s == null || s.emit("field:focus", { field: o, collection: i, item: t }));
103
+ u && o && (i == null || i.emit("field:focus", { field: o, collection: n, item: t }));
56
104
  },
57
- [s, i, t, l]
58
- ), u = O(
105
+ [i, n, t, u]
106
+ ), l = R(
59
107
  (o) => {
60
- l && o && (s == null || s.emit("field:blur", { field: o, collection: i, item: t }));
108
+ u && o && (i == null || i.emit("field:blur", { field: o, collection: n, item: t }));
61
109
  },
62
- [s, i, t, l]
110
+ [i, n, t, u]
63
111
  );
64
- return S(() => {
65
- if (!l || !e.capture || typeof document > "u") return;
66
- const o = (d) => {
67
- var n, w, a;
68
- return (a = (w = (n = d.target) == null ? void 0 : n.closest) == null ? void 0 : w.call(n, "[data-field]")) == null ? void 0 : a.getAttribute("data-field");
69
- }, b = (d) => {
70
- const n = o(d);
71
- n && p(n);
72
- }, y = (d) => {
73
- const n = o(d);
74
- n && u(n);
112
+ return v(() => {
113
+ 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);
119
+ c && S(c);
120
+ }, p = (m) => {
121
+ const c = o(m);
122
+ c && l(c);
75
123
  };
76
- return document.addEventListener("focusin", b), document.addEventListener("focusout", y), () => {
77
- document.removeEventListener("focusin", b), document.removeEventListener("focusout", y);
124
+ return document.addEventListener("focusin", b), document.addEventListener("focusout", p), () => {
125
+ document.removeEventListener("focusin", b), document.removeEventListener("focusout", p);
78
126
  };
79
- }, [l, e.capture, p, u]), { editing: g, focus: p, blur: u };
127
+ }, [u, e.capture, S, l]), { editing: w, focus: S, blur: l };
80
128
  }
81
- function J(i, c) {
82
- const e = q(i, c, "note"), [s, r] = C(!1);
83
- K(i, c, "note", s);
84
- const t = R(null), l = O((g) => {
85
- t.current && clearTimeout(t.current), t.current = null, r(g), g && (t.current = setTimeout(() => r(!1), 6e3));
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));
86
134
  }, []);
87
- return S(
135
+ return v(
88
136
  () => () => {
89
137
  t.current && clearTimeout(t.current);
90
138
  },
91
139
  []
92
- ), { typing: e, setTyping: l };
140
+ ), { typing: e, setTyping: u };
141
+ }
142
+ const X = {};
143
+ function k(n, r) {
144
+ return `${n}:${r}`;
93
145
  }
94
- const $ = {};
95
- function x(i, c) {
96
- return `${i}:${c}`;
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]) => [
151
+ k(e, s),
152
+ i(t)
153
+ ]) : r.item == null ? [] : [[k(e, String(r.item)), i(r.user_ids)]];
97
154
  }
98
- function B(i) {
99
- const c = I(), e = [...new Set(i.map((r) => r.toUpperCase()))].sort().join(","), { data: s } = k({
155
+ function ee(n) {
156
+ const r = q(), e = [...new Set(n.map((s) => s.toUpperCase()))].sort().join(","), { data: i } = F({
100
157
  queryKey: ["presence-visible-people", e],
101
- queryFn: () => c.request(
102
- _(`/presence/people?ids=${encodeURIComponent(e.split(",").slice(0, 100).join(","))}`)
103
- ).then((r) => new Set((r.data ?? []).map((t) => String(t.user_id).toUpperCase()))).catch(() => /* @__PURE__ */ new Set()),
104
- enabled: !!c && e.length > 0,
158
+ queryFn: () => r.request(
159
+ B(`/presence/people?ids=${encodeURIComponent(e.split(",").slice(0, 100).join(","))}`)
160
+ ).then((s) => new Set((s.data ?? []).map((t) => String(t.user_id).toUpperCase()))).catch(() => /* @__PURE__ */ new Set()),
161
+ enabled: !!r && e.length > 0,
105
162
  staleTime: 5 * 6e4
106
163
  });
107
- return e.length === 0 ? null : s ?? null;
164
+ return e.length === 0 ? null : i ?? null;
108
165
  }
109
- function U(i) {
110
- const c = /* @__PURE__ */ new Map();
111
- for (const s of i) {
112
- const r = s.indexOf(":");
113
- if (r <= 0) continue;
114
- const t = s.slice(0, r), l = c.get(t) ?? [];
115
- l.push(s.slice(r + 1)), c.set(t, l);
166
+ function U(n) {
167
+ const r = /* @__PURE__ */ new Map();
168
+ for (const i of n) {
169
+ const s = i.indexOf(":");
170
+ 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);
116
173
  }
117
174
  const e = [];
118
- for (const [s, r] of c)
119
- for (let t = 0; t < r.length; t += 100)
120
- e.push({ collection: s, items: r.slice(t, t + 100) });
175
+ for (const [i, s] of r)
176
+ for (let t = 0; t < s.length; t += 100)
177
+ e.push({ collection: i, items: s.slice(t, t + 100) });
121
178
  return e;
122
179
  }
123
- function X(i, c = {}) {
124
- const e = A(), s = I(), r = T(), t = c.enabled !== !1 && i.length > 0, l = i.filter((n) => n.collection && n.item != null).map((n) => x(n.collection, n.item)).join(""), [g, v] = C({}), [p, u] = C({}), o = R(/* @__PURE__ */ new Set()), b = O(() => {
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(() => {
125
182
  if (!(!e || !t))
126
- for (const n of U(o.current)) e.emit("presence:watch", n);
183
+ for (const c of U(o.current)) e.emit("presence:watch", c);
127
184
  }, [e, t]);
128
- S(() => {
185
+ v(() => {
129
186
  if (!e || !t) return;
130
- const n = new Set(l.split("").filter(Boolean)), w = [...n].filter((f) => !o.current.has(f)), a = [...o.current].filter((f) => !n.has(f));
131
- o.current = n;
132
- for (const f of U(w)) e.emit("presence:watch", f);
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);
133
190
  if (a.length) {
134
191
  for (const f of U(a)) e.emit("presence:unwatch", f);
135
- v((f) => {
136
- const m = { ...f };
137
- for (const h of a) delete m[h];
138
- return m;
192
+ h((f) => {
193
+ const y = { ...f };
194
+ for (const d of a) delete y[d];
195
+ return y;
139
196
  });
140
197
  }
141
- }, [e, l, t]), S(() => {
198
+ }, [e, u, t]), v(() => {
142
199
  if (e)
143
200
  return () => {
144
- o.current.size && e.emit("presence:unwatch", {}), o.current = /* @__PURE__ */ new Set(), v({});
201
+ o.current.size && e.emit("presence:unwatch", {}), o.current = /* @__PURE__ */ new Set(), h({});
145
202
  };
146
- }, [e]), P(b, !!e && t), E(
203
+ }, [e]), V(b, !!e && t), E(
147
204
  "presence:rows",
148
- (n) => {
149
- if (!(n != null && n.collection) || (n == null ? void 0 : n.item) == null) return;
150
- const w = x(String(n.collection), String(n.item)), a = (Array.isArray(n.user_ids) ? n.user_ids : []).map(String);
151
- v((f) => {
152
- const m = { ...f };
153
- return a.length ? m[w] = a : delete m[w], m;
205
+ (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;
154
212
  });
155
213
  },
156
214
  { enabled: !!e && t, includeOwn: !0 }
157
- ), S(() => {
158
- if (e || !s || !t) return;
159
- const n = c.pollMs ?? 3e4, w = l.split("").filter(Boolean).slice(0, 100).map((h) => {
160
- const M = h.indexOf(":");
161
- return { collection: h.slice(0, M), item_id: h.slice(M + 1) };
215
+ ), v(() => {
216
+ 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) };
162
220
  });
163
221
  let a = !0;
164
222
  const f = () => {
165
- s.request(L("/presence/record-viewers", { pairs: w })).then((h) => {
166
- a && u(h.data ?? {});
223
+ i.request($("/presence/record-viewers", { pairs: g })).then((d) => {
224
+ a && l(d.data ?? {});
167
225
  }).catch(() => {
168
226
  });
169
227
  };
170
228
  f();
171
- const m = n > 0 ? setInterval(f, n) : null;
229
+ const y = c > 0 ? setInterval(f, c) : null;
172
230
  return () => {
173
- a = !1, m && clearInterval(m);
231
+ a = !1, y && clearInterval(y);
174
232
  };
175
- }, [e, s, l, t, c.pollMs]);
176
- const y = j(() => [...new Set(Object.values(g).flat())], [g]), d = B(y);
233
+ }, [e, i, u, t, r.pollMs]);
234
+ const p = j(() => [...new Set(Object.values(w).flat())], [w]), m = ee(p);
177
235
  return j(() => {
178
- if (!t) return $;
179
- const n = {}, w = r == null ? void 0 : r.toUpperCase();
236
+ if (!t) return X;
237
+ const c = {}, g = s == null ? void 0 : s.toUpperCase();
180
238
  if (e)
181
- for (const [a, f] of Object.entries(g)) {
182
- const m = f.filter((h) => h.toUpperCase() !== w);
183
- m.length !== 0 && (n[a] = {
184
- ids: d ? m.filter((h) => d.has(h.toUpperCase())) : [],
185
- count: m.length
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
186
244
  });
187
245
  }
188
246
  else
189
- for (const [a, f] of Object.entries(p)) f > 1 && (n[a] = { ids: [], count: f - 1 });
190
- return n;
191
- }, [t, e, g, p, d, r]);
247
+ for (const [a, f] of Object.entries(S)) f > 0 && (c[a] = { ids: [], count: f });
248
+ return c;
249
+ }, [t, e, w, S, m, s]);
192
250
  }
193
251
  export {
194
- x as rowPresenceKey,
195
- H as useFieldFocus,
196
- G as usePresence,
197
- X as useRowPresence,
198
- J as useTyping
252
+ J as distinctOtherViewers,
253
+ H as onRecordTabAway,
254
+ K as recordTabAway,
255
+ _ as recordVisibilityPayload,
256
+ k as rowPresenceKey,
257
+ Z as rowPresenceUpdates,
258
+ fe as useFieldFocus,
259
+ le as usePresence,
260
+ de as useRowPresence,
261
+ ae as useTyping
199
262
  };
@@ -1,41 +1,41 @@
1
- import { useQueryClient as g } from "@tanstack/react-query";
2
- import { useRef as f, useEffect as y } from "react";
3
- import { useLiveEvent as u } from "./live.js";
4
- import { forgetSettledReads as w } from "./request-gate.js";
5
- const S = "nvr-prefs";
6
- let c = null;
7
- function p(n) {
1
+ import { useQueryClient as w } from "@tanstack/react-query";
2
+ import { useRef as v, useEffect as y } from "react";
3
+ import { useLiveEvent as a } from "./live.js";
4
+ import { forgetSettledReads as S } from "./request-gate.js";
5
+ const E = "nvr-prefs";
6
+ let o = null;
7
+ function g(t) {
8
8
  if (typeof BroadcastChannel > "u") return null;
9
- if (!c)
9
+ if (!o)
10
10
  try {
11
- c = new BroadcastChannel(`${S}:${n}`);
11
+ o = new BroadcastChannel(`${E}:${t}`);
12
12
  } catch {
13
- c = null;
13
+ o = null;
14
14
  }
15
- return c;
15
+ return o;
16
16
  }
17
- let d = "";
18
- function k(n) {
19
- if (n !== d) {
20
- d = n;
17
+ let f = "";
18
+ function k(t) {
19
+ if (t !== f) {
20
+ f = t;
21
21
  try {
22
- c == null || c.close();
22
+ o == null || o.close();
23
23
  } catch {
24
24
  }
25
- c = null;
25
+ o = null;
26
26
  }
27
27
  }
28
28
  function q() {
29
- return d.endsWith(":as");
29
+ return f.endsWith(":as");
30
30
  }
31
- function L(n = []) {
32
- var t;
31
+ function L(t = []) {
32
+ var n;
33
33
  try {
34
- (t = p(d)) == null || t.postMessage({ keys: n });
34
+ (n = g(f)) == null || n.postMessage({ keys: t });
35
35
  } catch {
36
36
  }
37
37
  }
38
- const E = /* @__PURE__ */ new Set([
38
+ const b = /* @__PURE__ */ new Set([
39
39
  "users",
40
40
  "people-search",
41
41
  "people-cards",
@@ -52,7 +52,7 @@ const E = /* @__PURE__ */ new Set([
52
52
  "users-list-for-approvals",
53
53
  "presence-visible-people",
54
54
  "team-members"
55
- ]), b = /* @__PURE__ */ new Set([
55
+ ]), M = /* @__PURE__ */ new Set([
56
56
  "user-card",
57
57
  "user-avatar",
58
58
  "user-name",
@@ -60,21 +60,28 @@ const E = /* @__PURE__ */ new Set([
60
60
  "user",
61
61
  "activity-chip-user",
62
62
  "nvr-directory-entry",
63
- "nvr-profile-card"
63
+ "nvr-profile-card",
64
+ // The people page header (ProfileView; Low shared 3): keyed by id, or 'me' + the row read.
65
+ "nvr-profile-user"
64
66
  ]);
65
- function C(n, t) {
66
- const i = n[0];
67
- if (typeof i != "string") return !1;
68
- if (E.has(i)) return !0;
69
- if (!b.has(i)) return !1;
70
- if (!t) return !0;
71
- const o = n[1];
72
- return (typeof o == "string" || typeof o == "number") && t.has(String(o).toUpperCase());
67
+ function C(t, n, i) {
68
+ const u = t[0];
69
+ if (typeof u != "string") return !1;
70
+ if (b.has(u)) return !0;
71
+ if (!M.has(u)) return !1;
72
+ if (!n) return !0;
73
+ let c = t[1];
74
+ return c === "me" && (c = i == null ? void 0 : i.id), (typeof c == "string" || typeof c == "number") && n.has(String(c).toUpperCase());
73
75
  }
74
- function m(n, t = 1200) {
75
- setTimeout(n, Math.floor(Math.random() * t));
76
+ function m(t, n = 1200) {
77
+ setTimeout(t, Math.floor(Math.random() * n));
76
78
  }
77
- const M = [["notification-count"], ["notifications"], ["my-work"]], T = [["nvr-chat-rooms"], ["nvr-chat-record-room"]], K = {
79
+ const p = [
80
+ ["notification-count"],
81
+ ["notifications"],
82
+ ["my-work"],
83
+ ["my-work-count"]
84
+ ], K = [["nvr-chat-rooms"], ["nvr-chat-record-room"]], T = {
78
85
  "saved-views": [["cbv-views"], ["cbv-view-count"]],
79
86
  "saved-searches": [["global-search-saved"]],
80
87
  overview: [
@@ -82,57 +89,63 @@ const M = [["notification-count"], ["notifications"], ["my-work"]], T = [["nvr-c
82
89
  ["overview", "pinned-widgets"]
83
90
  ]
84
91
  };
85
- function P(n = {}) {
86
- const t = g(), i = f(n.onPrefsChanged);
87
- i.current = n.onPrefsChanged, u(
92
+ function P(t = {}) {
93
+ const n = w(), i = v(t.onPrefsChanged);
94
+ i.current = t.onPrefsChanged, a(
95
+ "notification:retired",
96
+ () => {
97
+ for (const e of p) n.invalidateQueries({ queryKey: e });
98
+ },
99
+ { includeOwn: !0, debounceMs: 1e3 }
100
+ ), a(
88
101
  "read:changed",
89
102
  (e) => {
90
- const r = (e == null ? void 0 : e.kind) === "chat" ? T : M;
91
- for (const s of r) t.invalidateQueries({ queryKey: s });
103
+ const r = (e == null ? void 0 : e.kind) === "chat" ? K : p;
104
+ for (const s of r) n.invalidateQueries({ queryKey: s });
92
105
  },
93
106
  // Counts: a burst of reads (mark-all) is one re-read, not one per event.
94
107
  { includeOwn: !0, debounceMs: 2e3 }
95
108
  );
96
- const o = f(() => {
109
+ const u = v(() => {
97
110
  });
98
- o.current = () => {
111
+ u.current = () => {
99
112
  var e;
100
- t.invalidateQueries({ queryKey: ["nvr-profile-prefs"] }), t.invalidateQueries({ queryKey: ["presence-online"] }), t.invalidateQueries({ queryKey: ["nvr-nav-favorites"] }), (e = i.current) == null || e.call(i);
101
- }, u(
113
+ n.invalidateQueries({ queryKey: ["nvr-profile-prefs"] }), n.invalidateQueries({ queryKey: ["presence-online"] }), n.invalidateQueries({ queryKey: ["nvr-nav-favorites"] }), (e = i.current) == null || e.call(i);
114
+ }, a(
102
115
  "prefs:changed",
103
116
  (e) => {
104
117
  const r = Array.isArray(e == null ? void 0 : e.keys) ? e.keys : null;
105
- r && r.length > 0 && r.every((s) => s === "watch_list") || o.current();
118
+ r && r.length > 0 && r.every((s) => s === "watch_list") || u.current();
106
119
  },
107
120
  { includeOwn: !0, debounceMs: 250 }
108
- ), u(
121
+ ), a(
109
122
  "mine:changed",
110
123
  (e) => {
111
- for (const r of K[String(e == null ? void 0 : e.kind)] ?? [])
112
- t.invalidateQueries({ queryKey: r, refetchType: "active" });
124
+ for (const r of T[String(e == null ? void 0 : e.kind)] ?? [])
125
+ n.invalidateQueries({ queryKey: r, refetchType: "active" });
113
126
  },
114
127
  { includeOwn: !0, debounceMs: 300 }
115
- ), u(
128
+ ), a(
116
129
  "pins:changed",
117
- () => m(() => void t.invalidateQueries({ queryKey: ["collection-pins"] })),
130
+ () => m(() => void n.invalidateQueries({ queryKey: ["collection-pins"] })),
118
131
  { includeOwn: !0, debounceMs: 500 }
119
132
  );
120
- const v = f(n.onAccessChanged);
121
- v.current = n.onAccessChanged, u(
133
+ const c = v(t.onAccessChanged);
134
+ c.current = t.onAccessChanged, a(
122
135
  "access:changed",
123
136
  (e) => {
124
137
  e != null && e.perms && m(() => {
125
138
  var r;
126
- w(), (r = v.current ?? i.current) == null || r(), t.invalidateQueries({ refetchType: "active" });
139
+ S(), (r = c.current ?? i.current) == null || r(), n.invalidateQueries({ refetchType: "active" });
127
140
  });
128
141
  },
129
142
  { includeOwn: !0, debounceMs: 400 }
130
143
  );
131
- const a = f(null);
132
- u(
144
+ const d = v(null);
145
+ a(
133
146
  "people:changed",
134
147
  (e) => {
135
- const r = Array.isArray(e == null ? void 0 : e.user_ids) ? e.user_ids.map((l) => String(l).toUpperCase()) : null, s = a.current;
148
+ const r = Array.isArray(e == null ? void 0 : e.user_ids) ? e.user_ids.map((l) => String(l).toUpperCase()) : null, s = d.current;
136
149
  if (s) {
137
150
  if (!r) s.ids = null;
138
151
  else if (s.ids) for (const l of r) s.ids.add(l);
@@ -142,28 +155,28 @@ function P(n = {}) {
142
155
  ids: r ? new Set(r) : null,
143
156
  timer: setTimeout(
144
157
  () => {
145
- a.current = null, t.invalidateQueries({
158
+ d.current = null, n.invalidateQueries({
146
159
  refetchType: "active",
147
- predicate: (l) => C(l.queryKey, h.ids)
160
+ predicate: (l) => C(l.queryKey, h.ids, l.state.data)
148
161
  });
149
162
  },
150
163
  300 + Math.floor(Math.random() * 800)
151
164
  )
152
165
  };
153
- a.current = h;
166
+ d.current = h;
154
167
  },
155
168
  { includeOwn: !0 }
156
169
  ), y(
157
170
  () => () => {
158
- a.current && clearTimeout(a.current.timer);
171
+ d.current && clearTimeout(d.current.timer);
159
172
  },
160
173
  []
161
174
  ), y(() => {
162
- const e = p(d);
175
+ const e = g(f);
163
176
  if (!e) return;
164
177
  let r = null;
165
178
  const s = () => {
166
- r && clearTimeout(r), r = setTimeout(() => o.current(), 100);
179
+ r && clearTimeout(r), r = setTimeout(() => u.current(), 100);
167
180
  };
168
181
  return e.addEventListener("message", s), () => {
169
182
  e.removeEventListener("message", s), r && clearTimeout(r);
@@ -171,9 +184,9 @@ function P(n = {}) {
171
184
  }, []);
172
185
  }
173
186
  export {
174
- K as MINE_KEYS,
175
- E as PEOPLE_LIST_KEYS,
176
- b as PERSON_KEYS,
187
+ T as MINE_KEYS,
188
+ b as PEOPLE_LIST_KEYS,
189
+ M as PERSON_KEYS,
177
190
  L as announceLocalPrefs,
178
191
  k as configureUserSync,
179
192
  C as peopleQueryMatches,