@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 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 = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
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(element: unknown): element is FieldElement;
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(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data';
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(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
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(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void;
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 { type Intent, type Submission, type SubmissionResult } from './submission';
3
- type BaseCombine<T, K extends PropertyKey = T extends unknown ? keyof T : never> = T extends unknown ? T & Partial<Record<Exclude<K, keyof T>, never>> : never;
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
- [K in keyof BaseCombine<T>]: BaseCombine<T>[K];
12
+ [K in keyof BaseCombine<T>]: BaseCombine<T>[K];
6
13
  };
7
- export type DefaultValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? Schema | string | null | undefined : Schema extends File ? null | undefined : Schema extends Array<infer Item> ? Array<DefaultValue<Item>> | null | undefined : Schema extends Record<string, any> ? {
8
- [Key in keyof Schema]?: DefaultValue<Schema[Key]>;
9
- } | null | undefined : string | null | undefined;
10
- export type FormValue<Schema> = Schema extends string | number | boolean | Date | bigint | null | undefined ? string | undefined : Schema extends File ? File | undefined : Schema extends File[] ? File | Array<File> | undefined : Schema extends Array<infer Item> ? string | Array<FormValue<Item>> | undefined : Schema extends Record<string, any> ? {
11
- [Key in keyof Schema]?: FormValue<Schema[Key]>;
12
- } | null | undefined : unknown;
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<Schema extends Record<string, unknown> = Record<string, unknown>, Error = string[]> = string & {
17
- [error]?: Error;
18
- [form]?: Schema;
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<FieldSchema, FormSchema extends Record<string, unknown> = Record<string, unknown>, Error = string[]> = string & {
21
- [field]?: FieldSchema;
22
- [error]?: Error;
23
- [form]?: FormSchema;
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
- required?: boolean;
27
- minLength?: number;
28
- maxLength?: number;
29
- min?: string | number;
30
- max?: string | number;
31
- step?: string | number;
32
- multiple?: boolean;
33
- pattern?: string;
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
- formId: string;
37
- isValueUpdated: boolean;
38
- submissionStatus?: 'error' | 'success';
39
- defaultValue: Record<string, unknown>;
40
- initialValue: Record<string, unknown>;
41
- value: Record<string, unknown>;
42
- error: Record<string, FormError>;
43
- constraint: Record<string, Constraint>;
44
- key: Record<string, string | undefined>;
45
- validated: Record<string, boolean>;
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<FormMeta<FormError>, 'formId' | 'isValueUpdated'> & {
48
- valid: Record<string, boolean>;
49
- dirty: Record<string, boolean>;
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
- * The id of the form.
54
- */
55
- formId: string;
56
- /**
57
- * An object representing the initial value of the form.
58
- */
59
- defaultValue?: DefaultValue<Schema>;
60
- /**
61
- * An object describing the constraint of each field
62
- */
63
- constraint?: Record<string, Constraint>;
64
- /**
65
- * An object describing the result of the last submission
66
- */
67
- lastResult?: SubmissionResult<FormError> | null | undefined;
68
- /**
69
- * Define when conform should start validation.
70
- * Support "onSubmit", "onInput", "onBlur".
71
- *
72
- * @default "onSubmit"
73
- */
74
- shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
75
- /**
76
- * Define when conform should revalidate again.
77
- * Support "onSubmit", "onInput", "onBlur".
78
- *
79
- * @default Same as shouldValidate, or "onSubmit" if shouldValidate is not provided.
80
- */
81
- shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
82
- /**
83
- * Define if conform should considered the field for dirty state.
84
- * e.g. Excluding form fields that are not managed by Conform, such as CSRF token
85
- */
86
- shouldDirtyConsider?: (name: string) => boolean;
87
- /**
88
- * A function to be called when the form should be (re)validated.
89
- */
90
- onValidate?: (context: {
91
- form: HTMLFormElement;
92
- submitter: HTMLInputElement | HTMLButtonElement | null;
93
- formData: FormData;
94
- }) => Submission<Schema, FormError, FormValue>;
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
- [key in 'error' | 'initialValue' | 'value' | 'key' | 'valid' | 'dirty']?: SubscriptionScope;
152
+ [key in
153
+ | 'error'
154
+ | 'initialValue'
155
+ | 'value'
156
+ | 'key'
157
+ | 'valid'
158
+ | 'dirty']?: SubscriptionScope;
98
159
  } & {
99
- formId?: boolean;
100
- status?: boolean;
160
+ formId?: boolean;
161
+ status?: boolean;
101
162
  };
102
163
  export type SubscriptionScope = {
103
- prefix?: string[];
104
- name?: string[];
164
+ prefix?: string[];
165
+ name?: string[];
105
166
  };
106
167
  export type ControlButtonProps = {
107
- name: string;
108
- value: string;
109
- form: string;
110
- formNoValidate: boolean;
168
+ name: string;
169
+ value: string;
170
+ form: string;
171
+ formNoValidate: boolean;
111
172
  };
112
- export type FormContext<Schema extends Record<string, any> = any, FormError = string[], FormValue = Schema> = {
113
- getFormId(): string;
114
- submit(event: SubmitEvent): {
115
- formData: FormData;
116
- action: ReturnType<typeof getFormAction>;
117
- encType: ReturnType<typeof getFormEncType>;
118
- method: ReturnType<typeof getFormMethod>;
119
- submission?: Submission<Schema, FormError, FormValue>;
120
- };
121
- onReset(event: Event): void;
122
- onInput(event: Event): void;
123
- onBlur(event: Event): void;
124
- onUpdate(options: Partial<FormOptions<Schema, FormError, FormValue>>): void;
125
- observe(): () => void;
126
- subscribe(callback: () => void, getSubject?: () => SubscriptionSubject | undefined): () => void;
127
- getState(): FormState<FormError>;
128
- getSerializedState(): string;
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
- [Type in Intent['type']]: {} extends Extract<Intent, {
131
- type: Type;
132
- }>['payload'] ? (<FieldSchema = Schema>(payload?: Extract<Intent<FieldSchema>, {
133
- type: Type;
134
- }>['payload']) => void) & {
135
- getButtonProps<FieldSchema = Schema>(payload?: Extract<Intent<FieldSchema>, {
136
- type: Type;
137
- }>['payload']): ControlButtonProps;
138
- } : (<FieldSchema = Schema>(payload: Extract<Intent<FieldSchema>, {
139
- type: Type;
140
- }>['payload']) => void) & {
141
- getButtonProps<FieldSchema = Schema>(payload: Extract<Intent<FieldSchema>, {
142
- type: Type;
143
- }>['payload']): ControlButtonProps;
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<Schema extends Record<string, any>, FormError = string[], FormValue = Schema>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormError, FormValue>;
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 { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form';
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 { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
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
- name: typeof INTENT;
4
- value: string;
5
- formNoValidate?: boolean;
3
+ name: typeof INTENT;
4
+ value: string;
5
+ formNoValidate?: boolean;
6
6
  }
7
- export type ListIntentPayload<Schema = unknown> = {
8
- name: string;
9
- operation: 'insert';
10
- defaultValue?: Schema;
11
- index?: number;
12
- } | {
13
- name: string;
14
- operation: 'prepend';
15
- defaultValue?: Schema;
16
- } | {
17
- name: string;
18
- operation: 'append';
19
- defaultValue?: Schema;
20
- } | {
21
- name: string;
22
- operation: 'replace';
23
- defaultValue: Schema;
24
- index: number;
25
- } | {
26
- name: string;
27
- operation: 'remove';
28
- index: number;
29
- } | {
30
- name: string;
31
- operation: 'reorder';
32
- from: number;
33
- to: number;
34
- };
35
- type ExtractListIntentPayload<Operation, Schema = unknown> = Pretty<Omit<Extract<ListIntentPayload<Schema>, {
36
- operation: Operation;
37
- }>, 'name' | 'operation'>>;
38
- type ListIntent<Operation> = {} extends ExtractListIntentPayload<Operation> ? <Schema>(name: string, payload?: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps : <Schema>(name: string, payload: ExtractListIntentPayload<Operation, Schema>) => IntentButtonProps;
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
- * @deprecated You can use `insert` without specifying an index instead
47
- */
48
- append: ListIntent<'append'>;
49
- /**
50
- * @deprecated You can use `insert` with zero index instead
51
- */
52
- prepend: ListIntent<'prepend'>;
53
- insert: ListIntent<'insert'>;
54
- replace: ListIntent<'replace'>;
55
- remove: ListIntent<'remove'>;
56
- reorder: ListIntent<'reorder'>;
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 = "__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(form: HTMLFormElement | null | undefined, buttonProps: {
71
- value: string;
72
- formNoValidate?: boolean;
73
- }): void;
74
- export declare function parseIntent<Schema>(intent: string): {
75
- type: 'validate';
76
- payload: string;
77
- } | {
78
- type: 'list';
79
- payload: ListIntentPayload<Schema>;
80
- } | null;
81
- export declare function updateList<Schema>(list: Array<Schema>, payload: ListIntentPayload<Schema>): Array<Schema>;
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.4",
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
- intent: string;
3
- payload: Record<string, unknown>;
4
- error: Record<string, string[]>;
5
- value?: Schema | null;
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 = "__undefined__";
8
- export declare const VALIDATION_SKIPPED = "__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>(payload: FormData | URLSearchParams, options?: {
11
- resolve?: (payload: Record<string, any>, intent: string) => {
12
- value?: Schema;
13
- error?: Record<string, string[]>;
14
- };
15
- }): Submission<Schema>;
16
- export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
17
- resolve?: (payload: Record<string, any>, intent: string) => Promise<{
18
- value?: Schema;
19
- error?: Record<string, string[]>;
20
- }>;
21
- }): Promise<Submission<Schema>>;
22
- export declare function parse<Schema>(payload: FormData | URLSearchParams, options?: {
23
- resolve?: (payload: Record<string, any>, intent: string) => {
24
- value?: Schema;
25
- error?: Record<string, string[]>;
26
- } | Promise<{
27
- value?: Schema;
28
- error?: Record<string, string[]>;
29
- }>;
30
- }): Submission<Schema> | Promise<Submission<Schema>>;
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
- [K in keyof T]: T[K];
2
+ [K in keyof T]: T[K];
3
3
  } & {};
4
4
  export type FieldConstraint<Schema = any> = {
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;
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
- [k in K]?: any;
17
- } ? T[K] : undefined;
18
- export type FieldsetConstraint<Schema extends Record<string, any> | undefined> = {
19
- [Key in KeysOf<Schema>]?: FieldConstraint<ResolveType<Schema, Key>>;
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(expectedCondition: boolean, message: string): asserts expectedCondition;
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
- }