UNPKG

react-klasha

Version:

This is an reactJS library for implementing klasha payment gateway

748 lines (734 loc) 34.3 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var history = require('history'); var React = require('react'); var reactRouterDom = require('react-router-dom'); var react = require('@ionic/react'); var reactRouter = require('react-router'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var React__default = /*#__PURE__*/_interopDefaultLegacy(React); class IonRouteInner extends React__default['default'].PureComponent { render() { return (React__default['default'].createElement(reactRouter.Route, { path: this.props.path, exact: this.props.exact, render: this.props.render, computedMatch: this.props.computedMatch })); } } class ReactRouterViewStack extends react.ViewStacks { constructor() { super(); this.createViewItem = this.createViewItem.bind(this); this.findViewItemByRouteInfo = this.findViewItemByRouteInfo.bind(this); this.findLeavingViewItemByRouteInfo = this.findLeavingViewItemByRouteInfo.bind(this); this.getChildrenToRender = this.getChildrenToRender.bind(this); this.findViewItemByPathname = this.findViewItemByPathname.bind(this); } createViewItem(outletId, reactElement, routeInfo, page) { const viewItem = { id: react.generateId('viewItem'), outletId, ionPageElement: page, reactElement, mount: true, ionRoute: false, }; const matchProps = { exact: reactElement.props.exact, path: reactElement.props.path || reactElement.props.from, component: reactElement.props.component, }; const match = reactRouter.matchPath(routeInfo.pathname, matchProps); if (reactElement.type === react.IonRoute) { viewItem.ionRoute = true; viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement; } viewItem.routeData = { match, childProps: reactElement.props, }; return viewItem; } getChildrenToRender(outletId, ionRouterOutlet, routeInfo) { const viewItems = this.getViewItemsForOutlet(outletId); // Sync latest routes with viewItems React__default['default'].Children.forEach(ionRouterOutlet.props.children, (child) => { const viewItem = viewItems.find((v) => { return matchComponent$1(child, v.routeData.childProps.path || v.routeData.childProps.from); }); if (viewItem) { viewItem.reactElement = child; } }); const children = viewItems.map((viewItem) => { let clonedChild; if (viewItem.ionRoute && !viewItem.disableIonPageManagement) { clonedChild = (React__default['default'].createElement(react.ViewLifeCycleManager, { key: `view-${viewItem.id}`, mount: viewItem.mount, removeView: () => this.remove(viewItem) }, React__default['default'].cloneElement(viewItem.reactElement, { computedMatch: viewItem.routeData.match, }))); } else { const match = matchComponent$1(viewItem.reactElement, routeInfo.pathname); clonedChild = (React__default['default'].createElement(react.ViewLifeCycleManager, { key: `view-${viewItem.id}`, mount: viewItem.mount, removeView: () => this.remove(viewItem) }, React__default['default'].cloneElement(viewItem.reactElement, { computedMatch: viewItem.routeData.match, }))); if (!match && viewItem.routeData.match) { viewItem.routeData.match = undefined; viewItem.mount = false; } } return clonedChild; }); return children; } findViewItemByRouteInfo(routeInfo, outletId) { const { viewItem, match } = this.findViewItemByPath(routeInfo.pathname, outletId); if (viewItem && match) { viewItem.routeData.match = match; } return viewItem; } findLeavingViewItemByRouteInfo(routeInfo, outletId, mustBeIonRoute = true) { const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname, outletId, false, mustBeIonRoute); return viewItem; } findViewItemByPathname(pathname, outletId) { const { viewItem } = this.findViewItemByPath(pathname, outletId); return viewItem; } findViewItemByPath(pathname, outletId, forceExact, mustBeIonRoute) { let viewItem; let match; let viewStack; if (outletId) { viewStack = this.getViewItemsForOutlet(outletId); viewStack.some(matchView); if (!viewItem) { viewStack.some(matchDefaultRoute); } } else { const viewItems = this.getAllViewItems(); viewItems.some(matchView); if (!viewItem) { viewItems.some(matchDefaultRoute); } } return { viewItem, match }; function matchView(v) { if (mustBeIonRoute && !v.ionRoute) { return false; } const matchProps = { exact: forceExact ? true : v.routeData.childProps.exact, path: v.routeData.childProps.path || v.routeData.childProps.from, component: v.routeData.childProps.component, }; const myMatch = reactRouter.matchPath(pathname, matchProps); if (myMatch) { viewItem = v; match = myMatch; return true; } return false; } function matchDefaultRoute(v) { // try to find a route that doesn't have a path or from prop, that will be our default route if (!v.routeData.childProps.path && !v.routeData.childProps.from) { match = { path: pathname, url: pathname, isExact: true, params: {}, }; viewItem = v; return true; } return false; } } } function matchComponent$1(node, pathname, forceExact) { const matchProps = { exact: forceExact ? true : node.props.exact, path: node.props.path || node.props.from, component: node.props.component, }; const match = reactRouter.matchPath(pathname, matchProps); return match; } function clonePageElement(leavingViewHtml) { let html; if (typeof leavingViewHtml === 'string') { html = leavingViewHtml; } else { html = leavingViewHtml.outerHTML; } if (document) { const newEl = document.createElement('div'); newEl.innerHTML = html; newEl.style.zIndex = ''; // Remove an existing back button so the new element doesn't get two of them const ionBackButton = newEl.getElementsByTagName('ion-back-button'); if (ionBackButton[0]) { ionBackButton[0].remove(); } return newEl.firstChild; } return undefined; } class StackManager extends React__default['default'].PureComponent { constructor(props) { super(props); this.stackContextValue = { registerIonPage: this.registerIonPage.bind(this), isInOutlet: () => true, }; this.registerIonPage = this.registerIonPage.bind(this); this.transitionPage = this.transitionPage.bind(this); this.handlePageTransition = this.handlePageTransition.bind(this); this.id = react.generateId('routerOutlet'); } componentDidMount() { if (this.routerOutletElement) { this.setupRouterOutlet(this.routerOutletElement); // console.log(`SM Mount - ${this.routerOutletElement.id} (${this.id})`); this.handlePageTransition(this.props.routeInfo); } } componentDidUpdate(prevProps) { if (this.props.routeInfo.pathname !== prevProps.routeInfo.pathname) { this.handlePageTransition(this.props.routeInfo); } } componentWillUnmount() { // console.log(`SM UNMount - ${(this.routerOutletElement?.id as any).id} (${this.id})`); this.context.clearOutlet(this.id); } async handlePageTransition(routeInfo) { var _a, _b; // If routerOutlet isn't quite ready, give it another try in a moment if (!this.routerOutletElement || !this.routerOutletElement.commit) { setTimeout(() => this.handlePageTransition(routeInfo), 10); } else { let enteringViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id); let leavingViewItem = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id); if (!leavingViewItem && routeInfo.prevRouteLastPathname) { leavingViewItem = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id); } // Check if leavingViewItem should be unmounted if (leavingViewItem) { if (routeInfo.routeAction === 'replace') { leavingViewItem.mount = false; } else if (!(routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'forward')) { if (routeInfo.routeDirection !== 'none' && enteringViewItem !== leavingViewItem) { leavingViewItem.mount = false; } } else if ((_a = routeInfo.routeOptions) === null || _a === void 0 ? void 0 : _a.unmount) { leavingViewItem.mount = false; } } const enteringRoute = matchRoute((_b = this.ionRouterOutlet) === null || _b === void 0 ? void 0 : _b.props.children, routeInfo); if (enteringViewItem) { enteringViewItem.reactElement = enteringRoute; } if (!enteringViewItem) { if (enteringRoute) { enteringViewItem = this.context.createViewItem(this.id, enteringRoute, routeInfo); this.context.addViewItem(enteringViewItem); } } if (enteringViewItem && enteringViewItem.ionPageElement) { this.transitionPage(routeInfo, enteringViewItem, leavingViewItem); } else if (leavingViewItem && !enteringRoute && !enteringViewItem) { // If we have a leavingView but no entering view/route, we are probably leaving to // another outlet, so hide this leavingView. We do it in a timeout to give time for a // transition to finish. // setTimeout(() => { if (leavingViewItem.ionPageElement) { leavingViewItem.ionPageElement.classList.add('ion-page-hidden'); leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true'); } // }, 250); } this.forceUpdate(); } } registerIonPage(page, routeInfo) { const foundView = this.context.findViewItemByRouteInfo(routeInfo, this.id); if (foundView) { foundView.ionPageElement = page; foundView.ionRoute = true; } this.handlePageTransition(routeInfo); } async setupRouterOutlet(routerOutlet) { const canStart = () => { const config = react.getConfig(); const swipeEnabled = config && config.get('swipeBackEnabled', routerOutlet.mode === 'ios'); if (swipeEnabled) { return this.context.canGoBack(); } else { return false; } }; const onStart = () => { this.context.goBack(); }; routerOutlet.swipeHandler = { canStart, onStart, onEnd: (_shouldContinue) => true, }; } async transitionPage(routeInfo, enteringViewItem, leavingViewItem) { const routerOutlet = this.routerOutletElement; const direction = routeInfo.routeDirection === 'none' || routeInfo.routeDirection === 'root' ? undefined : routeInfo.routeDirection; if (enteringViewItem && enteringViewItem.ionPageElement && this.routerOutletElement) { if (leavingViewItem && leavingViewItem.ionPageElement && enteringViewItem === leavingViewItem) { // If a page is transitioning to another version of itself // we clone it so we can have an animation to show const match = matchComponent(leavingViewItem.reactElement, routeInfo.pathname, true); if (match) { const newLeavingElement = clonePageElement(leavingViewItem.ionPageElement.outerHTML); if (newLeavingElement) { this.routerOutletElement.appendChild(newLeavingElement); await runCommit(enteringViewItem.ionPageElement, newLeavingElement); this.routerOutletElement.removeChild(newLeavingElement); } } else { await runCommit(enteringViewItem.ionPageElement, undefined); } } else { await runCommit(enteringViewItem.ionPageElement, leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.ionPageElement); if (leavingViewItem && leavingViewItem.ionPageElement) { leavingViewItem.ionPageElement.classList.add('ion-page-hidden'); leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true'); } } } async function runCommit(enteringEl, leavingEl) { enteringEl.classList.add('ion-page'); enteringEl.classList.add('ion-page-invisible'); await routerOutlet.commit(enteringEl, leavingEl, { deepWait: true, duration: direction === undefined ? 0 : undefined, direction: direction, showGoBack: !!routeInfo.pushedByRoute, progressAnimation: false, animationBuilder: routeInfo.routeAnimation, }); } } render() { const { children } = this.props; const ionRouterOutlet = React__default['default'].Children.only(children); this.ionRouterOutlet = ionRouterOutlet; const components = this.context.getChildrenToRender(this.id, this.ionRouterOutlet, this.props.routeInfo, () => { this.forceUpdate(); }); return (React__default['default'].createElement(react.StackContext.Provider, { value: this.stackContextValue }, React__default['default'].cloneElement(ionRouterOutlet, { ref: (node) => { if (ionRouterOutlet.props.setRef) { ionRouterOutlet.props.setRef(node); } if (ionRouterOutlet.props.forwardedRef) { ionRouterOutlet.props.forwardedRef.current = node; } this.routerOutletElement = node; const { ref } = ionRouterOutlet; if (typeof ref === 'function') { ref(node); } }, }, components))); } static get contextType() { return react.RouteManagerContext; } } function matchRoute(node, routeInfo) { let matchedNode; React__default['default'].Children.forEach(node, (child) => { const matchProps = { exact: child.props.exact, path: child.props.path || child.props.from, component: child.props.component, }; const match = reactRouterDom.matchPath(routeInfo.pathname, matchProps); if (match) { matchedNode = child; } }); if (matchedNode) { return matchedNode; } // If we haven't found a node // try to find one that doesn't have a path or from prop, that will be our not found route React__default['default'].Children.forEach(node, (child) => { if (!(child.props.path || child.props.from)) { matchedNode = child; } }); return matchedNode; } function matchComponent(node, pathname, forceExact) { const matchProps = { exact: forceExact ? true : node.props.exact, path: node.props.path || node.props.from, component: node.props.component, }; const match = reactRouterDom.matchPath(pathname, matchProps); return match; } class IonRouterInner extends React__default['default'].PureComponent { constructor(props) { super(props); this.exitViewFromOtherOutletHandlers = []; this.locationHistory = new react.LocationHistory(); this.viewStack = new ReactRouterViewStack(); this.routeMangerContextState = { canGoBack: () => this.locationHistory.canGoBack(), clearOutlet: this.viewStack.clear, findViewItemByPathname: this.viewStack.findViewItemByPathname, getChildrenToRender: this.viewStack.getChildrenToRender, goBack: () => this.handleNavigateBack(), createViewItem: this.viewStack.createViewItem, findViewItemByRouteInfo: this.viewStack.findViewItemByRouteInfo, findLeavingViewItemByRouteInfo: this.viewStack.findLeavingViewItemByRouteInfo, addViewItem: this.viewStack.add, unMountViewItem: this.viewStack.remove, }; const routeInfo = { id: react.generateId('routeInfo'), pathname: this.props.location.pathname, search: this.props.location.search, }; this.locationHistory.add(routeInfo); this.handleChangeTab = this.handleChangeTab.bind(this); this.handleResetTab = this.handleResetTab.bind(this); this.handleNativeBack = this.handleNativeBack.bind(this); this.handleNavigate = this.handleNavigate.bind(this); this.handleNavigateBack = this.handleNavigateBack.bind(this); this.props.registerHistoryListener(this.handleHistoryChange.bind(this)); this.handleSetCurrentTab = this.handleSetCurrentTab.bind(this); this.state = { routeInfo, }; } handleChangeTab(tab, path, routeOptions) { if (!path) { return; } const routeInfo = this.locationHistory.getCurrentRouteInfoForTab(tab); const [pathname, search] = path.split('?'); if (routeInfo) { this.incomingRouteParams = Object.assign(Object.assign({}, routeInfo), { routeAction: 'push', routeDirection: 'none' }); if (routeInfo.pathname === pathname) { this.incomingRouteParams.routeOptions = routeOptions; this.props.history.push(routeInfo.pathname + (routeInfo.search || '')); } else { this.incomingRouteParams.pathname = pathname; this.incomingRouteParams.search = search ? '?' + search : undefined; this.incomingRouteParams.routeOptions = routeOptions; this.props.history.push(pathname + (search ? '?' + search : '')); } } else { this.handleNavigate(pathname, 'push', 'none', undefined, routeOptions, tab); } } handleHistoryChange(location, action) { var _a, _b, _c; let leavingLocationInfo; if (this.incomingRouteParams) { if (this.incomingRouteParams.routeAction === 'replace') { leavingLocationInfo = this.locationHistory.previous(); } else { leavingLocationInfo = this.locationHistory.current(); } } else { leavingLocationInfo = this.locationHistory.current(); } const leavingUrl = leavingLocationInfo.pathname + leavingLocationInfo.search; if (leavingUrl !== location.pathname) { if (!this.incomingRouteParams) { if (action === 'REPLACE') { this.incomingRouteParams = { routeAction: 'replace', routeDirection: 'none', tab: this.currentTab, }; } if (action === 'POP') { const currentRoute = this.locationHistory.current(); if (currentRoute && currentRoute.pushedByRoute) { const prevInfo = this.locationHistory.findLastLocation(currentRoute); this.incomingRouteParams = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back' }); } else { this.incomingRouteParams = { routeAction: 'pop', routeDirection: 'none', tab: this.currentTab, }; } } if (!this.incomingRouteParams) { this.incomingRouteParams = { routeAction: 'push', routeDirection: ((_a = location.state) === null || _a === void 0 ? void 0 : _a.direction) || 'forward', routeOptions: (_b = location.state) === null || _b === void 0 ? void 0 : _b.routerOptions, tab: this.currentTab, }; } } let routeInfo; if ((_c = this.incomingRouteParams) === null || _c === void 0 ? void 0 : _c.id) { routeInfo = Object.assign(Object.assign({}, this.incomingRouteParams), { lastPathname: leavingLocationInfo.pathname }); this.locationHistory.add(routeInfo); } else { const isPushed = this.incomingRouteParams.routeAction === 'push' && this.incomingRouteParams.routeDirection === 'forward'; routeInfo = Object.assign(Object.assign({ id: react.generateId('routeInfo') }, this.incomingRouteParams), { lastPathname: leavingLocationInfo.pathname, pathname: location.pathname, search: location.search, params: this.props.match.params, prevRouteLastPathname: leavingLocationInfo.lastPathname }); if (isPushed) { routeInfo.tab = leavingLocationInfo.tab; routeInfo.pushedByRoute = leavingLocationInfo.pathname; } else if (routeInfo.routeAction === 'pop') { const r = this.locationHistory.findLastLocation(routeInfo); routeInfo.pushedByRoute = r === null || r === void 0 ? void 0 : r.pushedByRoute; } else if (routeInfo.routeAction === 'push' && routeInfo.tab !== leavingLocationInfo.tab) { // If we are switching tabs grab the last route info for the tab and use its pushedByRoute const lastRoute = this.locationHistory.getCurrentRouteInfoForTab(routeInfo.tab); routeInfo.pushedByRoute = lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.pushedByRoute; } else if (routeInfo.routeAction === 'replace') { // Make sure to set the lastPathname, etc.. to the current route so the page transitions out const currentRouteInfo = this.locationHistory.current(); /** * If going from /home to /child, then replacing from * /child to /home, we don't want the route info to * say that /home was pushed by /home which is not correct. */ const currentPushedBy = currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.pushedByRoute; const pushedByRoute = (currentPushedBy !== undefined && currentPushedBy !== routeInfo.pathname) ? currentPushedBy : routeInfo.pushedByRoute; routeInfo.lastPathname = (currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.pathname) || routeInfo.lastPathname; routeInfo.prevRouteLastPathname = currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.lastPathname; routeInfo.pushedByRoute = pushedByRoute; routeInfo.routeDirection = (currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.routeDirection) || routeInfo.routeDirection; routeInfo.routeAnimation = (currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.routeAnimation) || routeInfo.routeAnimation; } this.locationHistory.add(routeInfo); } this.setState({ routeInfo, }); } this.incomingRouteParams = undefined; } /** * history@4.x uses goBack(), history@5.x uses back() * TODO: If support for React Router <=5 is dropped * this logic is no longer needed. We can just * assume back() is available. */ handleNativeBack() { const history = this.props.history; const goBack = history.goBack || history.back; goBack(); } handleNavigate(path, routeAction, routeDirection, routeAnimation, routeOptions, tab) { this.incomingRouteParams = Object.assign(this.incomingRouteParams || {}, { routeAction, routeDirection, routeOptions, routeAnimation, tab, }); if (routeAction === 'push') { this.props.history.push(path); } else { this.props.history.replace(path); } } handleNavigateBack(defaultHref = '/', routeAnimation) { const config = react.getConfig(); defaultHref = defaultHref ? defaultHref : config && config.get('backButtonDefaultHref'); const routeInfo = this.locationHistory.current(); if (routeInfo && routeInfo.pushedByRoute) { const prevInfo = this.locationHistory.findLastLocation(routeInfo); if (prevInfo) { this.incomingRouteParams = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back', routeAnimation: routeAnimation || routeInfo.routeAnimation }); if (routeInfo.lastPathname === routeInfo.pushedByRoute || ( /** * We need to exclude tab switches/tab * context changes here because tabbed * navigation is not linear, but router.back() * will go back in a linear fashion. */ prevInfo.pathname === routeInfo.pushedByRoute && routeInfo.tab === '' && prevInfo.tab === '')) { /** * history@4.x uses goBack(), history@5.x uses back() * TODO: If support for React Router <=5 is dropped * this logic is no longer needed. We can just * assume back() is available. */ const history = this.props.history; const goBack = history.goBack || history.back; goBack(); } else { this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back'); } } else { this.handleNavigate(defaultHref, 'pop', 'back'); } } else { this.handleNavigate(defaultHref, 'pop', 'back'); } } handleResetTab(tab, originalHref, originalRouteOptions) { const routeInfo = this.locationHistory.getFirstRouteInfoForTab(tab); if (routeInfo) { const newRouteInfo = Object.assign({}, routeInfo); newRouteInfo.pathname = originalHref; newRouteInfo.routeOptions = originalRouteOptions; this.incomingRouteParams = Object.assign(Object.assign({}, newRouteInfo), { routeAction: 'pop', routeDirection: 'back' }); this.props.history.push(newRouteInfo.pathname + (newRouteInfo.search || '')); } } handleSetCurrentTab(tab) { this.currentTab = tab; const ri = Object.assign({}, this.locationHistory.current()); if (ri.tab !== tab) { ri.tab = tab; this.locationHistory.update(ri); } } render() { return (React__default['default'].createElement(react.RouteManagerContext.Provider, { value: this.routeMangerContextState }, React__default['default'].createElement(react.NavManager, { ionRoute: IonRouteInner, ionRedirect: {}, stackManager: StackManager, routeInfo: this.state.routeInfo, onNativeBack: this.handleNativeBack, onNavigateBack: this.handleNavigateBack, onNavigate: this.handleNavigate, onSetCurrentTab: this.handleSetCurrentTab, onChangeTab: this.handleChangeTab, onResetTab: this.handleResetTab, locationHistory: this.locationHistory }, this.props.children))); } } const IonRouter = reactRouterDom.withRouter(IonRouterInner); IonRouter.displayName = 'IonRouter'; class IonReactRouter extends React__default['default'].Component { constructor(props) { super(props); const { history: history$1 } = props, rest = tslib.__rest(props, ["history"]); this.history = history$1 || history.createBrowserHistory(rest); this.history.listen(this.handleHistoryChange.bind(this)); this.registerHistoryListener = this.registerHistoryListener.bind(this); } /** * history@4.x passes separate location and action * params. history@5.x passes location and action * together as a single object. * TODO: If support for React Router <=5 is dropped * this logic is no longer needed. We can just assume * a single object with both location and action. */ handleHistoryChange(location, action) { const locationValue = location.location || location; const actionValue = location.action || action; if (this.historyListenHandler) { this.historyListenHandler(locationValue, actionValue); } } registerHistoryListener(cb) { this.historyListenHandler = cb; } render() { const _a = this.props, { children } = _a, props = tslib.__rest(_a, ["children"]); return (React__default['default'].createElement(reactRouterDom.Router, Object.assign({ history: this.history }, props), React__default['default'].createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children))); } } class IonReactMemoryRouter extends React__default['default'].Component { constructor(props) { super(props); this.history = props.history; this.history.listen(this.handleHistoryChange.bind(this)); this.registerHistoryListener = this.registerHistoryListener.bind(this); } /** * history@4.x passes separate location and action * params. history@5.x passes location and action * together as a single object. * TODO: If support for React Router <=5 is dropped * this logic is no longer needed. We can just assume * a single object with both location and action. */ handleHistoryChange(location, action) { const locationValue = location.location || location; const actionValue = location.action || action; if (this.historyListenHandler) { this.historyListenHandler(locationValue, actionValue); } } registerHistoryListener(cb) { this.historyListenHandler = cb; } render() { const _a = this.props, { children } = _a, props = tslib.__rest(_a, ["children"]); return (React__default['default'].createElement(reactRouter.Router, Object.assign({}, props), React__default['default'].createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children))); } } class IonReactHashRouter extends React__default['default'].Component { constructor(props) { super(props); const { history: history$1 } = props, rest = tslib.__rest(props, ["history"]); this.history = history$1 || history.createHashHistory(rest); this.history.listen(this.handleHistoryChange.bind(this)); this.registerHistoryListener = this.registerHistoryListener.bind(this); } /** * history@4.x passes separate location and action * params. history@5.x passes location and action * together as a single object. * TODO: If support for React Router <=5 is dropped * this logic is no longer needed. We can just assume * a single object with both location and action. */ handleHistoryChange(location, action) { const locationValue = location.location || location; const actionValue = location.action || action; if (this.historyListenHandler) { this.historyListenHandler(locationValue, actionValue); } } registerHistoryListener(cb) { this.historyListenHandler = cb; } render() { const _a = this.props, { children } = _a, props = tslib.__rest(_a, ["children"]); return (React__default['default'].createElement(reactRouterDom.Router, Object.assign({ history: this.history }, props), React__default['default'].createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children))); } } exports.IonReactHashRouter = IonReactHashRouter; exports.IonReactMemoryRouter = IonReactMemoryRouter; exports.IonReactRouter = IonReactRouter; //# sourceMappingURL=index.js.map