@nivaro/react 0.3.122 → 0.3.123

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.
@@ -1,284 +1,284 @@
1
- import { jsx as n, jsxs as p } from "react/jsx-runtime";
2
- import { useQuery as O } from "@tanstack/react-query";
3
- import { ChevronDown as fe, Loader2 as we, AlertTriangle as Ue, X as _e, Check as Ne, Mail as st } from "lucide-react";
4
- import { useState as Q, useRef as Ce, useEffect as qe } from "react";
5
- import { useNivaroClient as Oe, useItemEditAuth as Pe, useDrilldown as it } from "../../context.js";
6
- import { parseAllowedCollections as at } from "../../lib/allowed-collections.js";
1
+ import { jsx as n, jsxs as h } from "react/jsx-runtime";
2
+ import { useQuery as q } from "@tanstack/react-query";
3
+ import { ChevronDown as he, Loader2 as Ce, AlertTriangle as Ie, X as qe, Check as Oe, Mail as at } from "lucide-react";
4
+ import { useState as H, useRef as Le, useEffect as Fe } from "react";
5
+ import { useNivaroClient as Te, useItemEditAuth as De, useDrilldown as ot } from "../../context.js";
6
+ import { parseAllowedCollections as ct } from "../../lib/allowed-collections.js";
7
7
  import { get as $ } from "../../lib/commands.js";
