piral-ng 0.15.0-beta.4803 → 0.15.0-beta.4812
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.
- package/esm/RoutingService.js +33 -4
- package/esm/RoutingService.js.map +1 -1
- package/esm/bootstrap.d.ts +3 -2
- package/esm/bootstrap.js +41 -19
- package/esm/bootstrap.js.map +1 -1
- package/esm/converter.js +10 -5
- package/esm/converter.js.map +1 -1
- package/esm/module.d.ts +20 -1
- package/esm/module.js +35 -13
- package/esm/module.js.map +1 -1
- package/esm/queue.d.ts +1 -1
- package/esm/queue.js.map +1 -1
- package/esm/startup.d.ts +1 -0
- package/esm/startup.js +51 -35
- package/esm/startup.js.map +1 -1
- package/esm/types.d.ts +31 -3
- package/esm/utils.d.ts +2 -0
- package/esm/utils.js +7 -0
- package/esm/utils.js.map +1 -1
- package/lib/RoutingService.js +33 -4
- package/lib/RoutingService.js.map +1 -1
- package/lib/bootstrap.d.ts +3 -2
- package/lib/bootstrap.js +41 -19
- package/lib/bootstrap.js.map +1 -1
- package/lib/converter.js +10 -5
- package/lib/converter.js.map +1 -1
- package/lib/module.d.ts +20 -1
- package/lib/module.js +38 -14
- package/lib/module.js.map +1 -1
- package/lib/queue.d.ts +1 -1
- package/lib/queue.js.map +1 -1
- package/lib/startup.d.ts +1 -0
- package/lib/startup.js +52 -35
- package/lib/startup.js.map +1 -1
- package/lib/types.d.ts +31 -3
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +10 -1
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/RoutingService.ts +36 -4
- package/src/bootstrap.ts +48 -21
- package/src/converter.ts +13 -8
- package/src/module.ts +37 -13
- package/src/queue.ts +1 -1
- package/src/startup.ts +61 -39
- package/src/types.ts +29 -3
- package/src/utils.ts +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-ng",
|
|
3
|
-
"version": "0.15.0-beta.
|
|
3
|
+
"version": "0.15.0-beta.4812",
|
|
4
4
|
"description": "Plugin for integrating Angular components in Piral.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"piral",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@angular/platform-browser": "^14.0.0",
|
|
80
80
|
"@angular/platform-browser-dynamic": "^14.0.0",
|
|
81
81
|
"@angular/router": "^14.0.0",
|
|
82
|
-
"piral-core": "0.15.0-beta.
|
|
82
|
+
"piral-core": "0.15.0-beta.4812",
|
|
83
83
|
"rxjs": "^7.3.0"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"@angular/router": "^2.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
|
|
91
91
|
"rxjs": "^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "96956ad19ce349b35acd7992979466f911d33156"
|
|
94
94
|
}
|
package/src/RoutingService.ts
CHANGED
|
@@ -2,6 +2,34 @@ import type { Subscription } from 'rxjs';
|
|
|
2
2
|
import type { ComponentContext, Disposable } from 'piral-core';
|
|
3
3
|
import { Inject, Injectable, NgZone, OnDestroy, Optional } from '@angular/core';
|
|
4
4
|
import { NavigationError, Router, Scroll } from '@angular/router';
|
|
5
|
+
import { ɵBrowserPlatformLocation } from '@angular/common';
|
|
6
|
+
|
|
7
|
+
const noop = function () {};
|
|
8
|
+
|
|
9
|
+
// deactivates the usual platform behavior; all these operations are performed via the RoutingService
|
|
10
|
+
// to avoid any conflict, e.g., double-booking URL changes in React and Angular
|
|
11
|
+
ɵBrowserPlatformLocation.prototype.pushState = noop;
|
|
12
|
+
ɵBrowserPlatformLocation.prototype.replaceState = noop;
|
|
13
|
+
ɵBrowserPlatformLocation.prototype.forward = noop;
|
|
14
|
+
ɵBrowserPlatformLocation.prototype.back = noop;
|
|
15
|
+
ɵBrowserPlatformLocation.prototype.historyGo = noop;
|
|
16
|
+
|
|
17
|
+
function normalize(url: string) {
|
|
18
|
+
const search = url.indexOf('?');
|
|
19
|
+
const hash = url.indexOf('#');
|
|
20
|
+
|
|
21
|
+
if (search !== -1 || hash !== -1) {
|
|
22
|
+
if (search === -1) {
|
|
23
|
+
return url.substring(0, hash);
|
|
24
|
+
} else if (hash === -1) {
|
|
25
|
+
return url.substring(0, search);
|
|
26
|
+
} else {
|
|
27
|
+
return url.substring(0, Math.min(search, hash));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return url;
|
|
32
|
+
}
|
|
5
33
|
|
|
6
34
|
@Injectable()
|
|
7
35
|
export class RoutingService implements OnDestroy {
|
|
@@ -29,23 +57,27 @@ export class RoutingService implements OnDestroy {
|
|
|
29
57
|
const path = location.pathname;
|
|
30
58
|
|
|
31
59
|
if (!this.invalidRoutes.includes(path)) {
|
|
32
|
-
const url = path
|
|
60
|
+
const url = `${path}${location.search}${location.hash}`;
|
|
33
61
|
this.zone.run(() => this.router.navigateByUrl(url));
|
|
34
62
|
}
|
|
35
63
|
});
|
|
36
64
|
|
|
37
65
|
this.subscription = this.router.events.subscribe((e: NavigationError | Scroll) => {
|
|
38
66
|
if (e instanceof NavigationError) {
|
|
39
|
-
const
|
|
67
|
+
const routerUrl = e.url;
|
|
68
|
+
const path = normalize(routerUrl);
|
|
69
|
+
const locationUrl = nav.url;
|
|
40
70
|
|
|
41
71
|
if (!this.invalidRoutes.includes(path)) {
|
|
42
72
|
this.invalidRoutes.push(path);
|
|
43
73
|
}
|
|
44
74
|
|
|
45
|
-
|
|
75
|
+
if (routerUrl !== locationUrl) {
|
|
76
|
+
nav.push(routerUrl);
|
|
77
|
+
}
|
|
46
78
|
} else if (e.type === 15) {
|
|
47
79
|
// consistency check to avoid #535 and other Angular-specific issues
|
|
48
|
-
const locationUrl = nav.
|
|
80
|
+
const locationUrl = nav.url;
|
|
49
81
|
const routerUrl = e.routerEvent.url;
|
|
50
82
|
|
|
51
83
|
if (routerUrl !== locationUrl) {
|
package/src/bootstrap.ts
CHANGED
|
@@ -1,28 +1,55 @@
|
|
|
1
1
|
import type { BaseComponentProps, ComponentContext, Disposable, PiletApi } from 'piral-core';
|
|
2
2
|
import type { BehaviorSubject } from 'rxjs';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Type } from '@angular/core';
|
|
4
|
+
import type { NgLazyType, PrepareBootstrapResult } from './types';
|
|
5
|
+
import { createModuleInstance, getModuleInstance, defineModule, findModule, activateModuleInstance } from './module';
|
|
6
|
+
import { getAnnotations, hasSelector } from './utils';
|
|
4
7
|
import { startup } from './startup';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
|
|
9
|
+
export async function prepareBootstrap(
|
|
10
|
+
moduleOrComponent: Type<any> | NgLazyType,
|
|
11
|
+
piral: PiletApi,
|
|
12
|
+
): Promise<PrepareBootstrapResult> {
|
|
13
|
+
if ('module' in moduleOrComponent && typeof moduleOrComponent.module === 'function') {
|
|
14
|
+
if (!(moduleOrComponent.state.current instanceof Promise)) {
|
|
15
|
+
moduleOrComponent.state.current = moduleOrComponent.module().then((result) => {
|
|
16
|
+
if (typeof result !== 'object' || !('default' in result)) {
|
|
17
|
+
throw new Error('The lazy loaded module does not `default` export a NgModule class.');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
defineModule(result.default, moduleOrComponent.opts);
|
|
21
|
+
return findModule(result.default);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const moduleDef = await moduleOrComponent.state.current;
|
|
26
|
+
const { components } = moduleDef;
|
|
27
|
+
const component = components.find((m) => hasSelector(m, moduleOrComponent.selector));
|
|
28
|
+
|
|
29
|
+
if (!component) {
|
|
30
|
+
throw new Error(`No component matching the selector "${moduleOrComponent.selector}" has been found.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return [...activateModuleInstance(moduleDef, piral), component];
|
|
20
34
|
} else {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const [annotation] = getAnnotations(moduleOrComponent);
|
|
36
|
+
const standalone = annotation?.standalone;
|
|
37
|
+
|
|
38
|
+
// first way is to directly use a module, which is the legacy way
|
|
39
|
+
// second way is to find a previously defined Angular module
|
|
40
|
+
if (annotation && annotation.bootstrap) {
|
|
41
|
+
// usually contains things like imports, exports, declarations, ...
|
|
42
|
+
const [component] = annotation.bootstrap;
|
|
43
|
+
annotation.exports = [component];
|
|
44
|
+
defineModule(moduleOrComponent);
|
|
45
|
+
return [...getModuleInstance(component, standalone, piral), component];
|
|
46
|
+
} else {
|
|
47
|
+
// usually contains things like selector, template or templateUrl, changeDetection, ...
|
|
48
|
+
const result =
|
|
49
|
+
getModuleInstance(moduleOrComponent, standalone, piral) ||
|
|
50
|
+
createModuleInstance(moduleOrComponent, standalone, piral);
|
|
51
|
+
return [...result, moduleOrComponent];
|
|
52
|
+
}
|
|
26
53
|
}
|
|
27
54
|
}
|
|
28
55
|
|
package/src/converter.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ForeignComponent, BaseComponentProps, Disposable } from 'piral-core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Type } from '@angular/core';
|
|
3
|
+
import type { NgLazyType, NgModuleDefiner, PrepareBootstrapResult } from './types';
|
|
3
4
|
import { BehaviorSubject } from 'rxjs';
|
|
4
5
|
import { NgExtension } from './NgExtension';
|
|
5
6
|
import { enqueue } from './queue';
|
|
@@ -22,14 +23,10 @@ interface NgState<TProps> {
|
|
|
22
23
|
|
|
23
24
|
export function createConverter(_: NgConverterOptions = {}): NgConverter {
|
|
24
25
|
const registry = new Map<any, PrepareBootstrapResult>();
|
|
25
|
-
const convert = <TProps extends BaseComponentProps>(component: any): ForeignComponent<TProps> => ({
|
|
26
|
+
const convert = <TProps extends BaseComponentProps>(component: Type<any> | NgLazyType): ForeignComponent<TProps> => ({
|
|
26
27
|
mount(el, props, ctx, locals: NgState<TProps>) {
|
|
27
28
|
locals.active = true;
|
|
28
29
|
|
|
29
|
-
if (!registry.has(component)) {
|
|
30
|
-
registry.set(component, prepareBootstrap(component, props.piral));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
30
|
if (!locals.props) {
|
|
34
31
|
locals.props = new BehaviorSubject(props);
|
|
35
32
|
}
|
|
@@ -39,7 +36,15 @@ export function createConverter(_: NgConverterOptions = {}): NgConverter {
|
|
|
39
36
|
}
|
|
40
37
|
|
|
41
38
|
locals.queued = locals.queued.then(() =>
|
|
42
|
-
enqueue(() =>
|
|
39
|
+
enqueue(async () => {
|
|
40
|
+
if (!registry.has(component)) {
|
|
41
|
+
registry.set(component, await prepareBootstrap(component, props.piral));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (locals.active) {
|
|
45
|
+
bootstrap(registry.get(component), el, locals.props, ctx);
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
43
48
|
);
|
|
44
49
|
},
|
|
45
50
|
update(el, props, ctx, locals: NgState<TProps>) {
|
|
@@ -47,7 +52,7 @@ export function createConverter(_: NgConverterOptions = {}): NgConverter {
|
|
|
47
52
|
},
|
|
48
53
|
unmount(el, locals: NgState<TProps>) {
|
|
49
54
|
locals.active = false;
|
|
50
|
-
locals.queued = locals.queued.then((dispose) => dispose && dispose
|
|
55
|
+
locals.queued = locals.queued.then((dispose) => dispose && enqueue(dispose));
|
|
51
56
|
},
|
|
52
57
|
});
|
|
53
58
|
convert.defineModule = defineModule;
|
package/src/module.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
NgModule,
|
|
12
12
|
NgZone,
|
|
13
13
|
} from '@angular/core';
|
|
14
|
+
import { teardown } from './startup';
|
|
14
15
|
import { RoutingService } from './RoutingService';
|
|
15
16
|
import { SharedModule } from './SharedModule';
|
|
16
17
|
import { findComponents, getAnnotations } from './utils';
|
|
@@ -78,21 +79,29 @@ function instantiateModule(moduleDef: ModuleDefinition, piral: PiletApi) {
|
|
|
78
79
|
this.refs.splice(i, 1);
|
|
79
80
|
}
|
|
80
81
|
}
|
|
82
|
+
|
|
83
|
+
if (this.refs.length === 0) {
|
|
84
|
+
teardown(BootstrapModule);
|
|
85
|
+
}
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
return BootstrapModule;
|
|
85
90
|
}
|
|
86
91
|
|
|
87
|
-
export function
|
|
92
|
+
export function activateModuleInstance(moduleDef: ModuleDefinition, piral: PiletApi): ModuleInstanceResult {
|
|
93
|
+
if (!moduleDef.active) {
|
|
94
|
+
moduleDef.active = instantiateModule(moduleDef, piral);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return [moduleDef.active, moduleDef.opts];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function getModuleInstance(component: any, standalone: boolean, piral: PiletApi) {
|
|
88
101
|
const [moduleDef] = availableModules.filter((m) => m.components.includes(component));
|
|
89
102
|
|
|
90
103
|
if (moduleDef) {
|
|
91
|
-
|
|
92
|
-
moduleDef.active = instantiateModule(moduleDef, piral);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return [moduleDef.active, moduleDef.opts];
|
|
104
|
+
return activateModuleInstance(moduleDef, piral);
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
if (process.env.NODE_ENV === 'development') {
|
|
@@ -126,12 +135,27 @@ export function createModuleInstance(component: any, standalone: boolean, piral:
|
|
|
126
135
|
return getModuleInstance(component, standalone, piral);
|
|
127
136
|
}
|
|
128
137
|
|
|
138
|
+
export function findModule(module: any) {
|
|
139
|
+
return availableModules.find(m => m.module === module);
|
|
140
|
+
}
|
|
141
|
+
|
|
129
142
|
export function defineModule(module: any, opts: NgOptions = undefined) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
if (typeof module !== 'function') {
|
|
144
|
+
const [annotation] = getAnnotations(module);
|
|
145
|
+
availableModules.push({
|
|
146
|
+
active: undefined,
|
|
147
|
+
components: findComponents(annotation.exports),
|
|
148
|
+
module,
|
|
149
|
+
opts,
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
const state = {
|
|
153
|
+
current: undefined,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
return (selector: string) => ({
|
|
157
|
+
component: { selector, module, opts, state },
|
|
158
|
+
type: 'ng' as const,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
137
161
|
}
|
package/src/queue.ts
CHANGED
package/src/startup.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ComponentContext } from 'piral-core';
|
|
2
2
|
import type { NgOptions } from './types';
|
|
3
|
-
import { enableProdMode, NgModuleRef, NgZone } from '@angular/core';
|
|
3
|
+
import { enableProdMode, NgModuleRef, NgZone, PlatformRef } from '@angular/core';
|
|
4
4
|
import { APP_BASE_HREF } from '@angular/common';
|
|
5
5
|
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
|
6
|
-
import { getNgVersion } from './utils';
|
|
6
|
+
import { getId, getNgVersion } from './utils';
|
|
7
7
|
|
|
8
8
|
function getVersionHandler(versions: Record<string, () => void>) {
|
|
9
9
|
const major = getNgVersion();
|
|
@@ -11,10 +11,60 @@ function getVersionHandler(versions: Record<string, () => void>) {
|
|
|
11
11
|
return versions[version];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const runningModules: Array<[any, NgModuleInt]> = [];
|
|
14
|
+
const runningModules: Array<[any, NgModuleInt, PlatformRef]> = [];
|
|
15
|
+
|
|
16
|
+
function startNew(BootstrapModule: any, context: ComponentContext, ngOptions?: NgOptions) {
|
|
17
|
+
const path = context.publicPath || '/';
|
|
18
|
+
const platform = platformBrowserDynamic([
|
|
19
|
+
{ provide: 'Context', useValue: context },
|
|
20
|
+
{ provide: APP_BASE_HREF, useValue: path },
|
|
21
|
+
]);
|
|
22
|
+
const id = getId();
|
|
23
|
+
const zoneIdentifier = `piral-ng:${id}`;
|
|
24
|
+
|
|
25
|
+
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
26
|
+
// See:
|
|
27
|
+
// - https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33
|
|
28
|
+
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L144
|
|
29
|
+
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L257
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
NgZone.isInAngularZone = () => window.Zone.current._properties[zoneIdentifier] === true;
|
|
32
|
+
|
|
33
|
+
return platform
|
|
34
|
+
.bootstrapModule(BootstrapModule, ngOptions)
|
|
35
|
+
.catch((err) => console.log(err))
|
|
36
|
+
.then((instance: NgModuleInt) => {
|
|
37
|
+
if (instance) {
|
|
38
|
+
const zone = instance.injector.get(NgZone);
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
const z = zone?._inner ?? zone?.inner;
|
|
41
|
+
|
|
42
|
+
if (z && '_properties' in z) {
|
|
43
|
+
z._properties[zoneIdentifier] = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
runningModules.push([BootstrapModule, instance, platform]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return instance;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
15
52
|
|
|
16
53
|
export type NgModuleInt = NgModuleRef<any> & { _destroyed: boolean };
|
|
17
54
|
|
|
55
|
+
export function teardown(BootstrapModule: any) {
|
|
56
|
+
const runningModuleIndex = runningModules.findIndex(([ref]) => ref === BootstrapModule);
|
|
57
|
+
|
|
58
|
+
if (runningModuleIndex !== -1) {
|
|
59
|
+
const [, , platform] = runningModules[runningModuleIndex];
|
|
60
|
+
runningModules.splice(runningModuleIndex, 1);
|
|
61
|
+
|
|
62
|
+
if (!platform.destroyed) {
|
|
63
|
+
platform.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
18
68
|
export function startup(
|
|
19
69
|
BootstrapModule: any,
|
|
20
70
|
context: ComponentContext,
|
|
@@ -23,44 +73,16 @@ export function startup(
|
|
|
23
73
|
const runningModule = runningModules.find(([ref]) => ref === BootstrapModule);
|
|
24
74
|
|
|
25
75
|
if (runningModule) {
|
|
26
|
-
const [, instance] = runningModule;
|
|
27
|
-
return Promise.resolve(instance);
|
|
28
|
-
} else {
|
|
29
|
-
const path = context.publicPath || '/';
|
|
30
|
-
const platform = platformBrowserDynamic([
|
|
31
|
-
{ provide: 'Context', useValue: context },
|
|
32
|
-
{ provide: APP_BASE_HREF, useValue: path },
|
|
33
|
-
]);
|
|
34
|
-
const id = Math.random().toString(36);
|
|
35
|
-
const zoneIdentifier = `piral-ng:${id}`;
|
|
36
|
-
|
|
37
|
-
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
38
|
-
// See:
|
|
39
|
-
// - https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33
|
|
40
|
-
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L144
|
|
41
|
-
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L257
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
NgZone.isInAngularZone = () => window.Zone.current._properties[zoneIdentifier] === true;
|
|
44
|
-
|
|
45
|
-
return platform
|
|
46
|
-
.bootstrapModule(BootstrapModule, ngOptions)
|
|
47
|
-
.catch((err) => console.log(err))
|
|
48
|
-
.then((instance: NgModuleInt) => {
|
|
49
|
-
if (instance) {
|
|
50
|
-
const zone = instance.injector.get(NgZone);
|
|
51
|
-
// @ts-ignore
|
|
52
|
-
const z = zone?._inner ?? zone?.inner;
|
|
53
|
-
|
|
54
|
-
if (z && '_properties' in z) {
|
|
55
|
-
z._properties[zoneIdentifier] = true;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
runningModules.push([BootstrapModule, instance]);
|
|
59
|
-
}
|
|
76
|
+
const [, instance, platform] = runningModule;
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
if (platform.destroyed) {
|
|
79
|
+
teardown(BootstrapModule);
|
|
80
|
+
} else {
|
|
81
|
+
return Promise.resolve(instance);
|
|
82
|
+
}
|
|
63
83
|
}
|
|
84
|
+
|
|
85
|
+
return startNew(BootstrapModule, context, ngOptions);
|
|
64
86
|
}
|
|
65
87
|
|
|
66
88
|
if (process.env.NODE_ENV === 'development') {
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PlatformRef, NgModuleRef } from '@angular/core';
|
|
2
2
|
import type { ForeignComponent } from 'piral-core';
|
|
3
|
+
import type { Type } from '@angular/core';
|
|
3
4
|
|
|
4
5
|
declare module 'piral-core/lib/types/custom' {
|
|
5
6
|
interface PiletCustomApi extends PiletNgApi {}
|
|
@@ -23,6 +24,24 @@ export type PrepareBootstrapResult = [...ModuleInstanceResult, any];
|
|
|
23
24
|
|
|
24
25
|
export type NgModuleInt = NgModuleRef<any> & { _destroyed: boolean };
|
|
25
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Gives you the ability to use a component from a lazy loaded module.
|
|
29
|
+
*/
|
|
30
|
+
export interface NgComponentLoader {
|
|
31
|
+
/**
|
|
32
|
+
* Uses a component from a lazy loaded module.
|
|
33
|
+
* @param selector The selector defined for the component to load.
|
|
34
|
+
*/
|
|
35
|
+
(selector: string): NgComponent;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface NgLazyType {
|
|
39
|
+
selector: string;
|
|
40
|
+
module: () => Promise<{ default: Type<any> }>;
|
|
41
|
+
opts: NgOptions;
|
|
42
|
+
state: any;
|
|
43
|
+
}
|
|
44
|
+
|
|
26
45
|
/**
|
|
27
46
|
* Represents the interface implemented by a module definer function.
|
|
28
47
|
*/
|
|
@@ -32,14 +51,21 @@ export interface NgModuleDefiner {
|
|
|
32
51
|
* @param ngModule The module to use for running Angular.
|
|
33
52
|
* @param opts The options to pass when bootstrapping.
|
|
34
53
|
*/
|
|
35
|
-
(module:
|
|
54
|
+
<T>(module: Type<T>, opts?: NgOptions): void;
|
|
55
|
+
/**
|
|
56
|
+
* Defines the module to lazy load for bootstrapping the Angular pilet.
|
|
57
|
+
* @param getModule The module lazy loader to use for running Angular.
|
|
58
|
+
* @param opts The options to pass when bootstrapping.
|
|
59
|
+
* @returns The module ID to be used to reference components.
|
|
60
|
+
*/
|
|
61
|
+
<T>(getModule: () => Promise<{ default: Type<T> }>, opts?: NgOptions): NgComponentLoader;
|
|
36
62
|
}
|
|
37
63
|
|
|
38
64
|
export interface NgComponent {
|
|
39
65
|
/**
|
|
40
66
|
* The component root.
|
|
41
67
|
*/
|
|
42
|
-
component: any;
|
|
68
|
+
component: Type<any> | NgLazyType;
|
|
43
69
|
/**
|
|
44
70
|
* The type of the Angular component.
|
|
45
71
|
*/
|
|
@@ -62,7 +88,7 @@ export interface PiletNgApi {
|
|
|
62
88
|
* @param component The component root.
|
|
63
89
|
* @returns The Piral Ng component.
|
|
64
90
|
*/
|
|
65
|
-
fromNg(component:
|
|
91
|
+
fromNg<T>(component: Type<T>): NgComponent;
|
|
66
92
|
/**
|
|
67
93
|
* Angular component for displaying extensions of the given name.
|
|
68
94
|
*/
|
package/src/utils.ts
CHANGED
|
@@ -12,6 +12,10 @@ export interface NgAnnotation {
|
|
|
12
12
|
selector: string;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export function getId() {
|
|
16
|
+
return Math.random().toString(36);
|
|
17
|
+
}
|
|
18
|
+
|
|
15
19
|
export function getNgVersion() {
|
|
16
20
|
return VERSION.major || VERSION.full.split('.')[0];
|
|
17
21
|
}
|
|
@@ -39,6 +43,11 @@ export function getAnnotations(component: any): Array<NgAnnotation> {
|
|
|
39
43
|
return annotations || [];
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
export function hasSelector(component: any, selector: string) {
|
|
47
|
+
const [annotation] = getAnnotations(component);
|
|
48
|
+
return annotation && annotation.selector === selector;
|
|
49
|
+
}
|
|
50
|
+
|
|
42
51
|
export function findComponents(exports: Array<any>): Array<any> {
|
|
43
52
|
const components = [];
|
|
44
53
|
|