UNPKG

niceform-hook

Version:
1 lines 66.3 kB
{"version":3,"file":"index.esm.mjs","sources":["../src/utils/use-context-selector/createContext.tsx","../src/utils/dequalLite.ts","../src/utils/use-context-selector/useContextSelector.tsx","../src/contexts/niceform.tsx","../src/hooks/useNiceformContext.ts","../src/hooks/useDataRefByContext.ts","../src/hooks/useComputeInputedValueHandler.ts","../src/utils/debounce.ts","../src/utils/getDependentFieldsBy.ts","../src/utils/flattenJson.ts","../src/utils/unflattenJson.ts","../src/utils/getOutputtedValues.ts","../src/utils/isFieldActive.ts","../src/utils/normalizeFieldPayload.ts","../src/utils/isObject.ts","../src/utils/getEventValue.ts","../src/hooks/useDebounceChangeFieldHandler.ts","../src/hooks/useForm/useForm.ts","../src/hooks/useForm/useController.ts","../src/hooks/useInactiveFieldHandler.ts","../src/useField.ts","../src/components/RenderReactElement.tsx","../src/hooks/useDataRef.ts","../src/hooks/useChangeField.ts","../src/hooks/useDependentFieldsToClear.ts","../src/hooks/useInitialValues.ts","../src/utils/ManyKeysMap.ts","../src/hooks/useMemoize.ts","../src/hooks/useMemoizeCallback.ts","../src/hooks/useOnErrorDuringSubmit.ts","../src/create.ts"],"sourcesContent":["import React, {\n createContext as createContextOriginal,\n useEffect,\n useRef\n} from \"react\";\n\nimport { Listener } from \"./types\";\n\nfunction createProvider<T>(ProviderOriginal: React.Context<any>['Provider']) {\n return ({ value, children }) => {\n const valueRef = useRef<T>(value);\n const listenersRef = useRef(new Set<Listener>());\n const contextValue = useRef({\n value: valueRef,\n registerListener: (listener: Listener) => {\n listenersRef.current.add(listener);\n return () => listenersRef.current.delete(listener);\n }\n });\n\n useEffect(() => {\n valueRef.current = value;\n listenersRef.current.forEach((listener) => {\n listener(value);\n });\n }, [value]);\n\n return (\n <ProviderOriginal value={contextValue.current}>\n {children}\n </ProviderOriginal>\n );\n };\n}\n\nexport default function createContext<T>(defaultValue: T) {\n const context = createContextOriginal(defaultValue);\n\n delete (context as Partial<typeof context>).Consumer;\n\n context.Provider = createProvider<T>(context.Provider) as (typeof context)['Provider']\n\n return context;\n}\n","/*\n * This code is based on an implementation provided by Luke Edwards\n * [https://github.com/lukeed/dequal]\n * Copyright (c) Luke Edwards <luke.edwards05@gmail.com> (lukeed.com)\n * release v2.0.3\n */\n\n\nconst has = Object.prototype.hasOwnProperty;\n\nexport function dequalLite(foo, bar) {\n\tlet ctor, len;\n\tif (foo === bar) return true;\n\n\tif (foo && bar && (ctor=foo.constructor) === bar.constructor) {\n\t\tif (ctor === Date) return foo.getTime() === bar.getTime();\n\t\tif (ctor === RegExp) return foo.toString() === bar.toString();\n\n\t\tif (ctor === Array) {\n\t\t\tif ((len=foo.length) === bar.length) {\n\t\t\t\twhile (len-- && dequalLite(foo[len], bar[len]));\n\t\t\t}\n\t\t\treturn len === -1;\n\t\t}\n\n\t\tif (!ctor || typeof foo === 'object') {\n\t\t\tlen = 0;\n\t\t\tfor (ctor in foo) {\n\t\t\t\tif (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;\n\t\t\t\tif (!(ctor in bar) || !dequalLite(foo[ctor], bar[ctor])) return false;\n\t\t\t}\n\t\t\treturn Object.keys(bar).length === len;\n\t\t}\n\t}\n\n\treturn foo !== foo && bar !== bar;\n}","import { useContext, useEffect, useRef, useState } from \"react\";\nimport { dequalLite } from \"../dequalLite\";\n\nimport { ValueContext } from \"./types\";\n\nexport default function useContextSelector<Value, Selected>(\n context: React.Context<Value>, \n selector: (value: Value) => Selected, \n deepComparison = false\n): Selected {\n const { value, registerListener } = useContext(context) as ValueContext<Value, Selected>;\n const selectorRef = useRef(selector);\n const [selectedValue, setSelectedValue] = useState(() =>\n selector(value.current)\n );\n\n const _selectedValue = useRef(selectedValue)\n _selectedValue.current = selectedValue\n\n useEffect(() => {\n selectorRef.current = selector;\n });\n\n useEffect(() => {\n \n const updateValueIfNeeded = (newValue) => {\n const newSelectedValue = selectorRef.current(newValue);\n\n const compare = deepComparison ? dequalLite : Object.is\n if(!compare(_selectedValue.current, newSelectedValue)){\n setSelectedValue(() => newSelectedValue);\n }\n };\n\n const unregisterListener = registerListener(updateValueIfNeeded);\n\n return unregisterListener as () => void;\n }, [registerListener, value, deepComparison]);\n\n return selectedValue;\n}\n","\nimport { FormConfig} from '../types/FormConfig';\nimport { createContext, useContextSelector } from \"../utils/use-context-selector\";\n\n// ---------------------------------------------------------------------\ntype FormConfigWithDefinition = FormConfig<{fieldProps: Record<string, any>}, any>\n\nconst context = createContext<FormConfigWithDefinition | null>(null);\n\nexport function NiceformHookProvider({ children, ...props }: FormConfigWithDefinition & { children: any }) {\n return (\n <context.Provider value={props}>\n {children}\n </context.Provider>\n )\n}\n\nexport function useNiceformHookContext<Selected>(callback: (parameters: FormConfigWithDefinition) => Selected, deepComparison = false): Selected {\n return useContextSelector(context, callback as (parameters: FormConfigWithDefinition | null) => Selected, deepComparison)\n}","import { FieldValues } from \"react-hook-form\"\nimport { useNiceformHookContext } from \"../contexts/niceform\"\nimport { CreatePropsDefinition } from \"../types\"\nimport { FormConfig } from \"../types/FormConfig\"\n\nexport function useNiceformContext<Form extends CreatePropsDefinition = CreatePropsDefinition, TFieldValues extends FieldValues = FieldValues>(){\n return useNiceformHookContext(state => {\n return state.form as FormConfig<Form, TFieldValues>['form']\n }) \n}","import { useRef } from \"react\";\nimport { useNiceformHookContext } from \"../contexts/niceform\";\nimport { FormConfig } from \"../types/FormConfig\";\n\nexport function useDataRefByContext<T>(callback: (parameters: FormConfig) => T){\n const fieldMethodsRef = useRef<T>()\n\n return useNiceformHookContext(state => {\n fieldMethodsRef.current = callback(state)\n return fieldMethodsRef\n })\n}","import { useEffect } from \"react\";\nimport { FieldValues, UseControllerReturn } from \"react-hook-form\";\nimport { useNiceformHookContext } from \"../contexts/niceform\";\nimport { useDataRefByContext } from \"./useDataRefByContext\";\n\nexport function useComputeInputedValueHandler(controller: UseControllerReturn<FieldValues, string>){\n \n const name = controller.field.name\n const inputRef = useDataRefByContext(state => state.form.getField(name)?.input)\n const setValue = useNiceformHookContext(state => state.form.methods.setValue);\n const fieldsInputedCalled = useNiceformHookContext(state => state.form.control.fieldsInputedCalled)\n\n const isInputedValueRef = fieldsInputedCalled.has(name)\n const computeInputedValue: (callback: (value: any) => any) => any = (callback) => {\n const input = inputRef.current\n \n if(!input || isInputedValueRef || controller.fieldState.isDirty) return;\n\n let value = controller.field.value\n value = input(value)\n if(value === undefined) return;\n fieldsInputedCalled.add(name)\n controller.field.value = value\n callback(value)\n }\n\n computeInputedValue(value => setTimeout(setValue, 100, name, value))\n\n const value = controller.field.value\n useEffect(() => {\n computeInputedValue(value => setValue(name, value))\n }, [value])\n}","export function debounce<T extends (this: any, ...args) => any>(fn: T, ms) {\n let timer: any = 0\n return function (this: any, ...args) {\n clearTimeout(timer)\n timer = setTimeout(fn.bind(this, ...args), ms || 0)\n } as T\n}\n\nexport function dynamicDebounce<T extends (this: any, ...args) => any>() {\n let timer: any = 0\n return function (this: any, fn: T, ms: number, ...args) {\n clearTimeout(timer)\n timer = setTimeout(fn.bind(this, args), ms || 0)\n } as T\n}","import { Field } from '../types';\n\nexport function getDependentFieldsBy(name: string, fieldsToSearch: Map<string, Field>) {\n const allField = [...fieldsToSearch.values()]\n const fieldSelected = fieldsToSearch.get(name)\n\n if (!fieldSelected) return []\n\n const fieldsToClean = allField.reduce<Field[]>((collection, field) => {\n if (\n fieldSelected.name && \n field.dependsOnToClear && \n [field.dependsOnToClear].flat().includes(fieldSelected.name) && \n field.name !== fieldSelected.name\n ) {\n collection.push(field)\n }\n return collection\n }, [])\n\n return fieldsToClean\n\n}","export function flattenJson<T extends object = object>(obj: T): Record<string, any> {\n const flattenedObj = {} as Record<string, any>\n\n function flatten(innerObj: Record<string, any>, path: string) {\n for (const key in innerObj) {\n const newPath = path ? `${path}.${key}` : key;\n\n if (innerObj[key]?.constructor === ({}).constructor || Array.isArray(innerObj[key])) {\n flatten(innerObj[key], newPath);\n } else {\n flattenedObj[newPath] = innerObj[key];\n }\n }\n }\n\n flatten(obj, \"\");\n\n return flattenedObj;\n}","export function unflattenJson<T extends Record<string, any> = Record<string, any>>(obj: T): Record<string, any> {\n const unflattenedObj: Record<string, any> = {};\n\n for (const key in obj) {\n const keys = key.split(\".\");\n let innerObj = unflattenedObj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const currentKey = keys[i];\n\n if (!innerObj[currentKey]) {\n innerObj[currentKey] = !isNaN(Number(keys[i + 1])) ? [] : {};\n }\n innerObj = innerObj[currentKey];\n }\n\n innerObj[keys.at(-1) as string] = obj[key];\n }\n\n return unflattenedObj;\n}","\nimport { Field } from \"../types\";\nimport {flattenJson} from \"./flattenJson\";\nimport {unflattenJson} from \"./unflattenJson\";\n\ninterface GetOutputtedValues{\n fields: Map<string, Field>\n values: Record<string, any>\n}\nexport function getOutputtedValues({fields, values}: GetOutputtedValues){\n const valuesFlatterned = flattenJson(values)\n\n const result = [...fields.values()].reduce((obj, field) => {\n if(!field.name || !field.output || field.active === false) return obj;\n\n const value = valuesFlatterned[field.name]\n obj[field.name] = field.output(value)\n\n return obj\n }, {} as Record<string, any>)\n \n return unflattenJson({...valuesFlatterned, ...result})\n}","import { Field } from \"../types\"\n\nexport const isFieldActive = (arg: Field | Field['active']) => {\n if(typeof arg === 'object'){\n return arg.active !== false\n }\n\n return arg !== false\n}","import { RenderFieldPayload, RenderFieldPayloadAsFunction } from \"../types\"\n\nexport function normalizeFieldPayload(\n field: RenderFieldPayload<Record<string, any>> | RenderFieldPayloadAsFunction<Record<string, any>, any>, \n deps: Parameters<RenderFieldPayloadAsFunction<Record<string, any>, any>>[0]\n) {\n if (typeof field !== 'function') return field\n return field(deps)\n}","const isDateObject = (value: unknown): value is Date => value instanceof Date;\n\nconst isNullOrUndefined = (value: unknown): value is null | undefined => value == null;\n\nconst isObjectType = (value: unknown): value is object =>\n typeof value === 'object';\n\nexport const isObject = <T extends object>(value: unknown): value is T =>\n !isNullOrUndefined(value) &&\n !Array.isArray(value) &&\n isObjectType(value) &&\n !isDateObject(value);","import {isObject} from './isObject';\n\nconst isCheckBoxInput = (element: HTMLInputElement): element is HTMLInputElement => element.type === 'checkbox';\ntype Event = { target: any };\n\nexport const getEventValue = (event: unknown) =>\n isObject(event) && (event as Event).target\n ? isCheckBoxInput((event as Event).target)\n ? (event as Event).target.checked\n : (event as Event).target.value\n : event;","import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { FieldValues, UseControllerReturn } from \"react-hook-form\";\nimport { debounce } from \"../utils\";\nimport { getEventValue } from \"../utils/getEventValue\";\nimport { useNiceformHookContext } from \"../contexts/niceform\";\n\nexport function useDebounceChangeFieldHandler(controller: UseControllerReturn<FieldValues, string>, time = 400, enabled = true){\n const [value, setValue] = useState<any>(controller.field.value)\n const fieldOnchange = useRef(controller.field.onChange)\n const canExternalUpdate = useRef(true)\n\n const debounceSubmitDefinitions = useNiceformHookContext(state => state.form.control.debounceSubmitDefinitions)\n\n const onChangeDebounce = useMemo(() => debounce((...args) => {\n canExternalUpdate.current = true\n fieldOnchange.current(...args)\n }, time), [time])\n\n const newOnChange = useCallback((evt) => {\n canExternalUpdate.current = false\n const value = getEventValue(evt)\n setValue(value)\n onChangeDebounce(value)\n debounceSubmitDefinitions.set(time)\n }, [setValue, onChangeDebounce, time])\n\n const controlledValue = controller.field.value\n useEffect(() => {\n if(canExternalUpdate.current && !Object.is(value, controlledValue)){\n setValue(controlledValue)\n controller.field.value = controlledValue\n }\n }, [controlledValue])\n \n if(!enabled) return;\n\n controller.field.onChange = newOnChange\n controller.field.value = value\n}","import type { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {useNiceformHookContext} from '../../contexts/niceform'\nexport default function useForm<TFieldValues extends FieldValues = FieldValues>() {\n \n return useNiceformHookContext(state => state.form.methods as UseFormReturn<TFieldValues>)\n}","import { FieldValues, Path, UseControllerProps, useController as _useController } from 'react-hook-form'\n\nimport useForm from './useForm'\n\nexport default function useController<TFieldValues extends FieldValues = FieldValues>(props: UseControllerProps<TFieldValues, Path<TFieldValues>>) {\n\n const {control} = useForm<TFieldValues>()\n return _useController<TFieldValues>({control, ...props})\n}","import React, { useState } from \"react\";\nimport type { FieldValues, UseControllerReturn } from \"react-hook-form\";\n\nimport { useNiceformHookContext } from \"../contexts/niceform\";\nimport * as utils from '../utils'\n\nexport default function useInactiveFieldHandler(controller: UseControllerReturn<FieldValues, string>){\n\n const isFieldActive = useNiceformHookContext(state => {\n const field = state.form.getField(controller.field.name)\n return utils.isFieldActive(field?.active)\n })\n\n const [value, setValue] = useState<any>()\n\n if(!isFieldActive){\n controller.field = {\n ...controller.field,\n onBlur: () => null,\n onChange: (evt: React.ChangeEvent<HTMLInputElement>) => setValue(evt.target.value),\n value,\n ref: () => null\n }\n }\n}","import { FieldValues, Validate } from \"react-hook-form\";\n\nimport { useNiceformHookContext } from \"./contexts/niceform\";\nimport { useComputeInputedValueHandler } from \"./hooks/useComputeInputedValueHandler\";\nimport { useDataRefByContext } from \"./hooks/useDataRefByContext\";\nimport { useDebounceChangeFieldHandler } from \"./hooks/useDebounceChangeFieldHandler\";\nimport useController from \"./hooks/useForm/useController\";\nimport useInactiveFieldHandler from \"./hooks/useInactiveFieldHandler\";\nimport { FieldConfig } from \"./types\";\n\nconst obj = {}\nexport function useField(name: string, config?: FieldConfig) {\n if(!config) config = obj\n const methods = useNiceformHookContext(state => state.form.methods)\n const errorsControl = useNiceformHookContext(state => state.form.control.errorsControl)\n const fieldsRegistered = useNiceformHookContext(state => state.form.control.fieldsRegistered)\n\n const validationByErrorsControl = (errorsControl || []).reduce((obj, error, i) => {\n const field = fieldsRegistered.get(name)\n if(!field) return obj;\n\n obj['errors-control-' + i] = (value, formValues) => error({\n value,\n formValues,\n fieldsRegistered,\n methods,\n field\n })\n return obj\n }, {} as Validate<any, FieldValues>)\n\n const volatileFieldRef = useDataRefByContext(state => {\n const field = state.form.getField(name)\n if (!field) return {}\n\n return {\n input: field.input ?? config.input,\n onBlur: field.onBlur ?? config.onBlur,\n onChange: field.onChange ?? config.onChange,\n validate: field.validate ?? config.validate\n }\n })\n const { rules, others } = useNiceformHookContext(state => {\n const field = state.form.getField(name)\n if (!field) return { rules: {}, others: {} }\n\n const debounceTime = (\n field.debounceTime ?? \n config.debounceTime ?? \n state.form.control.parameters?.debounceTime ?? \n state.form.control.config.debounceTime ?? \n 400\n )\n const enableDebounce = (\n field.enableDebounce ?? \n config.enableDebounce ?? \n state.form.control.parameters?.enableDebounce ?? \n state.form.control.config.enableDebounce ?? \n false\n ) && debounceTime > 0\n\n return {\n rules: {\n min: field.min ?? config.min,\n max: field.max ?? config.max,\n deps: field.deps,\n maxLength: field.maxLength ?? config.maxLength,\n minLength: field.minLength ?? config.minLength,\n pattern: field.pattern ?? config.pattern,\n required: field.required ?? config.required,\n value: field.value ?? config.value,\n },\n others: {\n shouldUnregister: field.shouldUnregister ?? config.shouldUnregister,\n isActive: (field.active ?? config.active) !== false,\n disabled: field.disabled ?? config.disabled,\n debounceTime,\n enableDebounce\n }\n }\n }, true)\n\n const controller = useController({\n name,\n shouldUnregister: others.shouldUnregister,\n rules: others.isActive ? {\n onBlur: (...args) => volatileFieldRef.current?.onBlur?.(...args),\n onChange: (...args) => volatileFieldRef.current?.onChange?.(...args),\n shouldUnregister: others.shouldUnregister,\n deps: rules.deps,\n max: rules.max,\n min: rules.min,\n maxLength: rules.maxLength,\n minLength: rules.minLength,\n pattern: rules.pattern,\n required: rules.required,\n validate: {\n ...validationByErrorsControl,\n ...volatileFieldRef.current?.validate\n },\n value: rules.value,\n } : {},\n disabled: others.disabled\n })\n\n useComputeInputedValueHandler(controller)\n useDebounceChangeFieldHandler(controller, others.debounceTime, others.enableDebounce)\n useInactiveFieldHandler(controller)\n\n return controller\n}","\nimport { memo } from \"react\";\nimport type { UseControllerReturn } from 'react-hook-form';\nimport { useField } from \"../useField\";\n\ninterface RenderReactElementProps {\n name: string\n render(hook: UseControllerReturn): React.ReactElement;\n}\n\nexport const RenderReactElement = memo<RenderReactElementProps>(function RenderReactElement(props) {\n const hook = useField(props.name)\n return props.render(hook)\n})\n\nexport const renderReactElement = (props: RenderReactElementProps) => <RenderReactElement {...props}/>","import { useRef } from \"react\";\n\nexport default function useDataRef<T>(data: T){\n const ref = useRef(data)\n ref.current = data\n\n return ref\n}","import { useEffect, useRef } from \"react\";\nimport { UseFormReturn } from \"react-hook-form\";\nimport { Field } from \"../types\";\nimport { OnChangeField } from \"../types/auxiliar\";\n\nimport useDataRef from \"./useDataRef\";\n\nexport interface UseChangeField<T extends Record<string, any> = Record<string, any>> {\n methods: UseFormReturn<any>\n fields: Map<string, Field>\n onChangeField?: OnChangeField<T>\n}\nexport function useChangeField<T extends Record<string, any> = Record<string, any>>(props: UseChangeField<T>){\n \n const oldsValuesByName = useRef<Map<string, any> | null>(null)\n const onChangeFieldRef = useDataRef(props.onChangeField)\n\n const watch = props.methods.watch\n const methods = props.methods\n\n if(!oldsValuesByName.current){\n oldsValuesByName.current = new Map()\n }\n\n useEffect(() => {\n const subscription = watch((values, { name, type }) => {\n if (name === undefined || !onChangeFieldRef.current) return;\n const field = props.fields.get(name)\n if(!field) return;\n\n const value = methods.getValues(name)\n\n if(Object.is(oldsValuesByName.current!.get(name), value)) return;\n\n oldsValuesByName.current!.set(name, value)\n onChangeFieldRef.current(field, value)\n });\n\n return () => subscription.unsubscribe();\n\n }, [watch, onChangeFieldRef, methods]);\n}","import { useEffect } from \"react\";\nimport { UseFormReturn } from \"react-hook-form\";\n\nimport { Field } from \"../types\";\nimport { getDependentFieldsBy } from \"../utils/getDependentFieldsBy\";\nimport useDataRef from \"./useDataRef\";\n\nexport interface UseDependentFieldsToClear {\n methods: UseFormReturn<any>\n fields: Map<string, Field>\n optionsWhenCleaning?: Partial<{\n shouldValidate: boolean;\n shouldDirty: boolean;\n shouldTouch: boolean;\n shouldCleanChain: boolean\n }>\n}\nexport default function useDependentFieldsToClear(input: UseDependentFieldsToClear) {\n const {\n methods,\n optionsWhenCleaning\n } = input\n\n const dataRef = useDataRef({\n methods,\n optionsWhenCleaning\n })\n\n const watch = methods.watch\n\n useEffect(() => {\n const subscription = watch((values, { name, type }) => {\n if (name === undefined) return;\n\n const methods = dataRef.current.methods\n const optionsWhenCleaning = dataRef.current.optionsWhenCleaning\n const fields = input.fields\n const currentValue = methods.getValues(name)\n const shouldCleanChain = optionsWhenCleaning?.shouldCleanChain\n\n if (currentValue === undefined && !shouldCleanChain) return;\n\n const fieldsDependents = getDependentFieldsBy(name, fields || [])\n\n fieldsDependents.forEach(field => {\n\n const currentFieldValue = methods.getValues(field.name as string)\n\n if (!field.name || currentFieldValue === undefined) return;\n\n methods.setValue(field.name, null, optionsWhenCleaning)\n })\n\n });\n\n return () => subscription.unsubscribe();\n\n }, [watch, dataRef]);\n}","import { UseFormReturn } from \"react-hook-form\";\nimport {flattenJson} from \"../utils/flattenJson\";\n\ninterface UseInitialValues{\n methods: UseFormReturn<any> \n initialValues: Record<string, any>\n}\nexport function useInitialValues(props: UseInitialValues){\n const flatternInitialValues = flattenJson(props.initialValues)\n\n for(const fieldName in flatternInitialValues){\n const value = flatternInitialValues[fieldName]\n if(value === undefined) continue;\n\n if(props.methods.getValues(fieldName) !== undefined) continue\n props.methods.register(fieldName)\n props.methods.setValue(fieldName, value)\n }\n}","/*\n * This code is based on an implementation provided by Federico Brigante\n * [https://github.com/fregante/many-keys-map]\n * Copyright (c) Federico Brigante <me@fregante.com> (https://fregante.com)\n * release v2.0.1\n */\n\nconst nullKey = Symbol('null'); // `objectHashes` key for null\n\nlet keyCounter = 0;\n\nexport class ManyKeysMap<K, V> extends Map<K[], V> {\n \n private _objectHashes: WeakMap<any, any>\n private _symbolHashes: Map<any, any>\n private _publicKeys: Map<any, any>\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tthis._objectHashes = new WeakMap();\n\t\tthis._symbolHashes = new Map(); // https://github.com/tc39/ecma262/issues/1194\n\t\tthis._publicKeys = new Map();\n\n\t\tconst [pairs] = arguments; // Map compat\n\t\tif (pairs === null || pairs === undefined) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (typeof pairs[Symbol.iterator] !== 'function') {\n\t\t\tthrow new TypeError(typeof pairs + ' is not iterable (cannot read property Symbol(Symbol.iterator))');\n\t\t}\n\n\t\tfor (const [keys, value] of pairs) {\n\t\t\tthis.set(keys, value);\n\t\t}\n\t}\n\n\t_getPublicKeys(keys, create = false) {\n\t\tif (!Array.isArray(keys)) {\n\t\t\tthrow new TypeError('The keys parameter must be an array');\n\t\t}\n\n\t\tconst privateKey = this._getPrivateKey(keys, create);\n\n\t\tlet publicKey;\n\t\tif (privateKey && this._publicKeys.has(privateKey)) {\n\t\t\tpublicKey = this._publicKeys.get(privateKey);\n\t\t} else if (create) {\n\t\t\tpublicKey = [...keys]; // Regenerate keys array to avoid external interaction\n\t\t\tthis._publicKeys.set(privateKey, publicKey);\n\t\t}\n\n\t\treturn {privateKey, publicKey};\n\t}\n\n\t_getPrivateKey(keys, create = false) {\n\t\tconst privateKeys: any[] = [];\n\t\tfor (let key of keys) {\n\t\t\tif (key === null) {\n\t\t\t\tkey = nullKey;\n\t\t\t}\n\n\t\t\tconst hashes = typeof key === 'object' || typeof key === 'function' ? '_objectHashes' : (typeof key === 'symbol' ? '_symbolHashes' : false);\n\n\t\t\tif (!hashes) {\n\t\t\t\tprivateKeys.push(key);\n\t\t\t} else if (this[hashes].has(key)) {\n\t\t\t\tprivateKeys.push(this[hashes].get(key));\n\t\t\t} else if (create) {\n\t\t\t\tconst privateKey = `@@mkm-ref-${keyCounter++}@@`;\n\t\t\t\tthis[hashes].set(key, privateKey);\n\t\t\t\tprivateKeys.push(privateKey);\n\t\t\t} else {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\n\t\treturn JSON.stringify(privateKeys);\n\t}\n\n\tset(keys: K[], value: V) {\n\t\tconst {publicKey} = this._getPublicKeys(keys, true);\n\t\treturn super.set(publicKey, value);\n\t}\n\n\tget(keys: K[]): V | undefined {\n\t\tconst {publicKey} = this._getPublicKeys(keys);\n\t\treturn super.get(publicKey);\n\t}\n\n\thas(keys: K[]) {\n\t\tconst {publicKey} = this._getPublicKeys(keys);\n\t\treturn super.has(publicKey);\n\t}\n\n\tdelete(keys: K[]) {\n\t\tconst {publicKey, privateKey} = this._getPublicKeys(keys);\n\t\treturn Boolean(publicKey && super.delete(publicKey) && this._publicKeys.delete(privateKey));\n\t}\n\n\tclear() {\n\t\tsuper.clear();\n\t\tthis._symbolHashes.clear();\n\t\tthis._publicKeys.clear();\n\t}\n\n\tget [Symbol.toStringTag]() {\n\t\treturn 'ManyKeysMap';\n\t}\n\n\tget size() {\n // @ts-ignore\n\t\treturn super.size;\n\t}\n}","import { useCallback, useRef } from \"react\";\nimport { ManyKeysMap } from \"../utils/ManyKeysMap\";\n\nexport function useMemoize(){\n const cache = useRef(new ManyKeysMap<any, any>())\n\n const memoize = useCallback(function memoize<T>(callback: (() => T) | T, dependencies: [key: any, ...deps: any[]]): T {\n let currentValue = cache.current.get(dependencies)\n if(!currentValue){\n if (typeof callback === 'function') {\n cache.current.set(dependencies, (callback as () => T)());\n } else {\n cache.current.set(dependencies, callback);\n }\n currentValue = cache.current.get(dependencies)\n }\n return currentValue\n }, [])\n \n return memoize\n}","import { useCallback, useRef } from \"react\";\nimport { ManyKeysMap } from \"../utils/ManyKeysMap\";\n\nexport function useMemoizeCallback(){\n const cache = useRef(new ManyKeysMap<any, any>())\n\n const memoizeCallback = useCallback(function memoizeCallback<T extends () => any>(callback: T, dependencies: [key: any, ...deps: any[]]): T {\n let currentValue = cache.current.get(dependencies)\n if(!currentValue){\n cache.current.set(dependencies, callback);\n currentValue = cache.current.get(dependencies)\n }\n return currentValue\n }, [])\n \n return memoizeCallback\n}","import type { FieldErrors, FieldValues, UseFormReturn } from \"react-hook-form\"\nimport type { Field } from \"../types\"\nimport { useEffect } from \"react\"\n\ninterface UseOnErrorDuringSubmitArgs<FieldProps extends Record<string, any> = Record<string, any>>{\n methods: UseFormReturn<any> \n getField(name: string): Field | undefined\n onErrorDuringSubmit?(errors: FieldErrors, context: {\n methods: UseFormReturn<any>\n getField(name: string): Field<FieldProps, FieldValues> | undefined\n })\n}\nexport function useOnErrorDuringSubmit({getField, methods, onErrorDuringSubmit}: UseOnErrorDuringSubmitArgs){\n useEffect(() => {\n const errors = methods.formState.errors\n if(Object.keys(errors).length && methods.formState.submitCount) onErrorDuringSubmit?.(methods.formState.errors, {\n methods,\n getField\n })\n }, [methods.formState.submitCount])\n}","import { useCallback, useMemo, useRef } from \"react\";\nimport { FieldValues, useForm as useFormReactHookForm } from \"react-hook-form\";\nimport { renderReactElement } from \"./components/RenderReactElement\";\nimport { useChangeField } from \"./hooks/useChangeField\";\n\nimport useDependentFieldsToClear from \"./hooks/useDependentFieldsToClear\";\nimport { useInitialValues } from \"./hooks/useInitialValues\";\nimport { useMemoize } from \"./hooks/useMemoize\";\nimport { useMemoizeCallback } from \"./hooks/useMemoizeCallback\";\nimport { useOnErrorDuringSubmit } from \"./hooks/useOnErrorDuringSubmit\";\nimport type { ComponentDefinition, CreateConfig, CreatePropsDefinition, Field, RenderField, RenderFields, UseFormParameters } from \"./types\";\nimport { getOutputtedValues, normalizeFieldPayload } from \"./utils\";\nimport { dynamicDebounce } from \"./utils/debounce\";\n\nexport function create<T extends CreatePropsDefinition>(config: CreateConfig<T>){\n\n const components = new Map<string, ComponentDefinition>()\n \n for(const key in config.components){\n components.set(key, config.components[key])\n }\n\n return function useForm<TFieldValues extends FieldValues = FieldValues>(parameters?: UseFormParameters<T, TFieldValues>){\n \n const repository = useRef({\n fieldsRegistered: new Map<string, Field<T['fieldProps'], TFieldValues>>(),\n componentsDefinitions: new Map<string, ComponentDefinition>(components),\n errorsControl: config.errorsControl,\n debounceSubmitDefinitions: {\n debounceRegistry: {registeredAt: 0, time: 0},\n set(time: number){\n this.debounceRegistry.registeredAt = Date.now()\n this.debounceRegistry.time = time\n },\n getRemainingTime(){\n const timeDiff = Date.now() - this.debounceRegistry.registeredAt\n\n return Math.max(0, this.debounceRegistry.time - timeDiff + 50)\n },\n isActiveDebounce(){\n const timeDiff = Date.now() - this.debounceRegistry.registeredAt\n \n return timeDiff < this.debounceRegistry.time\n }\n },\n fieldsInputedCalled: new Set<string>()\n })\n \n const submitDynamicDebounce = useMemo(() => dynamicDebounce(), [])\n \n const memoize = useMemoize()\n const memoizeCallback = useMemoizeCallback()\n const methods = useFormReactHookForm<TFieldValues>(parameters)\n\n const getField = useCallback((name: string) => {\n return repository.current.fieldsRegistered.get(name)\n }, [])\n\n useOnErrorDuringSubmit({\n getField,\n methods,\n onErrorDuringSubmit: config.onErrorDuringSubmit\n })\n\n useInitialValues({\n methods, \n initialValues: parameters?.initialValues || {}\n })\n useDependentFieldsToClear({\n methods, \n get fields(){\n return repository.current.fieldsRegistered\n }, \n })\n useChangeField({\n methods, \n get fields(){\n return repository.current.fieldsRegistered\n },\n onChangeField: parameters?.onChangeField\n })\n \n const renderField = useCallback<RenderField<T['fieldProps'], TFieldValues>>(field => {\n const {render, ..._field} = normalizeFieldPayload(field, {\n getField,\n methods\n })\n \n const type = _field.type\n const name = _field.name\n if(!name) return null\n \n repository.current.fieldsRegistered.set(name, _field)\n \n if(type === 'node' && render){\n return renderReactElement({name, render})\n }\n\n const component = repository.current.componentsDefinitions.get(type)\n \n const fieldComponent = component?.render(_field)\n \n return fieldComponent\n \n }, [\n methods, \n getField\n ])\n\n const renderFields = useCallback<RenderFields<T['fieldProps'], TFieldValues>>(fields => {\n return fields.filter(Boolean).map(renderField)\n }, [renderField])\n \n if(!methods.handleSubmit.prototype){ \n \n const handleSubmit = methods.handleSubmit\n methods.handleSubmit = function(onValid, onInvalid){\n \n const resolver = handleSubmit(async (values, event) => {\n\n const valuesOutputted = getOutputtedValues({ \n fields: repository.current.fieldsRegistered, \n values: values \n })\n onValid(valuesOutputted as TFieldValues, event)\n }, onInvalid)\n\n return async function(evt){\n\n const enableDebounce = (\n parameters?.enableDebounceOnSubmit ?? \n config.enableDebounceOnSubmit\n ) && repository.current.debounceSubmitDefinitions.isActiveDebounce()\n \n if(!enableDebounce) return resolver(evt);\n\n const timeDebounce = repository.current.debounceSubmitDefinitions.getRemainingTime()\n \n evt?.preventDefault()\n \n submitDynamicDebounce(() => {\n resolver(evt)\n }, timeDebounce)\n }\n }\n }\n \n // --------------------------------------------------------------------------------------------\n\n const result = useRef({\n methods,\n renderField,\n renderFields,\n getField,\n memoize,\n memoizeCallback,\n control: {\n get errorsControl(){\n return repository.current.errorsControl\n },\n get fieldsRegistered(){\n return repository.current.fieldsRegistered\n },\n get fieldsInputedCalled(){\n return repository.current.fieldsInputedCalled\n },\n get debounceSubmitDefinitions(){\n return repository.current.debounceSubmitDefinitions\n },\n get parameters(){\n return parameters\n },\n get config(){\n return config\n }\n }\n })\n\n result.current.renderField = renderField\n result.current.renderFields = renderFields\n\n return result.current\n }\n}\n\nexport type Create = typeof create\nexport type UseForm = ReturnType<Create>\nexport type UseReturn = ReturnType<UseForm>"],"names":["_jsx","createContextOriginal","_useController","isFieldActive","utils.isFieldActive","useFormReactHookForm"],"mappings":"2OAQA,SAAS,cAAc,CAAI,gBAAgD,EAAA;AACvE,IAAA,OAAO,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAI;AAC3B,QAAA,MAAM,QAAQ,GAAG,MAAM,CAAI,KAAK,CAAC,CAAC;QAClC,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,GAAG,EAAY,CAAC,CAAC;QACjD,MAAM,YAAY,GAAG,MAAM,CAAC;AACxB,YAAA,KAAK,EAAE,QAAQ;AACf,YAAA,gBAAgB,EAAE,CAAC,QAAkB,KAAI;AACrC,gBAAA,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBACnC,OAAO,MAAM,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;aACtD;AACJ,SAAA,CAAC,CAAC;QAEH,SAAS,CAAC,MAAK;AACX,YAAA,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAC;YACzB,YAAY,CAAC,OAAO,CAAC,OAA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