@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,1670 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/router'), require('@angular/common/http'), require('rxjs/operators'), require('rxjs'), require('@angular/cdk/portal'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('@worktile/planet', ['exports', '@angular/core', '@angular/router', '@angular/common/http', 'rxjs/operators', 'rxjs', '@angular/cdk/portal', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.worktile = global.worktile || {}, global.worktile.planet = {}), global.ng.core, global.ng.router, global.ng.common.http, global.rxjs.operators, global.rxjs, global.ng.cdk.portal, global.ng.common));
5
- }(this, (function (exports, i0, i3, i1, operators, rxjs, portal, i1$1) { 'use strict';
6
-
7
- (function (SwitchModes) {
8
- SwitchModes["default"] = "default";
9
- SwitchModes["coexist"] = "coexist";
10
- })(exports.SwitchModes || (exports.SwitchModes = {}));
11
- var PLANET_APPLICATIONS = new i0.InjectionToken('PLANET_APPLICATIONS');
12
-
13
- var ELEMENT_NODE_TYPE = 1;
14
- function hashCode(str) {
15
- var hash = 0;
16
- var chr;
17
- if (str.length === 0) {
18
- return hash;
19
- }
20
- for (var i = 0; i < str.length; i++) {
21
- chr = str.charCodeAt(i);
22
- hash = (hash << 5) - hash + chr;
23
- hash |= 0; // Convert to 32bit integer
24
- }
25
- return hash;
26
- }
27
- function getHTMLElement(selector) {
28
- if (selector instanceof HTMLElement) {
29
- return selector;
30
- }
31
- else {
32
- return document.querySelector(selector);
33
- }
34
- }
35
- function getTagNameByTemplate(template) {
36
- var element = createElementByTemplate(template);
37
- return element ? element.nodeName : null;
38
- }
39
- function createElementByTemplate(template) {
40
- if (!template) {
41
- return null;
42
- }
43
- var element = document.createRange().createContextualFragment(template).firstChild;
44
- if (element.nodeType === ELEMENT_NODE_TYPE) {
45
- return element;
46
- }
47
- else {
48
- throw new Error("invalid template '" + template + "'");
49
- }
50
- }
51
- function coerceArray(value) {
52
- return Array.isArray(value) ? value : [value];
53
- }
54
- function isEmpty(value) {
55
- if (!value || value.length === 0) {
56
- return true;
57
- }
58
- else {
59
- return false;
60
- }
61
- }
62
- function isFunction(value) {
63
- var type = typeof value;
64
- return !!value && type === 'function';
65
- }
66
- /**
67
- * Get file name from path
68
- * 1. "main.js" => "main.js"
69
- * 2. "assets/scripts/main.js" => "main.js"
70
- * @param path path
71
- */
72
- function getResourceFileName(path) {
73
- var lastSlashIndex = path.lastIndexOf('/');
74
- if (lastSlashIndex >= 0) {
75
- return path.slice(lastSlashIndex + 1);
76
- }
77
- else {
78
- return path;
79
- }
80
- }
81
- /**
82
- * Build resource path by manifest
83
- * if manifest is { "main.js": "main.h2sh23abee.js"}
84
- * 1. "main.js" => "main.h2sh23abee.js"
85
- * 2. "assets/scripts/main.js" =>"assets/scripts/main.h2sh23abee.js"
86
- * @param resourceFilePath Resource File Path
87
- * @param manifestResult manifest
88
- */
89
- function buildResourceFilePath(resourceFilePath, manifestResult) {
90
- var fileName = getResourceFileName(resourceFilePath);
91
- if (manifestResult[fileName]) {
92
- return resourceFilePath.replace(fileName, manifestResult[fileName]);
93
- }
94
- else {
95
- return resourceFilePath;
96
- }
97
- }
98
- /**
99
- * Get static resource full path
100
- * @param app PlanetApplication
101
- * @param manifestResult manifest
102
- */
103
- function getScriptsAndStylesFullPaths(app, manifestResult) {
104
- var scripts = app.scripts || [];
105
- var styles = app.styles || [];
106
- // combine resource path by manifest
107
- if (manifestResult) {
108
- scripts = scripts.map(function (script) {
109
- return buildResourceFilePath(script, manifestResult);
110
- });
111
- styles = styles.map(function (style) {
112
- return buildResourceFilePath(style, manifestResult);
113
- });
114
- }
115
- if (app.resourcePathPrefix) {
116
- scripts = scripts.map(function (script) {
117
- return "" + app.resourcePathPrefix + script;
118
- });
119
- styles = styles.map(function (style) {
120
- return "" + app.resourcePathPrefix + style;
121
- });
122
- }
123
- return {
124
- scripts: scripts,
125
- styles: styles
126
- };
127
- }
128
-
129
- /*! *****************************************************************************
130
- Copyright (c) Microsoft Corporation.
131
-
132
- Permission to use, copy, modify, and/or distribute this software for any
133
- purpose with or without fee is hereby granted.
134
-
135
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
136
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
137
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
138
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
139
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
140
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
141
- PERFORMANCE OF THIS SOFTWARE.
142
- ***************************************************************************** */
143
- /* global Reflect, Promise */
144
- var extendStatics = function (d, b) {
145
- extendStatics = Object.setPrototypeOf ||
146
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
147
- function (d, b) { for (var p in b)
148
- if (Object.prototype.hasOwnProperty.call(b, p))
149
- d[p] = b[p]; };
150
- return extendStatics(d, b);
151
- };
152
- function __extends(d, b) {
153
- extendStatics(d, b);
154
- function __() { this.constructor = d; }
155
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
156
- }
157
- var __assign = function () {
158
- __assign = Object.assign || function __assign(t) {
159
- for (var s, i = 1, n = arguments.length; i < n; i++) {
160
- s = arguments[i];
161
- for (var p in s)
162
- if (Object.prototype.hasOwnProperty.call(s, p))
163
- t[p] = s[p];
164
- }
165
- return t;
166
- };
167
- return __assign.apply(this, arguments);
168
- };
169
- function __rest(s, e) {
170
- var t = {};
171
- for (var p in s)
172
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
173
- t[p] = s[p];
174
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
175
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
176
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
177
- t[p[i]] = s[p[i]];
178
- }
179
- return t;
180
- }
181
- function __decorate(decorators, target, key, desc) {
182
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
183
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
184
- r = Reflect.decorate(decorators, target, key, desc);
185
- else
186
- for (var i = decorators.length - 1; i >= 0; i--)
187
- if (d = decorators[i])
188
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
189
- return c > 3 && r && Object.defineProperty(target, key, r), r;
190
- }
191
- function __param(paramIndex, decorator) {
192
- return function (target, key) { decorator(target, key, paramIndex); };
193
- }
194
- function __metadata(metadataKey, metadataValue) {
195
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
196
- return Reflect.metadata(metadataKey, metadataValue);
197
- }
198
- function __awaiter(thisArg, _arguments, P, generator) {
199
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
200
- return new (P || (P = Promise))(function (resolve, reject) {
201
- function fulfilled(value) { try {
202
- step(generator.next(value));
203
- }
204
- catch (e) {
205
- reject(e);
206
- } }
207
- function rejected(value) { try {
208
- step(generator["throw"](value));
209
- }
210
- catch (e) {
211
- reject(e);
212
- } }
213
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
214
- step((generator = generator.apply(thisArg, _arguments || [])).next());
215
- });
216
- }
217
- function __generator(thisArg, body) {
218
- var _ = { label: 0, sent: function () { if (t[0] & 1)
219
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
220
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
221
- function verb(n) { return function (v) { return step([n, v]); }; }
222
- function step(op) {
223
- if (f)
224
- throw new TypeError("Generator is already executing.");
225
- while (_)
226
- try {
227
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
228
- return t;
229
- if (y = 0, t)
230
- op = [op[0] & 2, t.value];
231
- switch (op[0]) {
232
- case 0:
233
- case 1:
234
- t = op;
235
- break;
236
- case 4:
237
- _.label++;
238
- return { value: op[1], done: false };
239
- case 5:
240
- _.label++;
241
- y = op[1];
242
- op = [0];
243
- continue;
244
- case 7:
245
- op = _.ops.pop();
246
- _.trys.pop();
247
- continue;
248
- default:
249
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
250
- _ = 0;
251
- continue;
252
- }
253
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
254
- _.label = op[1];
255
- break;
256
- }
257
- if (op[0] === 6 && _.label < t[1]) {
258
- _.label = t[1];
259
- t = op;
260
- break;
261
- }
262
- if (t && _.label < t[2]) {
263
- _.label = t[2];
264
- _.ops.push(op);
265
- break;
266
- }
267
- if (t[2])
268
- _.ops.pop();
269
- _.trys.pop();
270
- continue;
271
- }
272
- op = body.call(thisArg, _);
273
- }
274
- catch (e) {
275
- op = [6, e];
276
- y = 0;
277
- }
278
- finally {
279
- f = t = 0;
280
- }
281
- if (op[0] & 5)
282
- throw op[1];
283
- return { value: op[0] ? op[1] : void 0, done: true };
284
- }
285
- }
286
- var __createBinding = Object.create ? (function (o, m, k, k2) {
287
- if (k2 === undefined)
288
- k2 = k;
289
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
290
- }) : (function (o, m, k, k2) {
291
- if (k2 === undefined)
292
- k2 = k;
293
- o[k2] = m[k];
294
- });
295
- function __exportStar(m, o) {
296
- for (var p in m)
297
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
298
- __createBinding(o, m, p);
299
- }
300
- function __values(o) {
301
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
302
- if (m)
303
- return m.call(o);
304
- if (o && typeof o.length === "number")
305
- return {
306
- next: function () {
307
- if (o && i >= o.length)
308
- o = void 0;
309
- return { value: o && o[i++], done: !o };
310
- }
311
- };
312
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
313
- }
314
- function __read(o, n) {
315
- var m = typeof Symbol === "function" && o[Symbol.iterator];
316
- if (!m)
317
- return o;
318
- var i = m.call(o), r, ar = [], e;
319
- try {
320
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
321
- ar.push(r.value);
322
- }
323
- catch (error) {
324
- e = { error: error };
325
- }
326
- finally {
327
- try {
328
- if (r && !r.done && (m = i["return"]))
329
- m.call(i);
330
- }
331
- finally {
332
- if (e)
333
- throw e.error;
334
- }
335
- }
336
- return ar;
337
- }
338
- function __spread() {
339
- for (var ar = [], i = 0; i < arguments.length; i++)
340
- ar = ar.concat(__read(arguments[i]));
341
- return ar;
342
- }
343
- function __spreadArrays() {
344
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
345
- s += arguments[i].length;
346
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
347
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
348
- r[k] = a[j];
349
- return r;
350
- }
351
- ;
352
- function __await(v) {
353
- return this instanceof __await ? (this.v = v, this) : new __await(v);
354
- }
355
- function __asyncGenerator(thisArg, _arguments, generator) {
356
- if (!Symbol.asyncIterator)
357
- throw new TypeError("Symbol.asyncIterator is not defined.");
358
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
359
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
360
- function verb(n) { if (g[n])
361
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
362
- function resume(n, v) { try {
363
- step(g[n](v));
364
- }
365
- catch (e) {
366
- settle(q[0][3], e);
367
- } }
368
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
369
- function fulfill(value) { resume("next", value); }
370
- function reject(value) { resume("throw", value); }
371
- function settle(f, v) { if (f(v), q.shift(), q.length)
372
- resume(q[0][0], q[0][1]); }
373
- }
374
- function __asyncDelegator(o) {
375
- var i, p;
376
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
377
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
378
- }
379
- function __asyncValues(o) {
380
- if (!Symbol.asyncIterator)
381
- throw new TypeError("Symbol.asyncIterator is not defined.");
382
- var m = o[Symbol.asyncIterator], i;
383
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
384
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
385
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
386
- }
387
- function __makeTemplateObject(cooked, raw) {
388
- if (Object.defineProperty) {
389
- Object.defineProperty(cooked, "raw", { value: raw });
390
- }
391
- else {
392
- cooked.raw = raw;
393
- }
394
- return cooked;
395
- }
396
- ;
397
- var __setModuleDefault = Object.create ? (function (o, v) {
398
- Object.defineProperty(o, "default", { enumerable: true, value: v });
399
- }) : function (o, v) {
400
- o["default"] = v;
401
- };
402
- function __importStar(mod) {
403
- if (mod && mod.__esModule)
404
- return mod;
405
- var result = {};
406
- if (mod != null)
407
- for (var k in mod)
408
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
409
- __createBinding(result, mod, k);
410
- __setModuleDefault(result, mod);
411
- return result;
412
- }
413
- function __importDefault(mod) {
414
- return (mod && mod.__esModule) ? mod : { default: mod };
415
- }
416
- function __classPrivateFieldGet(receiver, privateMap) {
417
- if (!privateMap.has(receiver)) {
418
- throw new TypeError("attempted to get private field on non-instance");
419
- }
420
- return privateMap.get(receiver);
421
- }
422
- function __classPrivateFieldSet(receiver, privateMap, value) {
423
- if (!privateMap.has(receiver)) {
424
- throw new TypeError("attempted to set private field on non-instance");
425
- }
426
- privateMap.set(receiver, value);
427
- return value;
428
- }
429
-
430
- var AssetsLoader = /** @class */ (function () {
431
- function AssetsLoader(http) {
432
- this.http = http;
433
- this.loadedSources = [];
434
- }
435
- AssetsLoader.prototype.loadScript = function (src) {
436
- var _this = this;
437
- var id = hashCode(src);
438
- if (this.loadedSources.includes(id)) {
439
- return rxjs.of({
440
- src: src,
441
- hashCode: id,
442
- loaded: true,
443
- status: 'Loaded'
444
- });
445
- }
446
- return new rxjs.Observable(function (observer) {
447
- var script = document.createElement('script');
448
- script.type = 'text/javascript';
449
- script.src = src;
450
- script.async = true;
451
- if (script['readyState']) {
452
- // IE
453
- script['onreadystatechange'] = function () {
454
- if (script['readyState'] === 'loaded' || script['readyState'] === 'complete') {
455
- script['onreadystatechange'] = null;
456
- observer.next({
457
- src: src,
458
- hashCode: id,
459
- loaded: true,
460
- status: 'Loaded'
461
- });
462
- observer.complete();
463
- _this.loadedSources.push(id);
464
- }
465
- };
466
- }
467
- else {
468
- // Others
469
- script.onload = function () {
470
- observer.next({
471
- src: src,
472
- hashCode: id,
473
- loaded: true,
474
- status: 'Loaded'
475
- });
476
- observer.complete();
477
- _this.loadedSources.push(id);
478
- };
479
- }
480
- script.onerror = function (error) {
481
- observer.error({
482
- src: src,
483
- hashCode: id,
484
- loaded: false,
485
- status: 'Error',
486
- error: error
487
- });
488
- observer.complete();
489
- };
490
- document.body.appendChild(script);
491
- });
492
- };
493
- AssetsLoader.prototype.loadStyle = function (src) {
494
- var _this = this;
495
- var id = hashCode(src);
496
- if (this.loadedSources.includes(id)) {
497
- return rxjs.of({
498
- src: src,
499
- hashCode: id,
500
- loaded: true,
501
- status: 'Loaded'
502
- });
503
- }
504
- return new rxjs.Observable(function (observer) {
505
- var head = document.getElementsByTagName('head')[0];
506
- var link = document.createElement('link');
507
- link.rel = 'stylesheet';
508
- link.type = 'text/css';
509
- link.href = src;
510
- link.media = 'all';
511
- link.onload = function () {
512
- observer.next({
513
- src: src,
514
- hashCode: id,
515
- loaded: true,
516
- status: 'Loaded'
517
- });
518
- observer.complete();
519
- _this.loadedSources.push(id);
520
- };
521
- link.onerror = function (error) {
522
- observer.error({
523
- src: src,
524
- hashCode: id,
525
- loaded: true,
526
- status: 'Loaded',
527
- error: error
528
- });
529
- observer.complete();
530
- };
531
- head.appendChild(link);
532
- });
533
- };
534
- AssetsLoader.prototype.loadScripts = function (sources, serial) {
535
- var _this = this;
536
- if (serial === void 0) { serial = false; }
537
- if (isEmpty(sources)) {
538
- return rxjs.of(null);
539
- }
540
- var observables = sources.map(function (src) {
541
- return _this.loadScript(src);
542
- });
543
- if (serial) {
544
- var a = rxjs.concat.apply(void 0, __spread(observables)).pipe(operators.map(function (item) {
545
- return rxjs.of([item]);
546
- }), operators.concatAll());
547
- return a;
548
- }
549
- else {
550
- return rxjs.forkJoin(observables).pipe();
551
- }
552
- };
553
- AssetsLoader.prototype.loadStyles = function (sources) {
554
- var _this = this;
555
- if (isEmpty(sources)) {
556
- return rxjs.of(null);
557
- }
558
- return rxjs.forkJoin(sources.map(function (src) {
559
- return _this.loadStyle(src);
560
- }));
561
- };
562
- AssetsLoader.prototype.loadScriptsAndStyles = function (scripts, styles, serial) {
563
- if (scripts === void 0) { scripts = []; }
564
- if (styles === void 0) { styles = []; }
565
- if (serial === void 0) { serial = false; }
566
- return rxjs.forkJoin([this.loadScripts(scripts, serial), this.loadStyles(styles)]);
567
- };
568
- AssetsLoader.prototype.loadAppAssets = function (app) {
569
- var _this = this;
570
- if (app.manifest) {
571
- return this.loadManifest(app.manifest + "?t=" + new Date().getTime()).pipe(operators.switchMap(function (manifestResult) {
572
- var _a = getScriptsAndStylesFullPaths(app, manifestResult), scripts = _a.scripts, styles = _a.styles;
573
- return _this.loadScriptsAndStyles(scripts, styles, app.loadSerial);
574
- }));
575
- }
576
- else {
577
- var _a = getScriptsAndStylesFullPaths(app), scripts = _a.scripts, styles = _a.styles;
578
- return this.loadScriptsAndStyles(scripts, styles, app.loadSerial);
579
- }
580
- };
581
- AssetsLoader.prototype.loadManifest = function (url) {
582
- return this.http.get(url).pipe(operators.map(function (response) {
583
- return response;
584
- }));
585
- };
586
- return AssetsLoader;
587
- }());
588
- AssetsLoader.ɵprov = i0.ɵɵdefineInjectable({ factory: function AssetsLoader_Factory() { return new AssetsLoader(i0.ɵɵinject(i1.HttpClient)); }, token: AssetsLoader, providedIn: "root" });
589
- AssetsLoader.decorators = [
590
- { type: i0.Injectable, args: [{
591
- providedIn: 'root'
592
- },] }
593
- ];
594
- AssetsLoader.ctorParameters = function () { return [
595
- { type: i1.HttpClient }
596
- ]; };
597
-
598
- var PlanetApplicationRef = /** @class */ (function () {
599
- function PlanetApplicationRef(name, options) {
600
- this.name = name;
601
- if (options) {
602
- this.template = options.template;
603
- this.innerSelector = this.template ? getTagNameByTemplate(this.template) : null;
604
- this.appModuleBootstrap = options.bootstrap;
605
- }
606
- // This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
607
- // See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
608
- // NgZone.isInAngularZone = () => {
609
- // // @ts-ignore
610
- // return window.Zone.current._properties[`ngx-planet-${name}`] === true;
611
- // };
612
- }
613
- Object.defineProperty(PlanetApplicationRef.prototype, "selector", {
614
- get: function () {
615
- return this.innerSelector;
616
- },
617
- enumerable: false,
618
- configurable: true
619
- });
620
- Object.defineProperty(PlanetApplicationRef.prototype, "bootstrapped", {
621
- get: function () {
622
- return !!this.appModuleRef;
623
- },
624
- enumerable: false,
625
- configurable: true
626
- });
627
- // 子应用路由变化后同步修改 portal 的 Route
628
- PlanetApplicationRef.prototype.syncPortalRouteWhenNavigationEnd = function () {
629
- var _this = this;
630
- var router = this.appModuleRef.injector.get(i3.Router);
631
- var ngZone = this.appModuleRef.injector.get(i0.NgZone);
632
- if (router) {
633
- router.events.subscribe(function (event) {
634
- if (event instanceof i3.NavigationEnd) {
635
- ngZone.onStable
636
- .asObservable()
637
- .pipe(operators.take(1))
638
- .subscribe(function () {
639
- _this.portalApp.router.navigateByUrl(event.url);
640
- });
641
- }
642
- });
643
- }
644
- };
645
- PlanetApplicationRef.prototype.bootstrap = function (app) {
646
- var _this = this;
647
- if (!this.appModuleBootstrap) {
648
- throw new Error("app(" + this.name + ") is not defined");
649
- }
650
- this.portalApp = app;
651
- return rxjs.from(this.appModuleBootstrap(app).then(function (appModuleRef) {
652
- _this.appModuleRef = appModuleRef;
653
- _this.appModuleRef.instance.appName = _this.name;
654
- _this.syncPortalRouteWhenNavigationEnd();
655
- return _this;
656
- }));
657
- };
658
- PlanetApplicationRef.prototype.getRouter = function () {
659
- return this.appModuleRef.injector.get(i3.Router);
660
- };
661
- PlanetApplicationRef.prototype.getCurrentRouterStateUrl = function () {
662
- return this.getRouter().routerState.snapshot.url;
663
- };
664
- PlanetApplicationRef.prototype.navigateByUrl = function (url) {
665
- var ngZone = this.appModuleRef.injector.get(i0.NgZone);
666
- var router = this.getRouter();
667
- ngZone.run(function () {
668
- router.navigateByUrl(url);
669
- });
670
- };
671
- PlanetApplicationRef.prototype.getComponentFactory = function () {
672
- return this.componentFactory;
673
- };
674
- PlanetApplicationRef.prototype.registerComponentFactory = function (componentFactory) {
675
- this.componentFactory = componentFactory;
676
- };
677
- PlanetApplicationRef.prototype.destroy = function () {
678
- if (this.appModuleRef) {
679
- var router = this.appModuleRef.injector.get(i3.Router);
680
- if (router) {
681
- router.dispose();
682
- }
683
- this.appModuleRef.destroy();
684
- delete this.appModuleRef;
685
- }
686
- };
687
- return PlanetApplicationRef;
688
- }());
689
-
690
- var globalPlanet = (window.planet = window.planet || {
691
- apps: {}
692
- });
693
- function defineApplication(name, options) {
694
- if (globalPlanet.apps[name]) {
695
- throw new Error(name + " application has exist.");
696
- }
697
- if (isFunction(options)) {
698
- options = {
699
- template: '',
700
- bootstrap: options
701
- };
702
- }
703
- var appRef = new PlanetApplicationRef(name, options);
704
- globalPlanet.apps[name] = appRef;
705
- }
706
- function getPlanetApplicationRef(appName) {
707
- if (globalPlanet && globalPlanet.apps && globalPlanet.apps[appName]) {
708
- return globalPlanet.apps[appName];
709
- }
710
- else {
711
- return null;
712
- }
713
- }
714
- function setPortalApplicationData(data) {
715
- globalPlanet.portalApplication.data = data;
716
- }
717
- function getPortalApplicationData() {
718
- return globalPlanet.portalApplication.data;
719
- }
720
- function setApplicationLoader(loader) {
721
- globalPlanet.applicationLoader = loader;
722
- }
723
- function getApplicationLoader() {
724
- return globalPlanet.applicationLoader;
725
- }
726
- function setApplicationService(service) {
727
- globalPlanet.applicationService = service;
728
- }
729
- function getApplicationService() {
730
- return globalPlanet.applicationService;
731
- }
732
- function clearGlobalPlanet() {
733
- window.planet.apps = {};
734
- window.planet.portalApplication = null;
735
- window.planet.applicationLoader = null;
736
- window.planet.applicationService = null;
737
- }
738
-
739
- var PlanetApplicationService = /** @class */ (function () {
740
- function PlanetApplicationService(http, assetsLoader) {
741
- this.http = http;
742
- this.assetsLoader = assetsLoader;
743
- this.apps = [];
744
- this.appsMap = {};
745
- if (getApplicationService()) {
746
- throw new Error('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
747
- }
748
- }
749
- PlanetApplicationService.prototype.register = function (appOrApps) {
750
- var _this = this;
751
- var apps = coerceArray(appOrApps);
752
- apps.forEach(function (app) {
753
- if (_this.appsMap[app.name]) {
754
- throw new Error(app.name + " has be registered.");
755
- }
756
- _this.apps.push(app);
757
- _this.appsMap[app.name] = app;
758
- });
759
- };
760
- PlanetApplicationService.prototype.registerByUrl = function (url) {
761
- var _this = this;
762
- var result = this.http.get("" + url).pipe(operators.map(function (apps) {
763
- if (apps && Array.isArray(apps)) {
764
- _this.register(apps);
765
- }
766
- else {
767
- _this.register(apps);
768
- }
769
- }), operators.shareReplay());
770
- result.subscribe();
771
- return result;
772
- };
773
- PlanetApplicationService.prototype.unregister = function (name) {
774
- if (this.appsMap[name]) {
775
- delete this.appsMap[name];
776
- this.apps = this.apps.filter(function (app) {
777
- return app.name !== name;
778
- });
779
- }
780
- };
781
- PlanetApplicationService.prototype.getAppsByMatchedUrl = function (url) {
782
- return this.getApps().filter(function (app) {
783
- if (app.routerPathPrefix instanceof RegExp) {
784
- return app.routerPathPrefix.test(url);
785
- }
786
- else {
787
- return url.startsWith(app.routerPathPrefix);
788
- }
789
- });
790
- };
791
- PlanetApplicationService.prototype.getAppByName = function (name) {
792
- return this.appsMap[name];
793
- };
794
- PlanetApplicationService.prototype.getAppsToPreload = function (excludeAppNames) {
795
- return this.getApps().filter(function (app) {
796
- if (excludeAppNames) {
797
- return app.preload && !excludeAppNames.includes(app.name);
798
- }
799
- else {
800
- return app.preload;
801
- }
802
- });
803
- };
804
- PlanetApplicationService.prototype.getApps = function () {
805
- return this.apps;
806
- };
807
- return PlanetApplicationService;
808
- }());
809
- PlanetApplicationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function PlanetApplicationService_Factory() { return new PlanetApplicationService(i0.ɵɵinject(i1.HttpClient), i0.ɵɵinject(AssetsLoader)); }, token: PlanetApplicationService, providedIn: "root" });
810
- PlanetApplicationService.decorators = [
811
- { type: i0.Injectable, args: [{
812
- providedIn: 'root'
813
- },] }
814
- ];
815
- PlanetApplicationService.ctorParameters = function () { return [
816
- { type: i1.HttpClient },
817
- { type: AssetsLoader }
818
- ]; };
819
-
820
- var PlanetPortalApplication = /** @class */ (function () {
821
- function PlanetPortalApplication() {
822
- }
823
- PlanetPortalApplication.prototype.navigateByUrl = function (url, extras) {
824
- var _this = this;
825
- return this.ngZone.run(function () {
826
- return _this.router.navigateByUrl(url, extras);
827
- });
828
- };
829
- PlanetPortalApplication.prototype.run = function (fn) {
830
- return this.ngZone.run(function () {
831
- return fn();
832
- });
833
- };
834
- PlanetPortalApplication.prototype.tick = function () {
835
- this.applicationRef.tick();
836
- };
837
- return PlanetPortalApplication;
838
- }());
839
-
840
- var CUSTOM_EVENT_NAME = 'PLANET_GLOBAL_EVENT_DISPATCHER';
841
- var GlobalEventDispatcher = /** @class */ (function () {
842
- function GlobalEventDispatcher(ngZone) {
843
- var _this = this;
844
- this.ngZone = ngZone;
845
- this.subject$ = new rxjs.Subject();
846
- this.hasAddGlobalEventListener = false;
847
- this.subscriptionCount = 0;
848
- this.globalEventListener = function (event) {
849
- _this.subject$.next(event.detail);
850
- };
851
- }
852
- GlobalEventDispatcher.prototype.addGlobalEventListener = function () {
853
- this.hasAddGlobalEventListener = true;
854
- window.addEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
855
- };
856
- GlobalEventDispatcher.prototype.removeGlobalEventListener = function () {
857
- this.hasAddGlobalEventListener = false;
858
- window.removeEventListener(CUSTOM_EVENT_NAME, this.globalEventListener);
859
- };
860
- GlobalEventDispatcher.prototype.dispatch = function (name, payload) {
861
- window.dispatchEvent(new CustomEvent(CUSTOM_EVENT_NAME, {
862
- detail: {
863
- name: name,
864
- payload: payload
865
- }
866
- }));
867
- };
868
- GlobalEventDispatcher.prototype.register = function (eventName) {
869
- var _this = this;
870
- return new rxjs.Observable(function (observer) {
871
- if (!_this.hasAddGlobalEventListener) {
872
- _this.addGlobalEventListener();
873
- }
874
- _this.subscriptionCount++;
875
- var subscription = _this.subject$
876
- .pipe(operators.filter(function (event) {
877
- return event.name === eventName;
878
- }), operators.map(function (event) {
879
- return event.payload;
880
- }))
881
- .subscribe(function (payload) {
882
- _this.ngZone.run(function () {
883
- observer.next(payload);
884
- });
885
- });
886
- return function () {
887
- _this.subscriptionCount--;
888
- subscription.unsubscribe();
889
- if (!_this.subscriptionCount) {
890
- _this.removeGlobalEventListener();
891
- }
892
- };
893
- });
894
- };
895
- GlobalEventDispatcher.prototype.getSubscriptionCount = function () {
896
- return this.subscriptionCount;
897
- };
898
- return GlobalEventDispatcher;
899
- }());
900
- GlobalEventDispatcher.ɵprov = i0.ɵɵdefineInjectable({ factory: function GlobalEventDispatcher_Factory() { return new GlobalEventDispatcher(i0.ɵɵinject(i0.NgZone)); }, token: GlobalEventDispatcher, providedIn: "root" });
901
- GlobalEventDispatcher.decorators = [
902
- { type: i0.Injectable, args: [{
903
- providedIn: 'root'
904
- },] }
905
- ];
906
- GlobalEventDispatcher.ctorParameters = function () { return [
907
- { type: i0.NgZone }
908
- ]; };
909
-
910
- (function (ApplicationStatus) {
911
- ApplicationStatus[ApplicationStatus["assetsLoading"] = 1] = "assetsLoading";
912
- ApplicationStatus[ApplicationStatus["assetsLoaded"] = 2] = "assetsLoaded";
913
- ApplicationStatus[ApplicationStatus["bootstrapping"] = 3] = "bootstrapping";
914
- ApplicationStatus[ApplicationStatus["bootstrapped"] = 4] = "bootstrapped";
915
- ApplicationStatus[ApplicationStatus["active"] = 5] = "active";
916
- ApplicationStatus[ApplicationStatus["loadError"] = 10] = "loadError";
917
- })(exports.ApplicationStatus || (exports.ApplicationStatus = {}));
918
- var PlanetApplicationLoader = /** @class */ (function () {
919
- function PlanetApplicationLoader(assetsLoader, planetApplicationService, ngZone, router, injector, applicationRef) {
920
- this.assetsLoader = assetsLoader;
921
- this.planetApplicationService = planetApplicationService;
922
- this.ngZone = ngZone;
923
- this.firstLoad = true;
924
- this.inProgressAppAssetsLoads = new Map();
925
- this.appsStatus = new Map();
926
- this.portalApp = new PlanetPortalApplication();
927
- this.routeChange$ = new rxjs.Subject();
928
- this.appStatusChange$ = new rxjs.Subject();
929
- this.appsLoadingStart$ = new rxjs.Subject();
930
- this.loadingDone = false;
931
- if (getApplicationLoader()) {
932
- throw new Error('PlanetApplicationLoader has been injected in the portal, repeated injection is not allowed');
933
- }
934
- this.options = {
935
- switchMode: exports.SwitchModes.default,
936
- errorHandler: function (error) {
937
- console.error(error);
938
- }
939
- };
940
- this.portalApp.ngZone = ngZone;
941
- this.portalApp.applicationRef = applicationRef;
942
- this.portalApp.router = router;
943
- this.portalApp.injector = injector;
944
- this.portalApp.globalEventDispatcher = injector.get(GlobalEventDispatcher);
945
- globalPlanet.portalApplication = this.portalApp;
946
- this.setupRouteChange();
947
- }
948
- Object.defineProperty(PlanetApplicationLoader.prototype, "appStatusChange", {
949
- get: function () {
950
- return this.appStatusChange$.asObservable();
951
- },
952
- enumerable: false,
953
- configurable: true
954
- });
955
- Object.defineProperty(PlanetApplicationLoader.prototype, "appsLoadingStart", {
956
- get: function () {
957
- return this.appsLoadingStart$.asObservable();
958
- },
959
- enumerable: false,
960
- configurable: true
961
- });
962
- PlanetApplicationLoader.prototype.setAppStatus = function (app, status) {
963
- var _this = this;
964
- this.ngZone.run(function () {
965
- _this.appStatusChange$.next({
966
- app: app,
967
- status: status
968
- });
969
- _this.appsStatus.set(app, status);
970
- });
971
- };
972
- PlanetApplicationLoader.prototype.switchModeIsCoexist = function (app) {
973
- if (app && app.switchMode) {
974
- return app.switchMode === exports.SwitchModes.coexist;
975
- }
976
- else {
977
- return this.options.switchMode === exports.SwitchModes.coexist;
978
- }
979
- };
980
- PlanetApplicationLoader.prototype.errorHandler = function (error) {
981
- var _this = this;
982
- this.ngZone.run(function () {
983
- _this.options.errorHandler(error);
984
- });
985
- };
986
- PlanetApplicationLoader.prototype.takeOneStable = function () {
987
- return this.ngZone.onStable.pipe(operators.take(1));
988
- };
989
- PlanetApplicationLoader.prototype.setLoadingDone = function () {
990
- var _this = this;
991
- this.ngZone.run(function () {
992
- _this.loadingDone = true;
993
- });
994
- };
995
- PlanetApplicationLoader.prototype.setupRouteChange = function () {
996
- var _this = this;
997
- this.routeChange$
998
- .pipe(operators.distinctUntilChanged(function (x, y) {
999
- return (x && x.url) === (y && y.url);
1000
- }),
1001
- // Using switchMap so we cancel executing loading when a new one comes in
1002
- operators.switchMap(function (event) {
1003
- // Return new observable use of and catchError,
1004
- // in order to prevent routeChange$ completed which never trigger new route change
1005
- return rxjs.of(event).pipe(
1006
- // unload apps and return should load apps
1007
- operators.map(function () {
1008
- _this.startRouteChangeEvent = event;
1009
- var shouldLoadApps = _this.planetApplicationService.getAppsByMatchedUrl(event.url);
1010
- var shouldUnloadApps = _this.getUnloadApps(shouldLoadApps);
1011
- _this.appsLoadingStart$.next({
1012
- shouldLoadApps: shouldLoadApps,
1013
- shouldUnloadApps: shouldUnloadApps
1014
- });
1015
- _this.unloadApps(shouldUnloadApps, event);
1016
- return shouldLoadApps;
1017
- }),
1018
- // Load app assets (static resources)
1019
- operators.switchMap(function (shouldLoadApps) {
1020
- var hasAppsNeedLoadingAssets = false;
1021
- var loadApps$ = shouldLoadApps.map(function (app) {
1022
- var appStatus = _this.appsStatus.get(app);
1023
- if (!appStatus ||
1024
- appStatus === exports.ApplicationStatus.assetsLoading ||
1025
- appStatus === exports.ApplicationStatus.loadError) {
1026
- hasAppsNeedLoadingAssets = true;
1027
- return _this.ngZone.runOutsideAngular(function () {
1028
- return _this.startLoadAppAssets(app);
1029
- });
1030
- }
1031
- else {
1032
- return rxjs.of(app);
1033
- }
1034
- });
1035
- if (hasAppsNeedLoadingAssets) {
1036
- _this.loadingDone = false;
1037
- }
1038
- return loadApps$.length > 0 ? rxjs.forkJoin(loadApps$) : rxjs.of([]);
1039
- }),
1040
- // Bootstrap or show apps
1041
- operators.map(function (apps) {
1042
- var apps$ = [];
1043
- apps.forEach(function (app) {
1044
- var appStatus = _this.appsStatus.get(app);
1045
- if (appStatus === exports.ApplicationStatus.bootstrapped) {
1046
- apps$.push(rxjs.of(app).pipe(operators.tap(function () {
1047
- _this.showApp(app);
1048
- var appRef = getPlanetApplicationRef(app.name);
1049
- appRef.navigateByUrl(event.url);
1050
- _this.setAppStatus(app, exports.ApplicationStatus.active);
1051
- _this.setLoadingDone();
1052
- })));
1053
- }
1054
- else if (appStatus === exports.ApplicationStatus.assetsLoaded) {
1055
- apps$.push(rxjs.of(app).pipe(operators.switchMap(function () {
1056
- return _this.bootstrapApp(app).pipe(operators.map(function () {
1057
- _this.setAppStatus(app, exports.ApplicationStatus.active);
1058
- _this.setLoadingDone();
1059
- return app;
1060
- }));
1061
- })));
1062
- }
1063
- else if (appStatus === exports.ApplicationStatus.active) {
1064
- apps$.push(rxjs.of(app).pipe(operators.tap(function () {
1065
- var appRef = getPlanetApplicationRef(app.name);
1066
- // Backwards compatibility sub app use old version which has not getCurrentRouterStateUrl
1067
- var currentUrl = appRef.getCurrentRouterStateUrl
1068
- ? appRef.getCurrentRouterStateUrl()
1069
- : '';
1070
- if (currentUrl !== event.url) {
1071
- appRef.navigateByUrl(event.url);
1072
- }
1073
- })));
1074
- }
1075
- else {
1076
- throw new Error("app(" + app.name + ")'s status is " + appStatus + ", can't be show or bootstrap");
1077
- }
1078
- });
1079
- if (apps$.length > 0) {
1080
- // 切换到应用后会有闪烁现象,所以使用 setTimeout 后启动应用
1081
- // example: redirect to app1's dashboard from portal's about page
1082
- // If app's route has redirect, it doesn't work, it ok just in setTimeout, I don't know why.
1083
- // TODO:: remove it, it is ok in version Angular 9.x
1084
- setTimeout(function () {
1085
- // 此处判断是因为如果静态资源加载完毕还未启动被取消,还是会启动之前的应用,虽然可能性比较小,但是无法排除这种可能性,所以只有当 Event 是最后一个才会启动
1086
- if (_this.startRouteChangeEvent === event) {
1087
- // runOutsideAngular for fix error: `Expected to not be in Angular Zone, but it is!`
1088
- _this.ngZone.runOutsideAngular(function () {
1089
- rxjs.forkJoin(apps$).subscribe(function () {
1090
- _this.setLoadingDone();
1091
- _this.ensurePreloadApps(apps);
1092
- });
1093
- });
1094
- }
1095
- });
1096
- }
1097
- else {
1098
- _this.ensurePreloadApps(apps);
1099
- _this.setLoadingDone();
1100
- }
1101
- }),
1102
- // Error handler
1103
- operators.catchError(function (error) {
1104
- _this.errorHandler(error);
1105
- return [];
1106
- }));
1107
- }))
1108
- .subscribe();
1109
- };
1110
- PlanetApplicationLoader.prototype.startLoadAppAssets = function (app) {
1111
- var _this = this;
1112
- if (this.inProgressAppAssetsLoads.get(app.name)) {
1113
- return this.inProgressAppAssetsLoads.get(app.name);
1114
- }
1115
- else {
1116
- var loadApp$ = this.assetsLoader.loadAppAssets(app).pipe(operators.tap(function () {
1117
- _this.inProgressAppAssetsLoads.delete(app.name);
1118
- _this.setAppStatus(app, exports.ApplicationStatus.assetsLoaded);
1119
- }), operators.map(function () {
1120
- return app;
1121
- }), operators.catchError(function (error) {
1122
- _this.inProgressAppAssetsLoads.delete(app.name);
1123
- _this.setAppStatus(app, exports.ApplicationStatus.loadError);
1124
- throw error;
1125
- }), operators.share());
1126
- this.inProgressAppAssetsLoads.set(app.name, loadApp$);
1127
- this.setAppStatus(app, exports.ApplicationStatus.assetsLoading);
1128
- return loadApp$;
1129
- }
1130
- };
1131
- PlanetApplicationLoader.prototype.hideApp = function (planetApp) {
1132
- var appRef = getPlanetApplicationRef(planetApp.name);
1133
- var appRootElement = document.querySelector(appRef.selector || planetApp.selector);
1134
- if (appRootElement) {
1135
- appRootElement.setAttribute('style', 'display:none;');
1136
- }
1137
- };
1138
- PlanetApplicationLoader.prototype.showApp = function (planetApp) {
1139
- var appRef = getPlanetApplicationRef(planetApp.name);
1140
- var appRootElement = document.querySelector(appRef.selector || planetApp.selector);
1141
- if (appRootElement) {
1142
- appRootElement.setAttribute('style', '');
1143
- }
1144
- };
1145
- PlanetApplicationLoader.prototype.destroyApp = function (planetApp) {
1146
- var appRef = getPlanetApplicationRef(planetApp.name);
1147
- if (appRef) {
1148
- appRef.destroy();
1149
- }
1150
- var container = getHTMLElement(planetApp.hostParent);
1151
- var appRootElement = container.querySelector((appRef && appRef.selector) || planetApp.selector);
1152
- if (appRootElement) {
1153
- container.removeChild(appRootElement);
1154
- }
1155
- };
1156
- PlanetApplicationLoader.prototype.bootstrapApp = function (app, defaultStatus) {
1157
- var _a, _b;
1158
- var _this = this;
1159
- if (defaultStatus === void 0) { defaultStatus = 'display'; }
1160
- this.setAppStatus(app, exports.ApplicationStatus.bootstrapping);
1161
- var appRef = getPlanetApplicationRef(app.name);
1162
- if (appRef && appRef.bootstrap) {
1163
- var container = getHTMLElement(app.hostParent);
1164
- var appRootElement_1;
1165
- if (container) {
1166
- appRootElement_1 = container.querySelector(appRef.selector || app.selector);
1167
- if (!appRootElement_1) {
1168
- if (appRef.template) {
1169
- appRootElement_1 = createElementByTemplate(appRef.template);
1170
- }
1171
- else {
1172
- appRootElement_1 = document.createElement(app.selector);
1173
- }
1174
- appRootElement_1.setAttribute('style', 'display:none;');
1175
- if (app.hostClass) {
1176
- (_a = appRootElement_1.classList).add.apply(_a, __spread(coerceArray(app.hostClass)));
1177
- }
1178
- if (app.stylePrefix) {
1179
- (_b = appRootElement_1.classList).add.apply(_b, __spread(coerceArray(app.stylePrefix)));
1180
- }
1181
- container.appendChild(appRootElement_1);
1182
- }
1183
- }
1184
- var result = appRef.bootstrap(this.portalApp);
1185
- // Backwards compatibility promise for bootstrap
1186
- if (result['then']) {
1187
- result = rxjs.from(result);
1188
- }
1189
- return result.pipe(operators.tap(function () {
1190
- _this.setAppStatus(app, exports.ApplicationStatus.bootstrapped);
1191
- if (defaultStatus === 'display' && appRootElement_1) {
1192
- appRootElement_1.removeAttribute('style');
1193
- }
1194
- }), operators.map(function () {
1195
- return appRef;
1196
- }));
1197
- }
1198
- else {
1199
- 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");
1200
- }
1201
- };
1202
- PlanetApplicationLoader.prototype.getUnloadApps = function (activeApps) {
1203
- var unloadApps = [];
1204
- this.appsStatus.forEach(function (value, app) {
1205
- if (value === exports.ApplicationStatus.active && !activeApps.find(function (item) { return item.name === app.name; })) {
1206
- unloadApps.push(app);
1207
- }
1208
- });
1209
- return unloadApps;
1210
- };
1211
- PlanetApplicationLoader.prototype.unloadApps = function (shouldUnloadApps, event) {
1212
- var _this = this;
1213
- var hideApps = [];
1214
- var destroyApps = [];
1215
- shouldUnloadApps.forEach(function (app) {
1216
- if (_this.switchModeIsCoexist(app)) {
1217
- hideApps.push(app);
1218
- _this.hideApp(app);
1219
- _this.setAppStatus(app, exports.ApplicationStatus.bootstrapped);
1220
- }
1221
- else {
1222
- destroyApps.push(app);
1223
- // 销毁之前先隐藏,否则会出现闪烁,因为 destroy 是延迟执行的
1224
- // 如果销毁不延迟执行,会出现切换到主应用的时候会有视图卡顿现象
1225
- _this.hideApp(app);
1226
- _this.setAppStatus(app, exports.ApplicationStatus.assetsLoaded);
1227
- }
1228
- });
1229
- if (hideApps.length > 0 || destroyApps.length > 0) {
1230
- // 从其他应用切换到主应用的时候会有视图卡顿现象,所以先等主应用渲染完毕后再加载其他应用
1231
- // 此处尝试使用 this.ngZone.onStable.pipe(take(1)) 应用之间的切换会出现闪烁
1232
- setTimeout(function () {
1233
- hideApps.forEach(function (app) {
1234
- var appRef = getPlanetApplicationRef(app.name);
1235
- if (appRef) {
1236
- appRef.navigateByUrl(event.url);
1237
- }
1238
- });
1239
- destroyApps.forEach(function (app) {
1240
- _this.destroyApp(app);
1241
- });
1242
- });
1243
- }
1244
- };
1245
- PlanetApplicationLoader.prototype.preloadApps = function (activeApps) {
1246
- var _this = this;
1247
- setTimeout(function () {
1248
- var toPreloadApps = _this.planetApplicationService.getAppsToPreload(activeApps ? activeApps.map(function (item) { return item.name; }) : null);
1249
- var loadApps$ = toPreloadApps.map(function (preloadApp) {
1250
- return _this.preloadInternal(preloadApp);
1251
- });
1252
- rxjs.forkJoin(loadApps$).subscribe({
1253
- error: function (error) { return _this.errorHandler(error); }
1254
- });
1255
- });
1256
- };
1257
- PlanetApplicationLoader.prototype.ensurePreloadApps = function (activeApps) {
1258
- // Start preload apps
1259
- // Start preload when first time app loaded
1260
- if (this.firstLoad) {
1261
- this.preloadApps(activeApps);
1262
- this.firstLoad = false;
1263
- }
1264
- };
1265
- PlanetApplicationLoader.prototype.setOptions = function (options) {
1266
- this.options = Object.assign(Object.assign({}, this.options), options);
1267
- };
1268
- /**
1269
- * reset route by current router
1270
- */
1271
- PlanetApplicationLoader.prototype.reroute = function (event) {
1272
- this.routeChange$.next(event);
1273
- };
1274
- PlanetApplicationLoader.prototype.preloadInternal = function (app, immediate) {
1275
- var _this = this;
1276
- var status = this.appsStatus.get(app);
1277
- if (!status || status === exports.ApplicationStatus.loadError) {
1278
- return this.startLoadAppAssets(app).pipe(operators.switchMap(function () {
1279
- if (immediate) {
1280
- return _this.bootstrapApp(app, 'hidden');
1281
- }
1282
- else {
1283
- return _this.ngZone.runOutsideAngular(function () {
1284
- return _this.bootstrapApp(app, 'hidden');
1285
- });
1286
- }
1287
- }), operators.map(function () {
1288
- return getPlanetApplicationRef(app.name);
1289
- }));
1290
- }
1291
- else if ([exports.ApplicationStatus.assetsLoading, exports.ApplicationStatus.assetsLoaded, exports.ApplicationStatus.bootstrapping].includes(status)) {
1292
- return this.appStatusChange.pipe(operators.filter(function (event) {
1293
- return event.app === app && event.status === exports.ApplicationStatus.bootstrapped;
1294
- }), operators.take(1), operators.map(function () {
1295
- return getPlanetApplicationRef(app.name);
1296
- }));
1297
- }
1298
- else {
1299
- var appRef = getPlanetApplicationRef(app.name);
1300
- if (!appRef) {
1301
- throw new Error(app.name + "'s status is " + exports.ApplicationStatus[status] + ", planetApplicationRef is null.");
1302
- }
1303
- return rxjs.of(appRef);
1304
- }
1305
- };
1306
- /**
1307
- * Preload planet application
1308
- * @param app app
1309
- * @param immediate bootstrap on stable by default, setting immediate is true, it will bootstrap immediate
1310
- */
1311
- PlanetApplicationLoader.prototype.preload = function (app, immediate) {
1312
- return this.preloadInternal(app, immediate);
1313
- };
1314
- return PlanetApplicationLoader;
1315
- }());
1316
- PlanetApplicationLoader.ɵprov = i0.ɵɵdefineInjectable({ factory: function PlanetApplicationLoader_Factory() { return new PlanetApplicationLoader(i0.ɵɵinject(AssetsLoader), i0.ɵɵinject(PlanetApplicationService), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i3.Router), i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i0.ApplicationRef)); }, token: PlanetApplicationLoader, providedIn: "root" });
1317
- PlanetApplicationLoader.decorators = [
1318
- { type: i0.Injectable, args: [{
1319
- providedIn: 'root'
1320
- },] }
1321
- ];
1322
- PlanetApplicationLoader.ctorParameters = function () { return [
1323
- { type: AssetsLoader },
1324
- { type: PlanetApplicationService },
1325
- { type: i0.NgZone },
1326
- { type: i3.Router },
1327
- { type: i0.Injector },
1328
- { type: i0.ApplicationRef }
1329
- ]; };
1330
-
1331
- var Planet = /** @class */ (function () {
1332
- function Planet(injector, router, planetApplications) {
1333
- this.injector = injector;
1334
- this.router = router;
1335
- if (!this.planetApplicationLoader) {
1336
- setApplicationLoader(this.injector.get(PlanetApplicationLoader));
1337
- }
1338
- if (!this.planetApplicationService) {
1339
- setApplicationService(this.injector.get(PlanetApplicationService));
1340
- }
1341
- if (planetApplications) {
1342
- this.registerApps(planetApplications);
1343
- }
1344
- }
1345
- Object.defineProperty(Planet.prototype, "planetApplicationLoader", {
1346
- get: function () {
1347
- return getApplicationLoader();
1348
- },
1349
- enumerable: false,
1350
- configurable: true
1351
- });
1352
- Object.defineProperty(Planet.prototype, "planetApplicationService", {
1353
- get: function () {
1354
- return getApplicationService();
1355
- },
1356
- enumerable: false,
1357
- configurable: true
1358
- });
1359
- Object.defineProperty(Planet.prototype, "loadingDone", {
1360
- get: function () {
1361
- return this.planetApplicationLoader.loadingDone;
1362
- },
1363
- enumerable: false,
1364
- configurable: true
1365
- });
1366
- Object.defineProperty(Planet.prototype, "appStatusChange", {
1367
- get: function () {
1368
- return this.planetApplicationLoader.appStatusChange;
1369
- },
1370
- enumerable: false,
1371
- configurable: true
1372
- });
1373
- Object.defineProperty(Planet.prototype, "appsLoadingStart", {
1374
- get: function () {
1375
- return this.planetApplicationLoader.appsLoadingStart;
1376
- },
1377
- enumerable: false,
1378
- configurable: true
1379
- });
1380
- Planet.prototype.setOptions = function (options) {
1381
- this.planetApplicationLoader.setOptions(options);
1382
- };
1383
- Planet.prototype.setPortalAppData = function (data) {
1384
- setPortalApplicationData(data);
1385
- };
1386
- Planet.prototype.registerApp = function (app) {
1387
- this.planetApplicationService.register(app);
1388
- };
1389
- Planet.prototype.registerApps = function (apps) {
1390
- this.planetApplicationService.register(apps);
1391
- };
1392
- Planet.prototype.unregisterApp = function (name) {
1393
- this.planetApplicationService.unregister(name);
1394
- };
1395
- Planet.prototype.getApps = function () {
1396
- return this.planetApplicationService.getApps();
1397
- };
1398
- Planet.prototype.start = function () {
1399
- var _this = this;
1400
- this.subscription = this.router.events
1401
- .pipe(operators.filter(function (event) {
1402
- return event instanceof i3.NavigationEnd;
1403
- }), operators.map(function (event) {
1404
- return event.urlAfterRedirects || event.url;
1405
- }), operators.startWith(location.pathname), operators.distinctUntilChanged())
1406
- .subscribe(function (url) {
1407
- _this.planetApplicationLoader.reroute({
1408
- url: url
1409
- });
1410
- });
1411
- };
1412
- Planet.prototype.stop = function () {
1413
- this.subscription.unsubscribe();
1414
- };
1415
- return Planet;
1416
- }());
1417
- Planet.ɵprov = i0.ɵɵdefineInjectable({ factory: function Planet_Factory() { return new Planet(i0.ɵɵinject(i0.INJECTOR), i0.ɵɵinject(i3.Router), i0.ɵɵinject(PLANET_APPLICATIONS, 8)); }, token: Planet, providedIn: "root" });
1418
- Planet.decorators = [
1419
- { type: i0.Injectable, args: [{
1420
- providedIn: 'root'
1421
- },] }
1422
- ];
1423
- Planet.ctorParameters = function () { return [
1424
- { type: i0.Injector },
1425
- { type: i3.Router },
1426
- { type: Array, decorators: [{ type: i0.Inject, args: [PLANET_APPLICATIONS,] }, { type: i0.Optional }] }
1427
- ]; };
1428
-
1429
- var EmptyComponent = /** @class */ (function () {
1430
- function EmptyComponent() {
1431
- }
1432
- return EmptyComponent;
1433
- }());
1434
- EmptyComponent.decorators = [
1435
- { type: i0.Component, args: [{
1436
- selector: 'empty-component',
1437
- template: ""
1438
- },] }
1439
- ];
1440
-
1441
- var NgxPlanetModule = /** @class */ (function () {
1442
- function NgxPlanetModule() {
1443
- }
1444
- NgxPlanetModule.forRoot = function (apps) {
1445
- return {
1446
- ngModule: NgxPlanetModule,
1447
- providers: [
1448
- {
1449
- provide: PLANET_APPLICATIONS,
1450
- useValue: apps
1451
- }
1452
- ]
1453
- };
1454
- };
1455
- return NgxPlanetModule;
1456
- }());
1457
- NgxPlanetModule.decorators = [
1458
- { type: i0.NgModule, args: [{
1459
- declarations: [EmptyComponent],
1460
- entryComponents: [EmptyComponent],
1461
- imports: [i1.HttpClientModule],
1462
- providers: [],
1463
- exports: [i1.HttpClientModule, EmptyComponent]
1464
- },] }
1465
- ];
1466
-
1467
- var PlanetComponentRef = /** @class */ (function () {
1468
- function PlanetComponentRef() {
1469
- }
1470
- return PlanetComponentRef;
1471
- }());
1472
-
1473
- var componentWrapperClass = 'planet-component-wrapper';
1474
- var PlanetComponentLoader = /** @class */ (function () {
1475
- function PlanetComponentLoader(applicationRef, ngModuleRef, ngZone, document) {
1476
- this.applicationRef = applicationRef;
1477
- this.ngModuleRef = ngModuleRef;
1478
- this.ngZone = ngZone;
1479
- this.document = document;
1480
- this.domPortalOutletCache = new WeakMap();
1481
- }
1482
- Object.defineProperty(PlanetComponentLoader.prototype, "applicationLoader", {
1483
- get: function () {
1484
- return getApplicationLoader();
1485
- },
1486
- enumerable: false,
1487
- configurable: true
1488
- });
1489
- Object.defineProperty(PlanetComponentLoader.prototype, "applicationService", {
1490
- get: function () {
1491
- return getApplicationService();
1492
- },
1493
- enumerable: false,
1494
- configurable: true
1495
- });
1496
- PlanetComponentLoader.prototype.getPlantAppRef = function (name) {
1497
- if (globalPlanet.apps[name] && globalPlanet.apps[name].appModuleRef) {
1498
- return rxjs.of(globalPlanet.apps[name]);
1499
- }
1500
- else {
1501
- var app = this.applicationService.getAppByName(name);
1502
- return this.applicationLoader.preload(app, true).pipe(operators.map(function () {
1503
- return globalPlanet.apps[name];
1504
- }));
1505
- }
1506
- };
1507
- PlanetComponentLoader.prototype.createInjector = function (appModuleRef, componentRef) {
1508
- var injectionTokens = new WeakMap([[PlanetComponentRef, componentRef]]);
1509
- var defaultInjector = appModuleRef.injector;
1510
- return new portal.PortalInjector(defaultInjector, injectionTokens);
1511
- };
1512
- PlanetComponentLoader.prototype.getContainerElement = function (config) {
1513
- if (!config.container) {
1514
- throw new Error("config 'container' cannot be null");
1515
- }
1516
- else {
1517
- if (config.container.nativeElement) {
1518
- return config.container.nativeElement;
1519
- }
1520
- else {
1521
- return config.container;
1522
- }
1523
- }
1524
- };
1525
- PlanetComponentLoader.prototype.createWrapperElement = function (config) {
1526
- var container = this.getContainerElement(config);
1527
- var element = this.document.createElement('div');
1528
- var subApp = this.applicationService.getAppByName(this.ngModuleRef.instance.appName);
1529
- element.classList.add(componentWrapperClass);
1530
- element.setAttribute('planet-inline', '');
1531
- if (config.wrapperClass) {
1532
- element.classList.add(config.wrapperClass);
1533
- }
1534
- if (subApp && subApp.stylePrefix) {
1535
- element.classList.add(subApp.stylePrefix);
1536
- }
1537
- container.appendChild(element);
1538
- return element;
1539
- };
1540
- PlanetComponentLoader.prototype.attachComponent = function (plantComponent, appModuleRef, config) {
1541
- var _this = this;
1542
- var plantComponentRef = new PlanetComponentRef();
1543
- var componentFactoryResolver = appModuleRef.componentFactoryResolver;
1544
- var appRef = this.applicationRef;
1545
- var injector = this.createInjector(appModuleRef, plantComponentRef);
1546
- var wrapper = this.createWrapperElement(config);
1547
- var portalOutlet = this.domPortalOutletCache.get(wrapper);
1548
- if (portalOutlet) {
1549
- portalOutlet.detach();
1550
- }
1551
- else {
1552
- portalOutlet = new portal.DomPortalOutlet(wrapper, componentFactoryResolver, appRef, injector);
1553
- this.domPortalOutletCache.set(wrapper, portalOutlet);
1554
- }
1555
- var componentPortal = new portal.ComponentPortal(plantComponent.component, null);
1556
- var componentRef = portalOutlet.attachComponentPortal(componentPortal);
1557
- if (config.initialState) {
1558
- Object.assign(componentRef.instance, config.initialState);
1559
- }
1560
- plantComponentRef.componentInstance = componentRef.instance;
1561
- plantComponentRef.componentRef = componentRef;
1562
- plantComponentRef.wrapperElement = wrapper;
1563
- plantComponentRef.dispose = function () {
1564
- _this.domPortalOutletCache.delete(wrapper);
1565
- portalOutlet.dispose();
1566
- };
1567
- return plantComponentRef;
1568
- };
1569
- PlanetComponentLoader.prototype.registerComponentFactory = function (componentOrComponents) {
1570
- var _this = this;
1571
- var app = this.ngModuleRef.instance.appName;
1572
- this.getPlantAppRef(app).subscribe(function (appRef) {
1573
- appRef.registerComponentFactory(function (componentName, config) {
1574
- var components = coerceArray(componentOrComponents);
1575
- var component = components.find(function (item) { return item.name === componentName; });
1576
- if (component) {
1577
- return _this.ngZone.run(function () {
1578
- var componentRef = _this.attachComponent(component, appRef.appModuleRef, config);
1579
- return componentRef;
1580
- });
1581
- }
1582
- else {
1583
- throw Error("unregistered component " + componentName + " in app " + app);
1584
- }
1585
- });
1586
- });
1587
- };
1588
- PlanetComponentLoader.prototype.register = function (components) {
1589
- var _this = this;
1590
- setTimeout(function () {
1591
- _this.registerComponentFactory(components);
1592
- });
1593
- };
1594
- PlanetComponentLoader.prototype.load = function (app, componentName, config) {
1595
- var _this = this;
1596
- var result = this.getPlantAppRef(app).pipe(operators.delayWhen(function (appRef) {
1597
- if (appRef.getComponentFactory()) {
1598
- return rxjs.of();
1599
- }
1600
- else {
1601
- // Because register use 'setTimeout',so timer 20
1602
- return rxjs.timer(20);
1603
- }
1604
- }), operators.map(function (appRef) {
1605
- var componentFactory = appRef.getComponentFactory();
1606
- if (componentFactory) {
1607
- return componentFactory(componentName, config);
1608
- }
1609
- else {
1610
- throw new Error(app + "'s component(" + componentName + ") is not registered");
1611
- }
1612
- }), operators.finalize(function () {
1613
- _this.applicationRef.tick();
1614
- }), operators.shareReplay());
1615
- result.subscribe();
1616
- return result;
1617
- };
1618
- return PlanetComponentLoader;
1619
- }());
1620
- PlanetComponentLoader.ɵprov = i0.ɵɵdefineInjectable({ factory: function PlanetComponentLoader_Factory() { return new PlanetComponentLoader(i0.ɵɵinject(i0.ApplicationRef), i0.ɵɵinject(i0.NgModuleRef), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i1$1.DOCUMENT)); }, token: PlanetComponentLoader, providedIn: "root" });
1621
- PlanetComponentLoader.decorators = [
1622
- { type: i0.Injectable, args: [{
1623
- providedIn: 'root'
1624
- },] }
1625
- ];
1626
- PlanetComponentLoader.ctorParameters = function () { return [
1627
- { type: i0.ApplicationRef },
1628
- { type: i0.NgModuleRef },
1629
- { type: i0.NgZone },
1630
- { type: undefined, decorators: [{ type: i0.Inject, args: [i1$1.DOCUMENT,] }] }
1631
- ]; };
1632
-
1633
- var PlantComponentConfig = /** @class */ (function () {
1634
- function PlantComponentConfig() {
1635
- /** Data being injected into the child component. */
1636
- this.initialState = null;
1637
- }
1638
- return PlantComponentConfig;
1639
- }());
1640
-
1641
- /*
1642
- * Public API Surface of core
1643
- */
1644
-
1645
- /**
1646
- * Generated bundle index. Do not edit.
1647
- */
1648
-
1649
- exports.AssetsLoader = AssetsLoader;
1650
- exports.EmptyComponent = EmptyComponent;
1651
- exports.GlobalEventDispatcher = GlobalEventDispatcher;
1652
- exports.NgxPlanetModule = NgxPlanetModule;
1653
- exports.PLANET_APPLICATIONS = PLANET_APPLICATIONS;
1654
- exports.Planet = Planet;
1655
- exports.PlanetApplicationLoader = PlanetApplicationLoader;
1656
- exports.PlanetApplicationRef = PlanetApplicationRef;
1657
- exports.PlanetApplicationService = PlanetApplicationService;
1658
- exports.PlanetComponentLoader = PlanetComponentLoader;
1659
- exports.PlanetComponentRef = PlanetComponentRef;
1660
- exports.PlanetPortalApplication = PlanetPortalApplication;
1661
- exports.PlantComponentConfig = PlantComponentConfig;
1662
- exports.defineApplication = defineApplication;
1663
- exports.getPlanetApplicationRef = getPlanetApplicationRef;
1664
- exports.getPortalApplicationData = getPortalApplicationData;
1665
- exports.ɵa = globalPlanet;
1666
-
1667
- Object.defineProperty(exports, '__esModule', { value: true });
1668
-
1669
- })));
1670
- //# sourceMappingURL=worktile-planet.umd.js.map