attaform 0.21.1 → 0.22.0

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 (108) hide show
  1. package/dist/chunks/dev-key-collision-warnings.cjs +1 -1
  2. package/dist/chunks/dev-key-collision-warnings.mjs +1 -1
  3. package/dist/chunks/devtools.cjs +1 -1
  4. package/dist/chunks/devtools.mjs +1 -1
  5. package/dist/chunks/fingerprint2.cjs +1 -1
  6. package/dist/chunks/fingerprint2.mjs +1 -1
  7. package/dist/chunks/indexeddb.cjs +1 -1
  8. package/dist/chunks/indexeddb.mjs +1 -1
  9. package/dist/chunks/local-storage.cjs +1 -1
  10. package/dist/chunks/local-storage.mjs +1 -1
  11. package/dist/chunks/multi-tab-sync.cjs +2 -2
  12. package/dist/chunks/multi-tab-sync.mjs +2 -2
  13. package/dist/chunks/session-storage.cjs +1 -1
  14. package/dist/chunks/session-storage.mjs +1 -1
  15. package/dist/chunks/wire-persistence.cjs +2 -2
  16. package/dist/chunks/wire-persistence.mjs +2 -2
  17. package/dist/index.cjs +37 -24
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +20 -18
  20. package/dist/index.d.mts +20 -18
  21. package/dist/index.d.ts +20 -18
  22. package/dist/index.mjs +38 -25
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/nuxt.d.cts +1 -1
  25. package/dist/nuxt.d.mts +1 -1
  26. package/dist/nuxt.d.ts +1 -1
  27. package/dist/runtime/components/AttaformDevtoolsPanel.vue +396 -216
  28. package/dist/runtime/components/DevtoolsValueTree.vue +176 -114
  29. package/dist/runtime/plugins/attaform.cjs +2 -2
  30. package/dist/runtime/plugins/attaform.mjs +2 -2
  31. package/dist/shared/{attaform.D32WwKk6.cjs → attaform.01iKS_lz.cjs} +260 -356
  32. package/dist/shared/attaform.01iKS_lz.cjs.map +1 -0
  33. package/dist/shared/{attaform.Y1ZGhM4k.mjs → attaform.6xE0Lcfd.mjs} +2 -2
  34. package/dist/shared/{attaform.Y1ZGhM4k.mjs.map → attaform.6xE0Lcfd.mjs.map} +1 -1
  35. package/dist/shared/{attaform.S-pYLSo4.cjs → attaform.AyujQoHp.cjs} +13 -16
  36. package/dist/shared/attaform.AyujQoHp.cjs.map +1 -0
  37. package/dist/shared/{attaform.BupwXkj_.mjs → attaform.BFWb6hDk.mjs} +29 -23
  38. package/dist/shared/attaform.BFWb6hDk.mjs.map +1 -0
  39. package/dist/shared/{attaform.NQ8mybyW.d.mts → attaform.BGwNZ9GV.d.cts} +63 -64
  40. package/dist/shared/{attaform.pmtahXKy.mjs → attaform.BKFwekY2.mjs} +257 -356
  41. package/dist/shared/attaform.BKFwekY2.mjs.map +1 -0
  42. package/dist/shared/{attaform.BSkvn43g.cjs → attaform.C-RtnCJM.cjs} +116 -47
  43. package/dist/shared/attaform.C-RtnCJM.cjs.map +1 -0
  44. package/dist/shared/{attaform.Bv7dRDWK.d.ts → attaform.CCCeEPwa.d.mts} +63 -64
  45. package/dist/shared/{attaform.BM6YD9kZ.cjs → attaform.CR6wGvNu.cjs} +29 -23
  46. package/dist/shared/attaform.CR6wGvNu.cjs.map +1 -0
  47. package/dist/shared/{attaform.Bq5sX7TF.cjs → attaform.CRzpFCjV.cjs} +2 -2
  48. package/dist/shared/{attaform.Bq5sX7TF.cjs.map → attaform.CRzpFCjV.cjs.map} +1 -1
  49. package/dist/shared/{attaform.ClXwitZj.cjs → attaform.CjMcwV7W.cjs} +894 -342
  50. package/dist/shared/attaform.CjMcwV7W.cjs.map +1 -0
  51. package/dist/shared/{attaform.DR6RmxWZ.mjs → attaform.CsB-iKbU.mjs} +888 -337
  52. package/dist/shared/attaform.CsB-iKbU.mjs.map +1 -0
  53. package/dist/shared/{attaform.BWfliRIK.d.cts → attaform.D4XYaasQ.d.ts} +63 -64
  54. package/dist/shared/{attaform.Be8NZG9M.mjs → attaform.DCjgGir_.mjs} +19 -45
  55. package/dist/shared/attaform.DCjgGir_.mjs.map +1 -0
  56. package/dist/shared/{attaform.DMEP_ENr.mjs → attaform.DNuiFCXG.mjs} +14 -17
  57. package/dist/shared/attaform.DNuiFCXG.mjs.map +1 -0
  58. package/dist/shared/{attaform.MtrpT6Ki.d.ts → attaform.DUMWQefY.d.ts} +1 -1
  59. package/dist/shared/{attaform.DozgVlCE.mjs → attaform.DgCfLqay.mjs} +116 -47
  60. package/dist/shared/attaform.DgCfLqay.mjs.map +1 -0
  61. package/dist/shared/{attaform.D0dWZsJt.d.mts → attaform.DvUH4a3o.d.cts} +307 -133
  62. package/dist/shared/{attaform.D0dWZsJt.d.cts → attaform.DvUH4a3o.d.mts} +307 -133
  63. package/dist/shared/{attaform.D0dWZsJt.d.ts → attaform.DvUH4a3o.d.ts} +307 -133
  64. package/dist/shared/{attaform.Duecg2NO.d.mts → attaform.FN0vaQAg.d.mts} +1 -1
  65. package/dist/shared/{attaform.CICFZ1iS.cjs → attaform.Q3eAD2wD.cjs} +19 -45
  66. package/dist/shared/attaform.Q3eAD2wD.cjs.map +1 -0
  67. package/dist/shared/{attaform.FudOcHaa.d.cts → attaform.aekT7mMx.d.cts} +1 -1
  68. package/dist/transforms.cjs +1 -1
  69. package/dist/transforms.mjs +1 -1
  70. package/dist/vite.cjs +1 -1
  71. package/dist/vite.mjs +1 -1
  72. package/dist/zod-v3.cjs +3 -4
  73. package/dist/zod-v3.cjs.map +1 -1
  74. package/dist/zod-v3.d.cts +4 -4
  75. package/dist/zod-v3.d.mts +4 -4
  76. package/dist/zod-v3.d.ts +4 -4
  77. package/dist/zod-v3.mjs +2 -3
  78. package/dist/zod-v3.mjs.map +1 -1
  79. package/dist/zod-v4.cjs +3 -4
  80. package/dist/zod-v4.cjs.map +1 -1
  81. package/dist/zod-v4.d.cts +4 -4
  82. package/dist/zod-v4.d.mts +4 -4
  83. package/dist/zod-v4.d.ts +4 -4
  84. package/dist/zod-v4.mjs +2 -3
  85. package/dist/zod-v4.mjs.map +1 -1
  86. package/dist/zod.cjs +6 -6
  87. package/dist/zod.cjs.map +1 -1
  88. package/dist/zod.d.cts +31 -22
  89. package/dist/zod.d.mts +31 -22
  90. package/dist/zod.d.ts +31 -22
  91. package/dist/zod.mjs +5 -6
  92. package/dist/zod.mjs.map +1 -1
  93. package/package.json +4 -12
  94. package/dist/shared/attaform.BM6YD9kZ.cjs.map +0 -1
  95. package/dist/shared/attaform.BSkvn43g.cjs.map +0 -1
  96. package/dist/shared/attaform.Be8NZG9M.mjs.map +0 -1
  97. package/dist/shared/attaform.BupwXkj_.mjs.map +0 -1
  98. package/dist/shared/attaform.CICFZ1iS.cjs.map +0 -1
  99. package/dist/shared/attaform.ClXwitZj.cjs.map +0 -1
  100. package/dist/shared/attaform.D32WwKk6.cjs.map +0 -1
  101. package/dist/shared/attaform.DMEP_ENr.mjs.map +0 -1
  102. package/dist/shared/attaform.DR6RmxWZ.mjs.map +0 -1
  103. package/dist/shared/attaform.DozgVlCE.mjs.map +0 -1
  104. package/dist/shared/attaform.S-pYLSo4.cjs.map +0 -1
  105. package/dist/shared/attaform.pmtahXKy.mjs.map +0 -1
  106. package/dist/shared/{attaform.DSD85fHb.d.cts → attaform.nf83TIR5.d.cts} +10 -10
  107. package/dist/shared/{attaform.DSD85fHb.d.mts → attaform.nf83TIR5.d.mts} +10 -10
  108. package/dist/shared/{attaform.DSD85fHb.d.ts → attaform.nf83TIR5.d.ts} +10 -10
