@coding-form/form-engine 0.0.1
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/LICENSE +201 -0
- package/README.md +23 -0
- package/dist/context/form-context.d.ts +25 -0
- package/dist/context/form-context.js +44 -0
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.js +1 -0
- package/dist/event/event-context.d.ts +10 -0
- package/dist/event/event-context.js +35 -0
- package/dist/event/index.d.ts +1 -0
- package/dist/event/index.js +1 -0
- package/dist/factory/index.d.ts +13 -0
- package/dist/factory/index.js +51 -0
- package/dist/form/index.d.ts +8 -0
- package/dist/form/index.js +37 -0
- package/dist/form/sub-view.d.ts +8 -0
- package/dist/form/sub-view.js +29 -0
- package/dist/hooks/create-form-instance.d.ts +3 -0
- package/dist/hooks/create-form-instance.js +3 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/hooks/index.js +3 -0
- package/dist/hooks/register-form-items.d.ts +8 -0
- package/dist/hooks/register-form-items.js +14 -0
- package/dist/hooks/use-form-context.d.ts +7 -0
- package/dist/hooks/use-form-context.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/instance/control.d.ts +14 -0
- package/dist/instance/control.js +40 -0
- package/dist/instance/index.d.ts +24 -0
- package/dist/instance/index.js +72 -0
- package/dist/layout/default-layout.d.ts +5 -0
- package/dist/layout/default-layout.js +10 -0
- package/dist/layout/index.d.ts +8 -0
- package/dist/layout/index.js +35 -0
- package/dist/presenters/form-presenter.d.ts +14 -0
- package/dist/presenters/form-presenter.js +124 -0
- package/dist/presenters/index.d.ts +1 -0
- package/dist/presenters/index.js +1 -0
- package/dist/register/form.d.ts +11 -0
- package/dist/register/form.js +20 -0
- package/dist/register/index.d.ts +2 -0
- package/dist/register/index.js +2 -0
- package/dist/register/layout.d.ts +10 -0
- package/dist/register/layout.js +18 -0
- package/dist/store/index.d.ts +15 -0
- package/dist/store/index.js +24 -0
- package/dist/types/dispatch.d.ts +4 -0
- package/dist/types/dispatch.js +0 -0
- package/dist/types/event.d.ts +10 -0
- package/dist/types/event.js +0 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +8 -0
- package/dist/types/item.d.ts +31 -0
- package/dist/types/item.js +0 -0
- package/dist/types/layout.d.ts +17 -0
- package/dist/types/layout.js +0 -0
- package/dist/types/state.d.ts +10 -0
- package/dist/types/state.js +5 -0
- package/dist/types/types.d.ts +16 -0
- package/dist/types/types.js +23 -0
- package/dist/types/validate.d.ts +11 -0
- package/dist/types/validate.js +0 -0
- package/dist/types/view.d.ts +80 -0
- package/dist/types/view.js +0 -0
- package/dist/validate/index.d.ts +15 -0
- package/dist/validate/index.js +53 -0
- package/package.json +43 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
class FormControl {
|
|
2
|
+
formCode;
|
|
3
|
+
proxyTarget;
|
|
4
|
+
constructor(formCode, target){
|
|
5
|
+
this.formCode = formCode;
|
|
6
|
+
this.proxyTarget = target;
|
|
7
|
+
}
|
|
8
|
+
getFormCode() {
|
|
9
|
+
return this.formCode;
|
|
10
|
+
}
|
|
11
|
+
getProxyTarget() {
|
|
12
|
+
return this.proxyTarget;
|
|
13
|
+
}
|
|
14
|
+
getFieldValue(name) {
|
|
15
|
+
return this.proxyTarget.getFieldValue(name);
|
|
16
|
+
}
|
|
17
|
+
getFieldsValue() {
|
|
18
|
+
return this.proxyTarget.getFieldsValue();
|
|
19
|
+
}
|
|
20
|
+
resetFields(nameList) {
|
|
21
|
+
this.proxyTarget.resetFields(nameList);
|
|
22
|
+
}
|
|
23
|
+
setFieldsValue(values) {
|
|
24
|
+
this.proxyTarget.setFieldsValue(values);
|
|
25
|
+
}
|
|
26
|
+
setFieldValue(name, value) {
|
|
27
|
+
this.proxyTarget.setFieldValue(name, value);
|
|
28
|
+
}
|
|
29
|
+
submit() {
|
|
30
|
+
this.proxyTarget.submit();
|
|
31
|
+
}
|
|
32
|
+
validateFields(nameList) {
|
|
33
|
+
return new Promise((resolve, reject)=>{
|
|
34
|
+
this.proxyTarget.validateFields(nameList).then((values)=>{
|
|
35
|
+
resolve(values);
|
|
36
|
+
}).catch(reject);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export { FormControl };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FormMeta } from "../types";
|
|
2
|
+
import { FormControl } from "./control";
|
|
3
|
+
import { FormPresenter } from "../presenters";
|
|
4
|
+
export declare class FormInstance {
|
|
5
|
+
private readonly instanceList;
|
|
6
|
+
private readonly meta;
|
|
7
|
+
private presenter;
|
|
8
|
+
constructor(meta: FormMeta);
|
|
9
|
+
private createInstance;
|
|
10
|
+
setPresenter(presenter: FormPresenter): void;
|
|
11
|
+
private initInstanceList;
|
|
12
|
+
getFormControl(formCode?: string): FormControl | undefined;
|
|
13
|
+
getProxyTarget(formCode?: string): any;
|
|
14
|
+
getFieldValue(name: string, formCode?: string): void;
|
|
15
|
+
getFieldsValue(formCode?: string): any;
|
|
16
|
+
resetFields(nameList?: string[], formCode?: string): void;
|
|
17
|
+
setFieldsValue(values: any, formCode?: string): void;
|
|
18
|
+
setFieldValue(name: string, value: any, formCode?: string): void;
|
|
19
|
+
submit(formCode?: string): void;
|
|
20
|
+
validateFields(nameList?: string[], formCode?: string): Promise<any>;
|
|
21
|
+
hiddenFields(hidden: boolean, nameList: string[] | string, formCode?: string): void;
|
|
22
|
+
requiredFields(required: boolean, nameList: string[] | string, formCode?: string): void;
|
|
23
|
+
refreshFields(nameList: string[] | string, formCode?: string): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FormRegistry } from "../register/index.js";
|
|
2
|
+
import { FormControl } from "./control.js";
|
|
3
|
+
class FormInstance {
|
|
4
|
+
instanceList;
|
|
5
|
+
meta;
|
|
6
|
+
presenter;
|
|
7
|
+
constructor(meta){
|
|
8
|
+
this.meta = meta;
|
|
9
|
+
this.instanceList = [];
|
|
10
|
+
this.initInstanceList();
|
|
11
|
+
}
|
|
12
|
+
createInstance(formCode) {
|
|
13
|
+
const form = FormRegistry.getInstance().getFormInstance()?.();
|
|
14
|
+
if (!form) throw new Error('Form Instance must register.');
|
|
15
|
+
return new FormControl(formCode, form);
|
|
16
|
+
}
|
|
17
|
+
setPresenter(presenter) {
|
|
18
|
+
this.presenter = presenter;
|
|
19
|
+
}
|
|
20
|
+
initInstanceList() {
|
|
21
|
+
const formList = [];
|
|
22
|
+
formList.push(this.meta);
|
|
23
|
+
const subFormList = this.meta.subForms || [];
|
|
24
|
+
for (const subForm of subFormList)formList.push(subForm);
|
|
25
|
+
for (const subForm of formList)this.instanceList.push(this.createInstance(subForm.code));
|
|
26
|
+
}
|
|
27
|
+
getFormControl(formCode) {
|
|
28
|
+
if (formCode) {
|
|
29
|
+
for (const item of this.instanceList)if (item.getFormCode() === formCode) return item;
|
|
30
|
+
} else if (this.instanceList.length > 0) return this.instanceList[0];
|
|
31
|
+
}
|
|
32
|
+
getProxyTarget(formCode) {
|
|
33
|
+
return this.getFormControl(formCode)?.getProxyTarget();
|
|
34
|
+
}
|
|
35
|
+
getFieldValue(name, formCode) {
|
|
36
|
+
this.getFormControl(formCode)?.getFieldValue(name);
|
|
37
|
+
}
|
|
38
|
+
getFieldsValue(formCode) {
|
|
39
|
+
return this.getFormControl(formCode)?.getFieldsValue();
|
|
40
|
+
}
|
|
41
|
+
resetFields(nameList, formCode) {
|
|
42
|
+
this.getFormControl(formCode)?.resetFields(nameList);
|
|
43
|
+
}
|
|
44
|
+
setFieldsValue(values, formCode) {
|
|
45
|
+
this.getFormControl(formCode)?.setFieldsValue(values);
|
|
46
|
+
}
|
|
47
|
+
setFieldValue(name, value, formCode) {
|
|
48
|
+
this.getFormControl(formCode)?.setFieldValue(name, value);
|
|
49
|
+
}
|
|
50
|
+
submit(formCode) {
|
|
51
|
+
this.getFormControl(formCode)?.submit();
|
|
52
|
+
}
|
|
53
|
+
validateFields(nameList, formCode) {
|
|
54
|
+
const formControl = this.getFormControl(formCode);
|
|
55
|
+
if (formControl) return formControl.validateFields(nameList);
|
|
56
|
+
return new Promise((resolve, reject)=>{
|
|
57
|
+
resolve({
|
|
58
|
+
message: 'no found form instance.'
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
hiddenFields(hidden, nameList, formCode) {
|
|
63
|
+
this.presenter?.hiddenFields(hidden, nameList, formCode);
|
|
64
|
+
}
|
|
65
|
+
requiredFields(required, nameList, formCode) {
|
|
66
|
+
this.presenter?.requiredFields(required, nameList, formCode);
|
|
67
|
+
}
|
|
68
|
+
refreshFields(nameList, formCode) {
|
|
69
|
+
this.presenter?.refreshFields(nameList, formCode);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export { FormInstance };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { FormItemFactory } from "../factory/index.js";
|
|
3
|
+
const DefaultLayout = (props)=>{
|
|
4
|
+
const fields = props.fields;
|
|
5
|
+
const formCode = props.formCode;
|
|
6
|
+
const review = props.review;
|
|
7
|
+
const context = props.context;
|
|
8
|
+
return /*#__PURE__*/ react.createElement(react.Fragment, null, fields.map((field)=>FormItemFactory.getInstance().render(formCode, field, 'vertical', review, context)));
|
|
9
|
+
};
|
|
10
|
+
export { DefaultLayout };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormField, FormLayout } from "../types";
|
|
2
|
+
import { FormContextScope } from "../context";
|
|
3
|
+
export declare class LayoutContext {
|
|
4
|
+
private readonly layouts;
|
|
5
|
+
constructor(layouts: FormLayout[]);
|
|
6
|
+
getLayouts(formCode: string): FormLayout[];
|
|
7
|
+
render(formCode: string, fields: FormField[], review: boolean, context: FormContextScope): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import { LayoutRegister } from "../register/layout.js";
|
|
3
|
+
import { DefaultLayout } from "./default-layout.js";
|
|
4
|
+
class LayoutContext {
|
|
5
|
+
layouts;
|
|
6
|
+
constructor(layouts){
|
|
7
|
+
this.layouts = layouts;
|
|
8
|
+
}
|
|
9
|
+
getLayouts(formCode) {
|
|
10
|
+
const layouts = [];
|
|
11
|
+
for (const layout of this.layouts)if (layout.formCode === formCode) layouts.push(layout);
|
|
12
|
+
return layouts;
|
|
13
|
+
}
|
|
14
|
+
render(formCode, fields, review, context) {
|
|
15
|
+
const layouts = this.getLayouts(formCode);
|
|
16
|
+
if (layouts && layouts.length > 0) return /*#__PURE__*/ react.createElement(react.Fragment, null, layouts.map((layout)=>{
|
|
17
|
+
const LayoutComponent = LayoutRegister.getInstance().getLayoutComponent(layout.type);
|
|
18
|
+
console.log('LayoutComponent', layout);
|
|
19
|
+
if (LayoutComponent) return /*#__PURE__*/ react.createElement(LayoutComponent, {
|
|
20
|
+
layout: layout,
|
|
21
|
+
fields: fields,
|
|
22
|
+
review: review,
|
|
23
|
+
context: context,
|
|
24
|
+
formCode: formCode
|
|
25
|
+
});
|
|
26
|
+
}));
|
|
27
|
+
return /*#__PURE__*/ react.createElement(DefaultLayout, {
|
|
28
|
+
fields: fields,
|
|
29
|
+
review: review,
|
|
30
|
+
context: context,
|
|
31
|
+
formCode: formCode
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { LayoutContext };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Dispatch, FormMeta, FormState } from "../types";
|
|
2
|
+
export declare class FormPresenter {
|
|
3
|
+
private state;
|
|
4
|
+
private readonly dispatch;
|
|
5
|
+
constructor(state: FormState, dispatch: Dispatch<FormState>);
|
|
6
|
+
syncState(state: FormState): void;
|
|
7
|
+
initialState(meta: FormMeta): void;
|
|
8
|
+
hiddenFields(hidden: boolean, nameList: string[] | string, formCode?: string): void;
|
|
9
|
+
refreshFields(nameList: string[] | string, formCode?: string): void;
|
|
10
|
+
requiredFields(required: boolean, nameList: string[] | string, formCode?: string): void;
|
|
11
|
+
private hiddenMapFields;
|
|
12
|
+
private refreshMapFields;
|
|
13
|
+
private requiredMapFields;
|
|
14
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
class FormPresenter {
|
|
2
|
+
state;
|
|
3
|
+
dispatch;
|
|
4
|
+
constructor(state, dispatch){
|
|
5
|
+
this.state = state;
|
|
6
|
+
this.dispatch = dispatch;
|
|
7
|
+
}
|
|
8
|
+
syncState(state) {
|
|
9
|
+
this.state = state;
|
|
10
|
+
}
|
|
11
|
+
initialState(meta) {
|
|
12
|
+
this.state = meta;
|
|
13
|
+
this.dispatch(meta);
|
|
14
|
+
}
|
|
15
|
+
hiddenFields(hidden, nameList, formCode) {
|
|
16
|
+
this.dispatch((prevState)=>{
|
|
17
|
+
const subFormList = prevState.subForms || [];
|
|
18
|
+
return {
|
|
19
|
+
...prevState,
|
|
20
|
+
fields: prevState.fields.map((item)=>{
|
|
21
|
+
if (!formCode) return this.hiddenMapFields(hidden, item, nameList);
|
|
22
|
+
if (formCode === prevState.code) return this.hiddenMapFields(hidden, item, nameList);
|
|
23
|
+
return item;
|
|
24
|
+
}),
|
|
25
|
+
subForms: subFormList.map((item)=>{
|
|
26
|
+
if (formCode) {
|
|
27
|
+
if (formCode === item.code) return {
|
|
28
|
+
...item,
|
|
29
|
+
fields: item.fields.map((item)=>this.hiddenMapFields(hidden, item, nameList))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return item;
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
refreshFields(nameList, formCode) {
|
|
38
|
+
this.dispatch((prevState)=>{
|
|
39
|
+
const subFormList = prevState.subForms || [];
|
|
40
|
+
return {
|
|
41
|
+
...prevState,
|
|
42
|
+
fields: prevState.fields.map((item)=>{
|
|
43
|
+
if (!formCode) return this.refreshMapFields(item, nameList);
|
|
44
|
+
if (formCode === prevState.code) return this.refreshMapFields(item, nameList);
|
|
45
|
+
return item;
|
|
46
|
+
}),
|
|
47
|
+
subForms: subFormList.map((item)=>{
|
|
48
|
+
if (formCode) {
|
|
49
|
+
if (formCode === item.code) return {
|
|
50
|
+
...item,
|
|
51
|
+
fields: item.fields.map((item)=>this.refreshMapFields(item, nameList))
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return item;
|
|
55
|
+
})
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
requiredFields(required, nameList, formCode) {
|
|
60
|
+
this.dispatch((prevState)=>{
|
|
61
|
+
const subFormList = prevState.subForms || [];
|
|
62
|
+
return {
|
|
63
|
+
...prevState,
|
|
64
|
+
fields: prevState.fields.map((item)=>{
|
|
65
|
+
if (!formCode) return this.requiredMapFields(required, item, nameList);
|
|
66
|
+
if (formCode === prevState.code) return this.requiredMapFields(required, item, nameList);
|
|
67
|
+
return item;
|
|
68
|
+
}),
|
|
69
|
+
subForms: subFormList.map((item)=>{
|
|
70
|
+
if (formCode) {
|
|
71
|
+
if (formCode === item.code) return {
|
|
72
|
+
...item,
|
|
73
|
+
fields: item.fields.map((item)=>this.requiredMapFields(required, item, nameList))
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return item;
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
hiddenMapFields(hidden, field, nameList) {
|
|
82
|
+
if ('string' == typeof nameList) {
|
|
83
|
+
if (field.code === nameList) return {
|
|
84
|
+
...field,
|
|
85
|
+
hidden: hidden
|
|
86
|
+
};
|
|
87
|
+
} else if (nameList.includes(field.code)) return {
|
|
88
|
+
...field,
|
|
89
|
+
hidden: hidden
|
|
90
|
+
};
|
|
91
|
+
return field;
|
|
92
|
+
}
|
|
93
|
+
refreshMapFields(field, nameList) {
|
|
94
|
+
if ('string' == typeof nameList) {
|
|
95
|
+
if (field.code === nameList) {
|
|
96
|
+
const version = field.version ? field.version : 0;
|
|
97
|
+
return {
|
|
98
|
+
...field,
|
|
99
|
+
version: version + 1
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
} else if (nameList.includes(field.code)) {
|
|
103
|
+
const version = field.version ? field.version : 0;
|
|
104
|
+
return {
|
|
105
|
+
...field,
|
|
106
|
+
version: version + 1
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return field;
|
|
110
|
+
}
|
|
111
|
+
requiredMapFields(required, field, nameList) {
|
|
112
|
+
if ('string' == typeof nameList) {
|
|
113
|
+
if (field.code === nameList) return {
|
|
114
|
+
...field,
|
|
115
|
+
required: required
|
|
116
|
+
};
|
|
117
|
+
} else if (nameList.includes(field.code)) return {
|
|
118
|
+
...field,
|
|
119
|
+
required: required
|
|
120
|
+
};
|
|
121
|
+
return field;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export { FormPresenter };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./form-presenter";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./form-presenter.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare class FormRegistry {
|
|
3
|
+
private formComponent;
|
|
4
|
+
private formInstance;
|
|
5
|
+
private constructor();
|
|
6
|
+
private static readonly instance;
|
|
7
|
+
static getInstance(): FormRegistry;
|
|
8
|
+
register(formComponent: React.ComponentType<any>, formInstance: () => any): void;
|
|
9
|
+
getFormComponent(): React.ComponentType<any> | undefined;
|
|
10
|
+
getFormInstance(): (() => any) | undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
class FormRegistry {
|
|
3
|
+
formComponent;
|
|
4
|
+
formInstance;
|
|
5
|
+
static instance = new FormRegistry();
|
|
6
|
+
static getInstance() {
|
|
7
|
+
return this.instance;
|
|
8
|
+
}
|
|
9
|
+
register(formComponent, formInstance) {
|
|
10
|
+
this.formComponent = formComponent;
|
|
11
|
+
this.formInstance = formInstance;
|
|
12
|
+
}
|
|
13
|
+
getFormComponent() {
|
|
14
|
+
return this.formComponent;
|
|
15
|
+
}
|
|
16
|
+
getFormInstance() {
|
|
17
|
+
return this.formInstance;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export { FormRegistry };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FormLayoutProps } from "../types";
|
|
3
|
+
export declare class LayoutRegister {
|
|
4
|
+
private readonly map;
|
|
5
|
+
private constructor();
|
|
6
|
+
private static readonly instance;
|
|
7
|
+
static getInstance(): LayoutRegister;
|
|
8
|
+
register(type: string, componentType: React.ComponentType<FormLayoutProps>): void;
|
|
9
|
+
getLayoutComponent(type: string): React.ComponentType<FormLayoutProps> | undefined;
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
class LayoutRegister {
|
|
3
|
+
map;
|
|
4
|
+
constructor(){
|
|
5
|
+
this.map = new Map();
|
|
6
|
+
}
|
|
7
|
+
static instance = new LayoutRegister();
|
|
8
|
+
static getInstance() {
|
|
9
|
+
return this.instance;
|
|
10
|
+
}
|
|
11
|
+
register(type, componentType) {
|
|
12
|
+
this.map.set(type, componentType);
|
|
13
|
+
}
|
|
14
|
+
getLayoutComponent(type) {
|
|
15
|
+
return this.map.get(type);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export { LayoutRegister };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PayloadAction } from '@reduxjs/toolkit';
|
|
2
|
+
import { FormState } from "../types";
|
|
3
|
+
export type FormStoreAction = {
|
|
4
|
+
updateState: (state: FormState, action: PayloadAction<Partial<FormState> | ((prev: FormState) => Partial<FormState>)>) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare const formSlice: import("@reduxjs/toolkit").Slice<FormState, FormStoreAction, "form", "form", {}>;
|
|
7
|
+
export declare const updateState: import("@reduxjs/toolkit").ActionCreatorWithPayload<Partial<FormState> | ((prev: FormState) => Partial<FormState>), "form/updateState">;
|
|
8
|
+
export declare const formStore: import("@reduxjs/toolkit").EnhancedStore<{
|
|
9
|
+
form: FormState;
|
|
10
|
+
}, import("redux").UnknownAction, import("@reduxjs/toolkit").Tuple<[import("redux").StoreEnhancer<{
|
|
11
|
+
dispatch: import("redux-thunk").ThunkDispatch<{
|
|
12
|
+
form: FormState;
|
|
13
|
+
}, undefined, import("redux").UnknownAction>;
|
|
14
|
+
}>, import("redux").StoreEnhancer]>>;
|
|
15
|
+
export type FormReduxState = ReturnType<typeof formStore.getState>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { configureStore, createSlice } from "@reduxjs/toolkit";
|
|
2
|
+
import { initialState } from "../types/index.js";
|
|
3
|
+
import { original } from "immer";
|
|
4
|
+
const formSlice = createSlice({
|
|
5
|
+
name: 'form',
|
|
6
|
+
initialState: {
|
|
7
|
+
...initialState
|
|
8
|
+
},
|
|
9
|
+
reducers: {
|
|
10
|
+
updateState: (state, action)=>{
|
|
11
|
+
if ('function' == typeof action.payload) {
|
|
12
|
+
const currentState = original(state);
|
|
13
|
+
Object.assign(state, action.payload(currentState));
|
|
14
|
+
} else Object.assign(state, action.payload);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { updateState: updateState } = formSlice.actions;
|
|
19
|
+
const formStore = configureStore({
|
|
20
|
+
reducer: {
|
|
21
|
+
form: formSlice.reducer
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
export { formSlice, formStore, updateState };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表单组件属性
|
|
3
|
+
*/
|
|
4
|
+
export interface FormItemProps {
|
|
5
|
+
/** 表单字段 **/
|
|
6
|
+
name: string;
|
|
7
|
+
/** 表单标题 **/
|
|
8
|
+
label?: string;
|
|
9
|
+
/** 是否隐藏 **/
|
|
10
|
+
hidden?: boolean;
|
|
11
|
+
/** 是否必填 **/
|
|
12
|
+
required?: boolean;
|
|
13
|
+
/** 默认值 **/
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
/** 当前值 **/
|
|
16
|
+
value?: string;
|
|
17
|
+
/** 变更事件 **/
|
|
18
|
+
onChange?: (value: string) => void;
|
|
19
|
+
/** 失去焦点事件 **/
|
|
20
|
+
onBlur?: (value: string) => void;
|
|
21
|
+
/** 输入提示信息 **/
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** 是否只读 **/
|
|
24
|
+
readOnly?: boolean;
|
|
25
|
+
/** 校验规则,Antd的规则 **/
|
|
26
|
+
rules?: any[];
|
|
27
|
+
/** 字段排版布局 **/
|
|
28
|
+
layout?: 'horizontal' | 'vertical';
|
|
29
|
+
/** 刷新版本号 **/
|
|
30
|
+
version?: number;
|
|
31
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormField, FormLayout } from "./view";
|
|
2
|
+
import { FormContextScope } from "../context";
|
|
3
|
+
/**
|
|
4
|
+
* 布局属性
|
|
5
|
+
*/
|
|
6
|
+
export interface FormLayoutProps {
|
|
7
|
+
/** 表单编码 **/
|
|
8
|
+
formCode: string;
|
|
9
|
+
/** 表单属性 **/
|
|
10
|
+
layout: FormLayout;
|
|
11
|
+
/** 表单字段 **/
|
|
12
|
+
fields: FormField[];
|
|
13
|
+
/** 是否预览模式 **/
|
|
14
|
+
review: boolean;
|
|
15
|
+
/** form上下文对象 **/
|
|
16
|
+
context: FormContextScope;
|
|
17
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数据类型
|
|
3
|
+
*/
|
|
4
|
+
export type DataType = 'STRING' | 'INTEGER' | 'BOOLEAN' | 'LONG' | 'DOUBLE';
|
|
5
|
+
export declare const dataTypeOptions: {
|
|
6
|
+
label: string;
|
|
7
|
+
value: string;
|
|
8
|
+
}[];
|
|
9
|
+
/**
|
|
10
|
+
* 表单类型
|
|
11
|
+
*/
|
|
12
|
+
export interface FormType {
|
|
13
|
+
name: string;
|
|
14
|
+
type: string;
|
|
15
|
+
dataType: DataType;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const dataTypeOptions = [
|
|
2
|
+
{
|
|
3
|
+
label: '整数',
|
|
4
|
+
value: 'INTEGER'
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
label: '长整数',
|
|
8
|
+
value: 'LONG'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
label: '小数',
|
|
12
|
+
value: 'DOUBLE'
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: '字符串',
|
|
16
|
+
value: 'STRING'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
label: '布尔类型',
|
|
20
|
+
value: 'BOOLEAN'
|
|
21
|
+
}
|
|
22
|
+
];
|
|
23
|
+
export { dataTypeOptions };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormInstance } from "../instance";
|
|
2
|
+
import { FieldKey } from "./";
|
|
3
|
+
/**
|
|
4
|
+
* 字段校验器
|
|
5
|
+
*/
|
|
6
|
+
export interface FormFieldValidator {
|
|
7
|
+
/** 字段名 **/
|
|
8
|
+
target: FieldKey;
|
|
9
|
+
/** 校验函数 **/
|
|
10
|
+
validator: (instance: FormInstance, value: any) => string | true;
|
|
11
|
+
}
|
|
File without changes
|