@nivaro/react 0.3.97 → 0.3.99

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +1,53 @@
1
1
  import { jsx as l, jsxs as f } from "react/jsx-runtime";
2
- import { useQueryClient as X, useQuery as R } from "@tanstack/react-query";
3
- import { Wrench as Y, ShieldAlert as Z, Loader2 as U } from "lucide-react";
4
- import { useState as w, useMemo as A } from "react";
5
- import { toast as F } from "sonner";
6
- import { useNivaroClient as I } from "../../context.js";
7
- import { get as $, patch as ee, del as te, post as ne } from "../../lib/commands.js";
8
- import { titleCase as Q } from "../../lib/utils.js";
9
- import { Button as T } from "../ui/button.js";
10
- import { Sheet as ae, SheetContent as re, SheetHeader as se, SheetTitle as ie } from "../ui/sheet.js";
11
- import { ChangeReasonDialog as le, changeReasonChallenge as oe } from "./ChangeReasonDialog.js";
12
- import { FieldRenderer as ce } from "./FieldRenderer.js";
13
- import { M2MCombobox as de, m2aAllowedCount as me, m2aWriteMeta as fe } from "./M2MCombobox.js";
14
- import { M2MStagingContext as ue } from "./M2MStagingContext.js";
2
+ import { useQueryClient as Y, useQuery as U } from "@tanstack/react-query";
3
+ import { Wrench as Z, ShieldAlert as I, Loader2 as F } from "lucide-react";
4
+ import { useState as w, useMemo as P } from "react";
5
+ import { toast as Q } from "sonner";
6
+ import { useNivaroClient as ee } from "../../context.js";
7
+ import { get as $, patch as te, del as ne, post as ae } from "../../lib/commands.js";
8
+ import { titleCase as T } from "../../lib/utils.js";
9
+ import { Button as W } from "../ui/button.js";
10
+ import { Sheet as re, SheetContent as ie, SheetHeader as se, SheetTitle as le } from "../ui/sheet.js";
11
+ import { ChangeReasonDialog as oe, changeReasonChallenge as ce } from "./ChangeReasonDialog.js";
12
+ import { FieldRenderer as de } from "./FieldRenderer.js";
13
+ import { M2MCombobox as me, m2aAllowedCount as fe, m2aWriteMeta as ue } from "./M2MCombobox.js";
14
+ import { M2MStagingContext as D } from "./M2MStagingContext.js";
15
15
  import { invalidateM2MFor as pe } from "./m2m-invalidate.js";
