@byteluck-fe/model-driven-engine 1.3.0-beta.25

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 (42) hide show
  1. package/README.md +30 -0
  2. package/dist/esm/common/ActionManager.js +135 -0
  3. package/dist/esm/common/DataManager.js +77 -0
  4. package/dist/esm/common/Engine.js +1161 -0
  5. package/dist/esm/common/OkWorker.js +89 -0
  6. package/dist/esm/common/Plugin.js +10 -0
  7. package/dist/esm/common/Runtime.js +257 -0
  8. package/dist/esm/common/Store.js +331 -0
  9. package/dist/esm/common/checkerValue.js +547 -0
  10. package/dist/esm/common/index.js +2 -0
  11. package/dist/esm/common/proxyState.js +316 -0
  12. package/dist/esm/index.js +3 -0
  13. package/dist/esm/plugins/CalcPlugin.js +394 -0
  14. package/dist/esm/plugins/ControlsEventPlugin.js +168 -0
  15. package/dist/esm/plugins/ES6ModulePlugin.js +145 -0
  16. package/dist/esm/plugins/LifecycleEventPlugin.js +180 -0
  17. package/dist/esm/plugins/StylePlugin.js +26 -0
  18. package/dist/esm/plugins/index.js +5 -0
  19. package/dist/esm/utils/index.js +1 -0
  20. package/dist/esm/utils/runtimeUtils.js +48 -0
  21. package/dist/index.umd.js +2 -0
  22. package/dist/types/common/ActionManager.d.ts +14 -0
  23. package/dist/types/common/DataManager.d.ts +10 -0
  24. package/dist/types/common/Engine.d.ts +165 -0
  25. package/dist/types/common/OkWorker.d.ts +13 -0
  26. package/dist/types/common/Plugin.d.ts +6 -0
  27. package/dist/types/common/Runtime.d.ts +22 -0
  28. package/dist/types/common/Store.d.ts +49 -0
  29. package/dist/types/common/checkerValue.d.ts +3 -0
  30. package/dist/types/common/index.d.ts +2 -0
  31. package/dist/types/common/proxyState.d.ts +29 -0
  32. package/dist/types/index.d.ts +3 -0
  33. package/dist/types/plugins/CalcPlugin.d.ts +121 -0
  34. package/dist/types/plugins/ControlsEventPlugin.d.ts +15 -0
  35. package/dist/types/plugins/ES6ModulePlugin.d.ts +25 -0
  36. package/dist/types/plugins/LifecycleEventPlugin.d.ts +14 -0
  37. package/dist/types/plugins/StylePlugin.d.ts +12 -0
  38. package/dist/types/plugins/index.d.ts +5 -0
  39. package/dist/types/utils/index.d.ts +1 -0
  40. package/dist/types/utils/runtimeUtils.d.ts +4 -0
  41. package/package.json +32 -0
  42. package/src/index.ts +3 -0
