@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.
@@ -1,8 +1,8 @@
1
1
  export type { FieldName, FormError, FormValue, Submission, SubmissionResult, } from '@conform-to/dom/future';
2
2
  export { getFieldValue, parseSubmission, report, isDirty, } from '@conform-to/dom/future';
3
- export type { Control, DefaultValue, BaseMetadata, BaseFieldMetadata, CustomMetadata, CustomMetadataDefinition, BaseErrorShape, CustomTypes, CustomSchemaTypes, FormsConfig, FormContext, FormMetadata, FormOptions, FormRef, FieldMetadata, Fieldset, IntentDispatcher, InferBaseErrorShape, InferCustomFormMetadata, InferCustomFieldMetadata, } from './types';
4
- export { configureForms } from './forms';
5
- export { PreserveBoundary, FormProvider, FormOptionsProvider, useControl, useField, useForm, useFormData, useFormMetadata, useIntent, } from './hooks';
3
+ export type { Control, ControlOptions, BaseControlProps, DefaultValue, BaseFieldMetadata, CustomSchemaTypes, FormsConfig, FormContext, FormMetadata, FormOptions, FormRef, FieldMetadata, Fieldset, IntentDispatcher, InferBaseErrorShape, InferCustomFormMetadata, InferCustomFieldMetadata, } from './types';
4
+ export { configureForms, FormProvider, useForm, useFormMetadata, useField, useIntent, } from './forms';
5
+ export { BaseControl, PreserveBoundary, useControl, useFormData, } from './hooks';
6
6
  export { shape } from './util';
7
7
  export { memoize } from './memoize';
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -26,15 +26,15 @@ Object.defineProperty(exports, 'report', {
26
26
  enumerable: true,
27
27
  get: function () { return future.report; }
28
28
  });
29
+ exports.FormProvider = forms.FormProvider;
29
30
  exports.configureForms = forms.configureForms;
30
- exports.FormOptionsProvider = hooks.FormOptionsProvider;
31
- exports.FormProvider = hooks.FormProvider;
31
+ exports.useField = forms.useField;
32
+ exports.useForm = forms.useForm;
33
+ exports.useFormMetadata = forms.useFormMetadata;
34
+ exports.useIntent = forms.useIntent;
35
+ exports.BaseControl = hooks.BaseControl;
32
36
  exports.PreserveBoundary = hooks.PreserveBoundary;
33
37
  exports.useControl = hooks.useControl;
34
- exports.useField = hooks.useField;
35
- exports.useForm = hooks.useForm;
36
38
  exports.useFormData = hooks.useFormData;
37
- exports.useFormMetadata = hooks.useFormMetadata;
38
- exports.useIntent = hooks.useIntent;
39
39
  exports.shape = util.shape;
40
40
  exports.memoize = memoize.memoize;
@@ -1,5 +1,5 @@
1
1
  export { getFieldValue, isDirty, parseSubmission, report } from '@conform-to/dom/future';
2
- export { configureForms } from './forms.mjs';
3
- export { FormOptionsProvider, FormProvider, PreserveBoundary, useControl, useField, useForm, useFormData, useFormMetadata, useIntent } from './hooks.mjs';
2
+ export { FormProvider, configureForms, useField, useForm, useFormMetadata, useIntent } from './forms.mjs';
3
+ export { BaseControl, PreserveBoundary, useControl, useFormData } from './hooks.mjs';
4
4
  export { shape } from './util.mjs';
5
5
  export { memoize } from './memoize.mjs';
