@conform-to/dom 1.1.5 → 1.2.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/form.d.ts +122 -221
- package/form.js +5 -7
- package/form.mjs +5 -7
- package/package.json +1 -1
- package/submission.d.ts +7 -4
- package/submission.js +16 -11
- package/submission.mjs +16 -11
package/form.d.ts
CHANGED
|
@@ -1,246 +1,147 @@
|
|
|
1
1
|
import { getFormAction, getFormEncType, getFormMethod } from './dom';
|
|
2
|
-
import {
|
|
3
|
-
|
|
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;
|
|
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;
|
|
11
4
|
export type Combine<T> = {
|
|
12
|
-
|
|
5
|
+
[K in keyof BaseCombine<T>]: BaseCombine<T>[K];
|
|
13
6
|
};
|
|
14
|
-
export type DefaultValue<Schema> = Schema extends
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
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
|
+
} | undefined : unknown;
|
|
58
13
|
declare const error: unique symbol;
|
|
59
14
|
declare const field: unique symbol;
|
|
60
15
|
declare const form: unique symbol;
|
|
61
|
-
export type FormId<
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
> = string & {
|
|
65
|
-
[error]?: Error;
|
|
66
|
-
[form]?: Schema;
|
|
16
|
+
export type FormId<Schema extends Record<string, unknown> = Record<string, unknown>, Error = string[]> = string & {
|
|
17
|
+
[error]?: Error;
|
|
18
|
+
[form]?: Schema;
|
|
67
19
|
};
|
|
68
|
-
export type FieldName<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
> = string & {
|
|
73
|
-
[field]?: FieldSchema;
|
|
74
|
-
[error]?: Error;
|
|
75
|
-
[form]?: FormSchema;
|
|
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;
|
|
76
24
|
};
|
|
77
25
|
export type Constraint = {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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;
|
|
86
34
|
};
|
|
87
35
|
export type FormMeta<FormError> = {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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>;
|
|
98
46
|
};
|
|
99
|
-
export type FormState<FormError> = Omit<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
> & {
|
|
103
|
-
valid: Record<string, boolean>;
|
|
104
|
-
dirty: Record<string, boolean>;
|
|
47
|
+
export type FormState<FormError> = Omit<FormMeta<FormError>, 'formId' | 'isValueUpdated'> & {
|
|
48
|
+
valid: Record<string, boolean>;
|
|
49
|
+
dirty: Record<string, boolean>;
|
|
105
50
|
};
|
|
106
51
|
export type FormOptions<Schema, FormError = string[], FormValue = Schema> = {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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>;
|
|
150
95
|
};
|
|
151
96
|
export type SubscriptionSubject = {
|
|
152
|
-
|
|
153
|
-
| 'error'
|
|
154
|
-
| 'initialValue'
|
|
155
|
-
| 'value'
|
|
156
|
-
| 'key'
|
|
157
|
-
| 'valid'
|
|
158
|
-
| 'dirty']?: SubscriptionScope;
|
|
97
|
+
[key in 'error' | 'initialValue' | 'value' | 'key' | 'valid' | 'dirty']?: SubscriptionScope;
|
|
159
98
|
} & {
|
|
160
|
-
|
|
161
|
-
|
|
99
|
+
formId?: boolean;
|
|
100
|
+
status?: boolean;
|
|
162
101
|
};
|
|
163
102
|
export type SubscriptionScope = {
|
|
164
|
-
|
|
165
|
-
|
|
103
|
+
prefix?: string[];
|
|
104
|
+
name?: string[];
|
|
166
105
|
};
|
|
167
106
|
export type ControlButtonProps = {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
107
|
+
name: string;
|
|
108
|
+
value: string;
|
|
109
|
+
form: string;
|
|
110
|
+
formNoValidate: boolean;
|
|
172
111
|
};
|
|
173
|
-
export type FormContext<
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
observe(): () => void;
|
|
191
|
-
subscribe(
|
|
192
|
-
callback: () => void,
|
|
193
|
-
getSubject?: () => SubscriptionSubject | undefined,
|
|
194
|
-
): () => void;
|
|
195
|
-
getState(): FormState<FormError>;
|
|
196
|
-
getSerializedState(): string;
|
|
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;
|
|
197
129
|
} & {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
};
|
|
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
|
+
};
|
|
238
145
|
};
|
|
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>;
|
|
146
|
+
export declare function createFormContext<Schema extends Record<string, any>, FormError = string[], FormValue = Schema>(options: FormOptions<Schema, FormError, FormValue>): FormContext<Schema, FormError, FormValue>;
|
|
246
147
|
export {};
|
package/form.js
CHANGED
|
@@ -22,9 +22,7 @@ function createFormMeta(options, initialized) {
|
|
|
22
22
|
value: initialValue,
|
|
23
23
|
constraint: (_options$constraint = options.constraint) !== null && _options$constraint !== void 0 ? _options$constraint : {},
|
|
24
24
|
validated: (_lastResult$state$val = lastResult === null || lastResult === void 0 || (_lastResult$state = lastResult.state) === null || _lastResult$state === void 0 ? void 0 : _lastResult$state.validated) !== null && _lastResult$state$val !== void 0 ? _lastResult$state$val : {},
|
|
25
|
-
key:
|
|
26
|
-
'': util.generateId()
|
|
27
|
-
}, getDefaultKey(defaultValue)),
|
|
25
|
+
key: getDefaultKey(defaultValue),
|
|
28
26
|
// The `lastResult` should comes from the server which we won't expect the error to be null
|
|
29
27
|
// We can consider adding a warning if it happens
|
|
30
28
|
error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
|
|
@@ -43,7 +41,9 @@ function getDefaultKey(defaultValue, prefix) {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
return result;
|
|
46
|
-
}, {
|
|
44
|
+
}, {
|
|
45
|
+
[prefix !== null && prefix !== void 0 ? prefix : '']: util.generateId()
|
|
46
|
+
});
|
|
47
47
|
}
|
|
48
48
|
function setFieldsValidated(meta, fields) {
|
|
49
49
|
for (var _name of Object.keys(meta.error).concat(fields !== null && fields !== void 0 ? fields : [])) {
|
|
@@ -147,9 +147,7 @@ function updateValue(meta, name, value) {
|
|
|
147
147
|
if (name === '') {
|
|
148
148
|
meta.initialValue = value;
|
|
149
149
|
meta.value = value;
|
|
150
|
-
meta.key =
|
|
151
|
-
'': util.generateId()
|
|
152
|
-
});
|
|
150
|
+
meta.key = getDefaultKey(value);
|
|
153
151
|
return;
|
|
154
152
|
}
|
|
155
153
|
meta.initialValue = util.clone(meta.initialValue);
|
package/form.mjs
CHANGED
|
@@ -18,9 +18,7 @@ function createFormMeta(options, initialized) {
|
|
|
18
18
|
value: initialValue,
|
|
19
19
|
constraint: (_options$constraint = options.constraint) !== null && _options$constraint !== void 0 ? _options$constraint : {},
|
|
20
20
|
validated: (_lastResult$state$val = lastResult === null || lastResult === void 0 || (_lastResult$state = lastResult.state) === null || _lastResult$state === void 0 ? void 0 : _lastResult$state.validated) !== null && _lastResult$state$val !== void 0 ? _lastResult$state$val : {},
|
|
21
|
-
key:
|
|
22
|
-
'': generateId()
|
|
23
|
-
}, getDefaultKey(defaultValue)),
|
|
21
|
+
key: getDefaultKey(defaultValue),
|
|
24
22
|
// The `lastResult` should comes from the server which we won't expect the error to be null
|
|
25
23
|
// We can consider adding a warning if it happens
|
|
26
24
|
error: (_ref = lastResult === null || lastResult === void 0 ? void 0 : lastResult.error) !== null && _ref !== void 0 ? _ref : {}
|
|
@@ -39,7 +37,9 @@ function getDefaultKey(defaultValue, prefix) {
|
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
return result;
|
|
42
|
-
}, {
|
|
40
|
+
}, {
|
|
41
|
+
[prefix !== null && prefix !== void 0 ? prefix : '']: generateId()
|
|
42
|
+
});
|
|
43
43
|
}
|
|
44
44
|
function setFieldsValidated(meta, fields) {
|
|
45
45
|
for (var _name of Object.keys(meta.error).concat(fields !== null && fields !== void 0 ? fields : [])) {
|
|
@@ -143,9 +143,7 @@ function updateValue(meta, name, value) {
|
|
|
143
143
|
if (name === '') {
|
|
144
144
|
meta.initialValue = value;
|
|
145
145
|
meta.value = value;
|
|
146
|
-
meta.key =
|
|
147
|
-
'': generateId()
|
|
148
|
-
});
|
|
146
|
+
meta.key = getDefaultKey(value);
|
|
149
147
|
return;
|
|
150
148
|
}
|
|
151
149
|
meta.initialValue = clone(meta.initialValue);
|
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.
|
|
6
|
+
"version": "1.2.0",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
package/submission.d.ts
CHANGED
|
@@ -2,9 +2,12 @@ import type { DefaultValue, FieldName, FormValue } from './form';
|
|
|
2
2
|
export type SubmissionState = {
|
|
3
3
|
validated: Record<string, boolean>;
|
|
4
4
|
};
|
|
5
|
+
export type SubmissionPayload<Entry extends FormDataEntryValue> = Entry | SubmissionPayload<Entry>[] | {
|
|
6
|
+
[key: string]: SubmissionPayload<Entry>;
|
|
7
|
+
};
|
|
5
8
|
export type SubmissionContext<Value = null, FormError = string[]> = {
|
|
6
9
|
intent: Intent | null;
|
|
7
|
-
payload: Record<string,
|
|
10
|
+
payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
|
|
8
11
|
fields: Set<string>;
|
|
9
12
|
value?: Value;
|
|
10
13
|
error?: Record<string, FormError | null> | null;
|
|
@@ -12,19 +15,19 @@ export type SubmissionContext<Value = null, FormError = string[]> = {
|
|
|
12
15
|
};
|
|
13
16
|
export type Submission<Schema, FormError = string[], FormValue = Schema> = {
|
|
14
17
|
status: 'success';
|
|
15
|
-
payload: Record<string,
|
|
18
|
+
payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
|
|
16
19
|
value: FormValue;
|
|
17
20
|
reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
|
|
18
21
|
} | {
|
|
19
22
|
status: 'error' | undefined;
|
|
20
|
-
payload: Record<string,
|
|
23
|
+
payload: Record<string, SubmissionPayload<FormDataEntryValue>>;
|
|
21
24
|
error: Record<string, FormError | null> | null;
|
|
22
25
|
reply(options?: ReplyOptions<FormError>): SubmissionResult<FormError>;
|
|
23
26
|
};
|
|
24
27
|
export type SubmissionResult<FormError = string[]> = {
|
|
25
28
|
status?: 'error' | 'success';
|
|
26
29
|
intent?: Intent;
|
|
27
|
-
initialValue?: Record<string,
|
|
30
|
+
initialValue?: Record<string, SubmissionPayload<string>> | null;
|
|
28
31
|
fields?: string[];
|
|
29
32
|
error?: Record<string, FormError | null>;
|
|
30
33
|
state?: SubmissionState;
|
package/submission.js
CHANGED
|
@@ -115,7 +115,7 @@ function createSubmission(context) {
|
|
|
115
115
|
};
|
|
116
116
|
}
|
|
117
117
|
function replySubmission(context) {
|
|
118
|
-
var _context$intent, _context$intent$paylo, _options$formErrors,
|
|
118
|
+
var _context$intent, _context$intent$paylo, _options$formErrors, _ref;
|
|
119
119
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
120
120
|
if ('resetForm' in options && options.resetForm || ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) === 'reset' && ((_context$intent$paylo = context.intent.payload.name) !== null && _context$intent$paylo !== void 0 ? _context$intent$paylo : '') === '') {
|
|
121
121
|
return {
|
|
@@ -134,12 +134,17 @@ function replySubmission(context) {
|
|
|
134
134
|
'': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
|
|
135
135
|
}, options.fieldErrors)) : null;
|
|
136
136
|
var error = context.error || extraError ? _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, context.error), extraError) : undefined;
|
|
137
|
+
var initialValue = (_ref = formdata.normalize(context.payload,
|
|
138
|
+
// We can't serialize the file and send it back from the server, but we can preserve it in the client
|
|
139
|
+
typeof document !== 'undefined'
|
|
140
|
+
// We need the file on the client because it's treated as the form value
|
|
141
|
+
// But we will exclude the File type for now as it's only used by the internal
|
|
142
|
+
// form state and we will remove the need to preserve the file on the client soon
|
|
143
|
+
)) !== null && _ref !== void 0 ? _ref : {};
|
|
137
144
|
return {
|
|
138
145
|
status: context.intent ? undefined : error ? 'error' : 'success',
|
|
139
146
|
intent: context.intent ? context.intent : undefined,
|
|
140
|
-
initialValue
|
|
141
|
-
// We can't serialize the file and send it back from the server, but we can preserve it in the client
|
|
142
|
-
typeof document !== 'undefined')) !== null && _normalize !== void 0 ? _normalize : {},
|
|
147
|
+
initialValue,
|
|
143
148
|
error,
|
|
144
149
|
state: context.state,
|
|
145
150
|
fields: Array.from(context.fields)
|
|
@@ -209,9 +214,9 @@ function setState(state, name, valueFn) {
|
|
|
209
214
|
var keys = Object.keys(state).sort((prev, next) => next.localeCompare(prev));
|
|
210
215
|
var target = {};
|
|
211
216
|
var _loop2 = function _loop2() {
|
|
212
|
-
var value = state[
|
|
213
|
-
if (formdata.isPrefix(
|
|
214
|
-
formdata.setValue(target,
|
|
217
|
+
var value = state[_key];
|
|
218
|
+
if (formdata.isPrefix(_key, name) && _key !== name) {
|
|
219
|
+
formdata.setValue(target, _key, currentValue => {
|
|
215
220
|
if (typeof currentValue === 'undefined') {
|
|
216
221
|
return value;
|
|
217
222
|
}
|
|
@@ -225,10 +230,10 @@ function setState(state, name, valueFn) {
|
|
|
225
230
|
});
|
|
226
231
|
|
|
227
232
|
// Remove the value from the data
|
|
228
|
-
delete state[
|
|
233
|
+
delete state[_key];
|
|
229
234
|
}
|
|
230
235
|
};
|
|
231
|
-
for (var
|
|
236
|
+
for (var _key of keys) {
|
|
232
237
|
_loop2();
|
|
233
238
|
}
|
|
234
239
|
var result = valueFn(formdata.getValue(target, name));
|
|
@@ -266,8 +271,8 @@ function setListState(state, intent, getDefaultValue) {
|
|
|
266
271
|
function serialize(defaultValue) {
|
|
267
272
|
if (formdata.isPlainObject(defaultValue)) {
|
|
268
273
|
// @ts-expect-error FIXME
|
|
269
|
-
return Object.entries(defaultValue).reduce((result,
|
|
270
|
-
var [key, value] =
|
|
274
|
+
return Object.entries(defaultValue).reduce((result, _ref2) => {
|
|
275
|
+
var [key, value] = _ref2;
|
|
271
276
|
result[key] = serialize(value);
|
|
272
277
|
return result;
|
|
273
278
|
}, {});
|
package/submission.mjs
CHANGED
|
@@ -111,7 +111,7 @@ function createSubmission(context) {
|
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
113
|
function replySubmission(context) {
|
|
114
|
-
var _context$intent, _context$intent$paylo, _options$formErrors,
|
|
114
|
+
var _context$intent, _context$intent$paylo, _options$formErrors, _ref;
|
|
115
115
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
116
116
|
if ('resetForm' in options && options.resetForm || ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) === 'reset' && ((_context$intent$paylo = context.intent.payload.name) !== null && _context$intent$paylo !== void 0 ? _context$intent$paylo : '') === '') {
|
|
117
117
|
return {
|
|
@@ -130,12 +130,17 @@ function replySubmission(context) {
|
|
|
130
130
|
'': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
|
|
131
131
|
}, options.fieldErrors)) : null;
|
|
132
132
|
var error = context.error || extraError ? _objectSpread2(_objectSpread2({}, context.error), extraError) : undefined;
|
|
133
|
+
var initialValue = (_ref = normalize(context.payload,
|
|
134
|
+
// We can't serialize the file and send it back from the server, but we can preserve it in the client
|
|
135
|
+
typeof document !== 'undefined'
|
|
136
|
+
// We need the file on the client because it's treated as the form value
|
|
137
|
+
// But we will exclude the File type for now as it's only used by the internal
|
|
138
|
+
// form state and we will remove the need to preserve the file on the client soon
|
|
139
|
+
)) !== null && _ref !== void 0 ? _ref : {};
|
|
133
140
|
return {
|
|
134
141
|
status: context.intent ? undefined : error ? 'error' : 'success',
|
|
135
142
|
intent: context.intent ? context.intent : undefined,
|
|
136
|
-
initialValue
|
|
137
|
-
// We can't serialize the file and send it back from the server, but we can preserve it in the client
|
|
138
|
-
typeof document !== 'undefined')) !== null && _normalize !== void 0 ? _normalize : {},
|
|
143
|
+
initialValue,
|
|
139
144
|
error,
|
|
140
145
|
state: context.state,
|
|
141
146
|
fields: Array.from(context.fields)
|
|
@@ -205,9 +210,9 @@ function setState(state, name, valueFn) {
|
|
|
205
210
|
var keys = Object.keys(state).sort((prev, next) => next.localeCompare(prev));
|
|
206
211
|
var target = {};
|
|
207
212
|
var _loop2 = function _loop2() {
|
|
208
|
-
var value = state[
|
|
209
|
-
if (isPrefix(
|
|
210
|
-
setValue(target,
|
|
213
|
+
var value = state[_key];
|
|
214
|
+
if (isPrefix(_key, name) && _key !== name) {
|
|
215
|
+
setValue(target, _key, currentValue => {
|
|
211
216
|
if (typeof currentValue === 'undefined') {
|
|
212
217
|
return value;
|
|
213
218
|
}
|
|
@@ -221,10 +226,10 @@ function setState(state, name, valueFn) {
|
|
|
221
226
|
});
|
|
222
227
|
|
|
223
228
|
// Remove the value from the data
|
|
224
|
-
delete state[
|
|
229
|
+
delete state[_key];
|
|
225
230
|
}
|
|
226
231
|
};
|
|
227
|
-
for (var
|
|
232
|
+
for (var _key of keys) {
|
|
228
233
|
_loop2();
|
|
229
234
|
}
|
|
230
235
|
var result = valueFn(getValue(target, name));
|
|
@@ -262,8 +267,8 @@ function setListState(state, intent, getDefaultValue) {
|
|
|
262
267
|
function serialize(defaultValue) {
|
|
263
268
|
if (isPlainObject(defaultValue)) {
|
|
264
269
|
// @ts-expect-error FIXME
|
|
265
|
-
return Object.entries(defaultValue).reduce((result,
|
|
266
|
-
var [key, value] =
|
|
270
|
+
return Object.entries(defaultValue).reduce((result, _ref2) => {
|
|
271
|
+
var [key, value] = _ref2;
|
|
267
272
|
result[key] = serialize(value);
|
|
268
273
|
return result;
|
|
269
274
|
}, {});
|