@ionic/react 9.0.15-dev.11796247574.1ecbe59d → 9.0.15-dev.11796324133.17b57e13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import React, { useContext, useRef, useEffect, createElement, useState, useMemo, Fragment as Fragment$1, useCallback } from 'react';
3
3
  import { getPlatforms as getPlatforms$1, isPlatform as isPlatform$1, componentOnReady, createAnimation, actionSheetController, alertController, toastController, modalController, popoverController, loadingController, initialize } from '@ionic/core/components';
4
- export { IonicSafeString, IonicSlides, LogLevel, componentOnReady, createAnimation, createGesture, getIonPageElement, getMode, getTimeGivenProgression, iosTransitionAnimation, mdTransitionAnimation, menuController, openURL, setNonce } from '@ionic/core/components';
4
+ export { IonicSafeString, IonicSlides, LogLevel, createAnimation, createGesture, getIonPageElement, getTimeGivenProgression, iosTransitionAnimation, mdTransitionAnimation, openURL } from '@ionic/core/components';
5
5
  import { createComponent } from '@stencil/react-output-target/runtime';
6
6
  import { defineCustomElement as defineCustomElement$2, IonAccordion as IonAccordion$1 } from '@ionic/core/components/ion-accordion.js';
7
7
  import { defineCustomElement as defineCustomElement$3, IonAccordionGroup as IonAccordionGroup$1 } from '@ionic/core/components/ion-accordion-group.js';
@@ -1372,6 +1372,11 @@ const IonItem = /*@__PURE__*/ createRoutingComponent('ion-item', IonItem$1);
1372
1372
  const IonItemOption = /*@__PURE__*/ createRoutingComponent('ion-item-option', IonItemOption$1);
1373
1373
  const IonBreadcrumb = /*@__PURE__*/ createRoutingComponent('ion-breadcrumb', IonBreadcrumb$1);
1374
1374
 
1375
+ const StackContext = React.createContext({
1376
+ registerIonPage: () => undefined,
1377
+ isInOutlet: () => false,
1378
+ });
1379
+
1375
1380
  /**
1376
1381
  * The @stencil/react-output-target will bind event listeners for any
1377
1382
  * attached props that use the `on` prefix. This function will remove
@@ -1417,6 +1422,15 @@ const detachEvent = (node, eventName) => {
1417
1422
  * React event-delegation root.
1418
1423
  */
1419
1424
  const NestedOverlayContext = React.createContext(false);
1425
+ /**
1426
+ * Stops an `IonPage` inside the overlay from registering with the enclosing
1427
+ * outlet, which would mistake it for the route's page. An outlet inside the
1428
+ * overlay provides its own.
1429
+ */
1430
+ const outsideOutletContext = {
1431
+ registerIonPage: () => undefined,
1432
+ isInOutlet: () => false,
1433
+ };
1420
1434
  /**
1421
1435
  * React skips `componentWillUnmount` when it destroys a subtree it had already
1422
1436
  * hidden, so a hidden overlay watches its own marker leave the document. One
@@ -1715,7 +1729,7 @@ const createInlineOverlayComponent = (tagName, defineCustomElement, hasDelegateH
1715
1729
  ? createElement('div', {
1716
1730
  ref: this.wrapperRef,
1717
1731
  className: getWrapperClasses(),
1718
- }, children)
1732
+ }, createElement(StackContext.Provider, { value: outsideOutletContext }, children))
1719
1733
  : null));
1720
1734
  // The marker sits at the JSX location on both branches and leaves the
1721
1735
  // document only on a real unmount, which is how `componentWillUnmount`
@@ -1978,11 +1992,6 @@ class IonApp extends React.Component {
1978
1992
  static displayName = 'IonApp';
1979
1993
  }
1980
1994
 
1981
- const StackContext = React.createContext({
1982
- registerIonPage: () => undefined,
1983
- isInOutlet: () => false,
1984
- });
1985
-
1986
1995
  class PageManager extends React.PureComponent {
1987
1996
  ionLifeCycleContext;
1988
1997
  ionPageElementRef;
@@ -2232,10 +2241,14 @@ class OutletPageManager extends React.Component {
2232
2241
  * here -- after hydration -- ensures they persist until the parent
2233
2242
  * outlet's forward animation removes ion-page-invisible, preventing
2234
2243
  * a flash where the outlet is briefly visible at full opacity.
2244
+ * Outside an outlet (e.g. inside an inline overlay) nothing would
2245
+ * remove ion-page-invisible, so only ion-page is added there.
2235
2246
  */
2236
2247
  if (!el.classList.contains('ion-page-invisible') && !el.classList.contains('ion-page-hidden')) {
2237
2248
  el.classList.add('ion-page');
2238
- el.classList.add('ion-page-invisible');
2249
+ if (this.context.isInOutlet()) {
2250
+ el.classList.add('ion-page-invisible');
2251
+ }
2239
2252
  }
2240
2253
  this.context.registerIonPage(el, this.props.routeInfo);
