@worktile/planet 11.0.0 → 12.1.2
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.
- package/application/planet-application-loader.d.ts.map +1 -1
- package/application/planet-application-loader.ngfactory.d.ts.map +1 -0
- package/application/planet-application-ref.d.ts +13 -10
- package/application/planet-application-ref.d.ts.map +1 -1
- package/application/planet-application.service.d.ts +1 -1
- package/application/planet-application.service.d.ts.map +1 -1
- package/application/planet-application.service.ngfactory.d.ts.map +1 -0
- package/application/portal-application.d.ts +6 -6
- package/application/portal-application.d.ts.map +1 -1
- package/assets-loader.d.ts +11 -2
- package/assets-loader.d.ts.map +1 -1
- package/assets-loader.ngfactory.d.ts.map +1 -0
- package/bundles/worktile-planet.umd.js +851 -58
- package/bundles/worktile-planet.umd.js.map +1 -1
- package/component/planet-component-loader.d.ts.map +1 -1
- package/component/planet-component-loader.ngfactory.d.ts.map +1 -0
- package/empty/empty.component.ngfactory.d.ts.map +1 -0
- package/esm2015/application/planet-application-loader.js +15 -10
- package/esm2015/application/planet-application-ref.js +29 -18
- package/esm2015/application/planet-application.service.js +1 -1
- package/esm2015/application/portal-application.js +1 -1
- package/esm2015/assets-loader.js +60 -8
- package/esm2015/component/planet-component-loader.js +3 -5
- package/esm2015/debug.js +2 -2
- package/esm2015/global-planet.js +6 -3
- package/esm2015/helpers.js +6 -3
- package/esm2015/planet.class.js +1 -1
- package/esm2015/planet.js +4 -3
- package/esm2015/sandbox/constants.js +7 -0
- package/esm2015/sandbox/exec.js +15 -0
- package/esm2015/sandbox/index.js +20 -0
- package/esm2015/sandbox/proxy/patches/document.js +12 -0
- package/esm2015/sandbox/proxy/patches/eventListener.js +41 -0
- package/esm2015/sandbox/proxy/patches/index.js +11 -0
- package/esm2015/sandbox/proxy/patches/storage.js +40 -0
- package/esm2015/sandbox/proxy/patches/timer.js +43 -0
- package/esm2015/sandbox/proxy/proxies/common.js +132 -0
- package/esm2015/sandbox/proxy/proxies/document.js +126 -0
- package/esm2015/sandbox/proxy/proxies/window.js +155 -0
- package/esm2015/sandbox/proxy/proxy-sandbox.js +49 -0
- package/esm2015/sandbox/proxy/types.js +2 -0
- package/esm2015/sandbox/sandbox.js +7 -0
- package/esm2015/sandbox/snapshot/snapshot-sandbox.js +12 -0
- package/esm2015/sandbox/types.js +2 -0
- package/fesm2015/worktile-planet.js +763 -45
- package/fesm2015/worktile-planet.js.map +1 -1
- package/global-event-dispatcher.ngfactory.d.ts.map +1 -0
- package/global-planet.d.ts +3 -3
- package/global-planet.d.ts.map +1 -1
- package/helpers.d.ts +3 -2
- package/helpers.d.ts.map +1 -1
- package/module.ngfactory.d.ts.map +1 -0
- package/package.json +5 -5
- package/planet.class.d.ts +1 -0
- package/planet.class.d.ts.map +1 -1
- package/planet.d.ts +1 -1
- package/planet.d.ts.map +1 -1
- package/planet.ngfactory.d.ts.map +1 -0
- package/sandbox/constants.d.ts +7 -0
- package/sandbox/constants.d.ts.map +1 -0
- package/sandbox/exec.d.ts +3 -0
- package/sandbox/exec.d.ts.map +1 -0
- package/sandbox/index.d.ts +7 -0
- package/sandbox/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/document.d.ts +3 -0
- package/sandbox/proxy/patches/document.d.ts.map +1 -0
- package/sandbox/proxy/patches/eventListener.d.ts +3 -0
- package/sandbox/proxy/patches/eventListener.d.ts.map +1 -0
- package/sandbox/proxy/patches/index.d.ts +3 -0
- package/sandbox/proxy/patches/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/storage.d.ts +15 -0
- package/sandbox/proxy/patches/storage.d.ts.map +1 -0
- package/sandbox/proxy/patches/timer.d.ts +3 -0
- package/sandbox/proxy/patches/timer.d.ts.map +1 -0
- package/sandbox/proxy/proxies/common.d.ts +13 -0
- package/sandbox/proxy/proxies/common.d.ts.map +1 -0
- package/sandbox/proxy/proxies/document.d.ts +14 -0
- package/sandbox/proxy/proxies/document.d.ts.map +1 -0
- package/sandbox/proxy/proxies/window.d.ts +13 -0
- package/sandbox/proxy/proxies/window.d.ts.map +1 -0
- package/sandbox/proxy/proxy-sandbox.d.ts +16 -0
- package/sandbox/proxy/proxy-sandbox.d.ts.map +1 -0
- package/sandbox/proxy/types.d.ts +14 -0
- package/sandbox/proxy/types.d.ts.map +1 -0
- package/sandbox/sandbox.d.ts +12 -0
- package/sandbox/sandbox.d.ts.map +1 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts +9 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts.map +1 -0
- package/sandbox/types.d.ts +2 -0
- package/sandbox/types.d.ts.map +1 -0
- package/worktile-planet.metadata.json +1 -1
- package/bundles/worktile-planet.umd.min.js +0 -16
- package/bundles/worktile-planet.umd.min.js.map +0 -1
|
@@ -4,8 +4,8 @@ import * as i3 from '@angular/router';
|
|
|
4
4
|
import { Router, NavigationEnd } from '@angular/router';
|
|
5
5
|
import * as i1 from '@angular/common/http';
|
|
6
6
|
import { HttpClient, HttpClientModule } from '@angular/common/http';
|
|
7
|
-
import { map, concatAll, switchMap, take, shareReplay, filter, distinctUntilChanged, catchError, tap, share, startWith, delayWhen
|
|
8
|
-
import {
|
|
7
|
+
import { map, concatAll, switchMap, take, shareReplay, filter, distinctUntilChanged, catchError, tap, share, startWith, delayWhen } from 'rxjs/operators';
|
|
8
|
+
import { Observable, of, concat, forkJoin, from, Subject, timer } from 'rxjs';
|
|
9
9
|
import { PortalInjector, DomPortalOutlet, ComponentPortal } from '@angular/cdk/portal';
|
|
10
10
|
import * as i1$1 from '@angular/common';
|
|
11
11
|
import { DOCUMENT } from '@angular/common';
|
|
@@ -41,14 +41,14 @@ function getHTMLElement(selector) {
|
|
|
41
41
|
}
|
|
42
42
|
function getTagNameByTemplate(template) {
|
|
43
43
|
const element = createElementByTemplate(template);
|
|
44
|
-
return element ? element.nodeName :
|
|
44
|
+
return element ? element.nodeName : '';
|
|
45
45
|
}
|
|
46
46
|
function createElementByTemplate(template) {
|
|
47
47
|
if (!template) {
|
|
48
48
|
return null;
|
|
49
49
|
}
|
|
50
50
|
const element = document.createRange().createContextualFragment(template).firstChild;
|
|
51
|
-
if (element.nodeType === ELEMENT_NODE_TYPE) {
|
|
51
|
+
if (element && element.nodeType === ELEMENT_NODE_TYPE) {
|
|
52
52
|
return element;
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
@@ -70,6 +70,9 @@ function isFunction(value) {
|
|
|
70
70
|
const type = typeof value;
|
|
71
71
|
return !!value && type === 'function';
|
|
72
72
|
}
|
|
73
|
+
function isObject(val) {
|
|
74
|
+
return val && typeof val === 'object';
|
|
75
|
+
}
|
|
73
76
|
/**
|
|
74
77
|
* Get file name from path
|
|
75
78
|
* 1. "main.js" => "main.js"
|
|
@@ -133,6 +136,653 @@ function getScriptsAndStylesFullPaths(app, manifestResult) {
|
|
|
133
136
|
};
|
|
134
137
|
}
|
|
135
138
|
|
|
139
|
+
const PLANET_SANDBOX_WINDOW_WHITELIST = window['___PLANET_SANDBOX_WINDOW_WHITELIST___'];
|
|
140
|
+
const PLANET_SANDBOX_DOCUMENT_WHITELIST = window['___PLANET_SANDBOX_DOCUMENT_WHITELIST___'];
|
|
141
|
+
const SANDBOX_INSTANCE = Symbol.for('PLANET_SANDBOX_INSTANCE');
|
|
142
|
+
const RAW_NODE = Symbol.for('PLANET_RAW_NODE');
|
|
143
|
+
const WINDOW_BIND_FN = Symbol.for('PLANET_WINDOW_BIND_FN');
|
|
144
|
+
const DOCUMENT_BIND_FN = Symbol.for('PLANET_DOCUMENT_BIND_FN');
|
|
145
|
+
|
|
146
|
+
const rawHasOwnProperty = Object.prototype.hasOwnProperty;
|
|
147
|
+
function hasOwnProp(obj, key) {
|
|
148
|
+
return rawHasOwnProperty.call(obj, key);
|
|
149
|
+
}
|
|
150
|
+
function isValueDescriptor(desc) {
|
|
151
|
+
if (desc === undefined) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
return 'value' in desc || 'writable' in desc;
|
|
155
|
+
}
|
|
156
|
+
function isAccessorDescriptor(desc) {
|
|
157
|
+
if (desc === undefined) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
return 'get' in desc || 'set' in desc;
|
|
161
|
+
}
|
|
162
|
+
function isNonWriteableValue(desc) {
|
|
163
|
+
return desc && desc.configurable === false && 'value' in desc && desc.writable === false;
|
|
164
|
+
}
|
|
165
|
+
function isInvalidSetAccessor(desc) {
|
|
166
|
+
if (desc && desc.configurable === false && 'set' in desc && desc.set === undefined) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function isInvalidGetAccessor(desc) {
|
|
174
|
+
if (desc && desc.configurable === false && 'get' in desc && desc.get === undefined) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function transferParams(args) {
|
|
182
|
+
args = Array.isArray(args) ? args : Array.from(args);
|
|
183
|
+
return args.map(arg => {
|
|
184
|
+
return arg[RAW_NODE] ? arg[RAW_NODE] : arg;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const buildInProps = ['length', 'caller', 'callee', 'arguments', 'prototype', Symbol.hasInstance];
|
|
188
|
+
function transferProps(o, n) {
|
|
189
|
+
for (const key of Reflect.ownKeys(o)) {
|
|
190
|
+
if (buildInProps.includes(key)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
const desc = Object.getOwnPropertyDescriptor(n, key);
|
|
194
|
+
if (desc && desc.writable) {
|
|
195
|
+
n[key] = o[key];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function bind(fn, context) {
|
|
200
|
+
const fNOP = function () { };
|
|
201
|
+
function bound() {
|
|
202
|
+
const args = transferParams(arguments);
|
|
203
|
+
if (this instanceof bound) {
|
|
204
|
+
const obj = new fn(...args);
|
|
205
|
+
Object.setPrototypeOf(obj, bound.prototype);
|
|
206
|
+
return obj;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return fn.apply(context, args);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
bound.$native = fn;
|
|
213
|
+
transferProps(fn, bound);
|
|
214
|
+
if (fn.prototype) {
|
|
215
|
+
fNOP.prototype = fn.prototype;
|
|
216
|
+
}
|
|
217
|
+
bound.prototype = new fNOP();
|
|
218
|
+
if (Symbol.hasInstance) {
|
|
219
|
+
Object.defineProperty(bound, Symbol.hasInstance, {
|
|
220
|
+
configurable: true,
|
|
221
|
+
value(instance) {
|
|
222
|
+
const op = fn.prototype;
|
|
223
|
+
return isObject(op) || typeof op === 'function' ? instance instanceof fn : false;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return bound;
|
|
228
|
+
}
|
|
229
|
+
function createFakeObject(target, writableKeys) {
|
|
230
|
+
const fakeObject = {};
|
|
231
|
+
const propertyMap = {};
|
|
232
|
+
const storageBox = Object.create(null);
|
|
233
|
+
const propertyNames = Object.getOwnPropertyNames(target);
|
|
234
|
+
const def = (p) => {
|
|
235
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, p);
|
|
236
|
+
if (descriptor === null || descriptor === void 0 ? void 0 : descriptor.configurable) {
|
|
237
|
+
const hasGetter = hasOwnProp(descriptor, 'get');
|
|
238
|
+
const hasSetter = hasOwnProp(descriptor, 'set');
|
|
239
|
+
const canWritable = writableKeys && writableKeys.length > 0 && writableKeys.includes(p);
|
|
240
|
+
if (hasGetter) {
|
|
241
|
+
descriptor.get = () => (hasOwnProp(storageBox, p) ? storageBox[p] : target[p]);
|
|
242
|
+
}
|
|
243
|
+
if (hasSetter) {
|
|
244
|
+
descriptor.set = val => {
|
|
245
|
+
storageBox[p] = val;
|
|
246
|
+
return true;
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
if (canWritable) {
|
|
250
|
+
if (descriptor.writable === false) {
|
|
251
|
+
descriptor.writable = true;
|
|
252
|
+
}
|
|
253
|
+
else if (hasGetter) {
|
|
254
|
+
descriptor.set = val => {
|
|
255
|
+
storageBox[p] = val;
|
|
256
|
+
return true;
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
Object.defineProperty(fakeObject, p, Object.freeze(descriptor));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
propertyNames.forEach(p => {
|
|
264
|
+
propertyMap[p] = true;
|
|
265
|
+
def(p);
|
|
266
|
+
});
|
|
267
|
+
// 再次循环是为了处理原型链中的属性
|
|
268
|
+
for (const prop in target) {
|
|
269
|
+
if (!propertyMap[prop]) {
|
|
270
|
+
def(prop);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return fakeObject;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const esGlobalFunctions = ('eval,isFinite,isNaN,parseFloat,parseInt,' +
|
|
277
|
+
// URL handling functions
|
|
278
|
+
'decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
|
|
279
|
+
// Constructor properties of the global object
|
|
280
|
+
'Array,ArrayBuffer,BigInt,BigInt64Array,BigUint64Array,Boolean,DataView,Date,Error,EvalError,' +
|
|
281
|
+
'FinalizationRegistry,Float32Array,Float64Array,Function,Int8Array,Int16Array,Int32Array,Map,Number,' +
|
|
282
|
+
'Object,Promise,Proxy,RangeError,ReferenceError,RegExp,Set,SharedArrayBuffer,String,Symbol,SyntaxError,' +
|
|
283
|
+
'TypeError,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,URIError,WeakMap,WeakRef,WeakSet,' +
|
|
284
|
+
// Other Properties of the Global Object
|
|
285
|
+
'Atomics,JSON,Math,Reflect').split(',');
|
|
286
|
+
const whitelistVariables = PLANET_SANDBOX_WINDOW_WHITELIST || [];
|
|
287
|
+
function isConstructor(fn) {
|
|
288
|
+
const fp = fn.prototype;
|
|
289
|
+
const hasConstructor = fp && fp.constructor === fn && Object.getOwnPropertyNames(fp).length > 1;
|
|
290
|
+
const functionStr = !hasConstructor && fn.toString();
|
|
291
|
+
return hasConstructor || /^function\s+[A-Z]/.test(functionStr) || /^class\b/.test(functionStr);
|
|
292
|
+
}
|
|
293
|
+
const unscopables = {
|
|
294
|
+
undefined: true,
|
|
295
|
+
Array: true,
|
|
296
|
+
Object: true,
|
|
297
|
+
String: true,
|
|
298
|
+
Boolean: true,
|
|
299
|
+
Math: true,
|
|
300
|
+
Number: true,
|
|
301
|
+
Symbol: true,
|
|
302
|
+
parseFloat: true,
|
|
303
|
+
Float32Array: true
|
|
304
|
+
};
|
|
305
|
+
class ProxyWindow {
|
|
306
|
+
constructor(sandbox) {
|
|
307
|
+
this.sandbox = sandbox;
|
|
308
|
+
this.definedVariables = new Set();
|
|
309
|
+
}
|
|
310
|
+
createGetter() {
|
|
311
|
+
return (target, key, receiver) => {
|
|
312
|
+
if (key === Symbol.unscopables) {
|
|
313
|
+
return unscopables;
|
|
314
|
+
}
|
|
315
|
+
if (key === SANDBOX_INSTANCE) {
|
|
316
|
+
return this.sandbox;
|
|
317
|
+
}
|
|
318
|
+
let value = null;
|
|
319
|
+
if (whitelistVariables.includes(key)) {
|
|
320
|
+
return Reflect.get(window, key);
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
value = hasOwnProp(target, key) ? Reflect.get(target, key, receiver) : Reflect.get(window, key);
|
|
324
|
+
}
|
|
325
|
+
if (isFunction(value)) {
|
|
326
|
+
if (esGlobalFunctions.includes(key) ||
|
|
327
|
+
whitelistVariables.includes(key) ||
|
|
328
|
+
this.sandbox.rewriteVariables.includes(key) ||
|
|
329
|
+
this.definedVariables.has(key) ||
|
|
330
|
+
isConstructor(value)) {
|
|
331
|
+
return value;
|
|
332
|
+
}
|
|
333
|
+
else {
|
|
334
|
+
const newValue = hasOwnProp(value, WINDOW_BIND_FN) ? value[WINDOW_BIND_FN] : bind(value, window);
|
|
335
|
+
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
336
|
+
if (isNonWriteableValue(desc)) {
|
|
337
|
+
return value;
|
|
338
|
+
}
|
|
339
|
+
if (isInvalidGetAccessor(desc)) {
|
|
340
|
+
return undefined;
|
|
341
|
+
}
|
|
342
|
+
value[WINDOW_BIND_FN] = newValue;
|
|
343
|
+
return newValue;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
return value;
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
createSetter() {
|
|
352
|
+
return (target, key, value, receiver) => {
|
|
353
|
+
const desc = Object.getOwnPropertyDescriptor(whitelistVariables.includes(key) ? window : receiver ? receiver : target, key);
|
|
354
|
+
if (desc && isNonWriteableValue(desc)) {
|
|
355
|
+
if (!Object.is(value, desc.value)) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (isInvalidSetAccessor(desc)) {
|
|
363
|
+
return false;
|
|
364
|
+
}
|
|
365
|
+
if (whitelistVariables.includes(key)) {
|
|
366
|
+
return Reflect.set(window, key, value);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
const success = Reflect.set(target, key, value, receiver);
|
|
370
|
+
if (success) {
|
|
371
|
+
if (this.sandbox.running) {
|
|
372
|
+
this.definedVariables.add(key);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return success;
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
createDefineProperty() {
|
|
380
|
+
return (target, p, descriptor) => {
|
|
381
|
+
if (whitelistVariables.includes(p)) {
|
|
382
|
+
return Reflect.defineProperty(window, p, descriptor);
|
|
383
|
+
}
|
|
384
|
+
else {
|
|
385
|
+
const success = Reflect.defineProperty(target, p, descriptor);
|
|
386
|
+
if (this.sandbox.running && success) {
|
|
387
|
+
this.definedVariables.add(p);
|
|
388
|
+
}
|
|
389
|
+
return success;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
createDeleteProperty() {
|
|
394
|
+
return (target, p) => {
|
|
395
|
+
if (hasOwnProp(target, p)) {
|
|
396
|
+
delete target[p];
|
|
397
|
+
if (this.sandbox.running && this.definedVariables.has(p)) {
|
|
398
|
+
this.definedVariables.delete(p);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return true;
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
createHas() {
|
|
405
|
+
return (_target, key) => {
|
|
406
|
+
return !whitelistVariables.includes(key);
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
create() {
|
|
410
|
+
const fakeWindow = createFakeObject(window, this.sandbox.rewriteVariables);
|
|
411
|
+
const baseHandlers = {
|
|
412
|
+
get: this.createGetter(),
|
|
413
|
+
set: this.createSetter(),
|
|
414
|
+
defineProperty: this.createDefineProperty(),
|
|
415
|
+
deleteProperty: this.createDeleteProperty()
|
|
416
|
+
};
|
|
417
|
+
const proxy = new Proxy(fakeWindow, Object.assign(Object.assign({}, baseHandlers), { has: this.createHas() }));
|
|
418
|
+
const subProxy = new Proxy(fakeWindow, baseHandlers);
|
|
419
|
+
proxy.self = subProxy;
|
|
420
|
+
proxy.window = subProxy;
|
|
421
|
+
proxy.globalThis = subProxy;
|
|
422
|
+
proxy.top = window.top === window ? subProxy : window.top;
|
|
423
|
+
proxy.parent = window.parent === window ? subProxy : window.top;
|
|
424
|
+
return proxy;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function eventListenerPatch(sandbox) {
|
|
429
|
+
const rawAddEventListener = window.addEventListener;
|
|
430
|
+
const rawRemoveEventListener = window.removeEventListener;
|
|
431
|
+
const listenerSubscriptions = new Map();
|
|
432
|
+
function addEventListener(type, listener, options) {
|
|
433
|
+
const observable = new Observable(() => {
|
|
434
|
+
rawAddEventListener.call(this, type, listener, options);
|
|
435
|
+
return () => {
|
|
436
|
+
rawRemoveEventListener.call(this, type, listener, options);
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
const subscription = observable.subscribe(() => { });
|
|
440
|
+
listenerSubscriptions.set(listener, subscription);
|
|
441
|
+
}
|
|
442
|
+
function removeEventListener(type, listener) {
|
|
443
|
+
const subscription = listenerSubscriptions.get(listener);
|
|
444
|
+
if (subscription) {
|
|
445
|
+
subscription.unsubscribe();
|
|
446
|
+
listenerSubscriptions.delete(listener);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
rewrite: {
|
|
451
|
+
addEventListener: addEventListener.bind(window),
|
|
452
|
+
removeEventListener: removeEventListener.bind(window)
|
|
453
|
+
},
|
|
454
|
+
init() {
|
|
455
|
+
const fakeDocument = sandbox.global.document;
|
|
456
|
+
if (fakeDocument) {
|
|
457
|
+
fakeDocument.addEventListener = addEventListener.bind(document);
|
|
458
|
+
fakeDocument.removeEventListener = removeEventListener.bind(document);
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
destroy() {
|
|
462
|
+
listenerSubscriptions.forEach(subscription => subscription.unsubscribe());
|
|
463
|
+
listenerSubscriptions.clear();
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
const rawDocument = Document;
|
|
469
|
+
const whitelist = ['cookie', 'title', 'location', ...(PLANET_SANDBOX_DOCUMENT_WHITELIST || [])];
|
|
470
|
+
class ProxyDocument {
|
|
471
|
+
constructor() { }
|
|
472
|
+
createGetter() {
|
|
473
|
+
return (target, p, receiver) => {
|
|
474
|
+
const value = hasOwnProp(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(document, p);
|
|
475
|
+
if (p === 'activeElement') {
|
|
476
|
+
return Reflect.get(document, p);
|
|
477
|
+
}
|
|
478
|
+
// TODO: 处理动态节点
|
|
479
|
+
// if (p === 'createElement') {
|
|
480
|
+
// return function(tagName: string, options: ElementCreationOptions) {
|
|
481
|
+
// const created = value.call(document, tagName, options);
|
|
482
|
+
// if (isObject(created)) {
|
|
483
|
+
// created[SANDBOX_INSTANCE] = sandbox;
|
|
484
|
+
// }
|
|
485
|
+
// return created;
|
|
486
|
+
// };
|
|
487
|
+
// }
|
|
488
|
+
if (isFunction(value)) {
|
|
489
|
+
let newValue = hasOwnProp(value, DOCUMENT_BIND_FN) ? value[DOCUMENT_BIND_FN] : null;
|
|
490
|
+
if (!newValue) {
|
|
491
|
+
newValue = bind(value, document);
|
|
492
|
+
}
|
|
493
|
+
const desc = Object.getOwnPropertyDescriptor(target, p);
|
|
494
|
+
if (desc && isNonWriteableValue(desc)) {
|
|
495
|
+
if (!Object.is(newValue, desc.value)) {
|
|
496
|
+
return value;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
if (isInvalidGetAccessor(desc)) {
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
value[DOCUMENT_BIND_FN] = newValue;
|
|
503
|
+
return newValue;
|
|
504
|
+
}
|
|
505
|
+
return value;
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
createSetter() {
|
|
509
|
+
return (target, p, value, receiver) => {
|
|
510
|
+
const desc = Object.getOwnPropertyDescriptor(whitelist.includes(p) ? document : receiver || target, p);
|
|
511
|
+
if (desc && isNonWriteableValue(desc)) {
|
|
512
|
+
if (Object.is(value, desc.value)) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
if (isInvalidSetAccessor(desc)) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
return whitelist.includes(p) ? Reflect.set(document, p, value) : Reflect.set(target, p, value, receiver);
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
createDefineProperty() {
|
|
526
|
+
return (target, p, descriptor) => {
|
|
527
|
+
return whitelist.includes(p)
|
|
528
|
+
? Reflect.defineProperty(document, p, descriptor)
|
|
529
|
+
: Reflect.defineProperty(target, p, descriptor);
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
create() {
|
|
533
|
+
let proxyDocument = null;
|
|
534
|
+
const fakeDocument = createFakeObject(document);
|
|
535
|
+
const getter = this.createGetter();
|
|
536
|
+
const fakeDocumentProto = new Proxy(fakeDocument, {
|
|
537
|
+
get: (...args) => {
|
|
538
|
+
return getter(...args);
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
const fakeDocumentCtor = function Document() {
|
|
542
|
+
if (!(this instanceof fakeDocumentCtor)) {
|
|
543
|
+
throw new TypeError(`Failed to construct 'Document': Please use the 'new' operator.`);
|
|
544
|
+
}
|
|
545
|
+
const docInstance = new rawDocument();
|
|
546
|
+
Object.setPrototypeOf(docInstance, fakeDocument);
|
|
547
|
+
return docInstance;
|
|
548
|
+
};
|
|
549
|
+
fakeDocumentCtor.prototype = fakeDocumentProto;
|
|
550
|
+
fakeDocumentCtor.prototype.constructor = fakeDocumentCtor;
|
|
551
|
+
if (Symbol.hasInstance) {
|
|
552
|
+
Object.defineProperty(fakeDocumentCtor, Symbol.hasInstance, {
|
|
553
|
+
configurable: true,
|
|
554
|
+
value(value) {
|
|
555
|
+
let proto = value;
|
|
556
|
+
if (proto === document) {
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
while ((proto = Object.getPrototypeOf(proto))) {
|
|
560
|
+
if (proto === fakeDocumentProto) {
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const cloned = function () { };
|
|
565
|
+
cloned.prototype = fakeDocument;
|
|
566
|
+
return value instanceof cloned;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
proxyDocument = new Proxy(Object.create(fakeDocumentProto, {
|
|
571
|
+
currentScript: {
|
|
572
|
+
value: null,
|
|
573
|
+
writable: true
|
|
574
|
+
},
|
|
575
|
+
[RAW_NODE]: {
|
|
576
|
+
writable: false,
|
|
577
|
+
configurable: false,
|
|
578
|
+
value: document
|
|
579
|
+
}
|
|
580
|
+
}), {
|
|
581
|
+
set: this.createSetter(),
|
|
582
|
+
defineProperty: this.createDefineProperty()
|
|
583
|
+
});
|
|
584
|
+
return {
|
|
585
|
+
document: proxyDocument,
|
|
586
|
+
Document: fakeDocumentCtor
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function documentPatch() {
|
|
592
|
+
const proxyDocument = new ProxyDocument();
|
|
593
|
+
const { document, Document } = proxyDocument.create();
|
|
594
|
+
return {
|
|
595
|
+
rewrite: {
|
|
596
|
+
document,
|
|
597
|
+
Document
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
const rawSetTimeout = window.setTimeout;
|
|
603
|
+
const rawClearTimeout = window.clearTimeout;
|
|
604
|
+
const rawSetInterval = window.setInterval;
|
|
605
|
+
const rawClearInterval = window.clearInterval;
|
|
606
|
+
function timerPatch() {
|
|
607
|
+
const timeout = new Set();
|
|
608
|
+
const interval = new Set();
|
|
609
|
+
function rewriteSetTimeout(handler, ms, ...args) {
|
|
610
|
+
const timeoutId = rawSetTimeout(handler, ms, ...args);
|
|
611
|
+
timeout.add(timeoutId);
|
|
612
|
+
return timeoutId;
|
|
613
|
+
}
|
|
614
|
+
function rewriteClearTimeout(timeoutId) {
|
|
615
|
+
timeout.delete(timeoutId);
|
|
616
|
+
rawClearTimeout(timeoutId);
|
|
617
|
+
}
|
|
618
|
+
function rewriteSetInterval(handler, ms, ...args) {
|
|
619
|
+
const intervalId = rawSetInterval(handler, ms, ...args);
|
|
620
|
+
interval.add(intervalId);
|
|
621
|
+
return intervalId;
|
|
622
|
+
}
|
|
623
|
+
function rewriteClearInterval(intervalId) {
|
|
624
|
+
interval.delete(intervalId);
|
|
625
|
+
rawClearInterval(intervalId);
|
|
626
|
+
}
|
|
627
|
+
return {
|
|
628
|
+
rewrite: {
|
|
629
|
+
setTimeout: rewriteSetTimeout,
|
|
630
|
+
clearTimeout: rewriteClearTimeout,
|
|
631
|
+
setInterval: rewriteSetInterval,
|
|
632
|
+
clearInterval: rewriteClearInterval
|
|
633
|
+
},
|
|
634
|
+
destroy: () => {
|
|
635
|
+
timeout.forEach(timeoutId => {
|
|
636
|
+
rawClearTimeout(timeoutId);
|
|
637
|
+
});
|
|
638
|
+
interval.forEach(intervalId => {
|
|
639
|
+
rawClearInterval(intervalId);
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
const PLANET_STORAGE_PREFIX = '__planet-storage-';
|
|
646
|
+
class RewriteStorage {
|
|
647
|
+
constructor(app, rawStorage) {
|
|
648
|
+
this.rawStorage = rawStorage;
|
|
649
|
+
this.prefix = `${PLANET_STORAGE_PREFIX}${app}__:`;
|
|
650
|
+
}
|
|
651
|
+
get length() {
|
|
652
|
+
return this.getKeys().length;
|
|
653
|
+
}
|
|
654
|
+
getKeys() {
|
|
655
|
+
return Object.keys(this.rawStorage).filter(key => key.startsWith(this.prefix));
|
|
656
|
+
}
|
|
657
|
+
key(n) {
|
|
658
|
+
const key = this.getKeys()[n];
|
|
659
|
+
return key ? key.substring(this.prefix.length) : null;
|
|
660
|
+
}
|
|
661
|
+
getItem(key) {
|
|
662
|
+
return this.rawStorage.getItem(`${this.prefix + key}`);
|
|
663
|
+
}
|
|
664
|
+
setItem(key, value) {
|
|
665
|
+
this.rawStorage.setItem(`${this.prefix + key}`, value);
|
|
666
|
+
}
|
|
667
|
+
removeItem(key) {
|
|
668
|
+
this.rawStorage.removeItem(`${this.prefix + key}`);
|
|
669
|
+
}
|
|
670
|
+
clear() {
|
|
671
|
+
this.getKeys().forEach(key => {
|
|
672
|
+
this.rawStorage.removeItem(key);
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function storagePatch(sandbox) {
|
|
677
|
+
return {
|
|
678
|
+
rewrite: {
|
|
679
|
+
localStorage: new RewriteStorage(sandbox.app, localStorage),
|
|
680
|
+
sessionStorage: new RewriteStorage(sandbox.app, sessionStorage)
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
const sandboxPatches = [documentPatch, eventListenerPatch, timerPatch, storagePatch];
|
|
686
|
+
function getSandboxPatchHandlers(sandbox) {
|
|
687
|
+
return sandboxPatches.map(patch => {
|
|
688
|
+
return patch(sandbox);
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
function execScript(code, url, global, strictGlobal) {
|
|
693
|
+
const sourceUrl = '//# sourceURL='.concat(url, '\n');
|
|
694
|
+
const window = (0, eval)('window');
|
|
695
|
+
window.tempGlobal = global;
|
|
696
|
+
code = strictGlobal
|
|
697
|
+
? ';(function(window, self, globalThis){with(window){;'
|
|
698
|
+
.concat(code, '\n')
|
|
699
|
+
.concat(sourceUrl, '}}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);')
|
|
700
|
+
: ';(function(window, self, globalThis){;'
|
|
701
|
+
.concat(code, '\n')
|
|
702
|
+
.concat(sourceUrl, '}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);');
|
|
703
|
+
(0, eval)(code);
|
|
704
|
+
delete window.tempGlobal;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
class Sandbox {
|
|
708
|
+
execScript(code, url = '') {
|
|
709
|
+
execScript(code, url, this.global, !!this.options.strictGlobal);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
class ProxySandbox extends Sandbox {
|
|
714
|
+
constructor(app, options) {
|
|
715
|
+
super();
|
|
716
|
+
this.app = app;
|
|
717
|
+
this.options = options;
|
|
718
|
+
this.running = false;
|
|
719
|
+
this.patchHandlers = [];
|
|
720
|
+
this.patchHandlers = getSandboxPatchHandlers(this);
|
|
721
|
+
this.start();
|
|
722
|
+
}
|
|
723
|
+
start() {
|
|
724
|
+
this.running = true;
|
|
725
|
+
this.rewriteVariables = this.getPatchRewriteVariables();
|
|
726
|
+
const proxyWindow = new ProxyWindow(this);
|
|
727
|
+
this.global = proxyWindow.create();
|
|
728
|
+
this.execPatchHandlers();
|
|
729
|
+
}
|
|
730
|
+
destroy() {
|
|
731
|
+
this.running = false;
|
|
732
|
+
this.patchHandlers.forEach(handler => {
|
|
733
|
+
if (handler.destroy) {
|
|
734
|
+
handler.destroy();
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
getPatchRewriteVariables() {
|
|
739
|
+
return this.patchHandlers.reduce((pre, cur) => {
|
|
740
|
+
return [...pre, ...(cur.rewrite ? Object.keys(cur.rewrite) : [])];
|
|
741
|
+
}, []);
|
|
742
|
+
}
|
|
743
|
+
execPatchHandlers() {
|
|
744
|
+
this.patchHandlers.forEach(handler => {
|
|
745
|
+
if (handler.rewrite) {
|
|
746
|
+
for (const key in handler.rewrite) {
|
|
747
|
+
if (handler.rewrite[key]) {
|
|
748
|
+
this.global[key] = handler.rewrite[key];
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
if (handler.init) {
|
|
753
|
+
handler === null || handler === void 0 ? void 0 : handler.init();
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
class SnapshotSandbox extends Sandbox {
|
|
760
|
+
constructor(app, options) {
|
|
761
|
+
super();
|
|
762
|
+
this.app = app;
|
|
763
|
+
this.options = options;
|
|
764
|
+
this.start();
|
|
765
|
+
}
|
|
766
|
+
start() { }
|
|
767
|
+
destroy() { }
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const defaultOptions = {
|
|
771
|
+
strictGlobal: false
|
|
772
|
+
};
|
|
773
|
+
function createSandbox(app, options) {
|
|
774
|
+
options = Object.assign({}, defaultOptions, options || {});
|
|
775
|
+
if (window.Proxy) {
|
|
776
|
+
return new ProxySandbox(app, options);
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
return new SnapshotSandbox(app, options);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function getSandboxInstance() {
|
|
783
|
+
return window[SANDBOX_INSTANCE];
|
|
784
|
+
}
|
|
785
|
+
|
|
136
786
|
class AssetsLoader {
|
|
137
787
|
constructor(http) {
|
|
138
788
|
this.http = http;
|
|
@@ -195,6 +845,40 @@ class AssetsLoader {
|
|
|
195
845
|
document.body.appendChild(script);
|
|
196
846
|
});
|
|
197
847
|
}
|
|
848
|
+
loadScriptWithSandbox(app, src) {
|
|
849
|
+
const id = hashCode(src);
|
|
850
|
+
if (this.loadedSources.includes(id)) {
|
|
851
|
+
return of({
|
|
852
|
+
src: src,
|
|
853
|
+
hashCode: id,
|
|
854
|
+
loaded: true,
|
|
855
|
+
status: 'Loaded'
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
return new Observable((observer) => {
|
|
859
|
+
this.http.get(src, { responseType: 'text' }).subscribe((code) => {
|
|
860
|
+
this.loadedSources.push(id);
|
|
861
|
+
const sandbox = createSandbox(app);
|
|
862
|
+
sandbox.execScript(code, src);
|
|
863
|
+
observer.next({
|
|
864
|
+
src: src,
|
|
865
|
+
hashCode: id,
|
|
866
|
+
loaded: true,
|
|
867
|
+
status: 'Loaded'
|
|
868
|
+
});
|
|
869
|
+
observer.complete();
|
|
870
|
+
}, error => {
|
|
871
|
+
observer.error({
|
|
872
|
+
src: src,
|
|
873
|
+
hashCode: id,
|
|
874
|
+
loaded: false,
|
|
875
|
+
status: 'Error',
|
|
876
|
+
error: error
|
|
877
|
+
});
|
|
878
|
+
observer.complete();
|
|
879
|
+
});
|
|
880
|
+
});
|
|
881
|
+
}
|
|
198
882
|
loadStyle(src) {
|
|
199
883
|
const id = hashCode(src);
|
|
200
884
|
if (this.loadedSources.includes(id)) {
|
|
@@ -235,14 +919,23 @@ class AssetsLoader {
|
|
|
235
919
|
head.appendChild(link);
|
|
236
920
|
});
|
|
237
921
|
}
|
|
238
|
-
loadScripts(sources,
|
|
922
|
+
loadScripts(sources, options = {
|
|
923
|
+
serial: false,
|
|
924
|
+
sandbox: false
|
|
925
|
+
}) {
|
|
239
926
|
if (isEmpty(sources)) {
|
|
240
927
|
return of(null);
|
|
241
928
|
}
|
|
242
929
|
const observables = sources.map(src => {
|
|
243
|
-
|
|
930
|
+
// TODO: 暂时只支持Proxy沙箱
|
|
931
|
+
if (options.sandbox && window.Proxy) {
|
|
932
|
+
return this.loadScriptWithSandbox(options.app, src);
|
|
933
|
+
}
|
|
934
|
+
else {
|
|
935
|
+
return this.loadScript(src);
|
|
936
|
+
}
|
|
244
937
|
});
|
|
245
|
-
if (serial) {
|
|
938
|
+
if (options.serial) {
|
|
246
939
|
const a = concat(...observables).pipe(map(item => {
|
|
247
940
|
return of([item]);
|
|
248
941
|
}), concatAll());
|
|
@@ -260,19 +953,27 @@ class AssetsLoader {
|
|
|
260
953
|
return this.loadStyle(src);
|
|
261
954
|
}));
|
|
262
955
|
}
|
|
263
|
-
loadScriptsAndStyles(scripts = [], styles = [],
|
|
264
|
-
return forkJoin([this.loadScripts(scripts,
|
|
956
|
+
loadScriptsAndStyles(scripts = [], styles = [], options) {
|
|
957
|
+
return forkJoin([this.loadScripts(scripts, options), this.loadStyles(styles)]);
|
|
265
958
|
}
|
|
266
959
|
loadAppAssets(app) {
|
|
267
960
|
if (app.manifest) {
|
|
268
961
|
return this.loadManifest(`${app.manifest}?t=${new Date().getTime()}`).pipe(switchMap(manifestResult => {
|
|
269
962
|
const { scripts, styles } = getScriptsAndStylesFullPaths(app, manifestResult);
|
|
270
|
-
return this.loadScriptsAndStyles(scripts, styles,
|
|
963
|
+
return this.loadScriptsAndStyles(scripts, styles, {
|
|
964
|
+
app: app.name,
|
|
965
|
+
sandbox: app.sandbox,
|
|
966
|
+
serial: app.loadSerial
|
|
967
|
+
});
|
|
271
968
|
}));
|
|
272
969
|
}
|
|
273
970
|
else {
|
|
274
971
|
const { scripts, styles } = getScriptsAndStylesFullPaths(app);
|
|
275
|
-
return this.loadScriptsAndStyles(scripts, styles,
|
|
972
|
+
return this.loadScriptsAndStyles(scripts, styles, {
|
|
973
|
+
app: app.name,
|
|
974
|
+
sandbox: app.sandbox,
|
|
975
|
+
serial: app.loadSerial
|
|
976
|
+
});
|
|
276
977
|
}
|
|
277
978
|
}
|
|
278
979
|
loadManifest(url) {
|
|
@@ -296,15 +997,15 @@ class PlanetApplicationRef {
|
|
|
296
997
|
this.name = name;
|
|
297
998
|
if (options) {
|
|
298
999
|
this.template = options.template;
|
|
299
|
-
this.innerSelector = this.template ? getTagNameByTemplate(this.template) :
|
|
1000
|
+
this.innerSelector = this.template ? getTagNameByTemplate(this.template) : '';
|
|
300
1001
|
this.appModuleBootstrap = options.bootstrap;
|
|
301
1002
|
}
|
|
302
1003
|
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
303
1004
|
// See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
1005
|
+
NgZone.isInAngularZone = () => {
|
|
1006
|
+
// @ts-ignore
|
|
1007
|
+
return window.Zone.current._properties[`ngx-planet-${name}`] === true;
|
|
1008
|
+
};
|
|
308
1009
|
}
|
|
309
1010
|
get selector() {
|
|
310
1011
|
return this.innerSelector;
|
|
@@ -312,17 +1013,22 @@ class PlanetApplicationRef {
|
|
|
312
1013
|
get bootstrapped() {
|
|
313
1014
|
return !!this.appModuleRef;
|
|
314
1015
|
}
|
|
1016
|
+
get ngZone() {
|
|
1017
|
+
var _a;
|
|
1018
|
+
return (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(NgZone);
|
|
1019
|
+
}
|
|
1020
|
+
get sandbox() {
|
|
1021
|
+
return getSandboxInstance();
|
|
1022
|
+
}
|
|
315
1023
|
// 子应用路由变化后同步修改 portal 的 Route
|
|
316
1024
|
syncPortalRouteWhenNavigationEnd() {
|
|
317
|
-
|
|
318
|
-
const
|
|
1025
|
+
var _a;
|
|
1026
|
+
const router = (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(Router);
|
|
319
1027
|
if (router) {
|
|
320
1028
|
router.events.subscribe(event => {
|
|
1029
|
+
var _a;
|
|
321
1030
|
if (event instanceof NavigationEnd) {
|
|
322
|
-
ngZone.onStable
|
|
323
|
-
.asObservable()
|
|
324
|
-
.pipe(take(1))
|
|
325
|
-
.subscribe(() => {
|
|
1031
|
+
(_a = this.ngZone) === null || _a === void 0 ? void 0 : _a.onStable.asObservable().pipe(take(1)).subscribe(() => {
|
|
326
1032
|
this.portalApp.router.navigateByUrl(event.url);
|
|
327
1033
|
});
|
|
328
1034
|
}
|
|
@@ -342,16 +1048,18 @@ class PlanetApplicationRef {
|
|
|
342
1048
|
}));
|
|
343
1049
|
}
|
|
344
1050
|
getRouter() {
|
|
345
|
-
|
|
1051
|
+
var _a;
|
|
1052
|
+
return (_a = this.appModuleRef) === null || _a === void 0 ? void 0 : _a.injector.get(Router);
|
|
346
1053
|
}
|
|
347
1054
|
getCurrentRouterStateUrl() {
|
|
348
|
-
|
|
1055
|
+
var _a;
|
|
1056
|
+
return (_a = this.getRouter()) === null || _a === void 0 ? void 0 : _a.routerState.snapshot.url;
|
|
349
1057
|
}
|
|
350
1058
|
navigateByUrl(url) {
|
|
351
|
-
|
|
1059
|
+
var _a;
|
|
352
1060
|
const router = this.getRouter();
|
|
353
|
-
ngZone.run(() => {
|
|
354
|
-
router.navigateByUrl(url);
|
|
1061
|
+
(_a = this.ngZone) === null || _a === void 0 ? void 0 : _a.run(() => {
|
|
1062
|
+
router === null || router === void 0 ? void 0 : router.navigateByUrl(url);
|
|
355
1063
|
});
|
|
356
1064
|
}
|
|
357
1065
|
getComponentFactory() {
|
|
@@ -366,8 +1074,11 @@ class PlanetApplicationRef {
|
|
|
366
1074
|
if (router) {
|
|
367
1075
|
router.dispose();
|
|
368
1076
|
}
|
|
1077
|
+
if (this.sandbox) {
|
|
1078
|
+
this.sandbox.destroy();
|
|
1079
|
+
}
|
|
369
1080
|
this.appModuleRef.destroy();
|
|
370
|
-
|
|
1081
|
+
this.appModuleRef = undefined;
|
|
371
1082
|
}
|
|
372
1083
|
}
|
|
373
1084
|
}
|
|
@@ -397,10 +1108,13 @@ function getPlanetApplicationRef(appName) {
|
|
|
397
1108
|
}
|
|
398
1109
|
}
|
|
399
1110
|
function setPortalApplicationData(data) {
|
|
400
|
-
globalPlanet.portalApplication
|
|
1111
|
+
if (globalPlanet.portalApplication) {
|
|
1112
|
+
globalPlanet.portalApplication.data = data;
|
|
1113
|
+
}
|
|
401
1114
|
}
|
|
402
1115
|
function getPortalApplicationData() {
|
|
403
|
-
|
|
1116
|
+
var _a;
|
|
1117
|
+
return (_a = globalPlanet.portalApplication) === null || _a === void 0 ? void 0 : _a.data;
|
|
404
1118
|
}
|
|
405
1119
|
function setApplicationLoader(loader) {
|
|
406
1120
|
globalPlanet.applicationLoader = loader;
|
|
@@ -607,7 +1321,7 @@ function setDebugFactory(debug) {
|
|
|
607
1321
|
_debugFactory = debug;
|
|
608
1322
|
}
|
|
609
1323
|
function clearDebugFactory() {
|
|
610
|
-
|
|
1324
|
+
_debugFactory = undefined;
|
|
611
1325
|
_debuggerMap = {};
|
|
612
1326
|
}
|
|
613
1327
|
function getDebugFactory() {
|
|
@@ -760,7 +1474,7 @@ class PlanetApplicationLoader {
|
|
|
760
1474
|
debug(`[routeChange] app(${app.name}) status is bootstrapped, show app and active`);
|
|
761
1475
|
this.showApp(app);
|
|
762
1476
|
const appRef = getPlanetApplicationRef(app.name);
|
|
763
|
-
appRef.navigateByUrl(event.url);
|
|
1477
|
+
appRef === null || appRef === void 0 ? void 0 : appRef.navigateByUrl(event.url);
|
|
764
1478
|
this.setAppStatus(app, ApplicationStatus.active);
|
|
765
1479
|
this.setLoadingDone();
|
|
766
1480
|
return of(app);
|
|
@@ -778,11 +1492,11 @@ class PlanetApplicationLoader {
|
|
|
778
1492
|
debug(`[routeChange] app(${app.name}) is active, do nothings`);
|
|
779
1493
|
const appRef = getPlanetApplicationRef(app.name);
|
|
780
1494
|
// Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
|
|
781
|
-
const currentUrl = appRef.getCurrentRouterStateUrl
|
|
1495
|
+
const currentUrl = (appRef === null || appRef === void 0 ? void 0 : appRef.getCurrentRouterStateUrl)
|
|
782
1496
|
? appRef.getCurrentRouterStateUrl()
|
|
783
1497
|
: '';
|
|
784
1498
|
if (currentUrl !== event.url) {
|
|
785
|
-
appRef.navigateByUrl(event.url);
|
|
1499
|
+
appRef === null || appRef === void 0 ? void 0 : appRef.navigateByUrl(event.url);
|
|
786
1500
|
}
|
|
787
1501
|
return of(app);
|
|
788
1502
|
}
|
|
@@ -853,14 +1567,14 @@ class PlanetApplicationLoader {
|
|
|
853
1567
|
}
|
|
854
1568
|
hideApp(planetApp) {
|
|
855
1569
|
const appRef = getPlanetApplicationRef(planetApp.name);
|
|
856
|
-
const appRootElement = document.querySelector(appRef.selector || planetApp.selector);
|
|
1570
|
+
const appRootElement = document.querySelector((appRef === null || appRef === void 0 ? void 0 : appRef.selector) || planetApp.selector);
|
|
857
1571
|
if (appRootElement) {
|
|
858
1572
|
appRootElement.setAttribute('style', 'display:none;');
|
|
859
1573
|
}
|
|
860
1574
|
}
|
|
861
1575
|
showApp(planetApp) {
|
|
862
1576
|
const appRef = getPlanetApplicationRef(planetApp.name);
|
|
863
|
-
const appRootElement = document.querySelector(appRef.selector || planetApp.selector);
|
|
1577
|
+
const appRootElement = document.querySelector((appRef === null || appRef === void 0 ? void 0 : appRef.selector) || planetApp.selector);
|
|
864
1578
|
if (appRootElement) {
|
|
865
1579
|
appRootElement.setAttribute('style', '');
|
|
866
1580
|
}
|
|
@@ -871,9 +1585,9 @@ class PlanetApplicationLoader {
|
|
|
871
1585
|
appRef.destroy();
|
|
872
1586
|
}
|
|
873
1587
|
const container = getHTMLElement(planetApp.hostParent);
|
|
874
|
-
const appRootElement = container.querySelector((appRef && appRef.selector) || planetApp.selector);
|
|
1588
|
+
const appRootElement = container === null || container === void 0 ? void 0 : container.querySelector((appRef && appRef.selector) || planetApp.selector);
|
|
875
1589
|
if (appRootElement) {
|
|
876
|
-
container.removeChild(appRootElement);
|
|
1590
|
+
container === null || container === void 0 ? void 0 : container.removeChild(appRootElement);
|
|
877
1591
|
}
|
|
878
1592
|
}
|
|
879
1593
|
bootstrapApp(app, defaultStatus = 'display') {
|
|
@@ -967,13 +1681,15 @@ class PlanetApplicationLoader {
|
|
|
967
1681
|
}
|
|
968
1682
|
preloadApps(activeApps) {
|
|
969
1683
|
setTimeout(() => {
|
|
970
|
-
const toPreloadApps = this.planetApplicationService.getAppsToPreload(activeApps ? activeApps.map(item => item.name) :
|
|
1684
|
+
const toPreloadApps = this.planetApplicationService.getAppsToPreload(activeApps ? activeApps.map(item => item.name) : undefined);
|
|
971
1685
|
debug(`start preload apps: ${this.getAppNames(toPreloadApps)}`);
|
|
972
1686
|
const loadApps$ = toPreloadApps.map(preloadApp => {
|
|
973
1687
|
return this.preloadInternal(preloadApp);
|
|
974
1688
|
});
|
|
975
1689
|
forkJoin(loadApps$).subscribe({
|
|
976
|
-
error: error =>
|
|
1690
|
+
error: error => {
|
|
1691
|
+
this.errorHandler(error);
|
|
1692
|
+
}
|
|
977
1693
|
});
|
|
978
1694
|
});
|
|
979
1695
|
}
|
|
@@ -1008,6 +1724,9 @@ class PlanetApplicationLoader {
|
|
|
1008
1724
|
return this.bootstrapApp(app, 'hidden');
|
|
1009
1725
|
});
|
|
1010
1726
|
}
|
|
1727
|
+
}), catchError(error => {
|
|
1728
|
+
this.errorHandler(error);
|
|
1729
|
+
return of(null);
|
|
1011
1730
|
}), map(() => {
|
|
1012
1731
|
return getPlanetApplicationRef(app.name);
|
|
1013
1732
|
}));
|
|
@@ -1104,7 +1823,7 @@ class Planet {
|
|
|
1104
1823
|
this.subscription = this.router.events
|
|
1105
1824
|
.pipe(filter(event => {
|
|
1106
1825
|
return event instanceof NavigationEnd;
|
|
1107
|
-
}), map(
|
|
1826
|
+
}), map(event => {
|
|
1108
1827
|
return event.urlAfterRedirects || event.url;
|
|
1109
1828
|
}), startWith(location.pathname), distinctUntilChanged())
|
|
1110
1829
|
.subscribe((url) => {
|
|
@@ -1114,7 +1833,8 @@ class Planet {
|
|
|
1114
1833
|
});
|
|
1115
1834
|
}
|
|
1116
1835
|
stop() {
|
|
1117
|
-
|
|
1836
|
+
var _a;
|
|
1837
|
+
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
1118
1838
|
}
|
|
1119
1839
|
}
|
|
1120
1840
|
Planet.ɵprov = i0.ɵɵdefineInjectable({ factory: function Planet_Factory() { return new Planet(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i3.Router), i0.ɵɵinject(PLANET_APPLICATIONS, 8)); }, token: Planet, providedIn: "root" });
|
|
@@ -1277,7 +1997,7 @@ class PlanetComponentLoader {
|
|
|
1277
1997
|
load(app, componentName, config) {
|
|
1278
1998
|
const result = this.getPlantAppRef(app).pipe(delayWhen(appRef => {
|
|
1279
1999
|
if (appRef.getComponentFactory()) {
|
|
1280
|
-
return of();
|
|
2000
|
+
return of('');
|
|
1281
2001
|
}
|
|
1282
2002
|
else {
|
|
1283
2003
|
// Because register use 'setTimeout',so timer 20
|
|
@@ -1291,8 +2011,6 @@ class PlanetComponentLoader {
|
|
|
1291
2011
|
else {
|
|
1292
2012
|
throw new Error(`${app}'s component(${componentName}) is not registered`);
|
|
1293
2013
|
}
|
|
1294
|
-
}), finalize(() => {
|
|
1295
|
-
this.applicationRef.tick();
|
|
1296
2014
|
}), shareReplay());
|
|
1297
2015
|
result.subscribe();
|
|
1298
2016
|
return result;
|