attaform 0.24.0 → 0.24.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 (88) hide show
  1. package/dist/chunks/devtools.cjs +1 -1
  2. package/dist/chunks/devtools.mjs +1 -1
  3. package/dist/chunks/fingerprint2.cjs +1 -1
  4. package/dist/chunks/fingerprint2.mjs +1 -1
  5. package/dist/index.cjs +5 -4
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +4 -4
  8. package/dist/index.d.mts +4 -4
  9. package/dist/index.d.ts +4 -4
  10. package/dist/index.mjs +4 -3
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/nuxt.d.cts +1 -1
  13. package/dist/nuxt.d.mts +1 -1
  14. package/dist/nuxt.d.ts +1 -1
  15. package/dist/runtime/plugins/attaform.cjs +2 -2
  16. package/dist/runtime/plugins/attaform.mjs +2 -2
  17. package/dist/shared/{attaform.CAWKNCzc.mjs → attaform.0-00cYGw.mjs} +2 -2
  18. package/dist/shared/{attaform.CAWKNCzc.mjs.map → attaform.0-00cYGw.mjs.map} +1 -1
  19. package/dist/shared/{attaform.DdUYEhkV.d.cts → attaform.0zueP54D.d.mts} +33 -15
  20. package/dist/shared/{attaform.Z1qTwOYE.cjs → attaform.B57G7ePY.cjs} +4 -4
  21. package/dist/shared/{attaform.BJ_W7q3U.mjs.map → attaform.B57G7ePY.cjs.map} +1 -1
  22. package/dist/shared/{attaform.DwkU0oY9.cjs → attaform.B7UdTs_o.cjs} +79 -75
  23. package/dist/shared/attaform.B7UdTs_o.cjs.map +1 -0
  24. package/dist/shared/{attaform.CuBdtfbe.mjs → attaform.BI7M3wK8.mjs} +88 -16
  25. package/dist/shared/attaform.BI7M3wK8.mjs.map +1 -0
  26. package/dist/shared/{attaform.nycEksJn.cjs → attaform.BOi6n2Pn.cjs} +2 -2
  27. package/dist/shared/{attaform.nycEksJn.cjs.map → attaform.BOi6n2Pn.cjs.map} +1 -1
  28. package/dist/shared/{attaform.BJ_W7q3U.mjs → attaform.B_-nZHtM.mjs} +4 -4
  29. package/dist/shared/{attaform.Z1qTwOYE.cjs.map → attaform.B_-nZHtM.mjs.map} +1 -1
  30. package/dist/shared/{attaform.o95Kjd3U.mjs → attaform.BjUaX7s8.mjs} +3 -3
  31. package/dist/shared/{attaform.o95Kjd3U.mjs.map → attaform.BjUaX7s8.mjs.map} +1 -1
  32. package/dist/shared/{attaform.BNmkKz0q.d.mts → attaform.BjiHiYAZ.d.ts} +3 -2
  33. package/dist/shared/{attaform.C42wL7EJ.cjs → attaform.Bos7wVZw.cjs} +90 -18
  34. package/dist/shared/attaform.Bos7wVZw.cjs.map +1 -0
  35. package/dist/shared/{attaform.CwFZGv5-.d.ts → attaform.Bx6pgrIy.d.cts} +3 -2
  36. package/dist/shared/{attaform.Df-s8j1X.mjs → attaform.C0au8oXd.mjs} +36 -29
  37. package/dist/shared/attaform.C0au8oXd.mjs.map +1 -0
  38. package/dist/shared/attaform.CjdepGnw.cjs +27 -0
  39. package/dist/shared/attaform.CjdepGnw.cjs.map +1 -0
  40. package/dist/shared/{attaform.BnUXV01g.cjs → attaform.D-gYGj5z.cjs} +4 -4
  41. package/dist/shared/{attaform.C-dAB90u.mjs.map → attaform.D-gYGj5z.cjs.map} +1 -1
  42. package/dist/shared/{attaform.C6eE50re.d.ts → attaform.DHjRN5JP.d.cts} +33 -15
  43. package/dist/shared/{attaform.CR6wGvNu.cjs → attaform.DK6_Ctv7.cjs} +10 -4
  44. package/dist/shared/attaform.DK6_Ctv7.cjs.map +1 -0
  45. package/dist/shared/{attaform.GJbSmwLB.d.mts → attaform.DUc6cetN.d.cts} +62 -13
  46. package/dist/shared/{attaform.GJbSmwLB.d.cts → attaform.DUc6cetN.d.mts} +62 -13
  47. package/dist/shared/{attaform.GJbSmwLB.d.ts → attaform.DUc6cetN.d.ts} +62 -13
  48. package/dist/shared/{attaform.BV_HyaMO.cjs → attaform.DdfLrIgM.cjs} +3 -3
  49. package/dist/shared/{attaform.BV_HyaMO.cjs.map → attaform.DdfLrIgM.cjs.map} +1 -1
  50. package/dist/shared/{attaform.K-3glmiT.d.cts → attaform.DvqdxvNU.d.mts} +3 -2
  51. package/dist/shared/{attaform.BFWb6hDk.mjs → attaform.DwCtxauq.mjs} +10 -4
  52. package/dist/shared/attaform.DwCtxauq.mjs.map +1 -0
  53. package/dist/shared/{attaform.C-dAB90u.mjs → attaform.K1MbxmIu.mjs} +4 -4
  54. package/dist/shared/{attaform.BnUXV01g.cjs.map → attaform.K1MbxmIu.mjs.map} +1 -1
  55. package/dist/shared/attaform.WvcckZMD.mjs +21 -0
  56. package/dist/shared/attaform.WvcckZMD.mjs.map +1 -0
  57. package/dist/shared/{attaform.DiWNbKWa.d.mts → attaform.yqcYwt0d.d.ts} +33 -15
  58. package/dist/transforms.cjs +1 -1
  59. package/dist/transforms.d.cts +4 -1
  60. package/dist/transforms.d.mts +4 -1
  61. package/dist/transforms.d.ts +4 -1
  62. package/dist/transforms.mjs +1 -1
  63. package/dist/vite.cjs +1 -1
  64. package/dist/vite.mjs +1 -1
  65. package/dist/zod-v3.cjs +2 -2
  66. package/dist/zod-v3.d.cts +8 -5
  67. package/dist/zod-v3.d.mts +8 -5
  68. package/dist/zod-v3.d.ts +8 -5
  69. package/dist/zod-v3.mjs +2 -2
  70. package/dist/zod-v4.cjs +2 -2
  71. package/dist/zod-v4.d.cts +5 -5
  72. package/dist/zod-v4.d.mts +5 -5
  73. package/dist/zod-v4.d.ts +5 -5
  74. package/dist/zod-v4.mjs +2 -2
  75. package/dist/zod.cjs +5 -5
  76. package/dist/zod.cjs.map +1 -1
  77. package/dist/zod.d.cts +23 -7
  78. package/dist/zod.d.mts +23 -7
  79. package/dist/zod.d.ts +23 -7
  80. package/dist/zod.mjs +5 -5
  81. package/dist/zod.mjs.map +1 -1
  82. package/package.json +1 -1
  83. package/dist/shared/attaform.BFWb6hDk.mjs.map +0 -1
  84. package/dist/shared/attaform.C42wL7EJ.cjs.map +0 -1
  85. package/dist/shared/attaform.CR6wGvNu.cjs.map +0 -1
  86. package/dist/shared/attaform.CuBdtfbe.mjs.map +0 -1
  87. package/dist/shared/attaform.Df-s8j1X.mjs.map +0 -1
  88. package/dist/shared/attaform.DwkU0oY9.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { G as GenericForm, u as FlatPath, O as NestedType, F as FormKey, U as UseFormConfiguration, a as AbstractSchema, D as DefaultValuesInput, af as ValidateOnConfig, b as UseFormReturnType } from './attaform.GJbSmwLB.mjs';
