attaform 0.24.0 → 0.24.1

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 (83) 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.BNmkKz0q.d.mts → attaform.4zesozTg.d.mts} +1 -1
  20. package/dist/shared/{attaform.DwkU0oY9.cjs → attaform.B7UdTs_o.cjs} +79 -75
  21. package/dist/shared/attaform.B7UdTs_o.cjs.map +1 -0
  22. package/dist/shared/{attaform.nycEksJn.cjs → attaform.BOi6n2Pn.cjs} +2 -2
  23. package/dist/shared/{attaform.nycEksJn.cjs.map → attaform.BOi6n2Pn.cjs.map} +1 -1
  24. package/dist/shared/{attaform.K-3glmiT.d.cts → attaform.Bk7vnQhG.d.cts} +1 -1
  25. package/dist/shared/{attaform.C6eE50re.d.ts → attaform.Bq6Copxn.d.cts} +24 -15
  26. package/dist/shared/{attaform.DdUYEhkV.d.cts → attaform.BrFPMFgi.d.ts} +24 -15
  27. package/dist/shared/{attaform.C-dAB90u.mjs → attaform.BunnTiTw.mjs} +4 -4
  28. package/dist/shared/{attaform.C-dAB90u.mjs.map → attaform.BunnTiTw.mjs.map} +1 -1
  29. package/dist/shared/{attaform.DiWNbKWa.d.mts → attaform.BwAcpoRw.d.mts} +24 -15
  30. package/dist/shared/{attaform.BV_HyaMO.cjs → attaform.C-1W0T1n.cjs} +3 -3
  31. package/dist/shared/{attaform.BV_HyaMO.cjs.map → attaform.C-1W0T1n.cjs.map} +1 -1
  32. package/dist/shared/{attaform.o95Kjd3U.mjs → attaform.C-tQKknW.mjs} +3 -3
  33. package/dist/shared/{attaform.o95Kjd3U.mjs.map → attaform.C-tQKknW.mjs.map} +1 -1
  34. package/dist/shared/{attaform.Df-s8j1X.mjs → attaform.C0au8oXd.mjs} +36 -29
  35. package/dist/shared/attaform.C0au8oXd.mjs.map +1 -0
  36. package/dist/shared/attaform.CjdepGnw.cjs +27 -0
  37. package/dist/shared/attaform.CjdepGnw.cjs.map +1 -0
  38. package/dist/shared/{attaform.Z1qTwOYE.cjs → attaform.Cn6JoG9o.cjs} +4 -4
  39. package/dist/shared/{attaform.Z1qTwOYE.cjs.map → attaform.Cn6JoG9o.cjs.map} +1 -1
  40. package/dist/shared/{attaform.BnUXV01g.cjs → attaform.CrrIaHM8.cjs} +4 -4
  41. package/dist/shared/{attaform.BnUXV01g.cjs.map → attaform.CrrIaHM8.cjs.map} +1 -1
  42. package/dist/shared/{attaform.GJbSmwLB.d.ts → attaform.DBhrKb2j.d.cts} +25 -12
  43. package/dist/shared/{attaform.GJbSmwLB.d.cts → attaform.DBhrKb2j.d.mts} +25 -12
  44. package/dist/shared/{attaform.GJbSmwLB.d.mts → attaform.DBhrKb2j.d.ts} +25 -12
  45. package/dist/shared/{attaform.C42wL7EJ.cjs → attaform.DRQjF16I.cjs} +55 -18
  46. package/dist/shared/attaform.DRQjF16I.cjs.map +1 -0
  47. package/dist/shared/{attaform.CwFZGv5-.d.ts → attaform.Df4xXKbE.d.ts} +1 -1
  48. package/dist/shared/{attaform.BFWb6hDk.mjs → attaform.DhXl0Kdr.mjs} +7 -1
  49. package/dist/shared/attaform.DhXl0Kdr.mjs.map +1 -0
  50. package/dist/shared/{attaform.CR6wGvNu.cjs → attaform.DwLw3Kzv.cjs} +7 -1
  51. package/dist/shared/attaform.DwLw3Kzv.cjs.map +1 -0
  52. package/dist/shared/{attaform.BJ_W7q3U.mjs → attaform.FY5r1BpA.mjs} +4 -4
  53. package/dist/shared/{attaform.BJ_W7q3U.mjs.map → attaform.FY5r1BpA.mjs.map} +1 -1
  54. package/dist/shared/{attaform.CuBdtfbe.mjs → attaform.NWrEGrNo.mjs} +53 -16
  55. package/dist/shared/attaform.NWrEGrNo.mjs.map +1 -0
  56. package/dist/shared/attaform.WvcckZMD.mjs +21 -0
  57. package/dist/shared/attaform.WvcckZMD.mjs.map +1 -0
  58. package/dist/transforms.cjs +1 -1
  59. package/dist/transforms.mjs +1 -1
  60. package/dist/vite.cjs +1 -1
  61. package/dist/vite.mjs +1 -1
  62. package/dist/zod-v3.cjs +2 -2
  63. package/dist/zod-v3.d.cts +3 -3
  64. package/dist/zod-v3.d.mts +3 -3
  65. package/dist/zod-v3.d.ts +3 -3
  66. package/dist/zod-v3.mjs +2 -2
  67. package/dist/zod-v4.cjs +2 -2
  68. package/dist/zod-v4.d.cts +5 -5
  69. package/dist/zod-v4.d.mts +5 -5
  70. package/dist/zod-v4.d.ts +5 -5
  71. package/dist/zod-v4.mjs +2 -2
  72. package/dist/zod.cjs +5 -5
  73. package/dist/zod.d.cts +5 -5
  74. package/dist/zod.d.mts +5 -5
  75. package/dist/zod.d.ts +5 -5
  76. package/dist/zod.mjs +5 -5
  77. package/package.json +1 -1
  78. package/dist/shared/attaform.BFWb6hDk.mjs.map +0 -1
  79. package/dist/shared/attaform.C42wL7EJ.cjs.map +0 -1
  80. package/dist/shared/attaform.CR6wGvNu.cjs.map +0 -1
  81. package/dist/shared/attaform.CuBdtfbe.mjs.map +0 -1
  82. package/dist/shared/attaform.Df-s8j1X.mjs.map +0 -1
  83. package/dist/shared/attaform.DwkU0oY9.cjs.map +0 -1
