@conform-to/react 1.18.0 → 1.19.1
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.md +1 -1
- package/dist/future/dom.js +6 -2
- package/dist/future/dom.mjs +6 -2
- package/dist/future/forms.d.ts +1157 -26
- package/dist/future/forms.js +152 -23
- package/dist/future/forms.mjs +150 -26
- package/dist/future/hooks.d.ts +25 -164
- package/dist/future/hooks.js +49 -372
- package/dist/future/hooks.mjs +54 -369
- package/dist/future/index.d.ts +3 -3
- package/dist/future/index.js +5 -6
- package/dist/future/index.mjs +2 -2
- package/dist/future/intent.js +24 -12
- package/dist/future/intent.mjs +24 -12
- package/dist/future/memoize.d.ts +1 -1
- package/dist/future/memoize.js +1 -1
- package/dist/future/memoize.mjs +1 -1
- package/dist/future/state.d.ts +8 -12
- package/dist/future/state.js +24 -27
- package/dist/future/state.mjs +25 -28
- package/dist/future/types.d.ts +66 -111
- package/dist/future/util.d.ts +6 -10
- package/dist/future/util.js +17 -20
- package/dist/future/util.mjs +16 -19
- package/dist/helpers.d.ts +14 -10
- package/dist/helpers.js +14 -10
- package/dist/helpers.mjs +14 -10
- package/dist/integrations.js +8 -10
- package/dist/integrations.mjs +8 -10
- package/package.json +2 -2
package/dist/future/intent.js
CHANGED
|
@@ -215,27 +215,39 @@ var intentHandlers = {
|
|
|
215
215
|
console.warn('intent.insert() with `onInvalid` or `from` requires the validation result to be available synchronously. ' + 'These options are ignored because the error is not yet known.');
|
|
216
216
|
return result;
|
|
217
217
|
}
|
|
218
|
-
var
|
|
219
|
-
if (options.onInvalid === 'revert' &&
|
|
218
|
+
var listError = (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.fieldErrors[options.name];
|
|
219
|
+
if (options.onInvalid === 'revert' && listError != null) {
|
|
220
220
|
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
|
|
221
221
|
targetValue: undefined
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
224
|
if (options.from !== undefined) {
|
|
225
|
-
var _options$index2, _result$error2;
|
|
225
|
+
var _options$index2, _result$error2, _result$error3;
|
|
226
226
|
var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : util.getPathArray(result.submission.payload, options.name).length;
|
|
227
227
|
var insertedItemPath = future.appendPath(options.name, index);
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
var
|
|
228
|
+
var insertedItemError = (_result$error2 = result.error) === null || _result$error2 === void 0 ? void 0 : _result$error2.fieldErrors[insertedItemPath];
|
|
229
|
+
var fromFieldError = (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.fieldErrors[options.from];
|
|
230
|
+
if (fromFieldError != null) {
|
|
231
|
+
var _result$error$formErr, _result$error4, _result$error5;
|
|
232
232
|
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
|
|
233
233
|
targetValue: undefined,
|
|
234
234
|
error: {
|
|
235
|
-
formErrors: (_result$error$formErr = (_result$error4 = result.error) === null || _result$error4 === void 0 ? void 0 : _result$error4.formErrors) !== null && _result$error$formErr !== void 0 ? _result$error$formErr :
|
|
235
|
+
formErrors: (_result$error$formErr = (_result$error4 = result.error) === null || _result$error4 === void 0 ? void 0 : _result$error4.formErrors) !== null && _result$error$formErr !== void 0 ? _result$error$formErr : null,
|
|
236
236
|
fieldErrors: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, (_result$error5 = result.error) === null || _result$error5 === void 0 ? void 0 : _result$error5.fieldErrors), {}, {
|
|
237
|
-
[
|
|
238
|
-
|
|
237
|
+
[insertedItemPath]: null
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
if (insertedItemError != null) {
|
|
243
|
+
var _result$error$formErr2, _result$error6, _result$error7;
|
|
244
|
+
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
|
|
245
|
+
targetValue: undefined,
|
|
246
|
+
error: {
|
|
247
|
+
formErrors: (_result$error$formErr2 = (_result$error6 = result.error) === null || _result$error6 === void 0 ? void 0 : _result$error6.formErrors) !== null && _result$error$formErr2 !== void 0 ? _result$error$formErr2 : null,
|
|
248
|
+
fieldErrors: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, (_result$error7 = result.error) === null || _result$error7 === void 0 ? void 0 : _result$error7.fieldErrors), {}, {
|
|
249
|
+
[options.from]: insertedItemError,
|
|
250
|
+
[insertedItemPath]: null
|
|
239
251
|
})
|
|
240
252
|
}
|
|
241
253
|
});
|
|
@@ -293,7 +305,7 @@ var intentHandlers = {
|
|
|
293
305
|
return util.updatePathValue(value, options.name, list);
|
|
294
306
|
},
|
|
295
307
|
apply(result, options) {
|
|
296
|
-
var _result$
|
|
308
|
+
var _result$error8;
|
|
297
309
|
// Warn if validation result is not yet available
|
|
298
310
|
if (typeof result.error === 'undefined' && options.onInvalid) {
|
|
299
311
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -302,7 +314,7 @@ var intentHandlers = {
|
|
|
302
314
|
}
|
|
303
315
|
return result;
|
|
304
316
|
}
|
|
305
|
-
if (result.targetValue && (_result$
|
|
317
|
+
if (result.targetValue && (_result$error8 = result.error) !== null && _result$error8 !== void 0 && _result$error8.fieldErrors[options.name]) {
|
|
306
318
|
switch (options.onInvalid) {
|
|
307
319
|
case 'revert':
|
|
308
320
|
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
|
package/dist/future/intent.mjs
CHANGED
|
@@ -211,27 +211,39 @@ var intentHandlers = {
|
|
|
211
211
|
console.warn('intent.insert() with `onInvalid` or `from` requires the validation result to be available synchronously. ' + 'These options are ignored because the error is not yet known.');
|
|
212
212
|
return result;
|
|
213
213
|
}
|
|
214
|
-
var
|
|
215
|
-
if (options.onInvalid === 'revert' &&
|
|
214
|
+
var listError = (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.fieldErrors[options.name];
|
|
215
|
+
if (options.onInvalid === 'revert' && listError != null) {
|
|
216
216
|
return _objectSpread2(_objectSpread2({}, result), {}, {
|
|
217
217
|
targetValue: undefined
|
|
218
218
|
});
|
|
219
219
|
}
|
|
220
220
|
if (options.from !== undefined) {
|
|
221
|
-
var _options$index2, _result$error2;
|
|
221
|
+
var _options$index2, _result$error2, _result$error3;
|
|
222
222
|
var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : getPathArray(result.submission.payload, options.name).length;
|
|
223
223
|
var insertedItemPath = appendPath(options.name, index);
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
var
|
|
224
|
+
var insertedItemError = (_result$error2 = result.error) === null || _result$error2 === void 0 ? void 0 : _result$error2.fieldErrors[insertedItemPath];
|
|
225
|
+
var fromFieldError = (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.fieldErrors[options.from];
|
|
226
|
+
if (fromFieldError != null) {
|
|
227
|
+
var _result$error$formErr, _result$error4, _result$error5;
|
|
228
228
|
return _objectSpread2(_objectSpread2({}, result), {}, {
|
|
229
229
|
targetValue: undefined,
|
|
230
230
|
error: {
|
|
231
|
-
formErrors: (_result$error$formErr = (_result$error4 = result.error) === null || _result$error4 === void 0 ? void 0 : _result$error4.formErrors) !== null && _result$error$formErr !== void 0 ? _result$error$formErr :
|
|
231
|
+
formErrors: (_result$error$formErr = (_result$error4 = result.error) === null || _result$error4 === void 0 ? void 0 : _result$error4.formErrors) !== null && _result$error$formErr !== void 0 ? _result$error$formErr : null,
|
|
232
232
|
fieldErrors: _objectSpread2(_objectSpread2({}, (_result$error5 = result.error) === null || _result$error5 === void 0 ? void 0 : _result$error5.fieldErrors), {}, {
|
|
233
|
-
[
|
|
234
|
-
|
|
233
|
+
[insertedItemPath]: null
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
if (insertedItemError != null) {
|
|
239
|
+
var _result$error$formErr2, _result$error6, _result$error7;
|
|
240
|
+
return _objectSpread2(_objectSpread2({}, result), {}, {
|
|
241
|
+
targetValue: undefined,
|
|
242
|
+
error: {
|
|
243
|
+
formErrors: (_result$error$formErr2 = (_result$error6 = result.error) === null || _result$error6 === void 0 ? void 0 : _result$error6.formErrors) !== null && _result$error$formErr2 !== void 0 ? _result$error$formErr2 : null,
|
|
244
|
+
fieldErrors: _objectSpread2(_objectSpread2({}, (_result$error7 = result.error) === null || _result$error7 === void 0 ? void 0 : _result$error7.fieldErrors), {}, {
|
|
245
|
+
[options.from]: insertedItemError,
|
|
246
|
+
[insertedItemPath]: null
|
|
235
247
|
})
|
|
236
248
|
}
|
|
237
249
|
});
|
|
@@ -289,7 +301,7 @@ var intentHandlers = {
|
|
|
289
301
|
return updatePathValue(value, options.name, list);
|
|
290
302
|
},
|
|
291
303
|
apply(result, options) {
|
|
292
|
-
var _result$
|
|
304
|
+
var _result$error8;
|
|
293
305
|
// Warn if validation result is not yet available
|
|
294
306
|
if (typeof result.error === 'undefined' && options.onInvalid) {
|
|
295
307
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -298,7 +310,7 @@ var intentHandlers = {
|
|
|
298
310
|
}
|
|
299
311
|
return result;
|
|
300
312
|
}
|
|
301
|
-
if (result.targetValue && (_result$
|
|
313
|
+
if (result.targetValue && (_result$error8 = result.error) !== null && _result$error8 !== void 0 && _result$error8.fieldErrors[options.name]) {
|
|
302
314
|
switch (options.onInvalid) {
|
|
303
315
|
case 'revert':
|
|
304
316
|
return _objectSpread2(_objectSpread2({}, result), {}, {
|
package/dist/future/memoize.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare function defaultEqualityCheck(prevArgs: any[], nextArgs: any[]):
|
|
|
24
24
|
* @param isEqual - Custom equality function to compare arguments (defaults to shallow comparison)
|
|
25
25
|
* @returns Memoized function with cache clearing capability
|
|
26
26
|
*
|
|
27
|
-
*
|
|
27
|
+
* **Example:**
|
|
28
28
|
* ```ts
|
|
29
29
|
* // Async validation with API call
|
|
30
30
|
* const validateUsername = useMemo(
|
package/dist/future/memoize.js
CHANGED
|
@@ -35,7 +35,7 @@ function defaultEqualityCheck(prevArgs, nextArgs) {
|
|
|
35
35
|
* @param isEqual - Custom equality function to compare arguments (defaults to shallow comparison)
|
|
36
36
|
* @returns Memoized function with cache clearing capability
|
|
37
37
|
*
|
|
38
|
-
*
|
|
38
|
+
* **Example:**
|
|
39
39
|
* ```ts
|
|
40
40
|
* // Async validation with API call
|
|
41
41
|
* const validateUsername = useMemo(
|
package/dist/future/memoize.mjs
CHANGED
|
@@ -31,7 +31,7 @@ function defaultEqualityCheck(prevArgs, nextArgs) {
|
|
|
31
31
|
* @param isEqual - Custom equality function to compare arguments (defaults to shallow comparison)
|
|
32
32
|
* @returns Memoized function with cache clearing capability
|
|
33
33
|
*
|
|
34
|
-
*
|
|
34
|
+
* **Example:**
|
|
35
35
|
* ```ts
|
|
36
36
|
* // Async validation with API call
|
|
37
37
|
* const validateUsername = useMemo(
|
package/dist/future/state.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FieldName,
|
|
1
|
+
import { type FieldName, FormError } from '@conform-to/dom/future';
|
|
2
2
|
import type { FieldMetadata, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, IntentHandler, BaseFieldMetadata, BaseFormMetadata, DefineConditionalField } from './types';
|
|
3
3
|
export declare function initializeState<ErrorShape>(options?: {
|
|
4
4
|
defaultValue?: Record<string, unknown> | null | undefined;
|
|
@@ -20,10 +20,10 @@ export declare function updateState<ErrorShape>(state: FormState<ErrorShape>, ac
|
|
|
20
20
|
* Minimizes UI state loss by only invalidating keys when necessary.
|
|
21
21
|
*/
|
|
22
22
|
export declare function pruneListKeys(listKeys: Record<string, string[]>, targetValue: Record<string, unknown>): Record<string, string[]>;
|
|
23
|
-
export declare function getDefaultPayload(context: FormContext<any>, name: string
|
|
24
|
-
export declare function getDefaultValue(context: FormContext<any>, name: string
|
|
25
|
-
export declare function getDefaultOptions(context: FormContext<any>, name: string
|
|
26
|
-
export declare function isDefaultChecked(context: FormContext<any>, name: string
|
|
23
|
+
export declare function getDefaultPayload(context: FormContext<any>, name: string): unknown;
|
|
24
|
+
export declare function getDefaultValue(context: FormContext<any>, name: string): string;
|
|
25
|
+
export declare function getDefaultOptions(context: FormContext<any>, name: string): string[];
|
|
26
|
+
export declare function isDefaultChecked(context: FormContext<any>, name: string): boolean;
|
|
27
27
|
/**
|
|
28
28
|
* Determine if the field is touched
|
|
29
29
|
*
|
|
@@ -33,15 +33,14 @@ export declare function isDefaultChecked(context: FormContext<any>, name: string
|
|
|
33
33
|
export declare function isTouched(state: FormState<any>, name?: string): boolean;
|
|
34
34
|
export declare function getDefaultListKey(prefix: string, initialValue: Record<string, unknown> | null, name: string): string[];
|
|
35
35
|
export declare function getListKey(context: FormContext<any>, name: string): string[];
|
|
36
|
-
export declare function getErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): ErrorShape
|
|
37
|
-
export declare function getFieldErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): Record<string, ErrorShape
|
|
36
|
+
export declare function getErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): ErrorShape | undefined;
|
|
37
|
+
export declare function getFieldErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): Record<string, ErrorShape>;
|
|
38
38
|
/**
|
|
39
39
|
* Checks if fieldErrors contains any errors at the given name or any child path.
|
|
40
40
|
*/
|
|
41
|
-
export declare function hasFieldError(error: FormError<
|
|
41
|
+
export declare function hasFieldError<ErrorShape>(error: FormError<ErrorShape>, name: string): boolean;
|
|
42
42
|
export declare function isValid(state: FormState<any>, name?: string): boolean;
|
|
43
43
|
export declare function getFormMetadata<ErrorShape, CustomFormMetadata extends Record<string, unknown> = {}, CustomFieldMetadata extends Record<string, unknown> = {}>(context: FormContext<ErrorShape>, options?: {
|
|
44
|
-
serialize?: Serialize | undefined;
|
|
45
44
|
extendFormMetadata?: ((metadata: BaseFormMetadata<ErrorShape>) => CustomFormMetadata) | undefined;
|
|
46
45
|
extendFieldMetadata?: (<FieldShape>(metadata: BaseFieldMetadata<FieldShape, ErrorShape>, ctx: {
|
|
47
46
|
form: BaseFormMetadata<ErrorShape>;
|
|
@@ -50,7 +49,6 @@ export declare function getFormMetadata<ErrorShape, CustomFormMetadata extends R
|
|
|
50
49
|
}): FormMetadata<ErrorShape, CustomFormMetadata, CustomFieldMetadata>;
|
|
51
50
|
export declare function getField<FieldShape, ErrorShape = string, CustomFieldMetadata extends Record<string, unknown> = {}>(context: FormContext<ErrorShape>, options: {
|
|
52
51
|
name: FieldName<FieldShape>;
|
|
53
|
-
serialize?: Serialize | undefined;
|
|
54
52
|
extendFieldMetadata?: (<F>(metadata: BaseFieldMetadata<F, ErrorShape>, ctx: {
|
|
55
53
|
form: BaseFormMetadata<ErrorShape>;
|
|
56
54
|
when: DefineConditionalField;
|
|
@@ -63,7 +61,6 @@ export declare function getField<FieldShape, ErrorShape = string, CustomFieldMet
|
|
|
63
61
|
*/
|
|
64
62
|
export declare function getFieldset<FieldShape = Record<string, any>, ErrorShape = string, CustomFieldMetadata extends Record<string, unknown> = {}>(context: FormContext<ErrorShape>, options: {
|
|
65
63
|
name?: FieldName<FieldShape> | undefined;
|
|
66
|
-
serialize?: Serialize | undefined;
|
|
67
64
|
extendFieldMetadata?: (<F>(metadata: BaseFieldMetadata<F, ErrorShape>, ctx: {
|
|
68
65
|
form: BaseFormMetadata<ErrorShape>;
|
|
69
66
|
when: DefineConditionalField;
|
|
@@ -75,7 +72,6 @@ export declare function getFieldset<FieldShape = Record<string, any>, ErrorShape
|
|
|
75
72
|
*/
|
|
76
73
|
export declare function getFieldList<FieldShape = Array<any>, ErrorShape = string, CustomFieldMetadata extends Record<string, unknown> = {}>(context: FormContext<ErrorShape>, options: {
|
|
77
74
|
name: FieldName<FieldShape>;
|
|
78
|
-
serialize?: Serialize | undefined;
|
|
79
75
|
extendFieldMetadata?: (<F>(metadata: BaseFieldMetadata<F, ErrorShape>, ctx: {
|
|
80
76
|
form: BaseFormMetadata<ErrorShape>;
|
|
81
77
|
when: DefineConditionalField;
|
package/dist/future/state.js
CHANGED
|
@@ -100,15 +100,18 @@ function pruneListKeys(listKeys, targetValue) {
|
|
|
100
100
|
}
|
|
101
101
|
function getDefaultPayload(context, name) {
|
|
102
102
|
var _ref, _context$state$server;
|
|
103
|
-
var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
|
|
104
103
|
var value = future.getPathValue((_ref = (_context$state$server = context.state.serverValue) !== null && _context$state$server !== void 0 ? _context$state$server : context.state.targetValue) !== null && _ref !== void 0 ? _ref : context.state.defaultValue, name);
|
|
105
|
-
|
|
104
|
+
if (value === null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
return future.normalize(value, context.serialize, name);
|
|
106
108
|
}
|
|
107
109
|
function getDefaultValue(context, name) {
|
|
108
110
|
var _ref2, _context$state$server2;
|
|
109
|
-
var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
|
|
110
111
|
var value = future.getPathValue((_ref2 = (_context$state$server2 = context.state.serverValue) !== null && _context$state$server2 !== void 0 ? _context$state$server2 : context.state.targetValue) !== null && _ref2 !== void 0 ? _ref2 : context.state.defaultValue, name);
|
|
111
|
-
var serializedValue = serialize(value
|
|
112
|
+
var serializedValue = context.serialize(value, {
|
|
113
|
+
name
|
|
114
|
+
});
|
|
112
115
|
if (typeof serializedValue === 'string') {
|
|
113
116
|
return serializedValue;
|
|
114
117
|
}
|
|
@@ -116,9 +119,10 @@ function getDefaultValue(context, name) {
|
|
|
116
119
|
}
|
|
117
120
|
function getDefaultOptions(context, name) {
|
|
118
121
|
var _ref3, _context$state$server3;
|
|
119
|
-
var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
|
|
120
122
|
var value = future.getPathValue((_ref3 = (_context$state$server3 = context.state.serverValue) !== null && _context$state$server3 !== void 0 ? _context$state$server3 : context.state.targetValue) !== null && _ref3 !== void 0 ? _ref3 : context.state.defaultValue, name);
|
|
121
|
-
var serializedValue = serialize(value
|
|
123
|
+
var serializedValue = context.serialize(value, {
|
|
124
|
+
name
|
|
125
|
+
});
|
|
122
126
|
if (Array.isArray(serializedValue) && serializedValue.every(item => typeof item === 'string')) {
|
|
123
127
|
return serializedValue;
|
|
124
128
|
}
|
|
@@ -129,11 +133,14 @@ function getDefaultOptions(context, name) {
|
|
|
129
133
|
}
|
|
130
134
|
function isDefaultChecked(context, name) {
|
|
131
135
|
var _ref4, _context$state$server4;
|
|
132
|
-
var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
|
|
133
136
|
var value = future.getPathValue((_ref4 = (_context$state$server4 = context.state.serverValue) !== null && _context$state$server4 !== void 0 ? _context$state$server4 : context.state.targetValue) !== null && _ref4 !== void 0 ? _ref4 : context.state.defaultValue, name);
|
|
134
|
-
var serializedValue = serialize(value
|
|
137
|
+
var serializedValue = context.serialize(value, {
|
|
138
|
+
name
|
|
139
|
+
});
|
|
135
140
|
if (typeof serializedValue === 'string') {
|
|
136
|
-
return serializedValue === serialize(true
|
|
141
|
+
return serializedValue === context.serialize(true, {
|
|
142
|
+
name
|
|
143
|
+
});
|
|
137
144
|
}
|
|
138
145
|
return false;
|
|
139
146
|
}
|
|
@@ -166,7 +173,7 @@ function getErrors(state, name) {
|
|
|
166
173
|
return;
|
|
167
174
|
}
|
|
168
175
|
var errors = name ? error.fieldErrors[name] : error.formErrors;
|
|
169
|
-
if (errors
|
|
176
|
+
if (errors != null) {
|
|
170
177
|
return errors;
|
|
171
178
|
}
|
|
172
179
|
}
|
|
@@ -197,9 +204,9 @@ function getFieldErrors(state, name) {
|
|
|
197
204
|
*/
|
|
198
205
|
function hasFieldError(error, name) {
|
|
199
206
|
var basePath = future.parsePath(name);
|
|
200
|
-
return Object.
|
|
201
|
-
var
|
|
202
|
-
return future.getRelativePath(field, basePath) !== null &&
|
|
207
|
+
return Object.entries(error.fieldErrors).some(_ref6 => {
|
|
208
|
+
var [field, fieldError] = _ref6;
|
|
209
|
+
return future.getRelativePath(field, basePath) !== null && fieldError !== null;
|
|
203
210
|
});
|
|
204
211
|
}
|
|
205
212
|
function isValid(state, name) {
|
|
@@ -264,21 +271,18 @@ function getFormMetadata(context, options) {
|
|
|
264
271
|
getField(name) {
|
|
265
272
|
return getField(context, {
|
|
266
273
|
name,
|
|
267
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
268
274
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
269
275
|
});
|
|
270
276
|
},
|
|
271
277
|
getFieldset(name) {
|
|
272
278
|
return getFieldset(context, {
|
|
273
279
|
name,
|
|
274
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
275
280
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
276
281
|
});
|
|
277
282
|
},
|
|
278
283
|
getFieldList(name) {
|
|
279
284
|
return getFieldList(context, {
|
|
280
285
|
name,
|
|
281
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
282
286
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
283
287
|
});
|
|
284
288
|
}
|
|
@@ -294,10 +298,8 @@ function getField(context, options) {
|
|
|
294
298
|
var {
|
|
295
299
|
key,
|
|
296
300
|
name,
|
|
297
|
-
serialize = future.serialize,
|
|
298
301
|
extendFieldMetadata,
|
|
299
302
|
form = getFormMetadata(context, {
|
|
300
|
-
serialize,
|
|
301
303
|
extendFieldMetadata
|
|
302
304
|
})
|
|
303
305
|
} = options;
|
|
@@ -320,16 +322,16 @@ function getField(context, options) {
|
|
|
320
322
|
multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
|
|
321
323
|
accept: constraint === null || constraint === void 0 ? void 0 : constraint.accept,
|
|
322
324
|
get defaultValue() {
|
|
323
|
-
return getDefaultValue(context, name
|
|
325
|
+
return getDefaultValue(context, name);
|
|
324
326
|
},
|
|
325
327
|
get defaultOptions() {
|
|
326
|
-
return getDefaultOptions(context, name
|
|
328
|
+
return getDefaultOptions(context, name);
|
|
327
329
|
},
|
|
328
330
|
get defaultChecked() {
|
|
329
|
-
return isDefaultChecked(context, name
|
|
331
|
+
return isDefaultChecked(context, name);
|
|
330
332
|
},
|
|
331
333
|
get defaultPayload() {
|
|
332
|
-
return getDefaultPayload(context, name
|
|
334
|
+
return getDefaultPayload(context, name);
|
|
333
335
|
},
|
|
334
336
|
get touched() {
|
|
335
337
|
return isTouched(context.state, name);
|
|
@@ -355,7 +357,6 @@ function getField(context, options) {
|
|
|
355
357
|
getFieldset() {
|
|
356
358
|
return getFieldset(context, {
|
|
357
359
|
name: name,
|
|
358
|
-
serialize,
|
|
359
360
|
extendFieldMetadata
|
|
360
361
|
});
|
|
361
362
|
},
|
|
@@ -364,7 +365,6 @@ function getField(context, options) {
|
|
|
364
365
|
getFieldList() {
|
|
365
366
|
return getFieldList(context, {
|
|
366
367
|
name,
|
|
367
|
-
serialize,
|
|
368
368
|
extendFieldMetadata
|
|
369
369
|
});
|
|
370
370
|
}
|
|
@@ -388,12 +388,10 @@ function getFieldset(context, options) {
|
|
|
388
388
|
if (typeof name === 'string') {
|
|
389
389
|
var _options$form;
|
|
390
390
|
(_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
|
|
391
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
392
391
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
393
392
|
});
|
|
394
393
|
return getField(context, {
|
|
395
394
|
name: future.appendPath(options === null || options === void 0 ? void 0 : options.name, name),
|
|
396
|
-
serialize: options.serialize,
|
|
397
395
|
extendFieldMetadata: options.extendFieldMetadata,
|
|
398
396
|
form: options.form
|
|
399
397
|
});
|
|
@@ -411,7 +409,6 @@ function getFieldList(context, options) {
|
|
|
411
409
|
return keys.map((key, index) => {
|
|
412
410
|
return getField(context, {
|
|
413
411
|
name: future.appendPath(options.name, index),
|
|
414
|
-
serialize: options.serialize,
|
|
415
412
|
extendFieldMetadata: options.extendFieldMetadata,
|
|
416
413
|
key
|
|
417
414
|
});
|
package/dist/future/state.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
-
import { parsePath, getRelativePath,
|
|
2
|
+
import { parsePath, getRelativePath, appendPath, deepEqual, getPathValue, normalize, formatPath } from '@conform-to/dom/future';
|
|
3
3
|
import { when, generateUniqueKey, merge, getPathArray } from './util.mjs';
|
|
4
4
|
|
|
5
5
|
function initializeState(options) {
|
|
@@ -96,15 +96,18 @@ function pruneListKeys(listKeys, targetValue) {
|
|
|
96
96
|
}
|
|
97
97
|
function getDefaultPayload(context, name) {
|
|
98
98
|
var _ref, _context$state$server;
|
|
99
|
-
var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
|
|
100
99
|
var value = getPathValue((_ref = (_context$state$server = context.state.serverValue) !== null && _context$state$server !== void 0 ? _context$state$server : context.state.targetValue) !== null && _ref !== void 0 ? _ref : context.state.defaultValue, name);
|
|
101
|
-
|
|
100
|
+
if (value === null) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
return normalize(value, context.serialize, name);
|
|
102
104
|
}
|
|
103
105
|
function getDefaultValue(context, name) {
|
|
104
106
|
var _ref2, _context$state$server2;
|
|
105
|
-
var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
|
|
106
107
|
var value = getPathValue((_ref2 = (_context$state$server2 = context.state.serverValue) !== null && _context$state$server2 !== void 0 ? _context$state$server2 : context.state.targetValue) !== null && _ref2 !== void 0 ? _ref2 : context.state.defaultValue, name);
|
|
107
|
-
var serializedValue = serialize
|
|
108
|
+
var serializedValue = context.serialize(value, {
|
|
109
|
+
name
|
|
110
|
+
});
|
|
108
111
|
if (typeof serializedValue === 'string') {
|
|
109
112
|
return serializedValue;
|
|
110
113
|
}
|
|
@@ -112,9 +115,10 @@ function getDefaultValue(context, name) {
|
|
|
112
115
|
}
|
|
113
116
|
function getDefaultOptions(context, name) {
|
|
114
117
|
var _ref3, _context$state$server3;
|
|
115
|
-
var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
|
|
116
118
|
var value = getPathValue((_ref3 = (_context$state$server3 = context.state.serverValue) !== null && _context$state$server3 !== void 0 ? _context$state$server3 : context.state.targetValue) !== null && _ref3 !== void 0 ? _ref3 : context.state.defaultValue, name);
|
|
117
|
-
var serializedValue = serialize
|
|
119
|
+
var serializedValue = context.serialize(value, {
|
|
120
|
+
name
|
|
121
|
+
});
|
|
118
122
|
if (Array.isArray(serializedValue) && serializedValue.every(item => typeof item === 'string')) {
|
|
119
123
|
return serializedValue;
|
|
120
124
|
}
|
|
@@ -125,11 +129,14 @@ function getDefaultOptions(context, name) {
|
|
|
125
129
|
}
|
|
126
130
|
function isDefaultChecked(context, name) {
|
|
127
131
|
var _ref4, _context$state$server4;
|
|
128
|
-
var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
|
|
129
132
|
var value = getPathValue((_ref4 = (_context$state$server4 = context.state.serverValue) !== null && _context$state$server4 !== void 0 ? _context$state$server4 : context.state.targetValue) !== null && _ref4 !== void 0 ? _ref4 : context.state.defaultValue, name);
|
|
130
|
-
var serializedValue = serialize
|
|
133
|
+
var serializedValue = context.serialize(value, {
|
|
134
|
+
name
|
|
135
|
+
});
|
|
131
136
|
if (typeof serializedValue === 'string') {
|
|
132
|
-
return serializedValue === serialize
|
|
137
|
+
return serializedValue === context.serialize(true, {
|
|
138
|
+
name
|
|
139
|
+
});
|
|
133
140
|
}
|
|
134
141
|
return false;
|
|
135
142
|
}
|
|
@@ -162,7 +169,7 @@ function getErrors(state, name) {
|
|
|
162
169
|
return;
|
|
163
170
|
}
|
|
164
171
|
var errors = name ? error.fieldErrors[name] : error.formErrors;
|
|
165
|
-
if (errors
|
|
172
|
+
if (errors != null) {
|
|
166
173
|
return errors;
|
|
167
174
|
}
|
|
168
175
|
}
|
|
@@ -193,9 +200,9 @@ function getFieldErrors(state, name) {
|
|
|
193
200
|
*/
|
|
194
201
|
function hasFieldError(error, name) {
|
|
195
202
|
var basePath = parsePath(name);
|
|
196
|
-
return Object.
|
|
197
|
-
var
|
|
198
|
-
return getRelativePath(field, basePath) !== null &&
|
|
203
|
+
return Object.entries(error.fieldErrors).some(_ref6 => {
|
|
204
|
+
var [field, fieldError] = _ref6;
|
|
205
|
+
return getRelativePath(field, basePath) !== null && fieldError !== null;
|
|
199
206
|
});
|
|
200
207
|
}
|
|
201
208
|
function isValid(state, name) {
|
|
@@ -260,21 +267,18 @@ function getFormMetadata(context, options) {
|
|
|
260
267
|
getField(name) {
|
|
261
268
|
return getField(context, {
|
|
262
269
|
name,
|
|
263
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
264
270
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
265
271
|
});
|
|
266
272
|
},
|
|
267
273
|
getFieldset(name) {
|
|
268
274
|
return getFieldset(context, {
|
|
269
275
|
name,
|
|
270
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
271
276
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
272
277
|
});
|
|
273
278
|
},
|
|
274
279
|
getFieldList(name) {
|
|
275
280
|
return getFieldList(context, {
|
|
276
281
|
name,
|
|
277
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
278
282
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
279
283
|
});
|
|
280
284
|
}
|
|
@@ -290,10 +294,8 @@ function getField(context, options) {
|
|
|
290
294
|
var {
|
|
291
295
|
key,
|
|
292
296
|
name,
|
|
293
|
-
serialize: serialize$1 = serialize,
|
|
294
297
|
extendFieldMetadata,
|
|
295
298
|
form = getFormMetadata(context, {
|
|
296
|
-
serialize: serialize$1,
|
|
297
299
|
extendFieldMetadata
|
|
298
300
|
})
|
|
299
301
|
} = options;
|
|
@@ -316,16 +318,16 @@ function getField(context, options) {
|
|
|
316
318
|
multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
|
|
317
319
|
accept: constraint === null || constraint === void 0 ? void 0 : constraint.accept,
|
|
318
320
|
get defaultValue() {
|
|
319
|
-
return getDefaultValue(context, name
|
|
321
|
+
return getDefaultValue(context, name);
|
|
320
322
|
},
|
|
321
323
|
get defaultOptions() {
|
|
322
|
-
return getDefaultOptions(context, name
|
|
324
|
+
return getDefaultOptions(context, name);
|
|
323
325
|
},
|
|
324
326
|
get defaultChecked() {
|
|
325
|
-
return isDefaultChecked(context, name
|
|
327
|
+
return isDefaultChecked(context, name);
|
|
326
328
|
},
|
|
327
329
|
get defaultPayload() {
|
|
328
|
-
return getDefaultPayload(context, name
|
|
330
|
+
return getDefaultPayload(context, name);
|
|
329
331
|
},
|
|
330
332
|
get touched() {
|
|
331
333
|
return isTouched(context.state, name);
|
|
@@ -351,7 +353,6 @@ function getField(context, options) {
|
|
|
351
353
|
getFieldset() {
|
|
352
354
|
return getFieldset(context, {
|
|
353
355
|
name: name,
|
|
354
|
-
serialize: serialize$1,
|
|
355
356
|
extendFieldMetadata
|
|
356
357
|
});
|
|
357
358
|
},
|
|
@@ -360,7 +361,6 @@ function getField(context, options) {
|
|
|
360
361
|
getFieldList() {
|
|
361
362
|
return getFieldList(context, {
|
|
362
363
|
name,
|
|
363
|
-
serialize: serialize$1,
|
|
364
364
|
extendFieldMetadata
|
|
365
365
|
});
|
|
366
366
|
}
|
|
@@ -384,12 +384,10 @@ function getFieldset(context, options) {
|
|
|
384
384
|
if (typeof name === 'string') {
|
|
385
385
|
var _options$form;
|
|
386
386
|
(_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
|
|
387
|
-
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
388
387
|
extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
|
|
389
388
|
});
|
|
390
389
|
return getField(context, {
|
|
391
390
|
name: appendPath(options === null || options === void 0 ? void 0 : options.name, name),
|
|
392
|
-
serialize: options.serialize,
|
|
393
391
|
extendFieldMetadata: options.extendFieldMetadata,
|
|
394
392
|
form: options.form
|
|
395
393
|
});
|
|
@@ -407,7 +405,6 @@ function getFieldList(context, options) {
|
|
|
407
405
|
return keys.map((key, index) => {
|
|
408
406
|
return getField(context, {
|
|
409
407
|
name: appendPath(options.name, index),
|
|
410
|
-
serialize: options.serialize,
|
|
411
408
|
extendFieldMetadata: options.extendFieldMetadata,
|
|
412
409
|
key
|
|
413
410
|
});
|