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.
Files changed (37) hide show
  1. package/README.md +3 -3
  2. package/dist/m3.css +57 -0
  3. package/dist/m3.js +1 -1
  4. package/es/m3.css +57 -0
  5. package/es/m3.js +2190 -1386
  6. package/lib/m3.css +57 -0
  7. package/lib/m3.js +2188 -1382
  8. package/package.json +13 -9
  9. package/src/framework/Init.tsx +152 -150
  10. package/src/framework/M3.tsx +83 -59
  11. package/src/framework/MUtil.tsx +275 -140
  12. package/src/framework/MViewer.tsx +198 -106
  13. package/src/framework/Schema.ts +100 -87
  14. package/src/types/MSetType.ts +128 -71
  15. package/src/ui/editor/basic/ACheckBox.tsx +98 -50
  16. package/src/ui/editor/complex/ACheckDrag.tsx +356 -0
  17. package/src/ui/editor/complex/AForm.tsx +3 -1
  18. package/src/ui/editor/complex/JsonEditor.tsx +32 -21
  19. package/src/ui/widget/DIYCheckbox.less +36 -0
  20. package/src/ui/widget/DIYCheckbox.tsx +154 -0
  21. package/src/ui/widget/SortDrag.less +32 -0
  22. package/src/ui/widget/SortDrag.tsx +145 -0
  23. package/types/framework/Assembly.d.ts +2 -2
  24. package/types/framework/M3.d.ts +2 -2
  25. package/types/framework/MUtil.d.ts +5 -5
  26. package/types/framework/MViewer.d.ts +1 -1
  27. package/types/framework/Schema.d.ts +13 -11
  28. package/types/framework/Validator.d.ts +1 -1
  29. package/types/types/MDecorationType.d.ts +3 -3
  30. package/types/types/MSetType.d.ts +1 -1
  31. package/types/ui/editor/basic/ACheckBox.d.ts +2 -2
  32. package/types/ui/editor/basic/ARangePicker.d.ts +6 -2
  33. package/types/ui/editor/complex/ACheckDrag.d.ts +28 -0
  34. package/types/ui/editor/complex/JsonEditor.d.ts +1 -1
  35. package/types/ui/widget/DIYCheckbox.d.ts +19 -0
  36. package/types/ui/widget/SegmentEditSwitch.d.ts +1 -1
  37. 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.13",
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.29.0",
126
+ "rollup-plugin-typescript2": "^0.36.0",
123
127
  "style-loader": "^0.20.0",
124
- "ts-loader": "^8.0.14",
128
+ "ts-loader": "^8.4.0",
125
129
  "ts-node-dev": "^1.0.0",
126
- "typescript": "^3.8.3",
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"
@@ -1,19 +1,19 @@
1
- import { assembly } from './Assembly';
1
+ import { assembly } from "./Assembly";
2
2
  import { MEnumType } from "../types/MEnumType";
3
3
  import { MGB2260Type } from "../types/MGB2260Type";
4
- import { MDateTimeType } from '../types/MDateTimeType';
5
- import { MSetType } from '../types/MSetType';
4
+ import { MDateTimeType } from "../types/MDateTimeType";
5
+ import { MSetType } from "../types/MSetType";
6
6
  import { MArrayType } from "../types/MArrayType";
7
- import { MStringType } from '../types/MStringType';
8
- import { MIntDiffType } from '../types/MIntDiffType';
9
- import { MIntType } from '../types/MIntType';
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 '../types/MTelType';
14
+ import { MTelType, MCnPhoneType, MEmailType } from "../types/MTelType";
15
15
  import { MDateRangeType } from "../types/MDateRangeType";
