@conform-to/react 1.7.0 → 1.7.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 CHANGED
@@ -7,7 +7,7 @@
7
7
  ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
8
8
  ```
9
9
 
10
- Version 1.7.0 / License MIT / Copyright (c) 2024 Edmund Hung
10
+ Version 1.7.2 / License MIT / Copyright (c) 2024 Edmund Hung
11
11
 
12
12
  A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
13
13
 
@@ -103,24 +103,25 @@ function getDefaultSnapshot(defaultValue, defaultChecked, value) {
103
103
  value: defaultValue
104
104
  };
105
105
  }
106
- if (Array.isArray(defaultValue) && defaultValue.every(item => typeof item === 'string')) {
107
- return {
108
- options: defaultValue
109
- };
110
- }
111
- if (defaultValue instanceof FileList) {
112
- return {
113
- files: Array.from(defaultValue)
114
- };
115
- }
116
106
  if (Array.isArray(defaultValue)) {
107
+ if (defaultValue.every(item => typeof item === 'string')) {
108
+ return {
109
+ options: defaultValue
110
+ };
111
+ } else {
112
+ return {
113
+ files: defaultValue
114
+ };
115
+ }
116
+ }
117
+ if (dom.isGlobalInstance(defaultValue, 'File')) {
117
118
  return {
118
- files: defaultValue
119
+ files: [defaultValue]
119
120
  };
120
121
  }
121
- if (defaultValue) {
122
+ if (dom.isGlobalInstance(defaultValue, 'FileList')) {
122
123
  return {
123
- files: [defaultValue]
124
+ files: Array.from(defaultValue)
124
125
  };
125
126
  }
126
127
  return {};
@@ -1,4 +1,4 @@
1
- import { unstable_updateField } from '@conform-to/dom';
1
+ import { unstable_updateField, isGlobalInstance } from '@conform-to/dom';
2
2
 
3
3
  function focusable(element) {
4
4
  if (!element.hidden && element.type !== 'hidden') {
@@ -99,24 +99,25 @@ function getDefaultSnapshot(defaultValue, defaultChecked, value) {
99
99
  value: defaultValue
100
100
  };
101
101
  }
102
- if (Array.isArray(defaultValue) && defaultValue.every(item => typeof item === 'string')) {
103
- return {
104
- options: defaultValue
105
- };
106
- }
107
- if (defaultValue instanceof FileList) {
108
- return {
109
- files: Array.from(defaultValue)
110
- };
111
- }
112
102
  if (Array.isArray(defaultValue)) {
103
+ if (defaultValue.every(item => typeof item === 'string')) {
104
+ return {
105
+ options: defaultValue
106
+ };
107
+ } else {
108
+ return {
109
+ files: defaultValue
110
+ };
111
+ }
112
+ }
113
+ if (isGlobalInstance(defaultValue, 'File')) {
113
114
  return {
114
- files: defaultValue
115
+ files: [defaultValue]
115
116
  };
116
117
  }
117
- if (defaultValue) {
118
+ if (isGlobalInstance(defaultValue, 'FileList')) {
118
119
  return {
119
- files: [defaultValue]
120
+ files: Array.from(defaultValue)
120
121
  };
121
122
  }
122
123
  return {};
package/dist/helpers.d.ts CHANGED
@@ -14,7 +14,7 @@ type FormControlOptions = {
14
14
  */
15
15
  ariaAttributes?: true;
16
16
  /**
17
- * Decide whether the aria-invalid attributes should be based on `meta.errors` or `meta.allErrors`.
17
+ * Decide whether the `aria-invalid` and `aria-describedby` attributes should be based on `meta.errors` or `meta.allErrors`.
18
18
  * @default 'errors'
19
19
  */
20
20
  ariaInvalid?: 'errors' | 'allErrors';
@@ -76,13 +76,13 @@ type TextareaOptions = Pretty<FormControlOptions & {
76
76
  /**
77
77
  * Derives aria attributes of a form control based on the field metadata.
78
78
  */
79
- export declare function getAriaAttributes(metadata: Metadata<any, any, any>, options?: FormControlOptions): {
79
+ export declare function getAriaAttributes(metadata: Metadata<any, any, any>, options?: FormControlOptions, field?: boolean): {
80
80
  'aria-invalid'?: boolean;
81
81
  'aria-describedby'?: string;
82
82
  };
83
83
  /**
84
84
  * Derives the properties of a form element based on the form metadata,
85
- * including `id`, `onSubmit`, `noValidate`, `aria-invalid` and `aria-describedby`.
85
+ * including `id`, `onSubmit`, `noValidate`, and `aria-describedby`.
86
86
  *
87
87
  * @example
88
88
  * ```tsx