@@ -92,7 +92,7 @@ function updateListKeys() {
92
92
  var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93
93
  var keyToBeRemoved = arguments.length > 1 ? arguments[1] : undefined;
94
94
  var updateKey = arguments.length > 2 ? arguments[2] : undefined;
95
- var basePath = future.getPathSegments(keyToBeRemoved);
95
+ var basePath = future.parsePath(keyToBeRemoved);
96
96
  return util.transformKeys(keys, field => {
97
97
  var _updateKey;
98
98
  return future.getRelativePath(field, basePath) !== null ? null : (_updateKey = updateKey === null || updateKey === void 0 ? void 0 : updateKey(field)) !== null && _updateKey !== void 0 ? _updateKey : field;
@@ -135,7 +135,7 @@ var intentHandlers = {
135
135
  error
136
136
  } = _ref;
137
137
  var name = (_intent$payload = intent.payload) !== null && _intent$payload !== void 0 ? _intent$payload : '';
138
- var basePath = future.getPathSegments(name);
138
+ var basePath = future.parsePath(name);
139
139
  var allFields = error ?
140
140
  // Consider fields / fieldset with errors as touched too
141
141
  submission.fields.concat(Object.keys(error.fieldErrors)) : submission.fields;
@@ -157,8 +157,8 @@ var intentHandlers = {
157
157
  },
158
158
  resolve(value, options) {
159
159
  var _options$value;
160
- var name = future.appendPathSegment(options.name, options.index);
161
- return util.updateValueAtPath(value, name, (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : name === '' ? {} : null);
160
+ var name = future.appendPath(options.name, options.index);
161
+ return util.updatePathValue(value, name, (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : name === '' ? {} : null);
162
162
  },
163
163
  update(state, _ref2) {
164
164
  var {
@@ -174,11 +174,11 @@ var intentHandlers = {
174
174
  // Update the keys only for client updates to avoid double updates if there is no client validation
175
175
  if (type === 'client') {
176
176
  // TODO: Do we really need to update the keys here?
177
- var name = future.appendPathSegment(intent.payload.name, intent.payload.index);
177
+ var name = future.appendPath(intent.payload.name, intent.payload.index);
178
178
  // Remove all child keys
179
179
  listKeys = name === '' ? {} : updateListKeys(state.listKeys, name);
180
180
  }
181
- var basePath = future.getPathSegments(intent.payload.name);
181
+ var basePath = future.parsePath(intent.payload.name);
182
182
  var touchedFields = state.touchedFields;
183
183
  for (var field of submission.fields) {
184
184
  if (basePath.length === 0 || future.getRelativePath(field, basePath) !== null) {
@@ -200,12 +200,12 @@ var intentHandlers = {
200
200
  var result = value;
201
201
  var itemValue = options.defaultValue;
202
202
  if (options.from !== undefined) {
203
- itemValue = future.getValueAtPath(result, options.from);
204
- result = util.updateValueAtPath(result, options.from, '');
203
+ itemValue = future.getPathValue(result, options.from);
204
+ result = util.updatePathValue(result, options.from, '');
205
205
  }
206
- var list = Array.from(util.getArrayAtPath(result, options.name));
206
+ var list = Array.from(util.getPathArray(result, options.name));
207
207
  insertItem(list, itemValue, (_options$index = options.index) !== null && _options$index !== void 0 ? _options$index : list.length);
208
- return util.updateValueAtPath(result, options.name, list);
208
+ return util.updatePathValue(result, options.name, list);
209
209
  },
210
210
  apply(result, options) {
211
211
  var _result$error;
@@ -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 arrayErrors = (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.fieldErrors[options.name];
219
- if (options.onInvalid === 'revert' && arrayErrors !== null && arrayErrors !== void 0 && arrayErrors.length) {
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;
226
- var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : util.getArrayAtPath(result.submission.payload, options.name).length;
227
- var insertedItemPath = future.appendPathSegment(options.name, index);
228
- var insertedItemErrors = (_result$error2 = result.error) === null || _result$error2 === void 0 ? void 0 : _result$error2.fieldErrors[insertedItemPath];
229
- if (insertedItemErrors !== null && insertedItemErrors !== void 0 && insertedItemErrors.length) {
230
- var _result$error$fieldEr, _result$error3, _result$error$formErr, _result$error4, _result$error5;
231
- var fromErrors = (_result$error$fieldEr = (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.fieldErrors[options.from]) !== null && _result$error$fieldEr !== void 0 ? _result$error$fieldEr : [];
225
+ var _options$index2, _result$error2, _result$error3;
226
+ var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : util.getPathArray(result.submission.payload, options.name).length;
227
+ var insertedItemPath = future.appendPath(options.name, index);
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
- [options.from]: [...fromErrors, ...insertedItemErrors],
238
- [insertedItemPath]: []
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
  });
@@ -255,7 +267,7 @@ var intentHandlers = {
255
267
  return state$1;
256
268
  }
257
269
  var from = intent.payload.from;
258
- var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : util.getArrayAtPath(submission.payload, intent.payload.name).length;
270
+ var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : util.getPathArray(submission.payload, intent.payload.name).length;
259
271
  var updateListIndex = util.createPathIndexUpdater(intent.payload.name, currentIndex => index <= currentIndex ? currentIndex + 1 : currentIndex);
260
272
  var touchedFields = state$1.touchedFields;
261
273
  var listKeys = state$1.listKeys;
@@ -267,7 +279,7 @@ var intentHandlers = {
267
279
  var _state$listKeys$inten;
268
280
  var selectedListKeys = Array.from((_state$listKeys$inten = state$1.listKeys[intent.payload.name]) !== null && _state$listKeys$inten !== void 0 ? _state$listKeys$inten : state.getDefaultListKey(state$1.resetKey, submission.payload, intent.payload.name));
269
281
  insertItem(selectedListKeys, util.generateUniqueKey(), index);
270
- listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPathSegment(intent.payload.name, index), updateListIndex)), {}, {
282
+ listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPath(intent.payload.name, index), updateListIndex)), {}, {
271
283
  // Update existing list keys
272
284
  [intent.payload.name]: selectedListKeys
273
285
  });
@@ -288,12 +300,12 @@ var intentHandlers = {
288
300
  return future.isPlainObject(options) && util.isString(options.name) && util.isNumber(options.index) && util.isOptional(options.onInvalid, v => v === 'revert' || v === 'insert');
289
301
  },
290
302
  resolve(value, options) {
291
- var list = Array.from(util.getArrayAtPath(value, options.name));
303
+ var list = Array.from(util.getPathArray(value, options.name));
292
304
  removeItem(list, options.index);
293
- return util.updateValueAtPath(value, options.name, list);
305
+ return util.updatePathValue(value, options.name, list);
294
306
  },
295
307
  apply(result, options) {
296
- var _result$error6;
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$error6 = result.error) !== null && _result$error6 !== void 0 && _result$error6.fieldErrors[options.name]) {
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), {}, {
@@ -310,10 +322,10 @@ var intentHandlers = {
310
322
  });
311
323
  case 'insert':
312
324
  {
313
- var list = Array.from(util.getArrayAtPath(result.targetValue, options.name));
325
+ var list = Array.from(util.getPathArray(result.targetValue, options.name));
314
326
  insertItem(list, options.defaultValue, list.length);
315
327
  return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, result), {}, {
316
- targetValue: util.updateValueAtPath(result.targetValue, options.name, list)
328
+ targetValue: util.updatePathValue(result.targetValue, options.name, list)
317
329
  });
318
330
  }
319
331
  }
@@ -349,14 +361,14 @@ var intentHandlers = {
349
361
  var _state$listKeys$inten2;
350
362
  var selectedListKeys = Array.from((_state$listKeys$inten2 = state$1.listKeys[intent.payload.name]) !== null && _state$listKeys$inten2 !== void 0 ? _state$listKeys$inten2 : state.getDefaultListKey(state$1.resetKey, currentValue, intent.payload.name));
351
363
  removeItem(selectedListKeys, intent.payload.index);
352
- listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPathSegment(intent.payload.name, intent.payload.index), updateListIndex)), {}, {
364
+ listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPath(intent.payload.name, intent.payload.index), updateListIndex)), {}, {
353
365
  // Update existing list keys
354
366
  [intent.payload.name]: selectedListKeys
355
367
  });
356
368
  if (ctx.cancelled) {
357
369
  var index = selectedListKeys.length;
358
370
  insertItem(selectedListKeys, util.generateUniqueKey(), index);
359
- listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPathSegment(intent.payload.name, index), updateListIndex)), {}, {
371
+ listKeys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPath(intent.payload.name, index), updateListIndex)), {}, {
360
372
  // Update existing list keys
361
373
  [intent.payload.name]: selectedListKeys
362
374
  });
