piral-ng 0.14.0-beta.3157 → 0.14.0-beta.3187

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 (66) hide show
  1. package/README.md +163 -15
  2. package/common.d.ts +2 -0
  3. package/common.js +2 -0
  4. package/esm/NgExtension.d.ts +16 -0
  5. package/esm/NgExtension.js +60 -0
  6. package/esm/NgExtension.js.map +1 -0
  7. package/esm/ResourceUrlPipe.d.ts +3 -0
  8. package/esm/ResourceUrlPipe.js +27 -2
  9. package/esm/ResourceUrlPipe.js.map +1 -1
  10. package/esm/RoutingService.d.ts +2 -0
  11. package/esm/RoutingService.js +46 -5
  12. package/esm/RoutingService.js.map +1 -1
  13. package/esm/SharedModule.d.ts +15 -0
  14. package/esm/SharedModule.js +42 -6
  15. package/esm/SharedModule.js.map +1 -1
  16. package/esm/bootstrap.js +2 -1
  17. package/esm/bootstrap.js.map +1 -1
  18. package/esm/converter.js +1 -1
  19. package/esm/converter.js.map +1 -1
  20. package/esm/module.js +73 -12
  21. package/esm/module.js.map +1 -1
  22. package/esm/startup.js +4 -2
  23. package/esm/startup.js.map +1 -1
  24. package/esm/utils.d.ts +3 -2
  25. package/esm/utils.js +14 -13
  26. package/esm/utils.js.map +1 -1
  27. package/extend-webpack.js +67 -0
  28. package/lib/NgExtension.d.ts +16 -0
  29. package/lib/{extension.js → NgExtension.js} +32 -4
  30. package/lib/NgExtension.js.map +1 -0
  31. package/lib/ResourceUrlPipe.d.ts +3 -0
  32. package/lib/ResourceUrlPipe.js +27 -2
  33. package/lib/ResourceUrlPipe.js.map +1 -1
  34. package/lib/RoutingService.d.ts +2 -0
  35. package/lib/RoutingService.js +46 -5
  36. package/lib/RoutingService.js.map +1 -1
  37. package/lib/SharedModule.d.ts +15 -0
  38. package/lib/SharedModule.js +42 -6
  39. package/lib/SharedModule.js.map +1 -1
  40. package/lib/bootstrap.js +2 -1
  41. package/lib/bootstrap.js.map +1 -1
  42. package/lib/converter.js +2 -2
  43. package/lib/converter.js.map +1 -1
  44. package/lib/module.js +73 -12
  45. package/lib/module.js.map +1 -1
  46. package/lib/startup.js +3 -1
  47. package/lib/startup.js.map +1 -1
  48. package/lib/utils.d.ts +3 -2
  49. package/lib/utils.js +17 -15
  50. package/lib/utils.js.map +1 -1
  51. package/package.json +5 -4
  52. package/src/NgExtension.ts +61 -0
  53. package/src/ResourceUrlPipe.ts +34 -0
  54. package/src/RoutingService.ts +67 -17
  55. package/src/SharedModule.ts +52 -4
  56. package/src/bootstrap.ts +2 -1
  57. package/src/converter.ts +1 -1
  58. package/src/module.ts +92 -9
  59. package/src/startup.ts +4 -2
  60. package/src/utils.ts +19 -19
  61. package/esm/extension.d.ts +0 -10
  62. package/esm/extension.js +0 -32
  63. package/esm/extension.js.map +0 -1
  64. package/lib/extension.d.ts +0 -10
  65. package/lib/extension.js.map +0 -1
  66. package/src/extension.ts +0 -20
@@ -1,14 +1,62 @@
1
+ import * as ngCore from '@angular/core';
1
2
  import { CommonModule } from '@angular/common';
2
3
  import { NgModule } from '@angular/core';
3
- import { NgExtension } from './extension';
4
+ import { NgExtension } from './NgExtension';
4
5
  import { ResourceUrlPipe } from './ResourceUrlPipe';
5
6
 
