@conform-to/react 1.10.1 → 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.
@@ -1,4 +1,4 @@
1
- import type { FormError, FormValue, SubmissionResult, ValidationAttributes } from '@conform-to/dom/future';
1
+ import type { FormError, FormValue, Serialize, SubmissionResult, ValidationAttributes } from '@conform-to/dom/future';
2
2
  import type { StandardSchemaV1 } from './standard-schema';
3
3
  export type Prettify<T> = {
4
4
  [K in keyof T]: T[K];
@@ -64,10 +64,10 @@ export type UseFormDataOptions = {
64
64
  */
65
65
  acceptFiles?: boolean;
66
66
  };
67
- export type DefaultValue<FormShape> = FormShape extends string | number | boolean | Date | File | bigint | null | undefined ? FormShape | null | undefined : FormShape extends Array<infer Item> | null | undefined ? Array<DefaultValue<Item>> | null | undefined : FormShape extends Record<string, any> | null | undefined ? {
67
+ export type DefaultValue<FormShape> = FormShape extends Array<infer Item> | null | undefined ? Array<DefaultValue<Item>> | null | undefined : FormShape extends Record<string, any> | null | undefined ? {
68
68
  [Key in keyof FormShape]?: DefaultValue<FormShape[Key]>;
69
- } | null | undefined : unknown;
70
- export type FormState<ErrorShape> = {
69
+ } | null | undefined : FormShape | string | null | undefined;
70
+ export type FormState<ErrorShape extends BaseErrorShape = DefaultErrorShape> = {
71
71
  /** Unique identifier that changes on form reset to trigger reset side effects */
72
72
  resetKey: string;
73
73
  /** Form values from client actions that will be synced to the DOM */
@@ -83,12 +83,41 @@ export type FormState<ErrorShape> = {
83
83
  /** Mapping of array field names to their item keys for React list rendering */
84
84
  listKeys: Record<string, string[]>;
85
85
  };
86
- export type FormAction<ErrorShape, Intent extends UnknownIntent | null | undefined = UnknownIntent | null, Context = {}> = SubmissionResult<ErrorShape> & {
86
+ export type FormAction<ErrorShape extends BaseErrorShape = DefaultErrorShape, Intent extends UnknownIntent | null | undefined = UnknownIntent | null, Context = {}> = SubmissionResult<ErrorShape> & {
87
87
  type: 'initialize' | 'server' | 'client';
88
88
  intent: Intent;
89
89
  ctx: Context;
90
90
  };
91
- export interface FormOptions<FormShape, ErrorShape = string, Value = undefined> {
91
+ export type GlobalFormOptions = {
92
+ /**
93
+ * The name of the submit button field that indicates the submission intent.
94
+ *
95
+ * @default "__intent__"
96
+ */
97
+ intentName: string;
98
+ /**
99
+ * A custom serialization function for converting form data.
100
+ */
101
+ serialize: Serialize;
102
+ /**
103
+ * Determines when validation should run for the first time on a field.
104
+ *
105
+ * @default "onSubmit"
106
+ */
107
+ shouldValidate: 'onSubmit' | 'onBlur' | 'onInput';
108
+ /**
109
+ * Determines when validation should run again after the field has been validated once.
110
+ *
111
+ * @default Same as shouldValidate
112
+ */
113
+ shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
114
+ /**
115
+ * A function that defines custom metadata properties for form fields.
116
+ * Useful for integrating with UI libraries or custom form components.
117
+ */
118
+ defineCustomMetadata?: CustomMetadataDefinition;
119
+ };
120
+ export type FormOptions<FormShape, ErrorShape extends BaseErrorShape = string extends BaseErrorShape ? string : BaseErrorShape, Value = undefined> = {
92
121
  /** Optional form identifier. If not provided, a unique ID is automatically generated. */
93
122
  id?: string;
94
123
  /** Optional key for form state reset. When the key changes, the form resets to its initial state. */
@@ -100,23 +129,21 @@ export interface FormOptions<FormShape, ErrorShape = string, Value = undefined>
100
129
  /** HTML validation attributes for fields (required, minLength, pattern, etc.). */
101
130
  constraint?: Record<string, ValidationAttributes>;
102
131
  /**
103
- * Define when conform should start validation.
104
- * Support "onSubmit", "onInput", "onBlur".
132
+ * Determines when validation should run for the first time on a field.
133
+ * Overrides the global default set by FormOptionsProvider if provided.
105
134
  *
106
- * @default "onSubmit"
135
+ * @default Inherits from FormOptionsProvider, or "onSubmit" if not configured
107
136
  */
108
137
  shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
109
138
  /**
110
- * Define when conform should revalidate again.
111
- * Support "onSubmit", "onInput", "onBlur".
139
+ * Determines when validation should run again after the field has been validated once.
140
+ * Overrides the global default set by FormOptionsProvider if provided.
112
141
  *
113
- * @default Same as shouldValidate, or "onSubmit" if shouldValidate is not provided.
142
+ * @default Inherits from FormOptionsProvider, or same as shouldValidate
114
143
  */
115
144
  shouldRevalidate?: 'onSubmit' | 'onBlur' | 'onInput';
116
145
  /** Server-side submission result for form state synchronization. */
117
146
  lastResult?: SubmissionResult<NoInfer<ErrorShape>> | null;
118
- /** Custom validation handler. Can be skipped if using the schema property, or combined with schema to customize validation errors. */
119
- onValidate?: ValidateHandler<ErrorShape, Value>;
120
147
  /** Error handling callback triggered when validation errors occur. By default, it focuses the first invalid field. */
121
148
  onError?: ErrorHandler<ErrorShape>;
122
149
  /** Form submission handler called when the form is submitted with no validation errors. */
@@ -125,14 +152,20 @@ export interface FormOptions<FormShape, ErrorShape = string, Value = undefined>
125
152
  onInput?: InputHandler;
126
153
  /** Blur event handler for custom focus handling logic. */
127
154
  onBlur?: BlurHandler;
128
- }
129
- export interface FormContext<ErrorShape = string> {
155
+ } & (string extends ErrorShape ? {
156
+ /** Custom validation handler. Can be skipped if using the schema property, or combined with schema to customize validation errors. */
157
+ onValidate?: ValidateHandler<ErrorShape, Value>;
158
+ } : {
159
+ /** Custom validation handler. Can be skipped if using the schema property, or combined with schema to customize validation errors. */
160
+ onValidate: ValidateHandler<ErrorShape, Value>;
161
+ });
162
+ export interface FormContext<ErrorShape extends BaseErrorShape = DefaultErrorShape> {
130
163
  /** The form's unique identifier */
131
164
  formId: string;
132
165
  /** Internal form state with validation results and field data */
133
166
  state: FormState<ErrorShape>;
134
167
  /** Initial form values */
135
- defaultValue: NonNullable<DefaultValue<Record<string, any>>> | null;
168
+ defaultValue: Record<string, any> | null;
136
169
  /** HTML validation attributes for fields */
137
170
  constraint: Record<string, ValidationAttributes> | null;
138
171
  /** Form submission event handler */
@@ -231,7 +264,7 @@ export type FormIntent<Dispatcher extends IntentDispatcher = IntentDispatcher> =
231
264
  export type ActionHandler<Signature extends (payload: any) => void = (payload: any) => void> = {
232
265
  validatePayload?(...args: UnknownArgs<Parameters<Signature>>): boolean;
233
266
  onApply?(value: Record<string, FormValue>, ...args: Parameters<Signature>): Record<string, FormValue> | null;
234
- onUpdate?<ErrorShape>(state: FormState<ErrorShape>, action: FormAction<ErrorShape, {
267
+ onUpdate?<ErrorShape extends BaseErrorShape>(state: FormState<ErrorShape>, action: FormAction<ErrorShape, {
235
268
  type: string;
236
269
  payload: Signature extends (payload: infer Payload) => void ? Payload : undefined;
237
270
  }>): FormState<ErrorShape>;
@@ -240,28 +273,84 @@ type BaseCombine<T, K extends PropertyKey = T extends unknown ? keyof T : never>
240
273
  export type Combine<T> = {
241
274
  [K in keyof BaseCombine<T>]: BaseCombine<T>[K];
242
275
  };
243
- /** Field metadata object containing field state, validation attributes, and nested field access methods. */
244
- export type FieldMetadata<FieldShape, Metadata extends Record<string, unknown> = DefaultMetadata<unknown>> = Readonly<Metadata & {
276
+ /**
277
+ * Extend this interface to define the base error shape for validation.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * declare module '@conform-to/react/future' {
282
+ * interface CustomTypes {
283
+ * errorShape: { message: string; code: string };
284
+ * }
285
+ * }
286
+ * ```
287
+ */
288
+ export interface CustomTypes {
289
+ }
290
+ export type BaseErrorShape = CustomTypes extends {
291
+ errorShape: infer Shape;
292
+ } ? Shape : unknown;
293
+ export type DefaultErrorShape = CustomTypes extends {
294
+ errorShape: infer Shape;
295
+ } ? Shape : string;
296
+ /** Base field metadata object containing field state, validation attributes, and accessibility IDs. */
297
+ export type BaseMetadata<FieldShape, ErrorShape extends BaseErrorShape> = ValidationAttributes & {
245
298
  /** Unique key for React list rendering (for array fields). */
246
299
  key: string | undefined;
247
300
  /** The field name path exactly as provided. */
248
301
  name: FieldName<FieldShape>;
302
+ /** The field's unique identifier, automatically generated as {formId}-field-{fieldName}. */
303
+ id: string;
304
+ /** Auto-generated ID for associating field descriptions via aria-describedby. */
305
+ descriptionId: string;
306
+ /** Auto-generated ID for associating field errors via aria-describedby. */
307
+ errorId: string;
308
+ /** The form's unique identifier for associating field via the `form` attribute. */
309
+ formId: string;
310
+ /** The field's default value as a string. */
311
+ defaultValue: string | undefined;
312
+ /** Default selected options for multi-select fields or checkbox group. */
313
+ defaultOptions: string[] | undefined;
314
+ /** Default checked state for checkbox/radio inputs. */
315
+ defaultChecked: boolean | undefined;
316
+ /** Whether this field has been touched (through intent.validate() or the shouldValidate option). */
317
+ touched: boolean;
318
+ /** Whether this field currently has no validation errors. */
319
+ valid: boolean;
320
+ /** @deprecated Use `.valid` instead. This was not an intentionl breaking change and would be removed in the next minor version soon */
321
+ invalid: boolean;
322
+ /** Array of validation error messages for this field. */
323
+ errors: ErrorShape[] | undefined;
324
+ /** Object containing errors for all touched subfields. */
325
+ fieldErrors: Record<string, ErrorShape[]>;
326
+ /** Boolean value for the `aria-invalid` attribute. Indicates whether the field has validation errors for screen readers. */
327
+ ariaInvalid: boolean | undefined;
328
+ /** String value for the `aria-describedby` attribute. Contains the errorId when invalid, undefined otherwise. Merge with descriptionId manually if needed (e.g. `${metadata.descriptionId} ${metadata.ariaDescribedBy}`). */
329
+ ariaDescribedBy: string | undefined;
249
330
  /** Method to get nested fieldset for object fields under this field. */
250
- getFieldset(): Fieldset<[
251
- FieldShape
252
- ] extends [Record<string, unknown> | null | undefined] ? FieldShape : unknown, Metadata>;
331
+ getFieldset<FieldsetShape = [FieldShape] extends [
332
+ Record<string, unknown> | null | undefined
333
+ ] ? FieldShape : unknown>(): Fieldset<FieldsetShape, ErrorShape>;
253
334
  /** Method to get array of fields for list/array fields under this field. */
254
- getFieldList(): Array<FieldMetadata<[
255
- FieldShape
256
- ] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, Metadata>>;
257
- }>;
335
+ getFieldList<FieldItemShape = [FieldShape] extends [
336
+ Array<infer ItemShape> | null | undefined
337
+ ] ? ItemShape : unknown>(): Array<FieldMetadata<FieldItemShape, ErrorShape>>;
338
+ };
339
+ export type SatisfyComponentProps<ElementType extends React.ElementType, CustomProps extends React.ComponentPropsWithoutRef<ElementType>> = CustomProps;
340
+ /**
341
+ * Interface for extending field metadata with additional properties.
342
+ */
343
+ export interface CustomMetadata<FieldShape = any, ErrorShape extends BaseErrorShape = DefaultErrorShape> {
344
+ }
345
+ export type CustomMetadataDefinition = <FieldShape, ErrorShape extends BaseErrorShape>(metadata: BaseMetadata<FieldShape, ErrorShape>) => keyof CustomMetadata<FieldShape, ErrorShape> extends never ? {} : CustomMetadata<any, any>;
346
+ /** Field metadata object containing field state, validation attributes, and nested field access methods. */
347
+ export type FieldMetadata<FieldShape, ErrorShape extends BaseErrorShape = DefaultErrorShape> = Readonly<(keyof CustomMetadata<FieldShape, ErrorShape> extends never ? {} : CustomMetadata<FieldShape, ErrorShape>) & BaseMetadata<FieldShape, ErrorShape>>;
258
348
  /** Fieldset object containing all form fields as properties with their respective field metadata. */
259
- export type Fieldset<FieldShape, // extends Record<string, unknown>,
260
- Metadata extends Record<string, unknown>> = {
261
- [Key in keyof Combine<FieldShape>]-?: FieldMetadata<Combine<FieldShape>[Key], Metadata>;
349
+ export type Fieldset<FieldShape, ErrorShape extends BaseErrorShape = DefaultErrorShape> = {
350
+ [Key in keyof Combine<FieldShape>]-?: FieldMetadata<Combine<FieldShape>[Key], ErrorShape>;
262
351
  };
263
352
  /** Form-level metadata and state object containing validation status, errors, and field access methods. */
264
- export type FormMetadata<ErrorShape, Metadata extends Record<string, unknown> = DefaultMetadata<ErrorShape>> = Readonly<{
353
+ export type FormMetadata<ErrorShape extends BaseErrorShape = DefaultErrorShape> = Readonly<{
265
354
  /** Unique identifier that changes on form reset */
266
355
  key: string;
267
356
  /** The form's unique identifier. */
@@ -291,56 +380,54 @@ export type FormMetadata<ErrorShape, Metadata extends Record<string, unknown> =
291
380
  /** The current state of the form */
292
381
  context: FormContext<ErrorShape>;
293
382
  /** Method to get metadata for a specific field by name. */
294
- getField<FieldShape>(name: FieldName<FieldShape>): FieldMetadata<FieldShape, Metadata>;
383
+ getField<FieldShape>(name: FieldName<FieldShape>): FieldMetadata<FieldShape, ErrorShape>;
295
384
  /** Method to get a fieldset object for nested object fields. */
296
385
  getFieldset<FieldShape>(name?: FieldName<FieldShape>): Fieldset<[
297
386
  FieldShape
298
- ] extends [Record<string, unknown> | null | undefined] ? FieldShape : unknown, Metadata>;
387
+ ] extends [Record<string, unknown> | null | undefined] ? FieldShape : unknown, ErrorShape>;
299
388
  /** Method to get an array of field objects for array fields. */
300
389
  getFieldList<FieldShape>(name: FieldName<FieldShape>): Array<FieldMetadata<[
301
390
  FieldShape
302
- ] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, Metadata>>;
303
- }>;
304
- /** Default field metadata object containing field state, validation attributes, and accessibility IDs. */
305
- export type DefaultMetadata<ErrorShape> = Readonly<ValidationAttributes & {
306
- /** The field's unique identifier, automatically generated as {formId}-field-{fieldName}. */
307
- id: string;
308
- /** Auto-generated ID for associating field descriptions via aria-describedby. */
309
- descriptionId: string;
310
- /** Auto-generated ID for associating field errors via aria-describedby. */
311
- errorId: string;
312
- /** The form's unique identifier for associating field via the `form` attribute. */
313
- formId: string;
314
- /** The field's default value as a string. */
315
- defaultValue: string | undefined;
316
- /** Default selected options for multi-select fields or checkbox group. */
317
- defaultOptions: string[] | undefined;
318
- /** Default checked state for checkbox/radio inputs. */
319
- defaultChecked: boolean | undefined;
320
- /** Whether this field has been touched (through intent.validate() or the shouldValidate option). */
321
- touched: boolean;
322
- /** Whether this field currently has no validation errors. */
323
- valid: boolean;
324
- /** @deprecated Use `.valid` instead. This was not an intentionl breaking change and would be removed in the next minor version soon */
325
- invalid: boolean;
326
- /** Array of validation error messages for this field. */
327
- errors: ErrorShape[] | undefined;
328
- /** Object containing errors for all touched subfields. */
329
- fieldErrors: Record<string, ErrorShape[]>;
391
+ ] extends [Array<infer ItemShape> | null | undefined] ? ItemShape : unknown, ErrorShape>>;
330
392
  }>;
331
393
  export type ValidateResult<ErrorShape, Value> = FormError<ErrorShape> | null | {
332
394
  error: FormError<ErrorShape> | null;
333
395
  value?: Value;
334
396
  };
335
- export type ValidateContext = {
397
+ export type ValidateContext<Value> = {
398
+ /**
399
+ * The submitted values mapped by field name.
400
+ * Supports nested names like `user.email` and indexed names like `items[0].id`.
401
+ */
336
402
  payload: Record<string, FormValue>;
403
+ /**
404
+ * Form error object. Initially empty, but populated with schema validation
405
+ * errors when a schema is provided and validation fails.
406
+ */
337
407
  error: FormError<string>;
408
+ /**
409
+ * The submission intent derived from the button that triggered the form submission.
410
+ */
338
411
  intent: UnknownIntent | null;
412
+ /**
413
+ * The raw FormData object of the submission.
414
+ */
339
415
  formData: FormData;
416
+ /**
417
+ * Reference to the HTML form element that triggered the submission.
418
+ */
340
419
  formElement: HTMLFormElement;
420
+ /**
421
+ * The specific element (button/input) that triggered the form submission.
422
+ */
341
423
  submitter: HTMLElement | null;
424
+ /**
425
+ * The validated value from schema validation. Only defined when a schema is provided
426
+ * and the validation succeeds. Undefined if no schema is provided or validation fails.
427
+ */
428
+ schemaValue: Value | undefined;
342
429
  };
343
- export type ValidateHandler<ErrorShape, Value> = (ctx: ValidateContext) => ValidateResult<ErrorShape, Value> | Promise<ValidateResult<ErrorShape, Value>> | [
430
+ export type ValidateHandler<ErrorShape, Value> = (ctx: ValidateContext<Value>) => ValidateResult<ErrorShape, Value> | Promise<ValidateResult<ErrorShape, Value>> | [
344
431
  ValidateResult<ErrorShape, Value> | undefined,
345
432
  Promise<ValidateResult<ErrorShape, Value>> | undefined
346
433
  ] | undefined;
@@ -361,7 +448,7 @@ export type ErrorContext<ErrorShape> = {
361
448
  export type ErrorHandler<ErrorShape> = (ctx: ErrorContext<ErrorShape>) => void;
362
449
  export type InputHandler = (event: FormInputEvent) => void;
363
450
  export type BlurHandler = (event: FormFocusEvent) => void;
364
- export type SubmitContext<ErrorShape = string, Value = undefined> = {
451
+ export type SubmitContext<ErrorShape extends BaseErrorShape = DefaultErrorShape, Value = undefined> = {
365
452
  formData: FormData;
366
453
  value: Value;
367
454
  update: (options: {
@@ -369,6 +456,6 @@ export type SubmitContext<ErrorShape = string, Value = undefined> = {
369
456
  reset?: boolean;
370
457
  }) => void;
371
458
  };
372
- export type SubmitHandler<ErrorShape = string, Value = undefined> = (event: React.FormEvent<HTMLFormElement>, ctx: SubmitContext<ErrorShape, Value>) => void | Promise<void>;
459
+ export type SubmitHandler<ErrorShape extends BaseErrorShape = DefaultErrorShape, Value = undefined> = (event: React.FormEvent<HTMLFormElement>, ctx: SubmitContext<ErrorShape, Value>) => void | Promise<void>;
373
460
  export {};
374
461
  //# sourceMappingURL=types.d.ts.map
@@ -41,7 +41,6 @@ export declare function resolveValidateResult<ErrorShape, Value>(result: ReturnT
41
41
  value?: Value | undefined;
42
42
  }> | undefined;
43
43
  };
44
- export declare function resolveStandardSchemaPath(issue: StandardSchemaV1.Issue): Array<string | number>;
45
44
  export declare function resolveStandardSchemaResult<Value>(result: StandardSchemaV1.Result<Value>): {
46
45
  error: FormError<string> | null;
47
46
  value?: Value;
@@ -2,10 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js');
6
5
  var future = require('@conform-to/dom/future');
7
6
 
8
- var _excluded = [""];
9
7
  function isUndefined(value) {
10
8
  return value === undefined;
11
9
  }
@@ -117,16 +115,6 @@ function resolveValidateResult(result) {
117
115
  asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
118
116
  };
119
117
  }
120
- function resolveStandardSchemaPath(issue) {
121
- if (!issue.path) {
122
- return [];
123
- }
124
- var segments = issue.path.map(segment => typeof segment === 'object' && 'key' in segment ? segment.key : segment);
125
- if (!segments.every(segment => typeof segment !== 'symbol')) {
126
- throw new Error('Path segments must not contain symbols. Use strings or numbers instead.');
127
- }
128
- return segments;
129
- }
130
118
  function resolveStandardSchemaResult(result) {
131
119
  if (!result.issues) {
132
120
  return {
@@ -134,23 +122,8 @@ function resolveStandardSchemaResult(result) {
134
122
  value: result.value
135
123
  };
136
124
  }
137
- var errorByName = {};
138
- for (var issue of result.issues) {
139
- var _errorByName$_name;
140
- var path = resolveStandardSchemaPath(issue);
141
- var _name = future.formatPathSegments(path);
142
- (_errorByName$_name = errorByName[_name]) !== null && _errorByName$_name !== void 0 ? _errorByName$_name : errorByName[_name] = [];
143
- errorByName[_name].push(issue.message);
144
- }
145
- var {
146
- '': formErrors = []
147
- } = errorByName,
148
- fieldErrors = _rollupPluginBabelHelpers.objectWithoutProperties(errorByName, _excluded);
149
125
  return {
150
- error: {
151
- formErrors,
152
- fieldErrors
153
- }
126
+ error: future.formatIssues(result.issues)
154
127
  };
155
128
  }
156
129
 
@@ -174,9 +147,9 @@ function merge(obj, update) {
174
147
  function transformKeys(obj, fn) {
175
148
  var result = {};
176
149
  for (var [_key, _value] of Object.entries(obj)) {
177
- var _name2 = fn(_key);
178
- if (_name2 !== null) {
179
- result[_name2] = _value;
150
+ var _name = fn(_key);
151
+ if (_name !== null) {
152
+ result[_name] = _value;
180
153
  }
181
154
  }
182
155
  return result;
@@ -222,7 +195,6 @@ exports.isUndefined = isUndefined;
222
195
  exports.merge = merge;
223
196
  exports.normalizeFormError = normalizeFormError;
224
197
  exports.normalizeValidateResult = normalizeValidateResult;
225
- exports.resolveStandardSchemaPath = resolveStandardSchemaPath;
226
198
  exports.resolveStandardSchemaResult = resolveStandardSchemaResult;
227
199
  exports.resolveValidateResult = resolveValidateResult;
228
200
  exports.transformKeys = transformKeys;
@@ -1,7 +1,5 @@
1
- import { objectWithoutProperties as _objectWithoutProperties } from '../_virtual/_rollupPluginBabelHelpers.mjs';
2
- import { formatPathSegments, getValueAtPath, isPlainObject, setValueAtPath, getPathSegments } from '@conform-to/dom/future';
1
+ import { formatIssues, getValueAtPath, isPlainObject, setValueAtPath, getPathSegments, formatPathSegments } from '@conform-to/dom/future';
3
2
 
4
- var _excluded = [""];
5
3
  function isUndefined(value) {
6
4
  return value === undefined;
7
5
  }
@@ -113,16 +111,6 @@ function resolveValidateResult(result) {
113
111
  asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
114
112
  };
115
113
  }
116
- function resolveStandardSchemaPath(issue) {
117
- if (!issue.path) {
118
- return [];
119
- }
120
- var segments = issue.path.map(segment => typeof segment === 'object' && 'key' in segment ? segment.key : segment);
121
- if (!segments.every(segment => typeof segment !== 'symbol')) {
122
- throw new Error('Path segments must not contain symbols. Use strings or numbers instead.');
123
- }
124
- return segments;
125
- }
126
114
  function resolveStandardSchemaResult(result) {
127
115
  if (!result.issues) {
128
116
  return {
@@ -130,23 +118,8 @@ function resolveStandardSchemaResult(result) {
130
118
  value: result.value
131
119
  };
132
120
  }
133
- var errorByName = {};
134
- for (var issue of result.issues) {
135
- var _errorByName$_name;
136
- var path = resolveStandardSchemaPath(issue);
137
- var _name = formatPathSegments(path);
138
- (_errorByName$_name = errorByName[_name]) !== null && _errorByName$_name !== void 0 ? _errorByName$_name : errorByName[_name] = [];
139
- errorByName[_name].push(issue.message);
140
- }
141
- var {
142
- '': formErrors = []
143
- } = errorByName,
144
- fieldErrors = _objectWithoutProperties(errorByName, _excluded);
145
121
  return {
146
- error: {
147
- formErrors,
148
- fieldErrors
149
- }
122
+ error: formatIssues(result.issues)
150
123
  };
151
124
  }
152
125
 
@@ -170,9 +143,9 @@ function merge(obj, update) {
170
143
  function transformKeys(obj, fn) {
171
144
  var result = {};
172
145
  for (var [_key, _value] of Object.entries(obj)) {
173
- var _name2 = fn(_key);
174
- if (_name2 !== null) {
175
- result[_name2] = _value;
146
+ var _name = fn(_key);
147
+ if (_name !== null) {
148
+ result[_name] = _value;
176
149
  }
177
150
  }
178
151
  return result;
@@ -206,4 +179,4 @@ function generateUniqueKey() {
206
179
  return Math.trunc(Date.now() * Math.random()).toString(36);
207
180
  }
208
181
 
209
- export { appendUniqueItem, compactMap, createPathIndexUpdater, generateUniqueKey, getArrayAtPath, isNumber, isOptional, isString, isUndefined, merge, normalizeFormError, normalizeValidateResult, resolveStandardSchemaPath, resolveStandardSchemaResult, resolveValidateResult, transformKeys, updateValueAtPath };
182
+ export { appendUniqueItem, compactMap, createPathIndexUpdater, generateUniqueKey, getArrayAtPath, isNumber, isOptional, isString, isUndefined, merge, normalizeFormError, normalizeValidateResult, resolveStandardSchemaResult, resolveValidateResult, transformKeys, updateValueAtPath };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Conform view adapter for react",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "1.10.1",
6
+ "version": "1.12.0",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "url": "https://github.com/edmundhung/conform/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@conform-to/dom": "1.10.1"
44
+ "@conform-to/dom": "1.12.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.17.8",