@worktile/planet 12.1.1 → 14.0.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/application/planet-application-loader.d.ts +73 -0
  3. package/application/planet-application-loader.d.ts.map +1 -0
  4. package/application/planet-application-ref.d.ts +36 -0
  5. package/application/planet-application-ref.d.ts.map +1 -0
  6. package/application/planet-application.service.d.ts +22 -0
  7. package/application/planet-application.service.d.ts.map +1 -0
  8. package/{packages/planet/src/application/portal-application.ts → application/portal-application.d.ts} +5 -18
  9. package/application/portal-application.d.ts.map +1 -0
  10. package/assets-loader.d.ts +36 -0
  11. package/assets-loader.d.ts.map +1 -0
  12. package/component/planet-component-loader.d.ts +31 -0
  13. package/component/planet-component-loader.d.ts.map +1 -0
  14. package/component/planet-component-ref.d.ts +8 -0
  15. package/component/planet-component-ref.d.ts.map +1 -0
  16. package/{packages/planet/src/component/plant-component.config.ts → component/plant-component.config.d.ts} +4 -4
  17. package/component/plant-component.config.d.ts.map +1 -0
  18. package/debug.d.ts +22 -0
  19. package/debug.d.ts.map +1 -0
  20. package/empty/empty.component.d.ts +6 -0
  21. package/empty/empty.component.d.ts.map +1 -0
  22. package/esm2020/application/planet-application-loader.mjs +454 -0
  23. package/esm2020/application/planet-application-ref.mjs +94 -0
  24. package/esm2020/application/planet-application.service.mjs +85 -0
  25. package/esm2020/application/portal-application.mjs +16 -0
  26. package/esm2020/assets-loader.mjs +216 -0
  27. package/esm2020/component/planet-component-loader.mjs +153 -0
  28. package/esm2020/component/planet-component-ref.mjs +3 -0
  29. package/esm2020/component/plant-component.config.mjs +7 -0
  30. package/esm2020/debug.mjs +33 -0
  31. package/esm2020/empty/empty.component.mjs +15 -0
  32. package/esm2020/global-event-dispatcher.mjs +70 -0
  33. package/esm2020/global-planet.mjs +53 -0
  34. package/esm2020/helpers.mjs +119 -0
  35. package/esm2020/module.mjs +31 -0
  36. package/esm2020/planet.class.mjs +9 -0
  37. package/esm2020/planet.mjs +91 -0
  38. package/esm2020/public-api.mjs +18 -0
  39. package/esm2020/sandbox/constants.mjs +7 -0
  40. package/esm2020/sandbox/exec.mjs +15 -0
  41. package/esm2020/sandbox/index.mjs +20 -0
  42. package/esm2020/sandbox/proxy/patches/document.mjs +12 -0
  43. package/esm2020/sandbox/proxy/patches/eventListener.mjs +41 -0
  44. package/esm2020/sandbox/proxy/patches/index.mjs +11 -0
  45. package/esm2020/sandbox/proxy/patches/storage.mjs +40 -0
  46. package/esm2020/sandbox/proxy/patches/timer.mjs +43 -0
  47. package/esm2020/sandbox/proxy/proxies/common.mjs +132 -0
  48. package/esm2020/sandbox/proxy/proxies/document.mjs +126 -0
  49. package/esm2020/sandbox/proxy/proxies/window.mjs +158 -0
  50. package/esm2020/sandbox/proxy/proxy-sandbox.mjs +49 -0
  51. package/esm2020/sandbox/proxy/types.mjs +2 -0
  52. package/esm2020/sandbox/sandbox.mjs +7 -0
  53. package/esm2020/sandbox/snapshot/snapshot-sandbox.mjs +12 -0
  54. package/esm2020/sandbox/types.mjs +2 -0
  55. package/esm2020/worktile-planet.mjs +5 -0
  56. package/fesm2015/worktile-planet.mjs +2049 -0
  57. package/fesm2015/worktile-planet.mjs.map +1 -0
  58. package/fesm2020/worktile-planet.mjs +2046 -0
  59. package/fesm2020/worktile-planet.mjs.map +1 -0
  60. package/global-event-dispatcher.d.ts +23 -0
  61. package/global-event-dispatcher.d.ts.map +1 -0
  62. package/global-planet.d.ts +23 -0
  63. package/global-planet.d.ts.map +1 -0
  64. package/helpers.d.ts +39 -0
  65. package/helpers.d.ts.map +1 -0
  66. package/index.d.ts +6 -0
  67. package/module.d.ts +12 -0
  68. package/module.d.ts.map +1 -0
  69. package/package.json +27 -120
  70. package/{packages/planet/src/planet.class.ts → planet.class.d.ts} +5 -26
  71. package/planet.class.d.ts.map +1 -0
  72. package/planet.d.ts +28 -0
  73. package/planet.d.ts.map +1 -0
  74. package/{packages/planet/src/public-api.ts → public-api.d.ts} +1 -4
  75. package/public-api.d.ts.map +1 -0
  76. package/sandbox/constants.d.ts +7 -0
  77. package/sandbox/constants.d.ts.map +1 -0
  78. package/sandbox/exec.d.ts +3 -0
  79. package/sandbox/exec.d.ts.map +1 -0
  80. package/sandbox/index.d.ts +7 -0
  81. package/sandbox/index.d.ts.map +1 -0
  82. package/sandbox/proxy/patches/document.d.ts +3 -0
  83. package/sandbox/proxy/patches/document.d.ts.map +1 -0
  84. package/sandbox/proxy/patches/eventListener.d.ts +3 -0
  85. package/sandbox/proxy/patches/eventListener.d.ts.map +1 -0
  86. package/sandbox/proxy/patches/index.d.ts +3 -0
  87. package/sandbox/proxy/patches/index.d.ts.map +1 -0
  88. package/sandbox/proxy/patches/storage.d.ts +15 -0
  89. package/sandbox/proxy/patches/storage.d.ts.map +1 -0
  90. package/sandbox/proxy/patches/timer.d.ts +3 -0
  91. package/sandbox/proxy/patches/timer.d.ts.map +1 -0
  92. package/sandbox/proxy/proxies/common.d.ts +13 -0
  93. package/sandbox/proxy/proxies/common.d.ts.map +1 -0
  94. package/sandbox/proxy/proxies/document.d.ts +14 -0
  95. package/sandbox/proxy/proxies/document.d.ts.map +1 -0
  96. package/sandbox/proxy/proxies/window.d.ts +13 -0
  97. package/sandbox/proxy/proxies/window.d.ts.map +1 -0
  98. package/sandbox/proxy/proxy-sandbox.d.ts +16 -0
  99. package/sandbox/proxy/proxy-sandbox.d.ts.map +1 -0
  100. package/{packages/planet/src/sandbox/proxy/types.ts → sandbox/proxy/types.d.ts} +2 -8
  101. package/sandbox/proxy/types.d.ts.map +1 -0
  102. package/sandbox/sandbox.d.ts +12 -0
  103. package/sandbox/sandbox.d.ts.map +1 -0
  104. package/sandbox/snapshot/snapshot-sandbox.d.ts +9 -0
  105. package/sandbox/snapshot/snapshot-sandbox.d.ts.map +1 -0
  106. package/sandbox/types.d.ts +2 -0
  107. package/sandbox/types.d.ts.map +1 -0
  108. package/worktile-planet.d.ts.map +1 -0
  109. package/.all-contributorsrc +0 -84
  110. package/.circleci/config.yml +0 -17
  111. package/.coveralls.yml +0 -1
  112. package/.docgeni/public/assets/favicon.ico +0 -0
  113. package/.docgeni/public/index.html +0 -13
  114. package/.docgenirc.js +0 -35
  115. package/.dockerignore +0 -1
  116. package/.editorconfig +0 -22
  117. package/.github/FUNDING.yml +0 -12
  118. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  119. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  120. package/.prettierignore +0 -7
  121. package/.prettierrc +0 -28
  122. package/.travis.yml +0 -26
  123. package/.wpmrc.js +0 -11
  124. package/CODE_OF_CONDUCT.md +0 -76
  125. package/Dockerfile +0 -11
  126. package/README.zh-CN.md +0 -307
  127. package/SECURITY.md +0 -21
  128. package/angular.json +0 -373
  129. package/commitlint.config.js +0 -6
  130. package/docs/api/defineApplication.md +0 -46
  131. package/docs/api/globalEventDispatcher.md +0 -51
  132. package/docs/api/index.md +0 -5
  133. package/docs/api/planet.md +0 -117
  134. package/docs/guides/getting-started.md +0 -174
  135. package/docs/guides/index.md +0 -5
  136. package/docs/guides/intro.md +0 -216
  137. package/examples/app1/browserslist +0 -11
  138. package/examples/app1/extra-webpack.config.js +0 -33
  139. package/examples/app1/karma.conf.js +0 -31
  140. package/examples/app1/postcss.config.js +0 -1
  141. package/examples/app1/src/app/app.module.ts +0 -44
  142. package/examples/app1/src/app/app.routing.ts +0 -49
  143. package/examples/app1/src/app/counter.service.ts +0 -16
  144. package/examples/app1/src/app/dashboard/dashboard.component.html +0 -51
  145. package/examples/app1/src/app/dashboard/dashboard.component.ts +0 -70
  146. package/examples/app1/src/app/detail/detail.component.html +0 -8
  147. package/examples/app1/src/app/detail/detail.component.ts +0 -18
  148. package/examples/app1/src/app/overlay.ts +0 -26
  149. package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +0 -10
  150. package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +0 -41
  151. package/examples/app1/src/app/projects/projects.component.ts +0 -33
  152. package/examples/app1/src/app/root/root.component.css +0 -3
  153. package/examples/app1/src/app/root/root.component.html +0 -16
  154. package/examples/app1/src/app/root/root.component.ts +0 -35
  155. package/examples/app1/src/app/services/initialized-data.resolver.ts +0 -15
  156. package/examples/app1/src/app/shared.module.ts +0 -57
  157. package/examples/app1/src/app/user/detail/user-detail.component.html +0 -5
  158. package/examples/app1/src/app/user/detail/user-detail.component.ts +0 -20
  159. package/examples/app1/src/app/user/user-list.component.html +0 -7
  160. package/examples/app1/src/app/user/user-list.component.ts +0 -20
  161. package/examples/app1/src/app/user/user.module.ts +0 -31
  162. package/examples/app1/src/assets/.gitkeep +0 -0
  163. package/examples/app1/src/assets/github.png +0 -0
  164. package/examples/app1/src/assets/main.css +0 -3
  165. package/examples/app1/src/environments/environment.prod.ts +0 -3
  166. package/examples/app1/src/environments/environment.ts +0 -16
  167. package/examples/app1/src/favicon.ico +0 -0
  168. package/examples/app1/src/index.html +0 -14
  169. package/examples/app1/src/main.ts +0 -35
  170. package/examples/app1/src/polyfills.ts +0 -84
  171. package/examples/app1/src/styles.scss +0 -35
  172. package/examples/app1/src/test.ts +0 -14
  173. package/examples/app1/temp.js +0 -221
  174. package/examples/app1/tsconfig.app.json +0 -10
  175. package/examples/app1/tsconfig.spec.json +0 -18
  176. package/examples/app1/tslint.json +0 -17
  177. package/examples/app1/webpack.config.js +0 -127
  178. package/examples/app2/browserslist +0 -11
  179. package/examples/app2/extra-webpack.config.js +0 -32
  180. package/examples/app2/karma.conf.js +0 -31
  181. package/examples/app2/src/app/app.module.ts +0 -90
  182. package/examples/app2/src/app/dashboard/dashboard.component.html +0 -21
  183. package/examples/app2/src/app/dashboard/dashboard.component.ts +0 -27
  184. package/examples/app2/src/app/overlay.ts +0 -26
  185. package/examples/app2/src/app/projects/detail/detail.component.html +0 -16
  186. package/examples/app2/src/app/projects/detail/detail.component.ts +0 -21
  187. package/examples/app2/src/app/projects/project-list.component.html +0 -29
  188. package/examples/app2/src/app/projects/project-list.component.ts +0 -58
  189. package/examples/app2/src/app/projects/project.resolver.ts +0 -15
  190. package/examples/app2/src/app/projects/projects.service.ts +0 -28
  191. package/examples/app2/src/app/projects/tasks/tasks.component.html +0 -10
  192. package/examples/app2/src/app/projects/tasks/tasks.component.ts +0 -16
  193. package/examples/app2/src/app/projects/view/view.component.html +0 -1
  194. package/examples/app2/src/app/projects/view/view.component.ts +0 -20
  195. package/examples/app2/src/app/root/root.component.html +0 -14
  196. package/examples/app2/src/app/root/root.component.scss +0 -12
  197. package/examples/app2/src/app/root/root.component.ts +0 -28
  198. package/examples/app2/src/app/shared.module.ts +0 -59
  199. package/examples/app2/src/assets/.gitkeep +0 -0
  200. package/examples/app2/src/environments/environment.prod.ts +0 -3
  201. package/examples/app2/src/environments/environment.ts +0 -16
  202. package/examples/app2/src/favicon.ico +0 -0
  203. package/examples/app2/src/index.html +0 -14
  204. package/examples/app2/src/main.ts +0 -36
  205. package/examples/app2/src/polyfills.ts +0 -84
  206. package/examples/app2/src/styles.scss +0 -28
  207. package/examples/app2/src/test.ts +0 -14
  208. package/examples/app2/tsconfig.app.json +0 -10
  209. package/examples/app2/tsconfig.spec.json +0 -18
  210. package/examples/app2/tslint.json +0 -7
  211. package/examples/app2/webpack.config.js +0 -92
  212. package/examples/common/app-root-context.ts +0 -10
  213. package/examples/common/cache.ts +0 -82
  214. package/examples/common/index.ts +0 -13
  215. package/examples/common/module.ts +0 -10
  216. package/examples/common/overlay-container.service.ts +0 -28
  217. package/examples/common/section-card/section-card.component.html +0 -5
  218. package/examples/common/section-card/section-card.component.scss +0 -15
  219. package/examples/common/section-card/section-card.component.ts +0 -11
  220. package/examples/common/utils.ts +0 -0
  221. package/examples/portal/src/app/a-detail/a-detail.component.html +0 -8
  222. package/examples/portal/src/app/a-detail/a-detail.component.ts +0 -18
  223. package/examples/portal/src/app/about/about.component.html +0 -27
  224. package/examples/portal/src/app/about/about.component.scss +0 -0
  225. package/examples/portal/src/app/about/about.component.spec.ts +0 -26
  226. package/examples/portal/src/app/about/about.component.ts +0 -26
  227. package/examples/portal/src/app/app-routing.module.ts +0 -57
  228. package/examples/portal/src/app/app.component.html +0 -73
  229. package/examples/portal/src/app/app.component.scss +0 -58
  230. package/examples/portal/src/app/app.component.spec.ts +0 -33
  231. package/examples/portal/src/app/app.component.ts +0 -111
  232. package/examples/portal/src/app/app.module.ts +0 -64
  233. package/examples/portal/src/app/custom-settings.service.ts +0 -44
  234. package/examples/portal/src/app/overlay.ts +0 -26
  235. package/examples/portal/src/app/settings/settings.component.html +0 -31
  236. package/examples/portal/src/app/settings/settings.component.scss +0 -3
  237. package/examples/portal/src/app/settings/settings.component.ts +0 -43
  238. package/examples/portal/src/assets/.gitkeep +0 -0
  239. package/examples/portal/src/assets/apps.json +0 -29
  240. package/examples/portal/src/assets/icons/sprite.defs.svg +0 -1
  241. package/examples/portal/src/assets/images/logo.svg +0 -16
  242. package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
  243. package/examples/portal/src/browserslist +0 -11
  244. package/examples/portal/src/environments/environment.prod.ts +0 -3
  245. package/examples/portal/src/environments/environment.ts +0 -16
  246. package/examples/portal/src/extra-webpack.config.js +0 -32
  247. package/examples/portal/src/favicon.ico +0 -0
  248. package/examples/portal/src/index.html +0 -14
  249. package/examples/portal/src/karma.conf.js +0 -31
  250. package/examples/portal/src/main.ts +0 -18
  251. package/examples/portal/src/polyfills.ts +0 -84
  252. package/examples/portal/src/reboot.scss +0 -14
  253. package/examples/portal/src/styles.scss +0 -14
  254. package/examples/portal/src/test.ts +0 -14
  255. package/examples/portal/src/tsconfig.app.json +0 -10
  256. package/examples/portal/src/tsconfig.spec.json +0 -9
  257. package/examples/portal/src/tslint.json +0 -7
  258. package/extra-webpack.config.js +0 -5
  259. package/nginx.conf +0 -17
  260. package/packages/planet/karma.conf.js +0 -37
  261. package/packages/planet/ng-package.json +0 -7
  262. package/packages/planet/package.json +0 -10
  263. package/packages/planet/src/application/planet-application-loader.spec.ts +0 -1102
  264. package/packages/planet/src/application/planet-application-loader.ts +0 -549
  265. package/packages/planet/src/application/planet-application-ref.spec.ts +0 -233
  266. package/packages/planet/src/application/planet-application-ref.ts +0 -131
  267. package/packages/planet/src/application/planet-application.service.spec.ts +0 -145
  268. package/packages/planet/src/application/planet-application.service.ts +0 -88
  269. package/packages/planet/src/application/portal-application.spec.ts +0 -53
  270. package/packages/planet/src/assets-loader.spec.ts +0 -689
  271. package/packages/planet/src/assets-loader.ts +0 -247
  272. package/packages/planet/src/component/planet-component-loader.spec.ts +0 -187
  273. package/packages/planet/src/component/planet-component-loader.ts +0 -173
  274. package/packages/planet/src/component/planet-component-ref.ts +0 -8
  275. package/packages/planet/src/debug.spec.ts +0 -58
  276. package/packages/planet/src/debug.ts +0 -66
  277. package/packages/planet/src/empty/empty.component.spec.ts +0 -34
  278. package/packages/planet/src/empty/empty.component.ts +0 -7
  279. package/packages/planet/src/global-event-dispatcher.spec.ts +0 -81
  280. package/packages/planet/src/global-event-dispatcher.ts +0 -82
  281. package/packages/planet/src/global-planet.spec.ts +0 -39
  282. package/packages/planet/src/global-planet.ts +0 -73
  283. package/packages/planet/src/helpers.spec.ts +0 -242
  284. package/packages/planet/src/helpers.ts +0 -125
  285. package/packages/planet/src/module.spec.ts +0 -79
  286. package/packages/planet/src/module.ts +0 -25
  287. package/packages/planet/src/planet.spec.ts +0 -226
  288. package/packages/planet/src/planet.ts +0 -113
  289. package/packages/planet/src/sandbox/constants.ts +0 -6
  290. package/packages/planet/src/sandbox/exec.ts +0 -22
  291. package/packages/planet/src/sandbox/index.ts +0 -24
  292. package/packages/planet/src/sandbox/proxy/patches/document.ts +0 -13
  293. package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +0 -49
  294. package/packages/planet/src/sandbox/proxy/patches/index.ts +0 -13
  295. package/packages/planet/src/sandbox/proxy/patches/storage.ts +0 -53
  296. package/packages/planet/src/sandbox/proxy/patches/timer.ts +0 -50
  297. package/packages/planet/src/sandbox/proxy/proxies/common.ts +0 -137
  298. package/packages/planet/src/sandbox/proxy/proxies/document.ts +0 -140
  299. package/packages/planet/src/sandbox/proxy/proxies/window.ts +0 -176
  300. package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +0 -59
  301. package/packages/planet/src/sandbox/sandbox.ts +0 -20
  302. package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +0 -12
  303. package/packages/planet/src/sandbox/types.ts +0 -1
  304. package/packages/planet/src/test.ts +0 -16
  305. package/packages/planet/src/testing/app1.module.ts +0 -34
  306. package/packages/planet/src/testing/app2.module.ts +0 -24
  307. package/packages/planet/src/testing/applications.ts +0 -58
  308. package/packages/planet/src/testing/index.ts +0 -2
  309. package/packages/planet/src/testing/utils.ts +0 -31
  310. package/packages/planet/tsconfig.lib.json +0 -27
  311. package/packages/planet/tsconfig.lib.prod.json +0 -9
  312. package/packages/planet/tsconfig.spec.json +0 -17
  313. package/packages/planet/tslint.json +0 -7
  314. package/postcss.config.js +0 -3
  315. package/proxy.conf.js +0 -15
  316. package/tsconfig.json +0 -23
  317. package/tslint.json +0 -80