7
+ const ngc = ngCore as any;
8
+ const declarationsDef = [NgExtension, ResourceUrlPipe];
9
+ const exportsDef = [NgExtension, ResourceUrlPipe];
10
+ const importsDef = [CommonModule];
11
+
6
12
  @NgModule({
7
- declarations: [NgExtension, ResourceUrlPipe],
13
+ declarations: declarationsDef,
8
14
  providers: [],
9
- imports: [CommonModule],
10
- exports: [NgExtension, ResourceUrlPipe],
15
+ imports: importsDef,
16
+ exports: exportsDef,
11
17
  })
12
18
  export class SharedModule {
13
19
  static props = {};
20
+
21
+ // @ts-ignore
22
+ static ɵfac: ngCore.ɵɵFactoryDeclaration<SharedModule, never> =
23
+ 'ɵɵinject' in ngc ? (t: any) => new (t || SharedModule)() : undefined;
24
+
25
+ // @ts-ignore
26
+ static ɵmod: ngCore.ɵɵNgModuleDeclaration<
27
+ SharedModule,
28
+ [typeof NgExtension, typeof ResourceUrlPipe],
29
+ [typeof CommonModule],
30
+ [typeof NgExtension, typeof ResourceUrlPipe]
31
+ > =
32
+ 'ɵɵdefineNgModule' in ngc
33
+ ? ngc.ɵɵdefineNgModule({
34
+ type: SharedModule,
35
+ })
36
+ : undefined;
37
+
38
+ // @ts-ignore
39
+ static ɵinj: ngCore.ɵɵInjectorDeclaration<SharedModule> =
40
+ 'ɵɵdefineInjector' in ngc
41
+ ? ngc.ɵɵdefineInjector({
42
+ providers: [],
43
+ imports: [importsDef],
44
+ })
45
+ : undefined;
46
+ }
47
+
48
+ if ('ɵsetClassMetadata' in ngc) {
49
+ ngc.ɵsetClassMetadata(SharedModule, [
50
+ {
51
+ type: NgModule,
52
+ args: [
53
+ {
54
+ declarations: declarationsDef,
55
+ providers: [],
56
+ imports: importsDef,
57
+ exports: exportsDef,
58
+ },
59
+ ],
60
+ },
61
+ ]);
14
62
  }
package/src/bootstrap.ts CHANGED
@@ -15,7 +15,8 @@ export function prepareBootstrap(moduleOrComponent: any): PrepareBootstrapResult
15
15
  return [...getModuleInstance(component), component];
16
16
  } else {
17
17
  // usually contains things like selector, template or templateUrl, changeDetection, ...
18
- return [...(getModuleInstance(moduleOrComponent) || createModuleInstance(moduleOrComponent)), moduleOrComponent];
18
+ const result = getModuleInstance(moduleOrComponent) || createModuleInstance(moduleOrComponent);
19
+ return [...result, moduleOrComponent];
19
20
  }
20
21
  }
21
22
 
package/src/converter.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { ForeignComponent, BaseComponentProps, Disposable } from 'piral-core';
2
2
  import type { NgModuleDefiner } from './types';
3
+ import { NgExtension } from './NgExtension';
3
4
  import { enqueue } from './queue';
4
5
  import { defineModule } from './module';
5
- import { NgExtension } from './extension';
6
6
  import { bootstrap, prepareBootstrap } from './bootstrap';
7
7
 
8
8
  export interface NgConverterOptions {}
package/src/module.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { NgOptions, ModuleInstanceResult } from './types';
2
+ import * as ngCore from '@angular/core';
2
3
  import { BrowserModule } from '@angular/platform-browser';
3
4
  import { CommonModule } from '@angular/common';
4
5
  import { ApplicationRef, ComponentFactoryResolver, ComponentRef, NgModule, NgZone } from '@angular/core';
@@ -6,6 +7,8 @@ import { RoutingService } from './RoutingService';
6
7
  import { SharedModule } from './SharedModule';
7
8
  import { findComponents, getAnnotations } from './utils';
8
9
 
