attaform 0.31.1 → 0.31.2

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 (44) hide show
  1. package/dist/abstract.d.mts +5 -5
  2. package/dist/abstract.mjs +3 -2
  3. package/dist/dev/abstract.mjs +3 -2
  4. package/dist/dev/directive.mjs +1 -1
  5. package/dist/dev/history.mjs +118 -11
  6. package/dist/dev/index.mjs +4 -3
  7. package/dist/dev/shared/{attaform-dev.OceE0X3v.mjs → attaform-dev.BKWPjEB2.mjs} +4 -3
  8. package/dist/dev/shared/{attaform-dev.D7lKyM_7.mjs → attaform-dev.BnLLxX2l.mjs} +3 -3
  9. package/dist/dev/shared/{attaform-dev.Cbx0AiQF.mjs → attaform-dev.CKSqs_xQ.mjs} +1 -1
  10. package/dist/dev/shared/{attaform-dev.BpVGFSFa.mjs → attaform-dev.Cf_hZfbT.mjs} +3 -3
  11. package/dist/dev/shared/{attaform-dev.3uTCYwy8.mjs → attaform-dev.DLk51W7-.mjs} +111 -909
  12. package/dist/dev/shared/{attaform-dev.CwYTWyPX.mjs → attaform-dev.DoG8mZTq.mjs} +8 -1
  13. package/dist/dev/shared/attaform-dev.G-3XDl9F.mjs +1192 -0
  14. package/dist/dev/shared/{attaform-dev.PTGM9KE1.mjs → attaform-dev.oguHqv1W.mjs} +7 -6
  15. package/dist/dev/zod-v3.mjs +5 -4
  16. package/dist/dev/zod-v4.mjs +5 -4
  17. package/dist/dev/zod.mjs +4 -3
  18. package/dist/directive.d.mts +2 -2
  19. package/dist/directive.mjs +1 -1
  20. package/dist/history.d.mts +1 -1
  21. package/dist/history.mjs +118 -11
  22. package/dist/index.d.mts +6 -6
  23. package/dist/index.mjs +4 -3
  24. package/dist/shared/{attaform.j9xI_ObC.mjs → attaform.3kV6PqVJ.mjs} +7 -6
  25. package/dist/shared/{attaform.KEfNRDot.mjs → attaform.BJeiuJE2.mjs} +3 -3
  26. package/dist/shared/{attaform._1Zp3mDG.mjs → attaform.BNUhW4qC.mjs} +8 -1
  27. package/dist/shared/{attaform.B5b-HmhH.mjs → attaform.BlAmZ-WU.mjs} +3 -3
  28. package/dist/shared/{attaform.u6jfHoed.mjs → attaform.CMzc4bPI.mjs} +4 -3
  29. package/dist/shared/attaform.CgyyJVuq.mjs +1187 -0
  30. package/dist/shared/{attaform.CYlF4P6X.d.mts → attaform.CibLYe9-.d.mts} +185 -165
  31. package/dist/shared/{attaform.DAf4ehIe.mjs → attaform.DCUJCKyG.mjs} +111 -909
  32. package/dist/shared/{attaform.DZOynI6c.d.mts → attaform.DCyZT7u-.d.mts} +1 -1
  33. package/dist/shared/{attaform.B9PYKlhB.d.mts → attaform.DD0Y8krq.d.mts} +1 -1
  34. package/dist/shared/{attaform.BPMOl562.mjs → attaform.T0YjhjPU.mjs} +1 -1
  35. package/dist/shared/{attaform.i13OEHJF.d.mts → attaform.bI_4nKZp.d.mts} +61 -3
  36. package/dist/zod-v3.d.mts +4 -4
  37. package/dist/zod-v3.mjs +5 -4
  38. package/dist/zod-v4.d.mts +6 -6
  39. package/dist/zod-v4.mjs +5 -4
  40. package/dist/zod.d.mts +4 -4
  41. package/dist/zod.mjs +4 -3
  42. package/package.json +1 -1
  43. package/dist/dev/shared/attaform-dev.n6n00owJ.mjs +0 -279
  44. package/dist/shared/attaform.BPSqtU7a.mjs +0 -274
@@ -1,83 +1,10 @@
1
1
  import { computed, readonly, toRaw, ref, watchEffect, getCurrentScope, onScopeDispose, shallowReadonly, reactive, shallowReactive, shallowRef, toValue, watch, triggerRef, getCurrentInstance, onServerPrefetch, provide, useId, inject, effectScope, onBeforeMount, onBeforeUpdate, onMounted, nextTick } from 'vue';
2
2
  import { e as ensureAttaformInstalled, u as useRegistry, d as kFormContext, f as kFormInstanceId, b as kAttaformWizardActiveStepResolver, i as kAttaformAncestorWizard } from './attaform.CdA9bfRv.mjs';
3
- import { c as armDomBinding, r as recordInheritedModifiers, w as withInheritedModifiers } from './attaform.BPMOl562.mjs';
3
+ import { c as armDomBinding, r as recordInheritedModifiers, w as withInheritedModifiers } from './attaform.T0YjhjPU.mjs';
4
4
  import { R as REGISTER_OWNER_MARKER, b as V_REGISTER_MARKER } from './attaform.KvlEedlF.mjs';
