@worktile/planet 12.1.2 → 13.0.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.
Files changed (77) hide show
  1. package/application/planet-application-loader.d.ts +3 -0
  2. package/application/planet-application-loader.d.ts.map +1 -1
  3. package/application/planet-application.service.d.ts +3 -0
  4. package/application/planet-application.service.d.ts.map +1 -1
  5. package/assets-loader.d.ts +3 -0
  6. package/assets-loader.d.ts.map +1 -1
  7. package/component/planet-component-loader.d.ts +3 -0
  8. package/component/planet-component-loader.d.ts.map +1 -1
  9. package/empty/empty.component.d.ts +3 -0
  10. package/empty/empty.component.d.ts.map +1 -1
  11. package/esm2020/application/planet-application-loader.mjs +454 -0
  12. package/esm2020/application/planet-application-ref.mjs +94 -0
  13. package/{esm2015/application/planet-application.service.js → esm2020/application/planet-application.service.mjs} +9 -11
  14. package/{esm2015/application/portal-application.js → esm2020/application/portal-application.mjs} +0 -0
  15. package/{esm2015/assets-loader.js → esm2020/assets-loader.mjs} +9 -10
  16. package/esm2020/component/planet-component-loader.mjs +153 -0
  17. package/{esm2015/component/planet-component-ref.js → esm2020/component/planet-component-ref.mjs} +0 -0
  18. package/{esm2015/component/plant-component.config.js → esm2020/component/plant-component.config.mjs} +0 -0
  19. package/{esm2015/debug.js → esm2020/debug.mjs} +0 -0
  20. package/esm2020/empty/empty.component.mjs +15 -0
  21. package/{esm2015/global-event-dispatcher.js → esm2020/global-event-dispatcher.mjs} +9 -10
  22. package/esm2020/global-planet.mjs +53 -0
  23. package/{esm2015/helpers.js → esm2020/helpers.mjs} +0 -0
  24. package/esm2020/module.mjs +31 -0
  25. package/{esm2015/planet.class.js → esm2020/planet.class.mjs} +0 -0
  26. package/esm2020/planet.mjs +91 -0
  27. package/{esm2015/public-api.js → esm2020/public-api.mjs} +0 -0
  28. package/{esm2015/sandbox/constants.js → esm2020/sandbox/constants.mjs} +0 -0
  29. package/{esm2015/sandbox/exec.js → esm2020/sandbox/exec.mjs} +0 -0
  30. package/{esm2015/sandbox/index.js → esm2020/sandbox/index.mjs} +0 -0
  31. package/{esm2015/sandbox/proxy/patches/document.js → esm2020/sandbox/proxy/patches/document.mjs} +0 -0
  32. package/{esm2015/sandbox/proxy/patches/eventListener.js → esm2020/sandbox/proxy/patches/eventListener.mjs} +0 -0
  33. package/{esm2015/sandbox/proxy/patches/index.js → esm2020/sandbox/proxy/patches/index.mjs} +0 -0
  34. package/{esm2015/sandbox/proxy/patches/storage.js → esm2020/sandbox/proxy/patches/storage.mjs} +0 -0
  35. package/{esm2015/sandbox/proxy/patches/timer.js → esm2020/sandbox/proxy/patches/timer.mjs} +0 -0
  36. package/{esm2015/sandbox/proxy/proxies/common.js → esm2020/sandbox/proxy/proxies/common.mjs} +2 -2
  37. package/{esm2015/sandbox/proxy/proxies/document.js → esm2020/sandbox/proxy/proxies/document.mjs} +0 -0
  38. package/{esm2015/sandbox/proxy/proxies/window.js → esm2020/sandbox/proxy/proxies/window.mjs} +5 -2
  39. package/{esm2015/sandbox/proxy/proxy-sandbox.js → esm2020/sandbox/proxy/proxy-sandbox.mjs} +2 -2
  40. package/{esm2015/sandbox/proxy/types.js → esm2020/sandbox/proxy/types.mjs} +0 -0
  41. package/{esm2015/sandbox/sandbox.js → esm2020/sandbox/sandbox.mjs} +0 -0
  42. package/{esm2015/sandbox/snapshot/snapshot-sandbox.js → esm2020/sandbox/snapshot/snapshot-sandbox.mjs} +0 -0
  43. package/{esm2015/sandbox/types.js → esm2020/sandbox/types.mjs} +0 -0
  44. package/esm2020/worktile-planet.mjs +5 -0
  45. package/fesm2015/{worktile-planet.js → worktile-planet.mjs} +231 -230
  46. package/fesm2015/worktile-planet.mjs.map +1 -0
  47. package/fesm2020/worktile-planet.mjs +2046 -0
  48. package/fesm2020/worktile-planet.mjs.map +1 -0
  49. package/global-event-dispatcher.d.ts +3 -0
  50. package/global-event-dispatcher.d.ts.map +1 -1
  51. package/module.d.ts +6 -0
  52. package/module.d.ts.map +1 -1
  53. package/package.json +28 -12
  54. package/planet.d.ts +3 -0
  55. package/planet.d.ts.map +1 -1
  56. package/worktile-planet.d.ts +1 -1
  57. package/worktile-planet.d.ts.map +1 -1
  58. package/application/planet-application-loader.ngfactory.d.ts.map +0 -1
  59. package/application/planet-application.service.ngfactory.d.ts.map +0 -1
  60. package/assets-loader.ngfactory.d.ts.map +0 -1
  61. package/bundles/worktile-planet.umd.js +0 -2564
  62. package/bundles/worktile-planet.umd.js.map +0 -1
  63. package/component/planet-component-loader.ngfactory.d.ts.map +0 -1
  64. package/empty/empty.component.ngfactory.d.ts.map +0 -1
  65. package/esm2015/application/planet-application-loader.js +0 -457
  66. package/esm2015/application/planet-application-ref.js +0 -97
  67. package/esm2015/component/planet-component-loader.js +0 -155
  68. package/esm2015/empty/empty.component.js +0 -10
  69. package/esm2015/global-planet.js +0 -54
  70. package/esm2015/module.js +0 -27
  71. package/esm2015/planet.js +0 -91
  72. package/esm2015/worktile-planet.js +0 -6
  73. package/fesm2015/worktile-planet.js.map +0 -1
  74. package/global-event-dispatcher.ngfactory.d.ts.map +0 -1
  75. package/module.ngfactory.d.ts.map +0 -1
  76. package/planet.ngfactory.d.ts.map +0 -1
  77. package/worktile-planet.metadata.json +0 -1
