UNPKG

48.9 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7const React = require('react');
8const React__default = _interopDefault(React);
9const loader = require('@ionic/core/loader');
10const ionicons = require('ionicons');
11const icons = require('ionicons/icons');
12const core = require('@ionic/core');
13const tslib = require('tslib');
14const ReactDom = _interopDefault(require('react-dom'));
15
16const IonLifeCycleContext = /*@__PURE__*/ React__default.createContext({
17 onIonViewWillEnter: () => { return; },
18 ionViewWillEnter: () => { return; },
19 onIonViewDidEnter: () => { return; },
20 ionViewDidEnter: () => { return; },
21 onIonViewWillLeave: () => { return; },
22 ionViewWillLeave: () => { return; },
23 onIonViewDidLeave: () => { return; },
24 ionViewDidLeave: () => { return; },
25});
26const DefaultIonLifeCycleContext = class {
27 constructor() {
28 this.ionViewWillEnterCallbacks = [];
29 this.ionViewDidEnterCallbacks = [];
30 this.ionViewWillLeaveCallbacks = [];
31 this.ionViewDidLeaveCallbacks = [];
32 }
33 onIonViewWillEnter(callback) {
34 if (callback.id) {
35 const index = this.ionViewWillEnterCallbacks.findIndex(x => x.id === callback.id);
36 if (index > -1) {
37 this.ionViewWillEnterCallbacks[index] = callback;
38 }
39 else {
40 this.ionViewWillEnterCallbacks.push(callback);
41 }
42 }
43 else {
44 this.ionViewWillEnterCallbacks.push(callback);
45 }
46 }
47 ionViewWillEnter() {
48 this.ionViewWillEnterCallbacks.forEach(cb => cb());
49 }
50 onIonViewDidEnter(callback) {
51 if (callback.id) {
52 const index = this.ionViewDidEnterCallbacks.findIndex(x => x.id === callback.id);
53 if (index > -1) {
54 this.ionViewDidEnterCallbacks[index] = callback;
55 }
56 else {
57 this.ionViewDidEnterCallbacks.push(callback);
58 }
59 }
60 else {
61 this.ionViewDidEnterCallbacks.push(callback);
62 }
63 }
64 ionViewDidEnter() {
65 this.ionViewDidEnterCallbacks.forEach(cb => cb());
66 }
67 onIonViewWillLeave(callback) {
68 if (callback.id) {
69 const index = this.ionViewWillLeaveCallbacks.findIndex(x => x.id === callback.id);
70 if (index > -1) {
71 this.ionViewWillLeaveCallbacks[index] = callback;
72 }
73 else {
74 this.ionViewWillLeaveCallbacks.push(callback);
75 }
76 }
77 else {
78 this.ionViewWillLeaveCallbacks.push(callback);
79 }
80 }
81 ionViewWillLeave() {
82 this.ionViewWillLeaveCallbacks.forEach(cb => cb());
83 }
84 onIonViewDidLeave(callback) {
85 if (callback.id) {
86 const index = this.ionViewDidLeaveCallbacks.findIndex(x => x.id === callback.id);
87 if (index > -1) {
88 this.ionViewDidLeaveCallbacks[index] = callback;
89 }
90 else {
91 this.ionViewDidLeaveCallbacks.push(callback);
92 }
93 }
94 else {
95 this.ionViewDidLeaveCallbacks.push(callback);
96 }
97 }
98 ionViewDidLeave() {
99 this.ionViewDidLeaveCallbacks.forEach(cb => cb());
100 this.componentCanBeDestroyed();
101 }
102 onComponentCanBeDestroyed(callback) {
103 this.componentCanBeDestroyedCallback = callback;
104 }
105 componentCanBeDestroyed() {
106 if (this.componentCanBeDestroyedCallback) {
107 this.componentCanBeDestroyedCallback();
108 }
109 }
110};
111
112const withIonLifeCycle = (WrappedComponent) => {
113 return class IonLifeCycle extends React__default.Component {
114 constructor(props) {
115 super(props);
116 this.componentRef = React__default.createRef();
117 }
118 componentDidMount() {
119 const element = this.componentRef.current;
120 this.context.onIonViewWillEnter(() => {
121 if (element && element.ionViewWillEnter) {
122 element.ionViewWillEnter();
123 }
124 });
125 this.context.onIonViewDidEnter(() => {
126 if (element && element.ionViewDidEnter) {
127 element.ionViewDidEnter();
128 }
129 });
130 this.context.onIonViewWillLeave(() => {
131 if (element && element.ionViewWillLeave) {
132 element.ionViewWillLeave();
133 }
134 });
135 this.context.onIonViewDidLeave(() => {
136 if (element && element.ionViewDidLeave) {
137 element.ionViewDidLeave();
138 }
139 });
140 }
141 render() {
142 return (React__default.createElement(IonLifeCycleContext.Consumer, null, context => {
143 this.context = context;
144 return (React__default.createElement(WrappedComponent, Object.assign({ ref: this.componentRef }, this.props)));
145 }));
146 }
147 };
148};
149
150const useIonViewWillEnter = (callback, deps = []) => {
151 const context = React.useContext(IonLifeCycleContext);
152 const id = React.useRef();
153 id.current = id.current || Math.floor(Math.random() * 1000000);
154 React.useEffect(() => {
155 callback.id = id.current;
156 context.onIonViewWillEnter(callback);
157 }, deps);
158};
159const useIonViewDidEnter = (callback, deps = []) => {
160 const context = React.useContext(IonLifeCycleContext);
161 const id = React.useRef();
162 id.current = id.current || Math.floor(Math.random() * 1000000);
163 React.useEffect(() => {
164 callback.id = id.current;
165 context.onIonViewDidEnter(callback);
166 }, deps);
167};
168const useIonViewWillLeave = (callback, deps = []) => {
169 const context = React.useContext(IonLifeCycleContext);
170 const id = React.useRef();
171 id.current = id.current || Math.floor(Math.random() * 1000000);
172 React.useEffect(() => {
173 callback.id = id.current;
174 context.onIonViewWillLeave(callback);
175 }, deps);
176};
177const useIonViewDidLeave = (callback, deps = []) => {
178 const context = React.useContext(IonLifeCycleContext);
179 const id = React.useRef();
180 id.current = id.current || Math.floor(Math.random() * 1000000);
181 React.useEffect(() => {
182 callback.id = id.current;
183 context.onIonViewDidLeave(callback);
184 }, deps);
185};
186
187const NavContext = /*@__PURE__*/ React__default.createContext({
188 getPageManager: () => undefined,
189 getStackManager: () => undefined,
190 goBack: (defaultHref) => {
191 if (defaultHref !== undefined) {
192 window.location.pathname = defaultHref;
193 }
194 else {
195 window.history.back();
196 }
197 },
198 navigate: (path) => { window.location.pathname = path; },
199 hasIonicRouter: () => false,
200 registerIonPage: () => undefined,
201 currentPath: undefined
202});
203
204const dashToPascalCase = (str) => str.toLowerCase().split('-').map(segment => segment.charAt(0).toUpperCase() + segment.slice(1)).join('');
205const camelToDashCase = (str) => str.replace(/([A-Z])/g, (m) => `-${m[0].toLowerCase()}`);
206
207const attachProps = (node, newProps, oldProps = {}) => {
208 // some test frameworks don't render DOM elements, so we test here to make sure we are dealing with DOM first
209 if (node instanceof Element) {
210 // add any classes in className to the class list
211 const className = getClassName(node.classList, newProps, oldProps);
212 if (className !== '') {
213 node.className = className;
214 }
215 Object.keys(newProps).forEach(name => {
216 if (name === 'children' || name === 'style' || name === 'ref' || name === 'class' || name === 'className' || name === 'forwardedRef') {
217 return;
218 }
219 if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
220 const eventName = name.substring(2);
221 const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
222 if (!isCoveredByReact(eventNameLc)) {
223 syncEvent(node, eventNameLc, newProps[name]);
224 }
225 }
226 else {
227 node[name] = newProps[name];
228 const propType = typeof newProps[name];
229 if (propType === 'string') {
230 node.setAttribute(camelToDashCase(name), newProps[name]);
231 }
232 else {
233 node[name] = newProps[name];
234 }
235 }
236 });
237 }
238};
239const getClassName = (classList, newProps, oldProps) => {
240 const newClassProp = newProps.className || newProps.class;
241 const oldClassProp = oldProps.className || oldProps.class;
242 // map the classes to Maps for performance
243 const currentClasses = arrayToMap(classList);
244 const incomingPropClasses = arrayToMap(newClassProp ? newClassProp.split(' ') : []);
245 const oldPropClasses = arrayToMap(oldClassProp ? oldClassProp.split(' ') : []);
246 const finalClassNames = [];
247 // loop through each of the current classes on the component
248 // to see if it should be a part of the classNames added
249 currentClasses.forEach(currentClass => {
250 if (incomingPropClasses.has(currentClass)) {
251 // add it as its already included in classnames coming in from newProps
252 finalClassNames.push(currentClass);
253 incomingPropClasses.delete(currentClass);
254 }
255 else if (!oldPropClasses.has(currentClass)) {
256 // add it as it has NOT been removed by user
257 finalClassNames.push(currentClass);
258 }
259 });
260 incomingPropClasses.forEach(s => finalClassNames.push(s));
261 return finalClassNames.join(' ');
262};
263/**
264 * Checks if an event is supported in the current execution environment.
265 * @license Modernizr 3.0.0pre (Custom Build) | MIT
266 */
267const isCoveredByReact = (eventNameSuffix, doc = document) => {
268 const eventName = 'on' + eventNameSuffix;
269 let isSupported = eventName in doc;
270 if (!isSupported) {
271 const element = doc.createElement('div');
272 element.setAttribute(eventName, 'return;');
273 isSupported = typeof element[eventName] === 'function';
274 }
275 return isSupported;
276};
277const syncEvent = (node, eventName, newEventHandler) => {
278 const eventStore = node.__events || (node.__events = {});
279 const oldEventHandler = eventStore[eventName];
280 // Remove old listener so they don't double up.
281 if (oldEventHandler) {
282 node.removeEventListener(eventName, oldEventHandler);
283 }
284 // Bind new listener.
285 node.addEventListener(eventName, eventStore[eventName] = function handler(e) {
286 if (newEventHandler) {
287 newEventHandler.call(this, e);
288 }
289 });
290};
291const arrayToMap = (arr) => {
292 const map = new Map();
293 arr.forEach((s) => map.set(s, s));
294 return map;
295};
296
297const createForwardRef = (ReactComponent, displayName) => {
298 const forwardRef = (props, ref) => {
299 return React__default.createElement(ReactComponent, Object.assign({}, props, { forwardedRef: ref }));
300 };
301 forwardRef.displayName = displayName;
302 return React__default.forwardRef(forwardRef);
303};
304const isPlatform = (platform) => {
305 return core.isPlatform(window, platform);
306};
307const getPlatforms = () => {
308 return core.getPlatforms(window);
309};
310const getConfig = () => {
311 if (typeof window !== 'undefined') {
312 const Ionic = window.Ionic;
313 if (Ionic && Ionic.config) {
314 return Ionic.config;
315 }
316 }
317 return null;
318};
319
320const createReactComponent = (tagName, routerLinkComponent = false) => {
321 const displayName = dashToPascalCase(tagName);
322 const ReactComponent = class extends React__default.Component {
323 constructor(props) {
324 super(props);
325 this.handleClick = (e) => {
326 const { routerLink, routerDirection } = this.props;
327 if (routerLink !== undefined) {
328 e.preventDefault();
329 this.context.navigate(routerLink, routerDirection);
330 }
331 };
332 }
333 componentDidMount() {
334 this.componentDidUpdate(this.props);
335 }
336 componentDidUpdate(prevProps) {
337 const node = ReactDom.findDOMNode(this);
338 attachProps(node, this.props, prevProps);
339 }
340 render() {
341 const _a = this.props, { children, forwardedRef, style, className, ref } = _a, cProps = tslib.__rest(_a, ["children", "forwardedRef", "style", "className", "ref"]);
342 const propsToPass = Object.keys(cProps).reduce((acc, name) => {
343 if (name.indexOf('on') === 0 && name[2] === name[2].toUpperCase()) {
344 const eventName = name.substring(2).toLowerCase();
345 if (isCoveredByReact(eventName)) {
346 acc[name] = cProps[name];
347 }
348 }
349 return acc;
350 }, {});
351 const newProps = Object.assign(Object.assign({}, propsToPass), { ref: forwardedRef, style });
352 if (routerLinkComponent) {
353 if (this.props.routerLink && !this.props.href) {
354 newProps.href = this.props.routerLink;
355 }
356 if (newProps.onClick) {
357 const oldClick = newProps.onClick;
358 newProps.onClick = (e) => {
359 oldClick(e);
360 if (!e.defaultPrevented) {
361 this.handleClick(e);
362 }
363 };
364 }
365 else {
366 newProps.onClick = this.handleClick;
367 }
368 }
369 return React__default.createElement(tagName, newProps, children);
370 }
371 static get displayName() {
372 return displayName;
373 }
374 static get contextType() {
375 return NavContext;
376 }
377 };
378 return createForwardRef(ReactComponent, displayName);
379};
380
381// ionic/core
382const IonApp = /*@__PURE__*/ createReactComponent('ion-app');
383const IonTab = /*@__PURE__*/ createReactComponent('ion-tab');
384const IonTabButton = /*@__PURE__*/ createReactComponent('ion-tab-button');
385const IonRouterLink = /*@__PURE__*/ createReactComponent('ion-router-link', true);
386const IonAvatar = /*@__PURE__*/ createReactComponent('ion-avatar');
387const IonBackdrop = /*@__PURE__*/ createReactComponent('ion-backdrop');
388const IonBadge = /*@__PURE__*/ createReactComponent('ion-badge');
389const IonButton = /*@__PURE__*/ createReactComponent('ion-button', true);
390const IonButtons = /*@__PURE__*/ createReactComponent('ion-buttons');
391const IonCard = /*@__PURE__*/ createReactComponent('ion-card', true);
392const IonCardContent = /*@__PURE__*/ createReactComponent('ion-card-content');
393const IonCardHeader = /*@__PURE__*/ createReactComponent('ion-card-header');
394const IonCardSubtitle = /*@__PURE__*/ createReactComponent('ion-card-subtitle');
395const IonCardTitle = /*@__PURE__*/ createReactComponent('ion-card-title');
396const IonCheckbox = /*@__PURE__*/ createReactComponent('ion-checkbox');
397const IonCol = /*@__PURE__*/ createReactComponent('ion-col');
398const IonContent = /*@__PURE__*/ createReactComponent('ion-content');
399const IonChip = /*@__PURE__*/ createReactComponent('ion-chip');
400const IonDatetime = /*@__PURE__*/ createReactComponent('ion-datetime');
401const IonFab = /*@__PURE__*/ createReactComponent('ion-fab');
402const IonFabButton = /*@__PURE__*/ createReactComponent('ion-fab-button', true);
403const IonFabList = /*@__PURE__*/ createReactComponent('ion-fab-list');
404const IonFooter = /*@__PURE__*/ createReactComponent('ion-footer');
405const IonGrid = /*@__PURE__*/ createReactComponent('ion-grid');
406const IonHeader = /*@__PURE__*/ createReactComponent('ion-header');
407const IonImg = /*@__PURE__*/ createReactComponent('ion-img');
408const IonInfiniteScroll = /*@__PURE__*/ createReactComponent('ion-infinite-scroll');
409const IonInfiniteScrollContent = /*@__PURE__*/ createReactComponent('ion-infinite-scroll-content');
410const IonInput = /*@__PURE__*/ createReactComponent('ion-input');
411const IonItem = /*@__PURE__*/ createReactComponent('ion-item', true);
412const IonItemDivider = /*@__PURE__*/ createReactComponent('ion-item-divider');
413const IonItemGroup = /*@__PURE__*/ createReactComponent('ion-item-group');
414const IonItemOption = /*@__PURE__*/ createReactComponent('ion-item-option', true);
415const IonItemOptions = /*@__PURE__*/ createReactComponent('ion-item-options');
416const IonItemSliding = /*@__PURE__*/ createReactComponent('ion-item-sliding');
417const IonLabel = /*@__PURE__*/ createReactComponent('ion-label');
418const IonList = /*@__PURE__*/ createReactComponent('ion-list');
419const IonListHeader = /*@__PURE__*/ createReactComponent('ion-list-header');
420const IonMenu = /*@__PURE__*/ createReactComponent('ion-menu');
421const IonMenuButton = /*@__PURE__*/ createReactComponent('ion-menu-button');
422const IonMenuToggle = /*@__PURE__*/ createReactComponent('ion-menu-toggle');
423const IonNote = /*@__PURE__*/ createReactComponent('ion-note');
424const IonPickerColumn = /*@__PURE__*/ createReactComponent('ion-picker-column');
425const IonNav = /*@__PURE__*/ createReactComponent('ion-nav');
426const IonProgressBar = /*@__PURE__*/ createReactComponent('ion-progress-bar');
427const IonRadio = /*@__PURE__*/ createReactComponent('ion-radio');
428const IonRadioGroup = /*@__PURE__*/ createReactComponent('ion-radio-group');
429const IonRange = /*@__PURE__*/ createReactComponent('ion-range');
430const IonRefresher = /*@__PURE__*/ createReactComponent('ion-refresher');
431const IonRefresherContent = /*@__PURE__*/ createReactComponent('ion-refresher-content');
432const IonReorder = /*@__PURE__*/ createReactComponent('ion-reorder');
433const IonReorderGroup = /*@__PURE__*/ createReactComponent('ion-reorder-group');
434const IonRippleEffect = /*@__PURE__*/ createReactComponent('ion-ripple-effect');
435const IonRow = /*@__PURE__*/ createReactComponent('ion-row');
436const IonSearchbar = /*@__PURE__*/ createReactComponent('ion-searchbar');
437const IonSegment = /*@__PURE__*/ createReactComponent('ion-segment');
438const IonSegmentButton = /*@__PURE__*/ createReactComponent('ion-segment-button');
439const IonSelect = /*@__PURE__*/ createReactComponent('ion-select');
440const IonSelectOption = /*@__PURE__*/ createReactComponent('ion-select-option');
441const IonSelectPopover = /*@__PURE__*/ createReactComponent('ion-select-popover');
442const IonSkeletonText = /*@__PURE__*/ createReactComponent('ion-skeleton-text');
443const IonSlide = /*@__PURE__*/ createReactComponent('ion-slide');
444const IonSlides = /*@__PURE__*/ createReactComponent('ion-slides');
445const IonSpinner = /*@__PURE__*/ createReactComponent('ion-spinner');
446const IonSplitPane = /*@__PURE__*/ createReactComponent('ion-split-pane');
447const IonText = /*@__PURE__*/ createReactComponent('ion-text');
448const IonTextarea = /*@__PURE__*/ createReactComponent('ion-textarea');
449const IonThumbnail = /*@__PURE__*/ createReactComponent('ion-thumbnail');
450const IonTitle = /*@__PURE__*/ createReactComponent('ion-title');
451const IonToggle = /*@__PURE__*/ createReactComponent('ion-toggle');
452const IonToolbar = /*@__PURE__*/ createReactComponent('ion-toolbar');
453const IonVirtualScroll = /*@__PURE__*/ createReactComponent('ion-virtual-scroll');
454
455const createControllerComponent = (displayName, controller) => {
456 const didDismissEventName = `on${displayName}DidDismiss`;
457 const didPresentEventName = `on${displayName}DidPresent`;
458 const willDismissEventName = `on${displayName}WillDismiss`;
459 const willPresentEventName = `on${displayName}WillPresent`;
460 class Overlay extends React__default.Component {
461 constructor(props) {
462 super(props);
463 this.isUnmounted = false;
464 this.handleDismiss = this.handleDismiss.bind(this);
465 }
466 static get displayName() {
467 return displayName;
468 }
469 async componentDidMount() {
470 const { isOpen } = this.props;
471 if (isOpen) {
472 this.present();
473 }
474 }
475 componentWillUnmount() {
476 this.isUnmounted = true;
477 if (this.overlay) {
478 this.overlay.dismiss();
479 }
480 }
481 async componentDidUpdate(prevProps) {
482 if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
483 this.present(prevProps);
484 }
485 if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
486 await this.overlay.dismiss();
487 }
488 }
489 handleDismiss(event) {
490 if (this.props.onDidDismiss) {
491 this.props.onDidDismiss(event);
492 }
493 if (this.props.forwardedRef) {
494 this.props.forwardedRef.current = undefined;
495 }
496 }
497 async present(prevProps) {
498 const _a = this.props, cProps = tslib.__rest(_a, ["isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]);
499 this.overlay = await controller.create(Object.assign({}, cProps));
500 attachProps(this.overlay, {
501 [didDismissEventName]: this.handleDismiss,
502 [didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e),
503 [willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e),
504 [willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e)
505 }, prevProps);
506 // Check isOpen again since the value could have changed during the async call to controller.create
507 // It's also possible for the component to have become unmounted.
508 if (this.props.isOpen === true && this.isUnmounted === false) {
509 if (this.props.forwardedRef) {
510 this.props.forwardedRef.current = this.overlay;
511 }
512 await this.overlay.present();
513 }
514 }
515 render() {
516 return null;
517 }
518 }
519 return React__default.forwardRef((props, ref) => {
520 return React__default.createElement(Overlay, Object.assign({}, props, { forwardedRef: ref }));
521 });
522};
523
524const IonAlert = /*@__PURE__*/ createControllerComponent('IonAlert', core.alertController);
525
526const IonLoading = /*@__PURE__*/ createControllerComponent('IonLoading', core.loadingController);
527
528const toastController = {
529 create: (options) => core.toastController.create(options),
530 dismiss: (data, role, id) => core.toastController.dismiss(data, role, id),
531 getTop: () => core.toastController.getTop()
532};
533const IonToast = /*@__PURE__*/ createControllerComponent('IonToast', toastController);
534
535const IonPicker = /*@__PURE__*/ createControllerComponent('IonPicker', core.pickerController);
536
537const createOverlayComponent = (displayName, controller) => {
538 const didDismissEventName = `on${displayName}DidDismiss`;
539 const didPresentEventName = `on${displayName}DidPresent`;
540 const willDismissEventName = `on${displayName}WillDismiss`;
541 const willPresentEventName = `on${displayName}WillPresent`;
542 class Overlay extends React__default.Component {
543 constructor(props) {
544 super(props);
545 this.el = document.createElement('div');
546 this.handleDismiss = this.handleDismiss.bind(this);
547 }
548 static get displayName() {
549 return displayName;
550 }
551 componentDidMount() {
552 if (this.props.isOpen) {
553 this.present();
554 }
555 }
556 componentWillUnmount() {
557 if (this.overlay) {
558 this.overlay.dismiss();
559 }
560 }
561 handleDismiss(event) {
562 if (this.props.onDidDismiss) {
563 this.props.onDidDismiss(event);
564 }
565 if (this.props.forwardedRef) {
566 this.props.forwardedRef.current = undefined;
567 }
568 }
569 async componentDidUpdate(prevProps) {
570 if (this.overlay) {
571 attachProps(this.overlay, this.props, prevProps);
572 }
573 if (prevProps.isOpen !== this.props.isOpen && this.props.isOpen === true) {
574 this.present(prevProps);
575 }
576 if (this.overlay && prevProps.isOpen !== this.props.isOpen && this.props.isOpen === false) {
577 await this.overlay.dismiss();
578 }
579 }
580 async present(prevProps) {
581 const _a = this.props, cProps = tslib.__rest(_a, ["children", "isOpen", "onDidDismiss", "onDidPresent", "onWillDismiss", "onWillPresent"]);
582 const elementProps = Object.assign(Object.assign({}, cProps), { ref: this.props.forwardedRef, [didDismissEventName]: this.handleDismiss, [didPresentEventName]: (e) => this.props.onDidPresent && this.props.onDidPresent(e), [willDismissEventName]: (e) => this.props.onWillDismiss && this.props.onWillDismiss(e), [willPresentEventName]: (e) => this.props.onWillPresent && this.props.onWillPresent(e) });
583 this.overlay = await controller.create(Object.assign(Object.assign({}, elementProps), { component: this.el, componentProps: {} }));
584 if (this.props.forwardedRef) {
585 this.props.forwardedRef.current = this.overlay;
586 }
587 attachProps(this.overlay, elementProps, prevProps);
588 await this.overlay.present();
589 }
590 render() {
591 return ReactDom.createPortal(this.props.isOpen ? this.props.children : null, this.el);
592 }
593 }
594 return React__default.forwardRef((props, ref) => {
595 return React__default.createElement(Overlay, Object.assign({}, props, { forwardedRef: ref }));
596 });
597};
598
599const actionSheetController = {
600 create: (options) => core.actionSheetController.create(options),
601 dismiss: (data, role, id) => core.actionSheetController.dismiss(data, role, id),
602 getTop: () => core.actionSheetController.getTop()
603};
604const IonActionSheet = /*@__PURE__*/ createOverlayComponent('IonActionSheet', actionSheetController);
605
606const IonModal = /*@__PURE__*/ createOverlayComponent('IonModal', core.modalController);
607
608const IonPopover = /*@__PURE__*/ createOverlayComponent('IonPopover', core.popoverController);
609
610class IonPageInternal extends React__default.Component {
611 constructor(props) {
612 super(props);
613 this.ref = this.props.forwardedRef || React__default.createRef();
614 }
615 componentDidMount() {
616 if (this.context && this.ref && this.ref.current) {
617 if (this.context.hasIonicRouter()) {
618 this.context.registerIonPage(this.ref.current);
619 }
620 }
621 }
622 render() {
623 const _a = this.props, { className, children, forwardedRef } = _a, props = tslib.__rest(_a, ["className", "children", "forwardedRef"]);
624 return (React__default.createElement("div", Object.assign({ className: className ? `ion-page ${className}` : 'ion-page', ref: this.ref }, props), children));
625 }
626 static get displayName() {
627 return 'IonPage';
628 }
629 static get contextType() {
630 return NavContext;
631 }
632}
633const IonPage = createForwardRef(IonPageInternal, 'IonPage');
634
635const IonTabsContext = React__default.createContext({
636 activeTab: undefined,
637 selectTab: () => false
638});
639
640const IonTabBarInner = /*@__PURE__*/ createReactComponent('ion-tab-bar');
641const IonBackButtonInner = /*@__PURE__*/ createReactComponent('ion-back-button');
642const IonRouterOutletInner = /*@__PURE__*/ createReactComponent('ion-router-outlet');
643// ionicons
644const IonIconInner = /*@__PURE__*/ createReactComponent('ion-icon');
645
646const IonRouterOutletContainer = /*@__PURE__*/ (() => class extends React__default.Component {
647 render() {
648 const StackManager = this.context.getStackManager();
649 return (this.context.hasIonicRouter() ? (React__default.createElement(StackManager, null,
650 React__default.createElement(IonRouterOutletInner, Object.assign({ ref: this.props.forwardedRef }, this.props), this.props.children))) : (React__default.createElement(IonRouterOutletInner, Object.assign({ ref: this.props.forwardedRef }, this.props), this.props.children)));
651 }
652 static get contextType() {
653 return NavContext;
654 }
655})();
656const IonRouterOutlet = createForwardRef(IonRouterOutletContainer, 'IonRouterOutlet');
657
658class IonTabBarUnwrapped extends React__default.PureComponent {
659 constructor(props) {
660 super(props);
661 this.setActiveTabOnContext = (_tab) => { };
662 const tabs = {};
663 React__default.Children.forEach(props.children, (child) => {
664 if (child != null && typeof child === 'object' && child.props && child.type === IonTabButton) {
665 tabs[child.props.tab] = {
666 originalHref: child.props.href,
667 currentHref: child.props.href
668 };
669 }
670 });
671 const tabKeys = Object.keys(tabs);
672 const activeTab = tabKeys
673 .find(key => {
674 const href = tabs[key].originalHref;
675 return props.currentPath.startsWith(href);
676 }) || tabKeys[0];
677 this.state = {
678 activeTab,
679 tabs
680 };
681 this.onTabButtonClick = this.onTabButtonClick.bind(this);
682 this.renderTabButton = this.renderTabButton.bind(this);
683 this.setActiveTabOnContext = this.setActiveTabOnContext.bind(this);
684 this.selectTab = this.selectTab.bind(this);
685 }
686 selectTab(tab) {
687 const tabUrl = this.state.tabs[tab];
688 if (tabUrl) {
689 this.onTabButtonClick(new CustomEvent('ionTabButtonClick', {
690 detail: {
691 href: tabUrl.currentHref,
692 tab,
693 selected: tab === this.state.activeTab
694 }
695 }));
696 return true;
697 }
698 return false;
699 }
700 static getDerivedStateFromProps(props, state) {
701 const tabs = Object.assign({}, state.tabs);
702 const activeTab = Object.keys(state.tabs)
703 .find(key => {
704 const href = state.tabs[key].originalHref;
705 return props.currentPath.startsWith(href);
706 });
707 // Check to see if the tab button href has changed, and if so, update it in the tabs state
708 React__default.Children.forEach(props.children, (child) => {
709 if (child != null && typeof child === 'object' && child.props && child.type === IonTabButton) {
710 const tab = tabs[child.props.tab];
711 if (tab.originalHref !== child.props.href) {
712 tabs[child.props.tab] = {
713 originalHref: child.props.href,
714 currentHref: child.props.href
715 };
716 }
717 }
718 });
719 if (!(activeTab === undefined || (activeTab === state.activeTab && state.tabs[activeTab].currentHref === props.currentPath))) {
720 tabs[activeTab] = {
721 originalHref: tabs[activeTab].originalHref,
722 currentHref: props.currentPath
723 };
724 }
725 return {
726 activeTab,
727 tabs
728 };
729 }
730 onTabButtonClick(e) {
731 const originalHref = this.state.tabs[e.detail.tab].originalHref;
732 const currentHref = e.detail.href;
733 const { activeTab: prevActiveTab } = this.state;
734 // Clicking the current tab will bring you back to the original href
735 if (prevActiveTab === e.detail.tab) {
736 if (originalHref === currentHref) {
737 this.context.navigate(originalHref, 'none');
738 }
739 else {
740 this.context.navigate(originalHref, 'back', 'pop');
741 }
742 }
743 else {
744 if (this.props.onIonTabsWillChange) {
745 this.props.onIonTabsWillChange(new CustomEvent('ionTabWillChange', { detail: { tab: e.detail.tab } }));
746 }
747 if (this.props.onIonTabsDidChange) {
748 this.props.onIonTabsDidChange(new CustomEvent('ionTabDidChange', { detail: { tab: e.detail.tab } }));
749 }
750 this.setActiveTabOnContext(e.detail.tab);
751 this.context.navigate(currentHref, 'none');
752 }
753 }
754 renderTabButton(activeTab) {
755 return (child) => {
756 if (child != null && child.props && child.type === IonTabButton) {
757 const href = (child.props.tab === activeTab) ? this.props.currentPath : (this.state.tabs[child.props.tab].currentHref);
758 return React__default.cloneElement(child, {
759 href,
760 onIonTabButtonClick: this.onTabButtonClick
761 });
762 }
763 return null;
764 };
765 }
766 render() {
767 const { activeTab } = this.state;
768 return (React__default.createElement(IonTabBarInner, Object.assign({}, this.props, { selectedTab: activeTab }), React__default.Children.map(this.props.children, this.renderTabButton(activeTab))));
769 }
770 static get contextType() {
771 return NavContext;
772 }
773}
774const IonTabBarContainer = React__default.memo((_a) => {
775 var { forwardedRef } = _a, props = tslib.__rest(_a, ["forwardedRef"]);
776 const context = React.useContext(NavContext);
777 return (React__default.createElement(IonTabBarUnwrapped, Object.assign({ ref: forwardedRef }, props, { currentPath: props.currentPath || context.currentPath }), props.children));
778});
779const IonTabBar = createForwardRef(IonTabBarContainer, 'IonTabBar');
780
781const hostStyles = {
782 display: 'flex',
783 position: 'absolute',
784 top: '0',
785 left: '0',
786 right: '0',
787 bottom: '0',
788 flexDirection: 'column',
789 width: '100%',
790 height: '100%',
791 contain: 'layout size style'
792};
793const tabsInner = {
794 position: 'relative',
795 flex: 1,
796 contain: 'layout size style'
797};
798class IonTabs extends React__default.Component {
799 constructor(props) {
800 super(props);
801 this.routerOutletRef = React__default.createRef();
802 this.tabBarRef = React__default.createRef();
803 this.ionTabContextState = {
804 activeTab: undefined,
805 selectTab: () => false
806 };
807 }
808 componentDidMount() {
809 if (this.tabBarRef.current) {
810 // Grab initial value
811 this.ionTabContextState.activeTab = this.tabBarRef.current.state.activeTab;
812 // Override method
813 this.tabBarRef.current.setActiveTabOnContext = (tab) => {
814 this.ionTabContextState.activeTab = tab;
815 };
816 this.ionTabContextState.selectTab = this.tabBarRef.current.selectTab;
817 }
818 }
819 render() {
820 let outlet;
821 let tabBar;
822 const children = typeof this.props.children === 'function' ?
823 this.props.children(this.ionTabContextState) : this.props.children;
824 React__default.Children.forEach(children, (child) => {
825 if (child == null || typeof child !== 'object' || !child.hasOwnProperty('type')) {
826 return;
827 }
828 if (child.type === IonRouterOutlet) {
829 outlet = child;
830 }
831 else if (child.type === React.Fragment && child.props.children[0].type === IonRouterOutlet) {
832 outlet = child.props.children[0];
833 }
834 if (child.type === IonTabBar) {
835 const { onIonTabsDidChange, onIonTabsWillChange } = this.props;
836 tabBar = React__default.cloneElement(child, {
837 onIonTabsDidChange,
838 onIonTabsWillChange,
839 ref: this.tabBarRef
840 });
841 }
842 else if (child.type === React.Fragment && child.props.children[1].type === IonTabBar) {
843 const { onIonTabsDidChange, onIonTabsWillChange } = this.props;
844 tabBar = React__default.cloneElement(child.props.children[1], {
845 onIonTabsDidChange,
846 onIonTabsWillChange,
847 ref: this.tabBarRef
848 });
849 }
850 });
851 if (!outlet) {
852 throw new Error('IonTabs must contain an IonRouterOutlet');
853 }
854 if (!tabBar) {
855 // TODO, this is not required
856 throw new Error('IonTabs needs a IonTabBar');
857 }
858 return (React__default.createElement(IonTabsContext.Provider, { value: this.ionTabContextState },
859 React__default.createElement("div", { style: hostStyles },
860 tabBar.props.slot === 'top' ? tabBar : null,
861 React__default.createElement("div", { style: tabsInner, className: "tabs-inner" }, outlet),
862 tabBar.props.slot === 'bottom' ? tabBar : null)));
863 }
864 static get contextType() {
865 return NavContext;
866 }
867}
868
869const IonBackButton = /*@__PURE__*/ (() => class extends React__default.Component {
870 constructor() {
871 super(...arguments);
872 this.clickButton = (e) => {
873 const defaultHref = this.props.defaultHref;
874 if (this.context.hasIonicRouter()) {
875 e.stopPropagation();
876 this.context.goBack(defaultHref);
877 }
878 else if (defaultHref !== undefined) {
879 window.location.href = defaultHref;
880 }
881 };
882 }
883 render() {
884 return (React__default.createElement(IonBackButtonInner, Object.assign({ onClick: this.clickButton }, this.props)));
885 }
886 static get displayName() {
887 return 'IonBackButton';
888 }
889 static get contextType() {
890 return NavContext;
891 }
892})();
893
894const isDevMode = () => {
895 return process && process.env && process.env.NODE_ENV === 'development';
896};
897const warnings = {};
898const deprecationWarning = (key, message) => {
899 if (isDevMode()) {
900 if (!warnings[key]) {
901 console.warn(message);
902 warnings[key] = true;
903 }
904 }
905};
906
907class IonIconContainer extends React__default.PureComponent {
908 constructor(props) {
909 super(props);
910 if (this.props.name) {
911 deprecationWarning('icon-name', 'In Ionic React, you import icons from "ionicons/icons" and set the icon you imported to the "icon" property. Setting the "name" property has no effect.');
912 }
913 }
914 render() {
915 var _a, _b;
916 const _c = this.props, { icon, ios, md } = _c, rest = tslib.__rest(_c, ["icon", "ios", "md"]);
917 let iconToUse;
918 if (ios || md) {
919 if (isPlatform('ios')) {
920 iconToUse = (_a = ios !== null && ios !== void 0 ? ios : md) !== null && _a !== void 0 ? _a : icon;
921 }
922 else {
923 iconToUse = (_b = md !== null && md !== void 0 ? md : ios) !== null && _b !== void 0 ? _b : icon;
924 }
925 }
926 else {
927 iconToUse = icon;
928 }
929 return (React__default.createElement(IonIconInner, Object.assign({ ref: this.props.forwardedRef, icon: iconToUse }, rest), this.props.children));
930 }
931 static get contextType() {
932 return NavContext;
933 }
934}
935const IonIcon = createForwardRef(IonIconContainer, 'IonIcon');
936
937class CreateAnimation extends React__default.PureComponent {
938 constructor(props) {
939 super(props);
940 this.nodes = new Map();
941 this.animation = core.createAnimation(props.id);
942 }
943 setupAnimation(props) {
944 const animation = this.animation;
945 if (this.nodes.size > 0) {
946 animation.addElement(Array.from(this.nodes.values()));
947 }
948 checkConfig(animation, props);
949 checkPlayback(animation, props);
950 }
951 componentDidMount() {
952 const props = this.props;
953 this.setupAnimation(props);
954 }
955 componentDidUpdate(prevProps) {
956 const animation = this.animation;
957 const props = this.props;
958 checkConfig(animation, props, prevProps);
959 checkProgress(animation, props, prevProps);
960 checkPlayback(animation, props, prevProps);
961 }
962 render() {
963 const { children } = this.props;
964 return (React__default.createElement(React__default.Fragment, null, React__default.Children.map(children, ((child, id) => React__default.cloneElement(child, { ref: (el) => this.nodes.set(id, el) })))));
965 }
966}
967const checkConfig = (animation, currentProps = {}, prevProps = {}) => {
968 const reservedProps = ['children', 'progressStart', 'progressStep', 'progressEnd', 'pause', 'stop', 'destroy', 'play', 'from', 'to', 'fromTo', 'onFinish'];
969 for (const key in currentProps) {
970 if (currentProps.hasOwnProperty(key) &&
971 !reservedProps.includes(key) &&
972 currentProps[key] !== prevProps[key]) {
973 animation[key](currentProps[key]);
974 }
975 }
976 const fromValues = currentProps.from;
977 if (fromValues && fromValues !== prevProps.from) {
978 const values = (Array.isArray(fromValues)) ? fromValues : [fromValues];
979 values.forEach(val => animation.from(val.property, val.value));
980 }
981 const toValues = currentProps.to;
982 if (toValues && toValues !== prevProps.to) {
983 const values = (Array.isArray(toValues)) ? toValues : [toValues];
984 values.forEach(val => animation.to(val.property, val.value));
985 }
986 const fromToValues = currentProps.fromTo;
987 if (fromToValues && fromToValues !== prevProps.fromTo) {
988 const values = (Array.isArray(fromToValues)) ? fromToValues : [fromToValues];
989 values.forEach(val => animation.fromTo(val.property, val.fromValue, val.toValue));
990 }
991 const onFinishValues = currentProps.onFinish;
992 if (onFinishValues && onFinishValues !== prevProps.onFinish) {
993 const values = (Array.isArray(onFinishValues)) ? onFinishValues : [onFinishValues];
994 values.forEach(val => animation.onFinish(val.callback, val.opts));
995 }
996};
997const checkProgress = (animation, currentProps = {}, prevProps = {}) => {
998 var _a, _b, _c, _d, _e;
999 const { progressStart, progressStep, progressEnd } = currentProps;
1000 if (progressStart && (((_a = prevProps.progressStart) === null || _a === void 0 ? void 0 : _a.forceLinearEasing) !== (progressStart === null || progressStart === void 0 ? void 0 : progressStart.forceLinearEasing) || ((_b = prevProps.progressStart) === null || _b === void 0 ? void 0 : _b.step) !== (progressStart === null || progressStart === void 0 ? void 0 : progressStart.step))) {
1001 animation.progressStart(progressStart.forceLinearEasing, progressStart.step);
1002 }
1003 if (progressStep && ((_c = prevProps.progressStep) === null || _c === void 0 ? void 0 : _c.step) !== (progressStep === null || progressStep === void 0 ? void 0 : progressStep.step)) {
1004 animation.progressStep(progressStep.step);
1005 }
1006 if (progressEnd && (((_d = prevProps.progressEnd) === null || _d === void 0 ? void 0 : _d.playTo) !== (progressEnd === null || progressEnd === void 0 ? void 0 : progressEnd.playTo) || ((_e = prevProps.progressEnd) === null || _e === void 0 ? void 0 : _e.step) !== (progressEnd === null || progressEnd === void 0 ? void 0 : progressEnd.step) || (prevProps === null || prevProps === void 0 ? void 0 : prevProps.dur) !== (progressEnd === null || progressEnd === void 0 ? void 0 : progressEnd.dur))) {
1007 animation.progressEnd(progressEnd.playTo, progressEnd.step, progressEnd.dur);
1008 }
1009};
1010const checkPlayback = (animation, currentProps = {}, prevProps = {}) => {
1011 if (!prevProps.play && currentProps.play) {
1012 animation.play();
1013 }
1014 if (!prevProps.pause && currentProps.pause) {
1015 animation.pause();
1016 }
1017 if (!prevProps.stop && currentProps.stop) {
1018 animation.stop();
1019 }
1020 if (!prevProps.destroy && currentProps.destroy) {
1021 animation.destroy();
1022 }
1023};
1024
1025// Icons that are used by internal components
1026ionicons.addIcons({
1027 'arrow-back-sharp': icons.arrowBackSharp,
1028 'caret-back-sharp': icons.caretBackSharp,
1029 'chevron-back': icons.chevronBack,
1030 'chevron-forward': icons.chevronForward,
1031 'close': icons.close,
1032 'close-circle': icons.closeCircle,
1033 'close-sharp': icons.closeSharp,
1034 'menu-outline': icons.menuOutline,
1035 'menu-sharp': icons.menuSharp,
1036 'reorder-two-sharp': icons.reorderTwoSharp,
1037 'reorder-three-outline': icons.reorderThreeOutline,
1038 'search-outline': icons.searchOutline,
1039 'search-sharp': icons.searchSharp,
1040});
1041// TODO: defineCustomElements() is asyncronous
1042// We need to use the promise
1043loader.defineCustomElements(window);
1044
1045Object.defineProperty(exports, 'IonicSafeString', {
1046 enumerable: true,
1047 get: function () {
1048 return core.IonicSafeString;
1049 }
1050});
1051Object.defineProperty(exports, 'createAnimation', {
1052 enumerable: true,
1053 get: function () {
1054 return core.createAnimation;
1055 }
1056});
1057Object.defineProperty(exports, 'createGesture', {
1058 enumerable: true,
1059 get: function () {
1060 return core.createGesture;
1061 }
1062});
1063Object.defineProperty(exports, 'iosTransitionAnimation', {
1064 enumerable: true,
1065 get: function () {
1066 return core.iosTransitionAnimation;
1067 }
1068});
1069Object.defineProperty(exports, 'mdTransitionAnimation', {
1070 enumerable: true,
1071 get: function () {
1072 return core.mdTransitionAnimation;
1073 }
1074});
1075Object.defineProperty(exports, 'setupConfig', {
1076 enumerable: true,
1077 get: function () {
1078 return core.setupConfig;
1079 }
1080});
1081exports.CreateAnimation = CreateAnimation;
1082exports.DefaultIonLifeCycleContext = DefaultIonLifeCycleContext;
1083exports.IonActionSheet = IonActionSheet;
1084exports.IonAlert = IonAlert;
1085exports.IonApp = IonApp;
1086exports.IonAvatar = IonAvatar;
1087exports.IonBackButton = IonBackButton;
1088exports.IonBackdrop = IonBackdrop;
1089exports.IonBadge = IonBadge;
1090exports.IonButton = IonButton;
1091exports.IonButtons = IonButtons;
1092exports.IonCard = IonCard;
1093exports.IonCardContent = IonCardContent;
1094exports.IonCardHeader = IonCardHeader;
1095exports.IonCardSubtitle = IonCardSubtitle;
1096exports.IonCardTitle = IonCardTitle;
1097exports.IonCheckbox = IonCheckbox;
1098exports.IonChip = IonChip;
1099exports.IonCol = IonCol;
1100exports.IonContent = IonContent;
1101exports.IonDatetime = IonDatetime;
1102exports.IonFab = IonFab;
1103exports.IonFabButton = IonFabButton;
1104exports.IonFabList = IonFabList;
1105exports.IonFooter = IonFooter;
1106exports.IonGrid = IonGrid;
1107exports.IonHeader = IonHeader;
1108exports.IonIcon = IonIcon;
1109exports.IonImg = IonImg;
1110exports.IonInfiniteScroll = IonInfiniteScroll;
1111exports.IonInfiniteScrollContent = IonInfiniteScrollContent;
1112exports.IonInput = IonInput;
1113exports.IonItem = IonItem;
1114exports.IonItemDivider = IonItemDivider;
1115exports.IonItemGroup = IonItemGroup;
1116exports.IonItemOption = IonItemOption;
1117exports.IonItemOptions = IonItemOptions;
1118exports.IonItemSliding = IonItemSliding;
1119exports.IonLabel = IonLabel;
1120exports.IonLifeCycleContext = IonLifeCycleContext;
1121exports.IonList = IonList;
1122exports.IonListHeader = IonListHeader;
1123exports.IonLoading = IonLoading;
1124exports.IonMenu = IonMenu;
1125exports.IonMenuButton = IonMenuButton;
1126exports.IonMenuToggle = IonMenuToggle;
1127exports.IonModal = IonModal;
1128exports.IonNav = IonNav;
1129exports.IonNote = IonNote;
1130exports.IonPage = IonPage;
1131exports.IonPicker = IonPicker;
1132exports.IonPickerColumn = IonPickerColumn;
1133exports.IonPopover = IonPopover;
1134exports.IonProgressBar = IonProgressBar;
1135exports.IonRadio = IonRadio;
1136exports.IonRadioGroup = IonRadioGroup;
1137exports.IonRange = IonRange;
1138exports.IonRefresher = IonRefresher;
1139exports.IonRefresherContent = IonRefresherContent;
1140exports.IonReorder = IonReorder;
1141exports.IonReorderGroup = IonReorderGroup;
1142exports.IonRippleEffect = IonRippleEffect;
1143exports.IonRouterLink = IonRouterLink;
1144exports.IonRouterOutlet = IonRouterOutlet;
1145exports.IonRow = IonRow;
1146exports.IonSearchbar = IonSearchbar;
1147exports.IonSegment = IonSegment;
1148exports.IonSegmentButton = IonSegmentButton;
1149exports.IonSelect = IonSelect;
1150exports.IonSelectOption = IonSelectOption;
1151exports.IonSelectPopover = IonSelectPopover;
1152exports.IonSkeletonText = IonSkeletonText;
1153exports.IonSlide = IonSlide;
1154exports.IonSlides = IonSlides;
1155exports.IonSpinner = IonSpinner;
1156exports.IonSplitPane = IonSplitPane;
1157exports.IonTab = IonTab;
1158exports.IonTabBar = IonTabBar;
1159exports.IonTabButton = IonTabButton;
1160exports.IonTabs = IonTabs;
1161exports.IonTabsContext = IonTabsContext;
1162exports.IonText = IonText;
1163exports.IonTextarea = IonTextarea;
1164exports.IonThumbnail = IonThumbnail;
1165exports.IonTitle = IonTitle;
1166exports.IonToast = IonToast;
1167exports.IonToggle = IonToggle;
1168exports.IonToolbar = IonToolbar;
1169exports.IonVirtualScroll = IonVirtualScroll;
1170exports.NavContext = NavContext;
1171exports.getConfig = getConfig;
1172exports.getPlatforms = getPlatforms;
1173exports.isPlatform = isPlatform;
1174exports.useIonViewDidEnter = useIonViewDidEnter;
1175exports.useIonViewDidLeave = useIonViewDidLeave;
1176exports.useIonViewWillEnter = useIonViewWillEnter;
1177exports.useIonViewWillLeave = useIonViewWillLeave;
1178exports.withIonLifeCycle = withIonLifeCycle;
1179//# sourceMappingURL=index.js.map