attaform 0.20.0 → 0.20.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 (76) hide show
  1. package/README.md +4 -1
  2. package/dist/chunks/devtools.cjs +2 -2
  3. package/dist/chunks/devtools.cjs.map +1 -1
  4. package/dist/chunks/devtools.mjs +2 -2
  5. package/dist/chunks/devtools.mjs.map +1 -1
  6. package/dist/chunks/indexeddb.cjs +1 -1
  7. package/dist/chunks/indexeddb.mjs +1 -1
  8. package/dist/chunks/local-storage.cjs +1 -1
  9. package/dist/chunks/local-storage.mjs +1 -1
  10. package/dist/chunks/session-storage.cjs +1 -1
  11. package/dist/chunks/session-storage.mjs +1 -1
  12. package/dist/index.cjs +3 -3
  13. package/dist/index.d.cts +4 -4
  14. package/dist/index.d.mts +4 -4
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.mjs +5 -5
  17. package/dist/nuxt.d.cts +1 -1
  18. package/dist/nuxt.d.mts +1 -1
  19. package/dist/nuxt.d.ts +1 -1
  20. package/dist/runtime/plugins/attaform.cjs +2 -2
  21. package/dist/runtime/plugins/attaform.mjs +2 -2
  22. package/dist/shared/{attaform.SfhU0OEY.d.ts → attaform.99cfHcIt.d.cts} +26 -9
  23. package/dist/shared/{attaform.SfhU0OEY.d.mts → attaform.99cfHcIt.d.mts} +26 -9
  24. package/dist/shared/{attaform.SfhU0OEY.d.cts → attaform.99cfHcIt.d.ts} +26 -9
  25. package/dist/shared/{attaform.BWgAFnsj.mjs → attaform.BGk8cfw2.mjs} +14 -10
  26. package/dist/shared/attaform.BGk8cfw2.mjs.map +1 -0
  27. package/dist/shared/{attaform.DoKXru-a.d.mts → attaform.BXinSW2T.d.mts} +1 -1
  28. package/dist/shared/{attaform.Dmb6itxC.cjs → attaform.B_hph5AE.cjs} +14 -10
  29. package/dist/shared/attaform.B_hph5AE.cjs.map +1 -0
  30. package/dist/shared/{attaform.DEBvCjeH.mjs → attaform.C5aYC_T8.mjs} +4 -4
  31. package/dist/shared/{attaform.DEBvCjeH.mjs.map → attaform.C5aYC_T8.mjs.map} +1 -1
  32. package/dist/shared/{attaform.CIn4bMsD.cjs → attaform.Cd4AOfwu.cjs} +4 -4
  33. package/dist/shared/{attaform.CIn4bMsD.cjs.map → attaform.Cd4AOfwu.cjs.map} +1 -1
  34. package/dist/shared/{attaform.EZG6fOFb.mjs → attaform.CnrxbkB6.mjs} +2 -2
  35. package/dist/shared/{attaform.EZG6fOFb.mjs.map → attaform.CnrxbkB6.mjs.map} +1 -1
  36. package/dist/shared/{attaform.DL4CQ-oW.cjs → attaform.CwLjUqmQ.cjs} +101 -50
  37. package/dist/shared/attaform.CwLjUqmQ.cjs.map +1 -0
  38. package/dist/shared/{attaform.GbDo_lJi.d.cts → attaform.CywE4y8x.d.cts} +1 -1
  39. package/dist/shared/{attaform.BPxsYtTe.cjs → attaform.D2SCCd4O.cjs} +2 -2
  40. package/dist/shared/{attaform.BPxsYtTe.cjs.map → attaform.D2SCCd4O.cjs.map} +1 -1
  41. package/dist/shared/{attaform.jgzuNZVC.cjs → attaform.DAKrGhxc.cjs} +4 -4
  42. package/dist/shared/{attaform.jgzuNZVC.cjs.map → attaform.DAKrGhxc.cjs.map} +1 -1
  43. package/dist/shared/{attaform.Dl5kDY-A.d.ts → attaform.DN5CvZrg.d.ts} +1 -1
  44. package/dist/shared/{attaform.D5-1XGQU.d.cts → attaform.DbRgDFa7.d.cts} +1 -1
  45. package/dist/shared/{attaform.DvA-CJJW.mjs → attaform.Dt7dEcHk.mjs} +4 -4
  46. package/dist/shared/{attaform.DvA-CJJW.mjs.map → attaform.Dt7dEcHk.mjs.map} +1 -1
  47. package/dist/shared/{attaform.BKozEdTr.mjs → attaform.QG5TG8lB.mjs} +51 -35
  48. package/dist/shared/attaform.QG5TG8lB.mjs.map +1 -0
  49. package/dist/shared/{attaform.EMzJcQci.d.mts → attaform.ceGEAEMk.d.ts} +1 -1
  50. package/dist/shared/{attaform.Bh3ACtts.d.ts → attaform.sWm8B15V.d.mts} +1 -1
  51. package/dist/shared/{attaform.CKFbKFb6.mjs → attaform.tiWEVznj.mjs} +100 -51
  52. package/dist/shared/attaform.tiWEVznj.mjs.map +1 -0
  53. package/dist/shared/{attaform.BPy-4qRx.cjs → attaform.z5j3LwJz.cjs} +51 -34
  54. package/dist/shared/attaform.z5j3LwJz.cjs.map +1 -0
  55. package/dist/zod-v3.cjs +3 -3
  56. package/dist/zod-v3.d.cts +3 -3
  57. package/dist/zod-v3.d.mts +3 -3
  58. package/dist/zod-v3.d.ts +3 -3
  59. package/dist/zod-v3.mjs +3 -3
  60. package/dist/zod-v4.cjs +3 -3
  61. package/dist/zod-v4.d.cts +4 -4
  62. package/dist/zod-v4.d.mts +4 -4
  63. package/dist/zod-v4.d.ts +4 -4
  64. package/dist/zod-v4.mjs +3 -3
  65. package/dist/zod.cjs +5 -5
  66. package/dist/zod.d.cts +5 -5
  67. package/dist/zod.d.mts +5 -5
  68. package/dist/zod.d.ts +5 -5
  69. package/dist/zod.mjs +6 -6
  70. package/package.json +4 -3
  71. package/dist/shared/attaform.BKozEdTr.mjs.map +0 -1
  72. package/dist/shared/attaform.BPy-4qRx.cjs.map +0 -1
  73. package/dist/shared/attaform.BWgAFnsj.mjs.map +0 -1
  74. package/dist/shared/attaform.CKFbKFb6.mjs.map +0 -1
  75. package/dist/shared/attaform.DL4CQ-oW.cjs.map +0 -1
  76. package/dist/shared/attaform.Dmb6itxC.cjs.map +0 -1
