@conform-to/react
Advanced tools
Comparing version 1.0.0-pre.7 to 1.0.0-rc.0
export { type Submission, type SubmissionResult, type DefaultValue, type Intent, type FormId, type FieldName, parse, } from '@conform-to/dom'; | ||
export { type FieldMetadata, type FormMetadata, FormProvider, FormStateInput, } from './context'; | ||
export { useForm, useFormMetadata, useField } from './hooks'; | ||
export { useInputControl } from './integrations'; | ||
export { type InputControlOptions, useInputControl } from './integrations'; | ||
export { getFormProps, getFieldsetProps, getInputProps, getSelectProps, getTextareaProps, getCollectionProps, } from './helpers'; |
import { type FieldElement } from '@conform-to/dom'; | ||
import { type Key } from 'react'; | ||
export type InputControl = { | ||
@@ -10,7 +11,8 @@ value: string | undefined; | ||
export declare function getEventTarget(formId: string, name: string): FieldElement; | ||
export declare function useInputControl(meta: { | ||
key?: string | null | undefined; | ||
export type InputControlOptions = { | ||
key?: Key | null | undefined; | ||
name: string; | ||
formId: string; | ||
initialValue?: string | undefined; | ||
}): InputControl; | ||
}; | ||
export declare function useInputControl(metaOrOptions: InputControlOptions): InputControl; |
@@ -35,3 +35,3 @@ 'use strict'; | ||
} | ||
function useInputControl(meta) { | ||
function useInputControl(metaOrOptions) { | ||
var eventDispatched = react.useRef({ | ||
@@ -42,7 +42,7 @@ change: false, | ||
}); | ||
var [key, setKey] = react.useState(meta.key); | ||
var [value, setValue] = react.useState(() => meta.initialValue); | ||
if (key !== meta.key) { | ||
setValue(meta.initialValue); | ||
setKey(meta.key); | ||
var [key, setKey] = react.useState(metaOrOptions.key); | ||
var [value, setValue] = react.useState(() => metaOrOptions.initialValue); | ||
if (key !== metaOrOptions.key) { | ||
setValue(metaOrOptions.initialValue); | ||
setKey(metaOrOptions.key); | ||
} | ||
@@ -52,3 +52,3 @@ react.useEffect(() => { | ||
return event => { | ||
var element = getFieldElement(meta.formId, meta.name, element => element === event.target); | ||
var element = getFieldElement(metaOrOptions.formId, metaOrOptions.name, element => element === event.target); | ||
if (element) { | ||
@@ -70,3 +70,3 @@ eventDispatched.current[listener] = true; | ||
}; | ||
}, [meta.formId, meta.name]); | ||
}, [metaOrOptions.formId, metaOrOptions.name]); | ||
var handlers = react.useMemo(() => { | ||
@@ -76,3 +76,3 @@ return { | ||
if (!eventDispatched.current.change) { | ||
var _element = getEventTarget(meta.formId, meta.name); | ||
var _element = getEventTarget(metaOrOptions.formId, metaOrOptions.name); | ||
eventDispatched.current.change = true; | ||
@@ -122,3 +122,3 @@ if (_element instanceof HTMLInputElement && (_element.type === 'checkbox' || _element.type === 'radio')) { | ||
if (!eventDispatched.current.focus) { | ||
var _element2 = getEventTarget(meta.formId, meta.name); | ||
var _element2 = getEventTarget(metaOrOptions.formId, metaOrOptions.name); | ||
eventDispatched.current.focus = true; | ||
@@ -134,3 +134,3 @@ _element2.dispatchEvent(new FocusEvent('focusin', { | ||
if (!eventDispatched.current.blur) { | ||
var _element3 = getEventTarget(meta.formId, meta.name); | ||
var _element3 = getEventTarget(metaOrOptions.formId, metaOrOptions.name); | ||
eventDispatched.current.blur = true; | ||
@@ -145,3 +145,3 @@ _element3.dispatchEvent(new FocusEvent('focusout', { | ||
}; | ||
}, [meta.formId, meta.name]); | ||
}, [metaOrOptions.formId, metaOrOptions.name]); | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, handlers), {}, { | ||
@@ -148,0 +148,0 @@ value |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0-pre.7", | ||
"version": "1.0.0-rc.0", | ||
"main": "index.js", | ||
@@ -34,3 +34,3 @@ "module": "index.mjs", | ||
"dependencies": { | ||
"@conform-to/dom": "1.0.0-pre.7" | ||
"@conform-to/dom": "1.0.0-rc.0" | ||
}, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78687
1742
+ Added@conform-to/dom@1.0.0-rc.0(transitive)
- Removed@conform-to/dom@1.0.0-pre.7(transitive)
Updated@conform-to/dom@1.0.0-rc.0