@worktile/planet 14.0.0 → 14.1.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.
@@ -1,12 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { InjectionToken, Injectable, NgZone, Inject, Optional, Component, NgModule } from '@angular/core';
2
+ import { InjectionToken, Injectable, NgZone, Inject, Optional, Component, Injector, EventEmitter, Directive, Input, Output, NgModule } from '@angular/core';
3
3
  import * as i3 from '@angular/router';
4
4
  import { Router, NavigationEnd } from '@angular/router';
5
5
  import * as i1 from '@angular/common/http';
6
6
  import { HttpClientModule } from '@angular/common/http';
7
- import { map, concatAll, switchMap, take, shareReplay, filter, distinctUntilChanged, catchError, tap, share, startWith, delayWhen } from 'rxjs/operators';
7
+ import { map, concatAll, switchMap, take, shareReplay, filter, distinctUntilChanged, catchError, tap, share, startWith, delayWhen, takeUntil } from 'rxjs/operators';
8
8
  import { Observable, of, concat, forkJoin, from, Subject, timer } from 'rxjs';
9
- import { PortalInjector, DomPortalOutlet, ComponentPortal } from '@angular/cdk/portal';
10
9
  import { DOCUMENT } from '@angular/common';
11
10
 
12
11
  var SwitchModes;
@@ -1854,32 +1853,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImpor
1854
1853
  }]
1855
1854
  }] });
1856
1855
 
1857
- class NgxPlanetModule {
1858
- static forRoot(apps) {
1859
- return {
1860
- ngModule: NgxPlanetModule,
1861
- providers: [
1862
- {
1863
- provide: PLANET_APPLICATIONS,
1864
- useValue: apps
1865
- }
1866
- ]
1867
- };
1868
- }
1869
- }
1870
- NgxPlanetModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1871
- NgxPlanetModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, declarations: [EmptyComponent], imports: [HttpClientModule], exports: [HttpClientModule, EmptyComponent] });
1872
- NgxPlanetModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, imports: [HttpClientModule, HttpClientModule] });
1873
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, decorators: [{
1874
- type: NgModule,
1875
- args: [{
1876
- declarations: [EmptyComponent],
1877
- imports: [HttpClientModule],
1878
- providers: [],
1879
- exports: [HttpClientModule, EmptyComponent]
1880
- }]
1881
- }] });
1882
-
1883
1856
  class PlanetComponentRef {
1884
1857
  }
1885
1858
 
@@ -1890,7 +1863,6 @@ class PlanetComponentLoader {
1890
1863
  this.ngModuleRef = ngModuleRef;
1891
1864
  this.ngZone = ngZone;
1892
1865
  this.document = document;
1893
- this.domPortalOutletCache = new WeakMap();
1894
1866
  }
1895
1867
  get applicationLoader() {
1896
1868
  return getApplicationLoader();
@@ -1910,9 +1882,15 @@ class PlanetComponentLoader {
1910
1882
  }
1911
1883
  }
1912
1884
  createInjector(appModuleRef, componentRef) {
1913
- const injectionTokens = new WeakMap([[PlanetComponentRef, componentRef]]);
1914
- const defaultInjector = appModuleRef.injector;
1915
- return new PortalInjector(defaultInjector, injectionTokens);
1885
+ return Injector.create({
1886
+ providers: [
1887
+ {
1888
+ provide: PlanetComponentRef,
1889
+ useValue: componentRef
1890
+ }
1891
+ ],
1892
+ parent: appModuleRef.injector
1893
+ });
1916
1894
  }
1917
1895
  getContainerElement(config) {
1918
1896
  if (!config.container) {
@@ -1927,49 +1905,53 @@ class PlanetComponentLoader {
1927
1905
  }
1928
1906
  }
1929
1907
  }
