@conform-to/dom 1.9.1 → 1.10.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.9.1 / License MIT / Copyright (c) 2025 Edmund Hung
10
+ Version 1.10.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
 
package/dist/dom.js CHANGED
@@ -397,7 +397,7 @@ function normalizeStringValues(value) {
397
397
  function normalizeFileValues(value) {
398
398
  if (typeof value === 'undefined') return undefined;
399
399
  if (value === null) return createFileList([]);
400
- if (isGlobalInstance(value, 'File')) return createFileList([value]);
400
+ if (isGlobalInstance(value, 'File')) return createFileList(value.name === '' && value.size === 0 ? [] : [value]);
401
401
  if (isGlobalInstance(value, 'FileList')) return value;
402
402
  if (Array.isArray(value) && value.every(item => isGlobalInstance(item, 'File'))) {
403
403
  return createFileList(value);
package/dist/dom.mjs CHANGED
@@ -393,7 +393,7 @@ function normalizeStringValues(value) {
393
393
  function normalizeFileValues(value) {
394
394
  if (typeof value === 'undefined') return undefined;
395
395
  if (value === null) return createFileList([]);
396
- if (isGlobalInstance(value, 'File')) return createFileList([value]);
396
+ if (isGlobalInstance(value, 'File')) return createFileList(value.name === '' && value.size === 0 ? [] : [value]);
397
397
  if (isGlobalInstance(value, 'FileList')) return value;
398
398
  if (Array.isArray(value) && value.every(item => isGlobalInstance(item, 'File'))) {
399
399
  return createFileList(value);
@@ -217,7 +217,7 @@ formData: FormData | URLSearchParams | FormValue | null, options?: {
217
217
  * - Date:
218
218
  * - Converted to ISO string using `.toISOString()`
219
219
  */
220
- serialize?: (value: unknown, defaultSerialize: Serialize) => SerializedValue | undefined;
220
+ serialize?: (value: unknown, defaultSerialize: Serialize) => SerializedValue | null | undefined;
221
221
  /**
222
222
  * A function to exclude specific fields from the comparison.
223
223
  * Useful for ignoring hidden inputs like CSRF tokens or internal fields added by frameworks
@@ -247,5 +247,5 @@ formData: FormData | URLSearchParams | FormValue | null, options?: {
247
247
  * - Array -> string[] or File[] if all items serialize to the same kind; otherwise undefined
248
248
  * - anything else -> undefined
249
249
  */
250
- export declare function serialize(value: unknown): SerializedValue | undefined;
250
+ export declare function serialize(value: unknown): SerializedValue | null | undefined;
251
251
  //# sourceMappingURL=formdata.d.ts.map
package/dist/formdata.js CHANGED
@@ -395,11 +395,13 @@ formData, options) {
395
395
  return serialize(value);
396
396
  };
397
397
  function normalize(data) {
398
- var _serializeData;
399
- var value = (_serializeData = serializeData(data)) !== null && _serializeData !== void 0 ? _serializeData : data;
398
+ var value = serializeData(data);
399
+ if (typeof value === 'undefined') {
400
+ value = data;
401
+ }
400
402
 
401
- // Removes empty strings, so that bpth empty string and undefined are treated as the same
402
- if (value === '') {
403
+ // Removes empty strings, so that both empty string, empty file, null and undefined are treated as the same
404
+ if (value === '' || value === null) {
403
405
  return undefined;
404
406
  }
405
407
  if (dom.isGlobalInstance(value, 'File')) {
@@ -457,12 +459,9 @@ formData, options) {
457
459
  */
458
460
  function serialize(value) {
459
461
  function serializePrimitive(value) {
460
- if (typeof value === 'string') {
462
+ if (typeof value === 'string' || value === null) {
461
463
  return value;
462
464
  }
463
- if (value === null) {
464
- return '';
465
- }
466
465
  if (typeof value === 'boolean') {
467
466
  return value ? 'on' : '';
468
467
  }
@@ -484,11 +483,13 @@ function serialize(value) {
484
483
  if (typeof serialized === 'undefined') {
485
484
  return;
486
485
  }
487
- if (typeof serialized === 'string') {
486
+
487
+ // It is unclear what `null` in a file array should mean, so we treat it as a string instead
488
+ if (typeof serialized === 'string' || serialized === null) {
488
489
  if (files.length > 0) {
489
490
  return;
490
491
  }
491
- _options.push(serialized);
492
+ _options.push(serialized !== null && serialized !== void 0 ? serialized : '');
492
493
  } else {
493
494
  if (_options.length > 0) {
494
495
  return;
package/dist/formdata.mjs CHANGED
@@ -391,11 +391,13 @@ formData, options) {
391
391
  return serialize(value);
392
392
  };
393
393
  function normalize(data) {
394
- var _serializeData;
395
- var value = (_serializeData = serializeData(data)) !== null && _serializeData !== void 0 ? _serializeData : data;
394
+ var value = serializeData(data);
395
+ if (typeof value === 'undefined') {
396
+ value = data;
397
+ }
396
398
 
397
- // Removes empty strings, so that bpth empty string and undefined are treated as the same
398
- if (value === '') {
399
+ // Removes empty strings, so that both empty string, empty file, null and undefined are treated as the same
400
+ if (value === '' || value === null) {
399
401
  return undefined;
400
402
  }
401
403
  if (isGlobalInstance(value, 'File')) {
@@ -453,12 +455,9 @@ formData, options) {
453
455
  */
454
456
  function serialize(value) {
455
457
  function serializePrimitive(value) {
456
- if (typeof value === 'string') {
458
+ if (typeof value === 'string' || value === null) {
457
459
  return value;
458
460
  }
459
- if (value === null) {
460
- return '';
461
- }
462
461
  if (typeof value === 'boolean') {
463
462
  return value ? 'on' : '';
464
463
  }
@@ -480,11 +479,13 @@ function serialize(value) {
480
479
  if (typeof serialized === 'undefined') {
481
480
  return;
482
481
  }
483
- if (typeof serialized === 'string') {
482
+
483
+ // It is unclear what `null` in a file array should mean, so we treat it as a string instead
484
+ if (typeof serialized === 'string' || serialized === null) {
484
485
  if (files.length > 0) {
485
486
  return;
486
487
  }
487
- _options.push(serialized);
488
+ _options.push(serialized !== null && serialized !== void 0 ? serialized : '');
488
489
  } else {
489
490
  if (_options.length > 0) {
490
491
  return;
package/dist/types.d.ts CHANGED
@@ -88,7 +88,7 @@ export type Serializable<T> = T extends File ? undefined : T extends Array<infer
88
88
  * @returns A `SerializedValue` if the input can be represented in `FormData`,
89
89
  * or `undefined` if it cannot be serialized.
90
90
  */
91
- export type Serialize = (value: unknown) => SerializedValue | undefined;
91
+ export type Serialize = (value: unknown) => SerializedValue | null | undefined;
92
92
  /**
93
93
  * A value that can be serialized into `FormData`.
94
94
  *
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.9.1",
6
+ "version": "1.10.0",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",