@nivaro/react 0.3.34 → 0.3.35

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,283 +1,309 @@
1
- import { useQueryClient as Le, useQuery as Ne } from "@tanstack/react-query";
2
- import { useRef as h, useMemo as Pe, useState as ne, useEffect as L, useCallback as a, createContext as Qe, useContext as ze } from "react";
3
- import { useNivaroClient as Te } from "../../context.js";
4
- import { get as Ye, del as Ee, put as Re } from "../../lib/commands.js";
5
- import { isEmptyValue as w, pickDefault as se, cascadeParents as V, orderTopDown as He, captureContext as Be } from "../../lib/personal-defaults.js";
6
- import { titleCase as Je } from "../../lib/utils.js";
7
- const We = Qe(null);
8
- function rt() {
9
- return ze(We);
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 N(u) {
12
- return ["field-defaults", u];
11
+ function j(o) {
12
+ return ["field-defaults", o];
13
13
  }
14
- function J(u) {
15
- return Array.isArray(u) ? u.map(J) : u && typeof u == "object" && "id" in u ? u.id : u;
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
- function S(u, f) {
18
- if (w(u) && w(f)) return !0;
19
- const m = (P) => {
20
- const x = J(P);
21
- return Array.isArray(x) ? x.map((b) => String(b)).sort() : String(x);
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(m(u)) === JSON.stringify(m(f));
40
+ return JSON.stringify(D(o)) === JSON.stringify(D(i));
24
41
  }
25
- function nt(u, f) {
26
- let m = 0;
27
- for (const [P, x] of u) {
28
- const b = f.get(P);
29
- for (const k of x) b != null && b.has(String(k)) || m++;
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 m;
48
+ return v;
32
49
  }
33
- function Ge(u) {
34
- return Array.isArray(u) ? u : w(u) ? [] : [u];
50
+ function tt(o) {
51
+ return Array.isArray(o) ? o : g(o) ? [] : [o];
35
52
  }
36
- function st(u) {
37
- const { collection: f, isNew: m, disabled: P, enabled: x = !0, ready: b = !0 } = u, k = Te(), F = Le(), d = h(u);
38
- d.current = u;
39
- const { data: Q } = Ne({
40
- queryKey: N(f),
41
- queryFn: () => k.request(Ye("/field-defaults/mine", { collection: f })).then((e) => e.data ?? []),
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: !!f && x
44
- }), z = Pe(() => {
60
+ enabled: !!i && S
61
+ }), H = Ee(() => {
45
62
  const e = /* @__PURE__ */ new Map();
46
- for (const t of Q ?? []) {
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
- }, [Q]), W = h(z);
52
- W.current = z;
53
- const i = h(/* @__PURE__ */ new Map()), [G, Me] = ne(() => /* @__PURE__ */ new Map()), v = h(/* @__PURE__ */ new Map()), [ce, qe] = ne(() => /* @__PURE__ */ new Map()), R = h(/* @__PURE__ */ new Set()), T = h(!0);
54
- L(() => (T.current = !0, () => {
55
- T.current = !1;
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 p = a(() => {
58
- T.current && (Me((e) => {
59
- const t = i.current;
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
- }), qe((e) => {
62
- const t = v.current;
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
- }, []), l = a((e) => {
82
+ }, []), c = a((e) => {
66
83
  var n;
67
- const t = d.current, r = (n = t.readValue) == null ? void 0 : n.call(t, e);
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
- }, []), A = a(
86
+ }, []), N = a(
70
87
  (e) => {
71
88
  const t = {};
72
- for (const r of e) t[r] = l(r);
89
+ for (const r of e) t[r] = c(r);
73
90
  return t;
74
91
  },
75
- [l]
92
+ [c]
76
93
  ), M = a(async (e, t) => {
77
- const r = d.current, s = (await Promise.all(
78
- Ge(J(t)).map(async (o) => {
79
- if (!r.valueLabel) return String(o);
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, o) ?? null;
98
+ return await r.valueLabel(e, l) ?? null;
82
99
  } catch {
83
100
  return null;
84
101
  }
85
102
  })
86
- )).filter((o) => !!o);
103
+ )).filter((l) => !!l);
87
104
  return s.length > 0 ? s.join(", ") : null;
88
- }, []), q = h(0), Y = a(
105
+ }, []), K = F(0), _ = a(
89
106
  async (e, t, r) => {
90
107
  const n = await t;
91
- q.current === r && (v.current.set(e, n), p());
108
+ K.current === r && (P.current.set(e, n), m());
92
109
  },
93
- [p]
94
- ), I = a(
110
+ [m]
111
+ ), X = a(
95
112
  async (e, t) => {
96
- var s, o;
97
- const r = ((o = (s = d.current).fieldLabel) == null ? void 0 : o.call(s, e)) ?? e, n = await M(e, t);
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
- ), E = a((e, t, r) => {
102
- const n = d.current;
103
- if (n.setFieldValue(e, t, r), w(t)) {
104
- i.current.delete(e);
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
- i.current.set(e, t), v.current.delete(e), n.markAutoFilled([e]);
108
- }, []), ue = a(
124
+ y.current.set(e, t), P.current.delete(e), n.markAutoFilled([e]);
125
+ }, []), ie = a(
109
126
  async (e, t) => {
110
- var ke, ve, be, Fe, xe, Ae;
111
- const r = d.current, n = () => q.current !== t, s = W.current.get(e) ?? [];
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 (R.current.has(e) || !(((ke = r.canFill) == null ? void 0 : ke.call(r, e)) ?? !0)) return [];
114
- const o = l(e), y = !w(o);
115
- if (y && !(((ve = r.replaceable) == null ? void 0 : ve.call(r, e, o)) ?? !1)) return [];
116
- const K = new Set(s.flatMap((c) => Object.keys(c.context ?? {}))), we = A(K), { pick: j, fillParents: te, blockedBy: C } = se(s, we);
117
- if (!j) {
118
- if (C) {
119
- const c = (be = s.find(
120
- (g) => g.context && C in g.context && !S(g.context[C], we[C])
121
- )) == null ? void 0 : be.context[C];
122
- await Y(e, I(C, c), t);
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 ge = V(e, r.rulesFor).reverse(), je = [
127
- ...ge.filter((c) => c in te),
128
- ...Object.keys(te).filter((c) => !ge.includes(c))
129
- ], re = [], O = () => {
130
- for (const [c, g] of re.reverse())
131
- S(l(c), g) ? E(c, null, g) : i.current.delete(c);
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 c of je) {
134
- const g = te[c], Se = r.layoutAllows(c) && !R.current.has(c) && (((Fe = r.canFill) == null ? void 0 : Fe.call(r, c)) ?? !0) ? await r.revalidate(c, g) : !1;
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 (Se === null)
137
- return O(), [];
138
- if (!Se || !w(l(c)))
139
- return O(), await Y(e, I(c, g), t), [];
140
- E(c, g), re.push([c, g]);
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 he = await r.revalidate(e, j.value);
159
+ const Fe = await r.revalidate(e, h.value);
143
160
  if (n()) return [];
144
- if (he === null)
145
- return O(), [];
146
- if (!he)
147
- return O(), await Y(
161
+ if (Fe === null)
162
+ return $(), [];
163
+ if (!Fe)
164
+ return $(), await _(
148
165
  e,
149
- M(e, j.value).then(
150
- (c) => c ? `Your default "${c}" is no longer available` : "Your saved default is no longer available"
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 (!S(l(e), o) || !(((xe = r.canFill) == null ? void 0 : xe.call(r, e)) ?? !0))
155
- return O(), [];
156
- const me = se(s, A(K));
157
- return ((Ae = me.pick) == null ? void 0 : Ae.id) !== j.id || Object.keys(me.fillParents).length > 0 ? (O(), "stale") : (E(e, j.value, y ? o : void 0), [...re.map(([c]) => c), e]);
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
- [l, A, Y, I, M, E]
160
- ), oe = a(
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 ue(e, t);
180
+ const n = await ie(e, t);
164
181
  if (n !== "stale") return n;
165
182
  }
166
183
  return [];
167
184
  },
168
- [ue]
169
- ), U = a(
185
+ [ie]
186
+ ), Z = a(
170
187
  async (e) => {
171
188
  var n, s;
172
- const t = q.current, r = /* @__PURE__ */ new Set();
173
- for (const o of e) {
174
- if (!T.current || q.current !== t) return;
175
- for (const y of await oe(o, t)) r.add(y);
176
- p();
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 (q.current === t) {
179
- for (const o of r)
180
- i.current.has(o) && ((s = (n = d.current).afterApply) == null || s.call(n, o, i.current.get(o)));
181
- p();
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
- [oe, p]
185
- ), X = a(() => {
186
- const e = d.current;
187
- return He(
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
- }, []), Z = h(!1);
192
- L(() => {
193
- !m || P || !b || Z.current || Q === void 0 || (Z.current = !0, U(X()));
194
- }, [m, P, b, Q, U, X]), L(() => {
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 i.current)
197
- S(l(t), r) || (i.current.delete(t), e = !0);
198
- for (const t of v.current.keys())
199
- w(l(t)) || (v.current.delete(t), e = !0);
200
- e && p();
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 D = h(/* @__PURE__ */ new Set()), $ = h(/* @__PURE__ */ new Map()), [Ce, Oe] = ne(0), Ve = a(
219
+ const L = F(/* @__PURE__ */ new Set()), Q = F(/* @__PURE__ */ new Map()), [Oe, Ve] = ce(0), Ke = a(
203
220
  (e) => {
204
- let t = i.current.delete(e);
205
- if (v.current.delete(e) && (t = !0), R.current.delete(e), $.current.delete(e), !d.current.isNew) {
206
- t && p();
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 = d.current.rulesFor;
210
- for (const [n, s] of [...i.current])
211
- V(n, r).includes(e) && ($.current.set(n, s), i.current.delete(n), t = !0);
212
- t && p(), D.current.add(e), Oe((n) => n + 1);
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
- [p]
231
+ [m]
215
232
  );
216
- L(() => {
217
- if (D.current.size === 0 || d.current.disabled) return;
218
- const e = [...D.current];
219
- D.current.clear();
220
- const t = new Map($.current);
221
- $.current.clear();
222
- const r = d.current, n = [];
223
- for (const s of X()) {
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 y = t.get(s), K = l(s);
226
- if (S(K, y)) r.setFieldValue(s, null, y);
227
- else if (!w(K)) continue;
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 o = V(s, r.rulesFor);
232
- e.some((y) => o.includes(y)) && v.current.has(s) && w(l(s)) && (v.current.delete(s), n.push(s));
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
- p(), n.length > 0 && U(n);
235
- }, [Ce]);
236
- const _ = a(
251
+ m(), n.length > 0 && Z(n);
252
+ }, [Oe]);
253
+ const re = a(
237
254
  (e) => {
238
- const t = d.current;
239
- if (!i.current.has(e)) return;
255
+ const t = f.current;
256
+ if (!y.current.has(e)) return;
240
257
  const r = [
241
258
  e,
242
- ...[...i.current.keys()].filter(
243
- (n) => n !== e && V(n, t.rulesFor).includes(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 = i.current.get(n);
248
- S(l(n), s) && t.setFieldValue(n, null, s), i.current.delete(n);
264
+ const s = y.current.get(n);
265
+ q(c(n), s) && t.setFieldValue(n, null, s), y.current.delete(n);
249
266
  }
250
- R.current.add(e), p();
267
+ E.current.add(e), m();
251
268
  },
252
- [l, p]
253
- ), De = a(
269
+ [c, m]
270
+ ), Ye = a(
254
271
  (e) => {
255
- if (!i.current.has(e)) return;
256
- const t = i.current.get(e);
257
- S(l(e), t) && d.current.setFieldValue(e, null, t), i.current.delete(e), R.current.add(e), p();
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
- [l, p]
260
- ), H = `${f}|${m ? "new" : "saved"}|${u.resetKey ?? ""}`, ae = h(H);
261
- L(() => {
262
- ae.current !== H && (ae.current = H, i.current.clear(), v.current.clear(), R.current.clear(), $.current.clear(), D.current.clear(), Z.current = !1, q.current += 1, p());
263
- }, [H, p]);
264
- const ee = a((e) => ce.get(e) ?? null, [ce]), $e = a(() => i.current, []), B = a(
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 = z.get(e) ?? [];
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 se(t, A(r)).pick;
286
+ return ue(t, N(r)).pick;
270
287
  },
271
- [z, A]
272
- ), le = a(() => {
273
- F.invalidateQueries({ queryKey: N(f) });
274
- }, [F, f]), ie = a(
275
- (e) => !w(l(e)),
276
- [l]
277
- ), fe = a(
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 = d.current, r = [
280
- ...[...V(e, t.rulesFor)].reverse().filter((n) => t.layoutAllows(n) && !w(l(n))),
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, l(n)) ?? ((s = t.fieldLabel) == null ? void 0 : s.call(t, n)) ?? Je(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
- [l, M]
294
- ), de = a(
319
+ [c, M]
320
+ ), me = a(
295
321
  async (e) => {
296
- const t = d.current, r = l(e);
297
- if (w(r)) throw new Error("Pick a value first");
298
- const n = V(e, t.rulesFor), s = A([e, ...n]), o = (y) => k.request(
299
- Re("/field-defaults/mine", {
300
- collection: f,
301
- field: y,
302
- value: J(s[y]),
303
- context: Be(y, s, t.rulesFor)
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 o(e);
308
- for (const y of [...n].reverse())
309
- t.layoutAllows(y) && !w(s[y]) && await o(y);
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 F.invalidateQueries({ queryKey: N(f) });
357
+ await p.invalidateQueries({ queryKey: j(i) });
312
358
  }
313
359
  },
314
- [k, F, f, l, A]
315
- ), ye = a(
360
+ [d, p, i, c, x]
361
+ ), ge = a(
316
362
  async (e) => {
317
- const t = B(e);
318
- return t ? (await k.request(Ee(`/field-defaults/mine/${t.id}`)), await F.invalidateQueries({ queryKey: N(f) }), t) : null;
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
- [k, F, f, B]
321
- ), pe = a(
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 k.request(
324
- Re("/field-defaults/mine", {
325
- collection: f,
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 F.invalidateQueries({ queryKey: N(f) });
391
+ ), await p.invalidateQueries({ queryKey: j(i) });
331
392
  },
332
- [k, F, f]
333
- ), Ke = Pe(
393
+ [d, p, i]
394
+ ), je = Ee(
334
395
  () => ({
335
- allowed: (e) => d.current.layoutAllows(e),
336
- defaultFor: B,
337
- save: de,
338
- clear: ye,
339
- restore: pe,
340
- refresh: le,
341
- hasValue: ie,
342
- describeSave: fe,
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: ee,
345
- undo: _
411
+ hintFor: ne,
412
+ undo: re
346
413
  }),
347
- [B, de, ye, pe, le, ie, fe, G, ee, _]
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: ee, undo: _, onPersonChange: Ve, release: De, appliedNow: $e, context: Ke };
433
+ return { ledger: G, hintFor: ne, undo: re, onPersonChange: Ke, release: Ye, appliedNow: $e, context: je };
350
434
  }
351
435
  export {
352
- We as PersonalDefaultsContext,
353
- nt as linksBeyond,
354
- N as personalDefaultsKey,
355
- S as sameDefaultValue,
356
- st as usePersonalDefaults,
357
- rt as usePersonalDefaultsApi
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
  };