@nivaro/react 0.3.8 → 0.3.10

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 (60) hide show
  1. package/dist/components/fields/FileField.js +20 -19
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/replayUploadQueue.js +107 -93
  4. package/dist/hooks/useNivaroForm.js +129 -126
  5. package/dist/hooks/useSessionRecorder.js +103 -101
  6. package/dist/index.d.ts +115 -2
  7. package/dist/index.js +466 -447
  8. package/dist/shared/components/CollectionBrowserView.js +1058 -1059
  9. package/dist/shared/components/ConformanceView.js +36 -35
  10. package/dist/shared/components/DataTable.js +230 -223
  11. package/dist/shared/components/ForceReloadBanner.js +58 -34
  12. package/dist/shared/components/ItemEditForm.js +3687 -3580
  13. package/dist/shared/components/JsonMapEditor.js +18 -17
  14. package/dist/shared/components/MatrixEditor.js +8 -7
  15. package/dist/shared/components/MyWorkView.js +32 -31
  16. package/dist/shared/components/PageRenderer.js +146 -145
  17. package/dist/shared/components/QueryTable.js +49 -49
  18. package/dist/shared/components/RecordGridEditor.js +76 -75
  19. package/dist/shared/components/ai/AiMemorySuggestions.js +15 -14
  20. package/dist/shared/components/ai/AskPanel.js +55 -54
  21. package/dist/shared/components/bulk/BulkActionButtons.js +30 -29
  22. package/dist/shared/components/bulk/PushBulkButtons.js +57 -56
  23. package/dist/shared/components/chat/ChatPanel.js +288 -287
  24. package/dist/shared/components/chat/SlashCommands.js +30 -29
  25. package/dist/shared/components/chat/chat-outbox.js +76 -75
  26. package/dist/shared/components/help-videos/recorder/useLeaveWarning.js +6 -5
  27. package/dist/shared/components/integrations/console/SignalCard.js +124 -123
  28. package/dist/shared/components/integrations/console/SnoozeMenu.js +24 -23
  29. package/dist/shared/components/item-edit/CloneDialog.js +85 -78
  30. package/dist/shared/components/item-edit/InlineTableField.js +301 -300
  31. package/dist/shared/components/item-edit/MembershipSetField.js +24 -23
  32. package/dist/shared/components/item-edit/QuickCreateButton.js +8 -7
  33. package/dist/shared/components/item-edit/RecordLiveSync.js +101 -100
  34. package/dist/shared/components/item-edit/staged-links.js +86 -0
  35. package/dist/shared/components/layout-editor/LayoutEditor.js +275 -274
  36. package/dist/shared/components/layout-editor/editors/cascade-rule-row.js +18 -17
  37. package/dist/shared/components/layout-editor/inspector/HelpTab.js +37 -36
  38. package/dist/shared/components/layout-editor/matrix/FieldStateMatrix.js +50 -49
  39. package/dist/shared/components/panels/CommentPanel.js +237 -236
  40. package/dist/shared/components/profile/AiMemoryCard.js +15 -14
  41. package/dist/shared/components/profile/PersonAdminTools.js +70 -67
  42. package/dist/shared/components/profile/usePersonPresence.js +42 -37
  43. package/dist/shared/components/queue/QueueItemSheet.js +36 -35
  44. package/dist/shared/components/queue/QueueWorklist.js +597 -598
  45. package/dist/shared/lib/client-version.js +63 -0
  46. package/dist/shared/lib/force-reload.js +36 -0
  47. package/dist/shared/lib/load-error.js +11 -10
  48. package/dist/shared/lib/presence-live.js +73 -0
  49. package/dist/shared/lib/presence-state.js +39 -31
  50. package/dist/shared/lib/record-outbox.js +76 -75
  51. package/dist/shared/lib/request-gate.js +120 -102
  52. package/dist/shared/lib/rum.js +45 -36
  53. package/dist/shared/lib/safe-error.js +39 -0
  54. package/dist/shared/lib/server-clock.js +11 -7
  55. package/dist/shared/lib/signed-out.js +114 -0
  56. package/dist/shared/lib/socket-realtime.js +19 -17
  57. package/dist/shared/lib/unsaved-work.js +62 -0
  58. package/dist/shared/lib/use-online-users.js +11 -10
  59. package/dist/shared/lib/worker-socket.js +89 -79
  60. package/package.json +1 -1