@@ -375,9 +387,9 @@ var intentHandlers = {
375
387
  return future.isPlainObject(options) && util.isString(options.name) && util.isNumber(options.from) && util.isNumber(options.to);
376
388
  },
377
389
  resolve(value, options) {
378
- var list = Array.from(util.getArrayAtPath(value, options.name));
390
+ var list = Array.from(util.getPathArray(value, options.name));
379
391
  reorderItems(list, options.from, options.to);
380
- return util.updateValueAtPath(value, options.name, list);
392
+ return util.updatePathValue(value, options.name, list);
381
393
  },
382
394
  update(state$1, _ref5) {
383
395
  var {
@@ -409,7 +421,7 @@ var intentHandlers = {
409
421
  var _state$listKeys$inten3;
410
422
  var listKeys = Array.from((_state$listKeys$inten3 = state$1.listKeys[intent.payload.name]) !== null && _state$listKeys$inten3 !== void 0 ? _state$listKeys$inten3 : state.getDefaultListKey(state$1.resetKey, currentValue, intent.payload.name));
411
423
  reorderItems(listKeys, intent.payload.from, intent.payload.to);
412
- keys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPathSegment(intent.payload.name, intent.payload.from), updateListIndex)), {}, {
424
+ keys = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, updateListKeys(state$1.listKeys, future.appendPath(intent.payload.name, intent.payload.from), updateListIndex)), {}, {
413
425
  // Update existing list keys
414
426
  [intent.payload.name]: listKeys
415
427
  });
