piral-ng 1.0.0-pre.2296 → 1.0.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.
- package/LICENSE +1 -1
- package/README.md +701 -42
- package/common/NgExtension.d.ts +14 -0
- package/common/ResourceUrlPipe.d.ts +10 -0
- package/common/SharedModule.d.ts +10 -0
- package/common/esm2022/NgExtension.mjs +47 -0
- package/common/esm2022/ResourceUrlPipe.mjs +23 -0
- package/common/esm2022/SharedModule.mjs +25 -0
- package/common/esm2022/piral-ng-common.mjs +5 -0
- package/common/esm2022/public_api.mjs +4 -0
- package/common/fesm2022/piral-ng-common.mjs +93 -0
- package/common/fesm2022/piral-ng-common.mjs.map +1 -0
- package/common/index.d.ts +1 -0
- package/common/package.json +35 -0
- package/common/piral-ng-common.js +3 -0
- package/common/public_api.d.ts +3 -0
- package/convert.d.ts +17 -7
- package/convert.js +17 -11
- package/esm/RoutingService.d.ts +13 -0
- package/esm/RoutingService.js +109 -0
- package/esm/RoutingService.js.map +1 -0
- package/esm/bootstrap.d.ts +6 -5
- package/esm/bootstrap.js +52 -87
- package/esm/bootstrap.js.map +1 -1
- package/esm/common/NgExtension.d.ts +11 -0
- package/esm/common/NgExtension.js +41 -0
- package/esm/common/NgExtension.js.map +1 -0
- package/esm/common/ResourceUrlPipe.d.ts +7 -0
- package/esm/common/ResourceUrlPipe.js +18 -0
- package/esm/common/ResourceUrlPipe.js.map +1 -0
- package/esm/common/SharedModule.d.ts +3 -0
- package/esm/common/SharedModule.js +21 -0
- package/esm/common/SharedModule.js.map +1 -0
- package/esm/common/public_api.d.ts +3 -0
- package/esm/common/public_api.js +4 -0
- package/esm/common/public_api.js.map +1 -0
- package/esm/converter.d.ts +10 -2
- package/esm/converter.js +35 -16
- package/esm/converter.js.map +1 -1
- package/esm/create.d.ts +2 -16
- package/esm/create.js +9 -13
- package/esm/create.js.map +1 -1
- package/esm/module.d.ts +24 -0
- package/esm/module.js +131 -0
- package/esm/module.js.map +1 -0
- package/esm/queue.d.ts +1 -1
- package/esm/queue.js +3 -3
- package/esm/queue.js.map +1 -1
- package/esm/startup.d.ts +8 -0
- package/esm/startup.js +115 -0
- package/esm/startup.js.map +1 -0
- package/esm/types.d.ts +71 -3
- package/esm/utils.d.ts +18 -0
- package/esm/utils.js +46 -0
- package/esm/utils.js.map +1 -0
- package/extend-webpack.js +107 -0
- package/lib/RoutingService.d.ts +13 -0
- package/lib/RoutingService.js +112 -0
- package/lib/RoutingService.js.map +1 -0
- package/lib/bootstrap.d.ts +6 -5
- package/lib/bootstrap.js +55 -91
- package/lib/bootstrap.js.map +1 -1
- package/lib/common/NgExtension.d.ts +11 -0
- package/lib/common/NgExtension.js +44 -0
- package/lib/common/NgExtension.js.map +1 -0
- package/lib/common/ResourceUrlPipe.d.ts +7 -0
- package/lib/common/ResourceUrlPipe.js +21 -0
- package/lib/common/ResourceUrlPipe.js.map +1 -0
- package/lib/common/SharedModule.d.ts +3 -0
- package/lib/common/SharedModule.js +24 -0
- package/lib/common/SharedModule.js.map +1 -0
- package/lib/common/public_api.d.ts +3 -0
- package/lib/common/public_api.js +7 -0
- package/lib/common/public_api.js.map +1 -0
- package/lib/converter.d.ts +10 -2
- package/lib/converter.js +36 -17
- package/lib/converter.js.map +1 -1
- package/lib/create.d.ts +2 -16
- package/lib/create.js +10 -14
- package/lib/create.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/module.d.ts +24 -0
- package/lib/module.js +139 -0
- package/lib/module.js.map +1 -0
- package/lib/queue.d.ts +1 -1
- package/lib/queue.js +3 -3
- package/lib/queue.js.map +1 -1
- package/lib/startup.d.ts +8 -0
- package/lib/startup.js +120 -0
- package/lib/startup.js.map +1 -0
- package/lib/types.d.ts +71 -3
- package/lib/utils.d.ts +18 -0
- package/lib/utils.js +55 -0
- package/lib/utils.js.map +1 -0
- package/package.json +51 -16
- package/src/RoutingService.ts +114 -0
- package/src/bootstrap.ts +57 -104
- package/src/common/NgExtension.ts +33 -0
- package/src/common/ResourceUrlPipe.ts +12 -0
- package/src/common/SharedModule.ts +18 -0
- package/src/common/index.d.ts +1 -0
- package/src/common/ng-package.json +11 -0
- package/src/common/package.json +19 -0
- package/src/common/piral-ng-common.js +3 -0
- package/src/common/public_api.ts +3 -0
- package/src/converter.ts +58 -20
- package/src/create.ts +6 -23
- package/src/module.ts +163 -0
- package/src/queue.ts +1 -1
- package/src/startup.ts +148 -0
- package/src/types.ts +73 -3
- package/src/utils.ts +69 -0
- package/convert.ts +0 -16
- package/esm/extension.d.ts +0 -1
- package/esm/extension.js +0 -41
- package/esm/extension.js.map +0 -1
- package/lib/extension.d.ts +0 -1
- package/lib/extension.js +0 -45
- package/lib/extension.js.map +0 -1
- package/src/extension.ts +0 -29
package/src/module.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { PiletApi } from 'piral-core';
|
|
2
|
+
import type { BehaviorSubject } from 'rxjs';
|
|
3
|
+
import type { NgOptions, ModuleInstanceResult } from './types';
|
|
4
|
+
import { BrowserModule } from '@angular/platform-browser';
|
|
5
|
+
import { CommonModule } from '@angular/common';
|
|
6
|
+
import {
|
|
7
|
+
ApplicationRef,
|
|
8
|
+
ComponentFactoryResolver,
|
|
9
|
+
ComponentRef,
|
|
10
|
+
CUSTOM_ELEMENTS_SCHEMA,
|
|
11
|
+
NgModule,
|
|
12
|
+
NgZone,
|
|
13
|
+
} from '@angular/core';
|
|
14
|
+
import { teardown } from './startup';
|
|
15
|
+
import { RoutingService } from './RoutingService';
|
|
16
|
+
import { findComponents, getAnnotations } from './utils';
|
|
17
|
+
import { SharedModule } from '../common';
|
|
18
|
+
|
|
19
|
+
interface ModuleDefinition {
|
|
20
|
+
active: any;
|
|
21
|
+
module: any;
|
|
22
|
+
components: Array<any>;
|
|
23
|
+
opts: NgOptions;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const availableModules: Array<ModuleDefinition> = [];
|
|
27
|
+
|
|
28
|
+
function instantiateModule(moduleDef: ModuleDefinition, piral: PiletApi) {
|
|
29
|
+
const { module, components } = moduleDef;
|
|
30
|
+
const imports = [BrowserModule, SharedModule, module];
|
|
31
|
+
const props = { current: undefined as BehaviorSubject<any> };
|
|
32
|
+
const providers = [
|
|
33
|
+
RoutingService,
|
|
34
|
+
{ provide: 'Props', useFactory: () => props.current.value, deps: [] },
|
|
35
|
+
{ provide: 'piral', useFactory: () => piral, deps: [] },
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
@NgModule({
|
|
39
|
+
imports,
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
entryComponents: components,
|
|
42
|
+
providers,
|
|
43
|
+
})
|
|
44
|
+
class BootstrapModule {
|
|
45
|
+
private appRef: ApplicationRef;
|
|
46
|
+
private refs: Array<[any, HTMLElement, ComponentRef<any>]> = [];
|
|
47
|
+
|
|
48
|
+
constructor(private resolver: ComponentFactoryResolver, private zone: NgZone, public routing: RoutingService) {}
|
|
49
|
+
|
|
50
|
+
ngDoBootstrap(appRef: ApplicationRef) {
|
|
51
|
+
this.appRef = appRef;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
attach(component: any, node: HTMLElement, $props: BehaviorSubject<any>) {
|
|
55
|
+
const factory = this.resolver.resolveComponentFactory(component);
|
|
56
|
+
props.current = $props;
|
|
57
|
+
|
|
58
|
+
if (factory) {
|
|
59
|
+
const ref = this.zone.run(() => this.appRef.bootstrap<any>(factory, node));
|
|
60
|
+
const name = (ref.componentType as any)?.ɵcmp?.inputs?.Props;
|
|
61
|
+
|
|
62
|
+
if (typeof name === 'string') {
|
|
63
|
+
const sub = $props.subscribe((props) => {
|
|
64
|
+
ref.instance[name] = props;
|
|
65
|
+
ref.changeDetectorRef?.detectChanges();
|
|
66
|
+
});
|
|
67
|
+
ref.onDestroy(() => sub.unsubscribe());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.refs.push([component, node, ref]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
detach(component: any, node: HTMLElement) {
|
|
75
|
+
for (let i = this.refs.length; i--; ) {
|
|
76
|
+
const [sourceComponent, sourceNode, ref] = this.refs[i];
|
|
77
|
+
|
|
78
|
+
if (sourceComponent === component && sourceNode === node) {
|
|
79
|
+
ref.destroy();
|
|
80
|
+
this.refs.splice(i, 1);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (this.refs.length === 0) {
|
|
85
|
+
teardown(BootstrapModule);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return BootstrapModule;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function activateModuleInstance(moduleDef: ModuleDefinition, piral: PiletApi): ModuleInstanceResult {
|
|
94
|
+
if (!moduleDef.active) {
|
|
95
|
+
moduleDef.active = instantiateModule(moduleDef, piral);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return [moduleDef.active, moduleDef.opts];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function getModuleInstance(component: any, standalone: boolean, piral: PiletApi) {
|
|
102
|
+
const [moduleDef] = availableModules.filter((m) => m.components.includes(component));
|
|
103
|
+
|
|
104
|
+
if (moduleDef) {
|
|
105
|
+
return activateModuleInstance(moduleDef, piral);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (process.env.NODE_ENV === 'development') {
|
|
109
|
+
if (!standalone) {
|
|
110
|
+
console.warn(
|
|
111
|
+
'Component not found in all defined Angular modules. Make sure to define (using `defineNgModule`) a module with your component(s) referenced in the exports section of the `@NgModule` decorator.',
|
|
112
|
+
component,
|
|
113
|
+
piral.meta,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function createModuleInstance(component: any, standalone: boolean, piral: PiletApi): ModuleInstanceResult {
|
|
122
|
+
const declarations = standalone ? [] : [component];
|
|
123
|
+
const importsDef = standalone ? [CommonModule, component] : [CommonModule];
|
|
124
|
+
const exportsDef = [component];
|
|
125
|
+
const schemasDef = [CUSTOM_ELEMENTS_SCHEMA];
|
|
126
|
+
|
|
127
|
+
@NgModule({
|
|
128
|
+
declarations,
|
|
129
|
+
imports: importsDef,
|
|
130
|
+
exports: exportsDef,
|
|
131
|
+
schemas: schemasDef,
|
|
132
|
+
})
|
|
133
|
+
class Module {}
|
|
134
|
+
|
|
135
|
+
defineModule(Module);
|
|
136
|
+
return getModuleInstance(component, standalone, piral);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function findModule(module: any) {
|
|
140
|
+
return availableModules.find((m) => m.module === module);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function defineModule(module: any, opts: NgOptions = undefined) {
|
|
144
|
+
const [annotation] = getAnnotations(module);
|
|
145
|
+
|
|
146
|
+
if (annotation) {
|
|
147
|
+
availableModules.push({
|
|
148
|
+
active: undefined,
|
|
149
|
+
components: findComponents(annotation.exports),
|
|
150
|
+
module,
|
|
151
|
+
opts,
|
|
152
|
+
});
|
|
153
|
+
} else if (typeof module === 'function') {
|
|
154
|
+
const state = {
|
|
155
|
+
current: undefined,
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return (selector: string) => ({
|
|
159
|
+
component: { selector, module, opts, state },
|
|
160
|
+
type: 'ng' as const,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
package/src/queue.ts
CHANGED
package/src/startup.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { ComponentContext } from 'piral-core';
|
|
2
|
+
import type { NgOptions } from './types';
|
|
3
|
+
import {
|
|
4
|
+
createPlatformFactory,
|
|
5
|
+
enableProdMode,
|
|
6
|
+
NgModuleRef,
|
|
7
|
+
NgZone,
|
|
8
|
+
PlatformRef,
|
|
9
|
+
ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS,
|
|
10
|
+
} from '@angular/core';
|
|
11
|
+
import { APP_BASE_HREF } from '@angular/common';
|
|
12
|
+
import {
|
|
13
|
+
ɵplatformCoreDynamic as platformCoreDynamic,
|
|
14
|
+
ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
|
|
15
|
+
} from '@angular/platform-browser-dynamic';
|
|
16
|
+
import { getId, getNgVersion } from './utils';
|
|
17
|
+
|
|
18
|
+
function getVersionHandler(versions: Record<string, () => void>) {
|
|
19
|
+
const major = getNgVersion();
|
|
20
|
+
const version = `v${major}`;
|
|
21
|
+
return versions[version];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Equivalent to platformBrowserDynamic, but with support for multiple platforms
|
|
25
|
+
const customPlatformDynamicFactory = createPlatformFactory(platformCoreDynamic, 'piralDynamic', [
|
|
26
|
+
...INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
|
|
27
|
+
{
|
|
28
|
+
provide: ALLOW_MULTIPLE_PLATFORMS,
|
|
29
|
+
useValue: true,
|
|
30
|
+
},
|
|
31
|
+
]);
|
|
32
|
+
const runningModules: Array<[any, NgModuleInt, PlatformRef]> = [];
|
|
33
|
+
|
|
34
|
+
function startNew(BootstrapModule: any, context: ComponentContext, ngOptions?: NgOptions) {
|
|
35
|
+
const path = context.publicPath || '/';
|
|
36
|
+
const platform = customPlatformDynamicFactory([
|
|
37
|
+
{ provide: 'Context', useValue: context },
|
|
38
|
+
{ provide: APP_BASE_HREF, useValue: path },
|
|
39
|
+
]);
|
|
40
|
+
const id = getId();
|
|
41
|
+
const zoneIdentifier = `piral-ng:${id}`;
|
|
42
|
+
|
|
43
|
+
// This is a hack, since NgZone doesn't allow you to configure the property that identifies your zone.
|
|
44
|
+
// See:
|
|
45
|
+
// - https://github.com/PlaceMe-SAS/single-spa-angular-cli/issues/33
|
|
46
|
+
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L144
|
|
47
|
+
// - https://github.com/angular/angular/blob/a14dc2d7a4821a19f20a9547053a5734798f541e/packages/core/src/zone/ng_zone.ts#L257
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
NgZone.isInAngularZone = () => window.Zone.current._properties[zoneIdentifier] === true;
|
|
50
|
+
|
|
51
|
+
return platform
|
|
52
|
+
.bootstrapModule(BootstrapModule, ngOptions)
|
|
53
|
+
.catch((err) => console.log(err))
|
|
54
|
+
.then((instance: NgModuleInt) => {
|
|
55
|
+
if (instance) {
|
|
56
|
+
const zone = instance.injector.get(NgZone);
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
const z = zone?._inner ?? zone?.inner;
|
|
59
|
+
|
|
60
|
+
if (z && '_properties' in z) {
|
|
61
|
+
z._properties[zoneIdentifier] = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
runningModules.push([BootstrapModule, instance, platform]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return instance;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type NgModuleInt = NgModuleRef<any> & { _destroyed: boolean };
|
|
72
|
+
|
|
73
|
+
export function teardown(BootstrapModule: any) {
|
|
74
|
+
const runningModuleIndex = runningModules.findIndex(([ref]) => ref === BootstrapModule);
|
|
75
|
+
|
|
76
|
+
if (runningModuleIndex !== -1) {
|
|
77
|
+
const [, , platform] = runningModules[runningModuleIndex];
|
|
78
|
+
runningModules.splice(runningModuleIndex, 1);
|
|
79
|
+
|
|
80
|
+
if (!platform.destroyed) {
|
|
81
|
+
platform.destroy();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function startup(
|
|
87
|
+
BootstrapModule: any,
|
|
88
|
+
context: ComponentContext,
|
|
89
|
+
ngOptions?: NgOptions,
|
|
90
|
+
): Promise<void | NgModuleInt> {
|
|
91
|
+
const runningModule = runningModules.find(([ref]) => ref === BootstrapModule);
|
|
92
|
+
|
|
93
|
+
if (runningModule) {
|
|
94
|
+
const [, instance, platform] = runningModule;
|
|
95
|
+
|
|
96
|
+
if (platform.destroyed) {
|
|
97
|
+
teardown(BootstrapModule);
|
|
98
|
+
} else {
|
|
99
|
+
return Promise.resolve(instance);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return startNew(BootstrapModule, context, ngOptions);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (process.env.NODE_ENV === 'development') {
|
|
107
|
+
// May be used later for something useful. Right now only debugging output.
|
|
108
|
+
const versionHandlers = {
|
|
109
|
+
legacy() {
|
|
110
|
+
console.log('Running in legacy mode (Angular 2, Angular 4)');
|
|
111
|
+
},
|
|
112
|
+
outdated() {
|
|
113
|
+
console.log('Running in outdated mode (Angular 5-8)');
|
|
114
|
+
},
|
|
115
|
+
current() {
|
|
116
|
+
console.log('Running in current mode (Angular 9-15)');
|
|
117
|
+
},
|
|
118
|
+
next() {
|
|
119
|
+
console.log('Running in next mode (Angular 16)');
|
|
120
|
+
},
|
|
121
|
+
unknown() {
|
|
122
|
+
console.log('Running with an unknown version of Angular');
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
const versions = {
|
|
126
|
+
v2: versionHandlers.legacy,
|
|
127
|
+
v4: versionHandlers.legacy,
|
|
128
|
+
v5: versionHandlers.outdated,
|
|
129
|
+
v6: versionHandlers.outdated,
|
|
130
|
+
v7: versionHandlers.outdated,
|
|
131
|
+
v8: versionHandlers.outdated,
|
|
132
|
+
v9: versionHandlers.current,
|
|
133
|
+
v10: versionHandlers.current,
|
|
134
|
+
v11: versionHandlers.current,
|
|
135
|
+
v12: versionHandlers.current,
|
|
136
|
+
v13: versionHandlers.current,
|
|
137
|
+
v14: versionHandlers.current,
|
|
138
|
+
v15: versionHandlers.current,
|
|
139
|
+
v16: versionHandlers.next,
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const handler = getVersionHandler(versions) || versionHandlers.unknown;
|
|
143
|
+
handler();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (process.env.NODE_ENV === 'production') {
|
|
147
|
+
enableProdMode();
|
|
148
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { PlatformRef, NgModuleRef } from '@angular/core';
|
|
1
2
|
import type { ForeignComponent } from 'piral-core';
|
|
3
|
+
import type { Type } from '@angular/core';
|
|
2
4
|
|
|
3
5
|
declare module 'piral-core/lib/types/custom' {
|
|
4
6
|
interface PiletCustomApi extends PiletNgApi {}
|
|
@@ -8,11 +10,72 @@ declare module 'piral-core/lib/types/custom' {
|
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Options passed through to Angular `bootstrapModule`.
|
|
15
|
+
*
|
|
16
|
+
* Mainly to specify Noop Zone, but also includes compiler specific settings.
|
|
17
|
+
* See https://angular.io/api/core/PlatformRef#bootstrapModule for possible values.
|
|
18
|
+
*/
|
|
19
|
+
export type NgOptions = Parameters<PlatformRef['bootstrapModule']>[1];
|
|
20
|
+
|
|
21
|
+
export type ModuleInstanceResult = [any, NgOptions];
|
|
22
|
+
|
|
23
|
+
export type PrepareBootstrapResult = [...ModuleInstanceResult, any];
|
|
24
|
+
|
|
25
|
+
export type NgModuleInt = NgModuleRef<any> & { _destroyed: boolean };
|
|
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
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The lazy loading interface for retrieving Angular components.
|
|
47
|
+
*/
|
|
48
|
+
export interface LazyType<T> {
|
|
49
|
+
/**
|
|
50
|
+
* Callback to be invoked for lazy loading an Angular module or component.
|
|
51
|
+
*/
|
|
52
|
+
(): Promise<{ default: Type<T> }>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Represents the interface implemented by a module definer function.
|
|
57
|
+
*/
|
|
58
|
+
export interface NgModuleDefiner {
|
|
59
|
+
/**
|
|
60
|
+
* Defines the module to use when bootstrapping the Angular pilet.
|
|
61
|
+
* @param ngModule The module to use for running Angular.
|
|
62
|
+
* @param opts The options to pass when bootstrapping.
|
|
63
|
+
*/
|
|
64
|
+
<T>(module: Type<T>, opts?: NgOptions): void;
|
|
65
|
+
/**
|
|
66
|
+
* Defines the module to lazy load for bootstrapping the Angular pilet.
|
|
67
|
+
* @param getModule The module lazy loader to use for running Angular.
|
|
68
|
+
* @param opts The options to pass when bootstrapping.
|
|
69
|
+
* @returns The module ID to be used to reference components.
|
|
70
|
+
*/
|
|
71
|
+
<T>(getModule: LazyType<T>, opts?: NgOptions): NgComponentLoader;
|
|
72
|
+
}
|
|
73
|
+
|
|
11
74
|
export interface NgComponent {
|
|
12
75
|
/**
|
|
13
76
|
* The component root.
|
|
14
77
|
*/
|
|
15
|
-
component: any;
|
|
78
|
+
component: Type<any> | NgLazyType;
|
|
16
79
|
/**
|
|
17
80
|
* The type of the Angular component.
|
|
18
81
|
*/
|
|
@@ -24,11 +87,18 @@ export interface NgComponent {
|
|
|
24
87
|
*/
|
|
25
88
|
export interface PiletNgApi {
|
|
26
89
|
/**
|
|
27
|
-
*
|
|
90
|
+
* Defines the module to use when bootstrapping the Angular pilet.
|
|
91
|
+
*/
|
|
92
|
+
defineNgModule: NgModuleDefiner;
|
|
93
|
+
/**
|
|
94
|
+
* Wraps an Angular component for use in Piral. Might reuse a previously
|
|
95
|
+
* defined module if the component was exported from it.
|
|
96
|
+
* Alternatively, a module might be passed in, where the first component
|
|
97
|
+
* of either the bootstrap or the entryComponents declaration is used.
|
|
28
98
|
* @param component The component root.
|
|
29
99
|
* @returns The Piral Ng component.
|
|
30
100
|
*/
|
|
31
|
-
fromNg(component:
|
|
101
|
+
fromNg<T>(component: Type<T>): NgComponent;
|
|
32
102
|
/**
|
|
33
103
|
* Angular component for displaying extensions of the given name.
|
|
34
104
|
*/
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { VERSION, StaticProvider } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
export interface NgAnnotation {
|
|
4
|
+
_initial?: Array<StaticProvider>;
|
|
5
|
+
standalone?: boolean;
|
|
6
|
+
providers: Array<StaticProvider>;
|
|
7
|
+
imports: Array<any>;
|
|
8
|
+
exports: Array<any>;
|
|
9
|
+
declarations: Array<any>;
|
|
10
|
+
entryComponents: Array<any>;
|
|
11
|
+
bootstrap: any;
|
|
12
|
+
selector: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getId() {
|
|
16
|
+
return Math.random().toString(36);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getNgVersion() {
|
|
20
|
+
return VERSION.major || VERSION.full.split('.')[0];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMinVersion() {
|
|
24
|
+
const major = getNgVersion();
|
|
25
|
+
return `${major}.0.0`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getAnnotations(component: any): Array<NgAnnotation> {
|
|
29
|
+
let annotations = component?.__annotations__;
|
|
30
|
+
|
|
31
|
+
if (!annotations && typeof Reflect !== 'undefined' && 'getOwnMetadata' in Reflect) {
|
|
32
|
+
annotations = (Reflect as any).getOwnMetadata('annotations', component);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (!annotations && typeof component.ɵcmp !== 'undefined') {
|
|
36
|
+
annotations = [{}];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (!annotations && typeof component.ɵmod !== 'undefined') {
|
|
40
|
+
annotations = [component.ɵmod];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return annotations || [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function hasSelector(component: any, selector: string) {
|
|
47
|
+
const [annotation] = getAnnotations(component);
|
|
48
|
+
return annotation && annotation.selector === selector;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function findComponents(exports: Array<any>): Array<any> {
|
|
52
|
+
const components = [];
|
|
53
|
+
|
|
54
|
+
if (Array.isArray(exports)) {
|
|
55
|
+
for (const ex of exports) {
|
|
56
|
+
const [annotation] = getAnnotations(ex);
|
|
57
|
+
|
|
58
|
+
if (annotation) {
|
|
59
|
+
if (annotation.exports) {
|
|
60
|
+
components.push(...findComponents(annotation.exports));
|
|
61
|
+
} else if (!annotation.imports || annotation.standalone) {
|
|
62
|
+
components.push(ex);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return components;
|
|
69
|
+
}
|
package/convert.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { HtmlComponent } from 'piral-core';
|
|
2
|
-
import { createConverter } from './lib/converter';
|
|
3
|
-
import { createExtension } from './lib/extension';
|
|
4
|
-
|
|
5
|
-
const convert = createConverter();
|
|
6
|
-
|
|
7
|
-
export interface NgConverter {
|
|
8
|
-
(...params: Parameters<typeof convert>): HtmlComponent<any>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const fromNg: NgConverter = (component) => ({
|
|
12
|
-
type: 'html',
|
|
13
|
-
component: convert(component),
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export const createNgExtension = createExtension;
|
package/esm/extension.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createExtension(rootName?: string, selector?: string): any;
|
package/esm/extension.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import { Component, ElementRef, Input, Inject, enableProdMode } from '@angular/core';
|
|
3
|
-
export function createExtension(rootName, selector) {
|
|
4
|
-
if (rootName === void 0) { rootName = 'slot'; }
|
|
5
|
-
if (selector === void 0) { selector = 'extension-component'; }
|
|
6
|
-
var template = "<" + rootName + "></" + rootName + ">";
|
|
7
|
-
var NgExtension = /** @class */ (function () {
|
|
8
|
-
function NgExtension(elRef, piral) {
|
|
9
|
-
this.elRef = elRef;
|
|
10
|
-
this.piral = piral;
|
|
11
|
-
}
|
|
12
|
-
NgExtension.prototype.ngAfterContentInit = function () {
|
|
13
|
-
this.piral.renderHtmlExtension(this.elRef.nativeElement, {
|
|
14
|
-
name: this.name,
|
|
15
|
-
params: this.params,
|
|
16
|
-
});
|
|
17
|
-
};
|
|
18
|
-
__decorate([
|
|
19
|
-
Input('name'),
|
|
20
|
-
__metadata("design:type", String)
|
|
21
|
-
], NgExtension.prototype, "name", void 0);
|
|
22
|
-
__decorate([
|
|
23
|
-
Input('params'),
|
|
24
|
-
__metadata("design:type", Object)
|
|
25
|
-
], NgExtension.prototype, "params", void 0);
|
|
26
|
-
NgExtension = __decorate([
|
|
27
|
-
Component({
|
|
28
|
-
selector: selector,
|
|
29
|
-
template: template,
|
|
30
|
-
}),
|
|
31
|
-
__param(1, Inject('piral')),
|
|
32
|
-
__metadata("design:paramtypes", [ElementRef, Object])
|
|
33
|
-
], NgExtension);
|
|
34
|
-
return NgExtension;
|
|
35
|
-
}());
|
|
36
|
-
if (process.env.ENV === 'production') {
|
|
37
|
-
enableProdMode();
|
|
38
|
-
}
|
|
39
|
-
return NgExtension;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=extension.js.map
|
package/esm/extension.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAErF,MAAM,UAAU,eAAe,CAAC,QAAiB,EAAE,QAAgC;IAAnD,yBAAA,EAAA,iBAAiB;IAAE,yBAAA,EAAA,gCAAgC;IACjF,IAAM,QAAQ,GAAG,MAAI,QAAQ,WAAM,QAAQ,MAAG,CAAC;IAM/C;QAIE,qBAAoB,KAA8B,EAA2B,KAAU;YAAnE,UAAK,GAAL,KAAK,CAAyB;YAA2B,UAAK,GAAL,KAAK,CAAK;QAAG,CAAC;QAE3F,wCAAkB,GAAlB;YACE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;gBACvD,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QAVc;YAAd,KAAK,CAAC,MAAM,CAAC;;iDAAqB;QAClB;YAAhB,KAAK,CAAC,QAAQ,CAAC;;mDAAuB;QAFnC,WAAW;YAJhB,SAAS,CAAC;gBACT,QAAQ,UAAA;gBACR,QAAQ,UAAA;aACT,CAAC;YAKqD,WAAA,MAAM,CAAC,OAAO,CAAC,CAAA;6CAAzC,UAAU;WAJjC,WAAW,CAYhB;QAAD,kBAAC;KAAA,AAZD,IAYC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,YAAY,EAAE;QACpC,cAAc,EAAE,CAAC;KAClB;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/lib/extension.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createExtension(rootName?: string, selector?: string): any;
|
package/lib/extension.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createExtension = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var core_1 = require("@angular/core");
|
|
6
|
-
function createExtension(rootName, selector) {
|
|
7
|
-
if (rootName === void 0) { rootName = 'slot'; }
|
|
8
|
-
if (selector === void 0) { selector = 'extension-component'; }
|
|
9
|
-
var template = "<" + rootName + "></" + rootName + ">";
|
|
10
|
-
var NgExtension = /** @class */ (function () {
|
|
11
|
-
function NgExtension(elRef, piral) {
|
|
12
|
-
this.elRef = elRef;
|
|
13
|
-
this.piral = piral;
|
|
14
|
-
}
|
|
15
|
-
NgExtension.prototype.ngAfterContentInit = function () {
|
|
16
|
-
this.piral.renderHtmlExtension(this.elRef.nativeElement, {
|
|
17
|
-
name: this.name,
|
|
18
|
-
params: this.params,
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
tslib_1.__decorate([
|
|
22
|
-
core_1.Input('name'),
|
|
23
|
-
tslib_1.__metadata("design:type", String)
|
|
24
|
-
], NgExtension.prototype, "name", void 0);
|
|
25
|
-
tslib_1.__decorate([
|
|
26
|
-
core_1.Input('params'),
|
|
27
|
-
tslib_1.__metadata("design:type", Object)
|
|
28
|
-
], NgExtension.prototype, "params", void 0);
|
|
29
|
-
NgExtension = tslib_1.__decorate([
|
|
30
|
-
core_1.Component({
|
|
31
|
-
selector: selector,
|
|
32
|
-
template: template,
|
|
33
|
-
}),
|
|
34
|
-
tslib_1.__param(1, core_1.Inject('piral')),
|
|
35
|
-
tslib_1.__metadata("design:paramtypes", [core_1.ElementRef, Object])
|
|
36
|
-
], NgExtension);
|
|
37
|
-
return NgExtension;
|
|
38
|
-
}());
|
|
39
|
-
if (process.env.ENV === 'production') {
|
|
40
|
-
core_1.enableProdMode();
|
|
41
|
-
}
|
|
42
|
-
return NgExtension;
|
|
43
|
-
}
|
|
44
|
-
exports.createExtension = createExtension;
|
|
45
|
-
//# sourceMappingURL=extension.js.map
|
package/lib/extension.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AAAA,sCAAqF;AAErF,SAAgB,eAAe,CAAC,QAAiB,EAAE,QAAgC;IAAnD,yBAAA,EAAA,iBAAiB;IAAE,yBAAA,EAAA,gCAAgC;IACjF,IAAM,QAAQ,GAAG,MAAI,QAAQ,WAAM,QAAQ,MAAG,CAAC;IAM/C;QAIE,qBAAoB,KAA8B,EAA2B,KAAU;YAAnE,UAAK,GAAL,KAAK,CAAyB;YAA2B,UAAK,GAAL,KAAK,CAAK;QAAG,CAAC;QAE3F,wCAAkB,GAAlB;YACE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;gBACvD,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,MAAM,EAAE,IAAI,CAAC,MAAM;aACpB,CAAC,CAAC;QACL,CAAC;QAVc;YAAd,YAAK,CAAC,MAAM,CAAC;;iDAAqB;QAClB;YAAhB,YAAK,CAAC,QAAQ,CAAC;;mDAAuB;QAFnC,WAAW;YAJhB,gBAAS,CAAC;gBACT,QAAQ,UAAA;gBACR,QAAQ,UAAA;aACT,CAAC;YAKqD,mBAAA,aAAM,CAAC,OAAO,CAAC,CAAA;qDAAzC,iBAAU;WAJjC,WAAW,CAYhB;QAAD,kBAAC;KAAA,AAZD,IAYC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,YAAY,EAAE;QACpC,qBAAc,EAAE,CAAC;KAClB;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AA1BD,0CA0BC"}
|
package/src/extension.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Component, ElementRef, Input, Inject, enableProdMode } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
export function createExtension(rootName = 'slot', selector = 'extension-component'): any {
|
|
4
|
-
const template = `<${rootName}></${rootName}>`;
|
|
5
|
-
|
|
6
|
-
@Component({
|
|
7
|
-
selector,
|
|
8
|
-
template,
|
|
9
|
-
})
|
|
10
|
-
class NgExtension {
|
|
11
|
-
@Input('name') public name: string;
|
|
12
|
-
@Input('params') public params: object;
|
|
13
|
-
|
|
14
|
-
constructor(private elRef: ElementRef<HTMLElement>, @Inject('piral') private piral: any) {}
|
|
15
|
-
|
|
16
|
-
ngAfterContentInit() {
|
|
17
|
-
this.piral.renderHtmlExtension(this.elRef.nativeElement, {
|
|
18
|
-
name: this.name,
|
|
19
|
-
params: this.params,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (process.env.ENV === 'production') {
|
|
25
|
-
enableProdMode();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return NgExtension;
|
|
29
|
-
}
|