@nivaro/react 0.3.25 → 0.3.26

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.
@@ -9,7 +9,7 @@ import { noteReplayEvent as _e, createReplayCheckoutState as De } from "../share
9
9
  import { emitReplayTap as Te, setReplayRecorderMode as N, registerReplayCapture as qe, clipEndOffset as Le, withClipKind as Pe } from "../shared/lib/replay-capture.js";
10
10
  import { instrumentConsole as Ne, instrumentRequests as Fe, redactSecrets as Me } from "../shared/lib/replay-context.js";
11
11
  import { instrumentSocket as Oe } from "../shared/lib/replay-socket.js";
12
- const Ue = "nivaro-react@0.3.25", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
12
+ const Ue = "nivaro-react@0.3.26", j = 1e4, We = 150, He = 3e3, Ke = 600, $e = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
13
13
  function Be(n) {
14
14
  return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
15
15
  const u = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
@@ -2,38 +2,39 @@ import { jsx as n, jsxs as c } from "react/jsx-runtime";
2
2
  import { useQuery as w } from "@tanstack/react-query";
3
3
  import { ChevronDown as te, Loader2 as ae, AlertTriangle as ce, X as oe, Check as de } from "lucide-react";
4
4
  import { useState as ne, useRef as me, useEffect as ue } from "react";
5
- import { useNivaroClient as fe, useItemEditAuth as pe, useDrilldown as $e } from "../../context.js";
6
- import { parseAllowedCollections as Ie } from "../../lib/allowed-collections.js";
7
- import { get as C } from "../../lib/commands.js";
8
- import { useRecordReader as Ae } from "../../lib/record-loader.js";
9
- import { useOnlineUsers as he } from "../../lib/use-online-users.js";
10
- import { cn as Q, userOptionFilter as be } from "../../lib/utils.js";
11
- import { UserAvatar as ye } from "../UserAvatar.js";
12
- import { Command as xe, CommandInput as ve, CommandList as ge, CommandEmpty as ke, CommandGroup as we, CommandItem as Ne } from "../ui/command.js";
13
- import { Popover as Se, PopoverTrigger as _e, PopoverContent as Ce } from "../ui/popover.js";
14
- import { applyDisplayTemplate as qe } from "./helpers.js";
15
- import { useM2MStaging as Le } from "./M2MStagingContext.js";
16
- import { useStaleTip as Ke, RelatedItemLabel as ie } from "./RelationCombobox.js";
17
- function je(s) {
18
- return s.replace(/\(.*$/, "").trim().split(/\s+/).map((o) => o[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
19
- }
5
+ import { useNivaroClient as fe, useItemEditAuth as pe, useDrilldown as Ie } from "../../context.js";
6
+ import { parseAllowedCollections as Ae } from "../../lib/allowed-collections.js";
7
+ import { get as q } from "../../lib/commands.js";
8
+ import { compareByMatch as he } from "../../lib/picker-rank.js";
9
+ import { useRecordReader as Ke } from "../../lib/record-loader.js";
10
+ import { useOnlineUsers as be } from "../../lib/use-online-users.js";
11
+ import { cn as Q, userOptionFilter as ye } from "../../lib/utils.js";
12
+ import { UserAvatar as xe } from "../UserAvatar.js";
13
+ import { Command as ve, CommandInput as ge, CommandList as ke, CommandEmpty as we, CommandGroup as Ne, CommandItem as Se } from "../ui/command.js";
14
+ import { Popover as _e, PopoverTrigger as qe, PopoverContent as Ce } from "../ui/popover.js";
15
+ import { applyDisplayTemplate as Le } from "./helpers.js";
16
+ import { useM2MStaging as je } from "./M2MStagingContext.js";
17
+ import { useStaleTip as Je, RelatedItemLabel as ie } from "./RelationCombobox.js";
20
18
  function Fe(s) {
21
- return Ie(s == null ? void 0 : s.one_allowed_collections);
19
+ return s.replace(/\(.*$/, "").trim().split(/\s+/).map((o) => o[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
22
20
  }
23
21
  function Te(s) {
22
+ return Ae(s == null ? void 0 : s.one_allowed_collections);
23
+ }
24
+ function Oe(s) {
24
25
  if (!s) return null;
25
26
  if (s.one_collection) return s.one_collection;
26
- const o = Fe(s);
27
+ const o = Te(s);
27
28
  return o.length === 0 ? null : o.some((N) => N === "directus_users" || N === "nivaro_users") ? "nivaro_users" : o[0];
28
29
  }
29
- function et(s) {
30
+ function nt(s) {
30
31
  if (!s || s.one_collection) return null;
31
- const o = Fe(s);
32
+ const o = Te(s);
32
33
  if (o.length === 0) return null;
33
34
  const N = o.includes("directus_users") ? "directus_users" : o.includes("nivaro_users") ? "nivaro_users" : o[0];
34
35
  return { field: s.one_collection_field ?? "collection", value: N };
35
36
  }
36
- function tt({
37
+ function lt({
37
38
  relation: s,
38
39
  parentId: o,
39
40
  allRelations: N,
@@ -43,57 +44,57 @@ function tt({
43
44
  onCountChange: J,
44
45
  drilldown: D
45
46
  }) {
46
- const y = fe(), W = $e(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = N.find(
47
+ const y = fe(), W = Ie(), t = je(), [P, C] = ne(!1), [x, T] = ne(""), le = N.find(
47
48
  (e) => e.many_collection === s.many_collection && e.many_field === s.junction_field && e.id !== s.id
48
- ), r = Te(le), x = s.junction_field ?? "", R = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: a } = w({
49
+ ), r = Oe(le), v = s.junction_field ?? "", R = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${v}`, { data: a } = w({
49
50
  queryKey: ["col-meta", r],
50
- queryFn: () => y.request(C(`/collections/${r}`)).then((e) => e.data),
51
+ queryFn: () => y.request(q(`/collections/${r}`)).then((e) => e.data),
51
52
  enabled: !!r,
52
53
  staleTime: 3e5,
53
54
  retry: !1
54
55
  }), { data: X = [] } = w({
55
56
  queryKey: ["m2m-items", s.many_collection, R, o],
56
57
  queryFn: () => y.request(
57
- C(`/items/${s.many_collection}`, {
58
+ q(`/items/${s.many_collection}`, {
58
59
  filter: JSON.stringify({ [R]: { _eq: o } }),
59
60
  limit: 200,
60
- fields: `id,${x}`
61
+ fields: `id,${v}`
61
62
  })
62
63
  ).then((e) => e.data ?? []),
63
64
  staleTime: 3e4,
64
65
  enabled: !!o && o !== "new"
65
- }), re = pe().isAdmin, z = r === "nivaro_users" ? be(re) : null, E = he(r === "nivaro_users"), H = h ? z ? { _and: [h, z] } : h : z, j = H ? JSON.stringify(H) : void 0, v = b && !/^-?label$/.test(b) ? b : void 0, S = (() => {
66
+ }), re = pe().isAdmin, z = r === "nivaro_users" ? ye(re) : null, E = be(r === "nivaro_users"), H = h ? z ? { _and: [h, z] } : h : z, L = H ? JSON.stringify(H) : void 0, g = b && !/^-?label$/.test(b) ? b : void 0, S = (() => {
66
67
  const e = a == null ? void 0 : a.display_template;
67
68
  if (!e || !e.includes(".")) return null;
68
69
  const i = [...e.matchAll(/\{\{([^}]+)\}\}/g)].map((u) => u[1].trim());
69
70
  return i.length === 0 ? null : ["id", ...i].join(",");
70
- })(), { data: O = [], isFetching: V } = w({
71
+ })(), { data: O = [], isFetching: B } = w({
71
72
  queryKey: [
72
73
  "m2m-options",
73
74
  r,
75
+ x,
74
76
  L,
75
- j,
76
- v ?? "",
77
+ g ?? "",
77
78
  S ?? ""
78
79
  ],
79
80
  queryFn: () => y.request(
80
- C(`/items/${r}`, {
81
+ q(`/items/${r}`, {
81
82
  limit: 200,
82
- search: L || void 0,
83
- filter: j,
83
+ search: x || void 0,
84
+ filter: L,
84
85
  picker: "1",
85
86
  // A dotted display template ({{core_category.name}}) needs the
86
87
  // nested expansion — a bare row only carries the FK id.
87
88
  ...S ? { fields: S } : {},
88
- ...v ? { sort: v } : {}
89
+ ...g ? { sort: g } : {}
89
90
  })
90
91
  ).then((e) => e.data ?? []),
91
92
  enabled: P && !!r,
92
- staleTime: j ? 0 : 3e4
93
- }), B = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], g = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), U = X.filter((e) => !g.has(e.id)), p = new Set(U.map((e) => String(e[x]))), _ = [...p], Y = JSON.stringify(h ? { _and: [{ id: { _in: _ } }, h] } : { id: { _in: _ } }), { data: m } = w({
94
- queryKey: ["m2m-avail", r, _.join(","), j],
93
+ staleTime: L ? 0 : 3e4
94
+ }), V = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], k = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), U = X.filter((e) => !k.has(e.id)), f = new Set(U.map((e) => String(e[v]))), _ = [...f], Y = JSON.stringify(h ? { _and: [{ id: { _in: _ } }, h] } : { id: { _in: _ } }), { data: m } = w({
95
+ queryKey: ["m2m-avail", r, _.join(","), L],
95
96
  queryFn: () => y.request(
96
- C(`/items/${r}`, {
97
+ q(`/items/${r}`, {
97
98
  filter: Y,
98
99
  picker: "1",
99
100
  limit: 200,
@@ -102,10 +103,10 @@ function tt({
102
103
  ).then((e) => e.data ?? []),
103
104
  enabled: !!r && _.length > 0,
104
105
  staleTime: 3e4
105
- }), Z = new Set((m ?? []).map((e) => String(e.id))), $ = m !== void 0 ? new Set(_.filter((e) => !Z.has(e))) : /* @__PURE__ */ new Set(), I = new Set(B.map(String)), A = /* @__PURE__ */ new Set([...p, ...I]), F = me(J);
106
- F.current = J, ue(() => {
106
+ }), Z = new Set((m ?? []).map((e) => String(e.id))), $ = m !== void 0 ? new Set(_.filter((e) => !Z.has(e))) : /* @__PURE__ */ new Set(), I = new Set(V.map(String)), A = /* @__PURE__ */ new Set([...f, ...I]), j = me(J);
107
+ j.current = J, ue(() => {
107
108
  var e;
108
- (e = F.current) == null || e.call(F, A.size);
109
+ (e = j.current) == null || e.call(j, A.size);
109
110
  }, [A.size]);
110
111
  function G(e) {
111
112
  const i = String(e);
@@ -113,16 +114,16 @@ function tt({
113
114
  t == null || t.unstageLink(d, e);
114
115
  return;
115
116
  }
116
- const u = X.find((M) => String(M[x]) === i);
117
+ const u = X.find((M) => String(M[v]) === i);
117
118
  if (u) {
118
- g.has(u.id) ? t == null || t.unstageUnlink(d, u.id) : t == null || t.stageUnlink(d, u.id);
119
+ k.has(u.id) ? t == null || t.unstageUnlink(d, u.id) : t == null || t.stageUnlink(d, u.id);
119
120
  return;
120
121
  }
121
122
  t == null || t.stageLink(d, e);
122
123
  }
123
- function k(e) {
124
+ function F(e) {
124
125
  const i = (a == null ? void 0 : a.display_template) ?? null;
125
- return i ? qe(i, e) : String(e._display ?? e.id ?? "");
126
+ return i ? Le(i, e) : String(e._display ?? e.id ?? "");
126
127
  }
127
128
  return K ? /* @__PURE__ */ c(
128
129
  "button",
@@ -140,20 +141,20 @@ function tt({
140
141
  ]
141
142
  }
142
143
  ) : /* @__PURE__ */ n("div", { children: /* @__PURE__ */ c(
143
- Se,
144
+ _e,
144
145
  {
145
146
  open: P,
146
147
  onOpenChange: (e) => {
147
- q(e), e || T("");
148
+ C(e), e || T("");
148
149
  },
149
150
  children: [
150
- /* @__PURE__ */ n(_e, { asChild: !0, children: /* @__PURE__ */ c(
151
+ /* @__PURE__ */ n(qe, { asChild: !0, children: /* @__PURE__ */ c(
151
152
  "div",
152
153
  {
153
154
  role: "button",
154
155
  tabIndex: 0,
155
156
  onKeyDown: (e) => {
156
- (e.key === "Enter" || e.key === " ") && (e.preventDefault(), q((i) => !i));
157
+ (e.key === "Enter" || e.key === " ") && (e.preventDefault(), C((i) => !i));
157
158
  },
158
159
  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
160
  children: [
@@ -166,7 +167,7 @@ function tt({
166
167
  },
167
168
  children: [
168
169
  U.map((e) => {
169
- const i = e[x], u = $.has(String(i));
170
+ const i = e[v], u = $.has(String(i));
170
171
  return /* @__PURE__ */ c(
171
172
  "span",
172
173
  {
@@ -221,7 +222,7 @@ function tt({
221
222
  String(e.id)
222
223
  );
223
224
  }),
224
- B.map((e) => /* @__PURE__ */ c(
225
+ V.map((e) => /* @__PURE__ */ c(
225
226
  "span",
226
227
  {
227
228
  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",
@@ -255,24 +256,24 @@ function tt({
255
256
  ]
256
257
  }
257
258
  ) }),
258
- /* @__PURE__ */ n(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(xe, { shouldFilter: !1, children: [
259
+ /* @__PURE__ */ n(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ve, { shouldFilter: !1, children: [
259
260
  /* @__PURE__ */ n(
260
- ve,
261
+ ge,
261
262
  {
262
263
  placeholder: "Search…",
263
- value: L,
264
+ value: x,
264
265
  onValueChange: T,
265
266
  className: "h-9 text-[13px]"
266
267
  }
267
268
  ),
268
- /* @__PURE__ */ c(ge, { children: [
269
- V ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(ke, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
270
- /* @__PURE__ */ n(we, { children: !V && (v ? [...O] : [...O].sort(
271
- (e, i) => b === "-label" ? k(i).localeCompare(k(e)) : k(e).localeCompare(k(i))
269
+ /* @__PURE__ */ c(ke, { children: [
270
+ B ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(we, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
271
+ /* @__PURE__ */ n(Ne, { children: !B && (g ? [...O] : [...O].sort(
272
+ (e, i) => he(F(e), F(i), x, b === "-label")
272
273
  )).map((e) => {
273
274
  const i = String(e.id), u = A.has(i);
274
275
  return /* @__PURE__ */ c(
275
- Ne,
276
+ Se,
276
277
  {
277
278
  value: i,
278
279
  onSelect: () => G(e.id),
@@ -289,11 +290,11 @@ function tt({
289
290
  }
290
291
  ),
291
292
  r === "nivaro_users" && /* @__PURE__ */ n(
292
- ye,
293
+ xe,
293
294
  {
294
295
  userId: i,
295
296
  className: "h-4 w-4",
296
- 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: je(k(e)) })
297
+ 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: Fe(F(e)) })
297
298
  }
298
299
  ),
299
300
  r === "nivaro_users" && E.has(i.toUpperCase()) && /* @__PURE__ */ n(
@@ -303,7 +304,7 @@ function tt({
303
304
  "data-tip": "Online now"
304
305
  }
305
306
  ),
306
- /* @__PURE__ */ n("span", { className: "truncate", children: k(e) })
307
+ /* @__PURE__ */ n("span", { className: "truncate", children: F(e) })
307
308
  ]
308
309
  },
309
310
  i
@@ -315,7 +316,7 @@ function tt({
315
316
  }
316
317
  ) });
317
318
  }
318
- function nt({
319
+ function rt({
319
320
  relation: s,
320
321
  parentId: o,
321
322
  allRelations: N,
@@ -325,44 +326,44 @@ function nt({
325
326
  onCountChange: J,
326
327
  readOnly: D
327
328
  }) {
328
- const y = fe(), W = Ae(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = N.find(
329
+ const y = fe(), W = Ke(), t = je(), [P, C] = ne(!1), [x, T] = ne(""), le = N.find(
329
330
  (l) => l.many_collection === s.many_collection && l.many_field === s.junction_field && l.id !== s.id
330
- ), r = Te(le), x = s.junction_field ?? "", R = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: a } = w({
331
+ ), r = Oe(le), v = s.junction_field ?? "", R = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${v}`, { data: a } = w({
331
332
  queryKey: ["col-meta", r],
332
- queryFn: () => y.request(C(`/collections/${r}`)).then((l) => l.data),
333
+ queryFn: () => y.request(q(`/collections/${r}`)).then((l) => l.data),
333
334
  enabled: !!r,
334
335
  staleTime: 3e5,
335
336
  retry: !1
336
337
  }), { data: X = [], isFetching: re } = w({
337
338
  queryKey: ["m2m-items", s.many_collection, R, o],
338
339
  queryFn: () => y.request(
339
- C(`/items/${s.many_collection}`, {
340
+ q(`/items/${s.many_collection}`, {
340
341
  filter: JSON.stringify({ [R]: { _eq: o } }),
341
342
  limit: 1,
342
- fields: `id,${x}`
343
+ fields: `id,${v}`
343
344
  })
344
345
  ).then((l) => l.data ?? []),
345
346
  staleTime: 3e4,
346
347
  enabled: !!o && o !== "new"
347
- }), z = pe().isAdmin, E = r === "nivaro_users" ? be(z) : null, H = he(r === "nivaro_users"), j = h ? E ? { _and: [h, E] } : h : E, v = j ? JSON.stringify(j) : void 0, S = b && !/^-?label$/.test(b) ? b : void 0, O = (() => {
348
+ }), z = pe().isAdmin, E = r === "nivaro_users" ? ye(z) : null, H = be(r === "nivaro_users"), L = h ? E ? { _and: [h, E] } : h : E, g = L ? JSON.stringify(L) : void 0, S = b && !/^-?label$/.test(b) ? b : void 0, O = (() => {
348
349
  const l = a == null ? void 0 : a.display_template;
349
350
  if (!l || !l.includes(".")) return null;
350
- const f = [...l.matchAll(/\{\{([^}]+)\}\}/g)].map((ee) => ee[1].trim());
351
- return f.length === 0 ? null : ["id", ...f].join(",");
352
- })(), { data: V = [], isFetching: B } = w({
351
+ const p = [...l.matchAll(/\{\{([^}]+)\}\}/g)].map((ee) => ee[1].trim());
352
+ return p.length === 0 ? null : ["id", ...p].join(",");
353
+ })(), { data: B = [], isFetching: V } = w({
353
354
  queryKey: [
354
355
  "m2m-options",
355
356
  r,
356
- L,
357
- v,
357
+ x,
358
+ g,
358
359
  S ?? "",
359
360
  O ?? ""
360
361
  ],
361
362
  queryFn: () => y.request(
362
- C(`/items/${r}`, {
363
+ q(`/items/${r}`, {
363
364
  limit: 200,
364
- search: L || void 0,
365
- filter: v,
365
+ search: x || void 0,
366
+ filter: g,
366
367
  picker: "1",
367
368
  // A dotted display template ({{core_category.name}}) needs the
368
369
  // nested expansion — a bare row only carries the FK id.
@@ -371,8 +372,8 @@ function nt({
371
372
  })
372
373
  ).then((l) => l.data ?? []),
373
374
  enabled: P && !!r,
374
- staleTime: v ? 0 : 3e4
375
- }), g = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], U = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), p = X.find((l) => !U.has(l.id)) ?? null, _ = p ? p[x] : null, Y = g.length > 0 ? g[g.length - 1] : null, m = Y ?? _, Z = g.length > 0 || U.size > 0, $ = me(J);
375
+ staleTime: g ? 0 : 3e4
376
+ }), k = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], U = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), f = X.find((l) => !U.has(l.id)) ?? null, _ = f ? f[v] : null, Y = k.length > 0 ? k[k.length - 1] : null, m = Y ?? _, Z = k.length > 0 || U.size > 0, $ = me(J);
376
377
  $.current = J, ue(() => {
377
378
  var l;
378
379
  (l = $.current) == null || l.call($, m != null ? 1 : 0);
@@ -382,10 +383,10 @@ function nt({
382
383
  queryFn: () => W(r, m),
383
384
  enabled: !!r && m != null,
384
385
  staleTime: 6e4
385
- }), A = JSON.stringify(h ? { _and: [{ id: { _eq: m } }, h] } : { id: { _eq: m } }), { data: F } = w({
386
- queryKey: ["relation-avail", r, String(m), v],
386
+ }), A = JSON.stringify(h ? { _and: [{ id: { _eq: m } }, h] } : { id: { _eq: m } }), { data: j } = w({
387
+ queryKey: ["relation-avail", r, String(m), g],
387
388
  queryFn: () => y.request(
388
- C(`/items/${r}`, {
389
+ q(`/items/${r}`, {
389
390
  filter: A,
390
391
  picker: "1",
391
392
  limit: 1,
@@ -394,20 +395,20 @@ function nt({
394
395
  ).then((l) => l.data ?? []),
395
396
  enabled: !!r && m != null && !!I,
396
397
  staleTime: 3e4
397
- }), G = F !== void 0 && F.length === 0, k = Ke(G), e = (a == null ? void 0 : a.display_template) ?? null;
398
+ }), G = j !== void 0 && j.length === 0, F = Je(G), e = (a == null ? void 0 : a.display_template) ?? null;
398
399
  function i(l) {
399
- return e ? qe(e, l) : String(l.name ?? l.title ?? l.label ?? l.id ?? "");
400
+ return e ? Le(e, l) : String(l.name ?? l.title ?? l.label ?? l.id ?? "");
400
401
  }
401
- const u = V.find((l) => String(l.id) === String(m)) ?? I, M = m != null && !I && !u, se = u ? i(u) : null;
402
+ const u = B.find((l) => String(l.id) === String(m)) ?? I, M = m != null && !I && !u, se = u ? i(u) : null;
402
403
  if (D)
403
404
  return /* @__PURE__ */ n("span", { className: "block truncate text-[12px] text-slate-700 dark:text-slate-200", children: M ? "…" : se ?? "—" });
404
- function Oe(l) {
405
- for (const f of g) t == null || t.unstageLink(d, f);
406
- p && !U.has(p.id) && (t == null || t.stageUnlink(d, p.id)), String(l) === String(_) && p ? t == null || t.unstageUnlink(d, p.id) : String(l) !== String(m) && (t == null || t.stageLink(d, l)), q(!1), T("");
405
+ function Ue(l) {
406
+ for (const p of k) t == null || t.unstageLink(d, p);
407
+ f && !U.has(f.id) && (t == null || t.stageUnlink(d, f.id)), String(l) === String(_) && f ? t == null || t.unstageUnlink(d, f.id) : String(l) !== String(m) && (t == null || t.stageLink(d, l)), C(!1), T("");
407
408
  }
408
- function Ue() {
409
- for (const l of g) t == null || t.unstageLink(d, l);
410
- p && (t == null || t.stageUnlink(d, p.id)), q(!1);
409
+ function $e() {
410
+ for (const l of k) t == null || t.unstageLink(d, l);
411
+ f && (t == null || t.stageUnlink(d, f.id)), C(!1);
411
412
  }
412
413
  return K ? /* @__PURE__ */ c(
413
414
  "button",
@@ -424,16 +425,16 @@ function nt({
424
425
  /* @__PURE__ */ n(te, { className: "h-4 w-4 shrink-0 opacity-50" })
425
426
  ]
426
427
  }
427
- ) : /* @__PURE__ */ c("div", { ...k.bind, children: [
428
+ ) : /* @__PURE__ */ c("div", { ...F.bind, children: [
428
429
  /* @__PURE__ */ c(
429
- Se,
430
+ _e,
430
431
  {
431
432
  open: P,
432
433
  onOpenChange: (l) => {
433
- q(l), l || T("");
434
+ C(l), l || T("");
434
435
  },
435
436
  children: [
436
- /* @__PURE__ */ n(_e, { asChild: !0, children: /* @__PURE__ */ c(
437
+ /* @__PURE__ */ n(qe, { asChild: !0, children: /* @__PURE__ */ c(
437
438
  "button",
438
439
  {
439
440
  type: "button",
@@ -459,12 +460,12 @@ function nt({
459
460
  ]
460
461
  }
461
462
  ) }),
462
- /* @__PURE__ */ n(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(xe, { shouldFilter: !1, children: [
463
+ /* @__PURE__ */ n(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ve, { shouldFilter: !1, children: [
463
464
  /* @__PURE__ */ n(
464
- ve,
465
+ ge,
465
466
  {
466
467
  placeholder: "Search…",
467
- value: L,
468
+ value: x,
468
469
  onValueChange: T,
469
470
  className: "h-9 text-[12px]"
470
471
  }
@@ -474,7 +475,7 @@ function nt({
474
475
  {
475
476
  type: "button",
476
477
  onClick: () => {
477
- Ue(), q(!1);
478
+ $e(), C(!1);
478
479
  },
479
480
  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",
480
481
  children: [
@@ -483,17 +484,17 @@ function nt({
483
484
  ]
484
485
  }
485
486
  ),
486
- /* @__PURE__ */ c(ge, { children: [
487
- B ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(ke, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
488
- !B && /* @__PURE__ */ n(we, { children: [...V].sort(
489
- (l, f) => S ? 0 : b === "-label" ? i(f).localeCompare(i(l)) : i(l).localeCompare(i(f))
487
+ /* @__PURE__ */ c(ke, { children: [
488
+ V ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(ae, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ n(we, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
489
+ !V && /* @__PURE__ */ n(Ne, { children: [...B].sort(
490
+ (l, p) => S ? 0 : he(i(l), i(p), x, b === "-label")
490
491
  ).map((l) => {
491
- const f = String(l.id), ee = String(m) === f;
492
+ const p = String(l.id), ee = String(m) === p;
492
493
  return /* @__PURE__ */ c(
493
- Ne,
494
+ Se,
494
495
  {
495
- value: f,
496
- onSelect: () => Oe(l.id),
496
+ value: p,
497
+ onSelect: () => Ue(l.id),
497
498
  className: "flex items-center gap-2 text-[12px]",
498
499
  children: [
499
500
  /* @__PURE__ */ n(
@@ -507,14 +508,14 @@ function nt({
507
508
  }
508
509
  ),
509
510
  r === "nivaro_users" && /* @__PURE__ */ n(
510
- ye,
511
+ xe,
511
512
  {
512
- userId: f,
513
+ userId: p,
513
514
  className: "h-4 w-4",
514
- 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: je(i(l)) })
515
+ 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: Fe(i(l)) })
515
516
  }
516
517
  ),
517
- r === "nivaro_users" && H.has(f.toUpperCase()) && /* @__PURE__ */ n(
518
+ r === "nivaro_users" && H.has(p.toUpperCase()) && /* @__PURE__ */ n(
518
519
  "span",
519
520
  {
520
521
  className: "h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",
@@ -524,7 +525,7 @@ function nt({
524
525
  /* @__PURE__ */ n("span", { className: "truncate", children: i(l) })
525
526
  ]
526
527
  },
527
- f
528
+ p
528
529
  );
529
530
  }) })
530
531
  ] })
@@ -532,12 +533,12 @@ function nt({
532
533
  ]
533
534
  }
534
535
  ),
535
- k.tip
536
+ F.tip
536
537
  ] });
537
538
  }
538
539
  export {
539
- tt as M2MCombobox,
540
- nt as M2MSingleSelectCombobox,
541
- et as m2aWriteMeta,
542
- Te as resolveM2MRelatedCollection
540
+ lt as M2MCombobox,
541
+ rt as M2MSingleSelectCombobox,
542
+ nt as m2aWriteMeta,
543
+ Oe as resolveM2MRelatedCollection
543
544
  };
@@ -1,30 +1,31 @@
1
1
  import { jsxs as c, jsx as n } from "react/jsx-runtime";
2
- import { useQuery as k } from "@tanstack/react-query";
2
+ import { useQuery as S } from "@tanstack/react-query";
3
3
  import { ChevronDown as Se, Loader2 as Q, AlertTriangle as Ue, Search as Ae, X as Me, Check as qe } from "lucide-react";
4
- import { useState as C, useRef as Z, useEffect as O, useLayoutEffect as De, useMemo as I } from "react";
4
+ import { useState as $, useRef as Z, useEffect as O, useLayoutEffect as De, useMemo as I } from "react";
5
5
  import { createPortal as _e } from "react-dom";
6
6
  import { useNivaroClient as ie, useItemEditAuth as Je, useStaleFieldReporter as ze } from "../../context.js";
7
7
  import { get as j, post as He } from "../../lib/commands.js";
8
- import { useRecordReader as Ce } from "../../lib/record-loader.js";
9
- import { useOnlineUsers as Ye } from "../../lib/use-online-users.js";
10
- import { UserAvatar as We } from "../UserAvatar.js";
11
- import { userOptionFilter as Xe, cn as D } from "../../lib/utils.js";
12
- import { applyDisplayTemplate as v } from "./helpers.js";
13
- import { collidingIds as Ge, disambiguators as Ve } from "./option-disambiguate.js";
14
- import { usePickerMissReport as Ze } from "./picker-miss.js";
15
- import { useLatestSearch as Qe, narrowLocally as Be } from "./picker-search.js";
16
- function et(o) {
17
- return o.replace(/\(.*$/, "").trim().split(/\s+/).map((r) => r[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
8
+ import { compareByMatch as Ye } from "../../lib/picker-rank.js";
9
+ import { useRecordReader as $e } from "../../lib/record-loader.js";
10
+ import { useOnlineUsers as We } from "../../lib/use-online-users.js";
11
+ import { UserAvatar as Xe } from "../UserAvatar.js";
12
+ import { userOptionFilter as Ge, cn as D } from "../../lib/utils.js";
13
+ import { applyDisplayTemplate as k } from "./helpers.js";
14
+ import { collidingIds as Ve, disambiguators as Ze } from "./option-disambiguate.js";
15
+ import { usePickerMissReport as Qe } from "./picker-miss.js";
16
+ import { useLatestSearch as Be, narrowLocally as et } from "./picker-search.js";
17
+ function tt(s) {
18
+ return s.replace(/\(.*$/, "").trim().split(/\s+/).map((r) => r[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
18
19
  }
19
- function tt(o) {
20
- const [r, d] = C(null), y = {
21
- onMouseEnter: (g) => {
22
- if (!o) return;
23
- const m = g.currentTarget.getBoundingClientRect(), u = window.innerHeight - m.bottom < 80;
20
+ function rt(s) {
21
+ const [r, d] = $(null), x = {
22
+ onMouseEnter: (h) => {
23
+ if (!s) return;
24
+ const m = h.currentTarget.getBoundingClientRect(), u = window.innerHeight - m.bottom < 80;
24
25
  d({ x: m.left, y: u ? m.top - 58 : m.bottom + 4 });
25
26
  },
26
27
  onMouseLeave: () => d(null)
27
- }, S = o && r ? _e(
28
+ }, q = s && r ? _e(
28
29
  /* @__PURE__ */ n(
29
30
  "div",
30
31
  {
@@ -35,49 +36,49 @@ function tt(o) {
35
36
  ),
36
37
  document.body
37
38
  ) : null;
38
- return { bind: y, tip: S };
39
+ return { bind: x, tip: q };
39
40
  }
40
- function rt({
41
- collection: o,
41
+ function nt({
42
+ collection: s,
42
43
  value: r,
43
44
  onChange: d,
44
- disabled: y,
45
- placeholder: S,
46
- extraFilter: g,
45
+ disabled: x,
46
+ placeholder: q,
47
+ extraFilter: h,
47
48
  autoSelectSingle: m,
48
49
  optionSort: u,
49
50
  requiredParent: R,
50
51
  facets: i,
51
- fieldKey: $,
52
+ fieldKey: C,
52
53
  narrowedBy: l,
53
54
  pinned: p,
54
- missPlacement: q
55
+ missPlacement: _
55
56
  }) {
56
- const F = ie(), ae = Ce(), [w, K] = C(!1), [_, le] = C(""), [$e, Le] = C(!1), L = Qe(_, $e), de = Z(null), J = Z(null);
57
+ const F = ie(), ae = $e(), [y, K] = $(!1), [N, le] = $(""), [Ce, Le] = $(!1), L = Be(N, Ce), de = Z(null), J = Z(null);
57
58
  O(() => {
58
- w ? setTimeout(() => {
59
+ y ? setTimeout(() => {
59
60
  var e;
60
61
  return (e = de.current) == null ? void 0 : e.focus();
61
62
  }, 30) : le("");
62
- }, [w]), O(() => {
63
- if (!w) return;
64
- const e = (s) => {
63
+ }, [y]), O(() => {
64
+ if (!y) return;
65
+ const e = (o) => {
65
66
  var a;
66
- const t = s.target;
67
- (a = t == null ? void 0 : t.closest) != null && a.call(t, "[data-nvr-combobox-panel]") || J.current && !J.current.contains(s.target) && K(!1);
67
+ const t = o.target;
68
+ (a = t == null ? void 0 : t.closest) != null && a.call(t, "[data-nvr-combobox-panel]") || J.current && !J.current.contains(o.target) && K(!1);
68
69
  };
69
70
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
70
- }, [w]);
71
- const [ce, B] = C(null), [ue, je] = C(null);
71
+ }, [y]);
72
+ const [ce, B] = $(null), [ue, je] = $(null);
72
73
  De(() => {
73
- if (!w) {
74
+ if (!y) {
74
75
  B(null);
75
76
  return;
76
77
  }
77
78
  const e = () => {
78
- const s = J.current;
79
- if (!s) return;
80
- const t = s.getBoundingClientRect(), a = s.closest('[role="dialog"]') ?? document.body;
79
+ const o = J.current;
80
+ if (!o) return;
81
+ const t = o.getBoundingClientRect(), a = o.closest('[role="dialog"]') ?? document.body;
81
82
  je(a);
82
83
  const ye = window.innerHeight - t.bottom < 340 && t.top > window.innerHeight - t.bottom, we = t.left, ve = ye ? t.top - 4 : t.bottom + 4, Ne = {
83
84
  minWidth: t.width,
@@ -94,104 +95,104 @@ function rt({
94
95
  return e(), window.addEventListener("scroll", e, !0), window.addEventListener("resize", e), () => {
95
96
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
96
97
  };
97
- }, [w]);
98
- const { data: ee, isPending: Re } = k({
99
- queryKey: ["col-meta", o],
100
- queryFn: () => F.request(j(`/collections/${o}`)).then((e) => e.data),
98
+ }, [y]);
99
+ const { data: ee, isPending: Re } = S({
100
+ queryKey: ["col-meta", s],
101
+ queryFn: () => F.request(j(`/collections/${s}`)).then((e) => e.data),
101
102
  staleTime: 3e5,
102
103
  retry: !1
103
- }), [te, Fe] = C({}), { data: me = [] } = k({
104
- queryKey: ["collection-meta", o],
104
+ }), [te, Fe] = $({}), { data: me = [] } = S({
105
+ queryKey: ["collection-meta", s],
105
106
  queryFn: () => F.request(
106
- j(`/collections/${o}`)
107
+ j(`/collections/${s}`)
107
108
  ).then(
108
109
  (e) => {
109
- var s;
110
- return ((s = e.data) == null ? void 0 : s.relations) ?? [];
110
+ var o;
111
+ return ((o = e.data) == null ? void 0 : o.relations) ?? [];
111
112
  }
112
113
  ),
113
114
  enabled: !!(i != null && i.length),
114
115
  staleTime: 10 * 6e4
115
116
  }), Te = I(() => {
116
117
  const e = {};
117
- for (const s of i ?? []) {
118
+ for (const o of i ?? []) {
118
119
  const t = me.find(
119
- (a) => a.many_collection === o && a.many_field === s.field && !a.junction_field
120
+ (a) => a.many_collection === s && a.many_field === o.field && !a.junction_field
120
121
  );
121
- t != null && t.one_collection && (e[s.field] = t.one_collection);
122
+ t != null && t.one_collection && (e[o.field] = t.one_collection);
122
123
  }
123
124
  return e;
124
- }, [i, me, o]), T = o === "nivaro_users", Ee = Ye(T), pe = Je().isAdmin, re = I(() => {
125
+ }, [i, me, s]), T = s === "nivaro_users", Ee = We(T), pe = Je().isAdmin, re = I(() => {
125
126
  const e = [];
126
- T && e.push(Xe(pe)), g && e.push(g);
127
- for (const [s, t] of Object.entries(te))
128
- t != null && t !== "" && e.push({ [s]: { _eq: t } });
127
+ T && e.push(Ge(pe)), h && e.push(h);
128
+ for (const [o, t] of Object.entries(te))
129
+ t != null && t !== "" && e.push({ [o]: { _eq: t } });
129
130
  if (e.length !== 0)
130
131
  return e.length === 1 ? e[0] : { _and: e };
131
- }, [g, te, pe]), z = (ee == null ? void 0 : ee.display_template) ?? (T ? "{{first_name}} {{last_name}} ({{email}})" : null), b = I(() => {
132
+ }, [h, te, pe]), z = (ee == null ? void 0 : ee.display_template) ?? (T ? "{{first_name}} {{last_name}} ({{email}})" : null), g = I(() => {
132
133
  if (!z) return;
133
- const e = [...z.matchAll(/\{\{([\w.]+)\}\}/g)].map((s) => s[1]);
134
+ const e = [...z.matchAll(/\{\{([\w.]+)\}\}/g)].map((o) => o[1]);
134
135
  if (e.length)
135
136
  return ["id", ...e].join(",");
136
- }, [z]), N = re ? JSON.stringify(re) : void 0, P = u && !/^-?label$/.test(u) ? u : void 0, {
137
+ }, [z]), v = re ? JSON.stringify(re) : void 0, P = u && !/^-?label$/.test(u) ? u : void 0, {
137
138
  data: f,
138
139
  isFetching: E,
139
140
  isPlaceholderData: fe
140
- } = k({
141
+ } = S({
141
142
  queryKey: [
142
143
  "relation-opts",
143
- o,
144
+ s,
144
145
  L,
145
- N,
146
- b,
146
+ v,
147
+ g,
147
148
  P ?? ""
148
149
  ],
149
150
  queryFn: () => F.request(
150
- j(`/items/${o}`, {
151
+ j(`/items/${s}`, {
151
152
  limit: 200,
152
153
  picker: "1",
153
154
  ...L ? { search: L } : {},
154
- ...N ? { filter: N } : {},
155
- ...b ? { fields: b } : {},
155
+ ...v ? { filter: v } : {},
156
+ ...g ? { fields: g } : {},
156
157
  ...P ? { sort: P } : {}
157
158
  })
158
159
  ).then((e) => e.data ?? []),
159
160
  // Wait for the display template: it decides `fields`, and starting before
160
161
  // it lands sent the whole first page twice.
161
- enabled: w && !Re,
162
- staleTime: N ? 0 : 3e4,
162
+ enabled: y && !Re,
163
+ staleTime: v ? 0 : 3e4,
163
164
  // A new SEARCH keeps the previous answer on screen (narrowed locally below)
164
165
  // instead of blanking the list behind a spinner. A changed filter, sort or
165
166
  // template never does — those rows may no longer be allowed.
166
- placeholderData: (e, s) => {
167
- const t = s == null ? void 0 : s.queryKey;
167
+ placeholderData: (e, o) => {
168
+ const t = o == null ? void 0 : o.queryKey;
168
169
  if (!(!e || !t))
169
- return t[1] === o && t[3] === N && t[4] === b && t[5] === (P ?? "") ? e : void 0;
170
+ return t[1] === s && t[3] === v && t[4] === g && t[5] === (P ?? "") ? e : void 0;
170
171
  }
171
172
  });
172
- O(() => Le(E), [E]), Ze({
173
- placement: q,
174
- open: w,
173
+ O(() => Le(E), [E]), Qe({
174
+ placement: _,
175
+ open: y,
175
176
  search: L,
176
177
  settled: !E && !fe && f !== void 0,
177
178
  count: (f == null ? void 0 : f.length) ?? 0
178
179
  });
179
- const { data: H, isLoading: Oe } = k({
180
- queryKey: ["relation-single", o, String(r), b],
181
- queryFn: () => ae(o, r, b),
180
+ const { data: H, isLoading: Oe } = S({
181
+ queryKey: ["relation-single", s, String(r), g],
182
+ queryFn: () => ae(s, r, g),
182
183
  enabled: !!r,
183
184
  staleTime: 6e4
184
- }), x = (p == null ? void 0 : p.id) != null && p.id !== "" ? String(p.id) : null, { data: U } = k({
185
- queryKey: ["relation-single", o, x ?? "", b],
186
- queryFn: () => ae(o, x, b).catch(
185
+ }), b = (p == null ? void 0 : p.id) != null && p.id !== "" ? String(p.id) : null, { data: U } = S({
186
+ queryKey: ["relation-single", s, b ?? "", g],
187
+ queryFn: () => ae(s, b, g).catch(
187
188
  () => null
188
189
  ),
189
- enabled: !!x && w,
190
+ enabled: !!b && y,
190
191
  staleTime: 6e4
191
- }), Ie = JSON.stringify(g ? { _and: [{ id: { _eq: r } }, g] } : { id: { _eq: r } }), { data: Y } = k({
192
- queryKey: ["relation-avail", o, String(r), N],
192
+ }), Ie = JSON.stringify(h ? { _and: [{ id: { _eq: r } }, h] } : { id: { _eq: r } }), { data: Y } = S({
193
+ queryKey: ["relation-avail", s, String(r), v],
193
194
  queryFn: () => F.request(
194
- j(`/items/${o}`, {
195
+ j(`/items/${s}`, {
195
196
  filter: Ie,
196
197
  picker: "1",
197
198
  limit: 1,
@@ -201,74 +202,74 @@ function rt({
201
202
  // The pinned option is offered OUTSIDE the option filter (a type's generic
202
203
  // item is excluded from the general list on purpose), so a value that IS
203
204
  // the pin is available by construction — never probe it, never flag it.
204
- enabled: !!r && !!H && String(r) !== x,
205
+ enabled: !!r && !!H && String(r) !== b,
205
206
  staleTime: 3e4
206
- }), A = !!r && String(r) !== x && Y !== void 0 && Y.length === 0, W = Z(null), ne = Z(!1), he = `${o}|${N ?? ""}`, Ke = () => {
207
+ }), A = !!r && String(r) !== b && Y !== void 0 && Y.length === 0, W = Z(null), ne = Z(!1), he = `${s}|${v ?? ""}`, Ke = () => {
207
208
  ne.current = !0, W.current = he, d(null);
208
209
  }, X = r == null || r === "";
209
210
  O(() => {
210
211
  X || (ne.current = !1);
211
212
  }, [X]), O(() => {
212
- if (!m || y || !X || ne.current) return;
213
+ if (!m || x || !X || ne.current) return;
213
214
  const e = he;
214
215
  W.current !== e && (W.current = e, F.request(
215
- j(`/items/${o}`, {
216
+ j(`/items/${s}`, {
216
217
  limit: 2,
217
218
  picker: "1",
218
219
  fields: "id",
219
- ...N ? { filter: N } : {}
220
+ ...v ? { filter: v } : {}
220
221
  })
221
- ).then((s) => {
222
+ ).then((o) => {
222
223
  var a;
223
- const t = s.data ?? [];
224
+ const t = o.data ?? [];
224
225
  t.length === 1 && ((a = t[0]) == null ? void 0 : a.id) != null && d(t[0].id);
225
226
  }).catch(() => {
226
227
  W.current = null;
227
228
  }));
228
- }, [m, y, X, o, N]);
229
- const h = z, ge = r && H ? v(h, H) : null, se = !fe && _ === L, G = I(
230
- () => Be(
229
+ }, [m, x, X, s, v]);
230
+ const w = z, ge = r && H ? k(w, H) : null, se = !fe && N === L, G = I(
231
+ () => et(
231
232
  f ?? [],
232
- (e) => v(h, e) || `#${e.id}`,
233
- _,
233
+ (e) => k(w, e) || `#${e.id}`,
234
+ N,
234
235
  se
235
236
  ),
236
- [f, h, _, se]
237
+ [f, w, N, se]
237
238
  ), V = I(
238
- () => Ge(f ?? [], (e) => v(h, e) || `#${e.id}`),
239
- [f, h]
240
- ), { data: M } = k({
241
- queryKey: ["relation-opts-dups", o, V.join(",")],
239
+ () => Ve(f ?? [], (e) => k(w, e) || `#${e.id}`),
240
+ [f, w]
241
+ ), { data: M } = S({
242
+ queryKey: ["relation-opts-dups", s, V.join(",")],
242
243
  queryFn: () => F.request(
243
- j(`/items/${o}`, {
244
+ j(`/items/${s}`, {
244
245
  limit: V.length,
245
246
  picker: "1",
246
247
  filter: JSON.stringify({ id: { _in: V } }),
247
248
  fields: "*"
248
249
  })
249
250
  ).then((e) => e.data ?? []),
250
- enabled: w && V.length > 0 && !T,
251
+ enabled: y && V.length > 0 && !T,
251
252
  staleTime: 6e4
252
253
  }), be = I(() => {
253
254
  if (!(M != null && M.length)) return /* @__PURE__ */ new Map();
254
255
  const e = new Map(
255
256
  (f ?? []).map((t) => [
256
257
  String(t.id),
257
- (v(h, t) || `#${t.id}`).trim().toLowerCase()
258
+ (k(w, t) || `#${t.id}`).trim().toLowerCase()
258
259
  ])
259
- ), s = /* @__PURE__ */ new Map();
260
+ ), o = /* @__PURE__ */ new Map();
260
261
  for (const t of M) {
261
262
  const a = e.get(String(t.id));
262
- a !== void 0 && s.set(a, [...s.get(a) ?? [], t]);
263
+ a !== void 0 && o.set(a, [...o.get(a) ?? [], t]);
263
264
  }
264
- return Ve(
265
- [...s.values()],
266
- ((b == null ? void 0 : b.split(",")) ?? []).map((t) => t.split(".")[0])
265
+ return Ze(
266
+ [...o.values()],
267
+ ((g == null ? void 0 : g.split(",")) ?? []).map((t) => t.split(".")[0])
267
268
  );
268
- }, [M, f, h, b]), Pe = !!r && Oe && !H, xe = tt(A), oe = ze();
269
+ }, [M, f, w, g]), Pe = !!r && Oe && !H, xe = rt(A), oe = ze();
269
270
  return O(() => {
270
- !oe || !$ || Y === void 0 || oe($, A);
271
- }, [oe, $, A, Y]), R ? /* @__PURE__ */ c(
271
+ !oe || !C || Y === void 0 || oe(C, A);
272
+ }, [oe, C, A, Y]), R ? /* @__PURE__ */ c(
272
273
  "button",
273
274
  {
274
275
  type: "button",
@@ -291,7 +292,7 @@ function rt({
291
292
  "button",
292
293
  {
293
294
  type: "button",
294
- disabled: y,
295
+ disabled: x,
295
296
  onClick: () => K((e) => !e),
296
297
  className: D(
297
298
  "flex h-9 w-full items-center justify-between gap-2 rounded-md border bg-background px-3 text-sm text-left hover:bg-muted disabled:pointer-events-none disabled:opacity-50",
@@ -307,7 +308,7 @@ function rt({
307
308
  ),
308
309
  children: [
309
310
  A && /* @__PURE__ */ n(Ue, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
310
- /* @__PURE__ */ n("span", { className: "truncate", children: ge ?? S ?? "Select…" })
311
+ /* @__PURE__ */ n("span", { className: "truncate", children: ge ?? q ?? "Select…" })
311
312
  ]
312
313
  }
313
314
  ),
@@ -316,7 +317,7 @@ function rt({
316
317
  }
317
318
  ),
318
319
  xe.tip,
319
- w && ce && ue && _e(
320
+ y && ce && ue && _e(
320
321
  /* @__PURE__ */ c(
321
322
  "div",
322
323
  {
@@ -328,13 +329,13 @@ function rt({
328
329
  ),
329
330
  children: [
330
331
  !!(i != null && i.length) && /* @__PURE__ */ n("div", { className: "grid grid-cols-2 gap-2 border-b border-border bg-slate-50/60 p-2 dark:bg-muted/40", children: i.map((e) => {
331
- const s = Te[e.field];
332
- return s ? /* @__PURE__ */ c("div", { children: [
332
+ const o = Te[e.field];
333
+ return o ? /* @__PURE__ */ c("div", { children: [
333
334
  /* @__PURE__ */ n("p", { className: "mb-0.5 text-[10px] font-medium uppercase tracking-wide text-slate-400", children: e.label ?? e.field }),
334
335
  /* @__PURE__ */ n(
335
- rt,
336
+ nt,
336
337
  {
337
- collection: s,
338
+ collection: o,
338
339
  value: te[e.field] ?? null,
339
340
  onChange: (t) => Fe((a) => ({ ...a, [e.field]: t })),
340
341
  placeholder: "Any",
@@ -350,7 +351,7 @@ function rt({
350
351
  "input",
351
352
  {
352
353
  ref: de,
353
- value: _,
354
+ value: N,
354
355
  onChange: (e) => le(e.target.value),
355
356
  placeholder: "Search…",
356
357
  className: "flex h-9 w-full bg-transparent py-3 text-[13px] outline-none placeholder:text-muted-foreground"
@@ -365,7 +366,7 @@ function rt({
365
366
  )
366
367
  ] }),
367
368
  /* @__PURE__ */ c("div", { className: "max-h-52 overflow-y-auto py-1", children: [
368
- !!r && !y && /* @__PURE__ */ c(
369
+ !!r && !x && /* @__PURE__ */ c(
369
370
  "button",
370
371
  {
371
372
  type: "button",
@@ -379,7 +380,7 @@ function rt({
379
380
  ]
380
381
  }
381
382
  ),
382
- x && /* @__PURE__ */ c(
383
+ b && /* @__PURE__ */ c(
383
384
  "button",
384
385
  {
385
386
  type: "button",
@@ -394,24 +395,24 @@ function rt({
394
395
  {
395
396
  className: D(
396
397
  "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",
397
- String(r) === x ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
398
+ String(r) === b ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300"
398
399
  ),
399
- children: String(r) === x && /* @__PURE__ */ n(qe, { className: "h-2.5 w-2.5 text-white" })
400
+ children: String(r) === b && /* @__PURE__ */ n(qe, { className: "h-2.5 w-2.5 text-white" })
400
401
  }
401
402
  ),
402
- /* @__PURE__ */ n("span", { className: "min-w-0 flex-1 truncate", children: U ? v(h, U) || `#${x}` : `#${x}` }),
403
+ /* @__PURE__ */ n("span", { className: "min-w-0 flex-1 truncate", children: U ? k(w, U) || `#${b}` : `#${b}` }),
403
404
  /* @__PURE__ */ n("span", { className: "shrink-0 rounded bg-nvr-cyan/15 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-slate-700 dark:text-foreground", children: (p == null ? void 0 : p.tag) ?? "Default" })
404
405
  ]
405
406
  }
406
407
  ),
407
- f === void 0 && E ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(Q, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : G.length === 0 && !se ? /* @__PURE__ */ n("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: "Searching…" }) : G.length === 0 ? l && l.labels.length > 0 && !_.trim() ? /* @__PURE__ */ c("div", { className: "px-3 py-2 text-[12px] leading-5 text-muted-foreground", children: [
408
+ f === void 0 && E ? /* @__PURE__ */ n("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ n(Q, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : G.length === 0 && !se ? /* @__PURE__ */ n("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: "Searching…" }) : G.length === 0 ? l && l.labels.length > 0 && !N.trim() ? /* @__PURE__ */ c("div", { className: "px-3 py-2 text-[12px] leading-5 text-muted-foreground", children: [
408
409
  /* @__PURE__ */ c("p", { children: [
409
410
  "No options for",
410
411
  " ",
411
412
  /* @__PURE__ */ n("span", { className: "font-medium text-foreground", children: l.labels.join(" · ") }),
412
413
  l.onClear ? " — clear one to widen the list:" : "."
413
414
  ] }),
414
- l.onClear && /* @__PURE__ */ n("div", { className: "mt-1.5 flex flex-wrap gap-1.5", children: l.keys.map((e, s) => /* @__PURE__ */ c(
415
+ l.onClear && /* @__PURE__ */ n("div", { className: "mt-1.5 flex flex-wrap gap-1.5", children: l.keys.map((e, o) => /* @__PURE__ */ c(
415
416
  "button",
416
417
  {
417
418
  type: "button",
@@ -422,15 +423,20 @@ function rt({
422
423
  className: "rounded-md border border-border bg-background px-2 py-0.5 text-[11.5px] font-medium text-foreground transition-colors duration-150 hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nvr-cyan",
423
424
  children: [
424
425
  "Clear ",
425
- l.labels[s] ?? e
426
+ l.labels[o] ?? e
426
427
  ]
427
428
  },
428
429
  e
429
430
  )) })
430
- ] }) : /* @__PURE__ */ n("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: _.trim() ? `No results for “${_.trim()}”` : "No results" }) : (P ? [...G] : [...G].sort(
431
- (e, s) => u === "-label" ? v(h, s).localeCompare(v(h, e)) : v(h, e).localeCompare(v(h, s))
432
- )).filter((e) => !x || String(e.id) !== x).map((e) => {
433
- const s = v(h, e) || `#${e.id}`, t = String(e.id) === String(r);
431
+ ] }) : /* @__PURE__ */ n("p", { className: "px-3 py-2 text-[13px] text-muted-foreground", children: N.trim() ? `No results for “${N.trim()}”` : "No results" }) : (P ? [...G] : [...G].sort(
432
+ (e, o) => Ye(
433
+ k(w, e),
434
+ k(w, o),
435
+ N,
436
+ u === "-label"
437
+ )
438
+ )).filter((e) => !b || String(e.id) !== b).map((e) => {
439
+ const o = k(w, e) || `#${e.id}`, t = String(e.id) === String(r);
434
440
  return /* @__PURE__ */ c(
435
441
  "button",
436
442
  {
@@ -451,11 +457,11 @@ function rt({
451
457
  }
452
458
  ),
453
459
  T && /* @__PURE__ */ n(
454
- We,
460
+ Xe,
455
461
  {
456
462
  userId: e.id,
457
463
  className: "h-4 w-4",
458
- 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: et(s) })
464
+ 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: tt(o) })
459
465
  }
460
466
  ),
461
467
  T && Ee.has(String(e.id).toUpperCase()) && /* @__PURE__ */ n(
@@ -465,7 +471,7 @@ function rt({
465
471
  "data-tip": "Online now"
466
472
  }
467
473
  ),
468
- s,
474
+ o,
469
475
  be.has(String(e.id)) && /* @__PURE__ */ n(
470
476
  "span",
471
477
  {
@@ -481,9 +487,9 @@ function rt({
481
487
  })
482
488
  ] }),
483
489
  !E && /* @__PURE__ */ n(
484
- nt,
490
+ st,
485
491
  {
486
- collection: o,
492
+ collection: s,
487
493
  search: L,
488
494
  filter: re,
489
495
  narrowedLabels: (l == null ? void 0 : l.labels) ?? [],
@@ -498,41 +504,41 @@ function rt({
498
504
  ] })
499
505
  );
500
506
  }
501
- function nt({
502
- collection: o,
507
+ function st({
508
+ collection: s,
503
509
  search: r,
504
510
  filter: d,
505
- narrowedLabels: y,
506
- auto: S
511
+ narrowedLabels: x,
512
+ auto: q
507
513
  }) {
508
- const g = ie(), [m, u] = C(!1), R = d ? JSON.stringify(d) : "", { data: i, isFetching: $ } = k({
509
- queryKey: ["picker-narrowing", o, r, R],
510
- queryFn: () => g.request(
511
- He("/picker-narrowing", { collection: o, search: r, filter: d ?? null })
512
- ).then((q) => q.data),
513
- enabled: m || S,
514
+ const h = ie(), [m, u] = $(!1), R = d ? JSON.stringify(d) : "", { data: i, isFetching: C } = S({
515
+ queryKey: ["picker-narrowing", s, r, R],
516
+ queryFn: () => h.request(
517
+ He("/picker-narrowing", { collection: s, search: r, filter: d ?? null })
518
+ ).then((_) => _.data),
519
+ enabled: m || q,
514
520
  staleTime: 3e4,
515
521
  retry: !1
516
522
  });
517
- if (!m && !S)
523
+ if (!m && !q)
518
524
  return /* @__PURE__ */ n(
519
525
  "button",
520
526
  {
521
527
  type: "button",
522
- onClick: (q) => {
523
- q.stopPropagation(), u(!0);
528
+ onClick: (_) => {
529
+ _.stopPropagation(), u(!0);
524
530
  },
525
531
  className: "w-full border-t border-border px-3 py-1.5 text-left text-[11px] text-muted-foreground hover:text-foreground",
526
532
  "data-picker-narrowing-ask": !0,
527
533
  children: "Missing something?"
528
534
  }
529
535
  );
530
- if ($ && !i)
536
+ if (C && !i)
531
537
  return /* @__PURE__ */ n("p", { className: "border-t border-border px-3 py-1.5 text-[11px] text-muted-foreground", children: "Checking what narrows this list…" });
532
538
  if (!i) return null;
533
539
  const l = [], p = r ? `match “${r}”` : "exist";
534
540
  return i.by_field_filter > 0 && l.push(
535
- `${i.by_field_filter.toLocaleString()} more ${p} but this field only offers ${y.length ? `records that fit ${y.join(" · ")}` : "records its filter allows"}.`
541
+ `${i.by_field_filter.toLocaleString()} more ${p} but this field only offers ${x.length ? `records that fit ${x.join(" · ")}` : "records its filter allows"}.`
536
542
  ), i.by_exclusions > 0 && l.push(
537
543
  `${i.by_exclusions.toLocaleString()} ${i.by_exclusions === 1 ? "is" : "are"} hidden from pickers by an admin.`
538
544
  ), i.scopes.length > 0 && l.push(`Your ${i.scopes.join(", ")} access narrows what you can pick here.`), i.row_filter && l.push("Your role only sees some of these records."), l.length === 0 && l.push(
@@ -544,42 +550,42 @@ function nt({
544
550
  "data-picker-narrowing": !0,
545
551
  "data-picker-narrowing-field": i.by_field_filter,
546
552
  "data-picker-narrowing-excluded": i.by_exclusions,
547
- children: l.map((q) => /* @__PURE__ */ n("p", { children: q }, q))
553
+ children: l.map((_) => /* @__PURE__ */ n("p", { children: _ }, _))
548
554
  }
549
555
  );
550
556
  }
551
- function yt({
552
- collection: o,
557
+ function vt({
558
+ collection: s,
553
559
  id: r,
554
560
  displayTemplate: d
555
561
  }) {
556
- const y = ie(), S = Ce(), g = o === "nivaro_files" || o === "directus_files", m = (() => {
562
+ const x = ie(), q = $e(), h = s === "nivaro_files" || s === "directus_files", m = (() => {
557
563
  if (!d || !d.includes(".")) return null;
558
- const i = [...d.matchAll(/\{\{([^}]+)\}\}/g)].map(($) => $[1].trim());
564
+ const i = [...d.matchAll(/\{\{([^}]+)\}\}/g)].map((C) => C[1].trim());
559
565
  return i.length > 0 ? ["id", ...i].join(",") : null;
560
- })(), { data: u, isLoading: R } = k({
561
- queryKey: ["relation-single", o, String(r), m ?? ""],
562
- queryFn: () => g ? (
566
+ })(), { data: u, isLoading: R } = S({
567
+ queryKey: ["relation-single", s, String(r), m ?? ""],
568
+ queryFn: () => h ? (
563
569
  // The file's row, not its bytes: GET /files/:id downloads the whole
564
570
  // file (twice with the retry, 404 when storage lost it) only to read
565
571
  // its name, and a missing object left the raw id as the label.
566
- y.request(
572
+ x.request(
567
573
  j(`/files/${encodeURIComponent(String(r))}/meta`)
568
574
  ).then((i) => i.data)
569
- ) : S(o, r, m),
570
- enabled: !!r && !!o,
575
+ ) : q(s, r, m),
576
+ enabled: !!r && !!s,
571
577
  staleTime: 6e4
572
578
  });
573
579
  if (R) return /* @__PURE__ */ n(Q, { className: "h-3 w-3 animate-spin text-slate-400" });
574
580
  if (!u) return /* @__PURE__ */ n("span", { children: String(r ?? "") });
575
- if (g) {
581
+ if (h) {
576
582
  const i = u.title || u.filename_download || u.filename_disk || String(r);
577
583
  return /* @__PURE__ */ n("span", { children: i });
578
584
  }
579
- return /* @__PURE__ */ n("span", { children: v(d, u) });
585
+ return /* @__PURE__ */ n("span", { children: k(d, u) });
580
586
  }
581
587
  export {
582
- yt as RelatedItemLabel,
583
- rt as RelationCombobox,
584
- tt as useStaleTip
588
+ vt as RelatedItemLabel,
589
+ nt as RelationCombobox,
590
+ rt as useStaleTip
585
591
  };
@@ -0,0 +1,21 @@
1
+ const i = (r) => r.toLocaleLowerCase().replace(/\s+/g, " ").trim();
2
+ function s(r, o) {
3
+ const t = i(o);
4
+ if (!t) return 4;
5
+ const e = i(r);
6
+ if (e === t) return 0;
7
+ if (e.startsWith(t)) return 1;
8
+ const n = e.split(/[\s,.;:()/\-_@]+/).filter(Boolean);
9
+ return t.split(" ").every((c) => n.some((f) => f.startsWith(c))) ? 2 : e.includes(t) ? 3 : 4;
10
+ }
11
+ function l(r, o, t, e = !1) {
12
+ if (t.trim()) {
13
+ const n = s(r, t) - s(o, t);
14
+ if (n) return n;
15
+ }
16
+ return e ? o.localeCompare(r) : r.localeCompare(o);
17
+ }
18
+ export {
19
+ l as compareByMatch,
20
+ s as pickerMatchTier
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",