@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,233 +0,0 @@
1
- import { PlanetPortalApplication } from './portal-application';
2
- import { NgModule, Compiler, Injector, Component, NgZone, Type } from '@angular/core';
3
- import { Router } from '@angular/router';
4
- import { TestBed, inject, tick, fakeAsync, flush } from '@angular/core/testing';
5
- import { defineApplication, getPlanetApplicationRef, clearGlobalPlanet } from '../global-planet';
6
- import { Subject } from 'rxjs';
7
- import { PlanetApplicationRef } from './planet-application-ref';
8
- import { RouterTestingModule } from '@angular/router/testing';
9
-
10
- @Component({
11
- selector: 'app-root',
12
- template: `
13
- <router-outlet></router-outlet>
14
- `
15
- })
16
- class EmptyComponent {}
17
- @NgModule({
18
- declarations: [EmptyComponent],
19
- imports: [
20
- RouterTestingModule.withRoutes([
21
- {
22
- path: 'app1',
23
- component: EmptyComponent
24
- },
25
- {
26
- path: 'app1/test',
27
- component: EmptyComponent
28
- }
29
- ])
30
- ]
31
- })
32
- class AppModule {}
33
-
34
- describe('PlanetApplicationRef', () => {
35
- afterEach(() => {
36
- clearGlobalPlanet();
37
- });
38
-
39
- describe('getPlanetApplicationRef', () => {
40
- it('should get planet application ref success', () => {
41
- defineApplication('app1', {
42
- template: '<app1-root></app1-root>',
43
- bootstrap: (portalApp?: PlanetPortalApplication) => {
44
- return new Promise(() => {});
45
- }
46
- });
47
- const planetAppRef = getPlanetApplicationRef('app1');
48
- expect(planetAppRef).toBeTruthy();
49
- expect(planetAppRef).toBe(window['planet'].apps['app1']);
50
- });
51
-
52
- it('should not get planet appRef which has not exist', () => {
53
- defineApplication('app1', {
54
- template: '<app1-root></app1-root>',
55
- bootstrap: (portalApp?: PlanetPortalApplication) => {
56
- return new Promise(() => {});
57
- }
58
- });
59
- const planetAppRef = getPlanetApplicationRef('app2');
60
- expect(planetAppRef).toBeFalsy();
61
- });
62
- });
63
-
64
- describe('ApplicationRef', () => {
65
- let compiler: Compiler;
66
- let injector: Injector;
67
-
68
- function bootstrapApp1<T>(moduleType?: Type<T>) {
69
- const portalApplication = new PlanetPortalApplication();
70
- const ngModuleFactory = compiler.compileModuleSync(moduleType ? moduleType : AppModule);
71
- const ngModuleRef = ngModuleFactory.create(injector);
72
- const router = ngModuleRef.injector.get(Router);
73
- defineApplication('app1', {
74
- template: '<app1-root></app1-root>',
75
- bootstrap: (portalApp?: PlanetPortalApplication) => {
76
- return new Promise(resolve => {
77
- expect(portalApp).toBe(portalApplication);
78
- resolve(ngModuleRef);
79
- });
80
- }
81
- });
82
-
83
- const appRef = getPlanetApplicationRef('app1');
84
- appRef.bootstrap(portalApplication).subscribe();
85
-
86
- flush();
87
- return {
88
- router,
89
- appRef
90
- };
91
- }
92
-
93
- beforeEach(() => {
94
- TestBed.configureTestingModule({});
95
- });
96
-
97
- beforeEach(inject([Compiler, Injector], (_compiler: Compiler, _injector: Injector) => {
98
- compiler = _compiler;
99
- injector = _injector;
100
- }));
101
-
102
- it(`should bootstrap application ref`, fakeAsync(() => {
103
- const portalApplication = new PlanetPortalApplication();
104
- const ngModuleFactory = compiler.compileModuleSync(AppModule);
105
- const ngModuleRef = ngModuleFactory.create(injector);
106
- defineApplication('app1', {
107
- template: '<app1-root></app1-root>',
108
- bootstrap: (portalApp?: PlanetPortalApplication) => {
109
- return new Promise(resolve => {
110
- expect(portalApp).toBe(portalApplication);
111
- resolve(ngModuleRef);
112
- });
113
- }
114
- });
115
- const appRef = getPlanetApplicationRef('app1');
116
- expect(appRef).toBeTruthy();
117
- const bootstrapSpy = jasmine.createSpy('bootstrap spy');
118
- appRef.bootstrap(portalApplication).subscribe(bootstrapSpy);
119
- expect(appRef.bootstrapped).toEqual(false);
120
- flush();
121
- expect(appRef.bootstrapped).toEqual(true);
122
- expect(appRef.appModuleRef).toEqual(ngModuleRef);
123
- expect(appRef.appModuleRef.instance.appName).toEqual('app1');
124
- expect(bootstrapSpy.calls.count()).toEqual(1);
125
- expect(bootstrapSpy).toHaveBeenCalled();
126
- expect(bootstrapSpy).toHaveBeenCalledWith(appRef);
127
- }));
128
-
129
- it(`should destroy application ref success`, fakeAsync(() => {
130
- const portalApplication = new PlanetPortalApplication();
131
- const ngModuleFactory = compiler.compileModuleSync(AppModule);
132
- const ngModuleRef = ngModuleFactory.create(injector);
133
- const router = ngModuleRef.injector.get(Router);
134
- defineApplication('app1', {
135
- template: '<app1-root></app1-root>',
136
- bootstrap: (portalApp?: PlanetPortalApplication) => {
137
- return new Promise(resolve => {
138
- expect(portalApp).toBe(portalApplication);
139
- resolve(ngModuleRef);
140
- });
141
- }
142
- });
143
-
144
- const appRef = getPlanetApplicationRef('app1');
145
- appRef.bootstrap(portalApplication).subscribe();
146
-
147
- flush();
148
- expect(appRef.bootstrapped).toEqual(true);
149
- expect(appRef.appModuleRef).toEqual(ngModuleRef);
150
-
151
- appRef.destroy();
152
- expect(appRef.bootstrapped).toEqual(false);
153
- expect(appRef.appModuleRef).toEqual(undefined);
154
- }));
155
-
156
- it(`should get router success`, fakeAsync(() => {
157
- const { appRef, router } = bootstrapApp1();
158
- expect(appRef.getRouter()).toBeTruthy();
159
- expect(appRef.getRouter()).toEqual(router);
160
- }));
161
-
162
- it(`should navigate to url success and get correct current router state url `, fakeAsync(() => {
163
- const routerSpy = {
164
- navigateByUrl: jasmine.createSpy('navigateByUrl syp'),
165
- events: new Subject(),
166
- routerState: {
167
- snapshot: {
168
- url: 'app1/hello'
169
- }
170
- }
171
- };
172
- @NgModule({
173
- declarations: [],
174
- imports: [],
175
- providers: [
176
- {
177
- provide: Router,
178
- useValue: routerSpy
179
- }
180
- ]
181
- })
182
- class AppModuleWithSpyRouter {}
183
- const { appRef } = bootstrapApp1(AppModuleWithSpyRouter);
184
- expect(appRef.getCurrentRouterStateUrl()).toEqual('app1/hello');
185
-
186
- expect(routerSpy.navigateByUrl).not.toHaveBeenCalled();
187
-
188
- const toUrl = 'app2/to-url';
189
- appRef.navigateByUrl('app2/to-url');
190
-
191
- expect(routerSpy.navigateByUrl).toHaveBeenCalled();
192
- expect(routerSpy.navigateByUrl).toHaveBeenCalledWith(toUrl);
193
- }));
194
-
195
- it(`should throw error when app is not defined`, () => {
196
- expect(() => {
197
- const appRef = new PlanetApplicationRef('app3', {} as any);
198
- appRef.bootstrap(undefined);
199
- }).toThrowError(`app(app3) is not defined`);
200
- });
201
-
202
- it(`should sync portal route change when sub app(app1) route navigate`, fakeAsync(() => {
203
- const portalApplication = new PlanetPortalApplication();
204
- portalApplication.router = { navigateByUrl: () => {} } as any;
205
- const navigateByUrlSpy = spyOn(portalApplication.router, 'navigateByUrl');
206
- const ngModuleFactory = compiler.compileModuleSync(AppModule);
207
- const ngModuleRef = ngModuleFactory.create(injector);
208
- defineApplication('app1', {
209
- template: '<app1-root></app1-root>',
210
- bootstrap: (portalApp?: PlanetPortalApplication) => {
211
- return new Promise(resolve => {
212
- expect(portalApp).toBe(portalApplication);
213
- resolve(ngModuleRef);
214
- });
215
- }
216
- });
217
- const appRef = getPlanetApplicationRef('app1');
218
- expect(appRef).toBeTruthy();
219
- appRef.bootstrap(portalApplication);
220
-
221
- const router = ngModuleRef.injector.get(Router);
222
- const ngZone = ngModuleRef.injector.get(NgZone);
223
- ngZone.run(() => {
224
- router.navigateByUrl('/app1');
225
- });
226
- expect(navigateByUrlSpy).not.toHaveBeenCalled();
227
- ngZone.onStable.next();
228
- tick();
229
- expect(navigateByUrlSpy).toHaveBeenCalled();
230
- expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1');
231
- }));
232
- });
233
- });
@@ -1,131 +0,0 @@
1
- import { NgModuleRef, NgZone } from '@angular/core';
2
- import { Router, NavigationEnd } from '@angular/router';
3
- import { take } from 'rxjs/operators';
4
- import { Observable, from } from 'rxjs';
5
- import { PlanetPortalApplication } from './portal-application';
6
- import { PlantComponentConfig } from '../component/plant-component.config';
7
- import { PlanetComponentRef } from '../component/planet-component-ref';
8
- import { getTagNameByTemplate } from '../helpers';
9
- import { getSandboxInstance, Sandbox } from '../sandbox/';
10
-
11
- export interface BootstrapOptions {
12
- template: string;
13
- bootstrap: BootstrapAppModule;
14
- }
15
-
16
- export type BootstrapAppModule = (portalApp: PlanetPortalApplication) => Promise<NgModuleRef<any> | undefined | null>;
17
-
18
- export type PlantComponentFactory = <TData, TComp>(
19
- componentName: string,
20
- config: PlantComponentConfig<TData>
21
- ) => PlanetComponentRef<TComp>;
22
-
23
- export class PlanetApplicationRef {
24
- public appModuleRef?: NgModuleRef<any>;
25
- public template?: string;
26
- private innerSelector?: string;
27
- private name: string;
28
- private portalApp!: PlanetPortalApplication;
29
- private appModuleBootstrap?: BootstrapAppModule;
30
- private componentFactory?: PlantComponentFactory;
31
-
32
- public get selector() {
33
- return this.innerSelector;
34
- }
35
-
36
- public get bootstrapped() {
37
- return !!this.appModuleRef;
38
- }
39
-
40
- public get ngZone(): NgZone | undefined {
41
- return this.appModuleRef?.injector.get(NgZone);
42
- }
43
-
44
- public get sandbox(): Sandbox {
45
- return getSandboxInstance();
46
- }
47
-
48
- constructor(name: string, options?: BootstrapOptions) {
49
- this.name = name;
50
- if (options) {
51
- this.template = options.template;
52
- this.innerSelector = this.template ? getTagNameByTemplate(this.template) : '';
53
- this.appModuleBootstrap = options.bootstrap;
54
- }
55
- // This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
56
- // See https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33,
57
- NgZone.isInAngularZone = () => {
58
- // @ts-ignore
59
- return window.Zone.current._properties[`ngx-planet-${name}`] === true;
60
- };
61
- }
62
-
63
- // 子应用路由变化后同步修改 portal 的 Route
64
- private syncPortalRouteWhenNavigationEnd() {
65
- const router = this.appModuleRef?.injector.get(Router);
66
- if (router) {
67
- router.events.subscribe(event => {
68
- if (event instanceof NavigationEnd) {
69
- this.ngZone?.onStable
70
- .asObservable()
71
- .pipe(take(1))
72
- .subscribe(() => {
73
- this.portalApp.router!.navigateByUrl(event.url);
74
- });
75
- }
76
- });
77
- }
78
- }
79
-
80
- bootstrap(app: PlanetPortalApplication): Observable<this> {
81
- if (!this.appModuleBootstrap) {
82
- throw new Error(`app(${this.name}) is not defined`);
83
- }
84
- this.portalApp = app;
85
- return from(
86
- this.appModuleBootstrap(app).then(appModuleRef => {
87
- this.appModuleRef = appModuleRef!;
88
- this.appModuleRef.instance.appName = this.name;
89
- this.syncPortalRouteWhenNavigationEnd();
90
- return this;
91
- })
92
- );
93
- }
94
-
95
- getRouter() {
96
- return this.appModuleRef?.injector.get(Router);
97
- }
98
-
99
- getCurrentRouterStateUrl() {
100
- return this.getRouter()?.routerState.snapshot.url;
101
- }
102
-
103
- navigateByUrl(url: string): void {
104
- const router = this.getRouter();
105
- this.ngZone?.run(() => {
106
- router?.navigateByUrl(url);
107
- });
108
- }
109
-
110
- getComponentFactory() {
111
- return this.componentFactory;
112
- }
113
-
114
- registerComponentFactory(componentFactory: PlantComponentFactory) {
115
- this.componentFactory = componentFactory;
116
- }
117
-
118
- destroy(): void {
119
- if (this.appModuleRef) {
120
- const router = this.appModuleRef.injector.get(Router);
121
- if (router) {
122
- router.dispose();
123
- }
124
- if (this.sandbox) {
125
- this.sandbox.destroy();
126
- }
127
- this.appModuleRef.destroy();
128
- this.appModuleRef = undefined;
129
- }
130
- }
131
- }
@@ -1,145 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
3
- import { PlanetApplicationService } from './planet-application.service';
4
- import { SwitchModes } from '../planet.class';
5
- import { HttpClient } from '@angular/common/http';
6
- import { app1, app2, app2WithPreload } from '../testing/applications';
7
- import { AssetsLoader } from 'ngx-planet/assets-loader';
8
- import { Planet } from 'ngx-planet/planet';
9
-
10
- describe('PlanetApplicationService', () => {
11
- let planetApplicationService: PlanetApplicationService;
12
- beforeEach(() => {
13
- TestBed.configureTestingModule({
14
- imports: [HttpClientTestingModule],
15
- providers: []
16
- });
17
- planetApplicationService = TestBed.inject(PlanetApplicationService);
18
- });
19
-
20
- it(`should throw error when repeat PlanetApplicationService injection`, () => {
21
- window['planet'].applicationService = TestBed.inject(PlanetApplicationService);
22
- expect(() => {
23
- return new PlanetApplicationService(TestBed.inject(HttpClient), TestBed.inject(AssetsLoader));
24
- }).toThrowError('PlanetApplicationService has been injected in the portal, repeated injection is not allowed');
25
- window['planet'].applicationService = null;
26
- });
27
-
28
- describe('register', () => {
29
- it('should register signal app1 success', () => {
30
- planetApplicationService.register(app1);
31
- expect(planetApplicationService.getApps()).toEqual([app1]);
32
- });
33
-
34
- it('should throw error when register exist app1 ', () => {
35
- planetApplicationService.register(app1);
36
- expect(() => {
37
- planetApplicationService.register(app1);
38
- }).toThrowError('app1 has be registered.');
39
- });
40
-
41
- it('should register multiple apps contains app1 and app2 success', () => {
42
- planetApplicationService.register([app1, app2]);
43
- expect(planetApplicationService.getApps()).toEqual([app1, app2]);
44
- });
45
-
46
- describe('registerByUrl', () => {
47
- let httpClient: HttpClient;
48
- let httpTestingController: HttpTestingController;
49
- beforeEach(() => {
50
- httpClient = TestBed.inject(HttpClient);
51
- httpTestingController = TestBed.inject(HttpTestingController);
52
- });
53
-
54
- afterEach(() => {
55
- // After every test, assert that there are no more pending requests.
56
- httpTestingController.verify();
57
- });
58
-
59
- it('should register multiple apps by url', () => {
60
- planetApplicationService.registerByUrl('/static/apps.json');
61
- const req = httpTestingController.expectOne('/static/apps.json');
62
-
63
- // Assert that the request is a GET.
64
- expect(req.request.method).toEqual('GET');
65
-
66
- // Respond with mock data, causing Observable to resolve.
67
- // Subscribe callback asserts that correct data was returned.
68
- req.flush([app1, app2]);
69
-
70
- expect(planetApplicationService.getApps()).toEqual([app1, app2]);
71
- });
72
-
73
- it('should register one app by url', () => {
74
- planetApplicationService.registerByUrl('/static/apps.json');
75
- const req = httpTestingController.expectOne('/static/apps.json');
76
- expect(req.request.method).toEqual('GET');
77
- req.flush(app1);
78
- expect(planetApplicationService.getApps()).toEqual([app1]);
79
- });
80
- });
81
- });
82
-
83
- describe('unregister', () => {
84
- it('should unregister app1 success', () => {
85
- planetApplicationService.register(app1);
86
- expect(planetApplicationService.getApps()).toEqual([app1]);
87
- planetApplicationService.unregister(app1.name);
88
- expect(planetApplicationService.getApps()).toEqual([]);
89
- });
90
- });
91
-
92
- describe('getAppsByMatchedUrl', () => {
93
- it('should get matched apps(app1) by url app1/dashboard', () => {
94
- planetApplicationService.register(app1);
95
- planetApplicationService.register(app2);
96
- const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
97
- expect(apps).toEqual([app1]);
98
- });
99
-
100
- it('should get matched apps by url when apps has same routerPathPrefix', () => {
101
- planetApplicationService.register(app1);
102
- const app2SameApp1 = { ...app2, routerPathPrefix: '/app1' };
103
- planetApplicationService.register(app2SameApp1);
104
- const apps = planetApplicationService.getAppsByMatchedUrl('/app1/dashboard');
105
- expect(apps).toEqual([app1, app2SameApp1]);
106
- });
107
-
108
- it('should get empty apps by url __/dashboard/app1 without start with app1', () => {
109
- planetApplicationService.register(app1);
110
- planetApplicationService.register(app2);
111
- const apps = planetApplicationService.getAppsByMatchedUrl('/__/dashboard/app1');
112
- expect(apps).toEqual([]);
113
- });
114
-
115
- it('should get matched apps which rule is RegExp("(a\\wp3)|app4") by url app3/dashboard', () => {
116
- planetApplicationService.register(app1);
117
- planetApplicationService.register(app2);
118
- const app3 = {
119
- ...app1,
120
- name: 'app3',
121
- routerPathPrefix: new RegExp('(a\\wp3)|app4')
122
- };
123
- planetApplicationService.register(app3);
124
- const apps = planetApplicationService.getAppsByMatchedUrl('/app3/dashboard');
125
- expect(apps).toBeTruthy('app is not found');
126
- expect(apps[0]).toBe(app3);
127
- });
128
- });
129
-
130
- describe('getAppsToPreload', () => {
131
- it('should get correct preload apps', () => {
132
- planetApplicationService.register(app1);
133
- planetApplicationService.register(app2WithPreload);
134
- const appsToPreload = planetApplicationService.getAppsToPreload();
135
- expect(appsToPreload).toEqual([app2WithPreload]);
136
- });
137
-
138
- it('should get correct preload apps exclude app names', () => {
139
- planetApplicationService.register(app1);
140
- planetApplicationService.register(app2WithPreload);
141
- const appsToPreload = planetApplicationService.getAppsToPreload(['app2']);
142
- expect(appsToPreload).toEqual([]);
143
- });
144
- });
145
- });
@@ -1,88 +0,0 @@
1
- import { PlanetApplication } from '../planet.class';
2
- import { Injectable } from '@angular/core';
3
- import { HttpClient } from '@angular/common/http';
4
- import { shareReplay, map } from 'rxjs/operators';
5
- import { coerceArray } from '../helpers';
6
- import { Observable } from 'rxjs';
7
- import { AssetsLoader } from '../assets-loader';
8
- import { getApplicationService } from '../global-planet';
9
-
10
- @Injectable({
11
- providedIn: 'root'
12
- })
13
- export class PlanetApplicationService {
14
- private apps: PlanetApplication[] = [];
15
-
16
- private appsMap: { [key: string]: PlanetApplication } = {};
17
-
18
- constructor(private http: HttpClient, private assetsLoader: AssetsLoader) {
19
- if (getApplicationService()) {
20
- throw new Error(
21
- 'PlanetApplicationService has been injected in the portal, repeated injection is not allowed'
22
- );
23
- }
24
- }
25
-
26
- register<TExtra>(appOrApps: PlanetApplication<TExtra> | PlanetApplication<TExtra>[]) {
27
- const apps = coerceArray(appOrApps);
28
- apps.forEach(app => {
29
- if (this.appsMap[app.name]) {
30
- throw new Error(`${app.name} has be registered.`);
31
- }
32
- this.apps.push(app);
33
- this.appsMap[app.name] = app;
34
- });
35
- }
36
-
37
- registerByUrl(url: string): Observable<void> {
38
- const result = this.http.get(`${url}`).pipe(
39
- map(apps => {
40
- if (apps && Array.isArray(apps)) {
41
- this.register(apps);
42
- } else {
43
- this.register(apps as PlanetApplication);
44
- }
45
- }),
46
- shareReplay()
47
- );
48
- result.subscribe();
49
- return result;
50
- }
51
-
52
- unregister(name: string) {
53
- if (this.appsMap[name]) {
54
- delete this.appsMap[name];
55
- this.apps = this.apps.filter(app => {
56
- return app.name !== name;
57
- });
58
- }
59
- }
60
-
61
- getAppsByMatchedUrl<TExtra = unknown>(url: string): PlanetApplication<TExtra>[] {
62
- return this.getApps().filter(app => {
63
- if (app.routerPathPrefix instanceof RegExp) {
64
- return app.routerPathPrefix.test(url);
65
- } else {
66
- return url.startsWith(app.routerPathPrefix);
67
- }
68
- });
69
- }
70
-
71
- getAppByName(name: string) {
72
- return this.appsMap[name];
73
- }
74
-
75
- getAppsToPreload(excludeAppNames?: string[]) {
76
- return this.getApps().filter(app => {
77
- if (excludeAppNames) {
78
- return app.preload && !excludeAppNames.includes(app.name);
79
- } else {
80
- return app.preload;
81
- }
82
- });
83
- }
84
-
85
- getApps() {
86
- return this.apps;
87
- }
88
- }
@@ -1,53 +0,0 @@
1
- import { TestBed } from '@angular/core/testing';
2
- import { Router } from '@angular/router';
3
- import { PlanetPortalApplication } from './portal-application';
4
- import { NgZone, ApplicationRef } from '@angular/core';
5
- import { RouterTestingModule } from '@angular/router/testing';
6
-
7
- describe('PlanetPortalApplication', () => {
8
- let router: Router;
9
- let planetPortalApplication: PlanetPortalApplication;
10
- beforeEach(() => {
11
- TestBed.configureTestingModule({
12
- imports: [RouterTestingModule.withRoutes([])]
13
- });
14
- router = TestBed.inject(Router);
15
- planetPortalApplication = new PlanetPortalApplication();
16
- planetPortalApplication.ngZone = TestBed.inject(NgZone);
17
- planetPortalApplication.applicationRef = TestBed.inject(ApplicationRef);
18
- planetPortalApplication.router = TestBed.inject(Router);
19
- });
20
-
21
- it(`should create PlanetPortalApplication`, () => {
22
- expect(planetPortalApplication).toBeTruthy();
23
- });
24
-
25
- it(`should run function`, () => {
26
- const spy = jasmine.createSpy('spy');
27
- expect(spy).not.toHaveBeenCalled();
28
- planetPortalApplication.run(spy);
29
- expect(spy).toHaveBeenCalled();
30
- });
31
-
32
- it(`should run function in ngZone`, () => {
33
- const ngZoneRunSpy = spyOn(planetPortalApplication.ngZone, 'run');
34
- expect(ngZoneRunSpy).not.toHaveBeenCalled();
35
- planetPortalApplication.run(() => {});
36
- expect(ngZoneRunSpy).toHaveBeenCalled();
37
- });
38
-
39
- it(`should run tick`, () => {
40
- const tickSpy = spyOn(planetPortalApplication.applicationRef, 'tick');
41
- expect(tickSpy).not.toHaveBeenCalled();
42
- planetPortalApplication.tick();
43
- expect(tickSpy).toHaveBeenCalled();
44
- });
45
-
46
- it(`should run navigateByUrl`, () => {
47
- const navigateByUrlSpy = spyOn(planetPortalApplication.router, 'navigateByUrl');
48
- expect(navigateByUrlSpy).not.toHaveBeenCalled();
49
- planetPortalApplication.navigateByUrl('/app1/dashboard', { skipLocationChange: true });
50
- expect(navigateByUrlSpy).toHaveBeenCalled();
51
- expect(navigateByUrlSpy).toHaveBeenCalledWith('/app1/dashboard', { skipLocationChange: true });
52
- });
53
- });