form-driver 0.1.21 → 0.2.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/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%"
@@ -18806,7 +18808,11 @@ var AArrayGrid = /*#__PURE__*/function (_BaseViewer) {
18806
18808
 
18807
18809
  return /*#__PURE__*/React.createElement("th", {
18808
18810
  key: f.name + i + ":first"
18809
- }, (_f$label = f.label) != null ? _f$label : f.name);
18811
+ }, f.required ? /*#__PURE__*/React.createElement("span", {
18812
+ style: {
18813
+ color: "red"
18814
+ }
18815
+ }, "*") : null, (_f$label = f.label) != null ? _f$label : f.name);
18810
18816
  }), /*#__PURE__*/React.createElement("td", {
18811
18817
  key: ":\u64CD\u4F5C\u680F",
18812
18818
  width: "40px",
@@ -20754,7 +20760,8 @@ var MViewer = /*#__PURE__*/function (_React$Component) {
20754
20760
  path: "",
20755
20761
  morph: props.morph,
20756
20762
  afterChange: PersistantTool.patchAfterChange(props.afterChange, props.persistant),
20757
- changeSchema: props.changeSchema
20763
+ changeSchema: props.changeSchema,
20764
+ changeDatabase: props.changeDatabase
20758
20765
  }), props.children));
20759
20766
  };
20760
20767
 
@@ -21057,56 +21064,73 @@ function standardSchema(schema, layout) {
21057
21064
  }
21058
21065
 
21059
21066
  var M3 = function M3(props) {
21060
- var _useState = useState(props),
21061
- prevProp = _useState[0],
21062
- setPrevProp = _useState[1];
21063
-
21064
- var _useState2 = useState(_.cloneDeep(props.database)),
21065
- database = _useState2[0],
21066
- setDatabase = _useState2[1];
21067
+ var _useState = useState(_.cloneDeep(props.database)),
21068
+ database = _useState[0],
21069
+ setDatabase = _useState[1];
21067
21070
 
21068
- var _useState3 = useState(standardSchema(props.schema)),
21069
- schema = _useState3[0],
21070
- setSchema = _useState3[1];
21071
+ var _useState2 = useState(standardSchema(props.schema)),
21072
+ schema = _useState2[0],
21073
+ setSchema = _useState2[1];
21071
21074
 
21072
- var _useState4 = useState(0),
21073
- k = _useState4[0],
21074
- setK = _useState4[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
21075
+ var _useState3 = useState(0),
21076
+ k = _useState3[0],
21077
+ setK = _useState3[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
21075
21078
 
21076
21079
 
21077
21080
  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
21081
 
21093
21082
  var changeSchema = function changeSchema(v) {
21094
- return setSchema(standardSchema(v));
21083
+ setSchema(standardSchema(v));
21084
+ setK(++k);
21095
21085
  };
21096
21086
 
21087
+ var changeDatabase = function changeDatabase(v) {
21088
+ setDatabase(_.cloneDeep(v));
21089
+ setK(++k);
21090
+ };
21091
+
21092
+ if (props.form) {
21093
+ props.form.setSchema = changeSchema;
21094
+ props.form.setDatabase = changeDatabase;
21095
+
21096
+ props.form.getSchema = function () {
21097
+ return schema;
21098
+ };
21099
+
21100
+ props.form.getDatabase = function () {
21101
+ return database;
21102
+ };
21103
+ }
21104
+
21105
+ useEffect(function () {
21106
+ changeDatabase(props.schema);
21107
+ }, [props.schema]);
21108
+ useEffect(function () {
21109
+ changeDatabase(props.database);
21110
+ }, [props.database]);
21097
21111
  return debug ? /*#__PURE__*/React.createElement(MViewerDebug, Object.assign({
21098
21112
  key: k
21099
21113
  }, props, {
21100
21114
  database: database,
21101
21115
  schema: schema,
21102
- changeSchema: changeSchema
21116
+ changeSchema: changeSchema,
21117
+ changeDatabase: changeDatabase
21103
21118
  })) : /*#__PURE__*/React.createElement(MViewer, Object.assign({
21104
21119
  key: k
21105
21120
  }, props, {
21106
21121
  database: database,
21107
21122
  schema: schema,
21108
- changeSchema: changeSchema
21123
+ changeSchema: changeSchema,
21124
+ changeDatabase: changeDatabase
21109
21125
  }));
21110
21126
  };
21127
+ function useForm() {
21128
+ return {
21129
+ setSchema: function setSchema(v) {},
21130
+ setDatabase: function setDatabase(v) {},
21131
+ getSchema: function getSchema() {},
21132
+ getDatabase: function getDatabase() {}
21133
+ };
21134
+ }
21111
21135
 
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 };
21136
+ 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%"
@@ -18826,7 +18828,11 @@ var AArrayGrid = /*#__PURE__*/function (_BaseViewer) {
18826
18828
 
18827
18829
  return /*#__PURE__*/React__default["default"].createElement("th", {
18828
18830
  key: f.name + i + ":first"
18829
- }, (_f$label = f.label) != null ? _f$label : f.name);
18831
+ }, f.required ? /*#__PURE__*/React__default["default"].createElement("span", {
18832
+ style: {
18833
+ color: "red"
18834
+ }
18835
+ }, "*") : null, (_f$label = f.label) != null ? _f$label : f.name);
18830
18836
  }), /*#__PURE__*/React__default["default"].createElement("td", {
18831
18837
  key: ":\u64CD\u4F5C\u680F",
18832
18838
  width: "40px",
@@ -20774,7 +20780,8 @@ var MViewer = /*#__PURE__*/function (_React$Component) {
20774
20780
  path: "",
20775
20781
  morph: props.morph,
20776
20782
  afterChange: PersistantTool.patchAfterChange(props.afterChange, props.persistant),
20777
- changeSchema: props.changeSchema
20783
+ changeSchema: props.changeSchema,
20784
+ changeDatabase: props.changeDatabase
20778
20785
  }), props.children));
