@goodie-forms/core 1.2.5-alpha → 1.2.6-alpha

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.
Files changed (43) hide show
  1. package/dist/field/FieldPath.d.ts +18 -9
  2. package/dist/field/FieldPath.d.ts.map +1 -1
  3. package/dist/field/FieldPathBuilder.d.ts +2 -2
  4. package/dist/field/FieldPathBuilder.d.ts.map +1 -1
  5. package/dist/field/Reconcile.d.ts +2 -2
  6. package/dist/field/Reconcile.d.ts.map +1 -1
  7. package/dist/form/FormController.d.ts +51 -20
  8. package/dist/form/FormController.d.ts.map +1 -1
  9. package/dist/form/FormField.d.ts +15 -10
  10. package/dist/form/FormField.d.ts.map +1 -1
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +523 -476
  14. package/dist/index.js.map +1 -1
  15. package/dist/types/DeepHelpers.d.ts +11 -0
  16. package/dist/types/DeepHelpers.d.ts.map +1 -0
  17. package/dist/types/FormHelpers.d.ts +5 -0
  18. package/dist/types/FormHelpers.d.ts.map +1 -0
  19. package/dist/types/Suppliable.d.ts +3 -0
  20. package/dist/types/Suppliable.d.ts.map +1 -0
  21. package/dist/validation/CustomValidation.d.ts +1 -1
  22. package/package.json +13 -3
  23. package/src/field/FieldPath.spec.ts +204 -0
  24. package/src/field/FieldPath.ts +62 -59
  25. package/src/field/FieldPathBuilder.spec.ts +47 -0
  26. package/src/field/FieldPathBuilder.ts +15 -81
  27. package/src/field/Reconcile.ts +2 -2
  28. package/src/form/FormController.spec.ts +55 -0
  29. package/src/form/FormController.ts +151 -115
  30. package/src/form/FormField.ts +63 -30
  31. package/src/index.ts +2 -2
  32. package/src/types/DeepHelpers.ts +15 -0
  33. package/src/types/FormHelpers.ts +13 -0
  34. package/src/types/Suppliable.ts +7 -0
  35. package/src/validation/CustomValidation.ts +1 -1
  36. package/dist/form/NonullFormField.d.ts +0 -9
  37. package/dist/form/NonullFormField.d.ts.map +0 -1
  38. package/dist/types/DeepPartial.d.ts +0 -6
  39. package/dist/types/DeepPartial.d.ts.map +0 -1
  40. package/src/form/NonullFormField.ts +0 -15
  41. package/src/types/DeepPartial.ts +0 -7
  42. package/tsconfig.json +0 -8
  43. package/vite.config.ts +0 -18
package/dist/index.js CHANGED
@@ -1,177 +1,177 @@
1
1
  var h;
