@byteluck-fe/model-driven-core-all 3.0.0-beta.6 → 3.0.0-beta.9

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.
@@ -0,0 +1,319 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
10
+ try {
11
+ var info = gen[key](arg);
12
+ var value = info.value;
13
+ } catch (error) {
14
+ reject(error);
15
+ return;
16
+ }
17
+ if (info.done) {
18
+ resolve(value);
19
+ } else {
20
+ Promise.resolve(value).then(_next, _throw);
21
+ }
22
+ }
23
+ function _async_to_generator(fn) {
24
+ return function() {
25
+ var self = this, args = arguments;
26
+ return new Promise(function(resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+ function _next(value) {
29
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
+ }
31
+ function _throw(err) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
+ }
34
+ _next(undefined);
35
+ });
36
+ };
37
+ }
38
+ function _iterable_to_array_limit(arr, i) {
39
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
+ if (_i == null) return;
41
+ var _arr = [];
42
+ var _n = true;
43
+ var _d = false;
44
+ var _s, _e;
45
+ try {
46
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
47
+ _arr.push(_s.value);
48
+ if (i && _arr.length === i) break;
49
+ }
50
+ } catch (err) {
51
+ _d = true;
52
+ _e = err;
53
+ } finally{
54
+ try {
55
+ if (!_n && _i["return"] != null) _i["return"]();
56
+ } finally{
57
+ if (_d) throw _e;
58
+ }
59
+ }
60
+ return _arr;
61
+ }
62
+ function _non_iterable_rest() {
63
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
+ }
65
+ function _sliced_to_array(arr, i) {
66
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
67
+ }
68
+ function _unsupported_iterable_to_array(o, minLen) {
69
+ if (!o) return;
70
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
71
+ var n = Object.prototype.toString.call(o).slice(8, -1);
72
+ if (n === "Object" && o.constructor) n = o.constructor.name;
73
+ if (n === "Map" || n === "Set") return Array.from(n);
74
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
75
+ }
76
+ function _ts_generator(thisArg, body) {
77
+ var f, y, t, _ = {
78
+ label: 0,
79
+ sent: function() {
80
+ if (t[0] & 1) throw t[1];
81
+ return t[1];
82
+ },
83
+ trys: [],
84
+ ops: []
85
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
86
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
87
+ return this;
88
+ }), g;
89
+ function verb(n) {
90
+ return function(v) {
91
+ return step([
92
+ n,
93
+ v
94
+ ]);
95
+ };
96
+ }
97
+ function step(op) {
98
+ if (f) throw new TypeError("Generator is already executing.");
99
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
100
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
101
+ if (y = 0, t) op = [
102
+ op[0] & 2,
103
+ t.value
104
+ ];
105
+ switch(op[0]){
106
+ case 0:
107
+ case 1:
108
+ t = op;
109
+ break;
110
+ case 4:
111
+ _.label++;
112
+ return {
113
+ value: op[1],
114
+ done: false
115
+ };
116
+ case 5:
117
+ _.label++;
118
+ y = op[1];
119
+ op = [
120
+ 0
121
+ ];
122
+ continue;
123
+ case 7:
124
+ op = _.ops.pop();
125
+ _.trys.pop();
126
+ continue;
127
+ default:
128
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
129
+ _ = 0;
130
+ continue;
131
+ }
132
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
133
+ _.label = op[1];
134
+ break;
135
+ }
136
+ if (op[0] === 6 && _.label < t[1]) {
137
+ _.label = t[1];
138
+ t = op;
139
+ break;
140
+ }
141
+ if (t && _.label < t[2]) {
142
+ _.label = t[2];
143
+ _.ops.push(op);
144
+ break;
145
+ }
146
+ if (t[2]) _.ops.pop();
147
+ _.trys.pop();
148
+ continue;
149
+ }
150
+ op = body.call(thisArg, _);
151
+ } catch (e) {
152
+ op = [
153
+ 6,
154
+ e
155
+ ];
156
+ y = 0;
157
+ } finally{
158
+ f = t = 0;
159
+ }
160
+ if (op[0] & 5) throw op[1];
161
+ return {
162
+ value: op[0] ? op[1] : void 0,
163
+ done: true
164
+ };
165
+ }
166
+ }
167
+ import { loadRemoteControl } from './loadRemoteScripts';
168
+ import { warn } from '@byteluck-fe/model-driven-shared';
169
+ import { getHackerControl } from './getHackerControl';
170
+ export function registerCustomControls(componentList, components, refLibs, payload) {
171
+ return _async_to_generator(function() {
172
+ var registered;
173
+ return _ts_generator(this, function(_state) {
174
+ switch(_state.label){
175
+ case 0:
176
+ registered = new Map();
177
+ if (componentList.length === 0) {
178
+ return [
179
+ 2,
180
+ registered
181
+ ];
182
+ }
183
+ //qiyu 2022-4-18 逐个加载自定义组件,只有异常的组件加载为hackerControl
184
+ return [
185
+ 4,
186
+ Promise.all(components.map(function(item) {
187
+ return _async_to_generator(function() {
188
+ var isLoaded, control, url, e, link, reg, reg1, styleLink;
189
+ return _ts_generator(this, function(_state) {
190
+ switch(_state.label){
191
+ case 0:
192
+ isLoaded = true;
193
+ _state.label = 1;
194
+ case 1:
195
+ _state.trys.push([
196
+ 1,
197
+ 3,
198
+ ,
199
+ 4
200
+ ]);
201
+ isLoaded = true;
202
+ url = '';
203
+ if (payload.type === 'runtime') {
204
+ url = item.runtime;
205
+ } else {
206
+ url = item.designer;
207
+ }
208
+ url += '?v=' + item.version + '&' + (payload.isPc === false ? 'mobile' : 'desktop');
209
+ return [
210
+ 4,
211
+ loadRemoteControl(url, refLibs)
212
+ ];
213
+ case 2:
214
+ control = _state.sent();
215
+ //探测组件是否加载正常
216
+ if (payload.type === 'runtime') {
217
+ control.Runtime.__is_control__ === true;
218
+ } else {
219
+ control.Designer.__is_control__ === true;
220
+ }
221
+ return [
222
+ 3,
223
+ 4
224
+ ];
225
+ case 3:
226
+ e = _state.sent();
227
+ isLoaded = false;
228
+ // @i18n-translate-ignore
229
+ warn('加载自定义控件异常,会影响到的控件:' + item.id, e);
230
+ control = getHackerControl(item.id, payload.type, payload.tipMessage);
231
+ return [
232
+ 3,
233
+ 4
234
+ ];
235
+ case 4:
236
+ if (isLoaded) {
237
+ link = '';
238
+ if (payload.type === 'runtime' && item.runtimecss !== undefined) {
239
+ reg = new RegExp(item.id + '-runtime-.*?$');
240
+ link = item.runtime.replace(reg, item.runtimecss);
241
+ } else if (payload.type === 'designer' && item.designercss !== undefined) {
242
+ reg1 = new RegExp(item.id + '-designer-.*?$');
243
+ link = item.designer.replace(reg1, item.designercss);
244
+ }
245
+ if (link !== '') {
246
+ styleLink = document.createElement('link');
247
+ styleLink.href = link;
248
+ styleLink.rel = 'stylesheet';
249
+ document.head.appendChild(styleLink);
250
+ }
251
+ }
252
+ pushControl(payload.type, control, registered, isLoaded, item);
253
+ return [
254
+ 2
255
+ ];
256
+ }
257
+ });
258
+ })();
259
+ }))
260
+ ];
261
+ case 1:
262
+ _state.sent();
263
+ componentList === null || componentList === void 0 ? void 0 : componentList.map(function(comIdWithVersion) {
264
+ var _comIdWithVersion_split = _sliced_to_array(comIdWithVersion.split(':'), 2), comid = _comIdWithVersion_split[0], version = _comIdWithVersion_split[1];
265
+ var hasControl = registered.has(comid);
266
+ if (hasControl === false) {
267
+ var control = getHackerControl(comid, payload.type, payload.tipMessage);
268
+ pushControl(payload.type, control, registered, false, {
269
+ fieldType: '',
270
+ id: comid,
271
+ name: '',
272
+ runtime: '',
273
+ designer: '',
274
+ type: '',
275
+ version: version
276
+ });
277
+ }
278
+ });
279
+ return [
280
+ 2,
281
+ registered
282
+ ];
283
+ }
284
+ });
285
+ })();
286
+ }
287
+ function pushControl(type, control, registered, isLoaded, props) {
288
+ if (type === 'runtime') {
289
+ if (registered.has(control.Runtime.controlType)) {
290
+ warn("repeat register ".concat(control.Runtime.controlType));
291
+ }
292
+ // let oldVersion // 此处不能赋值
293
+ // component_id_version_list.every(id => {
294
+ // const index = String(control.Runtime.controlType).indexOf(':')
295
+ // if (id.startsWith(control.Runtime.controlType) && index > -1) {
296
+ // oldVersion = String(control.Runtime.controlType).substring(index + 1)
297
+ // return false
298
+ // } else {
299
+ // return true
300
+ // }
301
+ // })
302
+ registered.set(control.Runtime.controlType, {
303
+ props: props,
304
+ version: props.version,
305
+ isLoaded: isLoaded,
306
+ control: control
307
+ });
308
+ } else {
309
+ if (registered.has(control.Designer.controlType)) {
310
+ warn("repeat register ".concat(control.Designer.controlType));
311
+ }
312
+ registered.set(control.Designer.controlType, {
313
+ props: props,
314
+ version: props.version,
315
+ isLoaded: isLoaded,
316
+ control: control
317
+ });
318
+ }
319
+ }
@@ -0,0 +1,60 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _iterable_to_array_limit(arr, i) {
10
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
11
+ if (_i == null) return;
12
+ var _arr = [];
13
+ var _n = true;
14
+ var _d = false;
15
+ var _s, _e;
16
+ try {
17
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
18
+ _arr.push(_s.value);
19
+ if (i && _arr.length === i) break;
20
+ }
21
+ } catch (err) {
22
+ _d = true;
23
+ _e = err;
24
+ } finally{
25
+ try {
26
+ if (!_n && _i["return"] != null) _i["return"]();
27
+ } finally{
28
+ if (_d) throw _e;
29
+ }
30
+ }
31
+ return _arr;
32
+ }
33
+ function _non_iterable_rest() {
34
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ function _sliced_to_array(arr, i) {
37
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
38
+ }
39
+ function _unsupported_iterable_to_array(o, minLen) {
40
+ if (!o) return;
41
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
42
+ var n = Object.prototype.toString.call(o).slice(8, -1);
43
+ if (n === "Object" && o.constructor) n = o.constructor.name;
44
+ if (n === "Map" || n === "Set") return Array.from(n);
45
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
46
+ }
47
+ export function upgradeCustomControlSchema(schema, registered, componentList, payload) {
48
+ var hasControl = registered.get(schema.type);
49
+ if (hasControl && hasControl.control.upgrade) {
50
+ var oldVersion = '';
51
+ componentList === null || componentList === void 0 ? void 0 : componentList.map(function(comIdWithVersion) {
52
+ var _comIdWithVersion_split = _sliced_to_array(comIdWithVersion.split(':'), 2), comid = _comIdWithVersion_split[0], version = _comIdWithVersion_split[1];
53
+ if (hasControl.props.id === comid) {
54
+ oldVersion = version !== null && version !== void 0 ? version : '';
55
+ }
56
+ });
57
+ schema = hasControl.control.upgrade(schema, hasControl.version, oldVersion, payload);
58
+ }
59
+ return schema;
60
+ }