@conform-to/react 1.11.0 → 1.12.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/README.md +1 -1
- package/dist/future/hooks.d.ts +14 -24
- package/dist/future/hooks.js +59 -47
- package/dist/future/hooks.mjs +58 -47
- package/dist/future/index.d.ts +2 -2
- package/dist/future/index.js +1 -0
- package/dist/future/index.mjs +1 -1
- package/dist/future/intent.js +16 -10
- package/dist/future/intent.mjs +16 -10
- package/dist/future/state.d.ts +10 -6
- package/dist/future/state.js +89 -49
- package/dist/future/state.mjs +89 -49
- package/dist/future/types.d.ts +121 -58
- package/package.json +2 -2
package/dist/future/intent.js
CHANGED
|
@@ -109,22 +109,16 @@ var actionHandlers = {
|
|
|
109
109
|
} = _ref;
|
|
110
110
|
var name = (_intent$payload = intent.payload) !== null && _intent$payload !== void 0 ? _intent$payload : '';
|
|
111
111
|
var basePath = future.getPathSegments(name);
|
|
112
|
+
var allFields = error ?
|
|
113
|
+
// Consider fields / fieldset with errors as touched too
|
|
114
|
+
submission.fields.concat(Object.keys(error.fieldErrors)) : submission.fields;
|
|
112
115
|
var touchedFields = util.appendUniqueItem(state.touchedFields, name);
|
|
113
|
-
for (var field of
|
|
116
|
+
for (var field of allFields) {
|
|
114
117
|
// Add all child fields to the touched fields too
|
|
115
118
|
if (future.getRelativePath(field, basePath) !== null) {
|
|
116
119
|
touchedFields = util.appendUniqueItem(touchedFields, field);
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
|
-
|
|
120
|
-
// We couldn't find out all the fields from the FormData, e.g. unchecked checkboxes.
|
|
121
|
-
// or fieldsets without any fields, but we can at least include missing
|
|
122
|
-
// required fields based on the form error
|
|
123
|
-
if (name === '' && error) {
|
|
124
|
-
for (var _name of Object.keys(error.fieldErrors)) {
|
|
125
|
-
touchedFields = util.appendUniqueItem(touchedFields, _name);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
122
|
return util.merge(state, {
|
|
129
123
|
touchedFields
|
|
130
124
|
});
|
|
@@ -143,6 +137,9 @@ var actionHandlers = {
|
|
|
143
137
|
submission,
|
|
144
138
|
intent
|
|
145
139
|
} = _ref2;
|
|
140
|
+
if (type === 'server') {
|
|
141
|
+
return state;
|
|
142
|
+
}
|
|
146
143
|
var listKeys = state.listKeys;
|
|
147
144
|
|
|
148
145
|
// Update the keys only for client updates to avoid double updates if there is no client validation
|
|
@@ -182,6 +179,9 @@ var actionHandlers = {
|
|
|
182
179
|
submission,
|
|
183
180
|
intent
|
|
184
181
|
} = _ref3;
|
|
182
|
+
if (type === 'server') {
|
|
183
|
+
return state$1;
|
|
184
|
+
}
|
|
185
185
|
var currentValue = submission.payload;
|
|
186
186
|
var list = util.getArrayAtPath(currentValue, intent.payload.name);
|
|
187
187
|
var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : list.length;
|
|
@@ -220,6 +220,9 @@ var actionHandlers = {
|
|
|
220
220
|
submission,
|
|
221
221
|
intent
|
|
222
222
|
} = _ref4;
|
|
223
|
+
if (type === 'server') {
|
|
224
|
+
return state$1;
|
|
225
|
+
}
|
|
223
226
|
var currentValue = submission.payload;
|
|
224
227
|
var updateListIndex = util.createPathIndexUpdater(intent.payload.name, currentIndex => {
|
|
225
228
|
if (intent.payload.index === currentIndex) {
|
|
@@ -261,6 +264,9 @@ var actionHandlers = {
|
|
|
261
264
|
submission,
|
|
262
265
|
intent
|
|
263
266
|
} = _ref5;
|
|
267
|
+
if (type === 'server') {
|
|
268
|
+
return state$1;
|
|
269
|
+
}
|
|
264
270
|
var currentValue = submission.payload;
|
|
265
271
|
var updateListIndex = util.createPathIndexUpdater(intent.payload.name, currentIndex => {
|
|
266
272
|
if (intent.payload.from === intent.payload.to) {
|
package/dist/future/intent.mjs
CHANGED
|
@@ -105,22 +105,16 @@ var actionHandlers = {
|
|
|
105
105
|
} = _ref;
|
|
106
106
|
var name = (_intent$payload = intent.payload) !== null && _intent$payload !== void 0 ? _intent$payload : '';
|
|
107
107
|
var basePath = getPathSegments(name);
|
|
108
|
+
var allFields = error ?
|
|
109
|
+
// Consider fields / fieldset with errors as touched too
|
|
110
|
+
submission.fields.concat(Object.keys(error.fieldErrors)) : submission.fields;
|
|
108
111
|
var touchedFields = appendUniqueItem(state.touchedFields, name);
|
|
109
|
-
for (var field of
|
|
112
|
+
for (var field of allFields) {
|
|
110
113
|
// Add all child fields to the touched fields too
|
|
111
114
|
if (getRelativePath(field, basePath) !== null) {
|
|
112
115
|
touchedFields = appendUniqueItem(touchedFields, field);
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
|
|
116
|
-
// We couldn't find out all the fields from the FormData, e.g. unchecked checkboxes.
|
|
117
|
-
// or fieldsets without any fields, but we can at least include missing
|
|
118
|
-
// required fields based on the form error
|
|
119
|
-
if (name === '' && error) {
|
|
120
|
-
for (var _name of Object.keys(error.fieldErrors)) {
|
|
121
|
-
touchedFields = appendUniqueItem(touchedFields, _name);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
118
|
return merge(state, {
|
|
125
119
|
touchedFields
|
|
126
120
|
});
|
|
@@ -139,6 +133,9 @@ var actionHandlers = {
|
|
|
139
133
|
submission,
|
|
140
134
|
intent
|
|
141
135
|
} = _ref2;
|
|
136
|
+
if (type === 'server') {
|
|
137
|
+
return state;
|
|
138
|
+
}
|
|
142
139
|
var listKeys = state.listKeys;
|
|
143
140
|
|
|
144
141
|
// Update the keys only for client updates to avoid double updates if there is no client validation
|
|
@@ -178,6 +175,9 @@ var actionHandlers = {
|
|
|
178
175
|
submission,
|
|
179
176
|
intent
|
|
180
177
|
} = _ref3;
|
|
178
|
+
if (type === 'server') {
|
|
179
|
+
return state;
|
|
180
|
+
}
|
|
181
181
|
var currentValue = submission.payload;
|
|
182
182
|
var list = getArrayAtPath(currentValue, intent.payload.name);
|
|
183
183
|
var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : list.length;
|
|
@@ -216,6 +216,9 @@ var actionHandlers = {
|
|
|
216
216
|
submission,
|
|
217
217
|
intent
|
|
218
218
|
} = _ref4;
|
|
219
|
+
if (type === 'server') {
|
|
220
|
+
return state;
|
|
221
|
+
}
|
|
219
222
|
var currentValue = submission.payload;
|
|
220
223
|
var updateListIndex = createPathIndexUpdater(intent.payload.name, currentIndex => {
|
|
221
224
|
if (intent.payload.index === currentIndex) {
|
|
@@ -257,6 +260,9 @@ var actionHandlers = {
|
|
|
257
260
|
submission,
|
|
258
261
|
intent
|
|
259
262
|
} = _ref5;
|
|
263
|
+
if (type === 'server') {
|
|
264
|
+
return state;
|
|
265
|
+
}
|
|
260
266
|
var currentValue = submission.payload;
|
|
261
267
|
var updateListIndex = createPathIndexUpdater(intent.payload.name, currentIndex => {
|
|
262
268
|
if (intent.payload.from === intent.payload.to) {
|
package/dist/future/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
|
|
2
|
-
import type { FieldMetadata, FieldName, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler } from './types';
|
|
2
|
+
import type { FieldMetadata, FieldName, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler, CustomMetadataDefinition } from './types';
|
|
3
3
|
export declare function initializeState<ErrorShape>(resetKey?: string): FormState<ErrorShape>;
|
|
4
4
|
/**
|
|
5
5
|
* Updates form state based on action type:
|
|
@@ -31,12 +31,14 @@ export declare function isValid(state: FormState<any>, name?: string): boolean;
|
|
|
31
31
|
* e.g. "array[0].key" falls back to "array[].key" if specific constraint not found.
|
|
32
32
|
*/
|
|
33
33
|
export declare function getConstraint(context: FormContext<any>, name: string): ValidationAttributes | undefined;
|
|
34
|
-
export declare function getFormMetadata<ErrorShape>(context: FormContext<ErrorShape>, options
|
|
35
|
-
serialize
|
|
34
|
+
export declare function getFormMetadata<ErrorShape>(context: FormContext<ErrorShape>, options?: {
|
|
35
|
+
serialize?: Serialize;
|
|
36
|
+
customize?: CustomMetadataDefinition;
|
|
36
37
|
}): FormMetadata<ErrorShape>;
|
|
37
38
|
export declare function getField<FieldShape, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
|
|
38
39
|
name: FieldName<FieldShape>;
|
|
39
|
-
serialize
|
|
40
|
+
serialize?: Serialize;
|
|
41
|
+
customize?: CustomMetadataDefinition;
|
|
40
42
|
key?: string;
|
|
41
43
|
}): FieldMetadata<FieldShape, ErrorShape>;
|
|
42
44
|
/**
|
|
@@ -44,14 +46,16 @@ export declare function getField<FieldShape, ErrorShape = string>(context: FormC
|
|
|
44
46
|
*/
|
|
45
47
|
export declare function getFieldset<FieldShape = Record<string, any>, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
|
|
46
48
|
name?: FieldName<FieldShape>;
|
|
47
|
-
serialize
|
|
49
|
+
serialize?: Serialize;
|
|
50
|
+
customize?: CustomMetadataDefinition;
|
|
48
51
|
}): Fieldset<FieldShape, ErrorShape>;
|
|
49
52
|
/**
|
|
50
53
|
* Creates an array of field objects for list/array inputs
|
|
51
54
|
*/
|
|
52
55
|
export declare function getFieldList<FieldShape = Array<any>, ErrorShape = string>(context: FormContext<ErrorShape>, options: {
|
|
53
56
|
name: FieldName<FieldShape>;
|
|
54
|
-
serialize
|
|
57
|
+
serialize?: Serialize;
|
|
58
|
+
customize?: CustomMetadataDefinition;
|
|
55
59
|
}): FieldMetadata<[
|
|
56
60
|
FieldShape
|
|
57
61
|
] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, ErrorShape>[];
|
package/dist/future/state.js
CHANGED
|
@@ -25,7 +25,7 @@ function initializeState(resetKey) {
|
|
|
25
25
|
* - Initialize: set initial intended value
|
|
26
26
|
*/
|
|
27
27
|
function updateState(state, action) {
|
|
28
|
-
var _action$intendedValue, _action$intendedValue2;
|
|
28
|
+
var _action$intendedValue, _action$intendedValue2, _action$intent, _action$ctx$handlers;
|
|
29
29
|
if (action.intendedValue === null) {
|
|
30
30
|
return action.ctx.reset();
|
|
31
31
|
}
|
|
@@ -48,23 +48,20 @@ function updateState(state, action) {
|
|
|
48
48
|
// Keep track of the value that the serverError is based on
|
|
49
49
|
serverIntendedValue: !future.deepEqual(state.serverIntendedValue, value) ? value : state.serverIntendedValue
|
|
50
50
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
51
|
+
// Validate the whole form if no intent is provided (default submission)
|
|
52
|
+
var intent = (_action$intent = action.intent) !== null && _action$intent !== void 0 ? _action$intent : {
|
|
53
|
+
type: 'validate'
|
|
54
|
+
};
|
|
55
|
+
var handler = (_action$ctx$handlers = action.ctx.handlers) === null || _action$ctx$handlers === void 0 ? void 0 : _action$ctx$handlers[intent.type];
|
|
56
|
+
if (typeof (handler === null || handler === void 0 ? void 0 : handler.onUpdate) === 'function') {
|
|
57
|
+
var _handler$validatePayl, _handler$validatePayl2;
|
|
58
|
+
if ((_handler$validatePayl = (_handler$validatePayl2 = handler.validatePayload) === null || _handler$validatePayl2 === void 0 ? void 0 : _handler$validatePayl2.call(handler, intent.payload)) !== null && _handler$validatePayl !== void 0 ? _handler$validatePayl : true) {
|
|
59
|
+
return handler.onUpdate(state, _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, action), {}, {
|
|
60
|
+
intent: {
|
|
61
|
+
type: intent.type,
|
|
62
|
+
payload: intent.payload
|
|
63
|
+
}
|
|
64
|
+
}));
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
return state;
|
|
@@ -237,27 +234,41 @@ function getFormMetadata(context, options) {
|
|
|
237
234
|
},
|
|
238
235
|
context,
|
|
239
236
|
getField(name) {
|
|
240
|
-
return getField(context,
|
|
241
|
-
name
|
|
242
|
-
|
|
237
|
+
return getField(context, {
|
|
238
|
+
name,
|
|
239
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
240
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
241
|
+
});
|
|
243
242
|
},
|
|
244
243
|
getFieldset(name) {
|
|
245
|
-
return getFieldset(context,
|
|
246
|
-
name
|
|
247
|
-
|
|
244
|
+
return getFieldset(context, {
|
|
245
|
+
name,
|
|
246
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
247
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
248
|
+
});
|
|
248
249
|
},
|
|
249
250
|
getFieldList(name) {
|
|
250
|
-
return getFieldList(context,
|
|
251
|
-
name
|
|
252
|
-
|
|
251
|
+
return getFieldList(context, {
|
|
252
|
+
name,
|
|
253
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
254
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
255
|
+
});
|
|
253
256
|
}
|
|
254
257
|
};
|
|
255
258
|
}
|
|
256
259
|
function getField(context, options) {
|
|
257
|
-
var
|
|
258
|
-
|
|
260
|
+
var {
|
|
261
|
+
key,
|
|
262
|
+
name,
|
|
263
|
+
serialize = future.serialize,
|
|
264
|
+
customize
|
|
265
|
+
} = options;
|
|
266
|
+
var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
|
|
267
|
+
var constraint = getConstraint(context, name);
|
|
259
268
|
var metadata = {
|
|
260
|
-
|
|
269
|
+
key,
|
|
270
|
+
name,
|
|
271
|
+
id,
|
|
261
272
|
descriptionId: "".concat(id, "-description"),
|
|
262
273
|
errorId: "".concat(id, "-error"),
|
|
263
274
|
formId: context.formId,
|
|
@@ -270,38 +281,63 @@ function getField(context, options) {
|
|
|
270
281
|
step: constraint === null || constraint === void 0 ? void 0 : constraint.step,
|
|
271
282
|
multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
|
|
272
283
|
get defaultValue() {
|
|
273
|
-
return getDefaultValue(context,
|
|
284
|
+
return getDefaultValue(context, name, serialize);
|
|
274
285
|
},
|
|
275
286
|
get defaultOptions() {
|
|
276
|
-
return getDefaultOptions(context,
|
|
287
|
+
return getDefaultOptions(context, name, serialize);
|
|
277
288
|
},
|
|
278
289
|
get defaultChecked() {
|
|
279
|
-
return isDefaultChecked(context,
|
|
290
|
+
return isDefaultChecked(context, name, serialize);
|
|
280
291
|
},
|
|
281
292
|
get touched() {
|
|
282
|
-
return isTouched(context.state,
|
|
293
|
+
return isTouched(context.state, name);
|
|
283
294
|
},
|
|
284
295
|
get valid() {
|
|
285
|
-
return isValid(context.state,
|
|
296
|
+
return isValid(context.state, name);
|
|
286
297
|
},
|
|
287
298
|
get invalid() {
|
|
288
299
|
return !this.valid;
|
|
289
300
|
},
|
|
290
301
|
get errors() {
|
|
291
|
-
return getErrors(context.state,
|
|
302
|
+
return getErrors(context.state, name);
|
|
292
303
|
},
|
|
293
304
|
get fieldErrors() {
|
|
294
|
-
return getFieldErrors(context.state,
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
305
|
+
return getFieldErrors(context.state, name);
|
|
306
|
+
},
|
|
307
|
+
get ariaInvalid() {
|
|
308
|
+
return !this.valid ? true : undefined;
|
|
309
|
+
},
|
|
310
|
+
get ariaDescribedBy() {
|
|
311
|
+
return !this.valid ? this.errorId : undefined;
|
|
312
|
+
},
|
|
300
313
|
getFieldset() {
|
|
301
|
-
return getFieldset(context,
|
|
314
|
+
return getFieldset(context, {
|
|
315
|
+
name: name,
|
|
316
|
+
serialize,
|
|
317
|
+
customize
|
|
318
|
+
});
|
|
302
319
|
},
|
|
303
320
|
getFieldList() {
|
|
304
|
-
return getFieldList(context,
|
|
321
|
+
return getFieldList(context, {
|
|
322
|
+
name: name,
|
|
323
|
+
serialize,
|
|
324
|
+
customize
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
if (typeof customize !== 'function') {
|
|
329
|
+
return metadata;
|
|
330
|
+
}
|
|
331
|
+
return new Proxy(metadata, {
|
|
332
|
+
get(target, prop, receiver) {
|
|
333
|
+
if (Reflect.has(target, prop)) {
|
|
334
|
+
return Reflect.get(target, prop, receiver);
|
|
335
|
+
}
|
|
336
|
+
var customMetadata = customize(metadata);
|
|
337
|
+
if (Reflect.has(customMetadata, prop)) {
|
|
338
|
+
return Reflect.get(customMetadata, prop, receiver);
|
|
339
|
+
}
|
|
340
|
+
throw new Error("Property \"".concat(String(prop), "\" does not exist on field metadata. ") + "If you have defined the CustomMetadata interface to include \"".concat(String(prop), "\", make sure to also implement it through the \"defineCustomMetadata\" property on <FormOptionsProvider />."));
|
|
305
341
|
}
|
|
306
342
|
});
|
|
307
343
|
}
|
|
@@ -313,9 +349,11 @@ function getFieldset(context, options) {
|
|
|
313
349
|
return new Proxy({}, {
|
|
314
350
|
get(target, name, receiver) {
|
|
315
351
|
if (typeof name === 'string') {
|
|
316
|
-
return getField(context,
|
|
317
|
-
name: future.appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name)
|
|
318
|
-
|
|
352
|
+
return getField(context, {
|
|
353
|
+
name: future.appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
|
|
354
|
+
serialize: options.serialize,
|
|
355
|
+
customize: options.customize
|
|
356
|
+
});
|
|
319
357
|
}
|
|
320
358
|
return Reflect.get(target, name, receiver);
|
|
321
359
|
}
|
|
@@ -328,10 +366,12 @@ function getFieldset(context, options) {
|
|
|
328
366
|
function getFieldList(context, options) {
|
|
329
367
|
var keys = getListKey(context, options.name);
|
|
330
368
|
return keys.map((key, index) => {
|
|
331
|
-
return getField(context,
|
|
369
|
+
return getField(context, {
|
|
332
370
|
name: future.appendPathSegment(options.name, index),
|
|
371
|
+
serialize: options.serialize,
|
|
372
|
+
customize: options.customize,
|
|
333
373
|
key
|
|
334
|
-
})
|
|
374
|
+
});
|
|
335
375
|
});
|
|
336
376
|
}
|
|
337
377
|
|
package/dist/future/state.mjs
CHANGED
|
@@ -21,7 +21,7 @@ function initializeState(resetKey) {
|
|
|
21
21
|
* - Initialize: set initial intended value
|
|
22
22
|
*/
|
|
23
23
|
function updateState(state, action) {
|
|
24
|
-
var _action$intendedValue, _action$intendedValue2;
|
|
24
|
+
var _action$intendedValue, _action$intendedValue2, _action$intent, _action$ctx$handlers;
|
|
25
25
|
if (action.intendedValue === null) {
|
|
26
26
|
return action.ctx.reset();
|
|
27
27
|
}
|
|
@@ -44,23 +44,20 @@ function updateState(state, action) {
|
|
|
44
44
|
// Keep track of the value that the serverError is based on
|
|
45
45
|
serverIntendedValue: !deepEqual(state.serverIntendedValue, value) ? value : state.serverIntendedValue
|
|
46
46
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
var
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
47
|
+
// Validate the whole form if no intent is provided (default submission)
|
|
48
|
+
var intent = (_action$intent = action.intent) !== null && _action$intent !== void 0 ? _action$intent : {
|
|
49
|
+
type: 'validate'
|
|
50
|
+
};
|
|
51
|
+
var handler = (_action$ctx$handlers = action.ctx.handlers) === null || _action$ctx$handlers === void 0 ? void 0 : _action$ctx$handlers[intent.type];
|
|
52
|
+
if (typeof (handler === null || handler === void 0 ? void 0 : handler.onUpdate) === 'function') {
|
|
53
|
+
var _handler$validatePayl, _handler$validatePayl2;
|
|
54
|
+
if ((_handler$validatePayl = (_handler$validatePayl2 = handler.validatePayload) === null || _handler$validatePayl2 === void 0 ? void 0 : _handler$validatePayl2.call(handler, intent.payload)) !== null && _handler$validatePayl !== void 0 ? _handler$validatePayl : true) {
|
|
55
|
+
return handler.onUpdate(state, _objectSpread2(_objectSpread2({}, action), {}, {
|
|
56
|
+
intent: {
|
|
57
|
+
type: intent.type,
|
|
58
|
+
payload: intent.payload
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
64
61
|
}
|
|
65
62
|
}
|
|
66
63
|
return state;
|
|
@@ -233,27 +230,41 @@ function getFormMetadata(context, options) {
|
|
|
233
230
|
},
|
|
234
231
|
context,
|
|
235
232
|
getField(name) {
|
|
236
|
-
return getField(context,
|
|
237
|
-
name
|
|
238
|
-
|
|
233
|
+
return getField(context, {
|
|
234
|
+
name,
|
|
235
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
236
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
237
|
+
});
|
|
239
238
|
},
|
|
240
239
|
getFieldset(name) {
|
|
241
|
-
return getFieldset(context,
|
|
242
|
-
name
|
|
243
|
-
|
|
240
|
+
return getFieldset(context, {
|
|
241
|
+
name,
|
|
242
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
243
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
244
|
+
});
|
|
244
245
|
},
|
|
245
246
|
getFieldList(name) {
|
|
246
|
-
return getFieldList(context,
|
|
247
|
-
name
|
|
248
|
-
|
|
247
|
+
return getFieldList(context, {
|
|
248
|
+
name,
|
|
249
|
+
serialize: options === null || options === void 0 ? void 0 : options.serialize,
|
|
250
|
+
customize: options === null || options === void 0 ? void 0 : options.customize
|
|
251
|
+
});
|
|
249
252
|
}
|
|
250
253
|
};
|
|
251
254
|
}
|
|
252
255
|
function getField(context, options) {
|
|
253
|
-
var
|
|
254
|
-
|
|
256
|
+
var {
|
|
257
|
+
key,
|
|
258
|
+
name,
|
|
259
|
+
serialize: serialize$1 = serialize,
|
|
260
|
+
customize
|
|
261
|
+
} = options;
|
|
262
|
+
var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
|
|
263
|
+
var constraint = getConstraint(context, name);
|
|
255
264
|
var metadata = {
|
|
256
|
-
|
|
265
|
+
key,
|
|
266
|
+
name,
|
|
267
|
+
id,
|
|
257
268
|
descriptionId: "".concat(id, "-description"),
|
|
258
269
|
errorId: "".concat(id, "-error"),
|
|
259
270
|
formId: context.formId,
|
|
@@ -266,38 +277,63 @@ function getField(context, options) {
|
|
|
266
277
|
step: constraint === null || constraint === void 0 ? void 0 : constraint.step,
|
|
267
278
|
multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
|
|
268
279
|
get defaultValue() {
|
|
269
|
-
return getDefaultValue(context,
|
|
280
|
+
return getDefaultValue(context, name, serialize$1);
|
|
270
281
|
},
|
|
271
282
|
get defaultOptions() {
|
|
272
|
-
return getDefaultOptions(context,
|
|
283
|
+
return getDefaultOptions(context, name, serialize$1);
|
|
273
284
|
},
|
|
274
285
|
get defaultChecked() {
|
|
275
|
-
return isDefaultChecked(context,
|
|
286
|
+
return isDefaultChecked(context, name, serialize$1);
|
|
276
287
|
},
|
|
277
288
|
get touched() {
|
|
278
|
-
return isTouched(context.state,
|
|
289
|
+
return isTouched(context.state, name);
|
|
279
290
|
},
|
|
280
291
|
get valid() {
|
|
281
|
-
return isValid(context.state,
|
|
292
|
+
return isValid(context.state, name);
|
|
282
293
|
},
|
|
283
294
|
get invalid() {
|
|
284
295
|
return !this.valid;
|
|
285
296
|
},
|
|
286
297
|
get errors() {
|
|
287
|
-
return getErrors(context.state,
|
|
298
|
+
return getErrors(context.state, name);
|
|
288
299
|
},
|
|
289
300
|
get fieldErrors() {
|
|
290
|
-
return getFieldErrors(context.state,
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
301
|
+
return getFieldErrors(context.state, name);
|
|
302
|
+
},
|
|
303
|
+
get ariaInvalid() {
|
|
304
|
+
return !this.valid ? true : undefined;
|
|
305
|
+
},
|
|
306
|
+
get ariaDescribedBy() {
|
|
307
|
+
return !this.valid ? this.errorId : undefined;
|
|
308
|
+
},
|
|
296
309
|
getFieldset() {
|
|
297
|
-
return getFieldset(context,
|
|
310
|
+
return getFieldset(context, {
|
|
311
|
+
name: name,
|
|
312
|
+
serialize: serialize$1,
|
|
313
|
+
customize
|
|
314
|
+
});
|
|
298
315
|
},
|
|
299
316
|
getFieldList() {
|
|
300
|
-
return getFieldList(context,
|
|
317
|
+
return getFieldList(context, {
|
|
318
|
+
name: name,
|
|
319
|
+
serialize: serialize$1,
|
|
320
|
+
customize
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
if (typeof customize !== 'function') {
|
|
325
|
+
return metadata;
|
|
326
|
+
}
|
|
327
|
+
return new Proxy(metadata, {
|
|
328
|
+
get(target, prop, receiver) {
|
|
329
|
+
if (Reflect.has(target, prop)) {
|
|
330
|
+
return Reflect.get(target, prop, receiver);
|
|
331
|
+
}
|
|
332
|
+
var customMetadata = customize(metadata);
|
|
333
|
+
if (Reflect.has(customMetadata, prop)) {
|
|
334
|
+
return Reflect.get(customMetadata, prop, receiver);
|
|
335
|
+
}
|
|
336
|
+
throw new Error("Property \"".concat(String(prop), "\" does not exist on field metadata. ") + "If you have defined the CustomMetadata interface to include \"".concat(String(prop), "\", make sure to also implement it through the \"defineCustomMetadata\" property on <FormOptionsProvider />."));
|
|
301
337
|
}
|
|
302
338
|
});
|
|
303
339
|
}
|
|
@@ -309,9 +345,11 @@ function getFieldset(context, options) {
|
|
|
309
345
|
return new Proxy({}, {
|
|
310
346
|
get(target, name, receiver) {
|
|
311
347
|
if (typeof name === 'string') {
|
|
312
|
-
return getField(context,
|
|
313
|
-
name: appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name)
|
|
314
|
-
|
|
348
|
+
return getField(context, {
|
|
349
|
+
name: appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
|
|
350
|
+
serialize: options.serialize,
|
|
351
|
+
customize: options.customize
|
|
352
|
+
});
|
|
315
353
|
}
|
|
316
354
|
return Reflect.get(target, name, receiver);
|
|
317
355
|
}
|
|
@@ -324,10 +362,12 @@ function getFieldset(context, options) {
|
|
|
324
362
|
function getFieldList(context, options) {
|
|
325
363
|
var keys = getListKey(context, options.name);
|
|
326
364
|
return keys.map((key, index) => {
|
|
327
|
-
return getField(context,
|
|
365
|
+
return getField(context, {
|
|
328
366
|
name: appendPathSegment(options.name, index),
|
|
367
|
+
serialize: options.serialize,
|
|
368
|
+
customize: options.customize,
|
|
329
369
|
key
|
|
330
|
-
})
|
|
370
|
+
});
|
|
331
371
|
});
|
|
332
372
|
}
|
|
333
373
|
|