ionic-angular-common.mjs 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664
  1. import * as i0 from '@angular/core';
  2. import { Injectable, Inject, Optional, InjectionToken, inject, NgZone, ApplicationRef, Injector, createComponent, TemplateRef, Directive, ContentChild, EventEmitter, ViewContainerRef, EnvironmentInjector, Attribute, SkipSelf, Input, Output, reflectComponentType, HostListener, ElementRef, ViewChild } from '@angular/core';
  3. import * as i3 from '@angular/router';
  4. import { NavigationStart, PRIMARY_OUTLET, ChildrenOutletContexts, ActivatedRoute, Router } from '@angular/router';
  5. import * as i1 from '@angular/common';
  6. import { DOCUMENT } from '@angular/common';
  7. import { isPlatform, getPlatforms, LIFECYCLE_WILL_ENTER, LIFECYCLE_DID_ENTER, LIFECYCLE_WILL_LEAVE, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_UNLOAD, componentOnReady } from '@ionic/core/components';
  8. import { Subject, fromEvent, BehaviorSubject, combineLatest, of } from 'rxjs';
  9. import { __decorate } from 'tslib';
  10. import { filter, switchMap, distinctUntilChanged } from 'rxjs/operators';
  11. import { NgControl } from '@angular/forms';
  12. class MenuController {
  13. menuController;
  14. constructor(menuController) {
  15. this.menuController = menuController;
  16. }
  17. /**
  18. * Programmatically open the Menu.
  19. * @param [menuId] Optionally get the menu by its id, or side.
  20. * @return returns a promise when the menu is fully opened
  21. */
  22. open(menuId) {
  23. return this.menuController.open(menuId);
  24. }
  25. /**
  26. * Programmatically close the Menu. If no `menuId` is given as the first
  27. * argument then it'll close any menu which is open. If a `menuId`
  28. * is given then it'll close that exact menu.
  29. * @param [menuId] Optionally get the menu by its id, or side.
  30. * @return returns a promise when the menu is fully closed
  31. */
  32. close(menuId) {
  33. return this.menuController.close(menuId);
  34. }
  35. /**
  36. * Toggle the menu. If it's closed, it will open, and if opened, it
  37. * will close.
  38. * @param [menuId] Optionally get the menu by its id, or side.
  39. * @return returns a promise when the menu has been toggled
  40. */
  41. toggle(menuId) {
  42. return this.menuController.toggle(menuId);
  43. }
  44. /**
  45. * Used to enable or disable a menu. For example, there could be multiple
  46. * left menus, but only one of them should be able to be opened at the same
  47. * time. If there are multiple menus on the same side, then enabling one menu
  48. * will also automatically disable all the others that are on the same side.
  49. * @param [menuId] Optionally get the menu by its id, or side.
  50. * @return Returns the instance of the menu, which is useful for chaining.
  51. */
  52. enable(shouldEnable, menuId) {
  53. return this.menuController.enable(shouldEnable, menuId);
  54. }
  55. /**
  56. * Used to enable or disable the ability to swipe open the menu.
  57. * @param shouldEnable True if it should be swipe-able, false if not.
  58. * @param [menuId] Optionally get the menu by its id, or side.
  59. * @return Returns the instance of the menu, which is useful for chaining.
  60. */
  61. swipeGesture(shouldEnable, menuId) {
  62. return this.menuController.swipeGesture(shouldEnable, menuId);
  63. }
  64. /**
  65. * @param [menuId] Optionally get the menu by its id, or side.
  66. * @return Returns true if the specified menu is currently open, otherwise false.
  67. * If the menuId is not specified, it returns true if ANY menu is currenly open.
  68. */
  69. isOpen(menuId) {
  70. return this.menuController.isOpen(menuId);
  71. }
  72. /**
  73. * @param [menuId] Optionally get the menu by its id, or side.
  74. * @return Returns true if the menu is currently enabled, otherwise false.
  75. */
  76. isEnabled(menuId) {
  77. return this.menuController.isEnabled(menuId);
  78. }
  79. /**
  80. * Used to get a menu instance. If a `menuId` is not provided then it'll
  81. * return the first menu found. If a `menuId` is `left` or `right`, then
  82. * it'll return the enabled menu on that side. Otherwise, if a `menuId` is
  83. * provided, then it'll try to find the menu using the menu's `id`
  84. * property. If a menu is not found then it'll return `null`.
  85. * @param [menuId] Optionally get the menu by its id, or side.
  86. * @return Returns the instance of the menu if found, otherwise `null`.
  87. */
  88. get(menuId) {
  89. return this.menuController.get(menuId);
  90. }
  91. /**
  92. * @return Returns the instance of the menu already opened, otherwise `null`.
  93. */
  94. getOpen() {
  95. return this.menuController.getOpen();
  96. }
  97. /**
  98. * @return Returns an array of all menu instances.
  99. */
  100. getMenus() {
  101. return this.menuController.getMenus();
  102. }
  103. registerAnimation(name, animation) {
  104. return this.menuController.registerAnimation(name, animation);
  105. }
  106. isAnimating() {
  107. return this.menuController.isAnimating();
  108. }
  109. _getOpenSync() {
  110. return this.menuController._getOpenSync();
  111. }
  112. _createAnimation(type, menuCmp) {
  113. return this.menuController._createAnimation(type, menuCmp);
  114. }
  115. _register(menu) {
  116. return this.menuController._register(menu);
  117. }
  118. _unregister(menu) {
  119. return this.menuController._unregister(menu);
  120. }
  121. _setOpen(menu, shouldOpen, animated) {
  122. return this.menuController._setOpen(menu, shouldOpen, animated);
  123. }
  124. }
  125. class DomController {
  126. /**
  127. * Schedules a task to run during the READ phase of the next frame.
  128. * This task should only read the DOM, but never modify it.
  129. */
  130. read(cb) {
  131. getQueue().read(cb);
  132. }
  133. /**
  134. * Schedules a task to run during the WRITE phase of the next frame.
  135. * This task should write the DOM, but never READ it.
  136. */
  137. write(cb) {
  138. getQueue().write(cb);
  139. }
  140. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DomController, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  141. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DomController, providedIn: 'root' });
  142. }
  143. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: DomController, decorators: [{
  144. type: Injectable,
  145. args: [{
  146. providedIn: 'root',
  147. }]
  148. }] });
  149. const getQueue = () => {
  150. const win = typeof window !== 'undefined' ? window : null;
  151. if (win != null) {
  152. const Ionic = win.Ionic;
  153. if (Ionic?.queue) {
  154. return Ionic.queue;
  155. }
  156. return {
  157. read: (cb) => win.requestAnimationFrame(cb),
  158. write: (cb) => win.requestAnimationFrame(cb),
  159. };
  160. }
  161. return {
  162. read: (cb) => cb(),
  163. write: (cb) => cb(),
  164. };
  165. };
  166. class Platform {
  167. doc;
  168. _readyPromise;
  169. win;
  170. /**
  171. * @hidden
  172. */
  173. backButton = new Subject();
  174. /**
  175. * The keyboardDidShow event emits when the
  176. * on-screen keyboard is presented.
  177. */
  178. keyboardDidShow = new Subject();
  179. /**
  180. * The keyboardDidHide event emits when the
  181. * on-screen keyboard is hidden.
  182. */
  183. keyboardDidHide = new Subject();
  184. /**
  185. * The pause event emits when the native platform puts the application
  186. * into the background, typically when the user switches to a different
  187. * application. This event would emit when a Cordova app is put into
  188. * the background, however, it would not fire on a standard web browser.
  189. */
  190. pause = new Subject();
  191. /**
  192. * The resume event emits when the native platform pulls the application
  193. * out from the background. This event would emit when a Cordova app comes
  194. * out from the background, however, it would not fire on a standard web browser.
  195. */
  196. resume = new Subject();
  197. /**
  198. * The resize event emits when the browser window has changed dimensions. This
  199. * could be from a browser window being physically resized, or from a device
  200. * changing orientation.
  201. */
  202. resize = new Subject();
  203. constructor(doc, zone) {
  204. this.doc = doc;
  205. zone.run(() => {
  206. this.win = doc.defaultView;
  207. this.backButton.subscribeWithPriority = function (priority, callback) {
  208. return this.subscribe((ev) => {
  209. return ev.register(priority, (processNextHandler) => zone.run(() => callback(processNextHandler)));
  210. });
  211. };
  212. proxyEvent(this.pause, doc, 'pause', zone);
  213. proxyEvent(this.resume, doc, 'resume', zone);
  214. proxyEvent(this.backButton, doc, 'ionBackButton', zone);
  215. proxyEvent(this.resize, this.win, 'resize', zone);
  216. proxyEvent(this.keyboardDidShow, this.win, 'ionKeyboardDidShow', zone);
  217. proxyEvent(this.keyboardDidHide, this.win, 'ionKeyboardDidHide', zone);
  218. let readyResolve;
  219. this._readyPromise = new Promise((res) => {
  220. readyResolve = res;
  221. });
  222. if (this.win?.['cordova']) {
  223. doc.addEventListener('deviceready', () => {
  224. readyResolve('cordova');
  225. }, { once: true });
  226. }
  227. else {
  228. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  229. readyResolve('dom');
  230. }
  231. });
  232. }
  233. /**
  234. * @returns returns true/false based on platform.
  235. * @description
  236. * Depending on the platform the user is on, `is(platformName)` will
  237. * return `true` or `false`. Note that the same app can return `true`
  238. * for more than one platform name. For example, an app running from
  239. * an iPad would return `true` for the platform names: `mobile`,
  240. * `ios`, `ipad`, and `tablet`. Additionally, if the app was running
  241. * from Cordova then `cordova` would be true, and if it was running
  242. * from a web browser on the iPad then `mobileweb` would be `true`.
  243. *
  244. * ```
  245. * import { Platform } from 'ionic-angular';
  246. *
  247. * @Component({...})
  248. * export MyPage {
  249. * constructor(public platform: Platform) {
  250. * if (this.platform.is('ios')) {
  251. * // This will only print when on iOS
  252. * console.log('I am an iOS device!');
  253. * }
  254. * }
  255. * }
  256. * ```
  257. *
  258. * | Platform Name | Description |
  259. * |-----------------|------------------------------------|
  260. * | android | on a device running Android. |
  261. * | capacitor | on a device running Capacitor. |
  262. * | cordova | on a device running Cordova. |
  263. * | ios | on a device running iOS. |
  264. * | ipad | on an iPad device. |
  265. * | iphone | on an iPhone device. |
  266. * | phablet | on a phablet device. |
  267. * | tablet | on a tablet device. |
  268. * | electron | in Electron on a desktop device. |
  269. * | pwa | as a PWA app. |
  270. * | mobile | on a mobile device. |
  271. * | mobileweb | on a mobile device in a browser. |
  272. * | desktop | on a desktop device. |
  273. * | hybrid | is a cordova or capacitor app. |
  274. *
  275. */
  276. is(platformName) {
  277. return isPlatform(this.win, platformName);
  278. }
  279. /**
  280. * @returns the array of platforms
  281. * @description
  282. * Depending on what device you are on, `platforms` can return multiple values.
  283. * Each possible value is a hierarchy of platforms. For example, on an iPhone,
  284. * it would return `mobile`, `ios`, and `iphone`.
  285. *
  286. * ```
  287. * import { Platform } from 'ionic-angular';
  288. *
  289. * @Component({...})
  290. * export MyPage {
  291. * constructor(public platform: Platform) {
  292. * // This will print an array of the current platforms
  293. * console.log(this.platform.platforms());
  294. * }
  295. * }
  296. * ```
  297. */
  298. platforms() {
  299. return getPlatforms(this.win);
  300. }
  301. /**
  302. * Returns a promise when the platform is ready and native functionality
  303. * can be called. If the app is running from within a web browser, then
  304. * the promise will resolve when the DOM is ready. When the app is running
  305. * from an application engine such as Cordova, then the promise will
  306. * resolve when Cordova triggers the `deviceready` event.
  307. *
  308. * The resolved value is the `readySource`, which states which platform
  309. * ready was used. For example, when Cordova is ready, the resolved ready
  310. * source is `cordova`. The default ready source value will be `dom`. The
  311. * `readySource` is useful if different logic should run depending on the
  312. * platform the app is running from. For example, only Cordova can execute
  313. * the status bar plugin, so the web should not run status bar plugin logic.
  314. *
  315. * ```
  316. * import { Component } from '@angular/core';
  317. * import { Platform } from 'ionic-angular';
  318. *
  319. * @Component({...})
  320. * export MyApp {
  321. * constructor(public platform: Platform) {
  322. * this.platform.ready().then((readySource) => {
  323. * console.log('Platform ready from', readySource);
  324. * // Platform now ready, execute any required native code
  325. * });
  326. * }
  327. * }
  328. * ```
  329. */
  330. ready() {
  331. return this._readyPromise;
  332. }
  333. /**
  334. * Returns if this app is using right-to-left language direction or not.
  335. * We recommend the app's `index.html` file already has the correct `dir`
  336. * attribute value set, such as `<html dir="ltr">` or `<html dir="rtl">`.
  337. * [W3C: Structural markup and right-to-left text in HTML](http://www.w3.org/International/questions/qa-html-dir)
  338. */
  339. get isRTL() {
  340. return this.doc.dir === 'rtl';
  341. }
  342. /**
  343. * Get the query string parameter
  344. */
  345. getQueryParam(key) {
  346. return readQueryParam(this.win.location.href, key);
  347. }
  348. /**
  349. * Returns `true` if the app is in landscape mode.
  350. */
  351. isLandscape() {
  352. return !this.isPortrait();
  353. }
  354. /**
  355. * Returns `true` if the app is in portrait mode.
  356. */
  357. isPortrait() {
  358. return this.win.matchMedia?.('(orientation: portrait)').matches;
  359. }
  360. testUserAgent(expression) {
  361. const nav = this.win.navigator;
  362. return !!(nav?.userAgent && nav.userAgent.indexOf(expression) >= 0);
  363. }
  364. /**
  365. * Get the current url.
  366. */
  367. url() {
  368. return this.win.location.href;
  369. }
  370. /**
  371. * Gets the width of the platform's viewport using `window.innerWidth`.
  372. */
  373. width() {
  374. return this.win.innerWidth;
  375. }
  376. /**
  377. * Gets the height of the platform's viewport using `window.innerHeight`.
  378. */
  379. height() {
  380. return this.win.innerHeight;
  381. }
  382. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Platform, deps: [{ token: DOCUMENT }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
  383. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Platform, providedIn: 'root' });
  384. }
  385. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Platform, decorators: [{
  386. type: Injectable,
  387. args: [{
  388. providedIn: 'root',
  389. }]
  390. }], ctorParameters: function () { return [{ type: undefined, decorators: [{
  391. type: Inject,
  392. args: [DOCUMENT]
  393. }] }, { type: i0.NgZone }]; } });
  394. const readQueryParam = (url, key) => {
  395. key = key.replace(/[[\]\\]/g, '\\$&');
  396. const regex = new RegExp('[\\?&]' + key + '=([^&#]*)');
  397. const results = regex.exec(url);
  398. return results ? decodeURIComponent(results[1].replace(/\+/g, ' ')) : null;
  399. };
  400. const proxyEvent = (emitter, el, eventName, zone) => {
  401. if (el) {
  402. el.addEventListener(eventName, (ev) => {
  403. /**
  404. * `zone.run` is required to make sure that we are running inside the Angular zone
  405. * at all times. This is necessary since an app that has Capacitor will
  406. * override the `document.addEventListener` with its own implementation.
  407. * The override causes the event to no longer be in the Angular zone.
  408. */
  409. zone.run(() => {
  410. // ?? cordova might emit "null" events
  411. const value = ev != null ? ev.detail : undefined;
  412. emitter.next(value);
  413. });
  414. });
  415. }
  416. };
  417. class NavController {
  418. location;
  419. serializer;
  420. router;
  421. topOutlet;
  422. direction = DEFAULT_DIRECTION;
  423. animated = DEFAULT_ANIMATED;
  424. animationBuilder;
  425. guessDirection = 'forward';
  426. guessAnimation;
  427. lastNavId = -1;
  428. constructor(platform, location, serializer, router) {
  429. this.location = location;
  430. this.serializer = serializer;
  431. this.router = router;
  432. // Subscribe to router events to detect direction
  433. if (router) {
  434. router.events.subscribe((ev) => {
  435. if (ev instanceof NavigationStart) {
  436. // restoredState is set if the browser back/forward button is used
  437. const id = ev.restoredState ? ev.restoredState.navigationId : ev.id;
  438. this.guessDirection = this.guessAnimation = id < this.lastNavId ? 'back' : 'forward';
  439. this.lastNavId = this.guessDirection === 'forward' ? ev.id : id;
  440. }
  441. });
  442. }
  443. // Subscribe to backButton events
  444. platform.backButton.subscribeWithPriority(0, (processNextHandler) => {
  445. this.pop();
  446. processNextHandler();
  447. });
  448. }
  449. /**
  450. * This method uses Angular's [Router](https://angular.io/api/router/Router) under the hood,
  451. * it's equivalent to calling `this.router.navigateByUrl()`, but it's explicit about the **direction** of the transition.
  452. *
  453. * Going **forward** means that a new page is going to be pushed to the stack of the outlet (ion-router-outlet),
  454. * and that it will show a "forward" animation by default.
  455. *
  456. * Navigating forward can also be triggered in a declarative manner by using the `[routerDirection]` directive:
  457. *
  458. * ```html
  459. * <a routerLink="/path/to/page" routerDirection="forward">Link</a>
  460. * ```
  461. */
  462. navigateForward(url, options = {}) {
  463. this.setDirection('forward', options.animated, options.animationDirection, options.animation);
  464. return this.navigate(url, options);
  465. }
  466. /**
  467. * This method uses Angular's [Router](https://angular.io/api/router/Router) under the hood,
  468. * it's equivalent to calling:
  469. *
  470. * ```ts
  471. * this.navController.setDirection('back');
  472. * this.router.navigateByUrl(path);
  473. * ```
  474. *
  475. * Going **back** means that all the pages in the stack until the navigated page is found will be popped,
  476. * and that it will show a "back" animation by default.
  477. *
  478. * Navigating back can also be triggered in a declarative manner by using the `[routerDirection]` directive:
  479. *
  480. * ```html
  481. * <a routerLink="/path/to/page" routerDirection="back">Link</a>
  482. * ```
  483. */
  484. navigateBack(url, options = {}) {
  485. this.setDirection('back', options.animated, options.animationDirection, options.animation);
  486. return this.navigate(url, options);
  487. }
  488. /**
  489. * This method uses Angular's [Router](https://angular.io/api/router/Router) under the hood,
  490. * it's equivalent to calling:
  491. *
  492. * ```ts
  493. * this.navController.setDirection('root');
  494. * this.router.navigateByUrl(path);
  495. * ```
  496. *
  497. * Going **root** means that all existing pages in the stack will be removed,
  498. * and the navigated page will become the single page in the stack.
  499. *
  500. * Navigating root can also be triggered in a declarative manner by using the `[routerDirection]` directive:
  501. *
  502. * ```html
  503. * <a routerLink="/path/to/page" routerDirection="root">Link</a>
  504. * ```
  505. */
  506. navigateRoot(url, options = {}) {
  507. this.setDirection('root', options.animated, options.animationDirection, options.animation);
  508. return this.navigate(url, options);
  509. }
  510. /**
  511. * Same as [Location](https://angular.io/api/common/Location)'s back() method.
  512. * It will use the standard `window.history.back()` under the hood, but featuring a `back` animation
  513. * by default.
  514. */
  515. back(options = { animated: true, animationDirection: 'back' }) {
  516. this.setDirection('back', options.animated, options.animationDirection, options.animation);
  517. return this.location.back();
  518. }
  519. /**
  520. * This methods goes back in the context of Ionic's stack navigation.
  521. *
  522. * It recursively finds the top active `ion-router-outlet` and calls `pop()`.
  523. * This is the recommended way to go back when you are using `ion-router-outlet`.
  524. *
  525. * Resolves to `true` if it was able to pop.
  526. */
  527. async pop() {
  528. let outlet = this.topOutlet;
  529. while (outlet) {
  530. if (await outlet.pop()) {
  531. return true;
  532. }
  533. else {
  534. outlet = outlet.parentOutlet;
  535. }
  536. }
  537. return false;
  538. }
  539. /**
  540. * This methods specifies the direction of the next navigation performed by the Angular router.
  541. *
  542. * `setDirection()` does not trigger any transition, it just sets some flags to be consumed by `ion-router-outlet`.
  543. *
  544. * It's recommended to use `navigateForward()`, `navigateBack()` and `navigateRoot()` instead of `setDirection()`.
  545. */
  546. setDirection(direction, animated, animationDirection, animationBuilder) {
  547. this.direction = direction;
  548. this.animated = getAnimation(direction, animated, animationDirection);
  549. this.animationBuilder = animationBuilder;
  550. }
  551. /**
  552. * @internal
  553. */
  554. setTopOutlet(outlet) {
  555. this.topOutlet = outlet;
  556. }
  557. /**
  558. * @internal
  559. */
  560. consumeTransition() {
  561. let direction = 'root';
  562. let animation;
  563. const animationBuilder = this.animationBuilder;
  564. if (this.direction === 'auto') {
  565. direction = this.guessDirection;
  566. animation = this.guessAnimation;
  567. }
  568. else {
  569. animation = this.animated;
  570. direction = this.direction;
  571. }
  572. this.direction = DEFAULT_DIRECTION;
  573. this.animated = DEFAULT_ANIMATED;
  574. this.animationBuilder = undefined;
  575. return {
  576. direction,
  577. animation,
  578. animationBuilder,
  579. };
  580. }
  581. navigate(url, options) {
  582. if (Array.isArray(url)) {
  583. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  584. return this.router.navigate(url, options);
  585. }
  586. else {
  587. /**
  588. * navigateByUrl ignores any properties that
  589. * would change the url, so things like queryParams
  590. * would be ignored unless we create a url tree
  591. * More Info: https://github.com/angular/angular/issues/18798
  592. */
  593. const urlTree = this.serializer.parse(url.toString());
  594. if (options.queryParams !== undefined) {
  595. urlTree.queryParams = { ...options.queryParams };
  596. }
  597. if (options.fragment !== undefined) {
  598. urlTree.fragment = options.fragment;
  599. }
  600. /**
  601. * `navigateByUrl` will still apply `NavigationExtras` properties
  602. * that do not modify the url, such as `replaceUrl` which is why
  603. * `options` is passed in here.
  604. */
  605. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  606. return this.router.navigateByUrl(urlTree, options);
  607. }
  608. }
  609. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavController, deps: [{ token: Platform }, { token: i1.Location }, { token: i3.UrlSerializer }, { token: i3.Router, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
  610. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavController, providedIn: 'root' });
  611. }
  612. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NavController, decorators: [{
  613. type: Injectable,
  614. args: [{
  615. providedIn: 'root',
  616. }]
  617. }], ctorParameters: function () { return [{ type: Platform }, { type: i1.Location }, { type: i3.UrlSerializer }, { type: i3.Router, decorators: [{
  618. type: Optional
  619. }] }]; } });
  620. const getAnimation = (direction, animated, animationDirection) => {
  621. if (animated === false) {
  622. return undefined;
  623. }
  624. if (animationDirection !== undefined) {
  625. return animationDirection;
  626. }
  627. if (direction === 'forward' || direction === 'back') {
  628. return direction;
  629. }
  630. else if (direction === 'root' && animated === true) {
  631. return 'forward';
  632. }
  633. return undefined;
  634. };
  635. const DEFAULT_DIRECTION = 'auto';
  636. const DEFAULT_ANIMATED = undefined;
  637. class Config {
  638. get(key, fallback) {
  639. const c = getConfig();
  640. if (c) {
  641. return c.get(key, fallback);
  642. }
  643. return null;
  644. }
  645. getBoolean(key, fallback) {
  646. const c = getConfig();
  647. if (c) {
  648. return c.getBoolean(key, fallback);
  649. }
  650. return false;
  651. }
  652. getNumber(key, fallback) {
  653. const c = getConfig();
  654. if (c) {
  655. return c.getNumber(key, fallback);
  656. }
  657. return 0;
  658. }
  659. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Config, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  660. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Config, providedIn: 'root' });
  661. }
  662. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: Config, decorators: [{
  663. type: Injectable,
  664. args: [{
  665. providedIn: 'root',
  666. }]
  667. }] });
  668. const ConfigToken = new InjectionToken('USERCONFIG');
  669. const getConfig = () => {
  670. if (typeof window !== 'undefined') {
  671. const Ionic = window.Ionic;
  672. if (Ionic?.config) {
  673. return Ionic.config;
  674. }
  675. }
  676. return null;
  677. };
  678. /**
  679. * @description
  680. * NavParams are an object that exists on a page and can contain data for that particular view.
  681. * Similar to how data was pass to a view in V1 with `$stateParams`, NavParams offer a much more flexible
  682. * option with a simple `get` method.
  683. *
  684. * @usage
  685. * ```ts
  686. * import { NavParams } from '@ionic/angular';
  687. *
  688. * export class MyClass{
  689. *
  690. * constructor(navParams: NavParams){
  691. * // userParams is an object we have in our nav-parameters
  692. * navParams.get('userParams');
  693. * }
  694. *
  695. * }
  696. * ```
  697. */
  698. class NavParams {
  699. data;
  700. constructor(data = {}) {
  701. this.data = data;
  702. console.warn(`[Ionic Warning]: NavParams has been deprecated in favor of using Angular's input API. Developers should migrate to either the @Input decorator or the Signals-based input API.`);
  703. }
  704. /**
  705. * Get the value of a nav-parameter for the current view
  706. *
  707. * ```ts
  708. * import { NavParams } from 'ionic-angular';
  709. *
  710. * export class MyClass{
  711. * constructor(public navParams: NavParams){
  712. * // userParams is an object we have in our nav-parameters
  713. * this.navParams.get('userParams');
  714. * }
  715. * }
  716. * ```
  717. *
  718. * @param param Which param you want to look up
  719. */
  720. get(param) {
  721. return this.data[param];
  722. }
  723. }
  724. // TODO(FW-2827): types
  725. class AngularDelegate {
  726. zone = inject(NgZone);
  727. applicationRef = inject(ApplicationRef);
  728. config = inject(ConfigToken);
  729. create(environmentInjector, injector, elementReferenceKey) {
  730. return new AngularFrameworkDelegate(environmentInjector, injector, this.applicationRef, this.zone, elementReferenceKey, this.config.useSetInputAPI ?? false);
  731. }
  732. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AngularDelegate, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  733. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AngularDelegate });
  734. }
  735. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AngularDelegate, decorators: [{
  736. type: Injectable
  737. }] });
  738. class AngularFrameworkDelegate {
  739. environmentInjector;
  740. injector;
  741. applicationRef;
  742. zone;
  743. elementReferenceKey;
  744. enableSignalsSupport;
  745. elRefMap = new WeakMap();
  746. elEventsMap = new WeakMap();
  747. constructor(environmentInjector, injector, applicationRef, zone, elementReferenceKey, enableSignalsSupport) {
  748. this.environmentInjector = environmentInjector;
  749. this.injector = injector;
  750. this.applicationRef = applicationRef;
  751. this.zone = zone;
  752. this.elementReferenceKey = elementReferenceKey;
  753. this.enableSignalsSupport = enableSignalsSupport;
  754. }
  755. attachViewToDom(container, component, params, cssClasses) {
  756. return this.zone.run(() => {
  757. return new Promise((resolve) => {
  758. const componentProps = {
  759. ...params,
  760. };
  761. /**
  762. * Ionic Angular passes a reference to a modal
  763. * or popover that can be accessed using a
  764. * variable in the overlay component. If
  765. * elementReferenceKey is defined, then we should
  766. * pass a reference to the component using
  767. * elementReferenceKey as the key.
  768. */
  769. if (this.elementReferenceKey !== undefined) {
  770. componentProps[this.elementReferenceKey] = container;
  771. }
  772. const el = attachView(this.zone, this.environmentInjector, this.injector, this.applicationRef, this.elRefMap, this.elEventsMap, container, component, componentProps, cssClasses, this.elementReferenceKey, this.enableSignalsSupport);
  773. resolve(el);
  774. });
  775. });
  776. }
  777. removeViewFromDom(_container, component) {
  778. return this.zone.run(() => {
  779. return new Promise((resolve) => {
  780. const componentRef = this.elRefMap.get(component);
  781. if (componentRef) {
  782. componentRef.destroy();
  783. this.elRefMap.delete(component);
  784. const unbindEvents = this.elEventsMap.get(component);
  785. if (unbindEvents) {
  786. unbindEvents();
  787. this.elEventsMap.delete(component);
  788. }
  789. }
  790. resolve();
  791. });
  792. });
  793. }
  794. }
  795. const attachView = (zone, environmentInjector, injector, applicationRef, elRefMap, elEventsMap, container, component, params, cssClasses, elementReferenceKey, enableSignalsSupport) => {
  796. /**
  797. * Wraps the injector with a custom injector that
  798. * provides NavParams to the component.
  799. *
  800. * NavParams is a legacy feature from Ionic v3 that allows
  801. * Angular developers to provide data to a component
  802. * and access it by providing NavParams as a dependency
  803. * in the constructor.
  804. *
  805. * The modern approach is to access the data directly
  806. * from the component's class instance.
  807. */
  808. const childInjector = Injector.create({
  809. providers: getProviders(params),
  810. parent: injector,
  811. });
  812. const componentRef = createComponent(component, {
  813. environmentInjector,
  814. elementInjector: childInjector,
  815. });
  816. const instance = componentRef.instance;
  817. const hostElement = componentRef.location.nativeElement;
  818. if (params) {
  819. /**
  820. * For modals and popovers, a reference to the component is
  821. * added to `params` during the call to attachViewToDom. If
  822. * a reference using this name is already set, this means
  823. * the app is trying to use the name as a component prop,
  824. * which will cause collisions.
  825. */
  826. if (elementReferenceKey && instance[elementReferenceKey] !== undefined) {
  827. console.error(`[Ionic Error]: ${elementReferenceKey} is a reserved property when using ${container.tagName.toLowerCase()}. Rename or remove the "${elementReferenceKey}" property from ${component.name}.`);
  828. }
  829. /**
  830. * Angular 14.1 added support for setInput
  831. * so we need to fall back to Object.assign
  832. * for Angular 14.0.
  833. */
  834. if (enableSignalsSupport === true && componentRef.setInput !== undefined) {
  835. const { modal, popover, ...otherParams } = params;
  836. /**
  837. * Any key/value pairs set in componentProps
  838. * must be set as inputs on the component instance.
  839. */
  840. for (const key in otherParams) {
  841. componentRef.setInput(key, otherParams[key]);
  842. }
  843. /**
  844. * Using setInput will cause an error when
  845. * setting modal/popover on a component that
  846. * does not define them as an input. For backwards
  847. * compatibility purposes we fall back to using
  848. * Object.assign for these properties.
  849. */
  850. if (modal !== undefined) {
  851. Object.assign(instance, { modal });
  852. }
  853. if (popover !== undefined) {
  854. Object.assign(instance, { popover });
  855. }
  856. }
  857. else {
  858. Object.assign(instance, params);
  859. }
  860. }
  861. if (cssClasses) {
  862. for (const cssClass of cssClasses) {
  863. hostElement.classList.add(cssClass);
  864. }
  865. }
  866. const unbindEvents = bindLifecycleEvents(zone, instance, hostElement);
  867. container.appendChild(hostElement);
  868. applicationRef.attachView(componentRef.hostView);
  869. elRefMap.set(hostElement, componentRef);
  870. elEventsMap.set(hostElement, unbindEvents);
  871. return hostElement;
  872. };
  873. const LIFECYCLES = [
  874. LIFECYCLE_WILL_ENTER,
  875. LIFECYCLE_DID_ENTER,
  876. LIFECYCLE_WILL_LEAVE,
  877. LIFECYCLE_DID_LEAVE,
  878. LIFECYCLE_WILL_UNLOAD,
  879. ];
  880. const bindLifecycleEvents = (zone, instance, element) => {
  881. return zone.run(() => {
  882. const unregisters = LIFECYCLES.filter((eventName) => typeof instance[eventName] === 'function').map((eventName) => {
  883. const handler = (ev) => instance[eventName](ev.detail);
  884. element.addEventListener(eventName, handler);
  885. return () => element.removeEventListener(eventName, handler);
  886. });
  887. return () => unregisters.forEach((fn) => fn());
  888. });
  889. };
  890. const NavParamsToken = new InjectionToken('NavParamsToken');
  891. const getProviders = (params) => {
  892. return [
  893. {
  894. provide: NavParamsToken,
  895. useValue: params,
  896. },
  897. {
  898. provide: NavParams,
  899. useFactory: provideNavParamsInjectable,
  900. deps: [NavParamsToken],
  901. },
  902. ];
  903. };
  904. const provideNavParamsInjectable = (params) => {
  905. return new NavParams(params);
  906. };
  907. // TODO: Is there a way we can grab this from angular-component-lib instead?
  908. /* eslint-disable */
  909. /* tslint:disable */
  910. const proxyInputs = (Cmp, inputs) => {
  911. const Prototype = Cmp.prototype;
  912. inputs.forEach((item) => {
  913. Object.defineProperty(Prototype, item, {
  914. get() {
  915. return this.el[item];
  916. },
  917. set(val) {
  918. this.z.runOutsideAngular(() => (this.el[item] = val));
  919. },
  920. });
  921. });
  922. };
  923. const proxyMethods = (Cmp, methods) => {
  924. const Prototype = Cmp.prototype;
  925. methods.forEach((methodName) => {
  926. Prototype[methodName] = function () {
  927. const args = arguments;
  928. return this.z.runOutsideAngular(() => this.el[methodName].apply(this.el, args));
  929. };
  930. });
  931. };
  932. const proxyOutputs = (instance, el, events) => {
  933. events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName)));
  934. };
  935. // tslint:disable-next-line: only-arrow-functions
  936. function ProxyCmp(opts) {
  937. const decorator = function (cls) {
  938. const { defineCustomElementFn, inputs, methods } = opts;
  939. if (defineCustomElementFn !== undefined) {
  940. defineCustomElementFn();
  941. }
  942. if (inputs) {
  943. proxyInputs(cls, inputs);
  944. }
  945. if (methods) {
  946. proxyMethods(cls, methods);
  947. }
  948. return cls;
  949. };
  950. return decorator;
  951. }
  952. const POPOVER_INPUTS = [
  953. 'alignment',
  954. 'animated',
  955. 'arrow',
  956. 'keepContentsMounted',
  957. 'backdropDismiss',
  958. 'cssClass',
  959. 'dismissOnSelect',
  960. 'enterAnimation',
  961. 'event',
  962. 'focusTrap',
  963. 'isOpen',
  964. 'keyboardClose',
  965. 'leaveAnimation',
  966. 'mode',
  967. 'showBackdrop',
  968. 'translucent',
  969. 'trigger',
  970. 'triggerAction',
  971. 'reference',
  972. 'size',
  973. 'side',
  974. ];
  975. const POPOVER_METHODS = ['present', 'dismiss', 'onDidDismiss', 'onWillDismiss'];
  976. let IonPopover = class IonPopover {
  977. z;
  978. // TODO(FW-2827): type
  979. template;
  980. isCmpOpen = false;
  981. el;
  982. constructor(c, r, z) {
  983. this.z = z;
  984. this.el = r.nativeElement;
  985. this.el.addEventListener('ionMount', () => {
  986. this.isCmpOpen = true;
  987. c.detectChanges();
  988. });
  989. this.el.addEventListener('didDismiss', () => {
  990. this.isCmpOpen = false;
  991. c.detectChanges();
  992. });
  993. proxyOutputs(this, this.el, [
  994. 'ionPopoverDidPresent',
  995. 'ionPopoverWillPresent',
  996. 'ionPopoverWillDismiss',
  997. 'ionPopoverDidDismiss',
  998. 'didPresent',
  999. 'willPresent',
  1000. 'willDismiss',
  1001. 'didDismiss',
  1002. ]);
  1003. }
  1004. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonPopover, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
  1005. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonPopover, selector: "ion-popover", inputs: { alignment: "alignment", animated: "animated", arrow: "arrow", keepContentsMounted: "keepContentsMounted", backdropDismiss: "backdropDismiss", cssClass: "cssClass", dismissOnSelect: "dismissOnSelect", enterAnimation: "enterAnimation", event: "event", focusTrap: "focusTrap", isOpen: "isOpen", keyboardClose: "keyboardClose", leaveAnimation: "leaveAnimation", mode: "mode", showBackdrop: "showBackdrop", translucent: "translucent", trigger: "trigger", triggerAction: "triggerAction", reference: "reference", size: "size", side: "side" }, queries: [{ propertyName: "template", first: true, predicate: TemplateRef, descendants: true }], ngImport: i0 });
  1006. };
  1007. IonPopover = __decorate([
  1008. ProxyCmp({
  1009. inputs: POPOVER_INPUTS,
  1010. methods: POPOVER_METHODS,
  1011. })
  1012. /**
  1013. * @Component extends from @Directive
  1014. * so by defining the inputs here we
  1015. * do not need to re-define them for the
  1016. * lazy loaded popover.
  1017. */
  1018. ], IonPopover);
  1019. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonPopover, decorators: [{
  1020. type: Directive,
  1021. args: [{
  1022. selector: 'ion-popover',
  1023. // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  1024. inputs: POPOVER_INPUTS,
  1025. }]
  1026. }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { template: [{
  1027. type: ContentChild,
  1028. args: [TemplateRef, { static: false }]
  1029. }] } });
  1030. const MODAL_INPUTS = [
  1031. 'animated',
  1032. 'keepContentsMounted',
  1033. 'backdropBreakpoint',
  1034. 'backdropDismiss',
  1035. 'breakpoints',
  1036. 'canDismiss',
  1037. 'cssClass',
  1038. 'enterAnimation',
  1039. 'expandToScroll',
  1040. 'event',
  1041. 'focusTrap',
  1042. 'handle',
  1043. 'handleBehavior',
  1044. 'initialBreakpoint',
  1045. 'isOpen',
  1046. 'keyboardClose',
  1047. 'leaveAnimation',
  1048. 'mode',
  1049. 'presentingElement',
  1050. 'showBackdrop',
  1051. 'translucent',
  1052. 'trigger',
  1053. ];
  1054. const MODAL_METHODS = [
  1055. 'present',
  1056. 'dismiss',
  1057. 'onDidDismiss',
  1058. 'onWillDismiss',
  1059. 'setCurrentBreakpoint',
  1060. 'getCurrentBreakpoint',
  1061. ];
  1062. let IonModal = class IonModal {
  1063. z;
  1064. // TODO(FW-2827): type
  1065. template;
  1066. isCmpOpen = false;
  1067. el;
  1068. constructor(c, r, z) {
  1069. this.z = z;
  1070. this.el = r.nativeElement;
  1071. this.el.addEventListener('ionMount', () => {
  1072. this.isCmpOpen = true;
  1073. c.detectChanges();
  1074. });
  1075. this.el.addEventListener('didDismiss', () => {
  1076. this.isCmpOpen = false;
  1077. c.detectChanges();
  1078. });
  1079. proxyOutputs(this, this.el, [
  1080. 'ionModalDidPresent',
  1081. 'ionModalWillPresent',
  1082. 'ionModalWillDismiss',
  1083. 'ionModalDidDismiss',
  1084. 'ionBreakpointDidChange',
  1085. 'didPresent',
  1086. 'willPresent',
  1087. 'willDismiss',
  1088. 'didDismiss',
  1089. ]);
  1090. }
  1091. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonModal, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
  1092. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonModal, selector: "ion-modal", inputs: { animated: "animated", keepContentsMounted: "keepContentsMounted", backdropBreakpoint: "backdropBreakpoint", backdropDismiss: "backdropDismiss", breakpoints: "breakpoints", canDismiss: "canDismiss", cssClass: "cssClass", enterAnimation: "enterAnimation", expandToScroll: "expandToScroll", event: "event", focusTrap: "focusTrap", handle: "handle", handleBehavior: "handleBehavior", initialBreakpoint: "initialBreakpoint", isOpen: "isOpen", keyboardClose: "keyboardClose", leaveAnimation: "leaveAnimation", mode: "mode", presentingElement: "presentingElement", showBackdrop: "showBackdrop", translucent: "translucent", trigger: "trigger" }, queries: [{ propertyName: "template", first: true, predicate: TemplateRef, descendants: true }], ngImport: i0 });
  1093. };
  1094. IonModal = __decorate([
  1095. ProxyCmp({
  1096. inputs: MODAL_INPUTS,
  1097. methods: MODAL_METHODS,
  1098. })
  1099. /**
  1100. * @Component extends from @Directive
  1101. * so by defining the inputs here we
  1102. * do not need to re-define them for the
  1103. * lazy loaded popover.
  1104. */
  1105. ], IonModal);
  1106. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonModal, decorators: [{
  1107. type: Directive,
  1108. args: [{
  1109. selector: 'ion-modal',
  1110. // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  1111. inputs: MODAL_INPUTS,
  1112. }]
  1113. }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { template: [{
  1114. type: ContentChild,
  1115. args: [TemplateRef, { static: false }]
  1116. }] } });
  1117. const insertView = (views, view, direction) => {
  1118. if (direction === 'root') {
  1119. return setRoot(views, view);
  1120. }
  1121. else if (direction === 'forward') {
  1122. return setForward(views, view);
  1123. }
  1124. else {
  1125. return setBack(views, view);
  1126. }
  1127. };
  1128. const setRoot = (views, view) => {
  1129. views = views.filter((v) => v.stackId !== view.stackId);
  1130. views.push(view);
  1131. return views;
  1132. };
  1133. const setForward = (views, view) => {
  1134. const index = views.indexOf(view);
  1135. if (index >= 0) {
  1136. views = views.filter((v) => v.stackId !== view.stackId || v.id <= view.id);
  1137. }
  1138. else {
  1139. views.push(view);
  1140. }
  1141. return views;
  1142. };
  1143. const setBack = (views, view) => {
  1144. const index = views.indexOf(view);
  1145. if (index >= 0) {
  1146. return views.filter((v) => v.stackId !== view.stackId || v.id <= view.id);
  1147. }
  1148. else {
  1149. return setRoot(views, view);
  1150. }
  1151. };
  1152. const getUrl = (router, activatedRoute) => {
  1153. const urlTree = router.createUrlTree(['.'], { relativeTo: activatedRoute });
  1154. return router.serializeUrl(urlTree);
  1155. };
  1156. const isTabSwitch = (enteringView, leavingView) => {
  1157. if (!leavingView) {
  1158. return true;
  1159. }
  1160. return enteringView.stackId !== leavingView.stackId;
  1161. };
  1162. const computeStackId = (prefixUrl, url) => {
  1163. if (!prefixUrl) {
  1164. return undefined;
  1165. }
  1166. const segments = toSegments(url);
  1167. for (let i = 0; i < segments.length; i++) {
  1168. if (i >= prefixUrl.length) {
  1169. return segments[i];
  1170. }
  1171. if (segments[i] !== prefixUrl[i]) {
  1172. return undefined;
  1173. }
  1174. }
  1175. return undefined;
  1176. };
  1177. const toSegments = (path) => {
  1178. return path
  1179. .split('/')
  1180. .map((s) => s.trim())
  1181. .filter((s) => s !== '');
  1182. };
  1183. const destroyView = (view) => {
  1184. if (view) {
  1185. view.ref.destroy();
  1186. view.unlistenEvents();
  1187. }
  1188. };
  1189. // TODO(FW-2827): types
  1190. class StackController {
  1191. containerEl;
  1192. router;
  1193. navCtrl;
  1194. zone;
  1195. location;
  1196. views = [];
  1197. runningTask;
  1198. skipTransition = false;
  1199. tabsPrefix;
  1200. activeView;
  1201. nextId = 0;
  1202. constructor(tabsPrefix, containerEl, router, navCtrl, zone, location) {
  1203. this.containerEl = containerEl;
  1204. this.router = router;
  1205. this.navCtrl = navCtrl;
  1206. this.zone = zone;
  1207. this.location = location;
  1208. this.tabsPrefix = tabsPrefix !== undefined ? toSegments(tabsPrefix) : undefined;
  1209. }
  1210. createView(ref, activatedRoute) {
  1211. const url = getUrl(this.router, activatedRoute);
  1212. const element = ref?.location?.nativeElement;
  1213. const unlistenEvents = bindLifecycleEvents(this.zone, ref.instance, element);
  1214. return {
  1215. id: this.nextId++,
  1216. stackId: computeStackId(this.tabsPrefix, url),
  1217. unlistenEvents,
  1218. element,
  1219. ref,
  1220. url,
  1221. };
  1222. }
  1223. getExistingView(activatedRoute) {
  1224. const activatedUrlKey = getUrl(this.router, activatedRoute);
  1225. const view = this.views.find((vw) => vw.url === activatedUrlKey);
  1226. if (view) {
  1227. view.ref.changeDetectorRef.reattach();
  1228. }
  1229. return view;
  1230. }
  1231. setActive(enteringView) {
  1232. const consumeResult = this.navCtrl.consumeTransition();
  1233. let { direction, animation, animationBuilder } = consumeResult;
  1234. const leavingView = this.activeView;
  1235. const tabSwitch = isTabSwitch(enteringView, leavingView);
  1236. if (tabSwitch) {
  1237. direction = 'back';
  1238. animation = undefined;
  1239. }
  1240. const viewsSnapshot = this.views.slice();
  1241. let currentNavigation;
  1242. const router = this.router;
  1243. // Angular >= 7.2.0
  1244. if (router.getCurrentNavigation) {
  1245. currentNavigation = router.getCurrentNavigation();
  1246. // Angular < 7.2.0
  1247. }
  1248. else if (router.navigations?.value) {
  1249. currentNavigation = router.navigations.value;
  1250. }
  1251. /**
  1252. * If the navigation action
  1253. * sets `replaceUrl: true`
  1254. * then we need to make sure
  1255. * we remove the last item
  1256. * from our views stack
  1257. */
  1258. if (currentNavigation?.extras?.replaceUrl) {
  1259. if (this.views.length > 0) {
  1260. this.views.splice(-1, 1);
  1261. }
  1262. }
  1263. const reused = this.views.includes(enteringView);
  1264. const views = this.insertView(enteringView, direction);
  1265. // Trigger change detection before transition starts
  1266. // This will call ngOnInit() the first time too, just after the view
  1267. // was attached to the dom, but BEFORE the transition starts
  1268. if (!reused) {
  1269. enteringView.ref.changeDetectorRef.detectChanges();
  1270. }
  1271. /**
  1272. * If we are going back from a page that
  1273. * was presented using a custom animation
  1274. * we should default to using that
  1275. * unless the developer explicitly
  1276. * provided another animation.
  1277. */
  1278. const customAnimation = enteringView.animationBuilder;
  1279. if (animationBuilder === undefined && direction === 'back' && !tabSwitch && customAnimation !== undefined) {
  1280. animationBuilder = customAnimation;
  1281. }
  1282. /**
  1283. * Save any custom animation so that navigating
  1284. * back will use this custom animation by default.
  1285. */
  1286. if (leavingView) {
  1287. leavingView.animationBuilder = animationBuilder;
  1288. }
  1289. // Wait until previous transitions finish
  1290. return this.zone.runOutsideAngular(() => {
  1291. return this.wait(() => {
  1292. // disconnect leaving page from change detection to
  1293. // reduce jank during the page transition
  1294. if (leavingView) {
  1295. leavingView.ref.changeDetectorRef.detach();
  1296. }
  1297. // In case the enteringView is the same as the leavingPage we need to reattach()
  1298. enteringView.ref.changeDetectorRef.reattach();
  1299. return this.transition(enteringView, leavingView, animation, this.canGoBack(1), false, animationBuilder)
  1300. .then(() => cleanupAsync(enteringView, views, viewsSnapshot, this.location, this.zone))
  1301. .then(() => ({
  1302. enteringView,
  1303. direction,
  1304. animation,
  1305. tabSwitch,
  1306. }));
  1307. });
  1308. });
  1309. }
  1310. canGoBack(deep, stackId = this.getActiveStackId()) {
  1311. return this.getStack(stackId).length > deep;
  1312. }
  1313. pop(deep, stackId = this.getActiveStackId()) {
  1314. return this.zone.run(() => {
  1315. const views = this.getStack(stackId);
  1316. if (views.length <= deep) {
  1317. return Promise.resolve(false);
  1318. }
  1319. const view = views[views.length - deep - 1];
  1320. let url = view.url;
  1321. const viewSavedData = view.savedData;
  1322. if (viewSavedData) {
  1323. const primaryOutlet = viewSavedData.get('primary');
  1324. if (primaryOutlet?.route?._routerState?.snapshot.url) {
  1325. url = primaryOutlet.route._routerState.snapshot.url;
  1326. }
  1327. }
  1328. const { animationBuilder } = this.navCtrl.consumeTransition();
  1329. return this.navCtrl.navigateBack(url, { ...view.savedExtras, animation: animationBuilder }).then(() => true);
  1330. });
  1331. }
  1332. startBackTransition() {
  1333. const leavingView = this.activeView;
  1334. if (leavingView) {
  1335. const views = this.getStack(leavingView.stackId);
  1336. const enteringView = views[views.length - 2];
  1337. const customAnimation = enteringView.animationBuilder;
  1338. return this.wait(() => {
  1339. return this.transition(enteringView, // entering view
  1340. leavingView, // leaving view
  1341. 'back', this.canGoBack(2), true, customAnimation);
  1342. });
  1343. }
  1344. return Promise.resolve();
  1345. }
  1346. endBackTransition(shouldComplete) {
  1347. if (shouldComplete) {
  1348. this.skipTransition = true;
  1349. this.pop(1);
  1350. }
  1351. else if (this.activeView) {
  1352. cleanup(this.activeView, this.views, this.views, this.location, this.zone);
  1353. }
  1354. }
  1355. getLastUrl(stackId) {
  1356. const views = this.getStack(stackId);
  1357. return views.length > 0 ? views[views.length - 1] : undefined;
  1358. }
  1359. /**
  1360. * @internal
  1361. */
  1362. getRootUrl(stackId) {
  1363. const views = this.getStack(stackId);
  1364. return views.length > 0 ? views[0] : undefined;
  1365. }
  1366. getActiveStackId() {
  1367. return this.activeView ? this.activeView.stackId : undefined;
  1368. }
  1369. /**
  1370. * @internal
  1371. */
  1372. getActiveView() {
  1373. return this.activeView;
  1374. }
  1375. hasRunningTask() {
  1376. return this.runningTask !== undefined;
  1377. }
  1378. destroy() {
  1379. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1380. this.containerEl = undefined;
  1381. this.views.forEach(destroyView);
  1382. this.activeView = undefined;
  1383. this.views = [];
  1384. }
  1385. getStack(stackId) {
  1386. return this.views.filter((v) => v.stackId === stackId);
  1387. }
  1388. insertView(enteringView, direction) {
  1389. this.activeView = enteringView;
  1390. this.views = insertView(this.views, enteringView, direction);
  1391. return this.views.slice();
  1392. }
  1393. transition(enteringView, leavingView, direction, showGoBack, progressAnimation, animationBuilder) {
  1394. if (this.skipTransition) {
  1395. this.skipTransition = false;
  1396. return Promise.resolve(false);
  1397. }
  1398. if (leavingView === enteringView) {
  1399. return Promise.resolve(false);
  1400. }
  1401. const enteringEl = enteringView ? enteringView.element : undefined;
  1402. const leavingEl = leavingView ? leavingView.element : undefined;
  1403. const containerEl = this.containerEl;
  1404. if (enteringEl && enteringEl !== leavingEl) {
  1405. enteringEl.classList.add('ion-page');
  1406. enteringEl.classList.add('ion-page-invisible');
  1407. if (containerEl.commit) {
  1408. return containerEl.commit(enteringEl, leavingEl, {
  1409. duration: direction === undefined ? 0 : undefined,
  1410. direction,
  1411. showGoBack,
  1412. progressAnimation,
  1413. animationBuilder,
  1414. });
  1415. }
  1416. }
  1417. return Promise.resolve(false);
  1418. }
  1419. async wait(task) {
  1420. if (this.runningTask !== undefined) {
  1421. await this.runningTask;
  1422. this.runningTask = undefined;
  1423. }
  1424. const promise = (this.runningTask = task());
  1425. promise.finally(() => (this.runningTask = undefined));
  1426. return promise;
  1427. }
  1428. }
  1429. const cleanupAsync = (activeRoute, views, viewsSnapshot, location, zone) => {
  1430. if (typeof requestAnimationFrame === 'function') {
  1431. return new Promise((resolve) => {
  1432. requestAnimationFrame(() => {
  1433. cleanup(activeRoute, views, viewsSnapshot, location, zone);
  1434. resolve();
  1435. });
  1436. });
  1437. }
  1438. return Promise.resolve();
  1439. };
  1440. const cleanup = (activeRoute, views, viewsSnapshot, location, zone) => {
  1441. /**
  1442. * Re-enter the Angular zone when destroying page components. This will allow
  1443. * lifecycle events (`ngOnDestroy`) to be run inside the Angular zone.
  1444. */
  1445. zone.run(() => viewsSnapshot.filter((view) => !views.includes(view)).forEach(destroyView));
  1446. views.forEach((view) => {
  1447. /**
  1448. * In the event that a user navigated multiple
  1449. * times in rapid succession, we want to make sure
  1450. * we don't pre-emptively detach a view while
  1451. * it is in mid-transition.
  1452. *
  1453. * In this instance we also do not care about query
  1454. * params or fragments as it will be the same view regardless
  1455. */
  1456. const locationWithoutParams = location.path().split('?')[0];
  1457. const locationWithoutFragment = locationWithoutParams.split('#')[0];
  1458. if (view !== activeRoute && view.url !== locationWithoutFragment) {
  1459. const element = view.element;
  1460. element.setAttribute('aria-hidden', 'true');
  1461. element.classList.add('ion-page-hidden');
  1462. view.ref.changeDetectorRef.detach();
  1463. }
  1464. });
  1465. };
  1466. // TODO(FW-2827): types
  1467. // eslint-disable-next-line @angular-eslint/directive-class-suffix
  1468. class IonRouterOutlet {
  1469. parentOutlet;
  1470. nativeEl;
  1471. activatedView = null;
  1472. tabsPrefix;
  1473. _swipeGesture;
  1474. stackCtrl;
  1475. // Maintain map of activated route proxies for each component instance
  1476. proxyMap = new WeakMap();
  1477. // Keep the latest activated route in a subject for the proxy routes to switch map to
  1478. currentActivatedRoute$ = new BehaviorSubject(null);
  1479. activated = null;
  1480. /** @internal */
  1481. get activatedComponentRef() {
  1482. return this.activated;
  1483. }
  1484. _activatedRoute = null;
  1485. /**
  1486. * The name of the outlet
  1487. */
  1488. name = PRIMARY_OUTLET;
  1489. /** @internal */
  1490. stackWillChange = new EventEmitter();
  1491. /** @internal */
  1492. stackDidChange = new EventEmitter();
  1493. // eslint-disable-next-line @angular-eslint/no-output-rename
  1494. activateEvents = new EventEmitter();
  1495. // eslint-disable-next-line @angular-eslint/no-output-rename
  1496. deactivateEvents = new EventEmitter();
  1497. parentContexts = inject(ChildrenOutletContexts);
  1498. location = inject(ViewContainerRef);
  1499. environmentInjector = inject(EnvironmentInjector);
  1500. inputBinder = inject(INPUT_BINDER, { optional: true });
  1501. /** @nodoc */
  1502. supportsBindingToComponentInputs = true;
  1503. // Ionic providers
  1504. config = inject(Config);
  1505. navCtrl = inject(NavController);
  1506. set animation(animation) {
  1507. this.nativeEl.animation = animation;
  1508. }
  1509. set animated(animated) {
  1510. this.nativeEl.animated = animated;
  1511. }
  1512. set swipeGesture(swipe) {
  1513. this._swipeGesture = swipe;
  1514. this.nativeEl.swipeHandler = swipe
  1515. ? {
  1516. canStart: () => this.stackCtrl.canGoBack(1) && !this.stackCtrl.hasRunningTask(),
  1517. onStart: () => this.stackCtrl.startBackTransition(),
  1518. onEnd: (shouldContinue) => this.stackCtrl.endBackTransition(shouldContinue),
  1519. }
  1520. : undefined;
  1521. }
  1522. constructor(name, tabs, commonLocation, elementRef, router, zone, activatedRoute, parentOutlet) {
  1523. this.parentOutlet = parentOutlet;
  1524. this.nativeEl = elementRef.nativeElement;
  1525. this.name = name || PRIMARY_OUTLET;
  1526. this.tabsPrefix = tabs === 'true' ? getUrl(router, activatedRoute) : undefined;
  1527. this.stackCtrl = new StackController(this.tabsPrefix, this.nativeEl, router, this.navCtrl, zone, commonLocation);
  1528. this.parentContexts.onChildOutletCreated(this.name, this);
  1529. }
  1530. ngOnDestroy() {
  1531. this.stackCtrl.destroy();
  1532. this.inputBinder?.unsubscribeFromRouteData(this);
  1533. }
  1534. getContext() {
  1535. return this.parentContexts.getContext(this.name);
  1536. }
  1537. ngOnInit() {
  1538. this.initializeOutletWithName();
  1539. }
  1540. // Note: Ionic deviates from the Angular Router implementation here
  1541. initializeOutletWithName() {
  1542. if (!this.activated) {
  1543. // If the outlet was not instantiated at the time the route got activated we need to populate
  1544. // the outlet when it is initialized (ie inside a NgIf)
  1545. const context = this.getContext();
  1546. if (context?.route) {
  1547. this.activateWith(context.route, context.injector);
  1548. }
  1549. }
  1550. new Promise((resolve) => componentOnReady(this.nativeEl, resolve)).then(() => {
  1551. if (this._swipeGesture === undefined) {
  1552. this.swipeGesture = this.config.getBoolean('swipeBackEnabled', this.nativeEl.mode === 'ios');
  1553. }
  1554. });
  1555. }
  1556. get isActivated() {
  1557. return !!this.activated;
  1558. }
  1559. get component() {
  1560. if (!this.activated) {
  1561. throw new Error('Outlet is not activated');
  1562. }
  1563. return this.activated.instance;
  1564. }
  1565. get activatedRoute() {
  1566. if (!this.activated) {
  1567. throw new Error('Outlet is not activated');
  1568. }
  1569. return this._activatedRoute;
  1570. }
  1571. get activatedRouteData() {
  1572. if (this._activatedRoute) {
  1573. return this._activatedRoute.snapshot.data;
  1574. }
  1575. return {};
  1576. }
  1577. /**
  1578. * Called when the `RouteReuseStrategy` instructs to detach the subtree
  1579. */
  1580. detach() {
  1581. throw new Error('incompatible reuse strategy');
  1582. }
  1583. /**
  1584. * Called when the `RouteReuseStrategy` instructs to re-attach a previously detached subtree
  1585. */
  1586. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  1587. attach(_ref, _activatedRoute) {
  1588. throw new Error('incompatible reuse strategy');
  1589. }
  1590. deactivate() {
  1591. if (this.activated) {
  1592. if (this.activatedView) {
  1593. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1594. const context = this.getContext();
  1595. this.activatedView.savedData = new Map(context.children['contexts']);
  1596. /**
  1597. * Angular v11.2.10 introduced a change
  1598. * where this route context is cleared out when
  1599. * a router-outlet is deactivated, However,
  1600. * we need this route information in order to
  1601. * return a user back to the correct tab when
  1602. * leaving and then going back to the tab context.
  1603. */
  1604. const primaryOutlet = this.activatedView.savedData.get('primary');
  1605. if (primaryOutlet && context.route) {
  1606. primaryOutlet.route = { ...context.route };
  1607. }
  1608. /**
  1609. * Ensure we are saving the NavigationExtras
  1610. * data otherwise it will be lost
  1611. */
  1612. this.activatedView.savedExtras = {};
  1613. if (context.route) {
  1614. const contextSnapshot = context.route.snapshot;
  1615. this.activatedView.savedExtras.queryParams = contextSnapshot.queryParams;
  1616. this.activatedView.savedExtras.fragment = contextSnapshot.fragment;
  1617. }
  1618. }
  1619. const c = this.component;
  1620. this.activatedView = null;
  1621. this.activated = null;
  1622. this._activatedRoute = null;
  1623. this.deactivateEvents.emit(c);
  1624. }
  1625. }
  1626. activateWith(activatedRoute, environmentInjector) {
  1627. if (this.isActivated) {
  1628. throw new Error('Cannot activate an already activated outlet');
  1629. }
  1630. this._activatedRoute = activatedRoute;
  1631. let cmpRef;
  1632. let enteringView = this.stackCtrl.getExistingView(activatedRoute);
  1633. if (enteringView) {
  1634. cmpRef = this.activated = enteringView.ref;
  1635. const saved = enteringView.savedData;
  1636. if (saved) {
  1637. // self-restore
  1638. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1639. const context = this.getContext();
  1640. context.children['contexts'] = saved;
  1641. }
  1642. // Updated activated route proxy for this component
  1643. this.updateActivatedRouteProxy(cmpRef.instance, activatedRoute);
  1644. }
  1645. else {
  1646. const snapshot = activatedRoute._futureSnapshot;
  1647. /**
  1648. * Angular 14 introduces a new `loadComponent` property to the route config.
  1649. * This function will assign a `component` property to the route snapshot.
  1650. * We check for the presence of this property to determine if the route is
  1651. * using standalone components.
  1652. */
  1653. const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
  1654. // We create an activated route proxy object that will maintain future updates for this component
  1655. // over its lifecycle in the stack.
  1656. const component$ = new BehaviorSubject(null);
  1657. const activatedRouteProxy = this.createActivatedRouteProxy(component$, activatedRoute);
  1658. const injector = new OutletInjector(activatedRouteProxy, childContexts, this.location.injector);
  1659. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1660. const component = snapshot.routeConfig.component ?? snapshot.component;
  1661. /**
  1662. * View components need to be added as a child of ion-router-outlet
  1663. * for page transitions and swipe to go back.
  1664. * However, createComponent mounts components as siblings of the
  1665. * ViewContainerRef. As a result, outletContent must reference
  1666. * an ng-container inside of ion-router-outlet and not
  1667. * ion-router-outlet itself.
  1668. */
  1669. cmpRef = this.activated = this.outletContent.createComponent(component, {
  1670. index: this.outletContent.length,
  1671. injector,
  1672. environmentInjector: environmentInjector ?? this.environmentInjector,
  1673. });
  1674. // Once the component is created we can push it to our local subject supplied to the proxy
  1675. component$.next(cmpRef.instance);
  1676. // Calling `markForCheck` to make sure we will run the change detection when the
  1677. // `RouterOutlet` is inside a `ChangeDetectionStrategy.OnPush` component.
  1678. /**
  1679. * At this point this.activated has been set earlier
  1680. * in this function, so it is guaranteed to be non-null.
  1681. */
  1682. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  1683. enteringView = this.stackCtrl.createView(this.activated, activatedRoute);
  1684. // Store references to the proxy by component
  1685. this.proxyMap.set(cmpRef.instance, activatedRouteProxy);
  1686. this.currentActivatedRoute$.next({ component: cmpRef.instance, activatedRoute });
  1687. }
  1688. this.inputBinder?.bindActivatedRouteToOutletComponent(this);
  1689. this.activatedView = enteringView;
  1690. /**
  1691. * The top outlet is set prior to the entering view's transition completing,
  1692. * so that when we have nested outlets (e.g. ion-tabs inside an ion-router-outlet),
  1693. * the tabs outlet will be assigned as the top outlet when a view inside tabs is
  1694. * activated.
  1695. *
  1696. * In this scenario, activeWith is called for both the tabs and the root router outlet.
  1697. * To avoid a race condition, we assign the top outlet synchronously.
  1698. */
  1699. this.navCtrl.setTopOutlet(this);
  1700. const leavingView = this.stackCtrl.getActiveView();
  1701. this.stackWillChange.emit({
  1702. enteringView,
  1703. tabSwitch: isTabSwitch(enteringView, leavingView),
  1704. });
  1705. this.stackCtrl.setActive(enteringView).then((data) => {
  1706. this.activateEvents.emit(cmpRef.instance);
  1707. this.stackDidChange.emit(data);
  1708. });
  1709. }
  1710. /**
  1711. * Returns `true` if there are pages in the stack to go back.
  1712. */
  1713. canGoBack(deep = 1, stackId) {
  1714. return this.stackCtrl.canGoBack(deep, stackId);
  1715. }
  1716. /**
  1717. * Resolves to `true` if it the outlet was able to sucessfully pop the last N pages.
  1718. */
  1719. pop(deep = 1, stackId) {
  1720. return this.stackCtrl.pop(deep, stackId);
  1721. }
  1722. /**
  1723. * Returns the URL of the active page of each stack.
  1724. */
  1725. getLastUrl(stackId) {
  1726. const active = this.stackCtrl.getLastUrl(stackId);
  1727. return active ? active.url : undefined;
  1728. }
  1729. /**
  1730. * Returns the RouteView of the active page of each stack.
  1731. * @internal
  1732. */
  1733. getLastRouteView(stackId) {
  1734. return this.stackCtrl.getLastUrl(stackId);
  1735. }
  1736. /**
  1737. * Returns the root view in the tab stack.
  1738. * @internal
  1739. */
  1740. getRootView(stackId) {
  1741. return this.stackCtrl.getRootUrl(stackId);
  1742. }
  1743. /**
  1744. * Returns the active stack ID. In the context of ion-tabs, it means the active tab.
  1745. */
  1746. getActiveStackId() {
  1747. return this.stackCtrl.getActiveStackId();
  1748. }
  1749. /**
  1750. * Since the activated route can change over the life time of a component in an ion router outlet, we create
  1751. * a proxy so that we can update the values over time as a user navigates back to components already in the stack.
  1752. */
  1753. createActivatedRouteProxy(component$, activatedRoute) {
  1754. const proxy = new ActivatedRoute();
  1755. proxy._futureSnapshot = activatedRoute._futureSnapshot;
  1756. proxy._routerState = activatedRoute._routerState;
  1757. proxy.snapshot = activatedRoute.snapshot;
  1758. proxy.outlet = activatedRoute.outlet;
  1759. proxy.component = activatedRoute.component;
  1760. // Setup wrappers for the observables so consumers don't have to worry about switching to new observables as the state updates
  1761. proxy._paramMap = this.proxyObservable(component$, 'paramMap');
  1762. proxy._queryParamMap = this.proxyObservable(component$, 'queryParamMap');
  1763. proxy.url = this.proxyObservable(component$, 'url');
  1764. proxy.params = this.proxyObservable(component$, 'params');
  1765. proxy.queryParams = this.proxyObservable(component$, 'queryParams');
  1766. proxy.fragment = this.proxyObservable(component$, 'fragment');
  1767. proxy.data = this.proxyObservable(component$, 'data');
  1768. return proxy;
  1769. }
  1770. /**
  1771. * Create a wrapped observable that will switch to the latest activated route matched by the given component
  1772. */
  1773. proxyObservable(component$, path) {
  1774. return component$.pipe(
  1775. // First wait until the component instance is pushed
  1776. filter((component) => !!component), switchMap((component) => this.currentActivatedRoute$.pipe(filter((current) => current !== null && current.component === component), switchMap((current) => current && current.activatedRoute[path]), distinctUntilChanged())));
  1777. }
  1778. /**
  1779. * Updates the activated route proxy for the given component to the new incoming router state
  1780. */
  1781. updateActivatedRouteProxy(component, activatedRoute) {
  1782. const proxy = this.proxyMap.get(component);
  1783. if (!proxy) {
  1784. throw new Error(`Could not find activated route proxy for view`);
  1785. }
  1786. proxy._futureSnapshot = activatedRoute._futureSnapshot;
  1787. proxy._routerState = activatedRoute._routerState;
  1788. proxy.snapshot = activatedRoute.snapshot;
  1789. proxy.outlet = activatedRoute.outlet;
  1790. proxy.component = activatedRoute.component;
  1791. this.currentActivatedRoute$.next({ component, activatedRoute });
  1792. }
  1793. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonRouterOutlet, deps: [{ token: 'name', attribute: true }, { token: 'tabs', attribute: true, optional: true }, { token: i1.Location }, { token: i0.ElementRef }, { token: i3.Router }, { token: i0.NgZone }, { token: i3.ActivatedRoute }, { token: IonRouterOutlet, optional: true, skipSelf: true }], target: i0.ɵɵFactoryTarget.Directive });
  1794. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonRouterOutlet, selector: "ion-router-outlet", inputs: { animated: "animated", animation: "animation", mode: "mode", swipeGesture: "swipeGesture", name: "name" }, outputs: { stackWillChange: "stackWillChange", stackDidChange: "stackDidChange", activateEvents: "activate", deactivateEvents: "deactivate" }, exportAs: ["outlet"], ngImport: i0 });
  1795. }
  1796. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonRouterOutlet, decorators: [{
  1797. type: Directive,
  1798. args: [{
  1799. selector: 'ion-router-outlet',
  1800. exportAs: 'outlet',
  1801. // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  1802. inputs: ['animated', 'animation', 'mode', 'swipeGesture'],
  1803. }]
  1804. }], ctorParameters: function () { return [{ type: undefined, decorators: [{
  1805. type: Attribute,
  1806. args: ['name']
  1807. }] }, { type: undefined, decorators: [{
  1808. type: Optional
  1809. }, {
  1810. type: Attribute,
  1811. args: ['tabs']
  1812. }] }, { type: i1.Location }, { type: i0.ElementRef }, { type: i3.Router }, { type: i0.NgZone }, { type: i3.ActivatedRoute }, { type: IonRouterOutlet, decorators: [{
  1813. type: SkipSelf
  1814. }, {
  1815. type: Optional
  1816. }] }]; }, propDecorators: { name: [{
  1817. type: Input
  1818. }], stackWillChange: [{
  1819. type: Output
  1820. }], stackDidChange: [{
  1821. type: Output
  1822. }], activateEvents: [{
  1823. type: Output,
  1824. args: ['activate']
  1825. }], deactivateEvents: [{
  1826. type: Output,
  1827. args: ['deactivate']
  1828. }] } });
  1829. class OutletInjector {
  1830. route;
  1831. childContexts;
  1832. parent;
  1833. constructor(route, childContexts, parent) {
  1834. this.route = route;
  1835. this.childContexts = childContexts;
  1836. this.parent = parent;
  1837. }
  1838. get(token, notFoundValue) {
  1839. if (token === ActivatedRoute) {
  1840. return this.route;
  1841. }
  1842. if (token === ChildrenOutletContexts) {
  1843. return this.childContexts;
  1844. }
  1845. return this.parent.get(token, notFoundValue);
  1846. }
  1847. }
  1848. // TODO: FW-4785 - Remove this once Angular 15 support is dropped
  1849. const INPUT_BINDER = new InjectionToken('');
  1850. /**
  1851. * Injectable used as a tree-shakable provider for opting in to binding router data to component
  1852. * inputs.
  1853. *
  1854. * The RouterOutlet registers itself with this service when an `ActivatedRoute` is attached or
  1855. * activated. When this happens, the service subscribes to the `ActivatedRoute` observables (params,
  1856. * queryParams, data) and sets the inputs of the component using `ComponentRef.setInput`.
  1857. * Importantly, when an input does not have an item in the route data with a matching key, this
  1858. * input is set to `undefined`. If it were not done this way, the previous information would be
  1859. * retained if the data got removed from the route (i.e. if a query parameter is removed).
  1860. *
  1861. * The `RouterOutlet` should unregister itself when destroyed via `unsubscribeFromRouteData` so that
  1862. * the subscriptions are cleaned up.
  1863. */
  1864. class RoutedComponentInputBinder {
  1865. outletDataSubscriptions = new Map();
  1866. bindActivatedRouteToOutletComponent(outlet) {
  1867. this.unsubscribeFromRouteData(outlet);
  1868. this.subscribeToRouteData(outlet);
  1869. }
  1870. unsubscribeFromRouteData(outlet) {
  1871. this.outletDataSubscriptions.get(outlet)?.unsubscribe();
  1872. this.outletDataSubscriptions.delete(outlet);
  1873. }
  1874. subscribeToRouteData(outlet) {
  1875. const { activatedRoute } = outlet;
  1876. const dataSubscription = combineLatest([activatedRoute.queryParams, activatedRoute.params, activatedRoute.data])
  1877. .pipe(switchMap(([queryParams, params, data], index) => {
  1878. data = { ...queryParams, ...params, ...data };
  1879. // Get the first result from the data subscription synchronously so it's available to
  1880. // the component as soon as possible (and doesn't require a second change detection).
  1881. if (index === 0) {
  1882. return of(data);
  1883. }
  1884. // Promise.resolve is used to avoid synchronously writing the wrong data when
  1885. // two of the Observables in the `combineLatest` stream emit one after
  1886. // another.
  1887. return Promise.resolve(data);
  1888. }))
  1889. .subscribe((data) => {
  1890. // Outlet may have been deactivated or changed names to be associated with a different
  1891. // route
  1892. if (!outlet.isActivated ||
  1893. !outlet.activatedComponentRef ||
  1894. outlet.activatedRoute !== activatedRoute ||
  1895. activatedRoute.component === null) {
  1896. this.unsubscribeFromRouteData(outlet);
  1897. return;
  1898. }
  1899. const mirror = reflectComponentType(activatedRoute.component);
  1900. if (!mirror) {
  1901. this.unsubscribeFromRouteData(outlet);
  1902. return;
  1903. }
  1904. for (const { templateName } of mirror.inputs) {
  1905. outlet.activatedComponentRef.setInput(templateName, data[templateName]);
  1906. }
  1907. });
  1908. this.outletDataSubscriptions.set(outlet, dataSubscription);
  1909. }
  1910. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RoutedComponentInputBinder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
  1911. /** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RoutedComponentInputBinder });
  1912. }
  1913. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RoutedComponentInputBinder, decorators: [{
  1914. type: Injectable
  1915. }] });
  1916. const provideComponentInputBinding = () => {
  1917. return {
  1918. provide: INPUT_BINDER,
  1919. useFactory: componentInputBindingFactory,
  1920. deps: [Router],
  1921. };
  1922. };
  1923. function componentInputBindingFactory(router) {
  1924. /**
  1925. * We cast the router to any here, since the componentInputBindingEnabled
  1926. * property is not available until Angular v16.
  1927. */
  1928. if (router?.componentInputBindingEnabled) {
  1929. return new RoutedComponentInputBinder();
  1930. }
  1931. return null;
  1932. }
  1933. const BACK_BUTTON_INPUTS = ['color', 'defaultHref', 'disabled', 'icon', 'mode', 'routerAnimation', 'text', 'type'];
  1934. let IonBackButton = class IonBackButton {
  1935. routerOutlet;
  1936. navCtrl;
  1937. config;
  1938. r;
  1939. z;
  1940. el;
  1941. constructor(routerOutlet, navCtrl, config, r, z, c) {
  1942. this.routerOutlet = routerOutlet;
  1943. this.navCtrl = navCtrl;
  1944. this.config = config;
  1945. this.r = r;
  1946. this.z = z;
  1947. c.detach();
  1948. this.el = this.r.nativeElement;
  1949. }
  1950. /**
  1951. * @internal
  1952. */
  1953. onClick(ev) {
  1954. const defaultHref = this.defaultHref || this.config.get('backButtonDefaultHref');
  1955. if (this.routerOutlet?.canGoBack()) {
  1956. this.navCtrl.setDirection('back', undefined, undefined, this.routerAnimation);
  1957. this.routerOutlet.pop();
  1958. ev.preventDefault();
  1959. }
  1960. else if (defaultHref != null) {
  1961. this.navCtrl.navigateBack(defaultHref, { animation: this.routerAnimation });
  1962. ev.preventDefault();
  1963. }
  1964. }
  1965. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonBackButton, deps: [{ token: IonRouterOutlet, optional: true }, { token: NavController }, { token: Config }, { token: i0.ElementRef }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
  1966. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonBackButton, inputs: { color: "color", defaultHref: "defaultHref", disabled: "disabled", icon: "icon", mode: "mode", routerAnimation: "routerAnimation", text: "text", type: "type" }, host: { listeners: { "click": "onClick($event)" } }, ngImport: i0 });
  1967. };
  1968. IonBackButton = __decorate([
  1969. ProxyCmp({
  1970. inputs: BACK_BUTTON_INPUTS,
  1971. })
  1972. ], IonBackButton);
  1973. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonBackButton, decorators: [{
  1974. type: Directive,
  1975. args: [{
  1976. // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  1977. inputs: BACK_BUTTON_INPUTS,
  1978. }]
  1979. }], ctorParameters: function () { return [{ type: IonRouterOutlet, decorators: [{
  1980. type: Optional
  1981. }] }, { type: NavController }, { type: Config }, { type: i0.ElementRef }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { onClick: [{
  1982. type: HostListener,
  1983. args: ['click', ['$event']]
  1984. }] } });
  1985. /**
  1986. * Adds support for Ionic routing directions and animations to the base Angular router link directive.
  1987. *
  1988. * When the router link is clicked, the directive will assign the direction and
  1989. * animation so that the routing integration will transition correctly.
  1990. */
  1991. class RouterLinkDelegateDirective {
  1992. locationStrategy;
  1993. navCtrl;
  1994. elementRef;
  1995. router;
  1996. routerLink;
  1997. routerDirection = 'forward';
  1998. routerAnimation;
  1999. constructor(locationStrategy, navCtrl, elementRef, router, routerLink) {
  2000. this.locationStrategy = locationStrategy;
  2001. this.navCtrl = navCtrl;
  2002. this.elementRef = elementRef;
  2003. this.router = router;
  2004. this.routerLink = routerLink;
  2005. }
  2006. ngOnInit() {
  2007. this.updateTargetUrlAndHref();
  2008. this.updateTabindex();
  2009. }
  2010. ngOnChanges() {
  2011. this.updateTargetUrlAndHref();
  2012. }
  2013. /**
  2014. * The `tabindex` is set to `0` by default on the host element when
  2015. * the `routerLink` directive is used. This causes issues with Ionic
  2016. * components that wrap an `a` or `button` element, such as `ion-item`.
  2017. * See issue https://github.com/angular/angular/issues/28345
  2018. *
  2019. * This method removes the `tabindex` attribute from the host element
  2020. * to allow the Ionic component to manage the focus state correctly.
  2021. */
  2022. updateTabindex() {
  2023. // Ionic components that render a native anchor or button element
  2024. const ionicComponents = [
  2025. 'ION-BACK-BUTTON',
  2026. 'ION-BREADCRUMB',
  2027. 'ION-BUTTON',
  2028. 'ION-CARD',
  2029. 'ION-FAB-BUTTON',
  2030. 'ION-ITEM',
  2031. 'ION-ITEM-OPTION',
  2032. 'ION-MENU-BUTTON',
  2033. 'ION-SEGMENT-BUTTON',
  2034. 'ION-TAB-BUTTON',
  2035. ];
  2036. const hostElement = this.elementRef.nativeElement;
  2037. if (ionicComponents.includes(hostElement.tagName)) {
  2038. if (hostElement.getAttribute('tabindex') === '0') {
  2039. hostElement.removeAttribute('tabindex');
  2040. }
  2041. }
  2042. }
  2043. updateTargetUrlAndHref() {
  2044. if (this.routerLink?.urlTree) {
  2045. const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
  2046. this.elementRef.nativeElement.href = href;
  2047. }
  2048. }
  2049. /**
  2050. * @internal
  2051. */
  2052. onClick(ev) {
  2053. this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
  2054. /**
  2055. * This prevents the browser from
  2056. * performing a page reload when pressing
  2057. * an Ionic component with routerLink.
  2058. * The page reload interferes with routing
  2059. * and causes ion-back-button to disappear
  2060. * since the local history is wiped on reload.
  2061. */
  2062. ev.preventDefault();
  2063. }
  2064. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkDelegateDirective, deps: [{ token: i1.LocationStrategy }, { token: NavController }, { token: i0.ElementRef }, { token: i3.Router }, { token: i3.RouterLink, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
  2065. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: RouterLinkDelegateDirective, selector: ":not(a):not(area)[routerLink]", inputs: { routerDirection: "routerDirection", routerAnimation: "routerAnimation" }, host: { listeners: { "click": "onClick($event)" } }, usesOnChanges: true, ngImport: i0 });
  2066. }
  2067. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkDelegateDirective, decorators: [{
  2068. type: Directive,
  2069. args: [{
  2070. selector: ':not(a):not(area)[routerLink]',
  2071. }]
  2072. }], ctorParameters: function () { return [{ type: i1.LocationStrategy }, { type: NavController }, { type: i0.ElementRef }, { type: i3.Router }, { type: i3.RouterLink, decorators: [{
  2073. type: Optional
  2074. }] }]; }, propDecorators: { routerDirection: [{
  2075. type: Input
  2076. }], routerAnimation: [{
  2077. type: Input
  2078. }], onClick: [{
  2079. type: HostListener,
  2080. args: ['click', ['$event']]
  2081. }] } });
  2082. class RouterLinkWithHrefDelegateDirective {
  2083. locationStrategy;
  2084. navCtrl;
  2085. elementRef;
  2086. router;
  2087. routerLink;
  2088. routerDirection = 'forward';
  2089. routerAnimation;
  2090. constructor(locationStrategy, navCtrl, elementRef, router, routerLink) {
  2091. this.locationStrategy = locationStrategy;
  2092. this.navCtrl = navCtrl;
  2093. this.elementRef = elementRef;
  2094. this.router = router;
  2095. this.routerLink = routerLink;
  2096. }
  2097. ngOnInit() {
  2098. this.updateTargetUrlAndHref();
  2099. }
  2100. ngOnChanges() {
  2101. this.updateTargetUrlAndHref();
  2102. }
  2103. updateTargetUrlAndHref() {
  2104. if (this.routerLink?.urlTree) {
  2105. const href = this.locationStrategy.prepareExternalUrl(this.router.serializeUrl(this.routerLink.urlTree));
  2106. this.elementRef.nativeElement.href = href;
  2107. }
  2108. }
  2109. /**
  2110. * @internal
  2111. */
  2112. onClick() {
  2113. this.navCtrl.setDirection(this.routerDirection, undefined, undefined, this.routerAnimation);
  2114. }
  2115. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkWithHrefDelegateDirective, deps: [{ token: i1.LocationStrategy }, { token: NavController }, { token: i0.ElementRef }, { token: i3.Router }, { token: i3.RouterLink, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
  2116. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: RouterLinkWithHrefDelegateDirective, selector: "a[routerLink],area[routerLink]", inputs: { routerDirection: "routerDirection", routerAnimation: "routerAnimation" }, host: { listeners: { "click": "onClick()" } }, usesOnChanges: true, ngImport: i0 });
  2117. }
  2118. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkWithHrefDelegateDirective, decorators: [{
  2119. type: Directive,
  2120. args: [{
  2121. selector: 'a[routerLink],area[routerLink]',
  2122. }]
  2123. }], ctorParameters: function () { return [{ type: i1.LocationStrategy }, { type: NavController }, { type: i0.ElementRef }, { type: i3.Router }, { type: i3.RouterLink, decorators: [{
  2124. type: Optional
  2125. }] }]; }, propDecorators: { routerDirection: [{
  2126. type: Input
  2127. }], routerAnimation: [{
  2128. type: Input
  2129. }], onClick: [{
  2130. type: HostListener,
  2131. args: ['click']
  2132. }] } });
  2133. const NAV_INPUTS = ['animated', 'animation', 'root', 'rootParams', 'swipeGesture'];
  2134. const NAV_METHODS = [
  2135. 'push',
  2136. 'insert',
  2137. 'insertPages',
  2138. 'pop',
  2139. 'popTo',
  2140. 'popToRoot',
  2141. 'removeIndex',
  2142. 'setRoot',
  2143. 'setPages',
  2144. 'getActive',
  2145. 'getByIndex',
  2146. 'canGoBack',
  2147. 'getPrevious',
  2148. ];
  2149. let IonNav = class IonNav {
  2150. z;
  2151. el;
  2152. constructor(ref, environmentInjector, injector, angularDelegate, z, c) {
  2153. this.z = z;
  2154. c.detach();
  2155. this.el = ref.nativeElement;
  2156. ref.nativeElement.delegate = angularDelegate.create(environmentInjector, injector);
  2157. proxyOutputs(this, this.el, ['ionNavDidChange', 'ionNavWillChange']);
  2158. }
  2159. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonNav, deps: [{ token: i0.ElementRef }, { token: i0.EnvironmentInjector }, { token: i0.Injector }, { token: AngularDelegate }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
  2160. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonNav, inputs: { animated: "animated", animation: "animation", root: "root", rootParams: "rootParams", swipeGesture: "swipeGesture" }, ngImport: i0 });
  2161. };
  2162. IonNav = __decorate([
  2163. ProxyCmp({
  2164. inputs: NAV_INPUTS,
  2165. methods: NAV_METHODS,
  2166. })
  2167. ], IonNav);
  2168. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonNav, decorators: [{
  2169. type: Directive,
  2170. args: [{
  2171. // eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
  2172. inputs: NAV_INPUTS,
  2173. }]
  2174. }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.EnvironmentInjector }, { type: i0.Injector }, { type: AngularDelegate }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }]; } });
  2175. // eslint-disable-next-line @angular-eslint/directive-class-suffix
  2176. class IonTabs {
  2177. navCtrl;
  2178. tabsInner;
  2179. /**
  2180. * Emitted before the tab view is changed.
  2181. */
  2182. ionTabsWillChange = new EventEmitter();
  2183. /**
  2184. * Emitted after the tab view is changed.
  2185. */
  2186. ionTabsDidChange = new EventEmitter();
  2187. tabBarSlot = 'bottom';
  2188. hasTab = false;
  2189. selectedTab;
  2190. leavingTab;
  2191. constructor(navCtrl) {
  2192. this.navCtrl = navCtrl;
  2193. }
  2194. ngAfterViewInit() {
  2195. /**
  2196. * Developers must pass at least one ion-tab
  2197. * inside of ion-tabs if they want to use a
  2198. * basic tab-based navigation without the
  2199. * history stack or URL updates associated
  2200. * with the router.
  2201. */
  2202. const firstTab = this.tabs.length > 0 ? this.tabs.first : undefined;
  2203. if (firstTab) {
  2204. this.hasTab = true;
  2205. this.setActiveTab(firstTab.tab);
  2206. this.tabSwitch();
  2207. }
  2208. }
  2209. ngAfterContentInit() {
  2210. this.detectSlotChanges();
  2211. }
  2212. ngAfterContentChecked() {
  2213. this.detectSlotChanges();
  2214. }
  2215. /**
  2216. * @internal
  2217. */
  2218. onStackWillChange({ enteringView, tabSwitch }) {
  2219. const stackId = enteringView.stackId;
  2220. if (tabSwitch && stackId !== undefined) {
  2221. this.ionTabsWillChange.emit({ tab: stackId });
  2222. }
  2223. }
  2224. /**
  2225. * @internal
  2226. */
  2227. onStackDidChange({ enteringView, tabSwitch }) {
  2228. const stackId = enteringView.stackId;
  2229. if (tabSwitch && stackId !== undefined) {
  2230. if (this.tabBar) {
  2231. this.tabBar.selectedTab = stackId;
  2232. }
  2233. this.ionTabsDidChange.emit({ tab: stackId });
  2234. }
  2235. }
  2236. /**
  2237. * When a tab button is clicked, there are several scenarios:
  2238. * 1. If the selected tab is currently active (the tab button has been clicked
  2239. * again), then it should go to the root view for that tab.
  2240. *
  2241. * a. Get the saved root view from the router outlet. If the saved root view
  2242. * matches the tabRootUrl, set the route view to this view including the
  2243. * navigation extras.
  2244. * b. If the saved root view from the router outlet does
  2245. * not match, navigate to the tabRootUrl. No navigation extras are
  2246. * included.
  2247. *
  2248. * 2. If the current tab tab is not currently selected, get the last route
  2249. * view from the router outlet.
  2250. *
  2251. * a. If the last route view exists, navigate to that view including any
  2252. * navigation extras
  2253. * b. If the last route view doesn't exist, then navigate
  2254. * to the default tabRootUrl
  2255. */
  2256. select(tabOrEvent) {
  2257. const isTabString = typeof tabOrEvent === 'string';
  2258. const tab = isTabString ? tabOrEvent : tabOrEvent.detail.tab;
  2259. /**
  2260. * If the tabs are not using the router, then
  2261. * the tab switch logic is handled by the tabs
  2262. * component itself.
  2263. */
  2264. if (this.hasTab) {
  2265. this.setActiveTab(tab);
  2266. this.tabSwitch();
  2267. return;
  2268. }
  2269. const alreadySelected = this.outlet.getActiveStackId() === tab;
  2270. const tabRootUrl = `${this.outlet.tabsPrefix}/${tab}`;
  2271. /**
  2272. * If this is a nested tab, prevent the event
  2273. * from bubbling otherwise the outer tabs
  2274. * will respond to this event too, causing
  2275. * the app to get directed to the wrong place.
  2276. */
  2277. if (!isTabString) {
  2278. tabOrEvent.stopPropagation();
  2279. }
  2280. if (alreadySelected) {
  2281. const activeStackId = this.outlet.getActiveStackId();
  2282. const activeView = this.outlet.getLastRouteView(activeStackId);
  2283. // If on root tab, do not navigate to root tab again
  2284. if (activeView?.url === tabRootUrl) {
  2285. return;
  2286. }
  2287. const rootView = this.outlet.getRootView(tab);
  2288. const navigationExtras = rootView && tabRootUrl === rootView.url && rootView.savedExtras;
  2289. return this.navCtrl.navigateRoot(tabRootUrl, {
  2290. ...navigationExtras,
  2291. animated: true,
  2292. animationDirection: 'back',
  2293. });
  2294. }
  2295. else {
  2296. const lastRoute = this.outlet.getLastRouteView(tab);
  2297. /**
  2298. * If there is a lastRoute, goto that, otherwise goto the fallback url of the
  2299. * selected tab
  2300. */
  2301. const url = lastRoute?.url || tabRootUrl;
  2302. const navigationExtras = lastRoute?.savedExtras;
  2303. return this.navCtrl.navigateRoot(url, {
  2304. ...navigationExtras,
  2305. animated: true,
  2306. animationDirection: 'back',
  2307. });
  2308. }
  2309. }
  2310. setActiveTab(tab) {
  2311. const tabs = this.tabs;
  2312. const selectedTab = tabs.find((t) => t.tab === tab);
  2313. if (!selectedTab) {
  2314. console.error(`[Ionic Error]: Tab with id: "${tab}" does not exist`);
  2315. return;
  2316. }
  2317. this.leavingTab = this.selectedTab;
  2318. this.selectedTab = selectedTab;
  2319. this.ionTabsWillChange.emit({ tab });
  2320. selectedTab.el.active = true;
  2321. }
  2322. tabSwitch() {
  2323. const { selectedTab, leavingTab } = this;
  2324. if (this.tabBar && selectedTab) {
  2325. this.tabBar.selectedTab = selectedTab.tab;
  2326. }
  2327. if (leavingTab?.tab !== selectedTab?.tab) {
  2328. if (leavingTab?.el) {
  2329. leavingTab.el.active = false;
  2330. }
  2331. }
  2332. if (selectedTab) {
  2333. this.ionTabsDidChange.emit({ tab: selectedTab.tab });
  2334. }
  2335. }
  2336. getSelected() {
  2337. if (this.hasTab) {
  2338. return this.selectedTab?.tab;
  2339. }
  2340. return this.outlet.getActiveStackId();
  2341. }
  2342. /**
  2343. * Detects changes to the slot attribute of the tab bar.
  2344. *
  2345. * If the slot attribute has changed, then the tab bar
  2346. * should be relocated to the new slot position.
  2347. */
  2348. detectSlotChanges() {
  2349. this.tabBars.forEach((tabBar) => {
  2350. // el is a protected attribute from the generated component wrapper
  2351. const currentSlot = tabBar.el.getAttribute('slot');
  2352. if (currentSlot !== this.tabBarSlot) {
  2353. this.tabBarSlot = currentSlot;
  2354. this.relocateTabBar();
  2355. }
  2356. });
  2357. }
  2358. /**
  2359. * Relocates the tab bar to the new slot position.
  2360. */
  2361. relocateTabBar() {
  2362. /**
  2363. * `el` is a protected attribute from the generated component wrapper.
  2364. * To avoid having to manually create the wrapper for tab bar, we
  2365. * cast the tab bar to any and access the protected attribute.
  2366. */
  2367. const tabBar = this.tabBar.el;
  2368. if (this.tabBarSlot === 'top') {
  2369. /**
  2370. * A tab bar with a slot of "top" should be inserted
  2371. * at the top of the container.
  2372. */
  2373. this.tabsInner.nativeElement.before(tabBar);
  2374. }
  2375. else {
  2376. /**
  2377. * A tab bar with a slot of "bottom" or without a slot
  2378. * should be inserted at the end of the container.
  2379. */
  2380. this.tabsInner.nativeElement.after(tabBar);
  2381. }
  2382. }
  2383. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonTabs, deps: [{ token: NavController }], target: i0.ɵɵFactoryTarget.Directive });
  2384. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: IonTabs, selector: "ion-tabs", outputs: { ionTabsWillChange: "ionTabsWillChange", ionTabsDidChange: "ionTabsDidChange" }, host: { listeners: { "ionTabButtonClick": "select($event)" } }, viewQueries: [{ propertyName: "tabsInner", first: true, predicate: ["tabsInner"], descendants: true, read: ElementRef, static: true }], ngImport: i0 });
  2385. }
  2386. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: IonTabs, decorators: [{
  2387. type: Directive,
  2388. args: [{
  2389. selector: 'ion-tabs',
  2390. }]
  2391. }], ctorParameters: function () { return [{ type: NavController }]; }, propDecorators: { tabsInner: [{
  2392. type: ViewChild,
  2393. args: ['tabsInner', { read: ElementRef, static: true }]
  2394. }], ionTabsWillChange: [{
  2395. type: Output
  2396. }], ionTabsDidChange: [{
  2397. type: Output
  2398. }], select: [{
  2399. type: HostListener,
  2400. args: ['ionTabButtonClick', ['$event']]
  2401. }] } });
  2402. const raf = (h) => {
  2403. if (typeof __zone_symbol__requestAnimationFrame === 'function') {
  2404. return __zone_symbol__requestAnimationFrame(h);
  2405. }
  2406. if (typeof requestAnimationFrame === 'function') {
  2407. return requestAnimationFrame(h);
  2408. }
  2409. return setTimeout(h);
  2410. };
  2411. // TODO(FW-2827): types
  2412. class ValueAccessor {
  2413. injector;
  2414. elementRef;
  2415. onChange = () => {
  2416. /**/
  2417. };
  2418. onTouched = () => {
  2419. /**/
  2420. };
  2421. lastValue;
  2422. statusChanges;
  2423. constructor(injector, elementRef) {
  2424. this.injector = injector;
  2425. this.elementRef = elementRef;
  2426. }
  2427. writeValue(value) {
  2428. this.elementRef.nativeElement.value = this.lastValue = value;
  2429. setIonicClasses(this.elementRef);
  2430. }
  2431. /**
  2432. * Notifies the ControlValueAccessor of a change in the value of the control.
  2433. *
  2434. * This is called by each of the ValueAccessor directives when we want to update
  2435. * the status and validity of the form control. For example with text components this
  2436. * is called when the ionInput event is fired. For select components this is called
  2437. * when the ionChange event is fired.
  2438. *
  2439. * This also updates the Ionic form status classes on the element.
  2440. *
  2441. * @param el The component element.
  2442. * @param value The new value of the control.
  2443. */
  2444. handleValueChange(el, value) {
  2445. if (el === this.elementRef.nativeElement) {
  2446. if (value !== this.lastValue) {
  2447. this.lastValue = value;
  2448. this.onChange(value);
  2449. }
  2450. setIonicClasses(this.elementRef);
  2451. }
  2452. }
  2453. _handleBlurEvent(el) {
  2454. if (el === this.elementRef.nativeElement) {
  2455. this.onTouched();
  2456. setIonicClasses(this.elementRef);
  2457. // When ion-radio is blurred, el and this.elementRef.nativeElement are
  2458. // different so we need to check if the closest ion-radio-group is the same
  2459. // as this.elementRef.nativeElement and if so, we need to mark the radio group
  2460. // as touched
  2461. }
  2462. else if (el.closest('ion-radio-group') === this.elementRef.nativeElement) {
  2463. this.onTouched();
  2464. }
  2465. }
  2466. registerOnChange(fn) {
  2467. this.onChange = fn;
  2468. }
  2469. registerOnTouched(fn) {
  2470. this.onTouched = fn;
  2471. }
  2472. setDisabledState(isDisabled) {
  2473. this.elementRef.nativeElement.disabled = isDisabled;
  2474. }
  2475. ngOnDestroy() {
  2476. if (this.statusChanges) {
  2477. this.statusChanges.unsubscribe();
  2478. }
  2479. }
  2480. ngAfterViewInit() {
  2481. let ngControl;
  2482. try {
  2483. ngControl = this.injector.get(NgControl);
  2484. }
  2485. catch {
  2486. /* No FormControl or ngModel binding */
  2487. }
  2488. if (!ngControl) {
  2489. return;
  2490. }
  2491. // Listen for changes in validity, disabled, or pending states
  2492. if (ngControl.statusChanges) {
  2493. this.statusChanges = ngControl.statusChanges.subscribe(() => setIonicClasses(this.elementRef));
  2494. }
  2495. /**
  2496. * TODO FW-2787: Remove this in favor of https://github.com/angular/angular/issues/10887
  2497. * whenever it is implemented.
  2498. */
  2499. const formControl = ngControl.control;
  2500. if (formControl) {
  2501. const methodsToPatch = ['markAsTouched', 'markAllAsTouched', 'markAsUntouched', 'markAsDirty', 'markAsPristine'];
  2502. methodsToPatch.forEach((method) => {
  2503. if (typeof formControl[method] !== 'undefined') {
  2504. const oldFn = formControl[method].bind(formControl);
  2505. formControl[method] = (...params) => {
  2506. oldFn(...params);
  2507. setIonicClasses(this.elementRef);
  2508. };
  2509. }
  2510. });
  2511. }
  2512. }
  2513. /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ValueAccessor, deps: [{ token: i0.Injector }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
  2514. /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: ValueAccessor, host: { listeners: { "ionBlur": "_handleBlurEvent($event.target)" } }, ngImport: i0 });
  2515. }
  2516. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ValueAccessor, decorators: [{
  2517. type: Directive
  2518. }], ctorParameters: function () { return [{ type: i0.Injector }, { type: i0.ElementRef }]; }, propDecorators: { _handleBlurEvent: [{
  2519. type: HostListener,
  2520. args: ['ionBlur', ['$event.target']]
  2521. }] } });
  2522. const setIonicClasses = (element) => {
  2523. raf(() => {
  2524. const input = element.nativeElement;
  2525. const hasValue = input.value != null && input.value.toString().length > 0;
  2526. const classes = getClasses(input);
  2527. setClasses(input, classes);
  2528. const item = input.closest('ion-item');
  2529. if (item) {
  2530. if (hasValue) {
  2531. setClasses(item, [...classes, 'item-has-value']);
  2532. }
  2533. else {
  2534. setClasses(item, classes);
  2535. }
  2536. }
  2537. });
  2538. };
  2539. const getClasses = (element) => {
  2540. const classList = element.classList;
  2541. const classes = [];
  2542. for (let i = 0; i < classList.length; i++) {
  2543. const item = classList.item(i);
  2544. if (item !== null && startsWith(item, 'ng-')) {
  2545. classes.push(`ion-${item.substring(3)}`);
  2546. }
  2547. }
  2548. return classes;
  2549. };
  2550. const setClasses = (element, classes) => {
  2551. const classList = element.classList;
  2552. classList.remove('ion-valid', 'ion-invalid', 'ion-touched', 'ion-untouched', 'ion-dirty', 'ion-pristine');
  2553. classList.add(...classes);
  2554. };
  2555. const startsWith = (input, search) => {
  2556. return input.substring(0, search.length) === search;
  2557. };
  2558. /**
  2559. * Provides a way to customize when activated routes get reused.
  2560. */
  2561. class IonicRouteStrategy {
  2562. /**
  2563. * Whether the given route should detach for later reuse.
  2564. */
  2565. shouldDetach(_route) {
  2566. return false;
  2567. }
  2568. /**
  2569. * Returns `false`, meaning the route (and its subtree) is never reattached
  2570. */
  2571. shouldAttach(_route) {
  2572. return false;
  2573. }
  2574. /**
  2575. * A no-op; the route is never stored since this strategy never detaches routes for later re-use.
  2576. */
  2577. store(_route, _detachedTree) {
  2578. return;
  2579. }
  2580. /**
  2581. * Returns `null` because this strategy does not store routes for later re-use.
  2582. */
  2583. retrieve(_route) {
  2584. return null;
  2585. }
  2586. /**
  2587. * Determines if a route should be reused.
  2588. * This strategy returns `true` when the future route config and
  2589. * current route config are identical and all route parameters are identical.
  2590. */
  2591. shouldReuseRoute(future, curr) {
  2592. if (future.routeConfig !== curr.routeConfig) {
  2593. return false;
  2594. }
  2595. // checking router params
  2596. const futureParams = future.params;
  2597. const currentParams = curr.params;
  2598. const keysA = Object.keys(futureParams);
  2599. const keysB = Object.keys(currentParams);
  2600. if (keysA.length !== keysB.length) {
  2601. return false;
  2602. }
  2603. // Test for A's keys different from B.
  2604. for (const key of keysA) {
  2605. if (currentParams[key] !== futureParams[key]) {
  2606. return false;
  2607. }
  2608. }
  2609. return true;
  2610. }
  2611. }
  2612. // TODO(FW-2827): types
  2613. class OverlayBaseController {
  2614. ctrl;
  2615. constructor(ctrl) {
  2616. this.ctrl = ctrl;
  2617. }
  2618. /**
  2619. * Creates a new overlay
  2620. */
  2621. create(opts) {
  2622. return this.ctrl.create((opts || {}));
  2623. }
  2624. /**
  2625. * When `id` is not provided, it dismisses the top overlay.
  2626. */
  2627. dismiss(data, role, id) {
  2628. return this.ctrl.dismiss(data, role, id);
  2629. }
  2630. /**
  2631. * Returns the top overlay.
  2632. */
  2633. getTop() {
  2634. return this.ctrl.getTop();
  2635. }
  2636. }
  2637. /**
  2638. * Generated bundle index. Do not edit.
  2639. */
  2640. export { AngularDelegate, Config, ConfigToken, DomController, IonBackButton, IonModal, IonNav, IonPopover, IonRouterOutlet, IonTabs, IonicRouteStrategy, MenuController, NavController, NavParams, OverlayBaseController, Platform, ProxyCmp, RouterLinkDelegateDirective, RouterLinkWithHrefDelegateDirective, ValueAccessor, bindLifecycleEvents, provideComponentInputBinding, raf, setIonicClasses };
  2641. //# sourceMappingURL=ionic-angular-common.mjs.map