@nivaro/react 0.3.34 → 0.3.36
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/full.css +1 -1
- package/dist/hooks/useSessionRecorder.js +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/shared/components/ItemEditForm.js +2009 -1996
- package/dist/shared/components/RecordReadView.js +88 -85
- package/dist/shared/components/item-edit/FieldAffordances.js +351 -307
- package/dist/shared/components/item-edit/FieldRow.js +453 -447
- package/dist/shared/components/item-edit/PersonalDefaultControl.js +228 -0
- package/dist/shared/components/item-edit/PersonalDefaultPill.js +9 -39
- package/dist/shared/components/item-edit/RecordLiveSync.js +115 -110
- package/dist/shared/components/item-edit/entry/useEntryKeyboard.js +27 -27
- package/dist/shared/components/item-edit/live-record-marks.js +13 -0
- package/dist/shared/components/item-edit/usePersonalDefaults.js +314 -230
- package/dist/shared/components/layout-editor/DesignNode.js +79 -78
- package/dist/shared/components/layout-editor/EditorCanvas.js +25 -17
- package/dist/shared/components/layout-editor/EditorTopBar.js +230 -188
- package/dist/shared/components/layout-editor/LayoutEditor.js +370 -369
- package/dist/shared/components/layout-editor/dnd/LayoutDndProvider.js +218 -182
- package/dist/shared/components/layout-editor/dnd/TrashZone.js +68 -0
- package/dist/shared/components/layout-editor/dnd/rail-drop.js +4 -4
- package/dist/shared/components/layout-editor/dnd/trash-drop.js +52 -0
- package/dist/shared/components/layout-editor/inspector/kit.js +1 -1
- package/dist/shared/components/layout-editor/panel-frame.js +1 -1
- package/dist/shared/components/layout-editor/personal-default-marks.js +40 -0
- package/dist/shared/components/layout-editor/preview/PreviewPanes.js +2 -2
- package/package.json +1 -1
|
@@ -1,283 +1,309 @@
|
|
|
1
|
-
import { useQueryClient as
|
|
2
|
-
import { useRef as
|
|
3
|
-
import { useNivaroClient as
|
|
4
|
-
import { get as
|
|
5
|
-
import { isEmptyValue as
|
|
6
|
-
import { titleCase as
|
|
7
|
-
const
|
|
8
|
-
function
|
|
9
|
-
return
|
|
1
|
+
import { useQueryClient as Qe, useQuery as ze } from "@tanstack/react-query";
|
|
2
|
+
import { useRef as F, useMemo as Ee, useState as ce, useEffect as z, useCallback as a, createContext as He, useContext as Ie } from "react";
|
|
3
|
+
import { useNivaroClient as _e } from "../../context.js";
|
|
4
|
+
import { get as Be, put as oe, del as Je } from "../../lib/commands.js";
|
|
5
|
+
import { isEmptyValue as g, pickDefault as ue, cascadeParents as C, orderTopDown as Ue, captureContext as We } from "../../lib/personal-defaults.js";
|
|
6
|
+
import { titleCase as Ne } from "../../lib/utils.js";
|
|
7
|
+
const Ge = He(null);
|
|
8
|
+
function it() {
|
|
9
|
+
return Ie(Ge);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
return ["field-defaults",
|
|
11
|
+
function j(o) {
|
|
12
|
+
return ["field-defaults", o];
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
return Array.isArray(
|
|
14
|
+
function O(o) {
|
|
15
|
+
return Array.isArray(o) ? o.map(O) : o && typeof o == "object" && "id" in o ? o.id : o;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const Xe = /* @__PURE__ */ new Set(["integer", "bigInteger", "float", "decimal", "number", "double"]), Ze = /* @__PURE__ */ new Set(["date"]), et = /* @__PURE__ */ new Set(["dateTime", "datetime", "timestamp", "time"]);
|
|
18
|
+
function q(o, i, v) {
|
|
19
|
+
if (g(o) && g(i)) return !0;
|
|
20
|
+
if (v && !Array.isArray(o) && !Array.isArray(i) && !g(o) && !g(i)) {
|
|
21
|
+
const S = O(o), b = O(i);
|
|
22
|
+
if (Xe.has(v)) {
|
|
23
|
+
const d = Number(S), p = Number(b);
|
|
24
|
+
if (Number.isFinite(d) && Number.isFinite(p)) return d === p;
|
|
25
|
+
} else if (Ze.has(v)) {
|
|
26
|
+
const d = (A) => {
|
|
27
|
+
var V;
|
|
28
|
+
return (V = /^(\d{4}-\d{2}-\d{2})/.exec(String(A))) == null ? void 0 : V[1];
|
|
29
|
+
}, p = d(S), f = d(b);
|
|
30
|
+
if (p && f) return p === f;
|
|
31
|
+
} else if (et.has(v)) {
|
|
32
|
+
const d = Date.parse(String(S)), p = Date.parse(String(b));
|
|
33
|
+
if (Number.isFinite(d) && Number.isFinite(p)) return d === p;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const D = (S) => {
|
|
37
|
+
const b = O(S);
|
|
38
|
+
return Array.isArray(b) ? b.map((d) => String(d)).sort() : String(b);
|
|
22
39
|
};
|
|
23
|
-
return JSON.stringify(
|
|
40
|
+
return JSON.stringify(D(o)) === JSON.stringify(D(i));
|
|
24
41
|
}
|
|
25
|
-
function
|
|
26
|
-
let
|
|
27
|
-
for (const [
|
|
28
|
-
const b =
|
|
29
|
-
for (const
|
|
42
|
+
function lt(o, i) {
|
|
43
|
+
let v = 0;
|
|
44
|
+
for (const [D, S] of o) {
|
|
45
|
+
const b = i.get(D);
|
|
46
|
+
for (const d of S) b != null && b.has(String(d)) || v++;
|
|
30
47
|
}
|
|
31
|
-
return
|
|
48
|
+
return v;
|
|
32
49
|
}
|
|
33
|
-
function
|
|
34
|
-
return Array.isArray(
|
|
50
|
+
function tt(o) {
|
|
51
|
+
return Array.isArray(o) ? o : g(o) ? [] : [o];
|
|
35
52
|
}
|
|
36
|
-
function
|
|
37
|
-
const { collection:
|
|
38
|
-
|
|
39
|
-
const { data:
|
|
40
|
-
queryKey:
|
|
41
|
-
queryFn: () =>
|
|
53
|
+
function ft(o) {
|
|
54
|
+
const { collection: i, isNew: v, disabled: D, enabled: S = !0, ready: b = !0 } = o, d = _e(), p = Qe(), f = F(o);
|
|
55
|
+
f.current = o;
|
|
56
|
+
const { data: A, isError: V } = ze({
|
|
57
|
+
queryKey: j(i),
|
|
58
|
+
queryFn: () => d.request(Be("/field-defaults/mine", { collection: i })).then((e) => e.data ?? []),
|
|
42
59
|
staleTime: 5 * 6e4,
|
|
43
|
-
enabled: !!
|
|
44
|
-
}),
|
|
60
|
+
enabled: !!i && S
|
|
61
|
+
}), H = Ee(() => {
|
|
45
62
|
const e = /* @__PURE__ */ new Map();
|
|
46
|
-
for (const t of
|
|
63
|
+
for (const t of A ?? []) {
|
|
47
64
|
const r = e.get(t.field) ?? [];
|
|
48
65
|
r.push(t), e.set(t.field, r);
|
|
49
66
|
}
|
|
50
67
|
return e;
|
|
51
|
-
}, [
|
|
52
|
-
W.current =
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
}, [A]), W = F(H);
|
|
69
|
+
W.current = H;
|
|
70
|
+
const y = F(/* @__PURE__ */ new Map()), [G, Te] = ce(() => /* @__PURE__ */ new Map()), P = F(/* @__PURE__ */ new Map()), [ae, Ce] = ce(() => /* @__PURE__ */ new Map()), E = F(/* @__PURE__ */ new Set()), I = F(!0);
|
|
71
|
+
z(() => (I.current = !0, () => {
|
|
72
|
+
I.current = !1;
|
|
56
73
|
}), []);
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const t =
|
|
74
|
+
const m = a(() => {
|
|
75
|
+
I.current && (Te((e) => {
|
|
76
|
+
const t = y.current;
|
|
60
77
|
return e.size === t.size && [...t].every(([r, n]) => e.get(r) === n) ? e : new Map(t);
|
|
61
|
-
}),
|
|
62
|
-
const t =
|
|
78
|
+
}), Ce((e) => {
|
|
79
|
+
const t = P.current;
|
|
63
80
|
return e.size === t.size && [...t].every(([r, n]) => e.get(r) === n) ? e : new Map(t);
|
|
64
81
|
}));
|
|
65
|
-
}, []),
|
|
82
|
+
}, []), c = a((e) => {
|
|
66
83
|
var n;
|
|
67
|
-
const t =
|
|
84
|
+
const t = f.current, r = (n = t.readValue) == null ? void 0 : n.call(t, e);
|
|
68
85
|
return r !== void 0 ? r : t.draftRef.current[e];
|
|
69
|
-
}, []),
|
|
86
|
+
}, []), N = a(
|
|
70
87
|
(e) => {
|
|
71
88
|
const t = {};
|
|
72
|
-
for (const r of e) t[r] =
|
|
89
|
+
for (const r of e) t[r] = c(r);
|
|
73
90
|
return t;
|
|
74
91
|
},
|
|
75
|
-
[
|
|
92
|
+
[c]
|
|
76
93
|
), M = a(async (e, t) => {
|
|
77
|
-
const r =
|
|
78
|
-
|
|
79
|
-
if (!r.valueLabel) return String(
|
|
94
|
+
const r = f.current, s = (await Promise.all(
|
|
95
|
+
tt(O(t)).map(async (l) => {
|
|
96
|
+
if (!r.valueLabel) return String(l);
|
|
80
97
|
try {
|
|
81
|
-
return await r.valueLabel(e,
|
|
98
|
+
return await r.valueLabel(e, l) ?? null;
|
|
82
99
|
} catch {
|
|
83
100
|
return null;
|
|
84
101
|
}
|
|
85
102
|
})
|
|
86
|
-
)).filter((
|
|
103
|
+
)).filter((l) => !!l);
|
|
87
104
|
return s.length > 0 ? s.join(", ") : null;
|
|
88
|
-
}, []),
|
|
105
|
+
}, []), K = F(0), _ = a(
|
|
89
106
|
async (e, t, r) => {
|
|
90
107
|
const n = await t;
|
|
91
|
-
|
|
108
|
+
K.current === r && (P.current.set(e, n), m());
|
|
92
109
|
},
|
|
93
|
-
[
|
|
94
|
-
),
|
|
110
|
+
[m]
|
|
111
|
+
), X = a(
|
|
95
112
|
async (e, t) => {
|
|
96
|
-
var s,
|
|
97
|
-
const r = ((
|
|
113
|
+
var s, l;
|
|
114
|
+
const r = ((l = (s = f.current).fieldLabel) == null ? void 0 : l.call(s, e)) ?? e, n = await M(e, t);
|
|
98
115
|
return n ? `Your default is for ${r} “${n}”` : `Your saved default is for a different ${r}`;
|
|
99
116
|
},
|
|
100
117
|
[M]
|
|
101
|
-
),
|
|
102
|
-
const n =
|
|
103
|
-
if (n.setFieldValue(e, t, r),
|
|
104
|
-
|
|
118
|
+
), B = a((e, t, r) => {
|
|
119
|
+
const n = f.current;
|
|
120
|
+
if (n.setFieldValue(e, t, r), g(t)) {
|
|
121
|
+
y.current.delete(e);
|
|
105
122
|
return;
|
|
106
123
|
}
|
|
107
|
-
|
|
108
|
-
}, []),
|
|
124
|
+
y.current.set(e, t), P.current.delete(e), n.markAutoFilled([e]);
|
|
125
|
+
}, []), ie = a(
|
|
109
126
|
async (e, t) => {
|
|
110
|
-
var
|
|
111
|
-
const r =
|
|
127
|
+
var Se, Ae, Pe, Me, Re, qe;
|
|
128
|
+
const r = f.current, n = () => K.current !== t, s = W.current.get(e) ?? [];
|
|
112
129
|
if (s.length === 0 || !r.layoutAllows(e)) return [];
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
const
|
|
117
|
-
if (!
|
|
118
|
-
if (
|
|
119
|
-
const
|
|
120
|
-
(
|
|
121
|
-
)) == null ? void 0 :
|
|
122
|
-
await
|
|
130
|
+
if (E.current.has(e) || !(((Se = r.canFill) == null ? void 0 : Se.call(r, e)) ?? !0)) return [];
|
|
131
|
+
const l = c(e), w = !g(l);
|
|
132
|
+
if (w && !(((Ae = r.replaceable) == null ? void 0 : Ae.call(r, e, l)) ?? !1)) return [];
|
|
133
|
+
const T = new Set(s.flatMap((u) => Object.keys(u.context ?? {}))), U = N(T), { pick: h, fillParents: R, blockedBy: Y } = ue(s, U);
|
|
134
|
+
if (!h) {
|
|
135
|
+
if (Y) {
|
|
136
|
+
const u = (Pe = s.find(
|
|
137
|
+
(k) => k.context && Y in k.context && !q(k.context[Y], U[Y])
|
|
138
|
+
)) == null ? void 0 : Pe.context[Y];
|
|
139
|
+
await _(e, X(Y, u), t);
|
|
123
140
|
}
|
|
124
141
|
return [];
|
|
125
142
|
}
|
|
126
|
-
const
|
|
127
|
-
...
|
|
128
|
-
...Object.keys(
|
|
129
|
-
],
|
|
130
|
-
for (const [
|
|
131
|
-
|
|
143
|
+
const ke = C(e, r.rulesFor).reverse(), Le = [
|
|
144
|
+
...ke.filter((u) => u in R),
|
|
145
|
+
...Object.keys(R).filter((u) => !ke.includes(u))
|
|
146
|
+
], se = [], $ = () => {
|
|
147
|
+
for (const [u, k] of se.reverse())
|
|
148
|
+
q(c(u), k) ? B(u, null, k) : y.current.delete(u);
|
|
132
149
|
};
|
|
133
|
-
for (const
|
|
134
|
-
const
|
|
150
|
+
for (const u of Le) {
|
|
151
|
+
const k = R[u], De = r.layoutAllows(u) && !E.current.has(u) && (((Me = r.canFill) == null ? void 0 : Me.call(r, u)) ?? !0) ? await r.revalidate(u, k) : !1;
|
|
135
152
|
if (n()) return [];
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
if (!
|
|
139
|
-
return
|
|
140
|
-
|
|
153
|
+
if (De === null)
|
|
154
|
+
return $(), [];
|
|
155
|
+
if (!De || !g(c(u)))
|
|
156
|
+
return $(), await _(e, X(u, k), t), [];
|
|
157
|
+
B(u, k), se.push([u, k]);
|
|
141
158
|
}
|
|
142
|
-
const
|
|
159
|
+
const Fe = await r.revalidate(e, h.value);
|
|
143
160
|
if (n()) return [];
|
|
144
|
-
if (
|
|
145
|
-
return
|
|
146
|
-
if (!
|
|
147
|
-
return
|
|
161
|
+
if (Fe === null)
|
|
162
|
+
return $(), [];
|
|
163
|
+
if (!Fe)
|
|
164
|
+
return $(), await _(
|
|
148
165
|
e,
|
|
149
|
-
M(e,
|
|
150
|
-
(
|
|
166
|
+
M(e, h.value).then(
|
|
167
|
+
(u) => u ? `Your default "${u}" is no longer available` : "Your saved default is no longer available"
|
|
151
168
|
),
|
|
152
169
|
t
|
|
153
170
|
), [];
|
|
154
|
-
if (!
|
|
155
|
-
return
|
|
156
|
-
const
|
|
157
|
-
return ((
|
|
171
|
+
if (!q(c(e), l) || !(((Re = r.canFill) == null ? void 0 : Re.call(r, e)) ?? !0))
|
|
172
|
+
return $(), [];
|
|
173
|
+
const xe = ue(s, N(T));
|
|
174
|
+
return ((qe = xe.pick) == null ? void 0 : qe.id) !== h.id || Object.keys(xe.fillParents).length > 0 ? ($(), "stale") : (B(e, h.value, w ? l : void 0), [...se.map(([u]) => u), e]);
|
|
158
175
|
},
|
|
159
|
-
[
|
|
160
|
-
),
|
|
176
|
+
[c, N, _, X, M, B]
|
|
177
|
+
), le = a(
|
|
161
178
|
async (e, t) => {
|
|
162
179
|
for (let r = 0; r < 3; r++) {
|
|
163
|
-
const n = await
|
|
180
|
+
const n = await ie(e, t);
|
|
164
181
|
if (n !== "stale") return n;
|
|
165
182
|
}
|
|
166
183
|
return [];
|
|
167
184
|
},
|
|
168
|
-
[
|
|
169
|
-
),
|
|
185
|
+
[ie]
|
|
186
|
+
), Z = a(
|
|
170
187
|
async (e) => {
|
|
171
188
|
var n, s;
|
|
172
|
-
const t =
|
|
173
|
-
for (const
|
|
174
|
-
if (!
|
|
175
|
-
for (const
|
|
176
|
-
|
|
189
|
+
const t = K.current, r = /* @__PURE__ */ new Set();
|
|
190
|
+
for (const l of e) {
|
|
191
|
+
if (!I.current || K.current !== t) return;
|
|
192
|
+
for (const w of await le(l, t)) r.add(w);
|
|
193
|
+
m();
|
|
177
194
|
}
|
|
178
|
-
if (
|
|
179
|
-
for (const
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
if (K.current === t) {
|
|
196
|
+
for (const l of r)
|
|
197
|
+
y.current.has(l) && ((s = (n = f.current).afterApply) == null || s.call(n, l, y.current.get(l)));
|
|
198
|
+
m();
|
|
182
199
|
}
|
|
183
200
|
},
|
|
184
|
-
[
|
|
185
|
-
),
|
|
186
|
-
const e =
|
|
187
|
-
return
|
|
201
|
+
[le, m]
|
|
202
|
+
), ee = a(() => {
|
|
203
|
+
const e = f.current;
|
|
204
|
+
return Ue(
|
|
188
205
|
[...W.current.keys()].filter((t) => e.layoutAllows(t)),
|
|
189
206
|
e.rulesFor
|
|
190
207
|
);
|
|
191
|
-
}, []),
|
|
192
|
-
|
|
193
|
-
!
|
|
194
|
-
}, [
|
|
208
|
+
}, []), te = F(!1);
|
|
209
|
+
z(() => {
|
|
210
|
+
!v || D || !b || te.current || A === void 0 || (te.current = !0, Z(ee()));
|
|
211
|
+
}, [v, D, b, A, Z, ee]), z(() => {
|
|
195
212
|
let e = !1;
|
|
196
|
-
for (const [t, r] of
|
|
197
|
-
|
|
198
|
-
for (const t of
|
|
199
|
-
|
|
200
|
-
e &&
|
|
213
|
+
for (const [t, r] of y.current)
|
|
214
|
+
q(c(t), r) || (y.current.delete(t), e = !0);
|
|
215
|
+
for (const t of P.current.keys())
|
|
216
|
+
g(c(t)) || (P.current.delete(t), e = !0);
|
|
217
|
+
e && m();
|
|
201
218
|
});
|
|
202
|
-
const
|
|
219
|
+
const L = F(/* @__PURE__ */ new Set()), Q = F(/* @__PURE__ */ new Map()), [Oe, Ve] = ce(0), Ke = a(
|
|
203
220
|
(e) => {
|
|
204
|
-
let t =
|
|
205
|
-
if (
|
|
206
|
-
t &&
|
|
221
|
+
let t = y.current.delete(e);
|
|
222
|
+
if (P.current.delete(e) && (t = !0), E.current.delete(e), Q.current.delete(e), !f.current.isNew) {
|
|
223
|
+
t && m();
|
|
207
224
|
return;
|
|
208
225
|
}
|
|
209
|
-
const r =
|
|
210
|
-
for (const [n, s] of [...
|
|
211
|
-
|
|
212
|
-
t &&
|
|
226
|
+
const r = f.current.rulesFor;
|
|
227
|
+
for (const [n, s] of [...y.current])
|
|
228
|
+
C(n, r).includes(e) && (Q.current.set(n, s), y.current.delete(n), t = !0);
|
|
229
|
+
t && m(), L.current.add(e), Ve((n) => n + 1);
|
|
213
230
|
},
|
|
214
|
-
[
|
|
231
|
+
[m]
|
|
215
232
|
);
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
const e = [...
|
|
219
|
-
|
|
220
|
-
const t = new Map(
|
|
221
|
-
|
|
222
|
-
const r =
|
|
223
|
-
for (const s of
|
|
233
|
+
z(() => {
|
|
234
|
+
if (L.current.size === 0 || f.current.disabled) return;
|
|
235
|
+
const e = [...L.current];
|
|
236
|
+
L.current.clear();
|
|
237
|
+
const t = new Map(Q.current);
|
|
238
|
+
Q.current.clear();
|
|
239
|
+
const r = f.current, n = [];
|
|
240
|
+
for (const s of ee()) {
|
|
224
241
|
if (t.has(s)) {
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
227
|
-
else if (!
|
|
242
|
+
const w = t.get(s), T = c(s);
|
|
243
|
+
if (q(T, w)) r.setFieldValue(s, null, w);
|
|
244
|
+
else if (!g(T)) continue;
|
|
228
245
|
n.push(s);
|
|
229
246
|
continue;
|
|
230
247
|
}
|
|
231
|
-
const
|
|
232
|
-
e.some((
|
|
248
|
+
const l = C(s, r.rulesFor);
|
|
249
|
+
e.some((w) => l.includes(w)) && P.current.has(s) && g(c(s)) && (P.current.delete(s), n.push(s));
|
|
233
250
|
}
|
|
234
|
-
|
|
235
|
-
}, [
|
|
236
|
-
const
|
|
251
|
+
m(), n.length > 0 && Z(n);
|
|
252
|
+
}, [Oe]);
|
|
253
|
+
const re = a(
|
|
237
254
|
(e) => {
|
|
238
|
-
const t =
|
|
239
|
-
if (!
|
|
255
|
+
const t = f.current;
|
|
256
|
+
if (!y.current.has(e)) return;
|
|
240
257
|
const r = [
|
|
241
258
|
e,
|
|
242
|
-
...[...
|
|
243
|
-
(n) => n !== e &&
|
|
259
|
+
...[...y.current.keys()].filter(
|
|
260
|
+
(n) => n !== e && C(n, t.rulesFor).includes(e)
|
|
244
261
|
)
|
|
245
262
|
];
|
|
246
263
|
for (const n of r) {
|
|
247
|
-
const s =
|
|
248
|
-
|
|
264
|
+
const s = y.current.get(n);
|
|
265
|
+
q(c(n), s) && t.setFieldValue(n, null, s), y.current.delete(n);
|
|
249
266
|
}
|
|
250
|
-
|
|
267
|
+
E.current.add(e), m();
|
|
251
268
|
},
|
|
252
|
-
[
|
|
253
|
-
),
|
|
269
|
+
[c, m]
|
|
270
|
+
), Ye = a(
|
|
254
271
|
(e) => {
|
|
255
|
-
if (!
|
|
256
|
-
const t =
|
|
257
|
-
|
|
272
|
+
if (!y.current.has(e)) return;
|
|
273
|
+
const t = y.current.get(e);
|
|
274
|
+
q(c(e), t) && f.current.setFieldValue(e, null, t), y.current.delete(e), E.current.add(e), m();
|
|
258
275
|
},
|
|
259
|
-
[
|
|
260
|
-
),
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}, [
|
|
264
|
-
const
|
|
276
|
+
[c, m]
|
|
277
|
+
), J = `${i}|${v ? "new" : "saved"}|${o.resetKey ?? ""}`, fe = F(J);
|
|
278
|
+
z(() => {
|
|
279
|
+
fe.current !== J && (fe.current = J, y.current.clear(), P.current.clear(), E.current.clear(), Q.current.clear(), L.current.clear(), te.current = !1, K.current += 1, m());
|
|
280
|
+
}, [J, m]);
|
|
281
|
+
const ne = a((e) => ae.get(e) ?? null, [ae]), $e = a(() => y.current, []), x = a(
|
|
265
282
|
(e) => {
|
|
266
|
-
const t =
|
|
283
|
+
const t = H.get(e) ?? [];
|
|
267
284
|
if (t.length === 0) return null;
|
|
268
285
|
const r = new Set(t.flatMap((n) => Object.keys(n.context ?? {})));
|
|
269
|
-
return
|
|
286
|
+
return ue(t, N(r)).pick;
|
|
270
287
|
},
|
|
271
|
-
[
|
|
272
|
-
),
|
|
273
|
-
|
|
274
|
-
}, [
|
|
275
|
-
(e) => !
|
|
276
|
-
[
|
|
277
|
-
),
|
|
288
|
+
[H, N]
|
|
289
|
+
), de = a(() => {
|
|
290
|
+
p.invalidateQueries({ queryKey: j(i) });
|
|
291
|
+
}, [p, i]), ye = a(
|
|
292
|
+
(e) => !g(c(e)),
|
|
293
|
+
[c]
|
|
294
|
+
), we = a(
|
|
295
|
+
(e) => {
|
|
296
|
+
var n, s;
|
|
297
|
+
const t = c(e);
|
|
298
|
+
if (g(t)) return !1;
|
|
299
|
+
const r = x(e);
|
|
300
|
+
return !!r && q(r.value, t, (s = (n = f.current).fieldType) == null ? void 0 : s.call(n, e));
|
|
301
|
+
},
|
|
302
|
+
[c, x]
|
|
303
|
+
), pe = a(
|
|
278
304
|
async (e) => {
|
|
279
|
-
const t =
|
|
280
|
-
...[...
|
|
305
|
+
const t = f.current, r = [
|
|
306
|
+
...[...C(e, t.rulesFor)].reverse().filter((n) => t.layoutAllows(n) && !g(c(n))),
|
|
281
307
|
e
|
|
282
308
|
];
|
|
283
309
|
return Promise.all(
|
|
@@ -285,74 +311,132 @@ function st(u) {
|
|
|
285
311
|
r.map(
|
|
286
312
|
async (n) => {
|
|
287
313
|
var s;
|
|
288
|
-
return await M(n,
|
|
314
|
+
return await M(n, c(n)) ?? ((s = t.fieldLabel) == null ? void 0 : s.call(t, n)) ?? Ne(n);
|
|
289
315
|
}
|
|
290
316
|
)
|
|
291
317
|
);
|
|
292
318
|
},
|
|
293
|
-
[
|
|
294
|
-
),
|
|
319
|
+
[c, M]
|
|
320
|
+
), me = a(
|
|
295
321
|
async (e) => {
|
|
296
|
-
const t =
|
|
297
|
-
if (
|
|
298
|
-
const n =
|
|
299
|
-
|
|
300
|
-
collection:
|
|
301
|
-
field:
|
|
302
|
-
value:
|
|
303
|
-
context:
|
|
322
|
+
const t = f.current, r = c(e);
|
|
323
|
+
if (g(r)) throw new Error("Pick a value first");
|
|
324
|
+
const n = C(e, t.rulesFor), s = N([e, ...n]), l = (w) => d.request(
|
|
325
|
+
oe("/field-defaults/mine", {
|
|
326
|
+
collection: i,
|
|
327
|
+
field: w,
|
|
328
|
+
value: O(s[w]),
|
|
329
|
+
context: We(w, s, t.rulesFor)
|
|
304
330
|
})
|
|
305
331
|
);
|
|
306
332
|
try {
|
|
307
|
-
await
|
|
308
|
-
for (const
|
|
309
|
-
t.layoutAllows(
|
|
333
|
+
await l(e);
|
|
334
|
+
for (const w of [...n].reverse())
|
|
335
|
+
t.layoutAllows(w) && !g(s[w]) && await l(w);
|
|
336
|
+
} finally {
|
|
337
|
+
await p.invalidateQueries({ queryKey: j(i) });
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
[d, p, i, c, N]
|
|
341
|
+
), he = a(
|
|
342
|
+
async (e) => {
|
|
343
|
+
const t = x(e);
|
|
344
|
+
if (!t) throw new Error("You have no default here to update");
|
|
345
|
+
const r = c(e);
|
|
346
|
+
if (g(r)) throw new Error("Pick a value first");
|
|
347
|
+
try {
|
|
348
|
+
await d.request(
|
|
349
|
+
oe("/field-defaults/mine", {
|
|
350
|
+
collection: i,
|
|
351
|
+
field: e,
|
|
352
|
+
value: O(r),
|
|
353
|
+
context: t.context ?? {}
|
|
354
|
+
})
|
|
355
|
+
);
|
|
310
356
|
} finally {
|
|
311
|
-
await
|
|
357
|
+
await p.invalidateQueries({ queryKey: j(i) });
|
|
312
358
|
}
|
|
313
359
|
},
|
|
314
|
-
[
|
|
315
|
-
),
|
|
360
|
+
[d, p, i, c, x]
|
|
361
|
+
), ge = a(
|
|
316
362
|
async (e) => {
|
|
317
|
-
const t =
|
|
318
|
-
|
|
363
|
+
const t = f.current, r = x(e), n = (r == null ? void 0 : r.context) ?? {}, s = [...C(e, t.rulesFor)].reverse(), l = [
|
|
364
|
+
...s.filter((h) => h in n),
|
|
365
|
+
...Object.keys(n).filter((h) => !s.includes(h))
|
|
366
|
+
], w = (h) => {
|
|
367
|
+
var R;
|
|
368
|
+
return ((R = t.fieldLabel) == null ? void 0 : R.call(t, h)) ?? Ne(h);
|
|
369
|
+
}, [T, ...U] = await Promise.all([
|
|
370
|
+
M(e, c(e)).then((h) => h ?? w(e)),
|
|
371
|
+
...l.map((h) => M(h, n[h]).then((R) => R ?? w(h)))
|
|
372
|
+
]);
|
|
373
|
+
return { value: T, context: U };
|
|
319
374
|
},
|
|
320
|
-
[
|
|
321
|
-
),
|
|
375
|
+
[c, x, M]
|
|
376
|
+
), be = a(
|
|
377
|
+
async (e) => {
|
|
378
|
+
const t = x(e);
|
|
379
|
+
return t ? (await d.request(Je(`/field-defaults/mine/${t.id}`)), y.current.delete(e) && (E.current.add(e), m()), await p.invalidateQueries({ queryKey: j(i) }), t) : null;
|
|
380
|
+
},
|
|
381
|
+
[d, p, i, x, m]
|
|
382
|
+
), ve = a(
|
|
322
383
|
async (e) => {
|
|
323
|
-
await
|
|
324
|
-
|
|
325
|
-
collection:
|
|
384
|
+
await d.request(
|
|
385
|
+
oe("/field-defaults/mine", {
|
|
386
|
+
collection: i,
|
|
326
387
|
field: e.field,
|
|
327
388
|
value: e.value,
|
|
328
389
|
context: e.context ?? {}
|
|
329
390
|
})
|
|
330
|
-
), await
|
|
391
|
+
), await p.invalidateQueries({ queryKey: j(i) });
|
|
331
392
|
},
|
|
332
|
-
[
|
|
333
|
-
),
|
|
393
|
+
[d, p, i]
|
|
394
|
+
), je = Ee(
|
|
334
395
|
() => ({
|
|
335
|
-
allowed: (e) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
396
|
+
allowed: (e) => (f.current.enabled ?? !0) && f.current.layoutAllows(e),
|
|
397
|
+
loaded: A !== void 0 || V,
|
|
398
|
+
failed: A === void 0 && V,
|
|
399
|
+
isNew: v,
|
|
400
|
+
defaultFor: x,
|
|
401
|
+
isDefault: we,
|
|
402
|
+
save: me,
|
|
403
|
+
update: he,
|
|
404
|
+
describeUpdate: ge,
|
|
405
|
+
clear: be,
|
|
406
|
+
restore: ve,
|
|
407
|
+
refresh: de,
|
|
408
|
+
hasValue: ye,
|
|
409
|
+
describeSave: pe,
|
|
343
410
|
applied: (e) => G.has(e),
|
|
344
|
-
hintFor:
|
|
345
|
-
undo:
|
|
411
|
+
hintFor: ne,
|
|
412
|
+
undo: re
|
|
346
413
|
}),
|
|
347
|
-
[
|
|
414
|
+
[
|
|
415
|
+
A,
|
|
416
|
+
V,
|
|
417
|
+
v,
|
|
418
|
+
x,
|
|
419
|
+
we,
|
|
420
|
+
me,
|
|
421
|
+
he,
|
|
422
|
+
ge,
|
|
423
|
+
be,
|
|
424
|
+
ve,
|
|
425
|
+
de,
|
|
426
|
+
ye,
|
|
427
|
+
pe,
|
|
428
|
+
G,
|
|
429
|
+
ne,
|
|
430
|
+
re
|
|
431
|
+
]
|
|
348
432
|
);
|
|
349
|
-
return { ledger: G, hintFor:
|
|
433
|
+
return { ledger: G, hintFor: ne, undo: re, onPersonChange: Ke, release: Ye, appliedNow: $e, context: je };
|
|
350
434
|
}
|
|
351
435
|
export {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
436
|
+
Ge as PersonalDefaultsContext,
|
|
437
|
+
lt as linksBeyond,
|
|
438
|
+
j as personalDefaultsKey,
|
|
439
|
+
q as sameDefaultValue,
|
|
440
|
+
ft as usePersonalDefaults,
|
|
441
|
+
it as usePersonalDefaultsApi
|
|
358
442
|
};
|