From c65e08dcd1535638661d99f0d1cc658da0ed5953 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 15 Aug 2023 10:45:37 -0500 Subject: [PATCH] feat(angular): add standalone providers, route strategy, component binding provider (#27997) --- .../directives/navigation/router-outlet.ts | 24 +++++++++++++++++-- packages/angular/common/src/index.ts | 4 +++- .../src/utils/routing.ts} | 0 packages/angular/src/index.ts | 4 +--- packages/angular/src/ionic-module.ts | 21 ++-------------- packages/angular/standalone/src/index.ts | 19 +++++++++++++++ 6 files changed, 47 insertions(+), 25 deletions(-) rename packages/angular/{src/util/ionic-router-reuse-strategy.ts => common/src/utils/routing.ts} (100%) diff --git a/packages/angular/common/src/directives/navigation/router-outlet.ts b/packages/angular/common/src/directives/navigation/router-outlet.ts index e57a3faf85..6534bd5587 100644 --- a/packages/angular/common/src/directives/navigation/router-outlet.ts +++ b/packages/angular/common/src/directives/navigation/router-outlet.ts @@ -20,6 +20,7 @@ import { Injectable, reflectComponentType, } from '@angular/core'; +import type { Provider } from '@angular/core'; import { OutletContext, Router, ActivatedRoute, ChildrenOutletContexts, PRIMARY_OUTLET, Data } from '@angular/router'; import { componentOnReady } from '@ionic/core/components'; import type { AnimationBuilder } from '@ionic/core/components'; @@ -433,7 +434,7 @@ class OutletInjector implements Injector { } // TODO: FW-4785 - Remove this once Angular 15 support is dropped -export const INPUT_BINDER = new InjectionToken(''); +const INPUT_BINDER = new InjectionToken(''); /** * Injectable used as a tree-shakable provider for opting in to binding router data to component @@ -450,7 +451,7 @@ export const INPUT_BINDER = new InjectionToken(''); * the subscriptions are cleaned up. */ @Injectable() -export class RoutedComponentInputBinder { +class RoutedComponentInputBinder { private outletDataSubscriptions = new Map(); bindActivatedRouteToOutletComponent(outlet: IonRouterOutlet): void { @@ -507,3 +508,22 @@ export class RoutedComponentInputBinder { this.outletDataSubscriptions.set(outlet, dataSubscription); } } + +export const provideComponentInputBinding = (): Provider => { + return { + provide: INPUT_BINDER, + useFactory: componentInputBindingFactory, + deps: [Router], + }; +}; + +function componentInputBindingFactory(router?: Router) { + /** + * We cast the router to any here, since the componentInputBindingEnabled + * property is not available until Angular v16. + */ + if ((router as any)?.componentInputBindingEnabled) { + return new RoutedComponentInputBinder(); + } + return null; +} diff --git a/packages/angular/common/src/index.ts b/packages/angular/common/src/index.ts index 8cd0c975b4..a085304b89 100644 --- a/packages/angular/common/src/index.ts +++ b/packages/angular/common/src/index.ts @@ -24,7 +24,7 @@ export { NavParams } from './directives/navigation/nav-params'; export { IonPopover } from './overlays/popover'; export { IonModal } from './overlays/modal'; -export { IonRouterOutlet, INPUT_BINDER, RoutedComponentInputBinder } from './directives/navigation/router-outlet'; +export { IonRouterOutlet, provideComponentInputBinding } from './directives/navigation/router-outlet'; export type { StackEvent } from './directives/navigation/stack-utils'; export { IonBackButtonDelegate } from './directives/navigation/back-button'; @@ -36,3 +36,5 @@ export { NavDelegate } from './directives/navigation/nav-delegate'; export { IonTabs } from './directives/navigation/tabs'; export { ProxyCmp } from './utils/proxy'; + +export { IonicRouteStrategy } from './utils/routing'; diff --git a/packages/angular/src/util/ionic-router-reuse-strategy.ts b/packages/angular/common/src/utils/routing.ts similarity index 100% rename from packages/angular/src/util/ionic-router-reuse-strategy.ts rename to packages/angular/common/src/utils/routing.ts diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index ee3d20c651..b90483fa62 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -35,11 +35,9 @@ export { Platform, AngularDelegate, NavParams, + IonicRouteStrategy, } from '@ionic/angular/common'; -// ROUTER STRATEGY -export { IonicRouteStrategy } from './util/ionic-router-reuse-strategy'; - // TYPES export * from './types/ionic-lifecycle-hooks'; diff --git a/packages/angular/src/ionic-module.ts b/packages/angular/src/ionic-module.ts index d24c4b727a..251d78f591 100644 --- a/packages/angular/src/ionic-module.ts +++ b/packages/angular/src/ionic-module.ts @@ -1,13 +1,11 @@ import { CommonModule, DOCUMENT } from '@angular/common'; import { ModuleWithProviders, APP_INITIALIZER, NgModule, NgZone } from '@angular/core'; -import { Router } from '@angular/router'; import { ModalController, PopoverController, ConfigToken, AngularDelegate, - INPUT_BINDER, - RoutedComponentInputBinder, + provideComponentInputBinding, } from '@ionic/angular/common'; import { IonicConfig } from '@ionic/core'; @@ -76,23 +74,8 @@ export class IonicModule { multi: true, deps: [ConfigToken, DOCUMENT, NgZone], }, - { - provide: INPUT_BINDER, - useFactory: componentInputBindingFactory, - deps: [Router], - }, + provideComponentInputBinding(), ], }; } } - -function componentInputBindingFactory(router?: Router) { - /** - * We cast the router to any here, since the componentInputBindingEnabled - * property is not available until Angular v16. - */ - if ((router as any)?.componentInputBindingEnabled) { - return new RoutedComponentInputBinder(); - } - return null; -} diff --git a/packages/angular/standalone/src/index.ts b/packages/angular/standalone/src/index.ts index a044f6b986..a1cdeac984 100644 --- a/packages/angular/standalone/src/index.ts +++ b/packages/angular/standalone/src/index.ts @@ -4,3 +4,22 @@ export { IonPopover } from './overlays/popover'; export { IonRouterOutlet } from './navigation/router-outlet'; export { IonRouterLink, IonRouterLinkWithHref } from './navigation/router-link-delegate'; export { IonNav } from './navigation/nav-delegate'; + +export { + ActionSheetController, + AlertController, + LoadingController, + MenuController, + ModalController, + PickerController, + PopoverController, + ToastController, + AnimationController, + GestureController, + DomController, + NavController, + Config, + Platform, + NavParams, + IonicRouteStrategy, +} from '@ionic/angular/common';