form-hook-kit 1.2.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +753 -0
  3. package/dist/FormContext.d.ts +8 -0
  4. package/dist/FormContext.d.ts.map +1 -0
  5. package/dist/FormProvider.d.ts +33 -0
  6. package/dist/FormProvider.d.ts.map +1 -0
  7. package/dist/devtools/FormDevTools.d.ts +86 -0
  8. package/dist/devtools/FormDevTools.d.ts.map +1 -0
  9. package/dist/devtools/index.d.ts +3 -0
  10. package/dist/devtools/index.d.ts.map +1 -0
  11. package/dist/hooks/index.d.ts +4 -0
  12. package/dist/hooks/index.d.ts.map +1 -0
  13. package/dist/hooks/useForm.d.ts +30 -0
  14. package/dist/hooks/useForm.d.ts.map +1 -0
  15. package/dist/hooks/useFormField.d.ts +40 -0
  16. package/dist/hooks/useFormField.d.ts.map +1 -0
  17. package/dist/hooks/useFormPerformance.d.ts +57 -0
  18. package/dist/hooks/useFormPerformance.d.ts.map +1 -0
  19. package/dist/index.d.ts +12 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.esm.js +394 -0
  22. package/dist/index.esm.js.map +1 -0
  23. package/dist/index.js +408 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/types/index.d.ts +94 -0
  26. package/dist/types/index.d.ts.map +1 -0
  27. package/dist/utils/debounce.d.ts +6 -0
  28. package/dist/utils/debounce.d.ts.map +1 -0
  29. package/dist/utils/errors.d.ts +11 -0
  30. package/dist/utils/errors.d.ts.map +1 -0
  31. package/dist/utils/formActions.d.ts +57 -0
  32. package/dist/utils/formActions.d.ts.map +1 -0
  33. package/dist/utils/formReducer.d.ts +7 -0
  34. package/dist/utils/formReducer.d.ts.map +1 -0
  35. package/dist/utils/index.d.ts +7 -0
  36. package/dist/utils/index.d.ts.map +1 -0
  37. package/dist/utils/performance.d.ts +7 -0
  38. package/dist/utils/performance.d.ts.map +1 -0
  39. package/dist/utils/validation.d.ts +25 -0
  40. package/dist/utils/validation.d.ts.map +1 -0
  41. package/package.json +91 -0
