@vizejs/composable 0.804.0 → 0.805.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.
- package/dist/{catalog-r4Z5nptX.mjs → catalog-BRX-Wg8B.mjs} +1 -1
- package/dist/{catalog-BeTXFKxF.d.mts → catalog-DUBGyBa6.d.mts} +1 -1
- package/dist/catalog.d.mts +1 -1
- package/dist/catalog.mjs +1 -1
- package/dist/create-global-state.d.mts +21 -7
- package/dist/create-global-state.mjs +10 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/resolver.mjs +1 -1
- package/dist/use-form-C2JXZ0i7.mjs +498 -0
- package/dist/use-form.mjs +2 -481
- package/package.json +2 -2
- package/registry/files/create-global-state.ts +25 -6
- package/registry/files/form-value-paths.ts +71 -0
- package/registry/files/use-form.ts +4 -53
- package/registry/registry.json +13 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { computed, ref, shallowRef, toRaw, triggerRef } from "vue";
|
|
2
2
|
import type { ComputedRef, Ref, ShallowRef, WritableComputedRef } from "vue";
|
|
3
3
|
|
|
4
|
+
import { isContainer, readPath, writePath } from "./form-value-paths.ts";
|
|
4
5
|
import { tryOnScopeDispose } from "./scope.ts";
|
|
5
6
|
import { validateStandardSchema } from "./standard-schema.ts";
|
|
6
7
|
import type { NormalizedSchemaIssue, StandardSchemaV1 } from "./standard-schema.ts";
|
|
@@ -414,57 +415,6 @@ export interface FormControls<Values extends object, Output> {
|
|
|
414
415
|
readonly reset: (values?: Values) => void;
|
|
415
416
|
}
|
|
416
417
|
|
|
417
|
-
type Container = Record<string, unknown> | unknown[];
|
|
418
|
-
|
|
419
|
-
function isContainer(value: unknown): value is Container {
|
|
420
|
-
if (Array.isArray(value)) return true;
|
|
421
|
-
if (typeof value !== "object" || value === null) return false;
|
|
422
|
-
const prototype: unknown = Object.getPrototypeOf(value);
|
|
423
|
-
return prototype === Object.prototype || prototype === null;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
function splitPath(path: string): readonly string[] {
|
|
427
|
-
return path === "" ? [] : path.split(".");
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
function readChild(container: Container, key: string): unknown {
|
|
431
|
-
return Array.isArray(container) ? container[Number(key)] : container[key];
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function writeChild(container: Container, key: string, value: unknown): void {
|
|
435
|
-
if (Array.isArray(container)) container[Number(key)] = value;
|
|
436
|
-
else container[key] = value;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/** Read a dotted path. */
|
|
440
|
-
function readPath(root: unknown, path: string): unknown {
|
|
441
|
-
let current = root;
|
|
442
|
-
for (const key of splitPath(path)) {
|
|
443
|
-
if (!isContainer(current)) return undefined;
|
|
444
|
-
current = readChild(current, key);
|
|
445
|
-
}
|
|
446
|
-
return current;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
/** Write a dotted path, creating intermediate containers. */
|
|
450
|
-
function writePath(root: unknown, path: string, value: unknown): void {
|
|
451
|
-
const keys = splitPath(path);
|
|
452
|
-
const last = keys.at(-1);
|
|
453
|
-
if (last === undefined || !isContainer(root)) return;
|
|
454
|
-
let current: Container = root;
|
|
455
|
-
for (let index = 0; index < keys.length - 1; index += 1) {
|
|
456
|
-
const key = keys[index] ?? "";
|
|
457
|
-
let next = readChild(current, key);
|
|
458
|
-
if (!isContainer(next)) {
|
|
459
|
-
next = /^\d+$/.test(keys[index + 1] ?? "") ? [] : {};
|
|
460
|
-
writeChild(current, key, next);
|
|
461
|
-
}
|
|
462
|
-
if (!isContainer(next)) return;
|
|
463
|
-
current = next;
|
|
464
|
-
}
|
|
465
|
-
writeChild(current, last, value);
|
|
466
|
-
}
|
|
467
|
-
|
|
468
418
|
function cloneValue<Value>(value: Value): Value {
|
|
469
419
|
return structuredClone(toRaw(value));
|
|
470
420
|
}
|
|
@@ -626,7 +576,8 @@ export function useForm<Values extends object, Output = Values>(
|
|
|
626
576
|
signal: AbortSignal,
|
|
627
577
|
): Promise<{ readonly errors: Record<string, string[]>; readonly output: unknown }> => {
|
|
628
578
|
const snapshot = values.value;
|
|
629
|
-
|
|
579
|
+
// No prototype, so a path such as `constructor` is an ordinary key.
|
|
580
|
+
const collected: Record<string, string[]> = Object.create(null);
|
|
630
581
|
const add = (path: string, messages: readonly string[]): void => {
|
|
631
582
|
if (messages.length === 0) return;
|
|
632
583
|
(collected[path] ??= []).push(...messages);
|
|
@@ -659,7 +610,7 @@ export function useForm<Values extends object, Output = Values>(
|
|
|
659
610
|
);
|
|
660
611
|
}
|
|
661
612
|
await Promise.all(tasks);
|
|
662
|
-
return { errors: collected, output };
|
|
613
|
+
return { errors: { ...collected }, output };
|
|
663
614
|
};
|
|
664
615
|
|
|
665
616
|
const validate = async (): Promise<FormResult<Output>> => {
|
package/registry/registry.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"registryKind": "vize-lib",
|
|
4
4
|
"package": {
|
|
5
5
|
"name": "@vizejs/composable",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.805.0"
|
|
7
7
|
},
|
|
8
8
|
"kind": "composable",
|
|
9
9
|
"filesDirectory": "files",
|
|
@@ -359,8 +359,8 @@
|
|
|
359
359
|
{
|
|
360
360
|
"path": "create-global-state.ts",
|
|
361
361
|
"role": "entry",
|
|
362
|
-
"sha256": "
|
|
363
|
-
"size":
|
|
362
|
+
"sha256": "cfebb3e7ca600f795bcfe5ce8059d7b448b0e3a6c08f26487dcb11727406c879",
|
|
363
|
+
"size": 1930
|
|
364
364
|
}
|
|
365
365
|
],
|
|
366
366
|
"registryDependencies": [],
|
|
@@ -371,7 +371,7 @@
|
|
|
371
371
|
"kind": "peer"
|
|
372
372
|
}
|
|
373
373
|
],
|
|
374
|
-
"contentHash": "
|
|
374
|
+
"contentHash": "574e0dd37f70e8bd2f27a4aa43e5c77c0677c2476d930dd546a8d050865d6fa7",
|
|
375
375
|
"examples": []
|
|
376
376
|
},
|
|
377
377
|
{
|
|
@@ -3263,11 +3263,17 @@
|
|
|
3263
3263
|
"packageSubpath": "./use-form",
|
|
3264
3264
|
"entry": "use-form.ts",
|
|
3265
3265
|
"files": [
|
|
3266
|
+
{
|
|
3267
|
+
"path": "form-value-paths.ts",
|
|
3268
|
+
"role": "module",
|
|
3269
|
+
"sha256": "95a1591ef65538b1e26a8a58ad78f34e25f2bffdbf4b98a0594175b6b025eefc",
|
|
3270
|
+
"size": 2725
|
|
3271
|
+
},
|
|
3266
3272
|
{
|
|
3267
3273
|
"path": "use-form.ts",
|
|
3268
3274
|
"role": "entry",
|
|
3269
|
-
"sha256": "
|
|
3270
|
-
"size":
|
|
3275
|
+
"sha256": "0fc0af684742d7dcd81938c4d700a6f6c82bfc06b6f3f29aa7cb03feb914565b",
|
|
3276
|
+
"size": 32452
|
|
3271
3277
|
}
|
|
3272
3278
|
],
|
|
3273
3279
|
"registryDependencies": [
|
|
@@ -3281,7 +3287,7 @@
|
|
|
3281
3287
|
"kind": "peer"
|
|
3282
3288
|
}
|
|
3283
3289
|
],
|
|
3284
|
-
"contentHash": "
|
|
3290
|
+
"contentHash": "fb6764d3548a0ea52cd29988bfe8f1dea65d81267a64330a971d3f51dc8ead31",
|
|
3285
3291
|
"examples": []
|
|
3286
3292
|
},
|
|
3287
3293
|
{
|