@@ -98,14 +98,14 @@ export declare function getFormProps<Schema extends Record<string, any>, FormErr
98
98
  };
99
99
  /**
100
100
  * Derives the properties of a fieldset element based on the field metadata,
101
- * including `id`, `name`, `form`, `aria-invalid` and `aria-describedby`.
101
+ * including `id`, `name`, `form`, and `aria-describedby`.
102
102
  *
103
103
  * @example
104
104
  * ```tsx
105
105
  * <fieldset {...getFieldsetProps(metadata)} />
106
106
  * ```
107
107
  */
108
- export declare function getFieldsetProps<Schema extends Record<string, any> | undefined | unknown>(metadata: FieldMetadata<Schema, any, any>, options?: FormControlOptions): {
108
+ export declare function getFieldsetProps<Schema extends Record<string, any> | undefined | unknown>(metadata: FieldMetadata<Schema, any, any>, options?: FormControlOptions, field?: boolean): {
109
109
  'aria-invalid'?: boolean;
110
110
  'aria-describedby'?: string;
111
111
  id: string;
package/dist/helpers.js CHANGED
@@ -22,20 +22,21 @@ function simplify(props) {
22
22
  */
23
23
  function getAriaAttributes(metadata) {
24
24
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
25
+ var field = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
25
26
  if (typeof options.ariaAttributes !== 'undefined' && !options.ariaAttributes) {
26
27
  return {};
27
28
  }
28
29
  var invalid = options.ariaInvalid === 'allErrors' ? !metadata.valid : typeof metadata.errors !== 'undefined';
29
30
  var ariaDescribedBy = options.ariaDescribedBy;
30
31
  return simplify({
31
- 'aria-invalid': invalid || undefined,
32
+ 'aria-invalid': field && invalid || undefined,
32
33
  'aria-describedby': invalid ? "".concat(metadata.errorId, " ").concat(ariaDescribedBy !== null && ariaDescribedBy !== void 0 ? ariaDescribedBy : '').trim() : ariaDescribedBy
33
34
  });
34
35
  }
35
36
 
36
37
  /**
37
38
  * Derives the properties of a form element based on the form metadata,
38
- * including `id`, `onSubmit`, `noValidate`, `aria-invalid` and `aria-describedby`.
39
+ * including `id`, `onSubmit`, `noValidate`, and `aria-describedby`.
39
40
  *
40
41
  * @example
41
42
  * ```tsx
@@ -52,7 +53,7 @@ function getFormProps(metadata, options) {
52
53
 
53
54
  /**
54
55
  * Derives the properties of a fieldset element based on the field metadata,
55
- * including `id`, `name`, `form`, `aria-invalid` and `aria-describedby`.
56
+ * including `id`, `name`, `form`, and `aria-describedby`.
56
57
  *
57
58
  * @example
58
59
  * ```tsx
@@ -60,11 +61,12 @@ function getFormProps(metadata, options) {
60
61
  * ```
61
62
  */
62
63
  function getFieldsetProps(metadata, options) {
64
+ var field = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
63
65
  return simplify(_rollupPluginBabelHelpers.objectSpread2({
64
66
  id: metadata.id,
65
67
  name: metadata.name,
66
68
  form: metadata.formId
67
- }, getAriaAttributes(metadata, options)));
69
+ }, getAriaAttributes(metadata, options, field)));
68
70
  }
69
71
 
