@worktile/planet 10.0.0 → 12.1.1

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 (256) hide show
  1. package/.all-contributorsrc +84 -0
  2. package/.circleci/config.yml +17 -0
  3. package/.coveralls.yml +1 -0
  4. package/.docgeni/public/assets/favicon.ico +0 -0
  5. package/.docgeni/public/index.html +13 -0
  6. package/.docgenirc.js +35 -0
  7. package/.dockerignore +1 -0
  8. package/.editorconfig +22 -0
  9. package/.github/FUNDING.yml +12 -0
  10. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  11. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  12. package/.prettierignore +7 -0
  13. package/.prettierrc +28 -0
  14. package/.travis.yml +26 -0
  15. package/.wpmrc.js +11 -0
  16. package/CHANGELOG.md +391 -0
  17. package/CODE_OF_CONDUCT.md +76 -0
  18. package/Dockerfile +11 -0
  19. package/LICENSE +21 -0
  20. package/README.md +348 -0
  21. package/README.zh-CN.md +307 -0
  22. package/SECURITY.md +21 -0
  23. package/angular.json +373 -0
  24. package/commitlint.config.js +6 -0
  25. package/docs/api/defineApplication.md +46 -0
  26. package/docs/api/globalEventDispatcher.md +51 -0
  27. package/docs/api/index.md +5 -0
  28. package/docs/api/planet.md +117 -0
  29. package/docs/guides/getting-started.md +174 -0
  30. package/docs/guides/index.md +5 -0
  31. package/docs/guides/intro.md +216 -0
  32. package/examples/app1/browserslist +11 -0
  33. package/examples/app1/extra-webpack.config.js +33 -0
  34. package/examples/app1/karma.conf.js +31 -0
  35. package/examples/app1/postcss.config.js +1 -0
  36. package/examples/app1/src/app/app.module.ts +44 -0
  37. package/examples/app1/src/app/app.routing.ts +49 -0
  38. package/examples/app1/src/app/counter.service.ts +16 -0
  39. package/examples/app1/src/app/dashboard/dashboard.component.html +51 -0
  40. package/examples/app1/src/app/dashboard/dashboard.component.ts +70 -0
  41. package/examples/app1/src/app/detail/detail.component.html +8 -0
  42. package/examples/app1/src/app/detail/detail.component.ts +18 -0
  43. package/examples/app1/src/app/overlay.ts +26 -0
  44. package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +10 -0
  45. package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +41 -0
  46. package/examples/app1/src/app/projects/projects.component.ts +33 -0
  47. package/examples/app1/src/app/root/root.component.css +3 -0
  48. package/examples/app1/src/app/root/root.component.html +16 -0
  49. package/examples/app1/src/app/root/root.component.ts +35 -0
  50. package/examples/app1/src/app/services/initialized-data.resolver.ts +15 -0
  51. package/examples/app1/src/app/shared.module.ts +57 -0
  52. package/examples/app1/src/app/user/detail/user-detail.component.html +5 -0
  53. package/examples/app1/src/app/user/detail/user-detail.component.ts +20 -0
  54. package/examples/app1/src/app/user/user-list.component.html +7 -0
  55. package/examples/app1/src/app/user/user-list.component.ts +20 -0
  56. package/examples/app1/src/app/user/user.module.ts +31 -0
  57. package/examples/app1/src/assets/.gitkeep +0 -0
  58. package/examples/app1/src/assets/github.png +0 -0
  59. package/examples/app1/src/assets/main.css +3 -0
  60. package/examples/app1/src/environments/environment.prod.ts +3 -0
  61. package/examples/app1/src/environments/environment.ts +16 -0
  62. package/examples/app1/src/favicon.ico +0 -0
  63. package/examples/app1/src/index.html +14 -0
  64. package/examples/app1/src/main.ts +35 -0
  65. package/examples/app1/src/polyfills.ts +84 -0
  66. package/examples/app1/src/styles.scss +35 -0
  67. package/examples/app1/src/test.ts +14 -0
  68. package/examples/app1/temp.js +221 -0
  69. package/examples/app1/tsconfig.app.json +10 -0
  70. package/examples/app1/tsconfig.spec.json +18 -0
  71. package/examples/app1/tslint.json +17 -0
  72. package/examples/app1/webpack.config.js +127 -0
  73. package/examples/app2/browserslist +11 -0
  74. package/examples/app2/extra-webpack.config.js +32 -0
  75. package/examples/app2/karma.conf.js +31 -0
  76. package/examples/app2/src/app/app.module.ts +90 -0
  77. package/examples/app2/src/app/dashboard/dashboard.component.html +21 -0
  78. package/examples/app2/src/app/dashboard/dashboard.component.ts +27 -0
  79. package/examples/app2/src/app/overlay.ts +26 -0
  80. package/examples/app2/src/app/projects/detail/detail.component.html +16 -0
  81. package/examples/app2/src/app/projects/detail/detail.component.ts +21 -0
  82. package/examples/app2/src/app/projects/project-list.component.html +29 -0
  83. package/examples/app2/src/app/projects/project-list.component.ts +58 -0
  84. package/examples/app2/src/app/projects/project.resolver.ts +15 -0
  85. package/examples/app2/src/app/projects/projects.service.ts +28 -0
  86. package/examples/app2/src/app/projects/tasks/tasks.component.html +10 -0
  87. package/examples/app2/src/app/projects/tasks/tasks.component.ts +16 -0
  88. package/examples/app2/src/app/projects/view/view.component.html +1 -0
  89. package/examples/app2/src/app/projects/view/view.component.ts +20 -0
  90. package/examples/app2/src/app/root/root.component.html +14 -0
  91. package/examples/app2/src/app/root/root.component.scss +12 -0
  92. package/examples/app2/src/app/root/root.component.ts +28 -0
  93. package/examples/app2/src/app/shared.module.ts +59 -0
  94. package/examples/app2/src/assets/.gitkeep +0 -0
  95. package/examples/app2/src/environments/environment.prod.ts +3 -0
  96. package/examples/app2/src/environments/environment.ts +16 -0
  97. package/examples/app2/src/favicon.ico +0 -0
  98. package/examples/app2/src/index.html +14 -0
  99. package/examples/app2/src/main.ts +36 -0
  100. package/examples/app2/src/polyfills.ts +84 -0
  101. package/examples/app2/src/styles.scss +28 -0
  102. package/examples/app2/src/test.ts +14 -0
  103. package/examples/app2/tsconfig.app.json +10 -0
  104. package/examples/app2/tsconfig.spec.json +18 -0
  105. package/examples/app2/tslint.json +7 -0
  106. package/examples/app2/webpack.config.js +92 -0
  107. package/examples/common/app-root-context.ts +10 -0
  108. package/examples/common/cache.ts +82 -0
  109. package/examples/common/index.ts +13 -0
  110. package/examples/common/module.ts +10 -0
  111. package/examples/common/overlay-container.service.ts +28 -0
  112. package/examples/common/section-card/section-card.component.html +5 -0
  113. package/examples/common/section-card/section-card.component.scss +15 -0
  114. package/examples/common/section-card/section-card.component.ts +11 -0
  115. package/examples/common/utils.ts +0 -0
  116. package/examples/portal/src/app/a-detail/a-detail.component.html +8 -0
  117. package/examples/portal/src/app/a-detail/a-detail.component.ts +18 -0
  118. package/examples/portal/src/app/about/about.component.html +27 -0
  119. package/examples/portal/src/app/about/about.component.scss +0 -0
  120. package/examples/portal/src/app/about/about.component.spec.ts +26 -0
  121. package/examples/portal/src/app/about/about.component.ts +26 -0
  122. package/examples/portal/src/app/app-routing.module.ts +57 -0
  123. package/examples/portal/src/app/app.component.html +73 -0
  124. package/examples/portal/src/app/app.component.scss +58 -0
  125. package/examples/portal/src/app/app.component.spec.ts +33 -0
  126. package/examples/portal/src/app/app.component.ts +111 -0
  127. package/examples/portal/src/app/app.module.ts +64 -0
  128. package/examples/portal/src/app/custom-settings.service.ts +44 -0
  129. package/examples/portal/src/app/overlay.ts +26 -0
  130. package/examples/portal/src/app/settings/settings.component.html +31 -0
  131. package/examples/portal/src/app/settings/settings.component.scss +3 -0
  132. package/examples/portal/src/app/settings/settings.component.ts +43 -0
  133. package/examples/portal/src/assets/.gitkeep +0 -0
  134. package/examples/portal/src/assets/apps.json +29 -0
  135. package/examples/portal/src/assets/icons/sprite.defs.svg +1 -0
  136. package/examples/portal/src/assets/images/logo.svg +16 -0
  137. package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
  138. package/examples/portal/src/browserslist +11 -0
  139. package/examples/portal/src/environments/environment.prod.ts +3 -0
  140. package/examples/portal/src/environments/environment.ts +16 -0
  141. package/examples/portal/src/extra-webpack.config.js +32 -0
  142. package/examples/portal/src/favicon.ico +0 -0
  143. package/examples/portal/src/index.html +14 -0
  144. package/examples/portal/src/karma.conf.js +31 -0
  145. package/examples/portal/src/main.ts +18 -0
  146. package/examples/portal/src/polyfills.ts +84 -0
  147. package/examples/portal/src/reboot.scss +14 -0
  148. package/examples/portal/src/styles.scss +14 -0
  149. package/examples/portal/src/test.ts +14 -0
  150. package/examples/portal/src/tsconfig.app.json +10 -0
  151. package/examples/portal/src/tsconfig.spec.json +9 -0
  152. package/examples/portal/src/tslint.json +7 -0
  153. package/extra-webpack.config.js +5 -0
  154. package/nginx.conf +17 -0
  155. package/package.json +120 -15
  156. package/packages/planet/karma.conf.js +37 -0
  157. package/packages/planet/ng-package.json +7 -0
  158. package/packages/planet/package.json +10 -0
  159. package/packages/planet/src/application/planet-application-loader.spec.ts +1102 -0
  160. package/packages/planet/src/application/planet-application-loader.ts +549 -0
  161. package/packages/planet/src/application/planet-application-ref.spec.ts +233 -0
  162. package/packages/planet/src/application/planet-application-ref.ts +131 -0
  163. package/packages/planet/src/application/planet-application.service.spec.ts +145 -0
  164. package/packages/planet/src/application/planet-application.service.ts +88 -0
  165. package/packages/planet/src/application/portal-application.spec.ts +53 -0
  166. package/packages/planet/src/application/portal-application.ts +28 -0
  167. package/packages/planet/src/assets-loader.spec.ts +689 -0
  168. package/packages/planet/src/assets-loader.ts +247 -0
  169. package/packages/planet/src/component/planet-component-loader.spec.ts +187 -0
  170. package/packages/planet/src/component/planet-component-loader.ts +173 -0
  171. package/{component/planet-component-ref.d.ts → packages/planet/src/component/planet-component-ref.ts} +3 -2
  172. package/{component/plant-component.config.d.ts → packages/planet/src/component/plant-component.config.ts} +4 -3
  173. package/packages/planet/src/debug.spec.ts +58 -0
  174. package/packages/planet/src/debug.ts +66 -0
  175. package/packages/planet/src/empty/empty.component.spec.ts +34 -0
  176. package/packages/planet/src/empty/empty.component.ts +7 -0
  177. package/packages/planet/src/global-event-dispatcher.spec.ts +81 -0
  178. package/packages/planet/src/global-event-dispatcher.ts +82 -0
  179. package/packages/planet/src/global-planet.spec.ts +39 -0
  180. package/packages/planet/src/global-planet.ts +73 -0
  181. package/packages/planet/src/helpers.spec.ts +242 -0
  182. package/packages/planet/src/helpers.ts +125 -0
  183. package/packages/planet/src/module.spec.ts +79 -0
  184. package/packages/planet/src/module.ts +25 -0
  185. package/packages/planet/src/planet.class.ts +59 -0
  186. package/packages/planet/src/planet.spec.ts +226 -0
  187. package/packages/planet/src/planet.ts +113 -0
  188. package/{public-api.d.ts → packages/planet/src/public-api.ts} +4 -0
  189. package/packages/planet/src/sandbox/constants.ts +6 -0
  190. package/packages/planet/src/sandbox/exec.ts +22 -0
  191. package/packages/planet/src/sandbox/index.ts +24 -0
  192. package/packages/planet/src/sandbox/proxy/patches/document.ts +13 -0
  193. package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +49 -0
  194. package/packages/planet/src/sandbox/proxy/patches/index.ts +13 -0
  195. package/packages/planet/src/sandbox/proxy/patches/storage.ts +53 -0
  196. package/packages/planet/src/sandbox/proxy/patches/timer.ts +50 -0
  197. package/packages/planet/src/sandbox/proxy/proxies/common.ts +137 -0
  198. package/packages/planet/src/sandbox/proxy/proxies/document.ts +140 -0
  199. package/packages/planet/src/sandbox/proxy/proxies/window.ts +176 -0
  200. package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +59 -0
  201. package/packages/planet/src/sandbox/proxy/types.ts +20 -0
  202. package/packages/planet/src/sandbox/sandbox.ts +20 -0
  203. package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +12 -0
  204. package/packages/planet/src/sandbox/types.ts +1 -0
  205. package/packages/planet/src/test.ts +16 -0
  206. package/packages/planet/src/testing/app1.module.ts +34 -0
  207. package/packages/planet/src/testing/app2.module.ts +24 -0
  208. package/packages/planet/src/testing/applications.ts +58 -0
  209. package/packages/planet/src/testing/index.ts +2 -0
  210. package/packages/planet/src/testing/utils.ts +31 -0
  211. package/packages/planet/tsconfig.lib.json +27 -0
  212. package/packages/planet/tsconfig.lib.prod.json +9 -0
  213. package/packages/planet/tsconfig.spec.json +17 -0
  214. package/packages/planet/tslint.json +7 -0
  215. package/postcss.config.js +3 -0
  216. package/proxy.conf.js +15 -0
  217. package/tsconfig.json +23 -0
  218. package/tslint.json +80 -0
  219. package/application/planet-application-loader.d.ts +0 -68
  220. package/application/planet-application-ref.d.ts +0 -32
  221. package/application/planet-application.service.d.ts +0 -18
  222. package/application/portal-application.d.ts +0 -14
  223. package/assets-loader.d.ts +0 -23
  224. package/bundles/worktile-planet.umd.js +0 -1670
  225. package/bundles/worktile-planet.umd.js.map +0 -1
  226. package/bundles/worktile-planet.umd.min.js +0 -16
  227. package/bundles/worktile-planet.umd.min.js.map +0 -1
  228. package/component/planet-component-loader.d.ts +0 -27
  229. package/empty/empty.component.d.ts +0 -2
  230. package/esm2015/application/planet-application-loader.js +0 -417
  231. package/esm2015/application/planet-application-ref.js +0 -86
  232. package/esm2015/application/planet-application.service.js +0 -87
  233. package/esm2015/application/portal-application.js +0 -16
  234. package/esm2015/assets-loader.js +0 -165
  235. package/esm2015/component/planet-component-loader.js +0 -157
  236. package/esm2015/component/planet-component-ref.js +0 -3
  237. package/esm2015/component/plant-component.config.js +0 -7
  238. package/esm2015/empty/empty.component.js +0 -10
  239. package/esm2015/global-event-dispatcher.js +0 -71
  240. package/esm2015/global-planet.js +0 -51
  241. package/esm2015/helpers.js +0 -116
  242. package/esm2015/module.js +0 -27
  243. package/esm2015/planet.class.js +0 -9
  244. package/esm2015/planet.js +0 -86
  245. package/esm2015/public-api.js +0 -18
  246. package/esm2015/worktile-planet.js +0 -6
  247. package/fesm2015/worktile-planet.js +0 -1257
  248. package/fesm2015/worktile-planet.js.map +0 -1
  249. package/global-event-dispatcher.d.ts +0 -19
  250. package/global-planet.d.ts +0 -22
  251. package/helpers.d.ts +0 -37
  252. package/module.d.ts +0 -5
  253. package/planet.class.d.ts +0 -34
  254. package/planet.d.ts +0 -24
  255. package/worktile-planet.d.ts +0 -5
  256. package/worktile-planet.metadata.json +0 -1