2
2
  ((t) => {
3
- function e(c) {
4
- return c.join(".");
5
- }
6
- t.toCanonicalPath = e;
7
- function i(c) {
8
- const a = r(c);
9
- let l = "";
3
+ function e(f) {
4
+ const a = r(f);
5
+ let u = "";
10
6
  for (const y of a)
11
- typeof y == "number" ? l += `[${y}]` : (l.length > 0 && (l += "."), l += y.toString());
12
- return l;
7
+ typeof y == "number" ? u += `[${y}]` : (u.length > 0 && (u += "."), u += y.toString());
8
+ return u;
13
9
  }
14
- t.toStringPath = i;
15
- function n(c) {
10
+ t.toStringPath = e;
11
+ function i(f) {
16
12
  const a = [];
17
- let l = 0;
18
- for (; l < c.length; ) {
19
- const y = c[l];
13
+ let u = 0;
14
+ for (; u < f.length; ) {
15
+ const y = f[u];
20
16
  if (y === ".") {
21
- l++;
17
+ u++;
22
18
  continue;
23
19
  }
24
20
  if (y === "[") {
25
- l++;
26
- let S = "";
27
- for (; l < c.length && c[l] !== "]"; )
28
- S += c[l], l++;
29
- if (l++, !S || !/^\d+$/.test(S))
30
- throw new Error(`Invalid array index in path: ${c}`);
31
- a.push(Number(S));
21
+ u++;
22
+ let V = "";
23
+ for (; u < f.length && f[u] !== "]"; )
24
+ V += f[u], u++;
25
+ if (u++, !V || !/^\d+$/.test(V))
26
+ throw new Error(`Invalid array index in path: ${f}`);
27
+ a.push(Number(V));
32
28
  continue;
33
29
  }
34
- let v = "";
35
- for (; l < c.length && /[^\.\[]/.test(c[l]); )
36
- v += c[l], l++;
37
- v && a.push(v);
30
+ let S = "";
31
+ for (; u < f.length && /[^\.\[]/.test(f[u]); )
32
+ S += f[u], u++;
33
+ S && a.push(S);
38
34
  }
39
35
  return a;
40
36
  }
41
- t.fromStringPath = n;
42
- function r(c) {
43
- return c?.map((a) => {
37
+ t.fromStringPath = i;
38
+ function r(f) {
39
+ return f?.map((a) => {
44
40
  if (typeof a == "string" || typeof a == "number" || typeof a == "symbol") return a;
45
41
  if (typeof a == "object" && "key" in a)
46
42
  return typeof a == "string" || typeof a == "number" || typeof a == "symbol" ? a : a.key;
47
43
  });
48
44
  }
49
45
  t.normalize = r;
50
- function s(c, a) {
51
- if (c === a) return !0;
52
- if (c == null || a == null || c.length !== a.length) return !1;
53
- for (let l = 0; l < c.length; l++)
54
- if (c[l] !== a[l]) return !1;
46
+ function n(f, a) {
47
+ if (f === a) return !0;
48
+ if (f == null || a == null || f.length !== a.length) return !1;
49
+ for (let u = 0; u < f.length; u++)
50
+ if (f[u] !== a[u]) return !1;
55
51
  return !0;
56
52
  }
57
- t.equals = s;
58
- function o(c, a) {
59
- if (c.length >= a.length) return !1;
60
- for (let l = 0; l < c.length; l++)
61
- if (c[l] !== a[l])
53
+ t.equals = n;
54
+ function s(f, a) {
55
+ if (f.length >= a.length) return !1;
56
+ for (let u = 0; u < f.length; u++)
57
+ if (f[u] !== a[u])
62
58
  return !1;
63
59
  return !0;
64
60
  }
65
- t.isDescendant = o;
66
- function f(c, a) {
67
- let l = c;
61
+ t.isDescendant = s;
62
+ function o(f, a, u) {
63
+ let y = f;
64
+ for (let V = 0; V < a.length - 1; V++) {
65
+ const Q = a[V], Ot = a[V + 1];
66
+ if (y[Q] == null) {
67
+ if (u?.returnOnEmptyBranch) return { target: null, key: null };
68
+ y[Q] = typeof Ot == "number" ? [] : {};
69
+ }
70
+ y = y[Q];
71
+ }
72
+ const S = a[a.length - 1];
73
+ return {
74
+ target: y,
75
+ key: S
76
+ };
77
+ }
78
+ t.walkPath = o;
79
+ function l(f, a) {
80
+ let u = f;
68
81
  for (const y of a) {
69
- if (l == null) return;
70
- l = l[y];
82
+ if (u == null) return;
83
+ u = u[y];
71
84
  }
72
- return l;
85
+ return u;
73
86
  }
74
- t.getValue = f;
75
- function d(c, a, l) {
76
- return t.modifyValue(c, a, () => l);
87
+ t.getValue = l;
88
+ function d(f, a, u) {
89
+ const { target: y, key: S } = o(f, a);
90
+ y[S] = u;
77
91
  }
78
92
  t.setValue = d;
79
- function u(c, a, l) {
80
- let y = c;
81
- for (let A = 0; A < a.length - 1; A++) {
82
- const Q = a[A], Ot = a[A + 1];
83
- y[Q] == null && (y[Q] = typeof Ot == "number" ? [] : {}), y = y[Q];
84
- }
85
- const v = a[a.length - 1], S = y[v], ht = l(S);
86
- ht !== void 0 && (y[v] = ht);
87
- }
88
- t.modifyValue = u;
89
- function _(c, a) {
90
- let l = c;
91
- for (let v = 0; v < a.length - 1; v++) {
92
- const S = a[v];
93
- if (l[S] == null) return;
94
- l = l[S];
95
- }
96
- const y = a[a.length - 1];
97
- delete l[y];
93
+ function c(f, a, u) {
94
+ const { target: y, key: S } = o(f, a);
95
+ u(y[S]);
96
+ }
97
+ t.modifyValue = c;
98
+ function _(f, a) {
99
+ const { target: u, key: y } = o(f, a, {
100
+ returnOnEmptyBranch: !0
101
+ });
102
+ y != null && delete u[y];
98
103
  }
99
104
  t.deleteValue = _;
100
105
  })(h || (h = {}));
101
- const _t = /* @__PURE__ */ Symbol("PathResolver");
102
- class et {
106
+ const dt = /* @__PURE__ */ Symbol("PathResolver");
107
+ class R {
103
108
  static wrap(e) {
104
109
  return new Proxy(e, {
105
- get(i, n, r) {
106
- if (n === _t) return e;
107
- const s = typeof n == "string" && /^\d+$/.test(n) ? Number(n) : n;
108
- return et.wrap([
110
+ get(i, r, n) {
111
+ if (r === dt) return e;
112
+ const s = typeof r == "string" && /^\d+$/.test(r) ? Number(r) : r;
113
+ return R.wrap([
109
114
  ...e,
110
115
  s
111
116
  ]);
112
117
  }
113
118
  });
114
119
  }
115
- fromStringPath(e) {
116
- return h.fromStringPath(
117
- e
118
- );
119
- }
120
- fromProxy(e) {
121
- return e(et.wrap([]))[_t];
120
+ of(e) {
121
+ return typeof e == "function" ? e(R.wrap([]))[dt] : h.fromStringPath(e);
122
122
  }
123
123
  }
124
- var V;
124
+ var v;
125
125
  ((t) => {
126
- function e(n, r, s) {
127
- if (n === r) return !0;
128
- if (n === null || r === null || typeof n != "object" || typeof r != "object") return !1;
129
- if (Array.isArray(n)) {
130
- if (!Array.isArray(r) || n.length !== r.length) return !1;
131
- for (let d = 0; d < n.length; d++)
132
- if (!e(n[d], r[d])) return !1;
126
+ function e(r, n, s) {
127
+ if (r === n) return !0;
128
+ if (r === null || n === null || typeof r != "object" || typeof n != "object") return !1;
129
+ if (Array.isArray(r)) {
130
+ if (!Array.isArray(n) || r.length !== n.length) return !1;
131
+ for (let d = 0; d < r.length; d++)
132
+ if (!e(r[d], n[d])) return !1;
133
133
  return !0;
134
134
  }
135
135
  if (s != null) {
136
- const d = s(n, r);
136
+ const d = s(r, n);
137
137
  if (d !== void 0) return d;
138
138
  }
139
- if (n instanceof Date && r instanceof Date)
140
- return n.getTime() === r.getTime();
141
- if (n instanceof RegExp && r instanceof RegExp)
142
- return n.source === r.source && n.flags === r.flags;
143
- if (n instanceof Map && r instanceof Map) {
144
- if (n.size !== r.size) return !1;
145
- for (const [d, u] of n)
146
- if (!r.has(d) || !e(u, r.get(d))) return !1;
139
+ if (r instanceof Date && n instanceof Date)
140
+ return r.getTime() === n.getTime();
141
+ if (r instanceof RegExp && n instanceof RegExp)
142
+ return r.source === n.source && r.flags === n.flags;
143
+ if (r instanceof Map && n instanceof Map) {
144
+ if (r.size !== n.size) return !1;
145
+ for (const [d, c] of r)
146
+ if (!n.has(d) || !e(c, n.get(d))) return !1;
147
147
  return !0;
148
148
  }
149
- if (n instanceof Set && r instanceof Set) {
150
- if (n.size !== r.size) return !1;
151
- for (const d of n)
152
- if (!r.has(d)) return !1;
149
+ if (r instanceof Set && n instanceof Set) {
150
+ if (r.size !== n.size) return !1;
151
+ for (const d of r)
152
+ if (!n.has(d)) return !1;
153
153
  return !0;
154
154
  }
155
- if (Object.getPrototypeOf(n) !== Object.getPrototypeOf(r))
155
+ if (Object.getPrototypeOf(r) !== Object.getPrototypeOf(n))
156
156
  return !1;
157
- const o = Object.keys(n), f = Object.keys(r);
158
- if (o.length !== f.length) return !1;
157
+ const o = Object.keys(r), l = Object.keys(n);
158
+ if (o.length !== l.length) return !1;
159
159
  for (const d of o)
160
- if (!Object.prototype.hasOwnProperty.call(r, d) || !e(n[d], r[d])) return !1;
160
+ if (!Object.prototype.hasOwnProperty.call(n, d) || !e(r[d], n[d])) return !1;
161
161
  return !0;
162
162
  }
163
163
  t.deepEqual = e;
164
- function i(n, r, s, o) {
165
- const f = [], d = [], u = [];
166
- for (const _ of r)
167
- n.some((c) => s(c, _)) ? (o?.(_) ?? !0) && u.push(_) : (o?.(_) ?? !0) && f.push(_);
164
+ function i(r, n, s, o) {
165
+ const l = [], d = [], c = [];
168
166
  for (const _ of n)
169
- r.some((c) => s(_, c)) || (o?.(_) ?? !0) && d.push(_);
170
- return { added: f, removed: d, unchanged: u };
167
+ r.some((f) => s(f, _)) ? (o?.(_) ?? !0) && c.push(_) : (o?.(_) ?? !0) && l.push(_);
168
+ for (const _ of r)
169
+ n.some((f) => s(_, f)) || (o?.(_) ?? !0) && d.push(_);
170
+ return { added: l, removed: d, unchanged: c };
171
171
  }
172
- t.diff = i;
173
- })(V || (V = {}));
174
- var Dt = /* @__PURE__ */ Symbol.for("immer-nothing"), x = /* @__PURE__ */ Symbol.for("immer-draftable"), m = /* @__PURE__ */ Symbol.for("immer-state"), At = process.env.NODE_ENV !== "production" ? [
172
+ t.arrayDiff = i;
173
+ })(v || (v = {}));
174
+ var Vt = /* @__PURE__ */ Symbol.for("immer-nothing"), x = /* @__PURE__ */ Symbol.for("immer-draftable"), g = /* @__PURE__ */ Symbol.for("immer-state"), It = process.env.NODE_ENV !== "production" ? [
175
175
  // All error codes, starting by 0:
176
176
  function(t) {
177
177
  return `The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`;
@@ -202,22 +202,22 @@ var Dt = /* @__PURE__ */ Symbol.for("immer-nothing"), x = /* @__PURE__ */ Symbol
202
202
  // Note: if more errors are added, the errorOffset in Patches.ts should be increased
203
203
  // See Patches.ts for additional errors
204
204
  ] : [];
205
- function g(t, ...e) {
205
+ function m(t, ...e) {
206
206
  if (process.env.NODE_ENV !== "production") {
207
- const i = At[t], n = b(i) ? i.apply(null, e) : i;
208
- throw new Error(`[Immer] ${n}`);
207
+ const i = It[t], r = E(i) ? i.apply(null, e) : i;
208
+ throw new Error(`[Immer] ${r}`);
209
209
  }
210
210
  throw new Error(
211
211
  `[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`
212
212
  );
213
213
  }
214
- var p = Object, F = p.getPrototypeOf, U = "constructor", W = "prototype", it = "configurable", j = "enumerable", M = "writable", C = "value", w = (t) => !!t && !!t[m];
215
- function D(t) {
216
- return t ? wt(t) || K(t) || !!t[x] || !!t[U]?.[x] || H(t) || Y(t) : !1;
214
+ var p = Object, F = p.getPrototypeOf, U = "constructor", W = "prototype", et = "configurable", q = "enumerable", A = "writable", z = "value", w = (t) => !!t && !!t[g];
215
+ function P(t) {
216
+ return t ? Dt(t) || K(t) || !!t[x] || !!t[U]?.[x] || H(t) || Y(t) : !1;
217
217
  }
218
- var Tt = p[W][U].toString(), yt = /* @__PURE__ */ new WeakMap();
219
- function wt(t) {
220
- if (!t || !ft(t))
218
+ var Tt = p[W][U].toString(), ht = /* @__PURE__ */ new WeakMap();
219
+ function Dt(t) {
220
+ if (!t || !lt(t))
221
221
  return !1;
222
222
  const e = F(t);
223
223
  if (e === null || e === p[W])
@@ -225,35 +225,35 @@ function wt(t) {
225
225
  const i = p.hasOwnProperty.call(e, U) && e[U];
226
226
  if (i === Object)
227
227
  return !0;
228
- if (!b(i))
228
+ if (!E(i))
229
229
  return !1;
230
- let n = yt.get(i);
231
- return n === void 0 && (n = Function.toString.call(i), yt.set(i, n)), n === Tt;
230
+ let r = ht.get(i);
231
+ return r === void 0 && (r = Function.toString.call(i), ht.set(i, r)), r === Tt;
232
232
  }
233
233
  function G(t, e, i = !0) {
234
- O(t) === 0 ? (i ? Reflect.ownKeys(t) : p.keys(t)).forEach((r) => {
235
- e(r, t[r], t);
236
- }) : t.forEach((n, r) => e(r, n, t));
234
+ I(t) === 0 ? (i ? Reflect.ownKeys(t) : p.keys(t)).forEach((n) => {
235
+ e(n, t[n], t);
236
+ }) : t.forEach((r, n) => e(n, r, t));
237
237
  }
238
- function O(t) {
239
- const e = t[m];
238
+ function I(t) {
239
+ const e = t[g];
240
240
  return e ? e.type_ : K(t) ? 1 : H(t) ? 2 : Y(t) ? 3 : 0;
241
241
  }
242
- var mt = (t, e, i = O(t)) => i === 2 ? t.has(e) : p[W].hasOwnProperty.call(t, e), nt = (t, e, i = O(t)) => (
242
+ var _t = (t, e, i = I(t)) => i === 2 ? t.has(e) : p[W].hasOwnProperty.call(t, e), it = (t, e, i = I(t)) => (
243
243
  // @ts-ignore
244
244
  i === 2 ? t.get(e) : t[e]
245
- ), q = (t, e, i, n = O(t)) => {
246
- n === 2 ? t.set(e, i) : n === 3 ? t.add(i) : t[e] = i;
245
+ ), B = (t, e, i, r = I(t)) => {
246
+ r === 2 ? t.set(e, i) : r === 3 ? t.add(i) : t[e] = i;
247
247
  };
248
- function Mt(t, e) {
248
+ function At(t, e) {
249
249
  return t === e ? t !== 0 || 1 / t === 1 / e : t !== t && e !== e;
250
250
  }
251
- var K = Array.isArray, H = (t) => t instanceof Map, Y = (t) => t instanceof Set, ft = (t) => typeof t == "object", b = (t) => typeof t == "function", Z = (t) => typeof t == "boolean";
252
- function Nt(t) {
251
+ var K = Array.isArray, H = (t) => t instanceof Map, Y = (t) => t instanceof Set, lt = (t) => typeof t == "object", E = (t) => typeof t == "function", Z = (t) => typeof t == "boolean";
252
+ function Mt(t) {
253
253
  const e = +t;
254
254
  return Number.isInteger(e) && String(e) === t;
255
255
  }
256
- var P = (t) => t.copy_ || t.base_, ct = (t) => t.modified_ ? t.copy_ : t.base_;
256
+ var D = (t) => t.copy_ || t.base_, ft = (t) => t.modified_ ? t.copy_ : t.base_;
257
257
  function rt(t, e) {
258
258
  if (H(t))
259
259
  return new Map(t);
@@ -261,59 +261,59 @@ function rt(t, e) {
261
261
  return new Set(t);
262
262
  if (K(t))
263
263
  return Array[W].slice.call(t);
264
- const i = wt(t);
264
+ const i = Dt(t);
265
265
  if (e === !0 || e === "class_only" && !i) {
266
- const n = p.getOwnPropertyDescriptors(t);
267
- delete n[m];
268
- let r = Reflect.ownKeys(n);
269
- for (let s = 0; s < r.length; s++) {
270
- const o = r[s], f = n[o];
271
- f[M] === !1 && (f[M] = !0, f[it] = !0), (f.get || f.set) && (n[o] = {
272
- [it]: !0,
273
- [M]: !0,
266
+ const r = p.getOwnPropertyDescriptors(t);
267
+ delete r[g];
268
+ let n = Reflect.ownKeys(r);
269
+ for (let s = 0; s < n.length; s++) {
270
+ const o = n[s], l = r[o];
271
+ l[A] === !1 && (l[A] = !0, l[et] = !0), (l.get || l.set) && (r[o] = {
272
+ [et]: !0,
273
+ [A]: !0,
274
274
  // could live with !!desc.set as well here...
275
- [j]: f[j],
276
- [C]: t[o]
275
+ [q]: l[q],
276
+ [z]: t[o]
277
277
  });
278
278
  }
279
- return p.create(F(t), n);
279
+ return p.create(F(t), r);
280
280
  } else {
281
- const n = F(t);
282
- if (n !== null && i)
281
+ const r = F(t);
282
+ if (r !== null && i)
283
283
  return { ...t };
284
- const r = p.create(n);
285
- return p.assign(r, t);
284
+ const n = p.create(r);
285
+ return p.assign(n, t);
286
286
  }
287
287
  }
288
- function dt(t, e = !1) {
289
- return X(t) || w(t) || !D(t) || (O(t) > 1 && p.defineProperties(t, {
288
+ function ct(t, e = !1) {
289
+ return X(t) || w(t) || !P(t) || (I(t) > 1 && p.defineProperties(t, {
290
290
  set: T,
291
291
  add: T,
292
292
  clear: T,
293
293
  delete: T
294
294
  }), p.freeze(t), e && G(
295
295
  t,
296
- (i, n) => {
297
- dt(n, !0);
296
+ (i, r) => {
297
+ ct(r, !0);
298
298
  },
299
299
  !1
300
300
  )), t;
301
301
  }
302
- function Rt() {
303
- g(2);
302
+ function Nt() {
303
+ m(2);
304
304
  }
305
305
  var T = {
306
- [C]: Rt
306
+ [z]: Nt
307
307
  };
308
308
  function X(t) {
309
- return t === null || !ft(t) ? !0 : p.isFrozen(t);
309
+ return t === null || !lt(t) ? !0 : p.isFrozen(t);
310
310
  }
311
- var B = "MapSet", st = "Patches", gt = "ArrayMethods", bt = {};
312
- function E(t) {
313
- const e = bt[t];
314
- return e || g(0, t), e;
311
+ var j = "MapSet", nt = "Patches", yt = "ArrayMethods", Pt = {};
312
+ function k(t) {
313
+ const e = Pt[t];
314
+ return e || m(0, t), e;
315
315
  }
316
- var pt = (t) => !!bt[t], k, Et = () => k, xt = (t, e) => ({
316
+ var gt = (t) => !!Pt[t], C, wt = () => C, Rt = (t, e) => ({
317
317
  drafts_: [],
318
318
  parent_: t,
319
319
  immer_: e,
@@ -323,42 +323,42 @@ var pt = (t) => !!bt[t], k, Et = () => k, xt = (t, e) => ({
323
323
  unfinalizedDrafts_: 0,
324
324
  handledSet_: /* @__PURE__ */ new Set(),
325
325
  processedForPatches_: /* @__PURE__ */ new Set(),
326
- mapSetPlugin_: pt(B) ? E(B) : void 0,
327
- arrayMethodsPlugin_: pt(gt) ? E(gt) : void 0
326
+ mapSetPlugin_: gt(j) ? k(j) : void 0,
327
+ arrayMethodsPlugin_: gt(yt) ? k(yt) : void 0
328
328
  });
329
- function vt(t, e) {
330
- e && (t.patchPlugin_ = E(st), t.patches_ = [], t.inversePatches_ = [], t.patchListener_ = e);
329
+ function mt(t, e) {
330
+ e && (t.patchPlugin_ = k(nt), t.patches_ = [], t.inversePatches_ = [], t.patchListener_ = e);
331
331
  }
332
- function ot(t) {
333
- at(t), t.drafts_.forEach(Ut), t.drafts_ = null;
332
+ function st(t) {
333
+ ot(t), t.drafts_.forEach(xt), t.drafts_ = null;
334
334
  }
335
- function at(t) {
336
- t === k && (k = t.parent_);
335
+ function ot(t) {
336
+ t === C && (C = t.parent_);
337
337
  }
338
- var St = (t) => k = xt(k, t);
339
- function Ut(t) {
340
- const e = t[m];
338
+ var pt = (t) => C = Rt(C, t);
339
+ function xt(t) {
340
+ const e = t[g];
341
341
  e.type_ === 0 || e.type_ === 1 ? e.revoke_() : e.revoked_ = !0;
342
342
  }
343
- function Pt(t, e) {
343
+ function vt(t, e) {
344
344
  e.unfinalizedDrafts_ = e.drafts_.length;
345
345
  const i = e.drafts_[0];
346
346
  if (t !== void 0 && t !== i) {
347
- i[m].modified_ && (ot(e), g(4)), D(t) && (t = Vt(e, t));
348
- const { patchPlugin_: r } = e;
349
- r && r.generateReplacementPatches_(
350
- i[m].base_,
347
+ i[g].modified_ && (st(e), m(4)), P(t) && (t = St(e, t));
348
+ const { patchPlugin_: n } = e;
349
+ n && n.generateReplacementPatches_(
350
+ i[g].base_,
351
351
  t,
352
352
  e
353
353
  );
354
354
  } else
355
- t = Vt(e, i);
356
- return jt(e, t, !0), ot(e), e.patches_ && e.patchListener_(e.patches_, e.inversePatches_), t !== Dt ? t : void 0;
355
+ t = St(e, i);
356
+ return Ut(e, t, !0), st(e), e.patches_ && e.patchListener_(e.patches_, e.inversePatches_), t !== Vt ? t : void 0;
357
357
  }
358
- function Vt(t, e) {
358
+ function St(t, e) {
359
359
  if (X(e))
360
360
  return e;
361
- const i = e[m];
361
+ const i = e[g];
362
362
  if (!i)
363
363
  return $(e, t.handledSet_, t);
364
364
  if (!J(i, t))
@@ -366,94 +366,94 @@ function Vt(t, e) {
366
366
  if (!i.modified_)
367
367
  return i.base_;
368
368
  if (!i.finalized_) {
369
- const { callbacks_: n } = i;
370
- if (n)
371
- for (; n.length > 0; )
372
- n.pop()(t);
373
- Ct(i, t);
369
+ const { callbacks_: r } = i;
370
+ if (r)
371
+ for (; r.length > 0; )
372
+ r.pop()(t);
373
+ bt(i, t);
374
374
  }
375
375
  return i.copy_;
376
376
  }
377
- function jt(t, e, i = !1) {
378
- !t.parent_ && t.immer_.autoFreeze_ && t.canAutoFreeze_ && dt(e, i);
377
+ function Ut(t, e, i = !1) {
378
+ !t.parent_ && t.immer_.autoFreeze_ && t.canAutoFreeze_ && ct(e, i);
379
379
  }
380
- function Ft(t) {
380
+ function Et(t) {
381
381
  t.finalized_ = !0, t.scope_.unfinalizedDrafts_--;
382
382
  }
383
383
  var J = (t, e) => t.scope_ === e, qt = [];
384
- function zt(t, e, i, n) {
385
- const r = P(t), s = t.type_;
386
- if (n !== void 0 && nt(r, n, s) === e) {
387
- q(r, n, i, s);
384
+ function kt(t, e, i, r) {
385
+ const n = D(t), s = t.type_;
386
+ if (r !== void 0 && it(n, r, s) === e) {
387
+ B(n, r, i, s);
388
388
  return;
389
389
  }
390
390
  if (!t.draftLocations_) {
391
- const f = t.draftLocations_ = /* @__PURE__ */ new Map();
392
- G(r, (d, u) => {
393
- if (w(u)) {
394
- const _ = f.get(u) || [];
395
- _.push(d), f.set(u, _);
391
+ const l = t.draftLocations_ = /* @__PURE__ */ new Map();
392
+ G(n, (d, c) => {
393
+ if (w(c)) {
394
+ const _ = l.get(c) || [];
395
+ _.push(d), l.set(c, _);
396
396
  }
397
397
  });
398
398
  }
399
399
  const o = t.draftLocations_.get(e) ?? qt;
400
- for (const f of o)
401
- q(r, f, i, s);
400
+ for (const l of o)
401
+ B(n, l, i, s);
402
402
  }
403
403
  function Bt(t, e, i) {
404
- t.callbacks_.push(function(r) {
404
+ t.callbacks_.push(function(n) {
405
405
  const s = e;
406
- if (!s || !J(s, r))
406
+ if (!s || !J(s, n))
407
407
  return;
408
- r.mapSetPlugin_?.fixSetContents(s);
409
- const o = ct(s);
410
- zt(t, s.draft_ ?? s, o, i), Ct(s, r);
408
+ n.mapSetPlugin_?.fixSetContents(s);
409
+ const o = ft(s);
410
+ kt(t, s.draft_ ?? s, o, i), bt(s, n);
411
411
  });
412
412
  }
413
- function Ct(t, e) {
413
+ function bt(t, e) {
414
414
  if (t.modified_ && !t.finalized_ && (t.type_ === 3 || t.type_ === 1 && t.allIndicesReassigned_ || (t.assigned_?.size ?? 0) > 0)) {
415
- const { patchPlugin_: n } = e;
416
- if (n) {
417
- const r = n.getPath(t);
418
- r && n.generatePatches_(t, r, e);
415
+ const { patchPlugin_: r } = e;
416
+ if (r) {
417
+ const n = r.getPath(t);
418
+ n && r.generatePatches_(t, n, e);
419
419
  }
420
- Ft(t);
420
+ Et(t);
421
421
  }
422
422
  }
423
- function $t(t, e, i) {
424
- const { scope_: n } = t;
423
+ function jt(t, e, i) {
424
+ const { scope_: r } = t;
425
425
  if (w(i)) {
426
- const r = i[m];
427
- J(r, n) && r.callbacks_.push(function() {
428
- N(t);
429
- const o = ct(r);
430
- zt(t, i, o, e);
426
+ const n = i[g];
427
+ J(n, r) && n.callbacks_.push(function() {
428
+ M(t);
429
+ const o = ft(n);
430
+ kt(t, i, o, e);
431
431
  });
432
- } else D(i) && t.callbacks_.push(function() {
433
- const s = P(t);
434
- t.type_ === 3 ? s.has(i) && $(i, n.handledSet_, n) : nt(s, e, t.type_) === i && n.drafts_.length > 1 && (t.assigned_.get(e) ?? !1) === !0 && t.copy_ && $(
435
- nt(t.copy_, e, t.type_),
436
- n.handledSet_,
437
- n
432
+ } else P(i) && t.callbacks_.push(function() {
433
+ const s = D(t);
434
+ t.type_ === 3 ? s.has(i) && $(i, r.handledSet_, r) : it(s, e, t.type_) === i && r.drafts_.length > 1 && (t.assigned_.get(e) ?? !1) === !0 && t.copy_ && $(
435
+ it(t.copy_, e, t.type_),
436
+ r.handledSet_,
437
+ r
438
438
  );
439
439
  });
440
440
  }
441
441
  function $(t, e, i) {
442
- return !i.immer_.autoFreeze_ && i.unfinalizedDrafts_ < 1 || w(t) || e.has(t) || !D(t) || X(t) || (e.add(t), G(t, (n, r) => {
443
- if (w(r)) {
444
- const s = r[m];
442
+ return !i.immer_.autoFreeze_ && i.unfinalizedDrafts_ < 1 || w(t) || e.has(t) || !P(t) || X(t) || (e.add(t), G(t, (r, n) => {
443
+ if (w(n)) {
444
+ const s = n[g];
445
445
  if (J(s, i)) {
446
- const o = ct(s);
447
- q(t, n, o, t.type_), Ft(s);
446
+ const o = ft(s);
447
+ B(t, r, o, t.type_), Et(s);
448
448
  }
449
- } else D(r) && $(r, e, i);
449
+ } else P(n) && $(n, e, i);
450
450
  })), t;
451
451
  }
452
- function Lt(t, e) {
453
- const i = K(t), n = {
452
+ function $t(t, e) {
453
+ const i = K(t), r = {
454
454
  type_: i ? 1 : 0,
455
455
  // Track which produce call this is associated with.
456
- scope_: e ? e.scope_ : Et(),
456
+ scope_: e ? e.scope_ : wt(),
457
457
  // True for both shallow and deep changes.
458
458
  modified_: !1,
459
459
  // Used during finalization.
@@ -476,177 +476,177 @@ function Lt(t, e) {
476
476
  // `callbacks` actually gets assigned in `createProxy`
477
477
  callbacks_: void 0
478
478
  };
479
- let r = n, s = L;
480
- i && (r = [n], s = I);
481
- const { revoke: o, proxy: f } = Proxy.revocable(r, s);
482
- return n.draft_ = f, n.revoke_ = o, [f, n];
479
+ let n = r, s = L;
480
+ i && (n = [r], s = O);
481
+ const { revoke: o, proxy: l } = Proxy.revocable(n, s);
482
+ return r.draft_ = l, r.revoke_ = o, [l, r];
483
483
  }
484
484
  var L = {
485
485
  get(t, e) {
486
- if (e === m)
486
+ if (e === g)
487
487
  return t;
488
488
  let i = t.scope_.arrayMethodsPlugin_;
489
- const n = t.type_ === 1 && typeof e == "string";
490
- if (n && i?.isArrayOperationMethod(e))
489
+ const r = t.type_ === 1 && typeof e == "string";
490
+ if (r && i?.isArrayOperationMethod(e))
491
491
  return i.createMethodInterceptor(t, e);
492
- const r = P(t);
493
- if (!mt(r, e, t.type_))
494
- return Wt(t, r, e);
495
- const s = r[e];
496
- if (t.finalized_ || !D(s) || n && t.operationMethod && i?.isMutatingArrayMethod(
492
+ const n = D(t);
493
+ if (!_t(n, e, t.type_))
494
+ return Lt(t, n, e);
495
+ const s = n[e];
496
+ if (t.finalized_ || !P(s) || r && t.operationMethod && i?.isMutatingArrayMethod(
497
497
  t.operationMethod
498
- ) && Nt(e))
498
+ ) && Mt(e))
499
499
  return s;
500
500
  if (s === tt(t.base_, e)) {
501
- N(t);
502
- const o = t.type_ === 1 ? +e : e, f = ut(t.scope_, s, t, o);
503
- return t.copy_[o] = f;
501
+ M(t);
502
+ const o = t.type_ === 1 ? +e : e, l = ut(t.scope_, s, t, o);
503
+ return t.copy_[o] = l;
504
504
  }
505
505
  return s;
506
506
  },
507
507
  has(t, e) {
508
- return e in P(t);
508
+ return e in D(t);
509
509
  },
510
510
  ownKeys(t) {
511
- return Reflect.ownKeys(P(t));
511
+ return Reflect.ownKeys(D(t));
512
512
  },
513
513
  set(t, e, i) {
514
- const n = kt(P(t), e);
515
- if (n?.set)
516
- return n.set.call(t.draft_, i), !0;
514
+ const r = Ft(D(t), e);
515
+ if (r?.set)
516
+ return r.set.call(t.draft_, i), !0;
517
517
  if (!t.modified_) {
518
- const r = tt(P(t), e), s = r?.[m];
518
+ const n = tt(D(t), e), s = n?.[g];
519
519
  if (s && s.base_ === i)
520
520
  return t.copy_[e] = i, t.assigned_.set(e, !1), !0;
521
- if (Mt(i, r) && (i !== void 0 || mt(t.base_, e, t.type_)))
521
+ if (At(i, n) && (i !== void 0 || _t(t.base_, e, t.type_)))
522
522
  return !0;
523
- N(t), lt(t);
523
+ M(t), at(t);
524
524
  }
525
525
  return t.copy_[e] === i && // special case: handle new props with value 'undefined'
526
526
  (i !== void 0 || e in t.copy_) || // special case: NaN
527
- Number.isNaN(i) && Number.isNaN(t.copy_[e]) || (t.copy_[e] = i, t.assigned_.set(e, !0), $t(t, e, i)), !0;
527
+ Number.isNaN(i) && Number.isNaN(t.copy_[e]) || (t.copy_[e] = i, t.assigned_.set(e, !0), jt(t, e, i)), !0;
528
528
  },
529
529
  deleteProperty(t, e) {
530
- return N(t), tt(t.base_, e) !== void 0 || e in t.base_ ? (t.assigned_.set(e, !1), lt(t)) : t.assigned_.delete(e), t.copy_ && delete t.copy_[e], !0;
530
+ return M(t), tt(t.base_, e) !== void 0 || e in t.base_ ? (t.assigned_.set(e, !1), at(t)) : t.assigned_.delete(e), t.copy_ && delete t.copy_[e], !0;
531
531
  },
532
532
  // Note: We never coerce `desc.value` into an Immer draft, because we can't make
533
533
  // the same guarantee in ES5 mode.
534
534
  getOwnPropertyDescriptor(t, e) {
535
- const i = P(t), n = Reflect.getOwnPropertyDescriptor(i, e);
536
- return n && {
537
- [M]: !0,
538
- [it]: t.type_ !== 1 || e !== "length",
539
- [j]: n[j],
540
- [C]: i[e]
535
+ const i = D(t), r = Reflect.getOwnPropertyDescriptor(i, e);
536
+ return r && {
537
+ [A]: !0,
538
+ [et]: t.type_ !== 1 || e !== "length",
539
+ [q]: r[q],
540
+ [z]: i[e]
541
541
  };
542
542
  },
543
543
  defineProperty() {
544
- g(11);
544
+ m(11);
545
545
  },
546
546
  getPrototypeOf(t) {
547
547
  return F(t.base_);
548
548
  },
549
549
  setPrototypeOf() {
550
- g(12);
550
+ m(12);
551
551
  }
552
- }, I = {};
552
+ }, O = {};
553
553
  for (let t in L) {
554
554
  let e = L[t];
555
- I[t] = function() {
555
+ O[t] = function() {
556
556
  const i = arguments;
557
557
  return i[0] = i[0][0], e.apply(this, i);
558
558
  };
559
559
  }
560
- I.deleteProperty = function(t, e) {
561
- return process.env.NODE_ENV !== "production" && isNaN(parseInt(e)) && g(13), I.set.call(this, t, e, void 0);
560
+ O.deleteProperty = function(t, e) {
561
+ return process.env.NODE_ENV !== "production" && isNaN(parseInt(e)) && m(13), O.set.call(this, t, e, void 0);
562
562
  };
563
- I.set = function(t, e, i) {
564
- return process.env.NODE_ENV !== "production" && e !== "length" && isNaN(parseInt(e)) && g(14), L.set.call(this, t[0], e, i, t[0]);
563
+ O.set = function(t, e, i) {
564
+ return process.env.NODE_ENV !== "production" && e !== "length" && isNaN(parseInt(e)) && m(14), L.set.call(this, t[0], e, i, t[0]);
565
565
  };
566
566
  function tt(t, e) {
567
- const i = t[m];
568
- return (i ? P(i) : t)[e];
567
+ const i = t[g];
568
+ return (i ? D(i) : t)[e];
569
569
  }
570
- function Wt(t, e, i) {
571
- const n = kt(e, i);
572
- return n ? C in n ? n[C] : (
570
+ function Lt(t, e, i) {
571
+ const r = Ft(e, i);
572
+ return r ? z in r ? r[z] : (
573
573
  // This is a very special case, if the prop is a getter defined by the
574
574
  // prototype, we should invoke it with the draft as context!
575
- n.get?.call(t.draft_)
575
+ r.get?.call(t.draft_)
576
576
  ) : void 0;
577
577
  }
578
- function kt(t, e) {
578
+ function Ft(t, e) {
579
579
  if (!(e in t))
580
580
  return;
581
581
  let i = F(t);
582
582
  for (; i; ) {
583
- const n = Object.getOwnPropertyDescriptor(i, e);
584
- if (n)
585
- return n;
583
+ const r = Object.getOwnPropertyDescriptor(i, e);
584
+ if (r)
585
+ return r;
586
586
  i = F(i);
587
587
  }
588
588
  }
589
- function lt(t) {
590
- t.modified_ || (t.modified_ = !0, t.parent_ && lt(t.parent_));
589
+ function at(t) {
590
+ t.modified_ || (t.modified_ = !0, t.parent_ && at(t.parent_));
591
591
  }
592
- function N(t) {
592
+ function M(t) {
593
593
  t.copy_ || (t.assigned_ = /* @__PURE__ */ new Map(), t.copy_ = rt(
594
594
  t.base_,
595
595
  t.scope_.immer_.useStrictShallowCopy_
596
596
  ));
597
597
  }
598
- var Gt = class {
598
+ var Wt = class {
599
599
  constructor(t) {
600
- this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1, this.produce = (e, i, n) => {
601
- if (b(e) && !b(i)) {
600
+ this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1, this.produce = (e, i, r) => {
601
+ if (E(e) && !E(i)) {
602
602
  const s = i;
603
603
  i = e;
604
604
  const o = this;
605
- return function(d = s, ...u) {
606
- return o.produce(d, (_) => i.call(this, _, ...u));
605
+ return function(d = s, ...c) {
606
+ return o.produce(d, (_) => i.call(this, _, ...c));
607
607
  };
608
608
  }
609
- b(i) || g(6), n !== void 0 && !b(n) && g(7);
610
- let r;
611
- if (D(e)) {
612
- const s = St(this), o = ut(s, e, void 0);
613
- let f = !0;
609
+ E(i) || m(6), r !== void 0 && !E(r) && m(7);
610
+ let n;
611
+ if (P(e)) {
612
+ const s = pt(this), o = ut(s, e, void 0);
613
+ let l = !0;
614
614
  try {
615
- r = i(o), f = !1;
615
+ n = i(o), l = !1;
616
616
  } finally {
617
- f ? ot(s) : at(s);
617
+ l ? st(s) : ot(s);
618
618
  }
619
- return vt(s, n), Pt(r, s);
620
- } else if (!e || !ft(e)) {
621
- if (r = i(e), r === void 0 && (r = e), r === Dt && (r = void 0), this.autoFreeze_ && dt(r, !0), n) {
619
+ return mt(s, r), vt(n, s);
620
+ } else if (!e || !lt(e)) {
621
+ if (n = i(e), n === void 0 && (n = e), n === Vt && (n = void 0), this.autoFreeze_ && ct(n, !0), r) {
622
622
  const s = [], o = [];
623
- E(st).generateReplacementPatches_(e, r, {
623
+ k(nt).generateReplacementPatches_(e, n, {
624
624
  patches_: s,
625
625
  inversePatches_: o
626
- }), n(s, o);
626
+ }), r(s, o);
627
627
  }
628
- return r;
628
+ return n;
629
629
  } else
630
- g(1, e);
630
+ m(1, e);
631
631
  }, this.produceWithPatches = (e, i) => {
632
- if (b(e))
633
- return (o, ...f) => this.produceWithPatches(o, (d) => e(d, ...f));
634
- let n, r;
635
- return [this.produce(e, i, (o, f) => {
636
- n = o, r = f;
637
- }), n, r];
632
+ if (E(e))
633
+ return (o, ...l) => this.produceWithPatches(o, (d) => e(d, ...l));
634
+ let r, n;
635
+ return [this.produce(e, i, (o, l) => {
636
+ r = o, n = l;
637
+ }), r, n];
638
638
  }, Z(t?.autoFreeze) && this.setAutoFreeze(t.autoFreeze), Z(t?.useStrictShallowCopy) && this.setUseStrictShallowCopy(t.useStrictShallowCopy), Z(t?.useStrictIteration) && this.setUseStrictIteration(t.useStrictIteration);
639
639
  }
640
640
  createDraft(t) {
641
- D(t) || g(8), w(t) && (t = Kt(t));
642
- const e = St(this), i = ut(e, t, void 0);
643
- return i[m].isManual_ = !0, at(e), i;
641
+ P(t) || m(8), w(t) && (t = Gt(t));
642
+ const e = pt(this), i = ut(e, t, void 0);
643
+ return i[g].isManual_ = !0, ot(e), i;
644
644
  }
645
645
  finishDraft(t, e) {
646
- const i = t && t[m];
647
- (!i || !i.isManual_) && g(9);
648
- const { scope_: n } = i;
649
- return vt(n, e), Pt(void 0, n);
646
+ const i = t && t[g];
647
+ (!i || !i.isManual_) && m(9);
648
+ const { scope_: r } = i;
649
+ return mt(r, e), vt(void 0, r);
650
650
  }
651
651
  /**
652
652
  * Pass true to automatically freeze all copies created by Immer.
@@ -679,55 +679,55 @@ var Gt = class {
679
679
  applyPatches(t, e) {
680
680
  let i;
681
681
  for (i = e.length - 1; i >= 0; i--) {
682
- const r = e[i];
683
- if (r.path.length === 0 && r.op === "replace") {
684
- t = r.value;
682
+ const n = e[i];
683
+ if (n.path.length === 0 && n.op === "replace") {
684
+ t = n.value;
685
685
  break;
686
686
  }
687
687
  }
688
688
  i > -1 && (e = e.slice(i + 1));
689
- const n = E(st).applyPatches_;
690
- return w(t) ? n(t, e) : this.produce(
689
+ const r = k(nt).applyPatches_;
690
+ return w(t) ? r(t, e) : this.produce(
691
691
  t,
692
- (r) => n(r, e)
692
+ (n) => r(n, e)
693
693
  );
694
694
  }
695
695
  };
696
- function ut(t, e, i, n) {
697
- const [r, s] = H(e) ? E(B).proxyMap_(e, i) : Y(e) ? E(B).proxySet_(e, i) : Lt(e, i);
698
- return (i?.scope_ ?? Et()).drafts_.push(r), s.callbacks_ = i?.callbacks_ ?? [], s.key_ = n, i && n !== void 0 ? Bt(i, s, n) : s.callbacks_.push(function(d) {
696
+ function ut(t, e, i, r) {
697
+ const [n, s] = H(e) ? k(j).proxyMap_(e, i) : Y(e) ? k(j).proxySet_(e, i) : $t(e, i);
698
+ return (i?.scope_ ?? wt()).drafts_.push(n), s.callbacks_ = i?.callbacks_ ?? [], s.key_ = r, i && r !== void 0 ? Bt(i, s, r) : s.callbacks_.push(function(d) {
699
699
  d.mapSetPlugin_?.fixSetContents(s);
700
- const { patchPlugin_: u } = d;
701
- s.modified_ && u && u.generatePatches_(s, [], d);
702
- }), r;
700
+ const { patchPlugin_: c } = d;
701
+ s.modified_ && c && c.generatePatches_(s, [], d);
702
+ }), n;
703
703
  }
704
- function Kt(t) {
705
- return w(t) || g(10, t), It(t);
704
+ function Gt(t) {
705
+ return w(t) || m(10, t), zt(t);
706
706
  }
707
- function It(t) {
708
- if (!D(t) || X(t))
707
+ function zt(t) {
708
+ if (!P(t) || X(t))
709
709
  return t;
710
- const e = t[m];
711
- let i, n = !0;
710
+ const e = t[g];
711
+ let i, r = !0;
712
712
  if (e) {
713
713
  if (!e.modified_)
714
714
  return e.base_;
715
- e.finalized_ = !0, i = rt(t, e.scope_.immer_.useStrictShallowCopy_), n = e.scope_.immer_.shouldUseStrictIteration();
715
+ e.finalized_ = !0, i = rt(t, e.scope_.immer_.useStrictShallowCopy_), r = e.scope_.immer_.shouldUseStrictIteration();
716
716
  } else
717
717
  i = rt(t, !0);
718
718
  return G(
719
719
  i,
720
- (r, s) => {
721
- q(i, r, It(s));
720
+ (n, s) => {
721
+ B(i, n, zt(s));
722
722
  },
723
- n
723
+ r
724
724
  ), e && (e.finalized_ = !1), i;
725
725
  }
726
- var Ht = new Gt(), z = Ht.produce;
727
- let Yt = () => ({
726
+ var Kt = new Wt(), b = Kt.produce;
727
+ let Ht = () => ({
728
728
  emit(t, ...e) {
729
- for (let i = this.events[t] || [], n = 0, r = i.length; n < r; n++)
730
- i[n](...e);
729
+ for (let i = this.events[t] || [], r = 0, n = i.length; r < n; r++)
730
+ i[r](...e);
731
731
  },
732
732
  events: {},
733
733
  on(t, e) {
@@ -736,32 +736,33 @@ let Yt = () => ({
736
736
  };
737
737
  }
738
738
  });
739
- function R(t) {
739
+ function Ct(t) {
740
+ return typeof t == "function" ? t() : t;
741
+ }
742
+ function N(t) {
740
743
  if (typeof t != "object" || t === null) return;
741
744
  const e = Object.getPrototypeOf(t);
742
745
  if (e === Object.prototype || e === null) return;
743
746
  const i = e.constructor;
744
747
  typeof i == "function" && (t instanceof Date || t instanceof RegExp || t instanceof Map || t instanceof Set || t instanceof WeakMap || t instanceof WeakSet || ArrayBuffer.isView(t) || i[x] !== !0 && (i[x] = !0));
745
748
  }
746
- let Xt = 0;
747
- function Jt() {
748
- return Xt++;
749
+ let Yt = 0;
750
+ function Xt() {
751
+ return Yt++;
749
752
  }
750
- class Qt {
751
- constructor(e, i, n) {
752
- this.controller = e, this.path = i, this.id = Jt(), this._isTouched = !1, this._isDirty = !1, n?.isTouched && this._setTouched(!0), n?.isDirty && this._setDirty(!0);
753
- }
754
- get canonicalPath() {
755
- return h.toCanonicalPath(this.path);
753
+ class Jt {
754
+ /** @internal register via `FormController::registerField` instead */
755
+ constructor(e, i, r, n) {
756
+ this.controller = e, this.path = i, this.defaultValue = r, this.id = Xt(), this._isTouched = !1, this._isDirty = !1, n?.isTouched && this._setTouched(!0), n?.isDirty && this._setDirty(!0);
756
757
  }
757
758
  get stringPath() {
758
759
  return h.toStringPath(this.path);
759
760
  }
760
761
  get value() {
761
- return h.getValue(this.controller._data, this.path);
762
+ return h.getValue(this.controller.data, this.path);
762
763
  }
763
764
  get initialValue() {
764
- return h.getValue(this.controller._initialData, this.path);
765
+ return h.getValue(this.controller.initialData, this.path);
765
766
  }
766
767
  get boundElement() {
767
768
  return this.target;
@@ -780,12 +781,18 @@ class Qt {
780
781
  get isValid() {
781
782
  return this.issues.length === 0;
782
783
  }
784
+ ensureDefault(e) {
785
+ if (this.value == null && this.defaultValue != null) {
786
+ const i = Ct(this.defaultValue);
787
+ i != null && this.setValue(i, e);
788
+ }
789
+ }
783
790
  _setTouched(e) {
784
791
  const i = this._isTouched !== e;
785
792
  if (this._isTouched = e, i) {
786
- const n = this.controller.getAscendantFields(this.path);
787
- for (let r = n.length - 1; r >= 0; r--) {
788
- const s = n[r];
793
+ const r = this.controller.getAscendantFields(this.path);
794
+ for (let n = r.length - 1; n >= 0; n--) {
795
+ const s = r[n];
789
796
  s != null && this.controller.events.emit("fieldTouchUpdated", s.path);
790
797
  }
791
798
  }
@@ -793,87 +800,112 @@ class Qt {
793
800
  _setDirty(e) {
794
801
  const i = this._isDirty !== e;
795
802
  if (this._isDirty = e, i) {
796
- const n = this.controller.getAscendantFields(this.path);
797
- for (let r = n.length - 1; r >= 0; r--) {
798
- const s = n[r];
803
+ const r = this.controller.getAscendantFields(this.path);
804
+ for (let n = r.length - 1; n >= 0; n--) {
805
+ const s = r[n];
799
806
  s != null && this.controller.events.emit("fieldDirtyUpdated", s.path);
800
807
  }
801
808
  }
802
809
  }
803
810
  bindElement(e) {
804
- this.target = e, e != null ? this.controller.events.emit("elementBound", this.path, e) : this.controller.events.emit("elementUnbound", this.path);
805
- }
806
- setValue(e, i) {
807
- return this.modifyValue(() => e, i);
808
- }
809
- modifyValue(e, i) {
810
- (i?.shouldTouch == null || i?.shouldTouch) && this.touch();
811
- const n = this.controller.getAscendantFields(this.path), r = n.map((u) => u?.initialValue);
812
- r.forEach((u) => R(u));
813
- const s = n.map((u) => u?.value);
814
- s.forEach((u) => R(u)), this.controller._data = z(this.controller._data, (u) => {
815
- h.modifyValue(u, this.path, (_) => e(_));
816
- });
817
- const o = n.map((u) => u?.value);
818
- o.forEach((u) => R(u));
819
- const f = (u, _) => {
820
- if (typeof u != "object" || typeof _ != "object") return;
821
- const c = u.constructor, a = _.constructor;
822
- if (c === a)
823
- return this.controller.equalityComparators?.[c]?.(u, _);
811
+ e != null ? (this.target = e, this.controller.events.emit("elementBound", this.path, e)) : this.unbindElement();
812
+ }
813
+ unbindElement() {
814
+ this.target != null && (this.target = void 0, this.controller.events.emit("elementUnbound", this.path));
815
+ }
816
+ clearIssues() {
817
+ return this.controller.clearFieldIssues(this.path);
818
+ }
819
+ modifyData(e, i) {
820
+ (i?.shouldTouch == null || i?.shouldTouch === !0) && this.touch();
821
+ const r = this.controller.getAscendantFields(this.path), n = r.map((c) => c?.initialValue);
822
+ n.forEach((c) => N(c));
823
+ const s = r.map((c) => c?.value);
824
+ s.forEach((c) => N(c)), this.controller._data = b(this.controller._data, e);
825
+ const o = r.map((c) => c?.value);
826
+ o.forEach((c) => N(c));
827
+ const l = (c, _) => {
828
+ if (typeof c != "object" || typeof _ != "object") return;
829
+ const f = c.constructor, a = _.constructor;
830
+ if (f === a)
831
+ return this.controller.equalityComparators?.get(f)?.(c, _);
824
832
  };
825
- if (!V.deepEqual(
833
+ if (!v.deepEqual(
826
834
  s[s.length - 1],
827
835
  o[o.length - 1],
828
- f
836
+ l
829
837
  ))
830
- for (let u = n.length - 1; u >= 0; u--) {
831
- const _ = n[u];
838
+ for (let c = r.length - 1; c >= 0; c--) {
839
+ const _ = r[c];
832
840
  this.controller.events.emit(
833
- "valueChanged",
841
+ "fieldValueChanged",
834
842
  _.path,
835
- o[u],
836
- s[u]
843
+ o[c],
844
+ s[c]
837
845
  );
838
846
  }
839
847
  if (i?.shouldMarkDirty == null || i?.shouldMarkDirty) {
840
- const u = !V.deepEqual(
841
- r[r.length - 1],
848
+ const c = !v.deepEqual(
849
+ n[n.length - 1],
842
850
  o[o.length - 1],
843
- f
851
+ l
844
852
  );
845
- this._setDirty(u);
853
+ this._setDirty(c);
846
854
  }
847
855
  }
856
+ setValue(e, i) {
857
+ return this.modifyData((r) => {
858
+ h.setValue(r, this.path, e);
859
+ }, i);
860
+ }
861
+ modifyValue(e, i) {
862
+ return this.modifyData((r) => {
863
+ h.modifyValue(r, this.path, (n) => {
864
+ e(n);
865
+ });
866
+ }, i);
867
+ }
848
868
  reset() {
849
- this._setTouched(!1), this._setDirty(!1);
869
+ this._setTouched(!1), this._setDirty(!1), this.controller.events.emit("fieldReset", this.path);
850
870
  }
851
871
  touch() {
852
872
  this._setTouched(!0);
853
873
  }
854
874
  markDirty() {
855
- this.touch(), this._setDirty(!0);
875
+ this._setDirty(!0);
856
876
  }
857
- triggerValidation() {
877
+ validate() {
858
878
  this.controller.validateField(this.path);
859
879
  }
860
880
  focus(e) {
861
881
  (e?.shouldTouch == null || e.shouldTouch) && this.target?.addEventListener("focus", () => this.touch(), {
862
882
  once: !0
863
- }), this.target?.scrollIntoView(), this.target?.focus();
883
+ }), this.target?.scrollIntoView(e?.scrollOptions), this.target?.focus();
864
884
  }
865
885
  }
866
- function Zt(t, e) {
886
+ function Qt(t, e) {
867
887
  let i = [];
868
- for (let n = t.length - 1; n >= 0; n--)
869
- e(t[n]) && i.push(n);
870
- i.forEach((n) => t.splice(n, 1));
888
+ for (let r = t.length - 1; r >= 0; r--)
889
+ e(t[r]) && i.push(r);
890
+ i.forEach((r) => t.splice(r, 1));
871
891
  }
872
- class te {
892
+ class Zt {
873
893
  constructor(e) {
874
- this._isValidating = !1, this._isSubmitting = !1, this._fields = /* @__PURE__ */ new Map(), this._issues = [], this.events = Yt(), this.validationSchema = e.validationSchema, this.equalityComparators = e.equalityComparators, this._initialData = e.initialData ?? {}, this._data = z(this._initialData, () => {
894
+ this._isValidating = !1, this._isSubmitting = !1, this._triedSubmitting = !1, this.pathBuilder = new R(), this._fields = /* @__PURE__ */ new Map(), this._issues = [], this.events = Ht(), this.validationSchema = e.validationSchema, this.equalityComparators = e.equalityComparators, this._initialData = e.initialData ?? {}, this._data = b(this._initialData, () => {
875
895
  });
876
896
  }
897
+ get data() {
898
+ return this._data;
899
+ }
900
+ get initialData() {
901
+ return this._initialData;
902
+ }
903
+ get issues() {
904
+ return this._issues;
905
+ }
906
+ get path() {
907
+ return this.pathBuilder;
908
+ }
877
909
  get isDirty() {
878
910
  for (const e of this._fields.values())
879
911
  if (e.isDirty) return !0;
@@ -888,72 +920,78 @@ class te {
888
920
  get isSubmitting() {
889
921
  return this._isSubmitting;
890
922
  }
923
+ get triedSubmitting() {
924
+ return this._triedSubmitting;
925
+ }
891
926
  setValidating(e) {
892
927
  this._isValidating !== e && (this._isValidating = e, this.events.emit("validationStatusChange", e));
893
928
  }
894
929
  setSubmitting(e) {
895
930
  this._isSubmitting !== e && (this._isSubmitting = e, this.events.emit("submissionStatusChange", e));
896
931
  }
897
- _unsafeSetFieldValue(e, i, n) {
898
- R(i), n?.updateInitialValue === !0 && (this._initialData = z(this._initialData, (r) => {
899
- h.setValue(r, e, i);
900
- })), this._data = z(this._data, (r) => {
901
- h.setValue(r, e, i);
902
- });
903
- }
904
- // TODO: Rename to "register" ??
905
- bindField(e, i) {
906
- let n = h.getValue(this._data, e);
907
- n == null && i?.defaultValue != null && (this._unsafeSetFieldValue(e, i.defaultValue, {
908
- updateInitialValue: i.overrideInitialValue
909
- }), n = h.getValue(this._data, e));
910
- const r = h.getValue(this._initialData, e), s = !V.deepEqual(n, r), o = new Qt(this, e, {
932
+ registerField(e, i) {
933
+ let r = h.getValue(this._data, e);
934
+ if (r == null && i?.defaultValue != null) {
935
+ const l = Ct(i.defaultValue);
936
+ N(l), i?.overrideInitialValue === !0 && (this._initialData = b(this._initialData, (d) => {
937
+ h.setValue(d, e, l);
938
+ })), this._data = b(this._data, (d) => {
939
+ h.setValue(d, e, l);
940
+ }), r = h.getValue(this._data, e);
941
+ }
942
+ const n = h.getValue(this._initialData, e), s = !v.deepEqual(r, n), o = new Jt(this, e, i?.defaultValue, {
911
943
  isDirty: s
912
944
  });
913
- return i?.domElement != null && o.bindElement(i.domElement), this._fields.set(o.stringPath, o), this.events.emit("fieldBound", o.path), s && this.events.emit("valueChanged", o.path, n, r), o;
945
+ return this._fields.set(o.stringPath, o), this.events.emit("fieldRegistered", o.path), s && this.events.emit(
946
+ "fieldValueChanged",
947
+ o.path,
948
+ r,
949
+ n
950
+ ), o;
914
951
  }
915
- unbindField(e) {
952
+ unregisterField(e) {
916
953
  const i = h.toStringPath(e);
917
- this._fields.delete(i), this.events.emit("fieldUnbound", e);
954
+ return this._fields.has(i) ? (this._fields.delete(i), this.events.emit("fieldUnregistered", e), !0) : !1;
918
955
  }
919
- // TODO: Add an option to keep dirty/touched fields as they are
920
956
  reset(e) {
921
- this._data = this._initialData, this._issues = [];
922
- for (const i of this._fields.values())
923
- i.reset();
924
- e != null && (this._initialData = e, this._data = z(this._initialData, () => {
925
- }));
957
+ const i = e ?? this._initialData, r = [];
958
+ for (const n of this._fields.values()) {
959
+ const s = h.getValue(this._data, n.path), o = h.getValue(i, n.path);
960
+ v.deepEqual(s, o) || r.push([n.path, o, s]), n.reset();
961
+ }
962
+ e != null && (this._initialData = b(e, () => {
963
+ })), this._data = b(i, () => {
964
+ }), this._issues = [], this._triedSubmitting = !1, r.forEach(([n, s, o]) => {
965
+ this.events.emit("fieldValueChanged", n, s, o);
966
+ });
926
967
  }
968
+ // TODO: resetGracefully(newInitialData?: DeepPartial<TOutput>)
969
+ // TODO: ^ Keeps dirty/touched fields as they are
927
970
  getAscendantFields(e) {
928
- return e.map((n, r) => e.slice(0, r + 1)).map((n) => this.getField(n)).filter((n) => !!n);
971
+ return e.map((r, n) => e.slice(0, n + 1)).map((r) => this.getField(r)).filter((r) => !!r);
929
972
  }
930
973
  getField(e) {
931
974
  const i = h.toStringPath(e);
932
975
  return this._fields.get(i);
933
976
  }
977
+ getFields() {
978
+ return this._fields.values();
979
+ }
934
980
  clearFieldIssues(e) {
935
981
  this._issues = this._issues.filter((i) => !h.equals(h.normalize(i.path), e));
936
982
  }
937
983
  async applyValidation(e, i) {
938
- const n = V.diff(
984
+ const r = v.arrayDiff(
939
985
  this._issues,
940
986
  e.issues ?? [],
941
- V.deepEqual,
942
- (r) => {
943
- if (r.path == null) return !1;
944
- const s = h.normalize(r.path);
987
+ v.deepEqual,
988
+ (n) => {
989
+ if (n.path == null) return !1;
990
+ const s = h.normalize(n.path);
945
991
  return h.equals(s, i) || h.isDescendant(i, s);
946
992
  }
947
993
  );
948
- Zt(this._issues, (r) => n.removed.includes(r)), n.added.forEach((r) => this._issues.push(r)), (n.added.length !== 0 || n.removed.length !== 0) && this.events.emit("fieldIssuesUpdated", i);
949
- }
950
- async validateField(e) {
951
- if (this._isValidating || this.validationSchema == null) return;
952
- this.setValidating(!0), this.getField(e) == null && this.bindField(e);
953
- const i = await this.validationSchema["~standard"].validate(
954
- this._data
955
- );
956
- this.events.emit("validationTriggered", e), this.applyValidation(i, e), this.setValidating(!1);
994
+ Qt(this._issues, (n) => r.removed.includes(n)), r.added.forEach((n) => this._issues.push(n)), (r.added.length !== 0 || r.removed.length !== 0) && this.events.emit("fieldIssuesUpdated", i);
957
995
  }
958
996
  async validateForm() {
959
997
  if (this._isValidating || this.validationSchema == null) return;
@@ -961,37 +999,45 @@ class te {
961
999
  const e = await this.validationSchema["~standard"].validate(
962
1000
  this._data
963
1001
  );
964
- for (const n of this._fields.keys()) {
965
- const r = h.fromStringPath(n);
966
- this.events.emit("validationTriggered", r), this.applyValidation(e, r);
1002
+ for (const r of this._fields.keys()) {
1003
+ const n = h.fromStringPath(r);
1004
+ this.events.emit("fieldValidationTriggered", n), this.applyValidation(e, n);
967
1005
  }
968
- V.diff(
1006
+ v.arrayDiff(
969
1007
  this._issues,
970
1008
  e.issues ?? [],
971
- V.deepEqual
972
- ).added.forEach((n) => this._issues.push(n)), this.setValidating(!1);
1009
+ v.deepEqual
1010
+ ).added.forEach((r) => this._issues.push(r)), this.setValidating(!1);
1011
+ }
1012
+ async validateField(e) {
1013
+ if (this._isValidating || this.validationSchema == null) return;
1014
+ this.setValidating(!0), this.getField(e) == null && this.registerField(e);
1015
+ const i = await this.validationSchema["~standard"].validate(
1016
+ this._data
1017
+ );
1018
+ this.events.emit("fieldValidationTriggered", e), this.applyValidation(i, e), this.setValidating(!1);
973
1019
  }
974
1020
  createSubmitHandler(e, i) {
975
- return async (n) => {
976
- if (n?.preventDefault(), this._isValidating || this._isSubmitting) return;
977
- const r = new AbortController();
978
- if (await this.validateForm(), this._issues.length === 0) {
979
- this.setSubmitting(!0), await e?.(this._data, n, r.signal), this.setSubmitting(!1);
980
- return;
981
- }
982
- for (const s of this._issues) {
983
- if (s.path == null) continue;
984
- const o = h.normalize(s.path), f = this.getField(o);
985
- if (f != null && f.boundElement != null) {
986
- f.focus();
987
- break;
1021
+ return async (r) => {
1022
+ if (r?.preventDefault(), !this._isValidating && !this._isSubmitting) {
1023
+ if (this._triedSubmitting = !0, await this.validateForm(), this._issues.length === 0) {
1024
+ this.setSubmitting(!0), await e?.(this._data, r), this.setSubmitting(!1);
1025
+ return;
1026
+ }
1027
+ for (const n of this._issues) {
1028
+ if (n.path == null) continue;
1029
+ const s = h.normalize(n.path), o = this.getField(s);
1030
+ if (o != null && o.boundElement != null) {
1031
+ o.focus();
1032
+ break;
1033
+ }
988
1034
  }
1035
+ await i?.(this._issues, r), this.setSubmitting(!1);
989
1036
  }
990
- await i?.(this._issues, n, r.signal), this.setSubmitting(!1);
991
1037
  };
992
1038
  }
993
1039
  }
994
- function ee(t) {
1040
+ function te(t) {
995
1041
  return {
996
1042
  "~standard": {
997
1043
  version: 1,
@@ -1000,9 +1046,9 @@ function ee(t) {
1000
1046
  try {
1001
1047
  const i = await t(e);
1002
1048
  return i == null ? { value: e } : {
1003
- issues: i.map((n) => ({
1004
- path: h.fromStringPath(n.path),
1005
- message: n.message
1049
+ issues: i.map((r) => ({
1050
+ path: h.fromStringPath(r.path),
1051
+ message: r.message
1006
1052
  }))
1007
1053
  };
1008
1054
  } catch (i) {
@@ -1020,10 +1066,11 @@ function ee(t) {
1020
1066
  }
1021
1067
  export {
1022
1068
  h as FieldPath,
1023
- et as FieldPathBuilder,
1024
- te as FormController,
1025
- Qt as FormField,
1026
- V as Reconsile,
1027
- ee as customValidation
1069
+ R as FieldPathBuilder,
1070
+ Zt as FormController,
1071
+ Jt as FormField,
1072
+ v as Reconcile,
1073
+ te as customValidation,
1074
+ Ct as supply
1028
1075
  };
1029
1076
  //# sourceMappingURL=index.js.map