@@ -2002,9 +2002,11 @@ type AttaformDefaults = {
2002
2002
  */
2003
2003
  type OnSubmit<Form extends GenericForm> = (form: Form) => void | Promise<void>;
2004
2004
  /**
2005
- * Callback invoked by `handleSubmit` when validation fails. Receives
2006
- * the full list of errors. Bind this when you want to react to
2007
- * submit failures explicitly (alongside or instead of the
2005
+ * Callback invoked by `handleSubmit` on a failed submit. Fires when
2006
+ * client validation fails AND when the submit callback leaves errors in
2007
+ * the user-error layer (the `setErrors(...); return` server-rejection
2008
+ * pattern). Receives the full list of errors. Bind this when you want to
2009
+ * react to submit failures explicitly (alongside or instead of the
2008
2010
  * automatic `onInvalidSubmit` UI nudge).
2009
2011
  */
2010
2012
  type OnError = (error: ValidationError[]) => void | Promise<void>;
@@ -3649,10 +3651,14 @@ type FormMeta<F = unknown> = FieldState<F> & {
3649
3651
  *
3650
3652
  * The submit handler does NOT re-throw — its returned promise always
3651
3653
  * resolves, so binding it to `@submit.prevent` never manufactures a
3652
- * `window` unhandledrejection. This is the single channel for "the
3653
- * submit failed", read the same way in templates and after an
3654
- * imperative `await submit()`. Like `hydrateError`, it stays distinct
3655
- * from the curated user-error store: render it where you choose:
3654
+ * `window` unhandledrejection. This is the channel for an UNEXPECTED
3655
+ * submit failure (a thrown exception or rejected promise), read the
3656
+ * same way in templates and after an imperative `await submit()`. An
3657
+ * EXPECTED rejection handled the documented way (`setErrors(...)` then
3658
+ * `return`, no throw) surfaces through the error store and `onError`
3659
+ * instead, leaving `submitError` `null`. Like `hydrateError`, it stays
3660
+ * distinct from the curated user-error store: render it where you
3661
+ * choose:
3656
3662
  *
3657
3663
  * ```vue
3658
3664
  * <p v-if="form.meta.submitError">{{ form.meta.submitError.message }}</p>
@@ -3669,11 +3675,18 @@ type FormMeta<F = unknown> = FieldState<F> & {
3669
3675
  */
3670
3676
  readonly errorCount: number;
3671
3677
  /**
3672
- * `true` once a `handleSubmit` callback has resolved without
3673
- * throwing. Independent of `submissionAttempts` — a failed submit
3674
- * (validation failure or callback rejection) increments attempts but
3675
- * leaves `submitted` at `false`. Templates read it as "the form has
3676
- * been submitted successfully at least once."
3678
+ * `true` once a `handleSubmit` callback has resolved without throwing
3679
+ * AND left no errors behind. Independent of `submissionAttempts` — a
3680
+ * failed submit (validation failure, callback rejection, or a callback
3681
+ * that calls `setErrors` and returns) increments attempts but leaves
3682
+ * `submitted` at `false`. Templates read it as "the form has been
3683
+ * submitted successfully at least once."
3684
+ *
3685
+ * The error check is scoped to the user-error layer (`setErrors` /
3686
+ * `clearErrors`): the documented server-rejection pattern
3687
+ * (`setErrors(response.errors); return`) is a failed submit, so it does
3688
+ * not flip `submitted`. A background async refinement that writes a
3689
+ * schema error mid-submit does not retroactively fail it.
3677
3690
  *
3678
3691
  * Cleared by `form.reset()` alongside `submissionAttempts` and
3679
3692
  * `submitError`. For "the user has attempted a submit," read
@@ -2002,9 +2002,11 @@ type AttaformDefaults = {
2002
2002
  */
2003
2003
  type OnSubmit<Form extends GenericForm> = (form: Form) => void | Promise<void>;
2004
2004
  /**
2005
- * Callback invoked by `handleSubmit` when validation fails. Receives
2006
- * the full list of errors. Bind this when you want to react to
2007
- * submit failures explicitly (alongside or instead of the
2005
+ * Callback invoked by `handleSubmit` on a failed submit. Fires when
2006
+ * client validation fails AND when the submit callback leaves errors in
2007
+ * the user-error layer (the `setErrors(...); return` server-rejection
2008
+ * pattern). Receives the full list of errors. Bind this when you want to
2009
+ * react to submit failures explicitly (alongside or instead of the
2008
2010
  * automatic `onInvalidSubmit` UI nudge).
2009
2011
  */
2010
2012
  type OnError = (error: ValidationError[]) => void | Promise<void>;
@@ -3649,10 +3651,14 @@ type FormMeta<F = unknown> = FieldState<F> & {
3649
3651
  *
3650
3652
  * The submit handler does NOT re-throw — its returned promise always
3651
3653
  * resolves, so binding it to `@submit.prevent` never manufactures a
3652
- * `window` unhandledrejection. This is the single channel for "the
3653
- * submit failed", read the same way in templates and after an
3654
- * imperative `await submit()`. Like `hydrateError`, it stays distinct
3655
- * from the curated user-error store: render it where you choose:
3654
+ * `window` unhandledrejection. This is the channel for an UNEXPECTED
3655
+ * submit failure (a thrown exception or rejected promise), read the
3656
+ * same way in templates and after an imperative `await submit()`. An
3657
+ * EXPECTED rejection handled the documented way (`setErrors(...)` then
3658
+ * `return`, no throw) surfaces through the error store and `onError`
3659
+ * instead, leaving `submitError` `null`. Like `hydrateError`, it stays
3660
+ * distinct from the curated user-error store: render it where you
3661
+ * choose:
3656
3662
  *
3657
3663
  * ```vue
3658
3664
  * <p v-if="form.meta.submitError">{{ form.meta.submitError.message }}</p>
@@ -3669,11 +3675,18 @@ type FormMeta<F = unknown> = FieldState<F> & {
3669
3675
  */
3670
3676
  readonly errorCount: number;
3671
3677
  /**
3672
- * `true` once a `handleSubmit` callback has resolved without
3673
- * throwing. Independent of `submissionAttempts` — a failed submit
3674
- * (validation failure or callback rejection) increments attempts but
3675
- * leaves `submitted` at `false`. Templates read it as "the form has
3676
- * been submitted successfully at least once."
3678
+ * `true` once a `handleSubmit` callback has resolved without throwing
3679
+ * AND left no errors behind. Independent of `submissionAttempts` — a
3680
+ * failed submit (validation failure, callback rejection, or a callback
3681
+ * that calls `setErrors` and returns) increments attempts but leaves
3682
+ * `submitted` at `false`. Templates read it as "the form has been
3683
+ * submitted successfully at least once."
3684
+ *
3685
+ * The error check is scoped to the user-error layer (`setErrors` /
3686
+ * `clearErrors`): the documented server-rejection pattern
3687
+ * (`setErrors(response.errors); return`) is a failed submit, so it does
3688
+ * not flip `submitted`. A background async refinement that writes a
3689
+ * schema error mid-submit does not retroactively fail it.
3677
3690
  *
3678
3691
  * Cleared by `form.reset()` alongside `submissionAttempts` and
3679
3692
  * `submitError`. For "the user has attempted a submit," read
@@ -2002,9 +2002,11 @@ type AttaformDefaults = {
2002
2002
  */
2003
2003
  type OnSubmit<Form extends GenericForm> = (form: Form) => void | Promise<void>;
2004
2004
  /**
2005
- * Callback invoked by `handleSubmit` when validation fails. Receives
2006
- * the full list of errors. Bind this when you want to react to
2007
- * submit failures explicitly (alongside or instead of the
2005
+ * Callback invoked by `handleSubmit` on a failed submit. Fires when
2006
+ * client validation fails AND when the submit callback leaves errors in
2007
+ * the user-error layer (the `setErrors(...); return` server-rejection
2008
+ * pattern). Receives the full list of errors. Bind this when you want to
2009
+ * react to submit failures explicitly (alongside or instead of the
2008
2010
  * automatic `onInvalidSubmit` UI nudge).
2009
2011
  */
2010
2012
  type OnError = (error: ValidationError[]) => void | Promise<void>;
@@ -3649,10 +3651,14 @@ type FormMeta<F = unknown> = FieldState<F> & {
3649
3651
  *
3650
3652
  * The submit handler does NOT re-throw — its returned promise always
3651
3653
  * resolves, so binding it to `@submit.prevent` never manufactures a
3652
- * `window` unhandledrejection. This is the single channel for "the
3653
- * submit failed", read the same way in templates and after an
3654
- * imperative `await submit()`. Like `hydrateError`, it stays distinct
3655
- * from the curated user-error store: render it where you choose:
3654
+ * `window` unhandledrejection. This is the channel for an UNEXPECTED
3655
+ * submit failure (a thrown exception or rejected promise), read the
3656
+ * same way in templates and after an imperative `await submit()`. An
3657
+ * EXPECTED rejection handled the documented way (`setErrors(...)` then
3658
+ * `return`, no throw) surfaces through the error store and `onError`
3659
+ * instead, leaving `submitError` `null`. Like `hydrateError`, it stays
3660
+ * distinct from the curated user-error store: render it where you
3661
+ * choose:
3656
3662
  *
3657
3663
  * ```vue
3658
3664
  * <p v-if="form.meta.submitError">{{ form.meta.submitError.message }}</p>
@@ -3669,11 +3675,18 @@ type FormMeta<F = unknown> = FieldState<F> & {
3669
3675
  */
3670
3676
  readonly errorCount: number;
3671
3677
  /**
3672
- * `true` once a `handleSubmit` callback has resolved without
3673
- * throwing. Independent of `submissionAttempts` — a failed submit
3674
- * (validation failure or callback rejection) increments attempts but
3675
- * leaves `submitted` at `false`. Templates read it as "the form has
3676
- * been submitted successfully at least once."
3678
+ * `true` once a `handleSubmit` callback has resolved without throwing
3679
+ * AND left no errors behind. Independent of `submissionAttempts` — a
3680
+ * failed submit (validation failure, callback rejection, or a callback
3681
+ * that calls `setErrors` and returns) increments attempts but leaves
3682
+ * `submitted` at `false`. Templates read it as "the form has been
3683
+ * submitted successfully at least once."
3684
+ *
3685
+ * The error check is scoped to the user-error layer (`setErrors` /
3686
+ * `clearErrors`): the documented server-rejection pattern
3687
+ * (`setErrors(response.errors); return`) is a failed submit, so it does
3688
+ * not flip `submitted`. A background async refinement that writes a
3689
+ * schema error mid-submit does not retroactively fail it.
3677
3690
  *
3678
3691
  * Cleared by `form.reset()` alongside `submissionAttempts` and
3679
3692
  * `submitError`. For "the user has attempted a submit," read
@@ -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__") {
@@ -1921,6 +1922,19 @@ function buildProcessForm(state, formInstanceId, options = {}) {
1921
1922
  state.clearSchemaErrors();
1922
1923
  }
1923
1924
  await onSubmit(merged.data);
1925
+ if (state.userErrors.size > 0) {
1926
+ if (state.submissionGeneration.value === genAtEntry) {
1927
+ applyInvalidSubmitPolicy(state, formInstanceId, invalidPolicy);
1928
+ }
1929
+ if (onError !== void 0) {
1930
+ try {
1931
+ await onError(Array.from(state.userErrors.values()).flat());
1932
+ } catch (cause) {
1933
+ throw new paths.SubmitErrorHandlerError("User-provided onError threw", { cause });
1934
+ }
1935
+ }
1936
+ return;
1937
+ }
1924
1938
  if (state.submissionGeneration.value === genAtEntry) {
1925
1939
  state.submitted.value = true;
1926
1940
  }
@@ -5923,7 +5937,7 @@ function useRegister() {
5923
5937
  const dirs = instance.vnode.dirs;
5924
5938
  if (dirs !== null && dirs !== void 0) {
5925
5939
  for (const dir of dirs) {
5926
- const marked = dir.dir?.[paths.V_REGISTER_MARKER];
5940
+ const marked = dir.dir?.[registerProtocol.V_REGISTER_MARKER];
5927
5941
  if (marked === true) {
5928
5942
  capturedRegisterValue.value = dir.value;
5929
5943
  break;
@@ -5939,7 +5953,7 @@ function useRegister() {
5939
5953
  vue.onMounted(() => {
5940
5954
  const el = instance.vnode.el;
5941
5955
  if (el !== null && el !== void 0 && typeof el === "object") {
5942
- el[paths.REGISTER_OWNER_MARKER] = true;
5956
+ el[registerProtocol.REGISTER_OWNER_MARKER] = true;
5943
5957
  }
5944
5958
  if (capturedRegisterValue.value === void 0) {
5945
5959
  warnNoParentRV(instance);
@@ -6738,6 +6752,30 @@ function useWizard(options) {
6738
6752
  }
6739
6753
  return out;
6740
6754
  }
6755
+ function collectCallbackErrors(keys) {
6756
+ const out = [];
6757
+ for (const key of keys) {
6758
+ const store = registry.forms.get(key);
6759
+ if (store === void 0) continue;
6760
+ for (const errs of store.userErrors.values()) {
6761
+ for (const err of errs) out.push(toWizardAggregateError(err, key));
6762
+ }
6763
+ }
6764
+ return out;
6765
+ }
6766
+ async function focusFirstWizardError(errors) {
6767
+ if (options.focusFirstError === false) return;
6768
+ const firstFailedKey = errors[0]?.formKey;
6769
+ if (firstFailedKey === void 0 || !isCompiledKey(firstFailedKey)) return;
6770
+ moveTo(firstFailedKey);
6771
+ await vue.nextTick();
6772
+ const failedForm = formsRecord.value[firstFailedKey];
6773
+ if (failedForm === void 0) return;
6774
+ const failedSource = asSubmissionSource(failedForm);
6775
+ if (typeof failedSource.applyInvalidSubmitPolicy === "function") {
6776
+ failedSource.applyInvalidSubmitPolicy();
6777
+ }
6778
+ }
6741
6779
  function handleSubmit(onSubmit, onError) {
6742
6780
  return async function submitHandler(event) {
6743
6781
  if (event !== void 0 && typeof event.preventDefault === "function") {
@@ -6800,6 +6838,18 @@ function useWizard(options) {
6800
6838
  }
6801
6839
  const ctx = buildSubmitContext(valuesMap, currentKey, final);
6802
6840
  await onSubmit(ctx);
6841
+ const callbackErrors = collectCallbackErrors(results.keys());
6842
+ if (callbackErrors.length > 0) {
6843
+ await focusFirstWizardError(callbackErrors);
6844
+ if (onError !== void 0) {
6845
+ try {
6846
+ await onError(callbackErrors);
6847
+ } catch (cause) {
6848
+ throw new paths.SubmitErrorHandlerError("User-provided onError threw", { cause });
6849
+ }
6850
+ }
6851
+ return;
6852
+ }
6803
6853
  if (final) {
6804
6854
  done.value = true;
6805
6855
  } else {
@@ -6809,20 +6859,7 @@ function useWizard(options) {
6809
6859
  if (target !== void 0) moveTo(target.key);
6810
6860
  }
6811
6861
  } 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
- }
6862
+ await focusFirstWizardError(errors);
6826
6863
  if (onError !== void 0) {
6827
6864
  try {
6828
6865
  await onError(errors);
@@ -7050,4 +7087,4 @@ exports.unset = unset;
7050
7087
  exports.useAbstractForm = useAbstractForm;
7051
7088
  exports.useRegister = useRegister;
7052
7089
  exports.useWizard = useWizard;
7053
- //# sourceMappingURL=attaform.C42wL7EJ.cjs.map
7090
+ //# sourceMappingURL=attaform.DRQjF16I.cjs.map