@nivaro/react 0.3.97 → 0.3.99

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