@@ -1,2564 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('@angular/common/http'), require('rxjs/operators'), require('rxjs'), require('@angular/cdk/portal'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('@worktile/planet', ['exports', '@angular/core', '@angular/router', '@angular/common/http', 'rxjs/operators', 'rxjs', '@angular/cdk/portal', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.worktile = global.worktile || {}, global.worktile.planet = {}), global.ng.core, global.ng.router, global.ng.common.http, global.rxjs.operators, global.rxjs, global.ng.cdk.portal, global.ng.common));
5
- }(this, (function (exports, i0, i3, i1, operators, rxjs, portal, i1$1) { 'use strict';
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () {
17
- return e[k];
18
- }
19
- });
20
- }
21
- });
22
- }
23
- n['default'] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
- var i3__namespace = /*#__PURE__*/_interopNamespace(i3);
29
- var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
30
- var i1__namespace$1 = /*#__PURE__*/_interopNamespace(i1$1);
31
-
32
- exports.SwitchModes = void 0;
33
- (function (SwitchModes) {
34
- SwitchModes["default"] = "default";
35
- SwitchModes["coexist"] = "coexist";
36
- })(exports.SwitchModes || (exports.SwitchModes = {}));
37
- var PLANET_APPLICATIONS = new i0.InjectionToken('PLANET_APPLICATIONS');
38
-
39
- var ELEMENT_NODE_TYPE = 1;
40
- function hashCode(str) {
41
- var hash = 0;
42
- var chr;
43
- if (str.length === 0) {
44
- return hash;
45
- }
46
- for (var i = 0; i < str.length; i++) {
47
- chr = str.charCodeAt(i);
48
- hash = (hash << 5) - hash + chr;
49
- hash |= 0; // Convert to 32bit integer
50
- }
51
- return hash;
52
- }
53
- function getHTMLElement(selector) {
54
- if (selector instanceof HTMLElement) {
55
- return selector;
56
- }
57
- else {
58
- return document.querySelector(selector);
59
- }
60
- }
61
- function getTagNameByTemplate(template) {
62
- var element = createElementByTemplate(template);
63
- return element ? element.nodeName : '';
64
- }
65
- function createElementByTemplate(template) {
66
- if (!template) {
67
- return null;
68
- }
69
- var element = document.createRange().createContextualFragment(template).firstChild;
70
- if (element && element.nodeType === ELEMENT_NODE_TYPE) {
71
- return element;
72
- }
73
- else {
74
- throw new Error("invalid template '" + template + "'");
75
- }
76
- }
77
- function coerceArray(value) {
78
- return Array.isArray(value) ? value : [value];
79
- }
80
- function isEmpty(value) {
81
- if (!value || value.length === 0) {
82
- return true;
83
- }
84
- else {
85
- return false;
86
- }
87
- }
88
- function isFunction(value) {
89
- var type = typeof value;
90
- return !!value && type === 'function';
91
- }
92
- function isObject(val) {
93
- return val && typeof val === 'object';
94
- }
95
- /**
96
- * Get file name from path
97
- * 1. "main.js" => "main.js"
98
- * 2. "assets/scripts/main.js" => "main.js"
99
- * @param path path
100
- */
101
- function getResourceFileName(path) {
102
- var lastSlashIndex = path.lastIndexOf('/');
103
- if (lastSlashIndex >= 0) {
104
- return path.slice(lastSlashIndex + 1);
105
- }
106
- else {
107
- return path;
108
- }
109
- }
110
- /**
111
- * Build resource path by manifest
112
- * if manifest is { "main.js": "main.h2sh23abee.js"}
113
- * 1. "main.js" => "main.h2sh23abee.js"
114
- * 2. "assets/scripts/main.js" =>"assets/scripts/main.h2sh23abee.js"
115
- * @param resourceFilePath Resource File Path
116
- * @param manifestResult manifest
117
- */
118
- function buildResourceFilePath(resourceFilePath, manifestResult) {
119
- var fileName = getResourceFileName(resourceFilePath);
120
- if (manifestResult[fileName]) {
121
- return resourceFilePath.replace(fileName, manifestResult[fileName]);
122
- }
123
- else {
124
- return resourceFilePath;
125
- }
126
- }
127
- /**
128
- * Get static resource full path
129
- * @param app PlanetApplication
130
- * @param manifestResult manifest
131
- */
132
- function getScriptsAndStylesFullPaths(app, manifestResult) {
133
- var scripts = app.scripts || [];
134
- var styles = app.styles || [];
135
- // combine resource path by manifest
136
- if (manifestResult) {
137
- scripts = scripts.map(function (script) {
138
- return buildResourceFilePath(script, manifestResult);
139
- });
140
- styles = styles.map(function (style) {
141
- return buildResourceFilePath(style, manifestResult);
142
- });
143
- }
144
- if (app.resourcePathPrefix) {
145
- scripts = scripts.map(function (script) {
146
- return "" + app.resourcePathPrefix + script;
147
- });
148
- styles = styles.map(function (style) {
149
- return "" + app.resourcePathPrefix + style;
150
- });
151
- }
152
- return {
153
- scripts: scripts,
154
- styles: styles
155
- };
156
- }
157
-
158
- /*! *****************************************************************************
159
- Copyright (c) Microsoft Corporation.
160
-
161
- Permission to use, copy, modify, and/or distribute this software for any
162
- purpose with or without fee is hereby granted.
163
-
164
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
165
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
166
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
167
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
168
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
169
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
170
- PERFORMANCE OF THIS SOFTWARE.
171
- ***************************************************************************** */
172
- /* global Reflect, Promise */
173
- var extendStatics = function (d, b) {
174
- extendStatics = Object.setPrototypeOf ||
175
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
176
- function (d, b) { for (var p in b)
177
- if (Object.prototype.hasOwnProperty.call(b, p))
178
- d[p] = b[p]; };
179
- return extendStatics(d, b);
180
- };
181
- function __extends(d, b) {
182
- if (typeof b !== "function" && b !== null)
183
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
184
- extendStatics(d, b);
185
- function __() { this.constructor = d; }
186
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
187
- }
188
- var __assign = function () {
189
- __assign = Object.assign || function __assign(t) {
190
- for (var s, i = 1, n = arguments.length; i < n; i++) {
191
- s = arguments[i];
192
- for (var p in s)
193
- if (Object.prototype.hasOwnProperty.call(s, p))
194
- t[p] = s[p];
195
- }
196
- return t;
197
- };
198
- return __assign.apply(this, arguments);
199
- };
200
- function __rest(s, e) {
201
- var t = {};
202
- for (var p in s)
203
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
204
- t[p] = s[p];
205
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
206
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
207
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
208
- t[p[i]] = s[p[i]];
209
- }
210
- return t;
211
- }
212
- function __decorate(decorators, target, key, desc) {
213
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
214
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
215
- r = Reflect.decorate(decorators, target, key, desc);
216
- else
217
- for (var i = decorators.length - 1; i >= 0; i--)
218
- if (d = decorators[i])
219
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
220
- return c > 3 && r && Object.defineProperty(target, key, r), r;
221
- }
222
- function __param(paramIndex, decorator) {
223
- return function (target, key) { decorator(target, key, paramIndex); };
224
- }
225
- function __metadata(metadataKey, metadataValue) {
226
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
227
- return Reflect.metadata(metadataKey, metadataValue);
228
- }
229
- function __awaiter(thisArg, _arguments, P, generator) {
230
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
231
- return new (P || (P = Promise))(function (resolve, reject) {
232
- function fulfilled(value) { try {
233
- step(generator.next(value));
234
- }
235
- catch (e) {
236
- reject(e);
237
- } }
238
- function rejected(value) { try {
239
- step(generator["throw"](value));
240
- }
241
- catch (e) {
242
- reject(e);
243
- } }
244
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
245
- step((generator = generator.apply(thisArg, _arguments || [])).next());
246
- });
247
- }
248
- function __generator(thisArg, body) {
249
- var _ = { label: 0, sent: function () { if (t[0] & 1)
250
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
251
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
252
- function verb(n) { return function (v) { return step([n, v]); }; }
253
- function step(op) {
254
- if (f)
255
- throw new TypeError("Generator is already executing.");
256
- while (_)
257
- try {
258
- 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)
259
- return t;
260
- if (y = 0, t)
261
- op = [op[0] & 2, t.value];
262
- switch (op[0]) {
263
- case 0:
264
- case 1:
265
- t = op;
266
- break;
267
- case 4:
268
- _.label++;
269
- return { value: op[1], done: false };
270
- case 5:
271
- _.label++;
272
- y = op[1];
273
- op = [0];
274
- continue;
275
- case 7:
276
- op = _.ops.pop();
277
- _.trys.pop();
278
- continue;
279
- default:
280
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
281
- _ = 0;
282
- continue;
283
- }
284
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
285
- _.label = op[1];
286
- break;
287
- }
288
- if (op[0] === 6 && _.label < t[1]) {
289
- _.label = t[1];
290
- t = op;
291
- break;
292
- }
293
- if (t && _.label < t[2]) {
294
- _.label = t[2];
295
- _.ops.push(op);
296
- break;
297
- }
298
- if (t[2])
299
- _.ops.pop();
300
- _.trys.pop();
301
- continue;
302
- }
303
- op = body.call(thisArg, _);
304
- }
305
- catch (e) {
306
- op = [6, e];
307
- y = 0;
308
- }
309
- finally {
310
- f = t = 0;
311
- }
312
- if (op[0] & 5)
313
- throw op[1];
314
- return { value: op[0] ? op[1] : void 0, done: true };
315
- }
316
- }
317
- var __createBinding = Object.create ? (function (o, m, k, k2) {
318
- if (k2 === undefined)
319
- k2 = k;
320
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
321
- }) : (function (o, m, k, k2) {
322
- if (k2 === undefined)
323
- k2 = k;
324
- o[k2] = m[k];
325
- });
326
- function __exportStar(m, o) {
327
- for (var p in m)
328
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
329
- __createBinding(o, m, p);
330
- }
331
- function __values(o) {
332
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
333
- if (m)
334
- return m.call(o);
335
- if (o && typeof o.length === "number")
336
- return {
337
- next: function () {
338
- if (o && i >= o.length)
339
- o = void 0;
340
- return { value: o && o[i++], done: !o };
341
- }
342
- };
343
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
344
- }
345
- function __read(o, n) {
346
- var m = typeof Symbol === "function" && o[Symbol.iterator];
347
- if (!m)
348
- return o;
349
- var i = m.call(o), r, ar = [], e;
350
- try {
351
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
352
- ar.push(r.value);
353
- }
354
- catch (error) {
355
- e = { error: error };
356
- }
357
- finally {
358
- try {
359
- if (r && !r.done && (m = i["return"]))
360
- m.call(i);
361
- }
362
- finally {
363
- if (e)
364
- throw e.error;
365
- }
366
- }
367
- return ar;
368
- }
369
- /** @deprecated */
370
- function __spread() {
371
- for (var ar = [], i = 0; i < arguments.length; i++)
372
- ar = ar.concat(__read(arguments[i]));
373
- return ar;
374
- }
375
- /** @deprecated */
376
- function __spreadArrays() {
377
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
378
- s += arguments[i].length;
379
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
380
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
381
- r[k] = a[j];
382
- return r;
383
- }
384
- function __spreadArray(to, from, pack) {
385
- if (pack || arguments.length === 2)
386
- for (var i = 0, l = from.length, ar; i < l; i++) {
387
- if (ar || !(i in from)) {
388
- if (!ar)
389
- ar = Array.prototype.slice.call(from, 0, i);
390
- ar[i] = from[i];
391
- }
392
- }
393
- return to.concat(ar || from);
394
- }
395
- function __await(v) {
396
- return this instanceof __await ? (this.v = v, this) : new __await(v);
397
- }
398
- function __asyncGenerator(thisArg, _arguments, generator) {
399
- if (!Symbol.asyncIterator)
400
- throw new TypeError("Symbol.asyncIterator is not defined.");
401
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
402
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
403
- function verb(n) { if (g[n])
404
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
405
- function resume(n, v) { try {
406
- step(g[n](v));
407
- }
408
- catch (e) {
409
- settle(q[0][3], e);
410
- } }
411
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
412
- function fulfill(value) { resume("next", value); }
413
- function reject(value) { resume("throw", value); }
414
- function settle(f, v) { if (f(v), q.shift(), q.length)
415
- resume(q[0][0], q[0][1]); }
416
- }
417
- function __asyncDelegator(o) {
418
- var i, p;
419
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
420
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
421
- }
422
- function __asyncValues(o) {
423
- if (!Symbol.asyncIterator)
424
- throw new TypeError("Symbol.asyncIterator is not defined.");
425
- var m = o[Symbol.asyncIterator], i;
426
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
427
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
428
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
429
- }
430
- function __makeTemplateObject(cooked, raw) {
431
- if (Object.defineProperty) {
432
- Object.defineProperty(cooked, "raw", { value: raw });
433
- }
434
- else {
435
- cooked.raw = raw;
436
- }
437
- return cooked;
438
- }
439
- ;
440
- var __setModuleDefault = Object.create ? (function (o, v) {
441
- Object.defineProperty(o, "default", { enumerable: true, value: v });
442
- }) : function (o, v) {
443
- o["default"] = v;
444
- };
445
- function __importStar(mod) {
446
- if (mod && mod.__esModule)
447
- return mod;
448
- var result = {};
449
- if (mod != null)
450
- for (var k in mod)
451
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
452
- __createBinding(result, mod, k);
453
- __setModuleDefault(result, mod);
454
- return result;
455
- }
456
- function __importDefault(mod) {
457
- return (mod && mod.__esModule) ? mod : { default: mod };
458
- }
459
- function __classPrivateFieldGet(receiver, state, kind, f) {
460
- if (kind === "a" && !f)
461
- throw new TypeError("Private accessor was defined without a getter");
462
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
463
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
464
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
465
- }
466
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
467
- if (kind === "m")
468
- throw new TypeError("Private method is not writable");
469
- if (kind === "a" && !f)
470
- throw new TypeError("Private accessor was defined without a setter");
471
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
472
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
473
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
474
- }
475
-
476
- var PLANET_SANDBOX_WINDOW_WHITELIST = window['___PLANET_SANDBOX_WINDOW_WHITELIST___'];
477
- var PLANET_SANDBOX_DOCUMENT_WHITELIST = window['___PLANET_SANDBOX_DOCUMENT_WHITELIST___'];
478
- var SANDBOX_INSTANCE = Symbol.for('PLANET_SANDBOX_INSTANCE');
479
- var RAW_NODE = Symbol.for('PLANET_RAW_NODE');
480
- var WINDOW_BIND_FN = Symbol.for('PLANET_WINDOW_BIND_FN');
481
- var DOCUMENT_BIND_FN = Symbol.for('PLANET_DOCUMENT_BIND_FN');
482
-
483
- var rawHasOwnProperty = Object.prototype.hasOwnProperty;
484
- function hasOwnProp(obj, key) {
485
- return rawHasOwnProperty.call(obj, key);
486
- }
487
- function isValueDescriptor(desc) {
488
- if (desc === undefined) {
489
- return false;
490
- }
491
- return 'value' in desc || 'writable' in desc;
492
- }
493
- function isAccessorDescriptor(desc) {
494
- if (desc === undefined) {
495
- return false;
496
- }
497
- return 'get' in desc || 'set' in desc;
498
- }
499
- function isNonWriteableValue(desc) {
500
- return desc && desc.configurable === false && 'value' in desc && desc.writable === false;
501
- }
502
- function isInvalidSetAccessor(desc) {
503
- if (desc && desc.configurable === false && 'set' in desc && desc.set === undefined) {
504
- return true;
505
- }
506
- else {
507
- return false;
508
- }
509
- }
510
- function isInvalidGetAccessor(desc) {
511
- if (desc && desc.configurable === false && 'get' in desc && desc.get === undefined) {
512
- return true;
513
- }
514
- else {
515
- return false;
516
- }
517
- }
518
- function transferParams(args) {
519
- args = Array.isArray(args) ? args : Array.from(args);
520
- return args.map(function (arg) {
521
- return arg[RAW_NODE] ? arg[RAW_NODE] : arg;
522
- });
523
- }
524
- var buildInProps = ['length', 'caller', 'callee', 'arguments', 'prototype', Symbol.hasInstance];
525
- function transferProps(o, n) {
526
- var e_1, _a;
527
- try {
528
- for (var _b = __values(Reflect.ownKeys(o)), _c = _b.next(); !_c.done; _c = _b.next()) {
529
- var key = _c.value;
530
- if (buildInProps.includes(key)) {
531
- continue;
532
- }
533
- var desc = Object.getOwnPropertyDescriptor(n, key);
534
- if (desc && desc.writable) {
535
- n[key] = o[key];
536
- }
537
- }
538
- }
539
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
540
- finally {
541
- try {
542
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
543
- }
544
- finally { if (e_1) throw e_1.error; }
545
- }
546
- }
547
- function bind(fn, context) {
548
- var fNOP = function () { };
549
- function bound() {
550
- var args = transferParams(arguments);
551
- if (this instanceof bound) {
552
- var obj = new (fn.bind.apply(fn, __spreadArray([void 0], __read(args))))();
553
- Object.setPrototypeOf(obj, bound.prototype);
554
- return obj;
555
- }
556
- else {
557
- return fn.apply(context, args);
558
- }
559
- }
560
- bound.$native = fn;
561
- transferProps(fn, bound);
562
- if (fn.prototype) {
563
- fNOP.prototype = fn.prototype;
564
- }
565
- bound.prototype = new fNOP();
566
- if (Symbol.hasInstance) {
567
- Object.defineProperty(bound, Symbol.hasInstance, {
568
- configurable: true,
569
- value: function (instance) {
570
- var op = fn.prototype;
571
- return isObject(op) || typeof op === 'function' ? instance instanceof fn : false;
572
- }
573
- });
574
- }
575
- return bound;
576
- }
577
- function createFakeObject(target, writableKeys) {
578
- var fakeObject = {};
579
- var propertyMap = {};
580
- var storageBox = Object.create(null);
581
- var propertyNames = Object.getOwnPropertyNames(target);
582
- var def = function (p) {
583
- var descriptor = Object.getOwnPropertyDescriptor(target, p);
584
- if (descriptor === null || descriptor === void 0 ? void 0 : descriptor.configurable) {
585
- var hasGetter = hasOwnProp(descriptor, 'get');
586
- var hasSetter = hasOwnProp(descriptor, 'set');
587
- var canWritable = writableKeys && writableKeys.length > 0 && writableKeys.includes(p);
588
- if (hasGetter) {
589
- descriptor.get = function () { return (hasOwnProp(storageBox, p) ? storageBox[p] : target[p]); };
590
- }
591
- if (hasSetter) {
592
- descriptor.set = function (val) {
593
- storageBox[p] = val;
594
- return true;
595
- };
596
- }
597
- if (canWritable) {
598
- if (descriptor.writable === false) {
599
- descriptor.writable = true;
600
- }
601
- else if (hasGetter) {
602
- descriptor.set = function (val) {
603
- storageBox[p] = val;
604
- return true;
605
- };
606
- }
607
- }
608
- Object.defineProperty(fakeObject, p, Object.freeze(descriptor));
609
- }
610
- };
611
- propertyNames.forEach(function (p) {
612
- propertyMap[p] = true;
613
- def(p);
614
- });
615
- // 再次循环是为了处理原型链中的属性
616
- for (var prop in target) {
617
- if (!propertyMap[prop]) {
618
- def(prop);
619
- }
620
- }
621
- return fakeObject;
622
- }
623
-
624
- var esGlobalFunctions = ('eval,isFinite,isNaN,parseFloat,parseInt,' +
625
- // URL handling functions
626
- 'decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
627
- // Constructor properties of the global object
628
- 'Array,ArrayBuffer,BigInt,BigInt64Array,BigUint64Array,Boolean,DataView,Date,Error,EvalError,' +
629
- 'FinalizationRegistry,Float32Array,Float64Array,Function,Int8Array,Int16Array,Int32Array,Map,Number,' +
630
- 'Object,Promise,Proxy,RangeError,ReferenceError,RegExp,Set,SharedArrayBuffer,String,Symbol,SyntaxError,' +
631
- 'TypeError,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,URIError,WeakMap,WeakRef,WeakSet,' +
632
- // Other Properties of the Global Object
633
- 'Atomics,JSON,Math,Reflect').split(',');
634
- var whitelistVariables = PLANET_SANDBOX_WINDOW_WHITELIST || [];
635
- function isConstructor(fn) {
636
- var fp = fn.prototype;
637
- var hasConstructor = fp && fp.constructor === fn && Object.getOwnPropertyNames(fp).length > 1;
638
- var functionStr = !hasConstructor && fn.toString();
639
- return hasConstructor || /^function\s+[A-Z]/.test(functionStr) || /^class\b/.test(functionStr);
640
- }
641
- var unscopables = {
642
- undefined: true,
643
- Array: true,
644
- Object: true,
645
- String: true,
646
- Boolean: true,
647
- Math: true,
648
- Number: true,
649
- Symbol: true,
650
- parseFloat: true,
651
- Float32Array: true
652
- };
653
- var ProxyWindow = /** @class */ (function () {
654
- function ProxyWindow(sandbox) {
655
- this.sandbox = sandbox;
656
- this.definedVariables = new Set();
657
- }
658
- ProxyWindow.prototype.createGetter = function () {
659
- var _this = this;
660
- return function (target, key, receiver) {
661
- if (key === Symbol.unscopables) {
662
- return unscopables;
663
- }
664
- if (key === SANDBOX_INSTANCE) {
665
- return _this.sandbox;
666
- }
667
- var value = null;
668
- if (whitelistVariables.includes(key)) {
669
- return Reflect.get(window, key);
670
- }
671
- else {
672
- value = hasOwnProp(target, key) ? Reflect.get(target, key, receiver) : Reflect.get(window, key);
673
- }
674
- if (isFunction(value)) {
675
- if (esGlobalFunctions.includes(key) ||
676
- whitelistVariables.includes(key) ||
677
- _this.sandbox.rewriteVariables.includes(key) ||
678
- _this.definedVariables.has(key) ||
679
- isConstructor(value)) {
680
- return value;
681
- }
682
- else {
683
- var newValue = hasOwnProp(value, WINDOW_BIND_FN) ? value[WINDOW_BIND_FN] : bind(value, window);
684
- var desc = Object.getOwnPropertyDescriptor(target, key);
685
- if (isNonWriteableValue(desc)) {
686
- return value;
687
- }
688
- if (isInvalidGetAccessor(desc)) {
689
- return undefined;
690
- }
691
- value[WINDOW_BIND_FN] = newValue;
692
- return newValue;
693
- }
694
- }
695
- else {
696
- return value;
697
- }
698
- };
699
- };
700
- ProxyWindow.prototype.createSetter = function () {
701
- var _this = this;
702
- return function (target, key, value, receiver) {
703
- var desc = Object.getOwnPropertyDescriptor(whitelistVariables.includes(key) ? window : receiver ? receiver : target, key);
704
- if (desc && isNonWriteableValue(desc)) {
705
- if (!Object.is(value, desc.value)) {
706
- return false;
707
- }
708
- else {
709
- return true;
710
- }
711
- }
712
- if (isInvalidSetAccessor(desc)) {
713
- return false;
714
- }
715
- if (whitelistVariables.includes(key)) {
716
- return Reflect.set(window, key, value);
717
- }
718
- else {
719
- var success = Reflect.set(target, key, value, receiver);
720
- if (success) {
721
- if (_this.sandbox.running) {
722
- _this.definedVariables.add(key);
723
- }
724
- }
725
- return success;
726
- }
727
- };
728
- };
729
- ProxyWindow.prototype.createDefineProperty = function () {
730
- var _this = this;
731
- return function (target, p, descriptor) {
732
- if (whitelistVariables.includes(p)) {
733
- return Reflect.defineProperty(window, p, descriptor);
734
- }
735
- else {
736
- var success = Reflect.defineProperty(target, p, descriptor);
737
- if (_this.sandbox.running && success) {
738
- _this.definedVariables.add(p);
739
- }
740
- return success;
741
- }
742
- };
743
- };
744
- ProxyWindow.prototype.createDeleteProperty = function () {
745
- var _this = this;
746
- return function (target, p) {
747
- if (hasOwnProp(target, p)) {
748
- delete target[p];
749
- if (_this.sandbox.running && _this.definedVariables.has(p)) {
750
- _this.definedVariables.delete(p);
751
- }
752
- }
753
- return true;
754
- };
755
- };
756
- ProxyWindow.prototype.createHas = function () {
757
- return function (_target, key) {
758
- return !whitelistVariables.includes(key);
759
- };
760
- };
761
- ProxyWindow.prototype.create = function () {
762
- var fakeWindow = createFakeObject(window, this.sandbox.rewriteVariables);
763
- var baseHandlers = {
764
- get: this.createGetter(),
765
- set: this.createSetter(),
766
- defineProperty: this.createDefineProperty(),
767
- deleteProperty: this.createDeleteProperty()
768
- };
769
- var proxy = new Proxy(fakeWindow, Object.assign(Object.assign({}, baseHandlers), { has: this.createHas() }));
770
- var subProxy = new Proxy(fakeWindow, baseHandlers);
771
- proxy.self = subProxy;
772
- proxy.window = subProxy;
773
- proxy.globalThis = subProxy;
774
- proxy.top = window.top === window ? subProxy : window.top;
775
- proxy.parent = window.parent === window ? subProxy : window.top;
776
- return proxy;
777
- };
778
- return ProxyWindow;
779
- }());
780
-
781
- function eventListenerPatch(sandbox) {
782
- var rawAddEventListener = window.addEventListener;
783
- var rawRemoveEventListener = window.removeEventListener;
784
- var listenerSubscriptions = new Map();
785
- function addEventListener(type, listener, options) {
786
- var _this = this;
787
- var observable = new rxjs.Observable(function () {
788
- rawAddEventListener.call(_this, type, listener, options);
789
- return function () {
790
- rawRemoveEventListener.call(_this, type, listener, options);
791
- };
792
- });
793
- var subscription = observable.subscribe(function () { });
794
- listenerSubscriptions.set(listener, subscription);
795
- }
796
- function removeEventListener(type, listener) {
797
- var subscription = listenerSubscriptions.get(listener);
798
- if (subscription) {
799
- subscription.unsubscribe();
800
- listenerSubscriptions.delete(listener);
801
- }
802
- }
803
- return {
804
- rewrite: {
805
- addEventListener: addEventListener.bind(window),
806
- removeEventListener: removeEventListener.bind(window)
807
- },
808
- init: function () {
809
- var fakeDocument = sandbox.global.document;
810
- if (fakeDocument) {
811
- fakeDocument.addEventListener = addEventListener.bind(document);
812
- fakeDocument.removeEventListener = removeEventListener.bind(document);
813
- }
814
- },
815
- destroy: function () {
816
- listenerSubscriptions.forEach(function (subscription) { return subscription.unsubscribe(); });
817
- listenerSubscriptions.clear();
818
- }
819
- };
820
- }
821
-
822
- var rawDocument = Document;
823
- var whitelist = __spreadArray(['cookie', 'title', 'location'], __read((PLANET_SANDBOX_DOCUMENT_WHITELIST || [])));
824
- var ProxyDocument = /** @class */ (function () {
825
- function ProxyDocument() {
826
- }
827
- ProxyDocument.prototype.createGetter = function () {
828
- return function (target, p, receiver) {
829
- var value = hasOwnProp(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(document, p);
830
- if (p === 'activeElement') {
831
- return Reflect.get(document, p);
832
- }
833
- // TODO: 处理动态节点
834
- // if (p === 'createElement') {
835
- // return function(tagName: string, options: ElementCreationOptions) {
836
- // const created = value.call(document, tagName, options);
837
- // if (isObject(created)) {
838
- // created[SANDBOX_INSTANCE] = sandbox;
839
- // }
840
- // return created;
841
- // };
842
- // }
843
- if (isFunction(value)) {
844
- var newValue = hasOwnProp(value, DOCUMENT_BIND_FN) ? value[DOCUMENT_BIND_FN] : null;
845
- if (!newValue) {
846
- newValue = bind(value, document);
847
- }
848
- var desc = Object.getOwnPropertyDescriptor(target, p);
849
- if (desc && isNonWriteableValue(desc)) {
850
- if (!Object.is(newValue, desc.value)) {
851
- return value;
852
- }
853
- }
854
- if (isInvalidGetAccessor(desc)) {
855
- return undefined;
856
- }
857
- value[DOCUMENT_BIND_FN] = newValue;
858
- return newValue;
859
- }
860
- return value;
861
- };
862
- };
863
- ProxyDocument.prototype.createSetter = function () {
864
- return function (target, p, value, receiver) {
865
- var desc = Object.getOwnPropertyDescriptor(whitelist.includes(p) ? document : receiver || target, p);
866
- if (desc && isNonWriteableValue(desc)) {
867
- if (Object.is(value, desc.value)) {
868
- return true;
869
- }
870
- else {
871
- return false;
872
- }
873
- }
874
- if (isInvalidSetAccessor(desc)) {
875
- return false;
876
- }
877
- return whitelist.includes(p) ? Reflect.set(document, p, value) : Reflect.set(target, p, value, receiver);
878
- };
879
- };
880
- ProxyDocument.prototype.createDefineProperty = function () {
881
- return function (target, p, descriptor) {
882
- return whitelist.includes(p)
883
- ? Reflect.defineProperty(document, p, descriptor)
884
- : Reflect.defineProperty(target, p, descriptor);
885
- };
886
- };
887
- ProxyDocument.prototype.create = function () {
888
- var _a;
889
- var proxyDocument = null;
890
- var fakeDocument = createFakeObject(document);
891
- var getter = this.createGetter();
892
- var fakeDocumentProto = new Proxy(fakeDocument, {
893
- get: function () {
894
- var args = [];
895
- for (var _i = 0; _i < arguments.length; _i++) {
896
- args[_i] = arguments[_i];
897
- }
898
- return getter.apply(void 0, __spreadArray([], __read(args)));
899
- }
900
- });
901
- var fakeDocumentCtor = function Document() {
902
- if (!(this instanceof fakeDocumentCtor)) {
903
- throw new TypeError("Failed to construct 'Document': Please use the 'new' operator.");
904
- }
905
- var docInstance = new rawDocument();
906
- Object.setPrototypeOf(docInstance, fakeDocument);
907
- return docInstance;
908
- };
909
- fakeDocumentCtor.prototype = fakeDocumentProto;
910
- fakeDocumentCtor.prototype.constructor = fakeDocumentCtor;
911
- if (Symbol.hasInstance) {
912
- Object.defineProperty(fakeDocumentCtor, Symbol.hasInstance, {
913
- configurable: true,
914
- value: function (value) {
915
- var proto = value;
916
- if (proto === document) {
917
- return true;
918
- }
919
- while ((proto = Object.getPrototypeOf(proto))) {
920
- if (proto === fakeDocumentProto) {
921
- return true;
922
- }
923
- }
924
- var cloned = function () { };
925
- cloned.prototype = fakeDocument;
926
- return value instanceof cloned;
927
- }
928
- });
929
- }
930
- proxyDocument = new Proxy(Object.create(fakeDocumentProto, (_a = {
931
- currentScript: {
932
- value: null,
933
- writable: true
934
- }
935
- },
936
- _a[RAW_NODE] = {
937
- writable: false,
938
- configurable: false,
939
- value: document
940
- },
941
- _a)), {
942
- set: this.createSetter(),
943
- defineProperty: this.createDefineProperty()
944
- });
945
- return {
946
- document: proxyDocument,
947
- Document: fakeDocumentCtor
948
- };
949
- };
950
- return ProxyDocument;
951
- }());
952
-
953
- function documentPatch() {
954
- var proxyDocument = new ProxyDocument();
955
- var _a = proxyDocument.create(), document = _a.document, Document = _a.Document;
956
- return {
957
- rewrite: {
958
- document: document,
959
- Document: Document
960
- }
961
- };
962
- }
963
-
964
- var rawSetTimeout = window.setTimeout;
965
- var rawClearTimeout = window.clearTimeout;
966
- var rawSetInterval = window.setInterval;
967
- var rawClearInterval = window.clearInterval;
968
- function timerPatch() {
969
- var timeout = new Set();
970
- var interval = new Set();
971
- function rewriteSetTimeout(handler, ms) {
972
- var args = [];
973
- for (var _i = 2; _i < arguments.length; _i++) {
974
- args[_i - 2] = arguments[_i];
975
- }
976
- var timeoutId = rawSetTimeout.apply(void 0, __spreadArray([handler, ms], __read(args)));
977
- timeout.add(timeoutId);
978
- return timeoutId;
979
- }
980
- function rewriteClearTimeout(timeoutId) {
981
- timeout.delete(timeoutId);
982
- rawClearTimeout(timeoutId);
983
- }
984
- function rewriteSetInterval(handler, ms) {
985
- var args = [];
986
- for (var _i = 2; _i < arguments.length; _i++) {
987
- args[_i - 2] = arguments[_i];
988
- }
989
- var intervalId = rawSetInterval.apply(void 0, __spreadArray([handler, ms], __read(args)));
990
- interval.add(intervalId);
991
- return intervalId;
992
- }
993
- function rewriteClearInterval(intervalId) {
994
- interval.delete(intervalId);
995
- rawClearInterval(intervalId);
996
- }
997
- return {
998
- rewrite: {
999
- setTimeout: rewriteSetTimeout,
1000
- clearTimeout: rewriteClearTimeout,
1001
- setInterval: rewriteSetInterval,
1002
- clearInterval: rewriteClearInterval
1003
- },
1004
- destroy: function () {
1005
- timeout.forEach(function (timeoutId) {
1006
- rawClearTimeout(timeoutId);
1007
- });
1008
- interval.forEach(function (intervalId) {
1009
- rawClearInterval(intervalId);
1010
- });
1011
- }
1012
- };
1013
- }
1014
-
1015
- var PLANET_STORAGE_PREFIX = '__planet-storage-';
1016
- var RewriteStorage = /** @class */ (function () {
1017
- function RewriteStorage(app, rawStorage) {
1018
- this.rawStorage = rawStorage;
1019
- this.prefix = "" + PLANET_STORAGE_PREFIX + app + "__:";
1020
- }
1021
- Object.defineProperty(RewriteStorage.prototype, "length", {
1022
- get: function () {
1023
- return this.getKeys().length;
1024
- },
1025
- enumerable: false,
1026
- configurable: true
1027
- });
1028
- RewriteStorage.prototype.getKeys = function () {
1029
- var _this = this;
1030
- return Object.keys(this.rawStorage).filter(function (key) { return key.startsWith(_this.prefix); });
1031
- };
1032
- RewriteStorage.prototype.key = function (n) {
1033
- var key = this.getKeys()[n];
1034
- return key ? key.substring(this.prefix.length) : null;
1035
- };
1036
- RewriteStorage.prototype.getItem = function (key) {
1037
- return this.rawStorage.getItem("" + (this.prefix + key));
1038
- };
1039
- RewriteStorage.prototype.setItem = function (key, value) {
1040
- this.rawStorage.setItem("" + (this.prefix + key), value);
1041
- };
1042
- RewriteStorage.prototype.removeItem = function (key) {
1043
- this.rawStorage.removeItem("" + (this.prefix + key));
1044
- };
1045
- RewriteStorage.prototype.clear = function () {
1046
- var _this = this;
1047
- this.getKeys().forEach(function (key) {
1048
- _this.rawStorage.removeItem(key);
1049
- });
1050
- };
1051
- return RewriteStorage;
1052
- }());
1053
- function storagePatch(sandbox) {
1054
- return {
1055
- rewrite: {
1056
- localStorage: new RewriteStorage(sandbox.app, localStorage),
1057
- sessionStorage: new RewriteStorage(sandbox.app, sessionStorage)
1058
- }
1059
- };
1060
- }
1061
-
1062
- var sandboxPatches = [documentPatch, eventListenerPatch, timerPatch, storagePatch];
1063
- function getSandboxPatchHandlers(sandbox) {
1064
- return sandboxPatches.map(function (patch) {
1065
- return patch(sandbox);
1066
- });
1067
- }
1068
-
1069
- function execScript(code, url, global, strictGlobal) {
1070
- var sourceUrl = '//# sourceURL='.concat(url, '\n');
1071
- var window = (0, eval)('window');
1072
- window.tempGlobal = global;
1073
- code = strictGlobal
1074
- ? ';(function(window, self, globalThis){with(window){;'
1075
- .concat(code, '\n')
1076
- .concat(sourceUrl, '}}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);')
1077
- : ';(function(window, self, globalThis){;'
1078
- .concat(code, '\n')
1079
- .concat(sourceUrl, '}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);');
1080
- (0, eval)(code);
1081
- delete window.tempGlobal;
1082
- }
1083
-
1084
- var Sandbox = /** @class */ (function () {
1085
- function Sandbox() {
1086
- }
1087
- Sandbox.prototype.execScript = function (code, url) {
1088
- if (url === void 0) { url = ''; }
1089
- execScript(code, url, this.global, !!this.options.strictGlobal);
1090
- };
1091
- return Sandbox;
1092
- }());
1093
-
1094
- var ProxySandbox = /** @class */ (function (_super) {
1095
- __extends(ProxySandbox, _super);
1096
- function ProxySandbox(app, options) {
1097
- var _this = _super.call(this) || this;
1098
- _this.app = app;
1099
- _this.options = options;
1100
- _this.running = false;
1101
- _this.patchHandlers = [];
1102
- _this.patchHandlers = getSandboxPatchHandlers(_this);
1103
- _this.start();
1104
- return _this;
1105
- }
1106
- ProxySandbox.prototype.start = function () {
1107
- this.running = true;
1108
- this.rewriteVariables = this.getPatchRewriteVariables();
1109
- var proxyWindow = new ProxyWindow(this);
1110
- this.global = proxyWindow.create();
1111
- this.execPatchHandlers();
1112
- };
1113
- ProxySandbox.prototype.destroy = function () {
1114
- this.running = false;
1115
- this.patchHandlers.forEach(function (handler) {
1116
- if (handler.destroy) {
1117
- handler.destroy();
1118
- }
1119
- });
1120
- };
1121
- ProxySandbox.prototype.getPatchRewriteVariables = function () {
1122
- return this.patchHandlers.reduce(function (pre, cur) {
1123
- return __spreadArray(__spreadArray([], __read(pre)), __read((cur.rewrite ? Object.keys(cur.rewrite) : [])));
1124
- }, []);
1125
- };
1126
- ProxySandbox.prototype.execPatchHandlers = function () {
1127
- var _this = this;
1128
- this.patchHandlers.forEach(function (handler) {
1129
- if (handler.rewrite) {
1130
- for (var key in handler.rewrite) {
1131
- if (handler.rewrite[key]) {
1132
- _this.global[key] = handler.rewrite[key];
1133
- }
1134
- }
1135
- }
1136
- if (handler.init) {
1137
- handler === null || handler === void 0 ? void 0 : handler.init();
1138
- }
1139
- });
1140
- };
1141
- return ProxySandbox;
1142
- }(Sandbox));
1143
-
1144
- var SnapshotSandbox = /** @class */ (function (_super) {
1145
- __extends(SnapshotSandbox, _super);
1146
- function SnapshotSandbox(app, options) {
1147
- var _this = _super.call(this) || this;
1148
- _this.app = app;
1149
- _this.options = options;
1150
- _this.start();
1151
- return _this;
1152
- }
1153
- SnapshotSandbox.prototype.start = function () { };
1154
- SnapshotSandbox.prototype.destroy = function () { };
1155
- return SnapshotSandbox;
1156
- }(Sandbox));
1157
-
1158
- var defaultOptions = {
1159
- strictGlobal: false
1160
- };
1161
- function createSandbox(app, options) {
1162
- options = Object.assign({}, defaultOptions, options || {});
1163
- if (window.Proxy) {
1164
- return new ProxySandbox(app, options);
1165
- }
1166
- else {
1167
- return new SnapshotSandbox(app, options);
1168
- }
1169
- }
1170
- function getSandboxInstance() {
1171
- return window[SANDBOX_INSTANCE];
1172
- }
1173
-
1174
- var AssetsLoader = /** @class */ (function () {
1175
- function AssetsLoader(http) {
1176
- this.http = http;
1177
- this.loadedSources = [];
1178
- }
1179
- AssetsLoader.prototype.loadScript = function (src) {
1180
- var _this = this;
1181
- var id = hashCode(src);
1182
- if (this.loadedSources.includes(id)) {
1183
- return rxjs.of({
1184
- src: src,
1185
- hashCode: id,
1186
- loaded: true,
1187
- status: 'Loaded'
1188
- });
1189
- }
1190
- return new rxjs.Observable(function (observer) {
1191
- var script = document.createElement('script');
1192
- script.type = 'text/javascript';
1193
- script.src = src;
1194
- script.async = true;
1195
- if (script['readyState']) {
1196
- // IE
1197
- script['onreadystatechange'] = function () {
1198
- if (script['readyState'] === 'loaded' || script['readyState'] === 'complete') {
1199
- script['onreadystatechange'] = null;
1200
- observer.next({
1201
- src: src,
1202
- hashCode: id,
1203
- loaded: true,
1204
- status: 'Loaded'
1205
- });
1206
- observer.complete();
1207
- _this.loadedSources.push(id);
1208
- }
1209
- };
1210
- }
1211
- else {
1212
- // Others
1213
- script.onload = function () {
1214
- observer.next({
1215
- src: src,
1216
- hashCode: id,
1217
- loaded: true,
1218
- status: 'Loaded'
1219
- });
1220
- observer.complete();
1221
- _this.loadedSources.push(id);
1222
- };
1223
- }
1224
- script.onerror = function (error) {
1225
- observer.error({
1226
- src: src,
1227
- hashCode: id,
1228
- loaded: false,
1229
- status: 'Error',
1230
- error: error
1231
- });
1232
- observer.complete();
1233
- };
1234
- document.body.appendChild(script);
1235
- });
1236
- };
1237
- AssetsLoader.prototype.loadScriptWithSandbox = function (app, src) {
1238
- var _this = this;
1239
- var id = hashCode(src);
1240
- if (this.loadedSources.includes(id)) {
1241
- return rxjs.of({
1242
- src: src,
1243
- hashCode: id,
1244
- loaded: true,
1245
- status: 'Loaded'
1246
- });
1247
- }
1248
- return new rxjs.Observable(function (observer) {
1249
- _this.http.get(src, { responseType: 'text' }).subscribe(function (code) {
1250
- _this.loadedSources.push(id);
1251
- var sandbox = createSandbox(app);
1252
- sandbox.execScript(code, src);
1253
- observer.next({
1254
- src: src,
1255
- hashCode: id,
1256
- loaded: true,
1257
- status: 'Loaded'
1258
- });
1259
- observer.complete();
1260
- }, function (error) {
1261
- observer.error({
1262
- src: src,
1263
- hashCode: id,
1264
- loaded: false,
1265
- status: 'Error',
1266
- error: error
1267
- });
1268
- observer.complete();
1269
- });
1270
- });
1271
- };
1272
- AssetsLoader.prototype.loadStyle = function (src) {
1273
- var _this = this;
1274
- var id = hashCode(src);
1275
- if (this.loadedSources.includes(id)) {
1276
- return rxjs.of({
1277
- src: src,
1278
- hashCode: id,
1279
- loaded: true,
1280
- status: 'Loaded'
1281
- });
1282
- }
1283
- return new rxjs.Observable(function (observer) {
1284
- var head = document.getElementsByTagName('head')[0];
1285
- var link = document.createElement('link');
1286
- link.rel = 'stylesheet';
1287
- link.type = 'text/css';
1288
- link.href = src;
1289
- link.media = 'all';
1290
- link.onload = function () {
1291
- observer.next({
1292
- src: src,
1293
- hashCode: id,
1294
- loaded: true,
1295
- status: 'Loaded'
1296
- });
1297
- observer.complete();
1298
- _this.loadedSources.push(id);
1299
- };
1300
- link.onerror = function (error) {
1301
- observer.error({
1302
- src: src,
1303
- hashCode: id,
1304
- loaded: true,
1305
- status: 'Loaded',
1306
- error: error
1307
- });
1308
- observer.complete();
1309
- };
1310
- head.appendChild(link);
1311
- });
1312
- };
1313
- AssetsLoader.prototype.loadScripts = function (sources, options) {
1314
- var _this = this;
1315
- if (options === void 0) { options = {
1316
- serial: false,
1317
- sandbox: false
1318
- }; }
1319
- if (isEmpty(sources)) {
1320
- return rxjs.of(null);
1321
- }
1322
- var observables = sources.map(function (src) {
1323
- // TODO: 暂时只支持Proxy沙箱
1324
- if (options.sandbox && window.Proxy) {
1325
- return _this.loadScriptWithSandbox(options.app, src);
1326
- }
1327
- else {
1328
- return _this.loadScript(src);
1329
- }
1330
- });
1331
- if (options.serial) {
1332
- var a = rxjs.concat.apply(void 0, __spreadArray([], __read(observables))).pipe(operators.map(function (item) {
1333
- return rxjs.of([item]);
1334
- }), operators.concatAll());
1335
- return a;
1336
- }
1337
- else {
1338
- return rxjs.forkJoin(observables).pipe();
1339
- }
1340
- };
1341
- AssetsLoader.prototype.loadStyles = function (sources) {
1342
- var _this = this;
1343
- if (isEmpty(sources)) {
1344
- return rxjs.of(null);
1345
- }
1346
- return rxjs.forkJoin(sources.map(function (src) {
1347
- return _this.loadStyle(src);
1348
- }));
1349
- };
1350
- AssetsLoader.prototype.loadScriptsAndStyles = function (scripts, styles, options) {
1351
- if (scripts === void 0) { scripts = []; }
1352
- if (styles === void 0) { styles = []; }
1353
- return rxjs.forkJoin([this.loadScripts(scripts, options), this.loadStyles(styles)]);
1354
- };
1355
- AssetsLoader.prototype.loadAppAssets = function (app) {
1356
- var _this = this;
1357
- if (app.manifest) {
1358
- return this.loadManifest(app.manifest + "?t=" + new Date().getTime()).pipe(operators.switchMap(function (manifestResult) {
1359
- var _a = getScriptsAndStylesFullPaths(app, manifestResult), scripts = _a.scripts, styles = _a.styles;
1360
- return _this.loadScriptsAndStyles(scripts, styles, {
1361
- app: app.name,
1362
- sandbox: app.sandbox,
1363
- serial: app.loadSerial
1364
- });
1365
- }));
1366
- }
1367
- else {
1368
- var _a = getScriptsAndStylesFullPaths(app), scripts = _a.scripts, styles = _a.styles;
1369
- return this.loadScriptsAndStyles(scripts, styles, {
1370
- app: app.name,
1371
- sandbox: app.sandbox,
1372
- serial: app.loadSerial
1373
- });
1374
- }
1375
- };
1376
- AssetsLoader.prototype.loadManifest = function (url) {
1377
- return this.http.get(url).pipe(operators.map(function (response) {
1378
- return response;
1379
- }));
1380
- };
1381
- return AssetsLoader;
1382
- }());
1383
- AssetsLoader.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function AssetsLoader_Factory() { return new AssetsLoader(i0__namespace.ɵɵinject(i1__namespace.HttpClient)); }, token: AssetsLoader, providedIn: "root" });
1384
- AssetsLoader.decorators = [
1385
- { type: i0.Injectable, args: [{
1386
- providedIn: 'root'
1387
- },] }
1388
- ];
1389
- AssetsLoader.ctorParameters = function () { return [
1390
- { type: i1.HttpClient }
1391
- ]; };
1392
-
1393
- var PlanetApplicationRef = /** @class */ (function () {
1394
- function PlanetApplicationRef(name, options) {
1395
- this.name = name;
1396
- if (options) {
1397
- this.template = options.template;
1398
- this.innerSelector = this.template ? getTagNameByTemplate(this.template) : '';
1399
- this.appModuleBootstrap = options.bootstrap;
1400
- }
1401
- // This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
1402
- // See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
1403
- i0.NgZone.isInAngularZone = function () {
1404
- // @ts-ignore
1405
- return window.Zone.current._properties["ngx-planet-" + name] === true;
1406
- };
1407
- }
1408
- Object.defineProperty(PlanetApplicationRef.prototype, "selector", {
1409
- get: function () {
1410
- return this.innerSelector;
1411
- },
1412
- enumerable: false,
1413
- configurable: true
1414
- });
1415
- Object.defineProperty(PlanetApplicationRef.prototype, "bootstrapped", {
1416
- get: function () {
1417
- return !!this.appModuleRef;
1418
- },
1419
- enumerable: false,
1420
- configurable: true
1421
- });
1422
- Object.defineProperty(PlanetApplicationRef.prototype, "ngZone", {
1423
- get: function () {
1424
- var _a;
1425
- return (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(i0.NgZone);
1426
- },
1427
- enumerable: false,
1428
- configurable: true
1429
- });
1430
- Object.defineProperty(PlanetApplicationRef.prototype, "sandbox", {
1431
- get: function () {
1432
- return getSandboxInstance();
1433
- },
1434
- enumerable: false,
1435
- configurable: true
1436
- });
1437
- // 子应用路由变化后同步修改 portal 的 Route
1438
- PlanetApplicationRef.prototype.syncPortalRouteWhenNavigationEnd = function () {
1439
- var _this = this;
1440
- var _a;
1441
- var router = (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(i3.Router);
1442
- if (router) {
1443
- router.events.subscribe(function (event) {
1444
- var _a;
1445
- if (event instanceof i3.NavigationEnd) {
1446
- (_a = _this.ngZone) === null || _a === void 0 ? void 0 : _a.onStable.asObservable().pipe(operators.take(1)).subscribe(function () {
1447
- _this.portalApp.router.navigateByUrl(event.url);
1448
- });
1449
- }
1450
- });
1451
- }
1452
- };
1453
- PlanetApplicationRef.prototype.bootstrap = function (app) {
1454
- var _this = this;
1455
- if (!this.appModuleBootstrap) {
1456
- throw new Error("app(" + this.name + ") is not defined");
1457
- }
1458
- this.portalApp = app;
1459
- return rxjs.from(this.appModuleBootstrap(app).then(function (appModuleRef) {
1460
- _this.appModuleRef = appModuleRef;
1461
- _this.appModuleRef.instance.appName = _this.name;
1462
- _this.syncPortalRouteWhenNavigationEnd();
1463
- return _this;
1464
- }));
1465
- };
1466
- PlanetApplicationRef.prototype.getRouter = function () {
1467
- var _a;
1468
- return (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(i3.Router);
1469
- };
1470
- PlanetApplicationRef.prototype.getCurrentRouterStateUrl = function () {
1471
- var _a;
1472
- return (_a = this.getRouter()) === null || _a === void 0 ? void 0 : _a.routerState.snapshot.url;
1473
- };
1474
- PlanetApplicationRef.prototype.navigateByUrl = function (url) {
1475
- var _a;
1476
- var router = this.getRouter();
1477
- (_a = this.ngZone) === null || _a === void 0 ? void 0 : _a.run(function () {
1478
- router === null || router === void 0 ? void 0 : router.navigateByUrl(url);
1479
- });
1480
- };
1481
- PlanetApplicationRef.prototype.getComponentFactory = function () {
1482
- return this.componentFactory;
1483
- };
1484
- PlanetApplicationRef.prototype.registerComponentFactory = function (componentFactory) {
1485
- this.componentFactory = componentFactory;
1486
- };
1487
- PlanetApplicationRef.prototype.destroy = function () {
1488
- if (this.appModuleRef) {
1489
- var router = this.appModuleRef.injector.get(i3.Router);
1490
- if (router) {
1491
- router.dispose();
1492
- }
1493
- if (this.sandbox) {
1494
- this.sandbox.destroy();
1495
- }
1496
- this.appModuleRef.destroy();
1497
- this.appModuleRef = undefined;
1498
- }
1499
- };
1500
- return PlanetApplicationRef;
1501
- }());
1502
-
1503
- var globalPlanet = (window.planet = window.planet || {
1504
- apps: {}
1505
- });
1506
- function defineApplication(name, options) {
1507
- if (globalPlanet.apps[name]) {
1508
- throw new Error(name + " application has exist.");
1509
- }
1510
- if (isFunction(options)) {
1511
- options = {
1512
- template: '',
1513
- bootstrap: options
1514
- };
1515
- }
1516
- var appRef = new PlanetApplicationRef(name, options);
1517
- globalPlanet.apps[name] = appRef;
1518
- }
1519
- function getPlanetApplicationRef(appName) {
1520
- if (globalPlanet && globalPlanet.apps && globalPlanet.apps[appName]) {
1521
- return globalPlanet.apps[appName];
1522
- }
1523
- else {
1524
- return null;
1525
- }
1526
- }
1527
- function setPortalApplicationData(data) {
1528
- if (globalPlanet.portalApplication) {
1529
- globalPlanet.portalApplication.data = data;
1530
- }
1531
- }
1532
- function getPortalApplicationData() {
1533
- var _a;
1534
- return (_a = globalPlanet.portalApplication) === null || _a === void 0 ? void 0 : _a.data;
1535
- }
1536
- function setApplicationLoader(loader) {
1537
- globalPlanet.applicationLoader = loader;
1538
- }
1539
- function getApplicationLoader() {
1540
- return globalPlanet.applicationLoader;
1541
- }
1542
- function setApplicationService(service) {
1543
- globalPlanet.applicationService = service;
1544
- }
1545
- function getApplicationService() {
1546
- return globalPlanet.applicationService;
1547
- }
1548
- function clearGlobalPlanet() {
1549
- window.planet.apps = {};
1550
- window.planet.portalApplication = null;
1551
- window.planet.applicationLoader = null;
1552
- window.planet.applicationService = null;
1553
- }
1554
-
1555
- var PlanetApplicationService = /** @class */ (function () {
1556
- function PlanetApplicationService(http, assetsLoader) {
1557
- this.http = http;
1558
- this.assetsLoader = assetsLoader;
1559
- this.apps = [];
1560
- this.appsMap = {};
1561
- if (getApplicationService()) {
1562
- throw new Error('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
1563
- }
1564
- }
1565
- PlanetApplicationService.prototype.register = function (appOrApps) {
1566
- var _this = this;
1567
- var apps = coerceArray(appOrApps);
1568
- apps.forEach(function (app) {
1569
- if (_this.appsMap[app.name]) {
1570
- throw new Error(app.name + " has be registered.");
1571
- }
1572
- _this.apps.push(app);
1573
- _this.appsMap[app.name] = app;
1574
- });
1575
- };
1576
- PlanetApplicationService.prototype.registerByUrl = function (url) {
1577
- var _this = this;
1578
- var result = this.http.get("" + url).pipe(operators.map(function (apps) {
1579
- if (apps && Array.isArray(apps)) {
1580
- _this.register(apps);
1581
- }
1582
- else {
1583
- _this.register(apps);
1584
- }
1585
- }), operators.shareReplay());
1586
- result.subscribe();
1587
- return result;
1588
- };
1589
- PlanetApplicationService.prototype.unregister = function (name) {
1590
- if (this.appsMap[name]) {
1591
- delete this.appsMap[name];
1592
- this.apps = this.apps.filter(function (app) {
1593
- return app.name !== name;
1594
- });
1595
- }
1596
- };
1597
- PlanetApplicationService.prototype.getAppsByMatchedUrl = function (url) {
1598
- return this.getApps().filter(function (app) {
1599
- if (app.routerPathPrefix instanceof RegExp) {
1600
- return app.routerPathPrefix.test(url);
1601
- }
1602
- else {
1603
- return url.startsWith(app.routerPathPrefix);
1604
- }
1605
- });
1606
- };
1607
- PlanetApplicationService.prototype.getAppByName = function (name) {
1608
- return this.appsMap[name];
1609
- };
1610
- PlanetApplicationService.prototype.getAppsToPreload = function (excludeAppNames) {
1611
- return this.getApps().filter(function (app) {
1612
- if (excludeAppNames) {
1613
- return app.preload && !excludeAppNames.includes(app.name);
1614
- }
1615
- else {
1616
- return app.preload;
1617
- }
1618
- });
1619
- };
1620
- PlanetApplicationService.prototype.getApps = function () {
1621
- return this.apps;
1622
- };
1623
- return PlanetApplicationService;
1624
- }());
1625
- PlanetApplicationService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function PlanetApplicationService_Factory() { return new PlanetApplicationService(i0__namespace.ɵɵinject(i1__namespace.HttpClient), i0__namespace.ɵɵinject(AssetsLoader)); }, token: PlanetApplicationService, providedIn: "root" });
1626
- PlanetApplicationService.decorators = [
1627
- { type: i0.Injectable, args: [{
1628
- providedIn: 'root'
1629
- },] }
1630
- ];
1631
- PlanetApplicationService.ctorParameters = function () { return [
1632
- { type: i1.HttpClient },
1633
- { type: AssetsLoader }
1634
- ]; };
1635
-
1636
- var PlanetPortalApplication = /** @class */ (function () {
1637
- function PlanetPortalApplication() {
1638
- }
1639
- PlanetPortalApplication.prototype.navigateByUrl = function (url, extras) {
1640
- var _this = this;
1641
- return this.ngZone.run(function () {
1642
- return _this.router.navigateByUrl(url, extras);
1643
- });
1644
- };
1645
- PlanetPortalApplication.prototype.run = function (fn) {
1646
- return this.ngZone.run(function () {
1647
- return fn();
1648
- });
1649
- };
1650
- PlanetPortalApplication.prototype.tick = function () {
1651
- this.applicationRef.tick();
1652
- };
1653
- return PlanetPortalApplication;
1654
- }());
1655
-
1656
- var CUSTOM_EVENT_NAME = 'PLANET_GLOBAL_EVENT_DISPATCHER';
1657
- var GlobalEventDispatcher = /** @class */ (function () {
1658
- function GlobalEventDispatcher(ngZone) {
1659
- var _this = this;
1660
- this.ngZone = ngZone;
1661
- this.subject$ = new rxjs.Subject();
1662
- this.hasAddGlobalEventListener = false;
1663
- this.subscriptionCount = 0;
1664
- this.globalEventListener = function (event) {
1665
- _this.subject$.next(event.detail);
1666
- };
1667
- }
1668
- GlobalEventDispatcher.prototype.addGlobalEventListener = function () {
1669
- this.hasAddGlobalEventListener = true;
1670
- window.addEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
1671
- };
1672
- GlobalEventDispatcher.prototype.removeGlobalEventListener = function () {
1673
- this.hasAddGlobalEventListener = false;
1674
- window.removeEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
1675
- };
1676
- GlobalEventDispatcher.prototype.dispatch = function (name, payload) {
1677
- window.dispatchEvent(new CustomEvent(CUSTOM_EVENT_NAME, {
1678
- detail: {
1679
- name: name,
1680
- payload: payload
1681
- }
1682
- }));
1683
- };
1684
- GlobalEventDispatcher.prototype.register = function (eventName) {
1685
- var _this = this;
1686
- return new rxjs.Observable(function (observer) {
1687
- if (!_this.hasAddGlobalEventListener) {
1688
- _this.addGlobalEventListener();
1689
- }
1690
- _this.subscriptionCount++;
1691
- var subscription = _this.subject$
1692
- .pipe(operators.filter(function (event) {
1693
- return event.name === eventName;
1694
- }), operators.map(function (event) {
1695
- return event.payload;
1696
- }))
1697
- .subscribe(function (payload) {
1698
- _this.ngZone.run(function () {
1699
- observer.next(payload);
1700
- });
1701
- });
1702
- return function () {
1703
- _this.subscriptionCount--;
1704
- subscription.unsubscribe();
1705
- if (!_this.subscriptionCount) {
1706
- _this.removeGlobalEventListener();
1707
- }
1708
- };
1709
- });
1710
- };
1711
- GlobalEventDispatcher.prototype.getSubscriptionCount = function () {
1712
- return this.subscriptionCount;
1713
- };
1714
- return GlobalEventDispatcher;
1715
- }());
1716
- GlobalEventDispatcher.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function GlobalEventDispatcher_Factory() { return new GlobalEventDispatcher(i0__namespace.ɵɵinject(i0__namespace.NgZone)); }, token: GlobalEventDispatcher, providedIn: "root" });
1717
- GlobalEventDispatcher.decorators = [
1718
- { type: i0.Injectable, args: [{
1719
- providedIn: 'root'
1720
- },] }
1721
- ];
1722
- GlobalEventDispatcher.ctorParameters = function () { return [
1723
- { type: i0.NgZone }
1724
- ]; };
1725
-
1726
- /**
1727
- * Debug factory for debug module
1728
- */
1729
- var _debugFactory;
1730
- var _debuggerMap = {};
1731
- function createDebug(namespace) {
1732
- var key = "planet:" + namespace;
1733
- return function (formatter) {
1734
- var args = [];
1735
- for (var _i = 1; _i < arguments.length; _i++) {
1736
- args[_i - 1] = arguments[_i];
1737
- }
1738
- if (_debugFactory) {
1739
- var debugDebugger = _debuggerMap[key];
1740
- if (!debugDebugger) {
1741
- debugDebugger = _debugFactory(key);
1742
- _debuggerMap[key] = debugDebugger;
1743
- }
1744
- debugDebugger(formatter, args);
1745
- }
1746
- };
1747
- }
1748
- function setDebugFactory(debug) {
1749
- if (debug && !isFunction(debug)) {
1750
- throw new Error('debug factory type is invalid, must be function');
1751
- }
1752
- _debugFactory = debug;
1753
- }
1754
- function clearDebugFactory() {
1755
- _debugFactory = undefined;
1756
- _debuggerMap = {};
1757
- }
1758
- function getDebugFactory() {
1759
- return _debugFactory;
1760
- }
1761
-
1762
- var debug = createDebug('app-loader');
1763
- exports.ApplicationStatus = void 0;
1764
- (function (ApplicationStatus) {
1765
- ApplicationStatus[ApplicationStatus["assetsLoading"] = 1] = "assetsLoading";
1766
- ApplicationStatus[ApplicationStatus["assetsLoaded"] = 2] = "assetsLoaded";
1767
- ApplicationStatus[ApplicationStatus["bootstrapping"] = 3] = "bootstrapping";
1768
- ApplicationStatus[ApplicationStatus["bootstrapped"] = 4] = "bootstrapped";
1769
- ApplicationStatus[ApplicationStatus["active"] = 5] = "active";
1770
- ApplicationStatus[ApplicationStatus["loadError"] = 10] = "loadError";
1771
- })(exports.ApplicationStatus || (exports.ApplicationStatus = {}));
1772
- var PlanetApplicationLoader = /** @class */ (function () {
1773
- function PlanetApplicationLoader(assetsLoader, planetApplicationService, ngZone, router, injector, applicationRef) {
1774
- this.assetsLoader = assetsLoader;
1775
- this.planetApplicationService = planetApplicationService;
1776
- this.ngZone = ngZone;
1777
- this.firstLoad = true;
1778
- this.inProgressAppAssetsLoads = new Map();
1779
- this.appsStatus = new Map();
1780
- this.portalApp = new PlanetPortalApplication();
1781
- this.routeChange$ = new rxjs.Subject();
1782
- this.appStatusChange$ = new rxjs.Subject();
1783
- this.appsLoadingStart$ = new rxjs.Subject();
1784
- this.loadingDone = false;
1785
- if (getApplicationLoader()) {
1786
- throw new Error('PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed');
1787
- }
1788
- this.options = {
1789
- switchMode: exports.SwitchModes.default,
1790
- errorHandler: function (error) {
1791
- console.error(error);
1792
- }
1793
- };
1794
- this.portalApp.ngZone = ngZone;
1795
- this.portalApp.applicationRef = applicationRef;
1796
- this.portalApp.router = router;
1797
- this.portalApp.injector = injector;
1798
- this.portalApp.globalEventDispatcher = injector.get(GlobalEventDispatcher);
1799
- globalPlanet.portalApplication = this.portalApp;
1800
- this.setupRouteChange();
1801
- }
1802
- Object.defineProperty(PlanetApplicationLoader.prototype, "appStatusChange", {
1803
- get: function () {
1804
- return this.appStatusChange$.asObservable();
1805
- },
1806
- enumerable: false,
1807
- configurable: true
1808
- });
1809
- Object.defineProperty(PlanetApplicationLoader.prototype, "appsLoadingStart", {
1810
- get: function () {
1811
- return this.appsLoadingStart$.asObservable();
1812
- },
1813
- enumerable: false,
1814
- configurable: true
1815
- });
1816
- PlanetApplicationLoader.prototype.setAppStatus = function (app, status) {
1817
- var _this = this;
1818
- this.ngZone.run(function () {
1819
- var fromStatus = _this.appsStatus.get(app);
1820
- debug("app(" + app.name + ") status change: " + (fromStatus ? exports.ApplicationStatus[fromStatus] : 'empty') + " => " + exports.ApplicationStatus[status]);
1821
- _this.appsStatus.set(app, status);
1822
- _this.appStatusChange$.next({
1823
- app: app,
1824
- status: status
1825
- });
1826
- });
1827
- };
1828
- PlanetApplicationLoader.prototype.getAppStatusChange$ = function (app, status) {
1829
- if (status === void 0) { status = exports.ApplicationStatus.bootstrapped; }
1830
- return this.appStatusChange.pipe(operators.filter(function (event) {
1831
- return event.app === app && event.status === status;
1832
- }), operators.map(function () {
1833
- return app;
1834
- }));
1835
- };
1836
- PlanetApplicationLoader.prototype.switchModeIsCoexist = function (app) {
1837
- if (app && app.switchMode) {
1838
- return app.switchMode === exports.SwitchModes.coexist;
1839
- }
1840
- else {
1841
- return this.options.switchMode === exports.SwitchModes.coexist;
1842
- }
1843
- };
1844
- PlanetApplicationLoader.prototype.errorHandler = function (error) {
1845
- var _this = this;
1846
- this.ngZone.run(function () {
1847
- _this.options.errorHandler(error);
1848
- });
1849
- };
1850
- PlanetApplicationLoader.prototype.setLoadingDone = function () {
1851
- var _this = this;
1852
- this.ngZone.run(function () {
1853
- _this.loadingDone = true;
1854
- });
1855
- };
1856
- PlanetApplicationLoader.prototype.getAppNames = function (apps) {
1857
- return apps.length === 0
1858
- ? "[]"
1859
- : apps.map(function (item) {
1860
- return item.name;
1861
- });
1862
- };
1863
- PlanetApplicationLoader.prototype.setupRouteChange = function () {
1864
- var _this = this;
1865
- this.routeChange$
1866
- .pipe(operators.distinctUntilChanged(function (x, y) {
1867
- return (x && x.url) === (y && y.url);
1868
- }),
1869
- // Using switchMap so we cancel executing loading when a new one comes in
1870
- operators.switchMap(function (event) {
1871
- // Return new observable use of and catchError,
1872
- // in order to prevent routeChange$ completed which never trigger new route change
1873
- return rxjs.of(event).pipe(
1874
- // unload apps and return should load apps
1875
- operators.map(function () {
1876
- debug("route change, url is: " + event.url);
1877
- _this.startRouteChangeEvent = event;
1878
- var shouldLoadApps = _this.planetApplicationService.getAppsByMatchedUrl(event.url);
1879
- debug("should load apps: " + _this.getAppNames(shouldLoadApps));
1880
- var shouldUnloadApps = _this.getUnloadApps(shouldLoadApps);
1881
- _this.appsLoadingStart$.next({
1882
- shouldLoadApps: shouldLoadApps,
1883
- shouldUnloadApps: shouldUnloadApps
1884
- });
1885
- _this.unloadApps(shouldUnloadApps, event);
1886
- debug("unload apps: " + _this.getAppNames(shouldUnloadApps));
1887
- return shouldLoadApps;
1888
- }),
1889
- // Load app assets (static resources)
1890
- operators.switchMap(function (shouldLoadApps) {
1891
- var hasAppsNeedLoadingAssets = false;
1892
- var loadApps$ = shouldLoadApps.map(function (app) {
1893
- var appStatus = _this.appsStatus.get(app);
1894
- if (!appStatus ||
1895
- appStatus === exports.ApplicationStatus.assetsLoading ||
1896
- appStatus === exports.ApplicationStatus.loadError) {
1897
- debug("app(" + app.name + ") status is " + exports.ApplicationStatus[appStatus] + ", start load assets");
1898
- hasAppsNeedLoadingAssets = true;
1899
- return _this.ngZone.runOutsideAngular(function () {
1900
- return _this.startLoadAppAssets(app);
1901
- });
1902
- }
1903
- else {
1904
- return rxjs.of(app);
1905
- }
1906
- });
1907
- if (hasAppsNeedLoadingAssets) {
1908
- _this.loadingDone = false;
1909
- }
1910
- return loadApps$.length > 0 ? rxjs.forkJoin(loadApps$) : rxjs.of([]);
1911
- }),
1912
- // Bootstrap or show apps
1913
- operators.map(function (apps) {
1914
- var apps$ = apps.map(function (app) {
1915
- return rxjs.of(app).pipe(operators.switchMap(function (app) {
1916
- var appStatus = _this.appsStatus.get(app);
1917
- if (appStatus === exports.ApplicationStatus.bootstrapped) {
1918
- debug("[routeChange] app(" + app.name + ") status is bootstrapped, show app and active");
1919
- _this.showApp(app);
1920
- var appRef = getPlanetApplicationRef(app.name);
1921
- appRef === null || appRef === void 0 ? void 0 : appRef.navigateByUrl(event.url);
1922
- _this.setAppStatus(app, exports.ApplicationStatus.active);
1923
- _this.setLoadingDone();
1924
- return rxjs.of(app);
1925
- }
1926
- else if (appStatus === exports.ApplicationStatus.assetsLoaded) {
1927
- debug("[routeChange] app(" + app.name + ") status is assetsLoaded, start bootstrapping");
1928
- return _this.bootstrapApp(app).pipe(operators.map(function () {
1929
- debug("app(" + app.name + ") bootstrapped success, active it");
1930
- _this.setAppStatus(app, exports.ApplicationStatus.active);
1931
- _this.setLoadingDone();
1932
- return app;
1933
- }));
1934
- }
1935
- else if (appStatus === exports.ApplicationStatus.active) {
1936
- debug("[routeChange] app(" + app.name + ") is active, do nothings");
1937
- var appRef = getPlanetApplicationRef(app.name);
1938
- // Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
1939
- var currentUrl = (appRef === null || appRef === void 0 ? void 0 : appRef.getCurrentRouterStateUrl)
1940
- ? appRef.getCurrentRouterStateUrl()
1941
- : '';
1942
- if (currentUrl !== event.url) {
1943
- appRef === null || appRef === void 0 ? void 0 : appRef.navigateByUrl(event.url);
1944
- }
1945
- return rxjs.of(app);
1946
- }
1947
- else {
1948
- debug("[routeChange] app(" + app.name + ") status is " + exports.ApplicationStatus[appStatus]);
1949
- return _this.getAppStatusChange$(app).pipe(operators.take(1), operators.map(function () {
1950
- debug("app(" + app.name + ") status is bootstrapped by subscribe status change, active it");
1951
- _this.setAppStatus(app, exports.ApplicationStatus.active);
1952
- _this.showApp(app);
1953
- return app;
1954
- }));
1955
- }
1956
- }));
1957
- });
1958
- if (apps$.length > 0) {
1959
- debug("start load and active apps: " + _this.getAppNames(apps));
1960
- // 切换到应用后会有闪烁现象,所以使用 setTimeout 后启动应用
1961
- // example: redirect to app1's dashboard from portal's about page
1962
- // If app's route has redirect, it doesn't work, it ok just in setTimeout, I don't know why.
1963
- // TODO:: remove it, it is ok in version Angular 9.x
1964
- setTimeout(function () {
1965
- // 此处判断是因为如果静态资源加载完毕还未启动被取消,还是会启动之前的应用,虽然可能性比较小,但是无法排除这种可能性,所以只有当 Event 是最后一个才会启动
1966
- if (_this.startRouteChangeEvent === event) {
1967
- // runOutsideAngular for fix error: `Expected to not be in Angular Zone, but it is!`
1968
- _this.ngZone.runOutsideAngular(function () {
1969
- rxjs.forkJoin(apps$).subscribe(function () {
1970
- _this.setLoadingDone();
1971
- _this.ensurePreloadApps(apps);
1972
- });
1973
- });
1974
- }
1975
- });
1976
- }
1977
- else {
1978
- debug("no apps need to be loaded, ensure preload apps");
1979
- _this.ensurePreloadApps(apps);
1980
- _this.setLoadingDone();
1981
- }
1982
- }),
1983
- // Error handler
1984
- operators.catchError(function (error) {
1985
- debug("apps loader error: " + error);
1986
- _this.errorHandler(error);
1987
- return [];
1988
- }));
1989
- }))
1990
- .subscribe();
1991
- };
1992
- PlanetApplicationLoader.prototype.startLoadAppAssets = function (app) {
1993
- var _this = this;
1994
- if (this.inProgressAppAssetsLoads.get(app.name)) {
1995
- return this.inProgressAppAssetsLoads.get(app.name);
1996
- }
1997
- else {
1998
- var loadApp$ = this.assetsLoader.loadAppAssets(app).pipe(operators.tap(function () {
1999
- _this.inProgressAppAssetsLoads.delete(app.name);
2000
- _this.setAppStatus(app, exports.ApplicationStatus.assetsLoaded);
2001
- }), operators.map(function () {
2002
- return app;
2003
- }), operators.catchError(function (error) {
2004
- _this.inProgressAppAssetsLoads.delete(app.name);
2005
- _this.setAppStatus(app, exports.ApplicationStatus.loadError);
2006
- throw error;
2007
- }), operators.share());
2008
- this.inProgressAppAssetsLoads.set(app.name, loadApp$);
2009
- this.setAppStatus(app, exports.ApplicationStatus.assetsLoading);
2010
- return loadApp$;
2011
- }
2012
- };
2013
- PlanetApplicationLoader.prototype.hideApp = function (planetApp) {
2014
- var appRef = getPlanetApplicationRef(planetApp.name);
2015
- var appRootElement = document.querySelector((appRef === null || appRef === void 0 ? void 0 : appRef.selector) || planetApp.selector);
2016
- if (appRootElement) {
2017
- appRootElement.setAttribute('style', 'display:none;');
2018
- }
2019
- };
2020
- PlanetApplicationLoader.prototype.showApp = function (planetApp) {
2021
- var appRef = getPlanetApplicationRef(planetApp.name);
2022
- var appRootElement = document.querySelector((appRef === null || appRef === void 0 ? void 0 : appRef.selector) || planetApp.selector);
2023
- if (appRootElement) {
2024
- appRootElement.setAttribute('style', '');
2025
- }
2026
- };
2027
- PlanetApplicationLoader.prototype.destroyApp = function (planetApp) {
2028
- var appRef = getPlanetApplicationRef(planetApp.name);
2029
- if (appRef) {
2030
- appRef.destroy();
2031
- }
2032
- var container = getHTMLElement(planetApp.hostParent);
2033
- var appRootElement = container === null || container === void 0 ? void 0 : container.querySelector((appRef && appRef.selector) || planetApp.selector);
2034
- if (appRootElement) {
2035
- container === null || container === void 0 ? void 0 : container.removeChild(appRootElement);
2036
- }
2037
- };
2038
- PlanetApplicationLoader.prototype.bootstrapApp = function (app, defaultStatus) {
2039
- var _a, _b;
2040
- var _this = this;
2041
- if (defaultStatus === void 0) { defaultStatus = 'display'; }
2042
- debug("app(" + app.name + ") start bootstrapping");
2043
- this.setAppStatus(app, exports.ApplicationStatus.bootstrapping);
2044
- var appRef = getPlanetApplicationRef(app.name);
2045
- if (appRef && appRef.bootstrap) {
2046
- var container = getHTMLElement(app.hostParent);
2047
- var appRootElement_1;
2048
- if (container) {
2049
- appRootElement_1 = container.querySelector(appRef.selector || app.selector);
2050
- if (!appRootElement_1) {
2051
- if (appRef.template) {
2052
- appRootElement_1 = createElementByTemplate(appRef.template);
2053
- }
2054
- else {
2055
- appRootElement_1 = document.createElement(app.selector);
2056
- }
2057
- appRootElement_1.setAttribute('style', 'display:none;');
2058
- if (app.hostClass) {
2059
- (_a = appRootElement_1.classList).add.apply(_a, __spreadArray([], __read(coerceArray(app.hostClass))));
2060
- }
2061
- if (app.stylePrefix) {
2062
- (_b = appRootElement_1.classList).add.apply(_b, __spreadArray([], __read(coerceArray(app.stylePrefix))));
2063
- }
2064
- container.appendChild(appRootElement_1);
2065
- }
2066
- }
2067
- var result = appRef.bootstrap(this.portalApp);
2068
- // Backwards compatibility promise for bootstrap
2069
- if (result['then']) {
2070
- result = rxjs.from(result);
2071
- }
2072
- return result.pipe(operators.tap(function () {
2073
- debug("app(" + app.name + ") bootstrapped success for " + defaultStatus);
2074
- _this.setAppStatus(app, exports.ApplicationStatus.bootstrapped);
2075
- if (defaultStatus === 'display' && appRootElement_1) {
2076
- appRootElement_1.removeAttribute('style');
2077
- }
2078
- }), operators.map(function () {
2079
- return appRef;
2080
- }));
2081
- }
2082
- else {
2083
- throw new Error("[" + app.name + "] not found, make sure that the app has the correct name defined use defineApplication(" + app.name + ") and runtimeChunk and vendorChunk are set to true, details see https://github.com/worktile/ngx-planet#throw-error-cannot-read-property-call-of-undefined-at-__webpack_require__-bootstrap79");
2084
- }
2085
- };
2086
- PlanetApplicationLoader.prototype.getUnloadApps = function (activeApps) {
2087
- var unloadApps = [];
2088
- this.appsStatus.forEach(function (value, app) {
2089
- if (value === exports.ApplicationStatus.active && !activeApps.find(function (item) { return item.name === app.name; })) {
2090
- unloadApps.push(app);
2091
- }
2092
- });
2093
- return unloadApps;
2094
- };
2095
- PlanetApplicationLoader.prototype.unloadApps = function (shouldUnloadApps, event) {
2096
- var _this = this;
2097
- var hideApps = [];
2098
- var destroyApps = [];
2099
- shouldUnloadApps.forEach(function (app) {
2100
- if (_this.switchModeIsCoexist(app)) {
2101
- debug("hide app(" + app.name + ") for coexist mode");
2102
- hideApps.push(app);
2103
- _this.hideApp(app);
2104
- _this.setAppStatus(app, exports.ApplicationStatus.bootstrapped);
2105
- }
2106
- else {
2107
- destroyApps.push(app);
2108
- // 销毁之前先隐藏,否则会出现闪烁,因为 destroy 是延迟执行的
2109
- // 如果销毁不延迟执行,会出现切换到主应用的时候会有视图卡顿现象
2110
- _this.hideApp(app);
2111
- _this.setAppStatus(app, exports.ApplicationStatus.assetsLoaded);
2112
- }
2113
- });
2114
- if (hideApps.length > 0 || destroyApps.length > 0) {
2115
- // 从其他应用切换到主应用的时候会有视图卡顿现象,所以先等主应用渲染完毕后再加载其他应用
2116
- // 此处尝试使用 this.ngZone.onStable.pipe(take(1)) 应用之间的切换会出现闪烁
2117
- setTimeout(function () {
2118
- hideApps.forEach(function (app) {
2119
- var appRef = getPlanetApplicationRef(app.name);
2120
- if (appRef) {
2121
- appRef.navigateByUrl(event.url);
2122
- }
2123
- });
2124
- destroyApps.forEach(function (app) {
2125
- debug("destroy app(" + app.name + ")");
2126
- _this.destroyApp(app);
2127
- });
2128
- });
2129
- }
2130
- };
2131
- PlanetApplicationLoader.prototype.preloadApps = function (activeApps) {
2132
- var _this = this;
2133
- setTimeout(function () {
2134
- var toPreloadApps = _this.planetApplicationService.getAppsToPreload(activeApps ? activeApps.map(function (item) { return item.name; }) : undefined);
2135
- debug("start preload apps: " + _this.getAppNames(toPreloadApps));
2136
- var loadApps$ = toPreloadApps.map(function (preloadApp) {
2137
- return _this.preloadInternal(preloadApp);
2138
- });
2139
- rxjs.forkJoin(loadApps$).subscribe({
2140
- error: function (error) {
2141
- _this.errorHandler(error);
2142
- }
2143
- });
2144
- });
2145
- };
2146
- PlanetApplicationLoader.prototype.ensurePreloadApps = function (activeApps) {
2147
- // Start preload apps
2148
- // Start preload when first time app loaded
2149
- if (this.firstLoad) {
2150
- this.preloadApps(activeApps);
2151
- this.firstLoad = false;
2152
- }
2153
- };
2154
- PlanetApplicationLoader.prototype.setOptions = function (options) {
2155
- this.options = Object.assign(Object.assign({}, this.options), options);
2156
- };
2157
- /**
2158
- * reset route by current router
2159
- */
2160
- PlanetApplicationLoader.prototype.reroute = function (event) {
2161
- this.routeChange$.next(event);
2162
- };
2163
- PlanetApplicationLoader.prototype.preloadInternal = function (app, immediate) {
2164
- var _this = this;
2165
- var status = this.appsStatus.get(app);
2166
- if (!status || status === exports.ApplicationStatus.loadError) {
2167
- debug("preload app(" + app.name + "), status is empty, start to load assets");
2168
- return this.startLoadAppAssets(app).pipe(operators.switchMap(function () {
2169
- debug("preload app(" + app.name + "), assets loaded, start bootstrap app, immediate: " + !!immediate);
2170
- if (immediate) {
2171
- return _this.bootstrapApp(app, 'hidden');
2172
- }
2173
- else {
2174
- return _this.ngZone.runOutsideAngular(function () {
2175
- return _this.bootstrapApp(app, 'hidden');
2176
- });
2177
- }
2178
- }), operators.catchError(function (error) {
2179
- _this.errorHandler(error);
2180
- return rxjs.of(null);
2181
- }), operators.map(function () {
2182
- return getPlanetApplicationRef(app.name);
2183
- }));
2184
- }
2185
- else if ([exports.ApplicationStatus.assetsLoading, exports.ApplicationStatus.assetsLoaded, exports.ApplicationStatus.bootstrapping].includes(status)) {
2186
- debug("preload app(" + app.name + "), status is " + exports.ApplicationStatus[status] + ", return until bootstrapped");
2187
- return this.getAppStatusChange$(app).pipe(operators.take(1), operators.map(function () {
2188
- return getPlanetApplicationRef(app.name);
2189
- }));
2190
- }
2191
- else {
2192
- var appRef = getPlanetApplicationRef(app.name);
2193
- if (!appRef) {
2194
- throw new Error(app.name + "'s status is " + exports.ApplicationStatus[status] + ", planetApplicationRef is null.");
2195
- }
2196
- return rxjs.of(appRef);
2197
- }
2198
- };
2199
- /**
2200
- * Preload planet application
2201
- * @param app app
2202
- * @param immediate bootstrap on stable by default, setting immediate is true, it will bootstrap immediate
2203
- */
2204
- PlanetApplicationLoader.prototype.preload = function (app, immediate) {
2205
- return this.preloadInternal(app, immediate);
2206
- };
2207
- return PlanetApplicationLoader;
2208
- }());
2209
- PlanetApplicationLoader.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function PlanetApplicationLoader_Factory() { return new PlanetApplicationLoader(i0__namespace.ɵɵinject(AssetsLoader), i0__namespace.ɵɵinject(PlanetApplicationService), i0__namespace.ɵɵinject(i0__namespace.NgZone), i0__namespace.ɵɵinject(i3__namespace.Router), i0__namespace.ɵɵinject(i0__namespace.INJECTOR), i0__namespace.ɵɵinject(i0__namespace.ApplicationRef)); }, token: PlanetApplicationLoader, providedIn: "root" });
2210
- PlanetApplicationLoader.decorators = [
2211
- { type: i0.Injectable, args: [{
2212
- providedIn: 'root'
2213
- },] }
2214
- ];
2215
- PlanetApplicationLoader.ctorParameters = function () { return [
2216
- { type: AssetsLoader },
2217
- { type: PlanetApplicationService },
2218
- { type: i0.NgZone },
2219
- { type: i3.Router },
2220
- { type: i0.Injector },
2221
- { type: i0.ApplicationRef }
2222
- ]; };
2223
-
2224
- var Planet = /** @class */ (function () {
2225
- function Planet(injector, router, planetApplications) {
2226
- this.injector = injector;
2227
- this.router = router;
2228
- if (!this.planetApplicationLoader) {
2229
- setApplicationLoader(this.injector.get(PlanetApplicationLoader));
2230
- }
2231
- if (!this.planetApplicationService) {
2232
- setApplicationService(this.injector.get(PlanetApplicationService));
2233
- }
2234
- if (planetApplications) {
2235
- this.registerApps(planetApplications);
2236
- }
2237
- }
2238
- Object.defineProperty(Planet.prototype, "planetApplicationLoader", {
2239
- get: function () {
2240
- return getApplicationLoader();
2241
- },
2242
- enumerable: false,
2243
- configurable: true
2244
- });
2245
- Object.defineProperty(Planet.prototype, "planetApplicationService", {
2246
- get: function () {
2247
- return getApplicationService();
2248
- },
2249
- enumerable: false,
2250
- configurable: true
2251
- });
2252
- Object.defineProperty(Planet.prototype, "loadingDone", {
2253
- get: function () {
2254
- return this.planetApplicationLoader.loadingDone;
2255
- },
2256
- enumerable: false,
2257
- configurable: true
2258
- });
2259
- Object.defineProperty(Planet.prototype, "appStatusChange", {
2260
- get: function () {
2261
- return this.planetApplicationLoader.appStatusChange;
2262
- },
2263
- enumerable: false,
2264
- configurable: true
2265
- });
2266
- Object.defineProperty(Planet.prototype, "appsLoadingStart", {
2267
- get: function () {
2268
- return this.planetApplicationLoader.appsLoadingStart;
2269
- },
2270
- enumerable: false,
2271
- configurable: true
2272
- });
2273
- Planet.prototype.setOptions = function (options) {
2274
- this.planetApplicationLoader.setOptions(options);
2275
- if (options.debugFactory) {
2276
- setDebugFactory(options.debugFactory);
2277
- }
2278
- };
2279
- Planet.prototype.setPortalAppData = function (data) {
2280
- setPortalApplicationData(data);
2281
- };
2282
- Planet.prototype.registerApp = function (app) {
2283
- this.planetApplicationService.register(app);
2284
- };
2285
- Planet.prototype.registerApps = function (apps) {
2286
- this.planetApplicationService.register(apps);
2287
- };
2288
- Planet.prototype.unregisterApp = function (name) {
2289
- this.planetApplicationService.unregister(name);
2290
- };
2291
- Planet.prototype.getApps = function () {
2292
- return this.planetApplicationService.getApps();
2293
- };
2294
- Planet.prototype.start = function () {
2295
- var _this = this;
2296
- this.subscription = this.router.events
2297
- .pipe(operators.filter(function (event) {
2298
- return event instanceof i3.NavigationEnd;
2299
- }), operators.map(function (event) {
2300
- return event.urlAfterRedirects || event.url;
2301
- }), operators.startWith(location.pathname), operators.distinctUntilChanged())
2302
- .subscribe(function (url) {
2303
- _this.planetApplicationLoader.reroute({
2304
- url: url
2305
- });
2306
- });
2307
- };
2308
- Planet.prototype.stop = function () {
2309
- var _a;
2310
- (_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
2311
- };
2312
- return Planet;
2313
- }());
2314
- Planet.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function Planet_Factory() { return new Planet(i0__namespace.ɵɵinject(i0__namespace.INJECTOR), i0__namespace.ɵɵinject(i3__namespace.Router), i0__namespace.ɵɵinject(PLANET_APPLICATIONS, 8)); }, token: Planet, providedIn: "root" });
2315
- Planet.decorators = [
2316
- { type: i0.Injectable, args: [{
2317
- providedIn: 'root'
2318
- },] }
2319
- ];
2320
- Planet.ctorParameters = function () { return [
2321
- { type: i0.Injector },
2322
- { type: i3.Router },
2323
- { type: Array, decorators: [{ type: i0.Inject, args: [PLANET_APPLICATIONS,] }, { type: i0.Optional }] }
2324
- ]; };
2325
-
2326
- var EmptyComponent = /** @class */ (function () {
2327
- function EmptyComponent() {
2328
- }
2329
- return EmptyComponent;
2330
- }());
2331
- EmptyComponent.decorators = [
2332
- { type: i0.Component, args: [{
2333
- selector: 'empty-component',
2334
- template: ""
2335
- },] }
2336
- ];
2337
-
2338
- var NgxPlanetModule = /** @class */ (function () {
2339
- function NgxPlanetModule() {
2340
- }
2341
- NgxPlanetModule.forRoot = function (apps) {
2342
- return {
2343
- ngModule: NgxPlanetModule,
2344
- providers: [
2345
- {
2346
- provide: PLANET_APPLICATIONS,
2347
- useValue: apps
2348
- }
2349
- ]
2350
- };
2351
- };
2352
- return NgxPlanetModule;
2353
- }());
2354
- NgxPlanetModule.decorators = [
2355
- { type: i0.NgModule, args: [{
2356
- declarations: [EmptyComponent],
2357
- entryComponents: [EmptyComponent],
2358
- imports: [i1.HttpClientModule],
2359
- providers: [],
2360
- exports: [i1.HttpClientModule, EmptyComponent]
2361
- },] }
2362
- ];
2363
-
2364
- var PlanetComponentRef = /** @class */ (function () {
2365
- function PlanetComponentRef() {
2366
- }
2367
- return PlanetComponentRef;
2368
- }());
2369
-
2370
- var componentWrapperClass = 'planet-component-wrapper';
2371
- var PlanetComponentLoader = /** @class */ (function () {
2372
- function PlanetComponentLoader(applicationRef, ngModuleRef, ngZone, document) {
2373
- this.applicationRef = applicationRef;
2374
- this.ngModuleRef = ngModuleRef;
2375
- this.ngZone = ngZone;
2376
- this.document = document;
2377
- this.domPortalOutletCache = new WeakMap();
2378
- }
2379
- Object.defineProperty(PlanetComponentLoader.prototype, "applicationLoader", {
2380
- get: function () {
2381
- return getApplicationLoader();
2382
- },
2383
- enumerable: false,
2384
- configurable: true
2385
- });
2386
- Object.defineProperty(PlanetComponentLoader.prototype, "applicationService", {
2387
- get: function () {
2388
- return getApplicationService();
2389
- },
2390
- enumerable: false,
2391
- configurable: true
2392
- });
2393
- PlanetComponentLoader.prototype.getPlantAppRef = function (name) {
2394
- if (globalPlanet.apps[name] && globalPlanet.apps[name].appModuleRef) {
2395
- return rxjs.of(globalPlanet.apps[name]);
2396
- }
2397
- else {
2398
- var app = this.applicationService.getAppByName(name);
2399
- return this.applicationLoader.preload(app, true).pipe(operators.map(function () {
2400
- return globalPlanet.apps[name];
2401
- }));
2402
- }
2403
- };
2404
- PlanetComponentLoader.prototype.createInjector = function (appModuleRef, componentRef) {
2405
- var injectionTokens = new WeakMap([[PlanetComponentRef, componentRef]]);
2406
- var defaultInjector = appModuleRef.injector;
2407
- return new portal.PortalInjector(defaultInjector, injectionTokens);
2408
- };
2409
- PlanetComponentLoader.prototype.getContainerElement = function (config) {
2410
- if (!config.container) {
2411
- throw new Error("config 'container' cannot be null");
2412
- }
2413
- else {
2414
- if (config.container.nativeElement) {
2415
- return config.container.nativeElement;
2416
- }
2417
- else {
2418
- return config.container;
2419
- }
2420
- }
2421
- };
2422
- PlanetComponentLoader.prototype.createWrapperElement = function (config) {
2423
- var container = this.getContainerElement(config);
2424
- var element = this.document.createElement('div');
2425
- var subApp = this.applicationService.getAppByName(this.ngModuleRef.instance.appName);
2426
- element.classList.add(componentWrapperClass);
2427
- element.setAttribute('planet-inline', '');
2428
- if (config.wrapperClass) {
2429
- element.classList.add(config.wrapperClass);
2430
- }
2431
- if (subApp && subApp.stylePrefix) {
2432
- element.classList.add(subApp.stylePrefix);
2433
- }
2434
- container.appendChild(element);
2435
- return element;
2436
- };
2437
- PlanetComponentLoader.prototype.attachComponent = function (plantComponent, appModuleRef, config) {
2438
- var _this = this;
2439
- var plantComponentRef = new PlanetComponentRef();
2440
- var componentFactoryResolver = appModuleRef.componentFactoryResolver;
2441
- var appRef = this.applicationRef;
2442
- var injector = this.createInjector(appModuleRef, plantComponentRef);
2443
- var wrapper = this.createWrapperElement(config);
2444
- var portalOutlet = this.domPortalOutletCache.get(wrapper);
2445
- if (portalOutlet) {
2446
- portalOutlet.detach();
2447
- }
2448
- else {
2449
- portalOutlet = new portal.DomPortalOutlet(wrapper, componentFactoryResolver, appRef, injector);
2450
- this.domPortalOutletCache.set(wrapper, portalOutlet);
2451
- }
2452
- var componentPortal = new portal.ComponentPortal(plantComponent.component, null);
2453
- var componentRef = portalOutlet.attachComponentPortal(componentPortal);
2454
- if (config.initialState) {
2455
- Object.assign(componentRef.instance, config.initialState);
2456
- }
2457
- plantComponentRef.componentInstance = componentRef.instance;
2458
- plantComponentRef.componentRef = componentRef;
2459
- plantComponentRef.wrapperElement = wrapper;
2460
- plantComponentRef.dispose = function () {
2461
- _this.domPortalOutletCache.delete(wrapper);
2462
- portalOutlet.dispose();
2463
- };
2464
- return plantComponentRef;
2465
- };
2466
- PlanetComponentLoader.prototype.registerComponentFactory = function (componentOrComponents) {
2467
- var _this = this;
2468
- var app = this.ngModuleRef.instance.appName;
2469
- this.getPlantAppRef(app).subscribe(function (appRef) {
2470
- appRef.registerComponentFactory(function (componentName, config) {
2471
- var components = coerceArray(componentOrComponents);
2472
- var component = components.find(function (item) { return item.name === componentName; });
2473
- if (component) {
2474
- return _this.ngZone.run(function () {
2475
- var componentRef = _this.attachComponent(component, appRef.appModuleRef, config);
2476
- return componentRef;
2477
- });
2478
- }
2479
- else {
2480
- throw Error("unregistered component " + componentName + " in app " + app);
2481
- }
2482
- });
2483
- });
2484
- };
2485
- PlanetComponentLoader.prototype.register = function (components) {
2486
- var _this = this;
2487
- setTimeout(function () {
2488
- _this.registerComponentFactory(components);
2489
- });
2490
- };
2491
- PlanetComponentLoader.prototype.load = function (app, componentName, config) {
2492
- var result = this.getPlantAppRef(app).pipe(operators.delayWhen(function (appRef) {
2493
- if (appRef.getComponentFactory()) {
2494
- return rxjs.of('');
2495
- }
2496
- else {
2497
- // Because register use 'setTimeout',so timer 20
2498
- return rxjs.timer(20);
2499
- }
2500
- }), operators.map(function (appRef) {
2501
- var componentFactory = appRef.getComponentFactory();
2502
- if (componentFactory) {
2503
- return componentFactory(componentName, config);
2504
- }
2505
- else {
2506
- throw new Error(app + "'s component(" + componentName + ") is not registered");
2507
- }
2508
- }), operators.shareReplay());
2509
- result.subscribe();
2510
- return result;
2511
- };
2512
- return PlanetComponentLoader;
2513
- }());
2514
- PlanetComponentLoader.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function PlanetComponentLoader_Factory() { return new PlanetComponentLoader(i0__namespace.ɵɵinject(i0__namespace.ApplicationRef), i0__namespace.ɵɵinject(i0__namespace.NgModuleRef), i0__namespace.ɵɵinject(i0__namespace.NgZone), i0__namespace.ɵɵinject(i1__namespace$1.DOCUMENT)); }, token: PlanetComponentLoader, providedIn: "root" });
2515
- PlanetComponentLoader.decorators = [
2516
- { type: i0.Injectable, args: [{
2517
- providedIn: 'root'
2518
- },] }
2519
- ];
2520
- PlanetComponentLoader.ctorParameters = function () { return [
2521
- { type: i0.ApplicationRef },
2522
- { type: i0.NgModuleRef },
2523
- { type: i0.NgZone },
2524
- { type: undefined, decorators: [{ type: i0.Inject, args: [i1$1.DOCUMENT,] }] }
2525
- ]; };
2526
-
2527
- var PlantComponentConfig = /** @class */ (function () {
2528
- function PlantComponentConfig() {
2529
- /** Data being injected into the child component. */
2530
- this.initialState = null;
2531
- }
2532
- return PlantComponentConfig;
2533
- }());
2534
-
2535
- /*
2536
- * Public API Surface of core
2537
- */
2538
-
2539
- /**
2540
- * Generated bundle index. Do not edit.
2541
- */
2542
-
2543
- exports.AssetsLoader = AssetsLoader;
2544
- exports.EmptyComponent = EmptyComponent;
2545
- exports.GlobalEventDispatcher = GlobalEventDispatcher;
2546
- exports.NgxPlanetModule = NgxPlanetModule;
2547
- exports.PLANET_APPLICATIONS = PLANET_APPLICATIONS;
2548
- exports.Planet = Planet;
2549
- exports.PlanetApplicationLoader = PlanetApplicationLoader;
2550
- exports.PlanetApplicationRef = PlanetApplicationRef;
2551
- exports.PlanetApplicationService = PlanetApplicationService;
2552
- exports.PlanetComponentLoader = PlanetComponentLoader;
2553
- exports.PlanetComponentRef = PlanetComponentRef;
2554
- exports.PlanetPortalApplication = PlanetPortalApplication;
2555
- exports.PlantComponentConfig = PlantComponentConfig;
2556
- exports.defineApplication = defineApplication;
2557
- exports.getPlanetApplicationRef = getPlanetApplicationRef;
2558
- exports.getPortalApplicationData = getPortalApplicationData;
2559
- exports.ɵa = globalPlanet;
2560
-
2561
- Object.defineProperty(exports, '__esModule', { value: true });
2562
-
2563
- })));
2564
- //# sourceMappingURL=worktile-planet.umd.js.map