UNPKG

@shopify/app-bridge-host

Version:

App Bridge Host contains components and middleware to be consumed by the app's host, as well as the host itself. The middleware and `Frame` component are responsible for facilitating communication between the client and host, and used to act on actions se

76 lines (71 loc) 3.66 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var tslib = require('tslib'); var Redirect = require('@shopify/app-bridge-core/actions/Navigation/Redirect'); var utilities = require('../utilities.js'); var actionCreators = require('./actionCreators.js'); var store_reducers_embeddedApp_navigation_reducer = require('./reducer.js'); var actions = require('./actions.js'); /** * An object containing the key, actions, initial state and reducer of the Navigation feature * Can be used with the `withFeature` decorator to add the reducer * and then make its actions and store available to the wrapped component * @public * */ var feature = { actions: actionCreators.navigationActionCreatorsMap, key: 'navigation', initialState: store_reducers_embeddedApp_navigation_reducer.defaultNavigationStore, reducer: utilities.resetStateReducer(store_reducers_embeddedApp_navigation_reducer.default), requiresRouter: true, getApi: function (_a) { var config = _a.config, actions = _a.actions; function handleRedirect(to, options) { var url = Redirect.normalizeUrl(to); var localOrigin = new URL(config.url).origin; var isAppUrl = url.startsWith(localOrigin); var isHostUrl = url.startsWith("https://".concat(config.hostName)); var isRelative = url.startsWith('/'); if (isAppUrl || isHostUrl || isRelative) { var path = Redirect.getRelativePath(url); if (isHostUrl || (options === null || options === void 0 ? void 0 : options.target) === 'new' || (options === null || options === void 0 ? void 0 : options.target) === 'host') { actions.handleRedirectAdmin({ path: path.replace(/^\/admin/, ''), newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new', }); return; } if (((options === null || options === void 0 ? void 0 : options.target) === 'self' || !(options === null || options === void 0 ? void 0 : options.target)) && (options === null || options === void 0 ? void 0 : options.replace)) { actions.handleReplaceHistory({ path: path }); return; } actions.handleRedirectApp({ path: path }); return; } actions.handleRedirectRemote({ url: url, newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new', }); } var navigate = function (to, options) { if (Redirect.isAdminSection(to)) { var convertedSection = tslib.__assign(tslib.__assign({}, to), { name: Redirect.ResourceType[to.name] }); actions.handleRedirectAdminSection({ section: convertedSection, newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new', }); return; } handleRedirect(to, options); }; return { navigate: navigate, }; }, }; exports.navigationActionCreatorsMap = actionCreators.navigationActionCreatorsMap; exports.default = store_reducers_embeddedApp_navigation_reducer.default; exports.defaultNavigationStore = store_reducers_embeddedApp_navigation_reducer.defaultNavigationStore; exports.COMPLETE_ROUTE_UPDATE = actions.COMPLETE_ROUTE_UPDATE; exports.completeRouteUpdate = actions.completeRouteUpdate; exports.feature = feature;