10
+ const ngc = ngCore as any;
11
+
9
12
  interface ModuleDefinition {
10
13
  active: any;
11
14
  module: any;
@@ -19,15 +22,16 @@ function instantiateModule(moduleDef: ModuleDefinition) {
19
22
  const { module, components } = moduleDef;
20
23
  const imports = [BrowserModule, SharedModule, module];
21
24
  const props = { current: undefined };
25
+ const providers = [
26
+ RoutingService,
27
+ { provide: 'Props', useFactory: () => props.current, deps: [] },
28
+ { provide: 'piral', useFactory: () => props.current.piral, deps: [] },
29
+ ];
22
30
 
23
31
  @NgModule({
24
32
  imports,
25
33
  entryComponents: components,
26
- providers: [
27
- RoutingService,
28
- { provide: 'Props', useFactory: () => props.current, deps: [] },
29
- { provide: 'piral', useFactory: () => props.current.piral, deps: [] },
30
- ],
34
+ providers,
31
35
  })
32
36
  class BootstrapModule {
33
37
  private appRef: ApplicationRef;
@@ -59,6 +63,50 @@ function instantiateModule(moduleDef: ModuleDefinition) {
59
63
  }
60
64
  }
61
65
  }
66
+
67
+ static ɵfac =
68
+ 'ɵɵinject' in ngc
69
+ ? (t: any) =>
70
+ new (t || BootstrapModule)(
71
+ ngc.ɵɵinject(ComponentFactoryResolver),
72
+ ngc.ɵɵinject(NgZone),
73
+ ngc.ɵɵinject(RoutingService),
74
+ )
75
+ : undefined;
76
+
77
+ static ɵmod =
78
+ 'ɵɵdefineNgModule' in ngc
79
+ ? ngc.ɵɵdefineNgModule({
80
+ type: BootstrapModule,
81
+ })
82
+ : undefined;
83
+
84
+ static ɵinj =
85
+ 'ɵɵdefineInjector' in ngc
86
+ ? ngc.ɵɵdefineInjector({
87
+ providers,
88
+ imports: [imports],
89
+ })
90
+ : undefined;
91
+ }
92
+
93
+ if ('ɵsetClassMetadata' in ngc) {
94
+ ngc.ɵsetClassMetadata(
95
+ BootstrapModule,
96
+ [
97
+ {
98
+ type: NgModule,
99
+ args: [
100
+ {
101
+ entryComponents: components,
102
+ providers,
103
+ imports,
104
+ },
105
+ ],
106
+ },
107
+ ],
108
+ () => [{ type: ComponentFactoryResolver }, { type: NgZone }, { type: RoutingService }],
109
+ );
62
110
  }
63
111
 
64
112
  return BootstrapModule;
@@ -79,12 +127,47 @@ export function getModuleInstance(component: any): ModuleInstanceResult {
79
127
  }
80
128
 
