@chris-c-brine/form-dialog 1.3.1 → 1.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chris-c-brine/form-dialog",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Easy MUI Form Dialogs with react-hook-form!",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,7 +10,8 @@
10
10
  "LICENSE"
11
11
  ],
12
12
  "scripts": {
13
- "build": "rollup -c",
13
+ "clean": "node --eval \"require('fs').rmSync('./dist', {recursive: true, force: true})\"",
14
+ "build": "npm run clean && rollup -c",
14
15
  "prepare": "npm run build"
15
16
  },
16
17
  "keywords": [
@@ -40,6 +41,7 @@
40
41
  "@types/node": "^25.6.0",
41
42
  "@types/react": "^19.2.14",
42
43
  "@types/react-dom": "^19.2.3",
44
+ "prettier": "^3.9.6",
43
45
  "react": "^19.2.5",
44
46
  "react-dom": "^19.2.5",
45
47
  "react-hook-form": "^7.75.0",
@@ -1,36 +0,0 @@
1
- import { type FC } from "react";
2
- import { AutoGridProps } from "../types";
3
- /**
4
- * A responsive grid component that automatically arranges children in equal columns
5
- *
6
- * AutoGrid simplifies the creation of grid layouts by automatically calculating
7
- * column sizes based on the provided `columnCount`. It's particularly useful
8
- * for form layouts where fields need to be arranged in a consistent grid pattern.
9
- *
10
- * @example
11
- * // Basic usage with 2 columns
12
- * <AutoGrid
13
- * columnCount={2}
14
- * components={[
15
- * <TextFieldElement key="name" label="Name" />,
16
- * <TextFieldElement key="email" label="Email" />
17
- * ]}
18
- * />
19
- *
20
- * @example
21
- * // With spacing and custom props
22
- * <AutoGrid
23
- * columnCount={3}
24
- * rowSpacing={2}
25
- * columnSpacing={3}
26
- * components={[
27
- * <TextFieldElement key="first" label="First Name" />,
28
- * <TextFieldElement key="middle" label="Middle Name" />,
29
- * <TextFieldElement key="last" label="Last Name" />
30
- * ]}
31
- * />
32
- *
33
- * @note Be careful of transferring keys of children to the wrapper Grid.
34
- * If not done correctly, it will cause React to discard the old tree and remount children components.
35
- */
36
- export declare const AutoGrid: FC<AutoGridProps>;
@@ -1,13 +0,0 @@
1
- import type { FC, ReactNode } from "react";
2
- import { type BlackoutDialogProps } from "./BlackoutDialog";
3
- import type { DialogContentProps, DialogTitleProps, DialogActionsProps } from "@mui/material";
4
- export type BaseDialogProps = Omit<BlackoutDialogProps, "children" | "title" | "content"> & {
5
- title?: ReactNode;
6
- titleProps?: DialogTitleProps;
7
- children?: ReactNode;
8
- contentProps?: DialogContentProps;
9
- actions?: ReactNode;
10
- actionsProps?: DialogActionsProps;
11
- closeButton?: ReactNode;
12
- };
13
- export declare const BaseDialog: FC<BaseDialogProps>;
@@ -1,23 +0,0 @@
1
- import { type DialogProps } from "@mui/material";
2
- import { type FC, type PropsWithChildren } from "react";
3
- export type BlackoutDialogProps = DialogProps & Partial<PropsWithChildren> & {
4
- /**
5
- * An optional unique string identifier
6
- * @default 'blackout-dialog'
7
- */
8
- id?: string;
9
- /**
10
- * Whether the dialog is currently visible.
11
- * @default false
12
- */
13
- open: boolean;
14
- /**
15
- * Whether to apply a black overlay behind the dialog.
16
- * @default false
17
- */
18
- blackout?: boolean;
19
- };
20
- /**
21
- * A component for rendering a modal dialog with an optional blackout effect.
22
- */
23
- export declare const BlackoutDialog: FC<BlackoutDialogProps>;
@@ -1,11 +0,0 @@
1
- import { type BaseDialogProps } from "./BaseDialog";
2
- import { type FieldValues, type FormContainerProps } from "react-hook-form-mui";
3
- /**
4
- * Props for the FormDialog component. Inherits from BaseDialogProps and adds formProps.
5
- * @param formProps - Props for the FormContainer component from react-hook-form-mui.
6
- * @returns The FormDialog component.
7
- */
8
- export type FormDialogProps<T extends FieldValues> = Omit<BaseDialogProps, "PaperComponent"> & {
9
- formProps: FormContainerProps<T>;
10
- };
11
- export declare const FormDialog: <T extends FieldValues>({ formProps, children, open, onClose, ...dialogProps }: FormDialogProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,15 +0,0 @@
1
- import { GridProps } from "@mui/material";
2
- import type { FC, PropsWithChildren } from "react";
3
- import { type FormCancelButtonProps } from "./buttons/FormCancelButton";
4
- import { type FormResetButtonProps } from "./buttons/FormResetButton";
5
- import { FormSubmitButtonProps } from "./buttons/FormSubmitButton";
6
- export type FormDialogActionsProps = PropsWithChildren & {
7
- cancelProps?: FormCancelButtonProps;
8
- resetProps?: FormResetButtonProps;
9
- submitProps?: FormSubmitButtonProps;
10
- variant?: "icon" | "text" | "iconText";
11
- removeCancelButton?: boolean;
12
- removeResetButton?: boolean;
13
- gridProps?: GridProps;
14
- };
15
- export declare const FormDialogActions: FC<FormDialogActionsProps>;
@@ -1,6 +0,0 @@
1
- import { type PaperProps } from "@mui/material";
2
- import { type FieldValues, type FormContainerProps } from "react-hook-form-mui";
3
- export type PaperFormProps<T extends FieldValues> = PaperProps & {
4
- formProps: FormContainerProps<T>;
5
- };
6
- export declare const PaperForm: <T extends FieldValues>({ children, formProps, ...paperProps }: PaperFormProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -1,5 +0,0 @@
1
- import type { FC, PropsWithChildren } from "react";
2
- export interface PersistFormProps extends PropsWithChildren {
3
- formName: string;
4
- }
5
- export declare const PersistForm: FC<PersistFormProps>;
@@ -1,43 +0,0 @@
1
- import { PersistFormProps } from "../../types";
2
- /**
3
- * A component that enables form state persistence across sessions
4
- *
5
- * PersistForm is a lightweight wrapper that connects a form to persistent storage,
6
- * allowing form values to be preserved when navigating away and returning. It wraps
7
- * the usePersistedForm hook in a convenient component API.
8
- *
9
- * Key features:
10
- * - Persists form values during navigation or page reloads
11
- * - Automatically restores saved values when the form is rendered
12
- * - Only saves changed fields, not the entire form state
13
- * - Automatically clears storage when form values match defaults
14
- * - Works with any React Hook Form based forms
15
- *
16
- * Note: This component must be used inside a FormProvider from react-hook-form
17
- * and should be within a FormDialogProvider for full functionality.
18
- *
19
- * @example
20
- * // Basic usage
21
- * const MyForm = () => {
22
- * const methods = useForm({ defaultValues: { name: '' } });
23
- *
24
- * return (<FormProvider {...methods}>
25
- * <PersistForm formName="user-profile">
26
- * <TextFieldElement name="name" label="Name" />
27
- * <FormSubmitButton>Save</FormSubmitButton>
28
- * </PersistForm>
29
- * </FormProvider>);
30
- * }
31
- *
32
- * @example
33
- * // Usage within a dialog
34
- * <FormDialog
35
- * formProps={{ defaultValues: defaultValues }}
36
- * title="Edit Profile"
37
- * >
38
- * <PersistForm formName="edit-profile-dialog">
39
- * <ProfileFormFields />
40
- * </PersistForm>
41
- * </FormDialog>
42
- */
43
- export declare const PersistForm: import("react").NamedExoticComponent<PersistFormProps>;
@@ -1,13 +0,0 @@
1
- import { UseMaxAttemptProps } from "../types";
2
- /**
3
- * Hook that monitors form submission attempts and disables the form when a limit is reached.
4
- *
5
- * It performs two main functions:
6
- * 1. Monitors `formState.submitCount` and calls `setDisabled(true)` from the dialog context
7
- * once it reaches or exceeds the specified `maxAttempts`.
8
- * 2. When the dialog context enters a `disabled` state, it automatically resets form fields
9
- * that have errors or are dirty to ensure a clean state for the user.
10
- *
11
- * @param props - UseMaxAttemptProps
12
- */
13
- export declare const useMaxAttempts: ({ maxAttempts }: UseMaxAttemptProps) => void;
@@ -1,6 +0,0 @@
1
- /**
2
- * Runs a provided callback function once on the first component mount.
3
- *
4
- * @param callback - The function to run on first mount.
5
- */
6
- export declare function useOnMount(callback: () => void): void;
@@ -1,18 +0,0 @@
1
- import { FieldValues } from "react-hook-form-mui";
2
- import { PersistedFormProviderProps } from "../types";
3
- /**
4
- * Hook that enables form state persistence across sessions
5
- *
6
- * This hook connects a form to persistent storage (e.g., sessionStorage)
7
- * allowing form values to be preserved when navigating away and returning.
8
- * It works by watching form changes and syncing with a zustand store.
9
- *
10
- * Key features:
11
- * - Persists form values during navigation or page reloads
12
- * - Automatically restores saved values when form is rendered
13
- * - Debounced updates to avoid excessive storage operations
14
- * - Only saves changed fields, not the entire form state
15
- * - Automatically clears storage when form values match defaults
16
- *
17
- */
18
- export declare const usePersistForm: <T extends FieldValues>({ formName, formContext }: PersistedFormProviderProps<T>) => void;
@@ -1,41 +0,0 @@
1
- export interface PersistedFormProviderProps {
2
- /**
3
- * A unique key for the form
4
- */
5
- formName: string | undefined;
6
- }
7
- /**
8
- * Hook that enables form state persistence across sessions
9
- *
10
- * This hook connects a form to persistent storage (e.g., sessionStorage)
11
- * allowing form values to be preserved when navigating away and returning.
12
- * It works by watching form changes and syncing with a zustand store.
13
- *
14
- * Key features:
15
- * - Persists form values during navigation or page reloads
16
- * - Automatically restores saved values when form is rendered
17
- * - Debounced updates to avoid excessive storage operations
18
- * - Only saves changed fields, not the entire form state
19
- * - Automatically clears storage when form values match defaults
20
- *
21
- * @example
22
- * // In a form component:
23
- * const MyPersistedForm = () => {
24
- * const formMethods = useForm({ defaultValues: { name: '' } });
25
- * // Connect the form to persistence
26
- * usePersistedForm({ formName: 'user-registration' });
27
- *
28
- * return (<FormProvider {...formMethods}>
29
- * <TextFieldElement name="name" label="Name" />
30
- * </FormProvider>);
31
- * }
32
- *
33
- * @example
34
- * // For convenience, use with the PersistForm wrapper component:
35
- * <PersistForm formName="user-profile">
36
- * <ProfileFormFields />
37
- * </PersistForm>
38
- *
39
- * @param props - Configuration options
40
- */
41
- export declare const usePersistedForm: ({ formName }: PersistedFormProviderProps) => void;
@@ -1,20 +0,0 @@
1
- import type { FieldValues } from "react-hook-form";
2
- import { FormStore } from "../types";
3
- /**
4
- * Factory function to create a form store with a custom storage name.
5
- *
6
- * @param storeName - Unique name for sessionStorage/localStorage key.
7
- * @returns Zustand store with form data.
8
- */
9
- export declare const createFormChangeStore: (storeName: string) => import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<FormStore<FieldValues>>, "persist"> & {
10
- persist: {
11
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<FormStore<FieldValues>, unknown>>) => void;
12
- clearStorage: () => void;
13
- rehydrate: () => Promise<void> | void;
14
- hasHydrated: () => boolean;
15
- onHydrate: (fn: (state: FormStore<FieldValues>) => void) => () => void;
16
- onFinishHydration: (fn: (state: FormStore<FieldValues>) => void) => () => void;
17
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<FormStore<FieldValues>, unknown>>;
18
- };
19
- }>;
20
- export default createFormChangeStore;
@@ -1,16 +0,0 @@
1
- /**
2
- * Compares two objects for deep equality.
3
- *
4
- * This function uses lodash's `isEqualWith` function for deep comparison,
5
- * with additional logic for handling numbers and empty values.
6
- *
7
- * @param a The first object to compare.
8
- * @param b The second object to compare.
9
- * @param equalEmpty (default: false) Whether to consider empty values (null, undefined, empty arrays or objects) equal.
10
- * @returns True if the objects are deeply equal, false otherwise.
11
- */
12
- declare const deepCompare: {
13
- <T>(a: T, b: T, equalEmpty?: boolean): boolean;
14
- displayName: string;
15
- };
16
- export default deepCompare;
@@ -1,5 +0,0 @@
1
- declare const hasMaxAttempts: {
2
- (maxAttempts?: number): maxAttempts is number;
3
- displayName: string;
4
- };
5
- export default hasMaxAttempts;
@@ -1,15 +0,0 @@
1
- /**
2
- * A utility type that simplifies complex nested types for better IDE display.
3
- * https://www.totaltypescript.com/concepts/the-prettify-helper
4
- *
5
- * WARNING: This utility strips TSDoc comments from the original type properties.
6
- * Always document the final exported type rather than properties within the type being prettified.
7
- *
8
- * @example
9
- * // Document the final type, not properties inside
10
- * /** Description of MyType *\/
11
- * export type MyType = Prettify<ComplexType>;
12
- */
13
- export type Prettify<T> = {
14
- [K in keyof T]: T[K];
15
- } & {};