@nivaro/react 0.3.58 → 0.3.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/components/fields/RelationField.js +110 -80
  2. package/dist/full.css +1 -1
  3. package/dist/hooks/useRelationOptions.js +1 -0
  4. package/dist/hooks/useSessionRecorder.js +1 -1
  5. package/dist/index.d.ts +32 -1
  6. package/dist/index.js +523 -520
  7. package/dist/shared/components/CollectionBrowserView.js +2083 -2052
  8. package/dist/shared/components/DataTable.js +497 -465
  9. package/dist/shared/components/ItemEditForm.js +4430 -4282
  10. package/dist/shared/components/PageRenderer.js +537 -508
  11. package/dist/shared/components/QueryTable.js +74 -74
  12. package/dist/shared/components/WidgetSlot.js +543 -520
  13. package/dist/shared/components/alerts/AlertManagerView.js +269 -275
  14. package/dist/shared/components/alerts/types.js +37 -14
  15. package/dist/shared/components/item-edit/FieldRenderer.js +22 -20
  16. package/dist/shared/components/item-edit/GridBulkEditDialog.js +55 -54
  17. package/dist/shared/components/item-edit/InlineTableField.js +2461 -2421
  18. package/dist/shared/components/item-edit/M2MCombobox.js +141 -137
  19. package/dist/shared/components/item-edit/PlanGrid.js +876 -820
  20. package/dist/shared/components/item-edit/QuickCreateButton.js +323 -130
  21. package/dist/shared/components/item-edit/RelationCombobox.js +408 -375
  22. package/dist/shared/components/item-edit/RelationGroupedCombobox.js +255 -156
  23. package/dist/shared/components/item-edit/SummaryPanel.js +356 -343
  24. package/dist/shared/components/item-edit/duplicate-rehearsal.js +47 -0
  25. package/dist/shared/components/item-edit/line-midair.js +82 -75
  26. package/dist/shared/components/item-edit/save-outcome.js +6 -4
  27. package/dist/shared/components/panels/ItemLockBanner.js +212 -209
  28. package/dist/shared/components/panels/PipelinePanel.js +775 -737
  29. package/dist/shared/components/panels/RecordIntegrityBanner.js +114 -86
  30. package/dist/shared/components/panels/RevisionsPanel.js +313 -299
  31. package/dist/shared/components/pipeline/PipelineEditorView.js +26 -16
  32. package/dist/shared/components/queue/QueueQuickFilters.js +13 -13
  33. package/dist/shared/components/queue/QueueWorklist.js +978 -953
  34. package/dist/shared/components/queue/live-state-aspect.js +9 -5
  35. package/dist/shared/components/widgets/ReviewListWidget.js +152 -149
  36. package/dist/shared/lib/display-prefs.js +60 -52
  37. package/dist/shared/lib/draft-store.js +71 -48
  38. package/dist/shared/lib/expression.js +53 -53
  39. package/dist/shared/lib/list-page-memory.js +42 -20
  40. package/dist/shared/lib/money-input.js +45 -0
  41. package/dist/shared/lib/sanitize-html.js +10 -6
  42. package/dist/shared/lib/staged-row-labels.js +18 -0
  43. package/package.json +1 -1
@@ -1,91 +1,94 @@
1
1
  import { jsx as l, jsxs as c } from "react/jsx-runtime";
2
2
  import { useQuery as L } from "@tanstack/react-query";
3
- import { ChevronDown as le, Loader2 as oe, AlertTriangle as de, X as ce, Check as ue } from "lucide-react";
4
- import { useState as re, useRef as me, useEffect as fe } from "react";
5
- import { useNivaroClient as pe, useItemEditAuth as he, useDrilldown as Je } from "../../context.js";
6
- import { parseAllowedCollections as Pe } from "../../lib/allowed-collections.js";
3
+ import { ChevronDown as re, Loader2 as ce, AlertTriangle as ue, X as de, Check as me } from "lucide-react";
4
+ import { useState as se, useRef as fe, useEffect as pe } from "react";
5
+ import { useNivaroClient as he, useItemEditAuth as be, useDrilldown as Pe } from "../../context.js";
6
+ import { parseAllowedCollections as De } from "../../lib/allowed-collections.js";
7
7
  import { get as U } from "../../lib/commands.js";