8
- import { pickerOptionsMeta as ot } from "../../lib/live-pickers.js";
9
- import { useOptionBadges as ct } from "../../lib/picker-badges.js";
10
- import { compareByMatch as Ie } from "../../lib/picker-rank.js";
11
- import { useRecordReader as dt } from "../../lib/record-loader.js";
12
- import { useOnlineUsers as De } from "../../lib/use-online-users.js";
13
- import { cn as Z, userOptionFilter as Me, matchesAllTokens as ut } from "../../lib/utils.js";
14
- import { UserAvatar as Ee } from "../UserAvatar.js";
15
- import { RecordPickerBadges as mt, PickerBadgeList as ft } from "./PickerBadges.js";
16
- import { Command as Je, CommandInput as ze, CommandList as Be, CommandEmpty as Ge, CommandGroup as Le, CommandItem as Fe } from "../ui/command.js";
17
- import { Popover as Ve, PopoverTrigger as Re, PopoverContent as We } from "../ui/popover.js";
18
- import { applyDisplayTemplate as pe } from "./helpers.js";
19
- import { useM2MStaging as Ze } from "./M2MStagingContext.js";
20
- import { onlyCloseMatches as pt } from "./picker-search.js";
21
- import { useStaleTip as ht, RelatedItemLabel as ue } from "./RelationCombobox.js";
22
- function Qe(t) {
23
- return t.replace(/\(.*$/, "").trim().split(/\s+/).map((l) => l[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
8
+ import { pickerOptionsMeta as dt } from "../../lib/live-pickers.js";
9
+ import { useOptionBadges as ut } from "../../lib/picker-badges.js";
10
+ import { compareByMatch as Me } from "../../lib/picker-rank.js";
11
+ import { useRecordReader as mt } from "../../lib/record-loader.js";
12
+ import { useOnlineUsers as Ee } from "../../lib/use-online-users.js";
13
+ import { cn as X, userOptionFilter as Je, matchesAllTokens as ft } from "../../lib/utils.js";
14
+ import { UserAvatar as ze } from "../UserAvatar.js";
15
+ import { RecordPickerBadges as pt, PickerBadgeList as ht } from "./PickerBadges.js";
16
+ import { Command as Be, CommandInput as Ge, CommandList as Re, CommandEmpty as Ve, CommandGroup as $e, CommandItem as Ke } from "../ui/command.js";
17
+ import { Popover as We, PopoverTrigger as Ze, PopoverContent as Qe } from "../ui/popover.js";
18
+ import { applyDisplayTemplate as ye } from "./helpers.js";
19
+ import { useM2MStaging as Xe } from "./M2MStagingContext.js";
20
+ import { onlyCloseMatches as yt } from "./picker-search.js";
21
+ import { useStaleTip as bt, RelatedItemLabel as me } from "./RelationCombobox.js";
22
+ function He(t) {
23
+ return t.replace(/\(.*$/, "").trim().split(/\s+/).map((s) => s[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
24
24
  }
25
- function ie(t) {
26
- return at(t == null ? void 0 : t.one_allowed_collections);
25
+ function oe(t) {
26
+ return ct(t == null ? void 0 : t.one_allowed_collections);
27
27
  }
28
- const yt = /^m2a:([A-Za-z_][A-Za-z0-9_]*):(.+)$/;
29
- function Te(t, l) {
30
- return `m2a:${t}:${String(l)}`;
28
+ const xt = /^m2a:([A-Za-z_][A-Za-z0-9_]*):(.+)$/;
29
+ function be(t, s) {
30
+ return `m2a:${t}:${String(s)}`;
31
31
  }
32
- function me(t) {
32
+ function fe(t) {
33
33
  if (typeof t != "string") return null;
34
- const l = t.match(yt);
35
- return l ? { collection: l[1], id: l[2] } : null;
34
+ const s = t.match(xt);
35
+ return s ? { collection: s[1], id: s[2] } : null;
36
36
  }
37
- function bt(t) {
37
+ function gt(t) {
38
38
  if (!t || t.one_collection) return [];
39
- const l = ie(t);
40
- return l.length < 2 ? [] : l.filter((d) => d !== "directus_users" && d !== "nivaro_users");
39
+ const s = oe(t);
40
+ return s.length < 2 ? [] : s.filter((d) => d !== "directus_users" && d !== "nivaro_users");
41
41
  }
42
- function Xe(t, l, d, o) {
43
- const c = bt(l), { data: v } = O({
44
- queryKey: ["m2a-extra-options", c.join(",")],
42
+ function Ye(t, s, d, a) {
43
+ const o = gt(s), { data: v } = q({
44
+ queryKey: ["m2a-extra-options", o.join(",")],
45
45
  queryFn: async () => {
46
46
  const f = [];
47
- for (const m of c) {
48
- const [L, r] = await Promise.all([
49
- t.request($(`/collections/${m}`)).then((h) => h.data).catch(() => null),
50
- t.request($(`/items/${m}`, { limit: 500 })).then((h) => h.data ?? []).catch(() => [])
47
+ for (const m of o) {
48
+ const [O, r] = await Promise.all([
49
+ t.request($(`/collections/${m}`)).then((y) => y.data).catch(() => null),
50
+ t.request($(`/items/${m}`, { limit: 500 })).then((y) => y.data ?? []).catch(() => [])
51
51
  ]);
52
- for (const h of r)
52
+ for (const y of r)
53
53
  f.push({
54
- token: Te(m, h.id),
54
+ token: be(m, y.id),
55
55
  collection: m,
56
- label: pe((L == null ? void 0 : L.display_template) ?? null, h)
56
+ label: ye((O == null ? void 0 : O.display_template) ?? null, y)
57
57
  });
58
58
  }
59
59
  return f;
60
60
  },
61
- enabled: o && c.length > 0,
61
+ enabled: a && o.length > 0,
62
62
  staleTime: 6e4
63
- }), x = d.trim().toLowerCase();
64
- return (v ?? []).filter((f) => !x || f.label.toLowerCase().includes(x)).sort((f, m) => f.label.localeCompare(m.label)).slice(0, 25);
63
+ }), g = d.trim().toLowerCase();
64
+ return (v ?? []).filter((f) => !g || f.label.toLowerCase().includes(g)).sort((f, m) => f.label.localeCompare(m.label)).slice(0, 25);
65
65
  }
66
- function He({
66
+ function et({
67
67
  options: t,
68
- isSelected: l,
68
+ isSelected: s,
69
69
  onPick: d,
70
- round: o
70
+ round: a
71
71
  }) {
72
- return t.length === 0 ? null : /* @__PURE__ */ n(Le, { heading: "External emails", "data-m2a-extra-options": "", children: t.map((c) => {
73
- const v = l(c.token);
74
- return /* @__PURE__ */ p(
75
- Fe,
72
+ return t.length === 0 ? null : /* @__PURE__ */ n($e, { heading: "External emails", "data-m2a-extra-options": "", children: t.map((o) => {
73
+ const v = s(o.token);
74
+ return /* @__PURE__ */ h(
75
+ Ke,
76
76
  {
77
- value: c.token,
78
- onSelect: () => d(c.token),
77
+ value: o.token,
78
+ onSelect: () => d(o.token),
79
79
  className: "flex items-center gap-2 text-[12px]",
80
80
  children: [
81
81
  /* @__PURE__ */ n(
82
82
  "div",
83
83
  {
84
- className: Z(
84
+ className: X(
85
85
  "flex h-4 w-4 shrink-0 items-center justify-center border transition-colors",
86
- o ? "rounded-full" : "rounded",
86
+ a ? "rounded-full" : "rounded",
87
87
  v ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
88
88
  ),
89
- children: v && /* @__PURE__ */ n(Ne, { className: "h-2.5 w-2.5 text-white" })
89
+ children: v && /* @__PURE__ */ n(Oe, { className: "h-2.5 w-2.5 text-white" })
90
90
  }
91
91
  ),
92
- /* @__PURE__ */ n(st, { className: "h-3.5 w-3.5 shrink-0 text-slate-400", "aria-hidden": !0 }),
93
- /* @__PURE__ */ n("span", { className: "truncate", children: c.label })
92
+ /* @__PURE__ */ n(at, { className: "h-3.5 w-3.5 shrink-0 text-slate-400", "aria-hidden": !0 }),
93
+ /* @__PURE__ */ n("span", { className: "truncate", children: o.label })
94
94
  ]
95
95
  },
96
- c.token
96
+ o.token
97
97
  );
98
98
  }) });
99
99
  }
100
- function Ye(t) {
101
- return !t || t.one_collection || ie(t).length < 2 ? null : t.one_collection_field || "collection";
100
+ function tt(t) {
101
+ return !t || t.one_collection || oe(t).length < 2 ? null : t.one_collection_field || "collection";
102
102
  }
103
- function Se(t, l, d) {
104
- if (!l || !t) return d;
105
- const o = t[l];
106
- if (typeof o != "string" || !o.trim()) return d;
107
- const c = o.trim();
108
- return c === "directus_users" || c === "nivaro_users" ? "nivaro_users" : c;
103
+ function pe(t, s, d) {
104
+ if (!s || !t) return d;
105
+ const a = t[s];
106
+ if (typeof a != "string" || !a.trim()) return d;
107
+ const o = a.trim();
108
+ return o === "directus_users" || o === "nivaro_users" ? "nivaro_users" : o;
109
109
  }
110
- function je({ collection: t, id: l }) {
111
- const d = Oe(), { data: o } = O({
110
+ function Pe({ collection: t, id: s }) {
111
+ const d = Te(), { data: a } = q({
112
112
  queryKey: ["col-meta", t],
113
- queryFn: () => d.request($(`/collections/${t}`)).then((c) => c.data),
113
+ queryFn: () => d.request($(`/collections/${t}`)).then((o) => o.data),
114
114
  staleTime: 3e5,
115
115
  retry: !1
116
116
  });
117
- return /* @__PURE__ */ n("span", { "data-m2a-collection": t, children: /* @__PURE__ */ n(ue, { collection: t, id: l, displayTemplate: o == null ? void 0 : o.display_template }) });
117
+ return /* @__PURE__ */ n("span", { "data-m2a-collection": t, children: /* @__PURE__ */ n(me, { collection: t, id: s, displayTemplate: a == null ? void 0 : a.display_template }) });
118
118
  }
119
- function Mt(t) {
120
- return !t || t.one_collection ? 0 : ie(t).length;
119
+ function Jt(t) {
120
+ return !t || t.one_collection ? 0 : oe(t).length;
121
121
  }
122
- function et(t) {
122
+ function nt(t) {
123
123
  if (!t) return null;
124
124
  if (t.one_collection) return t.one_collection;
125
- const l = ie(t);
126
- return l.length === 0 ? null : l.some((d) => d === "directus_users" || d === "nivaro_users") ? "nivaro_users" : l[0];
125
+ const s = oe(t);
126
+ return s.length === 0 ? null : s.some((d) => d === "directus_users" || d === "nivaro_users") ? "nivaro_users" : s[0];
127
127
  }
128
- function Et(t) {
128
+ function zt(t) {
129
129
  if (!t || t.one_collection) return null;
130
- const l = ie(t);
131
- if (l.length === 0) return null;
132
- const d = l.includes("directus_users") ? "directus_users" : l.includes("nivaro_users") ? "nivaro_users" : l[0];
130
+ const s = oe(t);
131
+ if (s.length === 0) return null;
132
+ const d = s.includes("directus_users") ? "directus_users" : s.includes("nivaro_users") ? "nivaro_users" : s[0];
133
133
  return { field: t.one_collection_field ?? "collection", value: d };
134
134
  }
135
- function W(t) {
135
+ function j(t) {
136
136
  return String(t).toLowerCase();
137
137
  }
138
- function Jt({
138
+ function Bt({
139
139
  relation: t,
140
- parentId: l,
140
+ parentId: s,
141
141
  allRelations: d,
142
- extraFilter: o,
143
- optionSort: c,
142
+ extraFilter: a,
143
+ optionSort: o,
144
144
  requiredParent: v,
145
- onCountChange: x,
145
+ onCountChange: g,
146
146
  drilldown: f
147
147
  }) {
148
- const m = Oe(), L = it(), r = Ze(), [h, A] = Q(!1), [b, F] = Q(""), j = d.find(
148
+ const m = Te(), O = ot(), r = Xe(), [y, K] = H(!1), [x, L] = H(""), U = d.find(
149
149
  (e) => e.many_collection === t.many_collection && e.many_field === t.junction_field && e.id !== t.id
150
- ), i = et(j), _ = t.junction_field ?? "", X = t.many_field ?? "", g = t.one_field ?? `${t.many_collection}.${_}`, T = Ye(j), { data: y } = O({
150
+ ), i = nt(U), w = t.junction_field ?? "", Y = t.many_field ?? "", k = t.one_field ?? `${t.many_collection}.${w}`, F = tt(U), { data: b } = q({
151
151
  queryKey: ["col-meta", i],
152
152
  queryFn: () => m.request($(`/collections/${i}`)).then((e) => e.data),
153
153
  enabled: !!i,
154
154
  staleTime: 3e5,
155
155
  retry: !1
156
- }), { data: ae = [] } = O({
156
+ }), { data: G = [] } = q({
157
157
  // An M2A read carries the discriminator: its own key (same prefix, so every
158
158
  // ['m2m-items', junction, …] invalidation still refreshes it).
159
159
  queryKey: [
160
160
  "m2m-items",
161
161
  t.many_collection,
162
- X,
163
- l,
164
- ...T ? ["m2a"] : []
162
+ Y,
163
+ s,
164
+ ...F ? ["m2a"] : []
165
165
  ],
166
166
  queryFn: () => m.request(
167
167
  $(`/items/${t.many_collection}`, {
168
- filter: JSON.stringify({ [X]: { _eq: l } }),
168
+ filter: JSON.stringify({ [Y]: { _eq: s } }),
169
169
  limit: 200,
170
- fields: `id,${_}${T ? `,${T}` : ""}`
170
+ fields: `id,${w}${F ? `,${F}` : ""}`
171
171
  })
172
172
  ).then((e) => e.data ?? []),
173
173
  staleTime: 3e4,
174
- enabled: !!l && l !== "new"
175
- }), H = (e) => Se(e, T, i), ye = Pe().isAdmin, I = i === "nivaro_users" ? Me(ye) : null, be = De(i === "nivaro_users"), Y = o ? I ? { _and: [o, I] } : o : I, ee = Y ? JSON.stringify(Y) : void 0, te = c && !/^-?label$/.test(c) ? c : void 0, xe = (() => {
176
- const e = y == null ? void 0 : y.display_template;
174
+ enabled: !!s && s !== "new"
175
+ }), ee = (e) => pe(e, F, i), ge = De().isAdmin, D = i === "nivaro_users" ? Je(ge) : null, ke = Ee(i === "nivaro_users"), te = a ? D ? { _and: [a, D] } : a : D, ne = te ? JSON.stringify(te) : void 0, re = o && !/^-?label$/.test(o) ? o : void 0, ve = (() => {
176
+ const e = b == null ? void 0 : b.display_template;
177
177
  if (!e || !e.includes(".")) return null;
178
- const a = [...e.matchAll(/\{\{([^}]+)\}\}/g)].map((u) => u[1].trim());
179
- return a.length === 0 ? null : ["id", ...a].join(",");
178
+ const c = [...e.matchAll(/\{\{([^}]+)\}\}/g)].map((u) => u[1].trim());
179
+ return c.length === 0 ? null : ["id", ...c].join(",");
180
180
  })(), {
181
- options: B,
182
- isLoading: D,
183
- localSearch: oe,
184
- closeMatches: ne
185
- } = tt({
181
+ options: R,
182
+ isLoading: M,
183
+ localSearch: ce,
184
+ closeMatches: le
185
+ } = rt({
186
186
  client: m,
187
187
  relatedCollection: i,
188
- search: b,
189
- filterParam: ee,
190
- serverSort: te,
191
- templateNestedFields: xe,
192
- enabled: h && !!i,
193
- labelOf: N
194
- }), ge = rt(!!ne, b), ke = Xe(m, j, b, h), U = (r == null ? void 0 : r.getStagedLinks(g)) ?? [], G = (r == null ? void 0 : r.getStagedUnlinks(g)) ?? /* @__PURE__ */ new Set(), k = ae.filter((e) => !G.has(e.id));
195
- new Set(k.map((e) => String(e[_])));
188
+ search: x,
189
+ filterParam: ne,
190
+ serverSort: re,
191
+ templateNestedFields: ve,
192
+ enabled: y && !!i,
193
+ labelOf: I
194
+ }), we = st(!!le, x), _e = Ye(m, U, x, y), T = (r == null ? void 0 : r.getStagedLinks(k)) ?? [], E = (r == null ? void 0 : r.getStagedUnlinks(k)) ?? /* @__PURE__ */ new Set(), S = G.filter((e) => !E.has(e.id));
195
+ new Set(S.map((e) => String(e[w])));
196
196
  const V = (e) => {
197
- const a = H(e);
198
- return a && a !== i ? Te(a, e[_]) : e[_];
199
- }, q = [
197
+ const c = ee(e);
198
+ return c && c !== i ? be(c, e[w]) : e[w];
199
+ }, N = [
200
200
  ...new Set(
201
- k.filter((e) => H(e) === i).map((e) => String(e[_]))
201
+ S.filter((e) => ee(e) === i).map((e) => String(e[w]))
202
202
  )
203
- ], S = JSON.stringify(o ? { _and: [{ id: { _in: q } }, o] } : { id: { _in: q } }), { data: re } = O({
204
- queryKey: ["m2m-avail", i, q.join(","), ee],
203
+ ], _ = JSON.stringify(a ? { _and: [{ id: { _in: N } }, a] } : { id: { _in: N } }), { data: se } = q({
204
+ queryKey: ["m2m-avail", i, N.join(","), ne],
205
205
  queryFn: () => m.request(
206
206
  $(`/items/${i}`, {
207
- filter: S,
207
+ filter: _,
208
208
  picker: "1",
209
209
  limit: 200,
210
210
  fields: "id"
211
211
  })
212
212
  ).then((e) => e.data ?? []),
213
- enabled: !!i && q.length > 0,
213
+ enabled: !!i && N.length > 0,
214
214
  staleTime: 3e4
215
- }), R = new Set((re ?? []).map((e) => String(e.id))), M = re !== void 0 ? new Set(q.filter((e) => !R.has(e))) : /* @__PURE__ */ new Set(), K = new Set(U.map(W)), P = /* @__PURE__ */ new Set([
216
- ...k.map((e) => W(V(e))),
217
- ...K
218
- ]), le = ct(
215
+ }), W = new Set((se ?? []).map((e) => String(e.id))), J = se !== void 0 ? new Set(N.filter((e) => !W.has(e))) : /* @__PURE__ */ new Set(), A = new Set(T.map(j)), P = /* @__PURE__ */ new Set([
216
+ ...S.map((e) => j(V(e))),
217
+ ...A
218
+ ]), ie = ut(
219
219
  i,
220
- (B ?? []).map((e) => e.id),
221
- h && i !== "nivaro_users"
222
- ), E = Ce(x);
223
- E.current = x, qe(() => {
220
+ (R ?? []).map((e) => e.id),
221
+ y && i !== "nivaro_users"
222
+ ), Z = Le(g);
223
+ Z.current = g, Fe(() => {
224
224
  var e;
225
- (e = E.current) == null || e.call(E, P.size);
225
+ (e = Z.current) == null || e.call(Z, P.size);
226
226
  }, [P.size]);
227
- function se(e) {
228
- const a = W(e);
229
- if (K.has(a)) {
230
- r == null || r.unstageLink(g, e);
227
+ function de(e) {
228
+ const c = j(e);
229
+ if (A.has(c)) {
230
+ r == null || r.unstageLink(k, e);
231
231
  return;
232
232
  }
233
- const u = ae.find((C) => W(V(C)) === a);
233
+ const u = G.find((C) => j(V(C)) === c);
234
234
  if (u) {
235
- G.has(u.id) ? r == null || r.unstageUnlink(g, u.id) : r == null || r.stageUnlink(g, u.id);
235
+ E.has(u.id) ? r == null || r.unstageUnlink(k, u.id) : r == null || r.stageUnlink(k, u.id);
236
236
  return;
237
237
  }
238
- r == null || r.stageLink(g, e);
238
+ r == null || r.stageLink(k, e);
239
239
  }
240
- function N(e) {
241
- const a = (y == null ? void 0 : y.display_template) ?? null;
242
- return a ? pe(a, e) : String(e._display ?? e.id ?? "");
240
+ function I(e) {
241
+ const c = (b == null ? void 0 : b.display_template) ?? null;
242
+ return c ? ye(c, e) : String(e._display ?? e.id ?? "");
243
243
  }
244
- return v ? /* @__PURE__ */ p(
244
+ return v ? /* @__PURE__ */ h(
245
245
  "button",
246
246
  {
247
247
  type: "button",
248
248
  disabled: !0,
249
249
  className: "flex h-9 w-full items-center justify-between gap-2 rounded-md border border-input bg-background px-3 text-sm text-muted-foreground opacity-50 cursor-not-allowed",
250
250
  children: [
251
- /* @__PURE__ */ p("span", { className: "truncate", children: [
251
+ /* @__PURE__ */ h("span", { className: "truncate", children: [
252
252
  "Select ",
253
253
  v,
254
254
  " first"
255
255
  ] }),
256
- /* @__PURE__ */ n(fe, { className: "h-4 w-4 shrink-0 opacity-50" })
256
+ /* @__PURE__ */ n(he, { className: "h-4 w-4 shrink-0 opacity-50" })
257
257
  ]
258
258
  }
259
- ) : /* @__PURE__ */ n("div", { children: /* @__PURE__ */ p(
260
- Ve,
259
+ ) : /* @__PURE__ */ n("div", { children: /* @__PURE__ */ h(
260
+ We,
261
261
  {
262
- open: h,
262
+ open: y,
263
263
  onOpenChange: (e) => {
264
- A(e), e || F("");
264
+ K(e), e || L("");
265
265
  },
266
266
  children: [
267
- /* @__PURE__ */ n(Re, { asChild: !0, children: /* @__PURE__ */ p(
267
+ /* @__PURE__ */ n(Ze, { asChild: !0, children: /* @__PURE__ */ h(
268
268
  "div",
269
269
  {
270
270
  role: "button",
271
271
  tabIndex: 0,
272
272
  onKeyDown: (e) => {
273
- if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (h || b !== "" || e.key !== " ")) {
273
+ if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey && (y || x !== "" || e.key !== " ")) {
274
274
  e.preventDefault();
275
275
  const u = e.key;
276
- F((C) => u === " " && (C === "" || C.endsWith(" ")) ? C : C + u), h || A(!0);
277
- } else (e.key === "Enter" || e.key === " " || !h && e.key === "ArrowDown") && (e.preventDefault(), A((u) => !u));
276
+ L((C) => u === " " && (C === "" || C.endsWith(" ")) ? C : C + u), y || K(!0);
277
+ } else (e.key === "Enter" || e.key === " " || !y && e.key === "ArrowDown") && (e.preventDefault(), K((u) => !u));
278
278
  },
279
279
  className: "flex min-h-9 w-full cursor-pointer items-center justify-between gap-2 rounded-md border border-input bg-background px-3 py-1 text-sm text-left font-normal hover:bg-muted",
280
280
  children: [
281
- P.size > 0 ? /* @__PURE__ */ p(
281
+ P.size > 0 ? /* @__PURE__ */ h(
282
282
  "span",
283
283
  {
284
284
  className: "flex min-w-0 flex-1 flex-wrap items-center gap-1",
@@ -286,60 +286,60 @@ function Jt({
286
286
  e.target.closest("button") && e.stopPropagation();
287
287
  },
288
288
  children: [
289
- k.map((e) => {
290
- const a = e[_], u = H(e), C = u !== i, J = !C && M.has(String(a));
291
- return /* @__PURE__ */ p(
289
+ S.map((e) => {
290
+ const c = e[w], u = ee(e), C = u !== i, Q = !C && J.has(String(c));
291
+ return /* @__PURE__ */ h(
292
292
  "span",
293
293
  {
294
- title: J ? "This record is no longer an available option" : void 0,
295
- className: Z(
294
+ title: Q ? "This record is no longer an available option" : void 0,
295
+ className: X(
296
296
  "inline-flex items-center gap-1 rounded-full border pl-2.5 pr-1.5 py-0.5 text-[12px]",
297
- J ? "border-amber-300 bg-amber-50 text-amber-700 dark:border-amber-600 dark:bg-amber-950/30 dark:text-amber-400" : "border-slate-200 bg-slate-50 text-slate-700 dark:border-border dark:bg-muted dark:text-slate-200"
297
+ Q ? "border-amber-300 bg-amber-50 text-amber-700 dark:border-amber-600 dark:bg-amber-950/30 dark:text-amber-400" : "border-slate-200 bg-slate-50 text-slate-700 dark:border-border dark:bg-muted dark:text-slate-200"
298
298
  ),
299
299
  children: [
300
- J && /* @__PURE__ */ n(Ue, { className: "h-3 w-3 shrink-0 text-amber-500" }),
300
+ Q && /* @__PURE__ */ n(Ie, { className: "h-3 w-3 shrink-0 text-amber-500" }),
301
301
  u && (C ? (
302
302
  // An external email (or another allowed kind): its own
303
303
  // table, its own label — never read as a person.
304
- /* @__PURE__ */ n(je, { collection: u, id: a })
305
- ) : f && L ? /* @__PURE__ */ n(
304
+ /* @__PURE__ */ n(Pe, { collection: u, id: c })
305
+ ) : f && O ? /* @__PURE__ */ n(
306
306
  "button",
307
307
  {
308
308
  type: "button",
309
309
  title: "Open detail panel",
310
- onClick: () => L.open({
310
+ onClick: () => O.open({
311
311
  collection: u,
312
- itemId: String(a),
312
+ itemId: String(c),
313
313
  layoutId: f.layout_id,
314
314
  width: f.width
315
315
  }),
316
316
  className: "underline decoration-slate-300 decoration-dotted underline-offset-2 hover:text-[#172940] hover:decoration-nvr-cyan dark:hover:text-nvr-cyan",
317
317
  children: /* @__PURE__ */ n(
318
- ue,
318
+ me,
319
319
  {
320
320
  collection: u,
321
- id: a,
322
- displayTemplate: y == null ? void 0 : y.display_template
321
+ id: c,
322
+ displayTemplate: b == null ? void 0 : b.display_template
323
323
  }
324
324
  )
325
325
  }
326
326
  ) : /* @__PURE__ */ n(
327
- ue,
327
+ me,
328
328
  {
329
329
  collection: u,
330
- id: a,
331
- displayTemplate: y == null ? void 0 : y.display_template
330
+ id: c,
331
+ displayTemplate: b == null ? void 0 : b.display_template
332
332
  }
333
333
  )),
334
- u && !C && u !== "nivaro_users" && /* @__PURE__ */ n(mt, { collection: u, id: a }),
334
+ u && !C && u !== "nivaro_users" && /* @__PURE__ */ n(pt, { collection: u, id: c }),
335
335
  /* @__PURE__ */ n(
336
336
  "button",
337
337
  {
338
338
  type: "button",
339
339
  "aria-label": "Remove",
340
- onClick: () => r == null ? void 0 : r.stageUnlink(g, e.id),
340
+ onClick: () => r == null ? void 0 : r.stageUnlink(k, e.id),
341
341
  className: "rounded-full p-0.5 text-slate-400 hover:text-red-500",
342
- children: /* @__PURE__ */ n(_e, { className: "h-3 w-3" })
342
+ children: /* @__PURE__ */ n(qe, { className: "h-3 w-3" })
343
343
  }
344
344
  )
345
345
  ]
@@ -347,23 +347,23 @@ function Jt({
347
347
  String(e.id)
348
348
  );
349
349
  }),
350
- U.map((e) => /* @__PURE__ */ p(
350
+ T.map((e) => /* @__PURE__ */ h(
351
351
  "span",
352
352
  {
353
353
  className: "inline-flex items-center gap-1 rounded-full border border-dashed border-nvr-cyan/50 bg-nvr-cyan/5 pl-2.5 pr-1.5 py-0.5 text-[12px] text-slate-600 dark:text-slate-300",
354
354
  children: [
355
- me(e) ? /* @__PURE__ */ n(
356
- je,
355
+ fe(e) ? /* @__PURE__ */ n(
356
+ Pe,
357
357
  {
358
- collection: me(e).collection,
359
- id: me(e).id
358
+ collection: fe(e).collection,
359
+ id: fe(e).id
360
360
  }
361
361
  ) : i ? /* @__PURE__ */ n(
362
- ue,
362
+ me,
363
363
  {
364
364
  collection: i,
365
365
  id: e,
366
- displayTemplate: y == null ? void 0 : y.display_template
366
+ displayTemplate: b == null ? void 0 : b.display_template
367
367
  }
368
368
  ) : String(e),
369
369
  /* @__PURE__ */ n(
@@ -371,9 +371,9 @@ function Jt({
371
371
  {
372
372
  type: "button",
373
373
  "aria-label": "Remove",
374
- onClick: () => r == null ? void 0 : r.unstageLink(g, e),
374
+ onClick: () => r == null ? void 0 : r.unstageLink(k, e),
375
375
  className: "rounded-full p-0.5 text-slate-400 hover:text-red-500",
376
- children: /* @__PURE__ */ n(_e, { className: "h-3 w-3" })
376
+ children: /* @__PURE__ */ n(qe, { className: "h-3 w-3" })
377
377
  }
378
378
  )
379
379
  ]
@@ -383,88 +383,88 @@ function Jt({
383
383
  ]
384
384
  }
385
385
  ) : /* @__PURE__ */ n("span", { className: "truncate text-muted-foreground", children: "Select items…" }),
386
- /* @__PURE__ */ n(fe, { className: "h-4 w-4 shrink-0 opacity-50" })
386
+ /* @__PURE__ */ n(he, { className: "h-4 w-4 shrink-0 opacity-50" })
387
387
  ]
388
388
  }
389
389
  ) }),
390
- /* @__PURE__ */ n(We, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ p(
391
- Je,
390
+ /* @__PURE__ */ n(Qe, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ h(
391
+ Be,
392
392
  {
393
393
  shouldFilter: !1,
394
- ...ge,
394
+ ...we,
395
395
  children: [
396
396
  /* @__PURE__ */ n(
397
- ze,
397
+ Ge,
398
398
  {
399
399
  placeholder: "Search…",
400
- value: b,
401
- onValueChange: F,
400
+ value: x,
401
+ onValueChange: L,
402
402
  className: "h-9 text-[13px]"
403
403
  }
404
404
  ),
405
- /* @__PURE__ */ p(Be, { children: [
406
- D ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(we, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(Ge, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
407
- !D && ne && /* @__PURE__ */ p(
405
+ /* @__PURE__ */ h(Re, { children: [
406
+ M ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(Ce, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(Ve, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
407
+ !M && le && /* @__PURE__ */ h(
408
408
  "p",
409
409
  {
410
410
  "data-picker-close-matches": !0,
411
411
  className: "px-3 pb-1 pt-2 text-[11.5px] text-muted-foreground",
412
412
  children: [
413
413
  "No exact match for “",
414
- b.trim(),
414
+ x.trim(),
415
415
  "” — did you mean:"
416
416
  ]
417
417
  }
418
418
  ),
419
- /* @__PURE__ */ n(Le, { children: !D && (te ? [...he(B, b, oe, N)] : [...he(B, b, oe, N)].sort(
420
- (e, a) => Ie(N(e), N(a), b, c === "-label")
419
+ /* @__PURE__ */ n($e, { children: !M && (re ? [...xe(R, x, ce, I)] : [...xe(R, x, ce, I)].sort(
420
+ (e, c) => Me(I(e), I(c), x, o === "-label")
421
421
  )).map((e) => {
422
- const a = String(e.id), u = P.has(W(a));
423
- return /* @__PURE__ */ p(
424
- Fe,
422
+ const c = String(e.id), u = P.has(j(c));
423
+ return /* @__PURE__ */ h(
424
+ Ke,
425
425
  {
426
- value: a,
427
- onSelect: () => se(e.id),
426
+ value: c,
427
+ onSelect: () => de(e.id),
428
428
  className: "flex items-center gap-2 text-[13px]",
429
429
  children: [
430
430
  /* @__PURE__ */ n(
431
431
  "div",
432
432
  {
433
- className: Z(
433
+ className: X(
434
434
  "flex h-4 w-4 shrink-0 items-center justify-center rounded border",
435
435
  u ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
436
436
  ),
437
- children: u && /* @__PURE__ */ n(Ne, { className: "h-2.5 w-2.5 text-white" })
437
+ children: u && /* @__PURE__ */ n(Oe, { className: "h-2.5 w-2.5 text-white" })
438
438
  }
439
439
  ),
440
440
  i === "nivaro_users" && /* @__PURE__ */ n(
441
- Ee,
441
+ ze,
442
442
  {
443
- userId: a,
443
+ userId: c,
444
444
  className: "h-4 w-4",
445
- fallback: /* @__PURE__ */ n("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: Qe(N(e)) })
445
+ fallback: /* @__PURE__ */ n("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: He(I(e)) })
446
446
  }
447
447
  ),
448
- i === "nivaro_users" && be.has(a.toUpperCase()) && /* @__PURE__ */ n(
448
+ i === "nivaro_users" && ke.has(c.toUpperCase()) && /* @__PURE__ */ n(
449
449
  "span",
450
450
  {
451
451
  className: "h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",
452
452
  "data-tip": "Online now"
453
453
  }
454
454
  ),
455
- /* @__PURE__ */ n("span", { className: "truncate", children: N(e) }),
456
- /* @__PURE__ */ n(ft, { badges: le[a] })
455
+ /* @__PURE__ */ n("span", { className: "truncate", children: I(e) }),
456
+ /* @__PURE__ */ n(ht, { badges: ie[c] })
457
457
  ]
458
458
  },
459
- a
459
+ c
460
460
  );
461
461
  }) }),
462
462
  /* @__PURE__ */ n(
463
- He,
463
+ et,
464
464
  {
465
- options: ke,
466
- isSelected: (e) => P.has(W(e)),
467
- onPick: (e) => se(e),
465
+ options: _e,
466
+ isSelected: (e) => P.has(j(e)),
467
+ onPick: (e) => de(e),
468
468
  round: !1
469
469
  }
470
470
  )
@@ -476,293 +476,304 @@ function Jt({
476
476
  }
477
477
  ) });
478
478
  }
479
- function tt(t) {
480
- const { client: l, relatedCollection: d, search: o, filterParam: c, serverSort: v, templateNestedFields: x } = t, f = (i) => l.request(
479
+ function rt(t) {
480
+ const { client: s, relatedCollection: d, search: a, filterParam: o, serverSort: v, templateNestedFields: g } = t, f = (i) => s.request(
481
481
  $(`/items/${d}`, {
482
- limit: nt,
482
+ limit: lt,
483
483
  search: i || void 0,
484
484
  // Typo pass (fix11-search): close matches only when the exact search finds nothing.
485
485
  ...i ? { typo: "1" } : {},
486
- filter: c,
486
+ filter: o,
487
487
  picker: "1",
488
488
  // A dotted display template ({{core_category.name}}) needs the
489
489
  // nested expansion — a bare row only carries the FK id.
490
- ...x ? { fields: x } : {},
490
+ ...g ? { fields: g } : {},
491
491
  ...v ? { sort: v } : {}
492
492
  })
493
- ).then((_) => _.data ?? []), m = (i) => [
493
+ ).then((w) => w.data ?? []), m = (i) => [
494
494
  "m2m-options",
495
495
  d,
496
496
  i,
497
- c,
497
+ o,
498
498
  v ?? "",
499
- x ?? ""
500
- ], L = c ? 0 : 3e4, r = ot(d), { data: h, isFetching: A } = O({
499
+ g ?? ""
500
+ ], O = o ? 0 : 3e4, r = dt(d), { data: y, isFetching: K } = q({
501
501
  queryKey: m(""),
502
502
  queryFn: () => f(""),
503
503
  enabled: t.enabled,
504
- staleTime: L,
504
+ staleTime: O,
505
505
  meta: r
506
- }), b = xt(h, o, t.labelOf), { data: F, isFetching: j } = O({
507
- queryKey: m(o),
508
- queryFn: () => f(o),
509
- enabled: t.enabled && b,
510
- staleTime: L,
506
+ }), x = kt(y, a, t.labelOf), { data: L, isFetching: U } = q({
507
+ queryKey: m(a),
508
+ queryFn: () => f(a),
509
+ enabled: t.enabled && x,
510
+ staleTime: O,
511
511
  meta: r
512
512
  });
513
- return b ? {
514
- options: F ?? [],
515
- isLoading: !F && j,
513
+ return x ? {
514
+ options: L ?? [],
515
+ isLoading: !L && U,
516
516
  localSearch: !1,
517
- closeMatches: pt(F)
518
- } : { options: h ?? [], isLoading: !h && A, localSearch: !!o };
517
+ closeMatches: yt(L)
518
+ } : { options: y ?? [], isLoading: !y && K, localSearch: !!a };
519
519
  }
520
- const nt = 200;
521
- function xt(t, l, d) {
522
- return l.trim() ? !t || t.length >= nt ? !0 : he(t, l, !0, d).length === 0 : !1;
520
+ const lt = 200;
521
+ function kt(t, s, d) {
522
+ return s.trim() ? !t || t.length >= lt ? !0 : xe(t, s, !0, d).length === 0 : !1;
523
523
  }
524
- function he(t, l, d, o) {
525
- return !d || !l.trim() ? t : t.filter((c) => ut(o(c), l));
524
+ function xe(t, s, d, a) {
525
+ return !d || !s.trim() ? t : t.filter((o) => ft(a(o), s));
526
526
  }
527
- function zt({
527
+ function Gt({
528
528
  relation: t,
529
- parentId: l,
529
+ parentId: s,
530
530
  allRelations: d,
531
- extraFilter: o,
532
- optionSort: c,
531
+ extraFilter: a,
532
+ optionSort: o,
533
533
  requiredParent: v,
534
- onCountChange: x,
534
+ onCountChange: g,
535
535
  readOnly: f
536
536
  }) {
537
- const m = Oe(), L = dt(), r = Ze(), [h, A] = Q(!1), [b, F] = Q(""), j = d.find(
538
- (s) => s.many_collection === t.many_collection && s.many_field === t.junction_field && s.id !== t.id
539
- ), i = et(j), _ = t.junction_field ?? "", X = t.many_field ?? "", g = t.one_field ?? `${t.many_collection}.${_}`, { data: T } = O({
537
+ const m = Te(), O = mt(), r = Xe(), [y, K] = H(!1), [x, L] = H(""), U = d.find(
538
+ (l) => l.many_collection === t.many_collection && l.many_field === t.junction_field && l.id !== t.id
539
+ ), i = nt(U), w = t.junction_field ?? "", Y = t.many_field ?? "", k = t.one_field ?? `${t.many_collection}.${w}`, { data: F } = q({
540
540
  queryKey: ["col-meta", i],
541
- queryFn: () => m.request($(`/collections/${i}`)).then((s) => s.data),
541
+ queryFn: () => m.request($(`/collections/${i}`)).then((l) => l.data),
542
542
  enabled: !!i,
543
543
  staleTime: 3e5,
544
544
  retry: !1
545
- }), y = Ye(j), { data: ae = [], isFetching: H } = O({
545
+ }), b = tt(U), { data: G = [], isFetching: ee } = q({
546
546
  queryKey: [
547
547
  "m2m-items",
548
548
  t.many_collection,
549
- X,
550
- l,
551
- ...y ? ["m2a"] : []
549
+ Y,
550
+ s,
551
+ ...b ? ["m2a"] : []
552
552
  ],
553
553
  queryFn: () => m.request(
554
554
  $(`/items/${t.many_collection}`, {
555
- filter: JSON.stringify({ [X]: { _eq: l } }),
555
+ filter: JSON.stringify({ [Y]: { _eq: s } }),
556
556
  limit: 1,
557
- fields: `id,${_}${y ? `,${y}` : ""}`
557
+ fields: `id,${w}${b ? `,${b}` : ""}`
558
558
  })
559
- ).then((s) => s.data ?? []),
559
+ ).then((l) => l.data ?? []),
560
560
  staleTime: 3e4,
561
- enabled: !!l && l !== "new"
562
- }), ye = Pe().isAdmin, I = i === "nivaro_users" ? Me(ye) : null, be = De(i === "nivaro_users"), Y = o ? I ? { _and: [o, I] } : o : I, ee = Y ? JSON.stringify(Y) : void 0, te = c && !/^-?label$/.test(c) ? c : void 0, xe = (() => {
563
- const s = T == null ? void 0 : T.display_template;
564
- if (!s || !s.includes(".")) return null;
565
- const w = [...s.matchAll(/\{\{([^}]+)\}\}/g)].map((de) => de[1].trim());
566
- return w.length === 0 ? null : ["id", ...w].join(",");
561
+ enabled: !!s && s !== "new"
562
+ }), ge = De().isAdmin, D = i === "nivaro_users" ? Je(ge) : null, ke = Ee(i === "nivaro_users"), te = a ? D ? { _and: [a, D] } : a : D, ne = te ? JSON.stringify(te) : void 0, re = o && !/^-?label$/.test(o) ? o : void 0, ve = (() => {
563
+ const l = F == null ? void 0 : F.display_template;
564
+ if (!l || !l.includes(".")) return null;
565
+ const p = [...l.matchAll(/\{\{([^}]+)\}\}/g)].map((ae) => ae[1].trim());
566
+ return p.length === 0 ? null : ["id", ...p].join(",");
567
567
  })(), {
568
- options: B,
569
- isLoading: D,
570
- localSearch: oe,
571
- closeMatches: ne
572
- } = tt({
568
+ options: R,
569
+ isLoading: M,
570
+ localSearch: ce,
571
+ closeMatches: le
572
+ } = rt({
573
573
  client: m,
574
574
  relatedCollection: i,
575
- search: b,
576
- filterParam: ee,
577
- serverSort: te,
578
- templateNestedFields: xe,
579
- enabled: h && !!i,
575
+ search: x,
576
+ filterParam: ne,
577
+ serverSort: re,
578
+ templateNestedFields: ve,
579
+ enabled: y && !!i,
580
580
  labelOf: z
581
- }), ge = rt(!!ne, b), ke = Xe(m, j, b, h), U = (r == null ? void 0 : r.getStagedLinks(g)) ?? [], G = (r == null ? void 0 : r.getStagedUnlinks(g)) ?? /* @__PURE__ */ new Set(), k = ae.find((s) => !G.has(s.id)) ?? null, V = k ? k[_] : null, q = U.length > 0 ? U[U.length - 1] : null, S = q ?? V, re = U.length > 0 || G.size > 0, R = Ce(x);
582
- R.current = x, qe(() => {
583
- var s;
584
- (s = R.current) == null || s.call(R, S != null ? 1 : 0);
585
- }, [S]);
586
- const M = me(q), K = q != null ? (M == null ? void 0 : M.collection) ?? i : Se(k, y, i), P = M ? M.id : S, le = Se(k, y, i), E = k == null ? null : le && le !== i ? Te(le, V) : String(V), se = q != null ? String(q) : E, N = K !== i, { data: e } = O({
587
- queryKey: ["col-meta", K],
588
- queryFn: () => m.request($(`/collections/${K}`)).then((s) => s.data),
589
- enabled: N && !!K,
581
+ }), we = st(!!le, x), _e = Ye(m, U, x, y), T = (r == null ? void 0 : r.getStagedLinks(k)) ?? [], E = (r == null ? void 0 : r.getStagedUnlinks(k)) ?? /* @__PURE__ */ new Set(), S = G.find((l) => !E.has(l.id)) ?? null, V = S ? S[w] : null, N = T.length > 0 ? T[T.length - 1] : null, _ = N ?? V, se = T.length > 0 || E.size > 0, W = Le(g);
582
+ W.current = g, Fe(() => {
583
+ var l;
584
+ (l = W.current) == null || l.call(W, _ != null ? 1 : 0);
585
+ }, [_]);
586
+ const J = fe(N), A = N != null ? (J == null ? void 0 : J.collection) ?? i : pe(S, b, i), P = J ? J.id : _, ie = pe(S, b, i), Z = S == null ? null : ie && ie !== i ? be(ie, V) : String(V), de = N != null ? String(N) : Z, I = (l) => {
587
+ const p = pe(l, b, i);
588
+ return j(
589
+ p && p !== i ? be(p, l[w]) : l[w]
590
+ );
591
+ }, e = A !== i, { data: c } = q({
592
+ queryKey: ["col-meta", A],
593
+ queryFn: () => m.request($(`/collections/${A}`)).then((l) => l.data),
594
+ enabled: e && !!A,
590
595
  staleTime: 3e5,
591
596
  retry: !1
592
- }), { data: a } = O({
593
- queryKey: ["relation-single", K, String(P)],
594
- queryFn: () => L(K, P),
595
- enabled: !!K && P != null,
597
+ }), { data: u } = q({
598
+ queryKey: ["relation-single", A, String(P)],
599
+ queryFn: () => O(A, P),
600
+ enabled: !!A && P != null,
596
601
  staleTime: 6e4
597
- }), u = JSON.stringify(o ? { _and: [{ id: { _eq: S } }, o] } : { id: { _eq: S } }), { data: C } = O({
598
- queryKey: ["relation-avail", i, String(S), ee],
602
+ }), C = JSON.stringify(a ? { _and: [{ id: { _eq: _ } }, a] } : { id: { _eq: _ } }), { data: Q } = q({
603
+ queryKey: ["relation-avail", i, String(_), ne],
599
604
  queryFn: () => m.request(
600
605
  $(`/items/${i}`, {
601
- filter: u,
606
+ filter: C,
602
607
  picker: "1",
603
608
  limit: 1,
604
609
  fields: "id"
605
610
  })
606
- ).then((s) => s.data ?? []),
607
- enabled: !!i && !N && S != null && !!a,
611
+ ).then((l) => l.data ?? []),
612
+ enabled: !!i && !e && _ != null && !!u,
608
613
  staleTime: 3e4
609
- }), J = !N && C !== void 0 && C.length === 0, $e = ht(J);
610
- function z(s) {
611
- const w = (T == null ? void 0 : T.display_template) ?? null;
612
- return w ? pe(w, s) : String(s.name ?? s.title ?? s.label ?? s.id ?? "");
614
+ }), Se = !e && Q !== void 0 && Q.length === 0, Ae = bt(Se);
615
+ function z(l) {
616
+ const p = (F == null ? void 0 : F.display_template) ?? null;
617
+ return p ? ye(p, l) : String(l.name ?? l.title ?? l.label ?? l.id ?? "");
613
618
  }
614
- const ce = N ? a : B.find((s) => String(s.id) === String(S)) ?? a, Ae = S != null && !a && !ce, ve = ce ? N ? pe((e == null ? void 0 : e.display_template) ?? null, ce) : z(ce) : null;
619
+ const ue = e ? u : R.find((l) => String(l.id) === String(_)) ?? u, je = _ != null && !u && !ue, Ne = ue ? e ? ye((c == null ? void 0 : c.display_template) ?? null, ue) : z(ue) : null;
615
620
  if (f)
616
- return /* @__PURE__ */ n("span", { className: "block truncate text-[12px] text-slate-700 dark:text-slate-200", children: Ae ? "…" : ve ?? "—" });
617
- function Ke(s) {
618
- for (const w of U) r == null || r.unstageLink(g, w);
619
- k && !G.has(k.id) && (r == null || r.stageUnlink(g, k.id)), String(s) === E && k ? r == null || r.unstageUnlink(g, k.id) : String(s) !== se && (r == null || r.stageLink(g, s)), A(!1), F("");
621
+ return /* @__PURE__ */ n("span", { className: "block truncate text-[12px] text-slate-700 dark:text-slate-200", children: je ? "…" : Ne ?? "—" });
622
+ function Ue(l) {
623
+ const p = G.find((B) => I(B) === j(l)) ?? null;
624
+ if (!(!p && T.length === 1 && j(T[0]) === j(l))) {
625
+ for (const B of T) r == null || r.unstageLink(k, B);
626
+ for (const B of G)
627
+ B !== p && !E.has(B.id) && (r == null || r.stageUnlink(k, B.id));
628
+ p ? E.has(p.id) && (r == null || r.unstageUnlink(k, p.id)) : r == null || r.stageLink(k, l);
629
+ }
630
+ K(!1), L("");
620
631
  }
621
- function lt() {
622
- for (const s of U) r == null || r.unstageLink(g, s);
623
- k && (r == null || r.stageUnlink(g, k.id)), A(!1);
632
+ function it() {
633
+ for (const l of T) r == null || r.unstageLink(k, l);
634
+ S && (r == null || r.stageUnlink(k, S.id)), K(!1);
624
635
  }
625
- return v ? /* @__PURE__ */ p(
636
+ return v ? /* @__PURE__ */ h(
626
637
  "button",
627
638
  {
628
639
  type: "button",
629
640
  disabled: !0,
630
641
  className: "w-full h-9 px-3 text-[12px] border border-input rounded-md bg-background text-left flex items-center justify-between opacity-50 cursor-not-allowed",
631
642
  children: [
632
- /* @__PURE__ */ p("span", { className: "truncate text-muted-foreground", children: [
643
+ /* @__PURE__ */ h("span", { className: "truncate text-muted-foreground", children: [
633
644
  "Select ",
634
645
  v,
635
646
  " first"
636
647
  ] }),
637
- /* @__PURE__ */ n(fe, { className: "h-4 w-4 shrink-0 opacity-50" })
648
+ /* @__PURE__ */ n(he, { className: "h-4 w-4 shrink-0 opacity-50" })
638
649
  ]
639
650
  }
640
- ) : /* @__PURE__ */ p("div", { ...$e.bind, children: [
641
- /* @__PURE__ */ p(
642
- Ve,
651
+ ) : /* @__PURE__ */ h("div", { ...Ae.bind, children: [
652
+ /* @__PURE__ */ h(
653
+ We,
643
654
  {
644
- open: h,
645
- onOpenChange: (s) => {
646
- A(s), s || F("");
655
+ open: y,
656
+ onOpenChange: (l) => {
657
+ K(l), l || L("");
647
658
  },
648
659
  children: [
649
- /* @__PURE__ */ n(Re, { asChild: !0, children: /* @__PURE__ */ p(
660
+ /* @__PURE__ */ n(Ze, { asChild: !0, children: /* @__PURE__ */ h(
650
661
  "button",
651
662
  {
652
663
  type: "button",
653
- className: Z(
664
+ className: X(
654
665
  "w-full h-9 px-3 text-[12px] border rounded-md bg-background text-left flex items-center justify-between hover:bg-muted cursor-pointer transition-colors disabled:pointer-events-none disabled:opacity-50",
655
- J ? "border-amber-300 dark:border-amber-600" : re ? "border-nvr-cyan/50" : "border-input"
666
+ Se ? "border-amber-300 dark:border-amber-600" : se ? "border-nvr-cyan/50" : "border-input"
656
667
  ),
657
668
  children: [
658
- Ae || H && q == null && l !== "new" ? /* @__PURE__ */ n(we, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ p(
669
+ je || ee && N == null && s !== "new" ? /* @__PURE__ */ n(Ce, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ h(
659
670
  "span",
660
671
  {
661
- className: Z(
672
+ className: X(
662
673
  "flex items-center gap-1.5 truncate min-w-0",
663
- ve ? re ? "text-nvr-cyan" : "text-slate-800 dark:text-slate-100" : "text-muted-foreground"
674
+ Ne ? se ? "text-nvr-cyan" : "text-slate-800 dark:text-slate-100" : "text-muted-foreground"
664
675
  ),
665
676
  children: [
666
- J && /* @__PURE__ */ n(Ue, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
667
- /* @__PURE__ */ n("span", { className: "truncate", children: ve ?? "Select…" })
677
+ Se && /* @__PURE__ */ n(Ie, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
678
+ /* @__PURE__ */ n("span", { className: "truncate", children: Ne ?? "Select…" })
668
679
  ]
669
680
  }
670
681
  ),
671
- /* @__PURE__ */ n(fe, { className: "h-4 w-4 shrink-0 opacity-50" })
682
+ /* @__PURE__ */ n(he, { className: "h-4 w-4 shrink-0 opacity-50" })
672
683
  ]
673
684
  }
674
685
  ) }),
675
- /* @__PURE__ */ n(We, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ p(
676
- Je,
686
+ /* @__PURE__ */ n(Qe, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ h(
687
+ Be,
677
688
  {
678
689
  shouldFilter: !1,
679
- ...ge,
690
+ ...we,
680
691
  children: [
681
692
  /* @__PURE__ */ n(
682
- ze,
693
+ Ge,
683
694
  {
684
695
  placeholder: "Search…",
685
- value: b,
686
- onValueChange: F,
696
+ value: x,
697
+ onValueChange: L,
687
698
  className: "h-9 text-[12px]"
688
699
  }
689
700
  ),
690
- S != null && /* @__PURE__ */ p(
701
+ _ != null && /* @__PURE__ */ h(
691
702
  "button",
692
703
  {
693
704
  type: "button",
694
705
  onClick: () => {
695
- lt(), A(!1);
706
+ it(), K(!1);
696
707
  },
697
708
  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",
698
709
  children: [
699
- /* @__PURE__ */ n(_e, { className: "h-3.5 w-3.5 text-slate-400" }),
710
+ /* @__PURE__ */ n(qe, { className: "h-3.5 w-3.5 text-slate-400" }),
700
711
  "Clear selection"
701
712
  ]
702
713
  }
703
714
  ),
704
- /* @__PURE__ */ p(Be, { children: [
705
- D ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(we, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(Ge, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
706
- !D && ne && /* @__PURE__ */ p(
715
+ /* @__PURE__ */ h(Re, { children: [
716
+ M ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(Ce, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(Ve, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
717
+ !M && le && /* @__PURE__ */ h(
707
718
  "p",
708
719
  {
709
720
  "data-picker-close-matches": !0,
710
721
  className: "px-3 pb-1 pt-2 text-[11.5px] text-muted-foreground",
711
722
  children: [
712
723
  "No exact match for “",
713
- b.trim(),
724
+ x.trim(),
714
725
  "” — did you mean:"
715
726
  ]
716
727
  }
717
728
  ),
718
- !D && /* @__PURE__ */ n(Le, { children: [...he(B, b, oe, z)].sort(
719
- (s, w) => te ? 0 : Ie(z(s), z(w), b, c === "-label")
720
- ).map((s) => {
721
- const w = String(s.id), de = String(S) === w;
722
- return /* @__PURE__ */ p(
723
- Fe,
729
+ !M && /* @__PURE__ */ n($e, { children: [...xe(R, x, ce, z)].sort(
730
+ (l, p) => re ? 0 : Me(z(l), z(p), x, o === "-label")
731
+ ).map((l) => {
732
+ const p = String(l.id), ae = String(_) === p;
733
+ return /* @__PURE__ */ h(
734
+ Ke,
724
735
  {
725
- value: w,
726
- onSelect: () => Ke(s.id),
736
+ value: p,
737
+ onSelect: () => Ue(l.id),
727
738
  className: "flex items-center gap-2 text-[12px]",
728
739
  children: [
729
740
  /* @__PURE__ */ n(
730
741
  "div",
731
742
  {
732
- className: Z(
743
+ className: X(
733
744
  "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",
734
- de ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
745
+ ae ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
735
746
  ),
736
- children: de && /* @__PURE__ */ n(Ne, { className: "h-2.5 w-2.5 text-white" })
747
+ children: ae && /* @__PURE__ */ n(Oe, { className: "h-2.5 w-2.5 text-white" })
737
748
  }
738
749
  ),
739
750
  i === "nivaro_users" && /* @__PURE__ */ n(
740
- Ee,
751
+ ze,
741
752
  {
742
- userId: w,
753
+ userId: p,
743
754
  className: "h-4 w-4",
744
- fallback: /* @__PURE__ */ n("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: Qe(z(s)) })
755
+ fallback: /* @__PURE__ */ n("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: He(z(l)) })
745
756
  }
746
757
  ),
747
- i === "nivaro_users" && be.has(w.toUpperCase()) && /* @__PURE__ */ n(
758
+ i === "nivaro_users" && ke.has(p.toUpperCase()) && /* @__PURE__ */ n(
748
759
  "span",
749
760
  {
750
761
  className: "h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",
751
762
  "data-tip": "Online now"
752
763
  }
753
764
  ),
754
- /* @__PURE__ */ n("span", { className: "truncate", children: z(s) })
765
+ /* @__PURE__ */ n("span", { className: "truncate", children: z(l) })
755
766
  ]
756
767
  },
757
- w
768
+ p
758
769
  );
759
770
  }) }),
760
771
  /* @__PURE__ */ n(
761
- He,
772
+ et,
762
773
  {
763
- options: ke,
764
- isSelected: (s) => se === s,
765
- onPick: (s) => Ke(s),
774
+ options: _e,
775
+ isSelected: (l) => de === l,
776
+ onPick: (l) => Ue(l),
766
777
  round: !0
767
778
  }
768
779
  )
@@ -773,39 +784,39 @@ function zt({
773
784
  ]
774
785
  }
775
786
  ),
776
- $e.tip
787
+ Ae.tip
777
788
  ] });
778
789
  }
779
- function rt(t, l) {
780
- const [d, o] = Q(null), [c, v] = Q(!1), x = Ce(!1);
781
- return qe(() => {
782
- o(null), x.current = !1;
783
- }, [l]), t ? {
784
- value: d ?? (c ? " " : ""),
790
+ function st(t, s) {
791
+ const [d, a] = H(null), [o, v] = H(!1), g = Le(!1);
792
+ return Fe(() => {
793
+ a(null), g.current = !1;
794
+ }, [s]), t ? {
795
+ value: d ?? (o ? " " : ""),
785
796
  onValueChange: (f) => {
786
- x.current ? o(f) : v((m) => !m);
797
+ g.current ? a(f) : v((m) => !m);
787
798
  },
788
799
  onKeyDownCapture: (f) => {
789
- f.key === "ArrowDown" || f.key === "ArrowUp" ? x.current = !0 : f.key === "Enter" && !x.current && (f.preventDefault(), f.stopPropagation());
800
+ f.key === "ArrowDown" || f.key === "ArrowUp" ? g.current = !0 : f.key === "Enter" && !g.current && (f.preventDefault(), f.stopPropagation());
790
801
  },
791
802
  onPointerMoveCapture: () => {
792
- x.current = !0;
803
+ g.current = !0;
793
804
  }
794
805
  } : {};
795
806
  }
796
807
  export {
797
- Jt as M2MCombobox,
798
- zt as M2MSingleSelectCombobox,
799
- je as OwnCollectionLabel,
800
- Mt as m2aAllowedCount,
801
- Ye as m2aDiscriminator,
802
- bt as m2aExtraCollections,
803
- Se as m2aRowCollection,
804
- Te as m2aToken,
805
- Et as m2aWriteMeta,
806
- xt as m2mAsksServer,
807
- W as m2mIdKey,
808
- he as narrowM2MOptions,
809
- me as parseM2aToken,
810
- et as resolveM2MRelatedCollection
808
+ Bt as M2MCombobox,
809
+ Gt as M2MSingleSelectCombobox,
810
+ Pe as OwnCollectionLabel,
811
+ Jt as m2aAllowedCount,
812
+ tt as m2aDiscriminator,
813
+ gt as m2aExtraCollections,
814
+ pe as m2aRowCollection,
815
+ be as m2aToken,
816
+ zt as m2aWriteMeta,
817
+ kt as m2mAsksServer,
818
+ j as m2mIdKey,
819
+ xe as narrowM2MOptions,
820
+ fe as parseM2aToken,
821
+ nt as resolveM2MRelatedCollection
811
822
  };