attaform 0.27.3 → 0.27.5

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 (70) hide show
  1. package/dist/abstract.cjs +2 -2
  2. package/dist/abstract.d.cts +4 -4
  3. package/dist/abstract.d.mts +4 -4
  4. package/dist/abstract.d.ts +4 -4
  5. package/dist/abstract.mjs +2 -2
  6. package/dist/chunks/devtools.cjs +1 -1
  7. package/dist/chunks/devtools.mjs +1 -1
  8. package/dist/chunks/fingerprint2.cjs +1 -1
  9. package/dist/chunks/fingerprint2.mjs +1 -1
  10. package/dist/index.cjs +3 -3
  11. package/dist/index.d.cts +5 -5
  12. package/dist/index.d.mts +5 -5
  13. package/dist/index.d.ts +5 -5
  14. package/dist/index.mjs +3 -3
  15. package/dist/nuxt.d.cts +1 -1
  16. package/dist/nuxt.d.mts +1 -1
  17. package/dist/nuxt.d.ts +1 -1
  18. package/dist/runtime/plugins/attaform.cjs +1 -1
  19. package/dist/runtime/plugins/attaform.mjs +1 -1
  20. package/dist/shared/{attaform.BjGedLx2.d.cts → attaform.B3abZaCV.d.cts} +58 -16
  21. package/dist/shared/{attaform.DeHCOlC8.cjs → attaform.Bh8A6YAc.cjs} +4 -4
  22. package/dist/shared/{attaform.DeHCOlC8.cjs.map → attaform.Bh8A6YAc.cjs.map} +1 -1
  23. package/dist/shared/{attaform.BBaMFa-k.cjs → attaform.Biytrv0-.cjs} +3 -3
  24. package/dist/shared/{attaform.CgsQZdy1.mjs.map → attaform.Biytrv0-.cjs.map} +1 -1
  25. package/dist/shared/{attaform.BqkFQ2B9.mjs → attaform.BypWgXRB.mjs} +91 -32
  26. package/dist/shared/attaform.BypWgXRB.mjs.map +1 -0
  27. package/dist/shared/{attaform.Mg4g-J0z.cjs → attaform.CF-EnyJn.cjs} +5 -5
  28. package/dist/shared/{attaform.Mg4g-J0z.cjs.map → attaform.CF-EnyJn.cjs.map} +1 -1
  29. package/dist/shared/{attaform.C8zVmank.d.ts → attaform.CIBMfxg9.d.ts} +1 -1
  30. package/dist/shared/{attaform.CEZP3i3I.d.mts → attaform.CJ1Z9Mz4.d.mts} +58 -16
  31. package/dist/shared/{attaform.BKxpBJVF.mjs → attaform.CTiZ9Rrv.mjs} +3 -3
  32. package/dist/shared/{attaform.BKxpBJVF.mjs.map → attaform.CTiZ9Rrv.mjs.map} +1 -1
  33. package/dist/shared/{attaform.ij2W7VTw.cjs → attaform.Cg1rUfcF.cjs} +91 -32
  34. package/dist/shared/attaform.Cg1rUfcF.cjs.map +1 -0
  35. package/dist/shared/{attaform.DuVCclwv.mjs → attaform.Cg_8gFQ7.mjs} +4 -4
  36. package/dist/shared/{attaform.DuVCclwv.mjs.map → attaform.Cg_8gFQ7.mjs.map} +1 -1
  37. package/dist/shared/{attaform.BOIpRdeG.cjs → attaform.Crv0RNiz.cjs} +4 -4
  38. package/dist/shared/{attaform.BOIpRdeG.cjs.map → attaform.Crv0RNiz.cjs.map} +1 -1
  39. package/dist/shared/{attaform.BIPSHY5U.d.ts → attaform.CzL2CZ8U.d.cts} +8 -1
  40. package/dist/shared/{attaform.BIPSHY5U.d.cts → attaform.CzL2CZ8U.d.mts} +8 -1
  41. package/dist/shared/{attaform.BIPSHY5U.d.mts → attaform.CzL2CZ8U.d.ts} +8 -1
  42. package/dist/shared/{attaform.C925L0WA.d.mts → attaform.DYwyM5Cp.d.cts} +1 -1
  43. package/dist/shared/{attaform.DHQjaGMP.mjs → attaform.Dc1mx48r.mjs} +5 -5
  44. package/dist/shared/{attaform.DHQjaGMP.mjs.map → attaform.Dc1mx48r.mjs.map} +1 -1
  45. package/dist/shared/{attaform.gqOCvpSB.d.ts → attaform.DcFDQVpa.d.ts} +58 -16
  46. package/dist/shared/{attaform.DDIn4fv-.mjs → attaform.Dkjh_F30.mjs} +4 -4
  47. package/dist/shared/{attaform.DDIn4fv-.mjs.map → attaform.Dkjh_F30.mjs.map} +1 -1
  48. package/dist/shared/{attaform.CnvbLiIO.d.cts → attaform.DrHOqB-d.d.mts} +1 -1
  49. package/dist/shared/{attaform.dX58Auwf.cjs → attaform.f2zyNh5d.cjs} +3 -3
  50. package/dist/shared/{attaform.dX58Auwf.cjs.map → attaform.f2zyNh5d.cjs.map} +1 -1
  51. package/dist/shared/{attaform.CgsQZdy1.mjs → attaform.nMaz2C5P.mjs} +3 -3
  52. package/dist/shared/{attaform.BBaMFa-k.cjs.map → attaform.nMaz2C5P.mjs.map} +1 -1
  53. package/dist/zod-v3.cjs +3 -3
  54. package/dist/zod-v3.d.cts +3 -3
  55. package/dist/zod-v3.d.mts +3 -3
  56. package/dist/zod-v3.d.ts +3 -3
  57. package/dist/zod-v3.mjs +3 -3
  58. package/dist/zod-v4.cjs +3 -3
  59. package/dist/zod-v4.d.cts +6 -6
  60. package/dist/zod-v4.d.mts +6 -6
  61. package/dist/zod-v4.d.ts +6 -6
  62. package/dist/zod-v4.mjs +3 -3
  63. package/dist/zod.cjs +3 -3
  64. package/dist/zod.d.cts +3 -3
  65. package/dist/zod.d.mts +3 -3
  66. package/dist/zod.d.ts +3 -3
  67. package/dist/zod.mjs +3 -3
  68. package/package.json +1 -1
  69. package/dist/shared/attaform.BqkFQ2B9.mjs.map +0 -1
  70. package/dist/shared/attaform.ij2W7VTw.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { computed, ref, watchEffect, getCurrentScope, onScopeDispose, shallowReadonly, nextTick, warn, readonly, toRaw, reactive, toValue, watch, markRaw, triggerRef, shallowRef, getCurrentInstance, onServerPrefetch, provide, useId, inject, onBeforeMount, onBeforeUpdate, onMounted, effectScope } from 'vue';