16
- import { ArrayViewer } from '../ui/readable/ArrayViewer';
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 '../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';
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 '../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 { AArrayGrid } from '../ui/editor/complex/AArrayGrid';
37
- import { ARangePicker } from '../ui/editor/basic/ARangePicker';
38
- import { AIntDiff } from '../ui/editor/complex/AIntDiff';
39
- import { MFloatType } from '../types/MFloatType';
40
- import { MDecorationType } from '../types/MDecorationType';
41
- import { DecorationViewer } from '../ui/readable/DecorationViewer';
42
- import { ATable } from '../ui/editor/complex/ATable';
43
- import { ARemoteSelector } from '../ui/editor/basic/ARemoteSelector';
44
- import { JsonEditor } from '../ui/editor/complex/JsonEditor';
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 '../ui/readable/A';
47
- import { ADialogForm } from '../ui/editor/complex/ADialogForm';
48
- import { MVLPairType } from '../types/MVLPairType';
49
- import { MKvSetType } from '../types/MKvSetType';
50
- import { AKvSet } from '../ui/editor/basic/AKvSet';
51
- import { ACascadePicker } from '../ui/editor/basic/ACascadePicker';
52
- import { MCascadeType } from '../types/MCascadeType';
53
- import editorMap from './editorMap';
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
- "enum": MEnumType,
70
- "gb2260": MGB2260Type,
71
- "datetime": MDateTimeType,
72
- "year": MDateTimeType,
73
- "yearMonth": MDateTimeType,
74
- "yearMonthDay": MDateTimeType,
75
- "set": MSetType,
76
- "array": MArrayType,
77
- "string": MStringType,
78
- "intDiff": MIntDiffType,
79
- "int": MIntType,
80
- "float": MFloatType,
81
- "matrix": MMatrixType,
82
- "object": MObjectType,
83
- "experience": MExperienceType,
84
- "cnAddress": MCnAddress,
85
- "tel": MTelType,
86
- "email": MEmailType,
87
- "cnPhone": MCnPhoneType,
88
- "dateRange": MDateRangeType,
89
- "decoration": MDecorationType,
90
- "vl": MVLPairType,
91
- "kvSet": MKvSetType,
92
- "cascade": MCascadeType,
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
- "ADatetimePicker": ADatetimePicker,
98
- "AGB2260": AGB2260,
99
- "ARadio": ARadio,
100
- "ARate": ARate,
101
- "AUpload": AUpload,
102
- "ATreeSelect": ATreeSelect,
103
- "NPS": NPS,
104
- "ACheckBox": ACheckBox,
105
- "AIntBox": AIntBox,
106
- "AInputBox": AInputBox,
107
- "AMatrix": AMatrix,
108
- "ASpecInputBox": ASpecInputBox,
109
- "AForm": AForm,
110
- "AArray": AArray,
111
- "AArrayGrid": AArrayGrid,
112
- "ARangePicker": ARangePicker,
113
- "AIntDiff": AIntDiff,
114
- "ACnAddress": ACnAddress,
115
- "AExperience": AExperience,
116
- "ASetSelector": ASetSelector,
117
- "ASelector": ASelector,
118
- "DivViewer": DivViewer,
119
- "ArrayViewer": ArrayViewer,
120
- "DecorationViewer": DecorationViewer,
121
- "ATable": ATable,
122
- "ARemoteSelector": ARemoteSelector,
123
- "JsonEditor": JsonEditor,
124
- "A": A,
125
- "ADialogForm": ADialogForm,
126
- "AKvSet": AKvSet,
127
- "ACascadePicker": ACascadePicker,
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
- "editor": {
133
- "enum": "ASelector",
134
- "gb2260":"AGB2260",
135
- "datetime": "ADatetimePicker",
136
- "year": "ADatetimePicker",
137
- "yearMonth": "ADatetimePicker",
138
- "yearMonthDay": "ADatetimePicker",
139
- "set": "ACheckBox",
140
- "array": "AArray",
141
- "string": "AInputBox",
142
-
143
- "intDiff": "AIntDiff",
144
- "int": "AIntBox",
145
- "float": "AIntBox",
146
-
147
- "matrix": "AMatrix",
148
- "object": "AForm",
149
-
150
- "experience": "AExperience",
151
- "kvSet": "AKvSet",
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
- "cnAddress": "ACnAddress",
155
- "tel": "ASpecInputBox",
156
- "email": "ASpecInputBox",
157
- "cnPhone": "ASpecInputBox",
158
- "dateRange": "ARangePicker",
159
- "decoration": "DecorationViewer",
156
+ cnAddress: "ACnAddress",
157
+ tel: "ASpecInputBox",
158
+ email: "ASpecInputBox",
159
+ cnPhone: "ASpecInputBox",
160
+ dateRange: "ARangePicker",
161
+ decoration: "DecorationViewer",
160
162
 
161
- "vl": "ARemoteSelector",
162
- "cascade": "ACascadePicker"
163
+ vl: "ARemoteSelector",
164
+ cascade: "ACascadePicker",
163
165
  },
