@nivaro/react 0.3.57 → 0.3.59

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 (69) hide show
  1. package/dist/components/fields/RelationField.js +110 -80
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useRelationOptions.js +1 -0
  4. package/dist/hooks/useSessionRecorder.js +1 -1
  5. package/dist/index.d.ts +37 -2
  6. package/dist/index.js +523 -520
  7. package/dist/shared/components/CollectionBrowserView.js +2693 -2619
  8. package/dist/shared/components/DataTable.js +538 -495
  9. package/dist/shared/components/ItemEditForm.js +4559 -4386
  10. package/dist/shared/components/PageRenderer.js +537 -508
  11. package/dist/shared/components/ProfileView.js +716 -715
  12. package/dist/shared/components/QueryTable.js +74 -74
  13. package/dist/shared/components/RecordReadView.js +367 -364
  14. package/dist/shared/components/ReportView.js +64 -39
  15. package/dist/shared/components/WidgetSlot.js +543 -520
  16. package/dist/shared/components/alerts/AlertManagerView.js +324 -317
  17. package/dist/shared/components/alerts/types.js +37 -14
  18. package/dist/shared/components/cbv/row-focus.js +19 -0
  19. package/dist/shared/components/help-videos/HelpVideoPlayer.js +152 -147
  20. package/dist/shared/components/integrations/console/SignalCard.js +59 -59
  21. package/dist/shared/components/integrations/console/tone.js +52 -30
  22. package/dist/shared/components/item-edit/CatalogPickerField.js +525 -505
  23. package/dist/shared/components/item-edit/FieldRenderer.js +22 -20
  24. package/dist/shared/components/item-edit/FieldRow.js +175 -173
  25. package/dist/shared/components/item-edit/GridBulkEditDialog.js +55 -54
  26. package/dist/shared/components/item-edit/InlineTableField.js +2487 -2442
  27. package/dist/shared/components/item-edit/M2MCombobox.js +321 -295
  28. package/dist/shared/components/item-edit/MidairCollisionDialog.js +1 -1
  29. package/dist/shared/components/item-edit/PlanGrid.js +973 -894
  30. package/dist/shared/components/item-edit/QuickCreateButton.js +335 -106
  31. package/dist/shared/components/item-edit/RecordLiveSync.js +77 -75
  32. package/dist/shared/components/item-edit/RelationCombobox.js +452 -335
  33. package/dist/shared/components/item-edit/RelationGroupedCombobox.js +262 -141
  34. package/dist/shared/components/item-edit/SummaryPanel.js +385 -358
  35. package/dist/shared/components/item-edit/duplicate-rehearsal.js +47 -0
  36. package/dist/shared/components/item-edit/line-midair.js +82 -75
  37. package/dist/shared/components/item-edit/option-disambiguate.js +44 -32
  38. package/dist/shared/components/item-edit/related-missing.js +45 -0
  39. package/dist/shared/components/item-edit/save-outcome.js +9 -7
  40. package/dist/shared/components/notifications/NotificationRulesEditor.js +130 -123
  41. package/dist/shared/components/panels/AccessDeniedPanel.js +52 -48
  42. package/dist/shared/components/panels/ItemLockBanner.js +213 -211
  43. package/dist/shared/components/panels/PipelinePanel.js +1140 -1053
  44. package/dist/shared/components/panels/RecordIntegrityBanner.js +114 -86
  45. package/dist/shared/components/panels/RevisionsPanel.js +316 -299
  46. package/dist/shared/components/panels/TaskPanel.js +265 -249
  47. package/dist/shared/components/panels/landing-state.js +27 -0
  48. package/dist/shared/components/pipeline/PipelineEditorView.js +110 -92
  49. package/dist/shared/components/profile/AiMemoryCard.js +12 -10
  50. package/dist/shared/components/queue/OwnerAvatars.js +80 -41
  51. package/dist/shared/components/queue/QueueQuickFilters.js +52 -52
  52. package/dist/shared/components/queue/QueueWorklist.js +1050 -1026
  53. package/dist/shared/components/queue/group-sums.js +27 -0
  54. package/dist/shared/components/queue/live-state-aspect.js +9 -5
  55. package/dist/shared/components/widgets/ReviewListWidget.js +175 -154
  56. package/dist/shared/lib/back-closes.js +25 -0
  57. package/dist/shared/lib/display-prefs.js +60 -52
  58. package/dist/shared/lib/draft-store.js +71 -48
  59. package/dist/shared/lib/expression.js +53 -53
  60. package/dist/shared/lib/form-usage-beacon.js +7 -7
  61. package/dist/shared/lib/list-page-memory.js +63 -0
  62. package/dist/shared/lib/live.js +44 -44
  63. package/dist/shared/lib/money-input.js +45 -0
  64. package/dist/shared/lib/own-writes.js +76 -28
  65. package/dist/shared/lib/request-gate.js +110 -109
  66. package/dist/shared/lib/sanitize-html.js +10 -6
  67. package/dist/shared/lib/staged-row-labels.js +18 -0
  68. package/dist/shared/lib/validation-rules.js +34 -19
  69. package/package.json +1 -1
