@conform-to/dom 1.0.0 → 1.0.2
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/README +16 -11
- package/form.d.ts +8 -8
- package/form.js +14 -10
- package/form.mjs +15 -11
- package/formdata.d.ts +4 -4
- package/formdata.js +16 -7
- package/formdata.mjs +16 -7
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/submission.js +8 -8
- package/submission.mjs +9 -9
package/README
CHANGED
|
@@ -8,25 +8,30 @@
|
|
|
8
8
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Version 1.0.
|
|
11
|
+
Version 1.0.2 / License MIT / Copyright (c) 2024 Edmund Hung
|
|
12
12
|
|
|
13
13
|
A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
# Getting Started
|
|
16
16
|
|
|
17
17
|
Check out the overview and tutorial at our website https://conform.guide
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
# Features
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
- Progressive enhancement first APIs
|
|
22
|
+
- Type-safe field inference
|
|
23
|
+
- Fine-grained subscription
|
|
24
|
+
- Built-in accessibility helpers
|
|
25
|
+
- Automatic type coercion with Zod
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
* Examples: https://conform.guide/examples
|
|
25
|
-
* Complex structures: https://conform.guide/complex-structures
|
|
26
|
-
* UI Integrations: https://conform.guide/integrations
|
|
27
|
-
* Accessibility Guide: https://conform.guide/accessibility
|
|
28
|
-
* API Reference: https://conform.guide/references
|
|
27
|
+
# Documentation
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
- Validation: https://conform.guide/validation
|
|
30
|
+
- Nested object and Array: https://conform.guide/complex-structures
|
|
31
|
+
- UI Integrations: https://conform.guide/integration/ui-libraries
|
|
32
|
+
- Intent button: https://conform.guide/intent-button
|
|
33
|
+
- Accessibility Guide: https://conform.guide/accessibility
|
|
34
|
+
|
|
35
|
+
# Support
|
|
31
36
|
|
|
32
37
|
To report a bug, please open an issue on the repository at https://github.com/edmundhung/conform. For feature requests and questions, you can post them in the Discussions section.
|
package/form.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getFormAction, getFormEncType, getFormMethod } from './dom';
|
|
2
2
|
import { type Intent, type Submission, type SubmissionResult } from './submission';
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
[
|
|
6
|
-
}
|
|
7
|
-
export type DefaultValue<Schema> = Schema extends string | number | boolean | Date | 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
|
|
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;
|
|
4
|
+
export type Combine<T> = {
|
|
5
|
+
[K in keyof BaseCombine<T>]: BaseCombine<T>[K];
|
|
6
|
+
};
|
|
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 Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>;
|
|
9
9
|
} | null | undefined : string | null | undefined;
|
|
10
|
-
export type FormValue<Schema> = Schema extends string | number | boolean | Date | null | undefined ? string | undefined : Schema extends File ? File | undefined : Schema extends Array<infer Item> ? Array<FormValue<Item>> | undefined : Schema extends Record<string, any> ? {
|
|
11
|
-
[Key in
|
|
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 Combine<Schema>]?: DefaultValue<Combine<Schema>[Key]>;
|
|
12
12
|
} | undefined : unknown;
|
|
13
13
|
declare const error: unique symbol;
|
|
14
14
|
declare const field: unique symbol;
|
package/form.js
CHANGED
|
@@ -11,7 +11,9 @@ var submission = require('./submission.js');
|
|
|
11
11
|
function createFormMeta(options, initialized) {
|
|
12
12
|
var _lastResult$initialVa, _options$constraint, _lastResult$state$val, _lastResult$state, _ref;
|
|
13
13
|
var lastResult = !initialized ? options.lastResult : undefined;
|
|
14
|
-
var defaultValue = options.defaultValue ?
|
|
14
|
+
var defaultValue = options.defaultValue ?
|
|
15
|
+
// @ts-expect-error
|
|
16
|
+
submission.serialize(options.defaultValue) : {};
|
|
15
17
|
var initialValue = (_lastResult$initialVa = lastResult === null || lastResult === void 0 ? void 0 : lastResult.initialValue) !== null && _lastResult$initialVa !== void 0 ? _lastResult$initialVa : defaultValue;
|
|
16
18
|
var result = {
|
|
17
19
|
submissionStatus: lastResult === null || lastResult === void 0 ? void 0 : lastResult.status,
|
|
@@ -52,7 +54,7 @@ function handleIntent(meta, intent, initialized) {
|
|
|
52
54
|
if (typeof intent.payload.value !== 'undefined') {
|
|
53
55
|
var _intent$payload$name;
|
|
54
56
|
var _name = (_intent$payload$name = intent.payload.name) !== null && _intent$payload$name !== void 0 ? _intent$payload$name : '';
|
|
55
|
-
var value = intent.payload.value;
|
|
57
|
+
var value = submission.serialize(intent.payload.value);
|
|
56
58
|
updateValue(meta, _name, value);
|
|
57
59
|
}
|
|
58
60
|
break;
|
|
@@ -96,12 +98,15 @@ function createStateProxy(fn) {
|
|
|
96
98
|
return new Proxy(cache, {
|
|
97
99
|
get(_, name, receiver) {
|
|
98
100
|
var _cache$name;
|
|
101
|
+
if (typeof name !== 'string') {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
99
104
|
return (_cache$name = cache[name]) !== null && _cache$name !== void 0 ? _cache$name : cache[name] = fn(name, receiver);
|
|
100
105
|
}
|
|
101
106
|
});
|
|
102
107
|
}
|
|
103
108
|
function createValueProxy(value) {
|
|
104
|
-
var val = formdata.
|
|
109
|
+
var val = formdata.normalize(value);
|
|
105
110
|
return createStateProxy((name, proxy) => {
|
|
106
111
|
if (name === '') {
|
|
107
112
|
return val;
|
|
@@ -210,9 +215,7 @@ function createFormContext(options) {
|
|
|
210
215
|
var meta = createFormMeta(options);
|
|
211
216
|
var state = createFormState(meta);
|
|
212
217
|
function getFormElement() {
|
|
213
|
-
|
|
214
|
-
util.invariant(element !== null, "Form#".concat(latestOptions.formId, " does not exist"));
|
|
215
|
-
return element;
|
|
218
|
+
return document.forms.namedItem(latestOptions.formId);
|
|
216
219
|
}
|
|
217
220
|
function createFormState(next) {
|
|
218
221
|
var prev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : next;
|
|
@@ -316,7 +319,7 @@ function createFormContext(options) {
|
|
|
316
319
|
function resolveTarget(event) {
|
|
317
320
|
var form = getFormElement();
|
|
318
321
|
var element = event.target;
|
|
319
|
-
if (!dom.isFieldElement(element) || element.form !== form || element.name === '') {
|
|
322
|
+
if (!form || !dom.isFieldElement(element) || element.form !== form || element.name === '') {
|
|
320
323
|
return null;
|
|
321
324
|
}
|
|
322
325
|
return element;
|
|
@@ -372,7 +375,7 @@ function createFormContext(options) {
|
|
|
372
375
|
var _result$error, _result$state$validat, _result$state;
|
|
373
376
|
var formElement = getFormElement();
|
|
374
377
|
if (!result.initialValue) {
|
|
375
|
-
formElement.reset();
|
|
378
|
+
formElement === null || formElement === void 0 || formElement.reset();
|
|
376
379
|
return;
|
|
377
380
|
}
|
|
378
381
|
var error = Object.entries((_result$error = result.error) !== null && _result$error !== void 0 ? _result$error : {}).reduce((result, _ref4) => {
|
|
@@ -393,7 +396,7 @@ function createFormContext(options) {
|
|
|
393
396
|
handleIntent(update, result.intent, true);
|
|
394
397
|
}
|
|
395
398
|
updateFormMeta(update);
|
|
396
|
-
if (result.status === 'error') {
|
|
399
|
+
if (formElement && result.status === 'error') {
|
|
397
400
|
for (var element of formElement.elements) {
|
|
398
401
|
if (dom.isFieldElement(element) && error[element.name]) {
|
|
399
402
|
element.focus();
|
|
@@ -409,7 +412,8 @@ function createFormContext(options) {
|
|
|
409
412
|
// Merge new options with the latest options
|
|
410
413
|
Object.assign(latestOptions, options);
|
|
411
414
|
if (latestOptions.formId !== currentFormId) {
|
|
412
|
-
|
|
415
|
+
var _getFormElement;
|
|
416
|
+
(_getFormElement = getFormElement()) === null || _getFormElement === void 0 || _getFormElement.reset();
|
|
413
417
|
} else if (options.lastResult && options.lastResult !== currentResult) {
|
|
414
418
|
report(options.lastResult);
|
|
415
419
|
}
|
package/form.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
import { flatten, formatPaths, getPaths, getValue, setValue, isPlainObject,
|
|
2
|
+
import { flatten, formatPaths, getPaths, getValue, setValue, isPlainObject, normalize, getFormData, isPrefix } from './formdata.mjs';
|
|
3
3
|
import { getFormAction, getFormEncType, getFormMethod, isFieldElement, requestSubmit } from './dom.mjs';
|
|
4
4
|
import { generateId, clone, invariant } from './util.mjs';
|
|
5
5
|
import { serialize, setListState, setListValue, setState, getSubmissionContext, INTENT, serializeIntent, STATE } from './submission.mjs';
|
|
@@ -7,7 +7,9 @@ import { serialize, setListState, setListValue, setState, getSubmissionContext,
|
|
|
7
7
|
function createFormMeta(options, initialized) {
|
|
8
8
|
var _lastResult$initialVa, _options$constraint, _lastResult$state$val, _lastResult$state, _ref;
|
|
9
9
|
var lastResult = !initialized ? options.lastResult : undefined;
|
|
10
|
-
var defaultValue = options.defaultValue ?
|
|
10
|
+
var defaultValue = options.defaultValue ?
|
|
11
|
+
// @ts-expect-error
|
|
12
|
+
serialize(options.defaultValue) : {};
|
|
11
13
|
var initialValue = (_lastResult$initialVa = lastResult === null || lastResult === void 0 ? void 0 : lastResult.initialValue) !== null && _lastResult$initialVa !== void 0 ? _lastResult$initialVa : defaultValue;
|
|
12
14
|
var result = {
|
|
13
15
|
submissionStatus: lastResult === null || lastResult === void 0 ? void 0 : lastResult.status,
|
|
@@ -48,7 +50,7 @@ function handleIntent(meta, intent, initialized) {
|
|
|
48
50
|
if (typeof intent.payload.value !== 'undefined') {
|
|
49
51
|
var _intent$payload$name;
|
|
50
52
|
var _name = (_intent$payload$name = intent.payload.name) !== null && _intent$payload$name !== void 0 ? _intent$payload$name : '';
|
|
51
|
-
var value = intent.payload.value;
|
|
53
|
+
var value = serialize(intent.payload.value);
|
|
52
54
|
updateValue(meta, _name, value);
|
|
53
55
|
}
|
|
54
56
|
break;
|
|
@@ -92,12 +94,15 @@ function createStateProxy(fn) {
|
|
|
92
94
|
return new Proxy(cache, {
|
|
93
95
|
get(_, name, receiver) {
|
|
94
96
|
var _cache$name;
|
|
97
|
+
if (typeof name !== 'string') {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
95
100
|
return (_cache$name = cache[name]) !== null && _cache$name !== void 0 ? _cache$name : cache[name] = fn(name, receiver);
|
|
96
101
|
}
|
|
97
102
|
});
|
|
98
103
|
}
|
|
99
104
|
function createValueProxy(value) {
|
|
100
|
-
var val =
|
|
105
|
+
var val = normalize(value);
|
|
101
106
|
return createStateProxy((name, proxy) => {
|
|
102
107
|
if (name === '') {
|
|
103
108
|
return val;
|
|
@@ -206,9 +211,7 @@ function createFormContext(options) {
|
|
|
206
211
|
var meta = createFormMeta(options);
|
|
207
212
|
var state = createFormState(meta);
|
|
208
213
|
function getFormElement() {
|
|
209
|
-
|
|
210
|
-
invariant(element !== null, "Form#".concat(latestOptions.formId, " does not exist"));
|
|
211
|
-
return element;
|
|
214
|
+
return document.forms.namedItem(latestOptions.formId);
|
|
212
215
|
}
|
|
213
216
|
function createFormState(next) {
|
|
214
217
|
var prev = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : next;
|
|
@@ -312,7 +315,7 @@ function createFormContext(options) {
|
|
|
312
315
|
function resolveTarget(event) {
|
|
313
316
|
var form = getFormElement();
|
|
314
317
|
var element = event.target;
|
|
315
|
-
if (!isFieldElement(element) || element.form !== form || element.name === '') {
|
|
318
|
+
if (!form || !isFieldElement(element) || element.form !== form || element.name === '') {
|
|
316
319
|
return null;
|
|
317
320
|
}
|
|
318
321
|
return element;
|
|
@@ -368,7 +371,7 @@ function createFormContext(options) {
|
|
|
368
371
|
var _result$error, _result$state$validat, _result$state;
|
|
369
372
|
var formElement = getFormElement();
|
|
370
373
|
if (!result.initialValue) {
|
|
371
|
-
formElement.reset();
|
|
374
|
+
formElement === null || formElement === void 0 || formElement.reset();
|
|
372
375
|
return;
|
|
373
376
|
}
|
|
374
377
|
var error = Object.entries((_result$error = result.error) !== null && _result$error !== void 0 ? _result$error : {}).reduce((result, _ref4) => {
|
|
@@ -389,7 +392,7 @@ function createFormContext(options) {
|
|
|
389
392
|
handleIntent(update, result.intent, true);
|
|
390
393
|
}
|
|
391
394
|
updateFormMeta(update);
|
|
392
|
-
if (result.status === 'error') {
|
|
395
|
+
if (formElement && result.status === 'error') {
|
|
393
396
|
for (var element of formElement.elements) {
|
|
394
397
|
if (isFieldElement(element) && error[element.name]) {
|
|
395
398
|
element.focus();
|
|
@@ -405,7 +408,8 @@ function createFormContext(options) {
|
|
|
405
408
|
// Merge new options with the latest options
|
|
406
409
|
Object.assign(latestOptions, options);
|
|
407
410
|
if (latestOptions.formId !== currentFormId) {
|
|
408
|
-
|
|
411
|
+
var _getFormElement;
|
|
412
|
+
(_getFormElement = getFormElement()) === null || _getFormElement === void 0 || _getFormElement.reset();
|
|
409
413
|
} else if (options.lastResult && options.lastResult !== currentResult) {
|
|
410
414
|
report(options.lastResult);
|
|
411
415
|
}
|
package/formdata.d.ts
CHANGED
|
@@ -43,11 +43,11 @@ export declare function isPlainObject(obj: unknown): obj is Record<string | numb
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function isFile(obj: unknown): obj is File;
|
|
45
45
|
/**
|
|
46
|
-
*
|
|
46
|
+
* Normalize value by removing empty object or array, empty string and null values
|
|
47
47
|
*/
|
|
48
|
-
export declare function
|
|
49
|
-
export declare function
|
|
50
|
-
export declare function
|
|
48
|
+
export declare function normalize<Type extends Record<string, unknown>>(value: Type | null): Type | null | undefined;
|
|
49
|
+
export declare function normalize<Type extends Array<unknown>>(value: Type | null): Type | null | undefined;
|
|
50
|
+
export declare function normalize(value: unknown): unknown | undefined;
|
|
51
51
|
/**
|
|
52
52
|
* Flatten a tree into a dictionary
|
|
53
53
|
*/
|
package/formdata.js
CHANGED
|
@@ -132,13 +132,13 @@ function isFile(obj) {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
135
|
+
* Normalize value by removing empty object or array, empty string and null values
|
|
136
136
|
*/
|
|
137
137
|
|
|
138
|
-
function
|
|
138
|
+
function normalize(value) {
|
|
139
139
|
if (isPlainObject(value)) {
|
|
140
140
|
var obj = Object.keys(value).sort().reduce((result, key) => {
|
|
141
|
-
var data =
|
|
141
|
+
var data = normalize(value[key]);
|
|
142
142
|
if (typeof data !== 'undefined') {
|
|
143
143
|
result[key] = data;
|
|
144
144
|
}
|
|
@@ -153,11 +153,20 @@ function simplify(value) {
|
|
|
153
153
|
if (value.length === 0) {
|
|
154
154
|
return undefined;
|
|
155
155
|
}
|
|
156
|
-
return value.map(
|
|
156
|
+
return value.map(normalize);
|
|
157
157
|
}
|
|
158
|
-
if (typeof value === 'string' && value === '' || value === null || isFile(value)) {
|
|
158
|
+
if (typeof value === 'string' && value === '' || value === null || isFile(value) && value.size === 0) {
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
+
|
|
162
|
+
// We will skip serializing file if the result is sent to the client
|
|
163
|
+
if (isFile(value)) {
|
|
164
|
+
return Object.assign(value, {
|
|
165
|
+
toJSON() {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
161
170
|
return value;
|
|
162
171
|
}
|
|
163
172
|
|
|
@@ -169,7 +178,7 @@ function flatten(data, options) {
|
|
|
169
178
|
var result = {};
|
|
170
179
|
var resolve = (_options$resolve = options === null || options === void 0 ? void 0 : options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data;
|
|
171
180
|
function setResult(data, name) {
|
|
172
|
-
var value =
|
|
181
|
+
var value = normalize(resolve(data));
|
|
173
182
|
if (typeof value !== 'undefined') {
|
|
174
183
|
result[name] = value;
|
|
175
184
|
}
|
|
@@ -221,5 +230,5 @@ exports.getValue = getValue;
|
|
|
221
230
|
exports.isFile = isFile;
|
|
222
231
|
exports.isPlainObject = isPlainObject;
|
|
223
232
|
exports.isPrefix = isPrefix;
|
|
233
|
+
exports.normalize = normalize;
|
|
224
234
|
exports.setValue = setValue;
|
|
225
|
-
exports.simplify = simplify;
|
package/formdata.mjs
CHANGED
|
@@ -128,13 +128,13 @@ function isFile(obj) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
|
-
*
|
|
131
|
+
* Normalize value by removing empty object or array, empty string and null values
|
|
132
132
|
*/
|
|
133
133
|
|
|
134
|
-
function
|
|
134
|
+
function normalize(value) {
|
|
135
135
|
if (isPlainObject(value)) {
|
|
136
136
|
var obj = Object.keys(value).sort().reduce((result, key) => {
|
|
137
|
-
var data =
|
|
137
|
+
var data = normalize(value[key]);
|
|
138
138
|
if (typeof data !== 'undefined') {
|
|
139
139
|
result[key] = data;
|
|
140
140
|
}
|
|
@@ -149,11 +149,20 @@ function simplify(value) {
|
|
|
149
149
|
if (value.length === 0) {
|
|
150
150
|
return undefined;
|
|
151
151
|
}
|
|
152
|
-
return value.map(
|
|
152
|
+
return value.map(normalize);
|
|
153
153
|
}
|
|
154
|
-
if (typeof value === 'string' && value === '' || value === null || isFile(value)) {
|
|
154
|
+
if (typeof value === 'string' && value === '' || value === null || isFile(value) && value.size === 0) {
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
+
|
|
158
|
+
// We will skip serializing file if the result is sent to the client
|
|
159
|
+
if (isFile(value)) {
|
|
160
|
+
return Object.assign(value, {
|
|
161
|
+
toJSON() {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
157
166
|
return value;
|
|
158
167
|
}
|
|
159
168
|
|
|
@@ -165,7 +174,7 @@ function flatten(data, options) {
|
|
|
165
174
|
var result = {};
|
|
166
175
|
var resolve = (_options$resolve = options === null || options === void 0 ? void 0 : options.resolve) !== null && _options$resolve !== void 0 ? _options$resolve : data => data;
|
|
167
176
|
function setResult(data, name) {
|
|
168
|
-
var value =
|
|
177
|
+
var value = normalize(resolve(data));
|
|
169
178
|
if (typeof value !== 'undefined') {
|
|
170
179
|
result[name] = value;
|
|
171
180
|
}
|
|
@@ -209,4 +218,4 @@ function flatten(data, options) {
|
|
|
209
218
|
return result;
|
|
210
219
|
}
|
|
211
220
|
|
|
212
|
-
export { flatten, formatPaths, getFormData, getPaths, getValue, isFile, isPlainObject, isPrefix,
|
|
221
|
+
export { flatten, formatPaths, getFormData, getPaths, getValue, isFile, isPlainObject, isPrefix, normalize, setValue };
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type
|
|
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';
|
|
2
2
|
export { type FieldElement, isFieldElement } from './dom';
|
|
3
3
|
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
|
|
4
4
|
export { getPaths, formatPaths, isPrefix } from './formdata';
|
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.0.
|
|
6
|
+
"version": "1.0.2",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
package/submission.js
CHANGED
|
@@ -62,9 +62,9 @@ function parse(payload, options) {
|
|
|
62
62
|
{
|
|
63
63
|
var {
|
|
64
64
|
name,
|
|
65
|
-
value: _value,
|
|
66
65
|
validated
|
|
67
66
|
} = intent.payload;
|
|
67
|
+
var _value = serialize(intent.payload.value);
|
|
68
68
|
if (typeof _value !== 'undefined') {
|
|
69
69
|
if (name) {
|
|
70
70
|
formdata.setValue(context.payload, name, () => _value);
|
|
@@ -161,7 +161,7 @@ function createSubmission(context) {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
function replySubmission(context) {
|
|
164
|
-
var _context$intent,
|
|
164
|
+
var _context$intent, _options$formErrors, _normalize;
|
|
165
165
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
166
166
|
switch ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) {
|
|
167
167
|
case 'reset':
|
|
@@ -188,21 +188,21 @@ function replySubmission(context) {
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
|
-
var submissionError = Object.entries(
|
|
191
|
+
var submissionError = context.error ? Object.entries(context.error).reduce((result, _ref) => {
|
|
192
192
|
var [name, error] = _ref;
|
|
193
193
|
if (context.state.validated[name]) {
|
|
194
194
|
result[name] = error;
|
|
195
195
|
}
|
|
196
196
|
return result;
|
|
197
|
-
}, {});
|
|
198
|
-
var extraError = 'formErrors' in options || 'fieldErrors' in options ? formdata.
|
|
199
|
-
'': options.formErrors
|
|
197
|
+
}, {}) : undefined;
|
|
198
|
+
var extraError = 'formErrors' in options || 'fieldErrors' in options ? formdata.normalize(_rollupPluginBabelHelpers.objectSpread2({
|
|
199
|
+
'': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
|
|
200
200
|
}, options.fieldErrors)) : null;
|
|
201
|
-
var error =
|
|
201
|
+
var error = submissionError || extraError ? _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, submissionError), extraError) : undefined;
|
|
202
202
|
return {
|
|
203
203
|
status: context.intent ? undefined : error ? 'error' : 'success',
|
|
204
204
|
intent: context.intent ? context.intent : undefined,
|
|
205
|
-
initialValue: (
|
|
205
|
+
initialValue: (_normalize = formdata.normalize(context.payload)) !== null && _normalize !== void 0 ? _normalize : {},
|
|
206
206
|
error,
|
|
207
207
|
state: context.state
|
|
208
208
|
};
|
package/submission.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
import { setValue, isPlainObject, flatten, getValue,
|
|
2
|
+
import { setValue, isPlainObject, flatten, getValue, normalize, isPrefix } from './formdata.mjs';
|
|
3
3
|
import { invariant } from './util.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -58,9 +58,9 @@ function parse(payload, options) {
|
|
|
58
58
|
{
|
|
59
59
|
var {
|
|
60
60
|
name,
|
|
61
|
-
value: _value,
|
|
62
61
|
validated
|
|
63
62
|
} = intent.payload;
|
|
63
|
+
var _value = serialize(intent.payload.value);
|
|
64
64
|
if (typeof _value !== 'undefined') {
|
|
65
65
|
if (name) {
|
|
66
66
|
setValue(context.payload, name, () => _value);
|
|
@@ -157,7 +157,7 @@ function createSubmission(context) {
|
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
function replySubmission(context) {
|
|
160
|
-
var _context$intent,
|
|
160
|
+
var _context$intent, _options$formErrors, _normalize;
|
|
161
161
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
162
162
|
switch ((_context$intent = context.intent) === null || _context$intent === void 0 ? void 0 : _context$intent.type) {
|
|
163
163
|
case 'reset':
|
|
@@ -184,21 +184,21 @@ function replySubmission(context) {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
var submissionError = Object.entries(
|
|
187
|
+
var submissionError = context.error ? Object.entries(context.error).reduce((result, _ref) => {
|
|
188
188
|
var [name, error] = _ref;
|
|
189
189
|
if (context.state.validated[name]) {
|
|
190
190
|
result[name] = error;
|
|
191
191
|
}
|
|
192
192
|
return result;
|
|
193
|
-
}, {});
|
|
194
|
-
var extraError = 'formErrors' in options || 'fieldErrors' in options ?
|
|
195
|
-
'': options.formErrors
|
|
193
|
+
}, {}) : undefined;
|
|
194
|
+
var extraError = 'formErrors' in options || 'fieldErrors' in options ? normalize(_objectSpread2({
|
|
195
|
+
'': (_options$formErrors = options.formErrors) !== null && _options$formErrors !== void 0 ? _options$formErrors : null
|
|
196
196
|
}, options.fieldErrors)) : null;
|
|
197
|
-
var error =
|
|
197
|
+
var error = submissionError || extraError ? _objectSpread2(_objectSpread2({}, submissionError), extraError) : undefined;
|
|
198
198
|
return {
|
|
199
199
|
status: context.intent ? undefined : error ? 'error' : 'success',
|
|
200
200
|
intent: context.intent ? context.intent : undefined,
|
|
201
|
-
initialValue: (
|
|
201
|
+
initialValue: (_normalize = normalize(context.payload)) !== null && _normalize !== void 0 ? _normalize : {},
|
|
202
202
|
error,
|
|
203
203
|
state: context.state
|
|
204
204
|
};
|