@@ -830,12 +830,8 @@ function syncElementRegistration(el, value, oldValue) {
830
830
  const wasRegistered = isRegisterValue(oldValue);
831
831
  const isRegistered = isRegisterValue(value);
832
832
  if (!wasRegistered && !isRegistered) return;
833
- if (wasRegistered && isRegistered) {
834
- const old = oldValue;
835
- const next = value;
836
- if (old.path === next.path && old.persistOptIns === next.persistOptIns) return;
837
- }
838
- if (wasRegistered) {
833
+ const samePathAndStore = wasRegistered && isRegistered && oldValue.path === value.path && oldValue.persistOptIns === value.persistOptIns;
834
+ if (wasRegistered && !samePathAndStore) {
839
835
  oldValue.deregisterElement(el);
840
836
  }
841
837
  if (isRegistered) {
@@ -859,14 +855,28 @@ function isRegisterValue(val) {
859
855
  function writeLastTypedForm(rv, next) {
860
856
  rv.lastTypedForm.value = next;
861
857
  }
862
- function computePersistMeta(el, registerValue) {
863
- const elementId = getOrAssignElementId(el);
864
- return { persist: registerValue.persistOptIns.hasOptIn(elementId, registerValue.path) };
865
- }
866
858
  const DEFAULT_ASSIGNER_TAG = Symbol.for("attaform:default-assigner-tag");
867
859
  function isDefaultAssigner(fn) {
868
860
  return typeof fn === "function" && fn[DEFAULT_ASSIGNER_TAG] === true;
869
861
  }
862
+ const CONSUMER_WRAPPED_TAG = Symbol.for("attaform:consumer-wrapped-assigner");
863
+ function isConsumerWrapped(fn) {
864
+ return typeof fn === "function" && fn[CONSUMER_WRAPPED_TAG] === true;
865
+ }
866
+ function fireAssigner(el, registerValue, value) {
867
+ const fn = el[assignKey];
868
+ if (fn === void 0) return void 0;
869
+ if (isDefaultAssigner(fn) || isConsumerWrapped(fn)) {
870
+ return fn(value);
871
+ }
872
+ if (!isRegisterValue(registerValue)) {
873
+ return fn(value, void 0);
874
+ }
875
+ const r = runTransforms(value, registerValue);
876
+ if (!r.ok) return false;
877
+ const coerced = applyCoerce(r.value, registerValue);
878
+ return fn(coerced, registerValue);
879
+ }
870
880
  function shouldBailListener(el) {
871
881
  if (INTERACTIVE_TAG_NAMES.has(el.tagName)) return false;
872
882
  return isDefaultAssigner(el[assignKey]);
@@ -922,38 +932,39 @@ function logTransformAsync(path) {
922
932
  );
923
933
  }
924
934
  }
925
- const getModelAssigner = (el, vnode, registerValue) => {
935
+ const getModelAssigner = (vnode, registerValue) => {
926
936
  const fn = vnode.props?.["onUpdate:registerValue"] ?? vnode.props?.["on:update:registerValue"];
927
937
  if (isArray(fn)) {
928
938
  const fnArr = fn.filter((x) => isFunction(x));
929
- return (value) => {
939
+ const wrapped = (value) => {
930
940
  const r = runTransforms(value, registerValue);
931
941
  if (!r.ok) return false;
932
942
  const coerced = applyCoerce(r.value, registerValue);
933
943
  invokeArrayFns(fnArr, coerced, registerValue);
934
944
  return void 0;
935
945
  };
946
+ wrapped[CONSUMER_WRAPPED_TAG] = true;
947
+ return wrapped;
936
948
  }
937
949
  if (isFunction(fn)) {
938
950
  const handler = fn;
939
- return (value) => {
951
+ const wrapped = (value) => {
940
952
  const r = runTransforms(value, registerValue);
941
953
  if (!r.ok) return false;
942
954
  const coerced = applyCoerce(r.value, registerValue);
943
955
  return handler(coerced, registerValue);
944
956
  };
957
+ wrapped[CONSUMER_WRAPPED_TAG] = true;
958
+ return wrapped;
945
959
  }
946
960
  const defaultAssigner = (value) => {
947
961
  if (value === void 0 && registerValue.acceptsUndefined) {
948
- return registerValue.setValueWithInternalPath(
949
- void 0,
950
- computePersistMeta(el, registerValue)
951
- );
962
+ return registerValue.setValueWithInternalPath(void 0);
952
963
  }
953
964
  const r = runTransforms(value, registerValue);
954
965
  if (!r.ok) return false;
955
966
  const coerced = applyCoerce(r.value, registerValue);
956
- return registerValue.setValueWithInternalPath(coerced, computePersistMeta(el, registerValue));
967
+ return registerValue.setValueWithInternalPath(coerced);
957
968
  };
958
969
  defaultAssigner[DEFAULT_ASSIGNER_TAG] = true;
959
970
  return defaultAssigner;
@@ -976,7 +987,8 @@ function makeNoopAssigner() {
976
987
  return noop;
977
988
  }
978
989
  function setAssignFunction(el, vnode, value) {
979
- if (el[assignKey] !== void 0 && !isDefaultAssigner(el[assignKey])) {
990
+ const current = el[assignKey];
991
+ if (current !== void 0 && !isDefaultAssigner(current) && !isConsumerWrapped(current)) {
980
992
  return;
981
993
  }
982
994
  if (value === void 0) {
@@ -990,11 +1002,12 @@ function setAssignFunction(el, vnode, value) {
990
1002
  el[assignKey] = makeNoopAssigner();
991
1003
  return;
992
1004
  }
993
- el[assignKey] = getModelAssigner(el, vnode, value);
1005
+ el[assignKey] = getModelAssigner(vnode, value);
994
1006
  }
995
1007
  const vRegisterText = {
996
1008
  created(el, { value, modifiers: { lazy, trim, number } }, vnode) {
997
- const castToNumber = number === true || vnode.props?.["type"] === "number";
1009
+ const castToNumberAtCreated = number === true || vnode.props?.["type"] === "number";
1010
+ const liveCastToNumber = () => number === true || el.getAttribute("type") === "number";
998
1011
  if (isRegisterValue(value)) {
999
1012
  value.registerElement(el);
1000
1013
  setAssignFunction(el, vnode, value);
@@ -1004,6 +1017,7 @@ const vRegisterText = {
1004
1017
  const target = e.target;
1005
1018
  if (target === null || target.composing) return;
1006
1019
  noteInteraction(value);
1020
+ const castToNumber = liveCastToNumber();
1007
1021
  let domValue = el.value;
1008
1022
  if (trim === true && lazy === true) {
1009
1023
  domValue = domValue.trim();
@@ -1044,7 +1058,7 @@ const vRegisterText = {
1044
1058
  return;
1045
1059
  }
1046
1060
  const commit = domValue === "" && isRegisterValue(value) && value.acceptsUndefined ? void 0 : domValue;
1047
- el[assignKey]?.(commit);
1061
+ fireAssigner(el, value, commit);
1048
1062
  if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
1049
1063
  const storage = value.innerRef.value;
1050
1064
  if (storage !== domValue) {
@@ -1054,17 +1068,18 @@ const vRegisterText = {
1054
1068
  }
1055
1069
  }
1056
1070
  });
1057
- if (trim === true || castToNumber) {
1071
+ if (trim === true || castToNumberAtCreated) {
1058
1072
  addTrackedListener(el, "change", () => {
1059
1073
  if (shouldBailListener(el)) return;
1060
1074
  let normalized = el.value;
1061
1075
  if (trim === true) normalized = normalized.trim();
1076
+ const castToNumber = liveCastToNumber();
1062
1077
  if (castToNumber) {
1063
1078
  const cast = looseToNumber(normalized);
1064
1079
  if (typeof cast === "number" && Number.isFinite(cast)) {
1065
1080
  if (isRegisterValue(value)) writeLastTypedForm(value, null);
1066
1081
  el.value = String(cast);
1067
- if (lazy !== true) el[assignKey]?.(cast);
1082
+ if (lazy !== true) fireAssigner(el, value, cast);
1068
1083
  } else {
1069
1084
  if (isRegisterValue(value)) {
1070
1085
  writeLastTypedForm(value, null);
@@ -1076,7 +1091,7 @@ const vRegisterText = {
1076
1091
  }
1077
1092
  el.value = typeof normalized === "number" ? String(normalized) : normalized;
1078
1093
  if (trim === true && lazy !== true) {
1079
- el[assignKey]?.(normalized);
1094
+ fireAssigner(el, value, normalized);
1080
1095
  }
1081
1096
  });
1082
1097
  }
@@ -1140,7 +1155,6 @@ const vRegisterCheckbox = {
1140
1155
  const explicitValueRequired = true;
1141
1156
  const rawElementValue = getValue(el, explicitValueRequired);
1142
1157
  const checked = el.checked;
1143
- const assign = el[assignKey];
1144
1158
  if (isArray(modelValue)) {
1145
1159
  if (rawElementValue === void 0) {
1146
1160
  warn(
@@ -1152,11 +1166,11 @@ const vRegisterCheckbox = {
1152
1166
  const index = looseIndexOf(modelValue, elementValue);
1153
1167
  const found = index !== -1;
1154
1168
  if (checked && !found) {
1155
- assign?.(modelValue.concat(elementValue));
1169
+ fireAssigner(el, value, modelValue.concat(elementValue));
1156
1170
  } else if (!checked && found) {
1157
1171
  const filtered = [...modelValue];
1158
1172
  filtered.splice(index, 1);
1159
- assign?.(filtered);
1173
+ fireAssigner(el, value, filtered);
1160
1174
  }
1161
1175
  } else if (isSet(modelValue)) {
1162
1176
  if (rawElementValue === void 0) {
@@ -1172,9 +1186,9 @@ const vRegisterCheckbox = {
1172
1186
  } else {
1173
1187
  cloned.delete(elementValue);
1174
1188
  }
1175
- assign?.(cloned);
1189
+ fireAssigner(el, value, cloned);
1176
1190
  } else {
1177
- assign?.(getCheckboxValue(el, checked));
1191
+ fireAssigner(el, value, getCheckboxValue(el, checked));
1178
1192
  }
1179
1193
  if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
1180
1194
  setChecked(el, value);
@@ -1234,7 +1248,7 @@ const vRegisterRadio = {
1234
1248
  addTrackedListener(el, "change", () => {
1235
1249
  if (shouldBailListener(el)) return;
1236
1250
  noteInteraction(value);
1237
- el[assignKey]?.(getValue(el));
1251
+ fireAssigner(el, value, getValue(el));
1238
1252
  if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
1239
1253
  const currentModel = value.innerRef.value;
1240
1254
  const target = looseEqual(currentModel, applyCoerce(getValue(el), value));
@@ -1279,12 +1293,14 @@ const vRegisterSelect = {
1279
1293
  created(el, { value, modifiers: { number } }, vnode) {
1280
1294
  if (!isRegisterValue(value)) return;
1281
1295
  value.registerElement(el);
1282
- const isSetModel = isSet(value.innerRef.value);
1283
1296
  addTrackedListener(el, "change", () => {
1284
1297
  if (shouldBailListener(el)) return;
1285
1298
  noteInteraction(value);
1299
+ const isSetModel = isSet(value.innerRef.value);
1286
1300
  const selectedVal = Array.prototype.filter.call(el.options, (o) => o.selected).map((o) => number === true ? looseToNumber(getValue(o)) : getValue(o));
1287
- const wrote = el[assignKey]?.(
1301
+ const wrote = fireAssigner(
1302
+ el,
1303
+ value,
1288
1304
  el.multiple ? isSetModel ? new Set(selectedVal) : selectedVal : selectedVal[0]
1289
1305
  );
1290
1306
  if (wrote !== false) {
@@ -1631,5 +1647,5 @@ function isPathPrefix(prefix, path) {
1631
1647
  return true;
1632
1648
  }
1633
1649
 
1634
- export { AnonPersistError as A, parseDottedPath as B, pathKeyToDotted as C, DEFAULT_SENSITIVE_NAMES as D, segmentsForPathKey as E, FORM_ERRORS_PATH as F, useRegister as G, useRegistry as H, INTERACTIVE_TAG_NAMES as I, vRegister as J, OutsideSetupError as O, ROOT_PATH as R, SubmitErrorHandlerError as S, __DEV__ as _, AttaformError as a, FORM_ERRORS_PATH_KEY as b, InvalidPathError as c, InvalidUseFormConfigError as d, ROOT_PATH_KEY as e, RegistryNotInstalledError as f, ReservedFormKeyError as g, allowSensitivePersist as h, assignKey as i, canonicalizePath as j, captureUserCallSite as k, coerceToPathKey as l, createAttaform as m, createIsSensitivePath as n, createPersistOptInRegistry as o, createRegistry as p, ensureAttaformInstalled as q, getRegistryFromApp as r, isPathPrefix as s, isRegisterValue as t, isSensitivePath as u, kAttaformAncestorWizard as v, kAttaformRegistry as w, kAttaformWizardActiveStepResolver as x, kFormContext as y, kFormInstanceId as z };
1635
- //# sourceMappingURL=attaform.BKozEdTr.mjs.map
1650
+ export { AnonPersistError as A, kFormInstanceId as B, parseDottedPath as C, DEFAULT_SENSITIVE_NAMES as D, pathKeyToDotted as E, FORM_ERRORS_PATH as F, segmentsForPathKey as G, useRegister as H, INTERACTIVE_TAG_NAMES as I, useRegistry as J, vRegister as K, OutsideSetupError as O, ROOT_PATH as R, SubmitErrorHandlerError as S, __DEV__ as _, AttaformError as a, FORM_ERRORS_PATH_KEY as b, InvalidPathError as c, InvalidUseFormConfigError as d, ROOT_PATH_KEY as e, RegistryNotInstalledError as f, ReservedFormKeyError as g, allowSensitivePersist as h, assignKey as i, canonicalizePath as j, captureUserCallSite as k, coerceToPathKey as l, createAttaform as m, createIsSensitivePath as n, createPersistOptInRegistry as o, createRegistry as p, ensureAttaformInstalled as q, getOrAssignElementId as r, getRegistryFromApp as s, isPathPrefix as t, isRegisterValue as u, isSensitivePath as v, kAttaformAncestorWizard as w, kAttaformRegistry as x, kAttaformWizardActiveStepResolver as y, kFormContext as z };
1651
+ //# sourceMappingURL=attaform.QG5TG8lB.mjs.map