70
72
  /**
@@ -75,7 +77,7 @@ function getFormControlProps(metadata, options) {
75
77
  return simplify(_rollupPluginBabelHelpers.objectSpread2({
76
78
  key: undefined,
77
79
  required: metadata.required || undefined
78
- }, getFieldsetProps(metadata, options)));
80
+ }, getFieldsetProps(metadata, options, true)));
79
81
  }
80
82
 
81
83
  /**
package/dist/helpers.mjs CHANGED
@@ -18,20 +18,21 @@ function simplify(props) {
18
18
  */
19
19
  function getAriaAttributes(metadata) {
20
20
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
21
+ var field = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
21
22
  if (typeof options.ariaAttributes !== 'undefined' && !options.ariaAttributes) {
22
23
  return {};
23
24
  }
24
25
  var invalid = options.ariaInvalid === 'allErrors' ? !metadata.valid : typeof metadata.errors !== 'undefined';
25
26
  var ariaDescribedBy = options.ariaDescribedBy;
26
27
  return simplify({
27
- 'aria-invalid': invalid || undefined,
28
+ 'aria-invalid': field && invalid || undefined,
28
29
  'aria-describedby': invalid ? "".concat(metadata.errorId, " ").concat(ariaDescribedBy !== null && ariaDescribedBy !== void 0 ? ariaDescribedBy : '').trim() : ariaDescribedBy
29
30
  });
30
31
  }
31
32
 
32
33
  /**
33
34
  * Derives the properties of a form element based on the form metadata,
34
- * including `id`, `onSubmit`, `noValidate`, `aria-invalid` and `aria-describedby`.
35
+ * including `id`, `onSubmit`, `noValidate`, and `aria-describedby`.
35
36
  *
36
37
  * @example
37
38
  * ```tsx
@@ -48,7 +49,7 @@ function getFormProps(metadata, options) {
48
49
 
49
50
  /**
50
51
  * Derives the properties of a fieldset element based on the field metadata,
51
- * including `id`, `name`, `form`, `aria-invalid` and `aria-describedby`.
52
+ * including `id`, `name`, `form`, and `aria-describedby`.
52
53
  *
53
54
  * @example
54
55
  * ```tsx
@@ -56,11 +57,12 @@ function getFormProps(metadata, options) {
56
57
  * ```
57
58
  */
58
59
  function getFieldsetProps(metadata, options) {
60
+ var field = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
59
61
  return simplify(_objectSpread2({
60
62
  id: metadata.id,
61
63
  name: metadata.name,
62
64
  form: metadata.formId
63
- }, getAriaAttributes(metadata, options)));
65
+ }, getAriaAttributes(metadata, options, field)));
64
66
  }
65
67
 
66
68
  /**
@@ -71,7 +73,7 @@ function getFormControlProps(metadata, options) {
71
73
  return simplify(_objectSpread2({
72
74
  key: undefined,
73
75
  required: metadata.required || undefined
74
- }, getFieldsetProps(metadata, options)));
76
+ }, getFieldsetProps(metadata, options, true)));
75
77
  }
76
78
 
77
79
  /**
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": "1.7.0",
6
+ "version": "1.7.2",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
@@ -41,7 +41,7 @@
41
41
  "url": "https://github.com/edmundhung/conform/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@conform-to/dom": "1.7.0"
44
+ "@conform-to/dom": "1.7.2"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.17.8",
@@ -51,10 +51,12 @@
51
51
  "@rollup/plugin-babel": "^5.3.1",
52
52
  "@rollup/plugin-node-resolve": "^13.3.0",
53
53
  "@types/react": "^18.2.43",
54
+ "@types/react-dom": "^18.3.5",
54
55
  "react": "^18.2.0",
56
+ "react-dom": "^18.2.0",
55
57
  "rollup-plugin-copy": "^3.4.0",
56
58
  "rollup": "^2.79.1",
57
- "vitest-browser-react": "^0.1.1"
59
+ "vitest-browser-react": "^0.3.0"
58
60
  },
59
61
  "peerDependencies": {
60
62
  "react": ">=18"
@@ -1,3 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;
3
- //# sourceMappingURL=vitest.config.d.ts.map