@nivaro/react 0.3.96 → 0.3.98

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