@conform-to/dom 1.6.0 → 1.7.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 +65 -0
- package/dist/dom.js +453 -0
- package/dist/dom.mjs +435 -0
- package/{form.d.ts → dist/form.d.ts} +1 -10
- package/{form.js → dist/form.js} +5 -98
- package/{form.mjs → dist/form.mjs} +7 -99
- package/{formdata.d.ts → dist/formdata.d.ts} +2 -0
- package/{formdata.js → dist/formdata.js} +36 -0
- package/{formdata.mjs → dist/formdata.mjs} +36 -1
- package/dist/index.d.ts +5 -0
- package/{index.js → dist/index.js} +7 -1
- package/dist/index.mjs +4 -0
- package/{submission.d.ts → dist/submission.d.ts} +1 -0
- package/{util.d.ts → dist/util.d.ts} +1 -0
- package/dist/vitest.config.d.ts +3 -0
- package/package.json +16 -11
- package/dom.d.ts +0 -43
- package/dom.js +0 -104
- package/dom.mjs +0 -95
- package/index.d.ts +0 -4
- package/index.mjs +0 -4
- /package/{_virtual → dist/_virtual}/_rollupPluginBabelHelpers.js +0 -0
- /package/{_virtual → dist/_virtual}/_rollupPluginBabelHelpers.mjs +0 -0
- /package/{submission.js → dist/submission.js} +0 -0
- /package/{submission.mjs → dist/submission.mjs} +0 -0
- /package/{util.js → dist/util.js} +0 -0
- /package/{util.mjs → dist/util.mjs} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
2
|
import { flatten, formatName, getValue, isPlainObject, isPrefix, setValue, normalize, getFormData, getPaths, getChildPaths, formatPaths } from './formdata.mjs';
|
|
3
|
-
import { getFormAction, getFormEncType, getFormMethod, isFieldElement, requestSubmit } from './dom.mjs';
|
|
3
|
+
import { getFormAction, getFormEncType, getFormMethod, isFieldElement, requestSubmit, updateField } from './dom.mjs';
|
|
4
4
|
import { generateId, clone, invariant } from './util.mjs';
|
|
5
5
|
import { serialize, setListState, setListValue, setState, INTENT, serializeIntent, root, getSubmissionContext } from './submission.mjs';
|
|
6
6
|
|
|
@@ -578,8 +578,8 @@ function createFormContext(options) {
|
|
|
578
578
|
var paths = getChildPaths(parentPaths, element.name);
|
|
579
579
|
if (paths) {
|
|
580
580
|
var value = getValue(intent.payload.value, formatPaths(paths));
|
|
581
|
-
|
|
582
|
-
value: typeof value === 'string' || Array.isArray(value) && value.every(item => typeof item === 'string') ? value :
|
|
581
|
+
updateField(element, {
|
|
582
|
+
value: typeof value === 'string' || Array.isArray(value) && value.every(item => typeof item === 'string') ? value : null
|
|
583
583
|
});
|
|
584
584
|
|
|
585
585
|
// Update the element attribute to notify useControl / useInputControl hook
|
|
@@ -593,10 +593,10 @@ function createFormContext(options) {
|
|
|
593
593
|
{
|
|
594
594
|
var prefix = formatName(intent.payload.name, intent.payload.index);
|
|
595
595
|
for (var _element of formElement.elements) {
|
|
596
|
-
if (isFieldElement(_element) && isPrefix(_element.name, prefix)) {
|
|
596
|
+
if (isFieldElement(_element) && _element.name && isPrefix(_element.name, prefix)) {
|
|
597
597
|
var _value2 = getValue(meta.defaultValue, _element.name);
|
|
598
|
-
var defaultValue = typeof _value2 === 'string' || Array.isArray(_value2) && _value2.every(item => typeof item === 'string') ? _value2 :
|
|
599
|
-
|
|
598
|
+
var defaultValue = typeof _value2 === 'string' || Array.isArray(_value2) && _value2.every(item => typeof item === 'string') ? _value2 : null;
|
|
599
|
+
updateField(_element, {
|
|
600
600
|
defaultValue,
|
|
601
601
|
value: defaultValue
|
|
602
602
|
});
|
|
@@ -634,96 +634,4 @@ function createFormContext(options) {
|
|
|
634
634
|
};
|
|
635
635
|
}
|
|
636
636
|
|
|
637
|
-
|
|
638
|
-
* Updates the DOM element with the provided value.
|
|
639
|
-
*
|
|
640
|
-
* @param element The form element to update
|
|
641
|
-
* @param options The options to update the form element
|
|
642
|
-
*/
|
|
643
|
-
function updateFieldValue(element, options) {
|
|
644
|
-
var value = typeof options.value === 'undefined' ? null : Array.isArray(options.value) ? Array.from(options.value) : [options.value];
|
|
645
|
-
var defaultValue = typeof options.defaultValue === 'undefined' ? null : Array.isArray(options.defaultValue) ? Array.from(options.defaultValue) : [options.defaultValue];
|
|
646
|
-
if (element instanceof HTMLInputElement && (element.type === 'checkbox' || element.type === 'radio')) {
|
|
647
|
-
if (value) {
|
|
648
|
-
element.checked = value.includes(element.value);
|
|
649
|
-
}
|
|
650
|
-
if (defaultValue) {
|
|
651
|
-
element.defaultChecked = defaultValue.includes(element.value);
|
|
652
|
-
}
|
|
653
|
-
} else if (element instanceof HTMLSelectElement) {
|
|
654
|
-
// If the select element is not multiple and the value is an empty array, unset the selected index
|
|
655
|
-
// This is to prevent the select element from showing the first option as selected
|
|
656
|
-
if (value && value.length === 0 && !element.multiple) {
|
|
657
|
-
element.selectedIndex = -1;
|
|
658
|
-
}
|
|
659
|
-
for (var option of element.options) {
|
|
660
|
-
if (value) {
|
|
661
|
-
var index = value.indexOf(option.value);
|
|
662
|
-
var selected = index > -1;
|
|
663
|
-
|
|
664
|
-
// Update the selected state of the option
|
|
665
|
-
if (option.selected !== selected) {
|
|
666
|
-
option.selected = selected;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// Remove the option from the value array
|
|
670
|
-
if (selected) {
|
|
671
|
-
value.splice(index, 1);
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
if (defaultValue) {
|
|
675
|
-
var _index = defaultValue.indexOf(option.value);
|
|
676
|
-
var _selected = _index > -1;
|
|
677
|
-
|
|
678
|
-
// Update the selected state of the option
|
|
679
|
-
if (option.selected !== _selected) {
|
|
680
|
-
option.defaultSelected = _selected;
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
// Remove the option from the defaultValue array
|
|
684
|
-
if (_selected) {
|
|
685
|
-
defaultValue.splice(_index, 1);
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
// We have already removed all selected options from the value and defaultValue array at this point
|
|
691
|
-
var missingOptions = new Set([...(value !== null && value !== void 0 ? value : []), ...(defaultValue !== null && defaultValue !== void 0 ? defaultValue : [])]);
|
|
692
|
-
for (var optionValue of missingOptions) {
|
|
693
|
-
element.options.add(new Option(optionValue, optionValue, defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.includes(optionValue), value === null || value === void 0 ? void 0 : value.includes(optionValue)));
|
|
694
|
-
}
|
|
695
|
-
} else {
|
|
696
|
-
if (value) {
|
|
697
|
-
var _value$;
|
|
698
|
-
/**
|
|
699
|
-
* Triggering react custom change event
|
|
700
|
-
* Solution based on dom-testing-library
|
|
701
|
-
* @see https://github.com/facebook/react/issues/10135#issuecomment-401496776
|
|
702
|
-
* @see https://github.com/testing-library/dom-testing-library/blob/main/src/events.js#L104-L123
|
|
703
|
-
*/
|
|
704
|
-
var inputValue = (_value$ = value[0]) !== null && _value$ !== void 0 ? _value$ : '';
|
|
705
|
-
var {
|
|
706
|
-
set: valueSetter
|
|
707
|
-
} = Object.getOwnPropertyDescriptor(element, 'value') || {};
|
|
708
|
-
var prototype = Object.getPrototypeOf(element);
|
|
709
|
-
var {
|
|
710
|
-
set: prototypeValueSetter
|
|
711
|
-
} = Object.getOwnPropertyDescriptor(prototype, 'value') || {};
|
|
712
|
-
if (prototypeValueSetter && valueSetter !== prototypeValueSetter) {
|
|
713
|
-
prototypeValueSetter.call(element, inputValue);
|
|
714
|
-
} else {
|
|
715
|
-
if (valueSetter) {
|
|
716
|
-
valueSetter.call(element, inputValue);
|
|
717
|
-
} else {
|
|
718
|
-
throw new Error('The given element does not have a value setter');
|
|
719
|
-
}
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
if (defaultValue) {
|
|
723
|
-
var _defaultValue$;
|
|
724
|
-
element.defaultValue = (_defaultValue$ = defaultValue[0]) !== null && _defaultValue$ !== void 0 ? _defaultValue$ : '';
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
export { createFormContext, updateFieldValue };
|
|
637
|
+
export { createFormContext };
|
|
@@ -64,3 +64,5 @@ export declare function flatten(data: unknown, options?: {
|
|
|
64
64
|
resolve?: (data: unknown) => unknown;
|
|
65
65
|
prefix?: string;
|
|
66
66
|
}): Record<string, unknown>;
|
|
67
|
+
export declare function deepEqual<Value>(prev: Value, next: Value): boolean;
|
|
68
|
+
//# sourceMappingURL=formdata.d.ts.map
|
|
@@ -213,7 +213,43 @@ function flatten(data) {
|
|
|
213
213
|
}
|
|
214
214
|
return result;
|
|
215
215
|
}
|
|
216
|
+
function deepEqual(prev, next) {
|
|
217
|
+
if (prev === next) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
if (!prev || !next) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
if (Array.isArray(prev) && Array.isArray(next)) {
|
|
224
|
+
if (prev.length !== next.length) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
for (var i = 0; i < prev.length; i++) {
|
|
228
|
+
if (!deepEqual(prev[i], next[i])) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
if (isPlainObject(prev) && isPlainObject(next)) {
|
|
235
|
+
var prevKeys = Object.keys(prev);
|
|
236
|
+
var nextKeys = Object.keys(next);
|
|
237
|
+
if (prevKeys.length !== nextKeys.length) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
for (var key of prevKeys) {
|
|
241
|
+
if (!Object.prototype.hasOwnProperty.call(next, key) ||
|
|
242
|
+
// @ts-expect-error FIXME
|
|
243
|
+
!deepEqual(prev[key], next[key])) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return true;
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
216
251
|
|
|
252
|
+
exports.deepEqual = deepEqual;
|
|
217
253
|
exports.flatten = flatten;
|
|
218
254
|
exports.formatName = formatName;
|
|
219
255
|
exports.formatPaths = formatPaths;
|
|
@@ -209,5 +209,40 @@ function flatten(data) {
|
|
|
209
209
|
}
|
|
210
210
|
return result;
|
|
211
211
|
}
|
|
212
|
+
function deepEqual(prev, next) {
|
|
213
|
+
if (prev === next) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
if (!prev || !next) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
if (Array.isArray(prev) && Array.isArray(next)) {
|
|
220
|
+
if (prev.length !== next.length) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
for (var i = 0; i < prev.length; i++) {
|
|
224
|
+
if (!deepEqual(prev[i], next[i])) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
if (isPlainObject(prev) && isPlainObject(next)) {
|
|
231
|
+
var prevKeys = Object.keys(prev);
|
|
232
|
+
var nextKeys = Object.keys(next);
|
|
233
|
+
if (prevKeys.length !== nextKeys.length) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
for (var key of prevKeys) {
|
|
237
|
+
if (!Object.prototype.hasOwnProperty.call(next, key) ||
|
|
238
|
+
// @ts-expect-error FIXME
|
|
239
|
+
!deepEqual(prev[key], next[key])) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
212
247
|
|
|
213
|
-
export { flatten, formatName, formatPaths, getChildPaths, getFormData, getPaths, getValue, isFile, isPlainObject, isPrefix, normalize, setValue };
|
|
248
|
+
export { deepEqual, flatten, formatName, formatPaths, getChildPaths, getFormData, getPaths, getValue, isFile, isPlainObject, isPrefix, normalize, setValue };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, } from './form';
|
|
2
|
+
export { type FieldElement, isFieldElement, updateField as unstable_updateField, createFileList, createGlobalFormsObserver as unstable_createGlobalFormsObserver, focus as unstable_focus, change as unstable_change, blur as unstable_blur, } from './dom';
|
|
3
|
+
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
|
|
4
|
+
export { getPaths, formatPaths, isPrefix, deepEqual as unstable_deepEqual, } from './formdata';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -10,8 +10,13 @@ var formdata = require('./formdata.js');
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
exports.unstable_createFormContext = form.createFormContext;
|
|
13
|
-
exports.
|
|
13
|
+
exports.createFileList = dom.createFileList;
|
|
14
14
|
exports.isFieldElement = dom.isFieldElement;
|
|
15
|
+
exports.unstable_blur = dom.blur;
|
|
16
|
+
exports.unstable_change = dom.change;
|
|
17
|
+
exports.unstable_createGlobalFormsObserver = dom.createGlobalFormsObserver;
|
|
18
|
+
exports.unstable_focus = dom.focus;
|
|
19
|
+
exports.unstable_updateField = dom.updateField;
|
|
15
20
|
exports.INTENT = submission.INTENT;
|
|
16
21
|
exports.STATE = submission.STATE;
|
|
17
22
|
exports.parse = submission.parse;
|
|
@@ -19,3 +24,4 @@ exports.serializeIntent = submission.serializeIntent;
|
|
|
19
24
|
exports.formatPaths = formdata.formatPaths;
|
|
20
25
|
exports.getPaths = formdata.getPaths;
|
|
21
26
|
exports.isPrefix = formdata.isPrefix;
|
|
27
|
+
exports.unstable_deepEqual = formdata.deepEqual;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createFormContext as unstable_createFormContext } from './form.mjs';
|
|
2
|
+
export { createFileList, isFieldElement, blur as unstable_blur, change as unstable_change, createGlobalFormsObserver as unstable_createGlobalFormsObserver, focus as unstable_focus, updateField as unstable_updateField } from './dom.mjs';
|
|
3
|
+
export { INTENT, STATE, parse, serializeIntent } from './submission.mjs';
|
|
4
|
+
export { formatPaths, getPaths, isPrefix, deepEqual as unstable_deepEqual } from './formdata.mjs';
|
|
@@ -136,3 +136,4 @@ export declare const root: unique symbol;
|
|
|
136
136
|
export declare function setState(state: Record<string, unknown>, name: string, valueFn: (value: unknown) => unknown): void;
|
|
137
137
|
export declare function setListState(state: Record<string, unknown>, intent: InsertIntent | RemoveIntent | ReorderIntent, getDefaultValue?: (defaultValue: any) => any): void;
|
|
138
138
|
export declare function serialize<Schema>(defaultValue: Schema): FormValue<Schema>;
|
|
139
|
+
//# sourceMappingURL=submission.d.ts.map
|
package/package.json
CHANGED
|
@@ -3,19 +3,23 @@
|
|
|
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.
|
|
7
|
-
"main": "index.js",
|
|
8
|
-
"module": "index.mjs",
|
|
9
|
-
"types": "index.d.ts",
|
|
6
|
+
"version": "1.7.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"types": "./index.d.ts",
|
|
13
|
-
"module": "./index.mjs",
|
|
14
|
-
"import": "./index.mjs",
|
|
15
|
-
"require": "./index.js",
|
|
16
|
-
"default": "./index.mjs"
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"module": "./dist/index.mjs",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"./dist/**/*.{js,mjs}",
|
|
21
|
+
"./dist/**/*.d.ts"
|
|
22
|
+
],
|
|
19
23
|
"repository": {
|
|
20
24
|
"type": "git",
|
|
21
25
|
"url": "https://github.com/edmundhung/conform",
|
|
@@ -50,10 +54,11 @@
|
|
|
50
54
|
},
|
|
51
55
|
"scripts": {
|
|
52
56
|
"build:js": "rollup -c",
|
|
53
|
-
"build:ts": "tsc",
|
|
57
|
+
"build:ts": "tsc --project ./tsconfig.build.json",
|
|
54
58
|
"build": "pnpm run \"/^build:.*/\"",
|
|
55
59
|
"dev:js": "pnpm run build:js --watch",
|
|
56
60
|
"dev:ts": "pnpm run build:ts --watch",
|
|
57
|
-
"dev": "pnpm run \"/^dev:.*/\""
|
|
61
|
+
"dev": "pnpm run \"/^dev:.*/\"",
|
|
62
|
+
"typecheck": "tsc"
|
|
58
63
|
}
|
|
59
64
|
}
|
package/dom.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Element that user can interact with,
|
|
3
|
-
* includes `<input>`, `<select>` and `<textarea>`.
|
|
4
|
-
*/
|
|
5
|
-
export type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
6
|
-
/**
|
|
7
|
-
* HTML Element that can be used as a form control,
|
|
8
|
-
* includes `<input>`, `<select>`, `<textarea>` and `<button>`.
|
|
9
|
-
*/
|
|
10
|
-
export type FormControl = FieldElement | HTMLButtonElement;
|
|
11
|
-
/**
|
|
12
|
-
* Form Control element. It can either be a submit button or a submit input.
|
|
13
|
-
*/
|
|
14
|
-
export type Submitter = HTMLInputElement | HTMLButtonElement;
|
|
15
|
-
/**
|
|
16
|
-
* A type guard to check if the provided element is a form control
|
|
17
|
-
*/
|
|
18
|
-
export declare function isFormControl(element: unknown): element is FormControl;
|
|
19
|
-
/**
|
|
20
|
-
* A type guard to check if the provided element is a field element, which
|
|
21
|
-
* is a form control excluding submit, button and reset type.
|
|
22
|
-
*/
|
|
23
|
-
export declare function isFieldElement(element: unknown): element is FieldElement;
|
|
24
|
-
/**
|
|
25
|
-
* Resolves the action from the submit event
|
|
26
|
-
* with respect to the submitter `formaction` attribute.
|
|
27
|
-
*/
|
|
28
|
-
export declare function getFormAction(event: SubmitEvent): string;
|
|
29
|
-
/**
|
|
30
|
-
* Resolves the encoding type from the submit event
|
|
31
|
-
* with respect to the submitter `formenctype` attribute.
|
|
32
|
-
*/
|
|
33
|
-
export declare function getFormEncType(event: SubmitEvent): 'application/x-www-form-urlencoded' | 'multipart/form-data';
|
|
34
|
-
/**
|
|
35
|
-
* Resolves the method from the submit event
|
|
36
|
-
* with respect to the submitter `formmethod` attribute.
|
|
37
|
-
*/
|
|
38
|
-
export declare function getFormMethod(event: SubmitEvent): 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
39
|
-
/**
|
|
40
|
-
* Trigger a form submit event with an optional submitter.
|
|
41
|
-
* If the submitter is not mounted, it will be appended to the form and removed after submission.
|
|
42
|
-
*/
|
|
43
|
-
export declare function requestSubmit(form: HTMLFormElement | null | undefined, submitter: Submitter | null): void;
|
package/dom.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var util = require('./util.js');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Element that user can interact with,
|
|
9
|
-
* includes `<input>`, `<select>` and `<textarea>`.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* HTML Element that can be used as a form control,
|
|
14
|
-
* includes `<input>`, `<select>`, `<textarea>` and `<button>`.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Form Control element. It can either be a submit button or a submit input.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A type guard to check if the provided element is a form control
|
|
23
|
-
*/
|
|
24
|
-
function isFormControl(element) {
|
|
25
|
-
return element instanceof Element && (element.tagName === 'INPUT' || element.tagName === 'SELECT' || element.tagName === 'TEXTAREA' || element.tagName === 'BUTTON');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A type guard to check if the provided element is a field element, which
|
|
30
|
-
* is a form control excluding submit, button and reset type.
|
|
31
|
-
*/
|
|
32
|
-
function isFieldElement(element) {
|
|
33
|
-
return isFormControl(element) && element.type !== 'submit' && element.type !== 'button' && element.type !== 'reset';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Resolves the action from the submit event
|
|
38
|
-
* with respect to the submitter `formaction` attribute.
|
|
39
|
-
*/
|
|
40
|
-
function getFormAction(event) {
|
|
41
|
-
var _ref, _submitter$getAttribu;
|
|
42
|
-
var form = event.target;
|
|
43
|
-
var submitter = event.submitter;
|
|
44
|
-
return (_ref = (_submitter$getAttribu = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formaction')) !== null && _submitter$getAttribu !== void 0 ? _submitter$getAttribu : form.getAttribute('action')) !== null && _ref !== void 0 ? _ref : "".concat(location.pathname).concat(location.search);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Resolves the encoding type from the submit event
|
|
49
|
-
* with respect to the submitter `formenctype` attribute.
|
|
50
|
-
*/
|
|
51
|
-
function getFormEncType(event) {
|
|
52
|
-
var _submitter$getAttribu2;
|
|
53
|
-
var form = event.target;
|
|
54
|
-
var submitter = event.submitter;
|
|
55
|
-
var encType = (_submitter$getAttribu2 = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formenctype')) !== null && _submitter$getAttribu2 !== void 0 ? _submitter$getAttribu2 : form.enctype;
|
|
56
|
-
if (encType === 'multipart/form-data') {
|
|
57
|
-
return encType;
|
|
58
|
-
}
|
|
59
|
-
return 'application/x-www-form-urlencoded';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Resolves the method from the submit event
|
|
64
|
-
* with respect to the submitter `formmethod` attribute.
|
|
65
|
-
*/
|
|
66
|
-
function getFormMethod(event) {
|
|
67
|
-
var _ref2, _submitter$getAttribu3;
|
|
68
|
-
var form = event.target;
|
|
69
|
-
var submitter = event.submitter;
|
|
70
|
-
var method = (_ref2 = (_submitter$getAttribu3 = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formmethod')) !== null && _submitter$getAttribu3 !== void 0 ? _submitter$getAttribu3 : form.getAttribute('method')) === null || _ref2 === void 0 ? void 0 : _ref2.toUpperCase();
|
|
71
|
-
switch (method) {
|
|
72
|
-
case 'POST':
|
|
73
|
-
case 'PUT':
|
|
74
|
-
case 'PATCH':
|
|
75
|
-
case 'DELETE':
|
|
76
|
-
return method;
|
|
77
|
-
}
|
|
78
|
-
return 'GET';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Trigger a form submit event with an optional submitter.
|
|
83
|
-
* If the submitter is not mounted, it will be appended to the form and removed after submission.
|
|
84
|
-
*/
|
|
85
|
-
function requestSubmit(form, submitter) {
|
|
86
|
-
util.invariant(!!form, 'Failed to submit the form. The element provided is null or undefined.');
|
|
87
|
-
if (typeof form.requestSubmit === 'function') {
|
|
88
|
-
form.requestSubmit(submitter);
|
|
89
|
-
} else {
|
|
90
|
-
var event = new SubmitEvent('submit', {
|
|
91
|
-
bubbles: true,
|
|
92
|
-
cancelable: true,
|
|
93
|
-
submitter
|
|
94
|
-
});
|
|
95
|
-
form.dispatchEvent(event);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
exports.getFormAction = getFormAction;
|
|
100
|
-
exports.getFormEncType = getFormEncType;
|
|
101
|
-
exports.getFormMethod = getFormMethod;
|
|
102
|
-
exports.isFieldElement = isFieldElement;
|
|
103
|
-
exports.isFormControl = isFormControl;
|
|
104
|
-
exports.requestSubmit = requestSubmit;
|
package/dom.mjs
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { invariant } from './util.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Element that user can interact with,
|
|
5
|
-
* includes `<input>`, `<select>` and `<textarea>`.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* HTML Element that can be used as a form control,
|
|
10
|
-
* includes `<input>`, `<select>`, `<textarea>` and `<button>`.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Form Control element. It can either be a submit button or a submit input.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A type guard to check if the provided element is a form control
|
|
19
|
-
*/
|
|
20
|
-
function isFormControl(element) {
|
|
21
|
-
return element instanceof Element && (element.tagName === 'INPUT' || element.tagName === 'SELECT' || element.tagName === 'TEXTAREA' || element.tagName === 'BUTTON');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* A type guard to check if the provided element is a field element, which
|
|
26
|
-
* is a form control excluding submit, button and reset type.
|
|
27
|
-
*/
|
|
28
|
-
function isFieldElement(element) {
|
|
29
|
-
return isFormControl(element) && element.type !== 'submit' && element.type !== 'button' && element.type !== 'reset';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolves the action from the submit event
|
|
34
|
-
* with respect to the submitter `formaction` attribute.
|
|
35
|
-
*/
|
|
36
|
-
function getFormAction(event) {
|
|
37
|
-
var _ref, _submitter$getAttribu;
|
|
38
|
-
var form = event.target;
|
|
39
|
-
var submitter = event.submitter;
|
|
40
|
-
return (_ref = (_submitter$getAttribu = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formaction')) !== null && _submitter$getAttribu !== void 0 ? _submitter$getAttribu : form.getAttribute('action')) !== null && _ref !== void 0 ? _ref : "".concat(location.pathname).concat(location.search);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Resolves the encoding type from the submit event
|
|
45
|
-
* with respect to the submitter `formenctype` attribute.
|
|
46
|
-
*/
|
|
47
|
-
function getFormEncType(event) {
|
|
48
|
-
var _submitter$getAttribu2;
|
|
49
|
-
var form = event.target;
|
|
50
|
-
var submitter = event.submitter;
|
|
51
|
-
var encType = (_submitter$getAttribu2 = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formenctype')) !== null && _submitter$getAttribu2 !== void 0 ? _submitter$getAttribu2 : form.enctype;
|
|
52
|
-
if (encType === 'multipart/form-data') {
|
|
53
|
-
return encType;
|
|
54
|
-
}
|
|
55
|
-
return 'application/x-www-form-urlencoded';
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Resolves the method from the submit event
|
|
60
|
-
* with respect to the submitter `formmethod` attribute.
|
|
61
|
-
*/
|
|
62
|
-
function getFormMethod(event) {
|
|
63
|
-
var _ref2, _submitter$getAttribu3;
|
|
64
|
-
var form = event.target;
|
|
65
|
-
var submitter = event.submitter;
|
|
66
|
-
var method = (_ref2 = (_submitter$getAttribu3 = submitter === null || submitter === void 0 ? void 0 : submitter.getAttribute('formmethod')) !== null && _submitter$getAttribu3 !== void 0 ? _submitter$getAttribu3 : form.getAttribute('method')) === null || _ref2 === void 0 ? void 0 : _ref2.toUpperCase();
|
|
67
|
-
switch (method) {
|
|
68
|
-
case 'POST':
|
|
69
|
-
case 'PUT':
|
|
70
|
-
case 'PATCH':
|
|
71
|
-
case 'DELETE':
|
|
72
|
-
return method;
|
|
73
|
-
}
|
|
74
|
-
return 'GET';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Trigger a form submit event with an optional submitter.
|
|
79
|
-
* If the submitter is not mounted, it will be appended to the form and removed after submission.
|
|
80
|
-
*/
|
|
81
|
-
function requestSubmit(form, submitter) {
|
|
82
|
-
invariant(!!form, 'Failed to submit the form. The element provided is null or undefined.');
|
|
83
|
-
if (typeof form.requestSubmit === 'function') {
|
|
84
|
-
form.requestSubmit(submitter);
|
|
85
|
-
} else {
|
|
86
|
-
var event = new SubmitEvent('submit', {
|
|
87
|
-
bubbles: true,
|
|
88
|
-
cancelable: true,
|
|
89
|
-
submitter
|
|
90
|
-
});
|
|
91
|
-
form.dispatchEvent(event);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export { getFormAction, getFormEncType, getFormMethod, isFieldElement, isFormControl, requestSubmit };
|
package/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { type Combine, type Constraint, type ControlButtonProps, type FormId, type FieldName, type DefaultValue, type FormValue, type FormOptions, type FormState, type FormContext, type SubscriptionSubject, type SubscriptionScope, createFormContext as unstable_createFormContext, updateFieldValue as unstable_updateFieldValue, } from './form';
|
|
2
|
-
export { type FieldElement, isFieldElement } from './dom';
|
|
3
|
-
export { type Submission, type SubmissionResult, type Intent, INTENT, STATE, serializeIntent, parse, } from './submission';
|
|
4
|
-
export { getPaths, formatPaths, isPrefix } from './formdata';
|
package/index.mjs
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { createFormContext as unstable_createFormContext, updateFieldValue as unstable_updateFieldValue } from './form.mjs';
|
|
2
|
-
export { isFieldElement } from './dom.mjs';
|
|
3
|
-
export { INTENT, STATE, parse, serializeIntent } from './submission.mjs';
|
|
4
|
-
export { formatPaths, getPaths, isPrefix } from './formdata.mjs';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|