@worktile/planet 12.1.1 → 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 +70 -0
- package/application/planet-application-loader.d.ts.map +1 -0
- package/application/planet-application-loader.ngfactory.d.ts.map +1 -0
- package/application/planet-application-ref.d.ts +36 -0
- package/application/planet-application-ref.d.ts.map +1 -0
- package/application/planet-application.service.d.ts +19 -0
- package/application/planet-application.service.d.ts.map +1 -0
- package/application/planet-application.service.ngfactory.d.ts.map +1 -0
- package/{packages/planet/src/application/portal-application.ts → application/portal-application.d.ts} +5 -18
- package/application/portal-application.d.ts.map +1 -0
- package/assets-loader.d.ts +33 -0
- package/assets-loader.d.ts.map +1 -0
- package/assets-loader.ngfactory.d.ts.map +1 -0
- package/bundles/worktile-planet.umd.js +2564 -0
- package/bundles/worktile-planet.umd.js.map +1 -0
- package/component/planet-component-loader.d.ts +28 -0
- package/component/planet-component-loader.d.ts.map +1 -0
- package/component/planet-component-loader.ngfactory.d.ts.map +1 -0
- package/component/planet-component-ref.d.ts +8 -0
- package/component/planet-component-ref.d.ts.map +1 -0
- package/{packages/planet/src/component/plant-component.config.ts → component/plant-component.config.d.ts} +4 -4
- package/component/plant-component.config.d.ts.map +1 -0
- package/debug.d.ts +22 -0
- package/debug.d.ts.map +1 -0
- package/empty/empty.component.d.ts +3 -0
- package/empty/empty.component.d.ts.map +1 -0
- package/empty/empty.component.ngfactory.d.ts.map +1 -0
- package/esm2015/application/planet-application-loader.js +457 -0
- package/esm2015/application/planet-application-ref.js +97 -0
- package/esm2015/application/planet-application.service.js +87 -0
- package/esm2015/application/portal-application.js +16 -0
- package/esm2015/assets-loader.js +217 -0
- package/esm2015/component/planet-component-loader.js +155 -0
- package/esm2015/component/planet-component-ref.js +3 -0
- package/esm2015/component/plant-component.config.js +7 -0
- package/esm2015/debug.js +33 -0
- package/esm2015/empty/empty.component.js +10 -0
- package/esm2015/global-event-dispatcher.js +71 -0
- package/esm2015/global-planet.js +54 -0
- package/esm2015/helpers.js +119 -0
- package/esm2015/module.js +27 -0
- package/esm2015/planet.class.js +9 -0
- package/esm2015/planet.js +91 -0
- package/esm2015/public-api.js +18 -0
- 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/esm2015/worktile-planet.js +6 -0
- package/fesm2015/worktile-planet.js +2048 -0
- package/fesm2015/worktile-planet.js.map +1 -0
- package/global-event-dispatcher.d.ts +20 -0
- package/global-event-dispatcher.d.ts.map +1 -0
- package/global-event-dispatcher.ngfactory.d.ts.map +1 -0
- package/global-planet.d.ts +23 -0
- package/global-planet.d.ts.map +1 -0
- package/helpers.d.ts +39 -0
- package/helpers.d.ts.map +1 -0
- package/module.d.ts +6 -0
- package/module.d.ts.map +1 -0
- package/module.ngfactory.d.ts.map +1 -0
- package/package.json +16 -121
- package/{packages/planet/src/planet.class.ts → planet.class.d.ts} +5 -26
- package/planet.class.d.ts.map +1 -0
- package/planet.d.ts +25 -0
- package/planet.d.ts.map +1 -0
- package/planet.ngfactory.d.ts.map +1 -0
- package/{packages/planet/src/public-api.ts → public-api.d.ts} +1 -4
- package/public-api.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/{packages/planet/src/sandbox/proxy/types.ts → sandbox/proxy/types.d.ts} +2 -8
- 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.d.ts +6 -0
- package/worktile-planet.d.ts.map +1 -0
- package/worktile-planet.metadata.json +1 -0
- package/.all-contributorsrc +0 -84
- package/.circleci/config.yml +0 -17
- package/.coveralls.yml +0 -1
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +0 -13
- package/.docgenirc.js +0 -35
- package/.dockerignore +0 -1
- package/.editorconfig +0 -22
- package/.github/FUNDING.yml +0 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.prettierignore +0 -7
- package/.prettierrc +0 -28
- package/.travis.yml +0 -26
- package/.wpmrc.js +0 -11
- package/CHANGELOG.md +0 -391
- package/CODE_OF_CONDUCT.md +0 -76
- package/Dockerfile +0 -11
- package/LICENSE +0 -21
- package/README.md +0 -348
- package/README.zh-CN.md +0 -307
- package/SECURITY.md +0 -21
- package/angular.json +0 -373
- package/commitlint.config.js +0 -6
- package/docs/api/defineApplication.md +0 -46
- package/docs/api/globalEventDispatcher.md +0 -51
- package/docs/api/index.md +0 -5
- package/docs/api/planet.md +0 -117
- package/docs/guides/getting-started.md +0 -174
- package/docs/guides/index.md +0 -5
- package/docs/guides/intro.md +0 -216
- package/examples/app1/browserslist +0 -11
- package/examples/app1/extra-webpack.config.js +0 -33
- package/examples/app1/karma.conf.js +0 -31
- package/examples/app1/postcss.config.js +0 -1
- package/examples/app1/src/app/app.module.ts +0 -44
- package/examples/app1/src/app/app.routing.ts +0 -49
- package/examples/app1/src/app/counter.service.ts +0 -16
- package/examples/app1/src/app/dashboard/dashboard.component.html +0 -51
- package/examples/app1/src/app/dashboard/dashboard.component.ts +0 -70
- package/examples/app1/src/app/detail/detail.component.html +0 -8
- package/examples/app1/src/app/detail/detail.component.ts +0 -18
- package/examples/app1/src/app/overlay.ts +0 -26
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +0 -10
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +0 -41
- package/examples/app1/src/app/projects/projects.component.ts +0 -33
- package/examples/app1/src/app/root/root.component.css +0 -3
- package/examples/app1/src/app/root/root.component.html +0 -16
- package/examples/app1/src/app/root/root.component.ts +0 -35
- package/examples/app1/src/app/services/initialized-data.resolver.ts +0 -15
- package/examples/app1/src/app/shared.module.ts +0 -57
- package/examples/app1/src/app/user/detail/user-detail.component.html +0 -5
- package/examples/app1/src/app/user/detail/user-detail.component.ts +0 -20
- package/examples/app1/src/app/user/user-list.component.html +0 -7
- package/examples/app1/src/app/user/user-list.component.ts +0 -20
- package/examples/app1/src/app/user/user.module.ts +0 -31
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +0 -3
- package/examples/app1/src/environments/environment.prod.ts +0 -3
- package/examples/app1/src/environments/environment.ts +0 -16
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +0 -14
- package/examples/app1/src/main.ts +0 -35
- package/examples/app1/src/polyfills.ts +0 -84
- package/examples/app1/src/styles.scss +0 -35
- package/examples/app1/src/test.ts +0 -14
- package/examples/app1/temp.js +0 -221
- package/examples/app1/tsconfig.app.json +0 -10
- package/examples/app1/tsconfig.spec.json +0 -18
- package/examples/app1/tslint.json +0 -17
- package/examples/app1/webpack.config.js +0 -127
- package/examples/app2/browserslist +0 -11
- package/examples/app2/extra-webpack.config.js +0 -32
- package/examples/app2/karma.conf.js +0 -31
- package/examples/app2/src/app/app.module.ts +0 -90
- package/examples/app2/src/app/dashboard/dashboard.component.html +0 -21
- package/examples/app2/src/app/dashboard/dashboard.component.ts +0 -27
- package/examples/app2/src/app/overlay.ts +0 -26
- package/examples/app2/src/app/projects/detail/detail.component.html +0 -16
- package/examples/app2/src/app/projects/detail/detail.component.ts +0 -21
- package/examples/app2/src/app/projects/project-list.component.html +0 -29
- package/examples/app2/src/app/projects/project-list.component.ts +0 -58
- package/examples/app2/src/app/projects/project.resolver.ts +0 -15
- package/examples/app2/src/app/projects/projects.service.ts +0 -28
- package/examples/app2/src/app/projects/tasks/tasks.component.html +0 -10
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +0 -16
- package/examples/app2/src/app/projects/view/view.component.html +0 -1
- package/examples/app2/src/app/projects/view/view.component.ts +0 -20
- package/examples/app2/src/app/root/root.component.html +0 -14
- package/examples/app2/src/app/root/root.component.scss +0 -12
- package/examples/app2/src/app/root/root.component.ts +0 -28
- package/examples/app2/src/app/shared.module.ts +0 -59
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +0 -3
- package/examples/app2/src/environments/environment.ts +0 -16
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +0 -14
- package/examples/app2/src/main.ts +0 -36
- package/examples/app2/src/polyfills.ts +0 -84
- package/examples/app2/src/styles.scss +0 -28
- package/examples/app2/src/test.ts +0 -14
- package/examples/app2/tsconfig.app.json +0 -10
- package/examples/app2/tsconfig.spec.json +0 -18
- package/examples/app2/tslint.json +0 -7
- package/examples/app2/webpack.config.js +0 -92
- package/examples/common/app-root-context.ts +0 -10
- package/examples/common/cache.ts +0 -82
- package/examples/common/index.ts +0 -13
- package/examples/common/module.ts +0 -10
- package/examples/common/overlay-container.service.ts +0 -28
- package/examples/common/section-card/section-card.component.html +0 -5
- package/examples/common/section-card/section-card.component.scss +0 -15
- package/examples/common/section-card/section-card.component.ts +0 -11
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +0 -8
- package/examples/portal/src/app/a-detail/a-detail.component.ts +0 -18
- package/examples/portal/src/app/about/about.component.html +0 -27
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +0 -26
- package/examples/portal/src/app/about/about.component.ts +0 -26
- package/examples/portal/src/app/app-routing.module.ts +0 -57
- package/examples/portal/src/app/app.component.html +0 -73
- package/examples/portal/src/app/app.component.scss +0 -58
- package/examples/portal/src/app/app.component.spec.ts +0 -33
- package/examples/portal/src/app/app.component.ts +0 -111
- package/examples/portal/src/app/app.module.ts +0 -64
- package/examples/portal/src/app/custom-settings.service.ts +0 -44
- package/examples/portal/src/app/overlay.ts +0 -26
- package/examples/portal/src/app/settings/settings.component.html +0 -31
- package/examples/portal/src/app/settings/settings.component.scss +0 -3
- package/examples/portal/src/app/settings/settings.component.ts +0 -43
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +0 -29
- package/examples/portal/src/assets/icons/sprite.defs.svg +0 -1
- package/examples/portal/src/assets/images/logo.svg +0 -16
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +0 -11
- package/examples/portal/src/environments/environment.prod.ts +0 -3
- package/examples/portal/src/environments/environment.ts +0 -16
- package/examples/portal/src/extra-webpack.config.js +0 -32
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +0 -14
- package/examples/portal/src/karma.conf.js +0 -31
- package/examples/portal/src/main.ts +0 -18
- package/examples/portal/src/polyfills.ts +0 -84
- package/examples/portal/src/reboot.scss +0 -14
- package/examples/portal/src/styles.scss +0 -14
- package/examples/portal/src/test.ts +0 -14
- package/examples/portal/src/tsconfig.app.json +0 -10
- package/examples/portal/src/tsconfig.spec.json +0 -9
- package/examples/portal/src/tslint.json +0 -7
- package/extra-webpack.config.js +0 -5
- package/nginx.conf +0 -17
- package/packages/planet/karma.conf.js +0 -37
- package/packages/planet/ng-package.json +0 -7
- package/packages/planet/package.json +0 -10
- package/packages/planet/src/application/planet-application-loader.spec.ts +0 -1102
- package/packages/planet/src/application/planet-application-loader.ts +0 -549
- package/packages/planet/src/application/planet-application-ref.spec.ts +0 -233
- package/packages/planet/src/application/planet-application-ref.ts +0 -131
- package/packages/planet/src/application/planet-application.service.spec.ts +0 -145
- package/packages/planet/src/application/planet-application.service.ts +0 -88
- package/packages/planet/src/application/portal-application.spec.ts +0 -53
- package/packages/planet/src/assets-loader.spec.ts +0 -689
- package/packages/planet/src/assets-loader.ts +0 -247
- package/packages/planet/src/component/planet-component-loader.spec.ts +0 -187
- package/packages/planet/src/component/planet-component-loader.ts +0 -173
- package/packages/planet/src/component/planet-component-ref.ts +0 -8
- package/packages/planet/src/debug.spec.ts +0 -58
- package/packages/planet/src/debug.ts +0 -66
- package/packages/planet/src/empty/empty.component.spec.ts +0 -34
- package/packages/planet/src/empty/empty.component.ts +0 -7
- package/packages/planet/src/global-event-dispatcher.spec.ts +0 -81
- package/packages/planet/src/global-event-dispatcher.ts +0 -82
- package/packages/planet/src/global-planet.spec.ts +0 -39
- package/packages/planet/src/global-planet.ts +0 -73
- package/packages/planet/src/helpers.spec.ts +0 -242
- package/packages/planet/src/helpers.ts +0 -125
- package/packages/planet/src/module.spec.ts +0 -79
- package/packages/planet/src/module.ts +0 -25
- package/packages/planet/src/planet.spec.ts +0 -226
- package/packages/planet/src/planet.ts +0 -113
- package/packages/planet/src/sandbox/constants.ts +0 -6
- package/packages/planet/src/sandbox/exec.ts +0 -22
- package/packages/planet/src/sandbox/index.ts +0 -24
- package/packages/planet/src/sandbox/proxy/patches/document.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +0 -49
- package/packages/planet/src/sandbox/proxy/patches/index.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +0 -53
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +0 -50
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +0 -137
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +0 -140
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +0 -176
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +0 -59
- package/packages/planet/src/sandbox/sandbox.ts +0 -20
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +0 -12
- package/packages/planet/src/sandbox/types.ts +0 -1
- package/packages/planet/src/test.ts +0 -16
- package/packages/planet/src/testing/app1.module.ts +0 -34
- package/packages/planet/src/testing/app2.module.ts +0 -24
- package/packages/planet/src/testing/applications.ts +0 -58
- package/packages/planet/src/testing/index.ts +0 -2
- package/packages/planet/src/testing/utils.ts +0 -31
- package/packages/planet/tsconfig.lib.json +0 -27
- package/packages/planet/tsconfig.lib.prod.json +0 -9
- package/packages/planet/tsconfig.spec.json +0 -17
- package/packages/planet/tslint.json +0 -7
- package/postcss.config.js +0 -3
- package/proxy.conf.js +0 -15
- package/tsconfig.json +0 -23
- package/tslint.json +0 -80
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { PlanetApplication } from './planet.class';
|
|
2
|
-
|
|
3
|
-
const ELEMENT_NODE_TYPE = 1;
|
|
4
|
-
|
|
5
|
-
export function hashCode(str: string): number {
|
|
6
|
-
let hash = 0;
|
|
7
|
-
let chr: number;
|
|
8
|
-
if (str.length === 0) {
|
|
9
|
-
return hash;
|
|
10
|
-
}
|
|
11
|
-
for (let i = 0; i < str.length; i++) {
|
|
12
|
-
chr = str.charCodeAt(i);
|
|
13
|
-
hash = (hash << 5) - hash + chr;
|
|
14
|
-
hash |= 0; // Convert to 32bit integer
|
|
15
|
-
}
|
|
16
|
-
return hash;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function getHTMLElement(selector: string | HTMLElement): HTMLElement | null {
|
|
20
|
-
if (selector instanceof HTMLElement) {
|
|
21
|
-
return selector;
|
|
22
|
-
} else {
|
|
23
|
-
return document.querySelector(selector);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function getTagNameByTemplate(template: string): string {
|
|
28
|
-
const element = createElementByTemplate(template);
|
|
29
|
-
return element ? element.nodeName : '';
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function createElementByTemplate(template: string) {
|
|
33
|
-
if (!template) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const element = document.createRange().createContextualFragment(template).firstChild;
|
|
37
|
-
if (element && element.nodeType === ELEMENT_NODE_TYPE) {
|
|
38
|
-
return element as HTMLElement;
|
|
39
|
-
} else {
|
|
40
|
-
throw new Error(`invalid template '${template}'`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function coerceArray<T>(value: T | T[]): T[] {
|
|
45
|
-
return Array.isArray(value) ? value : [value];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function isEmpty(value: any): boolean {
|
|
49
|
-
if (!value || value.length === 0) {
|
|
50
|
-
return true;
|
|
51
|
-
} else {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isFunction(value: any): value is Function {
|
|
57
|
-
const type = typeof value;
|
|
58
|
-
return !!value && type === 'function';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function isObject(val: any) {
|
|
62
|
-
return val && typeof val === 'object';
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get file name from path
|
|
66
|
-
* 1. "main.js" => "main.js"
|
|
67
|
-
* 2. "assets/scripts/main.js" => "main.js"
|
|
68
|
-
* @param path path
|
|
69
|
-
*/
|
|
70
|
-
export function getResourceFileName(path: string) {
|
|
71
|
-
const lastSlashIndex = path.lastIndexOf('/');
|
|
72
|
-
if (lastSlashIndex >= 0) {
|
|
73
|
-
return path.slice(lastSlashIndex + 1);
|
|
74
|
-
} else {
|
|
75
|
-
return path;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Build resource path by manifest
|
|
81
|
-
* if manifest is { "main.js": "main.h2sh23abee.js"}
|
|
82
|
-
* 1. "main.js" => "main.h2sh23abee.js"
|
|
83
|
-
* 2. "assets/scripts/main.js" =>"assets/scripts/main.h2sh23abee.js"
|
|
84
|
-
* @param resourceFilePath Resource File Path
|
|
85
|
-
* @param manifestResult manifest
|
|
86
|
-
*/
|
|
87
|
-
export function buildResourceFilePath(resourceFilePath: string, manifestResult: { [key: string]: string }) {
|
|
88
|
-
const fileName = getResourceFileName(resourceFilePath);
|
|
89
|
-
if (manifestResult[fileName]) {
|
|
90
|
-
return resourceFilePath.replace(fileName, manifestResult[fileName]);
|
|
91
|
-
} else {
|
|
92
|
-
return resourceFilePath;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get static resource full path
|
|
98
|
-
* @param app PlanetApplication
|
|
99
|
-
* @param manifestResult manifest
|
|
100
|
-
*/
|
|
101
|
-
export function getScriptsAndStylesFullPaths(app: PlanetApplication, manifestResult?: { [key: string]: string }) {
|
|
102
|
-
let scripts = app.scripts || [];
|
|
103
|
-
let styles = app.styles || [];
|
|
104
|
-
// combine resource path by manifest
|
|
105
|
-
if (manifestResult) {
|
|
106
|
-
scripts = scripts.map(script => {
|
|
107
|
-
return buildResourceFilePath(script, manifestResult);
|
|
108
|
-
});
|
|
109
|
-
styles = styles.map(style => {
|
|
110
|
-
return buildResourceFilePath(style, manifestResult);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (app.resourcePathPrefix) {
|
|
114
|
-
scripts = scripts.map(script => {
|
|
115
|
-
return `${app.resourcePathPrefix}${script}`;
|
|
116
|
-
});
|
|
117
|
-
styles = styles.map(style => {
|
|
118
|
-
return `${app.resourcePathPrefix}${style}`;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
scripts: scripts,
|
|
123
|
-
styles: styles
|
|
124
|
-
};
|
|
125
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { TestBed } from '@angular/core/testing';
|
|
2
|
-
import { NgxPlanetModule } from './module';
|
|
3
|
-
import { NgModule } from '@angular/core';
|
|
4
|
-
import { Planet } from './planet';
|
|
5
|
-
import { clearGlobalPlanet } from './global-planet';
|
|
6
|
-
import { PlanetApplicationService } from './application/planet-application.service';
|
|
7
|
-
import { RouterTestingModule } from '@angular/router/testing';
|
|
8
|
-
|
|
9
|
-
const app1 = {
|
|
10
|
-
name: 'app1',
|
|
11
|
-
hostParent: '.host-selector',
|
|
12
|
-
selector: 'app1-root',
|
|
13
|
-
routerPathPrefix: '/app1',
|
|
14
|
-
hostClass: 'app1-host',
|
|
15
|
-
preload: false,
|
|
16
|
-
resourcePathPrefix: '/static/app1/',
|
|
17
|
-
styles: ['styles/main.css'],
|
|
18
|
-
scripts: ['vendor.js', 'main.js'],
|
|
19
|
-
loadSerial: false,
|
|
20
|
-
manifest: '',
|
|
21
|
-
extra: {
|
|
22
|
-
appName: '应用1'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
@NgModule({
|
|
27
|
-
imports: [NgxPlanetModule, RouterTestingModule.withRoutes([])]
|
|
28
|
-
})
|
|
29
|
-
class AppModule {}
|
|
30
|
-
|
|
31
|
-
@NgModule({
|
|
32
|
-
imports: [NgxPlanetModule.forRoot([app1]), RouterTestingModule.withRoutes([])]
|
|
33
|
-
})
|
|
34
|
-
class AppModuleWithApps {}
|
|
35
|
-
|
|
36
|
-
describe('NgxPlanetModule', () => {
|
|
37
|
-
afterEach(() => {
|
|
38
|
-
clearGlobalPlanet();
|
|
39
|
-
const applicationService = TestBed.inject(PlanetApplicationService);
|
|
40
|
-
applicationService['apps'] = [];
|
|
41
|
-
applicationService['appsMap'] = {};
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('basic', () => {
|
|
45
|
-
beforeEach(() => {
|
|
46
|
-
TestBed.configureTestingModule({
|
|
47
|
-
imports: [AppModule]
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('should get NgxPlanetModule', () => {
|
|
52
|
-
expect(TestBed.inject(NgxPlanetModule)).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should get planet', () => {
|
|
56
|
-
const planet: Planet = TestBed.inject(Planet);
|
|
57
|
-
expect(planet).toBeTruthy();
|
|
58
|
-
expect(planet.getApps()).toEqual([]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('forRoot', () => {
|
|
63
|
-
beforeEach(() => {
|
|
64
|
-
TestBed.configureTestingModule({
|
|
65
|
-
imports: [AppModuleWithApps]
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('should get NgxPlanetModule', () => {
|
|
70
|
-
expect(TestBed.inject(NgxPlanetModule)).toBeTruthy();
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('should register app1 when use forRoot', () => {
|
|
74
|
-
const planet: Planet = TestBed.inject(Planet);
|
|
75
|
-
expect(planet).toBeTruthy();
|
|
76
|
-
expect(planet.getApps()).toEqual([app1]);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { NgModule, ModuleWithProviders } from '@angular/core';
|
|
2
|
-
import { PlanetApplication, PLANET_APPLICATIONS } from './planet.class';
|
|
3
|
-
import { HttpClientModule } from '@angular/common/http';
|
|
4
|
-
import { EmptyComponent } from './empty/empty.component';
|
|
5
|
-
|
|
6
|
-
@NgModule({
|
|
7
|
-
declarations: [EmptyComponent],
|
|
8
|
-
entryComponents: [EmptyComponent],
|
|
9
|
-
imports: [HttpClientModule],
|
|
10
|
-
providers: [],
|
|
11
|
-
exports: [HttpClientModule, EmptyComponent]
|
|
12
|
-
})
|
|
13
|
-
export class NgxPlanetModule {
|
|
14
|
-
static forRoot(apps: PlanetApplication[]): ModuleWithProviders<NgxPlanetModule> {
|
|
15
|
-
return {
|
|
16
|
-
ngModule: NgxPlanetModule,
|
|
17
|
-
providers: [
|
|
18
|
-
{
|
|
19
|
-
provide: PLANET_APPLICATIONS,
|
|
20
|
-
useValue: apps
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { TestBed, tick, fakeAsync, waitForAsync } from '@angular/core/testing';
|
|
2
|
-
import { Planet } from './planet';
|
|
3
|
-
import { NgxPlanetModule } from './module';
|
|
4
|
-
import { Router, Event } from '@angular/router';
|
|
5
|
-
import { SwitchModes, PlanetRouterEvent, PlanetOptions } from './planet.class';
|
|
6
|
-
import { PlanetApplicationService } from './application/planet-application.service';
|
|
7
|
-
import { PlanetApplicationLoader } from './application/planet-application-loader';
|
|
8
|
-
import { EmptyComponent } from './empty/empty.component';
|
|
9
|
-
import { NgZone } from '@angular/core';
|
|
10
|
-
import { getApplicationService, getApplicationLoader, clearGlobalPlanet } from './global-planet';
|
|
11
|
-
import { RouterTestingModule } from '@angular/router/testing';
|
|
12
|
-
import { debug } from 'debug';
|
|
13
|
-
import { getDebugFactory, setDebugFactory } from './debug';
|
|
14
|
-
|
|
15
|
-
const app1 = {
|
|
16
|
-
name: 'app1',
|
|
17
|
-
hostParent: '.host-selector',
|
|
18
|
-
selector: 'app1-root',
|
|
19
|
-
routerPathPrefix: '/app1',
|
|
20
|
-
hostClass: 'app1-host',
|
|
21
|
-
preload: false,
|
|
22
|
-
switchMode: SwitchModes.default,
|
|
23
|
-
resourcePathPrefix: '/static/app1/',
|
|
24
|
-
styles: ['styles/main.css'],
|
|
25
|
-
scripts: ['vendor.js', 'main.js'],
|
|
26
|
-
loadSerial: false,
|
|
27
|
-
manifest: '',
|
|
28
|
-
extra: {
|
|
29
|
-
appName: '应用1'
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const app2 = {
|
|
34
|
-
name: 'app2',
|
|
35
|
-
hostParent: '.host-selector',
|
|
36
|
-
selector: 'app2-root',
|
|
37
|
-
routerPathPrefix: '/app2',
|
|
38
|
-
hostClass: 'app2-host',
|
|
39
|
-
preload: false,
|
|
40
|
-
switchMode: SwitchModes.coexist,
|
|
41
|
-
resourcePathPrefix: '/static/app2',
|
|
42
|
-
styles: ['styles/main.css'],
|
|
43
|
-
scripts: ['vendor.js', 'main.js'],
|
|
44
|
-
loadSerial: false,
|
|
45
|
-
extra: {
|
|
46
|
-
appName: '应用2'
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
describe('Planet', () => {
|
|
51
|
-
let planet: Planet;
|
|
52
|
-
let planetApplicationService: PlanetApplicationService;
|
|
53
|
-
let planetApplicationLoader: PlanetApplicationLoader;
|
|
54
|
-
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
TestBed.configureTestingModule({
|
|
57
|
-
imports: [
|
|
58
|
-
NgxPlanetModule,
|
|
59
|
-
RouterTestingModule.withRoutes([
|
|
60
|
-
{
|
|
61
|
-
path: '**',
|
|
62
|
-
component: EmptyComponent
|
|
63
|
-
}
|
|
64
|
-
])
|
|
65
|
-
]
|
|
66
|
-
});
|
|
67
|
-
planet = TestBed.inject(Planet);
|
|
68
|
-
planetApplicationService = getApplicationService();
|
|
69
|
-
planetApplicationLoader = getApplicationLoader();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
clearGlobalPlanet();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should create planet', () => {
|
|
77
|
-
expect(planet).toBeTruthy();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should register app1', () => {
|
|
81
|
-
const registerSpy = spyOn(planetApplicationService, 'register');
|
|
82
|
-
expect(registerSpy).not.toHaveBeenCalled();
|
|
83
|
-
planet.registerApp(app1);
|
|
84
|
-
expect(registerSpy).toHaveBeenCalled();
|
|
85
|
-
expect(registerSpy).toHaveBeenCalledWith(app1);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should register multiple apps', () => {
|
|
89
|
-
const registerSpy = spyOn(planetApplicationService, 'register');
|
|
90
|
-
expect(registerSpy).not.toHaveBeenCalled();
|
|
91
|
-
planet.registerApps([app1, app2]);
|
|
92
|
-
expect(registerSpy).toHaveBeenCalled();
|
|
93
|
-
expect(registerSpy).toHaveBeenCalledWith([app1, app2]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should unregister app', () => {
|
|
97
|
-
const unregisterSpy = spyOn(planetApplicationService, 'unregister');
|
|
98
|
-
expect(unregisterSpy).not.toHaveBeenCalled();
|
|
99
|
-
planet.unregisterApp('app1');
|
|
100
|
-
expect(unregisterSpy).toHaveBeenCalled();
|
|
101
|
-
expect(unregisterSpy).toHaveBeenCalledWith('app1');
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('should get apps', () => {
|
|
105
|
-
const getAppsSpy = spyOn(planetApplicationService, 'getApps');
|
|
106
|
-
getAppsSpy.and.returnValue([app1, app2]);
|
|
107
|
-
expect(getAppsSpy).not.toHaveBeenCalled();
|
|
108
|
-
const apps = planet.getApps();
|
|
109
|
-
expect(getAppsSpy).toHaveBeenCalled();
|
|
110
|
-
expect(apps).toEqual([app1, app2]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should set options success', () => {
|
|
114
|
-
const setOptionsSpy = spyOn(planetApplicationLoader, 'setOptions');
|
|
115
|
-
expect(setOptionsSpy).not.toHaveBeenCalled();
|
|
116
|
-
const options: PlanetOptions = {
|
|
117
|
-
switchMode: SwitchModes.coexist,
|
|
118
|
-
errorHandler: () => {},
|
|
119
|
-
debugFactory: debug
|
|
120
|
-
};
|
|
121
|
-
planet.setOptions(options);
|
|
122
|
-
expect(setOptionsSpy).toHaveBeenCalled();
|
|
123
|
-
expect(setOptionsSpy).toHaveBeenCalledWith(options);
|
|
124
|
-
expect(getDebugFactory()).toEqual(debug);
|
|
125
|
-
setDebugFactory(null);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should reroute when start or navigateByUrl', fakeAsync(() => {
|
|
129
|
-
const router: Router = TestBed.inject(Router);
|
|
130
|
-
const ngZone: NgZone = TestBed.inject(NgZone);
|
|
131
|
-
const rerouteSpy = spyOn(planetApplicationLoader, 'reroute');
|
|
132
|
-
expect(rerouteSpy).not.toHaveBeenCalled();
|
|
133
|
-
planet.start();
|
|
134
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(1);
|
|
135
|
-
|
|
136
|
-
ngZone.run(() => {
|
|
137
|
-
router.navigateByUrl('/app1/dashboard');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
tick();
|
|
141
|
-
|
|
142
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(2);
|
|
143
|
-
expect(rerouteSpy).toHaveBeenCalledWith({
|
|
144
|
-
url: '/app1/dashboard'
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
ngZone.run(() => {
|
|
148
|
-
router.navigateByUrl('/app1/users');
|
|
149
|
-
});
|
|
150
|
-
tick();
|
|
151
|
-
|
|
152
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(3);
|
|
153
|
-
expect(rerouteSpy).toHaveBeenCalledWith({
|
|
154
|
-
url: '/app1/users'
|
|
155
|
-
});
|
|
156
|
-
}));
|
|
157
|
-
|
|
158
|
-
it('should load app when redirect to app url "users"', fakeAsync(() => {
|
|
159
|
-
const router: Router = TestBed.inject(Router);
|
|
160
|
-
const ngZone: NgZone = TestBed.inject(NgZone);
|
|
161
|
-
const rerouteSpy = spyOn(planetApplicationLoader, 'reroute');
|
|
162
|
-
router.resetConfig([
|
|
163
|
-
{
|
|
164
|
-
path: '',
|
|
165
|
-
redirectTo: 'users',
|
|
166
|
-
pathMatch: 'full'
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
path: 'redirect-to-users',
|
|
170
|
-
redirectTo: 'users',
|
|
171
|
-
pathMatch: 'full'
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
path: 'users',
|
|
175
|
-
component: EmptyComponent
|
|
176
|
-
}
|
|
177
|
-
]);
|
|
178
|
-
let planetRouterEvent!: PlanetRouterEvent;
|
|
179
|
-
rerouteSpy.and.callFake(function(event) {
|
|
180
|
-
planetRouterEvent = event;
|
|
181
|
-
});
|
|
182
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(0);
|
|
183
|
-
planet.start();
|
|
184
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(1);
|
|
185
|
-
ngZone.run(() => {
|
|
186
|
-
router.navigateByUrl('/redirect-to-users');
|
|
187
|
-
});
|
|
188
|
-
tick();
|
|
189
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(2);
|
|
190
|
-
expect(planetRouterEvent.url).toEqual('/users');
|
|
191
|
-
}));
|
|
192
|
-
|
|
193
|
-
it('should reroute not be call when planet stop', fakeAsync(() => {
|
|
194
|
-
const router: Router = TestBed.inject(Router);
|
|
195
|
-
const ngZone: NgZone = TestBed.inject(NgZone);
|
|
196
|
-
const rerouteSpy = spyOn(planetApplicationLoader, 'reroute');
|
|
197
|
-
expect(rerouteSpy).not.toHaveBeenCalled();
|
|
198
|
-
planet.start();
|
|
199
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(1);
|
|
200
|
-
|
|
201
|
-
ngZone.run(() => {
|
|
202
|
-
router.navigateByUrl('/app1/dashboard');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
tick();
|
|
206
|
-
|
|
207
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(2);
|
|
208
|
-
expect(rerouteSpy).toHaveBeenCalledWith({
|
|
209
|
-
url: '/app1/dashboard'
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
planet.stop();
|
|
213
|
-
|
|
214
|
-
ngZone.run(() => {
|
|
215
|
-
router.navigateByUrl('/app1/users');
|
|
216
|
-
});
|
|
217
|
-
tick();
|
|
218
|
-
|
|
219
|
-
// rerouteSpy should not be call
|
|
220
|
-
// url should not change
|
|
221
|
-
expect(rerouteSpy).toHaveBeenCalledTimes(2);
|
|
222
|
-
expect(rerouteSpy).toHaveBeenCalledWith({
|
|
223
|
-
url: '/app1/dashboard'
|
|
224
|
-
});
|
|
225
|
-
}));
|
|
226
|
-
});
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { Injectable, Inject, Optional, Injector } from '@angular/core';
|
|
2
|
-
import { NavigationEnd, RouterEvent, Router } from '@angular/router';
|
|
3
|
-
import { PlanetOptions, PlanetApplication, PLANET_APPLICATIONS } from './planet.class';
|
|
4
|
-
import { PlanetApplicationService } from './application/planet-application.service';
|
|
5
|
-
import {
|
|
6
|
-
PlanetApplicationLoader,
|
|
7
|
-
AppsLoadingStartEvent,
|
|
8
|
-
AppStatusChangeEvent
|
|
9
|
-
} from './application/planet-application-loader';
|
|
10
|
-
import { Observable, Subscription } from 'rxjs';
|
|
11
|
-
import { filter, startWith, distinctUntilChanged, map } from 'rxjs/operators';
|
|
12
|
-
import {
|
|
13
|
-
setPortalApplicationData,
|
|
14
|
-
setApplicationLoader,
|
|
15
|
-
setApplicationService,
|
|
16
|
-
getApplicationLoader,
|
|
17
|
-
getApplicationService
|
|
18
|
-
} from './global-planet';
|
|
19
|
-
import { setDebugFactory } from './debug';
|
|
20
|
-
|
|
21
|
-
@Injectable({
|
|
22
|
-
providedIn: 'root'
|
|
23
|
-
})
|
|
24
|
-
export class Planet {
|
|
25
|
-
private get planetApplicationLoader(): PlanetApplicationLoader {
|
|
26
|
-
return getApplicationLoader();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
private get planetApplicationService() {
|
|
30
|
-
return getApplicationService();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public get loadingDone() {
|
|
34
|
-
return this.planetApplicationLoader.loadingDone;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
public get appStatusChange(): Observable<AppStatusChangeEvent> {
|
|
38
|
-
return this.planetApplicationLoader.appStatusChange;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public get appsLoadingStart(): Observable<AppsLoadingStartEvent> {
|
|
42
|
-
return this.planetApplicationLoader.appsLoadingStart;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private subscription?: Subscription;
|
|
46
|
-
|
|
47
|
-
constructor(
|
|
48
|
-
private injector: Injector,
|
|
49
|
-
private router: Router,
|
|
50
|
-
@Inject(PLANET_APPLICATIONS) @Optional() planetApplications: PlanetApplication[]
|
|
51
|
-
) {
|
|
52
|
-
if (!this.planetApplicationLoader) {
|
|
53
|
-
setApplicationLoader(this.injector.get(PlanetApplicationLoader));
|
|
54
|
-
}
|
|
55
|
-
if (!this.planetApplicationService) {
|
|
56
|
-
setApplicationService(this.injector.get(PlanetApplicationService));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (planetApplications) {
|
|
60
|
-
this.registerApps(planetApplications);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
setOptions(options: Partial<PlanetOptions>) {
|
|
65
|
-
this.planetApplicationLoader.setOptions(options);
|
|
66
|
-
if (options.debugFactory) {
|
|
67
|
-
setDebugFactory(options.debugFactory);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
setPortalAppData<T>(data: T) {
|
|
72
|
-
setPortalApplicationData(data);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
registerApp<TExtra>(app: PlanetApplication<TExtra>) {
|
|
76
|
-
this.planetApplicationService.register(app);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
registerApps<TExtra>(apps: PlanetApplication<TExtra>[]) {
|
|
80
|
-
this.planetApplicationService.register(apps);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
unregisterApp(name: string) {
|
|
84
|
-
this.planetApplicationService.unregister(name);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getApps() {
|
|
88
|
-
return this.planetApplicationService.getApps();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
start() {
|
|
92
|
-
this.subscription = (this.router.events as Observable<RouterEvent>)
|
|
93
|
-
.pipe(
|
|
94
|
-
filter(event => {
|
|
95
|
-
return event instanceof NavigationEnd;
|
|
96
|
-
}),
|
|
97
|
-
map(event => {
|
|
98
|
-
return (event as NavigationEnd).urlAfterRedirects || event.url;
|
|
99
|
-
}),
|
|
100
|
-
startWith(location.pathname),
|
|
101
|
-
distinctUntilChanged()
|
|
102
|
-
)
|
|
103
|
-
.subscribe((url: string) => {
|
|
104
|
-
this.planetApplicationLoader.reroute({
|
|
105
|
-
url: url
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
stop() {
|
|
111
|
-
this.subscription?.unsubscribe();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const PLANET_SANDBOX_WINDOW_WHITELIST = window['___PLANET_SANDBOX_WINDOW_WHITELIST___'];
|
|
2
|
-
export const PLANET_SANDBOX_DOCUMENT_WHITELIST = window['___PLANET_SANDBOX_DOCUMENT_WHITELIST___'];
|
|
3
|
-
export const SANDBOX_INSTANCE = Symbol.for('PLANET_SANDBOX_INSTANCE');
|
|
4
|
-
export const RAW_NODE = Symbol.for('PLANET_RAW_NODE');
|
|
5
|
-
export const WINDOW_BIND_FN = Symbol.for('PLANET_WINDOW_BIND_FN');
|
|
6
|
-
export const DOCUMENT_BIND_FN = Symbol.for('PLANET_DOCUMENT_BIND_FN');
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Global } from './types';
|
|
2
|
-
|
|
3
|
-
export function execScript(code: string, url: string, global: Global, strictGlobal: boolean) {
|
|
4
|
-
const sourceUrl = '//# sourceURL='.concat(url, '\n');
|
|
5
|
-
const window = (0, eval)('window');
|
|
6
|
-
window.tempGlobal = global;
|
|
7
|
-
code = strictGlobal
|
|
8
|
-
? ';(function(window, self, globalThis){with(window){;'
|
|
9
|
-
.concat(code, '\n')
|
|
10
|
-
.concat(
|
|
11
|
-
sourceUrl,
|
|
12
|
-
'}}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);'
|
|
13
|
-
)
|
|
14
|
-
: ';(function(window, self, globalThis){;'
|
|
15
|
-
.concat(code, '\n')
|
|
16
|
-
.concat(
|
|
17
|
-
sourceUrl,
|
|
18
|
-
'}).bind(window.tempGlobal)(window.tempGlobal, window.tempGlobal, window.tempGlobal);'
|
|
19
|
-
);
|
|
20
|
-
(0, eval)(code);
|
|
21
|
-
delete window.tempGlobal;
|
|
22
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { SandboxOptions } from './sandbox';
|
|
2
|
-
import { ProxySandbox } from './proxy/proxy-sandbox';
|
|
3
|
-
import { SnapshotSandbox } from './snapshot/snapshot-sandbox';
|
|
4
|
-
import { SANDBOX_INSTANCE } from './constants';
|
|
5
|
-
|
|
6
|
-
export { Sandbox } from './sandbox';
|
|
7
|
-
|
|
8
|
-
const defaultOptions: Partial<SandboxOptions> = {
|
|
9
|
-
strictGlobal: false
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function createSandbox(app: string, options?: SandboxOptions) {
|
|
13
|
-
options = Object.assign({}, defaultOptions, options || {});
|
|
14
|
-
|
|
15
|
-
if (window.Proxy) {
|
|
16
|
-
return new ProxySandbox(app, options);
|
|
17
|
-
} else {
|
|
18
|
-
return new SnapshotSandbox(app, options);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getSandboxInstance() {
|
|
23
|
-
return window[SANDBOX_INSTANCE];
|
|
24
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ProxyDocument } from '../proxies/document';
|
|
2
|
-
import { SandboxPatchHandler } from '../types';
|
|
3
|
-
|
|
4
|
-
export function documentPatch(): SandboxPatchHandler {
|
|
5
|
-
const proxyDocument = new ProxyDocument();
|
|
6
|
-
const { document, Document } = proxyDocument.create();
|
|
7
|
-
return {
|
|
8
|
-
rewrite: {
|
|
9
|
-
document,
|
|
10
|
-
Document
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { SandboxPatchHandler, ProxySandboxInstance } from '../types';
|
|
2
|
-
import { Observable, Subscription } from 'rxjs';
|
|
3
|
-
|
|
4
|
-
export function eventListenerPatch(sandbox: ProxySandboxInstance): SandboxPatchHandler {
|
|
5
|
-
const rawAddEventListener = window.addEventListener;
|
|
6
|
-
const rawRemoveEventListener = window.removeEventListener;
|
|
7
|
-
const listenerSubscriptions = new Map<EventListenerOrEventListenerObject, Subscription>();
|
|
8
|
-
|
|
9
|
-
function addEventListener(
|
|
10
|
-
type: string,
|
|
11
|
-
listener: EventListenerOrEventListenerObject,
|
|
12
|
-
options?: boolean | AddEventListenerOptions
|
|
13
|
-
) {
|
|
14
|
-
const observable = new Observable(() => {
|
|
15
|
-
rawAddEventListener.call(this, type, listener, options);
|
|
16
|
-
return () => {
|
|
17
|
-
rawRemoveEventListener.call(this, type, listener, options);
|
|
18
|
-
};
|
|
19
|
-
});
|
|
20
|
-
const subscription = observable.subscribe(() => {});
|
|
21
|
-
listenerSubscriptions.set(listener, subscription);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function removeEventListener(type: string, listener: EventListenerOrEventListenerObject) {
|
|
25
|
-
const subscription = listenerSubscriptions.get(listener);
|
|
26
|
-
if (subscription) {
|
|
27
|
-
subscription.unsubscribe();
|
|
28
|
-
listenerSubscriptions.delete(listener);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
rewrite: {
|
|
34
|
-
addEventListener: addEventListener.bind(window),
|
|
35
|
-
removeEventListener: removeEventListener.bind(window)
|
|
36
|
-
},
|
|
37
|
-
init() {
|
|
38
|
-
const fakeDocument = sandbox.global.document;
|
|
39
|
-
if (fakeDocument) {
|
|
40
|
-
fakeDocument.addEventListener = addEventListener.bind(document);
|
|
41
|
-
fakeDocument.removeEventListener = removeEventListener.bind(document);
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
destroy() {
|
|
45
|
-
listenerSubscriptions.forEach(subscription => subscription.unsubscribe());
|
|
46
|
-
listenerSubscriptions.clear();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|