@worktile/planet 17.1.0-next.0 → 17.1.0-next.1

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, NgZone, NgModuleRef, signal, Inject, Optional, Component, ChangeDetectionStrategy, Injector, createComponent, reflectComponentType, EventEmitter, Directive, Input, Output, inject, NgModule } from '@angular/core';
2
+ import { InjectionToken, Injectable, NgZone, NgModuleRef, signal, Inject, Optional, Component, ChangeDetectionStrategy, Injector, createComponent, reflectComponentType, TemplateRef, EventEmitter, Directive, Input, Output, inject, NgModule } from '@angular/core';
3
3
  import * as i3 from '@angular/router';
4
4
  import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
5
5
  import * as i1 from '@angular/common/http';
@@ -1386,6 +1386,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
1386
1386
  }], ctorParameters: () => [{ type: i1.HttpClient }, { type: AssetsLoader }] });
1387
1387
 
1388
1388
  class PlanetPortalApplication {
1389
+ constructor() {
1390
+ this.name = 'portal';
1391
+ }
1389
1392
  navigateByUrl(url, extras) {
1390
1393
  return this.ngZone.run(() => {
1391
1394
  return this.router.navigateByUrl(url, extras);
@@ -1399,6 +1402,12 @@ class PlanetPortalApplication {
1399
1402
  tick() {
1400
1403
  this.applicationRef.tick();
1401
1404
  }
1405
+ getComponentFactory() {
1406
+ return this.componentFactory;
1407
+ }
1408
+ registerComponentFactory(componentFactory) {
1409
+ this.componentFactory = componentFactory;
1410
+ }
1402
1411
  }
1403
1412
 
1404
1413
  const CUSTOM_EVENT_NAME = 'PLANET_GLOBAL_EVENT_DISPATCHER';
@@ -2152,7 +2161,14 @@ class PlanetComponentLoader {
2152
2161
  }
2153
2162
  registerComponentFactory(componentOrComponents) {
2154
2163
  const app = this.ngModuleRef.instance.appName;
2155
- this.getPlantAppRef(app).subscribe((appRef) => {
2164
+ let appRef$;
2165
+ if (app) {
2166
+ appRef$ = this.getPlantAppRef(app);
2167
+ }
2168
+ else {
2169
+ appRef$ = of(globalPlanet.portalApplication);
2170
+ }
2171
+ appRef$.subscribe(appRef => {
2156
2172
  appRef.registerComponentFactory((componentName, config) => {
2157
2173
  const components = coerceArray(componentOrComponents);
2158
2174
  const planetComponent = components.find(item => {
@@ -2162,7 +2178,7 @@ class PlanetComponentLoader {
2162
2178
  });
2163
2179
  if (planetComponent) {
2164
2180
  return this.ngZone.run(() => {
2165
- const componentRef = this.attachComponent(isComponentType(planetComponent) ? planetComponent : planetComponent.component, appRef.appModuleRef.injector, config);
2181
+ const componentRef = this.attachComponent(isComponentType(planetComponent) ? planetComponent : planetComponent.component, appRef instanceof NgPlanetApplicationRef ? appRef.appModuleRef.injector : this.ngModuleRef.injector, config);
2166
2182
  return componentRef;
2167
2183
  });
2168
2184
  }
@@ -2172,24 +2188,57 @@ class PlanetComponentLoader {
2172
2188
  });
2173
2189
  });
2174
2190
  }
2175
- register(components) {
2176
- setTimeout(() => {
2191
+ register(components, immediate) {
2192
+ if (immediate) {
2177
2193
  this.registerComponentFactory(components);
2178
- });
2194
+ }
2195
+ else {
2196
+ setTimeout(() => {
2197
+ this.registerComponentFactory(components);
2198
+ });
2199
+ }
2179
2200
  }
2180
2201
  load(app, componentName, config) {
2181
- const result = this.getPlantAppRef(app).pipe(delayWhen((appRef) => {
2182
- if (appRef.getComponentFactory()) {
2183
- return of('');
2184
- }
2185
- else {
2186
- // Because register use 'setTimeout',so timer 20
2187
- return timer(20);
2188
- }
2189
- }), map(appRef => {
2202
+ let appRef$;
2203
+ if (app === globalPlanet.portalApplication.name) {
2204
+ appRef$ = of(globalPlanet.portalApplication);
2205
+ }
2206
+ else {
2207
+ appRef$ = this.getPlantAppRef(app).pipe(delayWhen((appRef) => {
2208
+ if (appRef.getComponentFactory()) {
2209
+ return of('');
2210
+ }
2211
+ else {
2212
+ // Because register use 'setTimeout',so timer 20
2213
+ return timer(20);
2214
+ }
2215
+ }));
2216
+ }
2217
+ const result = appRef$.pipe(map(appRef => {
2190
2218
  const componentFactory = appRef.getComponentFactory();
2191
2219
  if (componentFactory) {
2192
- return componentFactory(componentName, config);
2220
+ const projectableEmbeddedViewRefs = [];
2221
+ const projectableNodes = (config.projectableNodes || []).map(node => {
2222
+ if (node instanceof TemplateRef) {
2223
+ const viewRef = node.createEmbeddedView({});
2224
+ projectableEmbeddedViewRefs.push(viewRef);
2225
+ this.applicationRef.attachView(viewRef);
2226
+ return viewRef.rootNodes;
2227
+ }
2228
+ else {
2229
+ return node;
2230
+ }
2231
+ });
2232
+ const compRef = componentFactory(componentName, { ...config, projectableNodes: projectableNodes });
2233
+ const dispose = compRef.dispose.bind(compRef);
2234
+ compRef.dispose = () => {
2235
+ projectableEmbeddedViewRefs.forEach(viewRef => {
2236
+ this.applicationRef.detachView(viewRef);
2237
+ viewRef.destroy();
2238
+ });
2239
+ dispose();
2240
+ };
2241
+ return compRef;
2193
2242
  }
2194
2243
  else {
2195
2244
  throw new Error(`${app}'s component(${componentName}) is not registered`);
@@ -2234,7 +2283,8 @@ class PlanetComponentOutlet {
2234
2283
  this.planetComponentLoader
2235
2284
  .load(this.planetComponentOutletApp, this.planetComponentOutlet, {
2236
2285
  container: this.elementRef.nativeElement,
2237
- initialState: this.planetComponentOutletInitialState
2286
+ initialState: this.planetComponentOutletInitialState,
2287
+ projectableNodes: this.planetComponentOutletProjectableNodes
2238
2288
  })
2239
2289
  .pipe(takeUntil(this.destroyed$))
2240
2290
  .subscribe(componentRef => {
@@ -2256,7 +2306,7 @@ class PlanetComponentOutlet {
2256
2306
  this.destroyed$.next();
2257
2307
  }
2258
2308
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: PlanetComponentOutlet, deps: [{ token: i0.ElementRef }, { token: PlanetComponentLoader }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive }); }
2259
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.2.3", type: PlanetComponentOutlet, isStandalone: true, selector: "[planetComponentOutlet]", inputs: { planetComponentOutlet: "planetComponentOutlet", planetComponentOutletApp: "planetComponentOutletApp", planetComponentOutletInitialState: "planetComponentOutletInitialState" }, outputs: { planetComponentLoaded: "planetComponentLoaded" }, usesOnChanges: true, ngImport: i0 }); }
2309
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.2.3", type: PlanetComponentOutlet, isStandalone: true, selector: "[planetComponentOutlet]", inputs: { planetComponentOutlet: "planetComponentOutlet", planetComponentOutletApp: "planetComponentOutletApp", planetComponentOutletProjectableNodes: "planetComponentOutletProjectableNodes", planetComponentOutletInitialState: "planetComponentOutletInitialState" }, outputs: { planetComponentLoaded: "planetComponentLoaded" }, usesOnChanges: true, ngImport: i0 }); }
2260
2310
  }
2261
2311
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImport: i0, type: PlanetComponentOutlet, decorators: [{
2262
2312
  type: Directive,
@@ -2268,6 +2318,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.3", ngImpor
2268
2318
  type: Input
2269
2319
  }], planetComponentOutletApp: [{
2270
2320
  type: Input
2321
+ }], planetComponentOutletProjectableNodes: [{
2322
+ type: Input
2271
2323
  }], planetComponentOutletInitialState: [{
2272
2324
  type: Input
2273
2325
  }], planetComponentLoaded: [{