autoforma 1.0.35 → 1.0.37

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 (62) hide show
  1. package/README.md +157 -157
  2. package/dist/{src/components → components}/AutoForm.d.ts +3 -4
  3. package/dist/{src/components → components}/FieldRender.d.ts +0 -1
  4. package/dist/{src/components → components}/fields/ArrayField.d.ts +0 -1
  5. package/dist/{src/components → components}/fields/CheckField.d.ts +0 -1
  6. package/dist/{src/components → components}/fields/DateField.d.ts +0 -1
  7. package/dist/{src/components → components}/fields/DateTimeField.d.ts +0 -1
  8. package/dist/{src/components → components}/fields/NumberField.d.ts +0 -1
  9. package/dist/{src/components → components}/fields/ObjectField.d.ts +0 -1
  10. package/dist/{src/components → components}/fields/SelectField.d.ts +0 -1
  11. package/dist/{src/components → components}/fields/TextAreaField.d.ts +0 -1
  12. package/dist/{src/components → components}/fields/TextField.d.ts +0 -1
  13. package/dist/{src/components → components}/fields/TimeField.d.ts +0 -1
  14. package/dist/index.cjs.js +15 -55
  15. package/dist/{src/index.d.ts → index.d.ts} +1 -1
  16. package/dist/index.es.js +3588 -12395
  17. package/dist/{src/stories → stories}/AutoForm.stories.d.ts +0 -1
  18. package/dist/{src/stories → stories}/Fields.stories.d.ts +0 -1
  19. package/dist/{src/theme.d.ts → theme.d.ts} +0 -1
  20. package/dist/{src/types → types}/custom-render.d.ts +0 -1
  21. package/dist/{src/types → types}/field.d.ts +2 -2
  22. package/dist/{src/types → types}/form.d.ts +0 -1
  23. package/package.json +27 -68
  24. package/dist/index.es.d.ts +0 -2
  25. package/dist/src/components/AutoForm.d.ts.map +0 -1
  26. package/dist/src/components/FieldRender.d.ts.map +0 -1
  27. package/dist/src/components/fields/ArrayField.d.ts.map +0 -1
  28. package/dist/src/components/fields/CheckField.d.ts.map +0 -1
  29. package/dist/src/components/fields/DateField.d.ts.map +0 -1
  30. package/dist/src/components/fields/DateTimeField.d.ts.map +0 -1
  31. package/dist/src/components/fields/NumberField.d.ts.map +0 -1
  32. package/dist/src/components/fields/ObjectField.d.ts.map +0 -1
  33. package/dist/src/components/fields/SelectField.d.ts.map +0 -1
  34. package/dist/src/components/fields/TextAreaField.d.ts.map +0 -1
  35. package/dist/src/components/fields/TextField.d.ts.map +0 -1
  36. package/dist/src/components/fields/TimeField.d.ts.map +0 -1
  37. package/dist/src/index.d.ts.map +0 -1
  38. package/dist/src/stories/AutoForm.stories.d.ts.map +0 -1
  39. package/dist/src/stories/Fields.stories.d.ts.map +0 -1
  40. package/dist/src/theme.d.ts.map +0 -1
  41. package/dist/src/types/custom-render.d.ts.map +0 -1
  42. package/dist/src/types/field.d.ts.map +0 -1
  43. package/dist/src/types/form.d.ts.map +0 -1
  44. package/dist/test-utils/index.d.ts +0 -5
  45. package/dist/test-utils/index.d.ts.map +0 -1
  46. package/dist/test-utils/render.d.ts +0 -2
  47. package/dist/test-utils/render.d.ts.map +0 -1
  48. package/src/components/AutoForm.tsx +0 -201
  49. package/src/components/FieldRender.tsx +0 -217
  50. package/src/components/fields/ArrayField.tsx +0 -59
  51. package/src/components/fields/CheckField.tsx +0 -23
  52. package/src/components/fields/DateField.tsx +0 -26
  53. package/src/components/fields/DateTimeField.tsx +0 -26
  54. package/src/components/fields/NumberField.tsx +0 -20
  55. package/src/components/fields/ObjectField.tsx +0 -41
  56. package/src/components/fields/SelectField.tsx +0 -23
  57. package/src/components/fields/TextAreaField.tsx +0 -25
  58. package/src/components/fields/TextField.tsx +0 -20
  59. package/src/components/fields/TimeField.tsx +0 -32
  60. package/src/types/custom-render.ts +0 -22
  61. package/src/types/field.ts +0 -32
  62. package/src/types/form.ts +0 -8
