autoforma 1.0.4 → 1.0.35
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 +157 -157
- package/dist/index.cjs.js +15 -18
- package/dist/index.es.d.ts +2 -0
- package/dist/index.es.js +5405 -6261
- package/dist/{components → src/components}/AutoForm.d.ts +3 -1
- package/dist/src/components/AutoForm.d.ts.map +1 -0
- package/dist/{components → src/components}/FieldRender.d.ts +1 -0
- package/dist/src/components/FieldRender.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/ArrayField.d.ts +1 -0
- package/dist/src/components/fields/ArrayField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/CheckField.d.ts +1 -0
- package/dist/src/components/fields/CheckField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/DateField.d.ts +1 -0
- package/dist/src/components/fields/DateField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/DateTimeField.d.ts +1 -0
- package/dist/src/components/fields/DateTimeField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/NumberField.d.ts +1 -0
- package/dist/src/components/fields/NumberField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/ObjectField.d.ts +1 -0
- package/dist/src/components/fields/ObjectField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/SelectField.d.ts +1 -0
- package/dist/src/components/fields/SelectField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/TextAreaField.d.ts +1 -0
- package/dist/src/components/fields/TextAreaField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/TextField.d.ts +1 -0
- package/dist/src/components/fields/TextField.d.ts.map +1 -0
- package/dist/{components → src/components}/fields/TimeField.d.ts +1 -0
- package/dist/src/components/fields/TimeField.d.ts.map +1 -0
- package/dist/{index.d.ts → src/index.d.ts} +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/{stories → src/stories}/AutoForm.stories.d.ts +1 -0
- package/dist/src/stories/AutoForm.stories.d.ts.map +1 -0
- package/dist/{stories → src/stories}/Fields.stories.d.ts +1 -0
- package/dist/src/stories/Fields.stories.d.ts.map +1 -0
- package/dist/{theme.d.ts → src/theme.d.ts} +1 -0
- package/dist/src/theme.d.ts.map +1 -0
- package/dist/{types → src/types}/custom-render.d.ts +1 -0
- package/dist/src/types/custom-render.d.ts.map +1 -0
- package/dist/{types → src/types}/field.d.ts +1 -0
- package/dist/src/types/field.d.ts.map +1 -0
- package/dist/{types → src/types}/form.d.ts +1 -0
- package/dist/src/types/form.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +5 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/test-utils/render.d.ts +2 -0
- package/dist/test-utils/render.d.ts.map +1 -0
- package/package.json +65 -22
- package/src/components/AutoForm.tsx +201 -0
- package/src/components/FieldRender.tsx +217 -0
- package/src/components/fields/ArrayField.tsx +59 -0
- package/src/components/fields/CheckField.tsx +23 -0
- package/src/components/fields/DateField.tsx +26 -0
- package/src/components/fields/DateTimeField.tsx +26 -0
- package/src/components/fields/NumberField.tsx +20 -0
- package/src/components/fields/ObjectField.tsx +41 -0
- package/src/components/fields/SelectField.tsx +23 -0
- package/src/components/fields/TextAreaField.tsx +25 -0
- package/src/components/fields/TextField.tsx +20 -0
- package/src/components/fields/TimeField.tsx +32 -0
- package/src/types/custom-render.ts +22 -0
- package/src/types/field.ts +32 -0
- package/src/types/form.ts +8 -0
|
@@ -14,4 +14,6 @@ export interface AutoFormProps {
|
|
|
14
14
|
onFieldChange?: (name: string, value: any, values: Record<string, any>) => Record<string, any>;
|
|
15
15
|
}
|
|
16
16
|
export declare const validateRequiredFields: (schema: FieldSchema[], values: Record<string, any>, parentPath?: string) => Record<string, string>;
|
|
17
|
-
|
|
17
|
+
declare const AutoForm: React.FC<AutoFormProps>;
|
|
18
|
+
export default AutoForm;
|
|
19
|
+
//# sourceMappingURL=AutoForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AutoForm.d.ts","source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,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CA6ErC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -14,3 +14,4 @@ interface FieldRenderProps {
|
|
|
14
14
|
export declare function getArrayOptions(name: string, onChange: (name: string, value: any) => void, value: Record<string, any>[]): ArrayFieldOptions;
|
|
15
15
|
declare const FieldRender: React.FC<FieldRenderProps>;
|
|
16
16
|
export default FieldRender;
|
|
17
|
+
//# sourceMappingURL=FieldRender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldRender.d.ts","sourceRoot":"","sources":["../../../src/components/FieldRender.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAY/D,UAAU,gBAAgB;IACxB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,CAAC,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAC1D,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,KAAK,KAAK,CAAC,SAAS,CAAC;IACvF,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,EAAE,IAAI,CAAC;CACjB;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,EAC5C,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAC3B,iBAAiB,CAgBnB;AAED,QAAA,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAsK3C,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayField.d.ts","sourceRoot":"","sources":["../../../../src/components/fields/ArrayField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5D,UAAU,eAAgB,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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme.ts"],"names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AC9B,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACjD,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IAClE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../../src/types/form.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autoforma",
|
|
3
|
-
"version": "1.0.4",
|
|
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
|
-
],
|
|
18
3
|
"type": "module",
|
|
4
|
+
"version": "1.0.35",
|
|
19
5
|
"homepage": "http://sajinael98.github.io/AutoForma",
|
|
20
6
|
"scripts": {
|
|
21
7
|
"dev": "vite",
|
|
@@ -33,7 +19,8 @@
|
|
|
33
19
|
"storybook": "storybook dev -p 6006",
|
|
34
20
|
"storybook:build": "storybook build",
|
|
35
21
|
"predeploy": "npm run build-storybook",
|
|
36
|
-
"deploy-storybook": "gh-pages -d storybook-static"
|
|
22
|
+
"deploy-storybook": "gh-pages -d storybook-static",
|
|
23
|
+
"build-storybook": "build-storybook"
|
|
37
24
|
},
|
|
38
25
|
"dependencies": {
|
|
39
26
|
"@mantine/core": "7.17.5",
|
|
@@ -43,16 +30,72 @@
|
|
|
43
30
|
"dayjs": "^1.11.13",
|
|
44
31
|
"react": "^19.1.0",
|
|
45
32
|
"react-dom": "^19.1.0",
|
|
46
|
-
"react-router-dom": "^7.4.0"
|
|
33
|
+
"react-router-dom": "^7.4.0",
|
|
34
|
+
"vite-plugin-dts": "^4.5.3"
|
|
47
35
|
},
|
|
48
36
|
"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",
|
|
49
54
|
"@vitejs/plugin-react": "^4.3.4",
|
|
50
|
-
"
|
|
51
|
-
"
|
|
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",
|
|
52
75
|
"typescript": "^5.8.2",
|
|
76
|
+
"typescript-eslint": "^8.27.0",
|
|
77
|
+
"vite": "^6.2.2",
|
|
53
78
|
"vite-tsconfig-paths": "^5.1.4",
|
|
54
|
-
"
|
|
55
|
-
"@types/react-dom": "^19.0.4"
|
|
79
|
+
"vitest": "^3.0.9"
|
|
56
80
|
},
|
|
57
|
-
"packageManager": "yarn@4.9.1"
|
|
81
|
+
"packageManager": "yarn@4.9.1",
|
|
82
|
+
"eslintConfig": {
|
|
83
|
+
"extends": [
|
|
84
|
+
"plugin:storybook/recommended"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
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
|
+
}
|
|
58
101
|
}
|
|
@@ -0,0 +1,201 @@
|
|
|
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;
|