@@ -1,1257 +0,0 @@
1
- import { InjectionToken, ɵɵdefineInjectable, ɵɵinject, Injectable, NgZone, INJECTOR, ApplicationRef, Injector, Inject, Optional, Component, NgModule, NgModuleRef } from '@angular/core';
2
- import { Router, NavigationEnd } from '@angular/router';
3
- import { HttpClient, HttpClientModule } from '@angular/common/http';
4
- import { map, concatAll, switchMap, take, shareReplay, filter, distinctUntilChanged, tap, catchError, share, startWith, delayWhen, finalize } from 'rxjs/operators';
5
- import { of, Observable, concat, forkJoin, from, Subject, timer } from 'rxjs';
6
- import { PortalInjector, DomPortalOutlet, ComponentPortal } from '@angular/cdk/portal';
7
- import { DOCUMENT } from '@angular/common';
8
-
9
- var SwitchModes;
10
- (function (SwitchModes) {
11
- SwitchModes["default"] = "default";
12
- SwitchModes["coexist"] = "coexist";
13
- })(SwitchModes || (SwitchModes = {}));
14
- const PLANET_APPLICATIONS = new InjectionToken('PLANET_APPLICATIONS');
15
-
16
- const ELEMENT_NODE_TYPE = 1;
17
- function hashCode(str) {
18
- let hash = 0;
19
- let chr;
20
- if (str.length === 0) {
21
- return hash;
22
- }
23
- for (let i = 0; i < str.length; i++) {
24
- chr = str.charCodeAt(i);
25
- hash = (hash << 5) - hash + chr;
26
- hash |= 0; // Convert to 32bit integer
27
- }
28
- return hash;
29
- }
30
- function getHTMLElement(selector) {
31
- if (selector instanceof HTMLElement) {
32
- return selector;
33
- }
34
- else {
35
- return document.querySelector(selector);
36
- }
37
- }
38
- function getTagNameByTemplate(template) {
39
- const element = createElementByTemplate(template);
40
- return element ? element.nodeName : null;
41
- }
42
- function createElementByTemplate(template) {
43
- if (!template) {
44
- return null;
45
- }
46
- const element = document.createRange().createContextualFragment(template).firstChild;
47
- if (element.nodeType === ELEMENT_NODE_TYPE) {
48
- return element;
49
- }
50
- else {
51
- throw new Error(`invalid template '${template}'`);
52
- }
53
- }
54
- function coerceArray(value) {
55
- return Array.isArray(value) ? value : [value];
56
- }
57
- function isEmpty(value) {
58
- if (!value || value.length === 0) {
59
- return true;
60
- }
61
- else {
62
- return false;
63
- }
64
- }
65
- function isFunction(value) {
66
- const type = typeof value;
67
- return !!value && type === 'function';
68
- }
69
- /**
70
- * Get file name from path
71
- * 1. "main.js" => "main.js"
72
- * 2. "assets/scripts/main.js" => "main.js"
73
- * @param path path
74
- */
75
- function getResourceFileName(path) {
76
- const lastSlashIndex = path.lastIndexOf('/');
77
- if (lastSlashIndex >= 0) {
78
- return path.slice(lastSlashIndex + 1);
79
- }
80
- else {
81
- return path;
82
- }
83
- }
84
- /**
85
- * Build resource path by manifest
86
- * if manifest is { "main.js": "main.h2sh23abee.js"}
87
- * 1. "main.js" => "main.h2sh23abee.js"
88
- * 2. "assets/scripts/main.js" =>"assets/scripts/main.h2sh23abee.js"
89
- * @param resourceFilePath Resource File Path
90
- * @param manifestResult manifest
91
- */
92
- function buildResourceFilePath(resourceFilePath, manifestResult) {
93
- const fileName = getResourceFileName(resourceFilePath);
94
- if (manifestResult[fileName]) {
95
- return resourceFilePath.replace(fileName, manifestResult[fileName]);
96
- }
97
- else {
98
- return resourceFilePath;
99
- }
100
- }
101
- /**
102
- * Get static resource full path
103
- * @param app PlanetApplication
104
- * @param manifestResult manifest
105
- */
106
- function getScriptsAndStylesFullPaths(app, manifestResult) {
107
- let scripts = app.scripts || [];
108
- let styles = app.styles || [];
109
- // combine resource path by manifest
110
- if (manifestResult) {
111
- scripts = scripts.map(script => {
112
- return buildResourceFilePath(script, manifestResult);
113
- });
114
- styles = styles.map(style => {
115
- return buildResourceFilePath(style, manifestResult);
116
- });
117
- }
118
- if (app.resourcePathPrefix) {
119
- scripts = scripts.map(script => {
120
- return `${app.resourcePathPrefix}${script}`;
121
- });
122
- styles = styles.map(style => {
123
- return `${app.resourcePathPrefix}${style}`;
124
- });
125
- }
126
- return {
127
- scripts: scripts,
128
- styles: styles
129
- };
130
- }
131
-
132
- class AssetsLoader {
133
- constructor(http) {
134
- this.http = http;
135
- this.loadedSources = [];
136
- }
137
- loadScript(src) {
138
- const id = hashCode(src);
139
- if (this.loadedSources.includes(id)) {
140
- return of({
141
- src: src,
142
- hashCode: id,
143
- loaded: true,
144
- status: 'Loaded'
145
- });
146
- }
147
- return new Observable((observer) => {
148
- const script = document.createElement('script');
149
- script.type = 'text/javascript';
150
- script.src = src;
151
- script.async = true;
152
- if (script['readyState']) {
153
- // IE
154
- script['onreadystatechange'] = () => {
155
- if (script['readyState'] === 'loaded' || script['readyState'] === 'complete') {
156
- script['onreadystatechange'] = null;
157
- observer.next({
158
- src: src,
159
- hashCode: id,
160
- loaded: true,
161
- status: 'Loaded'
162
- });
163
- observer.complete();
164
- this.loadedSources.push(id);
165
- }
166
- };
167
- }
168
- else {
169
- // Others
170
- script.onload = () => {
171
- observer.next({
172
- src: src,
173
- hashCode: id,
174
- loaded: true,
175
- status: 'Loaded'
176
- });
177
- observer.complete();
178
- this.loadedSources.push(id);
179
- };
180
- }
181
- script.onerror = error => {
182
- observer.error({
183
- src: src,
184
- hashCode: id,
185
- loaded: false,
186
- status: 'Error',
187
- error: error
188
- });
189
- observer.complete();
190
- };
191
- document.body.appendChild(script);
192
- });
193
- }
194
- loadStyle(src) {
195
- const id = hashCode(src);
196
- if (this.loadedSources.includes(id)) {
197
- return of({
198
- src: src,
199
- hashCode: id,
200
- loaded: true,
201
- status: 'Loaded'
202
- });
203
- }
204
- return new Observable((observer) => {
205
- const head = document.getElementsByTagName('head')[0];
206
- const link = document.createElement('link');
207
- link.rel = 'stylesheet';
208
- link.type = 'text/css';
209
- link.href = src;
210
- link.media = 'all';
211
- link.onload = () => {
212
- observer.next({
213
- src: src,
214
- hashCode: id,
215
- loaded: true,
216
- status: 'Loaded'
217
- });
218
- observer.complete();
219
- this.loadedSources.push(id);
220
- };
221
- link.onerror = error => {
222
- observer.error({
223
- src: src,
224
- hashCode: id,
225
- loaded: true,
226
- status: 'Loaded',
227
- error: error
228
- });
229
- observer.complete();
230
- };
231
- head.appendChild(link);
232
- });
233
- }
234
- loadScripts(sources, serial = false) {
235
- if (isEmpty(sources)) {
236
- return of(null);
237
- }
238
- const observables = sources.map(src => {
239
- return this.loadScript(src);
240
- });
241
- if (serial) {
242
- const a = concat(...observables).pipe(map(item => {
243
- return of([item]);
244
- }), concatAll());
245
- return a;
246
- }
247
- else {
248
- return forkJoin(observables).pipe();
249
- }
250
- }
251
- loadStyles(sources) {
252
- if (isEmpty(sources)) {
253
- return of(null);
254
- }
255
- return forkJoin(sources.map(src => {
256
- return this.loadStyle(src);
257
- }));
258
- }
259
- loadScriptsAndStyles(scripts = [], styles = [], serial = false) {
260
- return forkJoin([this.loadScripts(scripts, serial), this.loadStyles(styles)]);
261
- }
262
- loadAppAssets(app) {
263
- if (app.manifest) {
264
- return this.loadManifest(`${app.manifest}?t=${new Date().getTime()}`).pipe(switchMap(manifestResult => {
265
- const { scripts, styles } = getScriptsAndStylesFullPaths(app, manifestResult);
266
- return this.loadScriptsAndStyles(scripts, styles, app.loadSerial);
267
- }));
268
- }
269
- else {
270
- const { scripts, styles } = getScriptsAndStylesFullPaths(app);
271
- return this.loadScriptsAndStyles(scripts, styles, app.loadSerial);
272
- }
273
- }
274
- loadManifest(url) {
275
- return this.http.get(url).pipe(map((response) => {
276
- return response;
277
- }));
278
- }
279
- }
280
- AssetsLoader.ɵprov = ɵɵdefineInjectable({ factory: function AssetsLoader_Factory() { return new AssetsLoader(ɵɵinject(HttpClient)); }, token: AssetsLoader, providedIn: "root" });
281
- AssetsLoader.decorators = [
282
- { type: Injectable, args: [{
283
- providedIn: 'root'
284
- },] }
285
- ];
286
- AssetsLoader.ctorParameters = () => [
287
- { type: HttpClient }
288
- ];
289
-
290
- class PlanetApplicationRef {
291
- constructor(name, options) {
292
- this.name = name;
293
- if (options) {
294
- this.template = options.template;
295
- this.innerSelector = this.template ? getTagNameByTemplate(this.template) : null;
296
- this.appModuleBootstrap = options.bootstrap;
297
- }
298
- // This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
299
- // See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
300
- // NgZone.isInAngularZone = () => {
301
- // // @ts-ignore
302
- // return window.Zone.current._properties[`ngx-planet-${name}`] === true;
303
- // };
304
- }
305
- get selector() {
306
- return this.innerSelector;
307
- }
308
- get bootstrapped() {
309
- return !!this.appModuleRef;
310
- }
311
- // 子应用路由变化后同步修改 portal 的 Route
312
- syncPortalRouteWhenNavigationEnd() {
313
- const router = this.appModuleRef.injector.get(Router);
314
- const ngZone = this.appModuleRef.injector.get(NgZone);
315
- if (router) {
316
- router.events.subscribe(event => {
317
- if (event instanceof NavigationEnd) {
318
- ngZone.onStable
319
- .asObservable()
320
- .pipe(take(1))
321
- .subscribe(() => {
322
- this.portalApp.router.navigateByUrl(event.url);
323
- });
324
- }
325
- });
326
- }
327
- }
328
- bootstrap(app) {
329
- if (!this.appModuleBootstrap) {
330
- throw new Error(`app(${this.name}) is not defined`);
331
- }
332
- this.portalApp = app;
333
- return from(this.appModuleBootstrap(app).then(appModuleRef => {
334
- this.appModuleRef = appModuleRef;
335
- this.appModuleRef.instance.appName = this.name;
336
- this.syncPortalRouteWhenNavigationEnd();
337
- return this;
338
- }));
339
- }
340
- getRouter() {
341
- return this.appModuleRef.injector.get(Router);
342
- }
343
- getCurrentRouterStateUrl() {
344
- return this.getRouter().routerState.snapshot.url;
345
- }
346
- navigateByUrl(url) {
347
- const ngZone = this.appModuleRef.injector.get(NgZone);
348
- const router = this.getRouter();
349
- ngZone.run(() => {
350
- router.navigateByUrl(url);
351
- });
352
- }
353
- getComponentFactory() {
354
- return this.componentFactory;
355
- }
356
- registerComponentFactory(componentFactory) {
357
- this.componentFactory = componentFactory;
358
- }
359
- destroy() {
360
- if (this.appModuleRef) {
361
- const router = this.appModuleRef.injector.get(Router);
362
- if (router) {
363
- router.dispose();
364
- }
365
- this.appModuleRef.destroy();
366
- delete this.appModuleRef;
367
- }
368
- }
369
- }
370
-
371
- const globalPlanet = (window.planet = window.planet || {
372
- apps: {}
373
- });
374
- function defineApplication(name, options) {
375
- if (globalPlanet.apps[name]) {
376
- throw new Error(`${name} application has exist.`);
377
- }
378
- if (isFunction(options)) {
379
- options = {
380
- template: '',
381
- bootstrap: options
382
- };
383
- }
384
- const appRef = new PlanetApplicationRef(name, options);
385
- globalPlanet.apps[name] = appRef;
386
- }
387
- function getPlanetApplicationRef(appName) {
388
- if (globalPlanet && globalPlanet.apps && globalPlanet.apps[appName]) {
389
- return globalPlanet.apps[appName];
390
- }
391
- else {
392
- return null;
393
- }
394
- }
395
- function setPortalApplicationData(data) {
396
- globalPlanet.portalApplication.data = data;
397
- }
398
- function getPortalApplicationData() {
399
- return globalPlanet.portalApplication.data;
400
- }
401
- function setApplicationLoader(loader) {
402
- globalPlanet.applicationLoader = loader;
403
- }
404
- function getApplicationLoader() {
405
- return globalPlanet.applicationLoader;
406
- }
407
- function setApplicationService(service) {
408
- globalPlanet.applicationService = service;
409
- }
410
- function getApplicationService() {
411
- return globalPlanet.applicationService;
412
- }
413
- function clearGlobalPlanet() {
414
- window.planet.apps = {};
415
- window.planet.portalApplication = null;
416
- window.planet.applicationLoader = null;
417
- window.planet.applicationService = null;
418
- }
419
-
420
- class PlanetApplicationService {
421
- constructor(http, assetsLoader) {
422
- this.http = http;
423
- this.assetsLoader = assetsLoader;
424
- this.apps = [];
425
- this.appsMap = {};
426
- if (getApplicationService()) {
427
- throw new Error('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
428
- }
429
- }
430
- register(appOrApps) {
431
- const apps = coerceArray(appOrApps);
432
- apps.forEach(app => {
433
- if (this.appsMap[app.name]) {
434
- throw new Error(`${app.name} has be registered.`);
435
- }
436
- this.apps.push(app);
437
- this.appsMap[app.name] = app;
438
- });
439
- }
440
- registerByUrl(url) {
441
- const result = this.http.get(`${url}`).pipe(map(apps => {
442
- if (apps && Array.isArray(apps)) {
443
- this.register(apps);
444
- }
445
- else {
446
- this.register(apps);
447
- }
448
- }), shareReplay());
449
- result.subscribe();
450
- return result;
451
- }
452
- unregister(name) {
453
- if (this.appsMap[name]) {
454
- delete this.appsMap[name];
455
- this.apps = this.apps.filter(app => {
456
- return app.name !== name;
457
- });
458
- }
459
- }
460
- getAppsByMatchedUrl(url) {
461
- return this.getApps().filter(app => {
462
- if (app.routerPathPrefix instanceof RegExp) {
463
- return app.routerPathPrefix.test(url);
464
- }
465
- else {
466
- return url.startsWith(app.routerPathPrefix);
467
- }
468
- });
469
- }
470
- getAppByName(name) {
471
- return this.appsMap[name];
472
- }
473
- getAppsToPreload(excludeAppNames) {
474
- return this.getApps().filter(app => {
475
- if (excludeAppNames) {
476
- return app.preload && !excludeAppNames.includes(app.name);
477
- }
478
- else {
479
- return app.preload;
480
- }
481
- });
482
- }
483
- getApps() {
484
- return this.apps;
485
- }
486
- }
487
- PlanetApplicationService.ɵprov = ɵɵdefineInjectable({ factory: function PlanetApplicationService_Factory() { return new PlanetApplicationService(ɵɵinject(HttpClient), ɵɵinject(AssetsLoader)); }, token: PlanetApplicationService, providedIn: "root" });
488
- PlanetApplicationService.decorators = [
489
- { type: Injectable, args: [{
490
- providedIn: 'root'
491
- },] }
492
- ];
493
- PlanetApplicationService.ctorParameters = () => [
494
- { type: HttpClient },
495
- { type: AssetsLoader }
496
- ];
497
-
498
- class PlanetPortalApplication {
499
- navigateByUrl(url, extras) {
500
- return this.ngZone.run(() => {
501
- return this.router.navigateByUrl(url, extras);
502
- });
503
- }
504
- run(fn) {
505
- return this.ngZone.run(() => {
506
- return fn();
507
- });
508
- }
509
- tick() {
510
- this.applicationRef.tick();
511
- }
512
- }
513
-
514
- const CUSTOM_EVENT_NAME = 'PLANET_GLOBAL_EVENT_DISPATCHER';
515
- class GlobalEventDispatcher {
516
- constructor(ngZone) {
517
- this.ngZone = ngZone;
518
- this.subject$ = new Subject();
519
- this.hasAddGlobalEventListener = false;
520
- this.subscriptionCount = 0;
521
- this.globalEventListener = (event) => {
522
- this.subject$.next(event.detail);
523
- };
524
- }
525
- addGlobalEventListener() {
526
- this.hasAddGlobalEventListener = true;
527
- window.addEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
528
- }
529
- removeGlobalEventListener() {
530
- this.hasAddGlobalEventListener = false;
531
- window.removeEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
532
- }
533
- dispatch(name, payload) {
534
- window.dispatchEvent(new CustomEvent(CUSTOM_EVENT_NAME, {
535
- detail: {
536
- name: name,
537
- payload: payload
538
- }
539
- }));
540
- }
541
- register(eventName) {
542
- return new Observable(observer => {
543
- if (!this.hasAddGlobalEventListener) {
544
- this.addGlobalEventListener();
545
- }
546
- this.subscriptionCount++;
547
- const subscription = this.subject$
548
- .pipe(filter(event => {
549
- return event.name === eventName;
550
- }), map(event => {
551
- return event.payload;
552
- }))
553
- .subscribe(payload => {
554
- this.ngZone.run(() => {
555
- observer.next(payload);
556
- });
557
- });
558
- return () => {
559
- this.subscriptionCount--;
560
- subscription.unsubscribe();
561
- if (!this.subscriptionCount) {
562
- this.removeGlobalEventListener();
563
- }
564
- };
565
- });
566
- }
567
- getSubscriptionCount() {
568
- return this.subscriptionCount;
569
- }
570
- }
571
- GlobalEventDispatcher.ɵprov = ɵɵdefineInjectable({ factory: function GlobalEventDispatcher_Factory() { return new GlobalEventDispatcher(ɵɵinject(NgZone)); }, token: GlobalEventDispatcher, providedIn: "root" });
572
- GlobalEventDispatcher.decorators = [
573
- { type: Injectable, args: [{
574
- providedIn: 'root'
575
- },] }
576
- ];
577
- GlobalEventDispatcher.ctorParameters = () => [
578
- { type: NgZone }
579
- ];
580
-
581
- var ApplicationStatus;
582
- (function (ApplicationStatus) {
583
- ApplicationStatus[ApplicationStatus["assetsLoading"] = 1] = "assetsLoading";
584
- ApplicationStatus[ApplicationStatus["assetsLoaded"] = 2] = "assetsLoaded";
585
- ApplicationStatus[ApplicationStatus["bootstrapping"] = 3] = "bootstrapping";
586
- ApplicationStatus[ApplicationStatus["bootstrapped"] = 4] = "bootstrapped";
587
- ApplicationStatus[ApplicationStatus["active"] = 5] = "active";
588
- ApplicationStatus[ApplicationStatus["loadError"] = 10] = "loadError";
589
- })(ApplicationStatus || (ApplicationStatus = {}));
590
- class PlanetApplicationLoader {
591
- constructor(assetsLoader, planetApplicationService, ngZone, router, injector, applicationRef) {
592
- this.assetsLoader = assetsLoader;
593
- this.planetApplicationService = planetApplicationService;
594
- this.ngZone = ngZone;
595
- this.firstLoad = true;
596
- this.inProgressAppAssetsLoads = new Map();
597
- this.appsStatus = new Map();
598
- this.portalApp = new PlanetPortalApplication();
599
- this.routeChange$ = new Subject();
600
- this.appStatusChange$ = new Subject();
601
- this.appsLoadingStart$ = new Subject();
602
- this.loadingDone = false;
603
- if (getApplicationLoader()) {
604
- throw new Error('PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed');
605
- }
606
- this.options = {
607
- switchMode: SwitchModes.default,
608
- errorHandler: (error) => {
609
- console.error(error);
610
- }
611
- };
612
- this.portalApp.ngZone = ngZone;
613
- this.portalApp.applicationRef = applicationRef;
614
- this.portalApp.router = router;
615
- this.portalApp.injector = injector;
616
- this.portalApp.globalEventDispatcher = injector.get(GlobalEventDispatcher);
617
- globalPlanet.portalApplication = this.portalApp;
618
- this.setupRouteChange();
619
- }
620
- get appStatusChange() {
621
- return this.appStatusChange$.asObservable();
622
- }
623
- get appsLoadingStart() {
624
- return this.appsLoadingStart$.asObservable();
625
- }
626
- setAppStatus(app, status) {
627
- this.ngZone.run(() => {
628
- this.appStatusChange$.next({
629
- app: app,
630
- status: status
631
- });
632
- this.appsStatus.set(app, status);
633
- });
634
- }
635
- switchModeIsCoexist(app) {
636
- if (app && app.switchMode) {
637
- return app.switchMode === SwitchModes.coexist;
638
- }
639
- else {
640
- return this.options.switchMode === SwitchModes.coexist;
641
- }
642
- }
643
- errorHandler(error) {
644
- this.ngZone.run(() => {
645
- this.options.errorHandler(error);
646
- });
647
- }
648
- takeOneStable() {
649
- return this.ngZone.onStable.pipe(take(1));
650
- }
651
- setLoadingDone() {
652
- this.ngZone.run(() => {
653
- this.loadingDone = true;
654
- });
655
- }
656
- setupRouteChange() {
657
- this.routeChange$
658
- .pipe(distinctUntilChanged((x, y) => {
659
- return (x && x.url) === (y && y.url);
660
- }),
661
- // Using switchMap so we cancel executing loading when a new one comes in
662
- switchMap(event => {
663
- // Return new observable use of and catchError,
664
- // in order to prevent routeChange$ completed which never trigger new route change
665
- return of(event).pipe(
666
- // unload apps and return should load apps
667
- map(() => {
668
- this.startRouteChangeEvent = event;
669
- const shouldLoadApps = this.planetApplicationService.getAppsByMatchedUrl(event.url);
670
- const shouldUnloadApps = this.getUnloadApps(shouldLoadApps);
671
- this.appsLoadingStart$.next({
672
- shouldLoadApps,
673
- shouldUnloadApps
674
- });
675
- this.unloadApps(shouldUnloadApps, event);
676
- return shouldLoadApps;
677
- }),
678
- // Load app assets (static resources)
679
- switchMap(shouldLoadApps => {
680
- let hasAppsNeedLoadingAssets = false;
681
- const loadApps$ = shouldLoadApps.map(app => {
682
- const appStatus = this.appsStatus.get(app);
683
- if (!appStatus ||
684
- appStatus === ApplicationStatus.assetsLoading ||
685
- appStatus === ApplicationStatus.loadError) {
686
- hasAppsNeedLoadingAssets = true;
687
- return this.ngZone.runOutsideAngular(() => {
688
- return this.startLoadAppAssets(app);
689
- });
690
- }
691
- else {
692
- return of(app);
693
- }
694
- });
695
- if (hasAppsNeedLoadingAssets) {
696
- this.loadingDone = false;
697
- }
698
- return loadApps$.length > 0 ? forkJoin(loadApps$) : of([]);
699
- }),
700
- // Bootstrap or show apps
701
- map(apps => {
702
- const apps$ = [];
703
- apps.forEach(app => {
704
- const appStatus = this.appsStatus.get(app);
705
- if (appStatus === ApplicationStatus.bootstrapped) {
706
- apps$.push(of(app).pipe(tap(() => {
707
- this.showApp(app);
708
- const appRef = getPlanetApplicationRef(app.name);
709
- appRef.navigateByUrl(event.url);
710
- this.setAppStatus(app, ApplicationStatus.active);
711
- this.setLoadingDone();
712
- })));
713
- }
714
- else if (appStatus === ApplicationStatus.assetsLoaded) {
715
- apps$.push(of(app).pipe(switchMap(() => {
716
- return this.bootstrapApp(app).pipe(map(() => {
717
- this.setAppStatus(app, ApplicationStatus.active);
718
- this.setLoadingDone();
719
- return app;
720
- }));
721
- })));
722
- }
723
- else if (appStatus === ApplicationStatus.active) {
724
- apps$.push(of(app).pipe(tap(() => {
725
- const appRef = getPlanetApplicationRef(app.name);
726
- // Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
727
- const currentUrl = appRef.getCurrentRouterStateUrl
728
- ? appRef.getCurrentRouterStateUrl()
729
- : '';
730
- if (currentUrl !== event.url) {
731
- appRef.navigateByUrl(event.url);
732
- }
733
- })));
734
- }
735
- else {
736
- throw new Error(`app(${app.name})'s status is ${appStatus}, can't be show or bootstrap`);
737
- }
738
- });
739
- if (apps$.length > 0) {
740
- // 切换到应用后会有闪烁现象,所以使用 setTimeout 后启动应用
741
- // example: redirect to app1's dashboard from portal's about page
742
- // If app's route has redirect, it doesn't work, it ok just in setTimeout, I don't know why.
743
- // TODO:: remove it, it is ok in version Angular 9.x
744
- setTimeout(() => {
745
- // 此处判断是因为如果静态资源加载完毕还未启动被取消,还是会启动之前的应用,虽然可能性比较小,但是无法排除这种可能性,所以只有当 Event 是最后一个才会启动
746
- if (this.startRouteChangeEvent === event) {
747
- // runOutsideAngular for fix error: `Expected to not be in Angular Zone, but it is!`
748
- this.ngZone.runOutsideAngular(() => {
749
- forkJoin(apps$).subscribe(() => {
750
- this.setLoadingDone();
751
- this.ensurePreloadApps(apps);
752
- });
753
- });
754
- }
755
- });
756
- }
757
- else {
758
- this.ensurePreloadApps(apps);
759
- this.setLoadingDone();
760
- }
761
- }),
762
- // Error handler
763
- catchError(error => {
764
- this.errorHandler(error);
765
- return [];
766
- }));
767
- }))
768
- .subscribe();
769
- }
770
- startLoadAppAssets(app) {
771
- if (this.inProgressAppAssetsLoads.get(app.name)) {
772
- return this.inProgressAppAssetsLoads.get(app.name);
773
- }
774
- else {
775
- const loadApp$ = this.assetsLoader.loadAppAssets(app).pipe(tap(() => {
776
- this.inProgressAppAssetsLoads.delete(app.name);
777
- this.setAppStatus(app, ApplicationStatus.assetsLoaded);
778
- }), map(() => {
779
- return app;
780
- }), catchError(error => {
781
- this.inProgressAppAssetsLoads.delete(app.name);
782
- this.setAppStatus(app, ApplicationStatus.loadError);
783
- throw error;
784
- }), share());
785
- this.inProgressAppAssetsLoads.set(app.name, loadApp$);
786
- this.setAppStatus(app, ApplicationStatus.assetsLoading);
787
- return loadApp$;
788
- }
789
- }
790
- hideApp(planetApp) {
791
- const appRef = getPlanetApplicationRef(planetApp.name);
792
- const appRootElement = document.querySelector(appRef.selector || planetApp.selector);
793
- if (appRootElement) {
794
- appRootElement.setAttribute('style', 'display:none;');
795
- }
796
- }
797
- showApp(planetApp) {
798
- const appRef = getPlanetApplicationRef(planetApp.name);
799
- const appRootElement = document.querySelector(appRef.selector || planetApp.selector);
800
- if (appRootElement) {
801
- appRootElement.setAttribute('style', '');
802
- }
803
- }
804
- destroyApp(planetApp) {
805
- const appRef = getPlanetApplicationRef(planetApp.name);
806
- if (appRef) {
807
- appRef.destroy();
808
- }
809
- const container = getHTMLElement(planetApp.hostParent);
810
- const appRootElement = container.querySelector((appRef && appRef.selector) || planetApp.selector);
811
- if (appRootElement) {
812
- container.removeChild(appRootElement);
813
- }
814
- }
815
- bootstrapApp(app, defaultStatus = 'display') {
816
- this.setAppStatus(app, ApplicationStatus.bootstrapping);
817
- const appRef = getPlanetApplicationRef(app.name);
818
- if (appRef && appRef.bootstrap) {
819
- const container = getHTMLElement(app.hostParent);
820
- let appRootElement;
821
- if (container) {
822
- appRootElement = container.querySelector(appRef.selector || app.selector);
823
- if (!appRootElement) {
824
- if (appRef.template) {
825
- appRootElement = createElementByTemplate(appRef.template);
826
- }
827
- else {
828
- appRootElement = document.createElement(app.selector);
829
- }
830
- appRootElement.setAttribute('style', 'display:none;');
831
- if (app.hostClass) {
832
- appRootElement.classList.add(...coerceArray(app.hostClass));
833
- }
834
- if (app.stylePrefix) {
835
- appRootElement.classList.add(...coerceArray(app.stylePrefix));
836
- }
837
- container.appendChild(appRootElement);
838
- }
839
- }
840
- let result = appRef.bootstrap(this.portalApp);
841
- // Backwards compatibility promise for bootstrap
842
- if (result['then']) {
843
- result = from(result);
844
- }
845
- return result.pipe(tap(() => {
846
- this.setAppStatus(app, ApplicationStatus.bootstrapped);
847
- if (defaultStatus === 'display' && appRootElement) {
848
- appRootElement.removeAttribute('style');
849
- }
850
- }), map(() => {
851
- return appRef;
852
- }));
853
- }
854
- else {
855
- 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`);
856
- }
857
- }
858
- getUnloadApps(activeApps) {
859
- const unloadApps = [];
860
- this.appsStatus.forEach((value, app) => {
861
- if (value === ApplicationStatus.active && !activeApps.find(item => item.name === app.name)) {
862
- unloadApps.push(app);
863
- }
864
- });
865
- return unloadApps;
866
- }
867
- unloadApps(shouldUnloadApps, event) {
868
- const hideApps = [];
869
- const destroyApps = [];
870
- shouldUnloadApps.forEach(app => {
871
- if (this.switchModeIsCoexist(app)) {
872
- hideApps.push(app);
873
- this.hideApp(app);
874
- this.setAppStatus(app, ApplicationStatus.bootstrapped);
875
- }
876
- else {
877
- destroyApps.push(app);
878
- // 销毁之前先隐藏,否则会出现闪烁,因为 destroy 是延迟执行的
879
- // 如果销毁不延迟执行,会出现切换到主应用的时候会有视图卡顿现象
880
- this.hideApp(app);
881
- this.setAppStatus(app, ApplicationStatus.assetsLoaded);
882
- }
883
- });
884
- if (hideApps.length > 0 || destroyApps.length > 0) {
885
- // 从其他应用切换到主应用的时候会有视图卡顿现象,所以先等主应用渲染完毕后再加载其他应用
886
- // 此处尝试使用 this.ngZone.onStable.pipe(take(1)) 应用之间的切换会出现闪烁
887
- setTimeout(() => {
888
- hideApps.forEach(app => {
889
- const appRef = getPlanetApplicationRef(app.name);
890
- if (appRef) {
891
- appRef.navigateByUrl(event.url);
892
- }
893
- });
894
- destroyApps.forEach(app => {
895
- this.destroyApp(app);
896
- });
897
- });
898
- }
899
- }
900
- preloadApps(activeApps) {
901
- setTimeout(() => {
902
- const toPreloadApps = this.planetApplicationService.getAppsToPreload(activeApps ? activeApps.map(item => item.name) : null);
903
- const loadApps$ = toPreloadApps.map(preloadApp => {
904
- return this.preloadInternal(preloadApp);
905
- });
906
- forkJoin(loadApps$).subscribe({
907
- error: error => this.errorHandler(error)
908
- });
909
- });
910
- }
911
- ensurePreloadApps(activeApps) {
912
- // Start preload apps
913
- // Start preload when first time app loaded
914
- if (this.firstLoad) {
915
- this.preloadApps(activeApps);
916
- this.firstLoad = false;
917
- }
918
- }
919
- setOptions(options) {
920
- this.options = Object.assign(Object.assign({}, this.options), options);
921
- }
922
- /**
923
- * reset route by current router
924
- */
925
- reroute(event) {
926
- this.routeChange$.next(event);
927
- }
928
- preloadInternal(app, immediate) {
929
- const status = this.appsStatus.get(app);
930
- if (!status || status === ApplicationStatus.loadError) {
931
- return this.startLoadAppAssets(app).pipe(switchMap(() => {
932
- if (immediate) {
933
- return this.bootstrapApp(app, 'hidden');
934
- }
935
- else {
936
- return this.ngZone.runOutsideAngular(() => {
937
- return this.bootstrapApp(app, 'hidden');
938
- });
939
- }
940
- }), map(() => {
941
- return getPlanetApplicationRef(app.name);
942
- }));
943
- }
944
- else if ([ApplicationStatus.assetsLoading, ApplicationStatus.assetsLoaded, ApplicationStatus.bootstrapping].includes(status)) {
945
- return this.appStatusChange.pipe(filter(event => {
946
- return event.app === app && event.status === ApplicationStatus.bootstrapped;
947
- }), take(1), map(() => {
948
- return getPlanetApplicationRef(app.name);
949
- }));
950
- }
951
- else {
952
- const appRef = getPlanetApplicationRef(app.name);
953
- if (!appRef) {
954
- throw new Error(`${app.name}'s status is ${ApplicationStatus[status]}, planetApplicationRef is null.`);
955
- }
956
- return of(appRef);
957
- }
958
- }
959
- /**
960
- * Preload planet application
961
- * @param app app
962
- * @param immediate bootstrap on stable by default, setting immediate is true, it will bootstrap immediate
963
- */
964
- preload(app, immediate) {
965
- return this.preloadInternal(app, immediate);
966
- }
967
- }
968
- PlanetApplicationLoader.ɵprov = ɵɵdefineInjectable({ factory: function PlanetApplicationLoader_Factory() { return new PlanetApplicationLoader(ɵɵinject(AssetsLoader), ɵɵinject(PlanetApplicationService), ɵɵinject(NgZone), ɵɵinject(Router), ɵɵinject(INJECTOR), ɵɵinject(ApplicationRef)); }, token: PlanetApplicationLoader, providedIn: "root" });
969
- PlanetApplicationLoader.decorators = [
970
- { type: Injectable, args: [{
971
- providedIn: 'root'
972
- },] }
973
- ];
974
- PlanetApplicationLoader.ctorParameters = () => [
975
- { type: AssetsLoader },
976
- { type: PlanetApplicationService },
977
- { type: NgZone },
978
- { type: Router },
979
- { type: Injector },
980
- { type: ApplicationRef }
981
- ];
982
-
983
- class Planet {
984
- constructor(injector, router, planetApplications) {
985
- this.injector = injector;
986
- this.router = router;
987
- if (!this.planetApplicationLoader) {
988
- setApplicationLoader(this.injector.get(PlanetApplicationLoader));
989
- }
990
- if (!this.planetApplicationService) {
991
- setApplicationService(this.injector.get(PlanetApplicationService));
992
- }
993
- if (planetApplications) {
994
- this.registerApps(planetApplications);
995
- }
996
- }
997
- get planetApplicationLoader() {
998
- return getApplicationLoader();
999
- }
1000
- get planetApplicationService() {
1001
- return getApplicationService();
1002
- }
1003
- get loadingDone() {
1004
- return this.planetApplicationLoader.loadingDone;
1005
- }
1006
- get appStatusChange() {
1007
- return this.planetApplicationLoader.appStatusChange;
1008
- }
1009
- get appsLoadingStart() {
1010
- return this.planetApplicationLoader.appsLoadingStart;
1011
- }
1012
- setOptions(options) {
1013
- this.planetApplicationLoader.setOptions(options);
1014
- }
1015
- setPortalAppData(data) {
1016
- setPortalApplicationData(data);
1017
- }
1018
- registerApp(app) {
1019
- this.planetApplicationService.register(app);
1020
- }
1021
- registerApps(apps) {
1022
- this.planetApplicationService.register(apps);
1023
- }
1024
- unregisterApp(name) {
1025
- this.planetApplicationService.unregister(name);
1026
- }
1027
- getApps() {
1028
- return this.planetApplicationService.getApps();
1029
- }
1030
- start() {
1031
- this.subscription = this.router.events
1032
- .pipe(filter(event => {
1033
- return event instanceof NavigationEnd;
1034
- }), map((event) => {
1035
- return event.urlAfterRedirects || event.url;
1036
- }), startWith(location.pathname), distinctUntilChanged())
1037
- .subscribe((url) => {
1038
- this.planetApplicationLoader.reroute({
1039
- url: url
1040
- });
1041
- });
1042
- }
1043
- stop() {
1044
- this.subscription.unsubscribe();
1045
- }
1046
- }
1047
- Planet.ɵprov = ɵɵdefineInjectable({ factory: function Planet_Factory() { return new Planet(ɵɵinject(INJECTOR), ɵɵinject(Router), ɵɵinject(PLANET_APPLICATIONS, 8)); }, token: Planet, providedIn: "root" });
1048
- Planet.decorators = [
1049
- { type: Injectable, args: [{
1050
- providedIn: 'root'
1051
- },] }
1052
- ];
1053
- Planet.ctorParameters = () => [
1054
- { type: Injector },
1055
- { type: Router },
1056
- { type: Array, decorators: [{ type: Inject, args: [PLANET_APPLICATIONS,] }, { type: Optional }] }
1057
- ];
1058
-
1059
- class EmptyComponent {
1060
- }
1061
- EmptyComponent.decorators = [
1062
- { type: Component, args: [{
1063
- selector: 'empty-component',
1064
- template: ``
1065
- },] }
1066
- ];
1067
-
1068
- class NgxPlanetModule {
1069
- static forRoot(apps) {
1070
- return {
1071
- ngModule: NgxPlanetModule,
1072
- providers: [
1073
- {
1074
- provide: PLANET_APPLICATIONS,
1075
- useValue: apps
1076
- }
1077
- ]
1078
- };
1079
- }
1080
- }
1081
- NgxPlanetModule.decorators = [
1082
- { type: NgModule, args: [{
1083
- declarations: [EmptyComponent],
1084
- entryComponents: [EmptyComponent],
1085
- imports: [HttpClientModule],
1086
- providers: [],
1087
- exports: [HttpClientModule, EmptyComponent]
1088
- },] }
1089
- ];
1090
-
1091
- class PlanetComponentRef {
1092
- }
1093
-
1094
- const componentWrapperClass = 'planet-component-wrapper';
1095
- class PlanetComponentLoader {
1096
- constructor(applicationRef, ngModuleRef, ngZone, document) {
1097
- this.applicationRef = applicationRef;
1098
- this.ngModuleRef = ngModuleRef;
1099
- this.ngZone = ngZone;
1100
- this.document = document;
1101
- this.domPortalOutletCache = new WeakMap();
1102
- }
1103
- get applicationLoader() {
1104
- return getApplicationLoader();
1105
- }
1106
- get applicationService() {
1107
- return getApplicationService();
1108
- }
1109
- getPlantAppRef(name) {
1110
- if (globalPlanet.apps[name] && globalPlanet.apps[name].appModuleRef) {
1111
- return of(globalPlanet.apps[name]);
1112
- }
1113
- else {
1114
- const app = this.applicationService.getAppByName(name);
1115
- return this.applicationLoader.preload(app, true).pipe(map(() => {
1116
- return globalPlanet.apps[name];
1117
- }));
1118
- }
1119
- }
1120
- createInjector(appModuleRef, componentRef) {
1121
- const injectionTokens = new WeakMap([[PlanetComponentRef, componentRef]]);
1122
- const defaultInjector = appModuleRef.injector;
1123
- return new PortalInjector(defaultInjector, injectionTokens);
1124
- }
1125
- getContainerElement(config) {
1126
- if (!config.container) {
1127
- throw new Error(`config 'container' cannot be null`);
1128
- }
1129
- else {
1130
- if (config.container.nativeElement) {
1131
- return config.container.nativeElement;
1132
- }
1133
- else {
1134
- return config.container;
1135
- }
1136
- }
1137
- }
1138
- createWrapperElement(config) {
1139
- const container = this.getContainerElement(config);
1140
- const element = this.document.createElement('div');
1141
- const subApp = this.applicationService.getAppByName(this.ngModuleRef.instance.appName);
1142
- element.classList.add(componentWrapperClass);
1143
- element.setAttribute('planet-inline', '');
1144
- if (config.wrapperClass) {
1145
- element.classList.add(config.wrapperClass);
1146
- }
1147
- if (subApp && subApp.stylePrefix) {
1148
- element.classList.add(subApp.stylePrefix);
1149
- }
1150
- container.appendChild(element);
1151
- return element;
1152
- }
1153
- attachComponent(plantComponent, appModuleRef, config) {
1154
- const plantComponentRef = new PlanetComponentRef();
1155
- const componentFactoryResolver = appModuleRef.componentFactoryResolver;
1156
- const appRef = this.applicationRef;
1157
- const injector = this.createInjector(appModuleRef, plantComponentRef);
1158
- const wrapper = this.createWrapperElement(config);
1159
- let portalOutlet = this.domPortalOutletCache.get(wrapper);
1160
- if (portalOutlet) {
1161
- portalOutlet.detach();
1162
- }
1163
- else {
1164
- portalOutlet = new DomPortalOutlet(wrapper, componentFactoryResolver, appRef, injector);
1165
- this.domPortalOutletCache.set(wrapper, portalOutlet);
1166
- }
1167
- const componentPortal = new ComponentPortal(plantComponent.component, null);
1168
- const componentRef = portalOutlet.attachComponentPortal(componentPortal);
1169
- if (config.initialState) {
1170
- Object.assign(componentRef.instance, config.initialState);
1171
- }
1172
- plantComponentRef.componentInstance = componentRef.instance;
1173
- plantComponentRef.componentRef = componentRef;
1174
- plantComponentRef.wrapperElement = wrapper;
1175
- plantComponentRef.dispose = () => {
1176
- this.domPortalOutletCache.delete(wrapper);
1177
- portalOutlet.dispose();
1178
- };
1179
- return plantComponentRef;
1180
- }
1181
- registerComponentFactory(componentOrComponents) {
1182
- const app = this.ngModuleRef.instance.appName;
1183
- this.getPlantAppRef(app).subscribe(appRef => {
1184
- appRef.registerComponentFactory((componentName, config) => {
1185
- const components = coerceArray(componentOrComponents);
1186
- const component = components.find(item => item.name === componentName);
1187
- if (component) {
1188
- return this.ngZone.run(() => {
1189
- const componentRef = this.attachComponent(component, appRef.appModuleRef, config);
1190
- return componentRef;
1191
- });
1192
- }
1193
- else {
1194
- throw Error(`unregistered component ${componentName} in app ${app}`);
1195
- }
1196
- });
1197
- });
1198
- }
1199
- register(components) {
1200
- setTimeout(() => {
1201
- this.registerComponentFactory(components);
1202
- });
1203
- }
1204
- load(app, componentName, config) {
1205
- const result = this.getPlantAppRef(app).pipe(delayWhen(appRef => {
1206
- if (appRef.getComponentFactory()) {
1207
- return of();
1208
- }
1209
- else {
1210
- // Because register use 'setTimeout',so timer 20
1211
- return timer(20);
1212
- }
1213
- }), map(appRef => {
1214
- const componentFactory = appRef.getComponentFactory();
1215
- if (componentFactory) {
1216
- return componentFactory(componentName, config);
1217
- }
1218
- else {
1219
- throw new Error(`${app}'s component(${componentName}) is not registered`);
1220
- }
1221
- }), finalize(() => {
1222
- this.applicationRef.tick();
1223
- }), shareReplay());
1224
- result.subscribe();
1225
- return result;
1226
- }
1227
- }
1228
- PlanetComponentLoader.ɵprov = ɵɵdefineInjectable({ factory: function PlanetComponentLoader_Factory() { return new PlanetComponentLoader(ɵɵinject(ApplicationRef), ɵɵinject(NgModuleRef), ɵɵinject(NgZone), ɵɵinject(DOCUMENT)); }, token: PlanetComponentLoader, providedIn: "root" });
1229
- PlanetComponentLoader.decorators = [
1230
- { type: Injectable, args: [{
1231
- providedIn: 'root'
1232
- },] }
1233
- ];
1234
- PlanetComponentLoader.ctorParameters = () => [
1235
- { type: ApplicationRef },
1236
- { type: NgModuleRef },
1237
- { type: NgZone },
1238
- { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
1239
- ];
1240
-
1241
- class PlantComponentConfig {
1242
- constructor() {
1243
- /** Data being injected into the child component. */
1244
- this.initialState = null;
1245
- }
1246
- }
1247
-
1248
- /*
1249
- * Public API Surface of core
1250
- */
1251
-
1252
- /**
1253
- * Generated bundle index. Do not edit.
1254
- */
1255
-
1256
- export { ApplicationStatus, AssetsLoader, EmptyComponent, GlobalEventDispatcher, NgxPlanetModule, PLANET_APPLICATIONS, Planet, PlanetApplicationLoader, PlanetApplicationRef, PlanetApplicationService, PlanetComponentLoader, PlanetComponentRef, PlanetPortalApplication, PlantComponentConfig, SwitchModes, defineApplication, getPlanetApplicationRef, getPortalApplicationData, globalPlanet as ɵa };
1257
- //# sourceMappingURL=worktile-planet.js.map