@@ -7,4 +7,3 @@ export declare const Standard: Story;
7
7
  export declare const ReadOnly: Story;
8
8
  export declare const FormValidation: Story;
9
9
  export declare const CustomizedForm: Story;
10
- //# sourceMappingURL=AutoForm.stories.d.ts.map
@@ -10,4 +10,3 @@ export declare const CheckField: Story;
10
10
  export declare const DateField: Story;
11
11
  export declare const ArrayField: Story;
12
12
  export declare const ObjectField: Story;
13
- //# sourceMappingURL=Fields.stories.d.ts.map
@@ -139,4 +139,3 @@ export declare const theme: {
139
139
  [x: string]: any;
140
140
  } | undefined;
141
141
  };
142
- //# sourceMappingURL=theme.d.ts.map
@@ -9,4 +9,3 @@ export interface CustomFieldRender {
9
9
  options?: ArrayFieldOptions;
10
10
  readOnly?: true;
11
11
  }
12
- //# sourceMappingURL=custom-render.d.ts.map
@@ -1,4 +1,4 @@
1
- export type FieldType = 'text' | 'number' | 'object' | 'array' | 'check' | 'select' | 'textarea' | 'date' | 'datetime' | 'time';
1
+ export type FieldType = "text" | "number" | "object" | "array" | "check" | "select" | "textarea" | "date" | "datetime" | "time";
2
2
  export interface FieldSchema {
3
3
  name: string;
4
4
  type: FieldType;
@@ -16,6 +16,7 @@ export interface FieldSchema {
16
16
  label: string;
17
17
  value: string;
18
18
  }[];
19
+ meta?: Record<string, any>;
19
20
  }
