piral-ng 1.5.5-beta.7076 → 1.5.5-beta.7084

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/README.md CHANGED
@@ -108,7 +108,11 @@ which defines the selector (`angular-page`) matching the specified selector in t
108
108
 
109
109
  ### Standalone Components
110
110
 
111
- The `piral-ng` plugin also supports Angular standalone components as rendering source.
111
+ The `piral-ng` plugin also supports Angular standalone components as rendering source. For this we have two modes:
112
+
113
+ #### Legacy Standalone Mode
114
+
115
+ This mode works with `piral-ng` itself, i.e., integrated in the app shell. It also works in a mix with modules.
112
116
 
113
117
  Standalone components can also be used with lazy loading.
114
118
 
@@ -121,6 +125,20 @@ export function setup(piral: PiletApi) {
121
125
  }
122
126
  ```
123
127
 
128
+ #### Isolated Standalone Mode
129
+
130
+ This mode works only with `piral-ng/standalone`, which has to be used in a pilet directly (as a replacement for `piral-ng/convert`). It does not mix with modules - as components need to be proper standalone entry points.
131
+
132
+ ```ts
133
+ import { createConverter } from 'piral-ng/standalone';
134
+ import { PiletApi } from '<name-of-piral-instance>';
135
+
136
+ export function setup(piral: PiletApi) {
137
+ // Just make sure that `AngularPage` exports the component as `default` export
138
+ piral.registerPage('/sample', piral.fromNg(() => import('./AngularPage')));
139
+ }
140
+ ```
141
+
124
142
  ### Angular Options
125
143
 
126
144
  You can optionally provide Options to `defineNgModule`, which are identical to those given to `bootstrapModule` during the Angular boot process. See https://angular.io/api/core/PlatformRef#bootstrapModule for possible values.
@@ -0,0 +1,12 @@
1
+ import type { ComponentContext } from 'piral-core';
2
+ import { NgZone, OnDestroy } from '@angular/core';
3
+ import { Router } from '@angular/router';
4
+ export declare class CoreRoutingService implements OnDestroy {
5
+ context: ComponentContext;
6
+ private router;
7
+ private zone;
8
+ private dispose;
9
+ private subscription;
10
+ constructor(context: ComponentContext, router: Router, zone: NgZone);
11
+ ngOnDestroy(): void;
12
+ }
@@ -0,0 +1,77 @@
1
+ import { __decorate, __metadata, __param } from "tslib";
2
+ import { Inject, Injectable, NgZone, Optional } from '@angular/core';
3
+ import { Router } from '@angular/router';
4
+ import { BrowserPlatformLocation as ɵBrowserPlatformLocation } from '@angular/common';
5
+ const noop = function () { };
6
+ // deactivates the usual platform behavior; all these operations are performed via the RoutingService
7
+ // to avoid any conflict, e.g., double-booking URL changes in React and Angular
8
+ ɵBrowserPlatformLocation.prototype.pushState = noop;
9
+ ɵBrowserPlatformLocation.prototype.replaceState = noop;
10
+ ɵBrowserPlatformLocation.prototype.forward = noop;
11
+ ɵBrowserPlatformLocation.prototype.back = noop;
12
+ ɵBrowserPlatformLocation.prototype.historyGo = noop;
13
+ function normalize(url) {
14
+ const search = url.indexOf('?');
15
+ const hash = url.indexOf('#');
16
+ if (search !== -1 || hash !== -1) {
17
+ if (search === -1) {
18
+ return url.substring(0, hash);
19
+ }
20
+ else if (hash === -1) {
21
+ return url.substring(0, search);
22
+ }
23
+ else {
24
+ return url.substring(0, Math.min(search, hash));
25
+ }
26
+ }
27
+ return url;
28
+ }
29
+ let CoreRoutingService = class CoreRoutingService {
30
+ constructor(context, router, zone) {
31
+ this.context = context;
32
+ this.router = router;
33
+ this.zone = zone;
34
+ if (this.router) {
35
+ this.router.errorHandler = (error) => {
36
+ // Match in development and production
37
+ if (error.message.match('Cannot match any routes') || error.message.match('NG04002')) {
38
+ // ignore this special error
39
+ return undefined;
40
+ }
41
+ throw error;
42
+ };
43
+ const nav = this.context.navigation;
44
+ const queueNavigation = (url) => {
45
+ window.requestAnimationFrame(() => nav.push(url));
46
+ };
47
+ this.dispose = nav.listen(({ location }) => {
48
+ const path = location.pathname;
49
+ const url = `${path}${location.search}${location.hash}`;
50
+ this.zone.run(() => this.router.navigateByUrl(url));
51
+ });
52
+ this.subscription = this.router.events.subscribe((e) => {
53
+ if (e.type === 1) {
54
+ const routerUrl = normalize(e.urlAfterRedirects);
55
+ const locationUrl = nav.url;
56
+ if (routerUrl !== locationUrl) {
57
+ queueNavigation(routerUrl);
58
+ }
59
+ }
60
+ });
61
+ }
62
+ }
63
+ ngOnDestroy() {
64
+ this.dispose?.();
65
+ this.subscription?.unsubscribe();
66
+ }
67
+ };
68
+ CoreRoutingService = __decorate([
69
+ Injectable(),
70
+ __param(0, Inject('Context')),
71
+ __param(1, Optional()),
72
+ __param(2, Optional()),
73
+ __metadata("design:paramtypes", [Object, Router,
74
+ NgZone])
75
+ ], CoreRoutingService);
76
+ export { CoreRoutingService };
77
+ //# sourceMappingURL=CoreRoutingService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreRoutingService.js","sourceRoot":"","sources":["../src/CoreRoutingService.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAa,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAmD,MAAM,EAAU,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAAE,uBAAuB,IAAI,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEtF,MAAM,IAAI,GAAG,cAAa,CAAC,CAAC;AAE5B,qGAAqG;AACrG,+EAA+E;AAC/E,wBAAwB,CAAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;AACpD,wBAAwB,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC;AACvD,wBAAwB,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AAClD,wBAAwB,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;AAC/C,wBAAwB,CAAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;AAEpD,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE;QAChC,IAAI,MAAM,KAAK,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AAC,QAAQ,CAAC;gBAC/B,MAAM,GAAG,GAAG,GAAG,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACxD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9C,CAAC,CAA6D,EAAE,EAAE;gBAChE,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE;oBAChB,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;oBACjD,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC;oBAE5B,IAAI,SAAS,KAAK,WAAW,EAAE;wBAC7B,eAAe,CAAC,SAAS,CAAC,CAAC;qBAC5B;iBACF;YACH,CAAC,CACF,CAAC;SACH;IACH,CAAC;IAED,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACjB,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;IACnC,CAAC;CACF,CAAA;AAlDY,kBAAkB;IAD9B,UAAU,EAAE;IAMR,WAAA,MAAM,CAAC,SAAS,CAAC,CAAA;IACjB,WAAA,QAAQ,EAAE,CAAA;IACV,WAAA,QAAQ,EAAE,CAAA;6CADiB,MAAM;QACR,MAAM;GAPvB,kBAAkB,CAkD9B"}
@@ -0,0 +1,6 @@
1
+ import { ApplicationConfig, Type } from '@angular/core';
2
+ import type { BaseComponentProps, HtmlComponent } from 'piral-core';
3
+ export interface NgStandaloneConverter {
4
+ <TProps extends BaseComponentProps>(component: Type<TProps>): HtmlComponent<TProps>;
5
+ }
6
+ export declare function createConverter(options: ApplicationConfig): NgStandaloneConverter;
@@ -0,0 +1,61 @@
1
+ import { APP_BASE_HREF } from '@angular/common';
2
+ import { createApplication } from '@angular/platform-browser';
3
+ import { ɵresetCompiledComponents as reset, } from '@angular/core';
4
+ import { CoreRoutingService } from './CoreRoutingService';
5
+ export function createConverter(options) {
6
+ const update = (ref, props) => {
7
+ if (ref) {
8
+ const ct = ref.componentType;
9
+ if (ct?.ɵcmp?.inputs?.Props) {
10
+ ref.setInput('Props', props);
11
+ }
12
+ }
13
+ };
14
+ let app = undefined;
15
+ return (component) => ({
16
+ type: 'html',
17
+ component: {
18
+ mount(element, props, ctx, locals) {
19
+ if (!app) {
20
+ const { piral } = props;
21
+ app = createApplication({
22
+ ...options,
23
+ providers: [
24
+ ...options.providers,
25
+ CoreRoutingService,
26
+ { provide: APP_BASE_HREF, useValue: ctx.publicPath },
27
+ { provide: 'Context', useValue: ctx },
28
+ { provide: 'piral', useValue: piral },
29
+ ],
30
+ });
31
+ piral.on('unload-pilet', (ev) => {
32
+ if (ev.name === piral.meta.name && typeof reset === 'function') {
33
+ // pretty much a cleanup step for Angular.
34
+ reset();
35
+ }
36
+ });
37
+ }
38
+ locals.active = true;
39
+ app.then((appRef) => {
40
+ if (locals.active) {
41
+ const ref = appRef.bootstrap(component, element);
42
+ // Start the routing service.
43
+ appRef.injector.get(CoreRoutingService);
44
+ update(ref, props);
45
+ locals.component = ref;
46
+ }
47
+ });
48
+ },
49
+ update(_1, props, _2, locals) {
50
+ update(locals.component, props);
51
+ },
52
+ unmount(element, locals) {
53
+ locals.active = false;
54
+ locals.component?.destroy();
55
+ locals.component = undefined;
56
+ element.remove();
57
+ },
58
+ },
59
+ });
60
+ }
61
+ //# sourceMappingURL=standalone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.js","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAKL,wBAAwB,IAA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CAAC;yBACT;oBACH,CAAC,CAAC,CAAC;iBACJ;gBAED,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;gBAErB,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;oBAClB,IAAI,MAAM,CAAC,MAAM,EAAE;wBACjB,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;wBAEjD,6BAA6B;wBAC7B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;wBAExC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;wBACnB,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC;qBACxB;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;gBAC1B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,CAAC,OAAO,EAAE,MAAM;gBACrB,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;gBACtB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;gBAC5B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;gBAC7B,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ComponentContext } from 'piral-core';
2
+ import { NgZone, OnDestroy } from '@angular/core';
3
+ import { Router } from '@angular/router';
4
+ export declare class CoreRoutingService implements OnDestroy {
5
+ context: ComponentContext;
6
+ private router;
7
+ private zone;
8
+ private dispose;
9
+ private subscription;
10
+ constructor(context: ComponentContext, router: Router, zone: NgZone);
11
+ ngOnDestroy(): void;
12
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CoreRoutingService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@angular/core");
6
+ const router_1 = require("@angular/router");
7
+ const common_1 = require("@angular/common");
8
+ const noop = function () { };
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
+ common_1.BrowserPlatformLocation.prototype.pushState = noop;
12
+ common_1.BrowserPlatformLocation.prototype.replaceState = noop;
13
+ common_1.BrowserPlatformLocation.prototype.forward = noop;
14
+ common_1.BrowserPlatformLocation.prototype.back = noop;
15
+ common_1.BrowserPlatformLocation.prototype.historyGo = noop;
16
+ function normalize(url) {
17
+ const search = url.indexOf('?');
18
+ const hash = url.indexOf('#');
19
+ if (search !== -1 || hash !== -1) {
20
+ if (search === -1) {
21
+ return url.substring(0, hash);
22
+ }
23
+ else if (hash === -1) {
24
+ return url.substring(0, search);
25
+ }
26
+ else {
27
+ return url.substring(0, Math.min(search, hash));
28
+ }
29
+ }
30
+ return url;
31
+ }
32
+ let CoreRoutingService = class CoreRoutingService {
33
+ constructor(context, router, zone) {
34
+ this.context = context;
35
+ this.router = router;
36
+ this.zone = zone;
37
+ if (this.router) {
38
+ this.router.errorHandler = (error) => {
39
+ // Match in development and production
40
+ if (error.message.match('Cannot match any routes') || error.message.match('NG04002')) {
41
+ // ignore this special error
42
+ return undefined;
43
+ }
44
+ throw error;
45
+ };
46
+ const nav = this.context.navigation;
47
+ const queueNavigation = (url) => {
48
+ window.requestAnimationFrame(() => nav.push(url));
49
+ };
50
+ this.dispose = nav.listen(({ location }) => {
51
+ const path = location.pathname;
52
+ const url = `${path}${location.search}${location.hash}`;
53
+ this.zone.run(() => this.router.navigateByUrl(url));
54
+ });
55
+ this.subscription = this.router.events.subscribe((e) => {
56
+ if (e.type === 1) {
57
+ const routerUrl = normalize(e.urlAfterRedirects);
58
+ const locationUrl = nav.url;
59
+ if (routerUrl !== locationUrl) {
60
+ queueNavigation(routerUrl);
61
+ }
62
+ }
63
+ });
64
+ }
65
+ }
66
+ ngOnDestroy() {
67
+ this.dispose?.();
68
+ this.subscription?.unsubscribe();
69
+ }
70
+ };
71
+ exports.CoreRoutingService = CoreRoutingService;
72
+ exports.CoreRoutingService = CoreRoutingService = tslib_1.__decorate([
73
+ (0, core_1.Injectable)(),
74
+ tslib_1.__param(0, (0, core_1.Inject)('Context')),
75
+ tslib_1.__param(1, (0, core_1.Optional)()),
76
+ tslib_1.__param(2, (0, core_1.Optional)()),
77
+ tslib_1.__metadata("design:paramtypes", [Object, router_1.Router,
78
+ core_1.NgZone])
79
+ ], CoreRoutingService);
80
+ //# sourceMappingURL=CoreRoutingService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreRoutingService.js","sourceRoot":"","sources":["../src/CoreRoutingService.ts"],"names":[],"mappings":";;;;AAEA,wCAAgF;AAChF,4CAAkG;AAClG,4CAAsF;AAEtF,MAAM,IAAI,GAAG,cAAa,CAAC,CAAC;AAE5B,qGAAqG;AACrG,+EAA+E;AAC/E,gCAAwB,CAAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;AACpD,gCAAwB,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC;AACvD,gCAAwB,CAAC,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC;AAClD,gCAAwB,CAAC,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC;AAC/C,gCAAwB,CAAC,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;AAEpD,SAAS,SAAS,CAAC,GAAW;IAC5B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,MAAM,KAAK,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,EAAE;QAChC,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE;YACjB,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;SAC/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AAQ,CAAC,IAAI,EAAE,CAAC;gBACxD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;YACtD,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAC9C,CAAC,CAA6D,EAAE,EAAE;gBAChE,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,EAAE;oBAChB,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;oBACjD,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC;oBAE5B,IAAI,SAAS,KAAK,WAAW,EAAE;wBAC7B,eAAe,CAAC,SAAS,CAAC,CAAC;qBAC5B;iBACF;YACH,CAAC,CACF,CAAC;SACH;IACH,CAAC;IAED,WAAW;QACT,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACjB,IAAI,CAAC,YAAY,EAAE,WAAW,EAAE,CAAC;IACnC,CAAC;CACF,CAAA;AAlDY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,iBAAU,GAAE;IAMR,mBAAA,IAAA,aAAM,EAAC,SAAS,CAAC,CAAA;IACjB,mBAAA,IAAA,eAAQ,GAAE,CAAA;IACV,mBAAA,IAAA,eAAQ,GAAE,CAAA;qDADiB,eAAM;QACR,aAAM;GAPvB,kBAAkB,CAkD9B"}
@@ -0,0 +1,6 @@
1
+ import { ApplicationConfig, Type } from '@angular/core';
2
+ import type { BaseComponentProps, HtmlComponent } from 'piral-core';
3
+ export interface NgStandaloneConverter {
4
+ <TProps extends BaseComponentProps>(component: Type<TProps>): HtmlComponent<TProps>;
5
+ }
6
+ export declare function createConverter(options: ApplicationConfig): NgStandaloneConverter;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConverter = void 0;
4
+ const common_1 = require("@angular/common");
5
+ const platform_browser_1 = require("@angular/platform-browser");
6
+ const core_1 = require("@angular/core");
7
+ const CoreRoutingService_1 = require("./CoreRoutingService");
8
+ function createConverter(options) {
9
+ const update = (ref, props) => {
10
+ if (ref) {
11
+ const ct = ref.componentType;
12
+ if (ct?.ɵcmp?.inputs?.Props) {
13
+ ref.setInput('Props', props);
14
+ }
15
+ }
16
+ };
17
+ let app = undefined;
18
+ return (component) => ({
19
+ type: 'html',
20
+ component: {
21
+ mount(element, props, ctx, locals) {
22
+ if (!app) {
23
+ const { piral } = props;
24
+ app = (0, platform_browser_1.createApplication)({
25
+ ...options,
26
+ providers: [
27
+ ...options.providers,
28
+ CoreRoutingService_1.CoreRoutingService,
29
+ { provide: common_1.APP_BASE_HREF, useValue: ctx.publicPath },
30
+ { provide: 'Context', useValue: ctx },
31
+ { provide: 'piral', useValue: piral },
32
+ ],
33
+ });
34
+ piral.on('unload-pilet', (ev) => {
35
+ if (ev.name === piral.meta.name && typeof core_1.ɵresetCompiledComponents === 'function') {
36
+ // pretty much a cleanup step for Angular.
37
+ (0, core_1.ɵresetCompiledComponents)();
38
+ }
39
+ });
40
+ }
41
+ locals.active = true;
42
+ app.then((appRef) => {
43
+ if (locals.active) {
44
+ const ref = appRef.bootstrap(component, element);
45
+ // Start the routing service.
46
+ appRef.injector.get(CoreRoutingService_1.CoreRoutingService);
47
+ update(ref, props);
48
+ locals.component = ref;
49
+ }
50
+ });
51
+ },
52
+ update(_1, props, _2, locals) {
53
+ update(locals.component, props);
54
+ },
55
+ unmount(element, locals) {
56
+ locals.active = false;
57
+ locals.component?.destroy();
58
+ locals.component = undefined;
59
+ element.remove();
60
+ },
61
+ },
62
+ });
63
+ }
64
+ exports.createConverter = createConverter;
65
+ //# sourceMappingURL=standalone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standalone.js","sourceRoot":"","sources":["../src/standalone.ts"],"names":[],"mappings":";;;AAAA,4CAAgD;AAChD,g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BACJ;gBAED,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;gBAErB,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;oBAClB,IAAI,MAAM,CAAC,MAAM,EAAE;wBACjB,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;wBAEjD,6BAA6B;wBAC7B,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,uCAAkB,CAAC,CAAC;wBAExC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;wBACnB,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC;qBACxB;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YACD,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM;gBAC1B,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;YAClC,CAAC;YACD,OAAO,CAAC,OAAO,EAAE,MAAM;gBACrB,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC;gBACtB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;gBAC5B,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;gBAC7B,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAhED,0CAgEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-ng",
3
- "version": "1.5.5-beta.7076",
3
+ "version": "1.5.5-beta.7084",
4
4
  "description": "Plugin for integrating Angular components in Piral.",
5
5
  "keywords": [
6
6
  "piral",
@@ -36,6 +36,9 @@
36
36
  "./extend-webpack": {
37
37
  "require": "./extend-webpack.js"
38
38
  },
39
+ "./standalone": {
40
+ "import": "./esm/standalone.js"
41
+ },
39
42
  "./esm/*": {
40
43
  "import": "./esm/*"
41
44
  },
@@ -87,9 +90,9 @@
87
90
  "@angular/platform-browser": "^16.0.0",
88
91
  "@angular/platform-browser-dynamic": "^16.0.0",
89
92
  "@angular/router": "^16.0.0",
90
- "piral-core": "1.5.5-beta.7076",
93
+ "piral-core": "1.5.5-beta.7084",
91
94
  "piral-ng-common": "^16.0.0",
92
95
  "rxjs": "^7.3.0"
93
96
  },
94
- "gitHead": "a7df8af1f51c271dd51e16ae04048cae64ef001e"
97
+ "gitHead": "59ab59543def8bb327fc5b0a588bea2486f190a4"
95
98
  }
@@ -0,0 +1,85 @@
1
+ import type { Subscription } from 'rxjs';
2
+ import type { ComponentContext, Disposable } from 'piral-core';
3
+ import { Inject, Injectable, NgZone, OnDestroy, Optional } from '@angular/core';
4
+ import { NavigationEnd, NavigationError, NavigationStart, Router, Scroll } from '@angular/router';
5
+ import { BrowserPlatformLocation as ɵ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
+ }
33
+
34
+ @Injectable()
35
+ export class CoreRoutingService implements OnDestroy {
36
+ private dispose: Disposable | undefined;
37
+ private subscription: Subscription | undefined;
38
+
39
+ constructor(
40
+ @Inject('Context') public context: ComponentContext,
41
+ @Optional() private router: Router,
42
+ @Optional() private zone: NgZone,
43
+ ) {
44
+ if (this.router) {
45
+ this.router.errorHandler = (error: Error) => {
46
+ // Match in development and production
47
+ if (error.message.match('Cannot match any routes') || error.message.match('NG04002')) {
48
+ // ignore this special error
49
+ return undefined;
50
+ }
51
+ throw error;
52
+ };
53
+
54
+ const nav = this.context.navigation;
55
+
56
+ const queueNavigation = (url: string) => {
57
+ window.requestAnimationFrame(() => nav.push(url));
58
+ };
59
+
60
+ this.dispose = nav.listen(({ location }) => {
61
+ const path = location.pathname;
62
+ const url = `${path}${location.search}${location.hash}`;
63
+ this.zone.run(() => this.router.navigateByUrl(url));
64
+ });
65
+
66
+ this.subscription = this.router.events.subscribe(
67
+ (e: NavigationError | NavigationStart | NavigationEnd | Scroll) => {
68
+ if (e.type === 1) {
69
+ const routerUrl = normalize(e.urlAfterRedirects);
70
+ const locationUrl = nav.url;
71
+
72
+ if (routerUrl !== locationUrl) {
73
+ queueNavigation(routerUrl);
74
+ }
75
+ }
76
+ },
77
+ );
78
+ }
79
+ }
80
+
81
+ ngOnDestroy() {
82
+ this.dispose?.();
83
+ this.subscription?.unsubscribe();
84
+ }
85
+ }
@@ -0,0 +1,81 @@
1
+ import { APP_BASE_HREF } from '@angular/common';
2
+ import { createApplication } from '@angular/platform-browser';
3
+ import {
4
+ ApplicationConfig,
5
+ ApplicationRef,
6
+ ComponentRef,
7
+ Type,
8
+ ɵresetCompiledComponents as reset,
9
+ } from '@angular/core';
10
+ import type { BaseComponentProps, HtmlComponent } from 'piral-core';
11
+ import { CoreRoutingService } from './CoreRoutingService';
12
+
13
+ export interface NgStandaloneConverter {
14
+ <TProps extends BaseComponentProps>(component: Type<TProps>): HtmlComponent<TProps>;
15
+ }
16
+
17
+ export function createConverter(options: ApplicationConfig): NgStandaloneConverter {
18
+ const update = (ref: ComponentRef<any>, props: any) => {
19
+ if (ref) {
20
+ const ct = ref.componentType as any;
21
+
22
+ if (ct?.ɵcmp?.inputs?.Props) {
23
+ ref.setInput('Props', props);
24
+ }
25
+ }
26
+ };
27
+
28
+ let app: undefined | Promise<ApplicationRef> = undefined;
29
+
30
+ return (component) => ({
31
+ type: 'html',
32
+ component: {
33
+ mount(element, props, ctx, locals) {
34
+ if (!app) {
35
+ const { piral } = props;
36
+
37
+ app = createApplication({
38
+ ...options,
39
+ providers: [
40
+ ...options.providers,
41
+ CoreRoutingService,
42
+ { provide: APP_BASE_HREF, useValue: ctx.publicPath },
43
+ { provide: 'Context', useValue: ctx },
44
+ { provide: 'piral', useValue: piral },
45
+ ],
46
+ });
47
+
48
+ piral.on('unload-pilet', (ev) => {
49
+ if (ev.name === piral.meta.name && typeof reset === 'function') {
50
+ // pretty much a cleanup step for Angular.
51
+ reset();
52
+ }
53
+ });
54
+ }
55
+
56
+ locals.active = true;
57
+
58
+ app.then((appRef) => {
59
+ if (locals.active) {
60
+ const ref = appRef.bootstrap(component, element);
61
+
62
+ // Start the routing service.
63
+ appRef.injector.get(CoreRoutingService);
64
+
65
+ update(ref, props);
66
+ locals.component = ref;
67
+ }
68
+ });
69
+ },
70
+ update(_1, props, _2, locals) {
71
+ update(locals.component, props);
72
+ },
73
+ unmount(element, locals) {
74
+ locals.active = false;
75
+ locals.component?.destroy();
76
+ locals.component = undefined;
77
+ element.remove();
78
+ },
79
+ },
80
+ });
81
+ }