-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cdk)!: refactor portals abstractions (#6692)
- Loading branch information
Showing
95 changed files
with
423 additions
and
1,498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
projects/addon-mobile/components/pull-to-refresh/pull-to-refresh.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
projects/addon-mobile/components/sheet/directives/sheet-stop/sheet-stop.directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
projects/addon-mobile/directives/elastic-sticky/elastic-sticky.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
ComponentRef, | ||
Directive, | ||
EmbeddedViewRef, | ||
inject, | ||
Injectable, | ||
INJECTOR, | ||
Provider, | ||
TemplateRef, | ||
ViewChild, | ||
ViewContainerRef, | ||
} from '@angular/core'; | ||
import {TuiNoHostException} from '@taiga-ui/cdk/exceptions'; | ||
import {PolymorpheusComponent} from '@tinkoff/ng-polymorpheus'; | ||
|
||
/** | ||
* Abstract class for host element for dynamically created portals. | ||
*/ | ||
@Directive() | ||
export abstract class TuiPortalsComponent { | ||
@ViewChild('viewContainer', {read: ViewContainerRef}) | ||
private readonly vcr!: ViewContainerRef; | ||
|
||
private readonly injector = inject(INJECTOR); | ||
|
||
protected readonly nothing = inject(TuiPortalService).attach(this); | ||
|
||
addComponentChild<C>(component: PolymorpheusComponent<C>): ComponentRef<C> { | ||
const injector = component.createInjector(this.injector); | ||
const ref = this.vcr.createComponent(component.component, {injector}); | ||
|
||
ref.changeDetectorRef.detectChanges(); | ||
|
||
return ref; | ||
} | ||
|
||
addTemplateChild<C>(templateRef: TemplateRef<C>, context?: C): EmbeddedViewRef<C> { | ||
return this.vcr.createEmbeddedView(templateRef, context); | ||
} | ||
} | ||
|
||
/** | ||
* Abstract service for displaying portals | ||
*/ | ||
@Injectable() | ||
export abstract class TuiPortalService { | ||
protected host?: TuiPortalsComponent; | ||
|
||
protected get safeHost(): TuiPortalsComponent { | ||
if (!this.host) { | ||
throw new TuiNoHostException(); | ||
} | ||
|
||
return this.host; | ||
} | ||
|
||
attach(host: TuiPortalsComponent): void { | ||
this.host = host; | ||
} | ||
|
||
add<C>(component: PolymorpheusComponent<C>): ComponentRef<C> { | ||
return this.safeHost.addComponentChild(component); | ||
} | ||
|
||
remove<C>({hostView}: ComponentRef<C>): void { | ||
if (!hostView.destroyed) { | ||
hostView.destroy(); | ||
} | ||
} | ||
|
||
addTemplate<C>(templateRef: TemplateRef<C>, context?: C): EmbeddedViewRef<C> { | ||
return this.safeHost.addTemplateChild(templateRef, context); | ||
} | ||
|
||
removeTemplate<C>(viewRef: EmbeddedViewRef<C>): void { | ||
if (!viewRef.destroyed) { | ||
viewRef.destroy(); | ||
} | ||
} | ||
} | ||
|
||
export function tuiAsPortal(useExisting: typeof TuiPortalService): Provider { | ||
return { | ||
provide: TuiPortalService, | ||
useExisting, | ||
}; | ||
} |
23 changes: 0 additions & 23 deletions
23
projects/cdk/components/dropdown-host/dropdown-host.component.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
projects/cdk/components/dropdown-host/dropdown-host.module.ts
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
projects/cdk/components/dropdown-host/dropdown-host.style.less
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
projects/cdk/components/dropdown-host/dropdown-host.template.html
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
projects/cdk/components/dropdown-host/dropdown-portal.service.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.