2241
2254
  });
@@ -2321,6 +2334,7 @@ class IonTabs extends React.Component {
2321
2334
  routerOutletRef = React.createRef();
2322
2335
  selectTabHandler;
2323
2336
  tabBarRef = React.createRef();
2337
+ tabsElRef = React.createRef();
2324
2338
  ionTabContextState = {
2325
2339
  activeTab: undefined,
2326
2340
  selectTab: () => false,
@@ -2337,7 +2351,12 @@ class IonTabs extends React.Component {
2337
2351
  super(props);
2338
2352
  }
2339
2353
  componentDidMount() {
2340
- if (this.tabBarRef.current) {
2354
+ /**
2355
+ * Without a router outlet, the tab bar does not switch tabs,
2356
+ * so its `selectTab` and active tab must not replace the ones
2357
+ * set for `ion-tabs` in `render`.
2358
+ */
2359
+ if (this.ionTabContextState.hasRouterOutlet && this.tabBarRef.current) {
2341
2360
  // Grab initial value
2342
2361
  this.ionTabContextState.activeTab = this.tabBarRef.current.state.activeTab;
2343
2362
  // Override method
@@ -2347,6 +2366,31 @@ class IonTabs extends React.Component {
2347
2366
  this.ionTabContextState.selectTab = this.tabBarRef.current.selectTab;
2348
2367
  }
2349
2368
  }
2369
+ /**
2370
+ * Selects a tab on `ion-tabs` when it is used without a router outlet.
2371
+ * Returns `false` when no `ion-tab` has the given `tab`.
2372
+ */
2373
+ selectTabWithoutRouter = (tab) => {
2374
+ const tabsEl = this.tabsElRef.current;
2375
+ if (!tabsEl) {
2376
+ return false;
2377
+ }
2378
+ const hasTab = Array.from(tabsEl.querySelectorAll('ion-tab')).some((tabEl) => tabEl.tab === tab);
2379
+ if (!hasTab) {
2380
+ return false;
2381
+ }
2382
+ tabsEl.select(tab);
2383
+ return true;
2384
+ };
2385
+ onTabsDidChangeWithoutRouter = (event) => {
2386
+ /**
2387
+ * A tab change without a router does not re-render anything, so the
2388
+ * context needs a new value and a re-render to update its consumers.
2389
+ */
2390
+ this.ionTabContextState = { ...this.ionTabContextState, activeTab: event.detail.tab };
2391
+ this.forceUpdate();
2392
+ this.props.onIonTabsDidChange?.(event);
2393
+ };
2350
2394
  renderTabsInner(children, outlet) {
2351
2395
  return (jsx(IonTabsInner, { ...this.props, children: React.Children.map(children, (child) => {
2352
2396
  if (React.isValidElement(child)) {
@@ -2422,7 +2466,14 @@ class IonTabs extends React.Component {
2422
2466
  throw new Error('IonTabs cannot contain an IonRouterOutlet and an IonTab at the same time');
2423
2467
  }
2424
2468
  if (hasTab) {
2425
- return jsx(IonTabsInner, { ...this.props });
2469
+ /**
2470
+ * Core `ion-tabs` switches tabs and emits the tab change events
2471
+ * itself, so the tab bar gets no change handlers. Otherwise they
2472
+ * would run a second time from the tab bar's click handler.
2473
+ */
2474
+ this.ionTabContextState.tabBarProps = { ref: this.tabBarRef };
2475
+ this.ionTabContextState.selectTab = this.selectTabWithoutRouter;
2476
+ return (jsx(IonTabsContext.Provider, { value: this.ionTabContextState, children: jsx(IonTabsInner, { ...this.props, ref: this.tabsElRef, onIonTabsDidChange: this.onTabsDidChangeWithoutRouter, children: children }) }));
2426
2477
  }
2427
2478
  /**
2428
2479
  * TODO(ROU-11051)
@@ -3157,6 +3208,7 @@ const RouteManagerContext = /*@__PURE__*/ React.createContext({
3157
3208
  findViewItemByRouteInfo: () => undefined,
3158
3209
  getChildrenToRender: () => undefined,
3159
3210
  getViewItemsForOutlet: () => [],
3211
+ getLocationHistoryPathnames: () => [],
3160
3212
  goBack: () => undefined,
3161
3213
  unMountViewItem: () => undefined,
3162
3214
  });
@@ -3357,6 +3409,13 @@ class LocationHistory {
3357
3409
  canGoBack() {
3358
3410
  return this.locationHistory.length > 1;
3359
3411
  }
3412
+ /**
3413
+ * Returns the pathname of every entry in global history, oldest first.
3414
+ * The current entry is last.
3415
+ */
3416
+ getPathnames() {
3417
+ return this.locationHistory.map((ri) => ri.pathname);
3418
+ }
3360
3419
  findTabForPathname(pathname) {
3361
3420
  for (const tab of Object.keys(this.tabHistory)) {
3362
3421
  const routeInfos = this.tabHistory[tab];