@@ -1,32 +1,33 @@
1
- import { jsxs as u, jsx as s } from "react/jsx-runtime";
2
- import { useQuery as S } from "@tanstack/react-query";
3
- import { ChevronDown as $e, Loader2 as B, AlertTriangle as ze, Search as He, X as Ye, Check as Ce } from "lucide-react";
4
- import { useState as $, useRef as I, useEffect as j, useLayoutEffect as We, useMemo as K } from "react";
5
- import { createPortal as je } from "react-dom";
6
- import { useNivaroClient as ae, useItemEditAuth as Xe, useStaleFieldReporter as Ge } from "../../context.js";
7
- import { get as R, post as Ve } from "../../lib/commands.js";
8
- import { compareByMatch as Ze } from "../../lib/picker-rank.js";
9
- import { useRecordReader as Re } from "../../lib/record-loader.js";
10
- import { useOnlineUsers as Qe } from "../../lib/use-online-users.js";
11
- import { SearchHighlight as Be } from "../SearchHighlight.js";
12
- import { UserAvatar as et } from "../UserAvatar.js";
13
- import { userOptionFilter as tt, cn as J } from "../../lib/utils.js";
14
- import { applyDisplayTemplate as k } from "./helpers.js";
15
- import { collidingIds as rt, disambiguators as nt } from "./option-disambiguate.js";
16
- import { usePickerMissReport as st } from "./picker-miss.js";
17
- import { useLatestSearch as it, narrowLocally as ot } from "./picker-search.js";
18
- function at(n) {
19
- return n.replace(/\(.*$/, "").trim().split(/\s+/).map((r) => r[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
1
+ import { jsxs as h, jsx as s } from "react/jsx-runtime";
2
+ import { useQuery as R } from "@tanstack/react-query";
3
+ import { ChevronDown as Qe, Loader2 as pe, AlertTriangle as wt, Search as kt, X as Nt, Check as Be } from "lucide-react";
4
+ import { useState as C, useRef as q, useEffect as _, useId as St, useLayoutEffect as et, useMemo as T } from "react";
5
+ import { createPortal as nt } from "react-dom";
6
+ import { useNivaroClient as Ce, useItemEditAuth as _t, useStaleFieldReporter as Lt } from "../../context.js";
7
+ import { get as H, post as $t } from "../../lib/commands.js";
8
+ import { compareByMatch as Et } from "../../lib/picker-rank.js";
9
+ import { useRecordReader as rt } from "../../lib/record-loader.js";
10
+ import { useOnlineUsers as qt } from "../../lib/use-online-users.js";
11
+ import { SearchHighlight as Rt } from "../SearchHighlight.js";
12
+ import { UserAvatar as Ct } from "../UserAvatar.js";
13
+ import { userOptionFilter as Dt, matchesAllTokens as At, cn as P } from "../../lib/utils.js";
14
+ import { applyDisplayTemplate as L } from "./helpers.js";
15
+ import { collidingIds as It, disambiguators as Kt, isNamelessLabel as Z, NAMELESS_LABEL as se } from "./option-disambiguate.js";
16
+ import { usePickerMissReport as jt } from "./picker-miss.js";
17
+ import { useLatestSearch as Ft, narrowLocally as Tt } from "./picker-search.js";
18
+ import { retryRelatedRead as ot, RelatedMissingLabel as st } from "./related-missing.js";
19
+ function Mt(o) {
20
+ return o.replace(/\(.*$/, "").trim().split(/\s+/).map((r) => r[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
20
21
  }
21
- function lt(n) {
22
- const [r, d] = $(null), y = {
23
- onMouseEnter: (g) => {
24
- if (!n) return;
25
- const p = g.currentTarget.getBoundingClientRect(), m = window.innerHeight - p.bottom < 80;
26
- d({ x: p.left, y: m ? p.top - 58 : p.bottom + 4 });
22
+ function Ot(o) {
23
+ const [r, p] = C(null), x = {
24
+ onMouseEnter: (v) => {
25
+ if (!o) return;
26
+ const y = v.currentTarget.getBoundingClientRect(), b = window.innerHeight - y.bottom < 80;
27
+ p({ x: y.left, y: b ? y.top - 58 : y.bottom + 4 });
27
28
  },
28
- onMouseLeave: () => d(null)
29
- }, _ = n && r ? je(
29
+ onMouseLeave: () => p(null)
30
+ }, D = o && r ? nt(
30
31
  /* @__PURE__ */ s(
31
32
  "div",
32
33
  {
@@ -37,176 +38,212 @@ function lt(n) {
37
38
  ),
38
39
  document.body
39
40
  ) : null;
40
- return { bind: y, tip: _ };
41
+ return { bind: x, tip: D };
41
42
  }
42
- function Le(n, r) {
43
- return n == null || n === "" || r == null || r === "" ? !1 : String(n) === String(r);
43
+ function tt(o, r) {
44
+ return o == null || o === "" || r == null || r === "" ? !1 : String(o) === String(r);
44
45
  }
45
- function dt({
46
- collection: n,
46
+ function Ut({
47
+ collection: o,
47
48
  value: r,
48
- onChange: d,
49
- disabled: y,
50
- placeholder: _,
51
- extraFilter: g,
52
- autoSelectSingle: p,
53
- optionSort: m,
54
- requiredParent: F,
55
- facets: o,
56
- fieldKey: C,
57
- narrowedBy: a,
58
- pinned: f,
59
- missPlacement: q,
60
- defaultOpen: Fe,
61
- onClose: le
49
+ onChange: p,
50
+ disabled: x,
51
+ placeholder: D,
52
+ extraFilter: v,
53
+ autoSelectSingle: y,
54
+ optionSort: b,
55
+ requiredParent: J,
56
+ facets: c,
57
+ fieldKey: A,
58
+ narrowedBy: l,
59
+ pinned: u,
60
+ missPlacement: I,
61
+ defaultOpen: it,
62
+ onClose: De
62
63
  }) {
63
- const T = ae(), de = Re(), [c, P] = $(Fe ?? !1), [v, ce] = $(""), z = I(le);
64
- z.current = le;
65
- const ue = I(c);
66
- j(() => {
64
+ const z = Ce(), Ae = rt(), [a, K] = C(it ?? !1), [d, ie] = C(""), ae = q(De);
65
+ ae.current = De;
66
+ const Ie = q(a);
67
+ _(() => {
68
+ var e;
69
+ Ie.current && !a && ((e = ae.current) == null || e.call(ae)), Ie.current = a;
70
+ }, [a]);
71
+ const [at, lt] = C(!1), M = Ft(d, at), Ke = q(null), Y = q(null), ge = q(null), Q = q(null), be = St(), [je, O] = C(-1), j = q(null), B = () => {
72
+ var t;
73
+ const e = Ke.current;
74
+ if (!e || document.activeElement === e) return;
75
+ e.focus({ preventScroll: !0 });
76
+ const n = e.value.length;
77
+ (t = e.setSelectionRange) == null || t.call(e, n, n);
78
+ };
79
+ _(() => {
80
+ a ? setTimeout(B, 30) : (ie(""), j.current = null);
81
+ }, [a]);
82
+ const he = () => {
67
83
  var e;
68
- ue.current && !c && ((e = z.current) == null || e.call(z)), ue.current = c;
69
- }, [c]);
70
- const [Te, Ee] = $(!1), L = it(v, Te), me = I(null), H = I(null);
71
- j(() => {
72
- c ? setTimeout(() => {
73
- var e;
74
- return (e = me.current) == null ? void 0 : e.focus();
75
- }, 30) : ce("");
76
- }, [c]), j(() => {
77
- if (!c) return;
78
- const e = (i) => {
79
- var l;
80
- const t = i.target;
81
- (l = t == null ? void 0 : t.closest) != null && l.call(t, "[data-nvr-combobox-panel]") || H.current && !H.current.contains(i.target) && P(!1);
84
+ K(!1), (e = Q.current) == null || e.focus();
85
+ };
86
+ _(() => {
87
+ if (!a) return;
88
+ const e = (n) => {
89
+ var S, $, oe;
90
+ if (n.key !== "Escape") return;
91
+ const t = document.activeElement;
92
+ (t === document.body || t && ((S = ge.current) != null && S.contains(t) || ($ = Y.current) != null && $.contains(t))) && (n.preventDefault(), n.stopPropagation(), K(!1), (oe = Q.current) == null || oe.focus());
93
+ };
94
+ return window.addEventListener("keydown", e, !0), () => window.removeEventListener("keydown", e, !0);
95
+ }, [a]), _(() => {
96
+ if (!a) return;
97
+ const e = (n) => {
98
+ var i, S;
99
+ const t = n.target;
100
+ !t || t === document.body || (i = t.closest) != null && i.call(t, "[data-nvr-combobox-panel]") || (S = Y.current) != null && S.contains(t) || K(!1);
101
+ };
102
+ return document.addEventListener("focusin", e), () => document.removeEventListener("focusin", e);
103
+ }, [a]), _(() => {
104
+ if (!a) return;
105
+ const e = (n) => {
106
+ var i;
107
+ const t = n.target;
108
+ (i = t == null ? void 0 : t.closest) != null && i.call(t, "[data-nvr-combobox-panel]") || Y.current && !Y.current.contains(n.target) && K(!1);
82
109
  };
83
110
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
84
- }, [c]);
85
- const [pe, ee] = $(null), [fe, Oe] = $(null);
86
- We(() => {
87
- if (!c) {
88
- ee(null);
111
+ }, [a]);
112
+ const [ye, xe] = C(null), [ve, ct] = C(null);
113
+ et(() => {
114
+ if (!a) {
115
+ xe(null);
89
116
  return;
90
117
  }
91
118
  const e = () => {
92
- const i = H.current;
93
- if (!i) return;
94
- const t = i.getBoundingClientRect(), l = i.closest('[role="dialog"]') ?? document.body;
95
- Oe(l);
96
- const Ne = window.innerHeight - t.bottom < 340 && t.top > window.innerHeight - t.bottom, ke = t.left, Se = Ne ? t.top - 4 : t.bottom + 4, _e = {
119
+ const n = Y.current;
120
+ if (!n) return;
121
+ const t = n.getBoundingClientRect(), i = n.closest('[role="dialog"]') ?? document.body;
122
+ ct(i);
123
+ const S = window.innerHeight - t.bottom < 340 && t.top > window.innerHeight - t.bottom, $ = t.left, oe = S ? t.top - 4 : t.bottom + 4, Ge = {
97
124
  minWidth: t.width,
98
125
  zIndex: 120,
99
- ...Ne ? { transform: "translateY(-100%)" } : {}
126
+ ...S ? { transform: "translateY(-100%)" } : {}
100
127
  };
101
- if (l === document.body)
102
- ee({ position: "fixed", left: ke, top: Se, ..._e });
128
+ if (i === document.body)
129
+ xe({ position: "fixed", left: $, top: oe, ...Ge });
103
130
  else {
104
- const qe = l.getBoundingClientRect();
105
- ee({ position: "absolute", left: ke - qe.left, top: Se - qe.top, ..._e });
131
+ const Ze = i.getBoundingClientRect();
132
+ xe({ position: "absolute", left: $ - Ze.left, top: oe - Ze.top, ...Ge });
106
133
  }
107
134
  };
108
135
  return e(), window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
109
136
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
110
137
  };
111
- }, [c]);
112
- const { data: te, isPending: Ie } = S({
113
- queryKey: ["col-meta", n],
114
- queryFn: () => T.request(R(`/collections/${n}`)).then((e) => e.data),
138
+ }, [a]);
139
+ const Fe = a && !!ye && !!ve;
140
+ et(() => {
141
+ Fe && document.activeElement === Q.current && B();
142
+ }, [Fe]);
143
+ const { data: we, isPending: dt } = R({
144
+ queryKey: ["col-meta", o],
145
+ queryFn: () => z.request(H(`/collections/${o}`)).then((e) => e.data),
115
146
  staleTime: 3e5,
116
147
  retry: !1
117
- }), [re, Ke] = $({}), { data: he = [] } = S({
118
- queryKey: ["collection-meta", n],
119
- queryFn: () => T.request(
120
- R(`/collections/${n}`)
148
+ }), [ke, ut] = C({}), { data: Te = [] } = R({
149
+ queryKey: ["collection-meta", o],
150
+ queryFn: () => z.request(
151
+ H(`/collections/${o}`)
121
152
  ).then(
122
153
  (e) => {
123
- var i;
124
- return ((i = e.data) == null ? void 0 : i.relations) ?? [];
154
+ var n;
155
+ return ((n = e.data) == null ? void 0 : n.relations) ?? [];
125
156
  }
126
157
  ),
127
- enabled: !!(o != null && o.length),
158
+ enabled: !!(c != null && c.length),
128
159
  staleTime: 10 * 6e4
129
- }), Pe = K(() => {
160
+ }), ft = T(() => {
130
161
  const e = {};
131
- for (const i of o ?? []) {
132
- const t = he.find(
133
- (l) => l.many_collection === n && l.many_field === i.field && !l.junction_field
162
+ for (const n of c ?? []) {
163
+ const t = Te.find(
164
+ (i) => i.many_collection === o && i.many_field === n.field && !i.junction_field
134
165
  );
135
- t != null && t.one_collection && (e[i.field] = t.one_collection);
166
+ t != null && t.one_collection && (e[n.field] = t.one_collection);
136
167
  }
137
168
  return e;
138
- }, [o, he, n]), E = n === "nivaro_users", Ue = Qe(E), ge = Xe().isAdmin, ne = K(() => {
169
+ }, [c, Te, o]), W = o === "nivaro_users", mt = qt(W), Me = _t().isAdmin, Ne = T(() => {
139
170
  const e = [];
140
- E && e.push(tt(ge)), g && e.push(g);
141
- for (const [i, t] of Object.entries(re))
142
- t != null && t !== "" && e.push({ [i]: { _eq: t } });
171
+ W && e.push(Dt(Me)), v && e.push(v);
172
+ for (const [n, t] of Object.entries(ke))
173
+ t != null && t !== "" && e.push({ [n]: { _eq: t } });
143
174
  if (e.length !== 0)
144
175
  return e.length === 1 ? e[0] : { _and: e };
145
- }, [g, re, ge]), Y = (te == null ? void 0 : te.display_template) ?? (E ? "{{first_name}} {{last_name}} ({{email}})" : null), b = K(() => {
146
- if (!Y) return;
147
- const e = [...Y.matchAll(/\{\{([\w.]+)\}\}/g)].map((i) => i[1]);
176
+ }, [v, ke, Me]), le = (we == null ? void 0 : we.display_template) ?? (W ? "{{first_name}} {{last_name}} ({{email}})" : null), w = T(() => {
177
+ if (!le) return;
178
+ const e = [...le.matchAll(/\{\{([\w.]+)\}\}/g)].map((n) => n[1]);
148
179
  if (e.length)
149
180
  return ["id", ...e].join(",");
150
- }, [Y]), N = ne ? JSON.stringify(ne) : void 0, U = m && !/^-?label$/.test(m) ? m : void 0, {
151
- data: h,
152
- isFetching: O,
153
- isPlaceholderData: be
154
- } = S({
181
+ }, [le]), E = Ne ? JSON.stringify(Ne) : void 0, V = b && !/^-?label$/.test(b) ? b : void 0, {
182
+ data: m,
183
+ isFetching: X,
184
+ isPlaceholderData: Oe
185
+ } = R({
155
186
  queryKey: [
156
187
  "relation-opts",
157
- n,
158
- L,
159
- N,
160
- b,
161
- U ?? ""
188
+ o,
189
+ M,
190
+ E,
191
+ w,
192
+ V ?? ""
162
193
  ],
163
- queryFn: () => T.request(
164
- R(`/items/${n}`, {
194
+ queryFn: () => z.request(
195
+ H(`/items/${o}`, {
165
196
  limit: 200,
166
197
  picker: "1",
167
- ...L ? { search: L } : {},
168
- ...N ? { filter: N } : {},
169
- ...b ? { fields: b } : {},
170
- ...U ? { sort: U } : {}
198
+ ...M.trim() ? { search: M.trim() } : {},
199
+ ...E ? { filter: E } : {},
200
+ ...w ? { fields: w } : {},
201
+ ...V ? { sort: V } : {}
171
202
  })
172
203
  ).then((e) => e.data ?? []),
173
204
  // Wait for the display template: it decides `fields`, and starting before
174
205
  // it lands sent the whole first page twice.
175
- enabled: c && !Ie,
176
- staleTime: N ? 0 : 3e4,
206
+ enabled: a && !dt,
207
+ staleTime: E ? 0 : 3e4,
177
208
  // A new SEARCH keeps the previous answer on screen (narrowed locally below)
178
209
  // instead of blanking the list behind a spinner. A changed filter, sort or
179
210
  // template never does — those rows may no longer be allowed.
180
- placeholderData: (e, i) => {
181
- const t = i == null ? void 0 : i.queryKey;
211
+ placeholderData: (e, n) => {
212
+ const t = n == null ? void 0 : n.queryKey;
182
213
  if (!(!e || !t))
183
- return t[1] === n && t[3] === N && t[4] === b && t[5] === (U ?? "") ? e : void 0;
214
+ return t[1] === o && t[3] === E && t[4] === w && t[5] === (V ?? "") ? e : void 0;
184
215
  }
185
216
  });
186
- j(() => Ee(O), [O]), st({
187
- placement: q,
188
- open: c,
189
- search: L,
190
- settled: !O && !be && h !== void 0,
191
- count: (h == null ? void 0 : h.length) ?? 0
217
+ _(() => lt(X), [X]), jt({
218
+ placement: I,
219
+ open: a,
220
+ search: M,
221
+ settled: !X && !Oe && m !== void 0,
222
+ count: (m == null ? void 0 : m.length) ?? 0
192
223
  });
193
- const { data: W, isLoading: Ae } = S({
194
- queryKey: ["relation-single", n, String(r), b],
195
- queryFn: () => de(n, r, b),
224
+ const {
225
+ data: ee,
226
+ isLoading: Ue,
227
+ error: pt,
228
+ isFetched: gt
229
+ } = R({
230
+ queryKey: ["relation-single", o, String(r), w],
231
+ queryFn: () => Ae(o, r, w),
196
232
  enabled: !!r,
197
- staleTime: 6e4
198
- }), x = (f == null ? void 0 : f.id) != null && f.id !== "" ? String(f.id) : null, { data: A } = S({
199
- queryKey: ["relation-single", n, x ?? "", b],
200
- queryFn: () => de(n, x, b).catch(
233
+ staleTime: 6e4,
234
+ retry: ot
235
+ }), bt = !!r && !Ue && gt && !ee, k = (u == null ? void 0 : u.id) != null && u.id !== "" ? String(u.id) : null, { data: F } = R({
236
+ queryKey: ["relation-single", o, k ?? "", w],
237
+ queryFn: () => Ae(o, k, w).catch(
201
238
  () => null
202
239
  ),
203
- enabled: !!x && c,
240
+ enabled: !!k && a,
204
241
  staleTime: 6e4
205
- }), Me = JSON.stringify(g ? { _and: [{ id: { _eq: r } }, g] } : { id: { _eq: r } }), { data: X } = S({
206
- queryKey: ["relation-avail", n, String(r), N],
207
- queryFn: () => T.request(
208
- R(`/items/${n}`, {
209
- filter: Me,
242
+ }), ht = JSON.stringify(v ? { _and: [{ id: { _eq: r } }, v] } : { id: { _eq: r } }), { data: ce } = R({
243
+ queryKey: ["relation-avail", o, String(r), E],
244
+ queryFn: () => z.request(
245
+ H(`/items/${o}`, {
246
+ filter: ht,
210
247
  picker: "1",
211
248
  limit: 1,
212
249
  fields: "id"
@@ -215,145 +252,208 @@ function dt({
215
252
  // The pinned option is offered OUTSIDE the option filter (a type's generic
216
253
  // item is excluded from the general list on purpose), so a value that IS
217
254
  // the pin is available by construction — never probe it, never flag it.
218
- enabled: !!r && !!W && String(r) !== x,
255
+ enabled: !!r && !!ee && String(r) !== k,
219
256
  staleTime: 3e4
220
- }), M = !!r && String(r) !== x && X !== void 0 && X.length === 0, G = I(null), se = I(!1), xe = `${n}|${N ?? ""}`, De = () => {
221
- se.current = !0, G.current = xe, d(null);
222
- }, V = r == null || r === "";
223
- j(() => {
224
- V || (se.current = !1);
225
- }, [V]), j(() => {
226
- if (!p || y || !V || se.current) return;
227
- const e = xe;
228
- G.current !== e && (G.current = e, T.request(
229
- R(`/items/${n}`, {
257
+ }), te = !!r && String(r) !== k && ce !== void 0 && ce.length === 0, de = q(null), Se = q(!1), Pe = `${o}|${E ?? ""}`, yt = () => {
258
+ Se.current = !0, de.current = Pe, p(null);
259
+ }, ue = r == null || r === "";
260
+ _(() => {
261
+ ue || (Se.current = !1);
262
+ }, [ue]), _(() => {
263
+ if (!y || x || !ue || Se.current) return;
264
+ const e = Pe;
265
+ de.current !== e && (de.current = e, z.request(
266
+ H(`/items/${o}`, {
230
267
  limit: 2,
231
268
  picker: "1",
232
269
  fields: "id",
233
- ...N ? { filter: N } : {}
270
+ ...E ? { filter: E } : {}
234
271
  })
235
- ).then((i) => {
236
- var l;
237
- const t = i.data ?? [];
238
- t.length === 1 && ((l = t[0]) == null ? void 0 : l.id) != null && d(t[0].id);
272
+ ).then((n) => {
273
+ var i;
274
+ const t = n.data ?? [];
275
+ t.length === 1 && ((i = t[0]) == null ? void 0 : i.id) != null && p(t[0].id);
239
276
  }).catch(() => {
240
- G.current = null;
277
+ de.current = null;
241
278
  }));
242
- }, [p, y, V, n, N]);
243
- const w = Y, ye = r && W ? k(w, W) : null, ie = !be && v === L, Z = K(
244
- () => ot(
245
- h ?? [],
246
- (e) => k(w, e) || `#${e.id}`,
279
+ }, [y, x, ue, o, E]);
280
+ const g = le, _e = r && ee ? L(g, ee) : null, Le = _e === null ? null : Z(_e) ? se : _e, U = !Oe && d === M, $e = T(
281
+ () => Tt(
282
+ m ?? [],
283
+ (e) => L(g, e) || `#${e.id}`,
247
284
  // The server also reads a joined code by its parts ("2026-NNO-POWER"
248
285
  // finds 2026-WEST-NNO-HE-POWERING, services/search-synonyms.ts), so
249
286
  // the list narrowed while that search is out does too.
250
- v.replace(/[-_/]+/g, " "),
251
- ie
287
+ d.replace(/[-_/]+/g, " "),
288
+ U
252
289
  ),
253
- [h, w, v, ie]
254
- ), Q = K(
255
- () => rt(h ?? [], (e) => k(w, e) || `#${e.id}`),
256
- [h, w]
257
- ), { data: D } = S({
258
- queryKey: ["relation-opts-dups", n, Q.join(",")],
259
- queryFn: () => T.request(
260
- R(`/items/${n}`, {
261
- limit: Q.length,
290
+ [m, g, d, U]
291
+ ), fe = T(
292
+ () => It(m ?? [], (e) => L(g, e) || `#${e.id}`),
293
+ [m, g]
294
+ ), { data: ne } = R({
295
+ queryKey: ["relation-opts-dups", o, fe.join(",")],
296
+ queryFn: () => z.request(
297
+ H(`/items/${o}`, {
298
+ limit: fe.length,
262
299
  picker: "1",
263
- filter: JSON.stringify({ id: { _in: Q } }),
300
+ filter: JSON.stringify({ id: { _in: fe } }),
264
301
  fields: "*"
265
302
  })
266
303
  ).then((e) => e.data ?? []),
267
- enabled: c && Q.length > 0 && !E,
304
+ enabled: a && fe.length > 0 && !W,
268
305
  staleTime: 6e4
269
- }), we = K(() => {
270
- if (!(D != null && D.length)) return /* @__PURE__ */ new Map();
306
+ }), He = T(() => {
307
+ if (!(ne != null && ne.length)) return /* @__PURE__ */ new Map();
271
308
  const e = new Map(
272
- (h ?? []).map((t) => [
309
+ (m ?? []).map((t) => [
273
310
  String(t.id),
274
- (k(w, t) || `#${t.id}`).trim().toLowerCase()
311
+ (L(g, t) || `#${t.id}`).trim().toLowerCase()
275
312
  ])
276
- ), i = /* @__PURE__ */ new Map();
277
- for (const t of D) {
278
- const l = e.get(String(t.id));
279
- l !== void 0 && i.set(l, [...i.get(l) ?? [], t]);
313
+ ), n = /* @__PURE__ */ new Map();
314
+ for (const t of ne) {
315
+ const i = e.get(String(t.id));
316
+ i !== void 0 && n.set(i, [...n.get(i) ?? [], t]);
280
317
  }
281
- return nt(
282
- [...i.values()],
283
- ((b == null ? void 0 : b.split(",")) ?? []).map((t) => t.split(".")[0])
318
+ return Kt(
319
+ [...n.values()],
320
+ ((w == null ? void 0 : w.split(",")) ?? []).map((t) => t.split(".")[0])
284
321
  );
285
- }, [D, h, w, b]), Je = !!r && Ae && !W, ve = lt(M), oe = Ge();
286
- return j(() => {
287
- !oe || !C || X === void 0 || oe(C, M);
288
- }, [oe, C, M, X]), F ? /* @__PURE__ */ u(
322
+ }, [ne, m, g, w]), xt = !!r && Ue && !ee, Je = Ot(te), ze = T(
323
+ () => (m ?? []).some((e) => !Z(L(g, e))),
324
+ [m, g]
325
+ ), re = T(
326
+ () => (V ? [...$e] : [...$e].sort(
327
+ (e, n) => Et(
328
+ L(g, e),
329
+ L(g, n),
330
+ d,
331
+ b === "-label"
332
+ )
333
+ )).filter((e) => !k || String(e.id) !== k).filter(
334
+ (e) => !ze || String(e.id) === String(r) || !Z(L(g, e))
335
+ ),
336
+ [$e, V, g, d, b, k, r, ze]
337
+ ), Ye = F && !Z(L(g, F)) ? L(g, F) : se, Ee = !!k && (!d.trim() || At(
338
+ `${F ? Ye : ""} ${(u == null ? void 0 : u.tag) ?? "Default"}`,
339
+ d.replace(/[-_/]+/g, " ")
340
+ )), G = Ee ? 1 : 0, N = G + re.length, f = je >= N ? N - 1 : je;
341
+ _(() => {
342
+ O(a && d.trim() ? G : -1);
343
+ }, [a, d, G]);
344
+ const qe = (e) => `${be}-opt-${e}`, We = () => {
345
+ const e = (F == null ? void 0 : F.id) ?? (u == null ? void 0 : u.id);
346
+ tt(r, e) || p(e), he();
347
+ }, Ve = (e) => {
348
+ tt(r, e.id) || p(e.id), he();
349
+ }, me = (e) => {
350
+ e < 0 || e >= N || (e < G ? We() : Ve(re[e - G]));
351
+ };
352
+ _(() => {
353
+ var n, t;
354
+ if (!a || f < 0) return;
355
+ const e = (n = ge.current) == null ? void 0 : n.querySelector(`[data-nav-index="${f}"]`);
356
+ (t = e == null ? void 0 : e.scrollIntoView) == null || t.call(e, { block: "nearest" });
357
+ }, [a, f]), _(() => {
358
+ const e = j.current;
359
+ if (e !== null) {
360
+ if (!a || e !== d) {
361
+ j.current = null;
362
+ return;
363
+ }
364
+ U && (j.current = null, f >= 0 ? me(f) : N === 1 && m !== void 0 && me(0));
365
+ }
366
+ }, [a, d, U, f, N]);
367
+ const Xe = (e) => {
368
+ var n;
369
+ e.key === "ArrowDown" ? (e.preventDefault(), N > 0 && O(f < 0 ? 0 : Math.min(f + 1, N - 1))) : e.key === "ArrowUp" ? (e.preventDefault(), N > 0 && O(f <= 0 ? 0 : f - 1)) : e.key === "Home" && N > 0 && !d ? (e.preventDefault(), O(0)) : e.key === "End" && N > 0 && !d ? (e.preventDefault(), O(N - 1)) : e.key === "Enter" ? (e.preventDefault(), d.trim() && !U ? j.current = d : f >= 0 ? me(f) : N === 1 && U && m !== void 0 && me(0)) : e.key === "Tab" && (K(!1), (n = Q.current) == null || n.focus());
370
+ }, vt = (e) => {
371
+ if (x) return;
372
+ const n = e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (a || e.key !== " ");
373
+ if (!a && (e.key === "ArrowDown" || e.key === "ArrowUp"))
374
+ e.preventDefault(), K(!0);
375
+ else if (n) {
376
+ e.preventDefault();
377
+ const t = e.key;
378
+ j.current = null, ie((i) => t === " " && (i === "" || i.endsWith(" ")) ? i : i + t), a ? B() : K(!0);
379
+ } else a && e.key === "Backspace" ? (e.preventDefault(), j.current = null, ie((t) => t.slice(0, -1)), B()) : a && (e.key === "Enter" || e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") && (Xe(e), B());
380
+ }, Re = Lt();
381
+ return _(() => {
382
+ !Re || !A || ce === void 0 || Re(A, te);
383
+ }, [Re, A, te, ce]), J ? /* @__PURE__ */ h(
289
384
  "button",
290
385
  {
291
386
  type: "button",
292
387
  disabled: !0,
293
388
  className: "flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-background px-3 text-sm text-left opacity-50 cursor-not-allowed",
294
389
  children: [
295
- /* @__PURE__ */ u("span", { className: "truncate text-muted-foreground", children: [
390
+ /* @__PURE__ */ h("span", { className: "truncate text-muted-foreground", children: [
296
391
  "Select ",
297
- F,
392
+ J,
298
393
  " first"
299
394
  ] }),
300
- /* @__PURE__ */ s($e, { className: "h-4 w-4 shrink-0 opacity-50" })
395
+ /* @__PURE__ */ s(Qe, { className: "h-4 w-4 shrink-0 opacity-50" })
301
396
  ]
302
397
  }
303
398
  ) : (
304
399
  // Stale tooltip binds on the WRAPPER: a disabled trigger button swallows
305
400
  // mouse events, so a locked-but-stale field would never show the hint.
306
- /* @__PURE__ */ u("div", { ref: H, className: "relative", ...ve.bind, children: [
307
- /* @__PURE__ */ u(
401
+ /* @__PURE__ */ h("div", { ref: Y, className: "relative", ...Je.bind, children: [
402
+ /* @__PURE__ */ h(
308
403
  "button",
309
404
  {
405
+ ref: Q,
310
406
  type: "button",
311
- disabled: y,
312
- onClick: () => P((e) => !e),
313
- className: J(
314
- "flex h-9 w-full items-center justify-between gap-2 rounded-md border bg-background px-3 text-sm text-left hover:bg-muted disabled:pointer-events-none disabled:opacity-50",
315
- M ? "border-amber-300 dark:border-amber-600" : "border-input"
407
+ disabled: x,
408
+ "aria-haspopup": "listbox",
409
+ "aria-expanded": a,
410
+ onClick: () => K((e) => !e),
411
+ onKeyDown: vt,
412
+ className: P(
413
+ "flex h-9 w-full items-center justify-between gap-2 rounded-md border bg-background px-3 text-sm text-left hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan/60 disabled:pointer-events-none disabled:opacity-50",
414
+ te ? "border-amber-300 dark:border-amber-600" : "border-input"
316
415
  ),
317
416
  children: [
318
- Je ? /* @__PURE__ */ s(B, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ u(
417
+ xt ? /* @__PURE__ */ s(pe, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ h(
319
418
  "span",
320
419
  {
321
- className: J(
420
+ className: P(
322
421
  "flex items-center gap-1.5 truncate min-w-0",
323
- !ye && "text-muted-foreground"
422
+ (!Le || Le === se) && "text-muted-foreground"
324
423
  ),
325
424
  children: [
326
- M && /* @__PURE__ */ s(ze, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
327
- /* @__PURE__ */ s("span", { className: "truncate", children: ye ?? _ ?? "Select…" })
425
+ te && /* @__PURE__ */ s(wt, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
426
+ bt ? /* @__PURE__ */ s(st, { error: pt, className: "truncate" }) : /* @__PURE__ */ s("span", { className: "truncate", children: Le ?? D ?? "Select…" })
328
427
  ]
329
428
  }
330
429
  ),
331
- /* @__PURE__ */ s($e, { className: "h-4 w-4 shrink-0 opacity-50" })
430
+ /* @__PURE__ */ s(Qe, { className: "h-4 w-4 shrink-0 opacity-50" })
332
431
  ]
333
432
  }
334
433
  ),
335
- ve.tip,
336
- c && pe && fe && je(
337
- /* @__PURE__ */ u(
434
+ Je.tip,
435
+ a && ye && ve && nt(
436
+ /* @__PURE__ */ h(
338
437
  "div",
339
438
  {
439
+ ref: ge,
340
440
  "data-nvr-combobox-panel": "",
341
- style: pe,
342
- className: J(
441
+ style: ye,
442
+ className: P(
343
443
  "nvr-pop-in rounded-md border border-border bg-popover shadow-md",
344
- o != null && o.length ? "w-[560px] max-w-[92vw]" : "min-w-[240px] w-max max-w-[360px]"
444
+ c != null && c.length ? "w-[560px] max-w-[92vw]" : "min-w-[240px] w-max max-w-[360px]"
345
445
  ),
346
446
  children: [
347
- !!(o != null && o.length) && /* @__PURE__ */ s("div", { className: "grid grid-cols-2 gap-2 border-b border-border bg-slate-50/60 p-2 dark:bg-muted/40", children: o.map((e) => {
348
- const i = Pe[e.field];
349
- return i ? /* @__PURE__ */ u("div", { children: [
447
+ !!(c != null && c.length) && /* @__PURE__ */ s("div", { className: "grid grid-cols-2 gap-2 border-b border-border bg-slate-50/60 p-2 dark:bg-muted/40", children: c.map((e) => {
448
+ const n = ft[e.field];
449
+ return n ? /* @__PURE__ */ h("div", { children: [
350
450
  /* @__PURE__ */ s("p", { className: "mb-0.5 text-[10px] font-medium uppercase tracking-wide text-slate-400", children: e.label ?? e.field }),
351
451
  /* @__PURE__ */ s(
352
- dt,
452
+ Ut,
353
453
  {
354
- collection: i,
355
- value: re[e.field] ?? null,
356
- onChange: (t) => Ke((l) => ({ ...l, [e.field]: t })),
454
+ collection: n,
455
+ value: ke[e.field] ?? null,
456
+ onChange: (t) => ut((i) => ({ ...i, [e.field]: t })),
357
457
  placeholder: "Any",
358
458
  optionSort: e.sort,
359
459
  extraFilter: e.filter
@@ -361,142 +461,157 @@ function dt({
361
461
  )
362
462
  ] }, e.field) : null;
363
463
  }) }),
364
- /* @__PURE__ */ u("div", { className: "flex items-center border-b px-3", children: [
365
- /* @__PURE__ */ s(He, { className: "mr-2 h-4 w-4 shrink-0 opacity-50" }),
464
+ /* @__PURE__ */ h("div", { className: "flex items-center border-b px-3", children: [
465
+ /* @__PURE__ */ s(kt, { className: "mr-2 h-4 w-4 shrink-0 opacity-50" }),
366
466
  /* @__PURE__ */ s(
367
467
  "input",
368
468
  {
369
- ref: me,
370
- value: v,
371
- onChange: (e) => ce(e.target.value),
469
+ ref: Ke,
470
+ value: d,
471
+ onChange: (e) => {
472
+ j.current = null, ie(e.target.value);
473
+ },
474
+ onKeyDown: Xe,
475
+ role: "combobox",
476
+ "aria-expanded": !0,
477
+ "aria-autocomplete": "list",
478
+ "aria-controls": `${be}-list`,
479
+ "aria-activedescendant": f >= 0 ? qe(f) : void 0,
372
480
  placeholder: "Search…",
373
481
  className: "flex h-9 w-full bg-transparent py-3 text-[13px] outline-none placeholder:text-muted-foreground"
374
482
  }
375
483
  ),
376
- O && h !== void 0 && /* @__PURE__ */ s(
377
- B,
484
+ X && m !== void 0 && /* @__PURE__ */ s(
485
+ pe,
378
486
  {
379
487
  "data-picker-searching": !0,
380
488
  className: "ml-2 h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"
381
489
  }
382
490
  )
383
491
  ] }),
384
- /* @__PURE__ */ u("div", { className: "max-h-52 overflow-y-auto py-1", children: [
385
- !!r && !y && /* @__PURE__ */ u(
492
+ /* @__PURE__ */ h("div", { id: `${be}-list`, role: "listbox", className: "max-h-52 overflow-y-auto py-1", children: [
493
+ !!r && !x && /* @__PURE__ */ h(
386
494
  "button",
387
495
  {
388
496
  type: "button",
497
+ tabIndex: -1,
389
498
  onClick: () => {
390
- De(), P(!1);
499
+ yt(), he();
391
500
  },
392
501
  className: "flex w-full items-center gap-2 px-3 py-1.5 text-[13px] text-slate-500 hover:bg-muted border-b border-slate-100 dark:text-slate-400 dark:border-border",
393
502
  children: [
394
- /* @__PURE__ */ s(Ye, { className: "h-3.5 w-3.5 text-slate-400" }),
503
+ /* @__PURE__ */ s(Nt, { className: "h-3.5 w-3.5 text-slate-400" }),
395
504
  "Clear selection"
396
505
  ]
397
506
  }
398
507
  ),
399
- x && /* @__PURE__ */ u(
508
+ Ee && /* @__PURE__ */ h(
400
509
  "button",
401
510
  {
402
511
  type: "button",
512
+ tabIndex: -1,
513
+ id: qe(0),
514
+ role: "option",
515
+ "aria-selected": String(r) === k,
516
+ "data-nav-index": 0,
403
517
  "data-nvr-pinned-option": !0,
404
- onClick: () => {
405
- const e = (A == null ? void 0 : A.id) ?? (f == null ? void 0 : f.id);
406
- Le(r, e) || d(e), P(!1);
407
- },
408
- className: "flex w-full items-center gap-2 border-b border-slate-100 bg-nvr-cyan/5 px-3 py-1.5 text-left text-[13px] hover:bg-nvr-cyan/10 dark:border-border",
518
+ onClick: We,
519
+ onMouseMove: () => f !== 0 && O(0),
520
+ className: P(
521
+ "flex w-full items-center gap-2 border-b border-slate-100 px-3 py-1.5 text-left text-[13px] hover:bg-nvr-cyan/10 dark:border-border",
522
+ f === 0 ? "bg-nvr-cyan/10" : "bg-nvr-cyan/5"
523
+ ),
409
524
  children: [
410
525
  /* @__PURE__ */ s(
411
526
  "div",
412
527
  {
413
- className: J(
528
+ className: P(
414
529
  "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",
415
- String(r) === x ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
530
+ String(r) === k ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
416
531
  ),
417
- children: String(r) === x && /* @__PURE__ */ s(Ce, { className: "h-2.5 w-2.5 text-white" })
532
+ children: String(r) === k && /* @__PURE__ */ s(Be, { className: "h-2.5 w-2.5 text-white" })
418
533
  }
419
534
  ),
420
- /* @__PURE__ */ s("span", { className: "min-w-0 flex-1 truncate", children: A ? k(w, A) || `#${x}` : `#${x}` }),
421
- /* @__PURE__ */ s("span", { className: "shrink-0 rounded bg-nvr-cyan/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-slate-700 dark:text-foreground", children: (f == null ? void 0 : f.tag) ?? "Default" })
535
+ /* @__PURE__ */ s("span", { className: "min-w-0 flex-1 truncate", children: F === void 0 ? "Loading…" : Ye }),
536
+ /* @__PURE__ */ s("span", { className: "shrink-0 rounded bg-nvr-cyan/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-slate-700 dark:text-foreground", children: (u == null ? void 0 : u.tag) ?? "Default" })
422
537
  ]
423
538
  }
424
539
  ),
425
- h === void 0 && O ? /* @__PURE__ */ s("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ s(B, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : Z.length === 0 && !ie ? /* @__PURE__ */ s("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: "Searching…" }) : Z.length === 0 ? a && a.labels.length > 0 && !v.trim() ? /* @__PURE__ */ u("div", { className: "px-3 py-2 text-[12px] leading-5 text-muted-foreground", children: [
426
- /* @__PURE__ */ u("p", { children: [
540
+ m === void 0 && X ? /* @__PURE__ */ s("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ s(pe, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : re.length === 0 && !U ? /* @__PURE__ */ s("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: "Searching…" }) : re.length === 0 ? Ee && d.trim() ? null : l && l.labels.length > 0 && !d.trim() ? /* @__PURE__ */ h("div", { className: "px-3 py-2 text-[12px] leading-5 text-muted-foreground", children: [
541
+ /* @__PURE__ */ h("p", { children: [
427
542
  "No options for",
428
543
  " ",
429
- /* @__PURE__ */ s("span", { className: "font-medium text-foreground", children: a.labels.join(" · ") }),
430
- a.onClear ? " — clear one to widen the list:" : "."
544
+ /* @__PURE__ */ s("span", { className: "font-medium text-foreground", children: l.labels.join(" · ") }),
545
+ l.onClear ? " — clear one to widen the list:" : ". Change it, or ask an administrator to add options for it."
431
546
  ] }),
432
- a.onClear && /* @__PURE__ */ s("div", { className: "mt-1.5 flex flex-wrap gap-1.5", children: a.keys.map(
433
- (e, i) => a.clearable && !a.clearable.includes(e) ? null : /* @__PURE__ */ u(
547
+ l.onClear && /* @__PURE__ */ s("div", { className: "mt-1.5 flex flex-wrap gap-1.5", children: l.keys.map(
548
+ (e, n) => l.clearable && !l.clearable.includes(e) ? null : /* @__PURE__ */ h(
434
549
  "button",
435
550
  {
436
551
  type: "button",
437
552
  onClick: (t) => {
438
- var l;
439
- t.stopPropagation(), (l = a.onClear) == null || l.call(a, e);
553
+ var i;
554
+ t.stopPropagation(), (i = l.onClear) == null || i.call(l, e);
440
555
  },
441
556
  className: "rounded-md border border-border bg-background px-2 py-0.5 text-[11.5px] font-medium text-foreground transition-colors duration-150 hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan",
442
557
  children: [
443
558
  "Clear ",
444
- a.labels[i] ?? e
559
+ l.labels[n] ?? e
445
560
  ]
446
561
  },
447
562
  e
448
563
  )
449
564
  ) })
450
- ] }) : /* @__PURE__ */ s("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: v.trim() ? `No results for “${v.trim()}”` : "No results" }) : (U ? [...Z] : [...Z].sort(
451
- (e, i) => Ze(
452
- k(w, e),
453
- k(w, i),
454
- v,
455
- m === "-label"
456
- )
457
- )).filter((e) => !x || String(e.id) !== x).map((e) => {
458
- const i = k(w, e) || `#${e.id}`, t = String(e.id) === String(r);
459
- return /* @__PURE__ */ u(
565
+ ] }) : /* @__PURE__ */ s("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: d.trim() ? `No results for “${d.trim()}”` : "No results" }) : re.map((e, n) => {
566
+ const t = L(g, e), i = Z(t) ? se : t, S = String(e.id) === String(r), $ = n + G;
567
+ return /* @__PURE__ */ h(
460
568
  "button",
461
569
  {
462
570
  type: "button",
463
- onClick: () => {
464
- Le(r, e.id) || d(e.id), P(!1);
465
- },
466
- className: "flex w-full items-center gap-2 px-3 py-1.5 text-[13px] text-left hover:bg-muted",
571
+ tabIndex: -1,
572
+ id: qe($),
573
+ role: "option",
574
+ "aria-selected": S,
575
+ "data-nav-index": $,
576
+ onClick: () => Ve(e),
577
+ onMouseMove: () => f !== $ && O($),
578
+ className: P(
579
+ "flex w-full items-center gap-2 px-3 py-1.5 text-[13px] text-left hover:bg-muted",
580
+ f === $ && "bg-muted"
581
+ ),
467
582
  children: [
468
583
  /* @__PURE__ */ s(
469
584
  "div",
470
585
  {
471
- className: J(
586
+ className: P(
472
587
  "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",
473
- t ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
588
+ S ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
474
589
  ),
475
- children: t && /* @__PURE__ */ s(Ce, { className: "h-2.5 w-2.5 text-white" })
590
+ children: S && /* @__PURE__ */ s(Be, { className: "h-2.5 w-2.5 text-white" })
476
591
  }
477
592
  ),
478
- E && /* @__PURE__ */ s(
479
- et,
593
+ W && /* @__PURE__ */ s(
594
+ Ct,
480
595
  {
481
596
  userId: e.id,
482
597
  className: "h-4 w-4",
483
- fallback: /* @__PURE__ */ s("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-nvr-cyan/20 text-[8px] font-bold text-nvr-navy dark:text-nvr-cyan", children: at(i) })
598
+ fallback: /* @__PURE__ */ s("span", { className: "flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-nvr-cyan/20 text-[8px] font-bold text-nvr-navy dark:text-nvr-cyan", children: Mt(i) })
484
599
  }
485
600
  ),
486
- E && Ue.has(String(e.id).toUpperCase()) && /* @__PURE__ */ s(
601
+ W && mt.has(String(e.id).toUpperCase()) && /* @__PURE__ */ s(
487
602
  "span",
488
603
  {
489
604
  className: "h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",
490
605
  "data-tip": "Online now"
491
606
  }
492
607
  ),
493
- /* @__PURE__ */ s(Be, { text: i, query: v }),
494
- we.has(String(e.id)) && /* @__PURE__ */ s(
608
+ /* @__PURE__ */ s(Rt, { text: i, query: d }),
609
+ He.has(String(e.id)) && /* @__PURE__ */ s(
495
610
  "span",
496
611
  {
497
612
  className: "ml-auto max-w-[45%] shrink-0 truncate pl-2 text-[11.5px] text-muted-foreground",
498
613
  "data-option-detail": !0,
499
- children: we.get(String(e.id))
614
+ children: He.get(String(e.id))
500
615
  }
501
616
  )
502
617
  ]
@@ -505,107 +620,109 @@ function dt({
505
620
  );
506
621
  })
507
622
  ] }),
508
- !O && /* @__PURE__ */ s(
509
- ct,
623
+ !X && /* @__PURE__ */ s(
624
+ Pt,
510
625
  {
511
- collection: n,
512
- search: L,
513
- filter: ne,
514
- narrowedLabels: (a == null ? void 0 : a.labels) ?? [],
515
- auto: (h ?? []).length === 0 && !!L
626
+ collection: o,
627
+ search: M,
628
+ filter: Ne,
629
+ narrowedLabels: (l == null ? void 0 : l.labels) ?? [],
630
+ auto: (m ?? []).length === 0 && !!M
516
631
  }
517
632
  )
518
633
  ]
519
634
  }
520
635
  ),
521
- fe
636
+ ve
522
637
  )
523
638
  ] })
524
639
  );
525
640
  }
526
- function ct({
527
- collection: n,
641
+ function Pt({
642
+ collection: o,
528
643
  search: r,
529
- filter: d,
530
- narrowedLabels: y,
531
- auto: _
644
+ filter: p,
645
+ narrowedLabels: x,
646
+ auto: D
532
647
  }) {
533
- const g = ae(), [p, m] = $(!1), F = d ? JSON.stringify(d) : "", { data: o, isFetching: C } = S({
534
- queryKey: ["picker-narrowing", n, r, F],
535
- queryFn: () => g.request(
536
- Ve("/picker-narrowing", { collection: n, search: r, filter: d ?? null })
537
- ).then((q) => q.data),
538
- enabled: p || _,
648
+ const v = Ce(), [y, b] = C(!1), J = p ? JSON.stringify(p) : "", { data: c, isFetching: A } = R({
649
+ queryKey: ["picker-narrowing", o, r, J],
650
+ queryFn: () => v.request(
651
+ $t("/picker-narrowing", { collection: o, search: r, filter: p ?? null })
652
+ ).then((I) => I.data),
653
+ enabled: y || D,
539
654
  staleTime: 3e4,
540
655
  retry: !1
541
656
  });
542
- if (!p && !_)
657
+ if (!y && !D)
543
658
  return /* @__PURE__ */ s(
544
659
  "button",
545
660
  {
546
661
  type: "button",
547
- onClick: (q) => {
548
- q.stopPropagation(), m(!0);
662
+ onClick: (I) => {
663
+ I.stopPropagation(), b(!0);
549
664
  },
550
665
  className: "w-full border-t border-border px-3 py-1.5 text-left text-[11px] text-muted-foreground hover:text-foreground",
551
666
  "data-picker-narrowing-ask": !0,
552
667
  children: "Missing something?"
553
668
  }
554
669
  );
555
- if (C && !o)
670
+ if (A && !c)
556
671
  return /* @__PURE__ */ s("p", { className: "border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground", children: "Checking what narrows this list…" });
557
- if (!o) return null;
558
- const a = [], f = r ? `match “${r}”` : "exist";
559
- return o.by_field_filter > 0 && a.push(
560
- `${o.by_field_filter.toLocaleString()} more ${f} but this field only offers ${y.length ? `records that fit ${y.join(" · ")}` : "records its filter allows"}.`
561
- ), o.by_exclusions > 0 && a.push(
562
- `${o.by_exclusions.toLocaleString()} ${o.by_exclusions === 1 ? "is" : "are"} hidden from pickers by an admin.`
563
- ), o.scopes.length > 0 && a.push(`Your ${o.scopes.join(", ")} access narrows what you can pick here.`), o.row_filter && a.push("Your role only sees some of these records."), a.length === 0 && a.push(
672
+ if (!c) return null;
673
+ const l = [], u = r ? `match “${r}”` : "exist";
674
+ return c.by_field_filter > 0 && l.push(
675
+ `${c.by_field_filter.toLocaleString()} more ${u} but this field only offers ${x.length ? `records that fit ${x.join(" · ")}` : "records its filter allows"}.`
676
+ ), c.by_exclusions > 0 && l.push(
677
+ `${c.by_exclusions.toLocaleString()} ${c.by_exclusions === 1 ? "is" : "are"} hidden from pickers by an admin.`
678
+ ), c.scopes.length > 0 && l.push(`Your ${c.scopes.join(", ")} access narrows what you can pick here.`), c.row_filter && l.push("Your role only sees some of these records."), l.length === 0 && l.push(
564
679
  r ? `Nothing else you can see matches “${r}”.` : "Nothing narrows this list — every record you can see is offered."
565
680
  ), /* @__PURE__ */ s(
566
681
  "div",
567
682
  {
568
683
  className: "space-y-0.5 border-t border-border px-3 py-1.5 text-[11px] leading-4 text-muted-foreground",
569
684
  "data-picker-narrowing": !0,
570
- "data-picker-narrowing-field": o.by_field_filter,
571
- "data-picker-narrowing-excluded": o.by_exclusions,
572
- children: a.map((q) => /* @__PURE__ */ s("p", { children: q }, q))
685
+ "data-picker-narrowing-field": c.by_field_filter,
686
+ "data-picker-narrowing-excluded": c.by_exclusions,
687
+ children: l.map((I) => /* @__PURE__ */ s("p", { children: I }, I))
573
688
  }
574
689
  );
575
690
  }
576
- function Ct({
577
- collection: n,
691
+ function ln({
692
+ collection: o,
578
693
  id: r,
579
- displayTemplate: d
694
+ displayTemplate: p
580
695
  }) {
581
- const y = ae(), _ = Re(), g = n === "nivaro_files" || n === "directus_files", p = (() => {
582
- if (!d || !d.includes(".")) return null;
583
- const o = [...d.matchAll(/\{\{([^}]+)\}\}/g)].map((C) => C[1].trim());
584
- return o.length > 0 ? ["id", ...o].join(",") : null;
585
- })(), { data: m, isLoading: F } = S({
586
- queryKey: ["relation-single", n, String(r), p ?? ""],
587
- queryFn: () => g ? (
696
+ const x = Ce(), D = rt(), v = o === "nivaro_files" || o === "directus_files", y = (() => {
697
+ if (!p || !p.includes(".")) return null;
698
+ const l = [...p.matchAll(/\{\{([^}]+)\}\}/g)].map((u) => u[1].trim());
699
+ return l.length > 0 ? ["id", ...l].join(",") : null;
700
+ })(), { data: b, isLoading: J, error: c } = R({
701
+ queryKey: ["relation-single", o, String(r), y ?? ""],
702
+ queryFn: () => v ? (
588
703
  // The file's row, not its bytes: GET /files/:id downloads the whole
589
704
  // file (twice with the retry, 404 when storage lost it) only to read
590
705
  // its name, and a missing object left the raw id as the label.
591
- y.request(
592
- R(`/files/${encodeURIComponent(String(r))}/meta`)
593
- ).then((o) => o.data)
594
- ) : _(n, r, p),
595
- enabled: !!r && !!n,
596
- staleTime: 6e4
706
+ x.request(
707
+ H(`/files/${encodeURIComponent(String(r))}/meta`)
708
+ ).then((l) => l.data)
709
+ ) : D(o, r, y),
710
+ enabled: !!r && !!o,
711
+ staleTime: 6e4,
712
+ retry: ot
597
713
  });
598
- if (F) return /* @__PURE__ */ s(B, { className: "h-3 w-3 animate-spin text-slate-400" });
599
- if (!m) return /* @__PURE__ */ s("span", { children: String(r ?? "") });
600
- if (g) {
601
- const o = m.title || m.filename_download || m.filename_disk || String(r);
602
- return /* @__PURE__ */ s("span", { children: o });
714
+ if (J) return /* @__PURE__ */ s(pe, { className: "h-3 w-3 animate-spin text-slate-400" });
715
+ if (!b) return r == null || r === "" ? null : /* @__PURE__ */ s(st, { error: c });
716
+ if (v) {
717
+ const l = b.title || b.filename_download || b.filename_disk || String(r);
718
+ return /* @__PURE__ */ s("span", { children: l });
603
719
  }
604
- return /* @__PURE__ */ s("span", { children: k(d, m) });
720
+ const A = L(p, b);
721
+ return Z(A) ? /* @__PURE__ */ s("span", { className: "italic text-muted-foreground", children: se }) : /* @__PURE__ */ s("span", { children: A });
605
722
  }
606
723
  export {
607
- Ct as RelatedItemLabel,
608
- dt as RelationCombobox,
609
- Le as isSamePick,
610
- lt as useStaleTip
724
+ ln as RelatedItemLabel,
725
+ Ut as RelationCombobox,
726
+ tt as isSamePick,
727
+ Ot as useStaleTip
611
728
  };