autoforma 1.0.62 β†’ 1.0.64

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/README.md CHANGED
@@ -1,35 +1,32 @@
1
- # πŸš€ AutoForma
1
+ # πŸš€ Introduction
2
2
 
3
- **AutoForma** is a powerful and flexible **dynamic form builder** for React. It allows developers to build complex forms from simple schema definitions without writing repetitive boilerplate code. With AutoForma, you can focus on the logic and behavior of your forms β€” not the UI details.
3
+ **AutoForma** is a modern, dynamic, and extensible **form builder for React** β€” built on top of [Mantine](https://mantine.dev/) and fully written in TypeScript.
4
+ It allows you to create powerful forms **entirely from JSON schema definitions**, removing repetitive boilerplate code and giving you full control over field behavior and layout.
4
5
 
5
- ---
6
-
7
- ## ✨ Features
6
+ With AutoForma, you can:
7
+ - 🧩 Define forms using schema objects β€” no manual wiring.
8
+ - πŸͺ„ Dynamically show, hide, or disable fields based on other values.
9
+ - 🎨 Customize the UI with your own field renderers.
10
+ - 🧠 Extend with new field types or layouts effortlessly.
8
11
 
9
- - ⚑ **Fast form building:** Generate forms instantly from JSON schema.
10
- - 🧩 **Rich field types:** Text, Select, Checkbox, Date, Time, Switch, Tags, Array, Object, and more.
11
- - 🎨 **Full UI control:** Customize how each field looks and behaves.
12
- - πŸ”„ **Dynamic behavior:** Show/hide fields, enable/disable them, or update their properties based on form values.
13
- - πŸͺ„ **Custom renderers:** Replace any field’s renderer with your own component.
14
- - 🧠 **Validation support:** Built-in and custom validation supported out of the box.
15
- - πŸ“ **Multiple layouts:** Vertical, horizontal, or grid layouts.
16
- - πŸ§ͺ **Extendable:** Easily integrate with any backend and add your own field types.
12
+ > πŸ’‘ AutoForma is perfect for dashboards, admin panels, and SaaS apps where flexibility and maintainability matter.
17
13
 
18
14
  ---
19
15
 
20
16
  ## πŸ“¦ Installation
21
17
 
22
- Install AutoForma **and the exact peer dependencies** required for it to work properly:
18
+ Install **AutoForma** along with its required Mantine and React peer dependencies:
23
19
 
24
20
  ```bash
25
- npm install autoforma @mantine/core@^7.17.5 @mantine/hooks@^7.17.5 @mantine/form@^7.17.5 @mantine/dates@^7.17.5 @mantine/tiptap@^7.17.5 @tiptap/react@^3.6.6 react@^18.0.0 react-dom@^18.0.0
21
+ npm install autoforma @mantine/core@^8.3.2 @mantine/hooks@^8.3.2 @mantine/form@^8.3.2 @mantine/dates@^8.3.2 @mantine/tiptap@^8.3.2 @tiptap/react@^3.6.6 react@^19.0.0 react-dom@^19.0.0
26
22
  ```
27
23
 
28
24
  ---
29
25
 
30
- ## βš™οΈ Requirements
26
+ ## βš™οΈ Setup Requirements
31
27
 
32
- Before using `AutoForma`, make sure to wrap your application with `MantineProvider` and import Mantine's base styles:
28
+ Before using `AutoForma`, wrap your app with the `MantineProvider`
29
+ and import Mantine’s global styles and optional TipTap editor styles:
33
30
 
34
31
  ```tsx
35
32
  import { MantineProvider } from "@mantine/core";
@@ -44,243 +41,171 @@ const Root = () => (
44
41
  );
45
42
  ```
46
43
 
47
- > βœ… Without `MantineProvider`, the components might not render or style correctly.
44
+ > ⚠️ Without wrapping your app in `MantineProvider`,
45
+ > the components may not render or style correctly.
48
46
 
49
47
  ---
50
48
 
51
- ## πŸ› οΈ Usage
49
+ # 🧩 Basic Usage
52
50
 
53
- Here's a complete example showing how to use **AutoForma** with a custom field type (`newText`):
51
+ Here’s a quick example of how you can generate a complete form instantly using **AutoForma**.
52
+ Just define your schema and pass it to the `AutoForm` component β€” it handles layout, validation, and submission automatically.
54
53
 
55
54
  ```tsx
56
- import { MantineProvider } from "@mantine/core";
57
- import "@mantine/core/styles.css";
58
- import "@mantine/dates/styles.css";
59
- import "@mantine/tiptap/styles.css";
60
- import ReactDOM from "react-dom/client";
61
55
  import AutoForm from "autoforma";
62
- import { FieldSchema } from "autoforma";
63
-
64
- interface DemoFormValues {
65
- fullName: string;
66
- email: string;
67
- age: number;
68
- subscribe: boolean;
69
- birthDate: string | null;
70
- appointment: string | null;
71
- contacts: { type: string; value: string }[];
72
- gender: string;
73
- bio: string;
74
- }
75
-
76
- const schema: FieldSchema[] = [
77
- {
78
- name: "fullName",
79
- label: "Full Name",
80
- type: "newText",
81
- placeholder: "Enter your full name",
82
- required: true,
83
- },
84
- {
85
- name: "age",
86
- label: "Age",
87
- type: "number",
88
- placeholder: "Enter your age",
89
- },
90
- {
91
- name: "gender",
92
- label: "Gender",
93
- type: "select",
94
- placeholder: "Select your gender",
95
- data: [
96
- { label: "Male", value: "M" },
97
- { label: "Female", value: "F" },
98
- { label: "Prefer not to say", value: "N" },
99
- ],
100
- },
101
- {
102
- name: "subscribe",
103
- label: "Subscribe to newsletter",
104
- type: "checkbox",
105
- description: "Receive updates by email",
106
- },
107
- {
108
- name: "birthDate",
109
- label: "Birth Date",
110
- type: "date",
111
- placeholder: "Pick your birth date",
112
- },
113
- {
114
- name: "appointment",
115
- label: "Appointment",
116
- type: "datetime",
117
- placeholder: "Select date and time",
118
- },
119
- {
120
- name: "contacts",
121
- label: "Contacts",
122
- type: "array",
123
- fields: [
124
- {
125
- name: "type",
126
- label: "Contact Type",
127
- type: "select",
128
- data: [
129
- { label: "Email", value: "email" },
130
- { label: "Phone", value: "phone" },
131
- ],
132
- },
133
- {
134
- name: "value",
135
- label: "Contact Value",
136
- type: "text",
137
- },
138
- ],
139
- },
140
- {
141
- name: "bio",
142
- label: "Bio",
143
- type: "text",
144
- placeholder: "Tell us about yourself",
145
- },
146
- ];
147
-
148
- const App = () => {
149
- return (
150
- <AutoForm<DemoFormValues>
151
- layout="grid"
152
- schema={schema}
153
- customFieldTypes={{
154
- newText: (field, form) => (
155
- <div>
156
- <label htmlFor={field.name}>{field.label}</label>
157
- <input {...form.getInputProps(field.name)} />
158
- </div>
159
- ),
160
- }}
161
- onSubmit={(values) => alert(JSON.stringify(values))}
162
- />
163
- );
164
- };
56
+ import { userFormSchema } from "./schema";
165
57
 
166
- ReactDOM.createRoot(document.getElementById("root")!).render(
167
- <MantineProvider>
168
- <App />
169
- </MantineProvider>
58
+ const App = () => (
59
+ <AutoForm
60
+ schema={userFormSchema}
61
+ onSubmit={(values) => console.log("Submitted:", values)}
62
+ />
170
63
  );
171
64
  ```
172
65
 
173
- ---
174
-
175
- ## πŸ”§ Props / API Reference
176
-
177
- | Prop | Type | Description |
178
- | ----------------------- | -------------------------------------------- | --------------------------------------------------------- |
179
- | `schema` | `FieldSchema[]` | The form schema definition. |
180
- | `values` | `TValues` | Initial form values. |
181
- | `onSubmit` | `(values: TValues) => void` | Callback triggered when the form is submitted. |
182
- | `transformBeforeSubmit` | `(values: TValues) => TValues` | Optional function to transform form values before submit. |
183
- | `transformAfterSubmit` | `(values: TValues) => void \| Promise<void>` | Optional function called after form submission. |
184
- | `validate` | `FormValidateInput<TValues>` | Validation configuration. |
185
- | `readOnly` | `boolean` | Makes the entire form read-only. |
186
- | `onFieldChange` | `OnFieldChangeMap<TValues>` | Trigger callbacks when specific fields change. |
187
- | `layout` | `"vertical" \| "horizontal" \| "grid"` | Form layout type. |
188
- | `customFieldRenderers` | `CustomRenderersMap<TValues>` | Override default field renderers. |
189
- | `customFieldTypes` | `CustomFieldTypes<TValues>` | Add new field types dynamically and render them. |
190
- | `updateFieldSchema` | `UpdateFieldSchemaMap<TValues>` | Dynamically update field definitions based on values. |
191
- | `submitButton` | `boolean \| ReactNode` | Show or customize the submit button. |
66
+ > βœ… AutoForma automatically generates labels, validation, and layouts based on your schema.
192
67
 
193
68
  ---
194
69
 
195
- ## 🧩 Field Types
70
+ # 🎨 Customization & Field Types
196
71
 
197
- AutoForma supports a variety of field types out-of-the-box:
72
+ AutoForma gives you full control over how your form behaves and looks.
73
+ You can **dynamically update field properties** (like visibility, enabled state, or placeholder)
74
+ and even **inject your own custom field types** using `customFieldTypes`.
198
75
 
199
- - `text`
200
- - `number`
201
- - `select`
202
- - `checkbox`
203
- - `date`
204
- - `datetime`
205
- - `time`
206
- - `object`
207
- - `array`
208
- - `switch`
209
- - `texteditor`
210
- - `tags`
76
+ ---
211
77
 
212
- βœ… **Plus any custom type** you add through `customFieldTypes`.
78
+ ## 🧠 Supported Field Types
213
79
 
214
- ---
80
+ Out of the box, AutoForma supports a rich set of field types:
215
81
 
216
- ## βš™οΈ Advanced Usage
82
+ | Type | Description |
83
+ |------|--------------|
84
+ | `text` | Standard text input |
85
+ | `number` | Numeric input |
86
+ | `select` | Dropdown list |
87
+ | `checkbox` | Boolean checkbox |
88
+ | `date` | Date picker |
89
+ | `datetime` | Combined date & time picker |
90
+ | `time` | Time-only picker |
91
+ | `object` | Nested object field (grouped sub-fields) |
92
+ | `array` | Repeating array of fields |
93
+ | `switch` | Toggle switch |
94
+ | `texteditor` | Rich text editor (TipTap powered) |
95
+ | `tags` | Multi-value tag input |
96
+ | `TCustom` | Any custom type you define via `customFieldTypes` |
217
97
 
218
- You can control the behavior of fields dynamically based on form values **and** extend the form with new field types:
98
+ You can define your own type like this:
219
99
 
220
100
  ```tsx
221
101
  <AutoForm
222
102
  schema={schema}
223
- updateFieldSchema={{
224
- gender: (field, values) => {
225
- if (values.age && values.age < 18) {
226
- return { ...field, data: [{ label: "Prefer not to say", value: "N" }] };
227
- }
228
- return field;
229
- },
230
- appointment: (field, values) => ({
231
- ...field,
232
- disabled: !values.birthDate,
233
- }),
234
- }}
235
103
  customFieldTypes={{
236
- newText: (field, form) => (
237
- <div>
238
- <label htmlFor={field.name}>{field.label}</label>
239
- <input {...form.getInputProps(field.name)} />
240
- </div>
104
+ colorPicker: (field, form) => (
105
+ <input
106
+ type="color"
107
+ {...form.getInputProps(field.name)}
108
+ />
241
109
  ),
242
110
  }}
243
111
  />
244
112
  ```
245
113
 
246
- βœ… This gives you full power to:
114
+ ---
247
115
 
248
- - Dynamically adjust schema behavior.
249
- - Inject custom field types without touching the library core.
116
+ # βš™οΈ API Reference
250
117
 
251
- ---
118
+ AutoForma exposes several TypeScript interfaces and configuration objects that make it fully type-safe and flexible.
119
+ Below are the main types you can use to configure and extend the library.
252
120
 
253
- ## πŸ§ͺ Development
121
+ ## 🧩 `AutoFormProps<TValues>`
254
122
 
255
- If you want to contribute or run AutoForma locally:
123
+ The main props accepted by the `AutoForm` component.
256
124
 
257
- ```bash
258
- git clone https://github.com/your-username/AutoForma.git
259
- cd AutoForma
260
- npm install
261
- npm run dev
262
- ```
125
+ ```ts
126
+ export type AutoFormProps<
127
+ TValues extends Record<string, any> = Record<string, any>
128
+ > = CustomRenderersConfig<TValues> & {
129
+ schema: (FieldSchema<TValues> & Record<string, any>)[];
263
130
 
264
- ---
131
+ initialValues?: ValueProvider<TValues>;
132
+ currentValues?: ValueProvider<TValues>;
265
133
 
266
- ## 🀝 Contributing
134
+ prepareValues?: (values: TValues) => TValues | Promise<TValues>;
135
+ onSubmit: (values: TValues) => void | Promise<void>;
136
+ afterSubmit?: (values: TValues) => void | Promise<void>;
267
137
 
268
- Contributions are welcome! πŸŽ‰
269
- If you'd like to help improve AutoForma:
138
+ validate?: FormValidateInput<TValues>;
139
+ readOnly?: boolean;
270
140
 
271
- 1. Fork the repository
272
- 2. Create a new feature branch
273
- 3. Commit your changes
274
- 4. Submit a pull request πŸš€
141
+ onFieldChange?: OnFieldChangeMap<TValues>;
275
142
 
276
- ---
143
+ layout?: "vertical" | "horizontal" | "grid";
277
144
 
278
- ## πŸ“œ License
145
+ updateFieldSchema?: UpdateFieldSchemaMap<TValues>;
279
146
 
280
- This project is licensed under the **MIT License**.
147
+ submitButton?: boolean | React.ReactNode;
148
+
149
+ loading?: boolean;
150
+ };
151
+ ```
152
+
153
+ ### 🧠 Description of Properties
154
+
155
+ | Prop | Type | Description |
156
+ |------|------|--------------|
157
+ | `schema` | `FieldSchema[]` | The main schema defining all form fields. |
158
+ | `initialValues` | `ValueProvider<TValues>` | Function or object returning the **initial form values** (called once). |
159
+ | `currentValues` | `ValueProvider<TValues>` | Function or object providing **current values** (reactively updated). |
160
+ | `prepareValues` | `(values) => TValues \| Promise<TValues>` | Modify or sanitize values before submit. |
161
+ | `onSubmit` | `(values) => void \| Promise<void>` | Called when the form is submitted. |
162
+ | `afterSubmit` | `(values) => void \| Promise<void>` | Called after successful submission (for side effects). |
163
+ | `validate` | `FormValidateInput<TValues>` | Mantine validation config or validation schema. |
164
+ | `readOnly` | `boolean` | Makes the entire form read-only. |
165
+ | `onFieldChange` | `OnFieldChangeMap<TValues>` | Map of field-specific change handlers. |
166
+ | `layout` | `"vertical" \| "horizontal" \| "grid"` | Form layout type. |
167
+ | `updateFieldSchema` | `UpdateFieldSchemaMap<TValues>` | Dynamically modify schema based on values. |
168
+ | `submitButton` | `boolean \| ReactNode` | Whether to render or customize the submit button. |
169
+ | `loading` | `boolean` | Display a global loading state for the form. |
281
170
 
282
171
  ---
283
172
 
284
- ## ⭐ Support
173
+ ## 🧩 `CustomRenderersConfig<TValues>`
174
+
175
+ Defines all the ways you can override the default rendering logic.
176
+
177
+ ```ts
178
+ export type CustomRenderersConfig<
179
+ TValues extends Record<string, any> = Record<string, any>
180
+ > = {
181
+ customFieldRenderers?: Record<
182
+ string,
183
+ (
184
+ field: FieldSchema<TValues>,
185
+ form: UseFormReturnType<TValues>
186
+ ) => React.ReactNode
187
+ >;
188
+ customTypeRenderers?: Record<
189
+ string,
190
+ (
191
+ field: FieldSchema<TValues>,
192
+ form: UseFormReturnType<TValues>
193
+ ) => React.ReactNode
194
+ >;
195
+ customFieldTypes?: Record<
196
+ string,
197
+ (
198
+ field: FieldSchema<TValues>,
199
+ form: UseFormReturnType<TValues>
200
+ ) => React.ReactNode
201
+ >;
202
+ };
203
+ ```
204
+
205
+ ### 🧠 Description of Properties
285
206
 
286
- If you find AutoForma helpful, please consider giving it a ⭐ on [GitHub](https://github.com/your-username/AutoForma) β€” it helps the project grow!
207
+ | Prop | Type | Description |
208
+ |------|------|--------------|
209
+ | `customFieldRenderers` | `Record<string, (field, form) => ReactNode>` | Override rendering for specific **field names**. |
210
+ | `customTypeRenderers` | `Record<string, (field, form) => ReactNode>` | Override rendering for specific **field types** (like `select`, `text`, etc.). |
211
+ | `customFieldTypes` | `Record<string, (field, form) => ReactNode>` | Register completely new **custom field types**. |
@@ -1,11 +1,11 @@
1
1
  import { AutoFormRef } from './AutoForm.types';
2
2
  export declare const AutoForm: import('react').ForwardRefExoticComponent<import('../../fields/renderer.types').CustomRenderersConfig<Record<string, any>> & {
3
- schema: import('../..').FieldSchema<Record<string, any>>[];
4
- values?: Partial<Record<string, any>> | undefined;
5
- getInitialValues?: (() => Partial<Record<string, any>> | Promise<Partial<Record<string, any>>>) | undefined;
3
+ schema: (import('../..').FieldSchema<Record<string, any>> & Record<string, any>)[];
4
+ initialValues?: (() => Partial<Record<string, any>> | Promise<Partial<Record<string, any>>>) | undefined;
5
+ currentValues?: (() => Partial<Record<string, any>> | Promise<Partial<Record<string, any>>>) | undefined;
6
+ prepareValues?: ((values: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>) | undefined;
6
7
  onSubmit: (values: Record<string, any>) => void | Promise<void>;
7
- transformBeforeSubmit?: ((values: Record<string, any>) => Record<string, any> | Promise<Record<string, any>>) | undefined;
8
- transformAfterSubmit?: ((values: Record<string, any>) => void | Promise<void>) | undefined;
8
+ afterSubmit?: ((values: Record<string, any>) => void | Promise<void>) | undefined;
9
9
  validate?: import('@mantine/form').FormValidateInput<Record<string, any>> | undefined;
10
10
  readOnly?: boolean;
11
11
  onFieldChange?: import('./AutoForm.types').OnFieldChangeMap<Record<string, any>> | undefined;
@@ -1,13 +1,14 @@
1
1
  import { CustomRenderersConfig } from '../../fields/renderer.types';
2
2
  import { FieldSchema } from '../../fields/types';
3
3
  import { FormValidateInput, UseFormReturnType } from '@mantine/form';
4
+ type ValueProvider<TValues> = () => Partial<TValues> | Promise<Partial<TValues>>;
4
5
  export type AutoFormProps<TValues extends Record<string, any> = Record<string, any>> = CustomRenderersConfig<TValues> & {
5
- schema: FieldSchema<TValues>[];
6
- values?: Partial<TValues>;
7
- getInitialValues?: () => Partial<TValues> | Promise<Partial<TValues>>;
6
+ schema: (FieldSchema<TValues> & Record<string, any>)[];
7
+ initialValues?: ValueProvider<TValues>;
8
+ currentValues?: ValueProvider<TValues>;
9
+ prepareValues?: (values: TValues) => TValues | Promise<TValues>;
8
10
  onSubmit: (values: TValues) => void | Promise<void>;
9
- transformBeforeSubmit?: (values: TValues) => TValues | Promise<TValues>;
10
- transformAfterSubmit?: (values: TValues) => void | Promise<void>;
11
+ afterSubmit?: (values: TValues) => void | Promise<void>;
11
12
  validate?: FormValidateInput<TValues>;
12
13
  readOnly?: boolean;
13
14
  onFieldChange?: OnFieldChangeMap<TValues>;
@@ -32,4 +33,6 @@ export interface AutoFormRef<TValues extends Record<string, any> = Record<string
32
33
  setFieldValue: (path: string, value: any) => void;
33
34
  isValid: () => boolean;
34
35
  isDirty: () => boolean;
36
+ isLoading: () => boolean;
35
37
  }
38
+ export {};