notform 2.0.0-alpha.0 → 2.0.0-alpha.1
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/index.d.ts +715 -19
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { ComputedRef, MaybeRefOrGetter, Ref } from "vue";
|
|
1
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
2
|
-
import { MaybeRefOrGetter } from "vue";
|
|
3
3
|
|
|
4
4
|
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/primitive.d.ts
|
|
5
5
|
/**
|
|
@@ -9,6 +9,23 @@ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/
|
|
|
9
9
|
*/
|
|
10
10
|
type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/characters.d.ts
|
|
13
|
+
/**
|
|
14
|
+
Matches any digit as a string ('0'-'9').
|
|
15
|
+
|
|
16
|
+
@example
|
|
17
|
+
```
|
|
18
|
+
import type {DigitCharacter} from 'type-fest';
|
|
19
|
+
|
|
20
|
+
const a: DigitCharacter = '0'; // Valid
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
const b: DigitCharacter = 0; // Invalid
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
@category Type
|
|
26
|
+
*/
|
|
27
|
+
type DigitCharacter = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
28
|
+
//#endregion
|
|
12
29
|
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-any.d.ts
|
|
13
30
|
/**
|
|
14
31
|
Returns a boolean for whether the given type is `any`.
|
|
@@ -518,6 +535,245 @@ type ShouldBeTrue = IsNegative<-1>;
|
|
|
518
535
|
*/
|
|
519
536
|
type IsNegative<T extends _Numeric> = T extends Negative<T> ? true : false;
|
|
520
537
|
//#endregion
|
|
538
|
+
//#region ../../node_modules/.pnpm/tagged-tag@1.0.0/node_modules/tagged-tag/index.d.ts
|
|
539
|
+
declare const tag: unique symbol;
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/tagged.d.ts
|
|
542
|
+
// eslint-disable-next-line type-fest/require-exported-types
|
|
543
|
+
type TagContainer<Token> = {
|
|
544
|
+
readonly [tag]: Token;
|
|
545
|
+
};
|
|
546
|
+
type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{ [K in Token]: TagMetadata }>;
|
|
547
|
+
/**
|
|
548
|
+
Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for distinct concepts in your program that should not be interchangeable, even if their runtime values have the same type. (See examples.)
|
|
549
|
+
|
|
550
|
+
A type returned by `Tagged` can be passed to `Tagged` again, to create a type with multiple tags.
|
|
551
|
+
|
|
552
|
+
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
553
|
+
|
|
554
|
+
A tag's name is usually a string (and must be a string, number, or symbol), but each application of a tag can also contain an arbitrary type as its "metadata". See {@link GetTagMetadata} for examples and explanation.
|
|
555
|
+
|
|
556
|
+
A type `A` returned by `Tagged` is assignable to another type `B` returned by `Tagged` if and only if:
|
|
557
|
+
- the underlying (untagged) type of `A` is assignable to the underlying type of `B`;
|
|
558
|
+
- `A` contains at least all the tags `B` has;
|
|
559
|
+
- and the metadata type for each of `A`'s tags is assignable to the metadata type of `B`'s corresponding tag.
|
|
560
|
+
|
|
561
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
562
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
563
|
+
- [Microsoft/TypeScript#4895](https://github.com/microsoft/TypeScript/issues/4895)
|
|
564
|
+
- [Microsoft/TypeScript#33290](https://github.com/microsoft/TypeScript/pull/33290)
|
|
565
|
+
|
|
566
|
+
@example
|
|
567
|
+
```
|
|
568
|
+
import type {Tagged} from 'type-fest';
|
|
569
|
+
|
|
570
|
+
type AccountNumber = Tagged<number, 'AccountNumber'>;
|
|
571
|
+
type AccountBalance = Tagged<number, 'AccountBalance'>;
|
|
572
|
+
|
|
573
|
+
function createAccountNumber(): AccountNumber {
|
|
574
|
+
// As you can see, casting from a `number` (the underlying type being tagged) is allowed.
|
|
575
|
+
return 2 as AccountNumber;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
579
|
+
|
|
580
|
+
// This will compile successfully.
|
|
581
|
+
getMoneyForAccount(createAccountNumber());
|
|
582
|
+
|
|
583
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type!
|
|
584
|
+
// Critically, you could not accidentally use an `AccountBalance` as an `AccountNumber`.
|
|
585
|
+
// @ts-expect-error
|
|
586
|
+
getMoneyForAccount(2);
|
|
587
|
+
|
|
588
|
+
// You can also use tagged values like their underlying, untagged type.
|
|
589
|
+
// I.e., this will compile successfully because an `AccountNumber` can be used as a regular `number`.
|
|
590
|
+
// In this sense, the underlying base type is not hidden, which differentiates tagged types from opaque types in other languages.
|
|
591
|
+
const accountNumber = createAccountNumber() + 2;
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
@example
|
|
595
|
+
```
|
|
596
|
+
import type {Tagged} from 'type-fest';
|
|
597
|
+
|
|
598
|
+
// You can apply multiple tags to a type by using `Tagged` repeatedly.
|
|
599
|
+
type Url = Tagged<string, 'URL'>;
|
|
600
|
+
type SpecialCacheKey = Tagged<Url, 'SpecialCacheKey'>;
|
|
601
|
+
|
|
602
|
+
// You can also pass a union of tag names, so this is equivalent to the above, although it doesn't give you the ability to assign distinct metadata to each tag.
|
|
603
|
+
type SpecialCacheKey2 = Tagged<string, 'URL' | 'SpecialCacheKey'>;
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
@category Type
|
|
607
|
+
*/
|
|
608
|
+
type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
|
|
609
|
+
/**
|
|
610
|
+
Revert a tagged type back to its original type by removing all tags.
|
|
611
|
+
|
|
612
|
+
Why is this necessary?
|
|
613
|
+
|
|
614
|
+
1. Use a `Tagged` type as object keys
|
|
615
|
+
2. Prevent TS4058 error: "Return type of exported function has or is using name X from external module Y but cannot be named"
|
|
616
|
+
|
|
617
|
+
@example
|
|
618
|
+
```
|
|
619
|
+
import type {Tagged, UnwrapTagged} from 'type-fest';
|
|
620
|
+
|
|
621
|
+
type AccountType = Tagged<'SAVINGS' | 'CHECKING', 'AccountType'>;
|
|
622
|
+
|
|
623
|
+
const moneyByAccountType: Record<UnwrapTagged<AccountType>, number> = {
|
|
624
|
+
SAVINGS: 99,
|
|
625
|
+
CHECKING: 0.1,
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
// Without UnwrapTagged, the following expression would throw a type error.
|
|
629
|
+
const money = moneyByAccountType.SAVINGS; // TS error: Property 'SAVINGS' does not exist
|
|
630
|
+
|
|
631
|
+
// Attempting to pass a non-Tagged type to UnwrapTagged will raise a type error.
|
|
632
|
+
// @ts-expect-error
|
|
633
|
+
type WontWork = UnwrapTagged<string>;
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
@category Type
|
|
637
|
+
*/
|
|
638
|
+
type UnwrapTagged<TaggedType extends Tag<PropertyKey, any>> = RemoveAllTags<TaggedType>;
|
|
639
|
+
type RemoveAllTags<T> = T extends Tag<PropertyKey, any> ? { [ThisTag in keyof T[typeof tag]]: T extends Tagged<infer Type, ThisTag, T[typeof tag][ThisTag]> ? RemoveAllTags<Type> : never }[keyof T[typeof tag]] : T;
|
|
640
|
+
/**
|
|
641
|
+
Note: The `Opaque` type is deprecated in favor of `Tagged`.
|
|
642
|
+
|
|
643
|
+
Attach a "tag" to an arbitrary type. This allows you to create distinct types, that aren't assignable to one another, for runtime values that would otherwise have the same type. (See examples.)
|
|
644
|
+
|
|
645
|
+
The generic type parameters can be anything.
|
|
646
|
+
|
|
647
|
+
Note that `Opaque` is somewhat of a misnomer here, in that, unlike [some alternative implementations](https://github.com/microsoft/TypeScript/issues/4895#issuecomment-425132582), the original, untagged type is not actually hidden. (E.g., functions that accept the untagged type can still be called with the "opaque" version -- but not vice-versa.)
|
|
648
|
+
|
|
649
|
+
Also note that this implementation is limited to a single tag. If you want to allow multiple tags, use `Tagged` instead.
|
|
650
|
+
|
|
651
|
+
[Read more about tagged types.](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d)
|
|
652
|
+
|
|
653
|
+
There have been several discussions about adding similar features to TypeScript. Unfortunately, nothing has (yet) moved forward:
|
|
654
|
+
- [Microsoft/TypeScript#202](https://github.com/microsoft/TypeScript/issues/202)
|
|
655
|
+
- [Microsoft/TypeScript#15408](https://github.com/Microsoft/TypeScript/issues/15408)
|
|
656
|
+
- [Microsoft/TypeScript#15807](https://github.com/Microsoft/TypeScript/issues/15807)
|
|
657
|
+
|
|
658
|
+
@example
|
|
659
|
+
```
|
|
660
|
+
import type {Opaque} from 'type-fest';
|
|
661
|
+
|
|
662
|
+
type AccountNumber = Opaque<number, 'AccountNumber'>;
|
|
663
|
+
type AccountBalance = Opaque<number, 'AccountBalance'>;
|
|
664
|
+
|
|
665
|
+
// The `Token` parameter allows the compiler to differentiate between types, whereas "unknown" will not. For example, consider the following structures:
|
|
666
|
+
type ThingOne = Opaque<string>;
|
|
667
|
+
type ThingTwo = Opaque<string>;
|
|
668
|
+
|
|
669
|
+
// To the compiler, these types are allowed to be cast to each other as they have the same underlying type. They are both `string & { __opaque__: unknown }`.
|
|
670
|
+
// To avoid this behaviour, you would instead pass the "Token" parameter, like so.
|
|
671
|
+
type NewThingOne = Opaque<string, 'ThingOne'>;
|
|
672
|
+
type NewThingTwo = Opaque<string, 'ThingTwo'>;
|
|
673
|
+
|
|
674
|
+
// Now they're completely separate types, so the following will fail to compile.
|
|
675
|
+
function createNewThingOne(): NewThingOne {
|
|
676
|
+
// As you can see, casting from a string is still allowed. However, you may not cast NewThingOne to NewThingTwo, and vice versa.
|
|
677
|
+
return 'new thing one' as NewThingOne;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// This will fail to compile, as they are fundamentally different types.
|
|
681
|
+
// @ts-expect-error
|
|
682
|
+
const thingTwo = createNewThingOne() as NewThingTwo;
|
|
683
|
+
|
|
684
|
+
// Here's another example of opaque typing.
|
|
685
|
+
function createAccountNumber(): AccountNumber {
|
|
686
|
+
return 2 as AccountNumber;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
declare function getMoneyForAccount(accountNumber: AccountNumber): AccountBalance;
|
|
690
|
+
|
|
691
|
+
// This will compile successfully.
|
|
692
|
+
getMoneyForAccount(createAccountNumber());
|
|
693
|
+
|
|
694
|
+
// But this won't, because it has to be explicitly passed as an `AccountNumber` type.
|
|
695
|
+
// @ts-expect-error
|
|
696
|
+
getMoneyForAccount(2);
|
|
697
|
+
|
|
698
|
+
// You can use opaque values like they aren't opaque too.
|
|
699
|
+
const accountNumber = createAccountNumber();
|
|
700
|
+
|
|
701
|
+
// This will compile successfully.
|
|
702
|
+
const newAccountNumber = accountNumber + 2;
|
|
703
|
+
|
|
704
|
+
// As a side note, you can (and should) use recursive types for your opaque types to make them stronger and hopefully easier to type.
|
|
705
|
+
type Person = {
|
|
706
|
+
id: Opaque<number, Person>;
|
|
707
|
+
name: string;
|
|
708
|
+
};
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
@category Type
|
|
712
|
+
@deprecated Use {@link Tagged} instead
|
|
713
|
+
*/
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/is-literal.d.ts
|
|
716
|
+
/**
|
|
717
|
+
Returns a boolean for whether the given type is a `string` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
|
|
718
|
+
|
|
719
|
+
Useful for:
|
|
720
|
+
- providing strongly-typed string manipulation functions
|
|
721
|
+
- constraining strings to be a string literal
|
|
722
|
+
- type utilities, such as when constructing parsers and ASTs
|
|
723
|
+
|
|
724
|
+
The implementation of this type is inspired by the trick mentioned in this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
725
|
+
|
|
726
|
+
@example
|
|
727
|
+
```
|
|
728
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
729
|
+
|
|
730
|
+
type CapitalizedString<T extends string> = IsStringLiteral<T> extends true ? Capitalize<T> : string;
|
|
731
|
+
|
|
732
|
+
// https://github.com/yankeeinlondon/native-dash/blob/master/src/capitalize.ts
|
|
733
|
+
function capitalize<T extends Readonly<string>>(input: T): CapitalizedString<T> {
|
|
734
|
+
return (input.slice(0, 1).toUpperCase() + input.slice(1)) as CapitalizedString<T>;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
const output = capitalize('hello, world!');
|
|
738
|
+
//=> 'Hello, world!'
|
|
739
|
+
```
|
|
740
|
+
|
|
741
|
+
@example
|
|
742
|
+
```
|
|
743
|
+
// String types with infinite set of possible values return `false`.
|
|
744
|
+
|
|
745
|
+
import type {IsStringLiteral} from 'type-fest';
|
|
746
|
+
|
|
747
|
+
type AllUppercaseStrings = IsStringLiteral<Uppercase<string>>;
|
|
748
|
+
//=> false
|
|
749
|
+
|
|
750
|
+
type StringsStartingWithOn = IsStringLiteral<`on${string}`>;
|
|
751
|
+
//=> false
|
|
752
|
+
|
|
753
|
+
// This behaviour is particularly useful in string manipulation utilities, as infinite string types often require separate handling.
|
|
754
|
+
|
|
755
|
+
type Length<S extends string, Counter extends never[] = []> =
|
|
756
|
+
IsStringLiteral<S> extends false
|
|
757
|
+
? number // return `number` for infinite string types
|
|
758
|
+
: S extends `${string}${infer Tail}`
|
|
759
|
+
? Length<Tail, [...Counter, never]>
|
|
760
|
+
: Counter['length'];
|
|
761
|
+
|
|
762
|
+
type L1 = Length<Lowercase<string>>;
|
|
763
|
+
//=> number
|
|
764
|
+
|
|
765
|
+
type L2 = Length<`${number}`>;
|
|
766
|
+
//=> number
|
|
767
|
+
```
|
|
768
|
+
|
|
769
|
+
@category Type Guard
|
|
770
|
+
@category Utilities
|
|
771
|
+
*/
|
|
772
|
+
type IsStringLiteral<S> = IfNotAnyOrNever<S, _IsStringLiteral<CollapseLiterals<S extends TagContainer<any> ? UnwrapTagged<S> : S>>, false, false>;
|
|
773
|
+
type _IsStringLiteral<S> = // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
|
|
774
|
+
// and since `{}` extends index signatures, the result becomes `false`.
|
|
775
|
+
S extends string ? {} extends Record<S, never> ? false : true : false;
|
|
776
|
+
//#endregion
|
|
521
777
|
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/tuple-of.d.ts
|
|
522
778
|
/**
|
|
523
779
|
Create a tuple type of the specified length with elements of the specified type.
|
|
@@ -1120,6 +1376,35 @@ type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOp
|
|
|
1120
1376
|
```
|
|
1121
1377
|
*/
|
|
1122
1378
|
type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = If<IsAny<SpecifiedOptions>, Defaults, If<IsNever<SpecifiedOptions>, Defaults, Simplify<Merge<Defaults, { [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key]: SpecifiedOptions[Key] }> & Required<Options>>>>;
|
|
1379
|
+
// `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
1380
|
+
/**
|
|
1381
|
+
Collapses literal types in a union into their corresponding primitive types, when possible. For example, `CollapseLiterals<'foo' | 'bar' | (string & {})>` returns `string`.
|
|
1382
|
+
|
|
1383
|
+
Note: This doesn't collapse literals within tagged types. For example, `CollapseLiterals<Tagged<'foo' | (string & {}), 'Tag'>>` returns `("foo" & Tag<"Tag", never>) | (string & Tag<"Tag", never>)` and not `string & Tag<"Tag", never>`.
|
|
1384
|
+
|
|
1385
|
+
Use-case: For collapsing unions created using {@link LiteralUnion}.
|
|
1386
|
+
|
|
1387
|
+
@example
|
|
1388
|
+
```
|
|
1389
|
+
import type {LiteralUnion} from 'type-fest';
|
|
1390
|
+
|
|
1391
|
+
type A = CollapseLiterals<'foo' | 'bar' | (string & {})>;
|
|
1392
|
+
//=> string
|
|
1393
|
+
|
|
1394
|
+
type B = CollapseLiterals<LiteralUnion<1 | 2 | 3, number>>;
|
|
1395
|
+
//=> number
|
|
1396
|
+
|
|
1397
|
+
type C = CollapseLiterals<LiteralUnion<'onClick' | 'onChange', `on${string}`>>;
|
|
1398
|
+
//=> `on${string}`
|
|
1399
|
+
|
|
1400
|
+
type D = CollapseLiterals<'click' | 'change' | (`on${string}` & {})>;
|
|
1401
|
+
//=> 'click' | 'change' | `on${string}`
|
|
1402
|
+
|
|
1403
|
+
type E = CollapseLiterals<LiteralUnion<'foo' | 'bar', string> | null | undefined>;
|
|
1404
|
+
//=> string | null | undefined
|
|
1405
|
+
```
|
|
1406
|
+
*/
|
|
1407
|
+
type CollapseLiterals<T> = {} extends T ? T : T extends infer U & {} ? U : T;
|
|
1123
1408
|
//#endregion
|
|
1124
1409
|
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/some-extend.d.ts
|
|
1125
1410
|
/**
|
|
@@ -2167,21 +2452,288 @@ type InternalPaths<T, Options extends Required<PathsOptions>, CurrentDepth exten
|
|
|
2167
2452
|
| (GreaterThan<Options['maxRecursionDepth'], CurrentDepth> extends true // Limit the depth to prevent infinite recursion
|
|
2168
2453
|
? `${TransformedKey}${_Paths<T[Key], Options, Sum<CurrentDepth, 1>> & (string | number)}` : never) : never : never }[keyof T & (T extends UnknownArray ? number : unknown)];
|
|
2169
2454
|
//#endregion
|
|
2455
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/literal-union.d.ts
|
|
2456
|
+
type _LiteralStringUnion<T> = LiteralUnion<T, string>;
|
|
2457
|
+
/**
|
|
2458
|
+
Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
2459
|
+
|
|
2460
|
+
Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
|
|
2461
|
+
|
|
2462
|
+
This type is a workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as it's not needed anymore.
|
|
2463
|
+
|
|
2464
|
+
@example
|
|
2465
|
+
```
|
|
2466
|
+
import type {LiteralUnion} from 'type-fest';
|
|
2467
|
+
|
|
2468
|
+
// Before
|
|
2469
|
+
|
|
2470
|
+
type Pet = 'dog' | 'cat' | string;
|
|
2471
|
+
|
|
2472
|
+
const petWithoutAutocomplete: Pet = '';
|
|
2473
|
+
// Start typing in your TypeScript-enabled IDE.
|
|
2474
|
+
// You **will not** get auto-completion for `dog` and `cat` literals.
|
|
2475
|
+
|
|
2476
|
+
// After
|
|
2477
|
+
|
|
2478
|
+
type Pet2 = LiteralUnion<'dog' | 'cat', string>;
|
|
2479
|
+
|
|
2480
|
+
const petWithAutoComplete: Pet2 = '';
|
|
2481
|
+
// You **will** get auto-completion for `dog` and `cat` literals.
|
|
2482
|
+
```
|
|
2483
|
+
|
|
2484
|
+
@category Type
|
|
2485
|
+
*/
|
|
2486
|
+
type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
|
|
2487
|
+
//#endregion
|
|
2488
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/key-as-string.d.ts
|
|
2489
|
+
/**
|
|
2490
|
+
Get keys of the given type as strings.
|
|
2491
|
+
|
|
2492
|
+
Number keys are converted to strings.
|
|
2493
|
+
|
|
2494
|
+
Use-cases:
|
|
2495
|
+
- Get string keys from a type which may have number keys.
|
|
2496
|
+
- Makes it possible to index using strings retrieved from template types.
|
|
2497
|
+
|
|
2498
|
+
@example
|
|
2499
|
+
```
|
|
2500
|
+
import type {KeyAsString} from 'type-fest';
|
|
2501
|
+
|
|
2502
|
+
type Foo = {
|
|
2503
|
+
1: number;
|
|
2504
|
+
stringKey: string;
|
|
2505
|
+
};
|
|
2506
|
+
|
|
2507
|
+
type StringKeysOfFoo = KeyAsString<Foo>;
|
|
2508
|
+
//=> 'stringKey' | '1'
|
|
2509
|
+
```
|
|
2510
|
+
|
|
2511
|
+
@category Object
|
|
2512
|
+
*/
|
|
2513
|
+
type KeyAsString<BaseType> = `${Extract<keyof BaseType, string | number>}`;
|
|
2514
|
+
//#endregion
|
|
2515
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/split.d.ts
|
|
2516
|
+
/**
|
|
2517
|
+
Split options.
|
|
2518
|
+
|
|
2519
|
+
@see {@link Split}
|
|
2520
|
+
*/
|
|
2521
|
+
type SplitOptions = {
|
|
2522
|
+
/**
|
|
2523
|
+
When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
|
|
2524
|
+
@default true
|
|
2525
|
+
@example
|
|
2526
|
+
```ts
|
|
2527
|
+
import type {Split} from 'type-fest';
|
|
2528
|
+
type Example1 = Split<`foo.${string}.bar`, '.', {strictLiteralChecks: false}>;
|
|
2529
|
+
//=> ['foo', string, 'bar']
|
|
2530
|
+
type Example2 = Split<`foo.${string}`, '.', {strictLiteralChecks: true}>;
|
|
2531
|
+
//=> string[]
|
|
2532
|
+
type Example3 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: false}>;
|
|
2533
|
+
//=> ['foo', 'r', 'z']
|
|
2534
|
+
type Example4 = Split<'foobarbaz', `b${string}`, {strictLiteralChecks: true}>;
|
|
2535
|
+
//=> string[]
|
|
2536
|
+
```
|
|
2537
|
+
*/
|
|
2538
|
+
strictLiteralChecks?: boolean;
|
|
2539
|
+
};
|
|
2540
|
+
type DefaultSplitOptions = {
|
|
2541
|
+
strictLiteralChecks: true;
|
|
2542
|
+
};
|
|
2543
|
+
/**
|
|
2544
|
+
Represents an array of strings split using a given character or character set.
|
|
2545
|
+
|
|
2546
|
+
Use-case: Defining the return type of a method like `String.prototype.split`.
|
|
2547
|
+
|
|
2548
|
+
@example
|
|
2549
|
+
```
|
|
2550
|
+
import type {Split} from 'type-fest';
|
|
2551
|
+
|
|
2552
|
+
declare function split<S extends string, D extends string>(string: S, separator: D): Split<S, D>;
|
|
2553
|
+
|
|
2554
|
+
type Item = 'foo' | 'bar' | 'baz' | 'waldo';
|
|
2555
|
+
const items = 'foo,bar,baz,waldo';
|
|
2556
|
+
const array: Item[] = split(items, ',');
|
|
2557
|
+
```
|
|
2558
|
+
|
|
2559
|
+
@see {@link SplitOptions}
|
|
2560
|
+
|
|
2561
|
+
@category String
|
|
2562
|
+
@category Template literal
|
|
2563
|
+
*/
|
|
2564
|
+
type Split<S extends string, Delimiter extends string, Options extends SplitOptions = {}> = SplitHelper<S, Delimiter, ApplyDefaultOptions<SplitOptions, DefaultSplitOptions, Options>>;
|
|
2565
|
+
type SplitHelper<S extends string, Delimiter extends string, Options extends Required<SplitOptions>, Accumulator extends string[] = []> = S extends string // For distributing `S`
|
|
2566
|
+
? Delimiter extends string // For distributing `Delimiter`
|
|
2567
|
+
// If `strictLiteralChecks` is `false` OR `S` and `Delimiter` both are string literals, then perform the split
|
|
2568
|
+
? Or<Not<Options['strictLiteralChecks']>, And<IsStringLiteral<S>, IsStringLiteral<Delimiter>>> extends true ? S extends `${infer Head}${Delimiter}${infer Tail}` ? SplitHelper<Tail, Delimiter, Options, [...Accumulator, Head]> : Delimiter extends '' ? S extends '' ? Accumulator : [...Accumulator, S] : [...Accumulator, S] // Otherwise, return `string[]`
|
|
2569
|
+
: string[] : never // Should never happen
|
|
2570
|
+
: never; // Should never happen
|
|
2571
|
+
//#endregion
|
|
2572
|
+
//#region ../../node_modules/.pnpm/type-fest@5.5.0/node_modules/type-fest/source/get.d.ts
|
|
2573
|
+
type GetOptions = {
|
|
2574
|
+
/**
|
|
2575
|
+
Include `undefined` in the return type when accessing properties.
|
|
2576
|
+
Setting this to `false` is not recommended.
|
|
2577
|
+
@default true
|
|
2578
|
+
*/
|
|
2579
|
+
strict?: boolean;
|
|
2580
|
+
};
|
|
2581
|
+
type DefaultGetOptions = {
|
|
2582
|
+
strict: true;
|
|
2583
|
+
};
|
|
2584
|
+
/**
|
|
2585
|
+
Like the `Get` type but receives an array of strings as a path parameter.
|
|
2586
|
+
*/
|
|
2587
|
+
type GetWithPath<BaseType, Keys, Options extends Required<GetOptions>> = Keys extends readonly [] ? BaseType : Keys extends readonly [infer Head, ...infer Tail] ? GetWithPath<PropertyOf<BaseType, Extract<Head, string>, Options>, Extract<Tail, string[]>, Options> : never;
|
|
2588
|
+
/**
|
|
2589
|
+
Adds `undefined` to `Type` if `strict` is enabled.
|
|
2590
|
+
*/
|
|
2591
|
+
type Strictify<Type, Options extends Required<GetOptions>> = Options['strict'] extends false ? Type : (Type | undefined);
|
|
2592
|
+
/**
|
|
2593
|
+
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
|
2594
|
+
|
|
2595
|
+
Known limitations:
|
|
2596
|
+
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
|
2597
|
+
*/
|
|
2598
|
+
type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends Required<GetOptions>> = Record<string, any> extends BaseType ? string extends keyof BaseType ? Strictify<BaseType[Key], Options> // Record<string, any>
|
|
2599
|
+
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
2600
|
+
: BaseType[Key];
|
|
2601
|
+
/**
|
|
2602
|
+
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
|
2603
|
+
|
|
2604
|
+
@example
|
|
2605
|
+
```
|
|
2606
|
+
type A = ToPath<'foo.bar.baz'>;
|
|
2607
|
+
//=> ['foo', 'bar', 'baz']
|
|
2608
|
+
|
|
2609
|
+
type B = ToPath<'foo[0].bar.baz'>;
|
|
2610
|
+
//=> ['foo', '0', 'bar', 'baz']
|
|
2611
|
+
```
|
|
2612
|
+
*/
|
|
2613
|
+
type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.', {
|
|
2614
|
+
strictLiteralChecks: false;
|
|
2615
|
+
}>;
|
|
2616
|
+
/**
|
|
2617
|
+
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
|
2618
|
+
*/
|
|
2619
|
+
type FixPathSquareBrackets<Path extends string> = Path extends `[${infer Head}]${infer Tail}` ? Tail extends `[${string}` ? `${Head}.${FixPathSquareBrackets<Tail>}` : `${Head}${FixPathSquareBrackets<Tail>}` : Path extends `${infer Head}[${infer Middle}]${infer Tail}` ? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}` : Path;
|
|
2620
|
+
/**
|
|
2621
|
+
Returns true if `LongString` is made up out of `Substring` repeated 0 or more times.
|
|
2622
|
+
|
|
2623
|
+
@example
|
|
2624
|
+
```
|
|
2625
|
+
type A = ConsistsOnlyOf<'aaa', 'a'>; //=> true
|
|
2626
|
+
type B = ConsistsOnlyOf<'ababab', 'ab'>; //=> true
|
|
2627
|
+
type C = ConsistsOnlyOf<'aBa', 'a'>; //=> false
|
|
2628
|
+
type D = ConsistsOnlyOf<'', 'a'>; //=> true
|
|
2629
|
+
```
|
|
2630
|
+
*/
|
|
2631
|
+
type ConsistsOnlyOf<LongString extends string, Substring extends string> = LongString extends '' ? true : LongString extends `${Substring}${infer Tail}` ? ConsistsOnlyOf<Tail, Substring> : false;
|
|
2632
|
+
/**
|
|
2633
|
+
Convert a type which may have number keys to one with string keys, making it possible to index using strings retrieved from template types.
|
|
2634
|
+
|
|
2635
|
+
@example
|
|
2636
|
+
```
|
|
2637
|
+
type WithNumbers = {foo: string; 0: boolean};
|
|
2638
|
+
type WithStrings = WithStringKeys<WithNumbers>;
|
|
2639
|
+
|
|
2640
|
+
type WithNumbersKeys = keyof WithNumbers;
|
|
2641
|
+
//=> 'foo' | 0
|
|
2642
|
+
type WithStringsKeys = keyof WithStrings;
|
|
2643
|
+
//=> 'foo' | '0'
|
|
2644
|
+
```
|
|
2645
|
+
*/
|
|
2646
|
+
type WithStringKeys<BaseType> = { [Key in KeyAsString<BaseType>]: UncheckedIndex<BaseType, Key> };
|
|
2647
|
+
/**
|
|
2648
|
+
Perform a `T[U]` operation if `T` supports indexing.
|
|
2649
|
+
*/
|
|
2650
|
+
type UncheckedIndex<T, U extends string | number> = [T] extends [Record<string | number, any>] ? T[U] : never;
|
|
2651
|
+
/**
|
|
2652
|
+
Get a property of an object or array. Works when indexing arrays using number-literal-strings, for example, `PropertyOf<number[], '0'> = number`, and when indexing objects with number keys.
|
|
2653
|
+
|
|
2654
|
+
Note:
|
|
2655
|
+
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
|
2656
|
+
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
|
2657
|
+
*/
|
|
2658
|
+
type PropertyOf<BaseType, Key extends string, Options extends Required<GetOptions>> = BaseType extends null | undefined ? undefined : Key extends keyof BaseType ? StrictPropertyOf<BaseType, Key, Options> // Handle arrays and tuples
|
|
2659
|
+
: BaseType extends readonly unknown[] ? Key extends `${number}` // For arrays with unknown length (regular arrays)
|
|
2660
|
+
? number extends BaseType['length'] ? Strictify<BaseType[number], Options> // For tuples: check if the index is valid
|
|
2661
|
+
: Key extends keyof BaseType ? Strictify<BaseType[Key & keyof BaseType], Options> // Out-of-bounds access for tuples
|
|
2662
|
+
: unknown // Non-numeric string key for arrays/tuples
|
|
2663
|
+
: unknown // Handle array-like objects
|
|
2664
|
+
: BaseType extends {
|
|
2665
|
+
[n: number]: infer Item;
|
|
2666
|
+
length: number; // Note: This is needed to avoid being too lax with records types using number keys like `{0: string; 1: boolean}`.
|
|
2667
|
+
} ? (ConsistsOnlyOf<Key, DigitCharacter> extends true ? Strictify<Item, Options> : unknown) : Key extends keyof WithStringKeys<BaseType> ? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options> : unknown; // This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
|
2668
|
+
/**
|
|
2669
|
+
Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
|
|
2670
|
+
|
|
2671
|
+
Use-case: Retrieve a property from deep inside an API response or some other complex object.
|
|
2672
|
+
|
|
2673
|
+
@example
|
|
2674
|
+
```
|
|
2675
|
+
import type {Get} from 'type-fest';
|
|
2676
|
+
|
|
2677
|
+
declare function get<BaseType, const Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path>;
|
|
2678
|
+
|
|
2679
|
+
type ApiResponse = {
|
|
2680
|
+
hits: {
|
|
2681
|
+
hits: Array<{
|
|
2682
|
+
_id: string;
|
|
2683
|
+
_source: {
|
|
2684
|
+
name: Array<{
|
|
2685
|
+
given: string[];
|
|
2686
|
+
family: string;
|
|
2687
|
+
}>;
|
|
2688
|
+
birthDate: string;
|
|
2689
|
+
};
|
|
2690
|
+
}>;
|
|
2691
|
+
};
|
|
2692
|
+
};
|
|
2693
|
+
|
|
2694
|
+
const getName = (apiResponse: ApiResponse) => get(apiResponse, 'hits.hits[0]._source.name');
|
|
2695
|
+
//=> (apiResponse: ApiResponse) => {
|
|
2696
|
+
// given: string[];
|
|
2697
|
+
// family: string;
|
|
2698
|
+
// }[] | undefined
|
|
2699
|
+
|
|
2700
|
+
// Path also supports a readonly array of strings
|
|
2701
|
+
const getNameWithPathArray = (apiResponse: ApiResponse) => get(apiResponse, ['hits', 'hits', '0', '_source', 'name']);
|
|
2702
|
+
//=> (apiResponse: ApiResponse) => {
|
|
2703
|
+
// given: string[];
|
|
2704
|
+
// family: string;
|
|
2705
|
+
// }[] | undefined
|
|
2706
|
+
|
|
2707
|
+
// Non-strict mode:
|
|
2708
|
+
type A = Get<string[], '3', {strict: false}>;
|
|
2709
|
+
//=> string
|
|
2710
|
+
|
|
2711
|
+
type B = Get<Record<string, string>, 'foo', {strict: true}>;
|
|
2712
|
+
//=> string | undefined
|
|
2713
|
+
```
|
|
2714
|
+
|
|
2715
|
+
@category Object
|
|
2716
|
+
@category Array
|
|
2717
|
+
@category Template literal
|
|
2718
|
+
*/
|
|
2719
|
+
type Get<BaseType, Path extends readonly string[] | _LiteralStringUnion<ToString<Paths$1<BaseType, {
|
|
2720
|
+
bracketNotation: false;
|
|
2721
|
+
maxRecursionDepth: 2;
|
|
2722
|
+
}> | Paths$1<BaseType, {
|
|
2723
|
+
bracketNotation: true;
|
|
2724
|
+
maxRecursionDepth: 2;
|
|
2725
|
+
}>>>, Options extends GetOptions = {}> = GetWithPath<BaseType, Path extends string ? ToPath<Path> : Path, ApplyDefaultOptions<GetOptions, DefaultGetOptions, Options>>;
|
|
2726
|
+
//#endregion
|
|
2170
2727
|
//#region src/types/shared.d.ts
|
|
2171
2728
|
/**
|
|
2172
|
-
*
|
|
2173
|
-
* -
|
|
2174
|
-
* -
|
|
2729
|
+
* Interaction events that can trigger a validation check for a field.
|
|
2730
|
+
* - onBlur: Trigger validation when the field loses focus.
|
|
2731
|
+
* - onChange: Trigger validation when the field value is committed.
|
|
2732
|
+
* - onInput: Trigger validation on every keystroke.
|
|
2733
|
+
* - onMount: Trigger validation when the field is mounted.
|
|
2734
|
+
* - onFocus: Trigger validation when the field gains focus.
|
|
2175
2735
|
*/
|
|
2176
|
-
type
|
|
2177
|
-
/** Interaction events that can trigger a validation check for a field. */
|
|
2178
|
-
type ValidationTriggers = {
|
|
2179
|
-
/** Trigger validation when the field is blurred. */onBlur?: boolean; /** Trigger validation when the field value changes. */
|
|
2180
|
-
onChange?: boolean; /** Trigger validation when the field value is input. */
|
|
2181
|
-
onInput?: boolean; /** Trigger validation when the field is mounted. */
|
|
2182
|
-
onMount?: boolean; /** Trigger validation when the field is focused. */
|
|
2183
|
-
onFocus?: boolean;
|
|
2184
|
-
};
|
|
2736
|
+
type ValidationTrigger = 'onBlur' | 'onChange' | 'onInput' | 'onMount' | 'onFocus';
|
|
2185
2737
|
/**
|
|
2186
2738
|
* Constructs a type where all properties of the input type are optional recursively.
|
|
2187
2739
|
* @template TData The base data structure to transform.
|
|
@@ -2194,11 +2746,10 @@ type DeepPartial<TData> = PartialDeep<TData, {
|
|
|
2194
2746
|
* Constructs a type representing all possible dot-separated paths within an object.
|
|
2195
2747
|
* @template TReference The object type for which to generate paths.
|
|
2196
2748
|
*/
|
|
2197
|
-
type Paths<TReference> = Paths$1<TReference, {
|
|
2749
|
+
type Paths<TReference> = Extract<Paths$1<TReference, {
|
|
2198
2750
|
maxRecursionDepth: 10;
|
|
2199
2751
|
bracketNotation: true;
|
|
2200
|
-
|
|
2201
|
-
}> | (string & {});
|
|
2752
|
+
}>, string> | (string & {});
|
|
2202
2753
|
/**
|
|
2203
2754
|
* Represents a validation schema for object-based data structures.
|
|
2204
2755
|
* Complies with the Standard Schema specification.
|
|
@@ -2223,8 +2774,153 @@ type ArraySchema = StandardSchemaV1 & {
|
|
|
2223
2774
|
};
|
|
2224
2775
|
//#endregion
|
|
2225
2776
|
//#region src/types/use-not-form.d.ts
|
|
2226
|
-
|
|
2227
|
-
|
|
2777
|
+
/**
|
|
2778
|
+
* Configuration options for initializing a new form instance.
|
|
2779
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2780
|
+
*/
|
|
2781
|
+
type UseNotFormConfig<TSchema extends ObjectSchema> = {
|
|
2782
|
+
/** The validation schema used to parse and validate form data */schema: MaybeRefOrGetter<TSchema>; /** The initial values of the form */
|
|
2783
|
+
initialValues?: DeepPartial<StandardSchemaV1.InferInput<TSchema>>; /** The initial errors of the form */
|
|
2784
|
+
initialErrors?: StandardSchemaV1.Issue[];
|
|
2785
|
+
/**
|
|
2786
|
+
* The validation triggers of the form.
|
|
2787
|
+
* @default { onBlur: true, onChange: true, onInput: true }
|
|
2788
|
+
*/
|
|
2789
|
+
validateOn?: Partial<Record<ValidationTrigger, boolean>>;
|
|
2790
|
+
/**
|
|
2791
|
+
* Callback triggered when form validation passes and the form is submitted.
|
|
2792
|
+
* @param values The validated output data from the schema.
|
|
2793
|
+
*/
|
|
2794
|
+
onSubmit?: (values: StandardSchemaV1.InferOutput<TSchema>) => void | Promise<void>;
|
|
2795
|
+
};
|
|
2796
|
+
/**
|
|
2797
|
+
* The core state and methods provided by a form instance.
|
|
2798
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2799
|
+
*/
|
|
2800
|
+
type UseNotFormInstance<TSchema extends ObjectSchema> = Omit<UseNotFormConfig<TSchema>, 'schema' | 'onSubmit'> & {
|
|
2801
|
+
/**
|
|
2802
|
+
* A convenience self-reference to the form instance.
|
|
2803
|
+
* Useful when you prefer to destructure the composable return value but still need
|
|
2804
|
+
* to pass the full instance to NotForm or other components.
|
|
2805
|
+
* @example
|
|
2806
|
+
* const { values, submit, instance } = useNotForm({ schema, onSubmit })
|
|
2807
|
+
* // <NotForm :form="instance" />
|
|
2808
|
+
*/
|
|
2809
|
+
instance: UseNotFormInstance<TSchema>; /** Deeply reactive object of field values */
|
|
2810
|
+
values: Ref<StandardSchemaV1.InferInput<TSchema>>;
|
|
2811
|
+
/**
|
|
2812
|
+
* Updates a specific field value by path.
|
|
2813
|
+
* Also marks the field as touched and updates its dirty state.
|
|
2814
|
+
* @param path Dot-separated path to the field.
|
|
2815
|
+
* @param value The new value to apply.
|
|
2816
|
+
*/
|
|
2817
|
+
setValue: <const TPath extends Paths<StandardSchemaV1.InferInput<TSchema>>>(path: TPath, value: Get<StandardSchemaV1.InferInput<TSchema>, TPath, {
|
|
2818
|
+
strict: false;
|
|
2819
|
+
}>) => void;
|
|
2820
|
+
/**
|
|
2821
|
+
* Updates multiple field values at once.
|
|
2822
|
+
* Each path is processed through setValue individually.
|
|
2823
|
+
* @param values Partial object of field paths to new values.
|
|
2824
|
+
*/
|
|
2825
|
+
setValues: (values: DeepPartial<StandardSchemaV1.InferInput<TSchema>>) => void; /** Reactive set of field paths that have been touched */
|
|
2826
|
+
touchedFields: Ref<Set<Paths<StandardSchemaV1.InferInput<TSchema>>>>; /** Whether any field in the form has been touched */
|
|
2827
|
+
isTouched: ComputedRef<boolean>;
|
|
2828
|
+
/**
|
|
2829
|
+
* Marks a specific field as touched.
|
|
2830
|
+
* @param path Dot-separated path to the field.
|
|
2831
|
+
*/
|
|
2832
|
+
touchField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
2833
|
+
/**
|
|
2834
|
+
* Marks a specific field as not touched.
|
|
2835
|
+
* @param path Dot-separated path to the field.
|
|
2836
|
+
*/
|
|
2837
|
+
unTouchField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void; /** Marks all fields in the form as touched */
|
|
2838
|
+
touchAllFields: () => void; /** Marks all fields in the form as not touched */
|
|
2839
|
+
unTouchAllFields: () => void; /** Reactive set of field paths that have been dirtied */
|
|
2840
|
+
dirtyFields: Ref<Set<Paths<StandardSchemaV1.InferInput<TSchema>>>>; /** Whether any field in the form has been dirtied */
|
|
2841
|
+
isDirty: ComputedRef<boolean>;
|
|
2842
|
+
/**
|
|
2843
|
+
* Marks a specific field as dirty.
|
|
2844
|
+
* @param path Dot-separated path to the field.
|
|
2845
|
+
*/
|
|
2846
|
+
dirtyField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void;
|
|
2847
|
+
/**
|
|
2848
|
+
* Marks a specific field as not dirty.
|
|
2849
|
+
* @param path Dot-separated path to the field.
|
|
2850
|
+
*/
|
|
2851
|
+
unDirtyField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => void; /** Marks all fields in the form as dirty */
|
|
2852
|
+
dirtyAllFields: () => void; /** Marks all fields in the form as not dirty */
|
|
2853
|
+
unDirtyAllFields: () => void; /** The raw issues from the last validation */
|
|
2854
|
+
errors: Ref<StandardSchemaV1.Issue[]>;
|
|
2855
|
+
/**
|
|
2856
|
+
* A flat object mapping field paths to their first error message.
|
|
2857
|
+
* Useful for direct template access: errorsMap['user.email']
|
|
2858
|
+
*/
|
|
2859
|
+
errorsMap: ComputedRef<Partial<Record<Paths<StandardSchemaV1.InferInput<TSchema>>, string>>>;
|
|
2860
|
+
/**
|
|
2861
|
+
* Sets a single field error, replacing any existing error for that path.
|
|
2862
|
+
* @param error The issue to apply.
|
|
2863
|
+
*/
|
|
2864
|
+
setError: (error: StandardSchemaV1.Issue) => void;
|
|
2865
|
+
/**
|
|
2866
|
+
* Replaces all current errors with the provided issues.
|
|
2867
|
+
* @param errors The new set of issues.
|
|
2868
|
+
*/
|
|
2869
|
+
setErrors: (errors: StandardSchemaV1.Issue[]) => void; /** Removes all active validation issues */
|
|
2870
|
+
clearErrors: () => void;
|
|
2871
|
+
/**
|
|
2872
|
+
* Returns all validation issues for a specific field path.
|
|
2873
|
+
* @param path Dot-separated path to the field.
|
|
2874
|
+
*/
|
|
2875
|
+
getFieldErrors: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => StandardSchemaV1.Issue[];
|
|
2876
|
+
/**
|
|
2877
|
+
* Reactive set of field paths currently being validated.
|
|
2878
|
+
* Empty when no validation is in progress.
|
|
2879
|
+
* Populated with all paths during full-form validation.
|
|
2880
|
+
*/
|
|
2881
|
+
validatingFields: Ref<Set<Paths<StandardSchemaV1.InferInput<TSchema>>>>; /** Whether any field or the full form is currently being validated */
|
|
2882
|
+
isValidating: ComputedRef<boolean>;
|
|
2883
|
+
/**
|
|
2884
|
+
* Validates the entire form against the schema.
|
|
2885
|
+
* @returns A promise resolving to the validation result.
|
|
2886
|
+
*/
|
|
2887
|
+
validate: () => Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>;
|
|
2888
|
+
/**
|
|
2889
|
+
* Validates a specific field against the schema.
|
|
2890
|
+
* Only replaces errors for that field, leaving other fields untouched.
|
|
2891
|
+
* @param path Dot-separated path to the field.
|
|
2892
|
+
* @returns A promise resolving to the validation result.
|
|
2893
|
+
*/
|
|
2894
|
+
validateField: (path: Paths<StandardSchemaV1.InferInput<TSchema>>) => Promise<StandardSchemaV1.Result<StandardSchemaV1.InferOutput<TSchema>>>; /** Whether the form is valid */
|
|
2895
|
+
isValid: ComputedRef<boolean>; /** Whether the form is currently submitting */
|
|
2896
|
+
isSubmitting: Ref<boolean>;
|
|
2897
|
+
/**
|
|
2898
|
+
* Validates and then triggers form submission.
|
|
2899
|
+
* Marks all fields as touched and dirty before validating.
|
|
2900
|
+
* Calls onSubmit if validation passes, otherwise prevents native submission.
|
|
2901
|
+
* @param event The native form submission event.
|
|
2902
|
+
*/
|
|
2903
|
+
submit: (event: Event) => Promise<void>;
|
|
2904
|
+
/**
|
|
2905
|
+
* Resets the form to its initial or provided state.
|
|
2906
|
+
* Clears all touched and dirty fields.
|
|
2907
|
+
* If new values or errors are provided, they become the new baseline.
|
|
2908
|
+
* @param values Optional new initial values to reset to.
|
|
2909
|
+
* @param errors Optional new initial errors to reset to.
|
|
2910
|
+
*/
|
|
2911
|
+
reset: (values?: DeepPartial<StandardSchemaV1.InferInput<TSchema>>, errors?: StandardSchemaV1.Issue[]) => void;
|
|
2912
|
+
};
|
|
2913
|
+
//#endregion
|
|
2914
|
+
//#region src/types/not-form.d.ts
|
|
2915
|
+
/**
|
|
2916
|
+
* Props for the NotForm component
|
|
2917
|
+
* @template TSchema The validation schema type derived from ObjectSchema.
|
|
2918
|
+
*/
|
|
2919
|
+
type NotFormProps<TSchema extends ObjectSchema> = {
|
|
2920
|
+
/** The form instance to use */instance: UseNotFormInstance<TSchema>;
|
|
2921
|
+
};
|
|
2922
|
+
type NotFormSlots<TSchema extends ObjectSchema> = {
|
|
2923
|
+
/** The default slot */default: (instance: UseNotFormInstance<TSchema>) => [];
|
|
2228
2924
|
};
|
|
2229
2925
|
//#endregion
|
|
2230
|
-
export { ArraySchema, DeepPartial, ObjectSchema, Paths,
|
|
2926
|
+
export { ArraySchema, DeepPartial, NotFormProps, NotFormSlots, ObjectSchema, Paths, UseNotFormConfig, UseNotFormInstance, ValidationTrigger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notform",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Vue Forms Without the Friction",
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@standard-schema/spec": "^1.1.0",
|
|
46
|
-
"
|
|
46
|
+
"dequal": "^2.0.3",
|
|
47
|
+
"dot-prop": "^10.1.0",
|
|
48
|
+
"klona": "^2.0.6"
|
|
47
49
|
},
|
|
48
50
|
"keywords": [
|
|
49
51
|
"notform",
|
|
@@ -57,6 +59,7 @@
|
|
|
57
59
|
"node": ">=24.13.0"
|
|
58
60
|
},
|
|
59
61
|
"inlinedDependencies": {
|
|
62
|
+
"tagged-tag": "1.0.0",
|
|
60
63
|
"type-fest": "5.5.0"
|
|
61
64
|
},
|
|
62
65
|
"scripts": {
|