2
+ import { G as GenericForm, u as FlatPath, O as NestedType, F as FormKey, U as UseFormConfiguration, a as AbstractSchema, ar as AcceptableDefaults, af as ValidateOnConfig, b as UseFormReturnType } from './attaform.DUc6cetN.js';
3
3
 
4
4
  /**
5
5
  * The shape `form.values.<key>` returns at runtime.
@@ -223,8 +223,9 @@ type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema
223
223
  type FormOf<Schema extends SupportedRootSchema> = z.input<Schema> extends GenericForm ? z.input<Schema> : never;
224
224
  type OutOf<Schema extends SupportedRootSchema> = z.output<Schema> extends GenericForm ? z.output<Schema> : never;
225
225
  type ReadOf<Schema extends SupportedRootSchema> = StorageShape<Schema> extends GenericForm ? StorageShape<Schema> : never;
226
- declare function useForm<Schema extends SupportedRootSchema, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<FormOf<Schema>, OutOf<Schema>, AbstractSchema<FormOf<Schema>, OutOf<Schema>>, DefaultValuesInput<FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
226
+ declare function useForm<Schema extends SupportedRootSchema, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<FormOf<Schema>, OutOf<Schema>, AbstractSchema<FormOf<Schema>, OutOf<Schema>>, never, K>, 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'> & {
227
227
  schema: Schema;
228
+ defaultValues?: AcceptableDefaults<FormOf<Schema>, z.input<Schema>>;
228
229
  } & ValidateOnConfig): UseFormReturnType<FormOf<Schema>, OutOf<Schema>, ReadOf<Schema>, K>;
229
230
 
230
231
  export { useForm as u };
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  const vue = require('vue');
4
- const paths = require('./attaform.DwkU0oY9.cjs');
4
+ const paths = require('./attaform.B7UdTs_o.cjs');
5
+ const registerProtocol = require('./attaform.CjdepGnw.cjs');
5
6
 
6
7
  function safeAssign(target, key, value) {
7
8
  if (key === "__proto__") {
@@ -915,6 +916,10 @@ function buildContainerFieldStateBase(state, segments, key, formInstanceId) {
915
916
  pristine = false;
916
917
  dirty = true;
917
918
  }
919
+ if (!dirty && state.hasRemovedSubtreeUnder(segments)) {
920
+ pristine = false;
921
+ dirty = true;
922
+ }
918
923
  const errors = aggregateErrorsAt(state, segments);
919
924
  const revealedDescendantError = errors.length > 0 && errors.some((e) => {
920
925
  const ePath = e.path;
@@ -1921,6 +1926,19 @@ function buildProcessForm(state, formInstanceId, options = {}) {
1921
1926
  state.clearSchemaErrors();
1922
1927
  }
1923
1928
  await onSubmit(merged.data);
1929
+ if (state.userErrors.size > 0) {
1930
+ if (state.submissionGeneration.value === genAtEntry) {
1931
+ applyInvalidSubmitPolicy(state, formInstanceId, invalidPolicy);
1932
+ }
1933
+ if (onError !== void 0) {
1934
+ try {
1935
+ await onError(Array.from(state.userErrors.values()).flat());
1936
+ } catch (cause) {
1937
+ throw new paths.SubmitErrorHandlerError("User-provided onError threw", { cause });
1938
+ }
1939
+ }
1940
+ return;
1941
+ }
1924
1942
  if (state.submissionGeneration.value === genAtEntry) {
1925
1943
  state.submitted.value = true;
1926
1944
  }
@@ -3888,6 +3906,7 @@ function mergeObjectKeys(target, source, path, schema) {
3888
3906
  return out;
3889
3907
  }
3890
3908
 
3909
+ const isContainer = (value) => Array.isArray(value) || isPlainRecord(value);
3891
3910
  function isHydratedFieldRecord(value) {
3892
3911
  if (typeof value !== "object" || value === null) return false;
3893
3912
  const r = value;
@@ -4077,6 +4096,7 @@ function createFormStore(options) {
4077
4096
  const schemaErrors = vue.reactive(/* @__PURE__ */ new Map());
