form-driver 0.1.21 → 0.1.22
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.js +1 -1
- package/es/m3.js +52 -32
- package/lib/m3.js +52 -31
- package/package.json +1 -1
- package/src/framework/M3.tsx +34 -20
- package/src/framework/MFieldViewer.tsx +1 -0
- package/src/framework/MViewer.tsx +13 -2
- package/src/framework/Schema.ts +3 -0
- package/src/index.ts +2 -1
- package/src/ui/editor/complex/AForm.tsx +1 -1
- package/types/framework/M3.d.ts +6 -0
- package/types/framework/MViewer.d.ts +3 -0
- package/types/framework/Schema.d.ts +2 -0
- package/types/index.d.ts +2 -2
package/es/m3.js
CHANGED
|
@@ -1213,6 +1213,7 @@ var MFieldViewer = /*#__PURE__*/function (_React$Component) {
|
|
|
1213
1213
|
var props = _objectSpread$e({
|
|
1214
1214
|
afterChange: function afterChange() {},
|
|
1215
1215
|
changeSchema: function changeSchema() {},
|
|
1216
|
+
changeDatabase: function changeDatabase() {},
|
|
1216
1217
|
name: this.props.path
|
|
1217
1218
|
}, this.props);
|
|
1218
1219
|
|
|
@@ -18109,6 +18110,7 @@ var AForm = /*#__PURE__*/function (_Viewer) {
|
|
|
18109
18110
|
},
|
|
18110
18111
|
parent: this.props.schema,
|
|
18111
18112
|
changeSchema: this.props.changeSchema,
|
|
18113
|
+
changeDatabase: this.props.changeDatabase,
|
|
18112
18114
|
forceValid: this.props.forceValid,
|
|
18113
18115
|
style: {
|
|
18114
18116
|
width: "100%"
|
|
@@ -20754,7 +20756,8 @@ var MViewer = /*#__PURE__*/function (_React$Component) {
|
|
|
20754
20756
|
path: "",
|
|
20755
20757
|
morph: props.morph,
|
|
20756
20758
|
afterChange: PersistantTool.patchAfterChange(props.afterChange, props.persistant),
|
|
20757
|
-
changeSchema: props.changeSchema
|
|
20759
|
+
changeSchema: props.changeSchema,
|
|
20760
|
+
changeDatabase: props.changeDatabase
|
|
20758
20761
|
}), props.children));
|
|
20759
20762
|
};
|
|
20760
20763
|
|
|
@@ -21057,56 +21060,73 @@ function standardSchema(schema, layout) {
|
|
|
21057
21060
|
}
|
|
21058
21061
|
|
|
21059
21062
|
var M3 = function M3(props) {
|
|
21060
|
-
var _useState = useState(props),
|
|
21061
|
-
|
|
21062
|
-
|
|
21063
|
+
var _useState = useState(_.cloneDeep(props.database)),
|
|
21064
|
+
database = _useState[0],
|
|
21065
|
+
setDatabase = _useState[1];
|
|
21063
21066
|
|
|
21064
|
-
var _useState2 = useState(
|
|
21065
|
-
|
|
21066
|
-
|
|
21067
|
+
var _useState2 = useState(standardSchema(props.schema)),
|
|
21068
|
+
schema = _useState2[0],
|
|
21069
|
+
setSchema = _useState2[1];
|
|
21067
21070
|
|
|
21068
|
-
var _useState3 = useState(
|
|
21069
|
-
|
|
21070
|
-
|
|
21071
|
-
|
|
21072
|
-
var _useState4 = useState(0),
|
|
21073
|
-
k = _useState4[0],
|
|
21074
|
-
setK = _useState4[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
21071
|
+
var _useState3 = useState(0),
|
|
21072
|
+
k = _useState3[0],
|
|
21073
|
+
setK = _useState3[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
21075
21074
|
|
|
21076
21075
|
|
|
21077
21076
|
var debug = props.debug || window.location.search.indexOf("debug") >= 0 || window.location.hash.indexOf("debug") >= 0;
|
|
21078
|
-
useEffect(function () {
|
|
21079
|
-
if (props.schema != prevProp.schema) {
|
|
21080
|
-
setSchema(standardSchema(props.schema));
|
|
21081
|
-
setPrevProp(props);
|
|
21082
|
-
setK(++k);
|
|
21083
|
-
}
|
|
21084
|
-
}, [props.schema]);
|
|
21085
|
-
useEffect(function () {
|
|
21086
|
-
if (props.database != prevProp.database) {
|
|
21087
|
-
setDatabase(_.cloneDeep(props.database));
|
|
21088
|
-
setPrevProp(props);
|
|
21089
|
-
setK(++k);
|
|
21090
|
-
}
|
|
21091
|
-
}, [props.database]);
|
|
21092
21077
|
|
|
21093
21078
|
var changeSchema = function changeSchema(v) {
|
|
21094
|
-
|
|
21079
|
+
setSchema(standardSchema(v));
|
|
21080
|
+
setK(++k);
|
|
21081
|
+
};
|
|
21082
|
+
|
|
21083
|
+
var changeDatabase = function changeDatabase(v) {
|
|
21084
|
+
setDatabase(_.cloneDeep(v));
|
|
21085
|
+
setK(++k);
|
|
21095
21086
|
};
|
|
21096
21087
|
|
|
21088
|
+
if (props.form) {
|
|
21089
|
+
props.form.setSchema = changeSchema;
|
|
21090
|
+
props.form.setDatabase = changeDatabase;
|
|
21091
|
+
|
|
21092
|
+
props.form.getSchema = function () {
|
|
21093
|
+
return schema;
|
|
21094
|
+
};
|
|
21095
|
+
|
|
21096
|
+
props.form.getDatabase = function () {
|
|
21097
|
+
return database;
|
|
21098
|
+
};
|
|
21099
|
+
}
|
|
21100
|
+
|
|
21101
|
+
useEffect(function () {
|
|
21102
|
+
changeDatabase(props.schema);
|
|
21103
|
+
}, [props.schema]);
|
|
21104
|
+
useEffect(function () {
|
|
21105
|
+
changeDatabase(props.database);
|
|
21106
|
+
}, [props.database]);
|
|
21097
21107
|
return debug ? /*#__PURE__*/React.createElement(MViewerDebug, Object.assign({
|
|
21098
21108
|
key: k
|
|
21099
21109
|
}, props, {
|
|
21100
21110
|
database: database,
|
|
21101
21111
|
schema: schema,
|
|
21102
|
-
changeSchema: changeSchema
|
|
21112
|
+
changeSchema: changeSchema,
|
|
21113
|
+
changeDatabase: changeDatabase
|
|
21103
21114
|
})) : /*#__PURE__*/React.createElement(MViewer, Object.assign({
|
|
21104
21115
|
key: k
|
|
21105
21116
|
}, props, {
|
|
21106
21117
|
database: database,
|
|
21107
21118
|
schema: schema,
|
|
21108
|
-
changeSchema: changeSchema
|
|
21119
|
+
changeSchema: changeSchema,
|
|
21120
|
+
changeDatabase: changeDatabase
|
|
21109
21121
|
}));
|
|
21110
21122
|
};
|
|
21123
|
+
function useForm() {
|
|
21124
|
+
return {
|
|
21125
|
+
setSchema: function setSchema(v) {},
|
|
21126
|
+
setDatabase: function setDatabase(v) {},
|
|
21127
|
+
getSchema: function getSchema() {},
|
|
21128
|
+
getDatabase: function getDatabase() {}
|
|
21129
|
+
};
|
|
21130
|
+
}
|
|
21111
21131
|
|
|
21112
|
-
export { Ajax, Assembly, BaseViewer, EmtpyType, M3, MContext, MFieldViewer, MUtil, MViewer, MViewerDebug, Segment, SegmentEditSwitch, SubmitBar, UnderlineInputBox, Validator, Viewer, assembly, createDefaultValue, M3 as default, ensureM3, useM3Database };
|
|
21132
|
+
export { Ajax, Assembly, BaseViewer, EmtpyType, M3, MContext, MFieldViewer, MUtil, MViewer, MViewerDebug, Segment, SegmentEditSwitch, SubmitBar, UnderlineInputBox, Validator, Viewer, assembly, createDefaultValue, M3 as default, ensureM3, useForm, useM3Database };
|
package/lib/m3.js
CHANGED
|
@@ -1233,6 +1233,7 @@ var MFieldViewer = /*#__PURE__*/function (_React$Component) {
|
|
|
1233
1233
|
var props = _objectSpread$e({
|
|
1234
1234
|
afterChange: function afterChange() {},
|
|
1235
1235
|
changeSchema: function changeSchema() {},
|
|
1236
|
+
changeDatabase: function changeDatabase() {},
|
|
1236
1237
|
name: this.props.path
|
|
1237
1238
|
}, this.props);
|
|
1238
1239
|
|
|
@@ -18129,6 +18130,7 @@ var AForm = /*#__PURE__*/function (_Viewer) {
|
|
|
18129
18130
|
},
|
|
18130
18131
|
parent: this.props.schema,
|
|
18131
18132
|
changeSchema: this.props.changeSchema,
|
|
18133
|
+
changeDatabase: this.props.changeDatabase,
|
|
18132
18134
|
forceValid: this.props.forceValid,
|
|
18133
18135
|
style: {
|
|
18134
18136
|
width: "100%"
|
|
@@ -20774,7 +20776,8 @@ var MViewer = /*#__PURE__*/function (_React$Component) {
|
|
|
20774
20776
|
path: "",
|
|
20775
20777
|
morph: props.morph,
|
|
20776
20778
|
afterChange: PersistantTool.patchAfterChange(props.afterChange, props.persistant),
|
|
20777
|
-
changeSchema: props.changeSchema
|
|
20779
|
+
changeSchema: props.changeSchema,
|
|
20780
|
+
changeDatabase: props.changeDatabase
|
|
20778
20781
|
}), props.children));
|
|
20779
20782
|
};
|
|
20780
20783
|
|
|
@@ -21077,57 +21080,74 @@ function standardSchema(schema, layout) {
|
|
|
21077
21080
|
}
|
|
21078
21081
|
|
|
21079
21082
|
var M3 = function M3(props) {
|
|
21080
|
-
var _useState = React.useState(props),
|
|
21081
|
-
|
|
21082
|
-
|
|
21083
|
+
var _useState = React.useState(___default["default"].cloneDeep(props.database)),
|
|
21084
|
+
database = _useState[0],
|
|
21085
|
+
setDatabase = _useState[1];
|
|
21083
21086
|
|
|
21084
|
-
var _useState2 = React.useState(
|
|
21085
|
-
|
|
21086
|
-
|
|
21087
|
+
var _useState2 = React.useState(standardSchema(props.schema)),
|
|
21088
|
+
schema = _useState2[0],
|
|
21089
|
+
setSchema = _useState2[1];
|
|
21087
21090
|
|
|
21088
|
-
var _useState3 = React.useState(
|
|
21089
|
-
|
|
21090
|
-
|
|
21091
|
-
|
|
21092
|
-
var _useState4 = React.useState(0),
|
|
21093
|
-
k = _useState4[0],
|
|
21094
|
-
setK = _useState4[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
21091
|
+
var _useState3 = React.useState(0),
|
|
21092
|
+
k = _useState3[0],
|
|
21093
|
+
setK = _useState3[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
21095
21094
|
|
|
21096
21095
|
|
|
21097
21096
|
var debug = props.debug || window.location.search.indexOf("debug") >= 0 || window.location.hash.indexOf("debug") >= 0;
|
|
21098
|
-
React.useEffect(function () {
|
|
21099
|
-
if (props.schema != prevProp.schema) {
|
|
21100
|
-
setSchema(standardSchema(props.schema));
|
|
21101
|
-
setPrevProp(props);
|
|
21102
|
-
setK(++k);
|
|
21103
|
-
}
|
|
21104
|
-
}, [props.schema]);
|
|
21105
|
-
React.useEffect(function () {
|
|
21106
|
-
if (props.database != prevProp.database) {
|
|
21107
|
-
setDatabase(___default["default"].cloneDeep(props.database));
|
|
21108
|
-
setPrevProp(props);
|
|
21109
|
-
setK(++k);
|
|
21110
|
-
}
|
|
21111
|
-
}, [props.database]);
|
|
21112
21097
|
|
|
21113
21098
|
var changeSchema = function changeSchema(v) {
|
|
21114
|
-
|
|
21099
|
+
setSchema(standardSchema(v));
|
|
21100
|
+
setK(++k);
|
|
21101
|
+
};
|
|
21102
|
+
|
|
21103
|
+
var changeDatabase = function changeDatabase(v) {
|
|
21104
|
+
setDatabase(___default["default"].cloneDeep(v));
|
|
21105
|
+
setK(++k);
|
|
21115
21106
|
};
|
|
21116
21107
|
|
|
21108
|
+
if (props.form) {
|
|
21109
|
+
props.form.setSchema = changeSchema;
|
|
21110
|
+
props.form.setDatabase = changeDatabase;
|
|
21111
|
+
|
|
21112
|
+
props.form.getSchema = function () {
|
|
21113
|
+
return schema;
|
|
21114
|
+
};
|
|
21115
|
+
|
|
21116
|
+
props.form.getDatabase = function () {
|
|
21117
|
+
return database;
|
|
21118
|
+
};
|
|
21119
|
+
}
|
|
21120
|
+
|
|
21121
|
+
React.useEffect(function () {
|
|
21122
|
+
changeDatabase(props.schema);
|
|
21123
|
+
}, [props.schema]);
|
|
21124
|
+
React.useEffect(function () {
|
|
21125
|
+
changeDatabase(props.database);
|
|
21126
|
+
}, [props.database]);
|
|
21117
21127
|
return debug ? /*#__PURE__*/React__default["default"].createElement(MViewerDebug, Object.assign({
|
|
21118
21128
|
key: k
|
|
21119
21129
|
}, props, {
|
|
21120
21130
|
database: database,
|
|
21121
21131
|
schema: schema,
|
|
21122
|
-
changeSchema: changeSchema
|
|
21132
|
+
changeSchema: changeSchema,
|
|
21133
|
+
changeDatabase: changeDatabase
|
|
21123
21134
|
})) : /*#__PURE__*/React__default["default"].createElement(MViewer, Object.assign({
|
|
21124
21135
|
key: k
|
|
21125
21136
|
}, props, {
|
|
21126
21137
|
database: database,
|
|
21127
21138
|
schema: schema,
|
|
21128
|
-
changeSchema: changeSchema
|
|
21139
|
+
changeSchema: changeSchema,
|
|
21140
|
+
changeDatabase: changeDatabase
|
|
21129
21141
|
}));
|
|
21130
21142
|
};
|
|
21143
|
+
function useForm() {
|
|
21144
|
+
return {
|
|
21145
|
+
setSchema: function setSchema(v) {},
|
|
21146
|
+
setDatabase: function setDatabase(v) {},
|
|
21147
|
+
getSchema: function getSchema() {},
|
|
21148
|
+
getDatabase: function getDatabase() {}
|
|
21149
|
+
};
|
|
21150
|
+
}
|
|
21131
21151
|
|
|
21132
21152
|
exports.Ajax = Ajax;
|
|
21133
21153
|
exports.Assembly = Assembly;
|
|
@@ -21149,4 +21169,5 @@ exports.assembly = assembly;
|
|
|
21149
21169
|
exports.createDefaultValue = createDefaultValue;
|
|
21150
21170
|
exports["default"] = M3;
|
|
21151
21171
|
exports.ensureM3 = ensureM3;
|
|
21172
|
+
exports.useForm = useForm;
|
|
21152
21173
|
exports.useM3Database = useM3Database;
|
package/package.json
CHANGED
package/src/framework/M3.tsx
CHANGED
|
@@ -7,10 +7,10 @@ import _ from "lodash";
|
|
|
7
7
|
|
|
8
8
|
// 外部 schema 转化为内部
|
|
9
9
|
function deal(fieldSchema: MFieldSchemaAnonymity | MFieldSchema) {
|
|
10
|
-
if(fieldSchema.arrayMember){
|
|
11
|
-
|
|
12
|
-
} else if(fieldSchema.objectFields){
|
|
13
|
-
for(let f of fieldSchema.objectFields){
|
|
10
|
+
if (fieldSchema.arrayMember) {
|
|
11
|
+
deal(fieldSchema.arrayMember);
|
|
12
|
+
} else if (fieldSchema.objectFields) {
|
|
13
|
+
for (let f of fieldSchema.objectFields) {
|
|
14
14
|
deal(f);
|
|
15
15
|
}
|
|
16
16
|
} else {
|
|
@@ -38,7 +38,7 @@ function deal(fieldSchema: MFieldSchemaAnonymity | MFieldSchema) {
|
|
|
38
38
|
|
|
39
39
|
// 标准化 schema
|
|
40
40
|
function standardSchema(schema: MFieldSchema | MFieldSchema[], layout?: M3UISpec) {
|
|
41
|
-
const _schema =
|
|
41
|
+
const _schema = _.cloneDeep(schema)
|
|
42
42
|
if (_.isArray(_schema)) {
|
|
43
43
|
_schema.forEach(item => {
|
|
44
44
|
deal(item)
|
|
@@ -59,7 +59,6 @@ function standardSchema(schema: MFieldSchema | MFieldSchema[], layout?: M3UISpec
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
const M3 = (props: React.PropsWithChildren<M3Prop & { debug?: boolean }>) => {
|
|
62
|
-
const [prevProp, setPrevProp] = useState(props);
|
|
63
62
|
|
|
64
63
|
let [database, setDatabase] = useState(_.cloneDeep(props.database))
|
|
65
64
|
let [schema, setSchema] = useState(standardSchema(props.schema))
|
|
@@ -68,28 +67,43 @@ const M3 = (props: React.PropsWithChildren<M3Prop & { debug?: boolean }>) => {
|
|
|
68
67
|
// debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
|
|
69
68
|
let debug = props.debug || (window.location.search.indexOf("debug") >= 0 || window.location.hash.indexOf("debug") >= 0);
|
|
70
69
|
|
|
70
|
+
const changeSchema = v => {
|
|
71
|
+
setSchema(standardSchema(v))
|
|
72
|
+
setK(++k)
|
|
73
|
+
}
|
|
74
|
+
const changeDatabase = v => {
|
|
75
|
+
setDatabase(_.cloneDeep(v))
|
|
76
|
+
setK(++k)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (props.form) {
|
|
80
|
+
props.form.setSchema = changeSchema
|
|
81
|
+
props.form.setDatabase = changeDatabase
|
|
82
|
+
props.form.getSchema = () => schema
|
|
83
|
+
props.form.getDatabase = () => database
|
|
84
|
+
}
|
|
85
|
+
|
|
71
86
|
useEffect(() => {
|
|
72
|
-
|
|
73
|
-
setSchema(standardSchema(props.schema))
|
|
74
|
-
setPrevProp(props);
|
|
75
|
-
setK(++k)
|
|
76
|
-
}
|
|
87
|
+
changeDatabase(props.schema)
|
|
77
88
|
}, [props.schema])
|
|
78
89
|
|
|
79
90
|
useEffect(() => {
|
|
80
|
-
|
|
81
|
-
setDatabase(_.cloneDeep(props.database))
|
|
82
|
-
setPrevProp(props);
|
|
83
|
-
setK(++k)
|
|
84
|
-
}
|
|
91
|
+
changeDatabase(props.database)
|
|
85
92
|
}, [props.database])
|
|
86
93
|
|
|
87
|
-
const changeSchema = v => setSchema(standardSchema(v))
|
|
88
|
-
|
|
89
94
|
return (
|
|
90
|
-
|
|
91
|
-
<MViewer key={k} {...props} database={database} schema={schema} changeSchema={changeSchema}/>
|
|
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} />
|
|
92
97
|
);
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
export default M3;
|
|
101
|
+
|
|
102
|
+
export function useForm() {
|
|
103
|
+
return {
|
|
104
|
+
setSchema: (v) => { },
|
|
105
|
+
setDatabase: (v) => { },
|
|
106
|
+
getSchema: () => { },
|
|
107
|
+
getDatabase: () => { },
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -18,6 +18,7 @@ export class MFieldViewer extends React.Component<MProp, any> {
|
|
|
18
18
|
const props = {
|
|
19
19
|
afterChange: () => { }, // 给afterChange一个默认值
|
|
20
20
|
changeSchema: () => { }, // 给changeSchema一个默认值
|
|
21
|
+
changeDatabase: () => { }, // 给changeDatabase一个默认值
|
|
21
22
|
name: this.props.path,
|
|
22
23
|
...this.props
|
|
23
24
|
};
|
|
@@ -19,6 +19,7 @@ export interface MViewerProp {
|
|
|
19
19
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
20
20
|
afterChange?: AFTER_CHANGE_CALLBACK,
|
|
21
21
|
changeSchema?: CHANGE_SCHEMA_CALLBACK,
|
|
22
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK,
|
|
22
23
|
wrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement,
|
|
23
24
|
formItemWrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement,
|
|
24
25
|
/** 持久存储选项,nil表示不持久存储 */
|
|
@@ -28,12 +29,14 @@ export interface MViewerProp {
|
|
|
28
29
|
export interface M3Prop {
|
|
29
30
|
schema: MFieldSchema | MFieldSchema[],
|
|
30
31
|
database: any,
|
|
32
|
+
form?: any,
|
|
31
33
|
layout?: M3UISpec,
|
|
32
34
|
style?: React.CSSProperties,
|
|
33
35
|
morph: MORPH,
|
|
34
36
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
35
37
|
afterChange?: AFTER_CHANGE_CALLBACK,
|
|
36
38
|
changeSchema?: CHANGE_SCHEMA_CALLBACK,
|
|
39
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK,
|
|
37
40
|
wrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement,
|
|
38
41
|
formItemWrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement,
|
|
39
42
|
/** 持久存储选项,nil表示不持久存储 */
|
|
@@ -84,13 +87,21 @@ export class MViewer extends React.Component<MViewerProp, State> {
|
|
|
84
87
|
const props = this.props;
|
|
85
88
|
const database = this.database;
|
|
86
89
|
const { ctrlVersion, forceValid } = this.state
|
|
87
|
-
|
|
90
|
+
|
|
88
91
|
return <MContext.Provider value={{
|
|
89
92
|
rootProps: props,
|
|
90
93
|
forceValid, setForceValid: (b) => { this.setState({ forceValid: true }) }
|
|
91
94
|
}}>
|
|
92
95
|
<div key={ctrlVersion} className={MUtil.phoneLike() ? "MEditor_p" : "MEditor"} style={props.style}>
|
|
93
|
-
<MFieldViewer
|
|
96
|
+
<MFieldViewer
|
|
97
|
+
schema={props.schema}
|
|
98
|
+
database={database}
|
|
99
|
+
path=""
|
|
100
|
+
morph={props.morph}
|
|
101
|
+
afterChange={PersistantTool.patchAfterChange(props.afterChange, props.persistant)}
|
|
102
|
+
changeSchema={props.changeSchema}
|
|
103
|
+
changeDatabase={props.changeDatabase}
|
|
104
|
+
/>
|
|
94
105
|
{props.children}
|
|
95
106
|
</div>
|
|
96
107
|
</MContext.Provider>
|
package/src/framework/Schema.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { MViewerDebug } from './framework/MViewerDebug';
|
|
|
6
6
|
import { MORPH, VIEWER, assembly, MTheme, Assembly } from './framework/Assembly';
|
|
7
7
|
import { ViewerState, Viewer, BaseViewer } from './ui/BaseViewer';
|
|
8
8
|
import { MViewer, SubmitBar, useM3Database } from './framework/MViewer';
|
|
9
|
-
import M3 from './framework/M3';
|
|
9
|
+
import M3 , {useForm} from './framework/M3';
|
|
10
10
|
import { MFieldViewer } from './framework/MFieldViewer';
|
|
11
11
|
import { MContext } from './framework/MContext';
|
|
12
12
|
import { MUtil } from './framework/MUtil';
|
|
@@ -19,6 +19,7 @@ import { MType, EmtpyType, createDefaultValue } from './types/MType';
|
|
|
19
19
|
|
|
20
20
|
export {
|
|
21
21
|
M3,
|
|
22
|
+
useForm,
|
|
22
23
|
MContext, MFieldViewer, BaseViewer, assembly, SegmentEditSwitch, Viewer, UnderlineInputBox, Segment, MUtil, Ajax,
|
|
23
24
|
MViewer,
|
|
24
25
|
MViewerDebug, SubmitBar,
|
|
@@ -142,7 +142,7 @@ export class AForm extends Viewer<State> {
|
|
|
142
142
|
//this.setState({shouldAnimation: shouldAnimation(hideMap, newHideMap, objectFields)});
|
|
143
143
|
this.setState({});
|
|
144
144
|
}
|
|
145
|
-
}} parent={this.props.schema} changeSchema={this.props.changeSchema} forceValid={this.props.forceValid} style={{ width: "100%" }} />
|
|
145
|
+
}} parent={this.props.schema} changeSchema={this.props.changeSchema} changeDatabase={this.props.changeDatabase} forceValid={this.props.forceValid} style={{ width: "100%" }} />
|
|
146
146
|
|
|
147
147
|
let ele;
|
|
148
148
|
if(uispec.layout === "vertical") { // label在字段上面的分段布局
|
package/types/framework/M3.d.ts
CHANGED
|
@@ -4,3 +4,9 @@ declare const M3: (props: React.PropsWithChildren<M3Prop & {
|
|
|
4
4
|
debug?: boolean;
|
|
5
5
|
}>) => JSX.Element;
|
|
6
6
|
export default M3;
|
|
7
|
+
export declare function useForm(): {
|
|
8
|
+
setSchema: (v: any) => void;
|
|
9
|
+
setDatabase: (v: any) => void;
|
|
10
|
+
getSchema: () => void;
|
|
11
|
+
getDatabase: () => void;
|
|
12
|
+
};
|
|
@@ -12,6 +12,7 @@ export interface MViewerProp {
|
|
|
12
12
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
13
13
|
afterChange?: AFTER_CHANGE_CALLBACK;
|
|
14
14
|
changeSchema?: CHANGE_SCHEMA_CALLBACK;
|
|
15
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK;
|
|
15
16
|
wrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement;
|
|
16
17
|
formItemWrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement;
|
|
17
18
|
/** 持久存储选项,nil表示不持久存储 */
|
|
@@ -20,12 +21,14 @@ export interface MViewerProp {
|
|
|
20
21
|
export interface M3Prop {
|
|
21
22
|
schema: MFieldSchema | MFieldSchema[];
|
|
22
23
|
database: any;
|
|
24
|
+
form?: any;
|
|
23
25
|
layout?: M3UISpec;
|
|
24
26
|
style?: React.CSSProperties;
|
|
25
27
|
morph: MORPH;
|
|
26
28
|
onSubmit?: (finalData: any) => Promise<any>;
|
|
27
29
|
afterChange?: AFTER_CHANGE_CALLBACK;
|
|
28
30
|
changeSchema?: CHANGE_SCHEMA_CALLBACK;
|
|
31
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK;
|
|
29
32
|
wrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement;
|
|
30
33
|
formItemWrapper?: (elem: React.ReactElement, schema: Partial<MFieldSchema>) => React.ReactElement;
|
|
31
34
|
/** 持久存储选项,nil表示不持久存储 */
|
|
@@ -264,6 +264,8 @@ export interface MProp {
|
|
|
264
264
|
afterChange?: AFTER_CHANGE_CALLBACK;
|
|
265
265
|
/** 修改schema */
|
|
266
266
|
changeSchema?: CHANGE_SCHEMA_CALLBACK;
|
|
267
|
+
/** 修改database */
|
|
268
|
+
changeDatabase?: CHANGE_SCHEMA_CALLBACK;
|
|
267
269
|
/** @deprecated 直接上层。有时parent是谁,会影响渲染字段 */
|
|
268
270
|
parent?: MFieldSchemaAnonymity;
|
|
269
271
|
/** 强制展示校验信息 */
|
package/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { MViewerDebug } from './framework/MViewerDebug';
|
|
|
6
6
|
import { MORPH, VIEWER, assembly, MTheme, Assembly } from './framework/Assembly';
|
|
7
7
|
import { ViewerState, Viewer, BaseViewer } from './ui/BaseViewer';
|
|
8
8
|
import { MViewer, SubmitBar, useM3Database } from './framework/MViewer';
|
|
9
|
-
import M3 from './framework/M3';
|
|
9
|
+
import M3, { useForm } from './framework/M3';
|
|
10
10
|
import { MFieldViewer } from './framework/MFieldViewer';
|
|
11
11
|
import { MContext } from './framework/MContext';
|
|
12
12
|
import { MUtil } from './framework/MUtil';
|
|
@@ -16,6 +16,6 @@ import { SegmentEditSwitch, SegmentEditSwitchState } from './ui/widget/SegmentEd
|
|
|
16
16
|
import { ensureM3 } from './framework/Init';
|
|
17
17
|
import Validator from './framework/Validator';
|
|
18
18
|
import { MType, EmtpyType, createDefaultValue } from './types/MType';
|
|
19
|
-
export { M3, MContext, MFieldViewer, BaseViewer, assembly, SegmentEditSwitch, Viewer, UnderlineInputBox, Segment, MUtil, Ajax, MViewer, MViewerDebug, SubmitBar, useM3Database, ensureM3, Validator, EmtpyType, createDefaultValue, Assembly };
|
|
19
|
+
export { M3, useForm, MContext, MFieldViewer, BaseViewer, assembly, SegmentEditSwitch, Viewer, UnderlineInputBox, Segment, MUtil, Ajax, MViewer, MViewerDebug, SubmitBar, useM3Database, ensureM3, Validator, EmtpyType, createDefaultValue, Assembly };
|
|
20
20
|
export type { M3UISpec, ViewerState, SegmentEditSwitchState, M3UISpecSegmentItem, MFieldSchema, MFieldSchemaAnonymity, MORPH, VIEWER, MType, MTheme };
|
|
21
21
|
export default M3;
|