@@ -0,0 +1,8 @@
1
+ import { FormContextValue } from './types';
2
+ /**
3
+ * Form context
4
+ * Provides form state and methods to child components
5
+ */
6
+ export declare const FormContext: import("react").Context<FormContextValue | null>;
7
+ export default FormContext;
8
+ //# sourceMappingURL=FormContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormContext.d.ts","sourceRoot":"","sources":["../src/FormContext.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,WAAW,kDAA+C,CAAC;AAExE,eAAe,WAAW,CAAC"}
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { FormProviderProps } from './types';
3
+ /**
4
+ * Form Provider Component
5
+ *
6
+ * Wraps your form and provides form state management using React Context.
7
+ * Integrates with Yup for validation.
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * import * as yup from 'yup';
12
+ * import {FormProvider} from 'form-hook-kit';
13
+ *
14
+ * const schema = yup.object({
15
+ * email: yup.string().email().required(),
16
+ * password: yup.string().min(8).required(),
17
+ * });
18
+ *
19
+ * function MyForm() {
20
+ * return (
21
+ * <FormProvider
22
+ * schema={schema}
23
+ * initialValues={{ email: '', password: '' }}
24
+ * >
25
+ * <MyFormFields />
26
+ * </FormProvider>
27
+ * );
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function FormProvider({ children, initialErrors, initialValues, schema, validationDebounce, }: FormProviderProps): React.JSX.Element;
32
+ export default FormProvider;
33
+ //# sourceMappingURL=FormProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormProvider.d.ts","sourceRoot":"","sources":["../src/FormProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAC,iBAAiB,EAAiB,MAAM,SAAS,CAAC;AAY1D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,aAAkB,EAClB,aAAkB,EAClB,MAAM,EACN,kBAAsB,GACvB,EAAE,iBAAiB,qBAkGnB;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,86 @@
1
+ import React from 'react';
2
+ /**
3
+ * DevTools mode configuration
4
+ */
5
+ export type DevToolsMode = 'ui' | 'console' | 'none';
6
+ export interface FormDevToolsProps {
7
+ /**
8
+ * Display mode for DevTools
9
+ * - 'ui': Shows visual UI panel (web only)
10
+ * - 'console': Logs to console (works everywhere, including React Native)
11
+ * - 'none': Disabled
12
+ * @default 'ui' in web, 'console' in React Native
13
+ */
14
+ mode?: DevToolsMode;
15
+ /**
16
+ * Enable automatic logging on value/error changes
17
+ * Only applies when mode is 'console'
18
+ * @default false
19
+ */
20
+ autoLog?: boolean;
21
+ /**
22
+ * Custom log prefix
23
+ * @default '[FormDevTools]'
24
+ */
25
+ logPrefix?: string;
26
+ /**
27
+ * Position of the UI panel (only for 'ui' mode)
28
+ * @default 'bottom-right'
29
+ */
30
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
31
+ /**
32
+ * Whether UI panel is open by default (only for 'ui' mode)
33
+ * @default true
34
+ */
35
+ defaultOpen?: boolean;
36
+ }
37
+ /**
38
+ * FormDevTools Component
39
+ *
40
+ * A cross-platform development tool for inspecting form state in real-time.
41
+ *
42
+ * **Platform Support:**
43
+ * - **Web**: Shows a visual UI panel by default (`mode="ui"`)
44
+ * - **React Native**: Logs to console by default (`mode="console"`)
45
+ * - Use with React Native Debugger, Flipper, or Metro logs
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * // Web - shows UI panel
50
+ * import {FormProvider} from 'form-hook-kit';
51
+ * import {FormDevTools} from 'form-hook-kit/devtools';
52
+ *
53
+ * function App() {
54
+ * return (
55
+ * <FormProvider schema={schema}>
56
+ * <MyForm />
57
+ * {process.env.NODE_ENV === 'development' && <FormDevTools />}
58
+ * </FormProvider>
59
+ * );
60
+ * }
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```tsx
65
+ * // React Native - logs to console
66
+ * import {FormProvider} from 'form-hook-kit';
67
+ * import {FormDevTools} from 'form-hook-kit/devtools';
68
+ *
69
+ * function App() {
70
+ * return (
71
+ * <FormProvider schema={schema}>
72
+ * <MyForm />
73
+ * {__DEV__ && <FormDevTools mode="console" autoLog />}
74
+ * </FormProvider>
75
+ * );
76
+ * }
77
+ * ```
78
+ *
79
+ * @example
80
+ * ```tsx
81
+ * // Force console mode (works everywhere)
82
+ * <FormDevTools mode="console" autoLog logPrefix="[MyForm]" />
83
+ * ```
84
+ */
85
+ export declare function FormDevTools({ mode, autoLog, logPrefix, position, defaultOpen, }?: FormDevToolsProps): React.JSX.Element | null;
86
+ //# sourceMappingURL=FormDevTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormDevTools.d.ts","sourceRoot":"","sources":["../../src/devtools/FormDevTools.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAIzD;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAErD,MAAM,WAAW,iBAAiB;IAChC;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,CAAC;IACrE;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,wBAAgB,YAAY,CAAC,EAC3B,IAAuC,EACvC,OAAe,EACf,SAA4B,EAC5B,QAAyB,EACzB,WAAkB,GACnB,GAAE,iBAAsB,4BAqMxB"}
@@ -0,0 +1,3 @@
1
+ export { FormDevTools } from './FormDevTools';
2
+ export type { FormDevToolsProps } from './FormDevTools';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/devtools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { useForm } from './useForm';
2
+ export { useFormField } from './useFormField';
3
+ export { useFormPerformance, useValidationPerformance } from './useFormPerformance';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,kBAAkB,EAAE,wBAAwB,EAAC,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,30 @@
1
+ import { FormContextValue } from '../types';
2
+ /**
3
+ * Hook to access form context
4
+ *
5
+ * Must be used within a FormProvider component.
6
+ * Provides access to form state, values, errors, and methods.
7
+ *
8
+ * @returns Form context value with state and methods
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function MyFormField() {
13
+ * const {values, errors, changeValue, validateField} = useForm();
14
+ *
15
+ * return (
16
+ * <div>
17
+ * <input
18
+ * value={values.email || ''}
19
+ * onChange={(e) => changeValue({name: 'email', value: e.target.value})}
20
+ * onBlur={() => validateField('email')}
21
+ * />
22
+ * {errors.email && <span>{errors.email}</span>}
23
+ * </div>
24
+ * );
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function useForm(): FormContextValue;
29
+ export default useForm;
30
+ //# sourceMappingURL=useForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/hooks/useForm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,OAAO,IAAI,gBAAgB,CAa1C;AAED,eAAe,OAAO,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { FormFieldRef } from '../types';
2
+ /**
3
+ * Hook for managing a single form field
4
+ *
5
+ * Provides field-specific state and handlers for common field operations.
6
+ *
7
+ * @param name - Field name
8
+ * @returns Field state and handlers
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function EmailField() {
13
+ * const {value, error, onChange, onBlur} = useFormField('email');
14
+ *
15
+ * return (
16
+ * <div>
17
+ * <input
18
+ * type="email"
19
+ * value={value || ''}
20
+ * onChange={onChange}
21
+ * onBlur={onBlur}
22
+ * />
23
+ * {error && <span className="error">{error}</span>}
24
+ * </div>
25
+ * );
26
+ * }
27
+ * ```
28
+ */
29
+ export declare function useFormField(name: string): {
30
+ value: import("../types").FormFieldValue;
31
+ error: string | null;
32
+ onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
33
+ onChangeValue: (newValue: string | number | boolean | null | undefined) => void;
34
+ onBlur: () => void;
35
+ onFocus: () => void;
36
+ setRef: (ref: FormFieldRef) => void;
37
+ name: string;
38
+ };
39
+ export default useFormField;
40
+ //# sourceMappingURL=useFormField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormField.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormField.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,YAAY,EAAC,MAAM,UAAU,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM;;;kBAQjC,KAAK,CAAC,WAAW,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;8BAOlD,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS;;;kBAejD,YAAY;;EAkBrB;AAED,eAAe,YAAY,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { FormFieldValue } from '../types';
2
+ export interface PerformanceMetrics {
3
+ renderCount: number;
4
+ lastRenderTime: number;
5
+ fieldChangeCount: number;
6
+ }
7
+ /**
8
+ * Hook to monitor form performance metrics
9
+ *
10
+ * Useful for debugging and optimizing form performance.
11
+ *
12
+ * @returns Performance metrics object
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * function MyForm() {
17
+ * const metrics = useFormPerformance();
18
+ *
19
+ * console.log('Render count:', metrics.renderCount);
20
+ * console.log('Avg validation time:', metrics.averageValidationTime);
21
+ *
22
+ * return <div>...</div>;
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function useFormPerformance(): PerformanceMetrics;
27
+ /**
28
+ * Hook to track validation performance
29
+ *
30
+ * Wraps validation calls with timing metrics.
31
+ *
32
+ * @returns Object with tracked validateField and validateForm functions
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * function MyForm() {
37
+ * const {validateField, validateForm, metrics} = useValidationPerformance();
38
+ *
39
+ * const handleSubmit = () => {
40
+ * validateForm();
41
+ * console.log('Validation took:', metrics.lastValidationTime, 'ms');
42
+ * };
43
+ *
44
+ * return <button onClick={handleSubmit}>Submit</button>;
45
+ * }
46
+ * ```
47
+ */
48
+ export declare function useValidationPerformance(): {
49
+ validateField: (name: string, value?: FormFieldValue) => string | null;
50
+ validateForm: () => Record<string, string | null>;
51
+ metrics: {
52
+ lastValidationTime: number;
53
+ totalValidations: number;
54
+ averageValidationTime: number;
55
+ };
56
+ };
57
+ //# sourceMappingURL=useFormPerformance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormPerformance.d.ts","sourceRoot":"","sources":["../../src/hooks/useFormPerformance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,cAAc,EAAC,MAAM,UAAU,CAAC;AAGxC,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,IAAI,kBAAkB,CAiCvD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,wBAAwB;0BAST,MAAM,UAAU,cAAc;;;;;;;EA2C5D"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * form-hook-kit
3
+ *
4
+ * A lightweight, flexible form management library for React and React Native
5
+ * using React Context and Yup validation.
6
+ */
7
+ export { FormProvider } from './FormProvider';
8
+ export { FormContext } from './FormContext';
9
+ export { useForm, useFormField } from './hooks';
10
+ export type { FormContextValue, FormProviderProps, FormState, FormActions, FormAction, } from './types';
11
+ export { getFieldError, getFormErrors, formReducer, generateChangeValue, generateChangeValues, generateClearError, generateSetError, generateValidateField, generateValidateForm, } from './utils';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAG1C,OAAO,EAAC,OAAO,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAG9C,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,UAAU,GACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,SAAS,CAAC"}