form-driver 0.3.13 → 0.4.0
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 +3 -3
- package/dist/m3.css +57 -0
- package/dist/m3.js +1 -1
- package/es/m3.css +57 -0
- package/es/m3.js +2190 -1386
- package/lib/m3.css +57 -0
- package/lib/m3.js +2188 -1382
- package/package.json +13 -9
- package/src/framework/Init.tsx +152 -150
- package/src/framework/M3.tsx +83 -59
- package/src/framework/MUtil.tsx +275 -140
- package/src/framework/MViewer.tsx +198 -106
- package/src/framework/Schema.ts +100 -87
- package/src/types/MSetType.ts +128 -71
- package/src/ui/editor/basic/ACheckBox.tsx +98 -50
- package/src/ui/editor/complex/ACheckDrag.tsx +356 -0
- package/src/ui/editor/complex/AForm.tsx +3 -1
- package/src/ui/editor/complex/JsonEditor.tsx +32 -21
- package/src/ui/widget/DIYCheckbox.less +36 -0
- package/src/ui/widget/DIYCheckbox.tsx +154 -0
- package/src/ui/widget/SortDrag.less +32 -0
- package/src/ui/widget/SortDrag.tsx +145 -0
- package/types/framework/Assembly.d.ts +2 -2
- package/types/framework/M3.d.ts +2 -2
- package/types/framework/MUtil.d.ts +5 -5
- package/types/framework/MViewer.d.ts +1 -1
- package/types/framework/Schema.d.ts +13 -11
- package/types/framework/Validator.d.ts +1 -1
- package/types/types/MDecorationType.d.ts +3 -3
- package/types/types/MSetType.d.ts +1 -1
- package/types/ui/editor/basic/ACheckBox.d.ts +2 -2
- package/types/ui/editor/basic/ARangePicker.d.ts +6 -2
- package/types/ui/editor/complex/ACheckDrag.d.ts +28 -0
- package/types/ui/editor/complex/JsonEditor.d.ts +1 -1
- package/types/ui/widget/DIYCheckbox.d.ts +19 -0
- package/types/ui/widget/SegmentEditSwitch.d.ts +1 -1
- package/types/ui/widget/SortDrag.d.ts +14 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "form-driver",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "An efficient framework for creating forms.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"authors": [
|
|
@@ -55,19 +55,20 @@
|
|
|
55
55
|
"displayName": "form-driver",
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@ant-design/icons": "^4.3.0",
|
|
58
|
+
"@atlaskit/pragmatic-drag-and-drop": "^1.7.4",
|
|
59
|
+
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^1.1.0",
|
|
58
60
|
"@babel/runtime": "^7.9.2",
|
|
59
61
|
"ali-oss": "^6.17.1",
|
|
60
|
-
"lodash": "^4.17.20",
|
|
61
62
|
"antd": "4.18.7",
|
|
62
63
|
"antd-mobile": "^2.3.4",
|
|
64
|
+
"clsx": "^2.1.1",
|
|
65
|
+
"lodash": "^4.17.20",
|
|
63
66
|
"moment": "^2.29.1",
|
|
64
67
|
"react": "^17.0.1",
|
|
65
|
-
"react-dom": "^17.0.1"
|
|
68
|
+
"react-dom": "^17.0.1",
|
|
69
|
+
"tiny-invariant": "^1.3.3"
|
|
66
70
|
},
|
|
67
71
|
"devDependencies": {
|
|
68
|
-
"@testing-library/jest-dom": "^5.11.4",
|
|
69
|
-
"@testing-library/react": "^11.1.0",
|
|
70
|
-
"@testing-library/user-event": "^12.1.10",
|
|
71
72
|
"@ant-design/tools": "^13.5.0-beta.1",
|
|
72
73
|
"@babel/cli": "^7.12.10",
|
|
73
74
|
"@babel/core": "^7.12.10",
|
|
@@ -84,6 +85,9 @@
|
|
|
84
85
|
"@rollup/plugin-babel": "^5.0.0",
|
|
85
86
|
"@rollup/plugin-image": "^2.0.6",
|
|
86
87
|
"@rollup/plugin-replace": "^2.3.2",
|
|
88
|
+
"@testing-library/jest-dom": "^5.11.4",
|
|
89
|
+
"@testing-library/react": "^11.1.0",
|
|
90
|
+
"@testing-library/user-event": "^12.1.10",
|
|
87
91
|
"@types/lodash": "^4.14.165",
|
|
88
92
|
"@types/node": "^14.14.10",
|
|
89
93
|
"@types/react": "^17.0.0",
|
|
@@ -119,11 +123,11 @@
|
|
|
119
123
|
"rollup-plugin-postcss": "^4.0.0",
|
|
120
124
|
"rollup-plugin-serve": "^1.0.1",
|
|
121
125
|
"rollup-plugin-terser": "^7.0.2",
|
|
122
|
-
"rollup-plugin-typescript2": "^0.
|
|
126
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
123
127
|
"style-loader": "^0.20.0",
|
|
124
|
-
"ts-loader": "^8.0
|
|
128
|
+
"ts-loader": "^8.4.0",
|
|
125
129
|
"ts-node-dev": "^1.0.0",
|
|
126
|
-
"typescript": "^
|
|
130
|
+
"typescript": "^4.9.0",
|
|
127
131
|
"webpack": "^4.16.1",
|
|
128
132
|
"webpack-cli": "^3.1.0",
|
|
129
133
|
"webpack-dev-server": "^3.1.11"
|
package/src/framework/Init.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { assembly } from
|
|
1
|
+
import { assembly } from "./Assembly";
|
|
2
2
|
import { MEnumType } from "../types/MEnumType";
|
|
3
3
|
import { MGB2260Type } from "../types/MGB2260Type";
|
|
4
|
-
import { MDateTimeType } from
|
|
5
|
-
import { MSetType } from
|
|
4
|
+
import { MDateTimeType } from "../types/MDateTimeType";
|
|
5
|
+
import { MSetType } from "../types/MSetType";
|
|
6
6
|
import { MArrayType } from "../types/MArrayType";
|
|
7
|
-
import { MStringType } from
|
|
8
|
-
import { MIntDiffType } from
|
|
9
|
-
import { MIntType } from
|
|
7
|
+
import { MStringType } from "../types/MStringType";
|
|
8
|
+
import { MIntDiffType } from "../types/MIntDiffType";
|
|
9
|
+
import { MIntType } from "../types/MIntType";
|
|
10
10
|
import { MMatrixType } from "../types/MMatrixType";
|
|
11
11
|
import { MObjectType } from "../types/MObjectType";
|
|
12
12
|
import { MExperienceType } from "../types/MExperienceType";
|
|
13
13
|
import { MCnAddress } from "../types/MCnAddressType";
|
|
14
|
-
import { MTelType, MCnPhoneType, MEmailType } from
|
|
14
|
+
import { MTelType, MCnPhoneType, MEmailType } from "../types/MTelType";
|
|
15
15
|
import { MDateRangeType } from "../types/MDateRangeType";
|
|
16
|
-
import { ArrayViewer } from
|
|
16
|
+
import { ArrayViewer } from "../ui/readable/ArrayViewer";
|
|
17
17
|
import { ADatetimePicker } from "../ui/editor/basic/ADatetimePicker";
|
|
18
18
|
import { AGB2260 } from "../ui/editor/basic/AGB2260";
|
|
19
19
|
import { ARadio } from "../ui/editor/basic/ARadio";
|
|
@@ -24,33 +24,34 @@ import { NPS } from "../ui/editor/basic/NPS";
|
|
|
24
24
|
import { AIntBox } from "../ui/editor/basic/AIntBox";
|
|
25
25
|
import { ACheckBox } from "../ui/editor/basic/ACheckBox";
|
|
26
26
|
import { AInputBox } from "../ui/editor/basic/AInputBox";
|
|
27
|
-
import { AMatrix } from
|
|
28
|
-
import { ASpecInputBox } from
|
|
29
|
-
import { AForm } from
|
|
30
|
-
import { DivViewer } from
|
|
27
|
+
import { AMatrix } from "../ui/editor/complex/AMatrix";
|
|
28
|
+
import { ASpecInputBox } from "../ui/editor/basic/ASpecInputBox";
|
|
29
|
+
import { AForm } from "../ui/editor/complex/AForm";
|
|
30
|
+
import { DivViewer } from "../ui/readable/DivViewer";
|
|
31
31
|
import { ASelector } from "../ui/editor/basic/ASelector";
|
|
32
|
-
import { ASetSelector } from
|
|
33
|
-
import { AExperience } from
|
|
34
|
-
import { ACnAddress } from
|
|
35
|
-
import { AArray } from
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
32
|
+
import { ASetSelector } from "../ui/editor/basic/ASetSelector";
|
|
33
|
+
import { AExperience } from "../ui/editor/complex/AExperience";
|
|
34
|
+
import { ACnAddress } from "../ui/editor/complex/ACnAddress";
|
|
35
|
+
import { AArray } from "../ui/editor/complex/AArray";
|
|
36
|
+
import { ACheckDrag } from "../ui/editor/complex/ACheckDrag";
|
|
37
|
+
import { AArrayGrid } from "../ui/editor/complex/AArrayGrid";
|
|
38
|
+
import { ARangePicker } from "../ui/editor/basic/ARangePicker";
|
|
39
|
+
import { AIntDiff } from "../ui/editor/complex/AIntDiff";
|
|
40
|
+
import { MFloatType } from "../types/MFloatType";
|
|
41
|
+
import { MDecorationType } from "../types/MDecorationType";
|
|
42
|
+
import { DecorationViewer } from "../ui/readable/DecorationViewer";
|
|
43
|
+
import { ATable } from "../ui/editor/complex/ATable";
|
|
44
|
+
import { ARemoteSelector } from "../ui/editor/basic/ARemoteSelector";
|
|
45
|
+
import { JsonEditor } from "../ui/editor/complex/JsonEditor";
|
|
45
46
|
import _ from "lodash";
|
|
46
|
-
import { A } from
|
|
47
|
-
import { ADialogForm } from
|
|
48
|
-
import { MVLPairType } from
|
|
49
|
-
import { MKvSetType } from
|
|
50
|
-
import { AKvSet } from
|
|
51
|
-
import { ACascadePicker } from
|
|
52
|
-
import { MCascadeType } from
|
|
53
|
-
import editorMap from
|
|
47
|
+
import { A } from "../ui/readable/A";
|
|
48
|
+
import { ADialogForm } from "../ui/editor/complex/ADialogForm";
|
|
49
|
+
import { MVLPairType } from "../types/MVLPairType";
|
|
50
|
+
import { MKvSetType } from "../types/MKvSetType";
|
|
51
|
+
import { AKvSet } from "../ui/editor/basic/AKvSet";
|
|
52
|
+
import { ACascadePicker } from "../ui/editor/basic/ACascadePicker";
|
|
53
|
+
import { MCascadeType } from "../types/MCascadeType";
|
|
54
|
+
import editorMap from "./editorMap";
|
|
54
55
|
import OssUpload from "../plugins/ossUpload/index";
|
|
55
56
|
|
|
56
57
|
// 在 m3 中注册oss上传插件
|
|
@@ -60,140 +61,141 @@ let init = false;
|
|
|
60
61
|
/**
|
|
61
62
|
* 确保m3已经初始化ensureM3
|
|
62
63
|
*/
|
|
63
|
-
export function ensureM3(){
|
|
64
|
-
if(init){
|
|
64
|
+
export function ensureM3() {
|
|
65
|
+
if (init) {
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
67
68
|
init = true;
|
|
68
69
|
assembly.types = _.merge(assembly.types, {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
70
|
+
enum: MEnumType,
|
|
71
|
+
gb2260: MGB2260Type,
|
|
72
|
+
datetime: MDateTimeType,
|
|
73
|
+
year: MDateTimeType,
|
|
74
|
+
yearMonth: MDateTimeType,
|
|
75
|
+
yearMonthDay: MDateTimeType,
|
|
76
|
+
set: MSetType,
|
|
77
|
+
array: MArrayType,
|
|
78
|
+
string: MStringType,
|
|
79
|
+
intDiff: MIntDiffType,
|
|
80
|
+
int: MIntType,
|
|
81
|
+
float: MFloatType,
|
|
82
|
+
matrix: MMatrixType,
|
|
83
|
+
object: MObjectType,
|
|
84
|
+
experience: MExperienceType,
|
|
85
|
+
cnAddress: MCnAddress,
|
|
86
|
+
tel: MTelType,
|
|
87
|
+
email: MEmailType,
|
|
88
|
+
cnPhone: MCnPhoneType,
|
|
89
|
+
dateRange: MDateRangeType,
|
|
90
|
+
decoration: MDecorationType,
|
|
91
|
+
vl: MVLPairType,
|
|
92
|
+
kvSet: MKvSetType,
|
|
93
|
+
cascade: MCascadeType,
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
+
|
|
95
96
|
// 实验性组件 AArray、ATable、ADialogForm、AForm、ASetSelector、JsonEditor
|
|
96
97
|
assembly.viewers = _.merge(assembly.viewers, {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
98
|
+
ADatetimePicker: ADatetimePicker,
|
|
99
|
+
AGB2260: AGB2260,
|
|
100
|
+
ARadio: ARadio,
|
|
101
|
+
ARate: ARate,
|
|
102
|
+
AUpload: AUpload,
|
|
103
|
+
ATreeSelect: ATreeSelect,
|
|
104
|
+
NPS: NPS,
|
|
105
|
+
ACheckBox: ACheckBox,
|
|
106
|
+
AIntBox: AIntBox,
|
|
107
|
+
AInputBox: AInputBox,
|
|
108
|
+
AMatrix: AMatrix,
|
|
109
|
+
ASpecInputBox: ASpecInputBox,
|
|
110
|
+
AForm: AForm,
|
|
111
|
+
AArray: AArray,
|
|
112
|
+
ACheckDrag: ACheckDrag,
|
|
113
|
+
AArrayGrid: AArrayGrid,
|
|
114
|
+
ARangePicker: ARangePicker,
|
|
115
|
+
AIntDiff: AIntDiff,
|
|
116
|
+
ACnAddress: ACnAddress,
|
|
117
|
+
AExperience: AExperience,
|
|
118
|
+
ASetSelector: ASetSelector,
|
|
119
|
+
ASelector: ASelector,
|
|
120
|
+
DivViewer: DivViewer,
|
|
121
|
+
ArrayViewer: ArrayViewer,
|
|
122
|
+
DecorationViewer: DecorationViewer,
|
|
123
|
+
ATable: ATable,
|
|
124
|
+
ARemoteSelector: ARemoteSelector,
|
|
125
|
+
JsonEditor: JsonEditor,
|
|
126
|
+
A: A,
|
|
127
|
+
ADialogForm: ADialogForm,
|
|
128
|
+
AKvSet: AKvSet,
|
|
129
|
+
ACascadePicker: ACascadePicker,
|
|
128
130
|
});
|
|
129
131
|
|
|
130
132
|
assembly.morph = _.merge(assembly.morph, {
|
|
131
133
|
// 编辑
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
134
|
+
editor: {
|
|
135
|
+
enum: "ASelector",
|
|
136
|
+
gb2260: "AGB2260",
|
|
137
|
+
datetime: "ADatetimePicker",
|
|
138
|
+
year: "ADatetimePicker",
|
|
139
|
+
yearMonth: "ADatetimePicker",
|
|
140
|
+
yearMonthDay: "ADatetimePicker",
|
|
141
|
+
set: "ACheckBox",
|
|
142
|
+
array: "AArray",
|
|
143
|
+
string: "AInputBox",
|
|
144
|
+
|
|
145
|
+
intDiff: "AIntDiff",
|
|
146
|
+
int: "AIntBox",
|
|
147
|
+
float: "AIntBox",
|
|
148
|
+
|
|
149
|
+
matrix: "AMatrix",
|
|
150
|
+
object: "AForm",
|
|
151
|
+
|
|
152
|
+
experience: "AExperience",
|
|
153
|
+
kvSet: "AKvSet",
|
|
154
|
+
|
|
153
155
|
// TODO 这些类型还没有校验
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
156
|
+
cnAddress: "ACnAddress",
|
|
157
|
+
tel: "ASpecInputBox",
|
|
158
|
+
email: "ASpecInputBox",
|
|
159
|
+
cnPhone: "ASpecInputBox",
|
|
160
|
+
dateRange: "ARangePicker",
|
|
161
|
+
decoration: "DecorationViewer",
|
|
160
162
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
+
vl: "ARemoteSelector",
|
|
164
|
+
cascade: "ACascadePicker",
|
|
163
165
|
},
|
|
164
166
|
// 详情
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
readable: {
|
|
168
|
+
enum: "DivViewer",
|
|
169
|
+
gb2260: "DivViewer",
|
|
170
|
+
datetime: "DivViewer",
|
|
171
|
+
year: "DivViewer",
|
|
172
|
+
yearMonth: "DivViewer",
|
|
173
|
+
yearMonthDay: "DivViewer",
|
|
174
|
+
|
|
175
|
+
set: "DivViewer",
|
|
176
|
+
array: "ArrayViewer",
|
|
177
|
+
string: "DivViewer",
|
|
172
178
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
intDiff: "DivViewer",
|
|
180
|
+
int: "DivViewer",
|
|
181
|
+
float: "DivViewer",
|
|
176
182
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
183
|
+
matrix: "DivViewer",
|
|
184
|
+
object: "AForm",
|
|
185
|
+
experience: "DivViewer",
|
|
186
|
+
kvSet: "DivViewer",
|
|
180
187
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
188
|
+
cnAddress: "DivViewer",
|
|
189
|
+
tel: "DivViewer",
|
|
190
|
+
email: "DivViewer",
|
|
191
|
+
cnPhone: "DivViewer",
|
|
192
|
+
dateRange: "DivViewer",
|
|
193
|
+
decoration: "DecorationViewer",
|
|
194
|
+
vl: "DivViewer",
|
|
185
195
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
"cnPhone": "DivViewer",
|
|
190
|
-
"dateRange":"DivViewer",
|
|
191
|
-
"decoration": "DecorationViewer",
|
|
192
|
-
"vl": "DivViewer",
|
|
196
|
+
cascade: "DivViewer",
|
|
197
|
+
},
|
|
198
|
+
});
|
|
193
199
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
assembly.editors = _.merge(assembly.editors, editorMap)
|
|
199
|
-
}
|
|
200
|
+
assembly.editors = _.merge(assembly.editors, editorMap);
|
|
201
|
+
}
|
package/src/framework/M3.tsx
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import React, { useState, useEffect } from
|
|
2
|
-
import { M3Prop, MViewer } from
|
|
3
|
-
import { MViewerDebug } from
|
|
4
|
-
import editorMap from
|
|
5
|
-
import {
|
|
1
|
+
import React, { useState, useEffect } from "react";
|
|
2
|
+
import { M3Prop, MViewer } from "./MViewer";
|
|
3
|
+
import { MViewerDebug } from "./MViewerDebug";
|
|
4
|
+
import editorMap from "./editorMap";
|
|
5
|
+
import {
|
|
6
|
+
MFieldSchema,
|
|
7
|
+
M3UISpec,
|
|
8
|
+
MFieldSchemaAnonymity,
|
|
9
|
+
} from "../../src/framework/Schema";
|
|
6
10
|
import _ from "lodash";
|
|
7
11
|
|
|
8
12
|
// 外部 schema 转化为内部
|
|
@@ -14,96 +18,116 @@ function deal(fieldSchema: MFieldSchemaAnonymity | MFieldSchema) {
|
|
|
14
18
|
deal(f);
|
|
15
19
|
}
|
|
16
20
|
} else {
|
|
17
|
-
let opt =
|
|
21
|
+
let opt =
|
|
22
|
+
fieldSchema.option ?? fieldSchema.setFields ?? fieldSchema.enumFields;
|
|
18
23
|
if (opt) {
|
|
19
|
-
if (typeof opt ===
|
|
20
|
-
fieldSchema.option = opt.split(" ").map(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
);
|
|
24
|
+
if (typeof opt === "string") {
|
|
25
|
+
fieldSchema.option = opt.split(" ").map((aEnum) => {
|
|
26
|
+
const kv = aEnum.split("=");
|
|
27
|
+
return { label: kv[0], value: kv[1] ?? kv[0] };
|
|
28
|
+
});
|
|
26
29
|
} else {
|
|
27
|
-
fieldSchema.option = opt
|
|
30
|
+
fieldSchema.option = opt;
|
|
28
31
|
}
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
fieldSchema.openOption =
|
|
34
|
+
fieldSchema.openOption =
|
|
35
|
+
fieldSchema.openOption ?? fieldSchema.setOpen ?? fieldSchema.enumOpen;
|
|
32
36
|
|
|
33
37
|
if (!fieldSchema.type && fieldSchema.editor) {
|
|
34
|
-
Object.assign(fieldSchema, editorMap[fieldSchema.editor])
|
|
38
|
+
Object.assign(fieldSchema, editorMap[fieldSchema.editor]);
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
// 标准化 schema
|
|
40
|
-
function standardSchema(
|
|
41
|
-
|
|
44
|
+
function standardSchema(
|
|
45
|
+
schema: MFieldSchema | MFieldSchema[],
|
|
46
|
+
layout?: M3UISpec
|
|
47
|
+
) {
|
|
48
|
+
const _schema = _.cloneDeep(schema);
|
|
42
49
|
if (_.isArray(_schema)) {
|
|
43
|
-
_schema.forEach(item => {
|
|
44
|
-
deal(item)
|
|
45
|
-
})
|
|
50
|
+
_schema.forEach((item) => {
|
|
51
|
+
deal(item);
|
|
52
|
+
});
|
|
46
53
|
const temp: MFieldSchema = {
|
|
47
|
-
name:
|
|
48
|
-
type:
|
|
49
|
-
objectFields: _schema
|
|
50
|
-
}
|
|
54
|
+
name: "__root__",
|
|
55
|
+
type: "object",
|
|
56
|
+
objectFields: _schema,
|
|
57
|
+
};
|
|
51
58
|
if (layout) {
|
|
52
|
-
temp.uispec = layout
|
|
59
|
+
temp.uispec = layout;
|
|
53
60
|
}
|
|
54
|
-
return _.cloneDeep(temp)
|
|
61
|
+
return _.cloneDeep(temp);
|
|
55
62
|
} else {
|
|
56
|
-
deal(_schema)
|
|
57
|
-
return _schema
|
|
63
|
+
deal(_schema);
|
|
64
|
+
return _schema;
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
67
|
|
|
61
68
|
const M3 = (props: React.PropsWithChildren<M3Prop & { debug?: boolean }>) => {
|
|
62
|
-
|
|
63
|
-
let [
|
|
64
|
-
let [
|
|
65
|
-
let [k, setK] = useState(0)
|
|
69
|
+
let [database, setDatabase] = useState(_.cloneDeep(props.database));
|
|
70
|
+
let [schema, setSchema] = useState(standardSchema(props.schema));
|
|
71
|
+
let [k, setK] = useState(0);
|
|
66
72
|
|
|
67
73
|
// debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
68
|
-
let debug =
|
|
74
|
+
let debug =
|
|
75
|
+
props.debug ||
|
|
76
|
+
window.location.search.indexOf("debug") >= 0 ||
|
|
77
|
+
window.location.hash.indexOf("debug") >= 0;
|
|
69
78
|
|
|
70
|
-
const changeSchema = v => {
|
|
71
|
-
setSchema(standardSchema(v))
|
|
72
|
-
setK(++k)
|
|
73
|
-
}
|
|
74
|
-
const changeDatabase = v => {
|
|
75
|
-
setDatabase(_.cloneDeep(v))
|
|
76
|
-
setK(++k)
|
|
77
|
-
}
|
|
79
|
+
const changeSchema = (v) => {
|
|
80
|
+
setSchema(standardSchema(v));
|
|
81
|
+
setK(++k);
|
|
82
|
+
};
|
|
83
|
+
const changeDatabase = (v) => {
|
|
84
|
+
setDatabase(_.cloneDeep(v));
|
|
85
|
+
setK(++k);
|
|
86
|
+
};
|
|
78
87
|
|
|
79
88
|
if (props.form) {
|
|
80
|
-
props.form.setSchema = changeSchema
|
|
81
|
-
props.form.setDatabase = changeDatabase
|
|
82
|
-
props.form.getSchema = () => schema
|
|
83
|
-
props.form.getDatabase = () => database
|
|
89
|
+
props.form.setSchema = changeSchema;
|
|
90
|
+
props.form.setDatabase = changeDatabase;
|
|
91
|
+
props.form.getSchema = () => schema;
|
|
92
|
+
props.form.getDatabase = () => database;
|
|
84
93
|
}
|
|
85
94
|
|
|
86
95
|
useEffect(() => {
|
|
87
|
-
changeDatabase(props.schema)
|
|
88
|
-
}, [props.schema])
|
|
96
|
+
changeDatabase(props.schema);
|
|
97
|
+
}, [props.schema]);
|
|
89
98
|
|
|
90
99
|
useEffect(() => {
|
|
91
|
-
changeDatabase(props.database)
|
|
92
|
-
}, [props.database])
|
|
100
|
+
changeDatabase(props.database);
|
|
101
|
+
}, [props.database]);
|
|
93
102
|
|
|
94
|
-
return (
|
|
95
|
-
|
|
96
|
-
|
|
103
|
+
return debug ? (
|
|
104
|
+
<MViewerDebug
|
|
105
|
+
key={k}
|
|
106
|
+
{...props}
|
|
107
|
+
database={database}
|
|
108
|
+
schema={schema}
|
|
109
|
+
changeSchema={changeSchema}
|
|
110
|
+
changeDatabase={changeDatabase}
|
|
111
|
+
/>
|
|
112
|
+
) : (
|
|
113
|
+
<MViewer
|
|
114
|
+
key={k}
|
|
115
|
+
{...props}
|
|
116
|
+
database={database}
|
|
117
|
+
schema={schema}
|
|
118
|
+
changeSchema={changeSchema}
|
|
119
|
+
changeDatabase={changeDatabase}
|
|
120
|
+
/>
|
|
97
121
|
);
|
|
98
|
-
}
|
|
122
|
+
};
|
|
99
123
|
|
|
100
124
|
export default M3;
|
|
101
125
|
|
|
102
126
|
export function useForm() {
|
|
103
127
|
return {
|
|
104
|
-
setSchema: (v) => {
|
|
105
|
-
setDatabase: (v) => {
|
|
106
|
-
getSchema: () => {
|
|
107
|
-
getDatabase: () => {
|
|
108
|
-
}
|
|
128
|
+
setSchema: (v) => {},
|
|
129
|
+
setDatabase: (v) => {},
|
|
130
|
+
getSchema: () => {},
|
|
131
|
+
getDatabase: () => {},
|
|
132
|
+
};
|
|
109
133
|
}
|