20
21
  export interface BaseFieldProps<T> {
21
22
  name: string;
@@ -28,4 +29,3 @@ export type ArrayFieldOptions = {
28
29
  replaceElement: (index: number, val: Record<string, any>) => void;
29
30
  removeElement: (index: number) => void;
30
31
  };
31
- //# sourceMappingURL=field.d.ts.map
@@ -5,4 +5,3 @@ export interface FormSchema {
5
5
  formData?: Record<string, any>;
6
6
  initialValues?: Record<string, any>;
7
7
  }
8
- //# sourceMappingURL=form.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "autoforma",
3
+ "version": "1.0.37",
4
+ "description": "AutoForma is a dynamic form builder based on Mantine and React",
5
+ "main": "./dist/index.cjs.js",
6
+ "module": "./dist/index.es.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.es.js",
11
+ "require": "./dist/index.cjs.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
3
18
  "type": "module",
4
- "version": "1.0.35",
5
19
  "homepage": "http://sajinael98.github.io/AutoForma",
6
20
  "scripts": {
7
21
  "dev": "vite",
@@ -19,83 +33,28 @@
19
33
  "storybook": "storybook dev -p 6006",
20
34
  "storybook:build": "storybook build",
21
35
  "predeploy": "npm run build-storybook",
22
- "deploy-storybook": "gh-pages -d storybook-static",
23
- "build-storybook": "build-storybook"
36
+ "deploy-storybook": "gh-pages -d storybook-static"
24
37
  },
25
38
  "dependencies": {
26
- "@mantine/core": "7.17.5",
27
39
  "@mantine/dates": "^7.17.5",
28
40
  "@mantine/form": "^7.17.5",
29
- "@mantine/hooks": "7.17.5",
30
41
  "dayjs": "^1.11.13",
31
- "react": "^19.1.0",
32
- "react-dom": "^19.1.0",
33
- "react-router-dom": "^7.4.0",
34
- "vite-plugin-dts": "^4.5.3"
42
+ "react-router-dom": "^7.4.0"
35
43
  },
36
44
  "devDependencies": {
37
- "@chromatic-com/storybook": "^3.2.6",
38
- "@eslint/js": "^9.23.0",
39
- "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
40
- "@storybook/addon-essentials": "^8.6.12",
41
- "@storybook/addon-onboarding": "^8.6.12",
42
- "@storybook/blocks": "^8.6.12",
43
- "@storybook/experimental-addon-test": "^8.6.12",
44
- "@storybook/react": "^8.6.8",
45
- "@storybook/react-vite": "^8.6.8",
46
- "@storybook/test": "^8.6.12",
47
- "@testing-library/dom": "^10.4.0",
48
- "@testing-library/jest-dom": "^6.6.3",
49
- "@testing-library/react": "^16.2.0",
50
- "@testing-library/user-event": "^14.6.1",
51
- "@types/node": "^22.13.11",
52
- "@types/react": "^19.0.12",
53
- "@types/react-dom": "^19.0.4",
45
+ "@types/react": "^18.3.1",
46
+ "@types/react-dom": "^18.3.1",
54
47
  "@vitejs/plugin-react": "^4.3.4",
55
- "@vitest/browser": "^3.1.2",
56
- "@vitest/coverage-v8": "^3.1.2",
57
- "eslint": "^9.23.0",
58
- "eslint-config-mantine": "^4.0.3",
59
- "eslint-plugin-jsx-a11y": "^6.10.2",
60
- "eslint-plugin-react": "^7.37.4",
61
- "eslint-plugin-storybook": "^0.12.0",
62
- "gh-pages": "^6.3.0",
63
- "identity-obj-proxy": "^3.0.0",
64
- "jsdom": "^26.0.0",
65
- "playwright": "^1.52.0",
66
- "postcss": "^8.5.3",
67
- "postcss-preset-mantine": "1.17.0",
68
- "postcss-simple-vars": "^7.0.1",
69
- "prettier": "^3.5.3",
70
- "prop-types": "^15.8.1",
71
- "storybook": "^8.6.8",
72
- "storybook-dark-mode": "^4.0.2",
73
- "stylelint": "^16.16.0",
74
- "stylelint-config-standard-scss": "^14.0.0",
48
+ "postcss-preset-mantine": "^1.17.0",
75
49
  "typescript": "^5.8.2",
76
- "typescript-eslint": "^8.27.0",
77
50
  "vite": "^6.2.2",
78
- "vite-tsconfig-paths": "^5.1.4",
79
- "vitest": "^3.0.9"
51
+ "vite-plugin-dts": "^4.5.3",
52
+ "vite-tsconfig-paths": "^5.1.4"
80
53
  },
81
- "packageManager": "yarn@4.9.1",
82
- "eslintConfig": {
83
- "extends": [
84
- "plugin:storybook/recommended"
85
- ]
54
+ "peerDependencies": {
55
+ "@mantine/core": "^7.17.5",
56
+ "react": "^18.0.0",
57
+ "react-dom": "^18.0.0"
86
58
  },
87
- "files": [
88
- "dist",
89
- "src/components",
90
- "src/types",
91
- "README.md"
92
- ],
93
- "main": "dist/index.js",
94
- "module": "dist/index.mjs",
95
- "exports": {
96
- ".": {
97
- "import": "./dist/index.mjs",
98
- "require": "./dist/index.js"
99
- }
100
- }
59
+ "packageManager": "yarn@4.9.1"
101
60
  }
@@ -1,2 +0,0 @@
1
- export * from './src/index'
2
- export {}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AutoForm.d.ts","sourceRoot":"","sources":["../../../src/components/AutoForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAqB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,MAA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,SAAQ,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IACrE,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE;QACP,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;QAC/C,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;QAClE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;KACxC,CAAC;IACF,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CACzC;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAwCzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CheckField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/CheckField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,eAAgB,SAAQ,cAAc,CAAC,OAAO,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,QAAA,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYzC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"DateField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/DateField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,UAAU,cAAe,SAAQ,cAAc,CAAC,IAAI,CAAC;CAAG;AAExD,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAavC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"DateTimeField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/DateTimeField.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAI/C,UAAU,kBAAmB,SAAQ,cAAc,CAAC,IAAI,CAAC;CAAG;AAE5D,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAa/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"NumberField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/NumberField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;CAAG;AAE5D,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAW3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"ObjectField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/ObjectField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5D,UAAU,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpE,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;CACzC;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CA2B3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/SelectField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;IACvD,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC1C;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAY3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextAreaField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/TextAreaField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,kBAAmB,SAAQ,cAAc,CAAC,MAAM,CAAC;CAAG;AAE9D,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAgB/C,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/TextField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,cAAe,SAAQ,cAAc,CAAC,MAAM,CAAC;CAAG;AAE1D,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAWvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TimeField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/TimeField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,UAAU,cAAe,SAAQ,cAAc,CAAC,MAAM,CAAC;CAAG;AAE1D,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CAsBvC,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AutoForm.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/AutoForm.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAM7C,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAyGvD,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,QAAQ,CAsL/B,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEvC,eAAO,MAAM,QAAQ,EAAE,KAAU,CAAC;AAElC,eAAO,MAAM,QAAQ,EAAE,KAEtB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAgB5B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KA2D5B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Fields.stories.d.ts","sourceRoot":"","sources":["../../../src/stories/Fields.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AA+F7C,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,QAAQ,CA0C/B,CAAC;AAEF,eAAe,IAAI,CAAC;AAMpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,QAAQ,CAAC,CAAC;AAEvC,eAAO,MAAM,SAAS,EAAE,KAIvB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAIzB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAIzB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAIxB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAIvB,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAIxB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAIzB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAEhB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"custom-render.d.ts","sourceRoot":"","sources":["../../../src/types/custom-render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD,MAAM,MAAM,uBAAuB,GAAG,CACpC,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,GAAG,EACV,KAAK,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,EACxD,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAC5C,UAAU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AAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrC"}
@@ -1,5 +0,0 @@
1
- import { default as userEvent } from '@testing-library/user-event';
2
- export * from '@testing-library/react';
3
- export { render } from './render';
4
- export { userEvent };
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../test-utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function render(ui: React.ReactNode): import('@testing-library/react').RenderResult<typeof import("@testing-library/dom/types/queries"), HTMLElement, HTMLElement>;
2
- //# sourceMappingURL=render.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../test-utils/render.tsx"],"names":[],"mappings":"AAIA,wBAAgB,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,gIAMzC"}
@@ -1,201 +0,0 @@
1
- import React, { useCallback, useEffect, useMemo } from 'react';
2
- import { createFormContext, FormValidateInput } from '@mantine/form';
3
- import { useDebouncedCallback } from '@mantine/hooks';
4
- import { FieldRenderCustomRender } from '@/types/custom-render';
5
- import { FieldSchema, FieldType } from '@/types/field';
6
- import FieldRender from './FieldRender';
7
-
8
-
9
- export interface AutoFormProps {
10
- values?: Record<string, any>;
11
- schema: FieldSchema[];
12
- onSubmit: (values: Record<string, any>) => void;
13
- container: (Form: React.ReactNode, onSubmit: VoidFunction, readOnly?: true) => React.ReactNode;
14
- fieldContainer?: (field: React.ReactNode, fieldSchema: FieldSchema) => React.ReactNode;
15
- customRender?: FieldRenderCustomRender;
16
- validate?: FormValidateInput<Record<string, any>>;
17
- readOnly?: true;
18
- onFieldChange?: (name: string, value: any, values: Record<string, any>) => Record<string, any>;
19
- }
20
-
21
- const [FormProvider, _, useForm] = createFormContext<Record<string, any>>();
22
-
23
- const getDefaultValueForField = (type: FieldType): any => {
24
- switch (type) {
25
- case 'number':
26
- return 0;
27
- case 'array':
28
- return [];
29
- case 'check':
30
- return false;
31
- case 'object':
32
- return {};
33
- case 'select':
34
- case 'date':
35
- case 'datetime':
36
- return null;
37
- default:
38
- return '';
39
- }
40
- };
41
-
42
- const generateInitialValues = (schema: FieldSchema[]): Record<string, any> => {
43
- const result: Record<string, any> = {};
44
-
45
- for (const field of schema) {
46
- if (field.type === 'object' && field.fields) {
47
- result[field.name] = generateInitialValues(field.fields);
48
- } else {
49
- result[field.name] = field.initialValue ?? getDefaultValueForField(field.type);
50
- }
51
- }
52
-
53
- return result;
54
- };
55
-
56
- const isValueEmpty = (value: any): boolean => {
57
- return (
58
- value === null ||
59
- value === undefined ||
60
- (typeof value === 'string' && value.trim() === '') ||
61
- (Array.isArray(value) && value.length === 0)
62
- );
63
- };
64
-
65
- export const validateRequiredFields = (
66
- schema: FieldSchema[],
67
- values: Record<string, any>,
68
- parentPath = ''
69
- ): Record<string, string> => {
70
- const errors: Record<string, string> = {};
71
-
72
- for (const field of schema) {
73
- const fullName = parentPath ? `${parentPath}.${field.name}` : field.name;
74
- const fieldValue = values?.[field.name];
75
-
76
- if (field.type === 'object') {
77
- Object.assign(errors, validateRequiredFields(field.fields, fieldValue || {}, fullName));
78
- } else if (field.type === 'array') {
79
- if (field.required && (!Array.isArray(fieldValue) || fieldValue.length === 0)) {
80
- errors[fullName] = field.name + ' is required';
81
- continue;
82
- }
83
-
84
- if (Array.isArray(fieldValue)) {
85
- fieldValue.forEach((item, index) => {
86
- Object.assign(errors, validateRequiredFields(field.fields, item, `${fullName}.${index}`));
87
- });
88
- }
89
- } else if (field.required && isValueEmpty(fieldValue)) {
90
- errors[fullName] = field.name + ' is required';
91
- }
92
- }
93
-
94
- return errors;
95
- };
96
-
97
- function buildErrorObject(flatErrors) {
98
- const error = {};
99
-
100
- Object.entries(flatErrors).forEach(([key, value]) => {
101
- const keys = key.split('.');
102
- let curr: Record<string, string> = error;
103
-
104
- keys.forEach((subKey, index) => {
105
- const isLast = index === keys.length - 1;
106
- const nextKey = keys[index + 1];
107
-
108
- if (isLast) {
109
- curr[subKey] = value;
110
- } else {
111
- if (!(subKey in curr)) {
112
- curr[subKey] = {};
113
- }
114
- curr = curr[subKey];
115
- }
116
- });
117
- });
118
-
119
- return error;
120
- }
121
-
122
- const AutoForm: React.FC<AutoFormProps> = ({
123
- onSubmit,
124
- schema,
125
- container,
126
- fieldContainer,
127
- customRender,
128
- validate,
129
- readOnly,
130
- values,
131
- onFieldChange,
132
- }) => {
133
- const form = useForm({
134
- mode: 'uncontrolled',
135
- initialValues: generateInitialValues(schema),
136
- validate,
137
- });
138
-
139
- const formValues = useMemo(() => form.getValues(), [form.getValues()]);
140
-
141
- const onChange = useDebouncedCallback((name: string, value: any) => {
142
- form.setFieldValue(name, value);
143
- if (onFieldChange) {
144
- const updates = onFieldChange(name, value, formValues);
145
- form.setValues(updates);
146
- }
147
- }, 0);
148
-
149
- const getFieldError = useCallback(
150
- (type: FieldType, name: string) => {
151
- const errors = form.errors;
152
-
153
- if (type === 'object' || type === 'array') {
154
- return buildErrorObject(errors)[name];
155
- }
156
-
157
- return errors[name];
158
- },
159
- [form.errors]
160
- );
161
-
162
- const handleSubmit = useCallback(() => {
163
- const currentValues = form.getValues();
164
- const errors = validateRequiredFields(schema, currentValues);
165
-
166
- if (Object.keys(errors).length > 0) {
167
- form.setErrors(errors);
168
- return;
169
- }
170
-
171
- form.onSubmit(onSubmit)();
172
- }, [form, onSubmit, schema]);
173
-
174
- useEffect(() => {
175
- if (values) {
176
- form.initialize(values);
177
- }
178
- }, [values]);
179
-
180
- const content = (
181
- <FormProvider form={form}>
182
- {schema.map((field, index) => (
183
- <FieldRender
184
- key={index}
185
- field={field}
186
- formValues={formValues}
187
- value={formValues[field.name]}
188
- error={getFieldError(field.type, field.name)}
189
- onChange={onChange}
190
- fieldContainer={fieldContainer}
191
- customRender={customRender}
192
- readOnly={field.readOnly || readOnly}
193
- />
194
- ))}
195
- </FormProvider>
196
- );
197
-
198
- return container(content, handleSubmit, readOnly);
199
- };
200
-
201
- export default AutoForm;