@conform-to/react 1.1.2 → 1.1.4

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 CHANGED
@@ -8,7 +8,7 @@
8
8
  ╚══════╝ ╚═════╝ ╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝
9
9
 
10
10
 
11
- Version 1.1.1 / License MIT / Copyright (c) 2024 Edmund Hung
11
+ Version 1.1.3 / License MIT / Copyright (c) 2024 Edmund Hung
12
12
 
13
13
  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.
14
14
 
package/helpers.d.ts CHANGED
@@ -72,7 +72,7 @@ type TextareaOptions = Pretty<FormControlOptions & {
72
72
  /**
73
73
  * Decide whether defaultValue should be returned. Pass `false` if you want to mange the value yourself.
74
74
  */
75
- value?: true;
75
+ value?: boolean;
76
76
  }>;
77
77
  /**
78
78
  * Derives aria attributes of a form control based on the field metadata.
@@ -138,7 +138,7 @@ export declare function getFormControlProps<Schema>(metadata: FieldMetadata<Sche
138
138
  * <input {...getInputProps(metadata, { type: 'radio', value: false })} />
139
139
  * ```
140
140
  */
141
- export declare function getInputProps<Schema>(metadata: FieldMetadata<Schema, any, any>, options: InputOptions): InputProps;
141
+ export declare function getInputProps<Schema, Options extends InputOptions>(metadata: FieldMetadata<Schema, any, any>, options: Options): InputProps & Pick<Options, 'type'>;
142
142
  /**
143
143
  * Derives the properties of a select element based on the field metadata,
144
144
  * including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
package/helpers.js CHANGED
@@ -112,7 +112,7 @@ function getInputProps(metadata, options) {
112
112
  if (typeof options.value === 'undefined' || options.value) {
113
113
  if (options.type === 'checkbox' || options.type === 'radio') {
114
114
  props.value = typeof options.value === 'string' ? options.value : 'on';
115
- props.defaultChecked = typeof metadata.initialValue === 'boolean' ? metadata.initialValue : metadata.initialValue === props.value;
115
+ props.defaultChecked = Array.isArray(metadata.initialValue) ? metadata.initialValue.includes(options.value) : metadata.initialValue === props.value;
116
116
  } else if (typeof metadata.initialValue === 'string') {
117
117
  props.defaultValue = metadata.initialValue;
118
118
  }
package/helpers.mjs CHANGED
@@ -108,7 +108,7 @@ function getInputProps(metadata, options) {
108
108
  if (typeof options.value === 'undefined' || options.value) {
109
109
  if (options.type === 'checkbox' || options.type === 'radio') {
110
110
  props.value = typeof options.value === 'string' ? options.value : 'on';
111
- props.defaultChecked = typeof metadata.initialValue === 'boolean' ? metadata.initialValue : metadata.initialValue === props.value;
111
+ props.defaultChecked = Array.isArray(metadata.initialValue) ? metadata.initialValue.includes(options.value) : metadata.initialValue === props.value;
112
112
  } else if (typeof metadata.initialValue === 'string') {
113
113
  props.defaultValue = metadata.initialValue;
114
114
  }
package/package.json CHANGED
@@ -1,53 +1,69 @@
1
1
  {
2
- "name": "@conform-to/react",
3
- "description": "Conform view adapter for react",
4
- "homepage": "https://conform.guide",
5
- "license": "MIT",
6
- "version": "1.1.2",
7
- "main": "index.js",
8
- "module": "index.mjs",
9
- "types": "index.d.ts",
10
- "exports": {
11
- ".": {
12
- "types": "./index.d.ts",
13
- "module": "./index.mjs",
14
- "import": "./index.mjs",
15
- "require": "./index.js",
16
- "default": "./index.mjs"
17
- }
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/edmundhung/conform",
22
- "directory": "packages/conform-react"
23
- },
24
- "author": {
25
- "name": "Edmund Hung",
26
- "email": "me@edmund.dev",
27
- "url": "https://edmund.dev"
28
- },
29
- "bugs": {
30
- "url": "https://github.com/edmundhung/conform/issues"
31
- },
32
- "dependencies": {
33
- "@conform-to/dom": "1.1.2"
34
- },
35
- "devDependencies": {
36
- "@types/react": "^18.2.43",
37
- "react": "^18.2.0"
38
- },
39
- "peerDependencies": {
40
- "react": ">=18"
41
- },
42
- "keywords": [
43
- "constraint-validation",
44
- "form",
45
- "form-validation",
46
- "html",
47
- "progressive-enhancement",
48
- "validation",
49
- "react",
50
- "remix"
51
- ],
52
- "sideEffects": false
53
- }
2
+ "name": "@conform-to/react",
3
+ "description": "Conform view adapter for react",
4
+ "homepage": "https://conform.guide",
5
+ "license": "MIT",
6
+ "version": "1.1.4",
7
+ "main": "index.js",
8
+ "module": "index.mjs",
9
+ "types": "index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./index.d.ts",
13
+ "module": "./index.mjs",
14
+ "import": "./index.mjs",
15
+ "require": "./index.js",
16
+ "default": "./index.mjs"
17
+ }
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/edmundhung/conform",
22
+ "directory": "packages/conform-react"
23
+ },
24
+ "author": {
25
+ "name": "Edmund Hung",
26
+ "email": "me@edmund.dev",
27
+ "url": "https://edmund.dev"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/edmundhung/conform/issues"
31
+ },
32
+ "dependencies": {
33
+ "@conform-to/dom": "1.1.4"
34
+ },
35
+ "devDependencies": {
36
+ "@babel/core": "^7.17.8",
37
+ "@babel/preset-env": "^7.20.2",
38
+ "@babel/preset-react": "^7.18.6",
39
+ "@babel/preset-typescript": "^7.20.2",
40
+ "@rollup/plugin-babel": "^5.3.1",
41
+ "@rollup/plugin-node-resolve": "^13.3.0",
42
+ "@types/react": "^18.2.43",
43
+ "react": "^18.2.0",
44
+ "rollup-plugin-copy": "^3.4.0",
45
+ "rollup": "^2.79.1"
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">=18"
49
+ },
50
+ "keywords": [
51
+ "constraint-validation",
52
+ "form",
53
+ "form-validation",
54
+ "html",
55
+ "progressive-enhancement",
56
+ "validation",
57
+ "react",
58
+ "remix"
59
+ ],
60
+ "sideEffects": false,
61
+ "scripts": {
62
+ "build:js": "rollup -c",
63
+ "build:ts": "tsc",
64
+ "build": "pnpm run \"/^build:.*/\"",
65
+ "dev:js": "pnpm run build:js --watch",
66
+ "dev:ts": "pnpm run build:ts --watch",
67
+ "dev": "pnpm run \"/^dev:.*/\""
68
+ }
69
+ }
@@ -0,0 +1,102 @@
1
+ import path from 'node:path';
2
+ import babel from '@rollup/plugin-babel';
3
+ import nodeResolve from '@rollup/plugin-node-resolve';
4
+ import copy from 'rollup-plugin-copy';
5
+
6
+ /** @returns {import("rollup").RollupOptions[]} */
7
+ function configurePackage() {
8
+ let sourceDir = '.';
9
+ let outputDir = sourceDir;
10
+
11
+ /** @type {import("rollup").RollupOptions} */
12
+ let ESM = {
13
+ external(id) {
14
+ return !id.startsWith('.') && !path.isAbsolute(id);
15
+ },
16
+ input: `${sourceDir}/index.ts`,
17
+ output: {
18
+ dir: outputDir,
19
+ format: 'esm',
20
+ preserveModules: true,
21
+ entryFileNames: '[name].mjs',
22
+ },
23
+ plugins: [
24
+ babel({
25
+ babelrc: false,
26
+ configFile: false,
27
+ presets: [
28
+ [
29
+ '@babel/preset-env',
30
+ {
31
+ targets: {
32
+ node: '16',
33
+ esmodules: true,
34
+ },
35
+ },
36
+ ],
37
+ ['@babel/preset-react', { runtime: 'automatic' }],
38
+ '@babel/preset-typescript',
39
+ ],
40
+ plugins: [],
41
+ babelHelpers: 'bundled',
42
+ exclude: /node_modules/,
43
+ extensions: ['.ts', '.tsx'],
44
+ }),
45
+ nodeResolve({
46
+ extensions: ['.ts', '.tsx'],
47
+ }),
48
+ copy({
49
+ targets: [
50
+ { src: `../../README`, dest: sourceDir },
51
+ { src: `../../LICENSE`, dest: sourceDir },
52
+ ],
53
+ }),
54
+ ],
55
+ };
56
+
57
+ /** @type {import("rollup").RollupOptions} */
58
+ let CJS = {
59
+ external(id) {
60
+ return !id.startsWith('.') && !path.isAbsolute(id);
61
+ },
62
+ input: `${sourceDir}/index.ts`,
63
+ output: {
64
+ dir: outputDir,
65
+ format: 'cjs',
66
+ preserveModules: true,
67
+ exports: 'auto',
68
+ },
69
+ plugins: [
70
+ babel({
71
+ babelrc: false,
72
+ configFile: false,
73
+ presets: [
74
+ [
75
+ '@babel/preset-env',
76
+ {
77
+ targets: {
78
+ node: '16',
79
+ esmodules: true,
80
+ },
81
+ },
82
+ ],
83
+ ['@babel/preset-react', { runtime: 'automatic' }],
84
+ '@babel/preset-typescript',
85
+ ],
86
+ plugins: [],
87
+ babelHelpers: 'bundled',
88
+ exclude: /node_modules/,
89
+ extensions: ['.ts', '.tsx'],
90
+ }),
91
+ nodeResolve({
92
+ extensions: ['.ts', '.tsx'],
93
+ }),
94
+ ],
95
+ };
96
+
97
+ return [ESM, CJS];
98
+ }
99
+
100
+ export default function rollup() {
101
+ return configurePackage();
102
+ }