@conform-to/dom 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
8
8
  ```
9
9
 
10
- Version 1.10.0 / License MIT / Copyright (c) 2025 Edmund Hung
10
+ Version 1.11.0 / License MIT / Copyright (c) 2025 Edmund Hung
11
11
 
12
12
  Progressively enhance HTML forms with React. Build resilient, type-safe forms with no hassle using web standards.
13
13
 
@@ -1,4 +1,5 @@
1
- import type { FormError, FormValue, JsonPrimitive, Serialize, SerializedValue, Submission, SubmissionResult } from './types';
1
+ import type { FormValue, JsonPrimitive, Serialize, SerializedValue, Submission, SubmissionResult } from './types';
2
+ import type { StandardSchemaIssue } from './standard-schema';
2
3
  export declare const DEFAULT_INTENT_NAME = "__INTENT__";
3
4
  /**
4
5
  * Construct a form data with the submitter value.
@@ -153,18 +154,48 @@ export declare function parseSubmission(formData: FormData | URLSearchParams, op
153
154
  */
154
155
  export declare function report<ErrorShape = string>(submission: Submission, options?: {
155
156
  keepFiles?: false;
156
- error?: Partial<FormError<ErrorShape>> | null;
157
+ error?: {
158
+ issues?: undefined;
159
+ formErrors?: ErrorShape[];
160
+ fieldErrors?: Record<string, ErrorShape[]>;
161
+ } | null;
157
162
  intendedValue?: Record<string, FormValue> | null;
158
163
  hideFields?: string[];
159
164
  reset?: boolean;
160
165
  }): SubmissionResult<ErrorShape, Exclude<JsonPrimitive | FormDataEntryValue, File>>;
161
166
  export declare function report<ErrorShape = string>(submission: Submission, options: {
162
167
  keepFiles: true;
163
- error?: Partial<FormError<ErrorShape>> | null;
168
+ error?: {
169
+ issues?: undefined;
170
+ formErrors?: ErrorShape[];
171
+ fieldErrors?: Record<string, ErrorShape[]>;
172
+ } | null;
164
173
  intendedValue?: Record<string, FormValue> | null;
165
174
  hideFields?: string[];
166
175
  reset?: boolean;
167
176
  }): SubmissionResult<ErrorShape>;
177
+ export declare function report(submission: Submission, options?: {
178
+ keepFiles?: false;
179
+ error?: {
180
+ issues: ReadonlyArray<StandardSchemaIssue>;
181
+ formErrors?: string[];
182
+ fieldErrors?: Record<string, string[]>;
183
+ };
184
+ intendedValue?: Record<string, FormValue> | null;
185
+ hideFields?: string[];
186
+ reset?: boolean;
187
+ }): SubmissionResult<string, Exclude<JsonPrimitive | FormDataEntryValue, File>>;
188
+ export declare function report(submission: Submission, options?: {
189
+ keepFiles: true;
190
+ error?: {
191
+ issues: ReadonlyArray<StandardSchemaIssue>;
192
+ formErrors?: string[];
193
+ fieldErrors?: Record<string, string[]>;
194
+ };
195
+ intendedValue?: Record<string, FormValue> | null;
196
+ hideFields?: string[];
197
+ reset?: boolean;
198
+ }): SubmissionResult<string>;
168
199
  /**
169
200
  * A utility function that checks whether the current form data differs from the default values.
170
201
  *
package/dist/formdata.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
6
6
  var dom = require('./dom.js');
7
7
  var util = require('./util.js');
8
+ var standardSchema = require('./standard-schema.js');
8
9
 
9
10
  var DEFAULT_INTENT_NAME = '__INTENT__';
10
11
 
@@ -327,16 +328,33 @@ function parseSubmission(formData, options) {
327
328
  */
328
329
 
329
330
  function report(submission) {
330
- var _options$error$formEr, _options$error$fieldE;
331
331
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
332
+ var error;
333
+ if (options.error == null) {
334
+ error = options.error;
335
+ } else {
336
+ var _options$error$issues;
337
+ error = standardSchema.formatIssues((_options$error$issues = options.error.issues) !== null && _options$error$issues !== void 0 ? _options$error$issues : []);
338
+ if (options.error.formErrors) {
339
+ error.formErrors.push(...options.error.formErrors);
340
+ }
341
+ if (options.error.fieldErrors) {
342
+ for (var [_name2, messages] of Object.entries(options.error.fieldErrors)) {
343
+ if (messages.length === 0) {
344
+ continue;
345
+ }
346
+ if (!error.fieldErrors[_name2]) {
347
+ error.fieldErrors[_name2] = messages;
348
+ } else {
349
+ error.fieldErrors[_name2].push(...messages);
350
+ }
351
+ }
352
+ }
353
+ }
332
354
  var intendedValue = options.reset ? null : typeof options.intendedValue === 'undefined' || submission.payload === options.intendedValue ? undefined : options.intendedValue && !options.keepFiles ? util.stripFiles(options.intendedValue) : options.intendedValue;
333
- var error = !options.error ? options.error : {
334
- formErrors: (_options$error$formEr = options.error.formErrors) !== null && _options$error$formEr !== void 0 ? _options$error$formEr : [],
335
- fieldErrors: (_options$error$fieldE = options.error.fieldErrors) !== null && _options$error$fieldE !== void 0 ? _options$error$fieldE : {}
336
- };
337
355
  if (options.hideFields) {
338
- for (var _name2 of options.hideFields) {
339
- var path = getPathSegments(_name2);
356
+ for (var _name3 of options.hideFields) {
357
+ var path = getPathSegments(_name3);
340
358
  setValueAtPath(submission.payload, path, undefined);
341
359
  if (intendedValue) {
342
360
  setValueAtPath(intendedValue, path, undefined);
package/dist/formdata.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
2
2
  import { isSubmitter, isGlobalInstance } from './dom.mjs';
3
3
  import { isPlainObject, stripFiles, deepEqual } from './util.mjs';
4
+ import { formatIssues } from './standard-schema.mjs';
4
5
 
5
6
  var DEFAULT_INTENT_NAME = '__INTENT__';
6
7
 
@@ -323,16 +324,33 @@ function parseSubmission(formData, options) {
323
324
  */
324
325
 
325
326
  function report(submission) {
326
- var _options$error$formEr, _options$error$fieldE;
327
327
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
328
+ var error;
329
+ if (options.error == null) {
330
+ error = options.error;
331
+ } else {
332
+ var _options$error$issues;
333
+ error = formatIssues((_options$error$issues = options.error.issues) !== null && _options$error$issues !== void 0 ? _options$error$issues : []);
334
+ if (options.error.formErrors) {
335
+ error.formErrors.push(...options.error.formErrors);
336
+ }
337
+ if (options.error.fieldErrors) {
338
+ for (var [_name2, messages] of Object.entries(options.error.fieldErrors)) {
339
+ if (messages.length === 0) {
340
+ continue;
341
+ }
342
+ if (!error.fieldErrors[_name2]) {
343
+ error.fieldErrors[_name2] = messages;
344
+ } else {
345
+ error.fieldErrors[_name2].push(...messages);
346
+ }
347
+ }
348
+ }
349
+ }
328
350
  var intendedValue = options.reset ? null : typeof options.intendedValue === 'undefined' || submission.payload === options.intendedValue ? undefined : options.intendedValue && !options.keepFiles ? stripFiles(options.intendedValue) : options.intendedValue;
329
- var error = !options.error ? options.error : {
330
- formErrors: (_options$error$formEr = options.error.formErrors) !== null && _options$error$formEr !== void 0 ? _options$error$formEr : [],
331
- fieldErrors: (_options$error$fieldE = options.error.fieldErrors) !== null && _options$error$fieldE !== void 0 ? _options$error$fieldE : {}
332
- };
333
351
  if (options.hideFields) {
334
- for (var _name2 of options.hideFields) {
335
- var path = getPathSegments(_name2);
352
+ for (var _name3 of options.hideFields) {
353
+ var path = getPathSegments(_name3);
336
354
  setValueAtPath(submission.payload, path, undefined);
337
355
  if (intendedValue) {
338
356
  setValueAtPath(intendedValue, path, undefined);
@@ -2,4 +2,5 @@ export type { Serialize, FormValue, FormError, Submission, SubmissionResult, Val
2
2
  export { DEFAULT_INTENT_NAME, getFormData, isDirty, parseSubmission, getPathSegments, formatPathSegments, appendPathSegment, getRelativePath, getValueAtPath, setValueAtPath, report, serialize, } from '../formdata';
3
3
  export { isPlainObject, deepEqual } from '../util';
4
4
  export { isFieldElement, isGlobalInstance, updateField, createFileList, createSubmitEvent, createGlobalFormsObserver, focus, change, blur, getFormAction, getFormEncType, getFormMethod, requestSubmit, requestIntent, } from '../dom';
5
+ export { formatIssues } from '../standard-schema';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var formdata = require('../formdata.js');
6
6
  var util = require('../util.js');
7
7
  var dom = require('../dom.js');
8
+ var standardSchema = require('../standard-schema.js');
8
9
 
9
10
 
10
11
 
@@ -36,3 +37,4 @@ exports.isGlobalInstance = dom.isGlobalInstance;
36
37
  exports.requestIntent = dom.requestIntent;
37
38
  exports.requestSubmit = dom.requestSubmit;
38
39
  exports.updateField = dom.updateField;
40
+ exports.formatIssues = standardSchema.formatIssues;
@@ -1,3 +1,4 @@
1
1
  export { DEFAULT_INTENT_NAME, appendPathSegment, formatPathSegments, getFormData, getPathSegments, getRelativePath, getValueAtPath, isDirty, parseSubmission, report, serialize, setValueAtPath } from '../formdata.mjs';
2
2
  export { deepEqual, isPlainObject } from '../util.mjs';
3
3
  export { blur, change, createFileList, createGlobalFormsObserver, createSubmitEvent, focus, getFormAction, getFormEncType, getFormMethod, isFieldElement, isGlobalInstance, requestIntent, requestSubmit, updateField } from '../dom.mjs';
4
+ export { formatIssues } from '../standard-schema.mjs';
@@ -0,0 +1,15 @@
1
+ import type { FormError } from './types';
2
+ /**
3
+ * A widened version of `StandardSchemaV1.Issue`.
4
+ *
5
+ * The `path` elements and `PropertyKey` fields are loosened to `unknown`
6
+ * to stay compatible with Valibot's native issue type.
7
+ */
8
+ export type StandardSchemaIssue = {
9
+ readonly message: string;
10
+ readonly path?: ReadonlyArray<unknown | {
11
+ key: unknown;
12
+ }> | undefined;
13
+ };
14
+ export declare function formatIssues(issues: Readonly<StandardSchemaIssue[]>): FormError<string>;
15
+ //# sourceMappingURL=standard-schema.d.ts.map
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var formdata = require('./formdata.js');
6
+ var util = require('./util.js');
7
+
8
+ /**
9
+ * A widened version of `StandardSchemaV1.Issue`.
10
+ *
11
+ * The `path` elements and `PropertyKey` fields are loosened to `unknown`
12
+ * to stay compatible with Valibot's native issue type.
13
+ */
14
+
15
+ function formatIssues(issues) {
16
+ var error = {
17
+ formErrors: [],
18
+ fieldErrors: {}
19
+ };
20
+ for (var issue of issues) {
21
+ var _issue$path$map, _issue$path;
22
+ var segments = (_issue$path$map = (_issue$path = issue.path) === null || _issue$path === void 0 ? void 0 : _issue$path.map(segment => {
23
+ var path = util.isPlainObject(segment) && 'key' in segment ? segment.key : segment;
24
+ if (typeof path !== 'string' && typeof path !== 'number') {
25
+ throw new Error("Only string or numeric path segment schemes are supported. Received segment: ".concat(String(path)));
26
+ }
27
+ return path;
28
+ })) !== null && _issue$path$map !== void 0 ? _issue$path$map : [];
29
+ var name = formdata.formatPathSegments(segments !== null && segments !== void 0 ? segments : []);
30
+ if (!name) {
31
+ error.formErrors.push(issue.message);
32
+ } else {
33
+ var _error$fieldErrors, _error$fieldErrors$na;
34
+ (_error$fieldErrors$na = (_error$fieldErrors = error.fieldErrors)[name]) !== null && _error$fieldErrors$na !== void 0 ? _error$fieldErrors$na : _error$fieldErrors[name] = [];
35
+ error.fieldErrors[name].push(issue.message);
36
+ }
37
+ }
38
+ return error;
39
+ }
40
+
41
+ exports.formatIssues = formatIssues;
@@ -0,0 +1,37 @@
1
+ import { formatPathSegments } from './formdata.mjs';
2
+ import { isPlainObject } from './util.mjs';
3
+
4
+ /**
5
+ * A widened version of `StandardSchemaV1.Issue`.
6
+ *
7
+ * The `path` elements and `PropertyKey` fields are loosened to `unknown`
8
+ * to stay compatible with Valibot's native issue type.
9
+ */
10
+
11
+ function formatIssues(issues) {
12
+ var error = {
13
+ formErrors: [],
14
+ fieldErrors: {}
15
+ };
16
+ for (var issue of issues) {
17
+ var _issue$path$map, _issue$path;
18
+ var segments = (_issue$path$map = (_issue$path = issue.path) === null || _issue$path === void 0 ? void 0 : _issue$path.map(segment => {
19
+ var path = isPlainObject(segment) && 'key' in segment ? segment.key : segment;
20
+ if (typeof path !== 'string' && typeof path !== 'number') {
21
+ throw new Error("Only string or numeric path segment schemes are supported. Received segment: ".concat(String(path)));
22
+ }
23
+ return path;
24
+ })) !== null && _issue$path$map !== void 0 ? _issue$path$map : [];
25
+ var name = formatPathSegments(segments !== null && segments !== void 0 ? segments : []);
26
+ if (!name) {
27
+ error.formErrors.push(issue.message);
28
+ } else {
29
+ var _error$fieldErrors, _error$fieldErrors$na;
30
+ (_error$fieldErrors$na = (_error$fieldErrors = error.fieldErrors)[name]) !== null && _error$fieldErrors$na !== void 0 ? _error$fieldErrors$na : _error$fieldErrors[name] = [];
31
+ error.fieldErrors[name].push(issue.message);
32
+ }
33
+ }
34
+ return error;
35
+ }
36
+
37
+ export { formatIssues };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "A set of opinionated helpers built on top of the Constraint Validation API",
4
4
  "homepage": "https://conform.guide",
5
5
  "license": "MIT",
6
- "version": "1.10.0",
6
+ "version": "1.11.0",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",