form-driver 0.3.14 → 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/dist/m3.css +57 -0
- package/dist/m3.js +1 -1
- package/es/m3.css +57 -0
- package/es/m3.js +2186 -1385
- package/lib/m3.css +57 -0
- package/lib/m3.js +2184 -1381
- 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/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
|
@@ -1,46 +1,63 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AFTER_CHANGE_CALLBACK,
|
|
4
|
+
CHANGE_SCHEMA_CALLBACK,
|
|
5
|
+
MFieldSchema,
|
|
6
|
+
M3UISpec,
|
|
7
|
+
} from "../framework/Schema";
|
|
3
8
|
import { Button, message, Modal } from "antd";
|
|
4
9
|
import "./MViewer.less";
|
|
5
10
|
import { MFieldViewer } from "./MFieldViewer";
|
|
6
|
-
import { MUtil } from
|
|
7
|
-
import { assembly, MORPH } from
|
|
11
|
+
import { MUtil } from "./MUtil";
|
|
12
|
+
import { assembly, MORPH } from "./Assembly";
|
|
8
13
|
import _ from "lodash";
|
|
9
|
-
import { ensureM3 } from
|
|
10
|
-
import { MContext } from
|
|
14
|
+
import { ensureM3 } from "./Init";
|
|
15
|
+
import { MContext } from "./MContext";
|
|
11
16
|
import { PersistantTool, PersistantConf } from "./Persistant";
|
|
12
17
|
|
|
13
18
|
export interface MViewerProp {
|
|
14
|
-
schema: MFieldSchema
|
|
15
|
-
database: any
|
|
16
|
-
layout?: M3UISpec
|
|
17
|
-
style?: React.CSSProperties
|
|
18
|
-
morph: MORPH
|
|
19
|
+
schema: MFieldSchema;
|
|
20
|
+
database: any;
|
|
21
|
+
layout?: M3UISpec;
|
|
22
|
+
style?: React.CSSProperties;
|
|
23
|
+
morph: MORPH;
|
|
19
24
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
20
|
-
afterChange?: AFTER_CHANGE_CALLBACK
|
|
21
|
-
changeSchema?: CHANGE_SCHEMA_CALLBACK
|
|
22
|
-
changeDatabase?: CHANGE_SCHEMA_CALLBACK
|
|
23
|
-
wrapper?: (
|
|
24
|
-
|
|
25
|
+
afterChange?: AFTER_CHANGE_CALLBACK;
|
|
26
|
+
changeSchema?: CHANGE_SCHEMA_CALLBACK;
|
|
27
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK;
|
|
28
|
+
wrapper?: (
|
|
29
|
+
elem: React.ReactElement,
|
|
30
|
+
schema: Partial<MFieldSchema>
|
|
31
|
+
) => React.ReactElement;
|
|
32
|
+
formItemWrapper?: (
|
|
33
|
+
elem: React.ReactElement,
|
|
34
|
+
schema: Partial<MFieldSchema>
|
|
35
|
+
) => React.ReactElement;
|
|
25
36
|
/** 持久存储选项,nil表示不持久存储 */
|
|
26
|
-
persistant?: PersistantConf
|
|
37
|
+
persistant?: PersistantConf;
|
|
27
38
|
}
|
|
28
39
|
|
|
29
40
|
export interface M3Prop {
|
|
30
|
-
schema: MFieldSchema | MFieldSchema[]
|
|
31
|
-
database: any
|
|
32
|
-
form?: any
|
|
33
|
-
layout?: M3UISpec
|
|
34
|
-
style?: React.CSSProperties
|
|
35
|
-
morph: MORPH
|
|
41
|
+
schema: MFieldSchema | MFieldSchema[];
|
|
42
|
+
database: any;
|
|
43
|
+
form?: any;
|
|
44
|
+
layout?: M3UISpec;
|
|
45
|
+
style?: React.CSSProperties;
|
|
46
|
+
morph: MORPH;
|
|
36
47
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
37
|
-
afterChange?: AFTER_CHANGE_CALLBACK
|
|
38
|
-
changeSchema?: CHANGE_SCHEMA_CALLBACK
|
|
39
|
-
changeDatabase?: CHANGE_SCHEMA_CALLBACK
|
|
40
|
-
wrapper?: (
|
|
41
|
-
|
|
48
|
+
afterChange?: AFTER_CHANGE_CALLBACK;
|
|
49
|
+
changeSchema?: CHANGE_SCHEMA_CALLBACK;
|
|
50
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK;
|
|
51
|
+
wrapper?: (
|
|
52
|
+
elem: React.ReactElement,
|
|
53
|
+
schema: Partial<MFieldSchema>
|
|
54
|
+
) => React.ReactElement;
|
|
55
|
+
formItemWrapper?: (
|
|
56
|
+
elem: React.ReactElement,
|
|
57
|
+
schema: Partial<MFieldSchema>
|
|
58
|
+
) => React.ReactElement;
|
|
42
59
|
/** 持久存储选项,nil表示不持久存储 */
|
|
43
|
-
persistant?: PersistantConf
|
|
60
|
+
persistant?: PersistantConf;
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
interface State {
|
|
@@ -58,53 +75,72 @@ export class MViewer extends React.Component<MViewerProp, State> {
|
|
|
58
75
|
this.state = {
|
|
59
76
|
forceValid: false,
|
|
60
77
|
ctrlVersion: 1,
|
|
61
|
-
}
|
|
78
|
+
};
|
|
62
79
|
|
|
63
80
|
ensureM3();
|
|
64
81
|
|
|
65
82
|
const props = this.props;
|
|
66
83
|
|
|
67
84
|
// 值类型兼容预处理
|
|
68
|
-
this.database = assembly.types[props.schema.type]?.standardValue(
|
|
85
|
+
this.database = assembly.types[props.schema.type]?.standardValue(
|
|
86
|
+
assembly,
|
|
87
|
+
props.schema,
|
|
88
|
+
props.database,
|
|
89
|
+
false
|
|
90
|
+
);
|
|
69
91
|
|
|
70
92
|
// 填入默认值
|
|
71
93
|
MUtil.applyDefaultValue(props.schema, props.database, "");
|
|
72
94
|
// 填入本地缓存值
|
|
73
|
-
this.recover()
|
|
95
|
+
this.recover();
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
recover() {
|
|
77
|
-
const { ctrlVersion } = this.state
|
|
78
|
-
const { persistant } = this.props
|
|
99
|
+
const { ctrlVersion } = this.state;
|
|
100
|
+
const { persistant } = this.props;
|
|
79
101
|
PersistantTool.load(this.database, persistant, () => {
|
|
80
102
|
this.setState({
|
|
81
|
-
ctrlVersion: ctrlVersion + 1
|
|
82
|
-
})
|
|
103
|
+
ctrlVersion: ctrlVersion + 1,
|
|
104
|
+
});
|
|
83
105
|
});
|
|
84
106
|
}
|
|
85
107
|
|
|
86
108
|
render() {
|
|
87
109
|
const props = this.props;
|
|
88
110
|
const database = this.database;
|
|
89
|
-
const { ctrlVersion, forceValid } = this.state
|
|
90
|
-
|
|
91
|
-
return
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
const { ctrlVersion, forceValid } = this.state;
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<MContext.Provider
|
|
115
|
+
value={{
|
|
116
|
+
rootProps: props,
|
|
117
|
+
forceValid,
|
|
118
|
+
setForceValid: (b) => {
|
|
119
|
+
this.setState({ forceValid: true });
|
|
120
|
+
},
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<div
|
|
124
|
+
key={ctrlVersion}
|
|
125
|
+
className={MUtil.phoneLike() ? "MEditor_p" : "MEditor"}
|
|
126
|
+
style={props.style}
|
|
127
|
+
>
|
|
128
|
+
<MFieldViewer
|
|
129
|
+
schema={props.schema}
|
|
130
|
+
database={database}
|
|
131
|
+
path=""
|
|
132
|
+
morph={props.morph}
|
|
133
|
+
afterChange={PersistantTool.patchAfterChange(
|
|
134
|
+
props.afterChange,
|
|
135
|
+
props.persistant
|
|
136
|
+
)}
|
|
137
|
+
changeSchema={props.changeSchema}
|
|
138
|
+
changeDatabase={props.changeDatabase}
|
|
139
|
+
/>
|
|
140
|
+
{props.children}
|
|
141
|
+
</div>
|
|
142
|
+
</MContext.Provider>
|
|
143
|
+
);
|
|
108
144
|
}
|
|
109
145
|
}
|
|
110
146
|
|
|
@@ -133,63 +169,119 @@ export class MViewer extends React.Component<MViewerProp, State> {
|
|
|
133
169
|
* @param props
|
|
134
170
|
*/
|
|
135
171
|
export function SubmitBar(props: {
|
|
136
|
-
style?: React.CSSProperties
|
|
137
|
-
onSubmit?: (finalData: any) => Promise<any
|
|
138
|
-
onCancel?: () => void
|
|
139
|
-
children?: React.ReactNode | ((loading: boolean) => React.ReactNode)
|
|
172
|
+
style?: React.CSSProperties;
|
|
173
|
+
onSubmit?: (finalData: any) => Promise<any>;
|
|
174
|
+
onCancel?: () => void;
|
|
175
|
+
children?: React.ReactNode | ((loading: boolean) => React.ReactNode);
|
|
140
176
|
}): JSX.Element {
|
|
141
|
-
|
|
142
177
|
const [loading, setLoading] = useState(false);
|
|
143
|
-
let style: React.CSSProperties = props.children
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
178
|
+
let style: React.CSSProperties = props.children
|
|
179
|
+
? undefined
|
|
180
|
+
: { textAlign: "center", ...props.style };
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<MContext.Consumer>
|
|
184
|
+
{(ctx) => {
|
|
185
|
+
const onClick = () => {
|
|
186
|
+
if (loading) {
|
|
187
|
+
message.warn("正在提交,请稍候");
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const r = assembly.validate(
|
|
191
|
+
ctx.rootProps.schema,
|
|
192
|
+
ctx.rootProps.database
|
|
193
|
+
);
|
|
194
|
+
// console.log("当前数据格式", {
|
|
195
|
+
// schema: ctx.rootProps.schema,
|
|
196
|
+
// database: ctx.rootProps.database,
|
|
197
|
+
// });
|
|
198
|
+
const submit = props.onSubmit ?? ctx.rootProps.onSubmit;
|
|
199
|
+
ctx.setForceValid(true);
|
|
200
|
+
if (r) {
|
|
201
|
+
Modal.warning({
|
|
202
|
+
content: "还没填完呢",
|
|
203
|
+
onOk: () => {
|
|
204
|
+
const viewer = document.getElementById(r.path);
|
|
205
|
+
if (viewer) {
|
|
206
|
+
viewer.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
207
|
+
} else {
|
|
208
|
+
console.error("viewer not found", r);
|
|
209
|
+
}
|
|
210
|
+
},
|
|
175
211
|
});
|
|
176
212
|
} else {
|
|
177
|
-
|
|
213
|
+
if (submit) {
|
|
214
|
+
// const sortQuestion = ctx.rootProps.schema.objectFields
|
|
215
|
+
// .filter((q) => q.editor === "AACheckDrag")
|
|
216
|
+
// ?.map((q) => q.name);
|
|
217
|
+
setLoading(true);
|
|
218
|
+
const finalData = MUtil.filterHide(
|
|
219
|
+
ctx.rootProps.schema,
|
|
220
|
+
ctx.rootProps.database
|
|
221
|
+
);
|
|
222
|
+
// const beforeHandleData = [...finalData];
|
|
223
|
+
// Object.keys(finalData).map((n) => {
|
|
224
|
+
// if (sortQuestion?.includes(n)) {
|
|
225
|
+
// finalData[n] = finalData[n].map((item) => {
|
|
226
|
+
// if (item.includes("open")) {
|
|
227
|
+
// return item.split("open-")?.[1];
|
|
228
|
+
// }
|
|
229
|
+
// return item;
|
|
230
|
+
// });
|
|
231
|
+
// }
|
|
232
|
+
// });
|
|
233
|
+
// console.log("最终提交的数据", {
|
|
234
|
+
// a: sortQuestion,
|
|
235
|
+
// b: ctx.rootProps.schema,
|
|
236
|
+
// c: ctx.rootProps.database,
|
|
237
|
+
// beforeHandleData: ctx.rootProps.database,
|
|
238
|
+
// finalData,
|
|
239
|
+
// });
|
|
240
|
+
submit(finalData)
|
|
241
|
+
.then(() => {
|
|
242
|
+
PersistantTool.clear(ctx.rootProps.persistant);
|
|
243
|
+
})
|
|
244
|
+
.finally(() => {
|
|
245
|
+
setLoading(false);
|
|
246
|
+
});
|
|
247
|
+
} else {
|
|
248
|
+
message.success(
|
|
249
|
+
"填是填完了,但提交功能还在开发中,请联系程序员解决"
|
|
250
|
+
);
|
|
251
|
+
}
|
|
178
252
|
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
253
|
+
};
|
|
254
|
+
return (
|
|
255
|
+
<div style={style} onClick={props.children ? onClick : undefined}>
|
|
256
|
+
{props.onCancel ? (
|
|
257
|
+
<Button
|
|
258
|
+
style={{ width: "40%", marginRight: "20px" }}
|
|
259
|
+
onClick={props.onCancel}
|
|
260
|
+
>
|
|
261
|
+
返回
|
|
262
|
+
</Button>
|
|
263
|
+
) : null}
|
|
264
|
+
{props.children ? (
|
|
265
|
+
_.isFunction(props.children) ? (
|
|
266
|
+
props.children(loading)
|
|
267
|
+
) : (
|
|
268
|
+
props.children
|
|
269
|
+
)
|
|
270
|
+
) : (
|
|
271
|
+
<Button
|
|
272
|
+
style={{ width: "40%" }}
|
|
273
|
+
type="primary"
|
|
274
|
+
loading={loading}
|
|
275
|
+
onClick={props.children ? undefined : onClick}
|
|
276
|
+
>
|
|
277
|
+
提交
|
|
278
|
+
</Button>
|
|
279
|
+
)}
|
|
280
|
+
</div>
|
|
281
|
+
);
|
|
282
|
+
}}
|
|
283
|
+
</MContext.Consumer>
|
|
284
|
+
);
|
|
193
285
|
}
|
|
194
286
|
|
|
195
287
|
export function useM3Database(initValue) {
|