@conform-to/dom 1.12.0 → 1.13.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 +1 -1
- package/dist/dom.d.ts +5 -0
- package/dist/dom.js +38 -0
- package/dist/dom.mjs +38 -1
- package/dist/future/index.d.ts +1 -1
- package/dist/future/index.js +1 -0
- package/dist/future/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
Version 1.
|
|
10
|
+
Version 1.13.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.d.ts
CHANGED
|
@@ -84,6 +84,11 @@ export declare function focus(element: HTMLInputElement | HTMLSelectElement | HT
|
|
|
84
84
|
export declare function blur(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): void;
|
|
85
85
|
export declare function normalizeStringValues(value: unknown): string[] | undefined;
|
|
86
86
|
export declare function normalizeFileValues(value: unknown): FileList | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Retrieves the default value of a form field element by reading the DOM's
|
|
89
|
+
* defaultValue, defaultChecked, or defaultSelected properties.
|
|
90
|
+
*/
|
|
91
|
+
export declare function getFieldDefaultValue(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): string | string[] | File | File[] | FileList | null;
|
|
87
92
|
/**
|
|
88
93
|
* Updates the DOM element with the provided value and defaultValue.
|
|
89
94
|
* If the value or defaultValue is undefined, it will keep the current value instead
|
package/dist/dom.js
CHANGED
|
@@ -405,6 +405,43 @@ function normalizeFileValues(value) {
|
|
|
405
405
|
throw new Error('Expected File, FileList or File[] for file input');
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
+
/**
|
|
409
|
+
* Retrieves the default value of a form field element by reading the DOM's
|
|
410
|
+
* defaultValue, defaultChecked, or defaultSelected properties.
|
|
411
|
+
*/
|
|
412
|
+
function getFieldDefaultValue(element) {
|
|
413
|
+
if (isInputElement(element)) {
|
|
414
|
+
switch (element.type) {
|
|
415
|
+
case 'file':
|
|
416
|
+
{
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
case 'checkbox':
|
|
420
|
+
case 'radio':
|
|
421
|
+
{
|
|
422
|
+
if (element.defaultChecked) {
|
|
423
|
+
return element.value;
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
} else if (isSelectElement(element)) {
|
|
429
|
+
if (element.multiple) {
|
|
430
|
+
var values = [];
|
|
431
|
+
for (var option of element.options) {
|
|
432
|
+
if (option.defaultSelected) {
|
|
433
|
+
values.push(option.value);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
return values;
|
|
437
|
+
} else {
|
|
438
|
+
var selectedOption = Array.from(element.options).find(option => option.defaultSelected);
|
|
439
|
+
return selectedOption ? selectedOption.value : null;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return element.defaultValue;
|
|
443
|
+
}
|
|
444
|
+
|
|
408
445
|
/**
|
|
409
446
|
* Updates the DOM element with the provided value and defaultValue.
|
|
410
447
|
* If the value or defaultValue is undefined, it will keep the current value instead
|
|
@@ -552,6 +589,7 @@ exports.createFileList = createFileList;
|
|
|
552
589
|
exports.createGlobalFormsObserver = createGlobalFormsObserver;
|
|
553
590
|
exports.createSubmitEvent = createSubmitEvent;
|
|
554
591
|
exports.focus = focus;
|
|
592
|
+
exports.getFieldDefaultValue = getFieldDefaultValue;
|
|
555
593
|
exports.getFormAction = getFormAction;
|
|
556
594
|
exports.getFormEncType = getFormEncType;
|
|
557
595
|
exports.getFormMethod = getFormMethod;
|
package/dist/dom.mjs
CHANGED
|
@@ -401,6 +401,43 @@ function normalizeFileValues(value) {
|
|
|
401
401
|
throw new Error('Expected File, FileList or File[] for file input');
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Retrieves the default value of a form field element by reading the DOM's
|
|
406
|
+
* defaultValue, defaultChecked, or defaultSelected properties.
|
|
407
|
+
*/
|
|
408
|
+
function getFieldDefaultValue(element) {
|
|
409
|
+
if (isInputElement(element)) {
|
|
410
|
+
switch (element.type) {
|
|
411
|
+
case 'file':
|
|
412
|
+
{
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
case 'checkbox':
|
|
416
|
+
case 'radio':
|
|
417
|
+
{
|
|
418
|
+
if (element.defaultChecked) {
|
|
419
|
+
return element.value;
|
|
420
|
+
}
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} else if (isSelectElement(element)) {
|
|
425
|
+
if (element.multiple) {
|
|
426
|
+
var values = [];
|
|
427
|
+
for (var option of element.options) {
|
|
428
|
+
if (option.defaultSelected) {
|
|
429
|
+
values.push(option.value);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
return values;
|
|
433
|
+
} else {
|
|
434
|
+
var selectedOption = Array.from(element.options).find(option => option.defaultSelected);
|
|
435
|
+
return selectedOption ? selectedOption.value : null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return element.defaultValue;
|
|
439
|
+
}
|
|
440
|
+
|
|
404
441
|
/**
|
|
405
442
|
* Updates the DOM element with the provided value and defaultValue.
|
|
406
443
|
* If the value or defaultValue is undefined, it will keep the current value instead
|
|
@@ -542,4 +579,4 @@ function isDirtyInput(element) {
|
|
|
542
579
|
return false;
|
|
543
580
|
}
|
|
544
581
|
|
|
545
|
-
export { blur, change, createFileList, createGlobalFormsObserver, createSubmitEvent, focus, getFormAction, getFormEncType, getFormMethod, isDirtyInput, isFieldElement, isGlobalInstance, isInputElement, isSelectElement, isSubmitter, isTextAreaElement, normalizeFileValues, normalizeStringValues, requestIntent, requestSubmit, updateField };
|
|
582
|
+
export { blur, change, createFileList, createGlobalFormsObserver, createSubmitEvent, focus, getFieldDefaultValue, getFormAction, getFormEncType, getFormMethod, isDirtyInput, isFieldElement, isGlobalInstance, isInputElement, isSelectElement, isSubmitter, isTextAreaElement, normalizeFileValues, normalizeStringValues, requestIntent, requestSubmit, updateField };
|
package/dist/future/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { Serialize, FormValue, FormError, Submission, SubmissionResult, ValidationAttributes, } from '../types';
|
|
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
|
-
export { isFieldElement, isGlobalInstance, updateField, createFileList, createSubmitEvent, createGlobalFormsObserver, focus, change, blur, getFormAction, getFormEncType, getFormMethod, requestSubmit, requestIntent, } from '../dom';
|
|
4
|
+
export { isFieldElement, isGlobalInstance, updateField, createFileList, createSubmitEvent, createGlobalFormsObserver, focus, change, blur, getFieldDefaultValue, getFormAction, getFormEncType, getFormMethod, requestSubmit, requestIntent, } from '../dom';
|
|
5
5
|
export { formatIssues } from '../standard-schema';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/future/index.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.createFileList = dom.createFileList;
|
|
|
29
29
|
exports.createGlobalFormsObserver = dom.createGlobalFormsObserver;
|
|
30
30
|
exports.createSubmitEvent = dom.createSubmitEvent;
|
|
31
31
|
exports.focus = dom.focus;
|
|
32
|
+
exports.getFieldDefaultValue = dom.getFieldDefaultValue;
|
|
32
33
|
exports.getFormAction = dom.getFormAction;
|
|
33
34
|
exports.getFormEncType = dom.getFormEncType;
|
|
34
35
|
exports.getFormMethod = dom.getFormMethod;
|
package/dist/future/index.mjs
CHANGED
|
@@ -1,4 +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
|
-
export { blur, change, createFileList, createGlobalFormsObserver, createSubmitEvent, focus, getFormAction, getFormEncType, getFormMethod, isFieldElement, isGlobalInstance, requestIntent, requestSubmit, updateField } from '../dom.mjs';
|
|
3
|
+
export { blur, change, createFileList, createGlobalFormsObserver, createSubmitEvent, focus, getFieldDefaultValue, getFormAction, getFormEncType, getFormMethod, isFieldElement, isGlobalInstance, requestIntent, requestSubmit, updateField } from '../dom.mjs';
|
|
4
4
|
export { formatIssues } from '../standard-schema.mjs';
|
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.
|
|
6
|
+
"version": "1.13.0",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts",
|