20779
20786
  };
20780
20787
 
@@ -21077,57 +21084,74 @@ function standardSchema(schema, layout) {
21077
21084
  }
21078
21085
 
21079
21086
  var M3 = function M3(props) {
21080
- var _useState = React.useState(props),
21081
- prevProp = _useState[0],
21082
- setPrevProp = _useState[1];
21083
-
21084
- var _useState2 = React.useState(___default["default"].cloneDeep(props.database)),
21085
- database = _useState2[0],
21086
- setDatabase = _useState2[1];
21087
+ var _useState = React.useState(___default["default"].cloneDeep(props.database)),
21088
+ database = _useState[0],
21089
+ setDatabase = _useState[1];
21087
21090
 
21088
- var _useState3 = React.useState(standardSchema(props.schema)),
21089
- schema = _useState3[0],
21090
- setSchema = _useState3[1];
21091
+ var _useState2 = React.useState(standardSchema(props.schema)),
21092
+ schema = _useState2[0],
21093
+ setSchema = _useState2[1];
21091
21094
 
21092
- var _useState4 = React.useState(0),
21093
- k = _useState4[0],
21094
- setK = _useState4[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
21095
+ var _useState3 = React.useState(0),
21096
+ k = _useState3[0],
21097
+ setK = _useState3[1]; // debug 属性为真 且 页面地址携带 debug 参数,开启调试模式
21095
21098
 
21096
21099
 
21097
21100
  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
21101
 
21113
21102
  var changeSchema = function changeSchema(v) {
21114
- return setSchema(standardSchema(v));
21103
+ setSchema(standardSchema(v));
21104
+ setK(++k);
21115
21105
  };
21116
21106
 
21107
+ var changeDatabase = function changeDatabase(v) {
21108
+ setDatabase(___default["default"].cloneDeep(v));
21109
+ setK(++k);
21110
+ };
21111
+
21112
+ if (props.form) {
21113
+ props.form.setSchema = changeSchema;
21114
+ props.form.setDatabase = changeDatabase;
21115
+
21116
+ props.form.getSchema = function () {
21117
+ return schema;
21118
+ };
21119
+
21120
+ props.form.getDatabase = function () {
21121
+ return database;
21122
+ };
21123
+ }
21124
+
21125
+ React.useEffect(function () {
21126
+ changeDatabase(props.schema);
21127
+ }, [props.schema]);
21128
+ React.useEffect(function () {
21129
+ changeDatabase(props.database);
21130
+ }, [props.database]);
21117
21131
  return debug ? /*#__PURE__*/React__default["default"].createElement(MViewerDebug, Object.assign({
21118
21132
  key: k
21119
21133
  }, props, {
21120
21134
  database: database,
21121
21135
  schema: schema,
21122
- changeSchema: changeSchema
21136
+ changeSchema: changeSchema,
21137
+ changeDatabase: changeDatabase
21123
21138
  })) : /*#__PURE__*/React__default["default"].createElement(MViewer, Object.assign({
21124
21139
  key: k
21125
21140
  }, props, {
21126
21141
  database: database,
21127
21142
  schema: schema,
21128
- changeSchema: changeSchema
21143
+ changeSchema: changeSchema,
21144
+ changeDatabase: changeDatabase
21129
21145
  }));
21130
21146
  };
21147
+ function useForm() {
21148
+ return {
21149
+ setSchema: function setSchema(v) {},
21150
+ setDatabase: function setDatabase(v) {},
21151
+ getSchema: function getSchema() {},
21152
+ getDatabase: function getDatabase() {}
21153
+ };
21154
+ }
21131
21155
 
21132
21156
  exports.Ajax = Ajax;
21133
21157
  exports.Assembly = Assembly;
@@ -21149,4 +21173,5 @@ exports.assembly = assembly;
21149
21173
  exports.createDefaultValue = createDefaultValue;
21150
21174
  exports["default"] = M3;
21151
21175
  exports.ensureM3 = ensureM3;
21176
+ exports.useForm = useForm;
21152
21177
  exports.useM3Database = useM3Database;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "form-driver",
3
- "version": "0.1.21",
3
+ "version": "0.2.0",
4
4
  "description": "An efficient framework for creating forms.",
5
5
  "license": "MIT",
6
6
  "authors": [
@@ -7,10 +7,10 @@ import _ from "lodash";
7
7
 
8
8
  // 外部 schema 转化为内部
9
9
  function deal(fieldSchema: MFieldSchemaAnonymity | MFieldSchema) {
10
- if(fieldSchema.arrayMember){
11
- deal(fieldSchema.arrayMember);
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 = _.cloneDeep(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
- if(props.schema != prevProp.schema) {
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
- if(props.database != prevProp.database) {
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
- debug ? <MViewerDebug key={k} {...props} database={database} schema={schema} changeSchema={changeSchema}/> :
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 schema={props.schema} database={database} path="" morph={props.morph} afterChange={PersistantTool.patchAfterChange(props.afterChange, props.persistant)} changeSchema={props.changeSchema}/>
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>
@@ -335,6 +335,9 @@ export interface MProp {
335
335
  /** 修改schema */
336
336
  changeSchema?: CHANGE_SCHEMA_CALLBACK,
337
337
 
338
+ /** 修改database */
339
+ changeDatabase?: CHANGE_SCHEMA_CALLBACK,
340
+
338
341
  /** @deprecated 直接上层。有时parent是谁,会影响渲染字段 */
339
342
  parent?: MFieldSchemaAnonymity,
340
343
 
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,
@@ -41,6 +41,7 @@ function uuid(len = 8, radix = 16) {
41
41
  * {from:"1606997544611",to:"", tillNow:true, company:"阿里巴巴", position:"CEO"},
42
42
  * ]
43
43
  */
44
+
44
45
  export class AArrayGrid extends BaseViewer {
45
46
  element() {
46
47
  const schema = this.props.schema;
@@ -118,7 +119,7 @@ export class AArrayGrid extends BaseViewer {
118
119
  return (
119
120
  <table key={this.props.path} className="AExperience M3_table" style={{ width: "100%" }}><tbody>
120
121
  <tr key=":header">
121
- {members.map((f, i) => <th key={f.name + i + ":first"}>{f.label ?? f.name}</th>)}
122
+ {members.map((f, i) => <th key={f.name + i + ":first"}>{f.required ? <span style={{ color: "red" }}>*</span> : null}{f.label ?? f.name}</th>)}
122
123
  <td key=":操作栏" width="40px" align="center"></td>
123
124
  </tr>
124
125
  {rows}
@@ -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在字段上面的分段布局
@@ -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;