@@ -0,0 +1,89 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ import { log } from "@byteluck-fe/model-driven-shared";
7
+ var OkWorker = /*#__PURE__*/ function() {
8
+ "use strict";
9
+ function OkWorker() {
10
+ _classCallCheck(this, OkWorker);
11
+ }
12
+ var _proto = OkWorker.prototype;
13
+ _proto.run = function run(initState) {
14
+ this.worker = OkWorker.createWorker();
15
+ this.postMessage({
16
+ action: "init",
17
+ payload: initState
18
+ });
19
+ };
20
+ _proto.destroy = function destroy() {
21
+ var ref;
22
+ (ref = this.worker) === null || ref === void 0 ? void 0 : ref.terminate();
23
+ };
24
+ _proto.postMessage = function postMessage(message) {
25
+ var ref;
26
+ (ref = this.worker) === null || ref === void 0 ? void 0 : ref.postMessage(message);
27
+ };
28
+ OkWorker.createWorker = function createWorker() {
29
+ var blob = new Blob([
30
+ "(".concat(OkWorker.createWorkerFunction().toString(), ")()")
31
+ ]);
32
+ var url = window.URL.createObjectURL(blob);
33
+ return new Worker(url);
34
+ };
35
+ OkWorker.createWorkerFunction = function createWorkerFunction() {
36
+ return function() {
37
+ var createHandler = function createHandler(parentKey) {
38
+ return {
39
+ get: function get(target, key, value) {
40
+ return Reflect.get(target, key, value);
41
+ },
42
+ set: function set(target, key, value) {
43
+ if (parentKey) {
44
+ _self.postMessage({
45
+ action: "update",
46
+ key: "".concat(parentKey, ".").concat(key)
47
+ });
48
+ }
49
+ return Reflect.set(target, key, value);
50
+ }
51
+ };
52
+ };
53
+ log("‍\uD83D\uDE80 worker running");
54
+ var _self = self;
55
+ // function createProxy(
56
+ // obj: Record<string, unknown> | Array<Record<string, unknown>>,
57
+ // parentKey?: string
58
+ // ) {
59
+ // for (const key in obj) {
60
+ // if (Array.isArray(obj[key])) {
61
+ //
62
+ // }
63
+ // }
64
+ // return new Proxy(obj, createHandler(parentKey))
65
+ // }
66
+ _self.addEventListener("message", function(event) {
67
+ var _data = event.data, action = _data.action, payload = _data.payload, fn = _data.fn;
68
+ log(action, payload);
69
+ // 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
70
+ // data.key1 = 1
71
+ //
72
+ // data.key2.amount = 1
73
+ //
74
+ // data.key3[0].key1 = 2
75
+ //
76
+ // const result = fn(data, schema)
77
+ _self.postMessage({
78
+ action: "delete",
79
+ payload: {
80
+ key: "key3[0].key1",
81
+ value: "index"
82
+ }
83
+ });
84
+ });
85
+ };
86
+ };
87
+ return OkWorker;
88
+ }();
89
+ export { OkWorker };
@@ -0,0 +1,10 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ var Plugin = function Plugin() {
7
+ "use strict";
8
+ _classCallCheck(this, Plugin);
9
+ };
10
+ export { Plugin };
@@ -0,0 +1,257 @@
1
+ function _assertThisInitialized(self) {
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
5
+ return self;
6
+ }
7
+ function _classCallCheck(instance, Constructor) {
8
+ if (!(instance instanceof Constructor)) {
9
+ throw new TypeError("Cannot call a class as a function");
10
+ }
11
+ }
12
+ function _defineProperties(target, props) {
13
+ for(var i = 0; i < props.length; i++){
14
+ var descriptor = props[i];
15
+ descriptor.enumerable = descriptor.enumerable || false;
16
+ descriptor.configurable = true;
17
+ if ("value" in descriptor) descriptor.writable = true;
18
+ Object.defineProperty(target, descriptor.key, descriptor);
19
+ }
20
+ }
21
+ function _createClass(Constructor, protoProps, staticProps) {
22
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
23
+ if (staticProps) _defineProperties(Constructor, staticProps);
24
+ return Constructor;
25
+ }
26
+ function _getPrototypeOf(o) {
27
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
28
+ return o.__proto__ || Object.getPrototypeOf(o);
29
+ };
30
+ return _getPrototypeOf(o);
31
+ }
32
+ function _inherits(subClass, superClass) {
33
+ if (typeof superClass !== "function" && superClass !== null) {
34
+ throw new TypeError("Super expression must either be null or a function");
35
+ }
36
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
37
+ constructor: {
38
+ value: subClass,
39
+ writable: true,
40
+ configurable: true
41
+ }
42
+ });
43
+ if (superClass) _setPrototypeOf(subClass, superClass);
44
+ }
45
+ function _instanceof(left, right) {
46
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
47
+ return !!right[Symbol.hasInstance](left);
48
+ } else {
49
+ return left instanceof right;
50
+ }
51
+ }
52
+ function _possibleConstructorReturn(self, call) {
53
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
54
+ return call;
55
+ }
56
+ return _assertThisInitialized(self);
57
+ }
58
+ function _setPrototypeOf(o, p) {
59
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
60
+ o.__proto__ = p;
61
+ return o;
62
+ };
63
+ return _setPrototypeOf(o, p);
64
+ }
65
+ var _typeof = function(obj) {
66
+ "@swc/helpers - typeof";
67
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
68
+ };
69
+ function _isNativeReflectConstruct() {
70
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
71
+ if (Reflect.construct.sham) return false;
72
+ if (typeof Proxy === "function") return true;
73
+ try {
74
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
75
+ return true;
76
+ } catch (e) {
77
+ return false;
78
+ }
79
+ }
80
+ function _createSuper(Derived) {
81
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
82
+ return function _createSuperInternal() {
83
+ var Super = _getPrototypeOf(Derived), result;
84
+ if (hasNativeReflectConstruct) {
85
+ var NewTarget = _getPrototypeOf(this).constructor;
86
+ result = Reflect.construct(Super, arguments, NewTarget);
87
+ } else {
88
+ result = Super.apply(this, arguments);
89
+ }
90
+ return _possibleConstructorReturn(this, result);
91
+ };
92
+ }
93
+ import { RuntimeFormControl, RuntimeListControl, RegisterControls } from "@byteluck-fe/model-driven-core";
94
+ import { CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
95
+ import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
96
+ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
97
+ "use strict";
98
+ _inherits(Runtime, RegisterControls);
99
+ var _super = _createSuper(Runtime);
100
+ function Runtime(props) {
101
+ _classCallCheck(this, Runtime);
102
+ var _this;
103
+ _this = _super.call(this, "Runtime");
104
+ _this._flatInstances = [];
105
+ _this._instanceMap = {};
106
+ var schema = props.schema;
107
+ _this._schema = schema;
108
+ _this._instance = _this.createControl(schema, props.beforeCreateInstance);
109
+ _this.getFlatInstances();
110
+ return _this;
111
+ }
112
+ var _proto = Runtime.prototype;
113
+ _proto.getFlatInstances = function getFlatInstances() {
114
+ var instances = [];
115
+ var instanceMap = {};
116
+ loop(this._instance, function(item) {
117
+ instances.push(item);
118
+ if (!instanceMap[item.id]) {
119
+ instanceMap[item.id] = [];
120
+ }
121
+ instanceMap[item.id].push(item);
122
+ });
123
+ this._flatInstances = instances;
124
+ this._instanceMap = instanceMap;
125
+ return this._flatInstances;
126
+ };
127
+ _createClass(Runtime, [
128
+ {
129
+ key: "schema",
130
+ get: function get() {
131
+ return this._schema;
132
+ }
133
+ },
134
+ {
135
+ key: "instance",
136
+ get: function get() {
137
+ return this._instance;
138
+ }
139
+ },
140
+ {
141
+ key: "flatInstances",
142
+ get: function get() {
143
+ return this._flatInstances;
144
+ }
145
+ },
146
+ {
147
+ key: "instanceMap",
148
+ get: function get() {
149
+ return this._instanceMap;
150
+ }
151
+ },
152
+ {
153
+ key: "rules",
154
+ get: function get() {
155
+ var ruleItems = {};
156
+ loopDataViewControl(this._instance, function(dataView) {
157
+ ruleItems[dataView.id] = dataView.rules[0];
158
+ loopFormControl(dataView.children, function(item) {
159
+ if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
160
+ buildControlRules(ruleItems[dataView.id].fields, item);
161
+ }
162
+ });
163
+ });
164
+ return ruleItems;
165
+ }
166
+ },
167
+ {
168
+ key: "antdRules",
169
+ get: function get() {
170
+ var antdRules = {};
171
+ loopDataViewControl(this._instance, function(dataView) {
172
+ antdRules[dataView.id] = dataView.rules[0];
173
+ loopFormControl(dataView.children, function(item) {
174
+ if (_instanceof(item, RuntimeFormControl) || _instanceof(item, RuntimeListControl)) {
175
+ buildControlAntdRules(antdRules[dataView.id].fields, item);
176
+ }
177
+ });
178
+ });
179
+ return antdRules;
180
+ }
181
+ }
182
+ ]);
183
+ return Runtime;
184
+ }(RegisterControls);
185
+ function loop(control, callback) {
186
+ if (Array.isArray(control)) {
187
+ control.map(function(item) {
188
+ callback(item);
189
+ if (hasChildrenControl(item)) {
190
+ // @ts-ignore
191
+ loop(item.children, callback);
192
+ }
193
+ });
194
+ } else {
195
+ callback(control);
196
+ }
197
+ }
198
+ /**
199
+ * 控件是否在视图中隐藏,遍历查找所有parent
200
+ * */ function getControlIsHide(control) {
201
+ if (control.props.isHide) {
202
+ return true;
203
+ }
204
+ if (control.parent === null) {
205
+ return false;
206
+ }
207
+ return getControlIsHide(control.parent);
208
+ }
209
+ function buildControlRules(data, // @ts-ignore
210
+ item) {
211
+ if (getControlIsHide(item)) {
212
+ return;
213
+ }
214
+ if (_instanceof(item, RuntimeFormControl)) {
215
+ data[item.id] = item.rules;
216
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
217
+ data[item.id] = item.rules;
218
+ var itemRules = {
219
+ type: "array",
220
+ fields: {}
221
+ };
222
+ item.children.forEach(function(row, index) {
223
+ loopFormSchema(row.children, function(formControl) {
224
+ if (itemRules.fields) {
225
+ if (!itemRules.fields[index]) {
226
+ itemRules.fields[index] = {
227
+ type: "object",
228
+ required: true,
229
+ fields: {}
230
+ };
231
+ }
232
+ // @ts-ignore
233
+ itemRules.fields[index].fields[formControl.id] = formControl.rules;
234
+ }
235
+ });
236
+ });
237
+ data[item.id].push(itemRules);
238
+ }
239
+ }
240
+ function buildControlAntdRules(antdRules, // @ts-ignore
241
+ item) {
242
+ if (getControlIsHide(item)) {
243
+ return;
244
+ }
245
+ if (_instanceof(item, RuntimeFormControl)) {
246
+ antdRules[item.id] = item.rules;
247
+ } else if (item.type === CONTROL_TYPE.SUBTABLE && item.children.length) {
248
+ antdRules[item.id] = [];
249
+ item.children.forEach(function(row) {
250
+ var rules = {};
251
+ loopFormSchema(row.children, function(formControl) {
252
+ rules[formControl.id] = formControl.rules;
253
+ });
254
+ antdRules[item.id].push(rules);
255
+ });
256
+ }
257
+ }
@@ -0,0 +1,331 @@
1
+ function _classCallCheck(instance, Constructor) {
2
+ if (!(instance instanceof Constructor)) {
3
+ throw new TypeError("Cannot call a class as a function");
4
+ }
5
+ }
6
+ function _defineProperty(obj, key, value) {
7
+ if (key in obj) {
8
+ Object.defineProperty(obj, key, {
9
+ value: value,
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true
13
+ });
14
+ } else {
15
+ obj[key] = value;
16
+ }
17
+ return obj;
18
+ }
19
+ function _instanceof(left, right) {
20
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
21
+ return !!right[Symbol.hasInstance](left);
22
+ } else {
23
+ return left instanceof right;
24
+ }
25
+ }
26
+ import { RuntimeFormControl, DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
27
+ import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE } from "@byteluck-fe/model-driven-shared";
28
+ import { loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
29
+ var Store = /*#__PURE__*/ function() {
30
+ "use strict";
31
+ function Store(props) {
32
+ _classCallCheck(this, Store);
33
+ var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping;
34
+ this.emptyState = emptyState;
35
+ this.state = state;
36
+ this.dataBindMapping = databindMapping;
37
+ this.controlIdMapping = controlidMapping;
38
+ }
39
+ var _proto = Store.prototype;
40
+ /**
41
+ * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
42
+ * @param controlId 组件ID
43
+ * @param value
44
+ */ _proto.setState = function setState(controlId, value, rowIndex) {
45
+ var _this = this;
46
+ var controlInfo = this.controlIdMapping[controlId];
47
+ if (controlInfo !== undefined) {
48
+ //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
49
+ this.state[controlInfo.dataView][controlId] = value;
50
+ // if (
51
+ // controlInfo.dataBind instanceof ObjectDataBind &&
52
+ // isPlainObject(value)
53
+ // ) {
54
+ // Object.assign(this.state[controlInfo.dataView][controlId], value)
55
+ // } else {
56
+ // this.state[controlInfo.dataView][controlId] = value
57
+ // }
58
+ } else {
59
+ if (rowIndex !== undefined) {
60
+ //TODO 目前只找了一层明细表,没有递归
61
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
62
+ var dataView = _this.controlIdMapping[subtableId].dataView;
63
+ var children = _this.controlIdMapping[subtableId].children;
64
+ if (children !== undefined) {
65
+ Object.keys(children).map(function(childControlId) {
66
+ if (childControlId === controlId) {
67
+ _this.state[dataView][subtableId][rowIndex][controlId] = value;
68
+ }
69
+ });
70
+ }
71
+ });
72
+ } else {
73
+ //不存在的 controlId,直接被挂载到外部key
74
+ this.state[controlId] = value;
75
+ }
76
+ }
77
+ };
78
+ _proto.getState = function getState(controlId, rowIndex) {
79
+ var _this = this;
80
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
81
+ // const controlInfo = this.controlIdMapping[controlId]
82
+ var detection = this.state[controlId];
83
+ if (detection !== undefined) {
84
+ return this.state[controlId];
85
+ } else {
86
+ var controlInfo = this.controlIdMapping[controlId];
87
+ if (controlInfo !== undefined) {
88
+ return this.state[controlInfo.dataView][controlId];
89
+ } else {
90
+ if (rowIndex !== undefined) {
91
+ var state;
92
+ //TODO 目前只找了一层明细表,没有递归
93
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
94
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
95
+ var children = _this.controlIdMapping[subtableId].children;
96
+ if (children !== undefined) {
97
+ Object.keys(children).map(function(childControlId) {
98
+ if (childControlId === controlId) {
99
+ var ref;
100
+ state = (ref = _this.state[dataViewId][subtableId][rowIndex]) === null || ref === void 0 ? void 0 : ref[controlId];
101
+ }
102
+ });
103
+ }
104
+ });
105
+ return state;
106
+ } else {
107
+ var states = [];
108
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
109
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
110
+ var children = _this.controlIdMapping[subtableId].children;
111
+ if (children !== undefined) {
112
+ Object.keys(children).map(function(childControlId) {
113
+ if (childControlId === controlId) {
114
+ _this.state[dataViewId][subtableId].map(function(item) {
115
+ states.push(item[controlId]);
116
+ });
117
+ }
118
+ });
119
+ }
120
+ });
121
+ return states;
122
+ }
123
+ }
124
+ }
125
+ };
126
+ _proto.getEmptyState = function getEmptyState(controlId) {
127
+ var _this = this;
128
+ var detection = this.emptyState[controlId];
129
+ if (detection !== undefined) {
130
+ return this.emptyState[controlId];
131
+ } else {
132
+ var controlInfo = this.controlIdMapping[controlId];
133
+ if (controlInfo !== undefined) {
134
+ return this.emptyState[controlInfo.dataView][controlId];
135
+ } else {
136
+ var state;
137
+ //TODO 目前只找了一层明细表,没有递归
138
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
139
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
140
+ var children = _this.controlIdMapping[subtableId].children;
141
+ if (children !== undefined) {
142
+ Object.keys(children).map(function(childControlId) {
143
+ if (childControlId === controlId) {
144
+ state = _this.emptyState[dataViewId][subtableId][controlId];
145
+ }
146
+ });
147
+ }
148
+ });
149
+ return state;
150
+ }
151
+ }
152
+ };
153
+ _proto.getDataBind = function getDataBind(controlId) {
154
+ var result = this.controlIdMapping[controlId];
155
+ if (result) {
156
+ return result.dataBind;
157
+ }
158
+ wrapperFor: for(var id in this.controlIdMapping){
159
+ var dataBindMapping = this.controlIdMapping[id];
160
+ if (dataBindMapping.children) {
161
+ for(var subId in dataBindMapping.children){
162
+ if (subId === controlId) {
163
+ result = dataBindMapping.children[subId];
164
+ break wrapperFor;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ return result === null || result === void 0 ? void 0 : result.dataBind;
170
+ };
171
+ return Store;
172
+ }();
173
+ function init(instance) {
174
+ var state = {};
175
+ var emptyState = {};
176
+ var databindMapping = {};
177
+ var controlidMapping = {};
178
+ // loopFormControl(instance, (item, children) => {
179
+ // })
180
+ // @ts-ignore
181
+ loopDataViewControl(instance, function(dataView) {
182
+ var dvId = dataView.id;
183
+ var dataViewState = {};
184
+ var emptyDataViewState = {};
185
+ // @ts-ignore
186
+ loopFormControl([
187
+ dataView
188
+ ], function(item, children) {
189
+ buildState(dataViewState, emptyDataViewState, item);
190
+ buildDataBindMapping(databindMapping, dvId, item);
191
+ buildControlIdMapping(controlidMapping, dvId, item);
192
+ });
193
+ state[dvId] = dataViewState;
194
+ emptyState[dvId] = emptyDataViewState;
195
+ });
196
+ return {
197
+ state: state,
198
+ emptyState: emptyState,
199
+ databindMapping: databindMapping,
200
+ controlidMapping: controlidMapping
201
+ };
202
+ }
203
+ function buildState(dataViewState, emptyDataViewState, // @ts-ignore
204
+ item) {
205
+ if (_instanceof(item, RuntimeFormControl)) {
206
+ dataViewState[item.id] = JSONCopy(item.props.defaultValue);
207
+ emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
208
+ } else {
209
+ var emptyTemplate = {};
210
+ loopFormSchema(item.props.headers, function(headerItem) {
211
+ emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
212
+ });
213
+ var _defaultRows;
214
+ dataViewState[item.id] = new Array((_defaultRows = item.props.defaultRows) !== null && _defaultRows !== void 0 ? _defaultRows : 1).fill(0).map(function() {
215
+ return JSONCopy(emptyTemplate);
216
+ });
217
+ emptyDataViewState[item.id] = emptyTemplate;
218
+ }
219
+ }
220
+ function buildDataBindMapping(data, dataViewId, // @ts-ignore
221
+ item) {
222
+ if (_instanceof(item, RuntimeFormControl)) {
223
+ if (_instanceof(item.props.dataBind, ObjectDataBind)) {
224
+ // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
225
+ Object.keys(item.props.dataBind).map(function(key) {
226
+ var dataBind = item.props.dataBind;
227
+ var dataCode = dataBind[key].dataCode;
228
+ if (dataCode !== undefined) {
229
+ if (data[dataCode] === undefined) {
230
+ data[dataCode] = {
231
+ controlId: item.id,
232
+ fields: [],
233
+ dataViewId: dataViewId
234
+ };
235
+ }
236
+ data[dataCode].fields.push({
237
+ fieldCode: dataBind[key].fieldCode,
238
+ controlId: item.id,
239
+ dataBind: dataBind,
240
+ dataViewId: [
241
+ dataViewId
242
+ ]
243
+ });
244
+ }
245
+ });
246
+ } else {
247
+ if (data[item.props.dataBind.dataCode] === undefined) {
248
+ data[item.props.dataBind.dataCode] = {
249
+ controlId: dataViewId,
250
+ fields: [],
251
+ dataViewId: dataViewId
252
+ };
253
+ }
254
+ data[item.props.dataBind.dataCode].fields.push({
255
+ fieldCode: item.props.dataBind.fieldCode,
256
+ controlId: item.id,
257
+ dataBind: item.props.dataBind,
258
+ dataViewId: [
259
+ dataViewId
260
+ ]
261
+ });
262
+ }
263
+ } else {
264
+ if (item.props.datasourceBind.dataCode === "") {
265
+ //敏捷依赖后端生成dataCode,预览的时候没有
266
+ warn("datasourceBind.dataCode is empty! maybe in preview mode, control:".concat(item.id, " type:").concat(item.type));
267
+ return;
268
+ }
269
+ data[item.props.datasourceBind.dataCode] = {
270
+ controlId: item.id,
271
+ fields: [],
272
+ dataViewId: dataViewId
273
+ };
274
+ var subtableId = item.id;
275
+ loopFormSchema(item.props.headers, function(item) {
276
+ if (_instanceof(item.props.dataBind, ObjectDataBind)) {
277
+ Object.keys(item.props.dataBind).map(function(key) {
278
+ var dataBind = item.props.dataBind;
279
+ var dataCode = dataBind[key].dataCode;
280
+ data[dataCode].fields.push({
281
+ fieldCode: dataBind[key].fieldCode,
282
+ controlId: item.id,
283
+ dataBind: dataBind,
284
+ dataViewId: [
285
+ dataViewId,
286
+ subtableId
287
+ ]
288
+ });
289
+ });
290
+ } else {
291
+ data[item.props.dataBind.dataCode].fields.push({
292
+ fieldCode: item.props.dataBind.fieldCode,
293
+ controlId: item.id,
294
+ dataBind: item.props.dataBind,
295
+ dataViewId: [
296
+ dataViewId,
297
+ subtableId
298
+ ]
299
+ });
300
+ }
301
+ });
302
+ }
303
+ }
304
+ function buildControlIdMapping(data, dataViewId, // @ts-ignore
305
+ item) {
306
+ if (_instanceof(item, RuntimeFormControl)) {
307
+ data[item.id] = {
308
+ dataBind: item.props.dataBind,
309
+ options: [],
310
+ dataView: dataViewId
311
+ };
312
+ } else if (item.type === CONTROL_TYPE.SUBTABLE) {
313
+ data[item.id] = {
314
+ dataBind: new DataBind({
315
+ dataCode: item.props.datasourceBind.dataCode,
316
+ fieldCode: ""
317
+ }),
318
+ dataView: dataViewId,
319
+ children: {},
320
+ options: []
321
+ };
322
+ loopFormSchema(item.props.headers, function(formControl) {
323
+ var ref;
324
+ var ref1;
325
+ Object.assign((ref1 = (ref = data[item.id]) === null || ref === void 0 ? void 0 : ref.children) !== null && ref1 !== void 0 ? ref1 : {}, _defineProperty({}, formControl.id, {
326
+ dataBind: formControl.props.dataBind
327
+ }));
328
+ });
329
+ }
330
+ }
331
+ export { Store };