@@ -1,6 +1,6 @@
1
1
  import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { getPathSegments, getRelativePath, isPlainObject, appendPathSegment, getValueAtPath } from '@conform-to/dom/future';
3
- import { isOptional, isUndefined, isNullable, appendUniqueItem, merge, updateValueAtPath, isString, getArrayAtPath, createPathIndexUpdater, compactMap, generateUniqueKey, isNumber, transformKeys } from './util.mjs';
2
+ import { parsePath, getRelativePath, isPlainObject, appendPath, getPathValue } from '@conform-to/dom/future';
3
+ import { isOptional, isUndefined, isNullable, appendUniqueItem, merge, updatePathValue, isString, getPathArray, createPathIndexUpdater, compactMap, generateUniqueKey, isNumber, transformKeys } from './util.mjs';
4
4
  import { getDefaultListKey } from './state.mjs';
5
5
 
6
6
  /**
@@ -88,7 +88,7 @@ function updateListKeys() {
88
88
  var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
89
89
  var keyToBeRemoved = arguments.length > 1 ? arguments[1] : undefined;
90
90
  var updateKey = arguments.length > 2 ? arguments[2] : undefined;
91
- var basePath = getPathSegments(keyToBeRemoved);
91
+ var basePath = parsePath(keyToBeRemoved);
92
92
  return transformKeys(keys, field => {
93
93
  var _updateKey;
94
94
  return getRelativePath(field, basePath) !== null ? null : (_updateKey = updateKey === null || updateKey === void 0 ? void 0 : updateKey(field)) !== null && _updateKey !== void 0 ? _updateKey : field;
@@ -131,7 +131,7 @@ var intentHandlers = {
131
131
  error
132
132
  } = _ref;
133
133
  var name = (_intent$payload = intent.payload) !== null && _intent$payload !== void 0 ? _intent$payload : '';
134
- var basePath = getPathSegments(name);
134
+ var basePath = parsePath(name);
135
135
  var allFields = error ?
136
136
  // Consider fields / fieldset with errors as touched too
137
137
  submission.fields.concat(Object.keys(error.fieldErrors)) : submission.fields;
@@ -153,8 +153,8 @@ var intentHandlers = {
153
153
  },
154
154
  resolve(value, options) {
155
155
  var _options$value;
156
- var name = appendPathSegment(options.name, options.index);
157
- return updateValueAtPath(value, name, (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : name === '' ? {} : null);
156
+ var name = appendPath(options.name, options.index);
157
+ return updatePathValue(value, name, (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : name === '' ? {} : null);
158
158
  },
159
159
  update(state, _ref2) {
160
160
  var {
@@ -170,11 +170,11 @@ var intentHandlers = {
170
170
  // Update the keys only for client updates to avoid double updates if there is no client validation
171
171
  if (type === 'client') {
172
172
  // TODO: Do we really need to update the keys here?
173
- var name = appendPathSegment(intent.payload.name, intent.payload.index);
173
+ var name = appendPath(intent.payload.name, intent.payload.index);
174
174
  // Remove all child keys
175
175
  listKeys = name === '' ? {} : updateListKeys(state.listKeys, name);
176
176
  }
177
- var basePath = getPathSegments(intent.payload.name);
177
+ var basePath = parsePath(intent.payload.name);
178
178
  var touchedFields = state.touchedFields;
179
179
  for (var field of submission.fields) {
180
180
  if (basePath.length === 0 || getRelativePath(field, basePath) !== null) {
@@ -196,12 +196,12 @@ var intentHandlers = {
196
196
  var result = value;
197
197
  var itemValue = options.defaultValue;
198
198
  if (options.from !== undefined) {
199
- itemValue = getValueAtPath(result, options.from);
200
- result = updateValueAtPath(result, options.from, '');
199
+ itemValue = getPathValue(result, options.from);
200
+ result = updatePathValue(result, options.from, '');
201
201
  }
202
- var list = Array.from(getArrayAtPath(result, options.name));
202
+ var list = Array.from(getPathArray(result, options.name));
203
203
  insertItem(list, itemValue, (_options$index = options.index) !== null && _options$index !== void 0 ? _options$index : list.length);
204
- return updateValueAtPath(result, options.name, list);
204
+ return updatePathValue(result, options.name, list);
205
205
  },
206
206
  apply(result, options) {
207
207
  var _result$error;
@@ -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 arrayErrors = (_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.fieldErrors[options.name];
215
- if (options.onInvalid === 'revert' && arrayErrors !== null && arrayErrors !== void 0 && arrayErrors.length) {
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;
222
- var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : getArrayAtPath(result.submission.payload, options.name).length;
223
- var insertedItemPath = appendPathSegment(options.name, index);
224
- var insertedItemErrors = (_result$error2 = result.error) === null || _result$error2 === void 0 ? void 0 : _result$error2.fieldErrors[insertedItemPath];
225
- if (insertedItemErrors !== null && insertedItemErrors !== void 0 && insertedItemErrors.length) {
226
- var _result$error$fieldEr, _result$error3, _result$error$formErr, _result$error4, _result$error5;
227
- var fromErrors = (_result$error$fieldEr = (_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.fieldErrors[options.from]) !== null && _result$error$fieldEr !== void 0 ? _result$error$fieldEr : [];
221
+ var _options$index2, _result$error2, _result$error3;
222
+ var index = (_options$index2 = options.index) !== null && _options$index2 !== void 0 ? _options$index2 : getPathArray(result.submission.payload, options.name).length;
223
+ var insertedItemPath = appendPath(options.name, index);
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
- [options.from]: [...fromErrors, ...insertedItemErrors],
234
- [insertedItemPath]: []
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
  });
@@ -251,7 +263,7 @@ var intentHandlers = {
251
263
  return state;
252
264
  }
253
265
  var from = intent.payload.from;
254
- var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : getArrayAtPath(submission.payload, intent.payload.name).length;
266
+ var index = (_intent$payload$index = intent.payload.index) !== null && _intent$payload$index !== void 0 ? _intent$payload$index : getPathArray(submission.payload, intent.payload.name).length;
255
267
  var updateListIndex = createPathIndexUpdater(intent.payload.name, currentIndex => index <= currentIndex ? currentIndex + 1 : currentIndex);
256
268
  var touchedFields = state.touchedFields;
257
269
  var listKeys = state.listKeys;
@@ -263,7 +275,7 @@ var intentHandlers = {
263
275
  var _state$listKeys$inten;
264
276
  var selectedListKeys = Array.from((_state$listKeys$inten = state.listKeys[intent.payload.name]) !== null && _state$listKeys$inten !== void 0 ? _state$listKeys$inten : getDefaultListKey(state.resetKey, submission.payload, intent.payload.name));
265
277
  insertItem(selectedListKeys, generateUniqueKey(), index);
266
- listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPathSegment(intent.payload.name, index), updateListIndex)), {}, {
278
+ listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPath(intent.payload.name, index), updateListIndex)), {}, {
267
279
  // Update existing list keys
268
280
  [intent.payload.name]: selectedListKeys
269
281
  });
@@ -284,12 +296,12 @@ var intentHandlers = {
284
296
  return isPlainObject(options) && isString(options.name) && isNumber(options.index) && isOptional(options.onInvalid, v => v === 'revert' || v === 'insert');
285
297
  },
286
298
  resolve(value, options) {
287
- var list = Array.from(getArrayAtPath(value, options.name));
299
+ var list = Array.from(getPathArray(value, options.name));
288
300
  removeItem(list, options.index);
289
- return updateValueAtPath(value, options.name, list);
301
+ return updatePathValue(value, options.name, list);
290
302
  },
291
303
  apply(result, options) {
292
- var _result$error6;
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$error6 = result.error) !== null && _result$error6 !== void 0 && _result$error6.fieldErrors[options.name]) {
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), {}, {
@@ -306,10 +318,10 @@ var intentHandlers = {
306
318
  });
307
319
  case 'insert':
308
320
  {
309
- var list = Array.from(getArrayAtPath(result.targetValue, options.name));
321
+ var list = Array.from(getPathArray(result.targetValue, options.name));
310
322
  insertItem(list, options.defaultValue, list.length);
311
323
  return _objectSpread2(_objectSpread2({}, result), {}, {
312
- targetValue: updateValueAtPath(result.targetValue, options.name, list)
324
+ targetValue: updatePathValue(result.targetValue, options.name, list)
313
325
  });
314
326
  }
315
327
  }
@@ -345,14 +357,14 @@ var intentHandlers = {
345
357
  var _state$listKeys$inten2;
346
358
  var selectedListKeys = Array.from((_state$listKeys$inten2 = state.listKeys[intent.payload.name]) !== null && _state$listKeys$inten2 !== void 0 ? _state$listKeys$inten2 : getDefaultListKey(state.resetKey, currentValue, intent.payload.name));
347
359
  removeItem(selectedListKeys, intent.payload.index);
348
- listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPathSegment(intent.payload.name, intent.payload.index), updateListIndex)), {}, {
360
+ listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPath(intent.payload.name, intent.payload.index), updateListIndex)), {}, {
349
361
  // Update existing list keys
350
362
  [intent.payload.name]: selectedListKeys
351
363
  });
352
364
  if (ctx.cancelled) {
353
365
  var index = selectedListKeys.length;
354
366
  insertItem(selectedListKeys, generateUniqueKey(), index);
355
- listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPathSegment(intent.payload.name, index), updateListIndex)), {}, {
367
+ listKeys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPath(intent.payload.name, index), updateListIndex)), {}, {
356
368
  // Update existing list keys
357
369
  [intent.payload.name]: selectedListKeys
358
370
  });
@@ -371,9 +383,9 @@ var intentHandlers = {
371
383
  return isPlainObject(options) && isString(options.name) && isNumber(options.from) && isNumber(options.to);
372
384
  },
373
385
  resolve(value, options) {
374
- var list = Array.from(getArrayAtPath(value, options.name));
386
+ var list = Array.from(getPathArray(value, options.name));
375
387
  reorderItems(list, options.from, options.to);
376
- return updateValueAtPath(value, options.name, list);
388
+ return updatePathValue(value, options.name, list);
377
389
  },
378
390
  update(state, _ref5) {
379
391
  var {
@@ -405,7 +417,7 @@ var intentHandlers = {
405
417
  var _state$listKeys$inten3;
406
418
  var listKeys = Array.from((_state$listKeys$inten3 = state.listKeys[intent.payload.name]) !== null && _state$listKeys$inten3 !== void 0 ? _state$listKeys$inten3 : getDefaultListKey(state.resetKey, currentValue, intent.payload.name));
407
419
  reorderItems(listKeys, intent.payload.from, intent.payload.to);
408
- keys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPathSegment(intent.payload.name, intent.payload.from), updateListIndex)), {}, {
420
+ keys = _objectSpread2(_objectSpread2({}, updateListKeys(state.listKeys, appendPath(intent.payload.name, intent.payload.from), updateListIndex)), {}, {
409
421
  // Update existing list keys
410
422
  [intent.payload.name]: listKeys
411
423
  });
@@ -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
- * @example
27
+ * **Example:**
28
28
  * ```ts
29
29
  * // Async validation with API call
30
30
  * const validateUsername = useMemo(
@@ -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
- * @example
38
+ * **Example:**
39
39
  * ```ts
40
40
  * // Async validation with API call
41
41
  * const validateUsername = useMemo(
@@ -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
- * @example
34
+ * **Example:**
35
35
  * ```ts
36
36
  * // Async validation with API call
37
37
  * const validateUsername = useMemo(
@@ -1,4 +1,4 @@
1
- import { type FieldName, type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
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,9 +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 getDefaultValue(context: FormContext<any>, name: string, serialize?: Serialize): string;
24
- export declare function getDefaultOptions(context: FormContext<any>, name: string, serialize?: Serialize): string[];
25
- export declare function isDefaultChecked(context: FormContext<any>, name: string, serialize?: Serialize): boolean;
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;
26
27
  /**
27
28
  * Determine if the field is touched
28
29
  *
@@ -32,16 +33,14 @@ export declare function isDefaultChecked(context: FormContext<any>, name: string
32
33
  export declare function isTouched(state: FormState<any>, name?: string): boolean;
33
34
  export declare function getDefaultListKey(prefix: string, initialValue: Record<string, unknown> | null, name: string): string[];
34
35
  export declare function getListKey(context: FormContext<any>, name: string): string[];
35
- export declare function getErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): ErrorShape[] | undefined;
36
- export declare function getFieldErrors<ErrorShape>(state: FormState<ErrorShape>, name?: string): Record<string, ErrorShape[]>;
37
- export declare function isValid(state: FormState<any>, name?: string): boolean;
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
- * Gets validation constraint for a field, with fallback to parent array patterns.
40
- * e.g. "array[0].key" falls back to "array[].key" if specific constraint not found.
39
+ * Checks if fieldErrors contains any errors at the given name or any child path.
41
40
  */
42
- export declare function getConstraint(context: FormContext<any>, name: string): ValidationAttributes | undefined;
41
+ export declare function hasFieldError<ErrorShape>(error: FormError<ErrorShape>, name: string): boolean;
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;