5
- import { A as ANONYMOUS_FORM_KEY_PREFIX, d as diffAndApply, i as isBarePatch, p as pickDefined, s as structuralSnapshot, n as normalizeNumericOption, a as DEFAULT_FIELD_VALIDATION_DEBOUNCE_MS, b as isDescendable, c as applyChangedKeys, R as RESERVED_KEY_PREFIX, e as DEFAULT_MAX_RECURSION_DEPTH, f as ANONYMOUS_WIZARD_KEY_PREFIX } from './attaform.BPSqtU7a.mjs';
6
- import { e as canonicalizePath, i as isPathPrefix, f as pathsEqual, k as keyForSegments, m as mapSegmentKeys, b as ROOT_PATH_KEY, s as segmentsForPathKey, S as SubmitErrorHandlerError, t as toError, j as groupErrorsByKey, n as normalizeErrorInput, h as SET_MEMBER_SEGMENT, R as ROOT_PATH, l as normalizeErrorInputs, a as InvalidUseFormConfigError, d as ReservedFormKeyError } from './attaform.BhtAZysa.mjs';
7
- import { i as isShadowedKey, e as safeOwnHas, a as safeOwnRead, f as consumerHas, g as spreadConsumerRecord, h as copyConsumerArray, r as readConsumerIndex, s as safeAssign, c as consumerKeys, b as readConsumerProp, d as callConsumerFn, j as consumerSymbolKeys } from './attaform._1Zp3mDG.mjs';
8
-
9
- const AttaformErrorCode = {
10
- /** A required field is in the blank set: no value was supplied. */
11
- NoValueSupplied: "atta:no-value-supplied",
12
- /** The schema adapter's `validateAtPath` threw synchronously. */
13
- AdapterThrew: "atta:adapter-threw",
14
- /**
15
- * User code inside a `z.preprocess`, `.refine`, or `.transform`
16
- * threw (sync or async). The adapter caught the throw and surfaced
17
- * it as a `ValidationError` at the field path so the form's normal
18
- * error pipeline handles it instead of leaking as an unhandled
19
- * rejection or routing through `submitError`.
20
- */
21
- ValidatorThrew: "atta:validator-threw",
22
- /**
23
- * A function-form `defaultValues` factory threw or its promise
24
- * rejected. The runtime captures the raw error on `form.hydrateError`
25
- * and ALSO surfaces a form-level `ValidationError` (path `[]`) so
26
- * the standard error pipeline carries the signal. Critical for the
27
- * SSR round-trip: `hydrateError` itself does not ride the wire
28
- * payload, but `schemaErrors` does, so the client sees the failure
29
- * after rehydration without an extra channel.
30
- */
31
- HydrationFailed: "atta:hydration-failed",
32
- /** The supplied path didn't resolve to any node in the schema. */
33
- PathNotFound: "atta:path-not-found",
34
- /**
35
- * A walked form's `activate()` (async `defaultValues` factory) threw
36
- * during `wizard.handleSubmit`'s path walk. Surfaced as a synthetic
37
- * `ValidationError` at the form-level path (`[]`) so the wizard's
38
- * aggregate error pipeline can carry the failure alongside ordinary
39
- * validation errors. The raw factory error remains on
40
- * `form.hydrateError` for retry UX.
41
- */
42
- ActivationFailed: "atta:activation-failed",
43
- /**
44
- * Default code stamped on a manual error set through `form.setErrors`
45
- * when the caller omits an explicit `code`. The `setErrors` input is
46
- * lenient (`code` optional), so this is the fallback that keeps every
47
- * produced `ValidationError` carrying a stable, branchable identifier.
48
- * Override it per error by passing your own `code` (`api:…`, `auth:…`).
49
- */
50
- UserError: "atta:user-error",
51
- /**
52
- * Stamped on a `ValidationError` synthesized from a throw or rejection
53
- * out of a `handleSubmit` `onSubmit` callback. The raw error also lands
54
- * on `form.meta.submitError` (a raw-`Error` inspection channel); this
55
- * code marks the copy piped into the user-error layer so the failure
56
- * also surfaces on `form.errors` / `meta.ownErrors` / `firstOwnError`
57
- * where the UI already reads. A throw carrying its own `path` / `code`
58
- * keeps them; a bare `Error` or a non-Error throw defaults here at the
59
- * form-level path `[]`.
60
- */
61
- SubmitError: "atta:submit-error",
62
- /**
63
- * Synthesized by `wizard.handleSubmit` when the whole-wizard submit
64
- * would otherwise succeed but a `gate()` step is still uncleared. A
65
- * gate clears only on its member form's clean submit (confirmation), so
66
- * a downstream step that happens to be valid-by-default must not let the
67
- * wizard finish past an unconfirmed prerequisite. Emitted at the gate
68
- * form's key (path `[]`) so the aggregate error pipeline routes focus to
69
- * the gate, and `done` never latches.
70
- */
71
- GateNotCleared: "atta:gate-not-cleared"
72
- };
73
- function makeBlankRequiredError(segments) {
74
- return {
75
- message: "No value supplied",
76
- path: [...segments],
77
- code: AttaformErrorCode.NoValueSupplied
78
- };
79
- }
80
- const NO_ERRORS = Object.freeze([]);
5
+ import { a as ANONYMOUS_FORM_KEY_PREFIX, g as getAtPath, i as isPlainRecord, h as hasAtPath, b as makeBlankRequiredError, A as AttaformErrorCode, p as pickDefined, c as buildFieldArrayApi, s as structuralSnapshot, n as normalizeNumericOption, d as DEFAULT_FIELD_VALIDATION_DEBOUNCE_MS, e as diffAndApply, f as mergeStructural, N as NO_ERRORS, j as createArrayBookkeeping, k as createVariantMemory, l as createArrayIdentity, o as isDescendable, q as migrateFieldRecords, r as setAtPath, t as remapForOp, u as isBarePatch, v as applyChangedKeys, w as cloneVariantSnapshot, x as setAtPathWithSchemaFill, y as tryInPlaceLeafWrite, R as RESERVED_KEY_PREFIX, z as DEFAULT_MAX_RECURSION_DEPTH, B as ANONYMOUS_WIZARD_KEY_PREFIX } from './attaform.CgyyJVuq.mjs';
6
+ import { e as canonicalizePath, i as isPathPrefix, f as pathsEqual, k as keyForSegments, m as mapSegmentKeys, b as ROOT_PATH_KEY, S as SubmitErrorHandlerError, t as toError, j as groupErrorsByKey, s as segmentsForPathKey, n as normalizeErrorInput, h as SET_MEMBER_SEGMENT, R as ROOT_PATH, l as normalizeErrorInputs, a as InvalidUseFormConfigError, d as ReservedFormKeyError } from './attaform.BhtAZysa.mjs';
7
+ import { r as readConsumerIndex, c as consumerKeys, b as readConsumerProp, d as safeOwnHas, i as isShadowedKey, s as safeAssign, a as safeOwnRead, h as callConsumerFn, j as consumerExtensible, k as consumerSymbolKeys } from './attaform.BNUhW4qC.mjs';
81
8
 
82
9
  function isGateOpen(field, formMeta) {
83
10
  return formMeta.submissionAttempts > 0 || field.blurredAfterInteraction === true;
@@ -177,323 +104,6 @@ function humanize(segment) {
177
104
  }).join(" ");
178
105
  }
179
106
 
