@nivaro/react 0.3.96 → 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 +501 -340
- package/dist/shared/components/item-edit/RawEditSheet.js +123 -104
- 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
|
|
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
5
|
import { toast as Q } from "sonner";
|
|
6
|
-
import { useNivaroClient as
|
|
7
|
-
import { get as
|
|
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
8
|
import { titleCase as T } from "../../lib/utils.js";
|
|
9
9
|
import { Button as W } from "../ui/button.js";
|
|
10
|
-
import { Sheet as
|
|
11
|
-
import { ChangeReasonDialog as
|
|
12
|
-
import { FieldRenderer as
|
|
13
|
-
import { M2MCombobox as
|
|
14
|
-
import { M2MStagingContext as
|
|
15
|
-
import { invalidateM2MFor as
|
|
16
|
-
|
|
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
|
+
import { invalidateM2MFor as pe } from "./m2m-invalidate.js";
|
|
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
|
-
const [e,
|
|
36
|
-
h.request(
|
|
37
|
-
h.request(
|
|
36
|
+
const [e, n] = await Promise.all([
|
|
37
|
+
h.request($(`/field-config/${i}`)).then((r) => r.data ?? []),
|
|
38
|
+
h.request($(`/collections/${i}`)).then((r) => r.data)
|
|
38
39
|
]);
|
|
39
|
-
return { fields: e, relations:
|
|
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(
|
|
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) ?? [],
|
|
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: {
|
|
@@ -57,147 +58,165 @@ function qe({
|
|
|
57
58
|
lock_condition: null,
|
|
58
59
|
dependency_config: null
|
|
59
60
|
},
|
|
60
|
-
alias:
|
|
61
|
-
m2mRel:
|
|
62
|
-
(
|
|
61
|
+
alias: r(t),
|
|
62
|
+
m2mRel: n.find(
|
|
63
|
+
(a) => a.one_collection === i && a.one_field === t.field && a.junction_field != null
|
|
63
64
|
)
|
|
64
|
-
})).sort((t,
|
|
65
|
-
}, [c,
|
|
66
|
-
(
|
|
67
|
-
),
|
|
65
|
+
})).sort((t, a) => (t.field.sort ?? 0) - (a.field.sort ?? 0));
|
|
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(
|
|
70
|
+
(r) => r.many_collection === e.many_collection && r.many_field === e.junction_field && r.id !== e.id
|
|
71
|
+
);
|
|
72
|
+
return !n || n.one_collection || fe(n) < 2 ? null : n.one_collection_field || "collection";
|
|
73
|
+
}, A = P(
|
|
68
74
|
() => ({
|
|
69
75
|
getStagedLinks: (e) => g.get(e) ?? [],
|
|
70
|
-
getStagedUnlinks: (e) =>
|
|
71
|
-
stageLink: (e,
|
|
72
|
-
const t = new Map(
|
|
73
|
-
return t.set(e, [...t.get(e) ?? [],
|
|
76
|
+
getStagedUnlinks: (e) => y.get(e) ?? /* @__PURE__ */ new Set(),
|
|
77
|
+
stageLink: (e, n) => v((r) => {
|
|
78
|
+
const t = new Map(r);
|
|
79
|
+
return t.set(e, [...t.get(e) ?? [], n]), t;
|
|
74
80
|
}),
|
|
75
|
-
unstageLink: (e,
|
|
76
|
-
const t = new Map(
|
|
81
|
+
unstageLink: (e, n) => v((r) => {
|
|
82
|
+
const t = new Map(r);
|
|
77
83
|
return t.set(
|
|
78
84
|
e,
|
|
79
|
-
(t.get(e) ?? []).filter((
|
|
85
|
+
(t.get(e) ?? []).filter((a) => String(a) !== String(n))
|
|
80
86
|
), t;
|
|
81
87
|
}),
|
|
82
|
-
stageUnlink: (e,
|
|
83
|
-
const t = new Map(
|
|
84
|
-
return
|
|
88
|
+
stageUnlink: (e, n) => _((r) => {
|
|
89
|
+
const t = new Map(r), a = new Set(t.get(e) ?? []);
|
|
90
|
+
return a.add(n), t.set(e, a), t;
|
|
85
91
|
}),
|
|
86
|
-
unstageUnlink: (e,
|
|
87
|
-
const t = new Map(
|
|
88
|
-
return
|
|
92
|
+
unstageUnlink: (e, n) => _((r) => {
|
|
93
|
+
const t = new Map(r), a = new Set(t.get(e) ?? []);
|
|
94
|
+
return a.delete(n), t.set(e, a), t;
|
|
89
95
|
})
|
|
90
96
|
}),
|
|
91
|
-
[g,
|
|
92
|
-
),
|
|
93
|
-
var
|
|
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) => {
|
|
99
|
+
var n;
|
|
94
100
|
L(!0);
|
|
95
101
|
try {
|
|
96
102
|
if (Object.keys(m).length > 0) {
|
|
97
103
|
const t = { ...m };
|
|
98
|
-
e && (t._change_reason = e), await h.request(
|
|
104
|
+
e && (t._change_reason = e), await h.request(te(`/items/${i}/${s}`, t));
|
|
99
105
|
}
|
|
100
|
-
const
|
|
101
|
-
for (const [t,
|
|
102
|
-
if (!
|
|
106
|
+
const r = [];
|
|
107
|
+
for (const [t, a] of y.entries()) {
|
|
108
|
+
if (!a.size) continue;
|
|
103
109
|
const d = O(t);
|
|
104
110
|
if (d)
|
|
105
|
-
for (const
|
|
106
|
-
|
|
111
|
+
for (const x of a)
|
|
112
|
+
r.push(h.request(ne(`/items/${d.many_collection}/${x}`)).catch(() => {
|
|
107
113
|
}));
|
|
108
114
|
}
|
|
109
|
-
for (const [t,
|
|
110
|
-
if (!
|
|
115
|
+
for (const [t, a] of g.entries()) {
|
|
116
|
+
if (!a.length) continue;
|
|
111
117
|
const d = O(t);
|
|
112
118
|
if (!d) continue;
|
|
113
|
-
const
|
|
119
|
+
const x = N.find(
|
|
114
120
|
(b) => b.many_collection === d.many_collection && b.many_field === d.junction_field && b.id !== d.id
|
|
115
|
-
),
|
|
116
|
-
for (const b of
|
|
117
|
-
|
|
121
|
+
), C = ue(x), X = C ? { [C.field]: C.value } : {};
|
|
122
|
+
for (const b of a)
|
|
123
|
+
r.push(
|
|
118
124
|
h.request(
|
|
119
|
-
|
|
120
|
-
[d.many_field ?? ""]:
|
|
125
|
+
ae(`/items/${d.many_collection}`, {
|
|
126
|
+
[d.many_field ?? ""]: s,
|
|
121
127
|
[d.junction_field ?? ""]: b,
|
|
122
|
-
...
|
|
128
|
+
...X
|
|
123
129
|
})
|
|
124
130
|
).catch(() => {
|
|
125
131
|
})
|
|
126
132
|
);
|
|
127
133
|
}
|
|
128
|
-
await Promise.all(
|
|
129
|
-
} catch (
|
|
130
|
-
const t =
|
|
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();
|
|
135
|
+
} catch (r) {
|
|
136
|
+
const t = ce(r);
|
|
131
137
|
if (t) {
|
|
132
|
-
|
|
138
|
+
q(t);
|
|
133
139
|
return;
|
|
134
140
|
}
|
|
135
|
-
const
|
|
136
|
-
Q.error(((
|
|
141
|
+
const a = r == null ? void 0 : r.response;
|
|
142
|
+
Q.error(((n = a == null ? void 0 : a.data) == null ? void 0 : n.error) ?? (a == null ? void 0 : a.error) ?? "Save failed");
|
|
137
143
|
} finally {
|
|
138
144
|
L(!1);
|
|
139
145
|
}
|
|
140
146
|
};
|
|
141
147
|
return /* @__PURE__ */ l(
|
|
142
|
-
|
|
148
|
+
re,
|
|
143
149
|
{
|
|
144
150
|
open: u,
|
|
145
151
|
onOpenChange: (e) => {
|
|
146
|
-
e || k || (
|
|
152
|
+
e || k || (j({}), v(/* @__PURE__ */ new Map()), _(/* @__PURE__ */ new Map()), p());
|
|
147
153
|
},
|
|
148
154
|
children: /* @__PURE__ */ f(
|
|
149
|
-
|
|
155
|
+
ie,
|
|
150
156
|
{
|
|
151
157
|
side: "right",
|
|
152
158
|
className: "flex w-[1040px] max-w-[94vw] flex-col p-0 sm:max-w-[94vw]",
|
|
153
159
|
children: [
|
|
154
|
-
/* @__PURE__ */ l(
|
|
155
|
-
/* @__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" }),
|
|
156
162
|
"Raw edit — ",
|
|
157
|
-
T(
|
|
163
|
+
T(i),
|
|
158
164
|
" #",
|
|
159
|
-
|
|
165
|
+
s
|
|
160
166
|
] }) }),
|
|
161
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: [
|
|
162
|
-
/* @__PURE__ */ l(
|
|
168
|
+
/* @__PURE__ */ l(I, { className: "h-3.5 w-3.5 shrink-0" }),
|
|
163
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."
|
|
164
170
|
] }),
|
|
165
|
-
/* @__PURE__ */ l("div", { className: "min-h-0 flex-1 overflow-y-auto px-5 py-4", children:
|
|
166
|
-
const t = e.field in m ? 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]);
|
|
167
173
|
return /* @__PURE__ */ f(
|
|
168
174
|
"div",
|
|
169
175
|
{
|
|
170
|
-
className: `grid grid-cols-[220px_1fr] items-start gap-3 rounded-md ${
|
|
171
|
-
"data-raw-changed":
|
|
176
|
+
className: `grid grid-cols-[220px_1fr] items-start gap-3 rounded-md ${a ? "-mx-2 bg-amber-50 px-2 py-1 ring-1 ring-amber-200 dark:bg-amber-400/10 dark:ring-amber-500/30" : ""}`,
|
|
177
|
+
"data-raw-changed": a ? e.field : void 0,
|
|
172
178
|
"data-raw-field": e.field,
|
|
173
179
|
children: [
|
|
174
180
|
/* @__PURE__ */ f("div", { className: "pt-1.5", children: [
|
|
175
181
|
/* @__PURE__ */ f("p", { className: "text-[12px] font-medium text-slate-700 dark:text-slate-200", children: [
|
|
176
182
|
e.label || T(e.field),
|
|
177
|
-
|
|
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" })
|
|
178
184
|
] }),
|
|
179
185
|
/* @__PURE__ */ l("p", { className: "font-mono text-[10.5px] text-slate-400", children: e.field }),
|
|
180
|
-
|
|
186
|
+
a && /* @__PURE__ */ f(
|
|
181
187
|
"p",
|
|
182
188
|
{
|
|
183
189
|
className: "mt-0.5 truncate text-[10.5px] text-slate-400",
|
|
184
|
-
"data-tip": `Was: ${
|
|
190
|
+
"data-tip": `Was: ${J(o == null ? void 0 : o[e.field])}`,
|
|
185
191
|
children: [
|
|
186
192
|
"was ",
|
|
187
|
-
|
|
193
|
+
J(o == null ? void 0 : o[e.field])
|
|
188
194
|
]
|
|
189
195
|
}
|
|
190
196
|
)
|
|
191
197
|
] }),
|
|
192
|
-
e.field === "id" ? /* @__PURE__ */ l("p", { className: "pt-1.5 font-mono text-[12px] text-slate-500", children: String(t ?? "") }) :
|
|
193
|
-
|
|
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) ? (
|
|
199
|
+
// A ship-to contact is a person OR an external email: the
|
|
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,
|
|
204
|
+
{
|
|
205
|
+
collection: i,
|
|
206
|
+
itemId: s,
|
|
207
|
+
field: e.field,
|
|
208
|
+
discriminator: z(r)
|
|
209
|
+
}
|
|
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,
|
|
194
213
|
{
|
|
195
214
|
field: e,
|
|
196
215
|
value: t,
|
|
197
|
-
onChange: (d) =>
|
|
216
|
+
onChange: (d) => j((x) => ({ ...x, [e.field]: d })),
|
|
198
217
|
relations: c.relations,
|
|
199
|
-
collection:
|
|
200
|
-
itemId:
|
|
218
|
+
collection: i,
|
|
219
|
+
itemId: s
|
|
201
220
|
}
|
|
202
221
|
)
|
|
203
222
|
]
|
|
@@ -207,22 +226,22 @@ function qe({
|
|
|
207
226
|
}) }) }),
|
|
208
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: [
|
|
209
228
|
/* @__PURE__ */ l("span", { className: "text-[11.5px] text-slate-400", children: (() => {
|
|
210
|
-
if (!
|
|
211
|
-
const e = Object.keys(m).filter((
|
|
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;
|
|
212
231
|
return e === 0 ? "No changes yet" : `${e} field${e !== 1 ? "s" : ""} changed`;
|
|
213
232
|
})() }),
|
|
214
233
|
/* @__PURE__ */ f("div", { className: "flex gap-2", children: [
|
|
215
234
|
/* @__PURE__ */ l(W, { variant: "outline", size: "sm", onClick: p, disabled: k, children: "Cancel" }),
|
|
216
|
-
/* @__PURE__ */ l(W, { size: "sm", onClick: () => void
|
|
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" })
|
|
217
236
|
] })
|
|
218
237
|
] }),
|
|
219
238
|
/* @__PURE__ */ l(
|
|
220
|
-
|
|
239
|
+
oe,
|
|
221
240
|
{
|
|
222
|
-
challenge:
|
|
223
|
-
onCancel: () =>
|
|
241
|
+
challenge: B,
|
|
242
|
+
onCancel: () => q(null),
|
|
224
243
|
onSubmit: (e) => {
|
|
225
|
-
|
|
244
|
+
q(null), R(e);
|
|
226
245
|
}
|
|
227
246
|
}
|
|
228
247
|
)
|
|
@@ -233,5 +252,5 @@ function qe({
|
|
|
233
252
|
);
|
|
234
253
|
}
|
|
235
254
|
export {
|
|
236
|
-
|
|
255
|
+
Oe as RawEditSheet
|
|
237
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
|
};
|