@nivaro/react 0.3.3 → 0.3.4

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.
@@ -8,7 +8,7 @@ import { normalizeReplaySampling as x, replaySampleDraw as Ae, currentReplayRout
8
8
  import { emitReplayTap as Ce, setReplayRecorderMode as N, registerReplayCapture as Ie, clipEndOffset as _e, withClipKind as De } from "../shared/lib/replay-capture.js";
9
9
  import { instrumentConsole as qe, instrumentRequests as Le, redactSecrets as Te } from "../shared/lib/replay-context.js";
10
10
  import { instrumentSocket as Pe } from "../shared/lib/replay-socket.js";
11
- const Ne = "nivaro-react@0.3.3", j = 1e4, Me = 150, Oe = 3e3, Ue = 600, We = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
11
+ const Ne = "nivaro-react@0.3.4", j = 1e4, Me = 150, Oe = 3e3, Ue = 600, We = (n) => `nvr_replay_resume${n ? `:${n}` : ""}`, G = () => typeof navigator > "u" || navigator.onLine !== !1;
12
12
  function Fe(n) {
13
13
  return typeof n.url != "string" || typeof fetch != "function" ? null : (f, a) => {
14
14
  const l = typeof n.getToken == "function" ? n.getToken() : void 0, d = { "Content-Type": "application/json" };
package/dist/index.d.ts CHANGED
@@ -1675,7 +1675,8 @@ declare interface CMSRelation {
1675
1675
  /** M2A only — the junction column naming which collection each row's `item` id
1676
1676
  * belongs to (usually 'collection'); one_collection is null on those rows. */
1677
1677
  one_collection_field?: string | null;
1678
- one_allowed_collections?: string | null;
1678
+ /** Array from the API, or JSON / comma text — read with parseAllowedCollections. */
1679
+ one_allowed_collections?: string | string[] | null;
1679
1680
  }
1680
1681
 
1681
1682
  declare interface CoalescingOptions {
@@ -1,28 +1,29 @@
1
1
  import { jsx as r, jsxs as u, Fragment as he } from "react/jsx-runtime";
2
2
  import { useQuery as V, useQueryClient as qt } from "@tanstack/react-query";
3
- import { Pencil as Tt, ChevronDown as Ct } from "lucide-react";
3
+ import { Pencil as Ct, ChevronDown as Tt } from "lucide-react";
4
4
  import { useMemo as ge, useRef as Ot, useState as Z, useEffect as be, useCallback as st, Fragment as At } from "react";
5
- import { DrilldownContext as Rt, useNivaroClient as Ce, useApiFetchConfig as Dt, useDrilldown as ct } from "../context.js";
5
+ import { DrilldownContext as Rt, useNivaroClient as Te, useApiFetchConfig as Dt, useDrilldown as ct } from "../context.js";
6
6
  import { useDebounced as Lt } from "../hooks/useDebounced.js";
7
+ import { parseAllowedCollections as Pt } from "../lib/allowed-collections.js";
7
8
  import { get as G } from "../lib/commands.js";
8
- import { readGroupStructure as Pt, isFolded as Kt, isEmptyValue as Be, planFieldGrid as jt } from "../lib/form-structure.js";
9
- import { useLiveRecord as Et } from "../lib/live.js";
10
- import { isDisplayFormulaField as qe, resolvePlacementText as It, displayFormulaOf as Wt, formatDisplayValue as Mt } from "../lib/placement-behaviour.js";
11
- import { useRecordReader as Ut } from "../lib/record-loader.js";
12
- import { sanitizeHtml as Vt } from "../lib/sanitize-html.js";
13
- import { titleCase as Ge, formatRelative as Te } from "../lib/utils.js";
14
- import { InboundRequestPopover as Bt } from "./integrations/InboundRequest.js";
15
- import { FileM2MField as Gt } from "./item-edit/FilePickerField.js";
16
- import { useFieldTouches as Jt } from "./item-edit/HeaderFreshness.js";
17
- import { richTextToPlain as Ht } from "./item-edit/helpers.js";
18
- import { usePlacementTextContext as Qt, evaluateDisplayFormula as zt } from "./item-edit/placement-behaviour.js";
9
+ import { readGroupStructure as Kt, isFolded as jt, isEmptyValue as Be, planFieldGrid as Et } from "../lib/form-structure.js";
10
+ import { useLiveRecord as It } from "../lib/live.js";
11
+ import { isDisplayFormulaField as qe, resolvePlacementText as Wt, displayFormulaOf as Mt, formatDisplayValue as Ut } from "../lib/placement-behaviour.js";
12
+ import { useRecordReader as Vt } from "../lib/record-loader.js";
13
+ import { sanitizeHtml as Bt } from "../lib/sanitize-html.js";
14
+ import { titleCase as Ge, formatRelative as Ce } from "../lib/utils.js";
15
+ import { InboundRequestPopover as Gt } from "./integrations/InboundRequest.js";
16
+ import { FileM2MField as Jt } from "./item-edit/FilePickerField.js";
17
+ import { useFieldTouches as Ht } from "./item-edit/HeaderFreshness.js";
18
+ import { richTextToPlain as Qt } from "./item-edit/helpers.js";
19
+ import { usePlacementTextContext as zt, evaluateDisplayFormula as Yt } from "./item-edit/placement-behaviour.js";
19
20
  import { UserChip as ut } from "./item-edit/UserChip.js";
20
- import { DesignNode as Yt } from "./layout-editor/DesignNode.js";
21
- import { DesignCanvas as Xt } from "./layout-editor/design-canvas.js";
22
- import { revealGroupKey as Zt } from "./layout-editor/design-context.js";
23
- import { useRecordIntegrity as el, integrityByField as tl } from "./panels/RecordIntegrityBanner.js";
21
+ import { DesignNode as Xt } from "./layout-editor/DesignNode.js";
22
+ import { DesignCanvas as Zt } from "./layout-editor/design-canvas.js";
23
+ import { revealGroupKey as el } from "./layout-editor/design-context.js";
24
+ import { useRecordIntegrity as tl, integrityByField as ll } from "./panels/RecordIntegrityBanner.js";
24
25
  import { SimpleSelectXs as dt } from "./ui/SimpleSelect.js";
25
- import { WidgetSlot as ll } from "./WidgetSlot.js";
26
+ import { WidgetSlot as rl } from "./WidgetSlot.js";
26
27
  const pe = (n) => {
27
28
  if (!n) return {};
28
29
  if (typeof n == "object") return n;
@@ -40,7 +41,7 @@ const pe = (n) => {
40
41
  }, Ie = (n) => {
41
42
  const m = Number(n);
42
43
  return Number.isNaN(m) ? String(n) : m.toLocaleString("en-US");
43
- }, Ee = "text-[11.5px] font-medium text-slate-500 dark:text-slate-400", ee = () => /* @__PURE__ */ r("span", { className: "text-slate-300 dark:text-slate-600", children: "—" }), rl = `
44
+ }, Ee = "text-[11.5px] font-medium text-slate-500 dark:text-slate-400", ee = () => /* @__PURE__ */ r("span", { className: "text-slate-300 dark:text-slate-600", children: "—" }), nl = `
44
45
  [data-read-board]{grid-template-columns:minmax(0,1fr)}
45
46
  [data-read-dl]{grid-template-columns:repeat(2,minmax(0,1fr))}
46
47
  @media (min-width:640px){[data-read-dl="full"]{grid-template-columns:repeat(3,minmax(0,1fr))}}
@@ -68,8 +69,8 @@ function ft({
68
69
  }
69
70
  );
70
71
  }
71
- function nl({ collection: n, id: m }) {
72
- const N = Ce(), c = Ut(), P = ct(), { data: w } = V({
72
+ function al({ collection: n, id: m }) {
73
+ const N = Te(), c = Vt(), P = ct(), { data: w } = V({
73
74
  queryKey: ["cbv-collection-meta", n],
74
75
  queryFn: () => N.request(
75
76
  G(`/collections/${n}`)
@@ -93,7 +94,7 @@ function nl({ collection: n, id: m }) {
93
94
  let v = "";
94
95
  const h = w == null ? void 0 : w.display_template;
95
96
  if (h && (v = h.replace(/\{\{\s*([^}]+?)\s*\}\}/g, (q, K) => {
96
- const M = K.split(".").reduce((S, y) => S == null ? void 0 : S[y], $);
97
+ const M = K.split(".").reduce((S, x) => S == null ? void 0 : S[x], $);
97
98
  return M == null ? "" : String(M);
98
99
  }).trim()), !v) {
99
100
  for (const q of [
@@ -121,8 +122,8 @@ function nl({ collection: n, id: m }) {
121
122
  }
122
123
  ) : /* @__PURE__ */ r(he, { children: v });
123
124
  }
124
- function al({ id: n }) {
125
- const m = Ce(), { apiBase: N } = Dt(), { data: c, isPending: P } = V({
125
+ function il({ id: n }) {
126
+ const m = Te(), { apiBase: N } = Dt(), { data: c, isPending: P } = V({
126
127
  queryKey: ["rrv-file-meta", String(n)],
127
128
  queryFn: () => m.request(
128
129
  G(`/files/${n}/meta`)
@@ -146,8 +147,8 @@ function al({ id: n }) {
146
147
  }
147
148
  );
148
149
  }
149
- const He = ({ collection: n, id: m }) => n === "nivaro_files" ? /* @__PURE__ */ r(al, { id: m }) : /* @__PURE__ */ r(nl, { collection: n, id: m });
150
- function il({
150
+ const He = ({ collection: n, id: m }) => n === "nivaro_files" ? /* @__PURE__ */ r(il, { id: m }) : /* @__PURE__ */ r(al, { collection: n, id: m });
151
+ function sl({
151
152
  junction: n,
152
153
  parentFk: m,
153
154
  junctionField: N,
@@ -157,14 +158,14 @@ function il({
157
158
  relation: $
158
159
  }) {
159
160
  var j;
160
- const W = Ce(), { data: v } = V({
161
+ const W = Te(), { data: v } = V({
161
162
  queryKey: ["cbv-collection-meta", n],
162
- queryFn: () => W.request(G(`/collections/${n}`)).then((b) => b.data),
163
+ queryFn: () => W.request(G(`/collections/${n}`)).then((y) => y.data),
163
164
  staleTime: 10 * 6e4,
164
165
  retry: !1
165
166
  }), h = ((v == null ? void 0 : v.relations) ?? []).find(
166
- (b) => b.many_collection === n && b.many_field === N
167
- ), q = String((h == null ? void 0 : h.one_allowed_collections) ?? "").split(",").map((b) => b.trim()).filter(Boolean), K = !!h && !h.one_collection && (q.length > 0 || !!h.one_collection_field), M = (h == null ? void 0 : h.one_collection_field) ?? "collection", S = (b) => b ? b === "directus_users" ? "nivaro_users" : b : null, y = (h == null ? void 0 : h.one_collection) ?? (K ? q.some((b) => b === "directus_users" || b === "nivaro_users") ? "nivaro_users" : S(q[0]) : null), { data: g } = V({
167
+ (y) => y.many_collection === n && y.many_field === N
168
+ ), q = Pt(h == null ? void 0 : h.one_allowed_collections), K = !!h && !h.one_collection && (q.length > 0 || !!h.one_collection_field), M = (h == null ? void 0 : h.one_collection_field) ?? "collection", S = (y) => y ? y === "directus_users" ? "nivaro_users" : y : null, x = (h == null ? void 0 : h.one_collection) ?? (K ? q.some((y) => y === "directus_users" || y === "nivaro_users") ? "nivaro_users" : S(q[0]) : null), { data: g } = V({
168
169
  queryKey: ["rrv-m2m", n, m, c, N, K ? M : ""],
169
170
  queryFn: () => W.request(
170
171
  G(`/items/${n}`, {
@@ -173,7 +174,7 @@ function il({
173
174
  limit: 200
174
175
  })
175
176
  ).then(
176
- (b) => (b.data ?? []).filter((k) => k[N] != null).map((k) => {
177
+ (y) => (y.data ?? []).filter((k) => k[N] != null).map((k) => {
177
178
  const F = k[N];
178
179
  return {
179
180
  id: String(typeof F == "object" ? F.id : F),
@@ -185,32 +186,32 @@ function il({
185
186
  enabled: !!v,
186
187
  staleTime: 3e4,
187
188
  retry: !1
188
- }), C = g == null ? void 0 : g.map((b) => b.id), _ = y ?? (K ? ((j = g == null ? void 0 : g.find((b) => b.collection)) == null ? void 0 : j.collection) ?? null : null), O = C == null ? void 0 : C.length;
189
+ }), T = g == null ? void 0 : g.map((y) => y.id), _ = x ?? (K ? ((j = g == null ? void 0 : g.find((y) => y.collection)) == null ? void 0 : j.collection) ?? null : null), O = T == null ? void 0 : T.length;
189
190
  return be(() => {
190
191
  O !== void 0 && (P == null || P(O));
191
192
  }, [O, P]), be(() => {
192
193
  _ && (w == null || w(_));
193
- }, [_, w]), v && !_ && (!K || g) ? /* @__PURE__ */ r(ee, {}) : !C || !_ ? /* @__PURE__ */ r("span", { className: "inline-block h-3.5 w-20 animate-pulse rounded bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" }) : C.length === 0 ? /* @__PURE__ */ r(ee, {}) : _ === "nivaro_files" && $ ? /* @__PURE__ */ r("div", { className: "mt-1", children: /* @__PURE__ */ r(
194
- Gt,
194
+ }, [_, w]), v && !_ && (!K || g) ? /* @__PURE__ */ r(ee, {}) : !T || !_ ? /* @__PURE__ */ r("span", { className: "inline-block h-3.5 w-20 animate-pulse rounded bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" }) : T.length === 0 ? /* @__PURE__ */ r(ee, {}) : _ === "nivaro_files" && $ ? /* @__PURE__ */ r("div", { className: "mt-1", children: /* @__PURE__ */ r(
195
+ Jt,
195
196
  {
196
197
  relation: $,
197
198
  parentId: c,
198
199
  allRelations: [],
199
200
  disabled: !0
200
201
  }
201
- ) }) : /* @__PURE__ */ r("span", { className: "flex flex-wrap gap-x-1.5 gap-y-0.5", children: (g ?? []).map(({ id: b, collection: k }, F) => /* @__PURE__ */ u(
202
+ ) }) : /* @__PURE__ */ r("span", { className: "flex flex-wrap gap-x-1.5 gap-y-0.5", children: (g ?? []).map(({ id: y, collection: k }, F) => /* @__PURE__ */ u(
202
203
  "span",
203
204
  {
204
205
  className: "inline-flex items-center whitespace-nowrap",
205
206
  children: [
206
- /* @__PURE__ */ r(He, { collection: k ?? _, id: b }),
207
- F < C.length - 1 && /* @__PURE__ */ r("span", { className: "text-slate-300 dark:text-slate-600", children: "," })
207
+ /* @__PURE__ */ r(He, { collection: k ?? _, id: y }),
208
+ F < T.length - 1 && /* @__PURE__ */ r("span", { className: "text-slate-300 dark:text-slate-600", children: "," })
208
209
  ]
209
210
  },
210
- `${k ?? _}:${b}`
211
+ `${k ?? _}:${y}`
211
212
  )) });
212
213
  }
213
- function sl({
214
+ function dl({
214
215
  collection: n,
215
216
  fkField: m,
216
217
  parentId: N,
@@ -219,7 +220,7 @@ function sl({
219
220
  defaultPreset: w,
220
221
  onCount: $
221
222
  }) {
222
- const W = Ce(), v = ct(), h = (P ?? []).filter((t) => t && Array.isArray(t.columns)), [q, K] = Z(
223
+ const W = Te(), v = ct(), h = (P ?? []).filter((t) => t && Array.isArray(t.columns)), [q, K] = Z(
223
224
  () => {
224
225
  var t;
225
226
  return h.length >= 2 ? ((t = h.find((i) => i.name === w)) == null ? void 0 : t.name) ?? h[0].name : "__all__";
@@ -234,7 +235,7 @@ function sl({
234
235
  return ((i = ((M == null ? void 0 : M.relations) ?? []).find(
235
236
  (o) => o.many_collection === n && o.many_field === t && o.one_collection
236
237
  )) == null ? void 0 : i.one_collection) ?? null;
237
- }, { data: y } = V({
238
+ }, { data: x } = V({
238
239
  queryKey: ["rrv-cols", n, c ?? null],
239
240
  queryFn: () => W.request(
240
241
  G(`/field-config/${n}`, c ? { layout_id: c } : {})
@@ -254,21 +255,21 @@ function sl({
254
255
  "timestamp",
255
256
  "uuid"
256
257
  ].includes(i.type ?? ""))
257
- ).filter((i, o, f) => f.findIndex((T) => T.field === i.field) === o)
258
+ ).filter((i, o, f) => f.findIndex((C) => C.field === i.field) === o)
258
259
  })),
259
260
  staleTime: 5 * 6e4,
260
261
  retry: !1
261
- }), g = (y == null ? void 0 : y.cols) ?? [], C = !!(y != null && y.lineNo), _ = q !== "__all__" ? h.find((t) => t.name === q) : null, O = ge(() => {
262
+ }), g = (x == null ? void 0 : x.cols) ?? [], T = !!(x != null && x.lineNo), _ = q !== "__all__" ? h.find((t) => t.name === q) : null, O = ge(() => {
262
263
  if (!_) return g;
263
264
  const t = new Set(_.columns), i = g.filter((o) => t.has(o.field));
264
265
  return i.length > 0 ? i : g;
265
- }, [g, _]), [j, b] = Z(""), [k, F] = Z(1), [ne, J] = Z({}), Y = Lt(ne, 350), Oe = ge(() => {
266
+ }, [g, _]), [j, y] = Z(""), [k, F] = Z(1), [ne, J] = Z({}), Y = Lt(ne, 350), Oe = ge(() => {
266
267
  const t = [
267
268
  { path: [m], op: "_eq", value: N }
268
269
  ];
269
270
  for (const [i, o] of Object.entries(Y)) {
270
271
  if (!(o != null && o.value.trim())) continue;
271
- const f = o.value.trim(), T = Number(f), D = o.op === "_contains" ? f : f === "true" || f === "false" ? f === "true" : Number.isNaN(T) ? f : T;
272
+ const f = o.value.trim(), C = Number(f), D = o.op === "_contains" ? f : f === "true" || f === "false" ? f === "true" : Number.isNaN(C) ? f : C;
272
273
  t.push({ path: [i], op: o.op, value: D });
273
274
  }
274
275
  return JSON.stringify(t);
@@ -277,12 +278,12 @@ function sl({
277
278
  isLoading: oe,
278
279
  isFetching: Ae
279
280
  } = V({
280
- queryKey: ["rrv-rows", n, m, N, j, C, k, Oe],
281
+ queryKey: ["rrv-rows", n, m, N, j, T, k, Oe],
281
282
  queryFn: () => W.request(
282
283
  G(`/items/${n}`, {
283
284
  limit: p,
284
285
  page: k,
285
- ...j ? { sort: j } : C ? { sort: "line_number" } : {},
286
+ ...j ? { sort: j } : T ? { sort: "line_number" } : {},
286
287
  conditions: Oe
287
288
  })
288
289
  ),
@@ -308,13 +309,13 @@ function sl({
308
309
  ).then((t) => t.data ?? { rows: {}, targets: {} }).catch(() => ({ rows: {}, targets: {} })),
309
310
  enabled: ce.length > 0 && ue.length > 0,
310
311
  staleTime: 3e4
311
- }), R = C && A.some((t) => t.line_number != null), xe = Math.max(1, Math.ceil(X / p)), ae = (t, i, o) => {
312
+ }), R = T && A.some((t) => t.line_number != null), xe = Math.max(1, Math.ceil(X / p)), ae = (t, i, o) => {
312
313
  F(1), J((f) => {
313
- const T = { ...f };
314
- return o ? T[t] = { op: i, value: o } : delete T[t], T;
314
+ const C = { ...f };
315
+ return o ? C[t] = { op: i, value: o } : delete C[t], C;
315
316
  });
316
317
  }, We = (t) => {
317
- F(1), b((i) => i === t ? `-${t}` : i === `-${t}` ? "" : t);
318
+ F(1), y((i) => i === t ? `-${t}` : i === `-${t}` ? "" : t);
318
319
  };
319
320
  if (oe)
320
321
  return /* @__PURE__ */ r("div", { className: "space-y-1.5 py-2", children: [0, 1, 2].map((t) => /* @__PURE__ */ r(
@@ -356,8 +357,8 @@ function sl({
356
357
  if (i.type === "decimal" || i.type === "float") return Je(o);
357
358
  if (i.type === "integer") return Ie(o);
358
359
  if (i.type === "date" || i.type === "datetime" || i.type === "timestamp") return mt(o);
359
- const T = String(o);
360
- return T.length > 48 ? `${T.slice(0, 48)}…` : T;
360
+ const C = String(o);
361
+ return C.length > 48 ? `${C.slice(0, 48)}…` : C;
361
362
  }, ie = (t) => ["decimal", "float", "integer"].includes(t.type ?? "") && !S(t.field) && !t.field.includes("."), Re = (t) => {
362
363
  const i = t.options;
363
364
  if (!i) return {};
@@ -377,8 +378,8 @@ function sl({
377
378
  const o = A.map((D) => Number(D[t.field])).filter((D) => !Number.isNaN(D));
378
379
  let f = null;
379
380
  if (i === "count" ? f = A.length : o.length > 0 && (i === "sum" ? f = o.reduce((D, te) => D + te, 0) : i === "avg" ? f = o.reduce((D, te) => D + te, 0) / o.length : i === "min" ? f = Math.min(...o) : i === "max" && (f = Math.max(...o))), f === null) return "—";
380
- const T = Re(t).format;
381
- return i === "count" || T === "int" ? Ie(Math.round(f)) : T === "currency" || t.type === "decimal" || t.type === "float" ? Je(f) : i === "avg" ? f.toFixed(2) : Ie(f);
381
+ const C = Re(t).format;
382
+ return i === "count" || C === "int" ? Ie(Math.round(f)) : C === "currency" || t.type === "decimal" || t.type === "float" ? Je(f) : i === "avg" ? f.toFixed(2) : Ie(f);
382
383
  }, _e = (t) => !S(t.field) && !t.field.includes("."), Le = (t) => S(t.field) || t.field.includes(".") ? null : t.type === "boolean" ? "bool" : ["integer", "decimal", "float"].includes(t.type ?? "") ? "num" : ["string", "text"].includes(t.type ?? "") ? "text" : null, ke = O.some((t) => Le(t) != null);
383
384
  return /* @__PURE__ */ u("div", { children: [
384
385
  h.length >= 2 && /* @__PURE__ */ r("div", { className: "mb-1.5 flex flex-wrap items-center gap-1", "data-read-presets": !0, children: [
@@ -585,48 +586,48 @@ function ot({
585
586
  gridCounts: h
586
587
  }) {
587
588
  var et;
588
- const q = Ce(), K = Qt(), M = c ? c.record ?? {} : null, S = !!(c != null && c.context.showHidden), y = c ? String(((et = c.record) == null ? void 0 : et.id) ?? "") : m ?? "", g = ge(
589
+ const q = Te(), K = zt(), M = c ? c.record ?? {} : null, S = !!(c != null && c.context.showHidden), x = c ? String(((et = c.record) == null ? void 0 : et.id) ?? "") : m ?? "", g = ge(
589
590
  () => c ? {
590
591
  ...c.layout,
591
592
  layout: c.layout.layout ?? { id: 0, name: "" }
592
593
  } : N,
593
594
  [c, N]
594
- ), C = (e) => ({
595
+ ), T = (e) => ({
595
596
  kind: qe(e.field) ? "slot" : "field",
596
597
  field: e.field,
597
598
  group_key: e.group_key ?? null
598
- }), _ = (e, l, s = !1) => c ? /* @__PURE__ */ r(Yt, { target: e, children: s ? /* @__PURE__ */ r("div", { "data-design-hidden": !0, className: "opacity-40", children: l }) : l }) : l, O = ge(
599
+ }), _ = (e, l, s = !1) => c ? /* @__PURE__ */ r(Xt, { target: e, children: s ? /* @__PURE__ */ r("div", { "data-design-hidden": !0, className: "opacity-40", children: l }) : l }) : l, O = ge(
599
600
  () => [
600
601
  ...new Set(
601
602
  (c ? [] : (g == null ? void 0 : g.assignments) ?? []).map((e) => e.field).filter((e) => e && !e.startsWith("__") && !e.includes("."))
602
603
  )
603
604
  ].sort(),
604
605
  [g, c]
605
- ), { data: j } = Jt(n, y, O), b = (e) => {
606
+ ), { data: j } = Ht(n, x, O), y = (e) => {
606
607
  const l = j == null ? void 0 : j[e];
607
608
  if (!l) return null;
608
609
  const s = l.via !== "user";
609
610
  return l.caller && l.activity_id ? /* @__PURE__ */ r(
610
- Bt,
611
+ Gt,
611
612
  {
612
613
  activityId: l.activity_id,
613
614
  callerName: l.caller.name,
614
615
  collection: n,
615
- itemId: y,
616
+ itemId: x,
616
617
  children: /* @__PURE__ */ u(
617
618
  "button",
618
619
  {
619
620
  type: "button",
620
621
  "data-field-touch": e,
621
622
  "data-field-touch-caller": l.caller.key,
622
- "data-tip": `Changed ${Te(l.at)} by ${l.caller.name} (through the API) — click for the request`,
623
- "aria-label": `Changed ${Te(l.at)} by ${l.caller.name} through the API`,
623
+ "data-tip": `Changed ${Ce(l.at)} by ${l.caller.name} (through the API) — click for the request`,
624
+ "aria-label": `Changed ${Ce(l.at)} by ${l.caller.name} through the API`,
624
625
  className: "ml-1 inline-flex items-center gap-1 rounded-full bg-amber-50 px-1.5 align-middle text-[9.5px] font-medium leading-4 text-amber-800 hover:bg-amber-100 dark:bg-amber-400/10 dark:text-amber-300 dark:hover:bg-amber-400/20",
625
626
  children: [
626
627
  /* @__PURE__ */ r("span", { className: "h-1.5 w-1.5 rounded-full bg-amber-400", "aria-hidden": !0 }),
627
628
  l.caller.name,
628
629
  " · ",
629
- Te(l.at)
630
+ Ce(l.at)
630
631
  ]
631
632
  }
632
633
  )
@@ -635,14 +636,14 @@ function ot({
635
636
  "span",
636
637
  {
637
638
  "data-field-touch": e,
638
- "data-tip": `Changed ${Te(l.at)} by ${l.who}${s ? ` · ${l.via}` : ""}`,
639
+ "data-tip": `Changed ${Ce(l.at)} by ${l.who}${s ? ` · ${l.via}` : ""}`,
639
640
  role: "img",
640
- "aria-label": `Changed ${Te(l.at)} by ${l.who}`,
641
+ "aria-label": `Changed ${Ce(l.at)} by ${l.who}`,
641
642
  className: `ml-1 inline-block h-1.5 w-1.5 rounded-full align-middle ${s ? "bg-amber-400" : "bg-slate-300 dark:bg-slate-600"}`
642
643
  }
643
644
  );
644
- }, { data: k } = el(n, y, !!$ && !c), F = ge(
645
- () => $ && (k != null && k.enabled) ? tl(k.findings) : null,
645
+ }, { data: k } = tl(n, x, !!$ && !c), F = ge(
646
+ () => $ && (k != null && k.enabled) ? ll(k.findings) : null,
646
647
  [$, k]
647
648
  ), ne = ({ field: e }) => {
648
649
  const l = F == null ? void 0 : F.get(e);
@@ -668,19 +669,19 @@ function ot({
668
669
  staleTime: 10 * 6e4,
669
670
  retry: !1
670
671
  }), Y = qt(), { data: Oe } = V({
671
- queryKey: ["rrv-record", n, y],
672
+ queryKey: ["rrv-record", n, x],
672
673
  enabled: !c,
673
- queryFn: () => q.request(G(`/items/${n}/${y}`)).then((e) => e.data),
674
- initialData: () => Y.getQueryData(["item", n, y]) ?? void 0,
674
+ queryFn: () => q.request(G(`/items/${n}/${x}`)).then((e) => e.data),
675
+ initialData: () => Y.getQueryData(["item", n, x]) ?? void 0,
675
676
  initialDataUpdatedAt: () => {
676
677
  var e;
677
- return (e = Y.getQueryState(["item", n, y])) == null ? void 0 : e.dataUpdatedAt;
678
+ return (e = Y.getQueryState(["item", n, x])) == null ? void 0 : e.dataUpdatedAt;
678
679
  },
679
680
  staleTime: 3e4,
680
681
  retry: !1
681
682
  }), p = M ?? Oe;
682
- Et(n, c ? null : y, (e) => {
683
- e.aspectsOnly || e.deleted || (Y.invalidateQueries({ queryKey: ["rrv-record", n, y] }), Y.invalidateQueries({ queryKey: ["field-touch", n, y] }));
683
+ It(n, c ? null : x, (e) => {
684
+ e.aspectsOnly || e.deleted || (Y.invalidateQueries({ queryKey: ["rrv-record", n, x] }), Y.invalidateQueries({ queryKey: ["field-touch", n, x] }));
684
685
  });
685
686
  const B = Ot(null), [oe, Ae] = Z(() => /* @__PURE__ */ new Set());
686
687
  be(() => {
@@ -749,17 +750,17 @@ function ot({
749
750
  }, [_e, Le] = Z({}), ke = (e) => S || _e[e] === !0, [t, i] = Z({}), o = st(
750
751
  (e) => (l) => i((s) => s[e] === l ? s : { ...s, [e]: l }),
751
752
  []
752
- ), [f, T] = Z({}), D = st(
753
- (e) => (l) => T((s) => s[e] === l ? s : { ...s, [e]: l }),
753
+ ), [f, C] = Z({}), D = st(
754
+ (e) => (l) => C((s) => s[e] === l ? s : { ...s, [e]: l }),
754
755
  []
755
756
  ), te = (e) => {
756
- const l = ae.filter((d) => d.group_key === e).sort((d, x) => d.sort - x.sort);
757
+ const l = ae.filter((d) => d.group_key === e).sort((d, b) => d.sort - b.sort);
757
758
  if (l.length === 0) return null;
758
759
  const s = l.some((d) => ke(d.field));
759
760
  return /* @__PURE__ */ r("div", { className: s ? "mt-3 space-y-4" : "hidden", "data-read-widgets": !0, children: l.map((d) => /* @__PURE__ */ r("div", { hidden: !ke(d.field), children: _(
760
761
  { kind: "slot", field: d.field, group_key: d.group_key ?? null },
761
762
  /* @__PURE__ */ r(
762
- ll,
763
+ rl,
763
764
  {
764
765
  widgetId: d.widget_id,
765
766
  inputBindings: We(d),
@@ -768,8 +769,8 @@ function ot({
768
769
  ready: !!p,
769
770
  label: d.label_override ?? void 0,
770
771
  defaultExpanded: d.default_expanded == null ? !0 : !!d.default_expanded,
771
- onContentChange: (x) => Le(
772
- (E) => E[d.field] === x ? E : { ...E, [d.field]: x }
772
+ onContentChange: (b) => Le(
773
+ (E) => E[d.field] === b ? E : { ...E, [d.field]: b }
773
774
  )
774
775
  }
775
776
  ),
@@ -782,7 +783,7 @@ function ot({
782
783
  be(() => {
783
784
  Ne && me(Ne.open ? new Set(g.groups.map((e) => e.key)) : /* @__PURE__ */ new Set());
784
785
  }, [Ne == null ? void 0 : Ne.seq]), be(() => {
785
- const e = we ? Zt(we.target) : null;
786
+ const e = we ? el(we.target) : null;
786
787
  e && me((l) => l.has(e) ? l : new Set(l).add(e));
787
788
  }, [we == null ? void 0 : we.seq]);
788
789
  const Ue = [];
@@ -806,50 +807,50 @@ function ot({
806
807
  }, Ke = (e) => {
807
808
  const l = H.get(e.field), s = pe(e.overrides);
808
809
  if (qe(e.field)) {
809
- const L = Wt(s), de = zt((L == null ? void 0 : L.expr) ?? "", p ?? {});
810
- return /* @__PURE__ */ r("span", { "data-display-formula": e.field, className: "tabular-nums", children: de.error ? "—" : Mt(de.value, L ?? { format: "", currency: null }) });
810
+ const L = Mt(s), de = Yt((L == null ? void 0 : L.expr) ?? "", p ?? {});
811
+ return /* @__PURE__ */ r("span", { "data-display-formula": e.field, className: "tabular-nums", children: de.error ? "—" : Ut(de.value, L ?? { format: "", currency: null }) });
811
812
  }
812
813
  const d = Q(e.field);
813
- if (c && !y && (d != null && d.junction_field)) return /* @__PURE__ */ r(ee, {});
814
+ if (c && !x && (d != null && d.junction_field)) return /* @__PURE__ */ r(ee, {});
814
815
  if (d != null && d.junction_field && d.many_collection && d.many_field)
815
816
  return /* @__PURE__ */ r(
816
- il,
817
+ sl,
817
818
  {
818
819
  junction: d.many_collection,
819
820
  parentFk: d.many_field,
820
821
  junctionField: d.junction_field,
821
- parentId: y,
822
+ parentId: x,
822
823
  onCount: o(e.field),
823
824
  onTarget: D(e.field),
824
825
  relation: d
825
826
  }
826
827
  );
827
- const x = p == null ? void 0 : p[e.field], E = ue(e.field);
828
- if (E === "nivaro_users" && x != null)
829
- return /* @__PURE__ */ r("span", { className: "inline-block", children: /* @__PURE__ */ r(ut, { userId: String(x), size: "compact" }) });
830
- if (E) return /* @__PURE__ */ r(He, { collection: E, id: x });
831
- if (x == null || x === "") return /* @__PURE__ */ r(ee, {});
828
+ const b = p == null ? void 0 : p[e.field], E = ue(e.field);
829
+ if (E === "nivaro_users" && b != null)
830
+ return /* @__PURE__ */ r("span", { className: "inline-block", children: /* @__PURE__ */ r(ut, { userId: String(b), size: "compact" }) });
831
+ if (E) return /* @__PURE__ */ r(He, { collection: E, id: b });
832
+ if (b == null || b === "") return /* @__PURE__ */ r(ee, {});
832
833
  if ((l == null ? void 0 : l.type) === "boolean")
833
834
  return /* @__PURE__ */ r(
834
835
  ft,
835
836
  {
836
- value: x,
837
+ value: b,
837
838
  trueTone: (s.options ?? {}).trueTone ?? "positive"
838
839
  }
839
840
  );
840
841
  const z = s.options ?? {};
841
- return Qe(e) && typeof x == "string" ? /^\s*\{/.test(x) ? /* @__PURE__ */ r("div", { className: "whitespace-pre-wrap font-normal", children: Ht(x) }) : /* @__PURE__ */ r(
842
+ return Qe(e) && typeof b == "string" ? /^\s*\{/.test(b) ? /* @__PURE__ */ r("div", { className: "whitespace-pre-wrap font-normal", children: Qt(b) }) : /* @__PURE__ */ r(
842
843
  "div",
843
844
  {
844
845
  className: "rrv-prose font-normal leading-relaxed [&_a]:underline [&_h1]:text-[15px] [&_h1]:font-semibold [&_h2]:text-[14px] [&_h2]:font-semibold [&_h3]:font-semibold [&_li]:ml-4 [&_ol]:list-decimal [&_p]:my-1 [&_ul]:list-disc",
845
- dangerouslySetInnerHTML: { __html: Vt(x) }
846
+ dangerouslySetInnerHTML: { __html: Bt(b) }
846
847
  }
847
- ) : z.format === "currency" ? /* @__PURE__ */ r("span", { className: "tabular-nums", children: Je(x) }) : (l == null ? void 0 : l.type) === "decimal" || (l == null ? void 0 : l.type) === "float" ? /* @__PURE__ */ r("span", { className: "tabular-nums", children: Ie(x) }) : (l == null ? void 0 : l.type) === "date" || (l == null ? void 0 : l.type) === "datetime" || (l == null ? void 0 : l.type) === "timestamp" ? mt(x) : String(x);
848
+ ) : z.format === "currency" ? /* @__PURE__ */ r("span", { className: "tabular-nums", children: Je(b) }) : (l == null ? void 0 : l.type) === "decimal" || (l == null ? void 0 : l.type) === "float" ? /* @__PURE__ */ r("span", { className: "tabular-nums", children: Ie(b) }) : (l == null ? void 0 : l.type) === "date" || (l == null ? void 0 : l.type) === "datetime" || (l == null ? void 0 : l.type) === "timestamp" ? mt(b) : String(b);
848
849
  }, ht = (e) => {
849
850
  const l = pe(e.overrides), s = Q(e.field);
850
851
  if (!(s != null && s.many_collection) || !s.many_field) return null;
851
- if (c && !y) return /* @__PURE__ */ r("p", { className: "py-3 text-[12px] text-slate-400", children: "No records" });
852
- const d = l.options ?? {}, x = (() => {
852
+ if (c && !x) return /* @__PURE__ */ r("p", { className: "py-3 text-[12px] text-slate-400", children: "No records" });
853
+ const d = l.options ?? {}, b = (() => {
853
854
  var L;
854
855
  const z = (L = H.get(e.field)) == null ? void 0 : L.options;
855
856
  if (!z) return {};
@@ -862,14 +863,14 @@ function ot({
862
863
  return z;
863
864
  })(), E = d.layout_id ?? null;
864
865
  return /* @__PURE__ */ r(
865
- sl,
866
+ dl,
866
867
  {
867
868
  collection: s.many_collection,
868
869
  fkField: s.many_field,
869
- parentId: y,
870
+ parentId: x,
870
871
  layoutId: E,
871
- presets: d.column_presets ?? x.column_presets,
872
- defaultPreset: d.default_preset ?? x.default_preset ?? null,
872
+ presets: d.column_presets ?? b.column_presets,
873
+ defaultPreset: d.default_preset ?? b.default_preset ?? null,
873
874
  onCount: o(e.field)
874
875
  },
875
876
  e.field
@@ -880,12 +881,12 @@ function ot({
880
881
  return l == null || l === "" || Array.isArray(l) && l.length === 0;
881
882
  }, yt = (e) => xe.find((l) => l.field === e), $e = (e) => {
882
883
  var d;
883
- const l = pe(e.overrides).label, s = K ? It(e.overrides, K).label : void 0;
884
+ const l = pe(e.overrides).label, s = K ? Wt(e.overrides, K).label : void 0;
884
885
  return s !== void 0 ? s : qe(e.field) ? typeof l == "string" && l.trim() ? l : "Formula" : typeof l == "string" && l.trim() ? l : e.label_override || ((d = H.get(e.field)) == null ? void 0 : d.label) || Ge(e.field);
885
886
  }, vt = (e) => {
886
- const l = Pt(e.swap_config), s = xe.filter((a) => a.group_key === e.key && !bt.has(a.field)).filter((a) => S || !p || !Kt(a.overrides) || !Be(p[a.field])).sort((a, I) => a.sort - I.sort), d = ae.filter((a) => a.group_key === e.key), x = De(e.key), E = s.length === 0 && d.length === 0 && x.length === 0;
887
+ const l = Kt(e.swap_config), s = xe.filter((a) => a.group_key === e.key && !bt.has(a.field)).filter((a) => S || !p || !jt(a.overrides) || !Be(p[a.field])).sort((a, I) => a.sort - I.sort), d = ae.filter((a) => a.group_key === e.key), b = De(e.key), E = s.length === 0 && d.length === 0 && b.length === 0;
887
888
  if (E && !c) return null;
888
- const z = (a) => gt && !S && (Se(a) || se(a)) && ((h == null ? void 0 : h[a.field]) ?? t[a.field]) === 0, L = s.filter((a) => !Se(a)), de = s.filter(Se), tt = d.filter((a) => ke(a.field)), kt = s.filter((a) => !z(a)), Nt = !E && kt.length === 0 && x.length === 0 && tt.length === 0, wt = (a) => (h == null ? void 0 : h[a.field]) ?? t[a.field], Ve = !!l.emptyText && !!p && !c && x.length === 0 && tt.length === 0 && s.every((a) => Se(a) || se(a) ? wt(a) === 0 : Be(p[a.field])), St = jt(L, { rows: l.rows }).units, lt = e.read_width === "full" || e.read_width === "half" || e.read_width === "third" ? e.read_width : de.length > 0 || d.length > 0 || x.length > 0 || L.length > 4 ? "full" : "half", $t = (a) => {
889
+ const z = (a) => gt && !S && (Se(a) || se(a)) && ((h == null ? void 0 : h[a.field]) ?? t[a.field]) === 0, L = s.filter((a) => !Se(a)), de = s.filter(Se), tt = d.filter((a) => ke(a.field)), kt = s.filter((a) => !z(a)), Nt = !E && kt.length === 0 && b.length === 0 && tt.length === 0, wt = (a) => (h == null ? void 0 : h[a.field]) ?? t[a.field], Ve = !!l.emptyText && !!p && !c && b.length === 0 && tt.length === 0 && s.every((a) => Se(a) || se(a) ? wt(a) === 0 : Be(p[a.field])), St = Et(L, { rows: l.rows }).units, lt = e.read_width === "full" || e.read_width === "half" || e.read_width === "third" ? e.read_width : de.length > 0 || d.length > 0 || b.length > 0 || L.length > 4 ? "full" : "half", $t = (a) => {
889
890
  var nt, at, it;
890
891
  if (z(a)) return null;
891
892
  const Fe = !!(pe(a.overrides).options ?? {}).emphasis, U = Qe(a) || !!((at = (nt = H.get(a.field)) == null ? void 0 : nt.interface) != null && at.includes("rich-text")), je = p == null ? void 0 : p[a.field], rt = !U && !se(a) && !ue(a.field) && (String(((it = H.get(a.field)) == null ? void 0 : it.interface) ?? "").includes("textarea") || typeof je == "string" && je.length > 36);
@@ -894,12 +895,12 @@ function ot({
894
895
  {
895
896
  className: `min-w-0 ${U || se(a) && (f[a.field] === "nivaro_files" || (t[a.field] ?? 0) > 3) ? "col-span-full" : Fe || rt ? "col-span-2" : ""}`,
896
897
  children: _(
897
- C(a),
898
+ T(a),
898
899
  /* @__PURE__ */ u(he, { children: [
899
900
  /* @__PURE__ */ u("dt", { className: Ee, children: [
900
901
  $e(a),
901
902
  /* @__PURE__ */ r(ne, { field: a.field }),
902
- b(a.field)
903
+ y(a.field)
903
904
  ] }),
904
905
  /* @__PURE__ */ r(
905
906
  "dd",
@@ -929,7 +930,7 @@ function ot({
929
930
  /* @__PURE__ */ r("dd", { className: "mt-1 flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-[13px] font-medium text-slate-800 dark:text-slate-100", children: p ? Fe.length === 0 ? /* @__PURE__ */ r(ee, {}) : Fe.map((U, je) => /* @__PURE__ */ u(At, { children: [
930
931
  je > 0 && /* @__PURE__ */ r("span", { "aria-hidden": !0, className: "text-slate-300 dark:text-slate-600", children: "·" }),
931
932
  _(
932
- C(U),
933
+ T(U),
933
934
  /* @__PURE__ */ r(
934
935
  "span",
935
936
  {
@@ -984,11 +985,11 @@ function ot({
984
985
  title: `Edit ${e.label}`,
985
986
  "aria-label": `Edit ${e.label}`,
986
987
  className: "relative -my-1 rounded p-1 text-slate-400 opacity-0 transition-opacity hover:bg-slate-100 hover:text-slate-700 focus-visible:opacity-100 group-hover/rs:opacity-100 dark:hover:bg-white/5 dark:hover:text-slate-200 motion-reduce:transition-none",
987
- children: /* @__PURE__ */ r(Tt, { className: "h-3 w-3" })
988
+ children: /* @__PURE__ */ r(Ct, { className: "h-3 w-3" })
988
989
  }
989
990
  ),
990
991
  e.is_collapsed && /* @__PURE__ */ r(
991
- Ct,
992
+ Tt,
992
993
  {
993
994
  "aria-hidden": "true",
994
995
  className: `pointer-events-none h-3.5 w-3.5 shrink-0 transition-transform group-hover/rs:text-slate-700 dark:group-hover/rs:text-slate-200 ${fe(e) ? "" : "-rotate-90"}`
@@ -1020,7 +1021,7 @@ function ot({
1020
1021
  className: L.length > 0 ? "mt-3" : "",
1021
1022
  hidden: z(a) || Ve,
1022
1023
  children: _(
1023
- C(a),
1024
+ T(a),
1024
1025
  /* @__PURE__ */ u(he, { children: [
1025
1026
  (I = F == null ? void 0 : F.get(a.field)) != null && I.length ? /* @__PURE__ */ u("div", { className: "mb-1.5 flex items-center gap-1.5 text-[11px] font-medium text-amber-700 dark:text-amber-300", children: [
1026
1027
  /* @__PURE__ */ r("span", { children: $e(a) }),
@@ -1096,7 +1097,7 @@ function ot({
1096
1097
  /* @__PURE__ */ u("dt", { className: Ee, children: [
1097
1098
  $e(e),
1098
1099
  /* @__PURE__ */ r(ne, { field: e.field }),
1099
- b(e.field)
1100
+ y(e.field)
1100
1101
  ] }),
1101
1102
  /* @__PURE__ */ r(
1102
1103
  "dd",
@@ -1114,7 +1115,7 @@ function ot({
1114
1115
  ]
1115
1116
  }
1116
1117
  ),
1117
- /* @__PURE__ */ r("style", { children: rl }),
1118
+ /* @__PURE__ */ r("style", { children: nl }),
1118
1119
  J ? /* @__PURE__ */ r("div", { className: "grid items-stretch gap-4", "data-read-board": !0, children: Ue.map(vt) }) : /* @__PURE__ */ u("div", { className: "flex flex-col gap-4", "data-read-board-pending": !0, children: [
1119
1120
  /* @__PURE__ */ r("div", { className: "h-32 animate-pulse rounded-xl bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" }),
1120
1121
  /* @__PURE__ */ r("div", { className: "h-32 animate-pulse rounded-xl bg-slate-100 dark:bg-[hsl(var(--nvr-skeleton))]" }),
@@ -1125,9 +1126,9 @@ function ot({
1125
1126
  }
1126
1127
  );
1127
1128
  }
1128
- function Ll(n) {
1129
- return n.design ? /* @__PURE__ */ r(Xt, { design: n.design.context, onRefusedWrite: n.design.onRefusedWrite, children: /* @__PURE__ */ r(Rt.Provider, { value: null, children: /* @__PURE__ */ r(ot, { ...n }) }) }) : /* @__PURE__ */ r(ot, { ...n });
1129
+ function Kl(n) {
1130
+ return n.design ? /* @__PURE__ */ r(Zt, { design: n.design.context, onRefusedWrite: n.design.onRefusedWrite, children: /* @__PURE__ */ r(Rt.Provider, { value: null, children: /* @__PURE__ */ r(ot, { ...n }) }) }) : /* @__PURE__ */ r(ot, { ...n });
1130
1131
  }
1131
1132
  export {
1132
- Ll as RecordReadView
1133
+ Kl as RecordReadView
1133
1134
  };
@@ -1,72 +1,73 @@
1
1
  import { jsx as n, jsxs as c } from "react/jsx-runtime";
2
- import { useQuery as N } from "@tanstack/react-query";
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
5
  import { useNivaroClient as fe, useItemEditAuth as pe, useDrilldown as $e } from "../../context.js";
6
+ import { parseAllowedCollections as Ie } from "../../lib/allowed-collections.js";
6
7
  import { get as C } from "../../lib/commands.js";
7
- import { useRecordReader as Ie } from "../../lib/record-loader.js";
8
+ import { useRecordReader as Ae } from "../../lib/record-loader.js";
8
9
  import { useOnlineUsers as he } from "../../lib/use-online-users.js";
9
10
  import { cn as Q, userOptionFilter as ye } from "../../lib/utils.js";
10
11
  import { UserAvatar as be } from "../UserAvatar.js";
11
- import { Command as xe, CommandInput as ge, CommandList as ve, CommandEmpty as ke, CommandGroup as Ne, CommandItem as we } from "../ui/command.js";
12
+ import { Command as xe, CommandInput as ge, CommandList as ve, CommandEmpty as ke, CommandGroup as we, CommandItem as Ne } from "../ui/command.js";
12
13
  import { Popover as Se, PopoverTrigger as _e, PopoverContent as Ce } from "../ui/popover.js";
13
14
  import { applyDisplayTemplate as qe } from "./helpers.js";
14
15
  import { useM2MStaging as Le } from "./M2MStagingContext.js";
15
- import { useStaleTip as Ae, RelatedItemLabel as ie } from "./RelationCombobox.js";
16
+ import { useStaleTip as Ke, RelatedItemLabel as ie } from "./RelationCombobox.js";
16
17
  function je(s) {
17
- return s.replace(/\(.*$/, "").trim().split(/\s+/).map((a) => a[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
18
+ return s.replace(/\(.*$/, "").trim().split(/\s+/).map((o) => o[0]).filter(Boolean).slice(0, 2).join("").toUpperCase() || "?";
18
19
  }
19
20
  function Fe(s) {
20
- return ((s == null ? void 0 : s.one_allowed_collections) ?? "").split(",").map((a) => a.trim()).filter(Boolean);
21
+ return Ie(s == null ? void 0 : s.one_allowed_collections);
21
22
  }
22
23
  function Te(s) {
23
24
  if (!s) return null;
24
25
  if (s.one_collection) return s.one_collection;
25
- const a = Fe(s);
26
- return a.length === 0 ? null : a.some((w) => w === "directus_users" || w === "nivaro_users") ? "nivaro_users" : a[0];
26
+ const o = Fe(s);
27
+ return o.length === 0 ? null : o.some((N) => N === "directus_users" || N === "nivaro_users") ? "nivaro_users" : o[0];
27
28
  }
28
- function Ze(s) {
29
+ function et(s) {
29
30
  if (!s || s.one_collection) return null;
30
- const a = Fe(s);
31
- if (a.length === 0) return null;
32
- const w = a.includes("directus_users") ? "directus_users" : a.includes("nivaro_users") ? "nivaro_users" : a[0];
33
- return { field: s.one_collection_field ?? "collection", value: w };
31
+ const o = Fe(s);
32
+ if (o.length === 0) return null;
33
+ const N = o.includes("directus_users") ? "directus_users" : o.includes("nivaro_users") ? "nivaro_users" : o[0];
34
+ return { field: s.one_collection_field ?? "collection", value: N };
34
35
  }
35
- function Me({
36
+ function tt({
36
37
  relation: s,
37
- parentId: a,
38
- allRelations: w,
38
+ parentId: o,
39
+ allRelations: N,
39
40
  extraFilter: h,
40
41
  optionSort: y,
41
42
  requiredParent: K,
42
43
  onCountChange: J,
43
44
  drilldown: D
44
45
  }) {
45
- const b = fe(), W = $e(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = w.find(
46
+ const b = fe(), W = $e(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = N.find(
46
47
  (e) => e.many_collection === s.many_collection && e.many_field === s.junction_field && e.id !== s.id
47
- ), r = Te(le), x = s.junction_field ?? "", z = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: o } = N({
48
+ ), r = Te(le), x = s.junction_field ?? "", z = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: a } = w({
48
49
  queryKey: ["col-meta", r],
49
50
  queryFn: () => b.request(C(`/collections/${r}`)).then((e) => e.data),
50
51
  enabled: !!r,
51
52
  staleTime: 3e5,
52
53
  retry: !1
53
- }), { data: X = [] } = N({
54
- queryKey: ["m2m-items", s.many_collection, z, a],
54
+ }), { data: X = [] } = w({
55
+ queryKey: ["m2m-items", s.many_collection, z, o],
55
56
  queryFn: () => b.request(
56
57
  C(`/items/${s.many_collection}`, {
57
- filter: JSON.stringify({ [z]: { _eq: a } }),
58
+ filter: JSON.stringify({ [z]: { _eq: o } }),
58
59
  limit: 200,
59
60
  fields: `id,${x}`
60
61
  })
61
62
  ).then((e) => e.data ?? []),
62
63
  staleTime: 3e4,
63
- enabled: !!a && a !== "new"
64
+ enabled: !!o && o !== "new"
64
65
  }), re = pe().isAdmin, E = r === "nivaro_users" ? ye(re) : null, R = he(r === "nivaro_users"), H = h ? E ? { _and: [h, E] } : h : E, j = H ? JSON.stringify(H) : void 0, g = y && !/^-?label$/.test(y) ? y : void 0, S = (() => {
65
- const e = o == null ? void 0 : o.display_template;
66
+ const e = a == null ? void 0 : a.display_template;
66
67
  if (!e || !e.includes(".")) return null;
67
68
  const i = [...e.matchAll(/\{\{([^}]+)\}\}/g)].map((u) => u[1].trim());
68
69
  return i.length === 0 ? null : ["id", ...i].join(",");
69
- })(), { data: O = [], isFetching: B } = N({
70
+ })(), { data: O = [], isFetching: V } = w({
70
71
  queryKey: [
71
72
  "m2m-options",
72
73
  r,
@@ -89,7 +90,7 @@ function Me({
89
90
  ).then((e) => e.data ?? []),
90
91
  enabled: P && !!r,
91
92
  staleTime: j ? 0 : 3e4
92
- }), V = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], v = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), U = X.filter((e) => !v.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 } = N({
93
+ }), B = (t == null ? void 0 : t.getStagedLinks(d)) ?? [], v = (t == null ? void 0 : t.getStagedUnlinks(d)) ?? /* @__PURE__ */ new Set(), U = X.filter((e) => !v.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({
93
94
  queryKey: ["m2m-avail", r, _.join(","), j],
94
95
  queryFn: () => b.request(
95
96
  C(`/items/${r}`, {
@@ -101,7 +102,7 @@ function Me({
101
102
  ).then((e) => e.data ?? []),
102
103
  enabled: !!r && _.length > 0,
103
104
  staleTime: 3e4
104
- }), 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([...p, ...I]), F = me(J);
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);
105
106
  F.current = J, ue(() => {
106
107
  var e;
107
108
  (e = F.current) == null || e.call(F, A.size);
@@ -120,7 +121,7 @@ function Me({
120
121
  t == null || t.stageLink(d, e);
121
122
  }
122
123
  function k(e) {
123
- const i = (o == null ? void 0 : o.display_template) ?? null;
124
+ const i = (a == null ? void 0 : a.display_template) ?? null;
124
125
  return i ? qe(i, e) : String(e._display ?? e.id ?? "");
125
126
  }
126
127
  return K ? /* @__PURE__ */ c(
@@ -193,7 +194,7 @@ function Me({
193
194
  {
194
195
  collection: r,
195
196
  id: i,
196
- displayTemplate: o == null ? void 0 : o.display_template
197
+ displayTemplate: a == null ? void 0 : a.display_template
197
198
  }
198
199
  )
199
200
  }
@@ -202,7 +203,7 @@ function Me({
202
203
  {
203
204
  collection: r,
204
205
  id: i,
205
- displayTemplate: o == null ? void 0 : o.display_template
206
+ displayTemplate: a == null ? void 0 : a.display_template
206
207
  }
207
208
  )),
208
209
  /* @__PURE__ */ n(
@@ -219,7 +220,7 @@ function Me({
219
220
  String(e.id)
220
221
  );
221
222
  }),
222
- V.map((e) => /* @__PURE__ */ c(
223
+ B.map((e) => /* @__PURE__ */ c(
223
224
  "span",
224
225
  {
225
226
  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",
@@ -229,7 +230,7 @@ function Me({
229
230
  {
230
231
  collection: r,
231
232
  id: e,
232
- displayTemplate: o == null ? void 0 : o.display_template
233
+ displayTemplate: a == null ? void 0 : a.display_template
233
234
  }
234
235
  ) : String(e),
235
236
  /* @__PURE__ */ n(
@@ -263,13 +264,13 @@ function Me({
263
264
  }
264
265
  ),
265
266
  /* @__PURE__ */ c(ve, { children: [
266
- 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" }),
267
- /* @__PURE__ */ n(Ne, { children: !B && (g ? [...O] : [...O].sort(
267
+ 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" }),
268
+ /* @__PURE__ */ n(we, { children: !V && (g ? [...O] : [...O].sort(
268
269
  (e, i) => y === "-label" ? k(i).localeCompare(k(e)) : k(e).localeCompare(k(i))
269
270
  )).map((e) => {
270
271
  const i = String(e.id), u = A.has(i);
271
272
  return /* @__PURE__ */ c(
272
- we,
273
+ Ne,
273
274
  {
274
275
  value: i,
275
276
  onSelect: () => G(e.id),
@@ -312,41 +313,41 @@ function Me({
312
313
  }
313
314
  ) });
314
315
  }
315
- function et({
316
+ function nt({
316
317
  relation: s,
317
- parentId: a,
318
- allRelations: w,
318
+ parentId: o,
319
+ allRelations: N,
319
320
  extraFilter: h,
320
321
  optionSort: y,
321
322
  requiredParent: K,
322
323
  onCountChange: J,
323
324
  readOnly: D
324
325
  }) {
325
- const b = fe(), W = Ie(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = w.find(
326
+ const b = fe(), W = Ae(), t = Le(), [P, q] = ne(!1), [L, T] = ne(""), le = N.find(
326
327
  (l) => l.many_collection === s.many_collection && l.many_field === s.junction_field && l.id !== s.id
327
- ), r = Te(le), x = s.junction_field ?? "", z = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: o } = N({
328
+ ), r = Te(le), x = s.junction_field ?? "", z = s.many_field ?? "", d = s.one_field ?? `${s.many_collection}.${x}`, { data: a } = w({
328
329
  queryKey: ["col-meta", r],
329
330
  queryFn: () => b.request(C(`/collections/${r}`)).then((l) => l.data),
330
331
  enabled: !!r,
331
332
  staleTime: 3e5,
332
333
  retry: !1
333
- }), { data: X = [], isFetching: re } = N({
334
- queryKey: ["m2m-items", s.many_collection, z, a],
334
+ }), { data: X = [], isFetching: re } = w({
335
+ queryKey: ["m2m-items", s.many_collection, z, o],
335
336
  queryFn: () => b.request(
336
337
  C(`/items/${s.many_collection}`, {
337
- filter: JSON.stringify({ [z]: { _eq: a } }),
338
+ filter: JSON.stringify({ [z]: { _eq: o } }),
338
339
  limit: 1,
339
340
  fields: `id,${x}`
340
341
  })
341
342
  ).then((l) => l.data ?? []),
342
343
  staleTime: 3e4,
343
- enabled: !!a && a !== "new"
344
+ enabled: !!o && o !== "new"
344
345
  }), E = pe().isAdmin, R = r === "nivaro_users" ? ye(E) : null, H = he(r === "nivaro_users"), j = h ? R ? { _and: [h, R] } : h : R, g = j ? JSON.stringify(j) : void 0, S = y && !/^-?label$/.test(y) ? y : void 0, O = (() => {
345
- const l = o == null ? void 0 : o.display_template;
346
+ const l = a == null ? void 0 : a.display_template;
346
347
  if (!l || !l.includes(".")) return null;
347
348
  const f = [...l.matchAll(/\{\{([^}]+)\}\}/g)].map((ee) => ee[1].trim());
348
349
  return f.length === 0 ? null : ["id", ...f].join(",");
349
- })(), { data: B = [], isFetching: V } = N({
350
+ })(), { data: V = [], isFetching: B } = w({
350
351
  queryKey: [
351
352
  "m2m-options",
352
353
  r,
@@ -374,12 +375,12 @@ function et({
374
375
  var l;
375
376
  (l = $.current) == null || l.call($, m != null ? 1 : 0);
376
377
  }, [m]);
377
- const { data: I } = N({
378
+ const { data: I } = w({
378
379
  queryKey: ["relation-single", r, String(m)],
379
380
  queryFn: () => W(r, m),
380
381
  enabled: !!r && m != null,
381
382
  staleTime: 6e4
382
- }), A = JSON.stringify(h ? { _and: [{ id: { _eq: m } }, h] } : { id: { _eq: m } }), { data: F } = N({
383
+ }), A = JSON.stringify(h ? { _and: [{ id: { _eq: m } }, h] } : { id: { _eq: m } }), { data: F } = w({
383
384
  queryKey: ["relation-avail", r, String(m), g],
384
385
  queryFn: () => b.request(
385
386
  C(`/items/${r}`, {
@@ -391,11 +392,11 @@ function et({
391
392
  ).then((l) => l.data ?? []),
392
393
  enabled: !!r && m != null && !!I,
393
394
  staleTime: 3e4
394
- }), G = F !== void 0 && F.length === 0, k = Ae(G), e = (o == null ? void 0 : o.display_template) ?? null;
395
+ }), G = F !== void 0 && F.length === 0, k = Ke(G), e = (a == null ? void 0 : a.display_template) ?? null;
395
396
  function i(l) {
396
397
  return e ? qe(e, l) : String(l.name ?? l.title ?? l.label ?? l.id ?? "");
397
398
  }
398
- const u = B.find((l) => String(l.id) === String(m)) ?? I, M = m != null && !I && !u, se = u ? i(u) : null;
399
+ const u = V.find((l) => String(l.id) === String(m)) ?? I, M = m != null && !I && !u, se = u ? i(u) : null;
399
400
  if (D)
400
401
  return /* @__PURE__ */ n("span", { className: "block truncate text-[12px] text-slate-700 dark:text-slate-200", children: M ? "…" : se ?? "—" });
401
402
  function Oe(l) {
@@ -439,7 +440,7 @@ function et({
439
440
  G ? "border-amber-300 dark:border-amber-600" : Z ? "border-nvr-cyan/50" : "border-input"
440
441
  ),
441
442
  children: [
442
- M || re && Y == null && a !== "new" ? /* @__PURE__ */ n(ae, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ c(
443
+ M || re && Y == null && o !== "new" ? /* @__PURE__ */ n(ae, { className: "h-3.5 w-3.5 animate-spin text-muted-foreground" }) : /* @__PURE__ */ c(
443
444
  "span",
444
445
  {
445
446
  className: Q(
@@ -481,13 +482,13 @@ function et({
481
482
  }
482
483
  ),
483
484
  /* @__PURE__ */ c(ve, { children: [
484
- 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" }),
485
- !V && /* @__PURE__ */ n(Ne, { children: [...B].sort(
485
+ 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" }),
486
+ !B && /* @__PURE__ */ n(we, { children: [...V].sort(
486
487
  (l, f) => S ? 0 : y === "-label" ? i(f).localeCompare(i(l)) : i(l).localeCompare(i(f))
487
488
  ).map((l) => {
488
489
  const f = String(l.id), ee = String(m) === f;
489
490
  return /* @__PURE__ */ c(
490
- we,
491
+ Ne,
491
492
  {
492
493
  value: f,
493
494
  onSelect: () => Oe(l.id),
@@ -533,8 +534,8 @@ function et({
533
534
  ] });
534
535
  }
535
536
  export {
536
- Me as M2MCombobox,
537
- et as M2MSingleSelectCombobox,
538
- Ze as m2aWriteMeta,
537
+ tt as M2MCombobox,
538
+ nt as M2MSingleSelectCombobox,
539
+ et as m2aWriteMeta,
539
540
  Te as resolveM2MRelatedCollection
540
541
  };
@@ -0,0 +1,15 @@
1
+ function n(t) {
2
+ if (t == null || t === "") return [];
3
+ if (Array.isArray(t)) return t.map((r) => String(r).trim()).filter(Boolean);
4
+ const i = String(t).trim();
5
+ if (i.startsWith("["))
6
+ try {
7
+ const r = JSON.parse(i);
8
+ if (Array.isArray(r)) return r.map((e) => String(e).trim()).filter(Boolean);
9
+ } catch {
10
+ }
11
+ return i.split(",").map((r) => r.trim()).filter(Boolean);
12
+ }
13
+ export {
14
+ n as parseAllowedCollections
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",