@conform-to/dom 1.1.3 → 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/form.js +1 -1
- package/form.mjs +1 -1
- package/formdata.d.ts +2 -2
- package/formdata.js +12 -34
- package/formdata.mjs +12 -34
- package/index.d.ts +24 -2
- package/intent.d.ts +114 -0
- package/intent.js +136 -0
- package/intent.mjs +126 -0
- package/package.json +58 -59
- package/parse.d.ts +50 -0
- package/parse.js +43 -0
- package/parse.mjs +37 -0
- package/submission.d.ts +2 -2
- package/submission.js +23 -21
- package/submission.mjs +23 -21
- package/types.d.ts +23 -0
- 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/form.js
CHANGED
|
@@ -74,7 +74,7 @@ function handleIntent(meta, intent, fields, initialized) {
|
|
|
74
74
|
} = intent.payload;
|
|
75
75
|
var _name2 = formdata.formatName(intent.payload.name, intent.payload.index);
|
|
76
76
|
if (typeof value !== 'undefined') {
|
|
77
|
-
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '',
|
|
77
|
+
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '', value);
|
|
78
78
|
}
|
|
79
79
|
if (typeof validated !== 'undefined') {
|
|
80
80
|
// Clean up previous validated state
|
package/form.mjs
CHANGED
|
@@ -70,7 +70,7 @@ function handleIntent(meta, intent, fields, initialized) {
|
|
|
70
70
|
} = intent.payload;
|
|
71
71
|
var _name2 = formatName(intent.payload.name, intent.payload.index);
|
|
72
72
|
if (typeof value !== 'undefined') {
|
|
73
|
-
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '',
|
|
73
|
+
updateValue(meta, _name2 !== null && _name2 !== void 0 ? _name2 : '', value);
|
|
74
74
|
}
|
|
75
75
|
if (typeof validated !== 'undefined') {
|
|
76
76
|
// Clean up previous validated state
|
package/formdata.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare function normalize(value: unknown, acceptFile?: boolean): unknown
|
|
|
55
55
|
/**
|
|
56
56
|
* Flatten a tree into a dictionary
|
|
57
57
|
*/
|
|
58
|
-
export declare function flatten(data:
|
|
59
|
-
resolve?: (data: unknown) => unknown
|
|
58
|
+
export declare function flatten(data: unknown, options?: {
|
|
59
|
+
resolve?: (data: unknown) => unknown;
|
|
60
60
|
prefix?: string;
|
|
61
61
|
}): Record<string, unknown>;
|
package/formdata.js
CHANGED
|
@@ -174,51 +174,29 @@ function normalize(value) {
|
|
|
174
174
|
/**
|
|
175
175
|
* Flatten a tree into a dictionary
|
|
176
176
|
*/
|
|
177
|
-
function flatten(data
|
|
177
|
+
function flatten(data) {
|
|
178
178
|
var _options$resolve;
|
|
179
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
179
180
|
var result = {};
|
|
180
|
-
var resolve = (_options$resolve = options
|
|
181
|
-
function
|
|
181
|
+
var resolve = (_options$resolve = options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data;
|
|
182
|
+
function process(data, prefix) {
|
|
182
183
|
var value = normalize(resolve(data));
|
|
183
184
|
if (typeof value !== 'undefined') {
|
|
184
|
-
result[
|
|
185
|
+
result[prefix] = value;
|
|
185
186
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
for (var [key, _value] of Object.entries(obj)) {
|
|
190
|
-
var name = prefix ? "".concat(prefix, ".").concat(key) : key;
|
|
191
|
-
if (Array.isArray(_value)) {
|
|
192
|
-
processArray(_value, name);
|
|
193
|
-
} else if (_value && isPlainObject(_value)) {
|
|
194
|
-
processObject(_value, name);
|
|
195
|
-
} else {
|
|
196
|
-
setResult(_value, name);
|
|
187
|
+
if (Array.isArray(data)) {
|
|
188
|
+
for (var i = 0; i < data.length; i++) {
|
|
189
|
+
process(data[i], "".concat(prefix, "[").concat(i, "]"));
|
|
197
190
|
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
setResult(array, prefix);
|
|
202
|
-
for (var i = 0; i < array.length; i++) {
|
|
203
|
-
var item = array[i];
|
|
204
|
-
var name = "".concat(prefix, "[").concat(i, "]");
|
|
205
|
-
if (Array.isArray(item)) {
|
|
206
|
-
processArray(item, name);
|
|
207
|
-
} else if (item && isPlainObject(item)) {
|
|
208
|
-
processObject(item, name);
|
|
209
|
-
} else {
|
|
210
|
-
setResult(item, name);
|
|
191
|
+
} else if (isPlainObject(data)) {
|
|
192
|
+
for (var [key, _value] of Object.entries(data)) {
|
|
193
|
+
process(_value, prefix ? "".concat(prefix, ".").concat(key) : key);
|
|
211
194
|
}
|
|
212
195
|
}
|
|
213
196
|
}
|
|
214
197
|
if (data) {
|
|
215
198
|
var _options$prefix;
|
|
216
|
-
|
|
217
|
-
if (Array.isArray(data)) {
|
|
218
|
-
processArray(data, prefix);
|
|
219
|
-
} else {
|
|
220
|
-
processObject(data, prefix);
|
|
221
|
-
}
|
|
199
|
+
process(data, (_options$prefix = options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : '');
|
|
222
200
|
}
|
|
223
201
|
return result;
|
|
224
202
|
}
|
package/formdata.mjs
CHANGED
|
@@ -170,51 +170,29 @@ function normalize(value) {
|
|
|
170
170
|
/**
|
|
171
171
|
* Flatten a tree into a dictionary
|
|
172
172
|
*/
|
|
173
|
-
function flatten(data
|
|
173
|
+
function flatten(data) {
|
|
174
174
|
var _options$resolve;
|
|
175
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
175
176
|
var result = {};
|
|
176
|
-
var resolve = (_options$resolve = options
|
|
177
|
-
function
|
|
177
|
+
var resolve = (_options$resolve = options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data;
|
|
178
|
+
function process(data, prefix) {
|
|
178
179
|
var value = normalize(resolve(data));
|
|
179
180
|
if (typeof value !== 'undefined') {
|
|
180
|
-
result[
|
|
181
|
+
result[prefix] = value;
|
|
181
182
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
for (var [key, _value] of Object.entries(obj)) {
|
|
186
|
-
var name = prefix ? "".concat(prefix, ".").concat(key) : key;
|
|
187
|
-
if (Array.isArray(_value)) {
|
|
188
|
-
processArray(_value, name);
|
|
189
|
-
} else if (_value && isPlainObject(_value)) {
|
|
190
|
-
processObject(_value, name);
|
|
191
|
-
} else {
|
|
192
|
-
setResult(_value, name);
|
|
183
|
+
if (Array.isArray(data)) {
|
|
184
|
+
for (var i = 0; i < data.length; i++) {
|
|
185
|
+
process(data[i], "".concat(prefix, "[").concat(i, "]"));
|
|
193
186
|
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
setResult(array, prefix);
|
|
198
|
-
for (var i = 0; i < array.length; i++) {
|
|
199
|
-
var item = array[i];
|
|
200
|
-
var name = "".concat(prefix, "[").concat(i, "]");
|
|
201
|
-
if (Array.isArray(item)) {
|
|
202
|
-
processArray(item, name);
|
|
203
|
-
} else if (item && isPlainObject(item)) {
|
|
204
|
-
processObject(item, name);
|
|
205
|
-
} else {
|
|
206
|
-
setResult(item, name);
|
|
187
|
+
} else if (isPlainObject(data)) {
|
|
188
|
+
for (var [key, _value] of Object.entries(data)) {
|
|
189
|
+
process(_value, prefix ? "".concat(prefix, ".").concat(key) : key);
|
|
207
190
|
}
|
|
208
191
|
}
|
|
209
192
|
}
|
|
210
193
|
if (data) {
|
|
211
194
|
var _options$prefix;
|
|
212
|
-
|
|
213
|
-
if (Array.isArray(data)) {
|
|
214
|
-
processArray(data, prefix);
|
|
215
|
-
} else {
|
|
216
|
-
processObject(data, prefix);
|
|
217
|
-
}
|
|
195
|
+
process(data, (_options$prefix = options.prefix) !== null && _options$prefix !== void 0 ? _options$prefix : '');
|
|
218
196
|
}
|
|
219
197
|
return result;
|
|
220
198
|
}
|
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';
|