@@ -5,28 +5,29 @@ import { useState as c } from "react";
5
5
  import { toast as K } from "sonner";
6
6
  import { useNivaroClient as W } from "../../context.js";
7
7
  import { get as ne, post as k } from "../../lib/commands.js";
8
- import { cn as x } from "../../lib/utils.js";
9
8
  import { invalidateRecordTasks as se } from "../../lib/record-tasks.js";
10
- import { useChatConfig as le, useUserSearch as ie } from "./chat-core.js";
11
- import { useRoomRecord as ce } from "./chat-hooks.js";
12
- const me = [
9
+ import { userErrorMessage as le } from "../../lib/safe-error.js";
10
+ import { cn as x } from "../../lib/utils.js";
11
+ import { useChatConfig as ie, useUserSearch as ce } from "./chat-core.js";
12
+ import { useRoomRecord as me } from "./chat-hooks.js";
13
+ const ue = [
13
14
  { name: "task", description: "Create a task on this record or for a person", builtin: !0 },
14
15
  { name: "remind", description: "Remind yourself about something", builtin: !0 },
15
16
  { name: "poll", description: "Ask the room a question with options", builtin: !0 },
16
17
  { name: "note", description: "Add a note to this room’s record", builtin: !0 }
17
18
  ];
18
- function ye(t, n) {
19
+ function Ce(t, n) {
19
20
  const m = t.slice(0, n).match(/^\/([a-z0-9-]{0,23})$/i);
20
21
  return m ? m[1].toLowerCase() : null;
21
22
  }
22
- function ke(t) {
23
+ function Se(t) {
23
24
  const n = t.match(/^\/([a-z][a-z0-9-]{1,23})(?:\s+([\s\S]*))?$/i);
24
25
  return n ? { name: n[1].toLowerCase(), args: (n[2] ?? "").trim() } : null;
25
26
  }
26
- function Ce(t, n) {
27
+ function De(t, n) {
27
28
  return t.filter((l) => l.name.startsWith(n.toLowerCase())).sort((l, m) => Number(m.builtin) - Number(l.builtin) || l.name.localeCompare(m.name));
28
29
  }
29
- function Se() {
30
+ function Ae() {
30
31
  const t = W(), { data: n } = ee({
31
32
  queryKey: ["nvr-chat-commands"],
32
33
  queryFn: () => t.request(
@@ -34,9 +35,9 @@ function Se() {
34
35
  ).then((l) => l.data ?? []).catch(() => []),
35
36
  staleTime: 5 * 6e4
36
37
  });
37
- return [...me, ...(n ?? []).map((l) => ({ ...l, builtin: !1 }))];
38
+ return [...ue, ...(n ?? []).map((l) => ({ ...l, builtin: !1 }))];
38
39
  }
39
- function De({
40
+ function qe({
40
41
  entries: t,
41
42
  index: n,
42
43
  onPick: l,
@@ -72,7 +73,7 @@ function C(t) {
72
73
  function P(t) {
73
74
  return `${t.getFullYear()}-${C(t.getMonth() + 1)}-${C(t.getDate())}T${C(t.getHours())}:${C(t.getMinutes())}`;
74
75
  }
75
- function Ae({
76
+ function Re({
76
77
  kind: t,
77
78
  room: n,
78
79
  initialText: l,
@@ -80,16 +81,16 @@ function Ae({
80
81
  onClose: h,
81
82
  th: v
82
83
  }) {
83
- const b = W(), S = te(), N = le(), r = ce(n, t === "task" || t === "note"), [i, F] = c(l), [M, B] = c(!0), [d, L] = c(
84
+ const b = W(), S = te(), N = ie(), r = me(n, t === "task" || t === "note"), [i, F] = c(l), [M, B] = c(!0), [u, L] = c(
84
85
  N.me ? { id: N.me.id, name: "Me" } : null
85
- ), [g, D] = c(""), [A, H] = c(""), U = ie(g, t === "task" && g.trim().length >= 2), [_, j] = c(() => P(new Date(Date.now() + 60 * 6e4))), [y, q] = c(["", ""]), [O, G] = c(!1), [I, X] = c(!1), [R, Y] = c(""), J = (e) => {
86
+ ), [g, D] = c(""), [A, H] = c(""), U = ce(g, t === "task" && g.trim().length >= 2), [_, j] = c(() => P(new Date(Date.now() + 60 * 6e4))), [y, q] = c(["", ""]), [O, G] = c(!1), [I, X] = c(!1), [R, Y] = c(""), J = (e) => {
86
87
  K.success(e), h();
87
88
  }, V = (e, s) => {
88
- var u;
89
- return K.error(((u = e == null ? void 0 : e.response) == null ? void 0 : u.error) ?? s);
89
+ var d;
90
+ return K.error(((d = e == null ? void 0 : e.response) == null ? void 0 : d.error) ?? s);
90
91
  }, $ = ae({
91
92
  mutationFn: async () => {
92
- var s, u;
93
+ var s, d;
93
94
  if (t === "task") {
94
95
  if (!i.trim()) throw new Error("A task needs a title");
95
96
  const p = M && !!r;
@@ -97,10 +98,10 @@ function Ae({
97
98
  k("/tasks", {
98
99
  ...p ? { collection: r == null ? void 0 : r.collection, item: String(r == null ? void 0 : r.id) } : {},
99
100
  title: i.trim().slice(0, 200),
100
- assignee: (d == null ? void 0 : d.id) ?? ((s = N.me) == null ? void 0 : s.id),
101
+ assignee: (u == null ? void 0 : u.id) ?? ((s = N.me) == null ? void 0 : s.id),
101
102
  ...A ? { due_date: A } : {}
102
103
  })
103
- ), p && r && se(S, r.collection, r.id), d && d.id !== ((u = N.me) == null ? void 0 : u.id) ? `Task created for ${d.name}` : "Task created";
104
+ ), p && r && se(S, r.collection, r.id), u && u.id !== ((d = N.me) == null ? void 0 : d.id) ? `Task created for ${u.name}` : "Task created";
104
105
  }
105
106
  if (t === "remind") {
106
107
  if (!i.trim()) throw new Error("Say what to remind you about");
@@ -136,7 +137,7 @@ function Ae({
136
137
  ), S.invalidateQueries({ queryKey: ["nvr-chat", n] }), "Poll posted";
137
138
  },
138
139
  onSuccess: (e) => J(e),
139
- onError: (e) => V(e, e instanceof Error ? e.message : "That did not work")
140
+ onError: (e) => V(e, le(e, "That did not work"))
140
141
  }), Z = { task: "New task", remind: "Remind me", poll: "New poll", note: "Add a note" }[t], Q = {
141
142
  task: "What needs doing?",
142
143
  remind: "Remind me to…",
@@ -211,7 +212,7 @@ function Ae({
211
212
  /* @__PURE__ */ a(
212
213
  "input",
213
214
  {
214
- value: d && !g ? d.name : g,
215
+ value: u && !g ? u.name : g,
215
216
  onFocus: () => {
216
217
  D("");
217
218
  },
@@ -234,7 +235,7 @@ function Ae({
234
235
  }
235
236
  )
236
237
  ] }),
237
- !d && g.trim().length >= 2 && /* @__PURE__ */ a("ul", { className: "max-h-24 overflow-y-auto rounded-md border border-slate-200 text-[12px] dark:border-border", children: U.users.slice(0, 6).map((e) => {
238
+ !u && g.trim().length >= 2 && /* @__PURE__ */ a("ul", { className: "max-h-24 overflow-y-auto rounded-md border border-slate-200 text-[12px] dark:border-border", children: U.users.slice(0, 6).map((e) => {
238
239
  const s = [e.first_name, e.last_name].filter(Boolean).join(" ") || e.email || "";
239
240
  return /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
240
241
  "button",
@@ -289,7 +290,7 @@ function Ae({
289
290
  "input",
290
291
  {
291
292
  value: e,
292
- onChange: (u) => q((p) => p.map((w, T) => T === s ? u.target.value : w)),
293
+ onChange: (d) => q((p) => p.map((w, T) => T === s ? d.target.value : w)),
293
294
  placeholder: `Option ${s + 1}`,
294
295
  className: f
295
296
  }
@@ -299,7 +300,7 @@ function Ae({
299
300
  {
300
301
  type: "button",
301
302
  "aria-label": "Remove option",
302
- onClick: () => q((u) => u.filter((p, w) => w !== s)),
303
+ onClick: () => q((d) => d.filter((p, w) => w !== s)),
303
304
  className: "text-slate-400 hover:text-slate-700",
304
305
  children: /* @__PURE__ */ a(z, { className: "h-3.5 w-3.5" })
305
306
  }
@@ -373,11 +374,11 @@ function Ae({
373
374
  );
374
375
  }
375
376
  export {
376
- Ae as SlashForm,
377
- De as SlashMenu,
378
- Ce as filterSlash,
379
- ke as parseSlashLine,
380
- ye as slashQuery,
377
+ Re as SlashForm,
378
+ qe as SlashMenu,
379
+ De as filterSlash,
380
+ Se as parseSlashLine,
381
+ Ce as slashQuery,
381
382
  P as toLocalInput,
382
- Se as useChatCommands
383
+ Ae as useChatCommands
383
384
  };
@@ -1,27 +1,28 @@
1
1
  import { useState as $, useEffect as T } from "react";
2
2
  import { post as F } from "../../lib/commands.js";
3
3
  import { useOptionalRealtime as Q } from "../../lib/realtime.js";
4
- const R = "nivaro-chat-outbox", v = "entries", j = "nvr-chat-outbox", J = 1440 * 60 * 1e3, P = 8e3, Y = "nvr-chat-outbox:flush";
5
- let G = !1;
4
+ import { userErrorMessage as R } from "../../lib/safe-error.js";
5
+ const j = "nivaro-chat-outbox", p = "entries", J = "nvr-chat-outbox", P = 1440 * 60 * 1e3, Y = 8e3, G = "nvr-chat-outbox:flush";
6
+ let I = !1;
6
7
  const h = /* @__PURE__ */ new Map();
7
- function I() {
8
+ function U() {
8
9
  return new Promise((e) => {
9
10
  try {
10
- if (G || typeof indexedDB > "u") return e(null);
11
- const t = indexedDB.open(R, 1);
11
+ if (I || typeof indexedDB > "u") return e(null);
12
+ const t = indexedDB.open(j, 1);
12
13
  t.onupgradeneeded = () => {
13
- t.result.objectStoreNames.contains(v) || t.result.createObjectStore(v, { keyPath: "client_id" });
14
+ t.result.objectStoreNames.contains(p) || t.result.createObjectStore(p, { keyPath: "client_id" });
14
15
  }, t.onsuccess = () => e(t.result), t.onerror = () => e(null), t.onblocked = () => e(null);
15
16
  } catch {
16
17
  e(null);
17
18
  }
18
19
  });
19
20
  }
20
- async function y(e, t) {
21
- const n = await I();
21
+ async function m(e, t) {
22
+ const n = await U();
22
23
  return n ? new Promise((i) => {
23
24
  try {
24
- const a = n.transaction(v, e), r = t(a.objectStore(v));
25
+ const a = n.transaction(p, e), r = t(a.objectStore(p));
25
26
  r.onsuccess = () => i({ ok: !0, value: r.result }), r.onerror = () => i({ ok: !1, value: null }), a.oncomplete = () => n.close(), a.onerror = () => {
26
27
  n.close(), i({ ok: !1, value: null });
27
28
  };
@@ -30,27 +31,27 @@ async function y(e, t) {
30
31
  }
31
32
  }) : { ok: !1, value: null };
32
33
  }
33
- const U = (e) => JSON.parse(JSON.stringify(e));
34
+ const X = (e) => JSON.parse(JSON.stringify(e));
34
35
  async function q(e) {
35
- h.set(e.client_id, e), await y("readwrite", (t) => t.put(U(e)));
36
+ h.set(e.client_id, e), await m("readwrite", (t) => t.put(X(e)));
36
37
  }
37
38
  async function L(e) {
38
- h.delete(e), await y("readwrite", (t) => t.delete(e));
39
+ h.delete(e), await m("readwrite", (t) => t.delete(e));
39
40
  }
40
41
  async function C(e) {
41
- const t = await y("readonly", (n) => n.get(e));
42
+ const t = await m("readonly", (n) => n.get(e));
42
43
  return t.ok ? t.value ?? null : h.get(e) ?? null;
43
44
  }
44
- async function B() {
45
- const e = await y("readonly", (t) => t.getAll());
45
+ async function M() {
46
+ const e = await m("readonly", (t) => t.getAll());
46
47
  return e.ok ? e.value ?? [] : [...h.values()];
47
48
  }
48
49
  let o = [];
49
50
  const D = /* @__PURE__ */ new Set();
50
- let p = null, s = null, l = null, M = !1, m = null, _ = !1, A = !1, f = null;
51
+ let v = null, s = null, c = null, B = !1, y = null, _ = !1, A = !1, f = null;
51
52
  const S = /* @__PURE__ */ new Set();
52
53
  let k = 0, g = !1;
53
- function X(e) {
54
+ function z(e) {
54
55
  return `${typeof location < "u" ? location.host : ""}|${e}`;
55
56
  }
56
57
  function w() {
@@ -64,9 +65,9 @@ function O() {
64
65
  }
65
66
  const E = (e, t) => e.created_at < t.created_at ? -1 : e.created_at > t.created_at ? 1 : 0;
66
67
  async function b() {
67
- if (!l || M) return;
68
- const e = l, t = await B();
69
- if (l !== e) return;
68
+ if (!c || B) return;
69
+ const e = c, t = await M();
70
+ if (c !== e) return;
70
71
  const n = t.filter((a) => (a == null ? void 0 : a.owner) === e).sort(E), i = new Set(n.map((a) => a.client_id));
71
72
  o = [
72
73
  ...n,
@@ -75,9 +76,9 @@ async function b() {
75
76
  }
76
77
  function x(e, t = Date.now()) {
77
78
  const n = new Date(e.created_at).getTime();
78
- return !Number.isFinite(n) || t - n > J;
79
+ return !Number.isFinite(n) || t - n > P;
79
80
  }
80
- function z(e, t = Date.now()) {
81
+ function H(e, t = Date.now()) {
81
82
  const n = /* @__PURE__ */ new Set();
82
83
  for (const i of [...e].sort(E))
83
84
  if (i.status !== "failed" && !n.has(i.room) && (n.add(i.room), !(i.held || x(i, t))))
@@ -93,29 +94,29 @@ async function d(e, t) {
93
94
  async function K(e) {
94
95
  o = o.filter((t) => t.client_id !== e), w(), await L(e), O();
95
96
  }
96
- function st(e, t, n) {
97
+ function lt(e, t, n) {
97
98
  var r;
98
- if (p = e, s = t, !n) return;
99
- const i = X(n);
100
- if (i === l) return;
101
- if (l = i, o = [], w(), !A && typeof window < "u" && (A = !0, window.addEventListener("online", () => u(0)), (r = document.addEventListener) == null || r.call(document, "visibilitychange", () => {
102
- document.visibilityState === "visible" && o.some((c) => c.status === "queued") && u(0);
99
+ if (v = e, s = t, !n) return;
100
+ const i = z(n);
101
+ if (i === c) return;
102
+ if (c = i, o = [], w(), !A && typeof window < "u" && (A = !0, window.addEventListener("online", () => u(0)), (r = document.addEventListener) == null || r.call(document, "visibilitychange", () => {
103
+ document.visibilityState === "visible" && o.some((l) => l.status === "queued") && u(0);
103
104
  })), typeof BroadcastChannel < "u" && !f)
104
105
  try {
105
106
  f = new BroadcastChannel("nvr-chat-outbox"), f.onmessage = () => void b();
106
107
  } catch {
107
108
  f = null;
108
109
  }
109
- const a = l;
110
+ const a = c;
110
111
  (async () => {
111
- for (const c of await B()) c && c.owner !== a && await L(c.client_id);
112
- await H(n, a), await b(), o.length && u(1e3);
112
+ for (const l of await M()) l && l.owner !== a && await L(l.client_id);
113
+ await V(n, a), await b(), o.length && u(1e3);
113
114
  })();
114
115
  }
115
- async function H(e, t) {
116
+ async function V(e, t) {
116
117
  try {
117
118
  if (typeof localStorage > "u") return;
118
- const n = `${j}:${e}`, i = localStorage.getItem(n);
119
+ const n = `${J}:${e}`, i = localStorage.getItem(n);
119
120
  if (!i) return;
120
121
  localStorage.removeItem(n);
121
122
  const a = JSON.parse(i);
@@ -124,17 +125,17 @@ async function H(e, t) {
124
125
  } catch {
125
126
  }
126
127
  }
127
- async function ut() {
128
- o = [], h.clear(), l = null, w(), await y("readwrite", (e) => e.clear()), O();
128
+ async function ct() {
129
+ o = [], h.clear(), c = null, w(), await m("readwrite", (e) => e.clear()), O();
129
130
  }
130
- function ct(e) {
131
+ function dt(e) {
131
132
  const t = typeof navigator < "u" && navigator.onLine === !1, n = g || t;
132
133
  let i = Date.parse(e.created_at) || Date.now();
133
134
  i <= k && (i = k + 1), k = i;
134
135
  const a = {
135
136
  ...e,
136
137
  created_at: new Date(i).toISOString(),
137
- owner: l ?? void 0,
138
+ owner: c ?? void 0,
138
139
  status: n ? "queued" : "sending",
139
140
  error: n ? "Waiting for a connection" : null,
140
141
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
@@ -144,50 +145,50 @@ function ct(e) {
144
145
  });
145
146
  }
146
147
  function u(e) {
147
- m && clearTimeout(m), m = setTimeout(() => {
148
- m = null, W();
148
+ y && clearTimeout(y), y = setTimeout(() => {
149
+ y = null, W();
149
150
  }, e);
150
151
  }
151
- function V() {
152
+ function Z() {
152
153
  o.some((e) => e.status === "queued" || e.status === "sending") && u(0);
153
154
  }
154
- function Z(e) {
155
+ function tt(e) {
155
156
  var i;
156
157
  const t = e, n = (t == null ? void 0 : t.status) ?? ((i = t == null ? void 0 : t.response) == null ? void 0 : i.status);
157
158
  return n == null ? !(t != null && t.response) : n === 0 || n === 502 || n === 503 || n === 504;
158
159
  }
159
- function tt() {
160
+ function et() {
160
161
  var e;
161
162
  return ((e = globalThis.navigator) == null ? void 0 : e.locks) ?? null;
162
163
  }
163
164
  async function W() {
164
- if (_ || !p) return;
165
- const e = tt();
165
+ if (_ || !v) return;
166
+ const e = et();
166
167
  if (!e) return N();
167
168
  let t = !1;
168
- await e.request(Y, { ifAvailable: !0 }, async (n) => {
169
+ await e.request(G, { ifAvailable: !0 }, async (n) => {
169
170
  n && (t = !0, await N());
170
171
  }).catch(() => {
171
172
  }), !t && o.some((n) => n.status !== "failed" && !n.held) && u(1500);
172
173
  }
173
174
  async function N() {
174
- if (_ || !p) return;
175
+ if (_ || !v) return;
175
176
  _ = !0;
176
- const e = p;
177
+ const e = v;
177
178
  try {
178
- await b(), et();
179
+ await b(), nt();
179
180
  for (let t = 0; t < 500; t++) {
180
- const n = z(o);
181
+ const n = H(o);
181
182
  if (!n) return;
182
- const i = M ? n : await C(n.client_id);
183
+ const i = B ? n : await C(n.client_id);
183
184
  if (!i || i.held || i.status === "failed") {
184
185
  i || S.delete(n.client_id), await b(), i || (o = o.filter((r) => r.client_id !== n.client_id));
185
186
  continue;
186
187
  }
187
- if (await d(i.client_id, { status: "sending", error: null }), await nt(e, i) === "offline") {
188
+ if (await d(i.client_id, { status: "sending", error: null }), await it(e, i) === "offline") {
188
189
  for (const r of o)
189
190
  r.status === "sending" && r.client_id !== i.client_id && await d(r.client_id, { status: "queued", error: "Waiting for a connection" });
190
- u(P);
191
+ u(Y);
191
192
  return;
192
193
  }
193
194
  }
@@ -195,7 +196,7 @@ async function N() {
195
196
  _ = !1;
196
197
  }
197
198
  }
198
- function et() {
199
+ function nt() {
199
200
  const e = Date.now();
200
201
  for (const t of o)
201
202
  t.status !== "failed" && !t.held && x(t, e) && d(t.client_id, {
@@ -203,7 +204,7 @@ function et() {
203
204
  error: "Not sent — it waited more than a day for a connection"
204
205
  });
205
206
  }
206
- async function nt(e, t) {
207
+ async function it(e, t) {
207
208
  try {
208
209
  const n = await e.request(
209
210
  F("/chat/messages", {
@@ -224,17 +225,17 @@ async function nt(e, t) {
224
225
  (a) => a && !a.data.some((r) => r.id === i.id) ? { ...a, data: [...a.data, i] } : a
225
226
  )), s == null || s.invalidateQueries({ queryKey: ["nvr-chat", t.room] }), s == null || s.invalidateQueries({ queryKey: ["nvr-chat-thread", t.room] }), s == null || s.invalidateQueries({ queryKey: ["nvr-chat-rooms"] }), "sent";
226
227
  } catch (n) {
227
- if (Z(n))
228
+ if (tt(n))
228
229
  return g = !0, await d(t.client_id, { status: "queued", error: "Waiting for a connection" }), "offline";
229
230
  g = !1;
230
231
  const i = n == null ? void 0 : n.response;
231
232
  return await d(t.client_id, {
232
233
  status: "failed",
233
- error: (i == null ? void 0 : i.error) ?? (n instanceof Error ? n.message : "Could not send")
234
+ error: (i == null ? void 0 : i.error) ?? R(n, "Could not send")
234
235
  }), "failed";
235
236
  }
236
237
  }
237
- function lt(e) {
238
+ function ft(e) {
238
239
  const t = o.find((n) => n.client_id === e);
239
240
  !t || t.status === "sending" || d(e, {
240
241
  status: "queued",
@@ -243,22 +244,22 @@ function lt(e) {
243
244
  created_at: x(t) ? (/* @__PURE__ */ new Date()).toISOString() : t.created_at
244
245
  }).then(() => u(0));
245
246
  }
246
- function it(e) {
247
+ function at(e) {
247
248
  const t = o.find((n) => n.client_id === e);
248
249
  !t || t.status === "sending" || K(e).then(() => u(0));
249
250
  }
250
- function dt(e, t) {
251
+ function wt(e, t) {
251
252
  const n = o.find((i) => i.client_id === e);
252
253
  return !n || n.status === "sending" ? !1 : (d(e, { held: t }).then(() => {
253
254
  t || u(0);
254
255
  }), !0);
255
256
  }
256
- function ft(e, t) {
257
+ function ht(e, t) {
257
258
  const n = o.find((a) => a.client_id === e);
258
259
  if (!n || n.status === "sending") return;
259
260
  const i = t.replace(/\s+$/, "");
260
261
  if (!i.trim() && n.attachments.length === 0) {
261
- it(e);
262
+ at(e);
262
263
  return;
263
264
  }
264
265
  d(e, {
@@ -269,7 +270,7 @@ function ft(e, t) {
269
270
  created_at: x(n) ? (/* @__PURE__ */ new Date()).toISOString() : n.created_at
270
271
  }).then(() => u(0));
271
272
  }
272
- function wt(e, t = null) {
273
+ function mt(e, t = null) {
273
274
  const [, n] = $(0), i = Q();
274
275
  return T(() => {
275
276
  const a = () => n((r) => r + 1);
@@ -280,24 +281,24 @@ function wt(e, t = null) {
280
281
  var r;
281
282
  if (!(i != null && i.onStatus)) return;
282
283
  let a = ((r = i.status) == null ? void 0 : r.call(i).state) ?? "live";
283
- return i.onStatus((c) => {
284
- c.state === "live" && a !== "live" && V(), a = c.state;
284
+ return i.onStatus((l) => {
285
+ l.state === "live" && a !== "live" && Z(), a = l.state;
285
286
  });
286
287
  }, [i]), o.filter((a) => a.room === e && (a.parent_id ?? null) === t);
287
288
  }
288
289
  export {
289
- J as OUTBOX_STALE_MS,
290
- st as bindChatOutbox,
291
- ut as clearChatOutbox,
292
- it as discardOutbox,
293
- ft as editOutbox,
294
- ct as enqueueChatOutbox,
290
+ P as OUTBOX_STALE_MS,
291
+ lt as bindChatOutbox,
292
+ ct as clearChatOutbox,
293
+ at as discardOutbox,
294
+ ht as editOutbox,
295
+ dt as enqueueChatOutbox,
295
296
  W as flushChatOutbox,
296
- dt as holdOutbox,
297
+ wt as holdOutbox,
297
298
  x as isStaleOutboxItem,
298
- z as nextToSend,
299
- V as nudgeChatOutbox,
300
- lt as retryOutbox,
299
+ H as nextToSend,
300
+ Z as nudgeChatOutbox,
301
+ ft as retryOutbox,
301
302
  u as scheduleFlush,
302
- wt as useOutbox
303
+ mt as useOutbox
303
304
  };
@@ -1,9 +1,10 @@
1
1
  import { useEffect as o } from "react";
2
- function u(n, e) {
2
+ import { useUnsavedWork as t } from "../../../lib/unsaved-work.js";
3
+ function d(n, e) {
3
4
  return n && (e === "countdown" || e === "recording" || e === "saving" || e === "remote");
4
5
  }
5
- function i(n) {
6
- o(() => {
6
+ function f(n) {
7
+ t(n, "Video recording"), o(() => {
7
8
  if (!n) return;
8
9
  const e = (r) => {
9
10
  r.preventDefault(), r.returnValue = "";
@@ -12,6 +13,6 @@ function i(n) {
12
13
  }, [n]);
13
14
  }
14
15
  export {
15
- u as leaveWarningActive,
16
- i as useLeaveWarning
16
+ d as leaveWarningActive,
17
+ f as useLeaveWarning
17
18
  };