@byteluck-fe/model-driven-engine 2.5.0-alpha.9 → 2.5.0-beta.4

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.
@@ -17,25 +17,11 @@ function _createClass(Constructor, protoProps, staticProps) {
17
17
  if (staticProps) _defineProperties(Constructor, staticProps);
18
18
  return Constructor;
19
19
  }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- import { log } from "@byteluck-fe/model-driven-shared";
20
+ import { log } from '@byteluck-fe/model-driven-shared';
34
21
  var OkWorker = /*#__PURE__*/ function() {
35
22
  "use strict";
36
23
  function OkWorker() {
37
24
  _classCallCheck(this, OkWorker);
38
- _defineProperty(this, "worker", void 0);
39
25
  }
40
26
  _createClass(OkWorker, [
41
27
  {
@@ -43,7 +29,7 @@ var OkWorker = /*#__PURE__*/ function() {
43
29
  value: function run(initState) {
44
30
  this.worker = OkWorker.createWorker();
45
31
  this.postMessage({
46
- action: "init",
32
+ action: 'init',
47
33
  payload: initState
48
34
  });
49
35
  }
@@ -51,15 +37,15 @@ var OkWorker = /*#__PURE__*/ function() {
51
37
  {
52
38
  key: "destroy",
53
39
  value: function destroy() {
54
- var _this_worker;
55
- (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
40
+ var ref;
41
+ (ref = this.worker) === null || ref === void 0 ? void 0 : ref.terminate();
56
42
  }
57
43
  },
58
44
  {
59
45
  key: "postMessage",
60
46
  value: function postMessage(message) {
61
- var _this_worker;
62
- (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
47
+ var ref;
48
+ (ref = this.worker) === null || ref === void 0 ? void 0 : ref.postMessage(message);
63
49
  }
64
50
  }
65
51
  ], [
@@ -85,7 +71,7 @@ var OkWorker = /*#__PURE__*/ function() {
85
71
  set: function set(target, key, value) {
86
72
  if (parentKey) {
87
73
  _self.postMessage({
88
- action: "update",
74
+ action: 'update',
89
75
  key: "".concat(parentKey, ".").concat(key)
90
76
  });
91
77
  }
@@ -93,7 +79,7 @@ var OkWorker = /*#__PURE__*/ function() {
93
79
  }
94
80
  };
95
81
  };
96
- log("‍\uD83D\uDE80 worker running");
82
+ log('‍🚀 worker running');
97
83
  var _self = self;
98
84
  // function createProxy(
99
85
  // obj: Record<string, unknown> | Array<Record<string, unknown>>,
@@ -106,8 +92,8 @@ var OkWorker = /*#__PURE__*/ function() {
106
92
  // }
107
93
  // return new Proxy(obj, createHandler(parentKey))
108
94
  // }
109
- _self.addEventListener("message", function(event) {
110
- var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
95
+ _self.addEventListener('message', function(event) {
96
+ var _data = event.data, action = _data.action, payload = _data.payload, fn = _data.fn;
111
97
  log(action, payload);
112
98
  // 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
113
99
  // data.key1 = 1
@@ -118,10 +104,10 @@ var OkWorker = /*#__PURE__*/ function() {
118
104
  //
119
105
  // const result = fn(data, schema)
120
106
  _self.postMessage({
121
- action: "delete",
107
+ action: 'delete',
122
108
  payload: {
123
- key: "key3[0].key1",
124
- value: "index"
109
+ key: 'key3[0].key1',
110
+ value: 'index'
125
111
  }
126
112
  });
127
113
  });
@@ -23,19 +23,6 @@ function _createClass(Constructor, protoProps, staticProps) {
23
23
  if (staticProps) _defineProperties(Constructor, staticProps);
24
24
  return Constructor;
25
25
  }
26
- function _defineProperty(obj, key, value) {
27
- if (key in obj) {
28
- Object.defineProperty(obj, key, {
29
- value: value,
30
- enumerable: true,
31
- configurable: true,
32
- writable: true
33
- });
34
- } else {
35
- obj[key] = value;
36
- }
37
- return obj;
38
- }
39
26
  function _getPrototypeOf(o) {
40
27
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
41
28
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -96,21 +83,19 @@ function _createSuper(Derived) {
96
83
  return _possibleConstructorReturn(this, result);
97
84
  };
98
85
  }
99
- import { RegisterControls } from "@byteluck-fe/model-driven-core";
100
- import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from "@byteluck-fe/model-driven-shared";
101
- import { hasChildrenControl, loopDataViewControl, loopFormControl } from "../utils/runtimeUtils";
102
- export var Runtime = /*#__PURE__*/ function(RegisterControls) {
86
+ import { RegisterControls } from '@byteluck-fe/model-driven-core';
87
+ import { CONTROL_BASE_TYPE, CONTROL_TYPE, loopFormSchema } from '@byteluck-fe/model-driven-shared';
88
+ import { hasChildrenControl, loopDataViewControl, loopFormControl } from '../utils/runtimeUtils';
89
+ export var Runtime = /*#__PURE__*/ function(RegisterControls1) {
103
90
  "use strict";
104
- _inherits(Runtime, RegisterControls);
91
+ _inherits(Runtime, RegisterControls1);
105
92
  var _super = _createSuper(Runtime);
106
93
  function Runtime(props) {
107
94
  _classCallCheck(this, Runtime);
108
95
  var _this;
109
- _this = _super.call(this, "Runtime");
110
- _defineProperty(_assertThisInitialized(_this), "_schema", void 0);
111
- _defineProperty(_assertThisInitialized(_this), "_instance", void 0);
112
- _defineProperty(_assertThisInitialized(_this), "_flatInstances", []);
113
- _defineProperty(_assertThisInitialized(_this), "_instanceMap", {});
96
+ _this = _super.call(this, 'Runtime');
97
+ _this._flatInstances = [];
98
+ _this._instanceMap = {};
114
99
  var schema = props.schema;
115
100
  _this._schema = schema;
116
101
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
@@ -125,7 +110,7 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
125
110
  var instanceMap = {};
126
111
  loop(this._instance, function(item) {
127
112
  // 3.4.1 避免将subtable-row 放到 _flatInstances 中
128
- if (item.type === "subtable-row" || item.type === "subtable-column") {
113
+ if (item.type === 'subtable-row' || item.type === 'subtable-column') {
129
114
  return;
130
115
  }
131
116
  instances.push(item);
@@ -264,7 +249,7 @@ item) {
264
249
  } else if (item.type === CONTROL_TYPE.SUBTABLE) {
265
250
  data[item.id] = item.rules;
266
251
  var itemRules = {
267
- type: "array",
252
+ type: 'array',
268
253
  fields: {}
269
254
  };
270
255
  item.children.forEach(function(row, index) {
@@ -272,7 +257,7 @@ item) {
272
257
  if (itemRules.fields) {
273
258
  if (!itemRules.fields[index]) {
274
259
  itemRules.fields[index] = {
275
- type: "object",
260
+ type: 'object',
276
261
  required: true,
277
262
  fields: {}
278
263
  };
@@ -32,28 +32,39 @@ function _defineProperty(obj, key, value) {
32
32
  }
33
33
  function _instanceof(left, right) {
34
34
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
35
- return !!right[Symbol.hasInstance](left);
35
+ return right[Symbol.hasInstance](left);
36
36
  } else {
37
37
  return left instanceof right;
38
38
  }
39
39
  }
40
- import { DataBind, ObjectDataBind } from "@byteluck-fe/model-driven-core";
41
- import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from "@byteluck-fe/model-driven-shared";
42
- import { loopDataViewControl, loopFormControl, buildUUID } from "../utils/runtimeUtils";
40
+ function _objectSpread(target) {
41
+ for(var i = 1; i < arguments.length; i++){
42
+ var source = arguments[i] != null ? arguments[i] : {};
43
+ var ownKeys = Object.keys(source);
44
+ if (typeof Object.getOwnPropertySymbols === "function") {
45
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
46
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
47
+ }));
48
+ }
49
+ ownKeys.forEach(function(key) {
50
+ _defineProperty(target, key, source[key]);
51
+ });
52
+ }
53
+ return target;
54
+ }
55
+ import { DataBind, ObjectDataBind } from '@byteluck-fe/model-driven-core';
56
+ import { loopFormSchema, JSONCopy, warn, CONTROL_TYPE, CONTROL_BASE_TYPE } from '@byteluck-fe/model-driven-shared';
57
+ import { loopDataViewControl, loopFormControl, buildUUID } from '../utils/runtimeUtils';
43
58
  var Store = /*#__PURE__*/ function() {
44
59
  "use strict";
45
60
  function Store(props) {
46
61
  _classCallCheck(this, Store);
47
- _defineProperty(this, "emptyState", void 0);
48
- _defineProperty(this, "state", void 0);
49
- _defineProperty(this, "dataBindMapping", void 0 // 主要提供给二开使用
50
- );
51
- _defineProperty(this, "controlIdMapping", void 0);
52
- var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping;
62
+ var ref = init(props.instance), state = ref.state, emptyState = ref.emptyState, databindMapping = ref.databindMapping, controlidMapping = ref.controlidMapping, defaultState = ref.defaultState;
53
63
  this.emptyState = emptyState;
54
64
  this.state = state;
55
65
  this.dataBindMapping = databindMapping;
56
66
  this.controlIdMapping = controlidMapping;
67
+ this.defaultState = defaultState;
57
68
  }
58
69
  _createClass(Store, [
59
70
  {
@@ -63,7 +74,6 @@ var Store = /*#__PURE__*/ function() {
63
74
  * @param value
64
75
  */ key: "setState",
65
76
  value: function setState(controlId, value, rowIndex) {
66
- var _this = this;
67
77
  var controlInfo = this.controlIdMapping[controlId];
68
78
  if (controlInfo !== undefined) {
69
79
  //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
@@ -78,14 +88,16 @@ var Store = /*#__PURE__*/ function() {
78
88
  // }
79
89
  } else {
80
90
  if (rowIndex !== undefined) {
91
+ var _this = this;
81
92
  //TODO 目前只找了一层明细表,没有递归 如果是添加uid
82
93
  Object.keys(this.controlIdMapping).map(function(subtableId) {
83
94
  var dataView = _this.controlIdMapping[subtableId].dataView;
84
95
  var children = _this.controlIdMapping[subtableId].children;
85
96
  if (children !== undefined) {
97
+ var _this1 = _this;
86
98
  Object.keys(children).map(function(childControlId) {
87
99
  if (childControlId === controlId) {
88
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
100
+ _this1.state[dataView][subtableId][rowIndex][controlId] = value;
89
101
  }
90
102
  });
91
103
  }
@@ -100,7 +112,6 @@ var Store = /*#__PURE__*/ function() {
100
112
  {
101
113
  key: "getState",
102
114
  value: function getState(controlId, rowIndex) {
103
- var _this = this;
104
115
  //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
105
116
  // const controlInfo = this.controlIdMapping[controlId]
106
117
  var detection = this.state[controlId];
@@ -112,27 +123,31 @@ var Store = /*#__PURE__*/ function() {
112
123
  return this.state[controlInfo.dataView][controlId];
113
124
  } else {
114
125
  if (rowIndex !== undefined) {
126
+ var _this = this;
115
127
  var state;
116
128
  //TODO 目前只找了一层明细表,没有递归
117
129
  Object.keys(this.controlIdMapping).map(function(subtableId) {
118
130
  var dataViewId = _this.controlIdMapping[subtableId].dataView;
119
131
  var children = _this.controlIdMapping[subtableId].children;
120
132
  if (children !== undefined) {
133
+ var _this3 = _this;
121
134
  Object.keys(children).map(function(childControlId) {
122
135
  if (childControlId === controlId) {
123
- var _this_state_dataViewId_subtableId_rowIndex;
124
- state = (_this_state_dataViewId_subtableId_rowIndex = _this.state[dataViewId][subtableId][rowIndex]) === null || _this_state_dataViewId_subtableId_rowIndex === void 0 ? void 0 : _this_state_dataViewId_subtableId_rowIndex[controlId];
136
+ var ref;
137
+ state = (ref = _this3.state[dataViewId][subtableId][rowIndex]) === null || ref === void 0 ? void 0 : ref[controlId];
125
138
  }
126
139
  });
127
140
  }
128
141
  });
129
142
  return state;
130
143
  } else {
144
+ var _this2 = this;
131
145
  var states = [];
132
146
  Object.keys(this.controlIdMapping).map(function(subtableId) {
133
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
134
- var children = _this.controlIdMapping[subtableId].children;
147
+ var dataViewId = _this2.controlIdMapping[subtableId].dataView;
148
+ var children = _this2.controlIdMapping[subtableId].children;
135
149
  if (children !== undefined) {
150
+ var _this = _this2;
136
151
  Object.keys(children).map(function(childControlId) {
137
152
  if (childControlId === controlId) {
138
153
  _this.state[dataViewId][subtableId].map(function(item) {
@@ -151,7 +166,6 @@ var Store = /*#__PURE__*/ function() {
151
166
  {
152
167
  key: "getEmptyState",
153
168
  value: function getEmptyState(controlId) {
154
- var _this = this;
155
169
  var detection = this.emptyState[controlId];
156
170
  if (detection !== undefined) {
157
171
  return this.emptyState[controlId];
@@ -160,22 +174,24 @@ var Store = /*#__PURE__*/ function() {
160
174
  if (controlInfo !== undefined) {
161
175
  var state = this.emptyState[controlInfo.dataView][controlId];
162
176
  //判断找到的是否是明细表的控件
163
- if ("children" in controlInfo) {
177
+ if ('children' in controlInfo) {
164
178
  Object.assign(state, {
165
- uid: "new:" + buildUUID("uid")
179
+ uid: 'new:' + buildUUID('uid')
166
180
  });
167
181
  }
168
182
  return state;
169
183
  } else {
184
+ var _this = this;
170
185
  var state1;
171
186
  //TODO 目前只找了一层明细表,没有递归
172
187
  Object.keys(this.controlIdMapping).map(function(subtableId) {
173
188
  var dataViewId = _this.controlIdMapping[subtableId].dataView;
174
189
  var children = _this.controlIdMapping[subtableId].children;
175
190
  if (children !== undefined) {
191
+ var _this4 = _this;
176
192
  Object.keys(children).map(function(childControlId) {
177
193
  if (childControlId === controlId) {
178
- state1 = _this.emptyState[dataViewId][subtableId][controlId];
194
+ state1 = _this4.emptyState[dataViewId][subtableId][controlId];
179
195
  }
180
196
  });
181
197
  }
@@ -214,6 +230,7 @@ function init(instance) {
214
230
  var emptyState = {};
215
231
  var databindMapping = {};
216
232
  var controlidMapping = {};
233
+ var defaultState = {};
217
234
  // loopFormControl(instance, (item, children) => {
218
235
  // })
219
236
  // @ts-ignore
@@ -229,11 +246,13 @@ function init(instance) {
229
246
  buildDataBindMapping(databindMapping, dvId, item);
230
247
  buildControlIdMapping(controlidMapping, dvId, item);
231
248
  });
232
- state[dvId] = dataViewState;
249
+ state[dvId] = {};
250
+ defaultState[dvId] = dataViewState;
233
251
  emptyState[dvId] = emptyDataViewState;
234
252
  });
235
253
  return {
236
254
  state: state,
255
+ defaultState: defaultState,
237
256
  emptyState: emptyState,
238
257
  databindMapping: databindMapping,
239
258
  controlidMapping: controlidMapping
@@ -244,41 +263,43 @@ item) {
244
263
  //if (item instanceof RuntimeFormControl) {
245
264
  if (item.controlType === CONTROL_BASE_TYPE.FORM) {
246
265
  // 2023-4-2 jiaqi 首次进入页面去除填充默认值
247
- // dataViewState[item.id] = JSONCopy(item.props.defaultValue)
266
+ dataViewState[item.id] = JSONCopy(item.props.defaultValue);
248
267
  emptyDataViewState[item.id] = JSONCopy(item.props.defaultValue);
249
268
  } else {
250
269
  var emptyTemplate = {};
251
270
  loopFormSchema(item.props.headers, function(headerItem) {
252
271
  emptyTemplate[headerItem.id] = JSONCopy(headerItem.props.defaultValue);
253
272
  });
254
- var _item_props_defaultRows;
255
- dataViewState[item.id] = new Array((_item_props_defaultRows = item.props.defaultRows) !== null && _item_props_defaultRows !== void 0 ? _item_props_defaultRows : 1).fill(0).map(function() {
256
- return JSONCopy(emptyTemplate);
273
+ var _defaultRows;
274
+ dataViewState[item.id] = new Array((_defaultRows = item.props.defaultRows) !== null && _defaultRows !== void 0 ? _defaultRows : 1).fill(0).map(function() {
275
+ return _objectSpread({
276
+ uid: 'new:' + buildUUID('uid')
277
+ }, JSONCopy(emptyTemplate));
257
278
  });
258
279
  emptyDataViewState[item.id] = emptyTemplate;
259
280
  }
260
281
  }
261
282
  function buildDataBindMapping(data, dataViewId, // @ts-ignore
262
- item) {
283
+ item1) {
263
284
  // if (item instanceof RuntimeFormControl) {
264
- if (item.controlType === CONTROL_BASE_TYPE.FORM) {
265
- var _item_props, _item_props_dataBind;
266
- if (_instanceof(item.props.dataBind, ObjectDataBind)) {
285
+ if (item1.controlType === CONTROL_BASE_TYPE.FORM) {
286
+ var ref, ref1;
287
+ if (_instanceof(item1.props.dataBind, ObjectDataBind)) {
267
288
  // 特殊的dataBind,比如:金额是currency+amount两个key组成的,日期区间,继承自ObjectDataBind的需要通过Object.keys拿到多个databind
268
- Object.keys(item.props.dataBind).map(function(key) {
269
- var dataBind = item.props.dataBind;
289
+ Object.keys(item1.props.dataBind).map(function(key) {
290
+ var dataBind = item1.props.dataBind;
270
291
  var dataCode = dataBind[key].dataCode;
271
292
  if (dataCode !== undefined) {
272
293
  if (data[dataCode] === undefined) {
273
294
  data[dataCode] = {
274
- controlId: item.id,
295
+ controlId: item1.id,
275
296
  fields: [],
276
297
  dataViewId: dataViewId
277
298
  };
278
299
  }
279
300
  data[dataCode].fields.push({
280
301
  fieldCode: dataBind[key].fieldCode,
281
- controlId: item.id,
302
+ controlId: item1.id,
282
303
  dataBind: dataBind,
283
304
  dataViewId: [
284
305
  dataViewId
@@ -286,38 +307,38 @@ item) {
286
307
  });
287
308
  }
288
309
  });
289
- } else if (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : (_item_props_dataBind = _item_props.dataBind) === null || _item_props_dataBind === void 0 ? void 0 : _item_props_dataBind.dataCode) === undefined) {
310
+ } else if (((ref = item1.props) === null || ref === void 0 ? void 0 : (ref1 = ref.dataBind) === null || ref1 === void 0 ? void 0 : ref1.dataCode) === undefined) {
290
311
  //qiyu 2023-2-27 为空跳过。form自定义组件加载失败时,hack的组件props为空。
291
312
  } else {
292
- if (data[item.props.dataBind.dataCode] === undefined) {
293
- data[item.props.dataBind.dataCode] = {
313
+ if (data[item1.props.dataBind.dataCode] === undefined) {
314
+ data[item1.props.dataBind.dataCode] = {
294
315
  controlId: dataViewId,
295
316
  fields: [],
296
317
  dataViewId: dataViewId
297
318
  };
298
319
  }
299
- data[item.props.dataBind.dataCode].fields.push({
300
- fieldCode: item.props.dataBind.fieldCode,
301
- controlId: item.id,
302
- dataBind: item.props.dataBind,
320
+ data[item1.props.dataBind.dataCode].fields.push({
321
+ fieldCode: item1.props.dataBind.fieldCode,
322
+ controlId: item1.id,
323
+ dataBind: item1.props.dataBind,
303
324
  dataViewId: [
304
325
  dataViewId
305
326
  ]
306
327
  });
307
328
  }
308
329
  } else {
309
- if (item.props.datasourceBind.dataCode === "") {
330
+ if (item1.props.datasourceBind.dataCode === '') {
310
331
  //敏捷依赖后端生成dataCode,预览的时候没有
311
- warn("datasourceBind.dataCode is empty! maybe in preview mode, control:".concat(item.id, " type:").concat(item.type));
332
+ warn("datasourceBind.dataCode is empty! maybe in preview mode, control:".concat(item1.id, " type:").concat(item1.type));
312
333
  return;
313
334
  }
314
- data[item.props.datasourceBind.dataCode] = {
315
- controlId: item.id,
335
+ data[item1.props.datasourceBind.dataCode] = {
336
+ controlId: item1.id,
316
337
  fields: [],
317
338
  dataViewId: dataViewId
318
339
  };
319
- var subtableId = item.id;
320
- loopFormSchema(item.props.headers, function(item) {
340
+ var subtableId = item1.id;
341
+ loopFormSchema(item1.props.headers, function(item) {
321
342
  if (_instanceof(item.props.dataBind, ObjectDataBind)) {
322
343
  Object.keys(item.props.dataBind).map(function(key) {
323
344
  var dataBind = item.props.dataBind;
@@ -359,16 +380,16 @@ item) {
359
380
  data[item.id] = {
360
381
  dataBind: new DataBind({
361
382
  dataCode: item.props.datasourceBind.dataCode,
362
- fieldCode: ""
383
+ fieldCode: ''
363
384
  }),
364
385
  dataView: dataViewId,
365
386
  children: {},
366
387
  options: []
367
388
  };
368
389
  loopFormSchema(item.props.headers, function(formControl) {
369
- var _data_item_id;
370
- var _data_item_id_children;
371
- Object.assign((_data_item_id_children = (_data_item_id = data[item.id]) === null || _data_item_id === void 0 ? void 0 : _data_item_id.children) !== null && _data_item_id_children !== void 0 ? _data_item_id_children : {}, _defineProperty({}, formControl.id, {
390
+ var ref;
391
+ var ref2;
392
+ Object.assign((ref2 = (ref = data[item.id]) === null || ref === void 0 ? void 0 : ref.children) !== null && ref2 !== void 0 ? ref2 : {}, _defineProperty({}, formControl.id, {
372
393
  dataBind: formControl.props.dataBind
373
394
  }));
374
395
  });