@conform-to/dom 1.1.4 → 1.1.5
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/dom.d.ts +17 -5
- package/form.d.ts +221 -122
- package/index.d.ts +24 -2
- package/intent.d.ts +92 -60
- package/package.json +1 -1
- package/parse.d.ts +47 -27
- package/types.d.ts +17 -14
- package/util.d.ts +4 -1
- package/rollup.config.js +0 -100
package/dom.d.ts
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
* Element that user can interact with,
|
|
3
3
|
* includes `<input>`, `<select>` and `<textarea>`.
|
|
4
4
|
*/
|
|
5
|
-
export type FieldElement =
|
|
5
|
+
export type FieldElement =
|
|
6
|
+
| HTMLInputElement
|
|
7
|
+
| HTMLSelectElement
|
|
8
|
+
| HTMLTextAreaElement;
|
|
6
9
|
/**
|
|
7
10
|
* HTML Element that can be used as a form control,
|
|
8
11
|
* includes `<input>`, `<select>`, `<textarea>` and `<button>`.
|
|
@@ -20,7 +23,9 @@ export declare function isFormControl(element: unknown): element is FormControl;
|
|
|
20
23
|
* A type guard to check if the provided element is a field element, which
|
|
21
24
|
* is a form control excluding submit, button and reset type.
|
|
22
25
|
*/
|
|
23
|
-
export declare function isFieldElement(
|
|
26
|
+
export declare function isFieldElement(
|
|
27
|
+
element: unknown,
|
|
28
|
+
): element is FieldElement;
|
|
24
29
|
/**
|
|
25
30
|
* Resolves the action from the submit event
|
|
26
31
|
* with respect to the submitter `formaction` attribute.
|
|
@@ -30,14 +35,21 @@ export declare function getFormAction(event: SubmitEvent): string;
|
|
|
30
35
|
* Resolves the encoding type from the submit event
|
|
31
36
|
* with respect to the submitter `formenctype` attribute.
|
|
32
37
|
*/
|
|
33
|
-
export declare function getFormEncType(
|
|
38
|
+
export declare function getFormEncType(
|
|
39
|
+
event: SubmitEvent,
|
|
40
|
+
): 'application/x-www-form-urlencoded' | 'multipart/form-data';
|
|
34
41
|
/**
|
|
35
42
|
* Resolves the method from the submit event
|
|
36
43
|
* with respect to the submitter `formmethod` attribute.
|
|
37
44
|
*/
|
|
38
|
-
export declare function getFormMethod(
|
|
45
|
+
export declare function getFormMethod(
|
|
46
|
+
event: SubmitEvent,
|
|
47
|
+
): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
39
48
|
/**
|
|
40
49
|
* Trigger a form submit event with an optional submitter.
|
|
41
50
|
* If the submitter is not mounted, it will be appended to the form and removed after submission.
|
|
42
51
|
*/
|
|
43
|
-
export declare function requestSubmit(
|
|
52
|
+
export declare function requestSubmit(
|
|
53
|
+
form: HTMLFormElement | null | undefined,
|
|
54
|
+
submitter: Submitter | null,
|
|
55
|
+
): void;
|
package/form.d.ts
CHANGED
|
@@ -1,147 +1,246 @@
|
|
|
1
1
|
import { getFormAction, getFormEncType, getFormMethod } from './dom';
|
|
2
|
-
import {
|
|
3
|
-
type
|
|
2
|
+
import {
|
|
3
|
+
type Intent,
|
|
4
|
+
type Submission,
|
|
5
|
+
type SubmissionResult,
|
|
6
|
+
} from './submission';
|
|
7
|
+
type BaseCombine<
|
|
8
|
+
T,
|
|
9
|
+
K extends PropertyKey = T extends unknown ? keyof T : never,
|
|
10
|
+
> = T extends unknown ? T & Partial<Record<Exclude<K, keyof T>, never>> : never;
|
|
4
11
|
export type Combine<T> = {
|
|
5
|
-
|
|
12
|
+
[K in keyof BaseCombine<T>]: BaseCombine<T>[K];
|
|
6
13
|
};
|
|
7
|
-
export type DefaultValue<Schema> = Schema extends
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
export type DefaultValue<Schema> = Schema extends
|
|
15
|
+
| string
|
|
16
|
+
| number
|
|
17
|
+
| boolean
|
|
18
|
+
| Date
|
|
19
|
+
| bigint
|
|
20
|
+
| null
|
|
21
|
+
| undefined
|
|
22
|
+
? Schema | string | null | undefined
|
|
23
|
+
: Schema extends File
|
|
24
|
+
? null | undefined
|
|
25
|
+
: Schema extends Array<infer Item>
|
|
26
|
+
? Array<DefaultValue<Item>> | null | undefined
|
|
27
|
+
: Schema extends Record<string, any>
|
|
28
|
+
?
|
|
29
|
+
| {
|
|
30
|
+
[Key in keyof Schema]?: DefaultValue<Schema[Key]>;
|
|
31
|
+
}
|
|
32
|
+
| null
|
|
33
|
+
| undefined
|
|
34
|
+
: string | null | undefined;
|
|
35
|
+
export type FormValue<Schema> = Schema extends
|
|
36
|
+
| string
|
|
37
|
+
| number
|
|
38
|
+
| boolean
|
|
39
|
+
| Date
|
|
40
|
+
| bigint
|
|
41
|
+
| null
|
|
42
|
+
| undefined
|
|
43
|
+
? string | undefined
|
|
44
|
+
: Schema extends File
|
|
45
|
+
? File | undefined
|
|
46
|
+
: Schema extends File[]
|
|
47
|
+
? File | Array<File> | undefined
|
|
48
|
+
: Schema extends Array<infer Item>
|
|
49
|
+
? string | Array<FormValue<Item>> | undefined
|
|
50
|
+
: Schema extends Record<string, any>
|
|
51
|
+
?
|
|
52
|
+
| {
|
|
53
|
+
[Key in keyof Schema]?: FormValue<Schema[Key]>;
|
|
54
|
+
}
|
|
55
|
+
| null
|
|
56
|
+
| undefined
|
|
57
|
+
: unknown;
|
|
13
58
|
declare const error: unique symbol;
|
|
14
59
|
declare const field: unique symbol;
|
|
15
60
|
declare const form: unique symbol;
|
|
16
|
-
export type FormId<
|
|
17
|
-
|
|
18
|
-
|
|
61
|
+
export type FormId<
|
|
62
|
+
Schema extends Record<string, unknown> = Record<string, unknown>,
|
|
63
|
+
Error = string[],
|
|
64
|
+
> = string & {
|
|
65
|
+
[error]?: Error;
|
|
66
|
+
[form]?: Schema;
|
|
19
67
|
};
|
|
20
|
-
export type FieldName<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
68
|
+
export type FieldName<
|
|
69
|
+
FieldSchema,
|
|
70
|
+
FormSchema extends Record<string, unknown> = Record<string, unknown>,
|
|
71
|
+
Error = string[],
|
|
72
|
+
> = string & {
|
|
73
|
+
[field]?: FieldSchema;
|
|
74
|
+
[error]?: Error;
|
|
75
|
+
[form]?: FormSchema;
|
|
24
76
|
};
|
|
25
77
|
export type Constraint = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
78
|
+
required?: boolean;
|
|
79
|
+
minLength?: number;
|
|
80
|
+
maxLength?: number;
|
|
81
|
+
min?: string | number;
|
|
82
|
+
max?: string | number;
|
|
83
|
+
step?: string | number;
|
|
84
|
+
multiple?: boolean;
|
|
85
|
+
pattern?: string;
|
|
34
86
|
};
|
|
35
87
|
export type FormMeta<FormError> = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
88
|
+
formId: string;
|
|
89
|
+
isValueUpdated: boolean;
|
|
90
|
+
submissionStatus?: 'error' | 'success';
|
|
91
|
+
defaultValue: Record<string, unknown>;
|
|
92
|
+
initialValue: Record<string, unknown>;
|
|
93
|
+
value: Record<string, unknown>;
|
|
94
|
+
error: Record<string, FormError>;
|
|
95
|
+
constraint: Record<string, Constraint>;
|
|
96
|
+
key: Record<string, string | undefined>;
|
|
97
|
+
validated: Record<string, boolean>;
|
|
46
98
|
};
|
|
47
|
-
export type FormState<FormError> = Omit<
|
|
48
|
-
|
|
49
|
-
|
|
99
|
+
export type FormState<FormError> = Omit<
|
|
100
|
+
FormMeta<FormError>,
|
|
101
|
+
'formId' | 'isValueUpdated'
|
|
102
|
+
> & {
|
|
103
|
+
valid: Record<string, boolean>;
|
|
104
|
+
dirty: Record<string, boolean>;
|
|
50
105
|
};
|
|
51
106
|
export type FormOptions<Schema, FormError = string[], FormValue = Schema> = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The id of the form.
|
|
109
|
+
*/
|
|
110
|
+
formId: string;
|
|
111
|
+
/**
|
|
112
|
+
* An object representing the initial value of the form.
|
|
113
|
+
*/
|
|
114
|
+
defaultValue?: DefaultValue<Schema>;
|
|
115
|
+
/**
|
|
116
|
+
* An object describing the constraint of each field
|
|
117
|
+
*/
|
|
118
|
+
constraint?: Record<string, Constraint>;
|
|
119
|
+
/**
|
|
120
|
+
* An object describing the result of the last submission
|
|
121
|
+
*/
|
|
122
|
+
lastResult?: SubmissionResult<FormError> | null | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Define when conform should start validation.
|
|
125
|
+
* Support "onSubmit", "onInput", "onBlur".
|
|
126
|
+
*
|
|
127
|
+
* @default "onSubmit"
|
|
128
|
+
*/
|
|
129
|
+
shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
130
|
+
/**
|
|
131
|
+
* Define when conform should revalidate again.
|
|
132
|
+
* Support "onSubmit", "onInput", "onBlur".
|
|
133
|
+
*
|
|
134
|
+
* @default Same as shouldValidate, or "onSubmit" if shouldValidate is not provided.
|
|
135
|
+
*/
|
|
136
|
+
shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
137
|
+
/**
|
|
138
|
+
* Define if conform should considered the field for dirty state.
|
|
139
|
+
* e.g. Excluding form fields that are not managed by Conform, such as CSRF token
|
|
140
|
+
*/
|
|
141
|
+
shouldDirtyConsider?: (name: string) => boolean;
|
|
142
|
+
/**
|
|
143
|
+
* A function to be called when the form should be (re)validated.
|
|
144
|
+
*/
|
|
145
|
+
onValidate?: (context: {
|
|
146
|
+
form: HTMLFormElement;
|
|
147
|
+
submitter: HTMLInputElement | HTMLButtonElement | null;
|
|
148
|
+
formData: FormData;
|
|
149
|
+
}) => Submission<Schema, FormError, FormValue>;
|
|
95
150
|
};
|
|
96
151
|
export type SubscriptionSubject = {
|
|
97
|
-
|
|
152
|
+
[key in
|
|
153
|
+
| 'error'
|
|
154
|
+
| 'initialValue'
|
|
155
|
+
| 'value'
|
|
156
|
+
| 'key'
|
|
157
|
+
| 'valid'
|
|
158
|
+
| 'dirty']?: SubscriptionScope;
|
|
98
159
|
} & {
|
|
99
|
-
|
|
100
|
-
|
|
160
|
+
formId?: boolean;
|
|
161
|
+
status?: boolean;
|
|
101
162
|
};
|
|
102
163
|
export type SubscriptionScope = {
|
|
103
|
-
|
|
104
|
-
|
|
164
|
+
prefix?: string[];
|
|
165
|
+
name?: string[];
|
|
105
166
|
};
|
|
106
167
|
export type ControlButtonProps = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
168
|
+
name: string;
|
|
169
|
+
value: string;
|
|
170
|
+
form: string;
|
|
171
|
+
formNoValidate: boolean;
|
|
111
172
|
};
|
|
112
|
-
export type FormContext<
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
173
|
+
export type FormContext<
|
|
174
|
+
Schema extends Record<string, any> = any,
|
|
175
|
+
FormError = string[],
|
|
176
|
+
FormValue = Schema,
|
|
177
|
+
> = {
|
|
178
|
+
getFormId(): string;
|
|
179
|
+
submit(event: SubmitEvent): {
|
|
180
|
+
formData: FormData;
|
|
181
|
+
action: ReturnType<typeof getFormAction>;
|
|
182
|
+
encType: ReturnType<typeof getFormEncType>;
|
|
183
|
+
method: ReturnType<typeof getFormMethod>;
|
|
184
|
+
submission?: Submission<Schema, FormError, FormValue>;
|
|
185
|
+
};
|
|
186
|
+
onReset(event: Event): void;
|
|
187
|
+
onInput(event: Event): void;
|
|
188
|
+
onBlur(event: Event): void;
|
|
189
|
+
onUpdate(options: Partial<FormOptions<Schema, FormError, FormValue>>): void;
|
|
190
|
+
observe(): () => void;
|
|
191
|
+
subscribe(
|
|
192
|
+
callback: () => void,
|
|
193
|
+
getSubject?: () => SubscriptionSubject | undefined,
|
|
194
|
+
): () => void;
|
|
195
|
+
getState(): FormState<FormError>;
|
|
196
|
+
getSerializedState(): string;
|
|
129
197
|
} & {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
198
|
+
[Type in Intent['type']]: {} extends Extract<
|
|
199
|
+
Intent,
|
|
200
|
+
{
|
|
201
|
+
type: Type;
|
|
202
|
+
}
|
|
203
|
+
>['payload']
|
|
204
|
+
? (<FieldSchema = Schema>(
|
|
205
|
+
payload?: Extract<
|
|
206
|
+
Intent<FieldSchema>,
|
|
207
|
+
{
|
|
208
|
+
type: Type;
|
|
209
|
+
}
|
|
210
|
+
>['payload'],
|
|
211
|
+
) => void) & {
|
|
212
|
+
getButtonProps<FieldSchema = Schema>(
|
|
213
|
+
payload?: Extract<
|
|
214
|
+
Intent<FieldSchema>,
|
|
215
|
+
{
|
|
216
|
+
type: Type;
|
|
217
|
+
}
|
|
218
|
+
>['payload'],
|
|
219
|
+
): ControlButtonProps;
|
|
220
|
+
}
|
|
221
|
+
: (<FieldSchema = Schema>(
|
|
222
|
+
payload: Extract<
|
|
223
|
+
Intent<FieldSchema>,
|
|
224
|
+
{
|
|
225
|
+
type: Type;
|
|
226
|
+
}
|
|
227
|
+
>['payload'],
|
|
228
|
+
) => void) & {
|
|
229
|
+
getButtonProps<FieldSchema = Schema>(
|
|
230
|
+
payload: Extract<
|
|
231
|
+
Intent<FieldSchema>,
|
|
232
|
+
{
|
|
233
|
+
type: Type;
|
|
234
|
+
}
|
|
235
|
+
>['payload'],
|
|
236
|
+
): ControlButtonProps;
|
|
237
|
+
};
|
|
145
238
|
};
|
|
146
|
-
export declare function createFormContext<
|
|
239
|
+
export declare function createFormContext<
|
|
240
|
+
Schema extends Record<string, any>,
|
|
241
|
+
FormError = string[],
|
|
242
|
+
FormValue = Schema,
|
|
243
|
+
>(
|
|
244
|
+
options: FormOptions<Schema, FormError, FormValue>,
|
|
245
|
+
): FormContext<Schema, FormError, FormValue>;
|
|
147
246
|
export {};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {
|
|
2
|
+
type Combine,
|
|
3
|
+
type Constraint,
|
|
4
|
+
type ControlButtonProps,
|
|
5
|
+
type FormId,
|
|
6
|
+
type FieldName,
|
|
7
|
+
type DefaultValue,
|
|
8
|
+
type FormValue,
|
|
9
|
+
type FormOptions,
|
|
10
|
+
type FormState,
|
|
11
|
+
type FormContext,
|
|
12
|
+
type SubscriptionSubject,
|
|
13
|
+
type SubscriptionScope,
|
|
14
|
+
createFormContext as unstable_createFormContext,
|
|
15
|
+
} from './form';
|
|
2
16
|
export { type FieldElement, isFieldElement } from './dom';
|
|
3
|
-
export {
|
|
17
|
+
export {
|
|
18
|
+
type Submission,
|
|
19
|
+
type SubmissionResult,
|
|
20
|
+
type Intent,
|
|
21
|
+
INTENT,
|
|
22
|
+
STATE,
|
|
23
|
+
serializeIntent,
|
|
24
|
+
parse,
|
|
25
|
+
} from './submission';
|
|
4
26
|
export { getPaths, formatPaths, isPrefix } from './formdata';
|
package/intent.d.ts
CHANGED
|
@@ -1,61 +1,84 @@
|
|
|
1
1
|
import { type Pretty } from './types.js';
|
|
2
2
|
export interface IntentButtonProps {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
name: typeof INTENT;
|
|
4
|
+
value: string;
|
|
5
|
+
formNoValidate?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export type ListIntentPayload<Schema = unknown> =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
7
|
+
export type ListIntentPayload<Schema = unknown> =
|
|
8
|
+
| {
|
|
9
|
+
name: string;
|
|
10
|
+
operation: 'insert';
|
|
11
|
+
defaultValue?: Schema;
|
|
12
|
+
index?: number;
|
|
13
|
+
}
|
|
14
|
+
| {
|
|
15
|
+
name: string;
|
|
16
|
+
operation: 'prepend';
|
|
17
|
+
defaultValue?: Schema;
|
|
18
|
+
}
|
|
19
|
+
| {
|
|
20
|
+
name: string;
|
|
21
|
+
operation: 'append';
|
|
22
|
+
defaultValue?: Schema;
|
|
23
|
+
}
|
|
24
|
+
| {
|
|
25
|
+
name: string;
|
|
26
|
+
operation: 'replace';
|
|
27
|
+
defaultValue: Schema;
|
|
28
|
+
index: number;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
name: string;
|
|
32
|
+
operation: 'remove';
|
|
33
|
+
index: number;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
name: string;
|
|
37
|
+
operation: 'reorder';
|
|
38
|
+
from: number;
|
|
39
|
+
to: number;
|
|
40
|
+
};
|
|
41
|
+
type ExtractListIntentPayload<Operation, Schema = unknown> = Pretty<
|
|
42
|
+
Omit<
|
|
43
|
+
Extract<
|
|
44
|
+
ListIntentPayload<Schema>,
|
|
45
|
+
{
|
|
46
|
+
operation: Operation;
|
|
47
|
+
}
|
|
48
|
+
>,
|
|
49
|
+
'name' | 'operation'
|
|
50
|
+
>
|
|
51
|
+
>;
|
|
52
|
+
type ListIntent<Operation> =
|
|
53
|
+
{} extends ExtractListIntentPayload<Operation>
|
|
54
|
+
? <Schema>(
|
|
55
|
+
name: string,
|
|
56
|
+
payload?: ExtractListIntentPayload<Operation, Schema>,
|
|
57
|
+
) => IntentButtonProps
|
|
58
|
+
: <Schema>(
|
|
59
|
+
name: string,
|
|
60
|
+
payload: ExtractListIntentPayload<Operation, Schema>,
|
|
61
|
+
) => IntentButtonProps;
|
|
39
62
|
/**
|
|
40
63
|
* Helpers to configure an intent button for modifying a list
|
|
41
64
|
*
|
|
42
65
|
* @see https://conform.guide/api/react#list
|
|
43
66
|
*/
|
|
44
67
|
export declare const list: {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated You can use `insert` without specifying an index instead
|
|
70
|
+
*/
|
|
71
|
+
append: ListIntent<'append'>;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated You can use `insert` with zero index instead
|
|
74
|
+
*/
|
|
75
|
+
prepend: ListIntent<'prepend'>;
|
|
76
|
+
insert: ListIntent<'insert'>;
|
|
77
|
+
replace: ListIntent<'replace'>;
|
|
78
|
+
remove: ListIntent<'remove'>;
|
|
79
|
+
reorder: ListIntent<'reorder'>;
|
|
57
80
|
};
|
|
58
|
-
export declare const INTENT =
|
|
81
|
+
export declare const INTENT = '__intent__';
|
|
59
82
|
/**
|
|
60
83
|
* Returns the intent from the form data or search params.
|
|
61
84
|
* It throws an error if multiple intent is set.
|
|
@@ -67,16 +90,25 @@ export declare function getIntent(payload: FormData | URLSearchParams): string;
|
|
|
67
90
|
* @see https://conform.guide/api/react#validate
|
|
68
91
|
*/
|
|
69
92
|
export declare function validate(field: string): IntentButtonProps;
|
|
70
|
-
export declare function requestIntent(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
export declare function requestIntent(
|
|
94
|
+
form: HTMLFormElement | null | undefined,
|
|
95
|
+
buttonProps: {
|
|
96
|
+
value: string;
|
|
97
|
+
formNoValidate?: boolean;
|
|
98
|
+
},
|
|
99
|
+
): void;
|
|
100
|
+
export declare function parseIntent<Schema>(intent: string):
|
|
101
|
+
| {
|
|
102
|
+
type: 'validate';
|
|
103
|
+
payload: string;
|
|
104
|
+
}
|
|
105
|
+
| {
|
|
106
|
+
type: 'list';
|
|
107
|
+
payload: ListIntentPayload<Schema>;
|
|
108
|
+
}
|
|
109
|
+
| null;
|
|
110
|
+
export declare function updateList<Schema>(
|
|
111
|
+
list: Array<Schema>,
|
|
112
|
+
payload: ListIntentPayload<Schema>,
|
|
113
|
+
): Array<Schema>;
|
|
82
114
|
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "A set of opinionated helpers built on top of the Constraint Validation API",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.5",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
package/parse.d.ts
CHANGED
|
@@ -1,30 +1,50 @@
|
|
|
1
1
|
export type Submission<Schema = any> = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
intent: string;
|
|
3
|
+
payload: Record<string, unknown>;
|
|
4
|
+
error: Record<string, string[]>;
|
|
5
|
+
value?: Schema | null;
|
|
6
6
|
};
|
|
7
|
-
export declare const VALIDATION_UNDEFINED =
|
|
8
|
-
export declare const VALIDATION_SKIPPED =
|
|
7
|
+
export declare const VALIDATION_UNDEFINED = '__undefined__';
|
|
8
|
+
export declare const VALIDATION_SKIPPED = '__skipped__';
|
|
9
9
|
export declare function parse(payload: FormData | URLSearchParams): Submission;
|
|
10
|
-
export declare function parse<Schema>(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export declare function parse<Schema>(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
export declare function parse<Schema>(
|
|
11
|
+
payload: FormData | URLSearchParams,
|
|
12
|
+
options?: {
|
|
13
|
+
resolve?: (
|
|
14
|
+
payload: Record<string, any>,
|
|
15
|
+
intent: string,
|
|
16
|
+
) => {
|
|
17
|
+
value?: Schema;
|
|
18
|
+
error?: Record<string, string[]>;
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
): Submission<Schema>;
|
|
22
|
+
export declare function parse<Schema>(
|
|
23
|
+
payload: FormData | URLSearchParams,
|
|
24
|
+
options?: {
|
|
25
|
+
resolve?: (
|
|
26
|
+
payload: Record<string, any>,
|
|
27
|
+
intent: string,
|
|
28
|
+
) => Promise<{
|
|
29
|
+
value?: Schema;
|
|
30
|
+
error?: Record<string, string[]>;
|
|
31
|
+
}>;
|
|
32
|
+
},
|
|
33
|
+
): Promise<Submission<Schema>>;
|
|
34
|
+
export declare function parse<Schema>(
|
|
35
|
+
payload: FormData | URLSearchParams,
|
|
36
|
+
options?: {
|
|
37
|
+
resolve?: (
|
|
38
|
+
payload: Record<string, any>,
|
|
39
|
+
intent: string,
|
|
40
|
+
) =>
|
|
41
|
+
| {
|
|
42
|
+
value?: Schema;
|
|
43
|
+
error?: Record<string, string[]>;
|
|
44
|
+
}
|
|
45
|
+
| Promise<{
|
|
46
|
+
value?: Schema;
|
|
47
|
+
error?: Record<string, string[]>;
|
|
48
|
+
}>;
|
|
49
|
+
},
|
|
50
|
+
): Submission<Schema> | Promise<Submission<Schema>>;
|
package/types.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
export type Pretty<T> = {
|
|
2
|
-
|
|
2
|
+
[K in keyof T]: T[K];
|
|
3
3
|
} & {};
|
|
4
4
|
export type FieldConstraint<Schema = any> = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
required?: boolean;
|
|
6
|
+
minLength?: number;
|
|
7
|
+
maxLength?: number;
|
|
8
|
+
min?: Schema extends number ? number : string | number;
|
|
9
|
+
max?: Schema extends number ? number : string | number;
|
|
10
|
+
step?: Schema extends number ? number : string | number;
|
|
11
|
+
multiple?: boolean;
|
|
12
|
+
pattern?: string;
|
|
13
13
|
};
|
|
14
14
|
export type KeysOf<T> = T extends any ? keyof T : never;
|
|
15
15
|
export type ResolveType<T, K extends KeysOf<T>> = T extends {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
[k in K]?: any;
|
|
17
|
+
}
|
|
18
|
+
? T[K]
|
|
19
|
+
: undefined;
|
|
20
|
+
export type FieldsetConstraint<Schema extends Record<string, any> | undefined> =
|
|
21
|
+
{
|
|
22
|
+
[Key in KeysOf<Schema>]?: FieldConstraint<ResolveType<Schema, Key>>;
|
|
23
|
+
};
|
package/util.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export declare function invariant(
|
|
1
|
+
export declare function invariant(
|
|
2
|
+
expectedCondition: boolean,
|
|
3
|
+
message: string,
|
|
4
|
+
): asserts expectedCondition;
|
|
2
5
|
export declare function generateId(): string;
|
|
3
6
|
export declare function clone<Data>(data: Data): Data;
|
package/rollup.config.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import babel from '@rollup/plugin-babel';
|
|
3
|
-
import nodeResolve from '@rollup/plugin-node-resolve';
|
|
4
|
-
import copy from 'rollup-plugin-copy';
|
|
5
|
-
|
|
6
|
-
/** @returns {import("rollup").RollupOptions[]} */
|
|
7
|
-
function configurePackage() {
|
|
8
|
-
let sourceDir = '.';
|
|
9
|
-
let outputDir = sourceDir;
|
|
10
|
-
|
|
11
|
-
/** @type {import("rollup").RollupOptions} */
|
|
12
|
-
let ESM = {
|
|
13
|
-
external(id) {
|
|
14
|
-
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
15
|
-
},
|
|
16
|
-
input: `${sourceDir}/index.ts`,
|
|
17
|
-
output: {
|
|
18
|
-
dir: outputDir,
|
|
19
|
-
format: 'esm',
|
|
20
|
-
preserveModules: true,
|
|
21
|
-
entryFileNames: '[name].mjs',
|
|
22
|
-
},
|
|
23
|
-
plugins: [
|
|
24
|
-
babel({
|
|
25
|
-
babelrc: false,
|
|
26
|
-
configFile: false,
|
|
27
|
-
presets: [
|
|
28
|
-
[
|
|
29
|
-
'@babel/preset-env',
|
|
30
|
-
{
|
|
31
|
-
targets: {
|
|
32
|
-
node: '16',
|
|
33
|
-
esmodules: true,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
'@babel/preset-typescript',
|
|
38
|
-
],
|
|
39
|
-
plugins: [],
|
|
40
|
-
babelHelpers: 'bundled',
|
|
41
|
-
exclude: /node_modules/,
|
|
42
|
-
extensions: ['.ts', '.tsx'],
|
|
43
|
-
}),
|
|
44
|
-
nodeResolve({
|
|
45
|
-
extensions: ['.ts', '.tsx'],
|
|
46
|
-
}),
|
|
47
|
-
copy({
|
|
48
|
-
targets: [
|
|
49
|
-
{ src: `../../README`, dest: sourceDir },
|
|
50
|
-
{ src: `../../LICENSE`, dest: sourceDir },
|
|
51
|
-
],
|
|
52
|
-
}),
|
|
53
|
-
],
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/** @type {import("rollup").RollupOptions} */
|
|
57
|
-
let CJS = {
|
|
58
|
-
external(id) {
|
|
59
|
-
return !id.startsWith('.') && !path.isAbsolute(id);
|
|
60
|
-
},
|
|
61
|
-
input: `${sourceDir}/index.ts`,
|
|
62
|
-
output: {
|
|
63
|
-
dir: outputDir,
|
|
64
|
-
format: 'cjs',
|
|
65
|
-
preserveModules: true,
|
|
66
|
-
exports: 'auto',
|
|
67
|
-
},
|
|
68
|
-
plugins: [
|
|
69
|
-
babel({
|
|
70
|
-
babelrc: false,
|
|
71
|
-
configFile: false,
|
|
72
|
-
presets: [
|
|
73
|
-
[
|
|
74
|
-
'@babel/preset-env',
|
|
75
|
-
{
|
|
76
|
-
targets: {
|
|
77
|
-
node: '16',
|
|
78
|
-
esmodules: true,
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
'@babel/preset-typescript',
|
|
83
|
-
],
|
|
84
|
-
plugins: [],
|
|
85
|
-
babelHelpers: 'bundled',
|
|
86
|
-
exclude: /node_modules/,
|
|
87
|
-
extensions: ['.ts', '.tsx'],
|
|
88
|
-
}),
|
|
89
|
-
nodeResolve({
|
|
90
|
-
extensions: ['.ts', '.tsx'],
|
|
91
|
-
}),
|
|
92
|
-
],
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return [ESM, CJS];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default function rollup() {
|
|
99
|
-
return configurePackage();
|
|
100
|
-
}
|