@goodie-forms/core 1.0.0-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.
- package/dist/form/Field.d.ts +17 -0
- package/dist/form/Field.d.ts.map +1 -0
- package/dist/form/FormController.d.ts +62 -0
- package/dist/form/FormController.d.ts.map +1 -0
- package/dist/form/FormField.d.ts +34 -0
- package/dist/form/FormField.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1184 -0
- package/dist/index.js.map +1 -0
- package/dist/types/DeepPartial.d.ts +4 -0
- package/dist/types/DeepPartial.d.ts.map +1 -0
- package/dist/utils/getId.d.ts +2 -0
- package/dist/utils/getId.d.ts.map +1 -0
- package/dist/utils/removeBy.d.ts +2 -0
- package/dist/utils/removeBy.d.ts.map +1 -0
- package/package.json +27 -0
- package/src/form/Field.ts +194 -0
- package/src/form/FormController.ts +290 -0
- package/src/form/FormField.ts +199 -0
- package/src/index.ts +3 -0
- package/src/types/DeepPartial.ts +3 -0
- package/src/utils/getId.ts +5 -0
- package/src/utils/removeBy.ts +11 -0
- package/tsconfig.json +7 -0
- package/vite.config.ts +18 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1184 @@
|
|
|
1
|
+
var S;
|
|
2
|
+
((t) => {
|
|
3
|
+
function e(u, a) {
|
|
4
|
+
if (u == null) return;
|
|
5
|
+
const r = a.split(".");
|
|
6
|
+
let s = u;
|
|
7
|
+
for (const f of r) {
|
|
8
|
+
if (s == null) return;
|
|
9
|
+
s = s[f];
|
|
10
|
+
}
|
|
11
|
+
return s;
|
|
12
|
+
}
|
|
13
|
+
t.getValue = e;
|
|
14
|
+
function i(u, a, r) {
|
|
15
|
+
if (u === a) return !0;
|
|
16
|
+
if (u === null || a === null || typeof u != "object" || typeof a != "object") return !1;
|
|
17
|
+
if (Array.isArray(u)) {
|
|
18
|
+
if (!Array.isArray(a) || u.length !== a.length) return !1;
|
|
19
|
+
for (let h = 0; h < u.length; h++)
|
|
20
|
+
if (!i(u[h], a[h])) return !1;
|
|
21
|
+
return !0;
|
|
22
|
+
}
|
|
23
|
+
if (r != null) {
|
|
24
|
+
const h = r(u, a);
|
|
25
|
+
if (h !== void 0) return h;
|
|
26
|
+
}
|
|
27
|
+
if (u instanceof Date && a instanceof Date)
|
|
28
|
+
return u.getTime() === a.getTime();
|
|
29
|
+
if (u instanceof RegExp && a instanceof RegExp)
|
|
30
|
+
return u.source === a.source && u.flags === a.flags;
|
|
31
|
+
if (u instanceof Map && a instanceof Map) {
|
|
32
|
+
if (u.size !== a.size) return !1;
|
|
33
|
+
for (const [h, v] of u)
|
|
34
|
+
if (!a.has(h) || !i(v, a.get(h))) return !1;
|
|
35
|
+
return !0;
|
|
36
|
+
}
|
|
37
|
+
if (u instanceof Set && a instanceof Set) {
|
|
38
|
+
if (u.size !== a.size) return !1;
|
|
39
|
+
for (const h of u)
|
|
40
|
+
if (!a.has(h)) return !1;
|
|
41
|
+
return !0;
|
|
42
|
+
}
|
|
43
|
+
if (Object.getPrototypeOf(u) !== Object.getPrototypeOf(a))
|
|
44
|
+
return !1;
|
|
45
|
+
const s = Object.keys(u), f = Object.keys(a);
|
|
46
|
+
if (s.length !== f.length) return !1;
|
|
47
|
+
for (const h of s)
|
|
48
|
+
if (!Object.prototype.hasOwnProperty.call(a, h) || !i(u[h], a[h])) return !1;
|
|
49
|
+
return !0;
|
|
50
|
+
}
|
|
51
|
+
t.deepEqual = i;
|
|
52
|
+
function n(u, a, r, s) {
|
|
53
|
+
const f = [], h = [], v = [];
|
|
54
|
+
for (const g of a)
|
|
55
|
+
u.some((I) => r(I, g)) ? (s?.(g) ?? !0) && v.push(g) : (s?.(g) ?? !0) && f.push(g);
|
|
56
|
+
for (const g of u)
|
|
57
|
+
a.some((I) => r(g, I)) || (s?.(g) ?? !0) && h.push(g);
|
|
58
|
+
return { added: f, removed: h, unchanged: v };
|
|
59
|
+
}
|
|
60
|
+
t.diff = n;
|
|
61
|
+
function o(u, a, r) {
|
|
62
|
+
return c(u, a, () => r);
|
|
63
|
+
}
|
|
64
|
+
t.setValue = o;
|
|
65
|
+
function c(u, a, r) {
|
|
66
|
+
const s = a.split(".");
|
|
67
|
+
let f = u;
|
|
68
|
+
for (let g = 0; g < s.length - 1; g++) {
|
|
69
|
+
const I = s[g];
|
|
70
|
+
f[I] == null && (f[I] = {}), f = f[I];
|
|
71
|
+
}
|
|
72
|
+
const h = f[s[s.length - 1]], v = r(h);
|
|
73
|
+
v !== void 0 && (f[s[s.length - 1]] = v);
|
|
74
|
+
}
|
|
75
|
+
t.modifyValue = c;
|
|
76
|
+
function l(u, a) {
|
|
77
|
+
const r = a.split(".");
|
|
78
|
+
let s = u;
|
|
79
|
+
for (let f = 0; f < r.length - 1; f++) {
|
|
80
|
+
const h = r[f];
|
|
81
|
+
if (s[h] == null)
|
|
82
|
+
return;
|
|
83
|
+
s = s[h];
|
|
84
|
+
}
|
|
85
|
+
delete s[r[r.length - 1]];
|
|
86
|
+
}
|
|
87
|
+
t.deleteValue = l;
|
|
88
|
+
})(S || (S = {}));
|
|
89
|
+
var zt = /* @__PURE__ */ Symbol.for("immer-nothing"), $ = /* @__PURE__ */ Symbol.for("immer-draftable"), _ = /* @__PURE__ */ Symbol.for("immer-state"), jt = process.env.NODE_ENV !== "production" ? [
|
|
90
|
+
// All error codes, starting by 0:
|
|
91
|
+
function(t) {
|
|
92
|
+
return `The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`;
|
|
93
|
+
},
|
|
94
|
+
function(t) {
|
|
95
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`;
|
|
96
|
+
},
|
|
97
|
+
"This object has been frozen and should not be mutated",
|
|
98
|
+
function(t) {
|
|
99
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + t;
|
|
100
|
+
},
|
|
101
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
102
|
+
"Immer forbids circular references",
|
|
103
|
+
"The first or second argument to `produce` must be a function",
|
|
104
|
+
"The third argument to `produce` must be a function or undefined",
|
|
105
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
106
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
107
|
+
function(t) {
|
|
108
|
+
return `'current' expects a draft, got: ${t}`;
|
|
109
|
+
},
|
|
110
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
111
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
112
|
+
"Immer only supports deleting array indices",
|
|
113
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
114
|
+
function(t) {
|
|
115
|
+
return `'original' expects a draft, got: ${t}`;
|
|
116
|
+
}
|
|
117
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
118
|
+
// See Patches.ts for additional errors
|
|
119
|
+
] : [];
|
|
120
|
+
function M(t, ...e) {
|
|
121
|
+
if (process.env.NODE_ENV !== "production") {
|
|
122
|
+
const i = jt[t], n = C(i) ? i.apply(null, e) : i;
|
|
123
|
+
throw new Error(`[Immer] ${n}`);
|
|
124
|
+
}
|
|
125
|
+
throw new Error(
|
|
126
|
+
`[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
var D = Object, k = D.getPrototypeOf, K = "constructor", et = "prototype", dt = "configurable", Y = "enumerable", W = "writable", R = "value", V = (t) => !!t && !!t[_];
|
|
130
|
+
function E(t) {
|
|
131
|
+
return t ? Tt(t) || it(t) || !!t[$] || !!t[K]?.[$] || nt(t) || rt(t) : !1;
|
|
132
|
+
}
|
|
133
|
+
var Lt = D[et][K].toString(), Mt = /* @__PURE__ */ new WeakMap();
|
|
134
|
+
function Tt(t) {
|
|
135
|
+
if (!t || !st(t))
|
|
136
|
+
return !1;
|
|
137
|
+
const e = k(t);
|
|
138
|
+
if (e === null || e === D[et])
|
|
139
|
+
return !0;
|
|
140
|
+
const i = D.hasOwnProperty.call(e, K) && e[K];
|
|
141
|
+
if (i === Object)
|
|
142
|
+
return !0;
|
|
143
|
+
if (!C(i))
|
|
144
|
+
return !1;
|
|
145
|
+
let n = Mt.get(i);
|
|
146
|
+
return n === void 0 && (n = Function.toString.call(i), Mt.set(i, n)), n === Lt;
|
|
147
|
+
}
|
|
148
|
+
function H(t, e, i = !0) {
|
|
149
|
+
q(t) === 0 ? (i ? Reflect.ownKeys(t) : D.keys(t)).forEach((o) => {
|
|
150
|
+
e(o, t[o], t);
|
|
151
|
+
}) : t.forEach((n, o) => e(o, n, t));
|
|
152
|
+
}
|
|
153
|
+
function q(t) {
|
|
154
|
+
const e = t[_];
|
|
155
|
+
return e ? e.type_ : it(t) ? 1 : nt(t) ? 2 : rt(t) ? 3 : 0;
|
|
156
|
+
}
|
|
157
|
+
var Dt = (t, e, i = q(t)) => i === 2 ? t.has(e) : D[et].hasOwnProperty.call(t, e), ht = (t, e, i = q(t)) => (
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
i === 2 ? t.get(e) : t[e]
|
|
160
|
+
), J = (t, e, i, n = q(t)) => {
|
|
161
|
+
n === 2 ? t.set(e, i) : n === 3 ? t.add(i) : t[e] = i;
|
|
162
|
+
};
|
|
163
|
+
function Bt(t, e) {
|
|
164
|
+
return t === e ? t !== 0 || 1 / t === 1 / e : t !== t && e !== e;
|
|
165
|
+
}
|
|
166
|
+
var it = Array.isArray, nt = (t) => t instanceof Map, rt = (t) => t instanceof Set, st = (t) => typeof t == "object", C = (t) => typeof t == "function", lt = (t) => typeof t == "boolean";
|
|
167
|
+
function Ht(t) {
|
|
168
|
+
const e = +t;
|
|
169
|
+
return Number.isInteger(e) && String(e) === t;
|
|
170
|
+
}
|
|
171
|
+
var qt = (t) => st(t) ? t?.[_] : null, p = (t) => t.copy_ || t.base_, Gt = (t) => {
|
|
172
|
+
const e = qt(t);
|
|
173
|
+
return e ? e.copy_ ?? e.base_ : t;
|
|
174
|
+
}, vt = (t) => t.modified_ ? t.copy_ : t.base_;
|
|
175
|
+
function _t(t, e) {
|
|
176
|
+
if (nt(t))
|
|
177
|
+
return new Map(t);
|
|
178
|
+
if (rt(t))
|
|
179
|
+
return new Set(t);
|
|
180
|
+
if (it(t))
|
|
181
|
+
return Array[et].slice.call(t);
|
|
182
|
+
const i = Tt(t);
|
|
183
|
+
if (e === !0 || e === "class_only" && !i) {
|
|
184
|
+
const n = D.getOwnPropertyDescriptors(t);
|
|
185
|
+
delete n[_];
|
|
186
|
+
let o = Reflect.ownKeys(n);
|
|
187
|
+
for (let c = 0; c < o.length; c++) {
|
|
188
|
+
const l = o[c], u = n[l];
|
|
189
|
+
u[W] === !1 && (u[W] = !0, u[dt] = !0), (u.get || u.set) && (n[l] = {
|
|
190
|
+
[dt]: !0,
|
|
191
|
+
[W]: !0,
|
|
192
|
+
// could live with !!desc.set as well here...
|
|
193
|
+
[Y]: u[Y],
|
|
194
|
+
[R]: t[l]
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return D.create(k(t), n);
|
|
198
|
+
} else {
|
|
199
|
+
const n = k(t);
|
|
200
|
+
if (n !== null && i)
|
|
201
|
+
return { ...t };
|
|
202
|
+
const o = D.create(n);
|
|
203
|
+
return D.assign(o, t);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function Pt(t, e = !1) {
|
|
207
|
+
return ot(t) || V(t) || !E(t) || (q(t) > 1 && D.defineProperties(t, {
|
|
208
|
+
set: G,
|
|
209
|
+
add: G,
|
|
210
|
+
clear: G,
|
|
211
|
+
delete: G
|
|
212
|
+
}), D.freeze(t), e && H(
|
|
213
|
+
t,
|
|
214
|
+
(i, n) => {
|
|
215
|
+
Pt(n, !0);
|
|
216
|
+
},
|
|
217
|
+
!1
|
|
218
|
+
)), t;
|
|
219
|
+
}
|
|
220
|
+
function Wt() {
|
|
221
|
+
M(2);
|
|
222
|
+
}
|
|
223
|
+
var G = {
|
|
224
|
+
[R]: Wt
|
|
225
|
+
};
|
|
226
|
+
function ot(t) {
|
|
227
|
+
return t === null || !st(t) ? !0 : D.isFrozen(t);
|
|
228
|
+
}
|
|
229
|
+
var U = "MapSet", pt = "Patches", yt = "ArrayMethods", Q = {};
|
|
230
|
+
function A(t) {
|
|
231
|
+
const e = Q[t];
|
|
232
|
+
return e || M(0, t), e;
|
|
233
|
+
}
|
|
234
|
+
var wt = (t) => !!Q[t];
|
|
235
|
+
function Vt(t, e) {
|
|
236
|
+
Q[t] || (Q[t] = e);
|
|
237
|
+
}
|
|
238
|
+
var j, X = () => j, $t = (t, e) => ({
|
|
239
|
+
drafts_: [],
|
|
240
|
+
parent_: t,
|
|
241
|
+
immer_: e,
|
|
242
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
243
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
244
|
+
canAutoFreeze_: !0,
|
|
245
|
+
unfinalizedDrafts_: 0,
|
|
246
|
+
handledSet_: /* @__PURE__ */ new Set(),
|
|
247
|
+
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
248
|
+
mapSetPlugin_: wt(U) ? A(U) : void 0,
|
|
249
|
+
arrayMethodsPlugin_: wt(yt) ? A(yt) : void 0
|
|
250
|
+
});
|
|
251
|
+
function Et(t, e) {
|
|
252
|
+
e && (t.patchPlugin_ = A(pt), t.patches_ = [], t.inversePatches_ = [], t.patchListener_ = e);
|
|
253
|
+
}
|
|
254
|
+
function mt(t) {
|
|
255
|
+
gt(t), t.drafts_.forEach(Kt), t.drafts_ = null;
|
|
256
|
+
}
|
|
257
|
+
function gt(t) {
|
|
258
|
+
t === j && (j = t.parent_);
|
|
259
|
+
}
|
|
260
|
+
var Ot = (t) => j = $t(j, t);
|
|
261
|
+
function Kt(t) {
|
|
262
|
+
const e = t[_];
|
|
263
|
+
e.type_ === 0 || e.type_ === 1 ? e.revoke_() : e.revoked_ = !0;
|
|
264
|
+
}
|
|
265
|
+
function It(t, e) {
|
|
266
|
+
e.unfinalizedDrafts_ = e.drafts_.length;
|
|
267
|
+
const i = e.drafts_[0];
|
|
268
|
+
if (t !== void 0 && t !== i) {
|
|
269
|
+
i[_].modified_ && (mt(e), M(4)), E(t) && (t = bt(e, t));
|
|
270
|
+
const { patchPlugin_: o } = e;
|
|
271
|
+
o && o.generateReplacementPatches_(
|
|
272
|
+
i[_].base_,
|
|
273
|
+
t,
|
|
274
|
+
e
|
|
275
|
+
);
|
|
276
|
+
} else
|
|
277
|
+
t = bt(e, i);
|
|
278
|
+
return Yt(e, t, !0), mt(e), e.patches_ && e.patchListener_(e.patches_, e.inversePatches_), t !== zt ? t : void 0;
|
|
279
|
+
}
|
|
280
|
+
function bt(t, e) {
|
|
281
|
+
if (ot(e))
|
|
282
|
+
return e;
|
|
283
|
+
const i = e[_];
|
|
284
|
+
if (!i)
|
|
285
|
+
return Z(e, t.handledSet_, t);
|
|
286
|
+
if (!at(i, t))
|
|
287
|
+
return e;
|
|
288
|
+
if (!i.modified_)
|
|
289
|
+
return i.base_;
|
|
290
|
+
if (!i.finalized_) {
|
|
291
|
+
const { callbacks_: n } = i;
|
|
292
|
+
if (n)
|
|
293
|
+
for (; n.length > 0; )
|
|
294
|
+
n.pop()(t);
|
|
295
|
+
kt(i, t);
|
|
296
|
+
}
|
|
297
|
+
return i.copy_;
|
|
298
|
+
}
|
|
299
|
+
function Yt(t, e, i = !1) {
|
|
300
|
+
!t.parent_ && t.immer_.autoFreeze_ && t.canAutoFreeze_ && Pt(e, i);
|
|
301
|
+
}
|
|
302
|
+
function Ct(t) {
|
|
303
|
+
t.finalized_ = !0, t.scope_.unfinalizedDrafts_--;
|
|
304
|
+
}
|
|
305
|
+
var at = (t, e) => t.scope_ === e, Jt = [];
|
|
306
|
+
function At(t, e, i, n) {
|
|
307
|
+
const o = p(t), c = t.type_;
|
|
308
|
+
if (n !== void 0 && ht(o, n, c) === e) {
|
|
309
|
+
J(o, n, i, c);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!t.draftLocations_) {
|
|
313
|
+
const u = t.draftLocations_ = /* @__PURE__ */ new Map();
|
|
314
|
+
H(o, (a, r) => {
|
|
315
|
+
if (V(r)) {
|
|
316
|
+
const s = u.get(r) || [];
|
|
317
|
+
s.push(a), u.set(r, s);
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
const l = t.draftLocations_.get(e) ?? Jt;
|
|
322
|
+
for (const u of l)
|
|
323
|
+
J(o, u, i, c);
|
|
324
|
+
}
|
|
325
|
+
function Qt(t, e, i) {
|
|
326
|
+
t.callbacks_.push(function(o) {
|
|
327
|
+
const c = e;
|
|
328
|
+
if (!c || !at(c, o))
|
|
329
|
+
return;
|
|
330
|
+
o.mapSetPlugin_?.fixSetContents(c);
|
|
331
|
+
const l = vt(c);
|
|
332
|
+
At(t, c.draft_ ?? c, l, i), kt(c, o);
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
function kt(t, e) {
|
|
336
|
+
if (t.modified_ && !t.finalized_ && (t.type_ === 3 || t.type_ === 1 && t.allIndicesReassigned_ || (t.assigned_?.size ?? 0) > 0)) {
|
|
337
|
+
const { patchPlugin_: n } = e;
|
|
338
|
+
if (n) {
|
|
339
|
+
const o = n.getPath(t);
|
|
340
|
+
o && n.generatePatches_(t, o, e);
|
|
341
|
+
}
|
|
342
|
+
Ct(t);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function St(t, e, i) {
|
|
346
|
+
const { scope_: n } = t;
|
|
347
|
+
if (V(i)) {
|
|
348
|
+
const o = i[_];
|
|
349
|
+
at(o, n) && o.callbacks_.push(function() {
|
|
350
|
+
N(t);
|
|
351
|
+
const l = vt(o);
|
|
352
|
+
At(t, i, l, e);
|
|
353
|
+
});
|
|
354
|
+
} else E(i) && t.callbacks_.push(function() {
|
|
355
|
+
const c = p(t);
|
|
356
|
+
t.type_ === 3 ? c.has(i) && Z(i, n.handledSet_, n) : ht(c, e, t.type_) === i && n.drafts_.length > 1 && (t.assigned_.get(e) ?? !1) === !0 && t.copy_ && Z(
|
|
357
|
+
ht(t.copy_, e, t.type_),
|
|
358
|
+
n.handledSet_,
|
|
359
|
+
n
|
|
360
|
+
);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
function Z(t, e, i) {
|
|
364
|
+
return !i.immer_.autoFreeze_ && i.unfinalizedDrafts_ < 1 || V(t) || e.has(t) || !E(t) || ot(t) || (e.add(t), H(t, (n, o) => {
|
|
365
|
+
if (V(o)) {
|
|
366
|
+
const c = o[_];
|
|
367
|
+
if (at(c, i)) {
|
|
368
|
+
const l = vt(c);
|
|
369
|
+
J(t, n, l, t.type_), Ct(c);
|
|
370
|
+
}
|
|
371
|
+
} else E(o) && Z(o, e, i);
|
|
372
|
+
})), t;
|
|
373
|
+
}
|
|
374
|
+
function Xt(t, e) {
|
|
375
|
+
const i = it(t), n = {
|
|
376
|
+
type_: i ? 1 : 0,
|
|
377
|
+
// Track which produce call this is associated with.
|
|
378
|
+
scope_: e ? e.scope_ : X(),
|
|
379
|
+
// True for both shallow and deep changes.
|
|
380
|
+
modified_: !1,
|
|
381
|
+
// Used during finalization.
|
|
382
|
+
finalized_: !1,
|
|
383
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
384
|
+
// actually instantiated in `prepareCopy()`
|
|
385
|
+
assigned_: void 0,
|
|
386
|
+
// The parent draft state.
|
|
387
|
+
parent_: e,
|
|
388
|
+
// The base state.
|
|
389
|
+
base_: t,
|
|
390
|
+
// The base proxy.
|
|
391
|
+
draft_: null,
|
|
392
|
+
// set below
|
|
393
|
+
// The base copy with any updated values.
|
|
394
|
+
copy_: null,
|
|
395
|
+
// Called by the `produce` function.
|
|
396
|
+
revoke_: null,
|
|
397
|
+
isManual_: !1,
|
|
398
|
+
// `callbacks` actually gets assigned in `createProxy`
|
|
399
|
+
callbacks_: void 0
|
|
400
|
+
};
|
|
401
|
+
let o = n, c = tt;
|
|
402
|
+
i && (o = [n], c = L);
|
|
403
|
+
const { revoke: l, proxy: u } = Proxy.revocable(o, c);
|
|
404
|
+
return n.draft_ = u, n.revoke_ = l, [u, n];
|
|
405
|
+
}
|
|
406
|
+
var tt = {
|
|
407
|
+
get(t, e) {
|
|
408
|
+
if (e === _)
|
|
409
|
+
return t;
|
|
410
|
+
let i = t.scope_.arrayMethodsPlugin_;
|
|
411
|
+
const n = t.type_ === 1 && typeof e == "string";
|
|
412
|
+
if (n && i?.isArrayOperationMethod(e))
|
|
413
|
+
return i.createMethodInterceptor(t, e);
|
|
414
|
+
const o = p(t);
|
|
415
|
+
if (!Dt(o, e, t.type_))
|
|
416
|
+
return Zt(t, o, e);
|
|
417
|
+
const c = o[e];
|
|
418
|
+
if (t.finalized_ || !E(c) || n && t.operationMethod && i?.isMutatingArrayMethod(
|
|
419
|
+
t.operationMethod
|
|
420
|
+
) && Ht(e))
|
|
421
|
+
return c;
|
|
422
|
+
if (c === ft(t.base_, e)) {
|
|
423
|
+
N(t);
|
|
424
|
+
const l = t.type_ === 1 ? +e : e, u = B(t.scope_, c, t, l);
|
|
425
|
+
return t.copy_[l] = u;
|
|
426
|
+
}
|
|
427
|
+
return c;
|
|
428
|
+
},
|
|
429
|
+
has(t, e) {
|
|
430
|
+
return e in p(t);
|
|
431
|
+
},
|
|
432
|
+
ownKeys(t) {
|
|
433
|
+
return Reflect.ownKeys(p(t));
|
|
434
|
+
},
|
|
435
|
+
set(t, e, i) {
|
|
436
|
+
const n = Ft(p(t), e);
|
|
437
|
+
if (n?.set)
|
|
438
|
+
return n.set.call(t.draft_, i), !0;
|
|
439
|
+
if (!t.modified_) {
|
|
440
|
+
const o = ft(p(t), e), c = o?.[_];
|
|
441
|
+
if (c && c.base_ === i)
|
|
442
|
+
return t.copy_[e] = i, t.assigned_.set(e, !1), !0;
|
|
443
|
+
if (Bt(i, o) && (i !== void 0 || Dt(t.base_, e, t.type_)))
|
|
444
|
+
return !0;
|
|
445
|
+
N(t), O(t);
|
|
446
|
+
}
|
|
447
|
+
return t.copy_[e] === i && // special case: handle new props with value 'undefined'
|
|
448
|
+
(i !== void 0 || e in t.copy_) || // special case: NaN
|
|
449
|
+
Number.isNaN(i) && Number.isNaN(t.copy_[e]) || (t.copy_[e] = i, t.assigned_.set(e, !0), St(t, e, i)), !0;
|
|
450
|
+
},
|
|
451
|
+
deleteProperty(t, e) {
|
|
452
|
+
return N(t), ft(t.base_, e) !== void 0 || e in t.base_ ? (t.assigned_.set(e, !1), O(t)) : t.assigned_.delete(e), t.copy_ && delete t.copy_[e], !0;
|
|
453
|
+
},
|
|
454
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
455
|
+
// the same guarantee in ES5 mode.
|
|
456
|
+
getOwnPropertyDescriptor(t, e) {
|
|
457
|
+
const i = p(t), n = Reflect.getOwnPropertyDescriptor(i, e);
|
|
458
|
+
return n && {
|
|
459
|
+
[W]: !0,
|
|
460
|
+
[dt]: t.type_ !== 1 || e !== "length",
|
|
461
|
+
[Y]: n[Y],
|
|
462
|
+
[R]: i[e]
|
|
463
|
+
};
|
|
464
|
+
},
|
|
465
|
+
defineProperty() {
|
|
466
|
+
M(11);
|
|
467
|
+
},
|
|
468
|
+
getPrototypeOf(t) {
|
|
469
|
+
return k(t.base_);
|
|
470
|
+
},
|
|
471
|
+
setPrototypeOf() {
|
|
472
|
+
M(12);
|
|
473
|
+
}
|
|
474
|
+
}, L = {};
|
|
475
|
+
for (let t in tt) {
|
|
476
|
+
let e = tt[t];
|
|
477
|
+
L[t] = function() {
|
|
478
|
+
const i = arguments;
|
|
479
|
+
return i[0] = i[0][0], e.apply(this, i);
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
L.deleteProperty = function(t, e) {
|
|
483
|
+
return process.env.NODE_ENV !== "production" && isNaN(parseInt(e)) && M(13), L.set.call(this, t, e, void 0);
|
|
484
|
+
};
|
|
485
|
+
L.set = function(t, e, i) {
|
|
486
|
+
return process.env.NODE_ENV !== "production" && e !== "length" && isNaN(parseInt(e)) && M(14), tt.set.call(this, t[0], e, i, t[0]);
|
|
487
|
+
};
|
|
488
|
+
function ft(t, e) {
|
|
489
|
+
const i = t[_];
|
|
490
|
+
return (i ? p(i) : t)[e];
|
|
491
|
+
}
|
|
492
|
+
function Zt(t, e, i) {
|
|
493
|
+
const n = Ft(e, i);
|
|
494
|
+
return n ? R in n ? n[R] : (
|
|
495
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
496
|
+
// prototype, we should invoke it with the draft as context!
|
|
497
|
+
n.get?.call(t.draft_)
|
|
498
|
+
) : void 0;
|
|
499
|
+
}
|
|
500
|
+
function Ft(t, e) {
|
|
501
|
+
if (!(e in t))
|
|
502
|
+
return;
|
|
503
|
+
let i = k(t);
|
|
504
|
+
for (; i; ) {
|
|
505
|
+
const n = Object.getOwnPropertyDescriptor(i, e);
|
|
506
|
+
if (n)
|
|
507
|
+
return n;
|
|
508
|
+
i = k(i);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function O(t) {
|
|
512
|
+
t.modified_ || (t.modified_ = !0, t.parent_ && O(t.parent_));
|
|
513
|
+
}
|
|
514
|
+
function N(t) {
|
|
515
|
+
t.copy_ || (t.assigned_ = /* @__PURE__ */ new Map(), t.copy_ = _t(
|
|
516
|
+
t.base_,
|
|
517
|
+
t.scope_.immer_.useStrictShallowCopy_
|
|
518
|
+
));
|
|
519
|
+
}
|
|
520
|
+
var te = class {
|
|
521
|
+
constructor(t) {
|
|
522
|
+
this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !1, this.produce = (e, i, n) => {
|
|
523
|
+
if (C(e) && !C(i)) {
|
|
524
|
+
const c = i;
|
|
525
|
+
i = e;
|
|
526
|
+
const l = this;
|
|
527
|
+
return function(a = c, ...r) {
|
|
528
|
+
return l.produce(a, (s) => i.call(this, s, ...r));
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
C(i) || M(6), n !== void 0 && !C(n) && M(7);
|
|
532
|
+
let o;
|
|
533
|
+
if (E(e)) {
|
|
534
|
+
const c = Ot(this), l = B(c, e, void 0);
|
|
535
|
+
let u = !0;
|
|
536
|
+
try {
|
|
537
|
+
o = i(l), u = !1;
|
|
538
|
+
} finally {
|
|
539
|
+
u ? mt(c) : gt(c);
|
|
540
|
+
}
|
|
541
|
+
return Et(c, n), It(o, c);
|
|
542
|
+
} else if (!e || !st(e)) {
|
|
543
|
+
if (o = i(e), o === void 0 && (o = e), o === zt && (o = void 0), this.autoFreeze_ && Pt(o, !0), n) {
|
|
544
|
+
const c = [], l = [];
|
|
545
|
+
A(pt).generateReplacementPatches_(e, o, {
|
|
546
|
+
patches_: c,
|
|
547
|
+
inversePatches_: l
|
|
548
|
+
}), n(c, l);
|
|
549
|
+
}
|
|
550
|
+
return o;
|
|
551
|
+
} else
|
|
552
|
+
M(1, e);
|
|
553
|
+
}, this.produceWithPatches = (e, i) => {
|
|
554
|
+
if (C(e))
|
|
555
|
+
return (l, ...u) => this.produceWithPatches(l, (a) => e(a, ...u));
|
|
556
|
+
let n, o;
|
|
557
|
+
return [this.produce(e, i, (l, u) => {
|
|
558
|
+
n = l, o = u;
|
|
559
|
+
}), n, o];
|
|
560
|
+
}, lt(t?.autoFreeze) && this.setAutoFreeze(t.autoFreeze), lt(t?.useStrictShallowCopy) && this.setUseStrictShallowCopy(t.useStrictShallowCopy), lt(t?.useStrictIteration) && this.setUseStrictIteration(t.useStrictIteration);
|
|
561
|
+
}
|
|
562
|
+
createDraft(t) {
|
|
563
|
+
E(t) || M(8), V(t) && (t = ee(t));
|
|
564
|
+
const e = Ot(this), i = B(e, t, void 0);
|
|
565
|
+
return i[_].isManual_ = !0, gt(e), i;
|
|
566
|
+
}
|
|
567
|
+
finishDraft(t, e) {
|
|
568
|
+
const i = t && t[_];
|
|
569
|
+
(!i || !i.isManual_) && M(9);
|
|
570
|
+
const { scope_: n } = i;
|
|
571
|
+
return Et(n, e), It(void 0, n);
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
575
|
+
*
|
|
576
|
+
* By default, auto-freezing is enabled.
|
|
577
|
+
*/
|
|
578
|
+
setAutoFreeze(t) {
|
|
579
|
+
this.autoFreeze_ = t;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Pass true to enable strict shallow copy.
|
|
583
|
+
*
|
|
584
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
585
|
+
*/
|
|
586
|
+
setUseStrictShallowCopy(t) {
|
|
587
|
+
this.useStrictShallowCopy_ = t;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
591
|
+
* but still handles symbols for compatibility.
|
|
592
|
+
*
|
|
593
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
594
|
+
*/
|
|
595
|
+
setUseStrictIteration(t) {
|
|
596
|
+
this.useStrictIteration_ = t;
|
|
597
|
+
}
|
|
598
|
+
shouldUseStrictIteration() {
|
|
599
|
+
return this.useStrictIteration_;
|
|
600
|
+
}
|
|
601
|
+
applyPatches(t, e) {
|
|
602
|
+
let i;
|
|
603
|
+
for (i = e.length - 1; i >= 0; i--) {
|
|
604
|
+
const o = e[i];
|
|
605
|
+
if (o.path.length === 0 && o.op === "replace") {
|
|
606
|
+
t = o.value;
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
i > -1 && (e = e.slice(i + 1));
|
|
611
|
+
const n = A(pt).applyPatches_;
|
|
612
|
+
return V(t) ? n(t, e) : this.produce(
|
|
613
|
+
t,
|
|
614
|
+
(o) => n(o, e)
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
function B(t, e, i, n) {
|
|
619
|
+
const [o, c] = nt(e) ? A(U).proxyMap_(e, i) : rt(e) ? A(U).proxySet_(e, i) : Xt(e, i);
|
|
620
|
+
return (i?.scope_ ?? X()).drafts_.push(o), c.callbacks_ = i?.callbacks_ ?? [], c.key_ = n, i && n !== void 0 ? Qt(i, c, n) : c.callbacks_.push(function(a) {
|
|
621
|
+
a.mapSetPlugin_?.fixSetContents(c);
|
|
622
|
+
const { patchPlugin_: r } = a;
|
|
623
|
+
c.modified_ && r && r.generatePatches_(c, [], a);
|
|
624
|
+
}), o;
|
|
625
|
+
}
|
|
626
|
+
function ee(t) {
|
|
627
|
+
return V(t) || M(10, t), Nt(t);
|
|
628
|
+
}
|
|
629
|
+
function Nt(t) {
|
|
630
|
+
if (!E(t) || ot(t))
|
|
631
|
+
return t;
|
|
632
|
+
const e = t[_];
|
|
633
|
+
let i, n = !0;
|
|
634
|
+
if (e) {
|
|
635
|
+
if (!e.modified_)
|
|
636
|
+
return e.base_;
|
|
637
|
+
e.finalized_ = !0, i = _t(t, e.scope_.immer_.useStrictShallowCopy_), n = e.scope_.immer_.shouldUseStrictIteration();
|
|
638
|
+
} else
|
|
639
|
+
i = _t(t, !0);
|
|
640
|
+
return H(
|
|
641
|
+
i,
|
|
642
|
+
(o, c) => {
|
|
643
|
+
J(i, o, Nt(c));
|
|
644
|
+
},
|
|
645
|
+
n
|
|
646
|
+
), e && (e.finalized_ = !1), i;
|
|
647
|
+
}
|
|
648
|
+
function ie() {
|
|
649
|
+
class t extends Map {
|
|
650
|
+
constructor(r, s) {
|
|
651
|
+
super(), this[_] = {
|
|
652
|
+
type_: 2,
|
|
653
|
+
parent_: s,
|
|
654
|
+
scope_: s ? s.scope_ : X(),
|
|
655
|
+
modified_: !1,
|
|
656
|
+
finalized_: !1,
|
|
657
|
+
copy_: void 0,
|
|
658
|
+
assigned_: void 0,
|
|
659
|
+
base_: r,
|
|
660
|
+
draft_: this,
|
|
661
|
+
isManual_: !1,
|
|
662
|
+
revoked_: !1,
|
|
663
|
+
callbacks_: []
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
get size() {
|
|
667
|
+
return p(this[_]).size;
|
|
668
|
+
}
|
|
669
|
+
has(r) {
|
|
670
|
+
return p(this[_]).has(r);
|
|
671
|
+
}
|
|
672
|
+
set(r, s) {
|
|
673
|
+
const f = this[_];
|
|
674
|
+
return l(f), (!p(f).has(r) || p(f).get(r) !== s) && (i(f), O(f), f.assigned_.set(r, !0), f.copy_.set(r, s), f.assigned_.set(r, !0), St(f, r, s)), this;
|
|
675
|
+
}
|
|
676
|
+
delete(r) {
|
|
677
|
+
if (!this.has(r))
|
|
678
|
+
return !1;
|
|
679
|
+
const s = this[_];
|
|
680
|
+
return l(s), i(s), O(s), s.base_.has(r) ? s.assigned_.set(r, !1) : s.assigned_.delete(r), s.copy_.delete(r), !0;
|
|
681
|
+
}
|
|
682
|
+
clear() {
|
|
683
|
+
const r = this[_];
|
|
684
|
+
l(r), p(r).size && (i(r), O(r), r.assigned_ = /* @__PURE__ */ new Map(), H(r.base_, (s) => {
|
|
685
|
+
r.assigned_.set(s, !1);
|
|
686
|
+
}), r.copy_.clear());
|
|
687
|
+
}
|
|
688
|
+
forEach(r, s) {
|
|
689
|
+
const f = this[_];
|
|
690
|
+
p(f).forEach((h, v, g) => {
|
|
691
|
+
r.call(s, this.get(v), v, this);
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
get(r) {
|
|
695
|
+
const s = this[_];
|
|
696
|
+
l(s);
|
|
697
|
+
const f = p(s).get(r);
|
|
698
|
+
if (s.finalized_ || !E(f) || f !== s.base_.get(r))
|
|
699
|
+
return f;
|
|
700
|
+
const h = B(s.scope_, f, s, r);
|
|
701
|
+
return i(s), s.copy_.set(r, h), h;
|
|
702
|
+
}
|
|
703
|
+
keys() {
|
|
704
|
+
return p(this[_]).keys();
|
|
705
|
+
}
|
|
706
|
+
values() {
|
|
707
|
+
const r = this.keys();
|
|
708
|
+
return {
|
|
709
|
+
[Symbol.iterator]: () => this.values(),
|
|
710
|
+
next: () => {
|
|
711
|
+
const s = r.next();
|
|
712
|
+
return s.done ? s : {
|
|
713
|
+
done: !1,
|
|
714
|
+
value: this.get(s.value)
|
|
715
|
+
};
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
entries() {
|
|
720
|
+
const r = this.keys();
|
|
721
|
+
return {
|
|
722
|
+
[Symbol.iterator]: () => this.entries(),
|
|
723
|
+
next: () => {
|
|
724
|
+
const s = r.next();
|
|
725
|
+
if (s.done)
|
|
726
|
+
return s;
|
|
727
|
+
const f = this.get(s.value);
|
|
728
|
+
return {
|
|
729
|
+
done: !1,
|
|
730
|
+
value: [s.value, f]
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
[Symbol.iterator]() {
|
|
736
|
+
return this.entries();
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
function e(a, r) {
|
|
740
|
+
const s = new t(a, r);
|
|
741
|
+
return [s, s[_]];
|
|
742
|
+
}
|
|
743
|
+
function i(a) {
|
|
744
|
+
a.copy_ || (a.assigned_ = /* @__PURE__ */ new Map(), a.copy_ = new Map(a.base_));
|
|
745
|
+
}
|
|
746
|
+
class n extends Set {
|
|
747
|
+
constructor(r, s) {
|
|
748
|
+
super(), this[_] = {
|
|
749
|
+
type_: 3,
|
|
750
|
+
parent_: s,
|
|
751
|
+
scope_: s ? s.scope_ : X(),
|
|
752
|
+
modified_: !1,
|
|
753
|
+
finalized_: !1,
|
|
754
|
+
copy_: void 0,
|
|
755
|
+
base_: r,
|
|
756
|
+
draft_: this,
|
|
757
|
+
drafts_: /* @__PURE__ */ new Map(),
|
|
758
|
+
revoked_: !1,
|
|
759
|
+
isManual_: !1,
|
|
760
|
+
assigned_: void 0,
|
|
761
|
+
callbacks_: []
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
get size() {
|
|
765
|
+
return p(this[_]).size;
|
|
766
|
+
}
|
|
767
|
+
has(r) {
|
|
768
|
+
const s = this[_];
|
|
769
|
+
return l(s), s.copy_ ? !!(s.copy_.has(r) || s.drafts_.has(r) && s.copy_.has(s.drafts_.get(r))) : s.base_.has(r);
|
|
770
|
+
}
|
|
771
|
+
add(r) {
|
|
772
|
+
const s = this[_];
|
|
773
|
+
return l(s), this.has(r) || (c(s), O(s), s.copy_.add(r), St(s, r, r)), this;
|
|
774
|
+
}
|
|
775
|
+
delete(r) {
|
|
776
|
+
if (!this.has(r))
|
|
777
|
+
return !1;
|
|
778
|
+
const s = this[_];
|
|
779
|
+
return l(s), c(s), O(s), s.copy_.delete(r) || (s.drafts_.has(r) ? s.copy_.delete(s.drafts_.get(r)) : (
|
|
780
|
+
/* istanbul ignore next */
|
|
781
|
+
!1
|
|
782
|
+
));
|
|
783
|
+
}
|
|
784
|
+
clear() {
|
|
785
|
+
const r = this[_];
|
|
786
|
+
l(r), p(r).size && (c(r), O(r), r.copy_.clear());
|
|
787
|
+
}
|
|
788
|
+
values() {
|
|
789
|
+
const r = this[_];
|
|
790
|
+
return l(r), c(r), r.copy_.values();
|
|
791
|
+
}
|
|
792
|
+
entries() {
|
|
793
|
+
const r = this[_];
|
|
794
|
+
return l(r), c(r), r.copy_.entries();
|
|
795
|
+
}
|
|
796
|
+
keys() {
|
|
797
|
+
return this.values();
|
|
798
|
+
}
|
|
799
|
+
[Symbol.iterator]() {
|
|
800
|
+
return this.values();
|
|
801
|
+
}
|
|
802
|
+
forEach(r, s) {
|
|
803
|
+
const f = this.values();
|
|
804
|
+
let h = f.next();
|
|
805
|
+
for (; !h.done; )
|
|
806
|
+
r.call(s, h.value, h.value, this), h = f.next();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function o(a, r) {
|
|
810
|
+
const s = new n(a, r);
|
|
811
|
+
return [s, s[_]];
|
|
812
|
+
}
|
|
813
|
+
function c(a) {
|
|
814
|
+
a.copy_ || (a.copy_ = /* @__PURE__ */ new Set(), a.base_.forEach((r) => {
|
|
815
|
+
if (E(r)) {
|
|
816
|
+
const s = B(a.scope_, r, a, r);
|
|
817
|
+
a.drafts_.set(r, s), a.copy_.add(s);
|
|
818
|
+
} else
|
|
819
|
+
a.copy_.add(r);
|
|
820
|
+
}));
|
|
821
|
+
}
|
|
822
|
+
function l(a) {
|
|
823
|
+
a.revoked_ && M(3, JSON.stringify(p(a)));
|
|
824
|
+
}
|
|
825
|
+
function u(a) {
|
|
826
|
+
if (a.type_ === 3 && a.copy_) {
|
|
827
|
+
const r = new Set(a.copy_);
|
|
828
|
+
a.copy_.clear(), r.forEach((s) => {
|
|
829
|
+
a.copy_.add(Gt(s));
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
Vt(U, { proxyMap_: e, proxySet_: o, fixSetContents: u });
|
|
834
|
+
}
|
|
835
|
+
function ne() {
|
|
836
|
+
const t = /* @__PURE__ */ new Set(["shift", "unshift"]), e = /* @__PURE__ */ new Set(["push", "pop"]), i = /* @__PURE__ */ new Set([
|
|
837
|
+
...e,
|
|
838
|
+
...t
|
|
839
|
+
]), n = /* @__PURE__ */ new Set(["reverse", "sort"]), o = /* @__PURE__ */ new Set([
|
|
840
|
+
...i,
|
|
841
|
+
...n,
|
|
842
|
+
"splice"
|
|
843
|
+
]), c = /* @__PURE__ */ new Set(["find", "findLast"]), l = /* @__PURE__ */ new Set([
|
|
844
|
+
"filter",
|
|
845
|
+
"slice",
|
|
846
|
+
"concat",
|
|
847
|
+
"flat",
|
|
848
|
+
...c,
|
|
849
|
+
"findIndex",
|
|
850
|
+
"findLastIndex",
|
|
851
|
+
"some",
|
|
852
|
+
"every",
|
|
853
|
+
"indexOf",
|
|
854
|
+
"lastIndexOf",
|
|
855
|
+
"includes",
|
|
856
|
+
"join",
|
|
857
|
+
"toString",
|
|
858
|
+
"toLocaleString"
|
|
859
|
+
]);
|
|
860
|
+
function u(d) {
|
|
861
|
+
return o.has(d);
|
|
862
|
+
}
|
|
863
|
+
function a(d) {
|
|
864
|
+
return l.has(d);
|
|
865
|
+
}
|
|
866
|
+
function r(d) {
|
|
867
|
+
return u(d) || a(d);
|
|
868
|
+
}
|
|
869
|
+
function s(d, y) {
|
|
870
|
+
d.operationMethod = y;
|
|
871
|
+
}
|
|
872
|
+
function f(d) {
|
|
873
|
+
d.operationMethod = void 0;
|
|
874
|
+
}
|
|
875
|
+
function h(d, y, w = !0) {
|
|
876
|
+
N(d);
|
|
877
|
+
const m = y();
|
|
878
|
+
return O(d), w && d.assigned_.set("length", !0), m;
|
|
879
|
+
}
|
|
880
|
+
function v(d) {
|
|
881
|
+
d.allIndicesReassigned_ = !0;
|
|
882
|
+
}
|
|
883
|
+
function g(d, y) {
|
|
884
|
+
return d < 0 ? Math.max(y + d, 0) : Math.min(d, y);
|
|
885
|
+
}
|
|
886
|
+
function I(d, y, w) {
|
|
887
|
+
return h(d, () => {
|
|
888
|
+
const m = d.copy_[y](...w);
|
|
889
|
+
return t.has(y) && v(d), i.has(y) ? m : d.draft_;
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
function xt(d, y, w) {
|
|
893
|
+
return h(
|
|
894
|
+
d,
|
|
895
|
+
() => (d.copy_[y](...w), v(d), d.draft_),
|
|
896
|
+
!1
|
|
897
|
+
);
|
|
898
|
+
}
|
|
899
|
+
function Rt(d, y) {
|
|
900
|
+
return function(...m) {
|
|
901
|
+
const P = y;
|
|
902
|
+
s(d, P);
|
|
903
|
+
try {
|
|
904
|
+
if (u(P)) {
|
|
905
|
+
if (i.has(P))
|
|
906
|
+
return I(d, P, m);
|
|
907
|
+
if (n.has(P))
|
|
908
|
+
return xt(d, P, m);
|
|
909
|
+
if (P === "splice") {
|
|
910
|
+
const b = h(
|
|
911
|
+
d,
|
|
912
|
+
() => d.copy_.splice(...m)
|
|
913
|
+
);
|
|
914
|
+
return v(d), b;
|
|
915
|
+
}
|
|
916
|
+
} else
|
|
917
|
+
return Ut(d, P, m);
|
|
918
|
+
} finally {
|
|
919
|
+
f(d);
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
}
|
|
923
|
+
function Ut(d, y, w) {
|
|
924
|
+
const m = p(d);
|
|
925
|
+
if (y === "filter") {
|
|
926
|
+
const P = w[0], b = [];
|
|
927
|
+
for (let z = 0; z < m.length; z++)
|
|
928
|
+
P(m[z], z, m) && b.push(d.draft_[z]);
|
|
929
|
+
return b;
|
|
930
|
+
}
|
|
931
|
+
if (c.has(y)) {
|
|
932
|
+
const P = w[0], b = y === "find", z = b ? 1 : -1, ct = b ? 0 : m.length - 1;
|
|
933
|
+
for (let T = ct; T >= 0 && T < m.length; T += z)
|
|
934
|
+
if (P(m[T], T, m))
|
|
935
|
+
return d.draft_[T];
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
if (y === "slice") {
|
|
939
|
+
const P = w[0] ?? 0, b = w[1] ?? m.length, z = g(P, m.length), ct = g(b, m.length), T = [];
|
|
940
|
+
for (let ut = z; ut < ct; ut++)
|
|
941
|
+
T.push(d.draft_[ut]);
|
|
942
|
+
return T;
|
|
943
|
+
}
|
|
944
|
+
return m[y](...w);
|
|
945
|
+
}
|
|
946
|
+
Vt(yt, {
|
|
947
|
+
createMethodInterceptor: Rt,
|
|
948
|
+
isArrayOperationMethod: r,
|
|
949
|
+
isMutatingArrayMethod: u
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
var re = new te(), F = re.produce;
|
|
953
|
+
let se = 0;
|
|
954
|
+
function oe() {
|
|
955
|
+
return se++;
|
|
956
|
+
}
|
|
957
|
+
class x {
|
|
958
|
+
constructor(e, i) {
|
|
959
|
+
this.controller = e, this.path = i, this.id = oe(), this._isTouched = !1, this._isDirty = !1;
|
|
960
|
+
}
|
|
961
|
+
get value() {
|
|
962
|
+
return S.getValue(
|
|
963
|
+
this.controller._data,
|
|
964
|
+
this.path
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
get boundElement() {
|
|
968
|
+
return this.target;
|
|
969
|
+
}
|
|
970
|
+
get issues() {
|
|
971
|
+
return this.controller._issues.filter(
|
|
972
|
+
(e) => e.path?.join(".") === this.path
|
|
973
|
+
);
|
|
974
|
+
}
|
|
975
|
+
get isTouched() {
|
|
976
|
+
return this._isTouched;
|
|
977
|
+
}
|
|
978
|
+
get isDirty() {
|
|
979
|
+
return this._isDirty;
|
|
980
|
+
}
|
|
981
|
+
get isValid() {
|
|
982
|
+
return this.issues.length === 0;
|
|
983
|
+
}
|
|
984
|
+
_setTouched(e) {
|
|
985
|
+
const i = this._isTouched !== e;
|
|
986
|
+
this._isTouched = e, i && this.controller.events.emit("fieldTouchUpdated", this.path);
|
|
987
|
+
}
|
|
988
|
+
_setDirty(e) {
|
|
989
|
+
const i = this._isDirty !== e;
|
|
990
|
+
this._isDirty = e, i && this.controller.events.emit("fieldDirtyUpdated", this.path);
|
|
991
|
+
}
|
|
992
|
+
bindElement(e) {
|
|
993
|
+
e != null ? this.controller.events.emit("elementBound", this.path, e) : this.controller.events.emit("elementUnbound", this.path), this.target = e;
|
|
994
|
+
}
|
|
995
|
+
static ensureImmerability(e) {
|
|
996
|
+
if (typeof e != "object" || e === null) return;
|
|
997
|
+
const i = Object.getPrototypeOf(e);
|
|
998
|
+
if (i === Object.prototype || i === null) return;
|
|
999
|
+
const n = i.constructor;
|
|
1000
|
+
typeof n == "function" && (e instanceof Date || e instanceof RegExp || e instanceof Map || e instanceof Set || e instanceof WeakMap || e instanceof WeakSet || ArrayBuffer.isView(e) || n[$] !== !0 && (n[$] = !0));
|
|
1001
|
+
}
|
|
1002
|
+
setValue(e, i) {
|
|
1003
|
+
return this.modifyValue(() => e, i);
|
|
1004
|
+
}
|
|
1005
|
+
modifyValue(e, i) {
|
|
1006
|
+
(i?.shouldTouch == null || i?.shouldTouch) && this.touch();
|
|
1007
|
+
const n = S.getValue(
|
|
1008
|
+
this.controller._initialData,
|
|
1009
|
+
this.path
|
|
1010
|
+
), o = S.getValue(
|
|
1011
|
+
this.controller._data,
|
|
1012
|
+
this.path
|
|
1013
|
+
);
|
|
1014
|
+
x.ensureImmerability(n), x.ensureImmerability(o), this.controller._data = F(this.controller._data, (a) => {
|
|
1015
|
+
S.modifyValue(
|
|
1016
|
+
a,
|
|
1017
|
+
this.path,
|
|
1018
|
+
(r) => e(r, this)
|
|
1019
|
+
);
|
|
1020
|
+
});
|
|
1021
|
+
const c = S.getValue(
|
|
1022
|
+
this.controller._data,
|
|
1023
|
+
this.path
|
|
1024
|
+
);
|
|
1025
|
+
x.ensureImmerability(c);
|
|
1026
|
+
const l = (a, r) => {
|
|
1027
|
+
if (typeof a != "object" || typeof r != "object") return;
|
|
1028
|
+
const s = a.constructor, f = r.constructor;
|
|
1029
|
+
if (s === f)
|
|
1030
|
+
return this.controller.equalityComparators?.[s]?.(a, r);
|
|
1031
|
+
};
|
|
1032
|
+
if (!S.deepEqual(o, c, l) && this.controller.events.emit(
|
|
1033
|
+
"valueChanged",
|
|
1034
|
+
this.path,
|
|
1035
|
+
c,
|
|
1036
|
+
o
|
|
1037
|
+
), i?.shouldMarkDirty == null || i?.shouldMarkDirty) {
|
|
1038
|
+
const a = !S.deepEqual(n, c, l);
|
|
1039
|
+
this._setDirty(a);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
reset() {
|
|
1043
|
+
this._setTouched(!1), this._setDirty(!1);
|
|
1044
|
+
}
|
|
1045
|
+
touch() {
|
|
1046
|
+
this._setTouched(!0);
|
|
1047
|
+
}
|
|
1048
|
+
markDirty() {
|
|
1049
|
+
this.touch(), this._setDirty(!0);
|
|
1050
|
+
}
|
|
1051
|
+
triggerValidation() {
|
|
1052
|
+
this.controller.validateField(this.path);
|
|
1053
|
+
}
|
|
1054
|
+
focus(e) {
|
|
1055
|
+
(e?.shouldTouch == null || e.shouldTouch) && this.target?.addEventListener("focus", () => this.touch(), {
|
|
1056
|
+
once: !0
|
|
1057
|
+
}), this.target?.scrollIntoView(), this.target?.focus();
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
let ae = () => ({
|
|
1061
|
+
emit(t, ...e) {
|
|
1062
|
+
for (let i = this.events[t] || [], n = 0, o = i.length; n < o; n++)
|
|
1063
|
+
i[n](...e);
|
|
1064
|
+
},
|
|
1065
|
+
events: {},
|
|
1066
|
+
on(t, e) {
|
|
1067
|
+
return (this.events[t] ||= []).push(e), () => {
|
|
1068
|
+
this.events[t] = this.events[t]?.filter((i) => e !== i);
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
function ce(t, e) {
|
|
1073
|
+
let i = [];
|
|
1074
|
+
for (let n = t.length - 1; n >= 0; n--)
|
|
1075
|
+
e(t[n]) && i.push(n);
|
|
1076
|
+
i.forEach((n) => t.splice(n, 1));
|
|
1077
|
+
}
|
|
1078
|
+
ie();
|
|
1079
|
+
ne();
|
|
1080
|
+
class ue {
|
|
1081
|
+
constructor(e) {
|
|
1082
|
+
this._status = "idle", this._fields = /* @__PURE__ */ new Map(), this._issues = [], this.events = ae(), this.validationSchema = e.validationSchema, this.equalityComparators = e.equalityComparators, this._initialData = e.initialData ?? {}, this._data = F(this._initialData, () => {
|
|
1083
|
+
});
|
|
1084
|
+
}
|
|
1085
|
+
get isDirty() {
|
|
1086
|
+
for (const e of this._fields.values())
|
|
1087
|
+
if (e.isDirty) return !0;
|
|
1088
|
+
return !1;
|
|
1089
|
+
}
|
|
1090
|
+
get isValid() {
|
|
1091
|
+
return this._issues.length === 0;
|
|
1092
|
+
}
|
|
1093
|
+
get isSubmitting() {
|
|
1094
|
+
return this._status === "submitting";
|
|
1095
|
+
}
|
|
1096
|
+
setStatus(e) {
|
|
1097
|
+
if (e === this._status) return;
|
|
1098
|
+
const i = this._status;
|
|
1099
|
+
this._status = e, this.events.emit("statusChanged", e, i);
|
|
1100
|
+
}
|
|
1101
|
+
_unsafeSetFieldValue(e, i, n) {
|
|
1102
|
+
n?.updateInitialValue && (this._initialData = F(this._initialData, (o) => {
|
|
1103
|
+
S.setValue(o, e, i);
|
|
1104
|
+
})), this._data = F(this._data, (o) => {
|
|
1105
|
+
S.setValue(o, e, i);
|
|
1106
|
+
});
|
|
1107
|
+
}
|
|
1108
|
+
bindField(e, i) {
|
|
1109
|
+
const n = new x(this, e);
|
|
1110
|
+
return console.log("Binding", e, i?.defaultValue, n.id), this._fields.set(e, n), this.events.emit("fieldBound", e), i?.defaultValue != null && this._unsafeSetFieldValue(e, i.defaultValue, {
|
|
1111
|
+
updateInitialValue: !0
|
|
1112
|
+
}), i?.domElement != null && n.bindElement(i.domElement), n;
|
|
1113
|
+
}
|
|
1114
|
+
unbindField(e) {
|
|
1115
|
+
this._fields.delete(e), this.events.emit("fieldUnbound", e);
|
|
1116
|
+
}
|
|
1117
|
+
// TODO: Add an option to keep dirty/touched fields as they are
|
|
1118
|
+
reset(e) {
|
|
1119
|
+
this.setStatus("idle"), this._data = this._initialData, this._issues = [];
|
|
1120
|
+
for (const i of this._fields.values())
|
|
1121
|
+
i.reset();
|
|
1122
|
+
e != null && (this._initialData = e, this._data = F(this._initialData, () => {
|
|
1123
|
+
}));
|
|
1124
|
+
}
|
|
1125
|
+
getField(e, i) {
|
|
1126
|
+
let n = this._fields.get(e);
|
|
1127
|
+
return n == null && i?.bindIfMissing && (n = this.bindField(e)), n;
|
|
1128
|
+
}
|
|
1129
|
+
clearFieldIssues(e) {
|
|
1130
|
+
this._issues = this._issues.filter((i) => i.path == null ? !0 : i.path.join(".") !== e);
|
|
1131
|
+
}
|
|
1132
|
+
async applyValidation(e, i) {
|
|
1133
|
+
const n = S.diff(
|
|
1134
|
+
this._issues,
|
|
1135
|
+
e.issues ?? [],
|
|
1136
|
+
S.deepEqual,
|
|
1137
|
+
(o) => o.path == null ? !1 : o.path.join(".") === i
|
|
1138
|
+
);
|
|
1139
|
+
ce(this._issues, (o) => n.removed.includes(o)), n.added.forEach((o) => this._issues.push(o)), (n.added.length !== 0 || n.removed.length !== 0) && this.events.emit("validationIssuesUpdated", i);
|
|
1140
|
+
}
|
|
1141
|
+
async validateField(e) {
|
|
1142
|
+
if (this._status !== "idle" || this.validationSchema == null) return;
|
|
1143
|
+
this.setStatus("validating"), this.getField(e, { bindIfMissing: !0 });
|
|
1144
|
+
const i = await this.validationSchema["~standard"].validate(
|
|
1145
|
+
this._data
|
|
1146
|
+
);
|
|
1147
|
+
this.events.emit("validationTriggered", e), this.applyValidation(i, e), this.setStatus("idle");
|
|
1148
|
+
}
|
|
1149
|
+
async validateForm() {
|
|
1150
|
+
if (this._status !== "idle" || this.validationSchema == null) return;
|
|
1151
|
+
this.setStatus("validating");
|
|
1152
|
+
const e = await this.validationSchema["~standard"].validate(
|
|
1153
|
+
this._data
|
|
1154
|
+
);
|
|
1155
|
+
for (const n of this._fields.keys())
|
|
1156
|
+
this.events.emit("validationTriggered", n), this.applyValidation(e, n);
|
|
1157
|
+
S.diff(this._issues, e.issues ?? [], S.deepEqual).added.forEach((n) => this._issues.push(n)), this.setStatus("idle");
|
|
1158
|
+
}
|
|
1159
|
+
createSubmitHandler(e, i) {
|
|
1160
|
+
return async (n) => {
|
|
1161
|
+
if (n?.preventDefault(), this._status !== "idle") return;
|
|
1162
|
+
const o = new AbortController();
|
|
1163
|
+
if (await this.validateForm(), this._issues.length === 0) {
|
|
1164
|
+
this.setStatus("submitting"), await e?.(this._data, n, o.signal), this.setStatus("idle");
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
for (const c of this._issues) {
|
|
1168
|
+
if (c.path == null) continue;
|
|
1169
|
+
const l = c.path.join("."), u = this.getField(l);
|
|
1170
|
+
if (u != null && u.boundElement != null) {
|
|
1171
|
+
u.focus();
|
|
1172
|
+
break;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
await i?.(this._issues, n, o.signal), this.setStatus("idle");
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
export {
|
|
1180
|
+
S as Field,
|
|
1181
|
+
ue as FormController,
|
|
1182
|
+
x as FormField
|
|
1183
|
+
};
|
|
1184
|
+
//# sourceMappingURL=index.js.map
|