@byteluck-fe/model-driven-engine 2.7.0-alpha.2 → 2.7.0-alpha.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.
@@ -3,87 +3,132 @@ function _classCallCheck(instance, Constructor) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
5
5
  }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _createClass(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
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
+ }
6
33
  import { log } from "@byteluck-fe/model-driven-shared";
7
34
  var OkWorker = /*#__PURE__*/ function() {
8
35
  "use strict";
9
36
  function OkWorker() {
10
37
  _classCallCheck(this, OkWorker);
38
+ _defineProperty(this, "worker", void 0);
11
39
  }
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 _this_worker;
22
- (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
23
- };
24
- _proto.postMessage = function postMessage(message) {
25
- var _this_worker;
26
- (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.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 _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_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
- }
40
+ _createClass(OkWorker, [
41
+ {
42
+ key: "run",
43
+ value: function run(initState) {
44
+ this.worker = OkWorker.createWorker();
45
+ this.postMessage({
46
+ action: "init",
47
+ payload: initState
83
48
  });
84
- });
85
- };
86
- };
49
+ }
50
+ },
51
+ {
52
+ key: "destroy",
53
+ value: function destroy() {
54
+ var _this_worker;
55
+ (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.terminate();
56
+ }
57
+ },
58
+ {
59
+ key: "postMessage",
60
+ value: function postMessage(message) {
61
+ var _this_worker;
62
+ (_this_worker = this.worker) === null || _this_worker === void 0 ? void 0 : _this_worker.postMessage(message);
63
+ }
64
+ }
65
+ ], [
66
+ {
67
+ key: "createWorker",
68
+ value: function createWorker() {
69
+ var blob = new Blob([
70
+ "(".concat(OkWorker.createWorkerFunction().toString(), ")()")
71
+ ]);
72
+ var url = window.URL.createObjectURL(blob);
73
+ return new Worker(url);
74
+ }
75
+ },
76
+ {
77
+ key: "createWorkerFunction",
78
+ value: function createWorkerFunction() {
79
+ return function() {
80
+ var createHandler = function createHandler(parentKey) {
81
+ return {
82
+ get: function get(target, key, value) {
83
+ return Reflect.get(target, key, value);
84
+ },
85
+ set: function set(target, key, value) {
86
+ if (parentKey) {
87
+ _self.postMessage({
88
+ action: "update",
89
+ key: "".concat(parentKey, ".").concat(key)
90
+ });
91
+ }
92
+ return Reflect.set(target, key, value);
93
+ }
94
+ };
95
+ };
96
+ log("‍\uD83D\uDE80 worker running");
97
+ var _self = self;
98
+ // function createProxy(
99
+ // obj: Record<string, unknown> | Array<Record<string, unknown>>,
100
+ // parentKey?: string
101
+ // ) {
102
+ // for (const key in obj) {
103
+ // if (Array.isArray(obj[key])) {
104
+ //
105
+ // }
106
+ // }
107
+ // return new Proxy(obj, createHandler(parentKey))
108
+ // }
109
+ _self.addEventListener("message", function(event) {
110
+ var _event_data = event.data, action = _event_data.action, payload = _event_data.payload, fn = _event_data.fn;
111
+ log(action, payload);
112
+ // 通过proxy进行代理,每次修改的时候,自动向外抛出postMessage
113
+ // data.key1 = 1
114
+ //
115
+ // data.key2.amount = 1
116
+ //
117
+ // data.key3[0].key1 = 2
118
+ //
119
+ // const result = fn(data, schema)
120
+ _self.postMessage({
121
+ action: "delete",
122
+ payload: {
123
+ key: "key3[0].key1",
124
+ value: "index"
125
+ }
126
+ });
127
+ });
128
+ };
129
+ }
130
+ }
131
+ ]);
87
132
  return OkWorker;
88
133
  }();
89
134
  export { OkWorker };