@@ -1,4 +1,4 @@
1
- import { shallowReactive, getCurrentInstance, inject, shallowRef, onBeforeMount, onBeforeUpdate, onMounted, effectScope, watch, warn, nextTick, isRef } from 'vue';
1
+ import { shallowReactive, getCurrentInstance, inject, isRef, effectScope, watch, warn, nextTick } from 'vue';
2
2
 
3
3
  const __DEV__ = (typeof process !== "undefined" ? process.env.NODE_ENV : "production") !== "production";
4
4
 
@@ -280,125 +280,20 @@ function invokeArrayFns(fns, ...args) {
280
280
  }
281
281
  }
282
282
 
283
- function captureUserCallSite() {
284
- const raw = new Error().stack;
285
- if (typeof raw !== "string") return void 0;
286
- const lines = raw.split("\n");
287
- for (let i = 1; i < lines.length; i++) {
288
- const frame = lines[i];
289
- if (frame === void 0) continue;
290
- if (/attaform[/-]forms?/i.test(frame)) continue;
291
- if (/\bforms\.[A-Za-z0-9_-]+\.m?js\b/.test(frame)) continue;
292
- const trimmed = frame.trim();
293
- if (trimmed.length === 0) continue;
294
- return shortenSourceFrame(trimmed);
295
- }
296
- return void 0;
297
- }
298
- function shortenSourceFrame(frame) {
299
- const match = /(?:^|\s|\()([^\s()]+):(\d+):\d+\)?$/.exec(frame);
300
- if (match === null) return frame;
301
- const [, urlOrPath, line] = match;
302
- if (urlOrPath === void 0 || line === void 0) return frame;
303
- let path = urlOrPath;
304
- path = path.replace(/^[a-z]+:\/\/[^/]+\//i, "");
305
- path = path.replace(/^_nuxt\//, "");
306
- path = path.replace(/^\//, "");
307
- return `(${path}:${line})`;
308
- }
309
-
283
+ const V_REGISTER_MARKER = Symbol.for("attaform:v-register-directive");
310
284
  const REGISTER_OWNER_MARKER = Symbol.for("attaform:register-owner-marker");
311
- const warnedNoParentRV = __DEV__ ? /* @__PURE__ */ new WeakSet() : null;
312
- let warnedOutsideSetup = false;
313
- function makeRegisterValueProxy(capturedRegisterValue) {
314
- return new Proxy({}, {
315
- get(_target, prop) {
316
- if (prop === "__v_isRef") return true;
317
- if (prop === "value") return capturedRegisterValue.value;
318
- const v = capturedRegisterValue.value;
319
- if (v === void 0) return void 0;
320
- return Reflect.get(v, prop);
321
- },
322
- has(_target, prop) {
323
- if (prop === "__v_isRef" || prop === "value") return true;
324
- const v = capturedRegisterValue.value;
325
- if (v === void 0) return false;
326
- return Reflect.has(v, prop);
327
- },
328
- ownKeys(_target) {
329
- const v = capturedRegisterValue.value;
330
- if (v === void 0) return [];
331
- return Reflect.ownKeys(v);
332
- },
333
- getOwnPropertyDescriptor(_target, prop) {
334
- const v = capturedRegisterValue.value;
335
- if (v === void 0) return void 0;
336
- const desc = Reflect.getOwnPropertyDescriptor(v, prop);
337
- if (desc !== void 0) {
338
- desc.configurable = true;
339
- }
340
- return desc;
341
- }
342
- });
343
- }
344
- function useRegister() {
345
- const instance = getCurrentInstance();
346
- if (instance === null) {
347
- warnOutsideSetup();
348
- return makeRegisterValueProxy(shallowRef(void 0));
349
- }
350
- ensureAttaformInstalled(instance.appContext.app);
351
- const capturedRegisterValue = shallowRef(void 0);
352
- const refreshAndStripBridgeAttrs = () => {
353
- const rawAttrs = instance.attrs;
354
- if ("registerValue" in rawAttrs) {
355
- capturedRegisterValue.value = rawAttrs["registerValue"];
356
- delete rawAttrs["registerValue"];
357
- } else {
358
- const dirs = instance.vnode.dirs;
359
- if (dirs !== null && dirs !== void 0) {
360
- for (const dir of dirs) {
361
- const marked = dir.dir?.[V_REGISTER_MARKER];
362
- if (marked === true) {
363
- capturedRegisterValue.value = dir.value;
364
- break;
365
- }
366
- }
367
- }
368
- }
369
- if ("value" in rawAttrs) delete rawAttrs["value"];
370
- };
371
- refreshAndStripBridgeAttrs();
372
- onBeforeMount(refreshAndStripBridgeAttrs);
373
- onBeforeUpdate(refreshAndStripBridgeAttrs);
374
- onMounted(() => {
375
- const el = instance.vnode.el;
376
- if (el !== null && el !== void 0 && typeof el === "object") {
377
- el[REGISTER_OWNER_MARKER] = true;
378
- }
379
- if (capturedRegisterValue.value === void 0) {
380
- warnNoParentRV(instance);
381
- }
382
- });
383
- return makeRegisterValueProxy(capturedRegisterValue);
384
- }
385
- function warnOutsideSetup() {
386
- if (!__DEV__) return;
387
- if (warnedOutsideSetup) return;
388
- warnedOutsideSetup = true;
389
- const frame = captureUserCallSite();
390
- console.warn(
391
- `[attaform] useRegister() called outside a component setup; returning an unbound RegisterValue proxy. Fix: call it inside <script setup> or a setup() function \u2014 not from an event handler or async callback.` + (frame !== void 0 ? ` ${frame}` : "")
392
- );
285
+ function isRegisterValue(val) {
286
+ if (typeof val !== "object" || val === null) return false;
287
+ if (!("innerRef" in val)) return false;
288
+ if (!isRef(val.innerRef)) return false;
289
+ if (!("registerElement" in val)) return false;
290
+ if (typeof val.registerElement !== "function") return false;
291
+ if (!("setValueWithInternalPath" in val)) return false;
292
+ if (typeof val.setValueWithInternalPath !== "function") return false;
293
+ return true;
393
294
  }
394
- function warnNoParentRV(instance) {
395
- if (!__DEV__ || warnedNoParentRV === null) return;
396
- if (warnedNoParentRV.has(instance)) return;
397
- warnedNoParentRV.add(instance);
398
- const frame = captureUserCallSite();
399
- console.warn(
400
- `[attaform] useRegister: no parent registerValue prop; RegisterValue fields will read as undefined. Pass v-register on the parent: \`<YourComponent v-register="form.register('field')" />\`.` + (frame !== void 0 ? ` ${frame}` : "")
401
- );
295
+ function isTransforming(value) {
296
+ return isRegisterValue(value) && value.transforming;
402
297
  }
403
298
 
404
299
  const MANAGED_ARIA_ATTRS = [
@@ -509,6 +404,199 @@ function isRegisterValueLike(val) {
509
404
  return typeof val === "object" && val !== null && "markInteracted" in val && typeof val.markInteracted === "function";
510
405
  }
511
406
 
407
+ const assignKey = Symbol.for("attaform:assign-key");
408
+ const DEFAULT_ASSIGNER_TAG = Symbol.for("attaform:default-assigner-tag");
409
+ function isDefaultAssigner(fn) {
410
+ return typeof fn === "function" && fn[DEFAULT_ASSIGNER_TAG] === true;
411
+ }
412
+ const CONSUMER_WRAPPED_TAG = Symbol.for("attaform:consumer-wrapped-assigner");
413
+ function isConsumerWrapped(fn) {
414
+ return typeof fn === "function" && fn[CONSUMER_WRAPPED_TAG] === true;
415
+ }
416
+ function fireAssigner(el, registerValue, value) {
417
+ const fn = el[assignKey];
418
+ if (fn === void 0) return void 0;
419
+ if (isDefaultAssigner(fn) || isConsumerWrapped(fn)) {
420
+ return fn(value);
421
+ }
422
+ if (!isRegisterValue(registerValue)) {
423
+ return fn(value, void 0);
424
+ }
425
+ return wrapWithTransforms(
426
+ value,
427
+ registerValue,
428
+ (coerced) => fn(coerced, registerValue),
429
+ void 0
430
+ );
431
+ }
432
+ function isThenable(x) {
433
+ return x !== null && (typeof x === "object" || typeof x === "function") && typeof x.then === "function";
434
+ }
435
+ function makeTransformContext() {
436
+ const holder = { controller: null, aborted: false };
437
+ const ctx = {
438
+ get signal() {
439
+ if (holder.controller === null) {
440
+ holder.controller = new AbortController();
441
+ if (holder.aborted) holder.controller.abort();
442
+ }
443
+ return holder.controller.signal;
444
+ }
445
+ };
446
+ return { ctx, holder };
447
+ }
448
+ function runTransforms(initial, registerValue) {
449
+ const transforms = registerValue.transforms;
450
+ if (transforms === void 0 || transforms.length === 0) {
451
+ return { kind: "sync", ok: true, value: initial };
452
+ }
453
+ const { ctx, holder } = makeTransformContext();
454
+ let v = initial;
455
+ for (let i = 0; i < transforms.length; i++) {
456
+ const fn = transforms[i];
457
+ let out;
458
+ try {
459
+ out = fn(v, ctx);
460
+ } catch (err) {
461
+ logTransformFailure(registerValue.path, i, fn, err);
462
+ return { kind: "sync", ok: false };
463
+ }
464
+ if (isThenable(out)) {
465
+ const rest = transforms.slice(i + 1);
466
+ const seed = out;
467
+ const run = () => rest.reduce(
468
+ (acc, next) => acc.then((value) => next(value, ctx)),
469
+ Promise.resolve(seed)
470
+ );
471
+ return { kind: "async", run, holder };
472
+ }
473
+ v = out;
474
+ }
475
+ return { kind: "sync", ok: true, value: v };
476
+ }
477
+ function kickoffAsyncTransform(rv, holder, run, commit, syncDom) {
478
+ const token = rv.beginTransform(holder);
479
+ void run().then(
480
+ (value) => {
481
+ const live = rv.isCurrentTransform(token);
482
+ rv.endTransform(token);
483
+ if (!live) return;
484
+ const coerced = applyCoerce(value, rv);
485
+ const wrote = commit(coerced);
486
+ if (wrote === false) rv.setTransformError(transformGateRejectedError(rv.path));
487
+ else syncDom?.();
488
+ },
489
+ (err) => {
490
+ if (rv.isCurrentTransform(token)) rv.setTransformError(toTransformError(err));
491
+ rv.endTransform(token);
492
+ }
493
+ );
494
+ }
495
+ function logTransformFailure(path, index, fn, err) {
496
+ if (__DEV__) {
497
+ const namePart = fn.name !== "" ? `, '${fn.name}'` : "";
498
+ console.error(
499
+ `[attaform] transform threw for path '${path}' (index ${index}${namePart}) \u2014 write aborted. Transforms must not throw; wrap your own try/catch if the throw is recoverable. Original error:`,
500
+ err
501
+ );
502
+ } else {
503
+ console.error(
504
+ `[attaform] transform error \u2014 write aborted (set NODE_ENV=development for details).`
505
+ );
506
+ }
507
+ }
508
+ function applyCoerce(value, registerValue) {
509
+ return registerValue.coerce !== void 0 ? registerValue.coerce(value) : value;
510
+ }
511
+ function wrapWithTransforms(value, registerValue, commit, syncDom) {
512
+ const r = runTransforms(value, registerValue);
513
+ if (r.kind === "async") {
514
+ kickoffAsyncTransform(registerValue, r.holder, r.run, commit, syncDom);
515
+ return true;
516
+ }
517
+ if (!r.ok) return false;
518
+ const coerced = applyCoerce(r.value, registerValue);
519
+ return commit(coerced);
520
+ }
521
+ function toTransformError(value) {
522
+ if (value instanceof Error) return value;
523
+ const message = typeof value === "string" && value.length > 0 ? value : `Transform rejected with a non-Error value (${typeof value})`;
524
+ return new Error(message, { cause: value });
525
+ }
526
+ function transformGateRejectedError(path) {
527
+ return new Error(
528
+ `[attaform] transform result for path '${path}' was rejected by the field's type gate (the resolved value did not fit the schema slot).`
529
+ );
530
+ }
531
+ const getModelAssigner = (el, vnode, registerValue) => {
532
+ const fn = vnode.props?.["onUpdate:registerValue"] ?? vnode.props?.["on:update:registerValue"];
533
+ if (isArray(fn)) {
534
+ const fnArr = fn.filter((x) => isFunction(x));
535
+ const wrapped = (value) => {
536
+ return wrapWithTransforms(
537
+ value,
538
+ registerValue,
539
+ (coerced) => {
540
+ invokeArrayFns(fnArr, coerced, registerValue);
541
+ return void 0;
542
+ },
543
+ void 0
544
+ );
545
+ };
546
+ wrapped[CONSUMER_WRAPPED_TAG] = true;
547
+ return wrapped;
548
+ }
549
+ if (isFunction(fn)) {
550
+ const handler = fn;
551
+ const wrapped = (value) => {
552
+ return wrapWithTransforms(
553
+ value,
554
+ registerValue,
555
+ (coerced) => handler(coerced, registerValue),
556
+ void 0
557
+ );
558
+ };
559
+ wrapped[CONSUMER_WRAPPED_TAG] = true;
560
+ return wrapped;
561
+ }
562
+ const defaultAssigner = (value) => {
563
+ if (value === void 0 && registerValue.acceptsUndefined) {
564
+ return registerValue.setValueWithInternalPath(void 0);
565
+ }
566
+ return wrapWithTransforms(
567
+ value,
568
+ registerValue,
569
+ (coerced) => registerValue.setValueWithInternalPath(coerced),
570
+ el._syncFromStorage
571
+ );
572
+ };
573
+ defaultAssigner[DEFAULT_ASSIGNER_TAG] = true;
574
+ return defaultAssigner;
575
+ };
576
+ function makeNoopAssigner() {
577
+ const noop = (_) => void 0;
578
+ noop[DEFAULT_ASSIGNER_TAG] = true;
579
+ return noop;
580
+ }
581
+ function setAssignFunction(el, vnode, value) {
582
+ const current = el[assignKey];
583
+ if (current !== void 0 && !isDefaultAssigner(current) && !isConsumerWrapped(current)) {
584
+ return;
585
+ }
586
+ if (value === void 0) {
587
+ el[assignKey] = makeNoopAssigner();
588
+ return;
589
+ }
590
+ if (!isRegisterValue(value)) {
591
+ warn(
592
+ `v-register expected a RegisterValue, got '${typeof value}'. Bind to form.register('field') \u2014 not the field's ref, value, or path string.`
593
+ );
594
+ el[assignKey] = makeNoopAssigner();
595
+ return;
596
+ }
597
+ el[assignKey] = getModelAssigner(el, vnode, value);
598
+ }
599
+
512
600
  function isBlankFileValue(value) {
513
601
  if (value === null || value === void 0) return true;
514
602
  if (Array.isArray(value) && value.length === 0) return true;
@@ -885,220 +973,16 @@ function teardownValueSync(el) {
885
973
 
886
974
  const INTERACTIVE_TAG_NAMES = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
887
975
 
888
- const assignKey = Symbol.for("attaform:assign-key");
889
- function isRegisterValue(val) {
890
- if (typeof val !== "object" || val === null) return false;
891
- if (!("innerRef" in val)) return false;
892
- if (!isRef(val.innerRef)) return false;
893
- if (!("registerElement" in val)) return false;
894
- if (typeof val.registerElement !== "function") return false;
895
- if (!("setValueWithInternalPath" in val)) return false;
896
- if (typeof val.setValueWithInternalPath !== "function") return false;
897
- return true;
898
- }
899
976
  function writeLastTypedForm(rv, next) {
900
977
  rv.lastTypedForm.value = next;
901
978
  }
902
- const DEFAULT_ASSIGNER_TAG = Symbol.for("attaform:default-assigner-tag");
903
- function isDefaultAssigner(fn) {
904
- return typeof fn === "function" && fn[DEFAULT_ASSIGNER_TAG] === true;
905
- }
906
- const CONSUMER_WRAPPED_TAG = Symbol.for("attaform:consumer-wrapped-assigner");
907
- function isConsumerWrapped(fn) {
908
- return typeof fn === "function" && fn[CONSUMER_WRAPPED_TAG] === true;
909
- }
910
- function fireAssigner(el, registerValue, value) {
911
- const fn = el[assignKey];
912
- if (fn === void 0) return void 0;
913
- if (isDefaultAssigner(fn) || isConsumerWrapped(fn)) {
914
- return fn(value);
915
- }
916
- if (!isRegisterValue(registerValue)) {
917
- return fn(value, void 0);
918
- }
919
- const r = runTransforms(value, registerValue);
920
- if (r.kind === "async") {
921
- kickoffAsyncTransform(
922
- registerValue,
923
- r.holder,
924
- r.run,
925
- (coerced2) => fn(coerced2, registerValue),
926
- void 0
927
- );
928
- return true;
929
- }
930
- if (!r.ok) return false;
931
- const coerced = applyCoerce(r.value, registerValue);
932
- return fn(coerced, registerValue);
933
- }
934
979
  function shouldBailListener(el) {
935
980
  if (INTERACTIVE_TAG_NAMES.has(el.tagName)) return false;
936
981
  return isDefaultAssigner(el[assignKey]);
937
982
  }
938
- function isThenable(x) {
939
- return x !== null && (typeof x === "object" || typeof x === "function") && typeof x.then === "function";
940
- }
941
- function makeTransformContext() {
942
- const holder = { controller: null, aborted: false };
943
- const ctx = {
944
- get signal() {
945
- if (holder.controller === null) {
946
- holder.controller = new AbortController();
947
- if (holder.aborted) holder.controller.abort();
948
- }
949
- return holder.controller.signal;
950
- }
951
- };
952
- return { ctx, holder };
953
- }
954
- function runTransforms(initial, registerValue) {
955
- const transforms = registerValue.transforms;
956
- if (transforms === void 0 || transforms.length === 0) {
957
- return { kind: "sync", ok: true, value: initial };
958
- }
959
- const { ctx, holder } = makeTransformContext();
960
- let v = initial;
961
- for (let i = 0; i < transforms.length; i++) {
962
- const fn = transforms[i];
963
- let out;
964
- try {
965
- out = fn(v, ctx);
966
- } catch (err) {
967
- logTransformFailure(registerValue.path, i, fn, err);
968
- return { kind: "sync", ok: false };
969
- }
970
- if (isThenable(out)) {
971
- const rest = transforms.slice(i + 1);
972
- const seed = out;
973
- const run = () => rest.reduce(
974
- (acc, next) => acc.then((value) => next(value, ctx)),
975
- Promise.resolve(seed)
976
- );
977
- return { kind: "async", run, holder };
978
- }
979
- v = out;
980
- }
981
- return { kind: "sync", ok: true, value: v };
982
- }
983
- function kickoffAsyncTransform(rv, holder, run, commit, syncDom) {
984
- const token = rv.beginTransform(holder);
985
- void run().then(
986
- (value) => {
987
- const live = rv.isCurrentTransform(token);
988
- rv.endTransform(token);
989
- if (!live) return;
990
- const coerced = applyCoerce(value, rv);
991
- const wrote = commit(coerced);
992
- if (wrote === false) rv.setTransformError(transformGateRejectedError(rv.path));
993
- else syncDom?.();
994
- },
995
- (err) => {
996
- if (rv.isCurrentTransform(token)) rv.setTransformError(toTransformError(err));
997
- rv.endTransform(token);
998
- }
999
- );
1000
- }
1001
- function logTransformFailure(path, index, fn, err) {
1002
- if (__DEV__) {
1003
- const namePart = fn.name !== "" ? `, '${fn.name}'` : "";
1004
- console.error(
1005
- `[attaform] transform threw for path '${path}' (index ${index}${namePart}) \u2014 write aborted. Transforms must not throw; wrap your own try/catch if the throw is recoverable. Original error:`,
1006
- err
1007
- );
1008
- } else {
1009
- console.error(
1010
- `[attaform] transform error \u2014 write aborted (set NODE_ENV=development for details).`
1011
- );
1012
- }
1013
- }
1014
- function applyCoerce(value, registerValue) {
1015
- return registerValue.coerce !== void 0 ? registerValue.coerce(value) : value;
1016
- }
1017
983
  function applyElementCoerce(value, registerValue) {
1018
984
  return registerValue.coerceElement !== void 0 ? registerValue.coerceElement(value) : value;
1019
985
  }
1020
- function toTransformError(value) {
1021
- if (value instanceof Error) return value;
1022
- const message = typeof value === "string" && value.length > 0 ? value : `Transform rejected with a non-Error value (${typeof value})`;
1023
- return new Error(message, { cause: value });
1024
- }
1025
- function transformGateRejectedError(path) {
1026
- return new Error(
1027
- `[attaform] transform result for path '${path}' was rejected by the field's type gate (the resolved value did not fit the schema slot).`
1028
- );
1029
- }
1030
- function isTransforming(value) {
1031
- return isRegisterValue(value) && value.transforming;
1032
- }
1033
- const getModelAssigner = (el, vnode, registerValue) => {
1034
- const fn = vnode.props?.["onUpdate:registerValue"] ?? vnode.props?.["on:update:registerValue"];
1035
- if (isArray(fn)) {
1036
- const fnArr = fn.filter((x) => isFunction(x));
1037
- const wrapped = (value) => {
1038
- const r = runTransforms(value, registerValue);
1039
- if (r.kind === "async") {
1040
- kickoffAsyncTransform(
1041
- registerValue,
1042
- r.holder,
1043
- r.run,
1044
- (coerced2) => {
1045
- invokeArrayFns(fnArr, coerced2, registerValue);
1046
- },
1047
- void 0
1048
- );
1049
- return true;
1050
- }
1051
- if (!r.ok) return false;
1052
- const coerced = applyCoerce(r.value, registerValue);
1053
- invokeArrayFns(fnArr, coerced, registerValue);
1054
- return void 0;
1055
- };
1056
- wrapped[CONSUMER_WRAPPED_TAG] = true;
1057
- return wrapped;
1058
- }
1059
- if (isFunction(fn)) {
1060
- const handler = fn;
1061
- const wrapped = (value) => {
1062
- const r = runTransforms(value, registerValue);
1063
- if (r.kind === "async") {
1064
- kickoffAsyncTransform(
1065
- registerValue,
1066
- r.holder,
1067
- r.run,
1068
- (coerced2) => handler(coerced2, registerValue),
1069
- void 0
1070
- );
1071
- return true;
1072
- }
1073
- if (!r.ok) return false;
1074
- const coerced = applyCoerce(r.value, registerValue);
1075
- return handler(coerced, registerValue);
1076
- };
1077
- wrapped[CONSUMER_WRAPPED_TAG] = true;
1078
- return wrapped;
1079
- }
1080
- const defaultAssigner = (value) => {
1081
- if (value === void 0 && registerValue.acceptsUndefined) {
1082
- return registerValue.setValueWithInternalPath(void 0);
1083
- }
1084
- const r = runTransforms(value, registerValue);
1085
- if (r.kind === "async") {
1086
- kickoffAsyncTransform(
1087
- registerValue,
1088
- r.holder,
1089
- r.run,
1090
- (coerced2) => registerValue.setValueWithInternalPath(coerced2),
1091
- el._syncFromStorage
1092
- );
1093
- return true;
1094
- }
1095
- if (!r.ok) return false;
1096
- const coerced = applyCoerce(r.value, registerValue);
1097
- return registerValue.setValueWithInternalPath(coerced);
1098
- };
1099
- defaultAssigner[DEFAULT_ASSIGNER_TAG] = true;
1100
- return defaultAssigner;
1101
- };
1102
986
  function onCompositionStart(e) {
1103
987
  const target = e.target;
1104
988
  if (!target) return;
@@ -1111,29 +995,6 @@ function onCompositionEnd(e) {
1111
995
  target.dispatchEvent(new Event("input"));
1112
996
  }
1113
997
  }
1114
- function makeNoopAssigner() {
1115
- const noop = (_) => void 0;
1116
- noop[DEFAULT_ASSIGNER_TAG] = true;
1117
- return noop;
1118
- }
1119
- function setAssignFunction(el, vnode, value) {
1120
- const current = el[assignKey];
1121
- if (current !== void 0 && !isDefaultAssigner(current) && !isConsumerWrapped(current)) {
1122
- return;
1123
- }
1124
- if (value === void 0) {
1125
- el[assignKey] = makeNoopAssigner();
1126
- return;
1127
- }
1128
- if (!isRegisterValue(value)) {
1129
- warn(
1130
- `v-register expected a RegisterValue, got '${typeof value}'. Bind to form.register('field') \u2014 not the field's ref, value, or path string.`
1131
- );
1132
- el[assignKey] = makeNoopAssigner();
1133
- return;
1134
- }
1135
- el[assignKey] = getModelAssigner(el, vnode, value);
1136
- }
1137
998
  const vRegisterText = {
1138
999
  created(el, { value, modifiers: { lazy, trim, number } }, vnode) {
1139
1000
  const castToNumberAtCreated = number === true || vnode.props?.["type"] === "number";
@@ -1596,6 +1457,9 @@ const vRegisterDynamic = {
1596
1457
  syncMultiTabOptOut(binding.value, void 0);
1597
1458
  callModelHook(el, binding, vnode, null, "created");
1598
1459
  if (isRegisterValue(binding.value)) setupAria(el, binding.value, vnode);
1460
+ },
1461
+ mounted(el, binding, vnode) {
1462
+ callModelHook(el, binding, vnode, null, "mounted");
1599
1463
  if (__DEV__ && warnedUnsupportedElements !== null && !INTERACTIVE_TAG_NAMES.has(el.tagName) && !warnedUnsupportedElements.has(el)) {
1600
1464
  void nextTick(() => {
1601
1465
  if (warnedUnsupportedElements.has(el)) return;
@@ -1611,9 +1475,6 @@ const vRegisterDynamic = {
1611
1475
  });
1612
1476
  }
1613
1477
  },
1614
- mounted(el, binding, vnode) {
1615
- callModelHook(el, binding, vnode, null, "mounted");
1616
- },
1617
1478
  beforeUpdate(el, binding, vnode, prevVNode) {
1618
1479
  syncPersistOptIn(el, binding.value, binding.oldValue, vnode.props?.["type"]);
1619
1480
  syncMultiTabOptOut(binding.value, binding.oldValue);
@@ -1663,7 +1524,11 @@ const vRegisterDynamic = {
1663
1524
  getSSRProps(binding, vnode) {
1664
1525
  const rv = binding.value;
1665
1526
  if (!isRegisterValue(rv)) return void 0;
1666
- return getSSRAriaProps(rv, vnode ?? null);
1527
+ const realVnode = vnode ?? null;
1528
+ const ariaProps = getSSRAriaProps(rv, realVnode);
1529
+ const formStateProps = realVnode !== null ? getSSRFormStateProps(rv, realVnode) : void 0;
1530
+ if (ariaProps === void 0 && formStateProps === void 0) return void 0;
1531
+ return { ...ariaProps, ...formStateProps };
1667
1532
  }
1668
1533
  };
1669
1534
  function resolveDynamicModel(tagName, type) {
@@ -1675,12 +1540,38 @@ function resolveDynamicModel(tagName, type) {
1675
1540
  if (type === "radio") return vRegisterRadio;
1676
1541
  return vRegisterText;
1677
1542
  }
1543
+ function ssrCheckboxProps(rv, props) {
1544
+ const model = rv.innerRef.value;
1545
+ const optionValue = props?.["value"];
1546
+ let checked;
1547
+ if (isArray(model)) {
1548
+ checked = looseIndexOf(model, applyElementCoerce(optionValue, rv)) > -1;
1549
+ } else if (isSet(model)) {
1550
+ checked = model.has(applyElementCoerce(optionValue, rv));
1551
+ } else {
1552
+ const trueValue = props !== null && "true-value" in props ? props["true-value"] : true;
1553
+ checked = looseEqual(model, applyCoerce(trueValue, rv));
1554
+ }
1555
+ return checked ? { checked: "" } : void 0;
1556
+ }
1557
+ function getSSRFormStateProps(rv, vnode) {
1558
+ if (typeof vnode.type !== "string") return void 0;
1559
+ const props = vnode.props ?? null;
1560
+ const variant = resolveDynamicModel(vnode.type.toUpperCase(), props?.["type"]);
1561
+ if (variant === vRegisterFile || variant === vRegisterSelect) return void 0;
1562
+ if (variant === vRegisterCheckbox) return ssrCheckboxProps(rv, props);
1563
+ if (variant === vRegisterRadio) {
1564
+ const matches = looseEqual(rv.innerRef.value, applyCoerce(props?.["value"], rv));
1565
+ return matches ? { checked: "" } : void 0;
1566
+ }
1567
+ const value = rv.displayValue.value;
1568
+ return value === "" ? void 0 : { value };
1569
+ }
1678
1570
  function callModelHook(el, binding, vnode, prevVNode, hook) {
1679
1571
  const modelToUse = resolveDynamicModel(el.tagName, vnode.props?.["type"]);
1680
1572
  const fn = modelToUse[hook];
1681
1573
  fn?.(el, binding, vnode, prevVNode);
1682
1574
  }
1683
- const V_REGISTER_MARKER = Symbol.for("attaform:v-register-directive");
1684
1575
  const vRegister = vRegisterDynamic;
1685
1576
  vRegisterDynamic[V_REGISTER_MARKER] = true;
1686
1577
 
@@ -1779,17 +1670,20 @@ function canonicalizePath(input) {
1779
1670
  if (typeof input === "string") {
1780
1671
  const cached = canonicalStringCache.get(input);
1781
1672
  if (cached !== void 0) return cached;
1782
- const segments2 = parseDottedPath(input);
1783
- const key2 = JSON.stringify(segments2);
1784
- const entry = { segments: segments2, key: key2 };
1673
+ const segments = parseDottedPath(input);
1674
+ const key = JSON.stringify(segments);
1675
+ const entry = { segments, key };
1785
1676
  if (canonicalStringCache.size >= CANONICAL_STRING_CACHE_MAX) {
1786
1677
  const oldest = canonicalStringCache.keys().next().value;
1787
1678
  if (oldest !== void 0) canonicalStringCache.delete(oldest);
1788
1679
  }
1789
1680
  canonicalStringCache.set(input, entry);
1790
- rememberSegmentsForPathKey(key2, segments2);
1681
+ rememberSegmentsForPathKey(key, segments);
1791
1682
  return entry;
1792
1683
  }
1684
+ return keyForSegments(input);
1685
+ }
1686
+ function keyForSegments(input) {
1793
1687
  const segments = Array.from(input).map(normalizeSegment);
1794
1688
  const key = JSON.stringify(segments);
1795
1689
  rememberSegmentsForPathKey(key, segments);
@@ -1826,6 +1720,13 @@ function isPathPrefix(prefix, path) {
1826
1720
  }
1827
1721
  return true;
1828
1722
  }
1723
+ function pathsEqual(a, b) {
1724
+ if (a.length !== b.length) return false;
1725
+ for (let i = 0; i < a.length; i++) {
1726
+ if (a[i] !== b[i]) return false;
1727
+ }
1728
+ return true;
1729
+ }
1829
1730
 
1830
- 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, toError as H, INTERACTIVE_TAG_NAMES as I, useRegister as J, useRegistry as K, vRegister as L, 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 };
1831
- //# sourceMappingURL=attaform.pmtahXKy.mjs.map
1731
+ export { AnonPersistError as A, segmentsToDotted as B, coerceToPathKey as C, DEFAULT_SENSITIVE_NAMES as D, isSensitivePath as E, FORM_ERRORS_PATH_KEY as F, createPersistOptInRegistry as G, ensureAttaformInstalled as H, InvalidPathError as I, kFormContext as J, kFormInstanceId as K, createIsSensitivePath as L, REGISTER_OWNER_MARKER as M, kAttaformAncestorWizard as N, OutsideSetupError as O, ROOT_PATH as R, SubmitErrorHandlerError as S, V_REGISTER_MARKER as V, __DEV__ as _, canonicalizePath as a, AttaformError as b, createAttaform as c, InvalidUseFormConfigError as d, ROOT_PATH_KEY as e, RegistryNotInstalledError as f, getRegistryFromApp as g, ReservedFormKeyError as h, assignKey as i, createRegistry as j, kAttaformWizardActiveStepResolver as k, isPathPrefix as l, isRegisterValue as m, kAttaformRegistry as n, pathKeyToDotted as o, parseDottedPath as p, pathsEqual as q, keyForSegments as r, segmentsForPathKey as s, toError as t, useRegistry as u, vRegister as v, INTERACTIVE_TAG_NAMES as w, getOrAssignElementId as x, allowSensitivePersist as y, FORM_ERRORS_PATH as z };
1732
+ //# sourceMappingURL=attaform.BKFwekY2.mjs.map