2
- import { n as pathsEqual, k as isPathPrefix, _ as __DEV__, f as canonicalizePath, s as segmentsForPathKey, o as keyForSegments, b as ROOT_PATH_KEY, S as SubmitErrorHandlerError, t as toError, q as normalizeErrorInput, w as INTERACTIVE_TAG_NAMES, R as ROOT_PATH, x as normalizeErrorInputs, y as coerceToPathKey, a as InvalidUseFormConfigError, z as ensureAttaformInstalled, u as useRegistry, B as kFormContext, C as kFormInstanceId, d as ReservedFormKeyError, m as kAttaformWizardActiveStepResolver, E as kAttaformAncestorWizard } from './attaform.CgsQZdy1.mjs';
2
+ import { n as pathsEqual, k as isPathPrefix, _ as __DEV__, f as canonicalizePath, s as segmentsForPathKey, o as keyForSegments, b as ROOT_PATH_KEY, S as SubmitErrorHandlerError, t as toError, q as normalizeErrorInput, w as INTERACTIVE_TAG_NAMES, R as ROOT_PATH, x as normalizeErrorInputs, y as coerceToPathKey, a as InvalidUseFormConfigError, z as ensureAttaformInstalled, u as useRegistry, B as kFormContext, C as kFormInstanceId, d as ReservedFormKeyError, m as kAttaformWizardActiveStepResolver, E as kAttaformAncestorWizard } from './attaform.nMaz2C5P.mjs';
3
3
  import { R as REGISTER_OWNER_MARKER, b as V_REGISTER_MARKER } from './attaform.KvlEedlF.mjs';
4
4
 