180
- const NOT_FOUND = /* @__PURE__ */ Symbol("NOT_FOUND");
181
- function mapKeyForSegment(map, segment, declared) {
182
- if (map.has(segment)) return segment;
183
- if (typeof segment !== "number") return segment;
184
- const asString = String(segment);
185
- if (map.has(asString)) return asString;
186
- return declared === "string" ? asString : segment;
187
- }
188
- function isRebuildableContainer(root, segment) {
189
- if (root === null || root === void 0 || typeof root !== "object") return true;
190
- return typeof segment === "number" ? Array.isArray(root) : isPlainRecord(root);
191
- }
192
- function descendStep(value, segment) {
193
- if (value === null || value === void 0) return NOT_FOUND;
194
- if (typeof value !== "object") return NOT_FOUND;
195
- if (Array.isArray(value)) {
196
- if (typeof segment !== "number") return NOT_FOUND;
197
- if (!(segment in value)) return NOT_FOUND;
198
- return value[segment];
199
- }
200
- if (value instanceof Map) {
201
- const key2 = mapKeyForSegment(value, segment);
202
- if (!value.has(key2)) return NOT_FOUND;
203
- return value.get(key2);
204
- }
205
- const record = value;
206
- const key = typeof segment === "number" ? String(segment) : segment;
207
- if (isShadowedKey(key)) {
208
- if (!safeOwnHas(record, key)) return NOT_FOUND;
209
- return safeOwnRead(record, key);
210
- }
211
- if (!(key in record)) return NOT_FOUND;
212
- return record[key];
213
- }
214
- function getAtPath(root, path) {
215
- if (path.length === 0) return root;
216
- try {
217
- let current = root;
218
- for (const segment of path) {
219
- const next = descendStep(current, segment);
220
- if (next === NOT_FOUND) return void 0;
221
- current = next;
222
- }
223
- return current;
224
- } catch {
225
- return void 0;
226
- }
227
- }
228
- function hasAtPath(root, path) {
229
- if (path.length === 0) return true;
230
- try {
231
- return hasAtPathUnguarded(root, path);
232
- } catch {
233
- return false;
234
- }
235
- }
236
- function hasAtPathUnguarded(root, path) {
237
- let current = root;
238
- for (let i = 0; i < path.length - 1; i++) {
239
- const segment = path[i];
240
- const next = descendStep(current, segment);
241
- if (next === NOT_FOUND) return false;
242
- current = next;
243
- }
244
- const last = path[path.length - 1];
245
- if (current === null || current === void 0) return false;
246
- if (typeof current !== "object") return false;
247
- if (Array.isArray(current)) {
248
- return typeof last === "number" && consumerHas(current, last);
249
- }
250
- if (current instanceof Map) {
251
- return current.has(mapKeyForSegment(current, last));
252
- }
253
- const key = typeof last === "number" ? String(last) : last;
254
- if (isShadowedKey(key)) return safeOwnHas(current, key);
255
- return consumerHas(current, key);
256
- }
257
- function isPlainRecord(value) {
258
- if (value === null || typeof value !== "object") return false;
259
- if (Array.isArray(value)) return false;
260
- const proto = Object.getPrototypeOf(value);
261
- return proto === null || proto === Object.prototype;
262
- }
263
- const NO_SCHEMA_DEFAULTS = /* @__PURE__ */ new Set();
264
- const NO_SCHEMA_FILL = {
265
- getDefaultAtPath: () => void 0,
266
- arrayShapeAtPath: () => null,
267
- getSlimPrimitiveTypesAtPath: () => NO_SCHEMA_DEFAULTS,
268
- entryKeyKindAtPath: () => void 0
269
- };
270
- function setAtPath(root, path, value) {
271
- return setAtPathWithSchemaFill(root, NO_SCHEMA_FILL, path, value);
272
- }
273
- const NO_IN_PLACE = { applied: false };
274
- function tryInPlaceLeafWrite(root, path, value) {
275
- if (path.length === 0) return NO_IN_PLACE;
276
- try {
277
- return descendAndWrite(root, path, value);
278
- } catch {
279
- return NO_IN_PLACE;
280
- }
281
- }
282
- function descendAndWrite(root, path, value) {
283
- let node = root;
284
- for (let i = 0; i < path.length; i++) {
285
- const seg = path[i];
286
- if (node instanceof Map) return NO_IN_PLACE;
287
- if (Array.isArray(node)) {
288
- if (typeof seg !== "number" || seg < 0 || seg >= node.length) return NO_IN_PLACE;
289
- } else if (isPlainRecord(node)) {
290
- if (typeof seg !== "string" || isShadowedKey(seg) || !(seg in node)) return NO_IN_PLACE;
291
- } else {
292
- return NO_IN_PLACE;
293
- }
294
- const container = node;
295
- if (i < path.length - 1) {
296
- node = container[seg];
297
- continue;
298
- }
299
- const old = container[seg];
300
- if (isPlainRecord(old) || Array.isArray(old)) return NO_IN_PLACE;
301
- container[seg] = value;
302
- return { applied: true, old };
303
- }
304
- return NO_IN_PLACE;
305
- }
306
- function mergeStructural(schema, path, consumer, defaultValue = schema.getDefaultAtPath(path)) {
307
- const scratch = path.slice();
308
- return mergeStructuralImpl(schema, scratch, consumer, defaultValue);
309
- }
310
- function mergeStructuralImpl(schema, scratch, consumer, defaultValue) {
311
- if (consumer === void 0) {
312
- if (schema.getSlimPrimitiveTypesAtPath(scratch).has("undefined")) {
313
- return void 0;
314
- }
315
- return defaultValue;
316
- }
317
- if (consumer === null) return null;
318
- if (Array.isArray(consumer)) {
319
- return mergeStructuralArray(schema, scratch, consumer);
320
- }
321
- if (consumer instanceof Map) {
322
- return mergeStructuralMap(schema, scratch, consumer);
323
- }
324
- if (isPlainRecord(consumer)) {
325
- if (!isPlainRecord(defaultValue)) {
326
- return consumer;
327
- }
328
- const out = spreadConsumerRecord(consumer);
329
- const filledAny = fillMissingKeysFromDefault(schema, scratch, consumer, defaultValue, out);
330
- const recursedAny = recurseIntoConsumerKeys(schema, scratch, consumer, defaultValue, out);
331
- return filledAny || recursedAny ? out : consumer;
332
- }
333
- return consumer;
334
- }
335
- function mergeStructuralMap(schema, scratch, consumer) {
336
- if (consumer.size === 0) return consumer;
337
- let entryDefault;
338
- let entryDefaultRead = false;
339
- let out = null;
340
- for (const [key, entry] of consumer) {
341
- if (typeof key !== "string" && typeof key !== "number") continue;
342
- scratch.push(key);
343
- if (!entryDefaultRead) {
344
- entryDefault = schema.getDefaultAtPath(scratch);
345
- entryDefaultRead = true;
346
- }
347
- const merged = mergeStructuralImpl(schema, scratch, entry, entryDefault);
348
- scratch.pop();
349
- if (merged === entry) continue;
350
- out ?? (out = new Map(consumer));
351
- out.set(key, merged);
352
- }
353
- return out ?? consumer;
354
- }
355
- function mergeStructuralArray(schema, scratch, consumer) {
356
- const shape = schema.arrayShapeAtPath(scratch);
357
- const isTuple = typeof shape === "number";
358
- const targetLen = isTuple ? shape : consumer.length;
359
- let cachedElementDefault;
360
- let cachedElementDefaultRead = false;
361
- let mutated = targetLen > consumer.length;
362
- const out = copyConsumerArray(consumer);
363
- while (out.length < targetLen) out.push(void 0);
364
- for (let i = 0; i < targetLen; i++) {
365
- scratch.push(i);
366
- let elemDefault;
367
- if (isTuple) {
368
- elemDefault = schema.getDefaultAtPath(scratch);
369
- } else {
370
- if (!cachedElementDefaultRead) {
371
- cachedElementDefault = schema.getDefaultAtPath(scratch);
372
- cachedElementDefaultRead = true;
373
- }
374
- elemDefault = cachedElementDefault;
375
- }
376
- const consumerElem = i < consumer.length ? readConsumerIndex(consumer, i) : void 0;
377
- const merged = mergeStructuralImpl(schema, scratch, consumerElem, elemDefault);
378
- scratch.pop();
379
- if (merged !== consumerElem) {
380
- out[i] = merged;
381
- mutated = true;
382
- }
383
- }
384
- return mutated ? out : consumer;
385
- }
386
- function fillMissingKeysFromDefault(schema, scratch, consumer, defaultValue, out) {
387
- let mutated = false;
388
- for (const key of Object.keys(defaultValue)) {
389
- if (!safeOwnHas(consumer, key)) {
390
- const defAtKey = safeOwnRead(defaultValue, key);
391
- scratch.push(key);
392
- const filled = mergeStructuralImpl(schema, scratch, void 0, defAtKey);
393
- scratch.pop();
394
- if (filled !== void 0) {
395
- safeAssign(out, key, filled);
396
- mutated = true;
397
- }
398
- }
399
- }
400
- return mutated;
401
- }
402
- function recurseIntoConsumerKeys(schema, scratch, consumer, defaultValue, out) {
403
- let mutated = false;
404
- for (const key of consumerKeys(consumer)) {
405
- const cVal = safeOwnRead(consumer, key);
406
- if (cVal === void 0) continue;
407
- scratch.push(key);
408
- const merged = mergeStructuralImpl(schema, scratch, cVal, safeOwnRead(defaultValue, key));
409
- scratch.pop();
410
- if (merged !== cVal) {
411
- safeAssign(out, key, merged);
412
- mutated = true;
413
- }
414
- }
415
- return mutated;
416
- }
417
- function setAtPathWithSchemaFill(root, schema, fullPath, value) {
418
- if (fullPath.length === 0) return value;
419
- return setAtPathWithSchemaFillImpl(root, schema, fullPath, value, 0);
420
- }
421
- function setAtPathWithSchemaFillImpl(root, schema, fullPath, value, startIdx) {
422
- if (startIdx >= fullPath.length) return value;
423
- const head = fullPath[startIdx];
424
- const isLeafStep = startIdx === fullPath.length - 1;
425
- if (root instanceof Map) {
426
- const next = new Map(root);
427
- const key = mapKeyForSegment(root, head, schema.entryKeyKindAtPath(fullPath.slice(0, startIdx)));
428
- if (isLeafStep) {
429
- next.set(key, value);
430
- return next;
431
- }
432
- let childRoot2 = next.get(key);
433
- if (childRoot2 === void 0 || childRoot2 !== null && typeof childRoot2 !== "object") {
434
- childRoot2 = schema.getDefaultAtPath(fullPath.slice(0, startIdx + 1));
435
- }
436
- next.set(key, setAtPathWithSchemaFillImpl(childRoot2, schema, fullPath, value, startIdx + 1));
437
- return next;
438
- }
439
- if (!isRebuildableContainer(root, head)) return root;
440
- if (typeof head === "number") {
441
- const arr = Array.isArray(root) ? [...root] : [];
442
- const prefix = fullPath.slice(0, startIdx);
443
- if (arr.length < head) {
444
- const scratch = prefix.slice();
445
- const shape = schema.arrayShapeAtPath(scratch);
446
- const tupleLike = typeof shape === "number";
447
- let cachedArrayDefault;
448
- if (!tupleLike) {
449
- scratch.push(0);
450
- cachedArrayDefault = schema.getDefaultAtPath(scratch);
451
- scratch.pop();
452
- }
453
- while (arr.length < head) {
454
- const idx = arr.length;
455
- if (tupleLike) {
456
- scratch.push(idx);
457
- arr.push(schema.getDefaultAtPath(scratch));
458
- scratch.pop();
459
- } else {
460
- arr.push(cachedArrayDefault);
461
- }
462
- }
463
- }
464
- if (isLeafStep) {
465
- arr[head] = value;
466
- return arr;
467
- }
468
- let childRoot2 = arr[head];
469
- if (childRoot2 === void 0 || childRoot2 !== null && typeof childRoot2 !== "object") {
470
- childRoot2 = schema.getDefaultAtPath([...prefix, head]);
471
- }
472
- arr[head] = setAtPathWithSchemaFillImpl(childRoot2, schema, fullPath, value, startIdx + 1);
473
- return arr;
474
- }
475
- const rec = isPlainRecord(root) ? { ...root } : {};
476
- if (isLeafStep) {
477
- safeAssign(rec, head, value);
478
- return rec;
479
- }
480
- const existing = safeOwnRead(rec, head);
481
- let childRoot;
482
- if (existing === void 0 || existing !== null && typeof existing !== "object") {
483
- const intermPath = [...fullPath.slice(0, startIdx + 1)];
484
- const intermDefault = schema.getDefaultAtPath(intermPath);
485
- childRoot = intermDefault;
486
- } else {
487
- childRoot = existing;
488
- }
489
- safeAssign(
490
- rec,
491
- head,
492
- setAtPathWithSchemaFillImpl(childRoot, schema, fullPath, value, startIdx + 1)
493
- );
494
- return rec;
495
- }
496
-
497
107
  function isUnderStubAncestor(state, segments) {
498
108
  for (let i = 0; i < segments.length; i++) {
499
109
  const ancestorPath = segments.slice(0, i);
@@ -629,7 +239,6 @@ function visitActiveLeafPaths(value, base, visit) {
629
239
  function buildContainerFieldStateBase(state, segments, key, formInstanceId) {
630
240
  const formValue = state.form.value;
631
241
  const value = getAtPath(formValue, segments);
632
- const original = state.originals.get(key)?.value;
633
242
  let pristine = true;
634
243
  let blank = true;
635
244
  let dirty = false;
@@ -746,7 +355,7 @@ function buildContainerFieldStateBase(state, segments, key, formInstanceId) {
746
355
  return {
747
356
  base: {
748
357
  value,
749
- original,
358
+ original: state.getOriginalAtPath(segments),
750
359
  pristine,
751
360
  dirty,
752
361
  focused,
@@ -1443,504 +1052,6 @@ function buildValuesSurface(form, onFormChange) {
1443
1052
  });
1444
1053
  }
1445
1054
 
1446
- function remapForOp(op, oldLen) {
1447
- const moved = /* @__PURE__ */ new Map();
1448
- const vacated = /* @__PURE__ */ new Set();
1449
- const fresh = /* @__PURE__ */ new Set();
1450
- let newLen = oldLen;
1451
- switch (op.kind) {
1452
- case "insert":
1453
- for (let i = op.index; i < oldLen; i++) moved.set(i, i + 1);
1454
- fresh.add(op.index);
1455
- newLen = oldLen + 1;
1456
- break;
1457
- case "remove":
1458
- vacated.add(op.index);
1459
- for (let i = op.index + 1; i < oldLen; i++) moved.set(i, i - 1);
1460
- newLen = Math.max(0, oldLen - 1);
1461
- break;
1462
- case "move":
1463
- if (op.from !== op.to) {
1464
- moved.set(op.from, op.to);
1465
- if (op.from < op.to) {
1466
- for (let i = op.from + 1; i <= op.to; i++) moved.set(i, i - 1);
1467
- } else {
1468
- for (let i = op.to; i < op.from; i++) moved.set(i, i + 1);
1469
- }
1470
- }
1471
- break;
1472
- case "swap":
1473
- if (op.a !== op.b) {
1474
- moved.set(op.a, op.b);
1475
- moved.set(op.b, op.a);
1476
- }
1477
- break;
1478
- case "replace-at":
1479
- vacated.add(op.index);
1480
- fresh.add(op.index);
1481
- break;
1482
- }
1483
- return { moved, vacated, fresh, oldLen, newLen };
1484
- }
1485
- function changedIndices(remap) {
1486
- const changed = new Set(remap.vacated);
1487
- for (const [from, to] of remap.moved) {
1488
- changed.add(from);
1489
- changed.add(to);
1490
- }
1491
- for (const index of remap.fresh) changed.add(index);
1492
- return changed;
1493
- }
1494
- function permuteList(list, remap, fill) {
1495
- const claimed = new Array(remap.newLen);
1496
- for (let i = 0; i < remap.oldLen; i++) {
1497
- if (remap.vacated.has(i)) continue;
1498
- const to = remap.moved.get(i) ?? i;
1499
- if (to < remap.newLen) claimed[to] = list[i];
1500
- }
1501
- const next = [];
1502
- for (let i = 0; i < remap.newLen; i++) {
1503
- next.push(claimed[i] ?? fill());
1504
- }
1505
- return next;
1506
- }
1507
- function elementIndexUnder(arrayPath, key, idxPos) {
1508
- const segments = segmentsForPathKey(key);
1509
- if (segments === null) return null;
1510
- if (!isPathPrefix(arrayPath, segments)) return null;
1511
- if (segments.length <= idxPos) return null;
1512
- const index = segments[idxPos];
1513
- return typeof index === "number" ? index : null;
1514
- }
1515
- function collectKeysAtIndices(keys, arrayPath, member) {
1516
- const idxPos = arrayPath.length;
1517
- const hits = [];
1518
- for (const key of keys) {
1519
- const index = elementIndexUnder(arrayPath, key, idxPos);
1520
- if (index === null || !member(index)) continue;
1521
- const segments = segmentsForPathKey(key);
1522
- if (segments === null) continue;
1523
- hits.push({ key, segments: [...segments], index });
1524
- }
1525
- return hits;
1526
- }
1527
- function remapAffects(remap) {
1528
- return (index) => remap.moved.has(index) || remap.vacated.has(index) || remap.fresh.has(index);
1529
- }
1530
- function migrateMapSubtree(map, arrayPath, remap, rewriteValue) {
1531
- const hits = collectKeysAtIndices(map.keys(), arrayPath, remapAffects(remap));
1532
- if (hits.length === 0) return;
1533
- const idxPos = arrayPath.length;
1534
- const snapshots = [];
1535
- for (const hit of hits) {
1536
- const value = map.get(hit.key);
1537
- if (value !== void 0) snapshots.push({ ...hit, value });
1538
- }
1539
- for (const snap of snapshots) map.delete(snap.key);
1540
- for (const snap of snapshots) {
1541
- const target = remap.moved.get(snap.index);
1542
- if (target === void 0) continue;
1543
- const relocated = snap.segments.slice();
1544
- relocated[idxPos] = target;
1545
- map.set(canonicalizePath(relocated).key, rewriteValue(snap.value, relocated));
1546
- }
1547
- }
1548
- function migrateSetSubtree(set, arrayPath, remap) {
1549
- const hits = collectKeysAtIndices(set, arrayPath, remapAffects(remap));
1550
- if (hits.length === 0) return;
1551
- const idxPos = arrayPath.length;
1552
- for (const hit of hits) set.delete(hit.key);
1553
- for (const hit of hits) {
1554
- const target = remap.moved.get(hit.index);
1555
- if (target === void 0) continue;
1556
- const relocated = hit.segments.slice();
1557
- relocated[idxPos] = target;
1558
- set.add(canonicalizePath(relocated).key);
1559
- }
1560
- }
1561
- function evictSchemaVerdictsAtIndices(errorCells, arrayPath, indices) {
1562
- for (const hit of collectKeysAtIndices(
1563
- [...errorCells.keys()],
1564
- arrayPath,
1565
- (index) => indices.has(index)
1566
- )) {
1567
- const cell = errorCells.get(hit.key);
1568
- if (cell === void 0) continue;
1569
- if (cell.user.length === 0) errorCells.delete(hit.key);
1570
- else if (cell.schema.length > 0) errorCells.set(hit.key, { schema: NO_ERRORS, user: cell.user });
1571
- }
1572
- }
1573
- function deleteKeysAtIndices(keys, del, arrayPath, indices) {
1574
- for (const hit of collectKeysAtIndices(keys, arrayPath, (index) => indices.has(index))) {
1575
- del(hit.key);
1576
- }
1577
- }
1578
- function createArrayIdentity(getArrayLength, onChange) {
1579
- const tokens = /* @__PURE__ */ new Map();
1580
- const baselines = /* @__PURE__ */ new Map();
1581
- let counter = 0;
1582
- const allocate = () => `k${(counter++).toString(36)}`;
1583
- function ensure(arrayKey, expectedLen) {
1584
- let ids = tokens.get(arrayKey);
1585
- const firstTrack = ids === void 0;
1586
- if (ids === void 0) {
1587
- ids = [];
1588
- tokens.set(arrayKey, ids);
1589
- }
1590
- if (ids.length < expectedLen) {
1591
- const baseline = baselines.get(arrayKey);
1592
- while (ids.length < expectedLen) {
1593
- const anchored = baseline?.[ids.length];
1594
- ids.push(anchored !== void 0 && !ids.includes(anchored) ? anchored : allocate());
1595
- }
1596
- }
1597
- if (ids.length > expectedLen) ids.length = expectedLen;
1598
- if (firstTrack) baselines.set(arrayKey, [...ids]);
1599
- return ids;
1600
- }
1601
- function orderPristineForKey(arrayKey) {
1602
- const baseline = baselines.get(arrayKey);
1603
- const current = tokens.get(arrayKey);
1604
- if (baseline === void 0 || current === void 0) return true;
1605
- if (baseline.length !== current.length) return false;
1606
- for (let i = 0; i < current.length; i++) {
1607
- if (current[i] !== baseline[i]) return false;
1608
- }
1609
- return true;
1610
- }
1611
- return {
1612
- tokenAt(arraySegs, index) {
1613
- const len = getArrayLength(arraySegs);
1614
- if (index < 0 || index >= len) return "";
1615
- const ids = ensure(canonicalizePath(arraySegs).key, len);
1616
- return ids[index] ?? "";
1617
- },
1618
- applyOp(arraySegs, remap) {
1619
- const arrayKey = canonicalizePath(arraySegs).key;
1620
- const ids = ensure(arrayKey, remap.oldLen);
1621
- tokens.set(arrayKey, permuteList(ids, remap, allocate));
1622
- onChange([arraySegs]);
1623
- },
1624
- applyRemap(arrayPath, remap) {
1625
- if (remap.moved.size === 0 && remap.vacated.size === 0 && remap.fresh.size === 0) return;
1626
- const moved = [];
1627
- for (const hit of collectKeysAtIndices(tokens.keys(), arrayPath, remapAffects(remap))) {
1628
- moved.push(hit.segments);
1629
- }
1630
- migrateMapSubtree(tokens, arrayPath, remap, (value, segments) => {
1631
- moved.push(segments);
1632
- return value;
1633
- });
1634
- migrateMapSubtree(baselines, arrayPath, remap, (value) => value);
1635
- if (moved.length > 0) onChange(moved);
1636
- },
1637
- realign(arraySegs) {
1638
- ensure(canonicalizePath(arraySegs).key, getArrayLength(arraySegs));
1639
- },
1640
- realignContaining(paths) {
1641
- if (tokens.size === 0 || paths.length === 0) return;
1642
- const resized = [];
1643
- for (const [arrayKey, ids] of tokens) {
1644
- const segs = segmentsForPathKey(arrayKey);
1645
- if (segs === null || !paths.some((path) => isPathPrefix(segs, path) || isPathPrefix(path, segs))) {
1646
- continue;
1647
- }
1648
- const len = getArrayLength(segs);
1649
- if (ids.length === len) continue;
1650
- ensure(arrayKey, len);
1651
- resized.push(segs);
1652
- }
1653
- if (resized.length > 0) onChange(resized);
1654
- },
1655
- hasStructuralChangeUnder(prefix) {
1656
- for (const arrayKey of tokens.keys()) {
1657
- if (orderPristineForKey(arrayKey)) continue;
1658
- const segs = segmentsForPathKey(arrayKey);
1659
- if (segs === null) continue;
1660
- if (isPathPrefix(prefix, segs)) return true;
1661
- }
1662
- return false;
1663
- },
1664
- rebaselineAll() {
1665
- const rebased = [];
1666
- for (const arrayKey of [...tokens.keys()]) {
1667
- const segs = segmentsForPathKey(arrayKey);
1668
- if (segs === null) continue;
1669
- const ids = ensure(arrayKey, getArrayLength(segs));
1670
- baselines.set(arrayKey, [...ids]);
1671
- rebased.push(segs);
1672
- }
1673
- if (rebased.length > 0) onChange(rebased);
1674
- },
1675
- snapshot() {
1676
- return { tokens: copyLists(tokens), baselines: copyLists(baselines) };
1677
- },
1678
- restore(orders) {
1679
- const keys = /* @__PURE__ */ new Set([...tokens.keys(), ...orders.tokens.keys()]);
1680
- tokens.clear();
1681
- for (const [key, ids] of orders.tokens) tokens.set(key, [...ids]);
1682
- baselines.clear();
1683
- for (const [key, ids] of orders.baselines) baselines.set(key, [...ids]);
1684
- const restored = [];
1685
- for (const key of keys) {
1686
- const segs = segmentsForPathKey(key);
1687
- if (segs !== null) restored.push(segs);
1688
- }
1689
- if (restored.length > 0) onChange(restored);
1690
- }
1691
- };
1692
- }
1693
- function copyLists(lists) {
1694
- const out = /* @__PURE__ */ new Map();
1695
- for (const [key, ids] of lists) out.set(key, [...ids]);
1696
- return out;
1697
- }
1698
- function createVariantMemory() {
1699
- const memory = /* @__PURE__ */ new Map();
1700
- return {
1701
- clear() {
1702
- memory.clear();
1703
- },
1704
- clearUnderPath(parentPath) {
1705
- for (const memKey of [...memory.keys()]) {
1706
- const segs = segmentsForPathKey(memKey);
1707
- if (segs === null) continue;
1708
- if (isPathPrefix(parentPath, segs)) memory.delete(memKey);
1709
- }
1710
- },
1711
- dropAtIndices(arrayPath, indices) {
1712
- deleteKeysAtIndices([...memory.keys()], (key) => memory.delete(key), arrayPath, indices);
1713
- },
1714
- recordOutgoing(unionKey, discValue, snapshot) {
1715
- let perUnion = memory.get(unionKey);
1716
- if (perUnion === void 0) {
1717
- perUnion = /* @__PURE__ */ new Map();
1718
- memory.set(unionKey, perUnion);
1719
- }
1720
- perUnion.set(discValue, snapshot);
1721
- },
1722
- lookupIncoming(unionKey, discValue) {
1723
- return memory.get(unionKey)?.get(discValue);
1724
- }
1725
- };
1726
- }
1727
- function cloneVariantSnapshot(value) {
1728
- if (value === null || typeof value !== "object") return value;
1729
- const raw = toRaw(value);
1730
- if (raw instanceof Date) return new Date(raw.getTime());
1731
- if (raw instanceof Map) {
1732
- const out2 = /* @__PURE__ */ new Map();
1733
- for (const [k, v] of raw.entries()) out2.set(cloneVariantSnapshot(k), cloneVariantSnapshot(v));
1734
- return out2;
1735
- }
1736
- if (raw instanceof Set) {
1737
- const out2 = /* @__PURE__ */ new Set();
1738
- for (const v of raw) out2.add(cloneVariantSnapshot(v));
1739
- return out2;
1740
- }
1741
- if (raw instanceof RegExp) return new RegExp(raw.source, raw.flags);
1742
- if (Array.isArray(raw)) {
1743
- const out2 = new Array(raw.length);
1744
- for (let i = 0; i < raw.length; i++) out2[i] = cloneVariantSnapshot(raw[i]);
1745
- return out2;
1746
- }
1747
- if (!isPlainRecord(raw)) return raw;
1748
- const src = raw;
1749
- const out = {};
1750
- for (const k of consumerKeys(src)) {
1751
- safeAssign(out, k, cloneVariantSnapshot(readConsumerProp(src, k)));
1752
- }
1753
- return out;
1754
- }
1755
- function createArrayBookkeeping(deps) {
1756
- const {
1757
- form,
1758
- fields,
1759
- errorCells,
1760
- originals,
1761
- blankPaths,
1762
- originalBlankPaths,
1763
- authoredPaths,
1764
- removedPaths,
1765
- notifyStructure,
1766
- fieldValidationCounts,
1767
- fieldValidatingSince,
1768
- fieldValidationState,
1769
- activeValidations,
1770
- arrayIdentity,
1771
- variantMemory,
1772
- touchFieldRecord,
1773
- stampContainers,
1774
- stampBareContainers,
1775
- foldInteractionHistory,
1776
- decFieldValidation
1777
- } = deps;
1778
- function migrateElementState(arrayPath, remap) {
1779
- if (remap.moved.size === 0 && remap.vacated.size === 0) return;
1780
- migrateSetSubtree(originalBlankPaths, arrayPath, remap);
1781
- migrateSetSubtree(authoredPaths, arrayPath, remap);
1782
- const removedMoved = [];
1783
- for (const hit of collectKeysAtIndices(removedPaths.keys(), arrayPath, remapAffects(remap))) {
1784
- removedMoved.push(hit.segments);
1785
- }
1786
- migrateMapSubtree(removedPaths, arrayPath, remap, (_, segments) => {
1787
- removedMoved.push(segments);
1788
- return segments;
1789
- });
1790
- if (remap.vacated.size > 0) {
1791
- const released = [];
1792
- for (const { key } of collectKeysAtIndices(
1793
- fields.keys(),
1794
- arrayPath,
1795
- (index) => remap.vacated.has(index)
1796
- )) {
1797
- const record = fields.get(key);
1798
- if (record !== void 0) released.push(record);
1799
- }
1800
- foldInteractionHistory(arrayPath, released);
1801
- }
1802
- migrateMapSubtree(fields, arrayPath, remap, (record, segments) => ({
1803
- ...record,
1804
- path: segments
1805
- }));
1806
- migrateMapSubtree(errorCells(), arrayPath, remap, (cell, segments) => ({
1807
- schema: NO_ERRORS,
1808
- user: cell.user.map((error) => ({ ...error, path: [...segments] }))
1809
- }));
1810
- migrateMapSubtree(originals, arrayPath, remap, (record, segments) => ({
1811
- segments,
1812
- value: record.value
1813
- }));
1814
- migrateSetSubtree(blankPaths, arrayPath, remap);
1815
- migrateMapSubtree(fieldValidatingSince, arrayPath, remap, (since) => since);
1816
- migrateMapSubtree(fieldValidationCounts, arrayPath, remap, (count) => count);
1817
- migrateMapSubtree(fieldValidationState, arrayPath, remap, (entry, segments) => {
1818
- entry.key = keyForSegments(segments).key;
1819
- entry.path = segments;
1820
- return entry;
1821
- });
1822
- arrayIdentity.applyRemap(arrayPath, remap);
1823
- if (removedMoved.length > 0) notifyStructure(removedMoved);
1824
- }
1825
- function seedFreshElement(arrayPath, freshIndex, now) {
1826
- const elementPath = [...arrayPath, freshIndex];
1827
- const patches = [];
1828
- diffAndApply(void 0, getAtPath(form.value, elementPath), elementPath, (patch) => {
1829
- patches.push(patch);
1830
- });
1831
- const bare = [];
1832
- patches.forEach((patch, index) => {
1833
- if (patch.kind !== "added") return;
1834
- if (isBarePatch(patch)) {
1835
- bare.push(index);
1836
- return;
1837
- }
1838
- const { key, segments } = canonicalizePath(patch.path);
1839
- if (!originals.has(key)) originals.set(key, { segments: patch.path, value: void 0 });
1840
- touchFieldRecord(key, segments, { updatedAt: now });
1841
- });
1842
- if (bare.length > 0) stampBareContainers(patches, bare, now);
1843
- else if (patches.length === 0 && hasAtPath(form.value, elementPath)) {
1844
- stampContainers([elementPath], now);
1845
- }
1846
- }
1847
- function abortValidationAtVacatedIndices(arrayPath, remap) {
1848
- if (remap.vacated.size === 0) return;
1849
- const hits = collectKeysAtIndices(
1850
- [...fieldValidationState.keys()],
1851
- arrayPath,
1852
- (index) => remap.vacated.has(index)
1853
- );
1854
- for (const hit of hits) {
1855
- const entry = fieldValidationState.get(hit.key);
1856
- if (entry === void 0) continue;
1857
- if (entry.timer !== null) {
1858
- clearTimeout(entry.timer);
1859
- } else if (!entry.settled && !entry.released) {
1860
- activeValidations.value = Math.max(0, activeValidations.value - 1);
1861
- decFieldValidation(hit.key);
1862
- entry.released = true;
1863
- }
1864
- entry.aborted = true;
1865
- fieldValidationState.delete(hit.key);
1866
- }
1867
- }
1868
- return {
1869
- applyStructuralOp(arrayPath, remap, now) {
1870
- abortValidationAtVacatedIndices(arrayPath, remap);
1871
- migrateElementState(arrayPath, remap);
1872
- for (const freshIndex of remap.fresh) seedFreshElement(arrayPath, freshIndex, now);
1873
- const changed = changedIndices(remap);
1874
- evictSchemaVerdictsAtIndices(errorCells(), arrayPath, changed);
1875
- variantMemory.dropAtIndices(arrayPath, changed);
1876
- arrayIdentity.applyOp(arrayPath, remap);
1877
- }
1878
- };
1879
- }
1880
- function buildFieldArrayApi(state) {
1881
- function readArray(path) {
1882
- const segments = canonicalizePath(path).segments;
1883
- const current = state.getValueAtPath(segments);
1884
- return Array.isArray(current) ? current.slice() : [];
1885
- }
1886
- function writeArray(path, next, arrayOp) {
1887
- const { segments } = canonicalizePath(path);
1888
- const meta = {
1889
- ...arrayOp !== void 0 ? { arrayOp } : {}
1890
- };
1891
- return state.setValueAtPath(segments, next, meta);
1892
- }
1893
- return {
1894
- append(path, value) {
1895
- const next = readArray(path);
1896
- next.push(value);
1897
- return writeArray(path, next, { kind: "insert", index: next.length - 1 });
1898
- },
1899
- prepend(path, value) {
1900
- const next = readArray(path);
1901
- next.unshift(value);
1902
- return writeArray(path, next, { kind: "insert", index: 0 });
1903
- },
1904
- insert(path, index, value) {
1905
- const next = readArray(path);
1906
- const preLen = next.length;
1907
- const insertIndex = index < 0 ? Math.max(0, preLen + index) : Math.min(index, preLen);
1908
- next.splice(insertIndex, 0, value);
1909
- return writeArray(path, next, { kind: "insert", index: insertIndex });
1910
- },
1911
- remove(path, index) {
1912
- const next = readArray(path);
1913
- if (index < 0 || index >= next.length) return false;
1914
- next.splice(index, 1);
1915
- return writeArray(path, next, { kind: "remove", index });
1916
- },
1917
- swap(path, a, b) {
1918
- const next = readArray(path);
1919
- if (a < 0 || a >= next.length) return false;
1920
- if (b < 0 || b >= next.length) return false;
1921
- if (a === b) return false;
1922
- const tmp = next[a];
1923
- next[a] = next[b];
1924
- next[b] = tmp;
1925
- return writeArray(path, next, { kind: "swap", a, b });
1926
- },
1927
- move(path, from, to) {
1928
- const next = readArray(path);
1929
- if (from < 0 || from >= next.length) return false;
1930
- const [item] = next.splice(from, 1);
1931
- const clampedTo = Math.max(0, Math.min(to, next.length));
1932
- next.splice(clampedTo, 0, item);
1933
- return writeArray(path, next, { kind: "move", from, to: clampedTo });
1934
- },
1935
- replace(path, index, value) {
1936
- const next = readArray(path);
1937
- if (index < 0 || index >= next.length) return false;
1938
- next[index] = value;
1939
- return writeArray(path, next, { kind: "replace-at", index });
1940
- }
1941
- };
1942
- }
1943
-
1944
1055
  function isErrorInputLike(value) {
1945
1056
  if (value instanceof Error) return true;
1946
1057
  if (typeof value !== "object" || value === null) return false;
@@ -3399,7 +2510,7 @@ function mergeObjectKeys(target, source, path, schema) {
3399
2510
 
3400
2511
  async function runFactoryAndApply(st, factory) {
3401
2512
  try {
3402
- const value = await factory();
2513
+ const value = structuralSnapshot(await factory());
3403
2514
  if (st.hasPreprocessOrCoerce) walkAuthoredFromConstraints(value, [], st.authoredPaths);
3404
2515
  const full = mergeSparseHydration(
3405
2516
  toRaw(st.form.value),
@@ -3509,7 +2620,7 @@ function walkDuStubs(schema, value, path, warned) {
3509
2620
  function stripSymbolsDeep(value) {
3510
2621
  if (value === null || typeof value !== "object") return value;
3511
2622
  if (Array.isArray(value)) {
3512
- let mutated2 = false;
2623
+ let mutated2 = !consumerExtensible(value);
3513
2624
  const out2 = new Array(value.length);
3514
2625
  for (let i = 0; i < value.length; i++) {
3515
2626
  const original = readConsumerIndex(value, i);
@@ -3523,7 +2634,7 @@ function stripSymbolsDeep(value) {
3523
2634
  if (proto !== Object.prototype && proto !== null) return value;
3524
2635
  const symKeys = consumerSymbolKeys(value);
3525
2636
  const stringKeys = consumerKeys(value);
3526
- let mutated = symKeys.length > 0;
2637
+ let mutated = symKeys.length > 0 || !consumerExtensible(value);
3527
2638
  const out = {};
3528
2639
  const src = value;
3529
2640
  for (const k of stringKeys) {
@@ -3862,6 +2973,7 @@ function foldInteractionHistory(st, path, released) {
3862
2973
  blurredAfterInteraction || (blurredAfterInteraction = record.blurredAfterInteraction);
3863
2974
  }
3864
2975
  if (!touched && !interacted && !blurredAfterInteraction) return;
2976
+ st.noteReleased?.(released);
3865
2977
  for (let depth = path.length; depth >= 0; depth--) {
3866
2978
  const { key, segments } = keyForSegments(path.slice(0, depth));
3867
2979
  const current = st.fields.get(key);
@@ -4445,6 +3557,34 @@ function dispose(st) {
4445
3557
  function getValueAtPath(st, path) {
4446
3558
  return getAtPath(st.form.value, path);
4447
3559
  }
3560
+ function freezeBaseline(value) {
3561
+ if (Object.isFrozen(value)) return value;
3562
+ if (Array.isArray(value)) {
3563
+ for (const item of value) freezeBaseline(item);
3564
+ return Object.freeze(value);
3565
+ }
3566
+ if (isPlainRecord(value)) {
3567
+ for (const k of Object.keys(value)) freezeBaseline(safeOwnRead(value, k));
3568
+ return Object.freeze(value);
3569
+ }
3570
+ return value;
3571
+ }
3572
+ function getOriginalAtPath(st, path) {
3573
+ let node = st.baselineValue;
3574
+ for (let i = 0; i < path.length; i++) {
3575
+ const segment = path[i];
3576
+ if (Array.isArray(node)) {
3577
+ const at = typeof segment === "number" ? st.arrayIdentity.baselineIndexOf(path.slice(0, i), segment) : -1;
3578
+ if (at < 0) return void 0;
3579
+ node = node[at];
3580
+ } else if (isPlainRecord(node) && typeof segment === "string") {
3581
+ node = safeOwnRead(node, segment);
3582
+ } else {
3583
+ return void 0;
3584
+ }
3585
+ }
3586
+ return freezeBaseline(node);
3587
+ }
4448
3588
  const ERROR_SOURCES = ["schema", "user"];
4449
3589
  function createErrorCells(schema, pristine) {
4450
3590
  const raw = /* @__PURE__ */ new Map();
@@ -4530,7 +3670,7 @@ function captureStructure(st) {
4530
3670
  removed: [...st.removedPaths]
4531
3671
  };
4532
3672
  }
4533
- function restoreStructure(st, snapshot) {
3673
+ function restoreStructure(st, snapshot, remaps, returning) {
4534
3674
  const originals = new Map(snapshot.originals);
4535
3675
  const raw = toRaw(st.form.value);
4536
3676
  const held = /* @__PURE__ */ new Map();
@@ -4550,6 +3690,24 @@ function restoreStructure(st, snapshot) {
4550
3690
  st.removedPaths.set(key, segments);
4551
3691
  pulsed.push(segments);
4552
3692
  }
3693
+ for (const [segments, remap] of remaps) {
3694
+ migrateFieldRecords(st.fields, segments, remap, (path, released) => {
3695
+ let stamp = "";
3696
+ for (const { updatedAt } of released) {
3697
+ if (updatedAt !== null && updatedAt > stamp) stamp = updatedAt;
3698
+ }
3699
+ if (stamp !== "") eachAncestorOnce([path], (key, at) => raiseStamp(st, key, at, stamp));
3700
+ foldInteractionHistory(st, path, released);
3701
+ });
3702
+ }
3703
+ for (const record of returning) {
3704
+ st.fields.set(canonicalizePath(record.path).key, {
3705
+ ...record,
3706
+ connected: false,
3707
+ focused: null,
3708
+ blurred: null
3709
+ });
3710
+ }
4553
3711
  if (pulsed.length > 0) pulseStructure(st.structureSignal, pulsed);
4554
3712
  }
4555
3713
  function getErrorsForPath(st, path) {
@@ -4636,6 +3794,27 @@ function markInteracted(st, path) {
4636
3794
  if (st.fields.get(key)?.interacted === true) return;
4637
3795
  touchFieldRecord(st, key, path, { interacted: true });
4638
3796
  }
3797
+ function markBareContainers(st, segments, ladder) {
3798
+ const value = getAtPath(toRaw(st.form.value), segments);
3799
+ if (!isDescendable(value)) return false;
3800
+ const bare = [];
3801
+ diffAndApply(void 0, value, segments, (patch) => {
3802
+ if (isBarePatch(patch)) bare.push(patch.path);
3803
+ });
3804
+ eachAncestorOnce(bare, (key, path) => {
3805
+ const current = st.fields.get(key);
3806
+ if (current?.touched === true && (!ladder || current.interacted && current.blurredAfterInteraction)) {
3807
+ return;
3808
+ }
3809
+ touchFieldRecord(
3810
+ st,
3811
+ key,
3812
+ path,
3813
+ ladder ? { touched: true, interacted: true, blurredAfterInteraction: true } : { touched: true }
3814
+ );
3815
+ });
3816
+ return bare.length > 0;
3817
+ }
4639
3818
  function touchAtPath(st, segments) {
4640
3819
  const formValue = st.form.value;
4641
3820
  for (const [leafKey, entry] of st.originals) {
@@ -4645,6 +3824,7 @@ function touchAtPath(st, segments) {
4645
3824
  if (current?.touched === true) continue;
4646
3825
  touchFieldRecord(st, leafKey, entry.segments, { touched: true });
4647
3826
  }
3827
+ if (markBareContainers(st, segments, false)) ;
4648
3828
  }
4649
3829
  function interactAtPath(st, segments) {
4650
3830
  if (st.effectiveDisabled.value) return false;
@@ -4664,6 +3844,7 @@ function interactAtPath(st, segments) {
4664
3844
  blurredAfterInteraction: true
4665
3845
  });
4666
3846
  }
3847
+ if (markBareContainers(st, segments, true)) interactedAny = true;
4667
3848
  return interactedAny;
4668
3849
  }
4669
3850
  function rehydrate(st) {
@@ -4705,14 +3886,31 @@ function adoptResolvedDefaults(st, value) {
4705
3886
  st.schema
4706
3887
  )
4707
3888
  );
4708
- seedOriginalsFromBaseline(
4709
- st,
4710
- computeBaseline(
4711
- st.schema,
4712
- st.defaultValues,
4713
- st.schema.getDefaultValues({ useDefaultSchemaValues: true })
4714
- )
3889
+ st.baselineValue = computeBaseline(
3890
+ st.schema,
3891
+ st.defaultValues,
3892
+ st.schema.getDefaultValues({ useDefaultSchemaValues: true })
4715
3893
  );
3894
+ seedOriginalsFromBaseline(st, st.baselineValue);
3895
+ st.arrayIdentity.rebaseline((segments) => holdsListAt(value, segments));
3896
+ const dropped = [];
3897
+ for (const [key, segments] of st.removedPaths) {
3898
+ if (st.originals.get(key)?.value !== void 0) continue;
3899
+ st.removedPaths.delete(key);
3900
+ dropped.push(segments);
3901
+ }
3902
+ if (dropped.length > 0) pulseStructure(st.structureSignal, dropped);
3903
+ }
3904
+ function holdsListAt(value, segments) {
3905
+ let node = value;
3906
+ for (const segment of segments) {
3907
+ if (Array.isArray(node)) return true;
3908
+ if (!isPlainRecord(node) || typeof segment !== "string" || !safeOwnHas(node, segment)) {
3909
+ return false;
3910
+ }
3911
+ node = safeOwnRead(node, segment);
3912
+ }
3913
+ return Array.isArray(node);
4716
3914
  }
4717
3915
  function reset(st, nextDefaultValues) {
4718
3916
  const resetSource = nextDefaultValues === void 0 ? st.defaultValues : mergeSparseHydration(
@@ -4723,7 +3921,7 @@ function reset(st, nextDefaultValues) {
4723
3921
  st.defaultValues = structuralSnapshot(resetSource);
4724
3922
  const next = computeBaseline(
4725
3923
  st.schema,
4726
- resetSource,
3924
+ st.defaultValues,
4727
3925
  st.schema.getDefaultValues({ useDefaultSchemaValues: true })
4728
3926
  );
4729
3927
  rebuildAuthoredPaths(st, resetSource, next);
@@ -4733,13 +3931,14 @@ function reset(st, nextDefaultValues) {
4733
3931
  for (const key of mentioned) st.originalBlankPaths.delete(key);
4734
3932
  }
4735
3933
  const now = writeInstant(st);
4736
- applyFormReplacementWithPath(st, next, void 0, null, now);
4737
- st.arrayIdentity.rebaselineAll();
3934
+ applyFormReplacementWithPath(st, structuralSnapshot(next), void 0, null, now);
3935
+ st.arrayIdentity.rebaseline(() => true);
4738
3936
  if (st.removedPaths.size > 0) {
4739
3937
  const cleared = [...st.removedPaths.values()];
4740
3938
  st.removedPaths.clear();
4741
3939
  pulseStructure(st.structureSignal, cleared);
4742
3940
  }
3941
+ st.baselineValue = next;
4743
3942
  seedOriginalsFromBaseline(st, next);
4744
3943
  st.blankPaths.clear();
4745
3944
  for (const key of st.originalBlankPaths) {
@@ -5094,6 +4293,8 @@ function createFormStore(options) {
5094
4293
  // the literal they passed from mutating the form's defaults from outside.
5095
4294
  // `reset()` snapshots for a harder reason, where an alias IS reachable.
5096
4295
  defaultValues: ownDefaultValues,
4296
+ // The form holds a copy of it, or the hydration payload.
4297
+ baselineValue: schemaInitialData,
5097
4298
  ssrPrefetch,
5098
4299
  rememberVariants,
5099
4300
  fieldValidationMode,
@@ -5131,6 +4332,7 @@ function createFormStore(options) {
5131
4332
  applyFormReplacement: bind(applyFormReplacement),
5132
4333
  setValueAtPath: bind(setValueAtPath),
5133
4334
  getValueAtPath: bind(getValueAtPath),
4335
+ getOriginalAtPath: bind(getOriginalAtPath),
5134
4336
  arrayElementKey: bind(arrayElementKey),
5135
4337
  reset: bind(reset),
5136
4338
  resetField: bind(resetField),
@@ -6867,4 +6069,4 @@ function escapeForInlineScript(json) {
6867
6069
  });
6868
6070
  }
6869
6071
 
6870
- export { AttaformErrorCode as A, injectWizard as a, isUnset as b, useAbstractForm as c, useRegister as d, escapeForInlineScript as e, useWizard as f, gate as g, getAtPath as h, injectForm as i, humanize as j, isPlainRecord as k, lazy as l, slimKindOf as s, unset as u };
6072
+ export { injectWizard as a, isUnset as b, useAbstractForm as c, useRegister as d, escapeForInlineScript as e, useWizard as f, gate as g, humanize as h, injectForm as i, lazy as l, slimKindOf as s, unset as u };