@conform-to/react 1.14.1 → 1.15.1

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.14.1 / License MIT / Copyright (c) 2025 Edmund Hung
10
+ Version 1.15.1 / License MIT / Copyright (c) 2025 Edmund Hung
11
11
 
12
12
  Progressively enhance HTML forms with React. Build resilient, type-safe forms with no hassle using web standards.
13
13
 
@@ -29,9 +29,18 @@ function initializeField(element, options) {
29
29
  }
30
30
  var defaultValue = typeof (options === null || options === void 0 ? void 0 : options.value) === 'string' || typeof (options === null || options === void 0 ? void 0 : options.defaultChecked) === 'boolean' ? options.defaultChecked ? (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : 'on' : null : options === null || options === void 0 ? void 0 : options.defaultValue;
31
31
 
32
- // Update the value of the element, including the default value
32
+ // Use change helper to set value and dispatch events
33
+ // This syncs React's internal value tracker so subsequent
34
+ // programmatic changes will properly trigger onChange
35
+ if (defaultValue !== undefined) {
36
+ future.change(element, defaultValue, {
37
+ // To avoid triggering validation on initialization
38
+ preventDefault: true
39
+ });
40
+ }
41
+
42
+ // Set the default value after change to preserve it for form reset
33
43
  future.updateField(element, {
34
- value: defaultValue,
35
44
  defaultValue
36
45
  });
37
46
  element.dataset.conform = 'initialized';
@@ -1,4 +1,4 @@
1
- import { updateField, isGlobalInstance, isFieldElement, requestIntent, getValueAtPath, change } from '@conform-to/dom/future';
1
+ import { change, updateField, isGlobalInstance, isFieldElement, requestIntent, getValueAtPath } from '@conform-to/dom/future';
2
2
  import { serializeIntent } from './intent.mjs';
3
3
 
4
4
  function getFormElement(formRef) {
@@ -25,9 +25,18 @@ function initializeField(element, options) {
25
25
  }
26
26
  var defaultValue = typeof (options === null || options === void 0 ? void 0 : options.value) === 'string' || typeof (options === null || options === void 0 ? void 0 : options.defaultChecked) === 'boolean' ? options.defaultChecked ? (_options$value = options.value) !== null && _options$value !== void 0 ? _options$value : 'on' : null : options === null || options === void 0 ? void 0 : options.defaultValue;
27
27
 
28
- // Update the value of the element, including the default value
28
+ // Use change helper to set value and dispatch events
29
+ // This syncs React's internal value tracker so subsequent
30
+ // programmatic changes will properly trigger onChange
31
+ if (defaultValue !== undefined) {
32
+ change(element, defaultValue, {
33
+ // To avoid triggering validation on initialization
34
+ preventDefault: true
35
+ });
36
+ }
37
+
38
+ // Set the default value after change to preserve it for form reset
29
39
  updateField(element, {
30
- value: defaultValue,
31
40
  defaultValue
32
41
  });
33
42
  element.dataset.conform = 'initialized';
@@ -1,6 +1,6 @@
1
- import { type FormValue, type Serialize, type SubmissionResult, createGlobalFormsObserver } from '@conform-to/dom/future';
1
+ import { type FieldName, type FormValue, type Serialize, type SubmissionResult, createGlobalFormsObserver } from '@conform-to/dom/future';
2
2
  import { useEffect } from 'react';
3
- import type { FormContext, IntentDispatcher, FormMetadata, Fieldset, GlobalFormOptions, FormOptions, FieldName, FieldMetadata, Control, Selector, UseFormDataOptions, ValidateHandler, ErrorHandler, SubmitHandler, FormState, FormRef, BaseErrorShape, DefaultErrorShape, BaseSchemaType, InferInput, InferOutput } from './types';
3
+ import type { FormContext, IntentDispatcher, FormMetadata, Fieldset, GlobalFormOptions, FormOptions, FieldMetadata, Control, Selector, UseFormDataOptions, ValidateHandler, ErrorHandler, SubmitHandler, FormState, FormRef, BaseErrorShape, DefaultErrorShape, BaseSchemaType, InferInput, InferOutput } from './types';
4
4
  import { StandardSchemaV1 } from './standard-schema';
5
5
  export declare const INITIAL_KEY = "INITIAL_KEY";
6
6
  export declare const GlobalFormOptionsContext: import("react").Context<GlobalFormOptions & {
@@ -1,6 +1,6 @@
1
- export type { FormError, FormValue, Submission, SubmissionResult, } from '@conform-to/dom/future';
2
- export { parseSubmission, report, isDirty } from '@conform-to/dom/future';
3
- export type { Control, DefaultValue, BaseMetadata, CustomMetadata, CustomMetadataDefinition, BaseErrorShape, CustomTypes, FormContext, FormMetadata, FormOptions, FormRef, FieldMetadata, FieldName, Fieldset, IntentDispatcher, } from './types';
1
+ export type { FieldName, FormError, FormValue, Submission, SubmissionResult, } from '@conform-to/dom/future';
2
+ export { getFieldValue, parseSubmission, report, isDirty, } from '@conform-to/dom/future';
3
+ export type { Control, DefaultValue, BaseMetadata, CustomMetadata, CustomMetadataDefinition, BaseErrorShape, CustomTypes, FormContext, FormMetadata, FormOptions, FormRef, FieldMetadata, Fieldset, IntentDispatcher, } from './types';
4
4
  export { FormProvider, FormOptionsProvider, useControl, useField, useForm, useFormData, useFormMetadata, useIntent, } from './hooks';
5
5
  export { memoize } from './memoize';
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -8,6 +8,10 @@ var memoize = require('./memoize.js');
8
8
 
9
9
 
10
10
 
11
+ Object.defineProperty(exports, 'getFieldValue', {
12
+ enumerable: true,
13
+ get: function () { return future.getFieldValue; }
14
+ });
11
15
  Object.defineProperty(exports, 'isDirty', {
12
16
  enumerable: true,
13
17
  get: function () { return future.isDirty; }
@@ -1,3 +1,3 @@
1
- export { isDirty, parseSubmission, report } from '@conform-to/dom/future';
1
+ export { getFieldValue, isDirty, parseSubmission, report } from '@conform-to/dom/future';
2
2
  export { FormOptionsProvider, FormProvider, useControl, useField, useForm, useFormData, useFormMetadata, useIntent } from './hooks.mjs';
3
3
  export { memoize } from './memoize.mjs';
@@ -1,5 +1,5 @@
1
- import { type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
2
- import type { FieldMetadata, FieldName, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler, CustomMetadataDefinition } from './types';
1
+ import { type FieldName, type ValidationAttributes, type Serialize } from '@conform-to/dom/future';
2
+ import type { FieldMetadata, Fieldset, FormContext, FormMetadata, FormState, FormAction, UnknownIntent, ActionHandler, CustomMetadataDefinition } from './types';
3
3
  export declare function initializeState<ErrorShape>(options?: {
4
4
  defaultValue?: Record<string, unknown> | null | undefined;
5
5
  resetKey?: string | undefined;
@@ -1,4 +1,4 @@
1
- import type { FormError, FormValue, Serialize, SubmissionResult, ValidationAttributes } from '@conform-to/dom/future';
1
+ import type { FieldName, FormError, FormValue, Serialize, SubmissionResult, ValidationAttributes } from '@conform-to/dom/future';
2
2
  import type { StandardSchemaV1 } from './standard-schema';
3
3
  export type Prettify<T> = {
4
4
  [K in keyof T]: T[K];
@@ -182,10 +182,6 @@ export interface FormContext<ErrorShape extends BaseErrorShape = DefaultErrorSha
182
182
  /** Blur event handler for form-wide blur events */
183
183
  handleBlur: (event: React.FocusEvent) => void;
184
184
  }
185
- /** The name of an input field with type information for TypeScript inference. */
186
- export type FieldName<FieldShape> = string & {
187
- '~shape'?: FieldShape;
188
- };
189
185
  export type UnknownIntent = {
190
186
  type: string;
191
187
  payload?: unknown;
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.14.1",
6
+ "version": "1.15.1",
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.14.1"
44
+ "@conform-to/dom": "1.15.1"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.17.8",