@conform-to/react 1.15.1 → 1.17.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.
@@ -1,6 +1,6 @@
1
1
  import type { FormError } from '@conform-to/dom/future';
2
2
  import type { StandardSchemaV1 } from './standard-schema';
3
- import { ValidateHandler, ValidateResult } from './types';
3
+ import { ValidateHandler, ValidateResult, BaseFieldMetadata, ConditionalFieldMetadata } from './types';
4
4
  export declare function isUndefined(value: unknown): value is undefined;
5
5
  export declare function isString(value: unknown): value is string;
6
6
  export declare function isNumber(value: unknown): value is number;
@@ -42,6 +42,9 @@ export declare function resolveValidateResult<ErrorShape, Value>(result: ReturnT
42
42
  value?: Value | undefined;
43
43
  }> | undefined;
44
44
  };
45
+ /**
46
+ * Resolves a StandardSchema validation result to conform's format.
47
+ */
45
48
  export declare function resolveStandardSchemaResult<Value>(result: StandardSchemaV1.Result<Value>): {
46
49
  error: FormError<string> | null;
47
50
  value?: Value;
@@ -65,4 +68,44 @@ export declare function appendUniqueItem<Item>(list: Array<Item>, item: Item): I
65
68
  */
66
69
  export declare function compactMap<Item>(list: Array<NonNullable<Item>>, fn: (value: Item) => Item | null): Array<Item>;
67
70
  export declare function generateUniqueKey(): string;
71
+ /**
72
+ * Creates a type-only marker for TypeScript inference.
73
+ *
74
+ * This function always returns `true` at runtime. It exists
75
+ * purely to capture the generic type parameter for compile-time type checking.
76
+ * No runtime validation is performed.
77
+ *
78
+ * Common uses:
79
+ * - `isError`: Specify the error shape for type inference
80
+ * - `when`: Narrow field metadata to specific shapes for conditional props
81
+ *
82
+ * @example Specify error shape
83
+ * ```ts
84
+ * configureForms({
85
+ * isError: shape<string>(), // errors are strings
86
+ * });
87
+ * ```
88
+ *
89
+ * @example Conditional field metadata
90
+ * ```ts
91
+ * extendFieldMetadata(metadata, { when }) {
92
+ * return {
93
+ * get dateRangePickerProps() {
94
+ * return when(metadata, shape<{ start: string; end: string }>(), (m) => ({
95
+ * startName: m.getFieldset().start.name,
96
+ * endName: m.getFieldset().end.name,
97
+ * }));
98
+ * },
99
+ * };
100
+ * }
101
+ * ```
102
+ */
103
+ export declare function shape<T>(): (value: unknown) => value is T;
104
+ /**
105
+ * Creates a conditional field metadata property that is only available
106
+ * when the field shape matches the specified type.
107
+ */
108
+ export declare function when<FieldShape, ErrorShape, Metadata>(metadata: BaseFieldMetadata<unknown, ErrorShape>, _shape: (value: unknown) => value is FieldShape, fn: (m: BaseFieldMetadata<FieldShape, ErrorShape>) => Metadata): ConditionalFieldMetadata<Metadata, FieldShape>;
109
+ export declare function isStandardSchemaV1(schema: unknown): schema is StandardSchemaV1;
110
+ export declare function validateStandardSchemaV1<Schema extends StandardSchemaV1>(schema: Schema, payload: Record<string, unknown>): any;
68
111
  //# sourceMappingURL=util.d.ts.map
@@ -118,6 +118,10 @@ function resolveValidateResult(result) {
118
118
  asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
119
119
  };
120
120
  }
