@nivaro/react 0.3.49 → 0.3.51

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