@conform-to/react 0.6.2 → 0.6.3-pre.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/helpers.d.ts CHANGED
@@ -46,10 +46,10 @@ type InputOptions = BaseOptions & ({
46
46
  type?: Exclude<HTMLInputTypeAttribute, 'button' | 'submit' | 'hidden'>;
47
47
  value?: never;
48
48
  });
49
+ export declare function input<Schema extends Primitive | unknown>(config: FieldConfig<Schema>, options?: InputOptions): InputProps<Schema>;
49
50
  export declare function input<Schema extends File | File[]>(config: FieldConfig<Schema>, options: InputOptions & {
50
51
  type: 'file';
51
52
  }): InputProps<Schema>;
52
- export declare function input<Schema extends Primitive>(config: FieldConfig<Schema>, options?: InputOptions): InputProps<Schema>;
53
- export declare function select(config: FieldConfig<Primitive | Primitive[]>, options?: BaseOptions): SelectProps;
54
- export declare function textarea(config: FieldConfig<Primitive>, options?: BaseOptions): TextareaProps;
53
+ export declare function select<Schema extends Primitive | Primitive[] | undefined | unknown>(config: FieldConfig<Schema>, options?: BaseOptions): SelectProps;
54
+ export declare function textarea<Schema extends Primitive | undefined | unknown>(config: FieldConfig<Schema>, options?: BaseOptions): TextareaProps;
55
55
  export { INTENT, VALIDATION_UNDEFINED, VALIDATION_SKIPPED };
package/hooks.d.ts CHANGED
@@ -18,7 +18,7 @@ export interface FieldConfig<Schema> extends FieldConstraint<Schema> {
18
18
  */
19
19
  errors?: string[];
20
20
  }
21
- export type FieldValue<Schema> = Schema extends Primitive ? string : Schema extends File ? File : Schema extends Array<infer InnerType> ? Array<FieldValue<InnerType>> : Schema extends Record<string, any> ? {
21
+ export type FieldValue<Schema> = Schema extends Primitive ? string : Schema extends File ? File : Schema extends Array<infer InnerType> ? Array<FieldValue<InnerType>> : unknown extends Schema ? any : Record<string, any> extends Schema ? {
22
22
  [Key in KeysOf<Schema>]?: FieldValue<ResolveType<Schema, Key>>;
23
23
  } : any;
24
24
  export interface FormConfig<Output extends Record<string, any>, Input extends Record<string, any> = Output> {
@@ -121,10 +121,10 @@ export declare function useForm<Output extends Record<string, any>, Input extend
121
121
  /**
122
122
  * A set of field configuration
123
123
  */
124
- export type Fieldset<Schema extends Record<string, any>> = {
124
+ export type Fieldset<Schema extends Record<string, any> | undefined> = {
125
125
  [Key in KeysOf<Schema>]-?: FieldConfig<ResolveType<Schema, Key>>;
126
126
  };
127
- export interface FieldsetConfig<Schema extends Record<string, any>> {
127
+ export interface FieldsetConfig<Schema extends Record<string, any> | undefined> {
128
128
  /**
129
129
  * The prefix used to generate the name of nested fields.
130
130
  */
@@ -151,16 +151,16 @@ export interface FieldsetConfig<Schema extends Record<string, any>> {
151
151
  *
152
152
  * @see https://conform.guide/api/react#usefieldset
153
153
  */
154
- export declare function useFieldset<Schema extends Record<string, any>>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldsetConfig<Schema>): Fieldset<Schema>;
155
- export declare function useFieldset<Schema extends Record<string, any>>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Schema>): Fieldset<Schema>;
154
+ export declare function useFieldset<Schema extends Record<string, any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldsetConfig<Schema>): Fieldset<Schema>;
155
+ export declare function useFieldset<Schema extends Record<string, any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Schema>): Fieldset<Schema>;
156
156
  /**
157
157
  * Returns a list of key and field config.
158
158
  *
159
159
  * @see https://conform.guide/api/react#usefieldlist
160
160
  */
161
- export declare function useFieldList<Payload = any>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Array<Payload>>): Array<{
161
+ export declare function useFieldList<Schema extends Array<any> | undefined>(ref: RefObject<HTMLFormElement | HTMLFieldSetElement>, config: FieldConfig<Schema>): Array<{
162
162
  key: string;
163
- } & FieldConfig<Payload>>;
163
+ } & FieldConfig<Schema extends Array<infer Item> ? Item : never>>;
164
164
  interface InputControl {
165
165
  change: (eventOrValue: {
166
166
  target: {
package/hooks.js CHANGED
@@ -165,7 +165,7 @@ function useForm() {
165
165
  shouldValidate = initialReport === 'onChange' ? 'onInput' : initialReport,
166
166
  shouldRevalidate = 'onInput'
167
167
  } = configRef.current;
168
- if (!form || !dom.isFocusableFormControl(field) || field.form !== form) {
168
+ if (!form || !dom.isFocusableFormControl(field) || field.form !== form || !field.name) {
169
169
  return;
170
170
  }
171
171
  if (field.dataset.conformTouched ? shouldRevalidate === name : shouldValidate === name) {
@@ -303,6 +303,7 @@ function useFieldset(ref, config) {
303
303
  }, {});
304
304
  var field = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, constraint), {}, {
305
305
  name: fieldsetConfig.name ? "".concat(fieldsetConfig.name, ".").concat(key) : key,
306
+ // @ts-expect-error The FieldValue type might need a rework
306
307
  defaultValue: (_fieldsetConfig$defau = fieldsetConfig.defaultValue) === null || _fieldsetConfig$defau === void 0 ? void 0 : _fieldsetConfig$defau[key],
307
308
  initialError,
308
309
  error: errors === null || errors === void 0 ? void 0 : errors[0],
package/module/hooks.js CHANGED
@@ -161,7 +161,7 @@ function useForm() {
161
161
  shouldValidate = initialReport === 'onChange' ? 'onInput' : initialReport,
162
162
  shouldRevalidate = 'onInput'
163
163
  } = configRef.current;
164
- if (!form || !isFocusableFormControl(field) || field.form !== form) {
164
+ if (!form || !isFocusableFormControl(field) || field.form !== form || !field.name) {
165
165
  return;
166
166
  }
167
167
  if (field.dataset.conformTouched ? shouldRevalidate === name : shouldValidate === name) {
@@ -299,6 +299,7 @@ function useFieldset(ref, config) {
299
299
  }, {});
300
300
  var field = _objectSpread2(_objectSpread2({}, constraint), {}, {
301
301
  name: fieldsetConfig.name ? "".concat(fieldsetConfig.name, ".").concat(key) : key,
302
+ // @ts-expect-error The FieldValue type might need a rework
302
303
  defaultValue: (_fieldsetConfig$defau = fieldsetConfig.defaultValue) === null || _fieldsetConfig$defau === void 0 ? void 0 : _fieldsetConfig$defau[key],
303
304
  initialError,
304
305
  error: errors === null || errors === void 0 ? void 0 : errors[0],
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.6.2",
6
+ "version": "0.6.3-pre.0",
7
7
  "main": "index.js",
8
8
  "module": "module/index.js",
9
9
  "repository": {
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/edmundhung/conform/issues"
21
21
  },
22
22
  "dependencies": {
23
- "@conform-to/dom": "0.6.2"
23
+ "@conform-to/dom": "0.6.3-pre.0"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "react": ">=16.8"