@@ -23,6 +23,19 @@ 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
+ }
26
39
  function _getPrototypeOf(o) {
27
40
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
28
41
  return o.__proto__ || Object.getPrototypeOf(o);
@@ -94,34 +107,38 @@ export var Runtime = /*#__PURE__*/ function(RegisterControls) {
94
107
  _classCallCheck(this, Runtime);
95
108
  var _this;
96
109
  _this = _super.call(this, "Runtime");
97
- _this._flatInstances = [];
98
- _this._instanceMap = {};
110
+ _defineProperty(_assertThisInitialized(_this), "_schema", void 0);
111
+ _defineProperty(_assertThisInitialized(_this), "_instance", void 0);
112
+ _defineProperty(_assertThisInitialized(_this), "_flatInstances", []);
113
+ _defineProperty(_assertThisInitialized(_this), "_instanceMap", {});
99
114
  var schema = props.schema;
100
115
  _this._schema = schema;
101
116
  _this._instance = _this.createControl(schema, props.beforeCreateInstance);
102
117
  _this.getFlatInstances();
103
118
  return _this;
104
119
  }
105
- var _proto = Runtime.prototype;
106
- _proto.getFlatInstances = function getFlatInstances() {
107
- var instances = [];
108
- var instanceMap = {};
109
- loop(this._instance, function(item) {
110
- // 3.4.1 避免将subtable-row 放到 _flatInstances 中
111
- if (item.type === "subtable-row" || item.type === "subtable-column") {
112
- return;
113
- }
114
- instances.push(item);
115
- if (!instanceMap[item.id]) {
116
- instanceMap[item.id] = [];
117
- }
118
- instanceMap[item.id].push(item);
119
- });
120
- this._flatInstances = instances;
121
- this._instanceMap = instanceMap;
122
- return this._flatInstances;
123
- };
124
120
  _createClass(Runtime, [
121
+ {
122
+ key: "getFlatInstances",
123
+ value: function getFlatInstances() {
124
+ var instances = [];
125
+ var instanceMap = {};
126
+ loop(this._instance, function(item) {
127
+ // 3.4.1 避免将subtable-row 放到 _flatInstances 中
128
+ if (item.type === "subtable-row" || item.type === "subtable-column") {
129
+ return;
130
+ }
131
+ instances.push(item);
132
+ if (!instanceMap[item.id]) {
133
+ instanceMap[item.id] = [];
134
+ }
135
+ instanceMap[item.id].push(item);
136
+ });
137
+ this._flatInstances = instances;
138
+ this._instanceMap = instanceMap;
139
+ return this._flatInstances;
140
+ }
141
+ },
125
142
  {
126
143
  key: "schema",
127
144
  get: function get() {
@@ -3,6 +3,20 @@ function _classCallCheck(instance, Constructor) {
3
3
  throw new TypeError("Cannot call a class as a function");
4
4
  }
5
5
  }
6
+ function _defineProperties(target, props) {
7
+ for(var i = 0; i < props.length; i++){
8
+ var descriptor = props[i];
9
+ descriptor.enumerable = descriptor.enumerable || false;
10
+ descriptor.configurable = true;
11
+ if ("value" in descriptor) descriptor.writable = true;
12
+ Object.defineProperty(target, descriptor.key, descriptor);
13
+ }
14
+ }
15
+ function _createClass(Constructor, protoProps, staticProps) {
16
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
+ if (staticProps) _defineProperties(Constructor, staticProps);
18
+ return Constructor;
19
+ }
6
20
  function _defineProperty(obj, key, value) {
7
21
  if (key in obj) {
8
22
  Object.defineProperty(obj, key, {
@@ -45,6 +59,12 @@ var Store = /*#__PURE__*/ function() {
45
59
  "use strict";
46
60
  function Store(props) {
47
61
  _classCallCheck(this, Store);
62
+ _defineProperty(this, "emptyState", void 0);
63
+ _defineProperty(this, "state", void 0);
64
+ _defineProperty(this, "dataBindMapping", void 0 // 主要提供给二开使用
65
+ );
66
+ _defineProperty(this, "controlIdMapping", void 0);
67
+ _defineProperty(this, "defaultState", void 0);
48
68
  var _init = init(props.instance), state = _init.state, emptyState = _init.emptyState, databindMapping = _init.databindMapping, controlidMapping = _init.controlidMapping, defaultState = _init.defaultState;
49
69
  this.emptyState = emptyState;
50
70
  this.state = state;
@@ -52,145 +72,158 @@ var Store = /*#__PURE__*/ function() {
52
72
  this.controlIdMapping = controlidMapping;
53
73
  this.defaultState = defaultState;
54
74
  }
55
- var _proto = Store.prototype;
56
- /**
75
+ _createClass(Store, [
76
+ {
77
+ /**
57
78
  * 使用该方法仅改变数据,不会表单触发事件。明细表可全量赋值也可根据rowIndex进行单独设置
58
79
  * @param controlId 组件ID
59
80
  * @param value
60
- */ _proto.setState = function setState(controlId, value, rowIndex) {
61
- var _this = this;
62
- var controlInfo = this.controlIdMapping[controlId];
63
- if (controlInfo !== undefined) {
64
- //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
65
- this.state[controlInfo.dataView][controlId] = value;
66
- // if (
67
- // controlInfo.dataBind instanceof ObjectDataBind &&
68
- // isPlainObject(value)
69
- // ) {
70
- // Object.assign(this.state[controlInfo.dataView][controlId], value)
71
- // } else {
72
- // this.state[controlInfo.dataView][controlId] = value
73
- // }
74
- } else {
75
- if (rowIndex !== undefined) {
76
- //TODO 目前只找了一层明细表,没有递归 如果是添加uid
77
- Object.keys(this.controlIdMapping).map(function(subtableId) {
78
- var dataView = _this.controlIdMapping[subtableId].dataView;
79
- var children = _this.controlIdMapping[subtableId].children;
80
- if (children !== undefined) {
81
- Object.keys(children).map(function(childControlId) {
82
- if (childControlId === controlId) {
83
- _this.state[dataView][subtableId][rowIndex][controlId] = value;
81
+ */ key: "setState",
82
+ value: function setState(controlId, value, rowIndex) {
83
+ var _this = this;
84
+ var controlInfo = this.controlIdMapping[controlId];
85
+ if (controlInfo !== undefined) {
86
+ //qiyu 按照对象赋值,Object.assign会触发多次key的change事件
87
+ this.state[controlInfo.dataView][controlId] = value;
88
+ // if (
89
+ // controlInfo.dataBind instanceof ObjectDataBind &&
90
+ // isPlainObject(value)
91
+ // ) {
92
+ // Object.assign(this.state[controlInfo.dataView][controlId], value)
93
+ // } else {
94
+ // this.state[controlInfo.dataView][controlId] = value
95
+ // }
96
+ } else {
97
+ if (rowIndex !== undefined) {
98
+ //TODO 目前只找了一层明细表,没有递归 如果是添加uid
99
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
100
+ var dataView = _this.controlIdMapping[subtableId].dataView;
101
+ var children = _this.controlIdMapping[subtableId].children;
102
+ if (children !== undefined) {
103
+ Object.keys(children).map(function(childControlId) {
104
+ if (childControlId === controlId) {
105
+ _this.state[dataView][subtableId][rowIndex][controlId] = value;
106
+ }
107
+ });
84
108
  }
85
109
  });
110
+ } else {
111
+ //不存在的 controlId,直接被挂载到外部key
112
+ this.state[controlId] = value;
86
113
  }
87
- });
88
- } else {
89
- //不存在的 controlId,直接被挂载到外部key
90
- this.state[controlId] = value;
114
+ }
91
115
  }
92
- }
93
- };
94
- _proto.getState = function getState(controlId, rowIndex) {
95
- var _this = this;
96
- //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
97
- // const controlInfo = this.controlIdMapping[controlId]
98
- var detection = this.state[controlId];
99
- if (detection !== undefined) {
100
- return this.state[controlId];
101
- } else {
102
- var controlInfo = this.controlIdMapping[controlId];
103
- if (controlInfo !== undefined) {
104
- return this.state[controlInfo.dataView][controlId];
105
- } else {
106
- if (rowIndex !== undefined) {
107
- var state;
108
- //TODO 目前只找了一层明细表,没有递归
109
- Object.keys(this.controlIdMapping).map(function(subtableId) {
110
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
111
- var children = _this.controlIdMapping[subtableId].children;
112
- if (children !== undefined) {
113
- Object.keys(children).map(function(childControlId) {
114
- if (childControlId === controlId) {
115
- var _this_state_dataViewId_subtableId_rowIndex;
116
- 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];
116
+ },
117
+ {
118
+ key: "getState",
119
+ value: function getState(controlId, rowIndex) {
120
+ var _this = this;
121
+ //qiyu 由于header的数据是后补充的,所以从state获取第一层值。
122
+ // const controlInfo = this.controlIdMapping[controlId]
123
+ var detection = this.state[controlId];
124
+ if (detection !== undefined) {
125
+ return this.state[controlId];
126
+ } else {
127
+ var controlInfo = this.controlIdMapping[controlId];
128
+ if (controlInfo !== undefined) {
129
+ return this.state[controlInfo.dataView][controlId];
130
+ } else {
131
+ if (rowIndex !== undefined) {
132
+ var state;
133
+ //TODO 目前只找了一层明细表,没有递归
134
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
135
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
136
+ var children = _this.controlIdMapping[subtableId].children;
137
+ if (children !== undefined) {
138
+ Object.keys(children).map(function(childControlId) {
139
+ if (childControlId === controlId) {
140
+ var _this_state_dataViewId_subtableId_rowIndex;
141
+ 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];
142
+ }
143
+ });
117
144
  }
118
145
  });
119
- }
120
- });
121
- return state;
122
- } else {
123
- var states = [];
124
- Object.keys(this.controlIdMapping).map(function(subtableId) {
125
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
126
- var children = _this.controlIdMapping[subtableId].children;
127
- if (children !== undefined) {
128
- Object.keys(children).map(function(childControlId) {
129
- if (childControlId === controlId) {
130
- _this.state[dataViewId][subtableId].map(function(item) {
131
- states.push(item[controlId]);
146
+ return state;
147
+ } else {
148
+ var states = [];
149
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
150
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
151
+ var children = _this.controlIdMapping[subtableId].children;
152
+ if (children !== undefined) {
153
+ Object.keys(children).map(function(childControlId) {
154
+ if (childControlId === controlId) {
155
+ _this.state[dataViewId][subtableId].map(function(item) {
156
+ states.push(item[controlId]);
157
+ });
158
+ }
132
159
  });
133
160
  }
134
161
  });
162
+ return states;
135
163
  }
136
- });
137
- return states;
164
+ }
138
165
  }
139
166
  }
140
- }
141
- };
142
- _proto.getEmptyState = function getEmptyState(controlId) {
143
- var _this = this;
144
- var detection = this.emptyState[controlId];
145
- if (detection !== undefined) {
146
- return this.emptyState[controlId];
147
- } else {
148
- var controlInfo = this.controlIdMapping[controlId];
149
- if (controlInfo !== undefined) {
150
- var state = this.emptyState[controlInfo.dataView][controlId];
151
- //判断找到的是否是明细表的控件
152
- if ("children" in controlInfo) {
153
- Object.assign(state, {
154
- uid: "new:" + buildUUID("uid")
155
- });
156
- }
157
- return state;
158
- } else {
159
- var state1;
160
- //TODO 目前只找了一层明细表,没有递归
161
- Object.keys(this.controlIdMapping).map(function(subtableId) {
162
- var dataViewId = _this.controlIdMapping[subtableId].dataView;
163
- var children = _this.controlIdMapping[subtableId].children;
164
- if (children !== undefined) {
165
- Object.keys(children).map(function(childControlId) {
166
- if (childControlId === controlId) {
167
- state1 = _this.emptyState[dataViewId][subtableId][controlId];
167
+ },
168
+ {
169
+ key: "getEmptyState",
170
+ value: function getEmptyState(controlId) {
171
+ var _this = this;
172
+ var detection = this.emptyState[controlId];
173
+ if (detection !== undefined) {
174
+ return this.emptyState[controlId];
175
+ } else {
176
+ var controlInfo = this.controlIdMapping[controlId];
177
+ if (controlInfo !== undefined) {
178
+ var state = this.emptyState[controlInfo.dataView][controlId];
179
+ //判断找到的是否是明细表的控件
180
+ if ("children" in controlInfo) {
181
+ Object.assign(state, {
182
+ uid: "new:" + buildUUID("uid")
183
+ });
184
+ }
185
+ return state;
186
+ } else {
187
+ var state1;
188
+ //TODO 目前只找了一层明细表,没有递归
189
+ Object.keys(this.controlIdMapping).map(function(subtableId) {
190
+ var dataViewId = _this.controlIdMapping[subtableId].dataView;
191
+ var children = _this.controlIdMapping[subtableId].children;
192
+ if (children !== undefined) {
193
+ Object.keys(children).map(function(childControlId) {
194
+ if (childControlId === controlId) {
195
+ state1 = _this.emptyState[dataViewId][subtableId][controlId];
196
+ }
197
+ });
168
198
  }
169
199
  });
200
+ return state1;
170
201
  }
171
- });
172
- return state1;
202
+ }
173
203
  }
174
- }
175
- };
176
- _proto.getDataBind = function getDataBind(controlId) {
177
- var result = this.controlIdMapping[controlId];
178
- if (result) {
179
- return result.dataBind;
180
- }
181
- wrapperFor: for(var id in this.controlIdMapping){
182
- var dataBindMapping = this.controlIdMapping[id];
183
- if (dataBindMapping.children) {
184
- for(var subId in dataBindMapping.children){
185
- if (subId === controlId) {
186
- result = dataBindMapping.children[subId];
187
- break wrapperFor;
204
+ },
205
+ {
206
+ key: "getDataBind",
207
+ value: function getDataBind(controlId) {
208
+ var result = this.controlIdMapping[controlId];
209
+ if (result) {
210
+ return result.dataBind;
211
+ }
212
+ wrapperFor: for(var id in this.controlIdMapping){
213
+ var dataBindMapping = this.controlIdMapping[id];
214
+ if (dataBindMapping.children) {
215
+ for(var subId in dataBindMapping.children){
216
+ if (subId === controlId) {
217
+ result = dataBindMapping.children[subId];
218
+ break wrapperFor;
219
+ }
220
+ }
188
221
  }
189
222
  }
223
+ return result === null || result === void 0 ? void 0 : result.dataBind;
190
224
  }
191
225
  }
192
- return result === null || result === void 0 ? void 0 : result.dataBind;
193
- };
226
+ ]);
194
227
  return Store;
195
228
  }();
196
229
  function init(instance) {