@codeleap/form 6.3.0 → 7.0.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/fields/bool.d.ts +17 -0
- package/dist/fields/bool.d.ts.map +1 -0
- package/dist/fields/date.d.ts +22 -0
- package/dist/fields/date.d.ts.map +1 -0
- package/dist/fields/file.d.ts +17 -0
- package/dist/fields/file.d.ts.map +1 -0
- package/dist/fields/group.d.ts +17 -0
- package/dist/fields/group.d.ts.map +1 -0
- package/dist/fields/index.d.ts +87 -0
- package/dist/fields/index.d.ts.map +1 -0
- package/dist/fields/list.d.ts +34 -0
- package/dist/fields/list.d.ts.map +1 -0
- package/dist/fields/number.d.ts +23 -0
- package/dist/fields/number.d.ts.map +1 -0
- package/dist/fields/selectable.d.ts +25 -0
- package/dist/fields/selectable.d.ts.map +1 -0
- package/dist/fields/text.d.ts +21 -0
- package/dist/fields/text.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/useField.d.ts +16 -0
- package/dist/hooks/useField.d.ts.map +1 -0
- package/dist/hooks/useValidate.d.ts +23 -0
- package/dist/hooks/useValidate.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/Field.d.ts +193 -0
- package/dist/lib/Field.d.ts.map +1 -0
- package/dist/lib/Form.d.ts +88 -0
- package/dist/lib/Form.d.ts.map +1 -0
- package/dist/lib/factories.d.ts +14 -0
- package/dist/lib/factories.d.ts.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/useFieldBinding.d.ts +14 -0
- package/dist/lib/useFieldBinding.d.ts.map +1 -0
- package/dist/types/field.d.ts +22 -0
- package/dist/types/field.d.ts.map +1 -0
- package/dist/types/form.d.ts +26 -0
- package/dist/types/form.d.ts.map +1 -0
- package/dist/types/globals.d.ts +15 -0
- package/dist/types/globals.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/validation.d.ts +9 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/dist/validators/index.d.ts +2 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/zod.d.ts +22 -0
- package/dist/validators/zod.d.ts.map +1 -0
- package/package.json +26 -10
- package/src/fields/bool.ts +6 -0
- package/src/fields/date.ts +9 -0
- package/src/fields/file.ts +7 -0
- package/src/fields/group.ts +6 -0
- package/src/fields/index.ts +17 -2
- package/src/fields/list.ts +66 -17
- package/src/fields/number.ts +9 -0
- package/src/fields/selectable.ts +9 -0
- package/src/fields/text.ts +8 -1
- package/src/hooks/useField.ts +13 -0
- package/src/hooks/useValidate.ts +16 -0
- package/src/lib/Field.ts +166 -22
- package/src/lib/Form.ts +98 -13
- package/src/lib/factories.tsx +8 -0
- package/src/lib/useFieldBinding.ts +13 -2
- package/src/types/globals.ts +6 -2
- package/src/validators/zod.ts +16 -1
- package/package.json.bak +0 -30
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
type VALUE = boolean;
|
|
4
|
+
/** Validator signature for boolean-valued fields. */
|
|
5
|
+
export type BooleanValidator<R = any, Err = any> = Validator<VALUE, R, Err>;
|
|
6
|
+
type BooleanFieldOptions<Validate extends BooleanValidator> = FieldOptions<VALUE, Validate>;
|
|
7
|
+
/**
|
|
8
|
+
* Field for boolean values (checkboxes, toggles). `Form.setValues` treats
|
|
9
|
+
* this field specially: it will only set a value when the incoming value is
|
|
10
|
+
* strictly `boolean`, because falsy coercion would prevent setting `false`.
|
|
11
|
+
*/
|
|
12
|
+
export declare class BooleanField<Validate extends BooleanValidator> extends Field<boolean, Validate> {
|
|
13
|
+
_type: string;
|
|
14
|
+
constructor(options: BooleanFieldOptions<Validate>);
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=bool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bool.d.ts","sourceRoot":"","sources":["../../src/fields/bool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGlD,KAAK,KAAK,GAAG,OAAO,CAAA;AAEpB,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAE3E,KAAK,mBAAmB,CAAC,QAAQ,SAAS,gBAAgB,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAE3F;;;;GAIG;AACH,qBAAa,YAAY,CAAC,QAAQ,SAAS,gBAAgB,CAAE,SAAQ,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3F,KAAK,SAAY;gBAEL,OAAO,EAAE,mBAAmB,CAAC,QAAQ,CAAC;CAMnD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
/** Validator signature for `Date`-valued fields. */
|
|
4
|
+
export type DateValidator<R = any, Err = any> = Validator<Date, R, Err>;
|
|
5
|
+
type DateFieldOptions<Validate extends DateValidator> = FieldOptions<Date, Validate> & {
|
|
6
|
+
minimumDate?: Date;
|
|
7
|
+
maximumDate?: Date;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Field for `Date` values with optional `minimumDate` / `maximumDate` bounds.
|
|
11
|
+
* The built-in validator normalises the raw input via `dayjs` before running
|
|
12
|
+
* boundary checks, so it transparently accepts `Date` objects, dayjs instances,
|
|
13
|
+
* and ISO date strings. Invalid or unparseable values are normalised to
|
|
14
|
+
* `undefined`, which fails the `z.date()` check. Bounds are enforced at the
|
|
15
|
+
* start of the day (`startOf('day')`) for dayjs inputs.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DateField<Validate extends DateValidator> extends Field<Date, Validate> {
|
|
18
|
+
_type: string;
|
|
19
|
+
constructor(options: DateFieldOptions<Validate>);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/fields/date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAIlD,oDAAoD;AACpD,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAEvE,KAAK,gBAAgB,CAAC,QAAQ,SAAS,aAAa,IAAI,YAAY,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG;IACrF,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,WAAW,CAAC,EAAE,IAAI,CAAA;CACnB,CAAA;AAeD;;;;;;;GAOG;AACH,qBAAa,SAAS,CAAC,QAAQ,SAAS,aAAa,CAAE,SAAQ,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;IAClF,KAAK,SAAS;gBAEF,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC;CAsBhD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
/** Validator signature for file-valued fields. The value type is intentionally `any` to accommodate platform-specific file objects (web `File`, React Native asset objects, etc.). */
|
|
4
|
+
export type FileValidator<R = any, Err = any> = Validator<any, R, Err>;
|
|
5
|
+
type FileFieldOptions<Validate extends FileValidator> = FieldOptions<any, Validate>;
|
|
6
|
+
/**
|
|
7
|
+
* Field for file uploads. The value type is `any` because the shape of a
|
|
8
|
+
* "file" differs between web (`File` / `FileList`) and React Native (asset
|
|
9
|
+
* descriptor objects). Supply a custom `validate` function to enforce whatever
|
|
10
|
+
* shape your platform produces.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FileField<Validate extends FileValidator> extends Field<any, Validate> {
|
|
13
|
+
_type: string;
|
|
14
|
+
constructor(options: FileFieldOptions<Validate>);
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/fields/file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGlD,sLAAsL;AACtL,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAEtE,KAAK,gBAAgB,CAAC,QAAQ,SAAS,aAAa,IAAI,YAAY,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AAEnF;;;;;GAKG;AACH,qBAAa,SAAS,CAAC,QAAQ,SAAS,aAAa,CAAE,SAAQ,KAAK,CAAC,GAAG,EAAE,QAAQ,CAAC;IACjF,KAAK,SAAS;gBAEF,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC;CAMhD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
type VALUE = string;
|
|
4
|
+
type GroupValidator<R = any, Err = any> = Validator<VALUE, R, Err>;
|
|
5
|
+
type GroupFieldOptions<Validate extends GroupValidator> = FieldOptions<VALUE, Validate>;
|
|
6
|
+
/**
|
|
7
|
+
* Field that represents a selected group or category, stored as a string key.
|
|
8
|
+
* Structurally identical to `TextField` but carries the `"group"` type tag so
|
|
9
|
+
* platform renderers can distinguish it and render a group-picker control
|
|
10
|
+
* instead of a free-text input.
|
|
11
|
+
*/
|
|
12
|
+
export declare class GroupField<Validate extends GroupValidator> extends Field<string, Validate> {
|
|
13
|
+
_type: string;
|
|
14
|
+
constructor(options: GroupFieldOptions<Validate>);
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=group.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../src/fields/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGlD,KAAK,KAAK,GAAG,MAAM,CAAA;AAEnB,KAAK,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAElE,KAAK,iBAAiB,CAAC,QAAQ,SAAS,cAAc,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAEvF;;;;;GAKG;AACH,qBAAa,UAAU,CAAC,QAAQ,SAAS,cAAc,CAAE,SAAQ,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC;IACtF,KAAK,SAAU;gBAEH,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC;CAMjD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TextField } from "./text";
|
|
2
|
+
import { ListField, listFieldFactory } from "./list";
|
|
3
|
+
import { NumberField } from "./number";
|
|
4
|
+
import { BooleanField } from "./bool";
|
|
5
|
+
import { SelectableField } from "./selectable";
|
|
6
|
+
import { DateField } from "./date";
|
|
7
|
+
import { FileField } from "./file";
|
|
8
|
+
/**
|
|
9
|
+
* Convenience namespace that exposes factory functions for every built-in field
|
|
10
|
+
* type. Prefer these over calling constructors directly — they provide better
|
|
11
|
+
* generic inference for the `validate` option.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* const emailField = fields.text({ validate: zodValidator(z.string().email()) })
|
|
15
|
+
* const tagsField = fields.list({ item: fields.text(), defaultValue: [] })
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Note: `fields.list` is the only entry that is not wrapped with
|
|
19
|
+
* `fieldFactory`, because `ListField` requires the `item` option's type to be
|
|
20
|
+
* inferred at the call site.
|
|
21
|
+
*/
|
|
22
|
+
export declare const fields: {
|
|
23
|
+
text: <A extends {
|
|
24
|
+
name?: string;
|
|
25
|
+
defaultValue?: string | null | undefined;
|
|
26
|
+
state?: import("nanostores").WritableAtom<string> | undefined;
|
|
27
|
+
validate?: import("./text").TextValidator<any, any> | undefined;
|
|
28
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<string, import("./text").TextValidator<any, any>>, "loader">>) | undefined;
|
|
29
|
+
onValueChange?: ((newValue: string) => void) | undefined;
|
|
30
|
+
} & import("..").ExtraFieldOptions & {
|
|
31
|
+
secure?: boolean;
|
|
32
|
+
multiline?: boolean;
|
|
33
|
+
}>(options?: A | undefined) => import("..").Field<string, A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<string, infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<string, any, infer E> ? E : never : never : never>;
|
|
34
|
+
list: typeof listFieldFactory;
|
|
35
|
+
number: <A extends {
|
|
36
|
+
name?: string;
|
|
37
|
+
defaultValue?: number | number[] | null | undefined;
|
|
38
|
+
state?: import("..").FieldState<number | number[]> | undefined;
|
|
39
|
+
validate?: import("./number").NumberValidator<any, any> | undefined;
|
|
40
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<number | number[], import("./number").NumberValidator<any, any>>, "loader">>) | undefined;
|
|
41
|
+
onValueChange?: ((newValue: number | number[]) => void) | undefined;
|
|
42
|
+
} & import("..").ExtraFieldOptions & {
|
|
43
|
+
min?: number;
|
|
44
|
+
max?: number;
|
|
45
|
+
}>(options?: A | undefined) => import("..").Field<number | number[], A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<number | number[], infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<number | number[], any, infer E> ? E : never : never : never>;
|
|
46
|
+
boolean: <A extends {
|
|
47
|
+
name?: string;
|
|
48
|
+
defaultValue?: boolean | null | undefined;
|
|
49
|
+
state?: import("nanostores").WritableAtom<boolean> | undefined;
|
|
50
|
+
validate?: import("./bool").BooleanValidator<any, any> | undefined;
|
|
51
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<boolean, import("./bool").BooleanValidator<any, any>>, "loader">>) | undefined;
|
|
52
|
+
onValueChange?: ((newValue: boolean) => void) | undefined;
|
|
53
|
+
} & import("..").ExtraFieldOptions>(options?: A | undefined) => import("..").Field<boolean, A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<boolean, infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<boolean, any, infer E> ? E : never : never : never>;
|
|
54
|
+
selectable: <A extends {
|
|
55
|
+
name?: string;
|
|
56
|
+
defaultValue?: (string | number) | null | undefined;
|
|
57
|
+
state?: import("nanostores").WritableAtom<string | number> | undefined;
|
|
58
|
+
validate?: import("./selectable").SelectableValidator<string | number, any, any> | undefined;
|
|
59
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<string | number, import("./selectable").SelectableValidator<string | number, any, any>>, "loader">>) | undefined;
|
|
60
|
+
onValueChange?: ((newValue: string | number) => void) | undefined;
|
|
61
|
+
} & import("..").ExtraFieldOptions & {
|
|
62
|
+
options: import("@codeleap/types").Options<string | number>;
|
|
63
|
+
minItems?: number;
|
|
64
|
+
maxItems?: number;
|
|
65
|
+
}>(options?: A | undefined) => import("..").Field<string | number, A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<string | number, infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<string | number, any, infer E> ? E : never : never : never>;
|
|
66
|
+
date: <A extends {
|
|
67
|
+
name?: string;
|
|
68
|
+
defaultValue?: Date | null | undefined;
|
|
69
|
+
state?: import("..").FieldState<Date> | undefined;
|
|
70
|
+
validate?: import("./date").DateValidator<any, any> | undefined;
|
|
71
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<Date, import("./date").DateValidator<any, any>>, "loader">>) | undefined;
|
|
72
|
+
onValueChange?: ((newValue: Date) => void) | undefined;
|
|
73
|
+
} & import("..").ExtraFieldOptions & {
|
|
74
|
+
minimumDate?: Date;
|
|
75
|
+
maximumDate?: Date;
|
|
76
|
+
}>(options?: A | undefined) => import("..").Field<Date, A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<Date, infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<Date, any, infer E> ? E : never : never : never>;
|
|
77
|
+
file: <A extends {
|
|
78
|
+
name?: string;
|
|
79
|
+
defaultValue?: any;
|
|
80
|
+
state?: import("..").FieldState<any> | undefined;
|
|
81
|
+
validate?: import("./file").FileValidator<any, any> | undefined;
|
|
82
|
+
loader?: ((form: any) => Partial<Omit<import("..").FieldOptions<any, import("./file").FileValidator<any, any>>, "loader">>) | undefined;
|
|
83
|
+
onValueChange?: ((newValue: any) => void) | undefined;
|
|
84
|
+
} & import("..").ExtraFieldOptions>(options?: A | undefined) => import("..").Field<any, A["validate"], A["validate"] extends infer T ? T extends A["validate"] ? T extends import("..").Validator<any, infer R, any> ? R : never : never : never, A["validate"] extends infer T_1 ? T_1 extends A["validate"] ? T_1 extends import("..").Validator<any, any, infer E> ? E : never : never : never>;
|
|
85
|
+
};
|
|
86
|
+
export { TextField, ListField, NumberField, BooleanField, SelectableField, DateField, FileField, };
|
|
87
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fields/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAE,SAAS,EAAG,gBAAgB,EAAC,MAAM,QAAQ,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGlC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQlB,CAAA;AAED,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,EACX,YAAY,EACZ,eAAe,EACf,SAAS,EACT,SAAS,GACV,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
/** Validator signature for array-valued fields. `R` and `Err` are the result and error types for the whole list, not individual items. */
|
|
4
|
+
export type ListValidator<Val, R = any, Err = any> = Validator<Val[], R, Err>;
|
|
5
|
+
type ExtractFieldValue<T> = T extends Field<infer Value, any> ? Value : never;
|
|
6
|
+
type AsListValidator<T> = T extends Field<infer Value, infer Validate> ? Validator<Value[], Validate extends Validator<any, infer R, any> ? R[] : never, Validate extends Validator<any, any, infer Err> ? Err[] : never> : never;
|
|
7
|
+
export type _ListFieldOptions<T> = T extends Field<infer Value, infer Validate> ? FieldOptions<Value[], Validator<Value[], Validate extends Validator<any, infer R, any> ? R[] : never, Validate extends Validator<any, any, infer Err> ? Err[] : never>> : never;
|
|
8
|
+
export type ListFieldOptions<ItemField extends Field<any, any>> = {
|
|
9
|
+
item: ItemField;
|
|
10
|
+
} & _ListFieldOptions<ItemField>;
|
|
11
|
+
/**
|
|
12
|
+
* Field that holds an array of values, each validated by a delegate `item`
|
|
13
|
+
* field. The built-in validator iterates every element through
|
|
14
|
+
* `options.item.validate` and collects all failures into an error array. The
|
|
15
|
+
* list is considered valid only when every element passes. If `item` has no
|
|
16
|
+
* validator, the list is always valid.
|
|
17
|
+
*
|
|
18
|
+
* The `item` field acts as a prototype — it is not mounted independently and
|
|
19
|
+
* does not own its own atom. Do not call `use()` on it directly.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ListField<T extends Field<any, any>> extends Field<ExtractFieldValue<T>[], AsListValidator<T>> {
|
|
22
|
+
_type: string;
|
|
23
|
+
constructor(options: ListFieldOptions<T>);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Convenience factory for `ListField`. Unlike `fieldFactory`-based helpers,
|
|
27
|
+
* `ListField` requires an `item` option whose generic type must be inferred at
|
|
28
|
+
* the call site, so it cannot share the same factory wrapper. This function
|
|
29
|
+
* exists to provide a consistent `fields.list(...)` call signature alongside
|
|
30
|
+
* the other entries in the `fields` namespace.
|
|
31
|
+
*/
|
|
32
|
+
export declare function listFieldFactory<T extends Field<any, any>>(options: ListFieldOptions<T>): ListField<T>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/fields/list.ts"],"names":[],"mappings":"A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,IAAI;IAChE,IAAI,EAAE,SAAS,CAAA;CAChB,GAAI,iBAAiB,CAAC,SAAS,CAAC,CAAA;AAEjC;;;;;;;;;GASG;AACH,qBAAa,SAAS,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAE,SAAQ,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACzG,KAAK,SAAS;gBAEF,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;CA+BzC;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,EAAC,GAAG,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAErG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
/** Validator signature for numeric fields. Accepts either a single number or an array of numbers (for range inputs). */
|
|
4
|
+
export type NumberValidator<R = any, Err = any> = Validator<number | number[], R, Err>;
|
|
5
|
+
type Props = {
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
};
|
|
9
|
+
type NumberFieldOptions<Validate extends NumberValidator> = FieldOptions<number | number[], Validate> & Props;
|
|
10
|
+
/**
|
|
11
|
+
* Field for numeric values. Supports both single numbers and arrays of numbers
|
|
12
|
+
* (range / multi-handle sliders) — the mode is inferred from whether
|
|
13
|
+
* `defaultValue` is an array. `min` defaults to `0` and `max` defaults to
|
|
14
|
+
* `1_000_000_000_000_000` (the maximum safe integer range the underlying input
|
|
15
|
+
* supports for arithmetic operations). Values outside the range fail
|
|
16
|
+
* validation.
|
|
17
|
+
*/
|
|
18
|
+
export declare class NumberField<Validate extends NumberValidator> extends Field<number | number[], Validate> {
|
|
19
|
+
_type: string;
|
|
20
|
+
constructor(options: NumberFieldOptions<Validate>);
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/fields/number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGlD,wHAAwH;AACxH,MAAM,MAAM,eAAe,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAEtF,KAAK,KAAK,GAAG;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,kBAAkB,CAAC,QAAQ,SAAS,eAAe,IAAI,YAAY,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAA;AAI7G;;;;;;;GAOG;AACH,qBAAa,WAAW,CAAC,QAAQ,SAAS,eAAe,CAAE,SAAQ,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,CAAC;IACnG,KAAK,SAAW;gBAEJ,OAAO,EAAE,kBAAkB,CAAC,QAAQ,CAAC;CAelD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
import { Options } from '@codeleap/types';
|
|
4
|
+
type VALUE = string | number;
|
|
5
|
+
/** Validator signature for selectable fields whose value is a `string` or `number` key. */
|
|
6
|
+
export type SelectableValidator<V extends VALUE, R = any, Err = any> = Validator<V, R, Err>;
|
|
7
|
+
type SelectableFieldOptions<V extends VALUE, Validate extends SelectableValidator<V>> = FieldOptions<V, Validate> & {
|
|
8
|
+
options: Options<V>;
|
|
9
|
+
minItems?: number;
|
|
10
|
+
maxItems?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Field for single or multi-select inputs whose options are a fixed list of
|
|
14
|
+
* string/number keys. `minItems` defaults to `1` (at least one selection
|
|
15
|
+
* required) and `maxItems` defaults to the length of the provided `options`
|
|
16
|
+
* array (all items selectable). The built-in validator accepts either a single
|
|
17
|
+
* value or an array, so the same field type covers both radio-style and
|
|
18
|
+
* checkbox-style UIs.
|
|
19
|
+
*/
|
|
20
|
+
export declare class SelectableField<V extends VALUE, Validate extends SelectableValidator<V>> extends Field<V, Validate> {
|
|
21
|
+
_type: string;
|
|
22
|
+
constructor(options: SelectableFieldOptions<V, Validate>);
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=selectable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectable.d.ts","sourceRoot":"","sources":["../../src/fields/selectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAEzC,KAAK,KAAK,GAAG,MAAM,GAAG,MAAM,CAAA;AAE5B,2FAA2F;AAC3F,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,KAAK,EAAE,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAE3F,KAAK,sBAAsB,CAAC,CAAC,SAAS,KAAK,EAAE,QAAQ,SAAS,mBAAmB,CAAC,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;IAClH,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;;;;;;GAOG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS,KAAK,EAAE,QAAQ,SAAS,mBAAmB,CAAC,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;IAC/G,KAAK,SAAe;gBAER,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,QAAQ,CAAC;CAYzD"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Field } from "../lib/Field";
|
|
2
|
+
import { FieldOptions, Validator } from "../types";
|
|
3
|
+
type VALUE = string;
|
|
4
|
+
/** Validator signature for string-valued fields. */
|
|
5
|
+
export type TextValidator<R = any, Err = any> = Validator<VALUE, R, Err>;
|
|
6
|
+
type TextFieldOptions<Validate extends TextValidator> = FieldOptions<VALUE, Validate> & {
|
|
7
|
+
secure?: boolean;
|
|
8
|
+
multiline?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Field for plain string values. Ships with a `z.string()` fallback validator
|
|
12
|
+
* so the field is always valid when no custom `validate` option is provided.
|
|
13
|
+
* Accepts `secure` (password masking) and `multiline` hints that are forwarded
|
|
14
|
+
* as props to the underlying input component.
|
|
15
|
+
*/
|
|
16
|
+
export declare class TextField<Validate extends TextValidator> extends Field<string, Validate> {
|
|
17
|
+
_type: string;
|
|
18
|
+
constructor(options: TextFieldOptions<Validate>);
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/fields/text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGlD,KAAK,KAAK,GAAG,MAAM,CAAA;AAEnB,oDAAoD;AACpD,MAAM,MAAM,aAAa,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAExE,KAAK,gBAAgB,CAAC,QAAQ,SAAS,aAAa,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG;IACtF,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED;;;;;GAKG;AACH,qBAAa,SAAS,CAAC,QAAQ,SAAS,aAAa,CAAE,SAAQ,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC;IACpF,KAAK,SAAS;gBAEF,OAAO,EAAE,gBAAgB,CAAC,QAAQ,CAAC;CAMhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Field } from "../lib";
|
|
2
|
+
/**
|
|
3
|
+
* Convenience hook for components that accept an optional `field` prop. When
|
|
4
|
+
* `field` is provided it is used directly; when it is absent (falsy), a
|
|
5
|
+
* temporary field created by `defaultField` is memoised for the component's
|
|
6
|
+
* lifetime.
|
|
7
|
+
*
|
|
8
|
+
* This lets components remain uncontrolled by default (using their own
|
|
9
|
+
* internal field) while still accepting external control when a `field` prop
|
|
10
|
+
* is supplied — without conditional hook calls.
|
|
11
|
+
*
|
|
12
|
+
* `params` are forwarded to `field.use()` in either branch, so imperative
|
|
13
|
+
* ref bindings work regardless of which field is active.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useField<V, T extends Field<V, any, any>>(field: T, params: Parameters<T['use']>, defaultField: () => T): ReturnType<T['use']>;
|
|
16
|
+
//# sourceMappingURL=useField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useField.d.ts","sourceRoot":"","sources":["../../src/hooks/useField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAEnC;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAU7I"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Validator } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Standalone validation hook for values managed outside a `Field` instance.
|
|
4
|
+
* Useful when you have a raw state value and a validator function but do not
|
|
5
|
+
* want to create a full `Field` object.
|
|
6
|
+
*
|
|
7
|
+
* Error display follows the same blur policy as `Field.useValidation`: if
|
|
8
|
+
* `value` is `undefined` on the first render (`startedUnset`), the error is
|
|
9
|
+
* hidden until the user has blurred the input. Call the returned
|
|
10
|
+
* `onInputBlurred` handler on the input's blur event to trigger visibility.
|
|
11
|
+
*
|
|
12
|
+
* `message` is resolved from `readableError` first, then from the first
|
|
13
|
+
* element's `.message` when `error` is an array.
|
|
14
|
+
*
|
|
15
|
+
* A {@link ValidationError} thrown by `providedValidate` is caught and
|
|
16
|
+
* normalised; other exceptions propagate.
|
|
17
|
+
*/
|
|
18
|
+
export declare const useValidate: <T, V extends Validator<T, any, any>>(value: T, providedValidate: V) => {
|
|
19
|
+
onInputBlurred: () => void;
|
|
20
|
+
showError: boolean;
|
|
21
|
+
message: any;
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useValidate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useValidate.d.ts","sourceRoot":"","sources":["../../src/hooks/useValidate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,SAAS,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,CAAC;;;;CA6C7F,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,OAAO,CAAA;AACrB,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { FieldState, FieldOptions, FieldMeasureResult } from '../types/field';
|
|
2
|
+
import { ValidationResult, Validator } from '../types/validation';
|
|
3
|
+
import { IFieldRef, IFieldProps, PropTransformer } from '../types/globals';
|
|
4
|
+
import { WritableAtom } from 'nanostores';
|
|
5
|
+
import { AnyRecord, SecondToLastArguments } from '@codeleap/types';
|
|
6
|
+
import { useFieldBinding } from './useFieldBinding';
|
|
7
|
+
/**
|
|
8
|
+
* Thrown inside a validator function to signal a structured validation failure
|
|
9
|
+
* without propagating as an unhandled exception. The `data` payload is forwarded
|
|
10
|
+
* verbatim as the `error` field of the resulting {@link ValidationResult}.
|
|
11
|
+
*
|
|
12
|
+
* Throw this instead of returning `{ isValid: false }` when you need to exit
|
|
13
|
+
* validation from a nested helper that cannot easily return a value.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ValidationError extends Error {
|
|
16
|
+
data: any;
|
|
17
|
+
constructor(data: any);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Base class for all form fields. Owns the nanostores atom that holds the
|
|
21
|
+
* field's current value, runs synchronous validation on demand, and exposes
|
|
22
|
+
* React hooks (`use`, `useValue`, `useValidation`) that components call to
|
|
23
|
+
* subscribe to reactive updates.
|
|
24
|
+
*
|
|
25
|
+
* **Validation lifecycle**
|
|
26
|
+
* Validation is always synchronous and called eagerly — there is no deferred
|
|
27
|
+
* or debounced step. `validate()` runs against the current atom value each
|
|
28
|
+
* time it is called, so repeated calls are cheap but not memoised. Error
|
|
29
|
+
* visibility is decoupled from validity: errors are hidden until
|
|
30
|
+
* `revealError()` is called (or the field has been blurred while starting
|
|
31
|
+
* with an undefined value), allowing UX to control when messages appear.
|
|
32
|
+
*
|
|
33
|
+
* **Initialization order constraint**
|
|
34
|
+
* The constructor calls `loadState()` synchronously. If `defaultValue` is a
|
|
35
|
+
* Promise or a function that returns a Promise, the atom is initialised with
|
|
36
|
+
* `undefined` immediately and the resolved value is set asynchronously once
|
|
37
|
+
* the promise settles. Do not read `initialValue` before the promise resolves.
|
|
38
|
+
*
|
|
39
|
+
* **Platform methods**
|
|
40
|
+
* `measurePosition`, `scrollTo`, and `getPadding` delegate to static method
|
|
41
|
+
* slots (`methodMeasurePosition`, `methodScrollTo`, `methodGetPadding`) that
|
|
42
|
+
* must be assigned by the platform layer (web or mobile) before use; calling
|
|
43
|
+
* them without an implementation throws.
|
|
44
|
+
*
|
|
45
|
+
* **Prop transformers**
|
|
46
|
+
* `props()` pipes the field's properties through every registered transformer
|
|
47
|
+
* in insertion order. Transformers are global and shared across all field
|
|
48
|
+
* instances via `Field.transformers`.
|
|
49
|
+
*/
|
|
50
|
+
export declare class Field<T, Validate extends Validator<T, any, any>, Result = Validate extends Validator<T, infer R, any> ? R : never, Err = Validate extends Validator<T, any, infer E> ? E : never> {
|
|
51
|
+
_type: string;
|
|
52
|
+
deep: boolean;
|
|
53
|
+
state: FieldState<T>;
|
|
54
|
+
errorRevealed: WritableAtom<boolean>;
|
|
55
|
+
properties: AnyRecord;
|
|
56
|
+
static transformers: Map<string, PropTransformer>;
|
|
57
|
+
options: FieldOptions<T, Validate>;
|
|
58
|
+
ref?: React.RefObject<IFieldRef<T> | null>;
|
|
59
|
+
__validationRes: ValidationResult<Result, Err>;
|
|
60
|
+
private initialValue;
|
|
61
|
+
static enableLogs: boolean;
|
|
62
|
+
static getProps: (field: Field<any, any>) => never;
|
|
63
|
+
static methodMeasurePosition: (field: Field<any, any>, wrapperRef: any) => Promise<FieldMeasureResult>;
|
|
64
|
+
static methodScrollTo: (field: Field<any, any>, scrollRef: any, measure: FieldMeasureResult) => Promise<void>;
|
|
65
|
+
static methodGetPadding: (field: Field<any, any>) => number;
|
|
66
|
+
/**
|
|
67
|
+
* Marks the field's error as visible. Typically called by `Form.validate`
|
|
68
|
+
* when `revealErrors: true` is passed, or imperatively after a failed submit.
|
|
69
|
+
* Has no effect on the underlying validity — only on whether the error
|
|
70
|
+
* message is shown to the user.
|
|
71
|
+
*/
|
|
72
|
+
revealError(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Resets error visibility to hidden without changing the field's value or
|
|
75
|
+
* validity state. Useful when clearing a form section programmatically
|
|
76
|
+
* while preserving the current value.
|
|
77
|
+
*/
|
|
78
|
+
hideError(): void;
|
|
79
|
+
get isErrorRevealed(): boolean;
|
|
80
|
+
constructor(options: FieldOptions<T, Validate>);
|
|
81
|
+
get name(): string | undefined;
|
|
82
|
+
get value(): T;
|
|
83
|
+
get isValid(): boolean;
|
|
84
|
+
private toInternalProperties;
|
|
85
|
+
/**
|
|
86
|
+
* Replaces the field's internal atom with a slice of the owning `Form`'s
|
|
87
|
+
* global state atom and migrates the current value into it. Called
|
|
88
|
+
* automatically by `Form.attachState()` during construction — do not call
|
|
89
|
+
* this manually unless you are building a custom form container.
|
|
90
|
+
*/
|
|
91
|
+
attach(to: FieldState<T>): void;
|
|
92
|
+
setValue(to: T): void;
|
|
93
|
+
useValue(): T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
94
|
+
resetValue(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Primary React hook for consuming a field inside a component. Subscribes to
|
|
97
|
+
* the field's value atom and validation state, and optionally wires an
|
|
98
|
+
* imperative ref handle via `useFieldBinding`. Must be called
|
|
99
|
+
* unconditionally at the component's top level.
|
|
100
|
+
*
|
|
101
|
+
* The `changed` flag compares the current value to the value captured at
|
|
102
|
+
* field construction time (or after the last `resetValue`), not to any
|
|
103
|
+
* previous render.
|
|
104
|
+
*/
|
|
105
|
+
use(impl?: Partial<IFieldRef<T>>, deps?: any[]): {
|
|
106
|
+
validation: {
|
|
107
|
+
onInputBlurred(): void;
|
|
108
|
+
hasBlurred: boolean;
|
|
109
|
+
hasChanged: boolean;
|
|
110
|
+
startedUnset: boolean;
|
|
111
|
+
isSet: boolean;
|
|
112
|
+
isInvalid: boolean;
|
|
113
|
+
isValid: boolean;
|
|
114
|
+
message: any;
|
|
115
|
+
showError: boolean;
|
|
116
|
+
isUnset: boolean;
|
|
117
|
+
validation: ValidationResult<Result, Err>;
|
|
118
|
+
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
119
|
+
};
|
|
120
|
+
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
121
|
+
setValue: (to: T) => void;
|
|
122
|
+
changed: boolean;
|
|
123
|
+
representation: any;
|
|
124
|
+
options: FieldOptions<T, Validate>;
|
|
125
|
+
};
|
|
126
|
+
useBinding(...args: SecondToLastArguments<typeof useFieldBinding<T>>): void;
|
|
127
|
+
changed(): boolean;
|
|
128
|
+
loadState(): Promise<void>;
|
|
129
|
+
formatLog(...args: any[]): any[];
|
|
130
|
+
/**
|
|
131
|
+
* Runs the field's validator synchronously against `value` (or the current
|
|
132
|
+
* atom value when omitted). A {@link ValidationError} thrown inside the
|
|
133
|
+
* validator is caught and converted to `{ isValid: false, error: e.data }`;
|
|
134
|
+
* any other exception is re-thrown.
|
|
135
|
+
*
|
|
136
|
+
* This method is called on every render inside `useValidation` — keep
|
|
137
|
+
* validators fast and free of side effects.
|
|
138
|
+
*/
|
|
139
|
+
validate(value?: any): ValidationResult<Result, Err>;
|
|
140
|
+
/**
|
|
141
|
+
* React hook that returns reactive validation state for the field's current
|
|
142
|
+
* value. Error display policy:
|
|
143
|
+
* - If the field started with an `undefined` value (`startedUnset`), the
|
|
144
|
+
* error is hidden until the user has blurred the input **or** until
|
|
145
|
+
* `revealError()` has been called.
|
|
146
|
+
* - If the field started with a defined value, the error is shown
|
|
147
|
+
* immediately whenever the field is invalid.
|
|
148
|
+
*
|
|
149
|
+
* `message` is resolved from `readableError` first, falling back to the
|
|
150
|
+
* first element's `.message` when `error` is an array.
|
|
151
|
+
*/
|
|
152
|
+
useValidation(): {
|
|
153
|
+
onInputBlurred(): void;
|
|
154
|
+
hasBlurred: boolean;
|
|
155
|
+
hasChanged: boolean;
|
|
156
|
+
startedUnset: boolean;
|
|
157
|
+
isSet: boolean;
|
|
158
|
+
isInvalid: boolean;
|
|
159
|
+
isValid: boolean;
|
|
160
|
+
message: any;
|
|
161
|
+
showError: boolean;
|
|
162
|
+
isUnset: boolean;
|
|
163
|
+
validation: ValidationResult<Result, Err>;
|
|
164
|
+
value: T | import("nanostores").StoreValue<T extends object ? import("nanostores").MapStore<T> : never>;
|
|
165
|
+
};
|
|
166
|
+
log(level?: string, ...args: any[]): void;
|
|
167
|
+
toInternalValue(v: any): T;
|
|
168
|
+
toRepresentation(v: T): any;
|
|
169
|
+
/**
|
|
170
|
+
* Registers a global prop transformer under `key`. Transformers are applied
|
|
171
|
+
* in insertion order by `props()`. Re-registering an existing key replaces
|
|
172
|
+
* the previous function.
|
|
173
|
+
*/
|
|
174
|
+
static attachTransformer(key: string, fn: PropTransformer): void;
|
|
175
|
+
/**
|
|
176
|
+
* Removes the transformer registered under `key`. Idempotent — no-op if the
|
|
177
|
+
* key is not present.
|
|
178
|
+
*/
|
|
179
|
+
static detachTransformer(key: string): void;
|
|
180
|
+
/**
|
|
181
|
+
* Returns the field's properties after running them through every registered
|
|
182
|
+
* global transformer. The raw `properties` object is built from `options`
|
|
183
|
+
* with internal keys (`name`, `defaultValue`, `state`, `validate`, `loader`,
|
|
184
|
+
* `onValueChange`) stripped out, plus a `field` reference to `this`.
|
|
185
|
+
* Use this when passing field metadata to a component that does not use the
|
|
186
|
+
* `use()` hook directly.
|
|
187
|
+
*/
|
|
188
|
+
props(): IFieldProps;
|
|
189
|
+
measurePosition<T>(wrapperRef: T): Promise<FieldMeasureResult>;
|
|
190
|
+
scrollTo<T>(scrollRef: T, measure: FieldMeasureResult): Promise<void>;
|
|
191
|
+
getPadding(): number;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=Field.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/lib/Field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAG,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EAAc,YAAY,EAAE,MAAO,YAAY,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAc,MAAM,iBAAiB,CAAC;AAG/E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD;;;;;;;GAOG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,IAAI,EAAE,GAAG,CAAA;gBAEG,IAAI,EAAE,GAAG;CAItB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,KAAK,CAChB,CAAC,EACD,QAAQ,SAAS,SAAS,CAAC,CAAC,EAAC,GAAG,EAAC,GAAG,CAAC,EACrC,MAAM,GA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