1930
- createWrapperElement(config) {
1931
- const container = this.getContainerElement(config);
1932
- const element = this.document.createElement('div');
1908
+ insertComponentRootNodeToContainer(container, componentRootNode, hostClass) {
1933
1909
  const subApp = this.applicationService.getAppByName(this.ngModuleRef.instance.appName);
1934
- element.classList.add(componentWrapperClass);
1935
- element.setAttribute('planet-inline', '');
1936
- if (config.wrapperClass) {
1937
- element.classList.add(config.wrapperClass);
1910
+ componentRootNode.classList.add(componentWrapperClass);
1911
+ componentRootNode.setAttribute('planet-inline', '');
1912
+ if (hostClass) {
1913
+ componentRootNode.classList.add(hostClass);
1938
1914
  }
1939
1915
  if (subApp && subApp.stylePrefix) {
1940
- element.classList.add(subApp.stylePrefix);
1916
+ componentRootNode.classList.add(subApp.stylePrefix);
1917
+ }
1918
+ // container 是注释则在前方插入,否则在元素内部插入
1919
+ if (container.nodeType === 8) {
1920
+ container.parentElement.insertBefore(componentRootNode, container);
1921
+ }
1922
+ else {
1923
+ container.appendChild(componentRootNode);
1941
1924
  }
1942
- container.appendChild(element);
1943
- return element;
1944
1925
  }
1945
1926
  attachComponent(plantComponent, appModuleRef, config) {
1946
1927
  const plantComponentRef = new PlanetComponentRef();
1947
1928
  const componentFactoryResolver = appModuleRef.componentFactoryResolver;
1948
1929
  const appRef = this.applicationRef;
1949
1930
  const injector = this.createInjector(appModuleRef, plantComponentRef);
1950
- const wrapper = this.createWrapperElement(config);
1951
- let portalOutlet = this.domPortalOutletCache.get(wrapper);
1952
- if (portalOutlet) {
1953
- portalOutlet.detach();
1954
- }
1955
- else {
1956
- portalOutlet = new DomPortalOutlet(wrapper, componentFactoryResolver, appRef, injector);
1957
- this.domPortalOutletCache.set(wrapper, portalOutlet);
1958
- }
1959
- const componentPortal = new ComponentPortal(plantComponent.component, null);
1960
- const componentRef = portalOutlet.attachComponentPortal(componentPortal);
1931
+ const container = this.getContainerElement(config);
1932
+ const componentFactory = componentFactoryResolver.resolveComponentFactory(plantComponent.component);
1933
+ const componentRef = componentFactory.create(injector);
1934
+ appRef.attachView(componentRef.hostView);
1935
+ const componentRootNode = this.getComponentRootNode(componentRef);
1936
+ this.insertComponentRootNodeToContainer(container, componentRootNode, config.hostClass || config.wrapperClass);
1961
1937
  if (config.initialState) {
1962
1938
  Object.assign(componentRef.instance, config.initialState);
1963
1939
  }
1964
1940
  plantComponentRef.componentInstance = componentRef.instance;
1965
1941
  plantComponentRef.componentRef = componentRef;
1966
- plantComponentRef.wrapperElement = wrapper;
1942
+ plantComponentRef.hostElement = componentRootNode;
1967
1943
  plantComponentRef.dispose = () => {
1968
- this.domPortalOutletCache.delete(wrapper);
1969
- portalOutlet.dispose();
1944
+ if (appRef.viewCount > 0) {
1945
+ appRef.detachView(componentRef.hostView);
1946
+ }
1947
+ componentRootNode.remove();
1970
1948
  };
1971
1949
  return plantComponentRef;
1972
1950
  }
1951
+ /** Gets the root HTMLElement for an instantiated component. */
1952
+ getComponentRootNode(componentRef) {
1953
+ return componentRef.hostView.rootNodes[0];
1954
+ }
1973
1955
  registerComponentFactory(componentOrComponents) {
1974
1956
  const app = this.ngModuleRef.instance.appName;
1975
1957
  this.getPlantAppRef(app).subscribe(appRef => {
@@ -2027,6 +2009,94 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImpor
2027
2009
  args: [DOCUMENT]
2028
2010
  }] }]; } });
2029
2011
 
