@conform-to/react 1.17.1 → 1.19.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.
@@ -82,7 +82,7 @@ function updateState(state, action) {
82
82
  function pruneListKeys(listKeys, targetValue) {
83
83
  var result = listKeys;
84
84
  for (var [name, keys] of Object.entries(listKeys)) {
85
- var list = util.getArrayAtPath(targetValue, name);
85
+ var list = util.getPathArray(targetValue, name);
86
86
 
87
87
  // Reset list keys only if the length has changed
88
88
  // to minimize potential UI state loss due to key changes
@@ -98,21 +98,31 @@ function pruneListKeys(listKeys, targetValue) {
98
98
  }
99
99
  return result;
100
100
  }
101
- function getDefaultValue(context, name) {
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
- var value = future.getValueAtPath((_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
- var serializedValue = serialize(value);
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);
104
+ if (value === null) {
105
+ return null;
106
+ }
107
+ return future.normalize(value, context.serialize, name);
108
+ }
109
+ function getDefaultValue(context, name) {
110
+ var _ref2, _context$state$server2;
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);
112
+ var serializedValue = context.serialize(value, {
113
+ name
114
+ });
106
115
  if (typeof serializedValue === 'string') {
107
116
  return serializedValue;
108
117
  }
109
118
  return '';
110
119
  }
111
120
  function getDefaultOptions(context, name) {
112
- var _ref2, _context$state$server2;
113
- var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
114
- var value = future.getValueAtPath((_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);
115
- var serializedValue = serialize(value);
121
+ var _ref3, _context$state$server3;
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);
123
+ var serializedValue = context.serialize(value, {
124
+ name
125
+ });
116
126
  if (Array.isArray(serializedValue) && serializedValue.every(item => typeof item === 'string')) {
117
127
  return serializedValue;
118
128
  }
@@ -122,12 +132,15 @@ function getDefaultOptions(context, name) {
122
132
  return [];
123
133
  }
124
134
  function isDefaultChecked(context, name) {
125
- var _ref3, _context$state$server3;
126
- var serialize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : future.serialize;
127
- var value = future.getValueAtPath((_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);
128
- var serializedValue = serialize(value);
135
+ var _ref4, _context$state$server4;
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);
137
+ var serializedValue = context.serialize(value, {
138
+ name
139
+ });
129
140
  if (typeof serializedValue === 'string') {
130
- return serializedValue === 'on';
141
+ return serializedValue === context.serialize(true, {
142
+ name
143
+ });
131
144
  }
132
145
  return false;
133
146
  }
@@ -143,15 +156,15 @@ function isTouched(state) {
143
156
  if (state.touchedFields.includes(name)) {
144
157
  return true;
145
158
  }
146
- var paths = future.getPathSegments(name);
159
+ var paths = future.parsePath(name);
147
160
  return state.touchedFields.some(field => field !== name && future.getRelativePath(field, paths) !== null);
148
161
  }
149
162
  function getDefaultListKey(prefix, initialValue, name) {
150
- return util.getArrayAtPath(initialValue, name).map((_, index) => "".concat(prefix, "-").concat(future.appendPathSegment(name, index)));
163
+ return util.getPathArray(initialValue, name).map((_, index) => "".concat(prefix, "-").concat(future.appendPath(name, index)));
151
164
  }
152
165
  function getListKey(context, name) {
153
- var _context$state$listKe, _context$state$listKe2, _ref4, _context$state$server4;
154
- return (_context$state$listKe = (_context$state$listKe2 = context.state.listKeys) === null || _context$state$listKe2 === void 0 ? void 0 : _context$state$listKe2[name]) !== null && _context$state$listKe !== void 0 ? _context$state$listKe : getDefaultListKey(context.state.resetKey, (_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);
166
+ var _context$state$listKe, _context$state$listKe2, _ref5, _context$state$server5;
167
+ return (_context$state$listKe = (_context$state$listKe2 = context.state.listKeys) === null || _context$state$listKe2 === void 0 ? void 0 : _context$state$listKe2[name]) !== null && _context$state$listKe !== void 0 ? _context$state$listKe : getDefaultListKey(context.state.resetKey, (_ref5 = (_context$state$server5 = context.state.serverValue) !== null && _context$state$server5 !== void 0 ? _context$state$server5 : context.state.targetValue) !== null && _ref5 !== void 0 ? _ref5 : context.state.defaultValue, name);
155
168
  }
156
169
  function getErrors(state, name) {
157
170
  var _state$serverError;
@@ -160,7 +173,7 @@ function getErrors(state, name) {
160
173
  return;
161
174
  }
162
175
  var errors = name ? error.fieldErrors[name] : error.formErrors;
163
- if (errors && errors.length > 0) {
176
+ if (errors != null) {
164
177
  return errors;
165
178
  }
166
179
  }
@@ -169,7 +182,7 @@ function getFieldErrors(state, name) {
169
182
  var result = {};
170
183
  var error = (_state$serverError2 = state.serverError) !== null && _state$serverError2 !== void 0 ? _state$serverError2 : state.clientError;
171
184
  if (error) {
172
- var basePath = future.getPathSegments(name);
185
+ var basePath = future.parsePath(name);
173
186
  for (var field of Object.keys(error.fieldErrors)) {
174
187
  var relativePath = future.getRelativePath(field, basePath);
175
188
 
@@ -179,12 +192,23 @@ function getFieldErrors(state, name) {
179
192
  }
180
193
  var _error = getErrors(state, field);
181
194
  if (typeof _error !== 'undefined') {
182
- result[future.formatPathSegments(relativePath)] = _error;
195
+ result[future.formatPath(relativePath)] = _error;
183
196
  }
184
197
  }
185
198
  }
186
199
  return result;
187
200
  }
201
+
202
+ /**
203
+ * Checks if fieldErrors contains any errors at the given name or any child path.
204
+ */
205
+ function hasFieldError(error, name) {
206
+ var basePath = future.parsePath(name);
207
+ return Object.entries(error.fieldErrors).some(_ref6 => {
208
+ var [field, fieldError] = _ref6;
209
+ return future.getRelativePath(field, basePath) !== null && fieldError !== null;
210
+ });
211
+ }
188
212
  function isValid(state, name) {
189
213
  var _state$serverError3;
190
214
  var error = (_state$serverError3 = state.serverError) !== null && _state$serverError3 !== void 0 ? _state$serverError3 : state.clientError;
@@ -193,7 +217,7 @@ function isValid(state, name) {
193
217
  if (!error) {
194
218
  return true;
195
219
  }
196
- var basePath = future.getPathSegments(name);
220
+ var basePath = future.parsePath(name);
197
221
  for (var field of Object.keys(error.fieldErrors)) {
198
222
  // When checking a specific field, only check that field and its children
199
223
  if (name && !future.getRelativePath(field, basePath)) {
@@ -213,34 +237,6 @@ function isValid(state, name) {
213
237
  }
214
238
  return true;
215
239
  }
216
-
217
- /**
218
- * Gets validation constraint for a field, with fallback to parent array patterns.
219
- * e.g. "array[0].key" falls back to "array[].key" if specific constraint not found.
220
- */
221
- function getConstraint(context, name) {
222
- var _context$constraint;
223
- var constraint = (_context$constraint = context.constraint) === null || _context$constraint === void 0 ? void 0 : _context$constraint[name];
224
- if (!constraint) {
225
- var path = future.getPathSegments(name);
226
- for (var i = path.length - 1; i >= 0; i--) {
227
- var segment = path[i];
228
- // Try searching a less specific path for the constraint
229
- // e.g. `array[0].anotherArray[1].key` -> `array[0].anotherArray[].key` -> `array[].anotherArray[].key`
230
- if (typeof segment === 'number') {
231
- // This overrides the current number segment with an empty string
232
- // which will be treated as an empty bracket
233
- path[i] = '';
234
- break;
235
- }
236
- }
237
- var alternative = future.formatPathSegments(path);
238
- if (name !== alternative) {
239
- constraint = getConstraint(context, alternative);
240
- }
241
- }
242
- return constraint;
243
- }
244
240
  function getFormMetadata(context, options) {
245
241
  var _options$extendFormMe, _options$extendFormMe2;
246
242
  var metadata = {
@@ -275,21 +271,18 @@ function getFormMetadata(context, options) {
275
271
  getField(name) {
276
272
  return getField(context, {
277
273
  name,
278
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
279
274
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
280
275
  });
281
276
  },
282
277
  getFieldset(name) {
283
278
  return getFieldset(context, {
284
279
  name,
285
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
286
280
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
287
281
  });
288
282
  },
289
283
  getFieldList(name) {
290
284
  return getFieldList(context, {
291
285
  name,
292
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
293
286
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
294
287
  });
295
288
  }
@@ -301,19 +294,17 @@ function getFormMetadata(context, options) {
301
294
  return extended;
302
295
  }
303
296
  function getField(context, options) {
304
- var _extendFieldMetadata;
297
+ var _context$constraint, _extendFieldMetadata;
305
298
  var {
306
299
  key,
307
300
  name,
308
- serialize = future.serialize,
309
301
  extendFieldMetadata,
310
302
  form = getFormMetadata(context, {
311
- serialize,
312
303
  extendFieldMetadata
313
304
  })
314
305
  } = options;
315
306
  var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
316
- var constraint = getConstraint(context, name);
307
+ var constraint = (_context$constraint = context.constraint) === null || _context$constraint === void 0 ? void 0 : _context$constraint[name];
317
308
  var metadata = {
318
309
  key,
319
310
  name,
@@ -331,13 +322,16 @@ function getField(context, options) {
331
322
  multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
332
323
  accept: constraint === null || constraint === void 0 ? void 0 : constraint.accept,
333
324
  get defaultValue() {
334
- return getDefaultValue(context, name, serialize);
325
+ return getDefaultValue(context, name);
335
326
  },
336
327
  get defaultOptions() {
337
- return getDefaultOptions(context, name, serialize);
328
+ return getDefaultOptions(context, name);
338
329
  },
339
330
  get defaultChecked() {
340
- return isDefaultChecked(context, name, serialize);
331
+ return isDefaultChecked(context, name);
332
+ },
333
+ get defaultPayload() {
334
+ return getDefaultPayload(context, name);
341
335
  },
342
336
  get touched() {
343
337
  return isTouched(context.state, name);
@@ -363,7 +357,6 @@ function getField(context, options) {
363
357
  getFieldset() {
364
358
  return getFieldset(context, {
365
359
  name: name,
366
- serialize,
367
360
  extendFieldMetadata
368
361
  });
369
362
  },
@@ -372,7 +365,6 @@ function getField(context, options) {
372
365
  getFieldList() {
373
366
  return getFieldList(context, {
374
367
  name,
375
- serialize,
376
368
  extendFieldMetadata
377
369
  });
378
370
  }
@@ -396,12 +388,10 @@ function getFieldset(context, options) {
396
388
  if (typeof name === 'string') {
397
389
  var _options$form;
398
390
  (_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
399
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
400
391
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
401
392
  });
402
393
  return getField(context, {
403
- name: future.appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
404
- serialize: options.serialize,
394
+ name: future.appendPath(options === null || options === void 0 ? void 0 : options.name, name),
405
395
  extendFieldMetadata: options.extendFieldMetadata,
406
396
  form: options.form
407
397
  });
@@ -418,17 +408,16 @@ function getFieldList(context, options) {
418
408
  var keys = getListKey(context, options.name);
419
409
  return keys.map((key, index) => {
420
410
  return getField(context, {
421
- name: future.appendPathSegment(options.name, index),
422
- serialize: options.serialize,
411
+ name: future.appendPath(options.name, index),
423
412
  extendFieldMetadata: options.extendFieldMetadata,
424
413
  key
425
414
  });
426
415
  });
427
416
  }
428
417
 
429
- exports.getConstraint = getConstraint;
430
418
  exports.getDefaultListKey = getDefaultListKey;
431
419
  exports.getDefaultOptions = getDefaultOptions;
420
+ exports.getDefaultPayload = getDefaultPayload;
432
421
  exports.getDefaultValue = getDefaultValue;
433
422
  exports.getErrors = getErrors;
434
423
  exports.getField = getField;
@@ -437,6 +426,7 @@ exports.getFieldList = getFieldList;
437
426
  exports.getFieldset = getFieldset;
438
427
  exports.getFormMetadata = getFormMetadata;
439
428
  exports.getListKey = getListKey;
429
+ exports.hasFieldError = hasFieldError;
440
430
  exports.initializeState = initializeState;
441
431
  exports.isDefaultChecked = isDefaultChecked;
442
432
  exports.isTouched = isTouched;
@@ -1,6 +1,6 @@
1
1
  import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { getPathSegments, getRelativePath, serialize, appendPathSegment, deepEqual, getValueAtPath, formatPathSegments } from '@conform-to/dom/future';
3
- import { when, generateUniqueKey, merge, getArrayAtPath } from './util.mjs';
2
+ import { parsePath, getRelativePath, appendPath, deepEqual, getPathValue, normalize, formatPath } from '@conform-to/dom/future';
3
+ import { when, generateUniqueKey, merge, getPathArray } from './util.mjs';
4
4
 
5
5
  function initializeState(options) {
6
6
  var _options$resetKey, _options$defaultValue;
@@ -78,7 +78,7 @@ function updateState(state, action) {
78
78
  function pruneListKeys(listKeys, targetValue) {
79
79
  var result = listKeys;
80
80
  for (var [name, keys] of Object.entries(listKeys)) {
81
- var list = getArrayAtPath(targetValue, name);
81
+ var list = getPathArray(targetValue, name);
82
82
 
83
83
  // Reset list keys only if the length has changed
84
84
  // to minimize potential UI state loss due to key changes
@@ -94,21 +94,31 @@ function pruneListKeys(listKeys, targetValue) {
94
94
  }
95
95
  return result;
96
96
  }
97
- function getDefaultValue(context, name) {
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
- var value = getValueAtPath((_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
- var serializedValue = serialize$1(value);
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);
100
+ if (value === null) {
101
+ return null;
102
+ }
103
+ return normalize(value, context.serialize, name);
104
+ }
105
+ function getDefaultValue(context, name) {
106
+ var _ref2, _context$state$server2;
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);
108
+ var serializedValue = context.serialize(value, {
109
+ name
110
+ });
102
111
  if (typeof serializedValue === 'string') {
103
112
  return serializedValue;
104
113
  }
105
114
  return '';
106
115
  }
107
116
  function getDefaultOptions(context, name) {
108
- var _ref2, _context$state$server2;
109
- var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
110
- var value = getValueAtPath((_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$1(value);
117
+ var _ref3, _context$state$server3;
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);
119
+ var serializedValue = context.serialize(value, {
120
+ name
121
+ });
112
122
  if (Array.isArray(serializedValue) && serializedValue.every(item => typeof item === 'string')) {
113
123
  return serializedValue;
114
124
  }
@@ -118,12 +128,15 @@ function getDefaultOptions(context, name) {
118
128
  return [];
119
129
  }
120
130
  function isDefaultChecked(context, name) {
121
- var _ref3, _context$state$server3;
122
- var serialize$1 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : serialize;
123
- var value = getValueAtPath((_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);
124
- var serializedValue = serialize$1(value);
131
+ var _ref4, _context$state$server4;
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);
133
+ var serializedValue = context.serialize(value, {
134
+ name
135
+ });
125
136
  if (typeof serializedValue === 'string') {
126
- return serializedValue === 'on';
137
+ return serializedValue === context.serialize(true, {
138
+ name
139
+ });
127
140
  }
128
141
  return false;
129
142
  }
@@ -139,15 +152,15 @@ function isTouched(state) {
139
152
  if (state.touchedFields.includes(name)) {
140
153
  return true;
141
154
  }
142
- var paths = getPathSegments(name);
155
+ var paths = parsePath(name);
143
156
  return state.touchedFields.some(field => field !== name && getRelativePath(field, paths) !== null);
144
157
  }
145
158
  function getDefaultListKey(prefix, initialValue, name) {
146
- return getArrayAtPath(initialValue, name).map((_, index) => "".concat(prefix, "-").concat(appendPathSegment(name, index)));
159
+ return getPathArray(initialValue, name).map((_, index) => "".concat(prefix, "-").concat(appendPath(name, index)));
147
160
  }
148
161
  function getListKey(context, name) {
149
- var _context$state$listKe, _context$state$listKe2, _ref4, _context$state$server4;
150
- return (_context$state$listKe = (_context$state$listKe2 = context.state.listKeys) === null || _context$state$listKe2 === void 0 ? void 0 : _context$state$listKe2[name]) !== null && _context$state$listKe !== void 0 ? _context$state$listKe : getDefaultListKey(context.state.resetKey, (_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);
162
+ var _context$state$listKe, _context$state$listKe2, _ref5, _context$state$server5;
163
+ return (_context$state$listKe = (_context$state$listKe2 = context.state.listKeys) === null || _context$state$listKe2 === void 0 ? void 0 : _context$state$listKe2[name]) !== null && _context$state$listKe !== void 0 ? _context$state$listKe : getDefaultListKey(context.state.resetKey, (_ref5 = (_context$state$server5 = context.state.serverValue) !== null && _context$state$server5 !== void 0 ? _context$state$server5 : context.state.targetValue) !== null && _ref5 !== void 0 ? _ref5 : context.state.defaultValue, name);
151
164
  }
152
165
  function getErrors(state, name) {
153
166
  var _state$serverError;
@@ -156,7 +169,7 @@ function getErrors(state, name) {
156
169
  return;
157
170
  }
158
171
  var errors = name ? error.fieldErrors[name] : error.formErrors;
159
- if (errors && errors.length > 0) {
172
+ if (errors != null) {
160
173
  return errors;
161
174
  }
162
175
  }
@@ -165,7 +178,7 @@ function getFieldErrors(state, name) {
165
178
  var result = {};
166
179
  var error = (_state$serverError2 = state.serverError) !== null && _state$serverError2 !== void 0 ? _state$serverError2 : state.clientError;
167
180
  if (error) {
168
- var basePath = getPathSegments(name);
181
+ var basePath = parsePath(name);
169
182
  for (var field of Object.keys(error.fieldErrors)) {
170
183
  var relativePath = getRelativePath(field, basePath);
171
184
 
@@ -175,12 +188,23 @@ function getFieldErrors(state, name) {
175
188
  }
176
189
  var _error = getErrors(state, field);
177
190
  if (typeof _error !== 'undefined') {
178
- result[formatPathSegments(relativePath)] = _error;
191
+ result[formatPath(relativePath)] = _error;
179
192
  }
180
193
  }
181
194
  }
182
195
  return result;
183
196
  }
197
+
198
+ /**
199
+ * Checks if fieldErrors contains any errors at the given name or any child path.
200
+ */
201
+ function hasFieldError(error, name) {
202
+ var basePath = parsePath(name);
203
+ return Object.entries(error.fieldErrors).some(_ref6 => {
204
+ var [field, fieldError] = _ref6;
205
+ return getRelativePath(field, basePath) !== null && fieldError !== null;
206
+ });
207
+ }
184
208
  function isValid(state, name) {
185
209
  var _state$serverError3;
186
210
  var error = (_state$serverError3 = state.serverError) !== null && _state$serverError3 !== void 0 ? _state$serverError3 : state.clientError;
@@ -189,7 +213,7 @@ function isValid(state, name) {
189
213
  if (!error) {
190
214
  return true;
191
215
  }
192
- var basePath = getPathSegments(name);
216
+ var basePath = parsePath(name);
193
217
  for (var field of Object.keys(error.fieldErrors)) {
194
218
  // When checking a specific field, only check that field and its children
195
219
  if (name && !getRelativePath(field, basePath)) {
@@ -209,34 +233,6 @@ function isValid(state, name) {
209
233
  }
210
234
  return true;
211
235
  }
212
-
213
- /**
214
- * Gets validation constraint for a field, with fallback to parent array patterns.
215
- * e.g. "array[0].key" falls back to "array[].key" if specific constraint not found.
216
- */
217
- function getConstraint(context, name) {
218
- var _context$constraint;
219
- var constraint = (_context$constraint = context.constraint) === null || _context$constraint === void 0 ? void 0 : _context$constraint[name];
220
- if (!constraint) {
221
- var path = getPathSegments(name);
222
- for (var i = path.length - 1; i >= 0; i--) {
223
- var segment = path[i];
224
- // Try searching a less specific path for the constraint
225
- // e.g. `array[0].anotherArray[1].key` -> `array[0].anotherArray[].key` -> `array[].anotherArray[].key`
226
- if (typeof segment === 'number') {
227
- // This overrides the current number segment with an empty string
228
- // which will be treated as an empty bracket
229
- path[i] = '';
230
- break;
231
- }
232
- }
233
- var alternative = formatPathSegments(path);
234
- if (name !== alternative) {
235
- constraint = getConstraint(context, alternative);
236
- }
237
- }
238
- return constraint;
239
- }
240
236
  function getFormMetadata(context, options) {
241
237
  var _options$extendFormMe, _options$extendFormMe2;
242
238
  var metadata = {
@@ -271,21 +267,18 @@ function getFormMetadata(context, options) {
271
267
  getField(name) {
272
268
  return getField(context, {
273
269
  name,
274
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
275
270
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
276
271
  });
277
272
  },
278
273
  getFieldset(name) {
279
274
  return getFieldset(context, {
280
275
  name,
281
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
282
276
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
283
277
  });
284
278
  },
285
279
  getFieldList(name) {
286
280
  return getFieldList(context, {
287
281
  name,
288
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
289
282
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
290
283
  });
291
284
  }
@@ -297,19 +290,17 @@ function getFormMetadata(context, options) {
297
290
  return extended;
298
291
  }
299
292
  function getField(context, options) {
300
- var _extendFieldMetadata;
293
+ var _context$constraint, _extendFieldMetadata;
301
294
  var {
302
295
  key,
303
296
  name,
304
- serialize: serialize$1 = serialize,
305
297
  extendFieldMetadata,
306
298
  form = getFormMetadata(context, {
307
- serialize: serialize$1,
308
299
  extendFieldMetadata
309
300
  })
310
301
  } = options;
311
302
  var id = "".concat(context.formId, "-field-").concat(name.replace(/[^a-zA-Z0-9._-]/g, '_'));
312
- var constraint = getConstraint(context, name);
303
+ var constraint = (_context$constraint = context.constraint) === null || _context$constraint === void 0 ? void 0 : _context$constraint[name];
313
304
  var metadata = {
314
305
  key,
315
306
  name,
@@ -327,13 +318,16 @@ function getField(context, options) {
327
318
  multiple: constraint === null || constraint === void 0 ? void 0 : constraint.multiple,
328
319
  accept: constraint === null || constraint === void 0 ? void 0 : constraint.accept,
329
320
  get defaultValue() {
330
- return getDefaultValue(context, name, serialize$1);
321
+ return getDefaultValue(context, name);
331
322
  },
332
323
  get defaultOptions() {
333
- return getDefaultOptions(context, name, serialize$1);
324
+ return getDefaultOptions(context, name);
334
325
  },
335
326
  get defaultChecked() {
336
- return isDefaultChecked(context, name, serialize$1);
327
+ return isDefaultChecked(context, name);
328
+ },
329
+ get defaultPayload() {
330
+ return getDefaultPayload(context, name);
337
331
  },
338
332
  get touched() {
339
333
  return isTouched(context.state, name);
@@ -359,7 +353,6 @@ function getField(context, options) {
359
353
  getFieldset() {
360
354
  return getFieldset(context, {
361
355
  name: name,
362
- serialize: serialize$1,
363
356
  extendFieldMetadata
364
357
  });
365
358
  },
@@ -368,7 +361,6 @@ function getField(context, options) {
368
361
  getFieldList() {
369
362
  return getFieldList(context, {
370
363
  name,
371
- serialize: serialize$1,
372
364
  extendFieldMetadata
373
365
  });
374
366
  }
@@ -392,12 +384,10 @@ function getFieldset(context, options) {
392
384
  if (typeof name === 'string') {
393
385
  var _options$form;
394
386
  (_options$form = options.form) !== null && _options$form !== void 0 ? _options$form : options.form = getFormMetadata(context, {
395
- serialize: options === null || options === void 0 ? void 0 : options.serialize,
396
387
  extendFieldMetadata: options === null || options === void 0 ? void 0 : options.extendFieldMetadata
397
388
  });
398
389
  return getField(context, {
399
- name: appendPathSegment(options === null || options === void 0 ? void 0 : options.name, name),
400
- serialize: options.serialize,
390
+ name: appendPath(options === null || options === void 0 ? void 0 : options.name, name),
401
391
  extendFieldMetadata: options.extendFieldMetadata,
402
392
  form: options.form
403
393
  });
@@ -414,12 +404,11 @@ function getFieldList(context, options) {
414
404
  var keys = getListKey(context, options.name);
415
405
  return keys.map((key, index) => {
416
406
  return getField(context, {
417
- name: appendPathSegment(options.name, index),
418
- serialize: options.serialize,
407
+ name: appendPath(options.name, index),
419
408
  extendFieldMetadata: options.extendFieldMetadata,
420
409
  key
421
410
  });
422
411
  });
423
412
  }
424
413
 
425
- export { getConstraint, getDefaultListKey, getDefaultOptions, getDefaultValue, getErrors, getField, getFieldErrors, getFieldList, getFieldset, getFormMetadata, getListKey, initializeState, isDefaultChecked, isTouched, isValid, pruneListKeys, updateState };
414
+ export { getDefaultListKey, getDefaultOptions, getDefaultPayload, getDefaultValue, getErrors, getField, getFieldErrors, getFieldList, getFieldset, getFormMetadata, getListKey, hasFieldError, initializeState, isDefaultChecked, isTouched, isValid, pruneListKeys, updateState };