81
129
  export function createModuleInstance(component: any): ModuleInstanceResult {
130
+ const declarations = [component];
131
+ const importsDef = [CommonModule];
132
+ const exportsDef = [component];
133
+
82
134
  @NgModule({
83
- declarations: [component],
84
- imports: [CommonModule],
85
- exports: [component],
135
+ declarations,
136
+ imports: importsDef,
137
+ exports: exportsDef,
86
138
  })
87
- class Module {}
139
+ class Module {
140
+ static ɵfac = 'ɵɵinject' in ngc ? (t: any) => new (t || Module)() : undefined;
141
+
142
+ static ɵmod =
143
+ 'ɵɵdefineNgModule' in ngc
144
+ ? ngc.ɵɵdefineNgModule({
145
+ type: Module,
146
+ })
147
+ : undefined;
148
+
149
+ static ɵinj =
150
+ 'ɵɵdefineInjector' in ngc
151
+ ? ngc.ɵɵdefineInjector({
152
+ imports: [importsDef],
153
+ })
154
+ : undefined;
155
+ }
156
+
157
+ if ('ɵsetClassMetadata' in ngc) {
158
+ ngc.ɵsetClassMetadata(Module, [
159
+ {
160
+ type: NgModule,
161
+ args: [
162
+ {
163
+ declarations,
164
+ imports: importsDef,
165
+ exports: exportsDef,
166
+ },
167
+ ],
168
+ },
169
+ ]);
170
+ }
88
171
 
89
172
  defineModule(Module);
90
173
  return getModuleInstance(component);
package/src/startup.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import type { ComponentContext } from 'piral-core';
2
2
  import type { NgOptions } from './types';
3
3
  import { enableProdMode, NgModuleRef, NgZone } from '@angular/core';
4
- import { APP_BASE_HREF, VERSION } from '@angular/common';
4
+ import { APP_BASE_HREF } from '@angular/common';
5
5
  import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
6
+ import { getNgVersion } from './utils';
6
7
 
7
8
  function getVersionHandler(versions: Record<string, () => void>) {
8
- const version = `v${VERSION.major || VERSION.full.split('.')[0]}`;
9
+ const major = getNgVersion();
10
+ const version = `v${major}`;
9
11
  return versions[version];
10
12
  }
11
13
 
package/src/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { StaticProvider } from '@angular/core';
1
+ import { VERSION, StaticProvider } from '@angular/core';
2
2
 
3
3
  export interface NgAnnotation {
4
4
  _initial?: Array<StaticProvider>;
@@ -11,6 +11,15 @@ export interface NgAnnotation {
11
11
  selector: string;
12
12
  }
13
13
 
14
+ export function getNgVersion() {
15
+ return VERSION.major || VERSION.full.split('.')[0];
16
+ }
17
+
18
+ export function getMinVersion() {
19
+ const major = getNgVersion();
20
+ return `${major}.0.0`;
21
+ }
22
+
14
23
  export function getAnnotations(component: any): Array<NgAnnotation> {
15
24
  let annotations = component?.__annotations__;
16
25
 
@@ -18,6 +27,14 @@ export function getAnnotations(component: any): Array<NgAnnotation> {
18
27
  annotations = (Reflect as any).getOwnMetadata('annotations', component);
19
28
  }
20
29
 
30
+ if (!annotations && typeof component.ɵcmp !== 'undefined') {
31
+ annotations = [{}];
32
+ }
33
+
34
+ if (!annotations && typeof component.ɵmod !== 'undefined') {
35
+ annotations = [component.ɵmod];
36
+ }
37
+
21
38
  return annotations || [];
22
39
  }
23
40
 
@@ -27,7 +44,7 @@ export function findComponents(exports: Array<any>): Array<any> {
27
44
  if (exports && Array.isArray(exports)) {
28
45
  for (const ex of exports) {
29
46
  const [annotation] = getAnnotations(ex);
30
-
47
+
31
48
  if (annotation) {
32
49
  if (annotation.exports) {
33
50
  components.push(...findComponents(annotation.exports));
@@ -40,20 +57,3 @@ export function findComponents(exports: Array<any>): Array<any> {
40
57
 
41
58
  return components;
42
59
  }
43
-
44
- export function addImportRecursively(targetModule: any, importModule: any) {
45
- const [annotation] = getAnnotations(targetModule);
46
-
47
- if (annotation) {
48
- const existingImports = annotation.imports || [];
49
- annotation.imports = [...existingImports, importModule];
50
-
51
- if ('ɵinj' in targetModule) {
52
- targetModule.ɵinj.imports = annotation.imports;
53
- }
54
-
55
- for (const existingImport of existingImports) {
56
- addImportRecursively(existingImport, importModule);
57
- }
58
- }
59
- }
@@ -1,10 +0,0 @@
1
- import type { PiletApi } from 'piral-core';
2
- import { ElementRef } from '@angular/core';
3
- export declare class NgExtension {
4
- private elRef;
5
- private piral;
6
- name: string;
7
- params: object;
8
- constructor(elRef: ElementRef<HTMLElement>, piral: PiletApi);
9
- ngAfterContentInit(): void;
10
- }
package/esm/extension.js DELETED
@@ -1,32 +0,0 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { Component, ElementRef, Input, Inject } from '@angular/core';
3
- let NgExtension = class NgExtension {
4
- constructor(elRef, piral) {
5
- this.elRef = elRef;
6
- this.piral = piral;
7
- }
8
- ngAfterContentInit() {
9
- this.piral.renderHtmlExtension(this.elRef.nativeElement, {
10
- name: this.name,
11
- params: this.params,
12
- });
13
- }
14
- };
15
- __decorate([
16
- Input('name'),
17
- __metadata("design:type", String)
18
- ], NgExtension.prototype, "name", void 0);
19
- __decorate([
20
- Input('params'),
21
- __metadata("design:type", Object)
22
- ], NgExtension.prototype, "params", void 0);
23
- NgExtension = __decorate([
24
- Component({
25
- selector: 'extension-component',
26
- template: '',
27
- }),
28
- __param(1, Inject('piral')),
29
- __metadata("design:paramtypes", [ElementRef, Object])
30
- ], NgExtension);
31
- export { NgExtension };
32
- //# sourceMappingURL=extension.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAMrE,IAAa,WAAW,GAAxB,MAAa,WAAW;IAItB,YAAoB,KAA8B,EAA2B,KAAe;QAAxE,UAAK,GAAL,KAAK,CAAyB;QAA2B,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAEhG,kBAAkB;QAChB,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;YACvD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAXgB;IAAd,KAAK,CAAC,MAAM,CAAC;;yCAAqB;AAClB;IAAhB,KAAK,CAAC,QAAQ,CAAC;;2CAAuB;AAF5B,WAAW;IAJvB,SAAS,CAAC;QACT,QAAQ,EAAE,qBAAqB;QAC/B,QAAQ,EAAE,EAAE;KACb,CAAC;IAKqD,WAAA,MAAM,CAAC,OAAO,CAAC,CAAA;qCAAzC,UAAU;GAJ1B,WAAW,CAYvB;SAZY,WAAW"}
@@ -1,10 +0,0 @@
1
- import type { PiletApi } from 'piral-core';
2
- import { ElementRef } from '@angular/core';
3
- export declare class NgExtension {
4
- private elRef;
5
- private piral;
6
- name: string;
7
- params: object;
8
- constructor(elRef: ElementRef<HTMLElement>, piral: PiletApi);
9
- ngAfterContentInit(): void;
10
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":";;;;AACA,wCAAqE;AAMrE,IAAa,WAAW,GAAxB,MAAa,WAAW;IAItB,YAAoB,KAA8B,EAA2B,KAAe;QAAxE,UAAK,GAAL,KAAK,CAAyB;QAA2B,UAAK,GAAL,KAAK,CAAU;IAAG,CAAC;IAEhG,kBAAkB;QAChB,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;YACvD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAXgB;IAAd,IAAA,YAAK,EAAC,MAAM,CAAC;;yCAAqB;AAClB;IAAhB,IAAA,YAAK,EAAC,QAAQ,CAAC;;2CAAuB;AAF5B,WAAW;IAJvB,IAAA,gBAAS,EAAC;QACT,QAAQ,EAAE,qBAAqB;QAC/B,QAAQ,EAAE,EAAE;KACb,CAAC;IAKqD,wBAAA,IAAA,aAAM,EAAC,OAAO,CAAC,CAAA;kDAAzC,iBAAU;GAJ1B,WAAW,CAYvB;AAZY,kCAAW"}
package/src/extension.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { PiletApi } from 'piral-core';
2
- import { Component, ElementRef, Input, Inject } from '@angular/core';
3
-
4
- @Component({
5
- selector: 'extension-component',
6
- template: '',
7
- })
8
- export class NgExtension {
9
- @Input('name') public name: string;
10
- @Input('params') public params: object;
11
-
12
- constructor(private elRef: ElementRef<HTMLElement>, @Inject('piral') private piral: PiletApi) {}
13
-
14
- ngAfterContentInit() {
15
- this.piral.renderHtmlExtension(this.elRef.nativeElement, {
16
- name: this.name,
17
- params: this.params,
18
- });
19
- }
20
- }