5
5
  function safeAssign(target, key, value) {
@@ -2507,8 +2507,8 @@ function buildRegister(state, formInstanceId, instanceConfig) {
2507
2507
  markConnectedOptimistically: () => {
2508
2508
  state.markConnectedOptimistically(segments);
2509
2509
  },
2510
- markHostConnected: (connected) => {
2511
- state.markHostConnected(segments, connected);
2510
+ markHostConnected: (connected, hostEl) => {
2511
+ state.markHostConnected(segments, connected, hostEl, formInstanceId);
2512
2512
  },
2513
2513
  markFocused: (focused) => {
2514
2514
  state.markFocused(
@@ -4066,6 +4066,25 @@ function mergeObjectKeys(target, source, path, schema) {
4066
4066
  }
4067
4067
 
4068
4068
  const isContainer = (value) => Array.isArray(value) || isPlainRecord(value);
4069
+ const HOST_FOCUS_TARGET_SELECTOR = [
4070
+ 'input:not([type="hidden"])',
4071
+ "select",
4072
+ "textarea",
4073
+ "button",
4074
+ "a[href]",
4075
+ '[tabindex]:not([tabindex="-1"])',
4076
+ '[contenteditable="true"]'
4077
+ ].join(", ");
4078
+ function resolveHostFocusTarget(hostRoot) {
4079
+ const candidates = hostRoot.querySelectorAll(HOST_FOCUS_TARGET_SELECTOR);
4080
+ for (const el of candidates) {
4081
+ if (!el.isConnected) continue;
4082
+ if (el.offsetParent === null) continue;
4083
+ if (el.matches(":disabled")) continue;
4084
+ return el;
4085
+ }
4086
+ return hostRoot;
4087
+ }
4069
4088
  function isHydratedFieldRecord(value) {
4070
4089
  if (typeof value !== "object" || value === null) return false;
4071
4090
  const r = value;
@@ -4251,6 +4270,7 @@ function createFormStore(options) {
4251
4270
  const fields = reactive(/* @__PURE__ */ new Map());
4252
4271
  const elements = reactive(/* @__PURE__ */ new Map());
4253
4272
  const elementToFormInstance = /* @__PURE__ */ new WeakMap();
4273
+ const hostTargets = /* @__PURE__ */ new Map();
4254
4274
  let sortedRegistrationsCache = null;
4255
4275
  const schemaErrors = reactive(/* @__PURE__ */ new Map());
4256
4276
  const userErrors = reactive(/* @__PURE__ */ new Map());
@@ -5123,6 +5143,7 @@ function createFormStore(options) {
5123
5143
  record.elements.add(raw);
5124
5144
  }
5125
5145
  elementToFormInstance.set(element, formInstanceId);
5146
+ hostTargets.delete(key);
5126
5147
  sortedRegistrationsCache = null;
5127
5148
  const current = fields.get(key);
5128
5149
  touchFieldRecord(key, path, {
@@ -5160,10 +5181,14 @@ function createFormStore(options) {
5160
5181
  blurred: current?.blurred ?? true
5161
5182
  });
5162
5183
  }
5163
- function markHostConnected(path, connected) {
5184
+ function markHostConnected(path, connected, hostEl, formInstanceId) {
5164
5185
  const { key } = canonicalizePath(path);
5165
5186
  const current = fields.get(key);
5166
5187
  if (connected) {
5188
+ if (!elements.has(key)) {
5189
+ hostTargets.set(key, { path, hostRoot: hostEl, formInstanceId });
5190
+ sortedRegistrationsCache = null;
5191
+ }
5167
5192
  if (current?.connected === true) return;
5168
5193
  touchFieldRecord(key, path, {
5169
5194
  connected: true,
@@ -5171,6 +5196,7 @@ function createFormStore(options) {
5171
5196
  blurred: current?.blurred ?? true
5172
5197
  });
5173
5198
  } else {
5199
+ if (hostTargets.delete(key)) sortedRegistrationsCache = null;
5174
5200
  if (current?.connected !== true) return;
5175
5201
  touchFieldRecord(key, path, { connected: false, focused: null, blurred: null });
5176
5202
  }
@@ -5505,18 +5531,35 @@ function createFormStore(options) {
5505
5531
  function getFirstErrorElement(formInstanceId) {
5506
5532
  sortedRegistrationsCache ?? (sortedRegistrationsCache = rebuildSortedRegistrations());
5507
5533
  for (const entry of sortedRegistrationsCache) {
5508
- if (elementToFormInstance.get(entry.element) !== formInstanceId) continue;
5534
+ if (entry.formInstanceId !== formInstanceId) continue;
5509
5535
  if (!entry.element.isConnected) continue;
5510
5536
  if (entry.element.offsetParent === null) continue;
5511
5537
  if (getErrorsForPath(entry.path).length === 0) continue;
5512
- return { path: entry.path, element: entry.element };
5538
+ const element = entry.host ? resolveHostFocusTarget(entry.element) : entry.element;
5539
+ return { path: entry.path, element };
5513
5540
  }
5514
5541
  return null;
5515
5542
  }
5516
5543
  function rebuildSortedRegistrations() {
5517
5544
  const flat = [];
5518
5545
  for (const [, record] of elements) {
5519
- for (const el of record.elements) flat.push({ path: record.path, element: el });
5546
+ for (const el of record.elements) {
5547
+ flat.push({
5548
+ path: record.path,
5549
+ element: el,
5550
+ host: false,
5551
+ formInstanceId: elementToFormInstance.get(el) ?? ""
5552
+ });
5553
+ }
5554
+ }
5555
+ for (const [key, target] of hostTargets) {
5556
+ if (elements.has(key)) continue;
5557
+ flat.push({
5558
+ path: target.path,
5559
+ element: target.hostRoot,
5560
+ host: true,
5561
+ formInstanceId: target.formInstanceId
5562
+ });
5520
5563
  }
5521
5564
  flat.sort(
5522
5565
  (a, b) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1
@@ -6687,24 +6730,6 @@ function useWizard(options) {
6687
6730
  (slot) => isGateMarker(slot) || isLazyMarker(slot) || typeof slot === "function"
6688
6731
  );
6689
6732
  const clearedGates = reactive(/* @__PURE__ */ new Set());
6690
- const seededSampled = /* @__PURE__ */ new Set();
6691
- function isGateVerdictSettled(key) {
6692
- const store = registry.forms.get(key);
6693
- if (store === void 0) return false;
6694
- return store.defaultsResolved.value === true && store.firstValidationDone.value === true && store.activeValidations.value === 0;
6695
- }
6696
- function isGateFormValid(key) {
6697
- const form = formsRecord.value[key] ?? formsAccumulator.get(key);
6698
- if (form === void 0) return false;
6699
- return asStatusSource(form).meta?.valid ?? false;
6700
- }
6701
- function sampleSeededGate(key) {
6702
- if (seededSampled.has(key)) return;
6703
- if (noopForms.has(key)) return;
6704
- if (!isGateVerdictSettled(key)) return;
6705
- seededSampled.add(key);
6706
- if (isGateFormValid(key)) clearedGates.add(key);
6707
- }
6708
6733
  const gateSubs = /* @__PURE__ */ new Map();
6709
6734
  function reconcileGates() {
6710
6735
  const gateKeys = /* @__PURE__ */ new Set();
@@ -6721,7 +6746,6 @@ function useWizard(options) {
6721
6746
  );
6722
6747
  }
6723
6748
  }
6724
- sampleSeededGate(key);
6725
6749
  }
6726
6750
  for (const [key, unsub] of gateSubs) {
6727
6751
  if (!gateKeys.has(key)) {
@@ -6779,8 +6803,7 @@ function useWizard(options) {
6779
6803
  for (const step of compiledSteps.value) {
6780
6804
  if (!step.isGate) continue;
6781
6805
  const store = registry.forms.get(step.key);
6782
- const settled = store !== void 0 && isGateVerdictSettled(step.key);
6783
- parts.push(`${step.key}:${store !== void 0 ? 1 : 0}:${settled ? 1 : 0}`);
6806
+ parts.push(`${step.key}:${store !== void 0 ? 1 : 0}`);
6784
6807
  }
6785
6808
  return parts.join("|");
6786
6809
  },
@@ -6813,20 +6836,30 @@ function useWizard(options) {
6813
6836
  });
6814
6837
  }
6815
6838
  }
6839
+ function applyGateSeed(map) {
6840
+ if (map === void 0 || !mightGate) return;
6841
+ const gates = gatePositions.value;
6842
+ for (const key of Object.keys(map)) {
6843
+ if (map[key]?.gate === "cleared" && gates.includes(key)) clearedGates.add(key);
6844
+ }
6845
+ }
6816
6846
  const seedRef = ref(void 0);
6817
6847
  const seedInput = options.defaultStatuses;
6818
6848
  if (seedInput !== void 0) {
6819
6849
  const resolved = resolveTrichotomy(seedInput);
6820
6850
  if (resolved.kind === "sync") {
6821
6851
  seedRef.value = resolved.value;
6852
+ applyGateSeed(resolved.value);
6822
6853
  } else {
6823
6854
  const eager = resolved.factory();
6824
6855
  if (eager instanceof Promise) {
6825
6856
  void eager.then((value) => {
6826
6857
  seedRef.value = value;
6858
+ applyGateSeed(value);
6827
6859
  });
6828
6860
  } else {
6829
6861
  seedRef.value = eager;
6862
+ applyGateSeed(eager);
6830
6863
  }
6831
6864
  }
6832
6865
  }
@@ -6858,7 +6891,7 @@ function useWizard(options) {
6858
6891
  return locked || gate !== null ? { ...NOOP_VALID_STATUS, locked, gate } : NOOP_VALID_STATUS;
6859
6892
  }
6860
6893
  const seed = seedRef.value?.[form.key];
6861
- if (seed !== void 0) return { ...seed, locked, gate };
6894
+ if (seed !== void 0) return { ...PENDING_STATUS, ...seed, locked, gate };
6862
6895
  return locked || gate !== null ? { ...PENDING_STATUS, locked, gate } : PENDING_STATUS;
6863
6896
  });
6864
6897
  statusCache.set(form.key, computedStatus);
@@ -7350,14 +7383,16 @@ function useWizard(options) {
7350
7383
  submitError.value = null;
7351
7384
  if (mightGate) {
7352
7385
  clearedGates.clear();
7353
- seededSampled.clear();
7354
7386
  }
7355
7387
  lazyEpoch.value += 1;
7356
7388
  for (const step of compiledSteps.value) {
7357
7389
  const full = asSubmissionSource(step.form);
7358
7390
  if (typeof full.reset === "function") full.reset();
7359
7391
  }
7360
- if (mightGate) reconcileGates();
7392
+ if (mightGate) {
7393
+ reconcileGates();
7394
+ applyGateSeed(seedRef.value);
7395
+ }
7361
7396
  const firstStep = compiledSteps.value[0];
7362
7397
  if (firstStep !== void 0) {
7363
7398
  const landing = commitActiveKey(firstStep.key);
@@ -7368,6 +7403,29 @@ function useWizard(options) {
7368
7403
  }
7369
7404
  }
7370
7405
  }
7406
+ async function relock(key, commit) {
7407
+ if (!mightGate || !gatePositions.value.includes(key)) {
7408
+ if (__DEV__) {
7409
+ console.warn(
7410
+ `[attaform] useWizard.relock(${JSON.stringify(key)}): no gate at that key; nothing to re-lock.`
7411
+ );
7412
+ }
7413
+ return false;
7414
+ }
7415
+ try {
7416
+ await commit();
7417
+ } catch (err) {
7418
+ if (__DEV__) {
7419
+ console.warn(
7420
+ `[attaform] useWizard.relock(${JSON.stringify(key)}): commit threw, so the gate was not re-sealed.`,
7421
+ err
7422
+ );
7423
+ }
7424
+ return false;
7425
+ }
7426
+ clearedGates.delete(key);
7427
+ return true;
7428
+ }
7371
7429
  if (mightGate) {
7372
7430
  watchEffect(() => {
7373
7431
  const key = activeKey.value;
@@ -7393,6 +7451,7 @@ function useWizard(options) {
7393
7451
  tryNext,
7394
7452
  handleSubmit,
7395
7453
  reset,
7454
+ relock,
7396
7455
  get currentStep() {
7397
7456
  return currentStep.value;
7398
7457
  },
@@ -7573,4 +7632,4 @@ function escapeForInlineScript(json) {
7573
7632
  }
7574
7633
 
7575
7634
  export { AttaformErrorCode as A, DEFAULT_TIMINGS as D, defaultDisplayState as a, defineCoercion as b, injectWizard as c, defaultCoercionRules as d, escapeForInlineScript as e, isUnset as f, gate as g, useAbstractForm as h, injectForm as i, useRegister as j, useWizard as k, lazy as l, makeDefaultDisplayState as m, isPlainRecord as n, safeAssign as o, slimKindOf as p, humanize as q, getAtPath as r, safeOwnRead as s, setAtPath as t, unset as u };
7576
- //# sourceMappingURL=attaform.BqkFQ2B9.mjs.map
7635
+ //# sourceMappingURL=attaform.BypWgXRB.mjs.map