164
166
  // 详情
165
- "readable": {
166
- "enum": "DivViewer",
167
- "gb2260": "DivViewer",
168
- "datetime": "DivViewer",
169
- "year": "DivViewer",
170
- "yearMonth": "DivViewer",
171
- "yearMonthDay": "DivViewer",
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
- "set": "DivViewer",
174
- "array": "ArrayViewer",
175
- "string": "DivViewer",
179
+ intDiff: "DivViewer",
180
+ int: "DivViewer",
181
+ float: "DivViewer",
176
182
 
177
- "intDiff": "DivViewer",
178
- "int": "DivViewer",
179
- "float": "DivViewer",
183
+ matrix: "DivViewer",
184
+ object: "AForm",
185
+ experience: "DivViewer",
186
+ kvSet: "DivViewer",
180
187
 
181
- "matrix": "DivViewer",
182
- "object": "AForm",
183
- "experience": "DivViewer",
184
- "kvSet": "DivViewer",
188
+ cnAddress: "DivViewer",
189
+ tel: "DivViewer",
190
+ email: "DivViewer",
191
+ cnPhone: "DivViewer",
192
+ dateRange: "DivViewer",
193
+ decoration: "DecorationViewer",
194
+ vl: "DivViewer",
185
195
 
186
- "cnAddress": "DivViewer",
187
- "tel": "DivViewer",
188
- "email": "DivViewer",
189
- "cnPhone": "DivViewer",
190
- "dateRange":"DivViewer",
191
- "decoration": "DecorationViewer",
192
- "vl": "DivViewer",
196
+ cascade: "DivViewer",
197
+ },
198
+ });
193
199
 
194
- "cascade": "DivViewer"
195
- }
196
- })
197
-
198
- assembly.editors = _.merge(assembly.editors, editorMap)
199
- }
200
+ assembly.editors = _.merge(assembly.editors, editorMap);
201
+ }
@@ -1,8 +1,12 @@
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 { MFieldSchema, M3UISpec, MFieldSchemaAnonymity } from "../../src/framework/Schema";
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 = fieldSchema.option ?? fieldSchema.setFields ?? fieldSchema.enumFields
21
+ let opt =
22
+ fieldSchema.option ?? fieldSchema.setFields ?? fieldSchema.enumFields;
18
23
  if (opt) {
19
- if (typeof opt === 'string') {
20
- fieldSchema.option = opt.split(" ").map(
21
- aEnum => {
22
- const kv = aEnum.split("=");
23
- return { label: kv[0], value: kv[1] ?? kv[0] };
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 = fieldSchema.openOption ?? fieldSchema.setOpen ?? fieldSchema.enumOpen
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(schema: MFieldSchema | MFieldSchema[], layout?: M3UISpec) {
41
- const _schema = _.cloneDeep(schema)
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: '__root__',
48
- type: 'object',
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 [database, setDatabase] = useState(_.cloneDeep(props.database))
64
- let [schema, setSchema] = useState(standardSchema(props.schema))
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 = props.debug || (window.location.search.indexOf("debug") >= 0 || window.location.hash.indexOf("debug") >= 0);
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
- debug ? <MViewerDebug key={k} {...props} database={database} schema={schema} changeSchema={changeSchema} changeDatabase={changeDatabase} /> :
96
- <MViewer key={k} {...props} database={database} schema={schema} changeSchema={changeSchema} changeDatabase={changeDatabase} />
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
  }