2012
+ // eslint-disable-next-line @angular-eslint/directive-class-suffix
2013
+ class PlanetComponentOutlet {
2014
+ constructor(elementRef, planetComponentLoader, ngZone) {
2015
+ this.elementRef = elementRef;
2016
+ this.planetComponentLoader = planetComponentLoader;
2017
+ this.ngZone = ngZone;
2018
+ this.planetComponentLoaded = new EventEmitter();
2019
+ this.destroyed$ = new Subject();
2020
+ }
2021
+ ngOnChanges(changes) {
2022
+ if (this.planetComponentOutlet && !changes.planetComponentOutlet.isFirstChange()) {
2023
+ this.loadComponent();
2024
+ }
2025
+ }
2026
+ ngAfterViewInit() {
2027
+ this.loadComponent();
2028
+ }
2029
+ loadComponent() {
2030
+ this.clear();
2031
+ if (this.planetComponentOutlet && this.planetComponentOutletApp) {
2032
+ this.planetComponentLoader
2033
+ .load(this.planetComponentOutletApp, this.planetComponentOutlet, {
2034
+ container: this.elementRef.nativeElement,
2035
+ initialState: this.planetComponentOutletInitialState
2036
+ })
2037
+ .pipe(takeUntil(this.destroyed$))
2038
+ .subscribe(componentRef => {
2039
+ this.componentRef = componentRef;
2040
+ this.ngZone.run(() => {
2041
+ Promise.resolve().then(() => {
2042
+ this.planetComponentLoaded.emit(this.componentRef);
2043
+ });
2044
+ });
2045
+ });
2046
+ }
2047
+ }
2048
+ ngOnDestroy() {
2049
+ this.clear();
2050
+ this.destroyed$.complete();
2051
+ }
2052
+ clear() {
2053
+ this.componentRef?.dispose();
2054
+ this.destroyed$.next();
2055
+ }
2056
+ }
2057
+ PlanetComponentOutlet.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: PlanetComponentOutlet, deps: [{ token: i0.ElementRef }, { token: PlanetComponentLoader }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
2058
+ PlanetComponentOutlet.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.1.2", type: PlanetComponentOutlet, selector: "[planetComponentOutlet]", inputs: { planetComponentOutlet: "planetComponentOutlet", planetComponentOutletApp: "planetComponentOutletApp", planetComponentOutletInitialState: "planetComponentOutletInitialState" }, outputs: { planetComponentLoaded: "planetComponentLoaded" }, usesOnChanges: true, ngImport: i0 });
2059
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: PlanetComponentOutlet, decorators: [{
2060
+ type: Directive,
2061
+ args: [{
2062
+ selector: '[planetComponentOutlet]'
2063
+ }]
2064
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: PlanetComponentLoader }, { type: i0.NgZone }]; }, propDecorators: { planetComponentOutlet: [{
2065
+ type: Input
2066
+ }], planetComponentOutletApp: [{
2067
+ type: Input
2068
+ }], planetComponentOutletInitialState: [{
2069
+ type: Input
2070
+ }], planetComponentLoaded: [{
2071
+ type: Output
2072
+ }] } });
2073
+
2074
+ class NgxPlanetModule {
2075
+ static forRoot(apps) {
2076
+ return {
2077
+ ngModule: NgxPlanetModule,
2078
+ providers: [
2079
+ {
2080
+ provide: PLANET_APPLICATIONS,
2081
+ useValue: apps
2082
+ }
2083
+ ]
2084
+ };
2085
+ }
2086
+ }
2087
+ NgxPlanetModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
2088
+ NgxPlanetModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, declarations: [EmptyComponent, PlanetComponentOutlet], imports: [HttpClientModule], exports: [HttpClientModule, EmptyComponent, PlanetComponentOutlet] });
2089
+ NgxPlanetModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, imports: [HttpClientModule, HttpClientModule] });
2090
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.2", ngImport: i0, type: NgxPlanetModule, decorators: [{
2091
+ type: NgModule,
2092
+ args: [{
2093
+ declarations: [EmptyComponent, PlanetComponentOutlet],
2094
+ imports: [HttpClientModule],
2095
+ providers: [],
2096
+ exports: [HttpClientModule, EmptyComponent, PlanetComponentOutlet]
2097
+ }]
2098
+ }] });
2099
+
2030
2100
  class PlantComponentConfig {
2031
2101
  constructor() {
2032
2102
  /** Data being injected into the child component. */
@@ -2042,5 +2112,5 @@ class PlantComponentConfig {
2042
2112
  * Generated bundle index. Do not edit.
2043
2113
  */
2044
2114
 
2045
- export { ApplicationStatus, AssetsLoader, EmptyComponent, GlobalEventDispatcher, NgxPlanetModule, PLANET_APPLICATIONS, Planet, PlanetApplicationLoader, PlanetApplicationRef, PlanetApplicationService, PlanetComponentLoader, PlanetComponentRef, PlanetPortalApplication, PlantComponentConfig, SwitchModes, defineApplication, getPlanetApplicationRef, getPortalApplicationData };
2115
+ export { ApplicationStatus, AssetsLoader, EmptyComponent, GlobalEventDispatcher, NgxPlanetModule, PLANET_APPLICATIONS, Planet, PlanetApplicationLoader, PlanetApplicationRef, PlanetApplicationService, PlanetComponentLoader, PlanetComponentOutlet, PlanetComponentRef, PlanetPortalApplication, PlantComponentConfig, SwitchModes, defineApplication, getPlanetApplicationRef, getPortalApplicationData };
2046
2116
  //# sourceMappingURL=worktile-planet.mjs.map