@conform-to/dom 1.13.0 → 1.13.2
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 +1 -1
- package/dist/dom.d.ts +1 -1
- package/dist/dom.js +11 -9
- package/dist/dom.mjs +11 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Version 1.13.
|
|
10
|
+
Version 1.13.2 / 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.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare function focus(element: HTMLInputElement | HTMLSelectElement | HT
|
|
|
83
83
|
*/
|
|
84
84
|
export declare function blur(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): void;
|
|
85
85
|
export declare function normalizeStringValues(value: unknown): string[] | undefined;
|
|
86
|
-
export declare function normalizeFileValues(value: unknown):
|
|
86
|
+
export declare function normalizeFileValues(value: unknown): File[] | undefined;
|
|
87
87
|
/**
|
|
88
88
|
* Retrieves the default value of a form field element by reading the DOM's
|
|
89
89
|
* defaultValue, defaultChecked, or defaultSelected properties.
|
package/dist/dom.js
CHANGED
|
@@ -396,11 +396,11 @@ function normalizeStringValues(value) {
|
|
|
396
396
|
}
|
|
397
397
|
function normalizeFileValues(value) {
|
|
398
398
|
if (typeof value === 'undefined') return undefined;
|
|
399
|
-
if (value === null) return
|
|
400
|
-
if (isGlobalInstance(value, 'File')) return
|
|
401
|
-
if (isGlobalInstance(value, 'FileList')) return value;
|
|
399
|
+
if (value === null) return [];
|
|
400
|
+
if (isGlobalInstance(value, 'File')) return value.name === '' && value.size === 0 ? [] : [value];
|
|
401
|
+
if (isGlobalInstance(value, 'FileList')) return Array.from(value);
|
|
402
402
|
if (Array.isArray(value) && value.every(item => isGlobalInstance(item, 'File'))) {
|
|
403
|
-
return
|
|
403
|
+
return value;
|
|
404
404
|
}
|
|
405
405
|
throw new Error('Expected File, FileList or File[] for file input');
|
|
406
406
|
}
|
|
@@ -453,9 +453,11 @@ function updateField(element, options) {
|
|
|
453
453
|
switch (element.type) {
|
|
454
454
|
case 'file':
|
|
455
455
|
{
|
|
456
|
+
var _element$files;
|
|
456
457
|
var files = normalizeFileValues(options.value);
|
|
457
|
-
|
|
458
|
-
|
|
458
|
+
var currentFiles = Array.from((_element$files = element.files) !== null && _element$files !== void 0 ? _element$files : []);
|
|
459
|
+
if (files && (files.length !== currentFiles.length || files.some((file, i) => file !== currentFiles[i]))) {
|
|
460
|
+
element.files = createFileList(files);
|
|
459
461
|
isChanged = true;
|
|
460
462
|
}
|
|
461
463
|
return isChanged;
|
|
@@ -525,7 +527,7 @@ function updateField(element, options) {
|
|
|
525
527
|
|
|
526
528
|
// If the select element is not multiple and the value is an empty array, unset the selected index
|
|
527
529
|
// This is to prevent the select element from showing the first option as selected
|
|
528
|
-
if (shouldUnselect) {
|
|
530
|
+
if (shouldUnselect && element.selectedIndex !== -1) {
|
|
529
531
|
element.selectedIndex = -1;
|
|
530
532
|
isChanged = true;
|
|
531
533
|
}
|
|
@@ -564,14 +566,14 @@ function updateField(element, options) {
|
|
|
564
566
|
return isChanged;
|
|
565
567
|
}
|
|
566
568
|
function isDirtyInput(element) {
|
|
567
|
-
var _element$files$length, _element$
|
|
569
|
+
var _element$files$length, _element$files2;
|
|
568
570
|
if (isInputElement(element)) {
|
|
569
571
|
switch (element.type) {
|
|
570
572
|
case 'checkbox':
|
|
571
573
|
case 'radio':
|
|
572
574
|
return element.checked !== element.defaultChecked;
|
|
573
575
|
case 'file':
|
|
574
|
-
return ((_element$files$length = (_element$
|
|
576
|
+
return ((_element$files$length = (_element$files2 = element.files) === null || _element$files2 === void 0 ? void 0 : _element$files2.length) !== null && _element$files$length !== void 0 ? _element$files$length : 0) > 0;
|
|
575
577
|
default:
|
|
576
578
|
return element.value !== element.defaultValue;
|
|
577
579
|
}
|
package/dist/dom.mjs
CHANGED
|
@@ -392,11 +392,11 @@ function normalizeStringValues(value) {
|
|
|
392
392
|
}
|
|
393
393
|
function normalizeFileValues(value) {
|
|
394
394
|
if (typeof value === 'undefined') return undefined;
|
|
395
|
-
if (value === null) return
|
|
396
|
-
if (isGlobalInstance(value, 'File')) return
|
|
397
|
-
if (isGlobalInstance(value, 'FileList')) return value;
|
|
395
|
+
if (value === null) return [];
|
|
396
|
+
if (isGlobalInstance(value, 'File')) return value.name === '' && value.size === 0 ? [] : [value];
|
|
397
|
+
if (isGlobalInstance(value, 'FileList')) return Array.from(value);
|
|
398
398
|
if (Array.isArray(value) && value.every(item => isGlobalInstance(item, 'File'))) {
|
|
399
|
-
return
|
|
399
|
+
return value;
|
|
400
400
|
}
|
|
401
401
|
throw new Error('Expected File, FileList or File[] for file input');
|
|
402
402
|
}
|
|
@@ -449,9 +449,11 @@ function updateField(element, options) {
|
|
|
449
449
|
switch (element.type) {
|
|
450
450
|
case 'file':
|
|
451
451
|
{
|
|
452
|
+
var _element$files;
|
|
452
453
|
var files = normalizeFileValues(options.value);
|
|
453
|
-
|
|
454
|
-
|
|
454
|
+
var currentFiles = Array.from((_element$files = element.files) !== null && _element$files !== void 0 ? _element$files : []);
|
|
455
|
+
if (files && (files.length !== currentFiles.length || files.some((file, i) => file !== currentFiles[i]))) {
|
|
456
|
+
element.files = createFileList(files);
|
|
455
457
|
isChanged = true;
|
|
456
458
|
}
|
|
457
459
|
return isChanged;
|
|
@@ -521,7 +523,7 @@ function updateField(element, options) {
|
|
|
521
523
|
|
|
522
524
|
// If the select element is not multiple and the value is an empty array, unset the selected index
|
|
523
525
|
// This is to prevent the select element from showing the first option as selected
|
|
524
|
-
if (shouldUnselect) {
|
|
526
|
+
if (shouldUnselect && element.selectedIndex !== -1) {
|
|
525
527
|
element.selectedIndex = -1;
|
|
526
528
|
isChanged = true;
|
|
527
529
|
}
|
|
@@ -560,14 +562,14 @@ function updateField(element, options) {
|
|
|
560
562
|
return isChanged;
|
|
561
563
|
}
|
|
562
564
|
function isDirtyInput(element) {
|
|
563
|
-
var _element$files$length, _element$
|
|
565
|
+
var _element$files$length, _element$files2;
|
|
564
566
|
if (isInputElement(element)) {
|
|
565
567
|
switch (element.type) {
|
|
566
568
|
case 'checkbox':
|
|
567
569
|
case 'radio':
|
|
568
570
|
return element.checked !== element.defaultChecked;
|
|
569
571
|
case 'file':
|
|
570
|
-
return ((_element$files$length = (_element$
|
|
572
|
+
return ((_element$files$length = (_element$files2 = element.files) === null || _element$files2 === void 0 ? void 0 : _element$files2.length) !== null && _element$files$length !== void 0 ? _element$files$length : 0) > 0;
|
|
571
573
|
default:
|
|
572
574
|
return element.value !== element.defaultValue;
|
|
573
575
|
}
|
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.13.
|
|
6
|
+
"version": "1.13.2",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|