Skip to content

Commit 5f873e8

Browse files
feat: standalone component architecture (#122)
1 parent d18b459 commit 5f873e8

21 files changed

+59
-22
lines changed

packages/angular/src/lib/cdk/action-bar/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const appendActionItem = (bar: NgActionBar, item: ActionItem) => {
7878
@Component({
7979
selector: 'ActionBar',
8080
template: '<ng-content></ng-content>',
81+
standalone: true,
8182
})
8283
export class ActionBarComponent {
8384
constructor(public element: ElementRef, @Optional() private page: Page) {
@@ -96,6 +97,7 @@ export class ActionBarComponent {
9697
@Component({
9798
selector: 'ActionBarExtension',
9899
template: '',
100+
standalone: true,
99101
})
100102
// eslint-disable-next-line @angular-eslint/component-class-suffix
101103
export class ActionBarScope {
@@ -130,6 +132,7 @@ export class ActionBarScope {
130132

131133
@Directive({
132134
selector: 'ActionItem', // tslint:disable-line:directive-selector
135+
standalone: true,
133136
})
134137
export class ActionItemDirective implements OnDestroy {
135138
constructor(public element: ElementRef, @Optional() private ownerScope: ActionBarScope) {
@@ -147,6 +150,7 @@ export class ActionItemDirective implements OnDestroy {
147150

148151
@Directive({
149152
selector: 'NavigationButton', // tslint:disable-line:directive-selector
153+
standalone: true,
150154
})
151155
export class NavigationButtonDirective implements OnDestroy {
152156
constructor(public element: ElementRef, @Optional() private ownerScope: ActionBarScope) {

packages/angular/src/lib/cdk/detached-loader.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ComponentRef, ComponentFactory, ViewContainerRef, Component, Type, ComponentFactoryResolver, ChangeDetectorRef, ApplicationRef, OnDestroy, TemplateRef, ViewChild, Injector } from '@angular/core';
1+
import { ApplicationRef, ChangeDetectorRef, Component, ComponentFactory, ComponentFactoryResolver, ComponentRef, Injector, NO_ERRORS_SCHEMA, OnDestroy, TemplateRef, Type, ViewChild, ViewContainerRef } from '@angular/core';
22
import { ProxyViewContainer, Trace } from '@nativescript/core';
3-
import { ComponentPortal, TemplatePortal } from './portal';
4-
import type { ComponentType } from '../utils/general';
53
import { registerElement } from '../element-registry';
4+
import type { ComponentType } from '../utils/general';
5+
import { ComponentPortal, TemplatePortal } from './portal';
66

77
registerElement('DetachedContainer', () => ProxyViewContainer, {
88
skipAddToDom: true,
@@ -19,6 +19,8 @@ registerElement('DetachedContainer', () => ProxyViewContainer, {
1919
template: `<Placeholder #loader></Placeholder>
2020
<ng-container #vc></ng-container>
2121
<ng-content></ng-content>`,
22+
standalone: true,
23+
schemas: [NO_ERRORS_SCHEMA],
2224
})
2325
// eslint-disable-next-line @angular-eslint/component-class-suffix
2426
export class DetachedLoader implements OnDestroy {

packages/angular/src/lib/cdk/dialog/dialog-content-directives.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { NativeDialogRef } from './dialog-ref';
1818
// eslint-disable-next-line @angular-eslint/directive-selector
1919
selector: '[native-dialog-close], [nativeDialogClose]',
2020
exportAs: 'nativeDialogClose',
21+
standalone: true,
2122
})
2223
export class NativeDialogCloseDirective implements OnInit, OnChanges {
2324
/** Dialog close input. */

packages/angular/src/lib/cdk/dialog/dialog-module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NativeDialogCloseDirective } from './dialog-content-directives';
33
import { NativeDialogService } from './dialog-services';
44

55
@NgModule({
6-
declarations: [NativeDialogCloseDirective],
6+
imports: [NativeDialogCloseDirective],
77
exports: [NativeDialogCloseDirective],
88
providers: [NativeDialogService],
99
})

packages/angular/src/lib/cdk/frame-page/frame-page.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ registerElement('FramePage', () => Frame, {
2424
// eslint-disable-next-line @angular-eslint/component-selector
2525
selector: 'FramePage',
2626
template: `<ng-content></ng-content>`,
27+
standalone: true,
2728
providers: [
2829
{
2930
provide: Frame,

packages/angular/src/lib/cdk/frame-page/frame-page.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FrameDirective } from './frame.directive';
44
import { PageDirective } from './page.directive';
55

66
@NgModule({
7-
declarations: [FrameDirective, PageDirective, FramePageComponent],
7+
imports: [FrameDirective, PageDirective, FramePageComponent],
88
exports: [FrameDirective, PageDirective, FramePageComponent],
99
})
1010
export class FramePageModule {}

packages/angular/src/lib/cdk/frame-page/frame.directive.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export function customFrameDirectiveFactory(v: FrameDirective) {
88
@Directive({
99
// eslint-disable-next-line @angular-eslint/directive-selector
1010
selector: 'Frame',
11+
standalone: true,
1112
providers: [
1213
{
1314
provide: Frame,

packages/angular/src/lib/cdk/frame-page/page.directive.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export function customPageFactory(v: PageDirective) {
99
@Directive({
1010
// eslint-disable-next-line @angular-eslint/directive-selector
1111
selector: 'Page',
12+
standalone: true,
1213
providers: [
1314
{
1415
provide: Page,

packages/angular/src/lib/cdk/list-view/list-view.component.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { ItemEventData, KeyedTemplate, LayoutBase, ListView, ObservableArray, pr
33

44
import { extractSingleViewRecursive } from '../../element-registry/registry';
55
import { NativeScriptDebug } from '../../trace';
6-
import { NgViewTemplate } from '../../view-refs';
76
import { isListLikeIterable } from '../../utils/general';
7+
import { NgViewTemplate } from '../../view-refs';
8+
import { DetachedLoader } from '../detached-loader';
89

910
const NG_VIEW = '_ngViewRef';
1011

@@ -89,7 +90,9 @@ export interface SetupItemViewArgs<T> {
8990
template: `<DetachedContainer>
9091
<ng-container #loader></ng-container>
9192
</DetachedContainer>`,
93+
standalone: true,
9294
changeDetection: ChangeDetectionStrategy.OnPush,
95+
imports: [DetachedLoader],
9396
providers: [{ provide: TEMPLATED_ITEMS_COMPONENT, useExisting: forwardRef(() => ListViewComponent) }],
9497
})
9598
export class ListViewComponent<T = any> implements DoCheck, OnDestroy, AfterContentInit, TemplatedItemsHost {
@@ -293,7 +296,10 @@ export function getItemViewRoot(viewRef: EmbeddedViewRef<unknown>, rootLocator:
293296
}
294297

295298
// eslint-disable-next-line @angular-eslint/directive-selector
296-
@Directive({ selector: '[nsTemplateKey],[nsTemplateKeys]' })
299+
@Directive({
300+
selector: '[nsTemplateKey],[nsTemplateKeys]',
301+
standalone: true,
302+
})
297303
export class TemplateKeyDirective<T> {
298304
constructor(private templateRef: TemplateRef<T>, @Host() @Inject(TEMPLATED_ITEMS_COMPONENT) private comp: TemplatedItemsHost<T>) {}
299305

packages/angular/src/lib/cdk/platform-filters/android-filter.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable @angular-eslint/component-selector */
22
import { Component, Inject } from '@angular/core';
3-
import { platformNames, IDevice } from '@nativescript/core';
3+
import { IDevice, platformNames } from '@nativescript/core';
44
import { DEVICE } from '../../tokens';
55

66
@Component({
77
selector: 'android',
8-
template: `<ng-content *ngIf="show"></ng-content>`,
8+
template: `@if (show) {
9+
<ng-content></ng-content>
10+
}`,
11+
standalone: true,
912
})
1013
export class AndroidFilterComponent {
1114
public show: boolean;

packages/angular/src/lib/cdk/platform-filters/ios-filter.component.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable @angular-eslint/component-selector */
22
import { Component, Inject } from '@angular/core';
3-
import { platformNames, IDevice } from '@nativescript/core';
3+
import { IDevice, platformNames } from '@nativescript/core';
44
import { DEVICE } from '../../tokens';
55

66
@Component({
77
selector: 'ios',
8-
template: `<ng-content *ngIf="show"></ng-content>`,
8+
template: `@if (show) {
9+
<ng-content></ng-content>
10+
}`,
11+
standalone: true,
912
})
1013
export class IOSFilterComponent {
1114
public show: boolean;

packages/angular/src/lib/cdk/platform-filters/vision-filter.component.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { DEVICE } from '../../tokens';
55

66
@Component({
77
selector: 'visionos',
8-
template: `<ng-content *ngIf="show"></ng-content>`,
8+
template: `@if (show) {
9+
<ng-content></ng-content>
10+
}`,
11+
standalone: true,
912
})
1013
export class VisionOSFilterComponent {
1114
public show: boolean;

packages/angular/src/lib/cdk/portal/portal-directives.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { BasePortalOutlet, ComponentPortal, DomPortal, Portal, TemplatePortal }
1818
@Directive({
1919
selector: '[cdkPortal]',
2020
exportAs: 'cdkPortal',
21+
standalone: true,
2122
})
2223
export class CdkPortal extends TemplatePortal {
2324
constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
@@ -40,6 +41,7 @@ export type CdkPortalOutletAttachedRef = ComponentRef<any> | EmbeddedViewRef<any
4041
@Directive({
4142
selector: '[cdkPortalOutlet]',
4243
exportAs: 'cdkPortalOutlet',
44+
standalone: true,
4345
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
4446
inputs: ['portal: cdkPortalOutlet'],
4547
})
@@ -191,7 +193,7 @@ export class CdkPortalOutlet extends BasePortalOutlet implements OnInit, OnDestr
191193
}
192194

193195
@NgModule({
196+
imports: [CdkPortal, CdkPortalOutlet],
194197
exports: [CdkPortal, CdkPortalOutlet],
195-
declarations: [CdkPortal, CdkPortalOutlet],
196198
})
197199
export class PortalModule {}

packages/angular/src/lib/cdk/tab-view/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface TabViewItemDef {
1414

1515
@Directive({
1616
selector: 'TabView', // eslint-disable-line @angular-eslint/directive-selector
17+
standalone: true,
1718
})
1819
export class TabViewDirective implements AfterViewInit {
1920
public tabView: TabView;
@@ -49,6 +50,7 @@ export class TabViewDirective implements AfterViewInit {
4950

5051
@Directive({
5152
selector: '[tabItem]', // eslint-disable-line @angular-eslint/directive-selector
53+
standalone: true,
5254
})
5355
export class TabViewItemDirective implements OnInit {
5456
private item: TabViewItem;

packages/angular/src/lib/legacy/router/ns-empty-outlet.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { PageRouterOutlet } from './page-router-outlet';
66
// tslint:disable-next-line:component-selector
77
selector: 'ns-empty-outlet',
88
template: "<page-router-outlet isEmptyOutlet='true'></page-router-outlet>",
9+
standalone: true,
10+
imports: [PageRouterOutlet],
911
})
1012
export class NSEmptyOutletComponent {
1113
@ViewChild(PageRouterOutlet, { read: PageRouterOutlet, static: false }) pageRouterOutlet: PageRouterOutlet;

packages/angular/src/lib/legacy/router/ns-router-link-active.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { NSRouterLink } from './ns-router-link';
5151
@Directive({
5252
selector: '[nsRouterLinkActive]',
5353
exportAs: 'routerLinkActive',
54+
standalone: true,
5455
})
5556
export class NSRouterLinkActive implements OnChanges, OnDestroy, AfterContentInit {
5657
// tslint:disable-line:max-line-length directive-class-suffix

packages/angular/src/lib/legacy/router/ns-router-link.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export type QueryParamsHandling = 'merge' | 'preserve' | '';
3333
* instead look in the current component"s children for the route.
3434
* And if the segment begins with `../`, the router will go up one level.
3535
*/
36-
@Directive({ selector: '[nsRouterLink]' })
36+
@Directive({
37+
selector: '[nsRouterLink]',
38+
standalone: true,
39+
})
3740
export class NSRouterLink implements AfterViewInit {
3841
// tslint:disable-line:directive-class-suffix
3942
@Input() target: string;

packages/angular/src/lib/legacy/router/page-router-outlet.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ const routeToString = function (activatedRoute: ActivatedRoute | ActivatedRouteS
7777

7878
registerElement('page-router-outlet', () => Frame);
7979
// eslint-disable-next-line @angular-eslint/directive-selector
80-
@Directive({ selector: 'page-router-outlet' }) // tslint:disable-line:directive-selector
80+
@Directive({
81+
selector: 'page-router-outlet',
82+
standalone: true,
83+
}) // tslint:disable-line:directive-selector
8184
export class PageRouterOutlet implements OnDestroy, RouterOutletContract {
8285
// tslint:disable-line:directive-class-suffix
8386
private activated: ComponentRef<any> | null = null;

packages/angular/src/lib/legacy/router/router.module.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export function provideLocationStrategy(locationStrategy: NSLocationStrategy, fr
2626
return locationStrategy ? locationStrategy : new NSLocationStrategy(frameService, startPath);
2727
}
2828

29+
const ROUTER_COMPONENTS = [NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent];
30+
2931
@NgModule({
30-
declarations: [NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
31-
imports: [RouterModule, NativeScriptCommonModule],
32-
exports: [RouterModule, NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
32+
imports: [RouterModule, NativeScriptCommonModule, ...ROUTER_COMPONENTS],
33+
exports: [RouterModule, ...ROUTER_COMPONENTS],
3334
schemas: [NO_ERRORS_SCHEMA],
3435
})
3536
export class NativeScriptRouterModule {

packages/angular/src/lib/nativescript-common.module.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const CDK_COMPONENTS = [ActionBarComponent, ActionBarScope, ActionItemDirective,
1515
registerNativeScriptViewComponents();
1616

1717
@NgModule({
18-
imports: [CommonModule, FramePageModule],
19-
declarations: [...CDK_COMPONENTS],
18+
imports: [CommonModule, FramePageModule, ...CDK_COMPONENTS],
2019
exports: [CommonModule, FramePageModule, ...CDK_COMPONENTS],
2120
providers: [ModalDialogService],
2221
schemas: [NO_ERRORS_SCHEMA],

packages/angular/src/lib/nativescript.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ export const NATIVESCRIPT_MODULE_STATIC_PROVIDERS: StaticProvider[] = [
4343
export const NATIVESCRIPT_MODULE_PROVIDERS: Provider[] = [{ provide: ViewportScroller, useClass: NullViewportScroller }];
4444

4545
@NgModule({
46-
imports: [ApplicationModule, NativeScriptCommonModule],
47-
declarations: [DetachedLoader],
46+
imports: [ApplicationModule, DetachedLoader, NativeScriptCommonModule],
4847
providers: [...NATIVESCRIPT_MODULE_STATIC_PROVIDERS, ...NATIVESCRIPT_MODULE_PROVIDERS],
4948
exports: [ApplicationModule, DetachedLoader, NativeScriptCommonModule],
5049
schemas: [NO_ERRORS_SCHEMA],

0 commit comments

Comments
 (0)