8
- import { compareByMatch as be } from "../../lib/picker-rank.js";
9
- import { useRecordReader as De } from "../../lib/record-loader.js";
10
- import { useOnlineUsers as ye } from "../../lib/use-online-users.js";
11
- import { cn as Q, userOptionFilter as xe, matchesAllTokens as Ee } from "../../lib/utils.js";
12
- import { UserAvatar as ge } from "../UserAvatar.js";
13
- import { Command as ve, CommandInput as ke, CommandList as Se, CommandEmpty as Ne, CommandGroup as we, CommandItem as _e } from "../ui/command.js";
14
- import { Popover as Le, PopoverTrigger as qe, PopoverContent as Ce } from "../ui/popover.js";
15
- import { applyDisplayTemplate as Oe } from "./helpers.js";
16
- import { useM2MStaging as Fe } from "./M2MStagingContext.js";
17
- import { useStaleTip as Re, RelatedItemLabel as ae } from "./RelationCombobox.js";
18
- function je(n) {
19
- return n.replace(/\(.*$/, "").trim().split(/\s+/).map((i) => i[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
20
- }
8
+ import { compareByMatch as ye } from "../../lib/picker-rank.js";
9
+ import { useRecordReader as Ee } from "../../lib/record-loader.js";
10
+ import { useOnlineUsers as xe } from "../../lib/use-online-users.js";
11
+ import { cn as W, userOptionFilter as ge, matchesAllTokens as Re } from "../../lib/utils.js";
12
+ import { UserAvatar as ve } from "../UserAvatar.js";
13
+ import { Command as ke, CommandInput as Se, CommandList as we, CommandEmpty as Ne, CommandGroup as _e, CommandItem as Le } from "../ui/command.js";
14
+ import { Popover as Ce, PopoverTrigger as qe, PopoverContent as Oe } from "../ui/popover.js";
15
+ import { applyDisplayTemplate as Fe } from "./helpers.js";
16
+ import { useM2MStaging as je } from "./M2MStagingContext.js";
17
+ import { useStaleTip as ze, RelatedItemLabel as oe } from "./RelationCombobox.js";
21
18
  function Te(n) {
22
- return Pe(n == null ? void 0 : n.one_allowed_collections);
19
+ return n.replace(/\(.*$/, "").trim().split(/\s+/).map((i) => i[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
23
20
  }
24
21
  function Ie(n) {
22
+ return De(n == null ? void 0 : n.one_allowed_collections);
23
+ }
24
+ function Ue(n) {
25
25
  if (!n) return null;
26
26
  if (n.one_collection) return n.one_collection;
27
- const i = Te(n);
27
+ const i = Ie(n);
28
28
  return i.length === 0 ? null : i.some((p) => p === "directus_users" || p === "nivaro_users") ? "nivaro_users" : i[0];
29
29
  }
30
- function at(n) {
30
+ function ot(n) {
31
31
  if (!n || n.one_collection) return null;
32
- const i = Te(n);
32
+ const i = Ie(n);
33
33
  if (i.length === 0) return null;
34
34
  const p = i.includes("directus_users") ? "directus_users" : i.includes("nivaro_users") ? "nivaro_users" : i[0];
35
35
  return { field: n.one_collection_field ?? "collection", value: p };
36
36
  }
37
- function ot({
37
+ function Q(n) {
38
+ return String(n).toLowerCase();
39
+ }
40
+ function ct({
38
41
  relation: n,
39
42
  parentId: i,
40
43
  allRelations: p,
41
44
  extraFilter: d,
42
45
  optionSort: h,
43
46
  requiredParent: S,
44
- onCountChange: N,
45
- drilldown: q
47
+ onCountChange: w,
48
+ drilldown: C
46
49
  }) {
47
- const x = pe(), F = Je(), t = Fe(), [j, v] = re(!1), [y, C] = re(""), T = p.find(
50
+ const x = he(), F = Pe(), t = je(), [j, v] = se(!1), [y, q] = se(""), T = p.find(
48
51
  (e) => e.many_collection === n.many_collection && e.many_field === n.junction_field && e.id !== n.id
49
- ), s = Ie(T), w = n.junction_field ?? "", P = n.many_field ?? "", u = n.one_field ?? `${n.many_collection}.${w}`, { data: o } = L({
52
+ ), s = Ue(T), N = n.junction_field ?? "", P = n.many_field ?? "", u = n.one_field ?? `${n.many_collection}.${N}`, { data: o } = L({
50
53
  queryKey: ["col-meta", s],
51
54
  queryFn: () => x.request(U(`/collections/${s}`)).then((e) => e.data),
52
55
  enabled: !!s,
53
56
  staleTime: 3e5,
54
57
  retry: !1
55
- }), { data: W = [] } = L({
58
+ }), { data: X = [] } = L({
56
59
  queryKey: ["m2m-items", n.many_collection, P, i],
57
60
  queryFn: () => x.request(
58
61
  U(`/items/${n.many_collection}`, {
59
62
  filter: JSON.stringify({ [P]: { _eq: i } }),
60
63
  limit: 200,
61
- fields: `id,${w}`
64
+ fields: `id,${N}`
62
65
  })
63
66
  ).then((e) => e.data ?? []),
64
67
  staleTime: 3e4,
65
68
  enabled: !!i && i !== "new"
66
- }), ie = he().isAdmin, D = s === "nivaro_users" ? xe(ie) : null, E = ye(s === "nivaro_users"), X = d ? D ? { _and: [d, D] } : d : D, R = X ? JSON.stringify(X) : void 0, z = h && !/^-?label$/.test(h) ? h : void 0, H = (() => {
69
+ }), ae = be().isAdmin, D = s === "nivaro_users" ? ge(ae) : null, E = xe(s === "nivaro_users"), H = d ? D ? { _and: [d, D] } : d : D, R = H ? JSON.stringify(H) : void 0, z = h && !/^-?label$/.test(h) ? h : void 0, Y = (() => {
67
70
  const e = o == null ? void 0 : o.display_template;
68
71
  if (!e || !e.includes(".")) return null;
69
72
  const a = [...e.matchAll(/\{\{([^}]+)\}\}/g)].map((f) => f[1].trim());
70
73
  return a.length === 0 ? null : ["id", ...a].join(",");
71
74
  })(), {
72
- options: Y,
75
+ options: Z,
73
76
  isLoading: M,
74
77
  localSearch: B
75
- } = Ue({
78
+ } = Ae({
76
79
  client: x,
77
80
  relatedCollection: s,
78
81
  search: y,
79
82
  filterParam: R,
80
83
  serverSort: z,
81
- templateNestedFields: H,
84
+ templateNestedFields: Y,
82
85
  enabled: j && !!s,
83
86
  labelOf: k
84
- }), Z = (t == null ? void 0 : t.getStagedLinks(u)) ?? [], _ = (t == null ? void 0 : t.getStagedUnlinks(u)) ?? /* @__PURE__ */ new Set(), A = W.filter((e) => !_.has(e.id)), g = new Set(A.map((e) => String(e[w]))), O = [...g], ee = JSON.stringify(d ? { _and: [{ id: { _in: O } }, d] } : { id: { _in: O } }), { data: m } = L({
87
+ }), ee = (t == null ? void 0 : t.getStagedLinks(u)) ?? [], _ = (t == null ? void 0 : t.getStagedUnlinks(u)) ?? /* @__PURE__ */ new Set(), A = X.filter((e) => !_.has(e.id)), g = new Set(A.map((e) => String(e[N]))), O = [...g], te = JSON.stringify(d ? { _and: [{ id: { _in: O } }, d] } : { id: { _in: O } }), { data: m } = L({
85
88
  queryKey: ["m2m-avail", s, O.join(","), R],
86
89
  queryFn: () => x.request(
87
90
  U(`/items/${s}`, {
88
- filter: ee,
91
+ filter: te,
89
92
  picker: "1",
90
93
  limit: 200,
91
94
  fields: "id"
@@ -93,18 +96,18 @@ function ot({
93
96
  ).then((e) => e.data ?? []),
94
97
  enabled: !!s && O.length > 0,
95
98
  staleTime: 3e4
96
- }), te = new Set((m ?? []).map((e) => String(e.id))), $ = m !== void 0 ? new Set(O.filter((e) => !te.has(e))) : /* @__PURE__ */ new Set(), K = new Set(Z.map(String)), J = /* @__PURE__ */ new Set([...g, ...K]), I = me(N);
97
- I.current = N, fe(() => {
99
+ }), ne = new Set((m ?? []).map((e) => String(e.id))), $ = m !== void 0 ? new Set(O.filter((e) => !ne.has(e))) : /* @__PURE__ */ new Set(), K = new Set(ee.map(Q)), J = /* @__PURE__ */ new Set([...[...g].map(Q), ...K]), I = fe(w);
100
+ I.current = w, pe(() => {
98
101
  var e;
99
102
  (e = I.current) == null || e.call(I, J.size);
100
103
  }, [J.size]);
101
104
  function G(e) {
102
- const a = String(e);
105
+ const a = Q(e);
103
106
  if (K.has(a)) {
104
107
  t == null || t.unstageLink(u, e);
105
108
  return;
106
109
  }
107
- const f = W.find((V) => String(V[w]) === a);
110
+ const f = X.find((V) => Q(V[N]) === a);
108
111
  if (f) {
109
112
  _.has(f.id) ? t == null || t.unstageUnlink(u, f.id) : t == null || t.stageUnlink(u, f.id);
110
113
  return;
@@ -113,7 +116,7 @@ function ot({
113
116
  }
114
117
  function k(e) {
115
118
  const a = (o == null ? void 0 : o.display_template) ?? null;
116
- return a ? Oe(a, e) : String(e._display ?? e.id ?? "");
119
+ return a ? Fe(a, e) : String(e._display ?? e.id ?? "");
117
120
  }
118
121
  return S ? /* @__PURE__ */ c(
119
122
  "button",
@@ -127,15 +130,15 @@ function ot({
127
130
  S,
128
131
  " first"
129
132
  ] }),
130
- /* @__PURE__ */ l(le, { className: "h-4 w-4 shrink-0 opacity-50" })
133
+ /* @__PURE__ */ l(re, { className: "h-4 w-4 shrink-0 opacity-50" })
131
134
  ]
132
135
  }
133
136
  ) : /* @__PURE__ */ l("div", { children: /* @__PURE__ */ c(
134
- Le,
137
+ Ce,
135
138
  {
136
139
  open: j,
137
140
  onOpenChange: (e) => {
138
- v(e), e || C("");
141
+ v(e), e || q("");
139
142
  },
140
143
  children: [
141
144
  /* @__PURE__ */ l(qe, { asChild: !0, children: /* @__PURE__ */ c(
@@ -157,18 +160,18 @@ function ot({
157
160
  },
158
161
  children: [
159
162
  A.map((e) => {
160
- const a = e[w], f = $.has(String(a));
163
+ const a = e[N], f = $.has(String(a));
161
164
  return /* @__PURE__ */ c(
162
165
  "span",
163
166
  {
164
167
  title: f ? "This record is no longer an available option" : void 0,
165
- className: Q(
168
+ className: W(
166
169
  "inline-flex items-center gap-1 rounded-full border pl-2.5 pr-1.5 py-0.5 text-[12px]",
167
170
  f ? "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"
168
171
  ),
169
172
  children: [
170
- f && /* @__PURE__ */ l(de, { className: "h-3 w-3 shrink-0 text-amber-500" }),
171
- s && (q && F ? /* @__PURE__ */ l(
173
+ f && /* @__PURE__ */ l(ue, { className: "h-3 w-3 shrink-0 text-amber-500" }),
174
+ s && (C && F ? /* @__PURE__ */ l(
172
175
  "button",
173
176
  {
174
177
  type: "button",
@@ -176,12 +179,12 @@ function ot({
176
179
  onClick: () => F.open({
177
180
  collection: s,
178
181
  itemId: String(a),
179
- layoutId: q.layout_id,
180
- width: q.width
182
+ layoutId: C.layout_id,
183
+ width: C.width
181
184
  }),
182
185
  className: "underline decoration-slate-300 decoration-dotted underline-offset-2 hover:text-[#172940] hover:decoration-nvr-cyan dark:hover:text-nvr-cyan",
183
186
  children: /* @__PURE__ */ l(
184
- ae,
187
+ oe,
185
188
  {
186
189
  collection: s,
187
190
  id: a,
@@ -190,7 +193,7 @@ function ot({
190
193
  )
191
194
  }
192
195
  ) : /* @__PURE__ */ l(
193
- ae,
196
+ oe,
194
197
  {
195
198
  collection: s,
196
199
  id: a,
@@ -204,7 +207,7 @@ function ot({
204
207
  "aria-label": "Remove",
205
208
  onClick: () => t == null ? void 0 : t.stageUnlink(u, e.id),
206
209
  className: "rounded-full p-0.5 text-slate-400 hover:text-red-500",
207
- children: /* @__PURE__ */ l(ce, { className: "h-3 w-3" })
210
+ children: /* @__PURE__ */ l(de, { className: "h-3 w-3" })
208
211
  }
209
212
  )
210
213
  ]
@@ -212,13 +215,13 @@ function ot({
212
215
  String(e.id)
213
216
  );
214
217
  }),
215
- Z.map((e) => /* @__PURE__ */ c(
218
+ ee.map((e) => /* @__PURE__ */ c(
216
219
  "span",
217
220
  {
218
221
  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",
219
222
  children: [
220
223
  s ? /* @__PURE__ */ l(
221
- ae,
224
+ oe,
222
225
  {
223
226
  collection: s,
224
227
  id: e,
@@ -232,7 +235,7 @@ function ot({
232
235
  "aria-label": "Remove",
233
236
  onClick: () => t == null ? void 0 : t.unstageLink(u, e),
234
237
  className: "rounded-full p-0.5 text-slate-400 hover:text-red-500",
235
- children: /* @__PURE__ */ l(ce, { className: "h-3 w-3" })
238
+ children: /* @__PURE__ */ l(de, { className: "h-3 w-3" })
236
239
  }
237
240
  )
238
241
  ]
@@ -242,28 +245,28 @@ function ot({
242
245
  ]
243
246
  }
244
247
  ) : /* @__PURE__ */ l("span", { className: "truncate text-muted-foreground", children: "Select items…" }),
245
- /* @__PURE__ */ l(le, { className: "h-4 w-4 shrink-0 opacity-50" })
248
+ /* @__PURE__ */ l(re, { className: "h-4 w-4 shrink-0 opacity-50" })
246
249
  ]
247
250
  }
248
251
  ) }),
249
- /* @__PURE__ */ l(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ve, { shouldFilter: !1, children: [
252
+ /* @__PURE__ */ l(Oe, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ke, { shouldFilter: !1, children: [
250
253
  /* @__PURE__ */ l(
251
- ke,
254
+ Se,
252
255
  {
253
256
  placeholder: "Search…",
254
257
  value: y,
255
- onValueChange: C,
258
+ onValueChange: q,
256
259
  className: "h-9 text-[13px]"
257
260
  }
258
261
  ),
259
- /* @__PURE__ */ c(Se, { children: [
260
- M ? /* @__PURE__ */ l("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ l(oe, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ l(Ne, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
261
- /* @__PURE__ */ l(we, { children: !M && (z ? [...se(Y, y, B, k)] : [...se(Y, y, B, k)].sort(
262
- (e, a) => be(k(e), k(a), y, h === "-label")
262
+ /* @__PURE__ */ c(we, { children: [
263
+ M ? /* @__PURE__ */ l("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ l(ce, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ l(Ne, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
264
+ /* @__PURE__ */ l(_e, { children: !M && (z ? [...ie(Z, y, B, k)] : [...ie(Z, y, B, k)].sort(
265
+ (e, a) => ye(k(e), k(a), y, h === "-label")
263
266
  )).map((e) => {
264
- const a = String(e.id), f = J.has(a);
267
+ const a = String(e.id), f = J.has(Q(a));
265
268
  return /* @__PURE__ */ c(
266
- _e,
269
+ Le,
267
270
  {
268
271
  value: a,
269
272
  onSelect: () => G(e.id),
@@ -272,19 +275,19 @@ function ot({
272
275
  /* @__PURE__ */ l(
273
276
  "div",
274
277
  {
275
- className: Q(
278
+ className: W(
276
279
  "flex h-4 w-4 shrink-0 items-center justify-center rounded border",
277
280
  f ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
278
281
  ),
279
- children: f && /* @__PURE__ */ l(ue, { className: "h-2.5 w-2.5 text-white" })
282
+ children: f && /* @__PURE__ */ l(me, { className: "h-2.5 w-2.5 text-white" })
280
283
  }
281
284
  ),
282
285
  s === "nivaro_users" && /* @__PURE__ */ l(
283
- ge,
286
+ ve,
284
287
  {
285
288
  userId: a,
286
289
  className: "h-4 w-4",
287
- fallback: /* @__PURE__ */ l("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)) })
290
+ fallback: /* @__PURE__ */ l("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: Te(k(e)) })
288
291
  }
289
292
  ),
290
293
  s === "nivaro_users" && E.has(a.toUpperCase()) && /* @__PURE__ */ l(
@@ -306,16 +309,16 @@ function ot({
306
309
  }
307
310
  ) });
308
311
  }
309
- function Ue(n) {
310
- const { client: i, relatedCollection: p, search: d, filterParam: h, serverSort: S, templateNestedFields: N } = n, q = (T) => i.request(
312
+ function Ae(n) {
313
+ const { client: i, relatedCollection: p, search: d, filterParam: h, serverSort: S, templateNestedFields: w } = n, C = (T) => i.request(
311
314
  U(`/items/${p}`, {
312
- limit: Ae,
315
+ limit: $e,
313
316
  search: T || void 0,
314
317
  filter: h,
315
318
  picker: "1",
316
319
  // A dotted display template ({{core_category.name}}) needs the
317
320
  // nested expansion — a bare row only carries the FK id.
318
- ...N ? { fields: N } : {},
321
+ ...w ? { fields: w } : {},
319
322
  ...S ? { sort: S } : {}
320
323
  })
321
324
  ).then((s) => s.data ?? []), x = (T) => [
@@ -324,76 +327,76 @@ function Ue(n) {
324
327
  T,
325
328
  h,
326
329
  S ?? "",
327
- N ?? ""
330
+ w ?? ""
328
331
  ], F = h ? 0 : 3e4, { data: t, isFetching: j } = L({
329
332
  queryKey: x(""),
330
- queryFn: () => q(""),
333
+ queryFn: () => C(""),
331
334
  enabled: n.enabled,
332
335
  staleTime: F
333
- }), v = ze(t, d, n.labelOf), { data: y, isFetching: C } = L({
336
+ }), v = Me(t, d, n.labelOf), { data: y, isFetching: q } = L({
334
337
  queryKey: x(d),
335
- queryFn: () => q(d),
338
+ queryFn: () => C(d),
336
339
  enabled: n.enabled && v,
337
340
  staleTime: F
338
341
  });
339
- return v ? { options: y ?? [], isLoading: !y && C, localSearch: !1 } : { options: t ?? [], isLoading: !t && j, localSearch: !!d };
342
+ return v ? { options: y ?? [], isLoading: !y && q, localSearch: !1 } : { options: t ?? [], isLoading: !t && j, localSearch: !!d };
340
343
  }
341
- const Ae = 200;
342
- function ze(n, i, p) {
343
- return i.trim() ? !n || n.length >= Ae ? !0 : se(n, i, !0, p).length === 0 : !1;
344
+ const $e = 200;
345
+ function Me(n, i, p) {
346
+ return i.trim() ? !n || n.length >= $e ? !0 : ie(n, i, !0, p).length === 0 : !1;
344
347
  }
345
- function se(n, i, p, d) {
346
- return !p || !i.trim() ? n : n.filter((h) => Ee(d(h), i));
348
+ function ie(n, i, p, d) {
349
+ return !p || !i.trim() ? n : n.filter((h) => Re(d(h), i));
347
350
  }
348
- function ct({
351
+ function dt({
349
352
  relation: n,
350
353
  parentId: i,
351
354
  allRelations: p,
352
355
  extraFilter: d,
353
356
  optionSort: h,
354
357
  requiredParent: S,
355
- onCountChange: N,
356
- readOnly: q
358
+ onCountChange: w,
359
+ readOnly: C
357
360
  }) {
358
- const x = pe(), F = De(), t = Fe(), [j, v] = re(!1), [y, C] = re(""), T = p.find(
361
+ const x = he(), F = Ee(), t = je(), [j, v] = se(!1), [y, q] = se(""), T = p.find(
359
362
  (r) => r.many_collection === n.many_collection && r.many_field === n.junction_field && r.id !== n.id
360
- ), s = Ie(T), w = n.junction_field ?? "", P = n.many_field ?? "", u = n.one_field ?? `${n.many_collection}.${w}`, { data: o } = L({
363
+ ), s = Ue(T), N = n.junction_field ?? "", P = n.many_field ?? "", u = n.one_field ?? `${n.many_collection}.${N}`, { data: o } = L({
361
364
  queryKey: ["col-meta", s],
362
365
  queryFn: () => x.request(U(`/collections/${s}`)).then((r) => r.data),
363
366
  enabled: !!s,
364
367
  staleTime: 3e5,
365
368
  retry: !1
366
- }), { data: W = [], isFetching: ie } = L({
369
+ }), { data: X = [], isFetching: ae } = L({
367
370
  queryKey: ["m2m-items", n.many_collection, P, i],
368
371
  queryFn: () => x.request(
369
372
  U(`/items/${n.many_collection}`, {
370
373
  filter: JSON.stringify({ [P]: { _eq: i } }),
371
374
  limit: 1,
372
- fields: `id,${w}`
375
+ fields: `id,${N}`
373
376
  })
374
377
  ).then((r) => r.data ?? []),
375
378
  staleTime: 3e4,
376
379
  enabled: !!i && i !== "new"
377
- }), D = he().isAdmin, E = s === "nivaro_users" ? xe(D) : null, X = ye(s === "nivaro_users"), R = d ? E ? { _and: [d, E] } : d : E, z = R ? JSON.stringify(R) : void 0, H = h && !/^-?label$/.test(h) ? h : void 0, Y = (() => {
380
+ }), D = be().isAdmin, E = s === "nivaro_users" ? ge(D) : null, H = xe(s === "nivaro_users"), R = d ? E ? { _and: [d, E] } : d : E, z = R ? JSON.stringify(R) : void 0, Y = h && !/^-?label$/.test(h) ? h : void 0, Z = (() => {
378
381
  const r = o == null ? void 0 : o.display_template;
379
382
  if (!r || !r.includes(".")) return null;
380
- const b = [...r.matchAll(/\{\{([^}]+)\}\}/g)].map((ne) => ne[1].trim());
383
+ const b = [...r.matchAll(/\{\{([^}]+)\}\}/g)].map((le) => le[1].trim());
381
384
  return b.length === 0 ? null : ["id", ...b].join(",");
382
385
  })(), {
383
386
  options: M,
384
387
  isLoading: B,
385
- localSearch: Z
386
- } = Ue({
388
+ localSearch: ee
389
+ } = Ae({
387
390
  client: x,
388
391
  relatedCollection: s,
389
392
  search: y,
390
393
  filterParam: z,
391
- serverSort: H,
392
- templateNestedFields: Y,
394
+ serverSort: Y,
395
+ templateNestedFields: Z,
393
396
  enabled: j && !!s,
394
397
  labelOf: e
395
- }), _ = (t == null ? void 0 : t.getStagedLinks(u)) ?? [], A = (t == null ? void 0 : t.getStagedUnlinks(u)) ?? /* @__PURE__ */ new Set(), g = W.find((r) => !A.has(r.id)) ?? null, O = g ? g[w] : null, ee = _.length > 0 ? _[_.length - 1] : null, m = ee ?? O, te = _.length > 0 || A.size > 0, $ = me(N);
396
- $.current = N, fe(() => {
398
+ }), _ = (t == null ? void 0 : t.getStagedLinks(u)) ?? [], A = (t == null ? void 0 : t.getStagedUnlinks(u)) ?? /* @__PURE__ */ new Set(), g = X.find((r) => !A.has(r.id)) ?? null, O = g ? g[N] : null, te = _.length > 0 ? _[_.length - 1] : null, m = te ?? O, ne = _.length > 0 || A.size > 0, $ = fe(w);
399
+ $.current = w, pe(() => {
397
400
  var r;
398
401
  (r = $.current) == null || r.call($, m != null ? 1 : 0);
399
402
  }, [m]);
@@ -414,19 +417,19 @@ function ct({
414
417
  ).then((r) => r.data ?? []),
415
418
  enabled: !!s && m != null && !!K,
416
419
  staleTime: 3e4
417
- }), G = I !== void 0 && I.length === 0, k = Re(G);
420
+ }), G = I !== void 0 && I.length === 0, k = ze(G);
418
421
  function e(r) {
419
422
  const b = (o == null ? void 0 : o.display_template) ?? null;
420
- return b ? Oe(b, r) : String(r.name ?? r.title ?? r.label ?? r.id ?? "");
423
+ return b ? Fe(b, r) : String(r.name ?? r.title ?? r.label ?? r.id ?? "");
421
424
  }
422
425
  const a = M.find((r) => String(r.id) === String(m)) ?? K, f = m != null && !K && !a, V = a ? e(a) : null;
423
- if (q)
426
+ if (C)
424
427
  return /* @__PURE__ */ l("span", { className: "block truncate text-[12px] text-slate-700 dark:text-slate-200", children: f ? "…" : V ?? "—" });
425
- function $e(r) {
428
+ function Ke(r) {
426
429
  for (const b of _) t == null || t.unstageLink(u, b);
427
- g && !A.has(g.id) && (t == null || t.stageUnlink(u, g.id)), String(r) === String(O) && g ? t == null || t.unstageUnlink(u, g.id) : String(r) !== String(m) && (t == null || t.stageLink(u, r)), v(!1), C("");
430
+ g && !A.has(g.id) && (t == null || t.stageUnlink(u, g.id)), String(r) === String(O) && g ? t == null || t.unstageUnlink(u, g.id) : String(r) !== String(m) && (t == null || t.stageLink(u, r)), v(!1), q("");
428
431
  }
429
- function Ke() {
432
+ function Je() {
430
433
  for (const r of _) t == null || t.unstageLink(u, r);
431
434
  g && (t == null || t.stageUnlink(u, g.id)), v(!1);
432
435
  }
@@ -442,51 +445,51 @@ function ct({
442
445
  S,
443
446
  " first"
444
447
  ] }),
445
- /* @__PURE__ */ l(le, { className: "h-4 w-4 shrink-0 opacity-50" })
448
+ /* @__PURE__ */ l(re, { className: "h-4 w-4 shrink-0 opacity-50" })
446
449
  ]
447
450
  }
448
451
  ) : /* @__PURE__ */ c("div", { ...k.bind, children: [
449
452
  /* @__PURE__ */ c(
450
- Le,
453
+ Ce,
451
454
  {
452
455
  open: j,
453
456
  onOpenChange: (r) => {
454
- v(r), r || C("");
457
+ v(r), r || q("");
455
458
  },
456
459
  children: [
457
460
  /* @__PURE__ */ l(qe, { asChild: !0, children: /* @__PURE__ */ c(
458
461
  "button",
459
462
  {
460
463
  type: "button",
461
- className: Q(
464
+ className: W(
462
465
  "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",
463
- G ? "border-amber-300 dark:border-amber-600" : te ? "border-nvr-cyan/50" : "border-input"
466
+ G ? "border-amber-300 dark:border-amber-600" : ne ? "border-nvr-cyan/50" : "border-input"
464
467
  ),
465
468
  children: [
466
- f || ie && ee == null && i !== "new" ? /* @__PURE__ */ l(oe, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ c(
469
+ f || ae && te == null && i !== "new" ? /* @__PURE__ */ l(ce, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ c(
467
470
  "span",
468
471
  {
469
- className: Q(
472
+ className: W(
470
473
  "flex items-center gap-1.5 truncate min-w-0",
471
- V ? te ? "text-nvr-cyan" : "text-slate-800 dark:text-slate-100" : "text-muted-foreground"
474
+ V ? ne ? "text-nvr-cyan" : "text-slate-800 dark:text-slate-100" : "text-muted-foreground"
472
475
  ),
473
476
  children: [
474
- G && /* @__PURE__ */ l(de, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
477
+ G && /* @__PURE__ */ l(ue, { className: "h-3.5 w-3.5 shrink-0 text-amber-500" }),
475
478
  /* @__PURE__ */ l("span", { className: "truncate", children: V ?? "Select…" })
476
479
  ]
477
480
  }
478
481
  ),
479
- /* @__PURE__ */ l(le, { className: "h-4 w-4 shrink-0 opacity-50" })
482
+ /* @__PURE__ */ l(re, { className: "h-4 w-4 shrink-0 opacity-50" })
480
483
  ]
481
484
  }
482
485
  ) }),
483
- /* @__PURE__ */ l(Ce, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ve, { shouldFilter: !1, children: [
486
+ /* @__PURE__ */ l(Oe, { className: "w-[320px] p-0", align: "start", children: /* @__PURE__ */ c(ke, { shouldFilter: !1, children: [
484
487
  /* @__PURE__ */ l(
485
- ke,
488
+ Se,
486
489
  {
487
490
  placeholder: "Search…",
488
491
  value: y,
489
- onValueChange: C,
492
+ onValueChange: q,
490
493
  className: "h-9 text-[12px]"
491
494
  }
492
495
  ),
@@ -495,47 +498,47 @@ function ct({
495
498
  {
496
499
  type: "button",
497
500
  onClick: () => {
498
- Ke(), v(!1);
501
+ Je(), v(!1);
499
502
  },
500
503
  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",
501
504
  children: [
502
- /* @__PURE__ */ l(ce, { className: "h-3.5 w-3.5 text-slate-400" }),
505
+ /* @__PURE__ */ l(de, { className: "h-3.5 w-3.5 text-slate-400" }),
503
506
  "Clear selection"
504
507
  ]
505
508
  }
506
509
  ),
507
- /* @__PURE__ */ c(Se, { children: [
508
- B ? /* @__PURE__ */ l("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ l(oe, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ l(Ne, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
509
- !B && /* @__PURE__ */ l(we, { children: [...se(M, y, Z, e)].sort(
510
- (r, b) => H ? 0 : be(e(r), e(b), y, h === "-label")
510
+ /* @__PURE__ */ c(we, { children: [
511
+ B ? /* @__PURE__ */ l("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ l(ce, { className: "h-4 w-4 animate-spin text-muted-foreground" }) }) : /* @__PURE__ */ l(Ne, { className: "py-3 text-left text-[12px] text-muted-foreground px-3", children: "No results" }),
512
+ !B && /* @__PURE__ */ l(_e, { children: [...ie(M, y, ee, e)].sort(
513
+ (r, b) => Y ? 0 : ye(e(r), e(b), y, h === "-label")
511
514
  ).map((r) => {
512
- const b = String(r.id), ne = String(m) === b;
515
+ const b = String(r.id), le = String(m) === b;
513
516
  return /* @__PURE__ */ c(
514
- _e,
517
+ Le,
515
518
  {
516
519
  value: b,
517
- onSelect: () => $e(r.id),
520
+ onSelect: () => Ke(r.id),
518
521
  className: "flex items-center gap-2 text-[12px]",
519
522
  children: [
520
523
  /* @__PURE__ */ l(
521
524
  "div",
522
525
  {
523
- className: Q(
526
+ className: W(
524
527
  "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors",
525
- ne ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
528
+ le ? "border-nvr-cyan bg-nvr-cyan" : "border-slate-300 dark:border-slate-500"
526
529
  ),
527
- children: ne && /* @__PURE__ */ l(ue, { className: "h-2.5 w-2.5 text-white" })
530
+ children: le && /* @__PURE__ */ l(me, { className: "h-2.5 w-2.5 text-white" })
528
531
  }
529
532
  ),
530
533
  s === "nivaro_users" && /* @__PURE__ */ l(
531
- ge,
534
+ ve,
532
535
  {
533
536
  userId: b,
534
537
  className: "h-4 w-4",
535
- fallback: /* @__PURE__ */ l("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(e(r)) })
538
+ fallback: /* @__PURE__ */ l("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: Te(e(r)) })
536
539
  }
537
540
  ),
538
- s === "nivaro_users" && X.has(b.toUpperCase()) && /* @__PURE__ */ l(
541
+ s === "nivaro_users" && H.has(b.toUpperCase()) && /* @__PURE__ */ l(
539
542
  "span",
540
543
  {
541
544
  className: "h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",
@@ -557,10 +560,11 @@ function ct({
557
560
  ] });
558
561
  }
559
562
  export {
560
- ot as M2MCombobox,
561
- ct as M2MSingleSelectCombobox,
562
- at as m2aWriteMeta,
563
- ze as m2mAsksServer,
564
- se as narrowM2MOptions,
565
- Ie as resolveM2MRelatedCollection
563
+ ct as M2MCombobox,
564
+ dt as M2MSingleSelectCombobox,
565
+ ot as m2aWriteMeta,
566
+ Me as m2mAsksServer,
567
+ Q as m2mIdKey,
568
+ ie as narrowM2MOptions,
569
+ Ue as resolveM2MRelatedCollection
566
570
  };