4078
4097
  const userErrors = vue.reactive(/* @__PURE__ */ new Map());
4079
4098
  const originals = vue.reactive(/* @__PURE__ */ new Map());
4099
+ const removedSubtrees = /* @__PURE__ */ new Set();
4080
4100
  const initialTransientList = hydration?.blankPaths ?? options.initialBlankPaths ?? [];
4081
4101
  const blankPaths = vue.reactive(/* @__PURE__ */ new Set());
4082
4102
  const originalBlankPaths = /* @__PURE__ */ new Set();
@@ -4562,6 +4582,9 @@ function createFormStore(options) {
4562
4582
  return true;
4563
4583
  }
4564
4584
  const oldArrayLength = Array.isArray(currentValue) ? currentValue.length : 0;
4585
+ if (meta?.arrayOp === void 0 && Array.isArray(value) && Array.isArray(currentValue)) {
4586
+ arrayIdentity.realign(path);
4587
+ }
4565
4588
  applyTargetedWrite(path, completedValue, meta);
4566
4589
  if (meta?.arrayOp !== void 0) {
4567
4590
  const remap = remapForOp(meta.arrayOp, oldArrayLength);
@@ -4574,6 +4597,10 @@ function createFormStore(options) {
4574
4597
  } else if (Array.isArray(value) && Array.isArray(currentValue)) {
4575
4598
  variantMemory.clearUnderPath(path);
4576
4599
  arrayIdentity.realign(path);
4600
+ } else if (isContainer(currentValue) && !isContainer(value)) {
4601
+ if (subtreeHadRealBaseline(path, currentValue)) {
4602
+ removedSubtrees.add(paths.canonicalizePath(path).key);
4603
+ }
4577
4604
  }
4578
4605
  const effectiveModeAfterWrite = meta?.instance?.validateOn ?? fieldValidationMode;
4579
4606
  if (effectiveModeAfterWrite === "change") {
@@ -5107,6 +5134,7 @@ function createFormStore(options) {
5107
5134
  rebuildAuthoredPaths(resetSource, next);
5108
5135
  applyFormReplacement(next);
5109
5136
  arrayIdentity.rebaselineAll();
5137
+ removedSubtrees.clear();
5110
5138
  originals.clear();
5111
5139
  diffAndApply({}, next, [], (patch) => {
5112
5140
  if (patch.kind !== "added") return;
@@ -5243,6 +5271,26 @@ function createFormStore(options) {
5243
5271
  function hasStructuralChangeUnder(path) {
5244
5272
  return arrayIdentity.hasStructuralChangeUnder(path);
5245
5273
  }
5274
+ function subtreeHadRealBaseline(prefix, removedValue) {
5275
+ let had = false;
5276
+ diffAndApply(removedValue, void 0, prefix, (patch) => {
5277
+ if (had || patch.kind !== "removed") return;
5278
+ const record = originals.get(paths.canonicalizePath(patch.path).key);
5279
+ if (record?.value !== void 0) had = true;
5280
+ });
5281
+ return had;
5282
+ }
5283
+ function hasRemovedSubtreeUnder(prefix) {
5284
+ if (removedSubtrees.size === 0) return false;
5285
+ for (const key of removedSubtrees) {
5286
+ const segments = paths.segmentsForPathKey(key);
5287
+ if (segments === null) continue;
5288
+ if (!paths.isPathPrefix(prefix, segments)) continue;
5289
+ if (isContainer(getAtPath(vue.toRaw(form.value), segments))) continue;
5290
+ return true;
5291
+ }
5292
+ return false;
5293
+ }
5246
5294
  function getFieldRecord(path) {
5247
5295
  const { key } = paths.canonicalizePath(path);
5248
5296
  return fields.get(key);
@@ -5338,6 +5386,7 @@ function createFormStore(options) {
5338
5386
  isPristineAtPath,
5339
5387
  isPristineAtPathByKey,
5340
5388
  hasStructuralChangeUnder,
5389
+ hasRemovedSubtreeUnder,
5341
5390
  getFieldRecord,
5342
5391
  getOriginalAtPath,
5343
5392
  getFirstErrorElement,
@@ -5923,7 +5972,7 @@ function useRegister() {
5923
5972
  const dirs = instance.vnode.dirs;
5924
5973
  if (dirs !== null && dirs !== void 0) {
5925
5974
  for (const dir of dirs) {
5926
- const marked = dir.dir?.[paths.V_REGISTER_MARKER];
5975
+ const marked = dir.dir?.[registerProtocol.V_REGISTER_MARKER];
5927
5976
  if (marked === true) {
5928
5977
  capturedRegisterValue.value = dir.value;
5929
5978
  break;
@@ -5939,7 +5988,7 @@ function useRegister() {
5939
5988
  vue.onMounted(() => {
5940
5989
  const el = instance.vnode.el;
5941
5990
  if (el !== null && el !== void 0 && typeof el === "object") {
5942
- el[paths.REGISTER_OWNER_MARKER] = true;
5991
+ el[registerProtocol.REGISTER_OWNER_MARKER] = true;
5943
5992
  }
5944
5993
  if (capturedRegisterValue.value === void 0) {
5945
5994
  warnNoParentRV(instance);
@@ -6738,6 +6787,30 @@ function useWizard(options) {
6738
6787
  }
6739
6788
  return out;
6740
6789
  }
6790
+ function collectCallbackErrors(keys) {
6791
+ const out = [];
6792
+ for (const key of keys) {
6793
+ const store = registry.forms.get(key);
6794
+ if (store === void 0) continue;
6795
+ for (const errs of store.userErrors.values()) {
6796
+ for (const err of errs) out.push(toWizardAggregateError(err, key));
6797
+ }
6798
+ }
6799
+ return out;
6800
+ }
6801
+ async function focusFirstWizardError(errors) {
6802
+ if (options.focusFirstError === false) return;
6803
+ const firstFailedKey = errors[0]?.formKey;
6804
+ if (firstFailedKey === void 0 || !isCompiledKey(firstFailedKey)) return;
6805
+ moveTo(firstFailedKey);
6806
+ await vue.nextTick();
6807
+ const failedForm = formsRecord.value[firstFailedKey];
6808
+ if (failedForm === void 0) return;
6809
+ const failedSource = asSubmissionSource(failedForm);
6810
+ if (typeof failedSource.applyInvalidSubmitPolicy === "function") {
6811
+ failedSource.applyInvalidSubmitPolicy();
6812
+ }
6813
+ }
6741
6814
  function handleSubmit(onSubmit, onError) {
6742
6815
  return async function submitHandler(event) {
6743
6816
  if (event !== void 0 && typeof event.preventDefault === "function") {
@@ -6800,6 +6873,18 @@ function useWizard(options) {
6800
6873
  }
6801
6874
  const ctx = buildSubmitContext(valuesMap, currentKey, final);
6802
6875
  await onSubmit(ctx);
6876
+ const callbackErrors = collectCallbackErrors(results.keys());
6877
+ if (callbackErrors.length > 0) {
6878
+ await focusFirstWizardError(callbackErrors);
6879
+ if (onError !== void 0) {
6880
+ try {
6881
+ await onError(callbackErrors);
6882
+ } catch (cause) {
6883
+ throw new paths.SubmitErrorHandlerError("User-provided onError threw", { cause });
6884
+ }
6885
+ }
6886
+ return;
6887
+ }
6803
6888
  if (final) {
6804
6889
  done.value = true;
6805
6890
  } else {
@@ -6809,20 +6894,7 @@ function useWizard(options) {
6809
6894
  if (target !== void 0) moveTo(target.key);
6810
6895
  }
6811
6896
  } else {
6812
- if (options.focusFirstError !== false) {
6813
- const firstFailedKey = errors[0]?.formKey;
6814
- if (firstFailedKey !== void 0 && isCompiledKey(firstFailedKey)) {
6815
- moveTo(firstFailedKey);
6816
- await vue.nextTick();
6817
- const failedForm = formsRecord.value[firstFailedKey];
6818
- if (failedForm !== void 0) {
6819
- const failedSource = asSubmissionSource(failedForm);
6820
- if (typeof failedSource.applyInvalidSubmitPolicy === "function") {
6821
- failedSource.applyInvalidSubmitPolicy();
6822
- }
6823
- }
6824
- }
6825
- }
6897
+ await focusFirstWizardError(errors);
6826
6898
  if (onError !== void 0) {
6827
6899
  try {
6828
6900
  await onError(errors);
@@ -7050,4 +7122,4 @@ exports.unset = unset;
7050
7122
  exports.useAbstractForm = useAbstractForm;
7051
7123
  exports.useRegister = useRegister;
7052
7124
  exports.useWizard = useWizard;
7053
- //# sourceMappingURL=attaform.C42wL7EJ.cjs.map
7125
+ //# sourceMappingURL=attaform.Bos7wVZw.cjs.map