@nivaro/react 0.3.97 → 0.3.98
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.
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/shared/components/ItemEditForm.js +1023 -1014
- package/dist/shared/components/item-edit/M2MCombobox.js +489 -332
- package/dist/shared/components/item-edit/RawEditSheet.js +92 -90
- package/dist/shared/components/item-edit/RawM2ALinks.js +101 -0
- package/dist/shared/components/item-edit/staged-links.js +77 -62
- package/package.json +1 -1
|
@@ -1,52 +1,53 @@
|
|
|
1
1
|
import { jsx as l, jsxs as f } from "react/jsx-runtime";
|
|
2
|
-
import { useQueryClient as
|
|
3
|
-
import { Wrench as
|
|
4
|
-
import { useState as w, useMemo as
|
|
5
|
-
import { toast as
|
|
6
|
-
import { useNivaroClient as
|
|
7
|
-
import { get as $, patch as
|
|
8
|
-
import { titleCase as
|
|
9
|
-
import { Button as
|
|
10
|
-
import { Sheet as
|
|
11
|
-
import { ChangeReasonDialog as
|
|
12
|
-
import { FieldRenderer as
|
|
13
|
-
import { M2MCombobox as
|
|
14
|
-
import { M2MStagingContext as
|
|
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
|
-
|
|
16
|
+
import { RawM2ALinks as he } from "./RawM2ALinks.js";
|
|
17
|
+
function E(i, s) {
|
|
17
18
|
const u = (p) => p == null || p === "";
|
|
18
|
-
return u(
|
|
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
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
return
|
|
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
|
|
26
|
-
collection:
|
|
27
|
-
itemId:
|
|
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 =
|
|
33
|
-
queryKey: ["raw-edit-config",
|
|
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/${
|
|
37
|
-
h.request($(`/collections/${
|
|
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:
|
|
44
|
-
queryKey: ["raw-edit-record",
|
|
45
|
-
queryFn: () => h.request($(`/items/${
|
|
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
|
-
}),
|
|
49
|
-
const e = (c == null ? void 0 : c.fields) ?? [], n = (c == null ? void 0 : c.relations) ?? [], r = (t) => n.some((a) => a.one_collection ===
|
|
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 ===
|
|
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,
|
|
66
|
-
(n) => n.one_collection ===
|
|
67
|
-
),
|
|
68
|
-
const n =
|
|
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 ?
|
|
72
|
-
},
|
|
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) =>
|
|
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) =>
|
|
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) =>
|
|
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,
|
|
97
|
-
),
|
|
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(
|
|
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
|
|
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
|
|
111
|
-
r.push(h.request(
|
|
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
|
|
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 =
|
|
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
|
-
|
|
125
|
-
[d.many_field ?? ""]:
|
|
125
|
+
ae(`/items/${d.many_collection}`, {
|
|
126
|
+
[d.many_field ?? ""]: s,
|
|
126
127
|
[d.junction_field ?? ""]: b,
|
|
127
|
-
...
|
|
128
|
+
...X
|
|
128
129
|
})
|
|
129
130
|
).catch(() => {
|
|
130
131
|
})
|
|
131
132
|
);
|
|
132
133
|
}
|
|
133
|
-
await Promise.all(r),
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
148
|
+
re,
|
|
148
149
|
{
|
|
149
150
|
open: u,
|
|
150
151
|
onOpenChange: (e) => {
|
|
151
|
-
e ||
|
|
152
|
+
e || k || (j({}), v(/* @__PURE__ */ new Map()), _(/* @__PURE__ */ new Map()), p());
|
|
152
153
|
},
|
|
153
154
|
children: /* @__PURE__ */ f(
|
|
154
|
-
|
|
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(
|
|
160
|
-
/* @__PURE__ */ l(
|
|
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
|
-
|
|
163
|
+
T(i),
|
|
163
164
|
" #",
|
|
164
|
-
|
|
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(
|
|
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:
|
|
171
|
-
const t = e.field in m ? m[e.field] : o == null ? void 0 : o[e.field], a = e.field in m && !
|
|
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 ||
|
|
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: ${
|
|
190
|
+
"data-tip": `Was: ${J(o == null ? void 0 : o[e.field])}`,
|
|
190
191
|
children: [
|
|
191
192
|
"was ",
|
|
192
|
-
|
|
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 &&
|
|
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
|
|
200
|
-
// email showed "Record not found".
|
|
201
|
-
/* @__PURE__ */ l(
|
|
202
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
205
|
+
collection: i,
|
|
206
|
+
itemId: s,
|
|
207
|
+
field: e.field,
|
|
208
|
+
discriminator: z(r)
|
|
207
209
|
}
|
|
208
|
-
)
|
|
209
|
-
) : n && r ? /* @__PURE__ */ l(
|
|
210
|
-
|
|
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((
|
|
216
|
+
onChange: (d) => j((x) => ({ ...x, [e.field]: d })),
|
|
215
217
|
relations: c.relations,
|
|
216
|
-
collection:
|
|
217
|
-
itemId:
|
|
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 (!
|
|
228
|
-
const e = Object.keys(m).filter((n) => !
|
|
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(
|
|
233
|
-
/* @__PURE__ */ l(
|
|
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
|
-
|
|
239
|
+
oe,
|
|
238
240
|
{
|
|
239
|
-
challenge:
|
|
241
|
+
challenge: B,
|
|
240
242
|
onCancel: () => q(null),
|
|
241
243
|
onSubmit: (e) => {
|
|
242
|
-
q(null),
|
|
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
|
-
|
|
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
|
|
3
|
-
var
|
|
4
|
-
let e =
|
|
5
|
-
if (!e &&
|
|
6
|
-
const
|
|
7
|
-
e =
|
|
8
|
-
(i) => i.one_collection === n && i.many_collection ===
|
|
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
|
|
13
|
-
if (!
|
|
14
|
-
const
|
|
15
|
-
(
|
|
16
|
-
),
|
|
17
|
-
return {
|
|
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
|
|
24
|
+
function O(n) {
|
|
20
25
|
return n == null || n === "" ? [] : Array.isArray(n) ? n : typeof n == "object" ? [] : [n];
|
|
21
26
|
}
|
|
22
|
-
const
|
|
23
|
-
function
|
|
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:
|
|
26
|
-
for (const
|
|
27
|
-
const g = e.get(
|
|
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
|
|
30
|
-
if (!
|
|
31
|
-
const
|
|
32
|
-
|
|
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
|
|
35
|
-
for (const
|
|
36
|
-
const
|
|
37
|
-
|
|
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
|
-
|
|
54
|
+
u[f.field] = o, _.add(m);
|
|
40
55
|
continue;
|
|
41
56
|
}
|
|
42
|
-
const
|
|
43
|
-
let
|
|
57
|
+
const S = (i = n.committed) == null ? void 0 : i.call(n, m);
|
|
58
|
+
let p = [];
|
|
44
59
|
if (y.size > 0) {
|
|
45
|
-
if (!
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
return
|
|
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 (
|
|
51
|
-
|
|
65
|
+
if (l.some((c) => c == null)) continue;
|
|
66
|
+
p = l;
|
|
52
67
|
}
|
|
53
|
-
const b = (
|
|
54
|
-
for (const
|
|
55
|
-
const
|
|
56
|
-
j.has(
|
|
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
|
-
|
|
59
|
-
...
|
|
60
|
-
...
|
|
61
|
-
},
|
|
73
|
+
u[f.field] = {
|
|
74
|
+
...h.length ? { create: h } : {},
|
|
75
|
+
...p.length ? { delete: p } : {}
|
|
76
|
+
}, _.add(m);
|
|
62
77
|
}
|
|
63
|
-
return
|
|
78
|
+
return _;
|
|
64
79
|
}
|
|
65
|
-
const
|
|
66
|
-
function
|
|
67
|
-
var
|
|
68
|
-
const
|
|
69
|
-
for (const [e,
|
|
70
|
-
if (
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
const
|
|
74
|
-
(i) => i.one_collection === n.collection && i.many_collection ===
|
|
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
|
-
|
|
77
|
-
const { id:
|
|
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
|
-
}),
|
|
94
|
+
}), r.add(e)));
|
|
80
95
|
}
|
|
81
|
-
return
|
|
96
|
+
return r;
|
|
82
97
|
}
|
|
83
98
|
export {
|
|
84
|
-
|
|
85
|
-
|
|
99
|
+
M as foldStagedLinks,
|
|
100
|
+
W as foldStagedRows
|
|
86
101
|
};
|