@nivaro/react 0.3.15 → 0.3.16

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 (34) hide show
  1. package/dist/full.css +1 -1
  2. package/dist/hooks/useSessionRecorder.js +1 -1
  3. package/dist/index.d.ts +127 -6
  4. package/dist/index.js +736 -734
  5. package/dist/shared/components/CollectionBrowserView.js +2344 -2309
  6. package/dist/shared/components/ItemEditForm.js +3773 -3604
  7. package/dist/shared/components/RecordGridEditor.js +319 -282
  8. package/dist/shared/components/RecordReadView.js +202 -200
  9. package/dist/shared/components/cbv/unknown-fields.js +18 -8
  10. package/dist/shared/components/import/DocumentAutofillButton.js +148 -142
  11. package/dist/shared/components/item-edit/CatalogPickerField.js +264 -276
  12. package/dist/shared/components/item-edit/FieldRenderer.js +136 -133
  13. package/dist/shared/components/item-edit/FieldRow.js +198 -184
  14. package/dist/shared/components/item-edit/HeaderTools.js +107 -99
  15. package/dist/shared/components/item-edit/InlineTableField.js +138 -136
  16. package/dist/shared/components/item-edit/RecordLiveSync.js +1 -0
  17. package/dist/shared/components/item-edit/RelationCombobox.js +30 -23
  18. package/dist/shared/components/item-edit/SummaryPanel.js +334 -294
  19. package/dist/shared/components/item-edit/column-length.js +12 -0
  20. package/dist/shared/components/panels/AccessDeniedPanel.js +47 -37
  21. package/dist/shared/components/panels/ItemLockBanner.js +307 -285
  22. package/dist/shared/components/panels/PipelinePanel.js +486 -465
  23. package/dist/shared/components/panels/RevisionsPanel.js +210 -204
  24. package/dist/shared/components/profile/DelegationCard.js +178 -121
  25. package/dist/shared/components/profile/PersonActivity.js +152 -139
  26. package/dist/shared/components/queue/QueueWorklist.js +668 -659
  27. package/dist/shared/components/queue/transition-note.js +90 -0
  28. package/dist/shared/components/support/SupportRequestDialog.js +100 -89
  29. package/dist/shared/components/support/TicketDetailSheet.js +104 -91
  30. package/dist/shared/lib/autofill-runs.js +33 -26
  31. package/dist/shared/lib/draft-store.js +40 -24
  32. package/dist/shared/lib/live-queries.js +10 -9
  33. package/dist/shared/lib/restore-skipped.js +10 -0
  34. package/package.json +1 -1
@@ -1,197 +1,219 @@
1
- import { jsxs as f, jsx as m } from "react/jsx-runtime";
2
- import { Lock as V, LockOpen as ee } from "lucide-react";
3
- import { useState as x, useRef as Y, useCallback as w, useEffect as S } from "react";
1
+ import { jsxs as y, jsx as k } from "react/jsx-runtime";
2
+ import { QueryClientContext as Le } from "@tanstack/react-query";
3
+ import { Lock as H, LockOpen as ne } from "lucide-react";
4
+ import { useContext as Ee, useState as _, useRef as A, useCallback as w, useEffect as N } from "react";
4
5
  import { toast as u } from "sonner";