@@ -1,247 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { hashCode, isEmpty, getScriptsAndStylesFullPaths } from './helpers';
3
- import { of, Observable, Observer, forkJoin, concat } from 'rxjs';
4
- import { map, switchMap, concatAll } from 'rxjs/operators';
5
- import { HttpClient } from '@angular/common/http';
6
- import { PlanetApplication } from './planet.class';
7
- import { createSandbox } from './sandbox';
8
-
9
- export interface AssetsLoadResult {
10
- src: string;
11
- hashCode: number;
12
- loaded: boolean;
13
- status: string;
14
- }
15
-
16
- @Injectable({
17
- providedIn: 'root'
18
- })
19
- export class AssetsLoader {
20
- private loadedSources: number[] = [];
21
-
22
- constructor(private http: HttpClient) {}
23
-
24
- loadScript(src: string): Observable<AssetsLoadResult> {
25
- const id = hashCode(src);
26
- if (this.loadedSources.includes(id)) {
27
- return of({
28
- src: src,
29
- hashCode: id,
30
- loaded: true,
31
- status: 'Loaded'
32
- });
33
- }
34
- return new Observable((observer: Observer<AssetsLoadResult>) => {
35
- const script: HTMLScriptElement = document.createElement('script');
36
- script.type = 'text/javascript';
37
- script.src = src;
38
- script.async = true;
39
- if (script['readyState']) {
40
- // IE
41
- script['onreadystatechange'] = () => {
42
- if (script['readyState'] === 'loaded' || script['readyState'] === 'complete') {
43
- script['onreadystatechange'] = null;
44
- observer.next({
45
- src: src,
46
- hashCode: id,
47
- loaded: true,
48
- status: 'Loaded'
49
- });
50
- observer.complete();
51
- this.loadedSources.push(id);
52
- }
53
- };
54
- } else {
55
- // Others
56
- script.onload = () => {
57
- observer.next({
58
- src: src,
59
- hashCode: id,
60
- loaded: true,
61
- status: 'Loaded'
62
- });
63
- observer.complete();
64
- this.loadedSources.push(id);
65
- };
66
- }
67
- script.onerror = error => {
68
- observer.error({
69
- src: src,
70
- hashCode: id,
71
- loaded: false,
72
- status: 'Error',
73
- error: error
74
- });
75
- observer.complete();
76
- };
77
- document.body.appendChild(script);
78
- });
79
- }
80
-
81
- loadScriptWithSandbox(app: string, src: string): Observable<AssetsLoadResult> {
82
- const id = hashCode(src);
83
- if (this.loadedSources.includes(id)) {
84
- return of({
85
- src: src,
86
- hashCode: id,
87
- loaded: true,
88
- status: 'Loaded'
89
- });
90
- }
91
- return new Observable((observer: Observer<AssetsLoadResult>) => {
92
- this.http.get(src, { responseType: 'text' }).subscribe(
93
- (code: string) => {
94
- this.loadedSources.push(id);
95
- const sandbox = createSandbox(app);
96
- sandbox.execScript(code, src);
97
- observer.next({
98
- src: src,
99
- hashCode: id,
100
- loaded: true,
101
- status: 'Loaded'
102
- });
103
- observer.complete();
104
- },
105
- error => {
106
- observer.error({
107
- src: src,
108
- hashCode: id,
109
- loaded: false,
110
- status: 'Error',
111
- error: error
112
- });
113
- observer.complete();
114
- }
115
- );
116
- });
117
- }
118
-
119
- loadStyle(src: string): Observable<AssetsLoadResult> {
120
- const id = hashCode(src);
121
- if (this.loadedSources.includes(id)) {
122
- return of({
123
- src: src,
124
- hashCode: id,
125
- loaded: true,
126
- status: 'Loaded'
127
- });
128
- }
129
- return new Observable((observer: Observer<AssetsLoadResult>) => {
130
- const head = document.getElementsByTagName('head')[0];
131
- const link = document.createElement('link');
132
- link.rel = 'stylesheet';
133
- link.type = 'text/css';
134
- link.href = src;
135
- link.media = 'all';
136
- link.onload = () => {
137
- observer.next({
138
- src: src,
139
- hashCode: id,
140
- loaded: true,
141
- status: 'Loaded'
142
- });
143
- observer.complete();
144
- this.loadedSources.push(id);
145
- };
146
- link.onerror = error => {
147
- observer.error({
148
- src: src,
149
- hashCode: id,
150
- loaded: true,
151
- status: 'Loaded',
152
- error: error
153
- });
154
- observer.complete();
155
- };
156
- head.appendChild(link);
157
- });
158
- }
159
-
160
- loadScripts(
161
- sources: string[],
162
- options: {
163
- app?: string;
164
- sandbox?: boolean;
165
- serial?: boolean;
166
- } = {
167
- serial: false,
168
- sandbox: false
169
- }
170
- ): Observable<AssetsLoadResult[]> {
171
- if (isEmpty(sources)) {
172
- return of(null);
173
- }
174
- const observables = sources.map(src => {
175
- // TODO: 暂时只支持Proxy沙箱
176
- if (options.sandbox && window.Proxy) {
177
- return this.loadScriptWithSandbox(options.app, src);
178
- } else {
179
- return this.loadScript(src);
180
- }
181
- });
182
- if (options.serial) {
183
- const a = concat(...observables).pipe(
184
- map(item => {
185
- return of([item]);
186
- }),
187
- concatAll()
188
- );
189
- return a;
190
- } else {
191
- return forkJoin(observables).pipe();
192
- }
193
- }
194
-
195
- loadStyles(sources: string[]): Observable<AssetsLoadResult[]> {
196
- if (isEmpty(sources)) {
197
- return of(null);
198
- }
199
- return forkJoin(
200
- sources.map(src => {
201
- return this.loadStyle(src);
202
- })
203
- );
204
- }
205
-
206
- loadScriptsAndStyles(
207
- scripts: string[] = [],
208
- styles: string[] = [],
209
- options?: {
210
- app?: string;
211
- sandbox?: boolean;
212
- serial?: boolean;
213
- }
214
- ) {
215
- return forkJoin([this.loadScripts(scripts, options), this.loadStyles(styles)]);
216
- }
217
-
218
- loadAppAssets(app: PlanetApplication) {
219
- if (app.manifest) {
220
- return this.loadManifest(`${app.manifest}?t=${new Date().getTime()}`).pipe(
221
- switchMap(manifestResult => {
222
- const { scripts, styles } = getScriptsAndStylesFullPaths(app, manifestResult);
223
- return this.loadScriptsAndStyles(scripts, styles, {
224
- app: app.name,
225
- sandbox: app.sandbox,
226
- serial: app.loadSerial
227
- });
228
- })
229
- );
230
- } else {
231
- const { scripts, styles } = getScriptsAndStylesFullPaths(app);
232
- return this.loadScriptsAndStyles(scripts, styles, {
233
- app: app.name,
234
- sandbox: app.sandbox,
235
- serial: app.loadSerial
236
- });
237
- }
238
- }
239
-
240
- loadManifest(url: string): Observable<{ [key: string]: string }> {
241
- return this.http.get(url).pipe(
242
- map((response: any) => {
243
- return response;
244
- })
245
- );
246
- }
247
- }
@@ -1,187 +0,0 @@
1
- import { TestBed, inject, tick, fakeAsync } from '@angular/core/testing';
2
- import { Compiler, Injector, Type, NgModuleRef } from '@angular/core';
3
- import { app1Name, App1Module, App1ProjectsComponent } from '../testing/app1.module';
4
- import { app2Name, App2Module } from '../testing/app2.module';
5
- import { PlanetPortalApplication } from '../application/portal-application';
6
- import { PlanetComponentLoader } from './planet-component-loader';
7
- import { HttpClientTestingModule } from '@angular/common/http/testing';
8
- import { of } from 'rxjs';
9
- import { tap } from 'rxjs/operators';
10
- import { PlantComponentConfig } from './plant-component.config';
11
- import {
12
- defineApplication,
13
- getPlanetApplicationRef,
14
- getApplicationLoader,
15
- clearGlobalPlanet,
16
- getApplicationService
17
- } from '../global-planet';
18
- import { Planet } from 'ngx-planet/planet';
19
- import { RouterTestingModule } from '@angular/router/testing';
20
-
21
- describe('PlanetComponentLoader', () => {
22
- let compiler: Compiler;
23
- let injector: Injector;
24
- let planet: Planet;
25
-
26
- function defineAndBootstrapApplication(name: string, appModule: Type<any>) {
27
- const ngModuleFactory = compiler.compileModuleSync(appModule);
28
- const ngModuleRef = ngModuleFactory.create(injector);
29
- defineApplication(name, {
30
- template: '<app1-root></app1-root>',
31
- bootstrap: (portalApp?: PlanetPortalApplication) => {
32
- return new Promise(resolve => {
33
- resolve(ngModuleRef);
34
- });
35
- }
36
- });
37
- const appRef = getPlanetApplicationRef(name);
38
- const portalApplication = new PlanetPortalApplication();
39
- appRef.bootstrap(portalApplication);
40
- return ngModuleRef;
41
- }
42
-
43
- beforeEach(() => {
44
- TestBed.configureTestingModule({
45
- imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])]
46
- });
47
- compiler = TestBed.inject(Compiler);
48
- planet = TestBed.inject(Planet);
49
- injector = TestBed.inject(Injector);
50
- });
51
-
52
- afterEach(() => {
53
- clearGlobalPlanet();
54
- });
55
-
56
- it('should register component success', fakeAsync(() => {
57
- // mock app1 and app2 bootstrap
58
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
59
- registerAppComponents(app1ModuleRef);
60
- tick();
61
- const app1Ref = getPlanetApplicationRef(app1Name);
62
- expect(app1Ref.getComponentFactory()).toBeTruthy();
63
- }));
64
-
65
- it('should app2 load app1 component when app1 component has completed the registration', fakeAsync(() => {
66
- // mock app1 and app2 bootstrap
67
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
68
- const app2ModuleRef = defineAndBootstrapApplication(app2Name, App2Module);
69
- tick();
70
-
71
- expect(() => {
72
- loadApp1Component(app2ModuleRef);
73
- }).toThrowError(`${app1Name}'s component(app1-projects) is not registered`);
74
-
75
- registerAppComponents(app1ModuleRef);
76
- tick();
77
-
78
- expect(() => {
79
- loadApp1Component(app2ModuleRef, { container: null });
80
- }).toThrowError(`config 'container' cannot be null`);
81
-
82
- loadApp1ComponentAndExpectHtml(app2ModuleRef);
83
- }));
84
-
85
- it('should app2 load app1 component with wrapperClass', fakeAsync(() => {
86
- // mock app1 and app2 bootstrap
87
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
88
- const app2ModuleRef = defineAndBootstrapApplication(app2Name, App2Module);
89
- tick();
90
- registerAppComponents(app1ModuleRef);
91
- loadApp1Component(app2ModuleRef, { wrapperClass: 'custom-wrapper' }).subscribe(componentRef => {
92
- expect(componentRef.wrapperElement.classList.contains('planet-component-wrapper')).toBeTruthy();
93
- expect(componentRef.wrapperElement.classList.contains('custom-wrapper')).toBeTruthy();
94
- });
95
- }));
96
-
97
- it('should app2 load app1 component with stylePrefix of app1', fakeAsync(() => {
98
- // mock app1 and app2 bootstrap
99
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
100
- const app2ModuleRef = defineAndBootstrapApplication(app2Name, App2Module);
101
- const applicationService = getApplicationService();
102
- const applicationServiceSpy = spyOn(applicationService, 'getAppByName');
103
- applicationServiceSpy.and.returnValue({
104
- stylePrefix: 'app1-prefix',
105
- name: 'app1',
106
- hostParent: '',
107
- routerPathPrefix: ''
108
- });
109
- tick();
110
- registerAppComponents(app1ModuleRef);
111
- loadApp1Component(app2ModuleRef, { wrapperClass: 'custom-wrapper' }).subscribe(componentRef => {
112
- expect(componentRef.wrapperElement.classList.contains('planet-component-wrapper')).toBeTruthy();
113
- expect(componentRef.wrapperElement.classList.contains('custom-wrapper')).toBeTruthy();
114
- expect(componentRef.wrapperElement.classList.contains('app1-prefix')).toBeTruthy();
115
- });
116
- }));
117
-
118
- it('should app2 load app1 component and preload app1', fakeAsync(() => {
119
- // mock app2 bootstrap
120
- const app2ModuleRef = defineAndBootstrapApplication(app2Name, App1Module);
121
- // mock app1 preload
122
- const applicationLoader = getApplicationLoader();
123
- const applicationLoaderSpy = spyOn(applicationLoader, 'preload');
124
- const preload$ = of(getPlanetApplicationRef(app1Name)).pipe(
125
- tap(() => {
126
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
127
- registerAppComponents(app1ModuleRef);
128
- })
129
- );
130
- applicationLoaderSpy.and.returnValue(preload$);
131
- expect(applicationLoaderSpy).not.toHaveBeenCalled();
132
- loadApp1ComponentAndExpectHtml(app2ModuleRef);
133
- expect(applicationLoaderSpy).toHaveBeenCalled();
134
- }));
135
-
136
- it('should app2 dispose app1 component', fakeAsync(() => {
137
- // mock app1 and app2 bootstrap
138
- const app1ModuleRef = defineAndBootstrapApplication(app1Name, App1Module);
139
- const app2ModuleRef = defineAndBootstrapApplication(app2Name, App2Module);
140
- tick();
141
- registerAppComponents(app1ModuleRef);
142
- loadApp1Component(app2ModuleRef).subscribe(componentRef => {
143
- const parent = componentRef.wrapperElement.parentElement;
144
- componentRef.dispose();
145
- expect(parent.innerHTML).toEqual('');
146
- });
147
- }));
148
- });
149
-
150
- function registerAppComponents(appModuleRef: NgModuleRef<any>) {
151
- const componentLoader = appModuleRef.injector.get(PlanetComponentLoader);
152
- componentLoader.register([{ name: 'app1-projects', component: App1ProjectsComponent }]);
153
- }
154
-
155
- function loadApp1Component(appModuleRef: NgModuleRef<any>, config?: Partial<PlantComponentConfig>) {
156
- const componentLoader = appModuleRef.injector.get(PlanetComponentLoader);
157
- const hostElement = createComponentHostElement();
158
- const result = componentLoader.load(
159
- app1Name,
160
- 'app1-projects',
161
- Object.assign({}, { container: hostElement }, config)
162
- );
163
- tick(20);
164
- return result;
165
- }
166
-
167
- function loadApp1ComponentAndExpectHtml(app2ModuleRef: NgModuleRef<any>) {
168
- loadApp1Component(app2ModuleRef).subscribe(componentRef => {
169
- expect(componentRef.wrapperElement.outerHTML).toEqual(
170
- `<div class="planet-component-wrapper" planet-inline=""><app1-projects> projects is work </app1-projects></div>`
171
- );
172
- });
173
- }
174
-
175
- function createComponentHostElement(): HTMLElement {
176
- const componentHostClass = 'component-host';
177
- let element = document.body.getElementsByClassName(componentHostClass)[0];
178
- if (element) {
179
- element.innerHTML = '';
180
- return element as HTMLElement;
181
- } else {
182
- element = document.createElement('DIV');
183
- element.classList.add('component-host');
184
- document.body.appendChild(element);
185
- return element as HTMLElement;
186
- }
187
- }
@@ -1,173 +0,0 @@
1
- import { Injectable, ApplicationRef, NgModuleRef, NgZone, ElementRef, Inject } from '@angular/core';
2
- import { ComponentType, DomPortalOutlet, ComponentPortal, PortalInjector } from '@angular/cdk/portal';
3
- import { PlanetApplicationRef } from '../application/planet-application-ref';
4
- import { PlanetComponentRef } from './planet-component-ref';
5
- import { PlantComponentConfig } from './plant-component.config';
6
- import { coerceArray } from '../helpers';
7
- import { map, shareReplay, finalize, debounce, filter, take, delay, delayWhen } from 'rxjs/operators';
8
- import { of, Observable, interval, timer } from 'rxjs';
9
- import { DOCUMENT } from '@angular/common';
10
- import { globalPlanet, getApplicationLoader, getApplicationService } from '../global-planet';
11
-
12
- const componentWrapperClass = 'planet-component-wrapper';
13
-
14
- export interface PlanetComponent<T = any> {
15
- name: string;
16
- component: ComponentType<T>;
17
- }
18
-
19
- @Injectable({
20
- providedIn: 'root'
21
- })
22
- export class PlanetComponentLoader {
23
- private domPortalOutletCache = new WeakMap<any, DomPortalOutlet>();
24
-
25
- private get applicationLoader() {
26
- return getApplicationLoader();
27
- }
28
-
29
- private get applicationService() {
30
- return getApplicationService();
31
- }
32
-
33
- constructor(
34
- private applicationRef: ApplicationRef,
35
- private ngModuleRef: NgModuleRef<any>,
36
- private ngZone: NgZone,
37
- @Inject(DOCUMENT) private document: any
38
- ) {}
39
-
40
- private getPlantAppRef(name: string): Observable<PlanetApplicationRef> {
41
- if (globalPlanet.apps[name] && globalPlanet.apps[name].appModuleRef) {
42
- return of(globalPlanet.apps[name]);
43
- } else {
44
- const app = this.applicationService.getAppByName(name);
45
- return this.applicationLoader.preload(app, true).pipe(
46
- map(() => {
47
- return globalPlanet.apps[name];
48
- })
49
- );
50
- }
51
- }
52
-
53
- private createInjector<TData>(
54
- appModuleRef: NgModuleRef<any>,
55
- componentRef: PlanetComponentRef<TData>
56
- ): PortalInjector {
57
- const injectionTokens = new WeakMap<any, any>([[PlanetComponentRef, componentRef]]);
58
- const defaultInjector = appModuleRef.injector;
59
- return new PortalInjector(defaultInjector, injectionTokens);
60
- }
61
-
62
- private getContainerElement(config: PlantComponentConfig): HTMLElement {
63
- if (!config.container) {
64
- throw new Error(`config 'container' cannot be null`);
65
- } else {
66
- if ((config.container as ElementRef).nativeElement) {
67
- return (config.container as ElementRef).nativeElement;
68
- } else {
69
- return config.container as HTMLElement;
70
- }
71
- }
72
- }
73
-
74
- private createWrapperElement(config: PlantComponentConfig) {
75
- const container = this.getContainerElement(config);
76
- const element = this.document.createElement('div');
77
- const subApp = this.applicationService.getAppByName(this.ngModuleRef.instance.appName);
78
- element.classList.add(componentWrapperClass);
79
- element.setAttribute('planet-inline', '');
80
- if (config.wrapperClass) {
81
- element.classList.add(config.wrapperClass);
82
- }
83
- if (subApp && subApp.stylePrefix) {
84
- element.classList.add(subApp.stylePrefix);
85
- }
86
- container.appendChild(element);
87
- return element;
88
- }
89
-
90
- private attachComponent<TData>(
91
- plantComponent: PlanetComponent,
92
- appModuleRef: NgModuleRef<any>,
93
- config: PlantComponentConfig
94
- ): PlanetComponentRef<TData> {
95
- const plantComponentRef = new PlanetComponentRef();
96
- const componentFactoryResolver = appModuleRef.componentFactoryResolver;
97
- const appRef = this.applicationRef;
98
- const injector = this.createInjector<TData>(appModuleRef, plantComponentRef);
99
- const wrapper = this.createWrapperElement(config);
100
- let portalOutlet = this.domPortalOutletCache.get(wrapper);
101
- if (portalOutlet) {
102
- portalOutlet.detach();
103
- } else {
104
- portalOutlet = new DomPortalOutlet(wrapper, componentFactoryResolver, appRef, injector);
105
- this.domPortalOutletCache.set(wrapper, portalOutlet);
106
- }
107
- const componentPortal = new ComponentPortal(plantComponent.component, null);
108
- const componentRef = portalOutlet.attachComponentPortal<TData>(componentPortal);
109
- if (config.initialState) {
110
- Object.assign(componentRef.instance, config.initialState);
111
- }
112
- plantComponentRef.componentInstance = componentRef.instance;
113
- plantComponentRef.componentRef = componentRef;
114
- plantComponentRef.wrapperElement = wrapper;
115
- plantComponentRef.dispose = () => {
116
- this.domPortalOutletCache.delete(wrapper);
117
- portalOutlet.dispose();
118
- };
119
- return plantComponentRef;
120
- }
121
-
122
- private registerComponentFactory(componentOrComponents: PlanetComponent | PlanetComponent[]) {
123
- const app = this.ngModuleRef.instance.appName;
124
- this.getPlantAppRef(app).subscribe(appRef => {
125
- appRef.registerComponentFactory((componentName: string, config: PlantComponentConfig<any>) => {
126
- const components = coerceArray(componentOrComponents);
127
- const component = components.find(item => item.name === componentName);
128
- if (component) {
129
- return this.ngZone.run(() => {
130
- const componentRef = this.attachComponent<any>(component, appRef.appModuleRef, config);
131
- return componentRef;
132
- });
133
- } else {
134
- throw Error(`unregistered component ${componentName} in app ${app}`);
135
- }
136
- });
137
- });
138
- }
139
-
140
- register(components: PlanetComponent | PlanetComponent[]) {
141
- setTimeout(() => {
142
- this.registerComponentFactory(components);
143
- });
144
- }
145
-
146
- load<TComp = unknown, TData = unknown>(
147
- app: string,
148
- componentName: string,
149
- config: PlantComponentConfig<TData>
150
- ): Observable<PlanetComponentRef<TComp>> {
151
- const result = this.getPlantAppRef(app).pipe(
152
- delayWhen(appRef => {
153
- if (appRef.getComponentFactory()) {
154
- return of('');
155
- } else {
156
- // Because register use 'setTimeout',so timer 20
157
- return timer(20);
158
- }
159
- }),
160
- map(appRef => {
161
- const componentFactory = appRef.getComponentFactory();
162
- if (componentFactory) {
163
- return componentFactory<TData, TComp>(componentName, config);
164
- } else {
165
- throw new Error(`${app}'s component(${componentName}) is not registered`);
166
- }
167
- }),
168
- shareReplay()
169
- );
170
- result.subscribe();
171
- return result;
172
- }
173
- }
@@ -1,8 +0,0 @@
1
- import { ComponentRef, ElementRef } from '@angular/core';
2
-
3
- export class PlanetComponentRef<TComp = any> {
4
- wrapperElement: HTMLElement;
5
- componentInstance: TComp;
6
- componentRef: ComponentRef<TComp>;
7
- dispose: () => void;
8
- }
@@ -1,58 +0,0 @@
1
- import { createDebug, clearDebugFactory, setDebugFactory, getDebugFactory, Debug, Debugger } from './debug';
2
-
3
- describe('debug', () => {
4
- afterEach(() => {
5
- clearDebugFactory();
6
- });
7
-
8
- it('should bypass create debug and log message', () => {
9
- const debug = createDebug('app-loader');
10
- debug('this is debug message');
11
- expect(true).toBe(true);
12
- });
13
-
14
- it('should set debug factory success', () => {
15
- const mockDebugFactory = function(namespace: string): Debugger {
16
- return undefined;
17
- } as Debug;
18
- setDebugFactory(mockDebugFactory);
19
- const debugFactory = getDebugFactory();
20
- expect(debugFactory).toBe(mockDebugFactory);
21
- });
22
-
23
- it('should set debug factory fail', () => {
24
- const mockDebugFactory = {} as Debug;
25
- expect(() => {
26
- setDebugFactory(mockDebugFactory);
27
- }).toThrowError('debug factory type is invalid, must be function');
28
- });
29
-
30
- it('should use custom debug factory to debug', () => {
31
- const mockDebug = jasmine.createSpy('mock debug');
32
- const mockDebugFactory = jasmine.createSpy('mock debug factory').and.callFake(namespace => {
33
- expect(namespace).toEqual('planet:app-loader');
34
- return mockDebug;
35
- });
36
- setDebugFactory(mockDebugFactory as any);
37
- const debug = createDebug('app-loader');
38
- expect(mockDebug).not.toHaveBeenCalled();
39
- debug('this is debug message');
40
- expect(mockDebug).toHaveBeenCalled();
41
-
42
- expect(mockDebug).toHaveBeenCalledWith('this is debug message', []);
43
- });
44
-
45
- it('should use cache debug for same namespace', () => {
46
- const mockDebugFactory = jasmine.createSpy('mock debug factory').and.callFake(namespace => {
47
- expect(namespace).toEqual('planet:app-loader');
48
- return jasmine.createSpy('mock debug');
49
- });
50
- setDebugFactory(mockDebugFactory as any);
51
- expect(mockDebugFactory).toHaveBeenCalledTimes(0);
52
- const debug1 = createDebug('app-loader');
53
- const debug2 = createDebug('app-loader');
54
- debug1('message1');
55
- debug2('message2');
56
- expect(mockDebugFactory).toHaveBeenCalledTimes(1);
57
- });
58
- });