16
- function W(s, i) {
16
+ import { RawM2ALinks as he } from "./RawM2ALinks.js";
17
+ function E(i, s) {
17
18
  const u = (p) => p == null || p === "";
18
- return u(s) && u(i) ? !0 : typeof s == "number" || typeof i == "number" ? Number(s) === Number(i) : typeof s == "boolean" || typeof i == "boolean" ? String(s) === String(i) : typeof s == "object" || typeof i == "object" ? JSON.stringify(s) === JSON.stringify(i) : String(s) === String(i);
19
+ return u(i) && u(s) ? !0 : typeof i == "number" || typeof s == "number" ? Number(i) === Number(s) : typeof i == "boolean" || typeof s == "boolean" ? String(i) === String(s) : typeof i == "object" || typeof s == "object" ? JSON.stringify(i) === JSON.stringify(s) : String(i) === String(s);
19
20
  }
20
- function E(s) {
21
- if (s == null || s === "") return "∅";
22
- const i = typeof s == "object" ? JSON.stringify(s) : String(s);
23
- return i.length > 60 ? `${i.slice(0, 57)}…` : i;
21
+ function J(i) {
22
+ if (i == null || i === "") return "∅";
23
+ const s = typeof i == "object" ? JSON.stringify(i) : String(i);
24
+ return s.length > 60 ? `${s.slice(0, 57)}…` : s;
24
25
  }
25
- function $e({
26
- collection: s,
27
- itemId: i,
26
+ function Oe({
27
+ collection: i,
28
+ itemId: s,
28
29
  open: u,
29
30
  onClose: p,
30
31
  onSaved: S
31
32
  }) {
32
- const h = I(), M = X(), [m, j] = w({}), [g, v] = w(/* @__PURE__ */ new Map()), [x, k] = w(/* @__PURE__ */ new Map()), [N, L] = w(!1), [J, q] = w(null), { data: c } = R({
33
- queryKey: ["raw-edit-config", s],
33
+ const h = ee(), M = Y(), [m, j] = w({}), [g, v] = w(/* @__PURE__ */ new Map()), [y, _] = w(/* @__PURE__ */ new Map()), [k, L] = w(!1), [B, q] = w(null), { data: c } = U({
34
+ queryKey: ["raw-edit-config", i],
34
35
  queryFn: async () => {
35
36
  const [e, n] = await Promise.all([
36
- h.request($(`/field-config/${s}`)).then((r) => r.data ?? []),
37
- h.request($(`/collections/${s}`)).then((r) => r.data)
37
+ h.request($(`/field-config/${i}`)).then((r) => r.data ?? []),
38
+ h.request($(`/collections/${i}`)).then((r) => r.data)
38
39
  ]);
39
40
  return { fields: e, relations: n.relations ?? [] };
40
41
  },
41
42
  enabled: u,
42
43
  staleTime: 6e4
43
- }), { data: o, isLoading: P } = R({
44
- queryKey: ["raw-edit-record", s, i],
45
- queryFn: () => h.request($(`/items/${s}/${i}`)).then((e) => e.data),
44
+ }), { data: o, isLoading: H } = U({
45
+ queryKey: ["raw-edit-record", i, s],
46
+ queryFn: () => h.request($(`/items/${i}/${s}`)).then((e) => e.data),
46
47
  enabled: u,
47
48
  staleTime: 0
48
- }), D = A(() => {
49
- const e = (c == null ? void 0 : c.fields) ?? [], n = (c == null ? void 0 : c.relations) ?? [], r = (t) => n.some((a) => a.one_collection === s && a.one_field === t.field);
49
+ }), G = P(() => {
50
+ const e = (c == null ? void 0 : c.fields) ?? [], n = (c == null ? void 0 : c.relations) ?? [], r = (t) => n.some((a) => a.one_collection === i && a.one_field === t.field);
50
51
  return e.filter((t) => !t.field.startsWith("__")).map((t) => ({
51
52
  // Strip every conditional/curation config — raw mode ignores them all
52
53
  field: {
@@ -59,20 +60,20 @@ function $e({
59
60
  },
60
61
  alias: r(t),
61
62
  m2mRel: n.find(
62
- (a) => a.one_collection === s && a.one_field === t.field && a.junction_field != null
63
+ (a) => a.one_collection === i && a.one_field === t.field && a.junction_field != null
63
64
  )
64
65
  })).sort((t, a) => (t.field.sort ?? 0) - (a.field.sort ?? 0));
65
- }, [c, s]), _ = (c == null ? void 0 : c.relations) ?? [], O = (e) => _.find(
66
- (n) => n.one_collection === s && n.one_field === e && n.junction_field != null
67
- ), B = (e) => {
68
- const n = _.find(
66
+ }, [c, i]), N = (c == null ? void 0 : c.relations) ?? [], O = (e) => N.find(
67
+ (n) => n.one_collection === i && n.one_field === e && n.junction_field != null
68
+ ), z = (e) => {
69
+ const n = N.find(
69
70
  (r) => r.many_collection === e.many_collection && r.many_field === e.junction_field && r.id !== e.id
70
71
  );
71
- return !n || n.one_collection ? !1 : me(n) > 1;
72
- }, H = A(
72
+ return !n || n.one_collection || fe(n) < 2 ? null : n.one_collection_field || "collection";
73
+ }, A = P(
73
74
  () => ({
74
75
  getStagedLinks: (e) => g.get(e) ?? [],
75
- getStagedUnlinks: (e) => x.get(e) ?? /* @__PURE__ */ new Set(),
76
+ getStagedUnlinks: (e) => y.get(e) ?? /* @__PURE__ */ new Set(),
76
77
  stageLink: (e, n) => v((r) => {
77
78
  const t = new Map(r);
78
79
  return t.set(e, [...t.get(e) ?? [], n]), t;
@@ -84,91 +85,91 @@ function $e({
84
85
  (t.get(e) ?? []).filter((a) => String(a) !== String(n))
85
86
  ), t;
86
87
  }),
87
- stageUnlink: (e, n) => k((r) => {
88
+ stageUnlink: (e, n) => _((r) => {
88
89
  const t = new Map(r), a = new Set(t.get(e) ?? []);
89
90
  return a.add(n), t.set(e, a), t;
90
91
  }),
91
- unstageUnlink: (e, n) => k((r) => {
92
+ unstageUnlink: (e, n) => _((r) => {
92
93
  const t = new Map(r), a = new Set(t.get(e) ?? []);
93
94
  return a.delete(n), t.set(e, a), t;
94
95
  })
95
96
  }),
96
- [g, x]
97
- ), G = [...g.values()].some((e) => e.length > 0) || [...x.values()].some((e) => e.size > 0), z = Object.keys(m).length > 0 || G, K = async (e) => {
97
+ [g, y]
98
+ ), V = [...g.values()].some((e) => e.length > 0) || [...y.values()].some((e) => e.size > 0), K = Object.keys(m).length > 0 || V, R = async (e) => {
98
99
  var n;
99
100
  L(!0);
100
101
  try {
101
102
  if (Object.keys(m).length > 0) {
102
103
  const t = { ...m };
103
- e && (t._change_reason = e), await h.request(ee(`/items/${s}/${i}`, t));
104
+ e && (t._change_reason = e), await h.request(te(`/items/${i}/${s}`, t));
104
105
  }
105
106
  const r = [];
106
- for (const [t, a] of x.entries()) {
107
+ for (const [t, a] of y.entries()) {
107
108
  if (!a.size) continue;
108
109
  const d = O(t);
109
110
  if (d)
110
- for (const y of a)
111
- r.push(h.request(te(`/items/${d.many_collection}/${y}`)).catch(() => {
111
+ for (const x of a)
112
+ r.push(h.request(ne(`/items/${d.many_collection}/${x}`)).catch(() => {
112
113
  }));
113
114
  }
114
115
  for (const [t, a] of g.entries()) {
115
116
  if (!a.length) continue;
116
117
  const d = O(t);
117
118
  if (!d) continue;
118
- const y = _.find(
119
+ const x = N.find(
119
120
  (b) => b.many_collection === d.many_collection && b.many_field === d.junction_field && b.id !== d.id
120
- ), C = fe(y), V = C ? { [C.field]: C.value } : {};
121
+ ), C = ue(x), X = C ? { [C.field]: C.value } : {};
121
122
  for (const b of a)
122
123
  r.push(
123
124
  h.request(
124
- ne(`/items/${d.many_collection}`, {
125
- [d.many_field ?? ""]: i,
125
+ ae(`/items/${d.many_collection}`, {
126
+ [d.many_field ?? ""]: s,
126
127
  [d.junction_field ?? ""]: b,
127
- ...V
128
+ ...X
128
129
  })
129
130
  ).catch(() => {
130
131
  })
131
132
  );
132
133
  }
133
- await Promise.all(r), F.success("Raw changes saved"), j({}), v(/* @__PURE__ */ new Map()), k(/* @__PURE__ */ new Map()), M.invalidateQueries({ queryKey: ["item", s, String(i)] }), M.invalidateQueries({ queryKey: ["raw-edit-record", s, i] }), pe(M, [i]), S == null || S(), p();
134
+ await Promise.all(r), Q.success("Raw changes saved"), j({}), v(/* @__PURE__ */ new Map()), _(/* @__PURE__ */ new Map()), M.invalidateQueries({ queryKey: ["item", i, String(s)] }), M.invalidateQueries({ queryKey: ["raw-edit-record", i, s] }), pe(M, [s]), S == null || S(), p();
134
135
  } catch (r) {
135
- const t = oe(r);
136
+ const t = ce(r);
136
137
  if (t) {
137
138
  q(t);
138
139
  return;
139
140
  }
140
141
  const a = r == null ? void 0 : r.response;
141
- F.error(((n = a == null ? void 0 : a.data) == null ? void 0 : n.error) ?? (a == null ? void 0 : a.error) ?? "Save failed");
142
+ Q.error(((n = a == null ? void 0 : a.data) == null ? void 0 : n.error) ?? (a == null ? void 0 : a.error) ?? "Save failed");
142
143
  } finally {
143
144
  L(!1);
144
145
  }
145
146
  };
146
147
  return /* @__PURE__ */ l(
147
- ae,
148
+ re,
148
149
  {
149
150
  open: u,
150
151
  onOpenChange: (e) => {
151
- e || N || (j({}), v(/* @__PURE__ */ new Map()), k(/* @__PURE__ */ new Map()), p());
152
+ e || k || (j({}), v(/* @__PURE__ */ new Map()), _(/* @__PURE__ */ new Map()), p());
152
153
  },
153
154
  children: /* @__PURE__ */ f(
154
- re,
155
+ ie,
155
156
  {
156
157
  side: "right",
157
158
  className: "flex w-[1040px] max-w-[94vw] flex-col p-0 sm:max-w-[94vw]",
158
159
  children: [
159
- /* @__PURE__ */ l(se, { className: "shrink-0 border-b border-slate-200 px-5 py-3 dark:border-border", children: /* @__PURE__ */ f(ie, { className: "flex items-center gap-2 text-[14px]", children: [
160
- /* @__PURE__ */ l(Y, { className: "h-4 w-4 text-nvr-cyan" }),
160
+ /* @__PURE__ */ l(se, { className: "shrink-0 border-b border-slate-200 px-5 py-3 dark:border-border", children: /* @__PURE__ */ f(le, { className: "flex items-center gap-2 text-[14px]", children: [
161
+ /* @__PURE__ */ l(Z, { className: "h-4 w-4 text-nvr-cyan" }),
161
162
  "Raw edit — ",
162
- Q(s),
163
+ T(i),
163
164
  " #",
164
- i
165
+ s
165
166
  ] }) }),
166
167
  /* @__PURE__ */ f("p", { className: "flex shrink-0 items-center gap-2 border-b border-amber-200 bg-amber-50 px-5 py-2 text-[12px] text-amber-800 dark:border-amber-500/20 dark:bg-amber-500/10 dark:text-amber-300", children: [
167
- /* @__PURE__ */ l(Z, { className: "h-3.5 w-3.5 shrink-0" }),
168
+ /* @__PURE__ */ l(I, { className: "h-3.5 w-3.5 shrink-0" }),
168
169
  "Admin raw mode — visibility rules, locks, cascades and layout restrictions are bypassed. Server-side validation still applies. Every change is recorded in the revision history."
169
170
  ] }),
170
- /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: P || !c ? /* @__PURE__ */ l("div", { className: "flex justify-center py-10", children: /* @__PURE__ */ l(U, { className: "h-5 w-5 animate-spin text-slate-400" }) }) : /* @__PURE__ */ l("div", { className: "space-y-3", children: D.map(({ field: e, alias: n, m2mRel: r }) => {
171
- const t = e.field in m ? m[e.field] : o == null ? void 0 : o[e.field], a = e.field in m && !W(m[e.field], o == null ? void 0 : o[e.field]);
171
+ /* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children: H || !c ? /* @__PURE__ */ l("div", { className: "flex justify-center py-10", children: /* @__PURE__ */ l(F, { className: "h-5 w-5 animate-spin text-slate-400" }) }) : /* @__PURE__ */ l("div", { className: "space-y-3", children: G.map(({ field: e, alias: n, m2mRel: r }) => {
172
+ const t = e.field in m ? m[e.field] : o == null ? void 0 : o[e.field], a = e.field in m && !E(m[e.field], o == null ? void 0 : o[e.field]);
172
173
  return /* @__PURE__ */ f(
173
174
  "div",
174
175
  {
@@ -178,7 +179,7 @@ function $e({
178
179
  children: [
179
180
  /* @__PURE__ */ f("div", { className: "pt-1.5", children: [
180
181
  /* @__PURE__ */ f("p", { className: "text-[12px] font-medium text-slate-700 dark:text-slate-200", children: [
181
- e.label || Q(e.field),
182
+ e.label || T(e.field),
182
183
  a && /* @__PURE__ */ l("span", { className: "ml-1.5 rounded bg-amber-200/70 px-1 text-[9px] font-semibold uppercase tracking-wide text-amber-900 dark:bg-amber-500/20 dark:text-amber-200", children: "changed" })
183
184
  ] }),
184
185
  /* @__PURE__ */ l("p", { className: "font-mono text-[10.5px] text-slate-400", children: e.field }),
@@ -186,35 +187,36 @@ function $e({
186
187
  "p",
187
188
  {
188
189
  className: "mt-0.5 truncate text-[10.5px] text-slate-400",
189
- "data-tip": `Was: ${E(o == null ? void 0 : o[e.field])}`,
190
+ "data-tip": `Was: ${J(o == null ? void 0 : o[e.field])}`,
190
191
  children: [
191
192
  "was ",
192
- E(o == null ? void 0 : o[e.field])
193
+ J(o == null ? void 0 : o[e.field])
193
194
  ]
194
195
  }
195
196
  )
196
197
  ] }),
197
- e.field === "id" ? /* @__PURE__ */ l("p", { className: "pt-1.5 font-mono text-[12px] text-slate-500", children: String(t ?? "") }) : n && r && B(r) ? (
198
+ e.field === "id" ? /* @__PURE__ */ l("p", { className: "pt-1.5 font-mono text-[12px] text-slate-500", children: String(t ?? "") }) : n && r && z(r) ? (
198
199
  // A ship-to contact is a person OR an external email: the
199
- // picker here reads every link as a person, so an external
200
- // email showed "Record not found". The normal form edits it.
201
- /* @__PURE__ */ l(
202
- "p",
200
+ // plain picker read every link as a person, so an external
201
+ // email showed "Record not found". List each link as it is.
202
+ /* @__PURE__ */ l(D.Provider, { value: A, children: /* @__PURE__ */ l(
203
+ he,
203
204
  {
204
- className: "pt-1.5 text-[11.5px] italic text-slate-400",
205
- "data-raw-m2a": e.field,
206
- children: "Links to more than one kind of record — edit through the normal form"
205
+ collection: i,
206
+ itemId: s,
207
+ field: e.field,
208
+ discriminator: z(r)
207
209
  }
208
- )
209
- ) : n && r ? /* @__PURE__ */ l(ue.Provider, { value: H, children: /* @__PURE__ */ l(de, { relation: r, parentId: i, allRelations: _ }) }) : n ? /* @__PURE__ */ l("p", { className: "pt-1.5 text-[11.5px] italic text-slate-400", children: "Child rows (one-to-many) — edit through the normal form" }) : /* @__PURE__ */ l(
210
- ce,
210
+ ) })
211
+ ) : n && r ? /* @__PURE__ */ l(D.Provider, { value: A, children: /* @__PURE__ */ l(me, { relation: r, parentId: s, allRelations: N }) }) : n ? /* @__PURE__ */ l("p", { className: "pt-1.5 text-[11.5px] italic text-slate-400", children: "Child rows (one-to-many) — edit through the normal form" }) : /* @__PURE__ */ l(
212
+ de,
211
213
  {
212
214
  field: e,
213
215
  value: t,
214
- onChange: (d) => j((y) => ({ ...y, [e.field]: d })),
216
+ onChange: (d) => j((x) => ({ ...x, [e.field]: d })),
215
217
  relations: c.relations,
216
- collection: s,
217
- itemId: i
218
+ collection: i,
219
+ itemId: s
218
220
  }
219
221
  )
220
222
  ]
@@ -224,22 +226,22 @@ function $e({
224
226
  }) }) }),
225
227
  /* @__PURE__ */ f("div", { className: "flex shrink-0 items-center justify-between gap-3 border-t border-slate-200 px-5 py-3 dark:border-border", children: [
226
228
  /* @__PURE__ */ l("span", { className: "text-[11.5px] text-slate-400", children: (() => {
227
- if (!z) return "No changes yet";
228
- const e = Object.keys(m).filter((n) => !W(m[n], o == null ? void 0 : o[n])).length + [...g.values()].filter((n) => n.length > 0).length + [...x.values()].filter((n) => n.size > 0).length;
229
+ if (!K) return "No changes yet";
230
+ const e = Object.keys(m).filter((n) => !E(m[n], o == null ? void 0 : o[n])).length + [...g.values()].filter((n) => n.length > 0).length + [...y.values()].filter((n) => n.size > 0).length;
229
231
  return e === 0 ? "No changes yet" : `${e} field${e !== 1 ? "s" : ""} changed`;
230
232
  })() }),
231
233
  /* @__PURE__ */ f("div", { className: "flex gap-2", children: [
232
- /* @__PURE__ */ l(T, { variant: "outline", size: "sm", onClick: p, disabled: N, children: "Cancel" }),
233
- /* @__PURE__ */ l(T, { size: "sm", onClick: () => void K(), disabled: !z || N, children: N ? /* @__PURE__ */ l(U, { className: "h-3.5 w-3.5 animate-spin" }) : "Save raw changes" })
234
+ /* @__PURE__ */ l(W, { variant: "outline", size: "sm", onClick: p, disabled: k, children: "Cancel" }),
235
+ /* @__PURE__ */ l(W, { size: "sm", onClick: () => void R(), disabled: !K || k, children: k ? /* @__PURE__ */ l(F, { className: "h-3.5 w-3.5 animate-spin" }) : "Save raw changes" })
234
236
  ] })
235
237
  ] }),
236
238
  /* @__PURE__ */ l(
237
- le,
239
+ oe,
238
240
  {
239
- challenge: J,
241
+ challenge: B,
240
242
  onCancel: () => q(null),
241
243
  onSubmit: (e) => {
242
- q(null), K(e);
244
+ q(null), R(e);
243
245
  }
244
246
  }
245
247
  )
@@ -250,5 +252,5 @@ function $e({
250
252
  );
251
253
  }
252
254
  export {
253
- $e as RawEditSheet
255
+ Oe as RawEditSheet
254
256
  };
@@ -0,0 +1,101 @@
1
+ import { jsxs as d, jsx as t } from "react/jsx-runtime";
2
+ import { useQuery as k } from "@tanstack/react-query";
3
+ import { Loader2 as f, RotateCcw as b, X as N } from "lucide-react";
4
+ import { useNivaroClient as w } from "../../context.js";
5
+ import { get as v } from "../../lib/commands.js";
6
+ import { cn as y, titleCase as S } from "../../lib/utils.js";
7
+ import { useM2MStaging as C } from "./M2MStagingContext.js";
8
+ function L(e) {
9
+ const r = String(e ?? "").toLowerCase();
10
+ return r === "directus_users" || r === "nivaro_users" ? "Person" : r === "additional_emails" ? "External email" : r ? S(r.replace(/_/g, " ")) : "Record";
11
+ }
12
+ function _(e) {
13
+ if (!e) return { name: null, email: null };
14
+ const r = String(e.first_name ?? "").trim(), n = String(e.last_name ?? "").trim(), m = [r, n].filter(Boolean).join(" ") || typeof e.name == "string" && e.name.trim() || typeof e.label == "string" && e.label.trim() || null, c = typeof e.email == "string" && e.email.trim() ? e.email.trim() : null;
15
+ return { name: m, email: c };
16
+ }
17
+ function M({
18
+ collection: e,
19
+ itemId: r,
20
+ field: n,
21
+ discriminator: m
22
+ }) {
23
+ const c = w(), s = C(), p = k({
24
+ queryKey: ["raw-edit-m2a", e, String(r), n],
25
+ queryFn: () => c.request(
26
+ v(`/items/${e}/${encodeURIComponent(String(r))}`, {
27
+ fields: `id,${n}.*`
28
+ })
29
+ ).then((a) => {
30
+ var i;
31
+ const l = (i = a.data) == null ? void 0 : i[n];
32
+ return Array.isArray(l) ? l : [];
33
+ }),
34
+ staleTime: 15e3
35
+ }), h = (s == null ? void 0 : s.getStagedUnlinks(n)) ?? /* @__PURE__ */ new Set();
36
+ if (p.isLoading)
37
+ return /* @__PURE__ */ d("p", { className: "flex items-center gap-1.5 pt-1.5 text-[11.5px] text-slate-400", children: [
38
+ /* @__PURE__ */ t(f, { className: "h-3 w-3 animate-spin", "aria-hidden": !0 }),
39
+ " Loading links…"
40
+ ] });
41
+ if (p.error)
42
+ return /* @__PURE__ */ t("p", { className: "pt-1.5 text-[11.5px] text-red-600 dark:text-red-400", children: "Couldn’t load the links." });
43
+ const u = p.data ?? [];
44
+ return /* @__PURE__ */ d("div", { className: "space-y-1.5", "data-raw-m2a": n, children: [
45
+ u.length === 0 ? /* @__PURE__ */ t("p", { className: "pt-1.5 text-[11.5px] italic text-slate-400", children: "No links" }) : /* @__PURE__ */ t("ul", { className: "flex flex-wrap gap-1.5", children: u.map((a) => {
46
+ const l = [...h].some((g) => String(g) === String(a.id)), { name: i, email: o } = _(a.item), x = L(a[m]);
47
+ return /* @__PURE__ */ d(
48
+ "li",
49
+ {
50
+ "data-raw-m2a-link": String(a.id),
51
+ className: y(
52
+ "inline-flex max-w-full items-center gap-2 rounded-md border px-2 py-1 text-[12px]",
53
+ l ? "border-dashed border-red-300 bg-red-50/60 text-slate-400 line-through dark:border-red-500/40 dark:bg-red-500/10" : "border-slate-200 bg-white text-slate-800 dark:border-border dark:bg-card dark:text-foreground"
54
+ ),
55
+ children: [
56
+ /* @__PURE__ */ t("span", { className: "shrink-0 rounded bg-slate-100 px-1.5 text-[10px] font-medium uppercase tracking-wide text-slate-500 no-underline dark:bg-muted dark:text-muted-foreground", children: x }),
57
+ a.item ? /* @__PURE__ */ d("span", { className: "min-w-0 truncate", children: [
58
+ i && /* @__PURE__ */ t("span", { className: "font-medium", children: i }),
59
+ i && o && /* @__PURE__ */ t("span", { className: "text-slate-400", children: " · " }),
60
+ o && /* @__PURE__ */ t("span", { className: "font-mono text-[11.5px]", children: o }),
61
+ !i && !o && /* @__PURE__ */ t("span", { className: "italic text-slate-400", children: "No name or email" })
62
+ ] }) : /* @__PURE__ */ d("span", { className: "italic text-slate-400", children: [
63
+ x,
64
+ " #",
65
+ String(a.item_id ?? ""),
66
+ " is gone or hidden from you"
67
+ ] }),
68
+ s && (l ? /* @__PURE__ */ t(
69
+ "button",
70
+ {
71
+ type: "button",
72
+ "aria-label": "Keep this link",
73
+ "data-tip": "Keep this link",
74
+ onClick: () => s.unstageUnlink(n, a.id),
75
+ className: "rounded p-0.5 text-slate-400 hover:bg-slate-100 hover:text-slate-700 dark:hover:bg-muted",
76
+ children: /* @__PURE__ */ t(b, { className: "h-3 w-3" })
77
+ }
78
+ ) : /* @__PURE__ */ t(
79
+ "button",
80
+ {
81
+ type: "button",
82
+ "aria-label": `Remove ${i ?? o ?? "this link"}`,
83
+ "data-tip": "Remove this link (saved with Save)",
84
+ onClick: () => s.stageUnlink(n, a.id),
85
+ className: "rounded p-0.5 text-slate-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-500/10",
86
+ children: /* @__PURE__ */ t(N, { className: "h-3 w-3" })
87
+ }
88
+ ))
89
+ ]
90
+ },
91
+ String(a.id)
92
+ );
93
+ }) }),
94
+ /* @__PURE__ */ t("p", { className: "text-[10.5px] text-slate-400", children: "Links to a person or an external email. Add one through the normal form." })
95
+ ] });
96
+ }
97
+ export {
98
+ M as RawM2ALinks,
99
+ L as m2aKindLabel,
100
+ _ as m2aLinkText
101
+ };
@@ -1,86 +1,101 @@
1
- import { m2aWriteMeta as x } from "./M2MCombobox.js";
2
- function F(n, l, s) {
3
- var r;
4
- let e = l.find((o) => o.one_collection === n && o.one_field === s);
5
- if (!e && s.includes(".")) {
6
- const o = s.slice(0, s.indexOf("."));
7
- e = l.find(
8
- (i) => i.one_collection === n && i.many_collection === o && !!i.one_field
1
+ import { m2aWriteMeta as x, parseM2aToken as E } from "./M2MCombobox.js";
2
+ function L(n, r, a) {
3
+ var _;
4
+ let e = r.find((t) => t.one_collection === n && t.one_field === a);
5
+ if (!e && a.includes(".")) {
6
+ const t = a.slice(0, a.indexOf("."));
7
+ e = r.find(
8
+ (i) => i.one_collection === n && i.many_collection === t && !!i.one_field
9
9
  );
10
10
  }
11
11
  if (!(e != null && e.one_field) || !e.many_collection) return null;
12
- const c = e.junction_field ?? ((r = l.find((o) => o.many_collection === e.many_collection && o.id !== e.id)) == null ? void 0 : r.many_field) ?? null;
13
- if (!c) return null;
14
- const d = l.find(
15
- (o) => o.many_collection === e.many_collection && o.many_field === c && o.id !== e.id
16
- ), _ = x(d);
17
- return { field: e.one_field, junctionField: c, m2aCollection: (_ == null ? void 0 : _.value) ?? null };
12
+ const s = e.junction_field ?? ((_ = r.find((t) => t.many_collection === e.many_collection && t.id !== e.id)) == null ? void 0 : _.many_field) ?? null;
13
+ if (!s) return null;
14
+ const u = r.find(
15
+ (t) => t.many_collection === e.many_collection && t.many_field === s && t.id !== e.id
16
+ ), d = x(u);
17
+ return {
18
+ field: e.one_field,
19
+ junctionField: s,
20
+ m2aCollection: (d == null ? void 0 : d.value) ?? null,
21
+ m2aField: (d == null ? void 0 : d.field) ?? null
22
+ };
18
23
  }
19
- function L(n) {
24
+ function O(n) {
20
25
  return n == null || n === "" ? [] : Array.isArray(n) ? n : typeof n == "object" ? [] : [n];
21
26
  }
22
- const C = (n) => n && typeof n == "object" ? `${String(n.collection ?? "").toLowerCase()}:${String(n.id ?? "").toLowerCase()}` : `:${String(n).toLowerCase()}`;
23
- function A(n) {
27
+ const F = (n) => n && typeof n == "object" ? `${String(n.collection ?? "").toLowerCase()}:${String(n.id ?? "").toLowerCase()}` : `:${String(n).toLowerCase()}`;
28
+ function M(n) {
24
29
  var i;
25
- const { collection: l, relations: s, links: e, unlinks: c, payload: d, isNew: _ } = n, r = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set([...e.keys(), ...c.keys()]);
26
- for (const f of o) {
27
- const g = e.get(f) ?? [], y = c.get(f) ?? /* @__PURE__ */ new Set();
30
+ const { collection: r, relations: a, links: e, unlinks: s, payload: u, isNew: d } = n, _ = /* @__PURE__ */ new Set(), t = /* @__PURE__ */ new Set([...e.keys(), ...s.keys()]);
31
+ for (const m of t) {
32
+ const g = e.get(m) ?? [], y = s.get(m) ?? /* @__PURE__ */ new Set();
28
33
  if (g.length === 0 && y.size === 0) continue;
29
- const u = F(l, s, f);
30
- if (!u) continue;
31
- const p = (t) => u.m2aCollection ? { collection: u.m2aCollection, id: t } : t;
32
- if (_) {
34
+ const f = L(r, a, m);
35
+ if (!f) continue;
36
+ const k = (o) => {
37
+ if (!f.m2aCollection) return o;
38
+ const l = E(o);
39
+ return l ? { collection: l.collection, id: l.id } : { collection: f.m2aCollection, id: o };
40
+ }, C = (o) => {
41
+ const l = o[f.junctionField];
42
+ if (l == null) return null;
43
+ if (!f.m2aCollection) return l;
44
+ const c = f.m2aField ? o[f.m2aField] : null;
45
+ return typeof c == "string" && c ? { collection: c, id: l } : null;
46
+ };
47
+ if (d) {
33
48
  if (y.size > 0) continue;
34
- const t = [], m = /* @__PURE__ */ new Set();
35
- for (const a of [...L(d[u.field]), ...g.map(p)]) {
36
- const S = C(a);
37
- m.has(S) || (m.add(S), t.push(a));
49
+ const o = [], l = /* @__PURE__ */ new Set();
50
+ for (const c of [...O(u[f.field]), ...g.map(k)]) {
51
+ const w = F(c);
52
+ l.has(w) || (l.add(w), o.push(c));
38
53
  }
39
- d[u.field] = t, r.add(f);
54
+ u[f.field] = o, _.add(m);
40
55
  continue;
41
56
  }
42
- const w = (i = n.committed) == null ? void 0 : i.call(n, f);
43
- let h = [];
57
+ const S = (i = n.committed) == null ? void 0 : i.call(n, m);
58
+ let p = [];
44
59
  if (y.size > 0) {
45
- if (!w) continue;
46
- const t = new Map(w.map((a) => [String(a.id), a])), m = [...y].map((a) => {
47
- var S;
48
- return (S = t.get(String(a))) == null ? void 0 : S[u.junctionField];
60
+ if (!S) continue;
61
+ const o = new Map(S.map((c) => [String(c.id), c])), l = [...y].map((c) => {
62
+ const w = o.get(String(c));
63
+ return w ? C(w) : null;
49
64
  });
50
- if (m.some((a) => a == null)) continue;
51
- h = m.map(p);
65
+ if (l.some((c) => c == null)) continue;
66
+ p = l;
52
67
  }
53
- const b = (w ?? []).filter((t) => !y.has(t.id) && !y.has(String(t.id))).map((t) => t[u.junctionField]).filter((t) => t != null), k = [], j = /* @__PURE__ */ new Set();
54
- for (const t of [...b.map(p), ...g.map(p)]) {
55
- const m = C(t);
56
- j.has(m) || (j.add(m), k.push(t));
68
+ const b = (S ?? []).filter((o) => !y.has(o.id) && !y.has(String(o.id))).map(C).filter((o) => o != null), h = [], j = /* @__PURE__ */ new Set();
69
+ for (const o of [...b, ...g.map(k)]) {
70
+ const l = F(o);
71
+ j.has(l) || (j.add(l), h.push(o));
57
72
  }
58
- d[u.field] = {
59
- ...k.length ? { create: k } : {},
60
- ...h.length ? { delete: h } : {}
61
- }, r.add(f);
73
+ u[f.field] = {
74
+ ...h.length ? { create: h } : {},
75
+ ...p.length ? { delete: p } : {}
76
+ }, _.add(m);
62
77
  }
63
- return r;
78
+ return _;
64
79
  }
65
- const O = 500;
66
- function E(n) {
67
- var s;
68
- const l = /* @__PURE__ */ new Set();
69
- for (const [e, c] of n.rows) {
70
- if (c.length === 0 || (s = n.skip) != null && s.has(e)) continue;
71
- const d = e.indexOf(".");
72
- if (d < 0) continue;
73
- const _ = e.slice(0, d), r = e.slice(d + 1), o = n.relations.find(
74
- (i) => i.one_collection === n.collection && i.many_collection === _ && i.many_field === r && !!i.one_field && i.junction_field == null
80
+ const z = 500;
81
+ function W(n) {
82
+ var a;
83
+ const r = /* @__PURE__ */ new Set();
84
+ for (const [e, s] of n.rows) {
85
+ if (s.length === 0 || (a = n.skip) != null && a.has(e)) continue;
86
+ const u = e.indexOf(".");
87
+ if (u < 0) continue;
88
+ const d = e.slice(0, u), _ = e.slice(u + 1), t = n.relations.find(
89
+ (i) => i.one_collection === n.collection && i.many_collection === d && i.many_field === _ && !!i.one_field && i.junction_field == null
75
90
  );
76
- o != null && o.one_field && (c.length > O || c.some((i) => Object.keys(i).some((f) => f.startsWith("__o2m_"))) || (n.payload[o.one_field] = c.map((i) => {
77
- const { id: f, ...g } = i;
91
+ t != null && t.one_field && (s.length > z || s.some((i) => Object.keys(i).some((m) => m.startsWith("__o2m_"))) || (n.payload[t.one_field] = s.map((i) => {
92
+ const { id: m, ...g } = i;
78
93
  return g;
79
- }), l.add(e)));
94
+ }), r.add(e)));
80
95
  }
81
- return l;
96
+ return r;
82
97
  }
83
98
  export {
84
- A as foldStagedLinks,
85
- E as foldStagedRows
99
+ M as foldStagedLinks,
100
+ W as foldStagedRows
86
101
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.3.97",
3
+ "version": "0.3.99",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",