@conform-to/react 0.8.0-pre.1 → 0.8.0-pre.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/helpers.d.ts +4 -0
- package/helpers.js +13 -0
- package/helpers.mjs +13 -1
- package/hooks.d.ts +2 -7
- package/hooks.js +3 -24
- package/hooks.mjs +4 -24
- package/index.d.ts +1 -1
- package/index.js +0 -1
- package/index.mjs +1 -1
- package/package.json +2 -2
package/helpers.d.ts
CHANGED
|
@@ -65,4 +65,8 @@ export declare function input<Schema extends File | File[]>(config: FieldConfig<
|
|
|
65
65
|
export declare function select<Schema extends Primitive | Primitive[] | undefined | unknown>(config: FieldConfig<Schema>, options?: ControlOptions): SelectProps;
|
|
66
66
|
export declare function textarea<Schema extends Primitive | undefined | unknown>(config: FieldConfig<Schema>, options?: ControlOptions): TextareaProps;
|
|
67
67
|
export declare function fieldset<Schema extends Record<string, unknown> | undefined | unknown>(config: FieldConfig<Schema>, options?: BaseOptions): FormControlProps;
|
|
68
|
+
export declare function collection<Schema extends Array<string | boolean> | string | boolean | undefined | unknown>(config: FieldConfig<Schema>, options: BaseOptions & {
|
|
69
|
+
type: 'checkbox' | 'radio';
|
|
70
|
+
options: string[];
|
|
71
|
+
}): Array<InputProps<Schema> & Pick<Required<InputProps<Schema>>, 'type' | 'value'>>;
|
|
68
72
|
export { INTENT, VALIDATION_UNDEFINED, VALIDATION_SKIPPED };
|
package/helpers.js
CHANGED
|
@@ -99,6 +99,18 @@ function textarea(config, options) {
|
|
|
99
99
|
function fieldset(config, options) {
|
|
100
100
|
return getFormElementProps(config, options);
|
|
101
101
|
}
|
|
102
|
+
function collection(config, options) {
|
|
103
|
+
return options.options.map(value => cleanup(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
104
|
+
id: config.id ? "".concat(config.id, "-").concat(value) : undefined,
|
|
105
|
+
type: options.type,
|
|
106
|
+
value,
|
|
107
|
+
defaultChecked: options.type === 'checkbox' && Array.isArray(config.defaultValue) ? config.defaultValue.includes(value) : config.defaultValue === value,
|
|
108
|
+
// The required attribute doesn't make sense for checkbox group
|
|
109
|
+
// As it would require all checkboxes to be checked instead of at least one
|
|
110
|
+
// overriden with `undefiend` so it gets cleaned up
|
|
111
|
+
required: options.type === 'checkbox' ? undefined : config.required
|
|
112
|
+
})));
|
|
113
|
+
}
|
|
102
114
|
|
|
103
115
|
Object.defineProperty(exports, 'INTENT', {
|
|
104
116
|
enumerable: true,
|
|
@@ -112,6 +124,7 @@ Object.defineProperty(exports, 'VALIDATION_UNDEFINED', {
|
|
|
112
124
|
enumerable: true,
|
|
113
125
|
get: function () { return dom.VALIDATION_UNDEFINED; }
|
|
114
126
|
});
|
|
127
|
+
exports.collection = collection;
|
|
115
128
|
exports.fieldset = fieldset;
|
|
116
129
|
exports.hiddenProps = hiddenProps;
|
|
117
130
|
exports.input = input;
|
package/helpers.mjs
CHANGED
|
@@ -95,5 +95,17 @@ function textarea(config, options) {
|
|
|
95
95
|
function fieldset(config, options) {
|
|
96
96
|
return getFormElementProps(config, options);
|
|
97
97
|
}
|
|
98
|
+
function collection(config, options) {
|
|
99
|
+
return options.options.map(value => cleanup(_objectSpread2(_objectSpread2({}, getFormControlProps(config, options)), {}, {
|
|
100
|
+
id: config.id ? "".concat(config.id, "-").concat(value) : undefined,
|
|
101
|
+
type: options.type,
|
|
102
|
+
value,
|
|
103
|
+
defaultChecked: options.type === 'checkbox' && Array.isArray(config.defaultValue) ? config.defaultValue.includes(value) : config.defaultValue === value,
|
|
104
|
+
// The required attribute doesn't make sense for checkbox group
|
|
105
|
+
// As it would require all checkboxes to be checked instead of at least one
|
|
106
|
+
// overriden with `undefiend` so it gets cleaned up
|
|
107
|
+
required: options.type === 'checkbox' ? undefined : config.required
|
|
108
|
+
})));
|
|
109
|
+
}
|
|
98
110
|
|
|
99
|
-
export { fieldset, hiddenProps, input, select, textarea };
|
|
111
|
+
export { collection, fieldset, hiddenProps, input, select, textarea };
|
package/hooks.d.ts
CHANGED
|
@@ -26,11 +26,6 @@ type SubmissionResult = {
|
|
|
26
26
|
payload: Submission['payload'] | null;
|
|
27
27
|
error: Submission['error'];
|
|
28
28
|
};
|
|
29
|
-
interface ReportOptions {
|
|
30
|
-
formError?: string[];
|
|
31
|
-
resetForm?: boolean;
|
|
32
|
-
}
|
|
33
|
-
export declare function report(submission: Submission, options?: ReportOptions): SubmissionResult;
|
|
34
29
|
export interface FormConfig<Output extends Record<string, any>, Input extends Record<string, any> = Output> {
|
|
35
30
|
/**
|
|
36
31
|
* If the form id is provided, Id for label,
|
|
@@ -43,14 +38,14 @@ export interface FormConfig<Output extends Record<string, any>, Input extends Re
|
|
|
43
38
|
ref?: RefObject<HTMLFormElement>;
|
|
44
39
|
/**
|
|
45
40
|
* Define when conform should start validation.
|
|
46
|
-
* Support "onSubmit", "
|
|
41
|
+
* Support "onSubmit", "onInput", "onBlur".
|
|
47
42
|
*
|
|
48
43
|
* @default "onSubmit"
|
|
49
44
|
*/
|
|
50
45
|
shouldValidate?: 'onSubmit' | 'onBlur' | 'onInput';
|
|
51
46
|
/**
|
|
52
47
|
* Define when conform should revalidate again.
|
|
53
|
-
* Support "onSubmit", "
|
|
48
|
+
* Support "onSubmit", "onInput", "onBlur".
|
|
54
49
|
*
|
|
55
50
|
* @default shouldValidate, or "onSubmit" if shouldValidate is not provided.
|
|
56
51
|
*/
|
package/hooks.js
CHANGED
|
@@ -6,17 +6,6 @@ var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js
|
|
|
6
6
|
var dom = require('@conform-to/dom');
|
|
7
7
|
var react = require('react');
|
|
8
8
|
|
|
9
|
-
function report(submission, options) {
|
|
10
|
-
var _submission$error$;
|
|
11
|
-
return {
|
|
12
|
-
intent: submission.intent,
|
|
13
|
-
payload: options !== null && options !== void 0 && options.resetForm ? null : submission.payload,
|
|
14
|
-
error: options !== null && options !== void 0 && options.formError ? _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, submission.error), {}, {
|
|
15
|
-
'': options.formError.concat((_submission$error$ = submission.error['']) !== null && _submission$error$ !== void 0 ? _submission$error$ : [])
|
|
16
|
-
}) : submission.error
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
9
|
/**
|
|
21
10
|
* Properties to be applied to the form element
|
|
22
11
|
*/
|
|
@@ -368,7 +357,7 @@ function useFieldList(ref, config) {
|
|
|
368
357
|
});
|
|
369
358
|
var [entries, setEntries] = react.useState(() => {
|
|
370
359
|
var _config$defaultValue;
|
|
371
|
-
return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : [
|
|
360
|
+
return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : []);
|
|
372
361
|
});
|
|
373
362
|
react.useEffect(() => {
|
|
374
363
|
var conformHandler = event => {
|
|
@@ -423,7 +412,7 @@ function useFieldList(ref, config) {
|
|
|
423
412
|
if (!form || event.target !== form) {
|
|
424
413
|
return;
|
|
425
414
|
}
|
|
426
|
-
setEntries(Object.entries((_configRef$current$de = configRef.current.defaultValue) !== null && _configRef$current$de !== void 0 ? _configRef$current$de : [
|
|
415
|
+
setEntries(Object.entries((_configRef$current$de = configRef.current.defaultValue) !== null && _configRef$current$de !== void 0 ? _configRef$current$de : []));
|
|
427
416
|
};
|
|
428
417
|
|
|
429
418
|
// @ts-expect-error Custom event: conform
|
|
@@ -456,7 +445,7 @@ function useFieldList(ref, config) {
|
|
|
456
445
|
};
|
|
457
446
|
if (config.form) {
|
|
458
447
|
fieldConfig.form = config.form;
|
|
459
|
-
fieldConfig.id = "".concat(config.form, "-").concat(config.name);
|
|
448
|
+
fieldConfig.id = "".concat(config.form, "-").concat(config.name, "-").concat(index);
|
|
460
449
|
fieldConfig.errorId = "".concat(fieldConfig.id, "-error");
|
|
461
450
|
fieldConfig.descriptionId = "".concat(fieldConfig.id, "-description");
|
|
462
451
|
}
|
|
@@ -698,15 +687,6 @@ function reportSubmission(form, submission) {
|
|
|
698
687
|
// As `form.element.namedItem('')` will always returns null
|
|
699
688
|
var elementName = name ? name : FORM_ERROR_ELEMENT_NAME;
|
|
700
689
|
var item = form.elements.namedItem(elementName);
|
|
701
|
-
if (item instanceof RadioNodeList) {
|
|
702
|
-
for (var field of item) {
|
|
703
|
-
if (field.type !== 'radio') {
|
|
704
|
-
// eslint-disable-next-line no-console
|
|
705
|
-
console.warn('Repeated field name is not supported.');
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
690
|
if (item === null) {
|
|
711
691
|
// Create placeholder button to keep the error without contributing to the form data
|
|
712
692
|
var button = document.createElement('button');
|
|
@@ -750,7 +730,6 @@ function getScope(intent) {
|
|
|
750
730
|
exports.FORM_ERROR_ELEMENT_NAME = FORM_ERROR_ELEMENT_NAME;
|
|
751
731
|
exports.getScope = getScope;
|
|
752
732
|
exports.getUniqueKey = getUniqueKey;
|
|
753
|
-
exports.report = report;
|
|
754
733
|
exports.reportSubmission = reportSubmission;
|
|
755
734
|
exports.useFieldList = useFieldList;
|
|
756
735
|
exports.useFieldset = useFieldset;
|
package/hooks.mjs
CHANGED
|
@@ -2,17 +2,6 @@ import { objectSpread2 as _objectSpread2 } from './_virtual/_rollupPluginBabelHe
|
|
|
2
2
|
import { parseIntent, getFormData, parse, VALIDATION_UNDEFINED, VALIDATION_SKIPPED, getFormAction, getFormEncType, getFormMethod, getPaths, getName, isFieldElement, getErrors, getFormControls, getFormElement, updateList, getValidationMessage, focusFirstInvalidControl, isFocusableFormControl, requestIntent, validate } from '@conform-to/dom';
|
|
3
3
|
import { useState, useMemo, useEffect, useRef, useCallback, useLayoutEffect } from 'react';
|
|
4
4
|
|
|
5
|
-
function report(submission, options) {
|
|
6
|
-
var _submission$error$;
|
|
7
|
-
return {
|
|
8
|
-
intent: submission.intent,
|
|
9
|
-
payload: options !== null && options !== void 0 && options.resetForm ? null : submission.payload,
|
|
10
|
-
error: options !== null && options !== void 0 && options.formError ? _objectSpread2(_objectSpread2({}, submission.error), {}, {
|
|
11
|
-
'': options.formError.concat((_submission$error$ = submission.error['']) !== null && _submission$error$ !== void 0 ? _submission$error$ : [])
|
|
12
|
-
}) : submission.error
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
5
|
/**
|
|
17
6
|
* Properties to be applied to the form element
|
|
18
7
|
*/
|
|
@@ -364,7 +353,7 @@ function useFieldList(ref, config) {
|
|
|
364
353
|
});
|
|
365
354
|
var [entries, setEntries] = useState(() => {
|
|
366
355
|
var _config$defaultValue;
|
|
367
|
-
return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : [
|
|
356
|
+
return Object.entries((_config$defaultValue = config.defaultValue) !== null && _config$defaultValue !== void 0 ? _config$defaultValue : []);
|
|
368
357
|
});
|
|
369
358
|
useEffect(() => {
|
|
370
359
|
var conformHandler = event => {
|
|
@@ -419,7 +408,7 @@ function useFieldList(ref, config) {
|
|
|
419
408
|
if (!form || event.target !== form) {
|
|
420
409
|
return;
|
|
421
410
|
}
|
|
422
|
-
setEntries(Object.entries((_configRef$current$de = configRef.current.defaultValue) !== null && _configRef$current$de !== void 0 ? _configRef$current$de : [
|
|
411
|
+
setEntries(Object.entries((_configRef$current$de = configRef.current.defaultValue) !== null && _configRef$current$de !== void 0 ? _configRef$current$de : []));
|
|
423
412
|
};
|
|
424
413
|
|
|
425
414
|
// @ts-expect-error Custom event: conform
|
|
@@ -452,7 +441,7 @@ function useFieldList(ref, config) {
|
|
|
452
441
|
};
|
|
453
442
|
if (config.form) {
|
|
454
443
|
fieldConfig.form = config.form;
|
|
455
|
-
fieldConfig.id = "".concat(config.form, "-").concat(config.name);
|
|
444
|
+
fieldConfig.id = "".concat(config.form, "-").concat(config.name, "-").concat(index);
|
|
456
445
|
fieldConfig.errorId = "".concat(fieldConfig.id, "-error");
|
|
457
446
|
fieldConfig.descriptionId = "".concat(fieldConfig.id, "-description");
|
|
458
447
|
}
|
|
@@ -694,15 +683,6 @@ function reportSubmission(form, submission) {
|
|
|
694
683
|
// As `form.element.namedItem('')` will always returns null
|
|
695
684
|
var elementName = name ? name : FORM_ERROR_ELEMENT_NAME;
|
|
696
685
|
var item = form.elements.namedItem(elementName);
|
|
697
|
-
if (item instanceof RadioNodeList) {
|
|
698
|
-
for (var field of item) {
|
|
699
|
-
if (field.type !== 'radio') {
|
|
700
|
-
// eslint-disable-next-line no-console
|
|
701
|
-
console.warn('Repeated field name is not supported.');
|
|
702
|
-
continue;
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
686
|
if (item === null) {
|
|
707
687
|
// Create placeholder button to keep the error without contributing to the form data
|
|
708
688
|
var button = document.createElement('button');
|
|
@@ -743,4 +723,4 @@ function getScope(intent) {
|
|
|
743
723
|
return null;
|
|
744
724
|
}
|
|
745
725
|
|
|
746
|
-
export { FORM_ERROR_ELEMENT_NAME, getScope, getUniqueKey,
|
|
726
|
+
export { FORM_ERROR_ELEMENT_NAME, getScope, getUniqueKey, reportSubmission, useFieldList, useFieldset, useForm, useInputEvent, validateConstraint };
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { type FieldsetConstraint, type Submission, parse, list, validate, requestIntent, isFieldElement, } from '@conform-to/dom';
|
|
2
|
-
export { type Fieldset, type FieldConfig, type FieldsetConfig, type FormConfig, useForm, useFieldset, useFieldList, useInputEvent, validateConstraint,
|
|
2
|
+
export { type Fieldset, type FieldConfig, type FieldsetConfig, type FormConfig, useForm, useFieldset, useFieldList, useInputEvent, validateConstraint, } from './hooks.js';
|
|
3
3
|
export * as conform from './helpers.js';
|
package/index.js
CHANGED
|
@@ -28,7 +28,6 @@ Object.defineProperty(exports, 'validate', {
|
|
|
28
28
|
enumerable: true,
|
|
29
29
|
get: function () { return dom.validate; }
|
|
30
30
|
});
|
|
31
|
-
exports.report = hooks.report;
|
|
32
31
|
exports.useFieldList = hooks.useFieldList;
|
|
33
32
|
exports.useFieldset = hooks.useFieldset;
|
|
34
33
|
exports.useForm = hooks.useForm;
|
package/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { isFieldElement, list, parse, requestIntent, validate } from '@conform-to/dom';
|
|
2
|
-
export {
|
|
2
|
+
export { useFieldList, useFieldset, useForm, useInputEvent, validateConstraint } from './hooks.mjs';
|
|
3
3
|
import * as helpers from './helpers.mjs';
|
|
4
4
|
export { helpers as conform };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Conform view adapter for react",
|
|
4
4
|
"homepage": "https://conform.guide",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.8.0-pre.
|
|
6
|
+
"version": "0.8.0-pre.2",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"module": "index.mjs",
|
|
9
9
|
"types": "index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/edmundhung/conform/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@conform-to/dom": "0.8.0-pre.
|
|
33
|
+
"@conform-to/dom": "0.8.0-pre.2"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=16.8"
|