UNPKG

@hackplan/polaris

Version:

Shopify’s product component library

41 lines (40 loc) 1.68 kB
import createApp, { getShopOrigin, LifecycleHook, } from '@shopify/app-bridge'; import StickyManager from '../StickyManager'; import ScrollLockManager from '../ScrollLockManager'; import Intl from '../Intl'; import Link from '../Link'; import { polarisVersion } from '../../../../configure'; export default function createAppProviderContext({ i18n, linkComponent, apiKey, shopOrigin, forceRedirect, stickyManager, scrollLockManager, } = { i18n: {} }) { const intl = new Intl(i18n); const link = new Link(linkComponent); const appBridge = apiKey ? createApp({ apiKey, shopOrigin: shopOrigin || getShopOrigin(), forceRedirect, }) : undefined; if (appBridge != null) { // eslint-disable-next-line no-console console.warn("Deprecation: Using `apiKey` and `shopOrigin` on `AppProvider` to initialize the Shopify App Bridge is deprecated. Support for this will be removed in v5.0. Use `Provider` from `@shopify/app-bridge-react` instead. For example, `import {Provider} from '@shopify/app-bridge-react';`"); } if (appBridge && appBridge.hooks) { appBridge.hooks.set(LifecycleHook.DispatchAction, setClientInterfaceHook); } return { intl, link, stickyManager: stickyManager || new StickyManager(), scrollLockManager: scrollLockManager || new ScrollLockManager(), appBridge, }; } export const setClientInterfaceHook = function (next) { return function (action) { action.clientInterface = { name: '@shopify/polaris', version: polarisVersion, }; return next(action); }; };