5
- import { useNivaroClient as pe, useItemEditAuth as $e } from "../../context.js";
6
- import { post as R, get as Ne, del as D } from "../../lib/commands.js";
7
- import { idleState as Se } from "../../lib/idle.js";
8
- import { useOptionalRealtime as te, updateTouches as qe } from "../../lib/realtime.js";
9
- import { announceRecordTabs as re, useRecordTabsSignal as Le } from "../../lib/record-tabs.js";
10
- import { Button as I } from "../ui/button.js";
11
- import { Popover as ae, PopoverTrigger as ne, PopoverContent as se } from "../ui/popover.js";
12
- const Re = 6e4, Ce = 2 * 6e4, Ee = 3e4;
13
- function Ae() {
14
- const [t, r] = x(
6
+ import { useNivaroClient as Re, useItemEditAuth as Ce } from "../../context.js";
7
+ import { post as C, get as Se, del as K } from "../../lib/commands.js";
8
+ import { idleState as qe } from "../../lib/idle.js";
9
+ import { useOptionalRealtime as ae, updateTouches as Ae } from "../../lib/realtime.js";
10
+ import { announceRecordTabs as se, useRecordTabsSignal as Te } from "../../lib/record-tabs.js";
11
+ import { Button as O } from "../ui/button.js";
12
+ import { Popover as oe, PopoverTrigger as ie, PopoverContent as le } from "../ui/popover.js";
13
+ const Ie = 6e4, Ye = 2 * 6e4, Oe = 3e4, De = 6e4, Me = 15e3;
14
+ function je() {
15
+ const [t, r] = _(
15
16
  () => typeof document > "u" || document.visibilityState !== "hidden"
16
17
  );
17
- return S(() => {
18
- const o = () => r(document.visibilityState !== "hidden");
19
- return document.addEventListener("visibilitychange", o), () => document.removeEventListener("visibilitychange", o);
18
+ return N(() => {
19
+ const i = () => r(document.visibilityState !== "hidden");
20
+ return document.addEventListener("visibilitychange", i), () => document.removeEventListener("visibilitychange", i);
20
21
  }, []), t;
21
22
  }
22
- function Ke(t, r, o, C = {}) {
23
- const { lazy: q = !1, active: E = !0 } = C, s = pe(), { isAdmin: N, userId: b } = $e(), [_, g] = x(null), [p, $] = x(!1), [M, A] = x(!1), [oe, ie] = x([]), [le, O] = x(null), [ce, U] = x(!1), [ue, W] = x(""), [de, F] = x(!1), [me, J] = x(!1), z = Y(null), i = Y(!1), L = Y(!1), P = Y(!1), j = Y(!1), K = Y(null), h = w(() => {
24
- z.current && (clearInterval(z.current), z.current = null);
25
- }, []), c = w(async () => {
26
- var n, a;
27
- if (!t || !r || j.current) return !1;
28
- K.current = null;
23
+ function Xe(t, r, i, S = {}) {
24
+ const { lazy: L = !1, active: T = !0 } = S, s = Re(), { isAdmin: E, userId: g } = Ce(), v = Ee(Le), [p, h] = _(null), [F, $] = _(!1), [D, J] = _(!1), [ce, ue] = _([]), [de, M] = _(null), [fe, G] = _(!1), [ke, X] = _(""), [me, P] = _(!1), [he, Z] = _(!1), j = A(null), l = A(!1), R = A(!1), Q = A(!1), V = A(0), q = A(!1), z = A(null), m = w(() => {
25
+ j.current && (clearInterval(j.current), j.current = null);
26
+ }, []), U = w(
27
+ (a) => {
28
+ var e, c;
29
+ const n = a, f = n.status ?? ((e = n.response) == null ? void 0 : e.status), o = ((c = n.response) == null ? void 0 : c.data) ?? n.response;
30
+ return f !== 403 || (o == null ? void 0 : o.code) !== "EDIT_LOCKED" ? !1 : (m(), l.current = !1, $(!1), u.warning(o.error || "You can no longer edit this record — your edit lock was let go"), v == null || v.invalidateQueries({ queryKey: ["pipeline-instance-lock", t, r] }), v == null || v.invalidateQueries({ queryKey: ["pipeline-instance", t, r] }), !0);
31
+ },
32
+ [v, t, r, m]
33
+ ), d = w(async () => {
34
+ var a, n;
35
+ if (!t || !r || q.current) return !1;
36
+ z.current = null;
29
37
  try {
30
- return await s.request(R(`/item-locks/${t}/${r}/lock`, {})), i.current = !0, $(!0), F(!1), g(null), h(), z.current = setInterval(() => {
31
- const k = Math.max(
38
+ return await s.request(C(`/item-locks/${t}/${r}/lock`, {})), l.current = !0, $(!0), P(!1), h(null), m(), j.current = setInterval(() => {
39
+ const f = Math.max(
32
40
  0,
33
- Math.floor((Date.now() - new Date(Se().last_active).getTime()) / 1e3)
41
+ Math.floor((Date.now() - new Date(qe().last_active).getTime()) / 1e3)
34
42
  );
35
- s.request(R(`/item-locks/${t}/${r}/heartbeat`, { idle_seconds: k })).then((l) => {
36
- if (!(l != null && l.idle_released)) return;
37
- h(), i.current = !1, $(!1), u.info(
43
+ s.request(C(`/item-locks/${t}/${r}/heartbeat`, { idle_seconds: f })).then((o) => {
44
+ if (!(o != null && o.idle_released)) return;
45
+ m(), l.current = !1, $(!1), u.info(
38
46
  "Your edit lock was released after inactivity — it re-locks when you resume."
39
47
  );
40
48
  const e = () => {
41
- window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0), c();
49
+ window.removeEventListener("pointerdown", e, !0), window.removeEventListener("keydown", e, !0), d();
42
50
  };
43
51
  window.addEventListener("pointerdown", e, !0), window.addEventListener("keydown", e, !0);
44
- }).catch((l) => {
45
- var X, Z;
46
- const e = l, d = e.status ?? ((X = e.response) == null ? void 0 : X.status);
47
- if (d !== 404 && d !== 409) return;
48
- const v = ((Z = e.response) == null ? void 0 : Z.data) ?? e.response;
49
- if (d === 404 && !(v != null && v.locked_by)) {
50
- c();
52
+ }).catch((o) => {
53
+ var te, re;
54
+ const e = o, c = e.status ?? ((te = e.response) == null ? void 0 : te.status);
55
+ if (U(o) || c !== 404 && c !== 409) return;
56
+ const x = ((re = e.response) == null ? void 0 : re.data) ?? e.response;
57
+ if (c === 404 && !(x != null && x.locked_by)) {
58
+ d();
51
59
  return;
52
60
  }
53
- h(), i.current = !1, $(!1), v != null && v.locked_by && (g({
54
- locked_by: v.locked_by,
55
- locked_by_name: v.locked_by_name ?? null
61
+ m(), l.current = !1, $(!1), x != null && x.locked_by && (h({
62
+ locked_by: x.locked_by,
63
+ locked_by_name: x.locked_by_name ?? null
56
64
  }), u.warning(
57
- `${v.locked_by_name ?? "Another user"} took over editing — your changes are no longer being saved`
65
+ `${x.locked_by_name ?? "Another user"} took over editing — your changes are no longer being saved`
58
66
  ));
59
67
  });
60
- }, Re), !0;
61
- } catch (k) {
62
- const l = k, e = l.status ?? ((n = l.response) == null ? void 0 : n.status), d = ((a = l.response) == null ? void 0 : a.data) ?? l.response;
63
- return K.current = e ?? null, e === 404 ? (j.current = !0, h(), i.current = !1, $(!1), !1) : (e === 409 && (d != null && d.locked_by) && (i.current = !1, $(!1), g({
64
- locked_by: d.locked_by,
65
- locked_by_name: d.locked_by_name ?? null,
66
- ...typeof d.may_take_over == "boolean" ? { may_take_over: d.may_take_over } : {}
68
+ }, Ie), !0;
69
+ } catch (f) {
70
+ const o = f, e = o.status ?? ((a = o.response) == null ? void 0 : a.status), c = ((n = o.response) == null ? void 0 : n.data) ?? o.response;
71
+ return z.current = e ?? null, U(f) ? !1 : e === 404 ? (q.current = !0, m(), l.current = !1, $(!1), !1) : (e === 409 && (c != null && c.locked_by) && (l.current = !1, $(!1), h({
72
+ locked_by: c.locked_by,
73
+ locked_by_name: c.locked_by_name ?? null,
74
+ ...typeof c.may_take_over == "boolean" ? { may_take_over: c.may_take_over } : {}
67
75
  })), !1);
68
76
  }
69
- }, [s, t, r, h]), y = w(async () => {
77
+ }, [s, t, r, m, U]), b = w(async () => {
70
78
  if (!(!t || !r))
71
79
  try {
72
- const n = await s.request(Ne(`/item-locks/${t}/${r}/lock`)), a = n == null ? void 0 : n.data;
73
- ie(Array.isArray(a == null ? void 0 : a.queue) ? a.queue : []), O(typeof (a == null ? void 0 : a.my_position) == "number" ? a.my_position : null);
74
- const k = (a == null ? void 0 : a.is_mine) === !0 || !!b && String((a == null ? void 0 : a.locked_by) ?? "").toLowerCase() === b.toLowerCase(), l = typeof (a == null ? void 0 : a.may_take_over) == "boolean" ? { may_take_over: a.may_take_over } : {};
75
- if (i.current) return;
76
- if (!(a != null && a.locked_by) || k) {
77
- g(null);
80
+ const a = await s.request(Se(`/item-locks/${t}/${r}/lock`)), n = a == null ? void 0 : a.data;
81
+ ue(Array.isArray(n == null ? void 0 : n.queue) ? n.queue : []), M(typeof (n == null ? void 0 : n.my_position) == "number" ? n.my_position : null);
82
+ const f = (n == null ? void 0 : n.is_mine) === !0 || !!g && String((n == null ? void 0 : n.locked_by) ?? "").toLowerCase() === g.toLowerCase(), o = typeof (n == null ? void 0 : n.may_take_over) == "boolean" ? { may_take_over: n.may_take_over } : {};
83
+ if (l.current) return;
84
+ if (!(n != null && n.locked_by) || f) {
85
+ h(null);
78
86
  return;
79
87
  }
80
- g(
81
- (e) => e && e.locked_by === String(a.locked_by) ? {
88
+ h(
89
+ (e) => e && e.locked_by === String(n.locked_by) ? {
82
90
  ...e,
83
- note: a.note ?? e.note ?? null,
84
- idle_minutes: a.locked_by_idle_minutes ?? e.idle_minutes ?? null,
85
- ...l
91
+ note: n.note ?? e.note ?? null,
92
+ idle_minutes: n.locked_by_idle_minutes ?? e.idle_minutes ?? null,
93
+ ...o
86
94
  } : {
87
- locked_by: String(a.locked_by),
88
- locked_by_name: a.locked_by_name ?? null,
89
- note: a.note ?? null,
90
- idle_minutes: a.locked_by_idle_minutes ?? null,
91
- ...l
95
+ locked_by: String(n.locked_by),
96
+ locked_by_name: n.locked_by_name ?? null,
97
+ note: n.note ?? null,
98
+ idle_minutes: n.locked_by_idle_minutes ?? null,
99
+ ...o
92
100
  }
93
- ), F(!1);
94
- } catch (n) {
95
- (n == null ? void 0 : n.status) === 404 && (j.current = !0);
101
+ ), P(!1);
102
+ } catch (a) {
103
+ (a == null ? void 0 : a.status) === 404 && (q.current = !0);
96
104
  }
97
- }, [s, t, r, b]), B = (_ == null ? void 0 : _.locked_by) ?? null;
98
- S(() => {
99
- B && y();
100
- }, [B, y]), S(() => {
101
- if (!B) return;
102
- const n = setInterval(() => void y(), Ee);
103
- return () => clearInterval(n);
104
- }, [B, y]), S(() => {
105
- if (!(!o || !t || !r))
106
- return L.current = !1, j.current = !1, q ? y() : c(), () => {
107
- h(), L.current = !1, i.current && (i.current = !1, s.request(D(`/item-locks/${t}/${r}/lock`)).then(() => re(b, "lock-released", t, r)).catch(() => {
105
+ }, [s, t, r, g]), I = (p == null ? void 0 : p.locked_by) ?? null;
106
+ N(() => {
107
+ I && b();
108
+ }, [I, b]), N(() => {
109
+ if (!I) return;
110
+ const a = setInterval(() => void b(), Oe);
111
+ return () => clearInterval(a);
112
+ }, [I, b]), N(() => {
113
+ if (!(!i || !t || !r))
114
+ return R.current = !1, q.current = !1, L ? b() : d(), () => {
115
+ m(), R.current = !1, l.current && (l.current = !1, s.request(K(`/item-locks/${t}/${r}/lock`)).then(() => se(g, "lock-released", t, r)).catch(() => {
108
116
  }));
109
117
  };
110
- }, [o, t, r, c, s, h, b, q, y]);
111
- const ke = w(async () => {
112
- if (!(!o || i.current || P.current)) {
113
- P.current = !0;
118
+ }, [i, t, r, d, s, m, g, L, b]);
119
+ const be = w(async () => {
120
+ if (!(!i || l.current || Q.current) && !(Date.now() < V.current)) {
121
+ Q.current = !0;
114
122
  try {
115
- !await c() && K.current === 409 && u.warning("Someone else is editing this record — your change can’t be saved yet");
123
+ const a = await d();
124
+ !a && z.current === 409 && u.warning("Someone else is editing this record — your change can’t be saved yet"), !a && z.current !== 409 && !q.current && (V.current = Date.now() + Me);
116
125
  } finally {
117
- P.current = !1;
126
+ Q.current = !1;
118
127
  }
119
128
  }
120
- }, [o, c]), he = Ae(), G = E && he;
121
- S(() => {
122
- if (!o || !t || !r) return;
123
- if (G) {
124
- L.current && (L.current = !1, c());
129
+ }, [i, d]);
130
+ N(() => {
131
+ const a = () => {
132
+ V.current = 0;
133
+ };
134
+ return window.addEventListener("online", a), () => window.removeEventListener("online", a);
135
+ }, []);
136
+ const ye = je(), B = T && ye;
137
+ N(() => {
138
+ if (!i || !t || !r) return;
139
+ if (B) {
140
+ R.current && (R.current = !1, d());
125
141
  return;
126
142
  }
127
- const n = setTimeout(() => {
128
- i.current && (h(), i.current = !1, $(!1), L.current = !0, s.request(D(`/item-locks/${t}/${r}/lock`)).then(() => re(b, "lock-released", t, r)).catch(() => {
143
+ const a = setTimeout(() => {
144
+ l.current && (m(), l.current = !1, $(!1), R.current = !0, s.request(K(`/item-locks/${t}/${r}/lock`)).then(() => se(g, "lock-released", t, r)).catch(() => {
129
145
  }));
130
- }, Ce);
131
- return () => clearTimeout(n);
132
- }, [o, G, t, r, c, s, h, b]), S(() => {
133
- if (!o || !t || !r) return;
134
- const n = () => {
135
- var k;
136
- if (i.current) {
137
- h(), i.current = !1, L.current = !0;
146
+ }, Ye);
147
+ return () => clearTimeout(a);
148
+ }, [i, B, t, r, d, s, m, g]), N(() => {
149
+ if (!i || !L || !t || !r || I || !B) return;
150
+ const a = setInterval(() => {
151
+ !l.current && !q.current && b();
152
+ }, De);
153
+ return () => clearInterval(a);
154
+ }, [i, L, t, r, I, B, b]), N(() => {
155
+ if (!i || !t || !r) return;
156
+ const a = () => {
157
+ var f;
158
+ if (l.current) {
159
+ m(), l.current = !1, R.current = !0;
138
160
  try {
139
- const l = (k = s.getToken) == null ? void 0 : k.call(s), e = s.url ?? "";
161
+ const o = (f = s.getToken) == null ? void 0 : f.call(s), e = s.url ?? "";
140
162
  fetch(
141
163
  `${e}/api/item-locks/${encodeURIComponent(t)}/${encodeURIComponent(r)}/lock/release`,
142
164
  {
143
165
  method: "POST",
144
166
  keepalive: !0,
145
- credentials: l ? "omit" : "include",
146
- headers: l ? { Authorization: `Bearer ${l}` } : {}
167
+ credentials: o ? "omit" : "include",
168
+ headers: o ? { Authorization: `Bearer ${o}` } : {}
147
169
  }
148
170
  ).catch(() => {
149
171
  });
150
172
  } catch {
151
173
  }
152
174
  }
153
- }, a = (k) => {
154
- k.persisted && L.current && (L.current = !1, c());
175
+ }, n = (f) => {
176
+ f.persisted && R.current && (R.current = !1, d());
155
177
  };
156
- return window.addEventListener("pagehide", n), window.addEventListener("pageshow", a), () => {
157
- window.removeEventListener("pagehide", n), window.removeEventListener("pageshow", a);
178
+ return window.addEventListener("pagehide", a), window.addEventListener("pageshow", n), () => {
179
+ window.removeEventListener("pagehide", a), window.removeEventListener("pageshow", n);
158
180
  };
159
- }, [o, t, r, s, h, c]), Le(b, "lock-released", t, r, () => {
160
- o && i.current && c();
181
+ }, [i, t, r, s, m, d]), Te(g, "lock-released", t, r, () => {
182
+ i && l.current && d();
161
183
  });
162
- const Q = te();
163
- S(() => {
164
- if (!(!o || !Q || !t || !r))
165
- return Q.subscribeCollections([t], (n) => {
166
- var a;
167
- i.current || j.current || !((a = n.changed_fields) != null && a.includes("$lock")) || !qe(n, r) || y();
184
+ const W = ae();
185
+ N(() => {
186
+ if (!(!i || !W || !t || !r))
187
+ return W.subscribeCollections([t], (a) => {
188
+ var n;
189
+ l.current || q.current || !((n = a.changed_fields) != null && n.includes("$lock")) || !Ae(a, r) || b();
168
190
  });
169
- }, [o, Q, t, r, y]);
170
- const T = te(), [fe, H] = x(!1), be = w(async () => {
191
+ }, [i, W, t, r, b]);
192
+ const Y = ae(), [ge, ee] = _(!1), ve = w(async () => {
171
193
  if (!(!t || !r)) {
172
- H(!0);
194
+ ee(!0);
173
195
  try {
174
- await s.request(R(`/item-locks/${t}/${r}/lock/request`, {})), u.success("Asked the current editor to release the lock");
196
+ await s.request(C(`/item-locks/${t}/${r}/lock/request`, {})), u.success("Asked the current editor to release the lock");
175
197
  } catch {
176
198
  u.error("Could not send the lock request");
177
199
  } finally {
178
- H(!1);
200
+ ee(!1);
179
201
  }
180
202
  }
181
203
  }, [s, t, r]);
182
- S(() => {
183
- if (!T || !t || !r) return;
184
- const n = T.on("lock:requested", (e) => {
185
- if ((e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || !i.current) return;
186
- const d = (e == null ? void 0 : e.from) ?? {};
187
- u(`${d.name ?? "Someone"} is asking you to release this record`, {
204
+ N(() => {
205
+ if (!Y || !t || !r) return;
206
+ const a = Y.on("lock:requested", (e) => {
207
+ if ((e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || !l.current) return;
208
+ const c = (e == null ? void 0 : e.from) ?? {};
209
+ u(`${c.name ?? "Someone"} is asking you to release this record`, {
188
210
  duration: 3e4,
189
211
  action: {
190
212
  label: "Release",
191
213
  onClick: () => {
192
- h(), i.current = !1, $(!1), s.request(
193
- R(`/item-locks/${t}/${r}/lock/respond`, {
194
- to: d.id,
214
+ m(), l.current = !1, $(!1), s.request(
215
+ C(`/item-locks/${t}/${r}/lock/respond`, {
216
+ to: c.id,
195
217
  action: "release"
196
218
  })
197
219
  ).then(() => u.success("Lock released")).catch(() => u.error("Failed to release the lock"));
@@ -201,8 +223,8 @@ function Ke(t, r, o, C = {}) {
201
223
  label: "Keep editing",
202
224
  onClick: () => {
203
225
  s.request(
204
- R(`/item-locks/${t}/${r}/lock/respond`, {
205
- to: d.id,
226
+ C(`/item-locks/${t}/${r}/lock/respond`, {
227
+ to: c.id,
206
228
  action: "decline"
207
229
  })
208
230
  ).catch(() => {
@@ -210,125 +232,125 @@ function Ke(t, r, o, C = {}) {
210
232
  }
211
233
  }
212
234
  });
213
- }), a = T.on("lock:response", (e) => {
214
- var d, v;
215
- (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || i.current || ((e == null ? void 0 : e.action) === "release" ? (u.success(`${((d = e == null ? void 0 : e.from) == null ? void 0 : d.name) ?? "The editor"} released the lock — it's yours`), c()) : u.warning(
216
- `${((v = e == null ? void 0 : e.from) == null ? void 0 : v.name) ?? "The editor"} is keeping the lock${e != null && e.note ? `: "${e.note}"` : ""}`
235
+ }), n = Y.on("lock:response", (e) => {
236
+ var c, x;
237
+ (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || l.current || ((e == null ? void 0 : e.action) === "release" ? (u.success(`${((c = e == null ? void 0 : e.from) == null ? void 0 : c.name) ?? "The editor"} released the lock — it's yours`), d()) : u.warning(
238
+ `${((x = e == null ? void 0 : e.from) == null ? void 0 : x.name) ?? "The editor"} is keeping the lock${e != null && e.note ? `: "${e.note}"` : ""}`
217
239
  ));
218
- }), k = T.on("lock:available", (e) => {
219
- (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || i.current || (u.success("Your turn — the edit lock is yours"), O(null), c());
220
- }), l = T.on("lock:queued", (e) => {
221
- (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || (i.current && u(`${(e == null ? void 0 : e.user_name) ?? "Someone"} is waiting to edit this record`, { duration: 8e3 }), y());
240
+ }), f = Y.on("lock:available", (e) => {
241
+ (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || l.current || (u.success("Your turn — the edit lock is yours"), M(null), d());
242
+ }), o = Y.on("lock:queued", (e) => {
243
+ (e == null ? void 0 : e.collection) !== t || String(e == null ? void 0 : e.item) !== String(r) || (l.current && u(`${(e == null ? void 0 : e.user_name) ?? "Someone"} is waiting to edit this record`, { duration: 8e3 }), b());
222
244
  });
223
245
  return () => {
224
- n(), a(), k(), l();
246
+ a(), n(), f(), o();
225
247
  };
226
- }, [T, t, r, s, c, h, y]);
227
- const ye = w(async () => {
248
+ }, [Y, t, r, s, d, m, b]);
249
+ const xe = w(async () => {
228
250
  if (!(!t || !r)) {
229
- U(!0);
251
+ G(!0);
230
252
  try {
231
- const n = await s.request(
232
- R(`/item-locks/${t}/${r}/lock/queue`, {})
233
- ), a = n == null ? void 0 : n.data;
234
- if (a != null && a.free) {
235
- O(null), g(null), u.success("Nobody is editing this record now — go ahead");
253
+ const a = await s.request(
254
+ C(`/item-locks/${t}/${r}/lock/queue`, {})
255
+ ), n = a == null ? void 0 : a.data;
256
+ if (n != null && n.free) {
257
+ M(null), h(null), u.success("Nobody is editing this record now — go ahead");
236
258
  return;
237
259
  }
238
- const k = a == null ? void 0 : a.position;
239
- O(typeof k == "number" ? k : 1), u.success("You are in line — the lock comes to you automatically when it frees up"), y();
260
+ const f = n == null ? void 0 : n.position;
261
+ M(typeof f == "number" ? f : 1), u.success("You are in line — the lock comes to you automatically when it frees up"), b();
240
262
  } catch {
241
263
  u.error("Could not join the queue");
242
264
  } finally {
243
- U(!1);
265
+ G(!1);
244
266
  }
245
267
  }
246
- }, [s, t, r, y]), ge = w(async () => {
268
+ }, [s, t, r, b]), we = w(async () => {
247
269
  if (!(!t || !r))
248
270
  try {
249
- await s.request(D(`/item-locks/${t}/${r}/lock/queue`)), O(null), y();
271
+ await s.request(K(`/item-locks/${t}/${r}/lock/queue`)), M(null), b();
250
272
  } catch {
251
273
  }
252
- }, [s, t, r, y]), ve = w(
253
- async (n) => {
254
- if (!(!t || !r || !i.current)) {
255
- W(n);
274
+ }, [s, t, r, b]), _e = w(
275
+ async (a) => {
276
+ if (!(!t || !r || !l.current)) {
277
+ X(a);
256
278
  try {
257
- await s.request(R(`/item-locks/${t}/${r}/lock/note`, { note: n }));
279
+ await s.request(C(`/item-locks/${t}/${r}/lock/note`, { note: a }));
258
280
  } catch {
259
281
  }
260
282
  }
261
283
  },
262
284
  [s, t, r]
263
- ), xe = w(async () => {
264
- if (!(!t || !r || !i.current)) {
265
- J(!0), h(), i.current = !1, $(!1);
285
+ ), pe = w(async () => {
286
+ if (!(!t || !r || !l.current)) {
287
+ Z(!0), m(), l.current = !1, $(!1);
266
288
  try {
267
- await s.request(D(`/item-locks/${t}/${r}/lock`)), F(!0), W(""), u.success("Lock released — anyone can edit this record now");
289
+ await s.request(K(`/item-locks/${t}/${r}/lock`)), P(!0), X(""), u.success("Lock released — anyone can edit this record now");
268
290
  } catch {
269
- u.error("Failed to release the lock"), c();
291
+ u.error("Failed to release the lock"), d();
270
292
  } finally {
271
- J(!1);
293
+ Z(!1);
272
294
  }
273
295
  }
274
- }, [s, t, r, h, c]), we = w(async () => {
275
- if (i.current) return !0;
276
- const n = await c();
277
- return n && u.success("You hold the edit lock again"), n;
278
- }, [c]), _e = w(async () => {
279
- var n;
296
+ }, [s, t, r, m, d]), $e = w(async () => {
297
+ if (l.current) return !0;
298
+ const a = await d();
299
+ return a && u.success("You hold the edit lock again"), a;
300
+ }, [d]), Ne = w(async () => {
301
+ var a;
280
302
  if (!(!t || !r)) {
281
- A(!0);
303
+ J(!0);
282
304
  try {
283
- await s.request(R(`/item-locks/${t}/${r}/lock/force`, {})), u.success("You now hold the edit lock"), await c();
284
- } catch (a) {
285
- const k = ((n = a == null ? void 0 : a.response) == null ? void 0 : n.error) ?? "Failed to take over the lock";
286
- u.error(k), (a == null ? void 0 : a.status) === 403 && g((l) => l && { ...l, may_take_over: !1 });
305
+ await s.request(C(`/item-locks/${t}/${r}/lock/force`, {})), u.success("You now hold the edit lock"), await d();
306
+ } catch (n) {
307
+ const f = ((a = n == null ? void 0 : n.response) == null ? void 0 : a.error) ?? "Failed to take over the lock";
308
+ u.error(f), (n == null ? void 0 : n.status) === 403 && h((o) => o && { ...o, may_take_over: !1 });
287
309
  } finally {
288
- A(!1);
310
+ J(!1);
289
311
  }
290
312
  }
291
- }, [s, t, r, c]);
313
+ }, [s, t, r, d]);
292
314
  return {
293
- lockHolder: _,
294
- acquired: p,
295
- isReadOnly: !!_,
296
- takeOver: _e,
297
- takingOver: M,
298
- isAdmin: N,
299
- requestLock: be,
300
- requesting: fe,
301
- queue: oe,
302
- myPosition: le,
303
- joinQueue: ye,
304
- leaveQueue: ge,
305
- joining: ce,
306
- myNote: ue,
307
- saveNote: ve,
308
- release: xe,
309
- releasing: me,
310
- released: de,
311
- relock: we,
312
- claim: ke
315
+ lockHolder: p,
316
+ acquired: F,
317
+ isReadOnly: !!p,
318
+ takeOver: Ne,
319
+ takingOver: D,
320
+ isAdmin: E,
321
+ requestLock: ve,
322
+ requesting: ge,
323
+ queue: ce,
324
+ myPosition: de,
325
+ joinQueue: xe,
326
+ leaveQueue: we,
327
+ joining: fe,
328
+ myNote: ke,
329
+ saveNote: _e,
330
+ release: pe,
331
+ releasing: he,
332
+ released: me,
333
+ relock: $e,
334
+ claim: be
313
335
  };
314
336
  }
315
- function Qe({
337
+ function Ze({
316
338
  note: t,
317
339
  onSave: r,
318
- waiting: o,
319
- onRelease: C,
320
- releasing: q,
321
- released: E,
340
+ waiting: i,
341
+ onRelease: S,
342
+ releasing: L,
343
+ released: T,
322
344
  onRelock: s
323
345
  }) {
324
- var g;
325
- const [N, b] = x(t);
326
- S(() => b(t), [t]);
327
- const _ = () => {
328
- N.trim() !== t && r(N.trim());
346
+ var p;
347
+ const [E, g] = _(t);
348
+ N(() => g(t), [t]);
349
+ const v = () => {
350
+ E.trim() !== t && r(E.trim());
329
351
  };
330
- return E ? /* @__PURE__ */ f(ae, { children: [
331
- /* @__PURE__ */ m(ne, { asChild: !0, children: /* @__PURE__ */ m(
352
+ return T ? /* @__PURE__ */ y(oe, { children: [
353
+ /* @__PURE__ */ k(ie, { asChild: !0, children: /* @__PURE__ */ k(
332
354
  "button",
333
355
  {
334
356
  type: "button",
@@ -336,14 +358,14 @@ function Qe({
336
358
  title: "Lock released — anyone can edit this record",
337
359
  "data-lock-released": !0,
338
360
  className: "relative inline-flex h-8 w-8 items-center justify-center text-slate-400 transition-colors hover:bg-accent hover:text-accent-foreground dark:text-slate-500",
339
- children: /* @__PURE__ */ m(ee, { className: "h-4 w-4", strokeWidth: 2 })
361
+ children: /* @__PURE__ */ k(ne, { className: "h-4 w-4", strokeWidth: 2 })
340
362
  }
341
363
  ) }),
342
- /* @__PURE__ */ f(se, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
343
- /* @__PURE__ */ m("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You released the edit lock" }),
344
- /* @__PURE__ */ m("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Anyone can edit this record now. Your next edit locks it again — or lock it now." }),
345
- /* @__PURE__ */ f(
346
- I,
364
+ /* @__PURE__ */ y(le, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
365
+ /* @__PURE__ */ k("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You released the edit lock" }),
366
+ /* @__PURE__ */ k("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Anyone can edit this record now. Your next edit locks it again — or lock it now." }),
367
+ /* @__PURE__ */ y(
368
+ O,
347
369
  {
348
370
  type: "button",
349
371
  size: "sm",
@@ -351,102 +373,102 @@ function Qe({
351
373
  onClick: s,
352
374
  "data-lock-relock": !0,
353
375
  children: [
354
- /* @__PURE__ */ m(V, { className: "mr-1.5 h-3.5 w-3.5" }),
376
+ /* @__PURE__ */ k(H, { className: "mr-1.5 h-3.5 w-3.5" }),
355
377
  " Lock again"
356
378
  ]
357
379
  }
358
380
  )
359
381
  ] })
360
- ] }) : /* @__PURE__ */ f(ae, { children: [
361
- /* @__PURE__ */ m(ne, { asChild: !0, children: /* @__PURE__ */ f(
382
+ ] }) : /* @__PURE__ */ y(oe, { children: [
383
+ /* @__PURE__ */ k(ie, { asChild: !0, children: /* @__PURE__ */ y(
362
384
  "button",
363
385
  {
364
386
  type: "button",
365
387
  "aria-label": "You hold the edit lock — add a note for others",
366
- title: o.length > 0 ? `You hold the edit lock · ${o.length} waiting` : "You hold the edit lock",
388
+ title: i.length > 0 ? `You hold the edit lock · ${i.length} waiting` : "You hold the edit lock",
367
389
  "data-lock-holder": !0,
368
390
  className: "relative inline-flex h-8 w-8 items-center justify-center text-[#0e7490] transition-colors hover:bg-accent hover:text-accent-foreground dark:text-nvr-cyan",
369
391
  children: [
370
- /* @__PURE__ */ m(V, { className: "h-4 w-4", strokeWidth: 2 }),
371
- o.length > 0 && /* @__PURE__ */ m("span", { className: "absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-amber-500 ring-2 ring-background" })
392
+ /* @__PURE__ */ k(H, { className: "h-4 w-4", strokeWidth: 2 }),
393
+ i.length > 0 && /* @__PURE__ */ k("span", { className: "absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-amber-500 ring-2 ring-background" })
372
394
  ]
373
395
  }
374
396
  ) }),
375
- /* @__PURE__ */ f(se, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
376
- /* @__PURE__ */ m("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You hold the edit lock" }),
377
- /* @__PURE__ */ m("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Others see this record read-only. A note tells them what you’re doing." }),
378
- /* @__PURE__ */ m(
397
+ /* @__PURE__ */ y(le, { align: "end", sideOffset: 6, className: "w-[300px] p-3", children: [
398
+ /* @__PURE__ */ k("p", { className: "text-[12px] font-semibold text-slate-700 dark:text-slate-200", children: "You hold the edit lock" }),
399
+ /* @__PURE__ */ k("p", { className: "mt-0.5 text-[11px] text-slate-500 dark:text-slate-400", children: "Others see this record read-only. A note tells them what you’re doing." }),
400
+ /* @__PURE__ */ k(
379
401
  "input",
380
402
  {
381
- value: N,
382
- onChange: (p) => b(p.target.value.slice(0, 300)),
383
- onBlur: _,
384
- onKeyDown: (p) => {
385
- p.key === "Enter" && (p.preventDefault(), _());
403
+ value: E,
404
+ onChange: (h) => g(h.target.value.slice(0, 300)),
405
+ onBlur: v,
406
+ onKeyDown: (h) => {
407
+ h.key === "Enter" && (h.preventDefault(), v());
386
408
  },
387
409
  placeholder: "“editing lines, ~15 min”",
388
410
  "aria-label": "Lock note",
389
411
  className: "mt-2 h-7 w-full rounded-md border border-slate-200 bg-white px-2 text-[12px] dark:border-border dark:bg-card"
390
412
  }
391
413
  ),
392
- o.length > 0 && /* @__PURE__ */ f("div", { className: "mt-2 rounded-md bg-amber-50 px-2 py-1.5 text-[11px] text-amber-800 dark:bg-amber-500/10 dark:text-amber-200", children: [
393
- /* @__PURE__ */ f("span", { className: "font-semibold", children: [
394
- o.length,
414
+ i.length > 0 && /* @__PURE__ */ y("div", { className: "mt-2 rounded-md bg-amber-50 px-2 py-1.5 text-[11px] text-amber-800 dark:bg-amber-500/10 dark:text-amber-200", children: [
415
+ /* @__PURE__ */ y("span", { className: "font-semibold", children: [
416
+ i.length,
395
417
  " waiting for the lock:"
396
418
  ] }),
397
419
  " ",
398
- o.map((p) => p.name ?? "someone").join(", ")
420
+ i.map((h) => h.name ?? "someone").join(", ")
399
421
  ] }),
400
- C && /* @__PURE__ */ f(
401
- I,
422
+ S && /* @__PURE__ */ y(
423
+ O,
402
424
  {
403
425
  type: "button",
404
426
  variant: "outline",
405
427
  size: "sm",
406
428
  className: "mt-2 h-7 w-full text-[12px]",
407
- onClick: C,
408
- disabled: q,
429
+ onClick: S,
430
+ disabled: L,
409
431
  "data-lock-release": !0,
410
432
  children: [
411
- /* @__PURE__ */ m(ee, { className: "mr-1.5 h-3.5 w-3.5" }),
412
- q ? "Releasing…" : o.length > 0 ? `Release lock to ${((g = o[0]) == null ? void 0 : g.name) ?? "the next person"}` : "Release lock"
433
+ /* @__PURE__ */ k(ne, { className: "mr-1.5 h-3.5 w-3.5" }),
434
+ L ? "Releasing…" : i.length > 0 ? `Release lock to ${((p = i[0]) == null ? void 0 : p.name) ?? "the next person"}` : "Release lock"
413
435
  ]
414
436
  }
415
437
  )
416
438
  ] })
417
439
  ] });
418
440
  }
419
- function Ve({
441
+ function et({
420
442
  lockHolder: t,
421
443
  onTakeOver: r,
422
- takingOver: o,
423
- isAdmin: C,
424
- onRequestLock: q,
425
- requesting: E,
444
+ takingOver: i,
445
+ isAdmin: S,
446
+ onRequestLock: L,
447
+ requesting: T,
426
448
  queue: s,
427
- myPosition: N,
428
- onJoinQueue: b,
429
- onLeaveQueue: _,
430
- joining: g,
431
- noun: p = "this item",
432
- readOnlyText: $ = "fields are read-only"
449
+ myPosition: E,
450
+ onJoinQueue: g,
451
+ onLeaveQueue: v,
452
+ joining: p,
453
+ noun: h = "this item",
454
+ readOnlyText: F = "fields are read-only"
433
455
  }) {
434
456
  if (!t) return null;
435
- const M = t.locked_by_name || "Another user", A = (s == null ? void 0 : s.length) ?? 0;
436
- return /* @__PURE__ */ f(
457
+ const $ = t.locked_by_name || "Another user", D = (s == null ? void 0 : s.length) ?? 0;
458
+ return /* @__PURE__ */ y(
437
459
  "div",
438
460
  {
439
461
  className: "mb-4 flex flex-wrap items-center gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-100",
440
462
  "data-lock-banner": !0,
441
463
  children: [
442
- /* @__PURE__ */ m(V, { className: "h-4 w-4 shrink-0 text-amber-500" }),
443
- /* @__PURE__ */ f("span", { className: "min-w-0 flex-1", children: [
444
- /* @__PURE__ */ m("span", { className: "font-medium", children: M }),
464
+ /* @__PURE__ */ k(H, { className: "h-4 w-4 shrink-0 text-amber-500" }),
465
+ /* @__PURE__ */ y("span", { className: "min-w-0 flex-1", children: [
466
+ /* @__PURE__ */ k("span", { className: "font-medium", children: $ }),
445
467
  " is editing ",
446
- p,
468
+ h,
447
469
  " — ",
448
- $,
449
- t.idle_minutes != null && t.idle_minutes >= 2 && /* @__PURE__ */ f(
470
+ F,
471
+ t.idle_minutes != null && t.idle_minutes >= 2 && /* @__PURE__ */ y(
450
472
  "span",
451
473
  {
452
474
  className: "ml-1.5 rounded bg-amber-100 px-1 py-px text-[10px] font-semibold text-amber-700 dark:bg-amber-500/20 dark:text-amber-200",
@@ -461,67 +483,67 @@ function Ve({
461
483
  ),
462
484
  " ",
463
485
  "until the lock is released.",
464
- t.note && /* @__PURE__ */ f("span", { className: "mt-0.5 block text-[12.5px] text-amber-800/90 dark:text-amber-200/90", children: [
486
+ t.note && /* @__PURE__ */ y("span", { className: "mt-0.5 block text-[12.5px] text-amber-800/90 dark:text-amber-200/90", children: [
465
487
  "“",
466
488
  t.note,
467
489
  "”"
468
490
  ] }),
469
- A > 0 && N == null && /* @__PURE__ */ f("span", { className: "mt-0.5 block text-[11.5px] text-amber-700/80 dark:text-amber-300/80", children: [
470
- A,
491
+ D > 0 && E == null && /* @__PURE__ */ y("span", { className: "mt-0.5 block text-[11.5px] text-amber-700/80 dark:text-amber-300/80", children: [
492
+ D,
471
493
  " ",
472
- A === 1 ? "person is" : "people are",
494
+ D === 1 ? "person is" : "people are",
473
495
  " already waiting."
474
496
  ] })
475
497
  ] }),
476
- b && (N != null ? /* @__PURE__ */ f(
477
- I,
498
+ g && (E != null ? /* @__PURE__ */ y(
499
+ O,
478
500
  {
479
501
  size: "sm",
480
502
  variant: "outline",
481
503
  className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
482
- onClick: _,
504
+ onClick: v,
483
505
  "data-lock-queue-leave": !0,
484
506
  children: [
485
507
  "You’re #",
486
- N,
508
+ E,
487
509
  " in line · Leave"
488
510
  ]
489
511
  }
490
- ) : /* @__PURE__ */ m(
491
- I,
512
+ ) : /* @__PURE__ */ k(
513
+ O,
492
514
  {
493
515
  size: "sm",
494
516
  variant: "outline",
495
517
  className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
496
- onClick: b,
497
- disabled: g,
518
+ onClick: g,
519
+ disabled: p,
498
520
  "data-lock-queue-join": !0,
499
- children: g ? "Joining…" : "Ask to be next"
521
+ children: p ? "Joining…" : "Ask to be next"
500
522
  }
501
523
  )),
502
- q && /* @__PURE__ */ m(
503
- I,
524
+ L && /* @__PURE__ */ k(
525
+ O,
504
526
  {
505
527
  size: "sm",
506
528
  variant: "outline",
507
529
  className: "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15",
508
- onClick: q,
509
- disabled: E,
510
- children: E ? "Asking…" : "Ask them to wrap up"
530
+ onClick: L,
531
+ disabled: T,
532
+ children: T ? "Asking…" : "Ask them to wrap up"
511
533
  }
512
534
  ),
513
535
  // Admins always; other roles only when the server says they may (the
514
536
  // takeover-role allowlist, #256) — unknown = offered, and a 403 then
515
537
  // hides it. A Take over that can only fail was a dead end.
516
- (C || t.may_take_over !== !1) && /* @__PURE__ */ m(
517
- I,
538
+ (S || t.may_take_over !== !1) && /* @__PURE__ */ k(
539
+ O,
518
540
  {
519
541
  size: "sm",
520
542
  variant: "outline",
521
- className: C ? "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15" : "h-7 shrink-0 border-amber-200 bg-white/60 text-[12px] text-amber-700/80 hover:bg-amber-100 dark:border-amber-500/30 dark:bg-transparent dark:text-amber-200/80 dark:hover:bg-amber-500/15",
543
+ className: S ? "h-7 shrink-0 border-amber-300 bg-white text-[12px] text-amber-800 hover:bg-amber-100 dark:border-amber-500/40 dark:bg-transparent dark:text-amber-200 dark:hover:bg-amber-500/15" : "h-7 shrink-0 border-amber-200 bg-white/60 text-[12px] text-amber-700/80 hover:bg-amber-100 dark:border-amber-500/30 dark:bg-transparent dark:text-amber-200/80 dark:hover:bg-amber-500/15",
522
544
  onClick: r,
523
- disabled: o,
524
- children: o ? "Taking over…" : "Take over"
545
+ disabled: i,
546
+ children: i ? "Taking over…" : "Take over"
525
547
  }
526
548
  )
527
549
  ]
@@ -529,7 +551,7 @@ function Ve({
529
551
  );
530
552
  }
531
553
  export {
532
- Ve as ItemLockBanner,
533
- Qe as LockHolderButton,
534
- Ke as useItemLock
554
+ et as ItemLockBanner,
555
+ Ze as LockHolderButton,
556
+ Xe as useItemLock
535
557
  };