import { Actor } from '@reactorx/core'; import { Dictionary } from 'lodash'; import React, { SyntheticEvent, Provider, ReactNode } from 'react'; import { Observable } from 'rxjs'; interface IFieldState { name?: string; active?: boolean; changed?: boolean; touched?: boolean; visited?: boolean; error?: string; } interface IFormState { fields: Dictionary; initials: TFormValues; values: TFormValues; submitting?: boolean; } declare type TFormErrors = Dictionary; declare const FormActor: Actor; declare const formKey: (formName: string) => string; declare const formInitial: Actor; declare const formDestroy: Actor; declare const formStartSubmit: Actor; declare const formEndSubmit: Actor; declare const formSetErrors: Actor; declare const formAddField: Actor<{ defaultValue: any; error?: string | undefined; }, { field: string; } & { form: string; }>; declare const formUpdateField: Actor<{ value: any; error?: string | undefined; }, { field: string; } & { form: string; }>; declare const formRemoveField: Actor; declare const formFocusField: Actor; declare const formBlurField: Actor; declare function putValues(values: any, fieldName: string, value: string): any; declare function putFields(fields: Dictionary, fieldName: string, effect: (fieldState: IFieldState) => IFieldState): Dictionary; declare type TValidate = (value: any) => string | undefined; interface IFormContexts { formName: string; fieldPrefix?: string; setErrors: (errors: Dictionary) => void; getFormValues: () => TFormValues; getFormState: () => IFormState; createSubmit: (cb: (values: TFormValues) => void) => (evt: SyntheticEvent) => void; startSubmit: () => void; endSubmit: () => void; state$: Observable>; } declare const FormProvider: Provider>; declare function useForm(): IFormContexts; /** * @deprecated useForm instead */ declare const useFormContext: typeof useForm; declare const useFieldState: (name: string) => IFieldState & { name: string; value: any; }; interface IFieldStateProps { name: string; children: (formState: IFieldState & { name: string; value: any; }) => React.ReactNode; } /** * @deprecated use useFieldState(name: string) instead */ declare function FieldState(props: IFieldStateProps): JSX.Element; interface IFieldInnerProps extends IFieldState { name: TName | string; value: any; required?: boolean; fieldError?: string; reset: () => void; onValueChange: (v: any) => void; onChange: (e?: React.ChangeEvent) => void; onBlur: (e?: React.FocusEvent) => void; onFocus: (e?: React.FocusEvent) => void; } interface IFieldProps { defaultValue?: any; name: TName; required?: boolean; validate?: TValidate | TValidate[]; children: (fieldProps: IFieldInnerProps) => React.ReactNode; } declare const createValidate: (validate?: TValidate | TValidate[] | undefined, required?: boolean | undefined) => (value?: any) => string | undefined; declare function Field(props: IFieldProps): JSX.Element; interface IFieldArrayAPIs { add: (defaultValue?: any) => void; remove: (idx: number) => void; each: (render: (idx: number) => React.ReactNode) => React.ReactNode; } interface IFieldArrayProps { name: string; children: (fields: IFieldArrayAPIs) => React.ReactNode; } declare const FieldArray: ({ name, children }: IFieldArrayProps) => JSX.Element; declare type TFormContextChildRender = (ctx: IFormContexts & { submit: (evt: SyntheticEvent) => void; }) => ReactNode; interface IFormProps { onSubmit?: (values: TFormValues) => void; name: string; id?: string; initialValues?: TFormValues; children: ReactNode | TFormContextChildRender; } declare function pickValidValues(values: any): any; /** * @deprecated useNewForm instead */ declare function Form(props: IFormProps): JSX.Element; declare function useNewForm(formName: string, initialValues?: Partial): readonly [{ formName: string; getFormState: () => any; getFormValues: () => any; startSubmit: () => void; endSubmit: () => void; setErrors: (errors: Dictionary) => void; createSubmit: (cb: (values: TFormValues) => void) => (e: React.FormEvent) => void; state$: Observable; }, ({ providerOnly, onSubmit, children, ...otherProps }: { providerOnly?: boolean | undefined; onSubmit?: ((values: TFormValues, end: () => void) => void) | undefined; } & Pick, "children" | "style" | "title" | "name" | "dir" | "slot" | "defaultValue" | "id" | "acceptCharset" | "action" | "autoComplete" | "encType" | "method" | "noValidate" | "target" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "draggable" | "hidden" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture">) => JSX.Element]; interface IFormSection { name: string; children: React.ReactNode; } declare const FormSection: ({ name, children }: IFormSection) => JSX.Element; export { Field, FieldArray, FieldState, Form, FormActor, FormProvider, FormSection, IFieldArrayAPIs, IFieldArrayProps, IFieldInnerProps, IFieldProps, IFieldState, IFieldStateProps, IFormContexts, IFormProps, IFormSection, IFormState, TFormErrors, TValidate, createValidate, formAddField, formBlurField, formDestroy, formEndSubmit, formFocusField, formInitial, formKey, formRemoveField, formSetErrors, formStartSubmit, formUpdateField, pickValidValues, putFields, putValues, useFieldState, useForm, useFormContext, useNewForm };