@worktile/planet 12.1.1 → 12.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (328) hide show
  1. package/application/planet-application-loader.d.ts +70 -0
  2. package/application/planet-application-loader.d.ts.map +1 -0
  3. package/application/planet-application-loader.ngfactory.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 +19 -0
  7. package/application/planet-application.service.d.ts.map +1 -0
  8. package/application/planet-application.service.ngfactory.d.ts.map +1 -0
  9. package/{packages/planet/src/application/portal-application.ts → application/portal-application.d.ts} +5 -18
  10. package/application/portal-application.d.ts.map +1 -0
  11. package/assets-loader.d.ts +33 -0
  12. package/assets-loader.d.ts.map +1 -0
  13. package/assets-loader.ngfactory.d.ts.map +1 -0
  14. package/bundles/worktile-planet.umd.js +2564 -0
  15. package/bundles/worktile-planet.umd.js.map +1 -0
  16. package/component/planet-component-loader.d.ts +28 -0
  17. package/component/planet-component-loader.d.ts.map +1 -0
  18. package/component/planet-component-loader.ngfactory.d.ts.map +1 -0
  19. package/component/planet-component-ref.d.ts +8 -0
  20. package/component/planet-component-ref.d.ts.map +1 -0
  21. package/{packages/planet/src/component/plant-component.config.ts → component/plant-component.config.d.ts} +4 -4
  22. package/component/plant-component.config.d.ts.map +1 -0
  23. package/debug.d.ts +22 -0
  24. package/debug.d.ts.map +1 -0
  25. package/empty/empty.component.d.ts +3 -0
  26. package/empty/empty.component.d.ts.map +1 -0
  27. package/empty/empty.component.ngfactory.d.ts.map +1 -0
  28. package/esm2015/application/planet-application-loader.js +457 -0
  29. package/esm2015/application/planet-application-ref.js +97 -0
  30. package/esm2015/application/planet-application.service.js +87 -0
  31. package/esm2015/application/portal-application.js +16 -0
  32. package/esm2015/assets-loader.js +217 -0
  33. package/esm2015/component/planet-component-loader.js +155 -0
  34. package/esm2015/component/planet-component-ref.js +3 -0
  35. package/esm2015/component/plant-component.config.js +7 -0
  36. package/esm2015/debug.js +33 -0
  37. package/esm2015/empty/empty.component.js +10 -0
  38. package/esm2015/global-event-dispatcher.js +71 -0
  39. package/esm2015/global-planet.js +54 -0
  40. package/esm2015/helpers.js +119 -0
  41. package/esm2015/module.js +27 -0
  42. package/esm2015/planet.class.js +9 -0
  43. package/esm2015/planet.js +91 -0
  44. package/esm2015/public-api.js +18 -0
  45. package/esm2015/sandbox/constants.js +7 -0
  46. package/esm2015/sandbox/exec.js +15 -0
  47. package/esm2015/sandbox/index.js +20 -0
  48. package/esm2015/sandbox/proxy/patches/document.js +12 -0
  49. package/esm2015/sandbox/proxy/patches/eventListener.js +41 -0
  50. package/esm2015/sandbox/proxy/patches/index.js +11 -0
  51. package/esm2015/sandbox/proxy/patches/storage.js +40 -0
  52. package/esm2015/sandbox/proxy/patches/timer.js +43 -0
  53. package/esm2015/sandbox/proxy/proxies/common.js +132 -0
  54. package/esm2015/sandbox/proxy/proxies/document.js +126 -0
  55. package/esm2015/sandbox/proxy/proxies/window.js +155 -0
  56. package/esm2015/sandbox/proxy/proxy-sandbox.js +49 -0
  57. package/esm2015/sandbox/proxy/types.js +2 -0
  58. package/esm2015/sandbox/sandbox.js +7 -0
  59. package/esm2015/sandbox/snapshot/snapshot-sandbox.js +12 -0
  60. package/esm2015/sandbox/types.js +2 -0
  61. package/esm2015/worktile-planet.js +6 -0
  62. package/fesm2015/worktile-planet.js +2048 -0
  63. package/fesm2015/worktile-planet.js.map +1 -0
  64. package/global-event-dispatcher.d.ts +20 -0
  65. package/global-event-dispatcher.d.ts.map +1 -0
  66. package/global-event-dispatcher.ngfactory.d.ts.map +1 -0
  67. package/global-planet.d.ts +23 -0
  68. package/global-planet.d.ts.map +1 -0
  69. package/helpers.d.ts +39 -0
  70. package/helpers.d.ts.map +1 -0
  71. package/module.d.ts +6 -0
  72. package/module.d.ts.map +1 -0
  73. package/module.ngfactory.d.ts.map +1 -0
  74. package/package.json +16 -121
  75. package/{packages/planet/src/planet.class.ts → planet.class.d.ts} +5 -26
  76. package/planet.class.d.ts.map +1 -0
  77. package/planet.d.ts +25 -0
  78. package/planet.d.ts.map +1 -0
  79. package/planet.ngfactory.d.ts.map +1 -0
  80. package/{packages/planet/src/public-api.ts → public-api.d.ts} +1 -4
  81. package/public-api.d.ts.map +1 -0
  82. package/sandbox/constants.d.ts +7 -0
  83. package/sandbox/constants.d.ts.map +1 -0
  84. package/sandbox/exec.d.ts +3 -0
  85. package/sandbox/exec.d.ts.map +1 -0
  86. package/sandbox/index.d.ts +7 -0
  87. package/sandbox/index.d.ts.map +1 -0
  88. package/sandbox/proxy/patches/document.d.ts +3 -0
  89. package/sandbox/proxy/patches/document.d.ts.map +1 -0
  90. package/sandbox/proxy/patches/eventListener.d.ts +3 -0
  91. package/sandbox/proxy/patches/eventListener.d.ts.map +1 -0
  92. package/sandbox/proxy/patches/index.d.ts +3 -0
  93. package/sandbox/proxy/patches/index.d.ts.map +1 -0
  94. package/sandbox/proxy/patches/storage.d.ts +15 -0
  95. package/sandbox/proxy/patches/storage.d.ts.map +1 -0
  96. package/sandbox/proxy/patches/timer.d.ts +3 -0
  97. package/sandbox/proxy/patches/timer.d.ts.map +1 -0
  98. package/sandbox/proxy/proxies/common.d.ts +13 -0
  99. package/sandbox/proxy/proxies/common.d.ts.map +1 -0
  100. package/sandbox/proxy/proxies/document.d.ts +14 -0
  101. package/sandbox/proxy/proxies/document.d.ts.map +1 -0
  102. package/sandbox/proxy/proxies/window.d.ts +13 -0
  103. package/sandbox/proxy/proxies/window.d.ts.map +1 -0
  104. package/sandbox/proxy/proxy-sandbox.d.ts +16 -0
  105. package/sandbox/proxy/proxy-sandbox.d.ts.map +1 -0
  106. package/{packages/planet/src/sandbox/proxy/types.ts → sandbox/proxy/types.d.ts} +2 -8
  107. package/sandbox/proxy/types.d.ts.map +1 -0
  108. package/sandbox/sandbox.d.ts +12 -0
  109. package/sandbox/sandbox.d.ts.map +1 -0
  110. package/sandbox/snapshot/snapshot-sandbox.d.ts +9 -0
  111. package/sandbox/snapshot/snapshot-sandbox.d.ts.map +1 -0
  112. package/sandbox/types.d.ts +2 -0
  113. package/sandbox/types.d.ts.map +1 -0
  114. package/worktile-planet.d.ts +6 -0
  115. package/worktile-planet.d.ts.map +1 -0
  116. package/worktile-planet.metadata.json +1 -0
  117. package/.all-contributorsrc +0 -84
  118. package/.circleci/config.yml +0 -17
  119. package/.coveralls.yml +0 -1
  120. package/.docgeni/public/assets/favicon.ico +0 -0
  121. package/.docgeni/public/index.html +0 -13
  122. package/.docgenirc.js +0 -35
  123. package/.dockerignore +0 -1
  124. package/.editorconfig +0 -22
  125. package/.github/FUNDING.yml +0 -12
  126. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  127. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  128. package/.prettierignore +0 -7
  129. package/.prettierrc +0 -28
  130. package/.travis.yml +0 -26
  131. package/.wpmrc.js +0 -11
  132. package/CHANGELOG.md +0 -391
  133. package/CODE_OF_CONDUCT.md +0 -76
  134. package/Dockerfile +0 -11
  135. package/LICENSE +0 -21
  136. package/README.md +0 -348
  137. package/README.zh-CN.md +0 -307
  138. package/SECURITY.md +0 -21
  139. package/angular.json +0 -373
  140. package/commitlint.config.js +0 -6
  141. package/docs/api/defineApplication.md +0 -46
  142. package/docs/api/globalEventDispatcher.md +0 -51
  143. package/docs/api/index.md +0 -5
  144. package/docs/api/planet.md +0 -117
  145. package/docs/guides/getting-started.md +0 -174
  146. package/docs/guides/index.md +0 -5
  147. package/docs/guides/intro.md +0 -216
  148. package/examples/app1/browserslist +0 -11
  149. package/examples/app1/extra-webpack.config.js +0 -33
  150. package/examples/app1/karma.conf.js +0 -31
  151. package/examples/app1/postcss.config.js +0 -1
  152. package/examples/app1/src/app/app.module.ts +0 -44
  153. package/examples/app1/src/app/app.routing.ts +0 -49
  154. package/examples/app1/src/app/counter.service.ts +0 -16
  155. package/examples/app1/src/app/dashboard/dashboard.component.html +0 -51
  156. package/examples/app1/src/app/dashboard/dashboard.component.ts +0 -70
  157. package/examples/app1/src/app/detail/detail.component.html +0 -8
  158. package/examples/app1/src/app/detail/detail.component.ts +0 -18
  159. package/examples/app1/src/app/overlay.ts +0 -26
  160. package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +0 -10
  161. package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +0 -41
  162. package/examples/app1/src/app/projects/projects.component.ts +0 -33
  163. package/examples/app1/src/app/root/root.component.css +0 -3
  164. package/examples/app1/src/app/root/root.component.html +0 -16
  165. package/examples/app1/src/app/root/root.component.ts +0 -35
  166. package/examples/app1/src/app/services/initialized-data.resolver.ts +0 -15
  167. package/examples/app1/src/app/shared.module.ts +0 -57
  168. package/examples/app1/src/app/user/detail/user-detail.component.html +0 -5
  169. package/examples/app1/src/app/user/detail/user-detail.component.ts +0 -20
  170. package/examples/app1/src/app/user/user-list.component.html +0 -7
  171. package/examples/app1/src/app/user/user-list.component.ts +0 -20
  172. package/examples/app1/src/app/user/user.module.ts +0 -31
  173. package/examples/app1/src/assets/.gitkeep +0 -0
  174. package/examples/app1/src/assets/github.png +0 -0
  175. package/examples/app1/src/assets/main.css +0 -3
  176. package/examples/app1/src/environments/environment.prod.ts +0 -3
  177. package/examples/app1/src/environments/environment.ts +0 -16
  178. package/examples/app1/src/favicon.ico +0 -0
  179. package/examples/app1/src/index.html +0 -14
  180. package/examples/app1/src/main.ts +0 -35
  181. package/examples/app1/src/polyfills.ts +0 -84
  182. package/examples/app1/src/styles.scss +0 -35
  183. package/examples/app1/src/test.ts +0 -14
  184. package/examples/app1/temp.js +0 -221
  185. package/examples/app1/tsconfig.app.json +0 -10
  186. package/examples/app1/tsconfig.spec.json +0 -18
  187. package/examples/app1/tslint.json +0 -17
  188. package/examples/app1/webpack.config.js +0 -127
  189. package/examples/app2/browserslist +0 -11
  190. package/examples/app2/extra-webpack.config.js +0 -32
  191. package/examples/app2/karma.conf.js +0 -31
  192. package/examples/app2/src/app/app.module.ts +0 -90
  193. package/examples/app2/src/app/dashboard/dashboard.component.html +0 -21
  194. package/examples/app2/src/app/dashboard/dashboard.component.ts +0 -27
  195. package/examples/app2/src/app/overlay.ts +0 -26
  196. package/examples/app2/src/app/projects/detail/detail.component.html +0 -16
  197. package/examples/app2/src/app/projects/detail/detail.component.ts +0 -21
  198. package/examples/app2/src/app/projects/project-list.component.html +0 -29
  199. package/examples/app2/src/app/projects/project-list.component.ts +0 -58
  200. package/examples/app2/src/app/projects/project.resolver.ts +0 -15
  201. package/examples/app2/src/app/projects/projects.service.ts +0 -28
  202. package/examples/app2/src/app/projects/tasks/tasks.component.html +0 -10
  203. package/examples/app2/src/app/projects/tasks/tasks.component.ts +0 -16
  204. package/examples/app2/src/app/projects/view/view.component.html +0 -1
  205. package/examples/app2/src/app/projects/view/view.component.ts +0 -20
  206. package/examples/app2/src/app/root/root.component.html +0 -14
  207. package/examples/app2/src/app/root/root.component.scss +0 -12
  208. package/examples/app2/src/app/root/root.component.ts +0 -28
  209. package/examples/app2/src/app/shared.module.ts +0 -59
  210. package/examples/app2/src/assets/.gitkeep +0 -0
  211. package/examples/app2/src/environments/environment.prod.ts +0 -3
  212. package/examples/app2/src/environments/environment.ts +0 -16
  213. package/examples/app2/src/favicon.ico +0 -0
  214. package/examples/app2/src/index.html +0 -14
  215. package/examples/app2/src/main.ts +0 -36
  216. package/examples/app2/src/polyfills.ts +0 -84
  217. package/examples/app2/src/styles.scss +0 -28
  218. package/examples/app2/src/test.ts +0 -14
  219. package/examples/app2/tsconfig.app.json +0 -10
  220. package/examples/app2/tsconfig.spec.json +0 -18
  221. package/examples/app2/tslint.json +0 -7
  222. package/examples/app2/webpack.config.js +0 -92
  223. package/examples/common/app-root-context.ts +0 -10
  224. package/examples/common/cache.ts +0 -82
  225. package/examples/common/index.ts +0 -13
  226. package/examples/common/module.ts +0 -10
  227. package/examples/common/overlay-container.service.ts +0 -28
  228. package/examples/common/section-card/section-card.component.html +0 -5
  229. package/examples/common/section-card/section-card.component.scss +0 -15
  230. package/examples/common/section-card/section-card.component.ts +0 -11
  231. package/examples/common/utils.ts +0 -0
  232. package/examples/portal/src/app/a-detail/a-detail.component.html +0 -8
  233. package/examples/portal/src/app/a-detail/a-detail.component.ts +0 -18
  234. package/examples/portal/src/app/about/about.component.html +0 -27
  235. package/examples/portal/src/app/about/about.component.scss +0 -0
  236. package/examples/portal/src/app/about/about.component.spec.ts +0 -26
  237. package/examples/portal/src/app/about/about.component.ts +0 -26
  238. package/examples/portal/src/app/app-routing.module.ts +0 -57
  239. package/examples/portal/src/app/app.component.html +0 -73
  240. package/examples/portal/src/app/app.component.scss +0 -58
  241. package/examples/portal/src/app/app.component.spec.ts +0 -33
  242. package/examples/portal/src/app/app.component.ts +0 -111
  243. package/examples/portal/src/app/app.module.ts +0 -64
  244. package/examples/portal/src/app/custom-settings.service.ts +0 -44
  245. package/examples/portal/src/app/overlay.ts +0 -26
  246. package/examples/portal/src/app/settings/settings.component.html +0 -31
  247. package/examples/portal/src/app/settings/settings.component.scss +0 -3
  248. package/examples/portal/src/app/settings/settings.component.ts +0 -43
  249. package/examples/portal/src/assets/.gitkeep +0 -0
  250. package/examples/portal/src/assets/apps.json +0 -29
  251. package/examples/portal/src/assets/icons/sprite.defs.svg +0 -1
  252. package/examples/portal/src/assets/images/logo.svg +0 -16
  253. package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
  254. package/examples/portal/src/browserslist +0 -11
  255. package/examples/portal/src/environments/environment.prod.ts +0 -3
  256. package/examples/portal/src/environments/environment.ts +0 -16
  257. package/examples/portal/src/extra-webpack.config.js +0 -32
  258. package/examples/portal/src/favicon.ico +0 -0
  259. package/examples/portal/src/index.html +0 -14
  260. package/examples/portal/src/karma.conf.js +0 -31
  261. package/examples/portal/src/main.ts +0 -18
  262. package/examples/portal/src/polyfills.ts +0 -84
  263. package/examples/portal/src/reboot.scss +0 -14
  264. package/examples/portal/src/styles.scss +0 -14
  265. package/examples/portal/src/test.ts +0 -14
  266. package/examples/portal/src/tsconfig.app.json +0 -10
  267. package/examples/portal/src/tsconfig.spec.json +0 -9
  268. package/examples/portal/src/tslint.json +0 -7
  269. package/extra-webpack.config.js +0 -5
  270. package/nginx.conf +0 -17
  271. package/packages/planet/karma.conf.js +0 -37
  272. package/packages/planet/ng-package.json +0 -7
  273. package/packages/planet/package.json +0 -10
  274. package/packages/planet/src/application/planet-application-loader.spec.ts +0 -1102
  275. package/packages/planet/src/application/planet-application-loader.ts +0 -549
  276. package/packages/planet/src/application/planet-application-ref.spec.ts +0 -233
  277. package/packages/planet/src/application/planet-application-ref.ts +0 -131
  278. package/packages/planet/src/application/planet-application.service.spec.ts +0 -145
  279. package/packages/planet/src/application/planet-application.service.ts +0 -88
  280. package/packages/planet/src/application/portal-application.spec.ts +0 -53
  281. package/packages/planet/src/assets-loader.spec.ts +0 -689
  282. package/packages/planet/src/assets-loader.ts +0 -247
  283. package/packages/planet/src/component/planet-component-loader.spec.ts +0 -187
  284. package/packages/planet/src/component/planet-component-loader.ts +0 -173
  285. package/packages/planet/src/component/planet-component-ref.ts +0 -8
  286. package/packages/planet/src/debug.spec.ts +0 -58
  287. package/packages/planet/src/debug.ts +0 -66
  288. package/packages/planet/src/empty/empty.component.spec.ts +0 -34
  289. package/packages/planet/src/empty/empty.component.ts +0 -7
  290. package/packages/planet/src/global-event-dispatcher.spec.ts +0 -81
  291. package/packages/planet/src/global-event-dispatcher.ts +0 -82
  292. package/packages/planet/src/global-planet.spec.ts +0 -39
  293. package/packages/planet/src/global-planet.ts +0 -73
  294. package/packages/planet/src/helpers.spec.ts +0 -242
  295. package/packages/planet/src/helpers.ts +0 -125
  296. package/packages/planet/src/module.spec.ts +0 -79
  297. package/packages/planet/src/module.ts +0 -25
  298. package/packages/planet/src/planet.spec.ts +0 -226
  299. package/packages/planet/src/planet.ts +0 -113
  300. package/packages/planet/src/sandbox/constants.ts +0 -6
  301. package/packages/planet/src/sandbox/exec.ts +0 -22
  302. package/packages/planet/src/sandbox/index.ts +0 -24
  303. package/packages/planet/src/sandbox/proxy/patches/document.ts +0 -13
  304. package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +0 -49
  305. package/packages/planet/src/sandbox/proxy/patches/index.ts +0 -13
  306. package/packages/planet/src/sandbox/proxy/patches/storage.ts +0 -53
  307. package/packages/planet/src/sandbox/proxy/patches/timer.ts +0 -50
  308. package/packages/planet/src/sandbox/proxy/proxies/common.ts +0 -137
  309. package/packages/planet/src/sandbox/proxy/proxies/document.ts +0 -140
  310. package/packages/planet/src/sandbox/proxy/proxies/window.ts +0 -176
  311. package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +0 -59
  312. package/packages/planet/src/sandbox/sandbox.ts +0 -20
  313. package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +0 -12
  314. package/packages/planet/src/sandbox/types.ts +0 -1
  315. package/packages/planet/src/test.ts +0 -16
  316. package/packages/planet/src/testing/app1.module.ts +0 -34
  317. package/packages/planet/src/testing/app2.module.ts +0 -24
  318. package/packages/planet/src/testing/applications.ts +0 -58
  319. package/packages/planet/src/testing/index.ts +0 -2
  320. package/packages/planet/src/testing/utils.ts +0 -31
  321. package/packages/planet/tsconfig.lib.json +0 -27
  322. package/packages/planet/tsconfig.lib.prod.json +0 -9
  323. package/packages/planet/tsconfig.spec.json +0 -17
  324. package/packages/planet/tslint.json +0 -7
  325. package/postcss.config.js +0 -3
  326. package/proxy.conf.js +0 -15
  327. package/tsconfig.json +0 -23
  328. package/tslint.json +0 -80