121
+
122
+ /**
123
+ * Resolves a StandardSchema validation result to conform's format.
124
+ */
121
125
  function resolveStandardSchemaResult(result) {
122
126
  if (!result.issues) {
123
127
  return {
@@ -149,10 +153,10 @@ function merge(obj, update) {
149
153
  */
150
154
  function transformKeys(obj, fn) {
151
155
  var result = {};
152
- for (var [_key, _value] of Object.entries(obj)) {
156
+ for (var [_key, _value2] of Object.entries(obj)) {
153
157
  var _name = fn(_key);
154
158
  if (_name !== null) {
155
- result[_name] = _value;
159
+ result[_name] = _value2;
156
160
  }
157
161
  }
158
162
  return result;
@@ -175,9 +179,9 @@ function appendUniqueItem(list, item) {
175
179
  function compactMap(list, fn) {
176
180
  var result = [];
177
181
  for (var item of list) {
178
- var _value2 = fn(item);
179
- if (_value2 !== null) {
180
- result.push(_value2);
182
+ var _value3 = fn(item);
183
+ if (_value3 !== null) {
184
+ result.push(_value3);
181
185
  }
182
186
  }
183
187
  return result;
@@ -186,6 +190,60 @@ function generateUniqueKey() {
186
190
  return Math.trunc(Date.now() * Math.random()).toString(36);
187
191
  }
188
192
 
193
+ /**
194
+ * Creates a type-only marker for TypeScript inference.
195
+ *
196
+ * This function always returns `true` at runtime. It exists
197
+ * purely to capture the generic type parameter for compile-time type checking.
198
+ * No runtime validation is performed.
199
+ *
200
+ * Common uses:
201
+ * - `isError`: Specify the error shape for type inference
202
+ * - `when`: Narrow field metadata to specific shapes for conditional props
203
+ *
204
+ * @example Specify error shape
205
+ * ```ts
206
+ * configureForms({
207
+ * isError: shape<string>(), // errors are strings
208
+ * });
209
+ * ```
210
+ *
211
+ * @example Conditional field metadata
212
+ * ```ts
213
+ * extendFieldMetadata(metadata, { when }) {
214
+ * return {
215
+ * get dateRangePickerProps() {
216
+ * return when(metadata, shape<{ start: string; end: string }>(), (m) => ({
217
+ * startName: m.getFieldset().start.name,
218
+ * endName: m.getFieldset().end.name,
219
+ * }));
220
+ * },
221
+ * };
222
+ * }
223
+ * ```
224
+ */
225
+ function shape() {
226
+ return _value => true;
227
+ }
228
+
229
+ /**
230
+ * Creates a conditional field metadata property that is only available
231
+ * when the field shape matches the specified type.
232
+ */
233
+ function when(metadata, _shape, fn) {
234
+ return fn(metadata);
235
+ }
236
+ function isStandardSchemaV1(schema) {
237
+ return typeof schema === 'object' && schema !== null && '~standard' in schema && typeof schema['~standard'] === 'object' && schema['~standard'] !== null && 'version' in schema['~standard'] && schema['~standard'].version === 1;
238
+ }
239
+ function validateStandardSchemaV1(schema, payload) {
240
+ var result = schema['~standard'].validate(payload);
241
+ if (result instanceof Promise) {
242
+ return result.then(actualResult => resolveStandardSchemaResult(actualResult));
243
+ }
244
+ return resolveStandardSchemaResult(result);
245
+ }
246
+
189
247
  exports.appendUniqueItem = appendUniqueItem;
190
248
  exports.compactMap = compactMap;
191
249
  exports.createPathIndexUpdater = createPathIndexUpdater;
@@ -194,6 +252,7 @@ exports.getArrayAtPath = getArrayAtPath;
194
252
  exports.isNullable = isNullable;
195
253
  exports.isNumber = isNumber;
196
254
  exports.isOptional = isOptional;
255
+ exports.isStandardSchemaV1 = isStandardSchemaV1;
197
256
  exports.isString = isString;
198
257
  exports.isUndefined = isUndefined;
199
258
  exports.merge = merge;
@@ -201,5 +260,8 @@ exports.normalizeFormError = normalizeFormError;
201
260
  exports.normalizeValidateResult = normalizeValidateResult;
202
261
  exports.resolveStandardSchemaResult = resolveStandardSchemaResult;
203
262
  exports.resolveValidateResult = resolveValidateResult;
263
+ exports.shape = shape;
204
264
  exports.transformKeys = transformKeys;
205
265
  exports.updateValueAtPath = updateValueAtPath;
266
+ exports.validateStandardSchemaV1 = validateStandardSchemaV1;
267
+ exports.when = when;
@@ -114,6 +114,10 @@ function resolveValidateResult(result) {
114
114
  asyncResult: asyncResult ? asyncResult.then(normalizeValidateResult) : undefined
115
115
  };
116
116
  }
117
+
118
+ /**
119
+ * Resolves a StandardSchema validation result to conform's format.
120
+ */
117
121
  function resolveStandardSchemaResult(result) {
118
122
  if (!result.issues) {
119
123
  return {
@@ -145,10 +149,10 @@ function merge(obj, update) {
145
149
  */
146
150
  function transformKeys(obj, fn) {
147
151
  var result = {};
148
- for (var [_key, _value] of Object.entries(obj)) {
152
+ for (var [_key, _value2] of Object.entries(obj)) {
149
153
  var _name = fn(_key);
150
154
  if (_name !== null) {
151
- result[_name] = _value;
155
+ result[_name] = _value2;
152
156
  }
153
157
  }
154
158
  return result;
@@ -171,9 +175,9 @@ function appendUniqueItem(list, item) {
171
175
  function compactMap(list, fn) {
172
176
  var result = [];
173
177
  for (var item of list) {
174
- var _value2 = fn(item);
175
- if (_value2 !== null) {
176
- result.push(_value2);
178
+ var _value3 = fn(item);
179
+ if (_value3 !== null) {
180
+ result.push(_value3);
177
181
  }
178
182
  }
179
183
  return result;
@@ -182,4 +186,58 @@ function generateUniqueKey() {
182
186
  return Math.trunc(Date.now() * Math.random()).toString(36);
183
187
  }
184
188
 
185
- export { appendUniqueItem, compactMap, createPathIndexUpdater, generateUniqueKey, getArrayAtPath, isNullable, isNumber, isOptional, isString, isUndefined, merge, normalizeFormError, normalizeValidateResult, resolveStandardSchemaResult, resolveValidateResult, transformKeys, updateValueAtPath };
189
+ /**
190
+ * Creates a type-only marker for TypeScript inference.
191
+ *
192
+ * This function always returns `true` at runtime. It exists
193
+ * purely to capture the generic type parameter for compile-time type checking.
194
+ * No runtime validation is performed.
195
+ *
196
+ * Common uses:
197
+ * - `isError`: Specify the error shape for type inference
198
+ * - `when`: Narrow field metadata to specific shapes for conditional props
199
+ *
200
+ * @example Specify error shape
201
+ * ```ts
202
+ * configureForms({
203
+ * isError: shape<string>(), // errors are strings
204
+ * });
205
+ * ```
206
+ *
207
+ * @example Conditional field metadata
208
+ * ```ts
209
+ * extendFieldMetadata(metadata, { when }) {
210
+ * return {
211
+ * get dateRangePickerProps() {
212
+ * return when(metadata, shape<{ start: string; end: string }>(), (m) => ({
213
+ * startName: m.getFieldset().start.name,
214
+ * endName: m.getFieldset().end.name,
215
+ * }));
216
+ * },
217
+ * };
218
+ * }
219
+ * ```
220
+ */
221
+ function shape() {
222
+ return _value => true;
223
+ }
224
+
225
+ /**
226
+ * Creates a conditional field metadata property that is only available
227
+ * when the field shape matches the specified type.
228
+ */
229
+ function when(metadata, _shape, fn) {
230
+ return fn(metadata);
231
+ }
232
+ function isStandardSchemaV1(schema) {
233
+ return typeof schema === 'object' && schema !== null && '~standard' in schema && typeof schema['~standard'] === 'object' && schema['~standard'] !== null && 'version' in schema['~standard'] && schema['~standard'].version === 1;
234
+ }
235
+ function validateStandardSchemaV1(schema, payload) {
236
+ var result = schema['~standard'].validate(payload);
237
+ if (result instanceof Promise) {
238
+ return result.then(actualResult => resolveStandardSchemaResult(actualResult));
239
+ }
240
+ return resolveStandardSchemaResult(result);
241
+ }
242
+
243
+ export { appendUniqueItem, compactMap, createPathIndexUpdater, generateUniqueKey, getArrayAtPath, isNullable, isNumber, isOptional, isStandardSchemaV1, isString, isUndefined, merge, normalizeFormError, normalizeValidateResult, resolveStandardSchemaResult, resolveValidateResult, shape, transformKeys, updateValueAtPath, validateStandardSchemaV1, when };
package/dist/helpers.d.ts CHANGED
@@ -34,6 +34,7 @@ type InputProps = Pretty<FormControlProps & {
34
34
  step?: string | number;
35
35
  pattern?: string;
36
36
  multiple?: boolean;
37
+ accept?: string;
37
38
  value?: string;
38
39
  defaultChecked?: boolean;
39
40
  defaultValue?: string;
package/dist/helpers.js CHANGED
@@ -109,7 +109,8 @@ function getInputProps(metadata, options) {
109
109
  max: metadata.max,
110
110
  step: metadata.step,
111
111
  pattern: metadata.pattern,
112
- multiple: metadata.multiple
112
+ multiple: metadata.multiple,
113
+ accept: metadata.accept
113
114
  });
114
115
  if (typeof options.value === 'undefined' || options.value) {
115
116
  if (options.type === 'checkbox' || options.type === 'radio') {
package/dist/helpers.mjs CHANGED
@@ -105,7 +105,8 @@ function getInputProps(metadata, options) {
105
105
  max: metadata.max,
106
106
  step: metadata.step,
107
107
  pattern: metadata.pattern,
108
- multiple: metadata.multiple
108
+ multiple: metadata.multiple,
109
+ accept: metadata.accept
109
110
  });
110
111
  if (typeof options.value === 'undefined' || options.value) {
111
112
  if (options.type === 'checkbox' || options.type === 'radio') {
@@ -6,9 +6,9 @@ export declare function createDummySelect(form: HTMLFormElement, name: string, v
6
6
  export declare function isDummySelect(element: HTMLElement): element is HTMLSelectElement;
7
7
  export declare function getInputValue(element: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): string | string[] | null;
8
8
  export declare function useInputEvent(onUpdate: React.Dispatch<React.SetStateAction<string | string[] | undefined>>): {
9
- change(value: string | string[]): void;
10
- focus(): void;
11
- blur(): void;
9
+ change: (value: string | string[]) => void;
10
+ focus: () => void;
11
+ blur: () => void;
12
12
  register: RefCallback<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | undefined>;
13
13
  };
14
14
  export declare function useInputValue<Value extends string | string[] | Array<string | undefined>>(options: {
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.15.1",
6
+ "version": "1.17.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.15.1"
44
+ "@conform-to/dom": "1.17.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.17.8",