@conform-to/react 1.19.4 → 1.20.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/context.d.ts +2 -2
- package/dist/future/dom.d.ts +2 -2
- package/dist/future/dom.js +9 -4
- package/dist/future/dom.mjs +9 -4
- package/dist/future/forms.d.ts +62 -21
- package/dist/future/forms.js +59 -11
- package/dist/future/forms.mjs +56 -9
- package/dist/future/hooks.d.ts +9 -4
- package/dist/future/hooks.js +67 -35
- package/dist/future/hooks.mjs +70 -38
- package/dist/future/index.d.ts +4 -2
- package/dist/future/index.js +5 -0
- package/dist/future/index.mjs +3 -1
- package/dist/future/intent.d.ts +27 -21
- package/dist/future/intent.js +369 -371
- package/dist/future/intent.mjs +361 -372
- package/dist/future/state.d.ts +48 -21
- package/dist/future/state.js +344 -43
- package/dist/future/state.mjs +339 -46
- package/dist/future/types.d.ts +158 -149
- package/dist/future/util.d.ts +4 -8
- package/dist/future/util.js +25 -60
- package/dist/future/util.mjs +26 -59
- package/dist/helpers.d.ts +2 -2
- package/dist/helpers.js +2 -2
- package/dist/helpers.mjs +2 -2
- package/dist/hooks.d.ts +1 -1
- package/dist/vitest.config.d.ts +0 -1
- package/package.json +2 -2
package/dist/future/util.js
CHANGED
|
@@ -39,36 +39,32 @@ function updatePathValue(data, name, value) {
|
|
|
39
39
|
}
|
|
40
40
|
return value;
|
|
41
41
|
}
|
|
42
|
-
return future.setPathValue(data, future.parsePath(name), value
|
|
43
|
-
clone: true
|
|
44
|
-
});
|
|
42
|
+
return future.setPathValue(data, future.parsePath(name), value);
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
|
-
*
|
|
49
|
-
* Returns null to remove fields, or updated path with new index.
|
|
46
|
+
* Updates array indices in a field path.
|
|
47
|
+
* Returns null to remove fields, or the updated path with a new index.
|
|
50
48
|
*/
|
|
51
|
-
function
|
|
49
|
+
function updatePathIndex(name, listName, update) {
|
|
52
50
|
var listPaths = future.parsePath(listName);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return future.formatPath(paths);
|
|
67
|
-
}
|
|
51
|
+
var paths = future.parsePath(name);
|
|
52
|
+
if (paths.length > listPaths.length && listPaths.every((path, index) => paths[index] === path)) {
|
|
53
|
+
var currentIndex = paths[listPaths.length];
|
|
54
|
+
if (typeof currentIndex === 'number') {
|
|
55
|
+
var newIndex = update(currentIndex);
|
|
56
|
+
if (newIndex === null) {
|
|
57
|
+
// To remove the item instead of updating it
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (newIndex !== currentIndex) {
|
|
61
|
+
// Replace the index
|
|
62
|
+
paths.splice(listPaths.length, 1, newIndex);
|
|
63
|
+
return future.formatPath(paths);
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
}
|
|
67
|
+
return name;
|
|
72
68
|
}
|
|
73
69
|
function resolveSerialize(customSerialize, _defaultSerialize) {
|
|
74
70
|
if (typeof customSerialize === 'undefined') {
|
|
@@ -96,7 +92,7 @@ function normalizeValidateResult(result) {
|
|
|
96
92
|
/**
|
|
97
93
|
* Handles different validation result formats:
|
|
98
94
|
* - Promise: async validation only
|
|
99
|
-
* -
|
|
95
|
+
* - Staged result: immediate result with a pending result
|
|
100
96
|
* - Object: sync validation only
|
|
101
97
|
*/
|
|
102
98
|
function resolveValidateResult(result) {
|
|
@@ -104,14 +100,14 @@ function resolveValidateResult(result) {
|
|
|
104
100
|
var asyncResult;
|
|
105
101
|
if (result instanceof Promise) {
|
|
106
102
|
asyncResult = result;
|
|
107
|
-
} else if (
|
|
108
|
-
syncResult = result
|
|
109
|
-
asyncResult = result
|
|
103
|
+
} else if (result && 'result' in result && 'pending' in result) {
|
|
104
|
+
syncResult = result.result;
|
|
105
|
+
asyncResult = result.pending;
|
|
110
106
|
} else {
|
|
111
107
|
syncResult = result;
|
|
112
108
|
}
|
|
113
109
|
return {
|
|
114
|
-
syncResult: syncResult ? normalizeValidateResult(syncResult)
|
|
110
|
+
syncResult: typeof syncResult === 'undefined' ? undefined : normalizeValidateResult(syncResult),
|
|
115
111
|
asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
|
|
116
112
|
};
|
|
117
113
|
}
|
|
@@ -144,21 +140,6 @@ function merge(obj, update) {
|
|
|
144
140
|
return Object.assign({}, obj, update);
|
|
145
141
|
}
|
|
146
142
|
|
|
147
|
-
/**
|
|
148
|
-
* Transforms object keys using a mapping function.
|
|
149
|
-
* Keys mapped to null are filtered out.
|
|
150
|
-
*/
|
|
151
|
-
function transformKeys(obj, fn) {
|
|
152
|
-
var result = {};
|
|
153
|
-
for (var [_key, _value2] of Object.entries(obj)) {
|
|
154
|
-
var _name = fn(_key);
|
|
155
|
-
if (_name !== null) {
|
|
156
|
-
result[_name] = _value2;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
143
|
/**
|
|
163
144
|
* Appends item to array only if not already present.
|
|
164
145
|
* Returns original array if item exists, new array if added.
|
|
@@ -169,20 +150,6 @@ function appendUniqueItem(list, item) {
|
|
|
169
150
|
}
|
|
170
151
|
return list.concat(item);
|
|
171
152
|
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Maps over array and filters out null results.
|
|
175
|
-
*/
|
|
176
|
-
function compactMap(list, fn) {
|
|
177
|
-
var result = [];
|
|
178
|
-
for (var item of list) {
|
|
179
|
-
var _value3 = fn(item);
|
|
180
|
-
if (_value3 !== null) {
|
|
181
|
-
result.push(_value3);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
153
|
function generateUniqueKey() {
|
|
187
154
|
return Math.trunc(Date.now() * Math.random()).toString(36);
|
|
188
155
|
}
|
|
@@ -242,8 +209,6 @@ function validateStandardSchemaV1(schema, payload) {
|
|
|
242
209
|
}
|
|
243
210
|
|
|
244
211
|
exports.appendUniqueItem = appendUniqueItem;
|
|
245
|
-
exports.compactMap = compactMap;
|
|
246
|
-
exports.createPathIndexUpdater = createPathIndexUpdater;
|
|
247
212
|
exports.generateUniqueKey = generateUniqueKey;
|
|
248
213
|
exports.getPathArray = getPathArray;
|
|
249
214
|
exports.isNullable = isNullable;
|
|
@@ -258,7 +223,7 @@ exports.resolveSerialize = resolveSerialize;
|
|
|
258
223
|
exports.resolveStandardSchemaResult = resolveStandardSchemaResult;
|
|
259
224
|
exports.resolveValidateResult = resolveValidateResult;
|
|
260
225
|
exports.shape = shape;
|
|
261
|
-
exports.
|
|
226
|
+
exports.updatePathIndex = updatePathIndex;
|
|
262
227
|
exports.updatePathValue = updatePathValue;
|
|
263
228
|
exports.validateStandardSchemaV1 = validateStandardSchemaV1;
|
|
264
229
|
exports.when = when;
|
package/dist/future/util.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPathValue, isPlainObject, setPathValue, parsePath, formatPath, formatIssues, normalizeFormError } from '@conform-to/dom/future';
|
|
2
2
|
|
|
3
3
|
function isUndefined(value) {
|
|
4
4
|
return value === undefined;
|
|
@@ -35,36 +35,32 @@ function updatePathValue(data, name, value) {
|
|
|
35
35
|
}
|
|
36
36
|
return value;
|
|
37
37
|
}
|
|
38
|
-
return setPathValue(data, parsePath(name), value
|
|
39
|
-
clone: true
|
|
40
|
-
});
|
|
38
|
+
return setPathValue(data, parsePath(name), value);
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
/**
|
|
44
|
-
*
|
|
45
|
-
* Returns null to remove fields, or updated path with new index.
|
|
42
|
+
* Updates array indices in a field path.
|
|
43
|
+
* Returns null to remove fields, or the updated path with a new index.
|
|
46
44
|
*/
|
|
47
|
-
function
|
|
45
|
+
function updatePathIndex(name, listName, update) {
|
|
48
46
|
var listPaths = parsePath(listName);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return formatPath(paths);
|
|
63
|
-
}
|
|
47
|
+
var paths = parsePath(name);
|
|
48
|
+
if (paths.length > listPaths.length && listPaths.every((path, index) => paths[index] === path)) {
|
|
49
|
+
var currentIndex = paths[listPaths.length];
|
|
50
|
+
if (typeof currentIndex === 'number') {
|
|
51
|
+
var newIndex = update(currentIndex);
|
|
52
|
+
if (newIndex === null) {
|
|
53
|
+
// To remove the item instead of updating it
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (newIndex !== currentIndex) {
|
|
57
|
+
// Replace the index
|
|
58
|
+
paths.splice(listPaths.length, 1, newIndex);
|
|
59
|
+
return formatPath(paths);
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
}
|
|
63
|
+
return name;
|
|
68
64
|
}
|
|
69
65
|
function resolveSerialize(customSerialize, _defaultSerialize) {
|
|
70
66
|
if (typeof customSerialize === 'undefined') {
|
|
@@ -92,7 +88,7 @@ function normalizeValidateResult(result) {
|
|
|
92
88
|
/**
|
|
93
89
|
* Handles different validation result formats:
|
|
94
90
|
* - Promise: async validation only
|
|
95
|
-
* -
|
|
91
|
+
* - Staged result: immediate result with a pending result
|
|
96
92
|
* - Object: sync validation only
|
|
97
93
|
*/
|
|
98
94
|
function resolveValidateResult(result) {
|
|
@@ -100,14 +96,14 @@ function resolveValidateResult(result) {
|
|
|
100
96
|
var asyncResult;
|
|
101
97
|
if (result instanceof Promise) {
|
|
102
98
|
asyncResult = result;
|
|
103
|
-
} else if (
|
|
104
|
-
syncResult = result
|
|
105
|
-
asyncResult = result
|
|
99
|
+
} else if (result && 'result' in result && 'pending' in result) {
|
|
100
|
+
syncResult = result.result;
|
|
101
|
+
asyncResult = result.pending;
|
|
106
102
|
} else {
|
|
107
103
|
syncResult = result;
|
|
108
104
|
}
|
|
109
105
|
return {
|
|
110
|
-
syncResult: syncResult ? normalizeValidateResult(syncResult)
|
|
106
|
+
syncResult: typeof syncResult === 'undefined' ? undefined : normalizeValidateResult(syncResult),
|
|
111
107
|
asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
|
|
112
108
|
};
|
|
113
109
|
}
|
|
@@ -140,21 +136,6 @@ function merge(obj, update) {
|
|
|
140
136
|
return Object.assign({}, obj, update);
|
|
141
137
|
}
|
|
142
138
|
|
|
143
|
-
/**
|
|
144
|
-
* Transforms object keys using a mapping function.
|
|
145
|
-
* Keys mapped to null are filtered out.
|
|
146
|
-
*/
|
|
147
|
-
function transformKeys(obj, fn) {
|
|
148
|
-
var result = {};
|
|
149
|
-
for (var [_key, _value2] of Object.entries(obj)) {
|
|
150
|
-
var _name = fn(_key);
|
|
151
|
-
if (_name !== null) {
|
|
152
|
-
result[_name] = _value2;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return result;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
139
|
/**
|
|
159
140
|
* Appends item to array only if not already present.
|
|
160
141
|
* Returns original array if item exists, new array if added.
|
|
@@ -165,20 +146,6 @@ function appendUniqueItem(list, item) {
|
|
|
165
146
|
}
|
|
166
147
|
return list.concat(item);
|
|
167
148
|
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Maps over array and filters out null results.
|
|
171
|
-
*/
|
|
172
|
-
function compactMap(list, fn) {
|
|
173
|
-
var result = [];
|
|
174
|
-
for (var item of list) {
|
|
175
|
-
var _value3 = fn(item);
|
|
176
|
-
if (_value3 !== null) {
|
|
177
|
-
result.push(_value3);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
149
|
function generateUniqueKey() {
|
|
183
150
|
return Math.trunc(Date.now() * Math.random()).toString(36);
|
|
184
151
|
}
|
|
@@ -237,4 +204,4 @@ function validateStandardSchemaV1(schema, payload) {
|
|
|
237
204
|
return resolveStandardSchemaResult(result);
|
|
238
205
|
}
|
|
239
206
|
|
|
240
|
-
export { appendUniqueItem,
|
|
207
|
+
export { appendUniqueItem, generateUniqueKey, getPathArray, isNullable, isNumber, isOptional, isStandardSchemaV1, isString, isUndefined, merge, normalizeValidateResult, resolveSerialize, resolveStandardSchemaResult, resolveValidateResult, shape, updatePathIndex, updatePathValue, validateStandardSchemaV1, when };
|
package/dist/helpers.d.ts
CHANGED
|
@@ -122,8 +122,8 @@ export declare function getFormControlProps<Schema>(metadata: FieldMetadata<Sche
|
|
|
122
122
|
* Derives the properties of an input element based on the field metadata,
|
|
123
123
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
124
124
|
* and constraint attributes such as `type`, `required`, `minLength`, `maxLength`, `min`, `max`, `step`, `pattern`, `multiple`.
|
|
125
|
-
* Depends on the provided options, it will also set `defaultChecked` / `
|
|
126
|
-
* or otherwise `defaultValue
|
|
125
|
+
* Depends on the provided options, it will also set `defaultChecked` / `value` if it is a checkbox or radio button,
|
|
126
|
+
* or otherwise `defaultValue`.
|
|
127
127
|
*
|
|
128
128
|
* See https://conform.guide/api/react/getInputProps
|
|
129
129
|
*
|
package/dist/helpers.js
CHANGED
|
@@ -84,8 +84,8 @@ function getFormControlProps(metadata, options) {
|
|
|
84
84
|
* Derives the properties of an input element based on the field metadata,
|
|
85
85
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
86
86
|
* and constraint attributes such as `type`, `required`, `minLength`, `maxLength`, `min`, `max`, `step`, `pattern`, `multiple`.
|
|
87
|
-
* Depends on the provided options, it will also set `defaultChecked` / `
|
|
88
|
-
* or otherwise `defaultValue
|
|
87
|
+
* Depends on the provided options, it will also set `defaultChecked` / `value` if it is a checkbox or radio button,
|
|
88
|
+
* or otherwise `defaultValue`.
|
|
89
89
|
*
|
|
90
90
|
* See https://conform.guide/api/react/getInputProps
|
|
91
91
|
*
|
package/dist/helpers.mjs
CHANGED
|
@@ -80,8 +80,8 @@ function getFormControlProps(metadata, options) {
|
|
|
80
80
|
* Derives the properties of an input element based on the field metadata,
|
|
81
81
|
* including common form control attributes like `key`, `id`, `name`, `form`, `autoFocus`, `aria-invalid`, `aria-describedby`
|
|
82
82
|
* and constraint attributes such as `type`, `required`, `minLength`, `maxLength`, `min`, `max`, `step`, `pattern`, `multiple`.
|
|
83
|
-
* Depends on the provided options, it will also set `defaultChecked` / `
|
|
84
|
-
* or otherwise `defaultValue
|
|
83
|
+
* Depends on the provided options, it will also set `defaultChecked` / `value` if it is a checkbox or radio button,
|
|
84
|
+
* or otherwise `defaultValue`.
|
|
85
85
|
*
|
|
86
86
|
* See https://conform.guide/api/react/getInputProps
|
|
87
87
|
*
|
package/dist/hooks.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare function useForm<Schema extends Record<string, any>, FormValue =
|
|
|
26
26
|
export declare function useFormMetadata<Schema extends Record<string, any>, FormError = string[]>(formId?: FormId<Schema, FormError>, options?: {
|
|
27
27
|
defaultNoValidate?: boolean;
|
|
28
28
|
}): FormMetadata<Schema, FormError>;
|
|
29
|
-
export declare function useField<FieldSchema, FormSchema extends Record<string, unknown> =
|
|
29
|
+
export declare function useField<FieldSchema, FormSchema extends Record<string, unknown> = any, FormError = string[]>(name: FieldName<FieldSchema, FormSchema, FormError>, options?: {
|
|
30
30
|
formId?: FormId<FormSchema, FormError>;
|
|
31
31
|
}): [
|
|
32
32
|
FieldMetadata<FieldSchema, FormSchema, FormError>,
|
package/dist/vitest.config.d.ts
CHANGED
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.
|
|
6
|
+
"version": "1.20.0",
|
|
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.
|
|
44
|
+
"@conform-to/dom": "1.20.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/core": "^7.17.8",
|