@@ -1,13 +0,0 @@
1
- import { ProxySandboxInstance, SandboxPatch, SandboxPatchHandler } from '../types';
2
- import { eventListenerPatch } from './eventListener';
3
- import { documentPatch } from './document';
4
- import { timerPatch } from './timer';
5
- import { storagePatch } from './storage';
6
-
7
- const sandboxPatches: SandboxPatch[] = [documentPatch, eventListenerPatch, timerPatch, storagePatch];
8
-
9
- export function getSandboxPatchHandlers(sandbox: ProxySandboxInstance): SandboxPatchHandler[] {
10
- return sandboxPatches.map(patch => {
11
- return patch(sandbox);
12
- });
13
- }
@@ -1,53 +0,0 @@
1
- import { ProxySandboxInstance, SandboxPatchHandler } from '../types';
2
-
3
- const PLANET_STORAGE_PREFIX = '__planet-storage-';
4
-
5
- export class RewriteStorage {
6
- prefix: string;
7
- rawStorage: Storage;
8
-
9
- constructor(app: string, rawStorage: Storage) {
10
- this.rawStorage = rawStorage;
11
- this.prefix = `${PLANET_STORAGE_PREFIX}${app}__:`;
12
- }
13
-
14
- get length() {
15
- return this.getKeys().length;
16
- }
17
-
18
- private getKeys() {
19
- return Object.keys(this.rawStorage).filter(key => key.startsWith(this.prefix));
20
- }
21
-
22
- key(n: number) {
23
- const key = this.getKeys()[n];
24
- return key ? key.substring(this.prefix.length) : null;
25
- }
26
-
27
- getItem(key: string) {
28
- return this.rawStorage.getItem(`${this.prefix + key}`);
29
- }
30
-
31
- setItem(key: string, value: string) {
32
- this.rawStorage.setItem(`${this.prefix + key}`, value);
33
- }
34
-
35
- removeItem(key: string) {
36
- this.rawStorage.removeItem(`${this.prefix + key}`);
37
- }
38
-
39
- clear() {
40
- this.getKeys().forEach(key => {
41
- this.rawStorage.removeItem(key);
42
- });
43
- }
44
- }
45
-
46
- export function storagePatch(sandbox: ProxySandboxInstance): SandboxPatchHandler {
47
- return {
48
- rewrite: {
49
- localStorage: new RewriteStorage(sandbox.app, localStorage),
50
- sessionStorage: new RewriteStorage(sandbox.app, sessionStorage)
51
- }
52
- };
53
- }
@@ -1,50 +0,0 @@
1
- import { SandboxPatchHandler } from '../types';
2
-
3
- const rawSetTimeout = window.setTimeout;
4
- const rawClearTimeout = window.clearTimeout;
5
- const rawSetInterval = window.setInterval;
6
- const rawClearInterval = window.clearInterval;
7
-
8
- export function timerPatch(): SandboxPatchHandler {
9
- const timeout = new Set<number>();
10
- const interval = new Set<number>();
11
-
12
- function rewriteSetTimeout(handler: TimerHandler, ms?: number, ...args: any[]) {
13
- const timeoutId = rawSetTimeout(handler, ms, ...args);
14
- timeout.add(timeoutId);
15
- return timeoutId;
16
- }
17
-
18
- function rewriteClearTimeout(timeoutId: number) {
19
- timeout.delete(timeoutId);
20
- rawClearTimeout(timeoutId);
21
- }
22
-
23
- function rewriteSetInterval(handler: TimerHandler, ms: number, ...args: any[]) {
24
- const intervalId = rawSetInterval(handler, ms, ...args);
25
- interval.add(intervalId);
26
- return intervalId;
27
- }
28
-
29
- function rewriteClearInterval(intervalId: number) {
30
- interval.delete(intervalId);
31
- rawClearInterval(intervalId);
32
- }
33
-
34
- return {
35
- rewrite: {
36
- setTimeout: rewriteSetTimeout,
37
- clearTimeout: rewriteClearTimeout,
38
- setInterval: rewriteSetInterval,
39
- clearInterval: rewriteClearInterval
40
- },
41
- destroy: () => {
42
- timeout.forEach(timeoutId => {
43
- rawClearTimeout(timeoutId);
44
- });
45
- interval.forEach(intervalId => {
46
- rawClearInterval(intervalId);
47
- });
48
- }
49
- };
50
- }
@@ -1,137 +0,0 @@
1
- import { isObject } from '../../../helpers';
2
- import { RAW_NODE } from '../../constants';
3
-
4
- const rawHasOwnProperty = Object.prototype.hasOwnProperty;
5
- export function hasOwnProp(obj: any, key: PropertyKey): boolean {
6
- return rawHasOwnProperty.call(obj, key);
7
- }
8
-
9
- export function isValueDescriptor(desc?: PropertyDescriptor) {
10
- if (desc === undefined) {
11
- return false;
12
- }
13
- return 'value' in desc || 'writable' in desc;
14
- }
15
-
16
- export function isAccessorDescriptor(desc?: PropertyDescriptor) {
17
- if (desc === undefined) {
18
- return false;
19
- }
20
- return 'get' in desc || 'set' in desc;
21
- }
22
-
23
- export function isNonWriteableValue(desc?: PropertyDescriptor) {
24
- return desc && desc.configurable === false && 'value' in desc && desc.writable === false;
25
- }
26
-
27
- export function isInvalidSetAccessor(desc?: PropertyDescriptor) {
28
- if (desc && desc.configurable === false && 'set' in desc && desc.set === undefined) {
29
- return true;
30
- } else {
31
- return false;
32
- }
33
- }
34
-
35
- export function isInvalidGetAccessor(desc?: PropertyDescriptor) {
36
- if (desc && desc.configurable === false && 'get' in desc && desc.get === undefined) {
37
- return true;
38
- } else {
39
- return false;
40
- }
41
- }
42
-
43
- function transferParams(args: IArguments | Array<any>) {
44
- args = Array.isArray(args) ? args : Array.from(args);
45
- return args.map(arg => {
46
- return arg[RAW_NODE] ? arg[RAW_NODE] : arg;
47
- });
48
- }
49
-
50
- const buildInProps: PropertyKey[] = ['length', 'caller', 'callee', 'arguments', 'prototype', Symbol.hasInstance];
51
- function transferProps(o: Function, n: Function) {
52
- for (const key of Reflect.ownKeys(o)) {
53
- if (buildInProps.includes(key)) {
54
- continue;
55
- }
56
- const desc = Object.getOwnPropertyDescriptor(n, key);
57
- if (desc && desc.writable) {
58
- n[key] = o[key];
59
- }
60
- }
61
- }
62
-
63
- export function bind(fn: any, context: any) {
64
- const fNOP = function() {};
65
- function bound() {
66
- const args = transferParams(arguments);
67
- if (this instanceof bound) {
68
- const obj = new fn(...args);
69
- Object.setPrototypeOf(obj, bound.prototype);
70
- return obj;
71
- } else {
72
- return fn.apply(context, args);
73
- }
74
- }
75
- bound.$native = fn;
76
- transferProps(fn, bound);
77
- if (fn.prototype) {
78
- fNOP.prototype = fn.prototype;
79
- }
80
- bound.prototype = new fNOP();
81
- if (Symbol.hasInstance) {
82
- Object.defineProperty(bound, Symbol.hasInstance, {
83
- configurable: true,
84
- value(instance: any) {
85
- const op = fn.prototype;
86
- return isObject(op) || typeof op === 'function' ? instance instanceof fn : false;
87
- }
88
- });
89
- }
90
- return bound;
91
- }
92
-
93
- export function createFakeObject(target: Record<PropertyKey, any>, writableKeys?: PropertyKey[]) {
94
- const fakeObject = {};
95
- const propertyMap: Record<string, string | boolean> = {};
96
- const storageBox = Object.create(null);
97
- const propertyNames = Object.getOwnPropertyNames(target);
98
- const def = (p: string) => {
99
- const descriptor = Object.getOwnPropertyDescriptor(target, p);
100
- if (descriptor?.configurable) {
101
- const hasGetter = hasOwnProp(descriptor, 'get');
102
- const hasSetter = hasOwnProp(descriptor, 'set');
103
- const canWritable = writableKeys && writableKeys.length > 0 && writableKeys.includes(p);
104
- if (hasGetter) {
105
- descriptor.get = () => (hasOwnProp(storageBox, p) ? storageBox[p] : target[p]);
106
- }
107
- if (hasSetter) {
108
- descriptor.set = val => {
109
- storageBox[p] = val;
110
- return true;
111
- };
112
- }
113
- if (canWritable) {
114
- if (descriptor.writable === false) {
115
- descriptor.writable = true;
116
- } else if (hasGetter) {
117
- descriptor.set = val => {
118
- storageBox[p] = val;
119
- return true;
120
- };
121
- }
122
- }
123
- Object.defineProperty(fakeObject, p, Object.freeze(descriptor));
124
- }
125
- };
126
- propertyNames.forEach(p => {
127
- propertyMap[p] = true;
128
- def(p);
129
- });
130
- // 再次循环是为了处理原型链中的属性
131
- for (const prop in target) {
132
- if (!propertyMap[prop]) {
133
- def(prop);
134
- }
135
- }
136
- return fakeObject as any;
137
- }
@@ -1,140 +0,0 @@
1
- import { isFunction } from '../../../helpers';
2
- import { DOCUMENT_BIND_FN, PLANET_SANDBOX_DOCUMENT_WHITELIST, RAW_NODE } from '../../constants';
3
- import {
4
- hasOwnProp,
5
- createFakeObject,
6
- isInvalidSetAccessor,
7
- isNonWriteableValue,
8
- bind,
9
- isInvalidGetAccessor
10
- } from './common';
11
-
12
- const rawDocument = Document;
13
- const whitelist: PropertyKey[] = ['cookie', 'title', 'location', ...(PLANET_SANDBOX_DOCUMENT_WHITELIST || [])];
14
-
15
- export class ProxyDocument {
16
- constructor() {}
17
-
18
- private createGetter() {
19
- return (target: any, p: PropertyKey, receiver?: any) => {
20
- const value = hasOwnProp(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(document, p);
21
- if (p === 'activeElement') {
22
- return Reflect.get(document, p);
23
- }
24
- // TODO: 处理动态节点
25
- // if (p === 'createElement') {
26
- // return function(tagName: string, options: ElementCreationOptions) {
27
- // const created = value.call(document, tagName, options);
28
- // if (isObject(created)) {
29
- // created[SANDBOX_INSTANCE] = sandbox;
30
- // }
31
- // return created;
32
- // };
33
- // }
34
- if (isFunction(value)) {
35
- let newValue = hasOwnProp(value, DOCUMENT_BIND_FN) ? value[DOCUMENT_BIND_FN] : null;
36
- if (!newValue) {
37
- newValue = bind(value, document);
38
- }
39
- const desc = Object.getOwnPropertyDescriptor(target, p);
40
- if (desc && isNonWriteableValue(desc)) {
41
- if (!Object.is(newValue, desc.value)) {
42
- return value;
43
- }
44
- }
45
- if (isInvalidGetAccessor(desc)) {
46
- return undefined;
47
- }
48
- value[DOCUMENT_BIND_FN] = newValue;
49
- return newValue;
50
- }
51
- return value;
52
- };
53
- }
54
-
55
- private createSetter() {
56
- return (target: any, p: PropertyKey, value: any, receiver: any) => {
57
- const desc = Object.getOwnPropertyDescriptor(whitelist.includes(p) ? document : receiver || target, p);
58
- if (desc && isNonWriteableValue(desc)) {
59
- if (Object.is(value, desc.value)) {
60
- return true;
61
- } else {
62
- return false;
63
- }
64
- }
65
- if (isInvalidSetAccessor(desc)) {
66
- return false;
67
- }
68
- return whitelist.includes(p) ? Reflect.set(document, p, value) : Reflect.set(target, p, value, receiver);
69
- };
70
- }
71
-
72
- private createDefineProperty() {
73
- return (target: any, p: PropertyKey, descriptor: PropertyDescriptor) => {
74
- return whitelist.includes(p)
75
- ? Reflect.defineProperty(document, p, descriptor)
76
- : Reflect.defineProperty(target, p, descriptor);
77
- };
78
- }
79
-
80
- create() {
81
- let proxyDocument = null;
82
- const fakeDocument = createFakeObject(document);
83
- const getter = this.createGetter();
84
- const fakeDocumentProto = new Proxy(fakeDocument, {
85
- get: (...args) => {
86
- return getter(...args);
87
- }
88
- });
89
- const fakeDocumentCtor = function Document() {
90
- if (!(this instanceof fakeDocumentCtor)) {
91
- throw new TypeError(`Failed to construct 'Document': Please use the 'new' operator.`);
92
- }
93
- const docInstance = new rawDocument();
94
- Object.setPrototypeOf(docInstance, fakeDocument);
95
- return docInstance;
96
- };
97
- fakeDocumentCtor.prototype = fakeDocumentProto;
98
- fakeDocumentCtor.prototype.constructor = fakeDocumentCtor;
99
- if (Symbol.hasInstance) {
100
- Object.defineProperty(fakeDocumentCtor, Symbol.hasInstance, {
101
- configurable: true,
102
- value(value: any) {
103
- let proto = value;
104
- if (proto === document) {
105
- return true;
106
- }
107
- while ((proto = Object.getPrototypeOf(proto))) {
108
- if (proto === fakeDocumentProto) {
109
- return true;
110
- }
111
- }
112
- const cloned = function() {};
113
- cloned.prototype = fakeDocument;
114
- return value instanceof cloned;
115
- }
116
- });
117
- }
118
- proxyDocument = new Proxy(
119
- Object.create(fakeDocumentProto, {
120
- currentScript: {
121
- value: null,
122
- writable: true
123
- },
124
- [RAW_NODE]: {
125
- writable: false,
126
- configurable: false,
127
- value: document
128
- }
129
- }),
130
- {
131
- set: this.createSetter(),
132
- defineProperty: this.createDefineProperty()
133
- }
134
- );
135
- return {
136
- document: proxyDocument,
137
- Document: fakeDocumentCtor
138
- };
139
- }
140
- }
@@ -1,176 +0,0 @@
1
- import {
2
- hasOwnProp,
3
- createFakeObject,
4
- bind,
5
- isInvalidSetAccessor,
6
- isNonWriteableValue,
7
- isInvalidGetAccessor
8
- } from './common';
9
- import { PLANET_SANDBOX_WINDOW_WHITELIST, SANDBOX_INSTANCE, WINDOW_BIND_FN } from '../../constants';
10
- import { isFunction } from '../../../helpers';
11
- import { ProxySandboxInstance } from '../types';
12
-
13
- const esGlobalFunctions: PropertyKey[] = (
14
- 'eval,isFinite,isNaN,parseFloat,parseInt,' +
15
- // URL handling functions
16
- 'decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
17
- // Constructor properties of the global object
18
- 'Array,ArrayBuffer,BigInt,BigInt64Array,BigUint64Array,Boolean,DataView,Date,Error,EvalError,' +
19
- 'FinalizationRegistry,Float32Array,Float64Array,Function,Int8Array,Int16Array,Int32Array,Map,Number,' +
20
- 'Object,Promise,Proxy,RangeError,ReferenceError,RegExp,Set,SharedArrayBuffer,String,Symbol,SyntaxError,' +
21
- 'TypeError,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,URIError,WeakMap,WeakRef,WeakSet,' +
22
- // Other Properties of the Global Object
23
- 'Atomics,JSON,Math,Reflect'
24
- ).split(',');
25
-
26
- const whitelistVariables = PLANET_SANDBOX_WINDOW_WHITELIST || [];
27
-
28
- function isConstructor(fn: () => void | FunctionConstructor) {
29
- const fp = fn.prototype;
30
- const hasConstructor = fp && fp.constructor === fn && Object.getOwnPropertyNames(fp).length > 1;
31
- const functionStr = !hasConstructor && fn.toString();
32
- return hasConstructor || /^function\s+[A-Z]/.test(functionStr as string) || /^class\b/.test(functionStr as string);
33
- }
34
-
35
- const unscopables = {
36
- undefined: true,
37
- Array: true,
38
- Object: true,
39
- String: true,
40
- Boolean: true,
41
- Math: true,
42
- Number: true,
43
- Symbol: true,
44
- parseFloat: true,
45
- Float32Array: true
46
- };
47
-
48
- export class ProxyWindow {
49
- constructor(private sandbox: ProxySandboxInstance) {}
50
-
51
- private definedVariables = new Set();
52
-
53
- private createGetter() {
54
- return (target: Window, key: PropertyKey, receiver: any) => {
55
- if (key === Symbol.unscopables) {
56
- return unscopables;
57
- }
58
- if (key === SANDBOX_INSTANCE) {
59
- return this.sandbox;
60
- }
61
- let value = null;
62
- if (whitelistVariables.includes(key)) {
63
- return Reflect.get(window, key);
64
- } else {
65
- value = hasOwnProp(target, key) ? Reflect.get(target, key, receiver) : Reflect.get(window, key);
66
- }
67
- if (isFunction(value)) {
68
- if (
69
- esGlobalFunctions.includes(key) ||
70
- whitelistVariables.includes(key) ||
71
- this.sandbox.rewriteVariables.includes(key) ||
72
- this.definedVariables.has(key) ||
73
- isConstructor(value)
74
- ) {
75
- return value;
76
- } else {
77
- const newValue = hasOwnProp(value, WINDOW_BIND_FN) ? value[WINDOW_BIND_FN] : bind(value, window);
78
- const desc = Object.getOwnPropertyDescriptor(target, key);
79
- if (isNonWriteableValue(desc)) {
80
- return value;
81
- }
82
- if (isInvalidGetAccessor(desc)) {
83
- return undefined;
84
- }
85
- value[WINDOW_BIND_FN] = newValue;
86
- return newValue;
87
- }
88
- } else {
89
- return value;
90
- }
91
- };
92
- }
93
-
94
- private createSetter() {
95
- return (target: Window, key: PropertyKey, value: unknown, receiver: any) => {
96
- const desc = Object.getOwnPropertyDescriptor(
97
- whitelistVariables.includes(key) ? window : receiver ? receiver : target,
98
- key
99
- );
100
- if (desc && isNonWriteableValue(desc)) {
101
- if (!Object.is(value, desc.value)) {
102
- return false;
103
- } else {
104
- return true;
105
- }
106
- }
107
- if (isInvalidSetAccessor(desc)) {
108
- return false;
109
- }
110
- if (whitelistVariables.includes(key)) {
111
- return Reflect.set(window, key, value);
112
- } else {
113
- const success = Reflect.set(target, key, value, receiver);
114
- if (success) {
115
- if (this.sandbox.running) {
116
- this.definedVariables.add(key);
117
- }
118
- }
119
- return success;
120
- }
121
- };
122
- }
123
-
124
- private createDefineProperty() {
125
- return (target: Window, p: PropertyKey, descriptor: PropertyDescriptor) => {
126
- if (whitelistVariables.includes(p)) {
127
- return Reflect.defineProperty(window, p, descriptor);
128
- } else {
129
- const success = Reflect.defineProperty(target, p, descriptor);
130
- if (this.sandbox.running && success) {
131
- this.definedVariables.add(p);
132
- }
133
- return success;
134
- }
135
- };
136
- }
137
-
138
- private createDeleteProperty() {
139
- return (target: Window, p: PropertyKey) => {
140
- if (hasOwnProp(target, p)) {
141
- delete (target as any)[p];
142
- if (this.sandbox.running && this.definedVariables.has(p)) {
143
- this.definedVariables.delete(p);
144
- }
145
- }
146
- return true;
147
- };
148
- }
149
-
150
- private createHas() {
151
- return (_target: Window, key: PropertyKey) => {
152
- return !whitelistVariables.includes(key);
153
- };
154
- }
155
-
156
- create() {
157
- const fakeWindow = createFakeObject(window, this.sandbox.rewriteVariables);
158
- const baseHandlers = {
159
- get: this.createGetter(),
160
- set: this.createSetter(),
161
- defineProperty: this.createDefineProperty(),
162
- deleteProperty: this.createDeleteProperty()
163
- };
164
- const proxy = new Proxy(fakeWindow, {
165
- ...baseHandlers,
166
- has: this.createHas()
167
- });
168
- const subProxy = new Proxy(fakeWindow, baseHandlers);
169
- proxy.self = subProxy;
170
- proxy.window = subProxy;
171
- proxy.globalThis = subProxy;
172
- proxy.top = window.top === window ? subProxy : window.top;
173
- proxy.parent = window.parent === window ? subProxy : window.top;
174
- return proxy;
175
- }
176
- }
@@ -1,59 +0,0 @@
1
- import { ProxyWindow } from './proxies/window';
2
- import { getSandboxPatchHandlers } from './patches';
3
- import { SandboxPatchHandler } from './types';
4
- import { Global } from '../types';
5
- import { Sandbox, SandboxOptions } from '../sandbox';
6
-
7
- export class ProxySandbox extends Sandbox {
8
- public running = false;
9
-
10
- public global!: Global;
11
-
12
- public rewriteVariables!: PropertyKey[];
13
-
14
- private patchHandlers: SandboxPatchHandler[] = [];
15
-
16
- constructor(public app: string, public options: SandboxOptions) {
17
- super();
18
- this.patchHandlers = getSandboxPatchHandlers(this);
19
- this.start();
20
- }
21
-
22
- start() {
23
- this.running = true;
24
- this.rewriteVariables = this.getPatchRewriteVariables();
25
- const proxyWindow = new ProxyWindow(this);
26
- this.global = proxyWindow.create();
27
- this.execPatchHandlers();
28
- }
29
-
30
- destroy() {
31
- this.running = false;
32
- this.patchHandlers.forEach(handler => {
33
- if (handler.destroy) {
34
- handler.destroy();
35
- }
36
- });
37
- }
38
-
39
- private getPatchRewriteVariables() {
40
- return this.patchHandlers.reduce<string[]>((pre, cur) => {
41
- return [...pre, ...(cur.rewrite ? Object.keys(cur.rewrite) : [])];
42
- }, []);
43
- }
44
-
45
- private execPatchHandlers() {
46
- this.patchHandlers.forEach(handler => {
47
- if (handler.rewrite) {
48
- for (const key in handler.rewrite) {
49
- if (handler.rewrite[key]) {
50
- this.global[key] = handler.rewrite[key];
51
- }
52
- }
53
- }
54
- if (handler.init) {
55
- handler?.init();
56
- }
57
- });
58
- }
59
- }
@@ -1,20 +0,0 @@
1
- import { execScript } from './exec';
2
- import { Global } from './types';
3
-
4
- export interface SandboxOptions {
5
- strictGlobal?: boolean;
6
- }
7
-
8
- export abstract class Sandbox {
9
- options!: SandboxOptions;
10
-
11
- global!: Global;
12
-
13
- abstract start(): void;
14
-
15
- abstract destroy(): void;
16
-
17
- execScript(code: string, url = '') {
18
- execScript(code, url, this.global, !!this.options.strictGlobal);
19
- }
20
- }
@@ -1,12 +0,0 @@
1
- import { Sandbox, SandboxOptions } from '../sandbox';
2
-
3
- export class SnapshotSandbox extends Sandbox {
4
- constructor(public app: string, public options: SandboxOptions) {
5
- super();
6
- this.start();
7
- }
8
-
9
- start() {}
10
-
11
- destroy() {}
12
- }
@@ -1 +0,0 @@
1
- export type Global = Record<PropertyKey, any>;
@@ -1,16 +0,0 @@
1
- // This file is required by karma.conf.js and loads recursively all the .spec and framework files
2
-
3
- // import 'core-js/es7/reflect';
4
- import 'zone.js';
5
- import 'zone.js/testing';
6
- import { getTestBed } from '@angular/core/testing';
7
- import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
8
-
9
- declare const require: any;
10
-
11
- // First, initialize the Angular testing environment.
12
- getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
13
- // Then we find all the tests.
14
- const context = require.context('./', true, /\.spec\.ts$/);
15
- // And load the modules.
16
- context.keys().map(context);