@nivaro/react 0.3.10 → 0.3.11

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