attaform 0.21.0 → 0.21.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.
- package/dist/chunks/dev-key-collision-warnings.cjs +1 -1
- package/dist/chunks/dev-key-collision-warnings.mjs +1 -1
- package/dist/chunks/devtools.cjs +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/fingerprint2.cjs +1 -1
- package/dist/chunks/fingerprint2.mjs +1 -1
- package/dist/chunks/indexeddb.cjs +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/multi-tab-sync.cjs +2 -2
- package/dist/chunks/multi-tab-sync.mjs +2 -2
- package/dist/chunks/session-storage.cjs +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/chunks/wire-persistence.cjs +2 -2
- package/dist/chunks/wire-persistence.mjs +2 -2
- package/dist/index.cjs +37 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +31 -28
- package/dist/index.d.mts +31 -28
- package/dist/index.d.ts +31 -28
- package/dist/index.mjs +38 -25
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +396 -216
- package/dist/runtime/components/DevtoolsValueTree.vue +176 -114
- package/dist/runtime/plugins/attaform.cjs +2 -2
- package/dist/runtime/plugins/attaform.mjs +2 -2
- package/dist/shared/{attaform.BA3vRDos.cjs → attaform.B5LNzqQh.cjs} +349 -277
- package/dist/shared/attaform.B5LNzqQh.cjs.map +1 -0
- package/dist/shared/{attaform.PnqML3xW.cjs → attaform.BBDIKtKY.cjs} +13 -16
- package/dist/shared/attaform.BBDIKtKY.cjs.map +1 -0
- package/dist/shared/{attaform.CRsXyy-Y.d.ts → attaform.BCcrLApm.d.mts} +131 -64
- package/dist/shared/{attaform.BupwXkj_.mjs → attaform.BFWb6hDk.mjs} +29 -23
- package/dist/shared/attaform.BFWb6hDk.mjs.map +1 -0
- package/dist/shared/{attaform.7lzO9pdM.d.mts → attaform.BGf_J22U.d.ts} +131 -64
- package/dist/shared/{attaform.BnK_bfcb.mjs → attaform.BVeLgfEh.mjs} +14 -17
- package/dist/shared/attaform.BVeLgfEh.mjs.map +1 -0
- package/dist/shared/{attaform.BK1RE2ha.d.ts → attaform.BYgioWLF.d.ts} +2 -2
- package/dist/shared/{attaform.F8LMHHWV.d.cts → attaform.BkjJfMvJ.d.cts} +131 -64
- package/dist/shared/{attaform.BDIEq9qP.d.cts → attaform.BoY6RZUl.d.cts} +2 -2
- package/dist/shared/{attaform.CEf6wYfD.cjs → attaform.BwLp9KM7.cjs} +2 -2
- package/dist/shared/{attaform.CEf6wYfD.cjs.map → attaform.BwLp9KM7.cjs.map} +1 -1
- package/dist/shared/{attaform._rsCZy2j.cjs → attaform.BwrowMp2.cjs} +25 -45
- package/dist/shared/attaform.BwrowMp2.cjs.map +1 -0
- package/dist/shared/{attaform.ezb5Nh2t.mjs → attaform.C41gjp-a.mjs} +2 -2
- package/dist/shared/{attaform.ezb5Nh2t.mjs.map → attaform.C41gjp-a.mjs.map} +1 -1
- package/dist/shared/{attaform.BM6YD9kZ.cjs → attaform.CR6wGvNu.cjs} +29 -23
- package/dist/shared/attaform.CR6wGvNu.cjs.map +1 -0
- package/dist/shared/{attaform.DSqO6Db7.mjs → attaform.CTheKoTc.mjs} +705 -282
- package/dist/shared/attaform.CTheKoTc.mjs.map +1 -0
- package/dist/shared/{attaform.BzvOdiSI.cjs → attaform.CcnF1AKJ.cjs} +4 -4
- package/dist/shared/attaform.CcnF1AKJ.cjs.map +1 -0
- package/dist/shared/{attaform.BQ6drorq.d.mts → attaform.CnEl--PF.d.mts} +2 -2
- package/dist/shared/{attaform.CkjTapyq.mjs → attaform.CrD73S4m.mjs} +4 -4
- package/dist/shared/attaform.CrD73S4m.mjs.map +1 -0
- package/dist/shared/{attaform.BUszFoKq.cjs → attaform.D2ZuIOCf.cjs} +711 -287
- package/dist/shared/attaform.D2ZuIOCf.cjs.map +1 -0
- package/dist/shared/{attaform.r3PePkDR.mjs → attaform.D6GYGshL.mjs} +25 -45
- package/dist/shared/attaform.D6GYGshL.mjs.map +1 -0
- package/dist/shared/{attaform.Y_Mgg0Yp.mjs → attaform.DP-u7_tk.mjs} +348 -277
- package/dist/shared/attaform.DP-u7_tk.mjs.map +1 -0
- package/dist/shared/{attaform.B1nyO4ec.d.cts → attaform.ory-3WhV.d.cts} +395 -176
- package/dist/shared/{attaform.B1nyO4ec.d.mts → attaform.ory-3WhV.d.mts} +395 -176
- package/dist/shared/{attaform.B1nyO4ec.d.ts → attaform.ory-3WhV.d.ts} +395 -176
- package/dist/transforms.cjs +1 -1
- package/dist/transforms.mjs +1 -1
- package/dist/vite.cjs +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/zod-v3.cjs +3 -4
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +4 -4
- package/dist/zod-v3.d.mts +4 -4
- package/dist/zod-v3.d.ts +4 -4
- package/dist/zod-v3.mjs +2 -3
- package/dist/zod-v3.mjs.map +1 -1
- package/dist/zod-v4.cjs +3 -4
- package/dist/zod-v4.cjs.map +1 -1
- package/dist/zod-v4.d.cts +4 -4
- package/dist/zod-v4.d.mts +4 -4
- package/dist/zod-v4.d.ts +4 -4
- package/dist/zod-v4.mjs +2 -3
- package/dist/zod-v4.mjs.map +1 -1
- package/dist/zod.cjs +6 -6
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +77 -26
- package/dist/zod.d.mts +77 -26
- package/dist/zod.d.ts +77 -26
- package/dist/zod.mjs +5 -6
- package/dist/zod.mjs.map +1 -1
- package/package.json +3 -11
- package/dist/shared/attaform.BA3vRDos.cjs.map +0 -1
- package/dist/shared/attaform.BM6YD9kZ.cjs.map +0 -1
- package/dist/shared/attaform.BUszFoKq.cjs.map +0 -1
- package/dist/shared/attaform.BnK_bfcb.mjs.map +0 -1
- package/dist/shared/attaform.BupwXkj_.mjs.map +0 -1
- package/dist/shared/attaform.BzvOdiSI.cjs.map +0 -1
- package/dist/shared/attaform.CkjTapyq.mjs.map +0 -1
- package/dist/shared/attaform.DSqO6Db7.mjs.map +0 -1
- package/dist/shared/attaform.PnqML3xW.cjs.map +0 -1
- package/dist/shared/attaform.Y_Mgg0Yp.mjs.map +0 -1
- package/dist/shared/attaform._rsCZy2j.cjs.map +0 -1
- package/dist/shared/attaform.r3PePkDR.mjs.map +0 -1
- package/dist/shared/{attaform.DSD85fHb.d.cts → attaform.nf83TIR5.d.cts} +10 -10
- package/dist/shared/{attaform.DSD85fHb.d.mts → attaform.nf83TIR5.d.mts} +10 -10
- package/dist/shared/{attaform.DSD85fHb.d.ts → attaform.nf83TIR5.d.ts} +10 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { shallowReactive, getCurrentInstance, inject,
|
|
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
|
|
|
@@ -22,6 +22,11 @@ class InvalidUseFormConfigError extends AttaformError {
|
|
|
22
22
|
}
|
|
23
23
|
class SubmitErrorHandlerError extends AttaformError {
|
|
24
24
|
}
|
|
25
|
+
function toError(value) {
|
|
26
|
+
if (value instanceof Error) return value;
|
|
27
|
+
const message = typeof value === "string" && value.length > 0 ? value : `Submit callback threw a non-Error value (${typeof value})`;
|
|
28
|
+
return new Error(message, { cause: value });
|
|
29
|
+
}
|
|
25
30
|
class RegistryNotInstalledError extends AttaformError {
|
|
26
31
|
constructor() {
|
|
27
32
|
super(
|
|
@@ -275,125 +280,20 @@ function invokeArrayFns(fns, ...args) {
|
|
|
275
280
|
}
|
|
276
281
|
}
|
|
277
282
|
|
|
278
|
-
|
|
279
|
-
const raw = new Error().stack;
|
|
280
|
-
if (typeof raw !== "string") return void 0;
|
|
281
|
-
const lines = raw.split("\n");
|
|
282
|
-
for (let i = 1; i < lines.length; i++) {
|
|
283
|
-
const frame = lines[i];
|
|
284
|
-
if (frame === void 0) continue;
|
|
285
|
-
if (/attaform[/-]forms?/i.test(frame)) continue;
|
|
286
|
-
if (/\bforms\.[A-Za-z0-9_-]+\.m?js\b/.test(frame)) continue;
|
|
287
|
-
const trimmed = frame.trim();
|
|
288
|
-
if (trimmed.length === 0) continue;
|
|
289
|
-
return shortenSourceFrame(trimmed);
|
|
290
|
-
}
|
|
291
|
-
return void 0;
|
|
292
|
-
}
|
|
293
|
-
function shortenSourceFrame(frame) {
|
|
294
|
-
const match = /(?:^|\s|\()([^\s()]+):(\d+):\d+\)?$/.exec(frame);
|
|
295
|
-
if (match === null) return frame;
|
|
296
|
-
const [, urlOrPath, line] = match;
|
|
297
|
-
if (urlOrPath === void 0 || line === void 0) return frame;
|
|
298
|
-
let path = urlOrPath;
|
|
299
|
-
path = path.replace(/^[a-z]+:\/\/[^/]+\//i, "");
|
|
300
|
-
path = path.replace(/^_nuxt\//, "");
|
|
301
|
-
path = path.replace(/^\//, "");
|
|
302
|
-
return `(${path}:${line})`;
|
|
303
|
-
}
|
|
304
|
-
|
|
283
|
+
const V_REGISTER_MARKER = Symbol.for("attaform:v-register-directive");
|
|
305
284
|
const REGISTER_OWNER_MARKER = Symbol.for("attaform:register-owner-marker");
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return Reflect.get(v, prop);
|
|
316
|
-
},
|
|
317
|
-
has(_target, prop) {
|
|
318
|
-
if (prop === "__v_isRef" || prop === "value") return true;
|
|
319
|
-
const v = capturedRegisterValue.value;
|
|
320
|
-
if (v === void 0) return false;
|
|
321
|
-
return Reflect.has(v, prop);
|
|
322
|
-
},
|
|
323
|
-
ownKeys(_target) {
|
|
324
|
-
const v = capturedRegisterValue.value;
|
|
325
|
-
if (v === void 0) return [];
|
|
326
|
-
return Reflect.ownKeys(v);
|
|
327
|
-
},
|
|
328
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
329
|
-
const v = capturedRegisterValue.value;
|
|
330
|
-
if (v === void 0) return void 0;
|
|
331
|
-
const desc = Reflect.getOwnPropertyDescriptor(v, prop);
|
|
332
|
-
if (desc !== void 0) {
|
|
333
|
-
desc.configurable = true;
|
|
334
|
-
}
|
|
335
|
-
return desc;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
function useRegister() {
|
|
340
|
-
const instance = getCurrentInstance();
|
|
341
|
-
if (instance === null) {
|
|
342
|
-
warnOutsideSetup();
|
|
343
|
-
return makeRegisterValueProxy(shallowRef(void 0));
|
|
344
|
-
}
|
|
345
|
-
ensureAttaformInstalled(instance.appContext.app);
|
|
346
|
-
const capturedRegisterValue = shallowRef(void 0);
|
|
347
|
-
const refreshAndStripBridgeAttrs = () => {
|
|
348
|
-
const rawAttrs = instance.attrs;
|
|
349
|
-
if ("registerValue" in rawAttrs) {
|
|
350
|
-
capturedRegisterValue.value = rawAttrs["registerValue"];
|
|
351
|
-
delete rawAttrs["registerValue"];
|
|
352
|
-
} else {
|
|
353
|
-
const dirs = instance.vnode.dirs;
|
|
354
|
-
if (dirs !== null && dirs !== void 0) {
|
|
355
|
-
for (const dir of dirs) {
|
|
356
|
-
const marked = dir.dir?.[V_REGISTER_MARKER];
|
|
357
|
-
if (marked === true) {
|
|
358
|
-
capturedRegisterValue.value = dir.value;
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if ("value" in rawAttrs) delete rawAttrs["value"];
|
|
365
|
-
};
|
|
366
|
-
refreshAndStripBridgeAttrs();
|
|
367
|
-
onBeforeMount(refreshAndStripBridgeAttrs);
|
|
368
|
-
onBeforeUpdate(refreshAndStripBridgeAttrs);
|
|
369
|
-
onMounted(() => {
|
|
370
|
-
const el = instance.vnode.el;
|
|
371
|
-
if (el !== null && el !== void 0 && typeof el === "object") {
|
|
372
|
-
el[REGISTER_OWNER_MARKER] = true;
|
|
373
|
-
}
|
|
374
|
-
if (capturedRegisterValue.value === void 0) {
|
|
375
|
-
warnNoParentRV(instance);
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
return makeRegisterValueProxy(capturedRegisterValue);
|
|
379
|
-
}
|
|
380
|
-
function warnOutsideSetup() {
|
|
381
|
-
if (!__DEV__) return;
|
|
382
|
-
if (warnedOutsideSetup) return;
|
|
383
|
-
warnedOutsideSetup = true;
|
|
384
|
-
const frame = captureUserCallSite();
|
|
385
|
-
console.warn(
|
|
386
|
-
`[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}` : "")
|
|
387
|
-
);
|
|
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;
|
|
388
294
|
}
|
|
389
|
-
function
|
|
390
|
-
|
|
391
|
-
if (warnedNoParentRV.has(instance)) return;
|
|
392
|
-
warnedNoParentRV.add(instance);
|
|
393
|
-
const frame = captureUserCallSite();
|
|
394
|
-
console.warn(
|
|
395
|
-
`[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}` : "")
|
|
396
|
-
);
|
|
295
|
+
function isTransforming(value) {
|
|
296
|
+
return isRegisterValue(value) && value.transforming;
|
|
397
297
|
}
|
|
398
298
|
|
|
399
299
|
const MANAGED_ARIA_ATTRS = [
|
|
@@ -504,6 +404,199 @@ function isRegisterValueLike(val) {
|
|
|
504
404
|
return typeof val === "object" && val !== null && "markInteracted" in val && typeof val.markInteracted === "function";
|
|
505
405
|
}
|
|
506
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
|
+
|
|
507
600
|
function isBlankFileValue(value) {
|
|
508
601
|
if (value === null || value === void 0) return true;
|
|
509
602
|
if (Array.isArray(value) && value.length === 0) return true;
|
|
@@ -511,6 +604,11 @@ function isBlankFileValue(value) {
|
|
|
511
604
|
return true;
|
|
512
605
|
return false;
|
|
513
606
|
}
|
|
607
|
+
function isMultipleInput(el, vnode) {
|
|
608
|
+
if (el.multiple) return true;
|
|
609
|
+
const authored = vnode.props?.["multiple"];
|
|
610
|
+
return authored === true || authored === "";
|
|
611
|
+
}
|
|
514
612
|
function readFilesFromInput(el) {
|
|
515
613
|
const files = el.files;
|
|
516
614
|
if (el.multiple) {
|
|
@@ -536,21 +634,25 @@ function maybeWarnPersistedFile(value) {
|
|
|
536
634
|
}
|
|
537
635
|
const fileScopeKey = Symbol.for("attaform:file-scope");
|
|
538
636
|
const vRegisterFile = {
|
|
539
|
-
created(el, { value }) {
|
|
637
|
+
created(el, { value }, vnode) {
|
|
540
638
|
if (!isRegisterValue(value)) return;
|
|
541
639
|
const input = el;
|
|
542
640
|
value.registerElement(input);
|
|
641
|
+
setAssignFunction(input, vnode, value);
|
|
543
642
|
maybeWarnPersistedFile(value);
|
|
544
643
|
const currentRaw = value.innerRef.value;
|
|
545
644
|
if (isBlankFileValue(currentRaw)) {
|
|
546
|
-
const blankShape = input
|
|
645
|
+
const blankShape = isMultipleInput(input, vnode) ? [] : null;
|
|
547
646
|
value.setValueWithInternalPath(blankShape, { blank: true });
|
|
548
647
|
}
|
|
549
648
|
addTrackedListener(input, "change", () => {
|
|
550
649
|
noteInteraction(value);
|
|
551
650
|
const next = readFilesFromInput(input);
|
|
552
|
-
|
|
553
|
-
|
|
651
|
+
if (isBlankFileValue(next)) {
|
|
652
|
+
value.setValueWithInternalPath(next, { blank: true });
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
655
|
+
fireAssigner(input, value, next);
|
|
554
656
|
});
|
|
555
657
|
const scope = effectScope(true);
|
|
556
658
|
scope.run(() => {
|
|
@@ -570,7 +672,7 @@ const vRegisterFile = {
|
|
|
570
672
|
if (!isRegisterValue(value)) return;
|
|
571
673
|
const input = el;
|
|
572
674
|
const currentRaw = value.innerRef.value;
|
|
573
|
-
if (isBlankFileValue(currentRaw)) {
|
|
675
|
+
if (isBlankFileValue(currentRaw) && !isTransforming(value)) {
|
|
574
676
|
value.setValueWithInternalPath(currentRaw, { blank: true });
|
|
575
677
|
if (input.value !== "") input.value = "";
|
|
576
678
|
}
|
|
@@ -839,136 +941,48 @@ function syncElementRegistration(el, value, oldValue) {
|
|
|
839
941
|
}
|
|
840
942
|
}
|
|
841
943
|
|
|
944
|
+
const valueSyncScopeKey = Symbol.for("attaform:value-sync-scope");
|
|
945
|
+
function isElementFocused(el) {
|
|
946
|
+
const rootNode = el.getRootNode();
|
|
947
|
+
const activeElement = rootNode instanceof Document || rootNode instanceof ShadowRoot ? rootNode.activeElement : null;
|
|
948
|
+
return activeElement === el;
|
|
949
|
+
}
|
|
950
|
+
function setupValueSync(el, source, apply, options = {}) {
|
|
951
|
+
const skipWhileFocused = options.skipWhileFocused === true;
|
|
952
|
+
const scope = effectScope(true);
|
|
953
|
+
scope.run(() => {
|
|
954
|
+
watch(
|
|
955
|
+
source,
|
|
956
|
+
() => {
|
|
957
|
+
if (el.composing === true) return;
|
|
958
|
+
if (skipWhileFocused && isElementFocused(el)) return;
|
|
959
|
+
apply();
|
|
960
|
+
},
|
|
961
|
+
{ flush: "post" }
|
|
962
|
+
);
|
|
963
|
+
});
|
|
964
|
+
el[valueSyncScopeKey] = () => scope.stop();
|
|
965
|
+
}
|
|
966
|
+
function teardownValueSync(el) {
|
|
967
|
+
const carrier = el;
|
|
968
|
+
const stop = carrier[valueSyncScopeKey];
|
|
969
|
+
if (stop === void 0) return;
|
|
970
|
+
stop();
|
|
971
|
+
delete carrier[valueSyncScopeKey];
|
|
972
|
+
}
|
|
973
|
+
|
|
842
974
|
const INTERACTIVE_TAG_NAMES = /* @__PURE__ */ new Set(["INPUT", "SELECT", "TEXTAREA"]);
|
|
843
975
|
|
|
844
|
-
const assignKey = Symbol.for("attaform:assign-key");
|
|
845
|
-
function isRegisterValue(val) {
|
|
846
|
-
if (typeof val !== "object" || val === null) return false;
|
|
847
|
-
if (!("innerRef" in val)) return false;
|
|
848
|
-
if (!isRef(val.innerRef)) return false;
|
|
849
|
-
if (!("registerElement" in val)) return false;
|
|
850
|
-
if (typeof val.registerElement !== "function") return false;
|
|
851
|
-
if (!("setValueWithInternalPath" in val)) return false;
|
|
852
|
-
if (typeof val.setValueWithInternalPath !== "function") return false;
|
|
853
|
-
return true;
|
|
854
|
-
}
|
|
855
976
|
function writeLastTypedForm(rv, next) {
|
|
856
977
|
rv.lastTypedForm.value = next;
|
|
857
978
|
}
|
|
858
|
-
const DEFAULT_ASSIGNER_TAG = Symbol.for("attaform:default-assigner-tag");
|
|
859
|
-
function isDefaultAssigner(fn) {
|
|
860
|
-
return typeof fn === "function" && fn[DEFAULT_ASSIGNER_TAG] === true;
|
|
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
|
-
}
|
|
880
979
|
function shouldBailListener(el) {
|
|
881
980
|
if (INTERACTIVE_TAG_NAMES.has(el.tagName)) return false;
|
|
882
981
|
return isDefaultAssigner(el[assignKey]);
|
|
883
982
|
}
|
|
884
|
-
function runTransforms(initial, registerValue) {
|
|
885
|
-
const transforms = registerValue.transforms;
|
|
886
|
-
if (transforms === void 0 || transforms.length === 0) {
|
|
887
|
-
return { ok: true, value: initial };
|
|
888
|
-
}
|
|
889
|
-
let v = initial;
|
|
890
|
-
for (let i = 0; i < transforms.length; i++) {
|
|
891
|
-
const fn = transforms[i];
|
|
892
|
-
try {
|
|
893
|
-
v = fn(v);
|
|
894
|
-
} catch (err) {
|
|
895
|
-
logTransformFailure(registerValue.path, i, fn, err);
|
|
896
|
-
return { ok: false };
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
if (v instanceof Promise) {
|
|
900
|
-
logTransformAsync(registerValue.path);
|
|
901
|
-
return { ok: false };
|
|
902
|
-
}
|
|
903
|
-
return { ok: true, value: v };
|
|
904
|
-
}
|
|
905
|
-
function logTransformFailure(path, index, fn, err) {
|
|
906
|
-
if (__DEV__) {
|
|
907
|
-
const namePart = fn.name !== "" ? `, '${fn.name}'` : "";
|
|
908
|
-
console.error(
|
|
909
|
-
`[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:`,
|
|
910
|
-
err
|
|
911
|
-
);
|
|
912
|
-
} else {
|
|
913
|
-
console.error(
|
|
914
|
-
`[attaform] transform error \u2014 write aborted (set NODE_ENV=development for details).`
|
|
915
|
-
);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
function applyCoerce(value, registerValue) {
|
|
919
|
-
return registerValue.coerce !== void 0 ? registerValue.coerce(value) : value;
|
|
920
|
-
}
|
|
921
983
|
function applyElementCoerce(value, registerValue) {
|
|
922
984
|
return registerValue.coerceElement !== void 0 ? registerValue.coerceElement(value) : value;
|
|
923
985
|
}
|
|
924
|
-
function logTransformAsync(path) {
|
|
925
|
-
if (__DEV__) {
|
|
926
|
-
console.error(
|
|
927
|
-
`[attaform] transform pipeline for path '${path}' returned a Promise \u2014 transforms must be sync. Use async field validation for canonicalize-before-write patterns. Write aborted.`
|
|
928
|
-
);
|
|
929
|
-
} else {
|
|
930
|
-
console.error(
|
|
931
|
-
`[attaform] transform error \u2014 write aborted (set NODE_ENV=development for details).`
|
|
932
|
-
);
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
const getModelAssigner = (vnode, registerValue) => {
|
|
936
|
-
const fn = vnode.props?.["onUpdate:registerValue"] ?? vnode.props?.["on:update:registerValue"];
|
|
937
|
-
if (isArray(fn)) {
|
|
938
|
-
const fnArr = fn.filter((x) => isFunction(x));
|
|
939
|
-
const wrapped = (value) => {
|
|
940
|
-
const r = runTransforms(value, registerValue);
|
|
941
|
-
if (!r.ok) return false;
|
|
942
|
-
const coerced = applyCoerce(r.value, registerValue);
|
|
943
|
-
invokeArrayFns(fnArr, coerced, registerValue);
|
|
944
|
-
return void 0;
|
|
945
|
-
};
|
|
946
|
-
wrapped[CONSUMER_WRAPPED_TAG] = true;
|
|
947
|
-
return wrapped;
|
|
948
|
-
}
|
|
949
|
-
if (isFunction(fn)) {
|
|
950
|
-
const handler = fn;
|
|
951
|
-
const wrapped = (value) => {
|
|
952
|
-
const r = runTransforms(value, registerValue);
|
|
953
|
-
if (!r.ok) return false;
|
|
954
|
-
const coerced = applyCoerce(r.value, registerValue);
|
|
955
|
-
return handler(coerced, registerValue);
|
|
956
|
-
};
|
|
957
|
-
wrapped[CONSUMER_WRAPPED_TAG] = true;
|
|
958
|
-
return wrapped;
|
|
959
|
-
}
|
|
960
|
-
const defaultAssigner = (value) => {
|
|
961
|
-
if (value === void 0 && registerValue.acceptsUndefined) {
|
|
962
|
-
return registerValue.setValueWithInternalPath(void 0);
|
|
963
|
-
}
|
|
964
|
-
const r = runTransforms(value, registerValue);
|
|
965
|
-
if (!r.ok) return false;
|
|
966
|
-
const coerced = applyCoerce(r.value, registerValue);
|
|
967
|
-
return registerValue.setValueWithInternalPath(coerced);
|
|
968
|
-
};
|
|
969
|
-
defaultAssigner[DEFAULT_ASSIGNER_TAG] = true;
|
|
970
|
-
return defaultAssigner;
|
|
971
|
-
};
|
|
972
986
|
function onCompositionStart(e) {
|
|
973
987
|
const target = e.target;
|
|
974
988
|
if (!target) return;
|
|
@@ -981,29 +995,6 @@ function onCompositionEnd(e) {
|
|
|
981
995
|
target.dispatchEvent(new Event("input"));
|
|
982
996
|
}
|
|
983
997
|
}
|
|
984
|
-
function makeNoopAssigner() {
|
|
985
|
-
const noop = (_) => void 0;
|
|
986
|
-
noop[DEFAULT_ASSIGNER_TAG] = true;
|
|
987
|
-
return noop;
|
|
988
|
-
}
|
|
989
|
-
function setAssignFunction(el, vnode, value) {
|
|
990
|
-
const current = el[assignKey];
|
|
991
|
-
if (current !== void 0 && !isDefaultAssigner(current) && !isConsumerWrapped(current)) {
|
|
992
|
-
return;
|
|
993
|
-
}
|
|
994
|
-
if (value === void 0) {
|
|
995
|
-
el[assignKey] = makeNoopAssigner();
|
|
996
|
-
return;
|
|
997
|
-
}
|
|
998
|
-
if (!isRegisterValue(value)) {
|
|
999
|
-
warn(
|
|
1000
|
-
`v-register expected a RegisterValue, got '${typeof value}'. Bind to form.register('field') \u2014 not the field's ref, value, or path string.`
|
|
1001
|
-
);
|
|
1002
|
-
el[assignKey] = makeNoopAssigner();
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
|
-
el[assignKey] = getModelAssigner(vnode, value);
|
|
1006
|
-
}
|
|
1007
998
|
const vRegisterText = {
|
|
1008
999
|
created(el, { value, modifiers: { lazy, trim, number } }, vnode) {
|
|
1009
1000
|
const castToNumberAtCreated = number === true || vnode.props?.["type"] === "number";
|
|
@@ -1012,6 +1003,13 @@ const vRegisterText = {
|
|
|
1012
1003
|
value.registerElement(el);
|
|
1013
1004
|
setAssignFunction(el, vnode, value);
|
|
1014
1005
|
}
|
|
1006
|
+
el._syncFromStorage = () => {
|
|
1007
|
+
if (!isRegisterValue(value)) return;
|
|
1008
|
+
const storage = value.innerRef.value;
|
|
1009
|
+
const display = storage == null ? "" : String(storage);
|
|
1010
|
+
if (el.value !== display) el.value = display;
|
|
1011
|
+
if (liveCastToNumber()) writeLastTypedForm(value, null);
|
|
1012
|
+
};
|
|
1015
1013
|
addTrackedListener(el, lazy === true ? "change" : "input", (e) => {
|
|
1016
1014
|
if (shouldBailListener(el)) return;
|
|
1017
1015
|
const target = e.target;
|
|
@@ -1059,7 +1057,7 @@ const vRegisterText = {
|
|
|
1059
1057
|
}
|
|
1060
1058
|
const commit = domValue === "" && isRegisterValue(value) && value.acceptsUndefined ? void 0 : domValue;
|
|
1061
1059
|
fireAssigner(el, value, commit);
|
|
1062
|
-
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
|
|
1060
|
+
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey]) && !isTransforming(value)) {
|
|
1063
1061
|
const storage = value.innerRef.value;
|
|
1064
1062
|
if (storage !== domValue) {
|
|
1065
1063
|
const display = storage == null ? "" : String(storage);
|
|
@@ -1119,6 +1117,15 @@ const vRegisterText = {
|
|
|
1119
1117
|
mounted(el, { value }) {
|
|
1120
1118
|
if (!isRegisterValue(value)) return;
|
|
1121
1119
|
el.value = value.displayValue.value;
|
|
1120
|
+
setupValueSync(
|
|
1121
|
+
el,
|
|
1122
|
+
value.displayValue,
|
|
1123
|
+
() => {
|
|
1124
|
+
const next = value.displayValue.value;
|
|
1125
|
+
if (el.value !== next) el.value = next;
|
|
1126
|
+
},
|
|
1127
|
+
{ skipWhileFocused: true }
|
|
1128
|
+
);
|
|
1122
1129
|
},
|
|
1123
1130
|
beforeUpdate(el, { value, oldValue, modifiers: { lazy, trim } }, vnode) {
|
|
1124
1131
|
setAssignFunction(el, vnode, value);
|
|
@@ -1148,6 +1155,11 @@ const vRegisterCheckbox = {
|
|
|
1148
1155
|
if (!isRegisterValue(value)) return;
|
|
1149
1156
|
value.registerElement(el);
|
|
1150
1157
|
setAssignFunction(el, vnode, value);
|
|
1158
|
+
el._syncFromStorage = () => {
|
|
1159
|
+
if (!isRegisterValue(value)) return;
|
|
1160
|
+
setChecked(el, value);
|
|
1161
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1162
|
+
};
|
|
1151
1163
|
addTrackedListener(el, "change", () => {
|
|
1152
1164
|
if (shouldBailListener(el)) return;
|
|
1153
1165
|
noteInteraction(value);
|
|
@@ -1190,7 +1202,7 @@ const vRegisterCheckbox = {
|
|
|
1190
1202
|
} else {
|
|
1191
1203
|
fireAssigner(el, value, getCheckboxValue(el, checked));
|
|
1192
1204
|
}
|
|
1193
|
-
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
|
|
1205
|
+
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey]) && !isTransforming(value)) {
|
|
1194
1206
|
setChecked(el, value);
|
|
1195
1207
|
el._lastAppliedModel = value.innerRef.value;
|
|
1196
1208
|
}
|
|
@@ -1199,7 +1211,12 @@ const vRegisterCheckbox = {
|
|
|
1199
1211
|
// set initial checked on mount to wait for true-value/false-value
|
|
1200
1212
|
mounted(el, { value }) {
|
|
1201
1213
|
setChecked(el, value);
|
|
1202
|
-
if (isRegisterValue(value))
|
|
1214
|
+
if (!isRegisterValue(value)) return;
|
|
1215
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1216
|
+
setupValueSync(el, value.innerRef, () => {
|
|
1217
|
+
setChecked(el, value);
|
|
1218
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1219
|
+
});
|
|
1203
1220
|
},
|
|
1204
1221
|
// Skip the DOM sync when the model is identity-unchanged from the
|
|
1205
1222
|
// last application. Pre-fix the scalar branch in `setChecked`
|
|
@@ -1245,11 +1262,18 @@ const vRegisterRadio = {
|
|
|
1245
1262
|
if (!isRegisterValue(value)) return;
|
|
1246
1263
|
value.registerElement(el);
|
|
1247
1264
|
setAssignFunction(el, vnode, value);
|
|
1265
|
+
el._syncFromStorage = () => {
|
|
1266
|
+
if (!isRegisterValue(value)) return;
|
|
1267
|
+
const currentModel = value.innerRef.value;
|
|
1268
|
+
const target = looseEqual(currentModel, applyCoerce(getValue(el), value));
|
|
1269
|
+
if (el.checked !== target) el.checked = target;
|
|
1270
|
+
el._lastAppliedModel = currentModel;
|
|
1271
|
+
};
|
|
1248
1272
|
addTrackedListener(el, "change", () => {
|
|
1249
1273
|
if (shouldBailListener(el)) return;
|
|
1250
1274
|
noteInteraction(value);
|
|
1251
1275
|
fireAssigner(el, value, getValue(el));
|
|
1252
|
-
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
|
|
1276
|
+
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey]) && !isTransforming(value)) {
|
|
1253
1277
|
const currentModel = value.innerRef.value;
|
|
1254
1278
|
const target = looseEqual(currentModel, applyCoerce(getValue(el), value));
|
|
1255
1279
|
if (el.checked !== target) el.checked = target;
|
|
@@ -1268,6 +1292,10 @@ const vRegisterRadio = {
|
|
|
1268
1292
|
if (!isRegisterValue(value)) return;
|
|
1269
1293
|
el.checked = looseEqual(value.innerRef.value, applyCoerce(getValue(el), value));
|
|
1270
1294
|
el._lastAppliedModel = value.innerRef.value;
|
|
1295
|
+
setupValueSync(el, value.innerRef, () => {
|
|
1296
|
+
el.checked = looseEqual(value.innerRef.value, applyCoerce(getValue(el), value));
|
|
1297
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1298
|
+
});
|
|
1271
1299
|
},
|
|
1272
1300
|
// Skip the DOM sync when the model is identity-unchanged from the
|
|
1273
1301
|
// last application. Pre-fix the guard read `value.innerRef.value
|
|
@@ -1293,6 +1321,11 @@ const vRegisterSelect = {
|
|
|
1293
1321
|
created(el, { value, modifiers: { number } }, vnode) {
|
|
1294
1322
|
if (!isRegisterValue(value)) return;
|
|
1295
1323
|
value.registerElement(el);
|
|
1324
|
+
el._syncFromStorage = () => {
|
|
1325
|
+
if (!isRegisterValue(value)) return;
|
|
1326
|
+
setSelected(el, value);
|
|
1327
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1328
|
+
};
|
|
1296
1329
|
addTrackedListener(el, "change", () => {
|
|
1297
1330
|
if (shouldBailListener(el)) return;
|
|
1298
1331
|
noteInteraction(value);
|
|
@@ -1309,7 +1342,7 @@ const vRegisterSelect = {
|
|
|
1309
1342
|
el._assigning = false;
|
|
1310
1343
|
});
|
|
1311
1344
|
}
|
|
1312
|
-
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey])) {
|
|
1345
|
+
if (isRegisterValue(value) && isDefaultAssigner(el[assignKey]) && !isTransforming(value)) {
|
|
1313
1346
|
setSelected(el, value);
|
|
1314
1347
|
el._lastAppliedModel = value.innerRef.value;
|
|
1315
1348
|
}
|
|
@@ -1320,7 +1353,13 @@ const vRegisterSelect = {
|
|
|
1320
1353
|
// <option>s.
|
|
1321
1354
|
mounted(el, { value }) {
|
|
1322
1355
|
setSelected(el, value);
|
|
1323
|
-
if (isRegisterValue(value))
|
|
1356
|
+
if (!isRegisterValue(value)) return;
|
|
1357
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1358
|
+
setupValueSync(el, value.innerRef, () => {
|
|
1359
|
+
if (el._assigning === true) return;
|
|
1360
|
+
setSelected(el, value);
|
|
1361
|
+
el._lastAppliedModel = value.innerRef.value;
|
|
1362
|
+
});
|
|
1324
1363
|
},
|
|
1325
1364
|
beforeUpdate(el, binding, vnode) {
|
|
1326
1365
|
setAssignFunction(el, vnode, binding.value);
|
|
@@ -1418,6 +1457,9 @@ const vRegisterDynamic = {
|
|
|
1418
1457
|
syncMultiTabOptOut(binding.value, void 0);
|
|
1419
1458
|
callModelHook(el, binding, vnode, null, "created");
|
|
1420
1459
|
if (isRegisterValue(binding.value)) setupAria(el, binding.value, vnode);
|
|
1460
|
+
},
|
|
1461
|
+
mounted(el, binding, vnode) {
|
|
1462
|
+
callModelHook(el, binding, vnode, null, "mounted");
|
|
1421
1463
|
if (__DEV__ && warnedUnsupportedElements !== null && !INTERACTIVE_TAG_NAMES.has(el.tagName) && !warnedUnsupportedElements.has(el)) {
|
|
1422
1464
|
void nextTick(() => {
|
|
1423
1465
|
if (warnedUnsupportedElements.has(el)) return;
|
|
@@ -1433,9 +1475,6 @@ const vRegisterDynamic = {
|
|
|
1433
1475
|
});
|
|
1434
1476
|
}
|
|
1435
1477
|
},
|
|
1436
|
-
mounted(el, binding, vnode) {
|
|
1437
|
-
callModelHook(el, binding, vnode, null, "mounted");
|
|
1438
|
-
},
|
|
1439
1478
|
beforeUpdate(el, binding, vnode, prevVNode) {
|
|
1440
1479
|
syncPersistOptIn(el, binding.value, binding.oldValue, vnode.props?.["type"]);
|
|
1441
1480
|
syncMultiTabOptOut(binding.value, binding.oldValue);
|
|
@@ -1463,6 +1502,7 @@ const vRegisterDynamic = {
|
|
|
1463
1502
|
beforeUnmount(el, { value }) {
|
|
1464
1503
|
removeTrackedListeners(el);
|
|
1465
1504
|
teardownAria(el);
|
|
1505
|
+
teardownValueSync(el);
|
|
1466
1506
|
if (isRegisterValue(value)) {
|
|
1467
1507
|
value.persistOptIns.removeAllFor(getOrAssignElementId(el));
|
|
1468
1508
|
value.unmarkNoSync?.();
|
|
@@ -1471,6 +1511,7 @@ const vRegisterDynamic = {
|
|
|
1471
1511
|
value.deregisterElement(el);
|
|
1472
1512
|
delete el.composing;
|
|
1473
1513
|
delete el._assigning;
|
|
1514
|
+
delete el._syncFromStorage;
|
|
1474
1515
|
delete el[assignKey];
|
|
1475
1516
|
},
|
|
1476
1517
|
// The lifecycle hooks above don't run on the server (Vue skips
|
|
@@ -1483,7 +1524,11 @@ const vRegisterDynamic = {
|
|
|
1483
1524
|
getSSRProps(binding, vnode) {
|
|
1484
1525
|
const rv = binding.value;
|
|
1485
1526
|
if (!isRegisterValue(rv)) return void 0;
|
|
1486
|
-
|
|
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 };
|
|
1487
1532
|
}
|
|
1488
1533
|
};
|
|
1489
1534
|
function resolveDynamicModel(tagName, type) {
|
|
@@ -1495,12 +1540,38 @@ function resolveDynamicModel(tagName, type) {
|
|
|
1495
1540
|
if (type === "radio") return vRegisterRadio;
|
|
1496
1541
|
return vRegisterText;
|
|
1497
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
|
+
}
|
|
1498
1570
|
function callModelHook(el, binding, vnode, prevVNode, hook) {
|
|
1499
1571
|
const modelToUse = resolveDynamicModel(el.tagName, vnode.props?.["type"]);
|
|
1500
1572
|
const fn = modelToUse[hook];
|
|
1501
1573
|
fn?.(el, binding, vnode, prevVNode);
|
|
1502
1574
|
}
|
|
1503
|
-
const V_REGISTER_MARKER = Symbol.for("attaform:v-register-directive");
|
|
1504
1575
|
const vRegister = vRegisterDynamic;
|
|
1505
1576
|
vRegisterDynamic[V_REGISTER_MARKER] = true;
|
|
1506
1577
|
|
|
@@ -1647,5 +1718,5 @@ function isPathPrefix(prefix, path) {
|
|
|
1647
1718
|
return true;
|
|
1648
1719
|
}
|
|
1649
1720
|
|
|
1650
|
-
export { AnonPersistError as A,
|
|
1651
|
-
//# sourceMappingURL=attaform.
|
|
1721
|
+
export { AnonPersistError as A, createPersistOptInRegistry as B, ensureAttaformInstalled as C, DEFAULT_SENSITIVE_NAMES as D, kFormContext as E, FORM_ERRORS_PATH_KEY as F, kFormInstanceId as G, createIsSensitivePath as H, InvalidPathError as I, REGISTER_OWNER_MARKER as J, kAttaformAncestorWizard as K, 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, INTERACTIVE_TAG_NAMES as q, getOrAssignElementId as r, segmentsForPathKey as s, toError as t, useRegistry as u, vRegister as v, allowSensitivePersist as w, FORM_ERRORS_PATH as x, coerceToPathKey as y, isSensitivePath as z };
|
|
1722
|
+
//# sourceMappingURL=attaform.DP-u7_tk.mjs.map
|