@shopify/app-bridge-react 2.1.1-alpha.0 → 2.1.1-alpha.1

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/components/ClientRouter/ClientRouter.d.ts +21 -0
  3. package/components/ClientRouter/ClientRouter.js +52 -0
  4. package/components/ClientRouter/hook.d.ts +10 -0
  5. package/components/ClientRouter/hook.js +20 -0
  6. package/components/ClientRouter/index.d.ts +3 -0
  7. package/components/ClientRouter/index.js +10 -0
  8. package/components/ClientRouter/router.d.ts +5 -0
  9. package/components/ClientRouter/router.js +11 -0
  10. package/components/ContextualSaveBar/ContextualSaveBar.d.ts +13 -0
  11. package/components/ContextualSaveBar/ContextualSaveBar.js +64 -0
  12. package/components/ContextualSaveBar/index.d.ts +3 -0
  13. package/components/ContextualSaveBar/index.js +7 -0
  14. package/components/Loading/Loading.d.ts +17 -0
  15. package/components/Loading/Loading.js +55 -0
  16. package/components/Loading/index.d.ts +2 -0
  17. package/components/Loading/index.js +7 -0
  18. package/components/Modal/Modal.d.ts +32 -0
  19. package/components/Modal/Modal.js +139 -0
  20. package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
  21. package/components/Modal/ModalContent/ModalContent.js +61 -0
  22. package/components/Modal/ModalContent/index.d.ts +2 -0
  23. package/components/Modal/ModalContent/index.js +7 -0
  24. package/components/Modal/index.d.ts +4 -0
  25. package/components/Modal/index.js +10 -0
  26. package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
  27. package/components/NavigationMenu/NavigationMenu.js +40 -0
  28. package/components/NavigationMenu/index.d.ts +3 -0
  29. package/components/NavigationMenu/index.js +7 -0
  30. package/components/Provider/Provider.d.ts +81 -0
  31. package/components/Provider/Provider.js +70 -0
  32. package/components/Provider/index.d.ts +3 -0
  33. package/components/Provider/index.js +7 -0
  34. package/components/ResourcePicker/ResourcePicker.d.ts +68 -0
  35. package/components/ResourcePicker/ResourcePicker.js +114 -0
  36. package/components/ResourcePicker/index.d.ts +3 -0
  37. package/components/ResourcePicker/index.js +7 -0
  38. package/components/RoutePropagator/RoutePropagator.d.ts +20 -0
  39. package/components/RoutePropagator/RoutePropagator.js +54 -0
  40. package/components/RoutePropagator/globals.d.ts +3 -0
  41. package/components/RoutePropagator/globals.js +15 -0
  42. package/components/RoutePropagator/hook.d.ts +10 -0
  43. package/components/RoutePropagator/hook.js +20 -0
  44. package/components/RoutePropagator/index.d.ts +3 -0
  45. package/components/RoutePropagator/index.js +10 -0
  46. package/components/RoutePropagator/route-propagator.d.ts +7 -0
  47. package/components/RoutePropagator/route-propagator.js +91 -0
  48. package/components/TitleBar/TitleBar.d.ts +27 -0
  49. package/components/TitleBar/TitleBar.js +108 -0
  50. package/components/TitleBar/index.d.ts +3 -0
  51. package/components/TitleBar/index.js +7 -0
  52. package/components/Toast/Toast.d.ts +31 -0
  53. package/components/Toast/Toast.js +59 -0
  54. package/components/Toast/index.d.ts +3 -0
  55. package/components/Toast/index.js +7 -0
  56. package/components/index.d.ts +10 -0
  57. package/components/index.js +35 -0
  58. package/context.d.ts +13 -0
  59. package/context.js +10 -0
  60. package/hooks/index.d.ts +8 -0
  61. package/hooks/index.js +17 -0
  62. package/hooks/useAppBridgeState/index.d.ts +1 -0
  63. package/hooks/useAppBridgeState/index.js +13 -0
  64. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
  65. package/hooks/useAppBridgeState/useAppBridgeState.js +89 -0
  66. package/hooks/useContextualSaveBar/index.d.ts +1 -0
  67. package/hooks/useContextualSaveBar/index.js +5 -0
  68. package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +13 -0
  69. package/hooks/useContextualSaveBar/useContextualSaveBar.js +68 -0
  70. package/hooks/useFeatureRequest/index.d.ts +1 -0
  71. package/hooks/useFeatureRequest/index.js +13 -0
  72. package/hooks/useFeatureRequest/useFeatureRequest.d.ts +13 -0
  73. package/hooks/useFeatureRequest/useFeatureRequest.js +49 -0
  74. package/hooks/useFeaturesAvailable/index.d.ts +2 -0
  75. package/hooks/useFeaturesAvailable/index.js +5 -0
  76. package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +12 -0
  77. package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +101 -0
  78. package/hooks/useLocale/index.d.ts +1 -0
  79. package/hooks/useLocale/index.js +5 -0
  80. package/hooks/useLocale/useLocale.d.ts +1 -0
  81. package/hooks/useLocale/useLocale.js +8 -0
  82. package/hooks/useNavigate/index.d.ts +1 -0
  83. package/hooks/useNavigate/index.js +5 -0
  84. package/hooks/useNavigate/useNavigate.d.ts +24 -0
  85. package/hooks/useNavigate/useNavigate.js +109 -0
  86. package/hooks/useNavigationHistory/index.d.ts +1 -0
  87. package/hooks/useNavigationHistory/index.js +5 -0
  88. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
  89. package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
  90. package/hooks/useToast/index.d.ts +1 -0
  91. package/hooks/useToast/index.js +5 -0
  92. package/hooks/useToast/useToast.d.ts +15 -0
  93. package/hooks/useToast/useToast.js +38 -0
  94. package/index.d.ts +4 -0
  95. package/index.js +19 -0
  96. package/package.json +3 -3
  97. package/types.d.ts +35 -0
  98. package/types.js +5 -0
  99. package/umd/index.js +14 -0
  100. package/useAppBridge.d.ts +1 -0
  101. package/useAppBridge.js +13 -0
  102. package/utilities/transformers.d.ts +20 -0
  103. package/utilities/transformers.js +105 -0
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
4
+ var AppLink_1 = require("@shopify/app-bridge/actions/Link/AppLink");
5
+ var NavigationMenu_1 = require("@shopify/app-bridge/actions/Menu/NavigationMenu");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ function defaultMatcher(link, location) {
8
+ return link.destination.replace(/\/$/, '') === location.pathname.replace(/\/$/, '');
9
+ }
10
+ function NavigationMenu(_a) {
11
+ var navigationLinks = _a.navigationLinks, _b = _a.matcher, matcher = _b === void 0 ? defaultMatcher : _b;
12
+ var app = useAppBridge_1.useAppBridge();
13
+ var _c = react_1.useState(), items = _c[0], setItems = _c[1];
14
+ react_1.useEffect(function () {
15
+ var items = navigationLinks.map(function (link) { return AppLink_1.create(app, link); });
16
+ setItems(items);
17
+ }, [app, JSON.stringify(navigationLinks)]);
18
+ var activeLink = react_1.useMemo(function () {
19
+ var activeLinkIndex = (items || []).findIndex(function (link) {
20
+ return matcher(link, location);
21
+ });
22
+ if (activeLinkIndex >= 0) {
23
+ return items === null || items === void 0 ? void 0 : items[activeLinkIndex];
24
+ }
25
+ }, [app, location.pathname, matcher, items, location.pathname]);
26
+ react_1.useEffect(function () {
27
+ // Skip creating the navigation menu on initial render
28
+ if (!items) {
29
+ return;
30
+ }
31
+ /**
32
+ * There isn't any advantage to keeping around a consistent instance of
33
+ * the navigation menu as when we create a new one it results in
34
+ * the same UPDATE action to be dispatched
35
+ */
36
+ NavigationMenu_1.create(app, { items: items, active: activeLink });
37
+ }, [items, activeLink]);
38
+ return null;
39
+ }
40
+ exports.default = NavigationMenu;
@@ -0,0 +1,3 @@
1
+ import NavigationMenu from './NavigationMenu';
2
+ export { Props } from './NavigationMenu';
3
+ export default NavigationMenu;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var NavigationMenu_1 = __importDefault(require("./NavigationMenu"));
7
+ exports.default = NavigationMenu_1.default;
@@ -0,0 +1,81 @@
1
+ import React, { PropsWithChildren } from 'react';
2
+ import type { AppConfigV2, DispatchActionHook } from '@shopify/app-bridge/client';
3
+ import type { History } from '../ClientRouter';
4
+ import type { LocationOrHref } from '../RoutePropagator';
5
+ /**
6
+ * Provider props
7
+ *
8
+ * @public
9
+ */
10
+ export interface Props {
11
+ /** Application configuration */
12
+ config: AppConfigV2;
13
+ /** The child elements to render. */
14
+ children?: React.ReactNode;
15
+ /**
16
+ * Option to set up client routing and route propagation automatically.
17
+ * Passing in a router will allow you to bypass setting these
18
+ * utilities up yourself.
19
+ *
20
+ * If you are using React Router, ensure that the Provider is a child
21
+ * of the router component. For example:
22
+ *
23
+ * import {useMemo} from 'react';
24
+ * import {useLocation, useNavigate, BrowserRouter} from 'react-router-dom';
25
+ * import {Provider} from '@shopify/app-bridge-react';
26
+ * import Routes from './Routes';
27
+ *
28
+ * export function App() {
29
+ * const navigate = useNavigate();
30
+ * const location = useLocation();
31
+ * const history = useMemo(
32
+ * () => ({replace: (path: string) => navigate(path, {replace: true})}),
33
+ * [navigate],
34
+ * );
35
+ * const router = useMemo(
36
+ * () => ({
37
+ * location,
38
+ * history,
39
+ * }),
40
+ * [location, navigate],
41
+ * );
42
+ * return (
43
+ * <Provider
44
+ * apiKey={{
45
+ * apiKey: 'API key from Shopify Partner Dashboard',
46
+ * host: host,
47
+ * }}
48
+ * router={router}
49
+ * >
50
+ * <Routes />
51
+ * </Provider>
52
+ * );
53
+ * }
54
+ *
55
+ * export default function AppWrapper() {
56
+ * return (
57
+ * <BrowserRouter>
58
+ * <App />
59
+ * </BrowserRouter>
60
+ * );
61
+ * }
62
+ */
63
+ router?: {
64
+ location: LocationOrHref;
65
+ history: History;
66
+ };
67
+ }
68
+ /**
69
+ * Create an App Bridge client application from a config and pass it as the
70
+ * value to the context provider.
71
+ *
72
+ * @public
73
+ */
74
+ declare function Provider({ config, router, children }: PropsWithChildren<Props>): JSX.Element;
75
+ /**
76
+ * Augment actions with clientInterface metadata, identifying use of this library
77
+ *
78
+ * @internal
79
+ */
80
+ export declare const setClientInterfaceHook: DispatchActionHook;
81
+ export default Provider;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.setClientInterfaceHook = void 0;
23
+ var react_1 = __importStar(require("react"));
24
+ var app_bridge_1 = __importStar(require("@shopify/app-bridge"));
25
+ var context_1 = require("../../context");
26
+ var ClientRouter_1 = require("../ClientRouter");
27
+ var RoutePropagator_1 = require("../RoutePropagator");
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
29
+ var packageJson = require('../../package.json');
30
+ /**
31
+ * Create an App Bridge client application from a config and pass it as the
32
+ * value to the context provider.
33
+ *
34
+ * @public
35
+ */
36
+ function Provider(_a) {
37
+ var config = _a.config, router = _a.router, children = _a.children;
38
+ var app = react_1.useMemo(function () { return app_bridge_1.default(config); }, [JSON.stringify(config)]);
39
+ react_1.useEffect(function () {
40
+ if (app === null || app === void 0 ? void 0 : app.hooks) {
41
+ app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
42
+ }
43
+ }, [app]);
44
+ var routerMarkup = (router === null || router === void 0 ? void 0 : router.history) && (router === null || router === void 0 ? void 0 : router.location) ? (react_1.default.createElement(Router, { history: router.history, location: router.location })) : null;
45
+ return (react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: app },
46
+ routerMarkup,
47
+ children));
48
+ }
49
+ /**
50
+ * Augment actions with clientInterface metadata, identifying use of this library
51
+ *
52
+ * @internal
53
+ */
54
+ var setClientInterfaceHook = function (next) {
55
+ return function (action) {
56
+ action.clientInterface = {
57
+ name: '@shopify/app-bridge-react',
58
+ version: packageJson.version,
59
+ };
60
+ return next(action);
61
+ };
62
+ };
63
+ exports.setClientInterfaceHook = setClientInterfaceHook;
64
+ function Router(_a) {
65
+ var history = _a.history, location = _a.location;
66
+ ClientRouter_1.useClientRouting(history);
67
+ RoutePropagator_1.useRoutePropagation(location);
68
+ return null;
69
+ }
70
+ exports.default = Provider;
@@ -0,0 +1,3 @@
1
+ import Provider from './Provider';
2
+ export { Props } from './Provider';
3
+ export default Provider;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var Provider_1 = __importDefault(require("./Provider"));
7
+ exports.default = Provider_1.default;
@@ -0,0 +1,68 @@
1
+ import { ActionVerb, ResourceType } from '@shopify/app-bridge/actions/ResourcePicker';
2
+ import type { BaseResource, Options, ResourceSelection, ProductOptions } from '@shopify/app-bridge/actions/ResourcePicker';
3
+ export interface SelectPayload {
4
+ /** The selected resources
5
+ * @see {@link https://help.shopify.com/en/api/embedded-apps/app-bridge/actions/resourcepicker|resource picker documentation} for more information
6
+ */
7
+ selection: ResourceSelection[];
8
+ }
9
+ interface BaseProps {
10
+ /** Whether the picker is open or not */
11
+ open: boolean;
12
+ /** GraphQL initial search query for filtering resources available in the picker
13
+ * @see {@link https://help.shopify.com/en/api/getting-started/search-syntax|search syntax} for more information
14
+ */
15
+ initialQuery?: string;
16
+ /** Resources that should already be selected when the picker is opened */
17
+ initialSelectionIds?: BaseResource[];
18
+ /** Show products that are not published on the Online Store */
19
+ showHidden?: boolean;
20
+ /**
21
+ * @deprecated as of 1.28.0
22
+ */
23
+ /** Whether to allow selection of multiple items */
24
+ allowMultiple?: boolean;
25
+ /** Whether to allow selection of multiple items, or the maximum number of selected items */
26
+ selectMultiple?: boolean | number;
27
+ /** Override default action verb `Add`. The actionVerb appears in the title `<actionVerb>` `<resourceType>` and as the primary action of the resource picker. */
28
+ actionVerb?: ActionVerb;
29
+ /** Callback when a selection has been made */
30
+ onSelection?(selectPayload: SelectPayload): void;
31
+ /** Callback when the picker is closed without selection */
32
+ onCancel?(): void;
33
+ }
34
+ export interface ProductPickerProps extends BaseProps {
35
+ /** The type of resource you want to pick */
36
+ resourceType: 'Product';
37
+ /** Whether to show product variants or not. Only applies to the product resource type picker */
38
+ showVariants?: boolean;
39
+ /** Whether to show draft products or not. Only applies to the product resource type picker */
40
+ showDraft?: boolean;
41
+ /** Whether to show archived products or not. Only applies to the product resource type picker */
42
+ showArchived?: boolean;
43
+ /** Whether to show draft badge for draft products or not. Only works when `showDraft` prop is set, and only applies to the product resource type picker */
44
+ showDraftBadge?: boolean;
45
+ /** Whether to show archived badge for archived products or not. Only works when `showArchived` prop is set, and only applies to the product resource type picker */
46
+ showArchivedBadge?: boolean;
47
+ }
48
+ export interface ProductVariantProps extends BaseProps {
49
+ /** The type of resource you want to pick */
50
+ resourceType: 'ProductVariant';
51
+ }
52
+ export interface CollectionPickerProps extends BaseProps {
53
+ /** The type of resource you want to pick */
54
+ resourceType: 'Collection';
55
+ }
56
+ export declare type Props = ProductPickerProps | ProductVariantProps | CollectionPickerProps;
57
+ /**
58
+ * ResourcePicker component
59
+ *
60
+ * @remarks
61
+ * React component which wraps the Shopify App Bridge ResourcePicker action.
62
+ *
63
+ * @public
64
+ */
65
+ declare function ResourcePicker(props: Props): null;
66
+ export default ResourcePicker;
67
+ export type { BaseResource, Options, ProductOptions };
68
+ export { ActionVerb, ResourceType };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ResourceType = exports.ActionVerb = void 0;
15
+ var react_1 = require("react");
16
+ var ResourcePicker_1 = require("@shopify/app-bridge/actions/ResourcePicker");
17
+ Object.defineProperty(exports, "ActionVerb", { enumerable: true, get: function () { return ResourcePicker_1.ActionVerb; } });
18
+ Object.defineProperty(exports, "ResourceType", { enumerable: true, get: function () { return ResourcePicker_1.ResourceType; } });
19
+ var useAppBridge_1 = require("../../useAppBridge");
20
+ /**
21
+ * ResourcePicker component
22
+ *
23
+ * @remarks
24
+ * React component which wraps the Shopify App Bridge ResourcePicker action.
25
+ *
26
+ * @public
27
+ */
28
+ function ResourcePicker(props) {
29
+ var app = useAppBridge_1.useAppBridge();
30
+ var focusReturnPoint = react_1.useRef(null);
31
+ var resourceType = props.resourceType, onSelection = props.onSelection, onCancel = props.onCancel, open = props.open;
32
+ // Initialize with open: false so the open action will dispatch on initial load
33
+ var prevProps = react_1.useRef({ open: false });
34
+ var picker = react_1.useMemo(function () {
35
+ return ResourcePicker_1.create(app, {
36
+ resourceType: ResourcePicker_1.ResourceType[resourceType],
37
+ options: getActionOptions(props),
38
+ });
39
+ // We purposely want to reuse the same picker instance
40
+ // and use a useEffect to call `picker.set` when needed
41
+ }, [app]);
42
+ react_1.useEffect(function () {
43
+ var _a;
44
+ var wasOpen = (_a = prevProps.current) === null || _a === void 0 ? void 0 : _a.open;
45
+ if (wasOpen !== open) {
46
+ if (open) {
47
+ picker.dispatch(ResourcePicker_1.Action.OPEN);
48
+ }
49
+ else {
50
+ picker.dispatch(ResourcePicker_1.Action.CLOSE);
51
+ }
52
+ }
53
+ if (!wasOpen && open) {
54
+ focusReturnPoint.current = document.activeElement;
55
+ }
56
+ else if (wasOpen &&
57
+ !open &&
58
+ focusReturnPoint.current != null &&
59
+ document.contains(focusReturnPoint.current)) {
60
+ focusReturnPoint.current.focus();
61
+ focusReturnPoint.current = null;
62
+ }
63
+ }, [open]);
64
+ react_1.useEffect(function () {
65
+ var unsubscribeList = [];
66
+ if (onSelection != null) {
67
+ unsubscribeList.push(picker.subscribe(ResourcePicker_1.Action.SELECT, onSelection));
68
+ }
69
+ if (onCancel != null) {
70
+ unsubscribeList.push(picker.subscribe(ResourcePicker_1.Action.CANCEL, onCancel));
71
+ }
72
+ return function () {
73
+ var unsubscribe = unsubscribeList.pop();
74
+ while (unsubscribe) {
75
+ unsubscribe();
76
+ unsubscribe = unsubscribeList.pop();
77
+ }
78
+ };
79
+ }, [onSelection, onCancel]);
80
+ react_1.useEffect(function () {
81
+ var shouldUpdate = JSON.stringify(__assign(__assign({}, prevProps.current), { open: undefined })) !==
82
+ JSON.stringify(__assign(__assign({}, props), { open: undefined }));
83
+ if (!shouldUpdate) {
84
+ return;
85
+ }
86
+ picker.set(getActionOptions(props));
87
+ prevProps.current = props;
88
+ }, [props]);
89
+ return null;
90
+ }
91
+ function getActionOptions(props) {
92
+ var initialQuery = props.initialQuery, initialSelectionIds = props.initialSelectionIds, showHidden = props.showHidden, allowMultiple = props.allowMultiple, selectMultiple = props.selectMultiple, actionVerb = props.actionVerb;
93
+ var sharedOptions = {
94
+ initialQuery: initialQuery,
95
+ initialSelectionIds: initialSelectionIds,
96
+ showHidden: showHidden,
97
+ selectMultiple: selectMultiple !== null && selectMultiple !== void 0 ? selectMultiple : allowMultiple,
98
+ actionVerb: actionVerb,
99
+ };
100
+ var result = sharedOptions;
101
+ if (props.resourceType === 'Product') {
102
+ var showVariants = props.showVariants, showDraft = props.showDraft, showArchived = props.showArchived, showDraftBadge = props.showDraftBadge, showArchivedBadge = props.showArchivedBadge;
103
+ var productSpecificOptions = {
104
+ showVariants: showVariants,
105
+ showDraft: showDraft,
106
+ showArchived: showArchived,
107
+ showDraftBadge: showDraftBadge,
108
+ showArchivedBadge: showArchivedBadge,
109
+ };
110
+ result = __assign(__assign({}, sharedOptions), productSpecificOptions);
111
+ }
112
+ return result;
113
+ }
114
+ exports.default = ResourcePicker;
@@ -0,0 +1,3 @@
1
+ import ResourcePicker from './ResourcePicker';
2
+ export { Props } from './ResourcePicker';
3
+ export default ResourcePicker;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var ResourcePicker_1 = __importDefault(require("./ResourcePicker"));
7
+ exports.default = ResourcePicker_1.default;
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { LocationOrHref } from './route-propagator';
3
+ export interface Props {
4
+ location: LocationOrHref;
5
+ }
6
+ /**
7
+ * RoutePropagator component
8
+ *
9
+ * @remarks
10
+ * React component which keeps the Shopify admin url in sync with the app url
11
+ *
12
+ * @public
13
+ */
14
+ declare class RoutePropagator extends React.Component<Props, never> {
15
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
16
+ componentDidMount(): void;
17
+ componentDidUpdate({ location: prevLocation }: Props): void;
18
+ render(): null;
19
+ }
20
+ export default RoutePropagator;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ var react_1 = __importDefault(require("react"));
22
+ var context_1 = require("../../context");
23
+ var route_propagator_1 = require("./route-propagator");
24
+ /**
25
+ * RoutePropagator component
26
+ *
27
+ * @remarks
28
+ * React component which keeps the Shopify admin url in sync with the app url
29
+ *
30
+ * @public
31
+ */
32
+ var RoutePropagator = /** @class */ (function (_super) {
33
+ __extends(RoutePropagator, _super);
34
+ function RoutePropagator() {
35
+ return _super !== null && _super.apply(this, arguments) || this;
36
+ }
37
+ RoutePropagator.prototype.componentDidMount = function () {
38
+ var location = this.props.location;
39
+ route_propagator_1.updateHistory(this.context, location);
40
+ };
41
+ RoutePropagator.prototype.componentDidUpdate = function (_a) {
42
+ var prevLocation = _a.location;
43
+ var location = this.props.location;
44
+ if (location !== prevLocation) {
45
+ route_propagator_1.updateHistory(this.context, location);
46
+ }
47
+ };
48
+ RoutePropagator.prototype.render = function () {
49
+ return null;
50
+ };
51
+ RoutePropagator.contextType = context_1.AppBridgeContext;
52
+ return RoutePropagator;
53
+ }(react_1.default.Component));
54
+ exports.default = RoutePropagator;
@@ -0,0 +1,3 @@
1
+ export declare function getSelfWindow(): Window & typeof globalThis;
2
+ export declare function getTopWindow(): Window;
3
+ export declare function getOrigin(): string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOrigin = exports.getTopWindow = exports.getSelfWindow = void 0;
4
+ function getSelfWindow() {
5
+ return window.self;
6
+ }
7
+ exports.getSelfWindow = getSelfWindow;
8
+ function getTopWindow() {
9
+ return window.top;
10
+ }
11
+ exports.getTopWindow = getTopWindow;
12
+ function getOrigin() {
13
+ return location.origin;
14
+ }
15
+ exports.getOrigin = getOrigin;
@@ -0,0 +1,10 @@
1
+ import { LocationOrHref } from './route-propagator';
2
+ /**
3
+ * useRoutePropagation
4
+ *
5
+ * @remarks
6
+ * A hook which keeps the Shopify admin url in sync with the app url
7
+ *
8
+ * @public
9
+ */
10
+ export default function useRoutePropagation(location: LocationOrHref): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
4
+ var useAppBridge_1 = require("../../useAppBridge");
5
+ var route_propagator_1 = require("./route-propagator");
6
+ /**
7
+ * useRoutePropagation
8
+ *
9
+ * @remarks
10
+ * A hook which keeps the Shopify admin url in sync with the app url
11
+ *
12
+ * @public
13
+ */
14
+ function useRoutePropagation(location) {
15
+ var app = useAppBridge_1.useAppBridge();
16
+ react_1.useEffect(function () {
17
+ route_propagator_1.updateHistory(app, location);
18
+ }, [app, location]);
19
+ }
20
+ exports.default = useRoutePropagation;
@@ -0,0 +1,3 @@
1
+ export { default as RoutePropagator } from './RoutePropagator';
2
+ export { default as useRoutePropagation } from './hook';
3
+ export { LocationOrHref } from './route-propagator';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useRoutePropagation = exports.RoutePropagator = void 0;
7
+ var RoutePropagator_1 = require("./RoutePropagator");
8
+ Object.defineProperty(exports, "RoutePropagator", { enumerable: true, get: function () { return __importDefault(RoutePropagator_1).default; } });
9
+ var hook_1 = require("./hook");
10
+ Object.defineProperty(exports, "useRoutePropagation", { enumerable: true, get: function () { return __importDefault(hook_1).default; } });
@@ -0,0 +1,7 @@
1
+ import type { ClientApplication } from '@shopify/app-bridge';
2
+ export declare type LocationOrHref = string | {
3
+ search: string;
4
+ hash: string;
5
+ pathname: string;
6
+ };
7
+ export declare function updateHistory(app: ClientApplication, location: LocationOrHref): Promise<void>;
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.updateHistory = void 0;
40
+ var MessageTransport_1 = require("@shopify/app-bridge/MessageTransport");
41
+ var actions_1 = require("@shopify/app-bridge/actions");
42
+ var globals_1 = require("./globals");
43
+ // These parameters are added to the iframe url but we don't want to propagate
44
+ // them up to the address bar as they are not provided by the application
45
+ // Removing hmac is especially important as its presence may cause infinite
46
+ // oauth authentication loops
47
+ var embeddedFrameParamsToRemove = [
48
+ 'hmac',
49
+ 'locale',
50
+ 'protocol',
51
+ 'session',
52
+ 'shop',
53
+ 'timestamp',
54
+ 'host',
55
+ ];
56
+ function updateHistory(app, location) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var selfWindow, topWindow, renderedInTheTopWindow, renderedAsMainApp, normalizedLocation, pathname, search, hash, locationStr;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ selfWindow = globals_1.getSelfWindow();
63
+ topWindow = globals_1.getTopWindow();
64
+ renderedInTheTopWindow = selfWindow === topWindow;
65
+ return [4 /*yield*/, app.getState('context').then(function (context) {
66
+ return context === MessageTransport_1.Context.Main;
67
+ })];
68
+ case 1:
69
+ renderedAsMainApp = _a.sent();
70
+ if (renderedInTheTopWindow || !renderedAsMainApp) {
71
+ return [2 /*return*/];
72
+ }
73
+ normalizedLocation = getNormalizedURL(location);
74
+ embeddedFrameParamsToRemove.forEach(function (param) { return normalizedLocation.searchParams.delete(param); });
75
+ pathname = normalizedLocation.pathname, search = normalizedLocation.search, hash = normalizedLocation.hash;
76
+ locationStr = "" + pathname + search + hash;
77
+ actions_1.History.create(app).dispatch(actions_1.History.Action.REPLACE, locationStr);
78
+ return [2 /*return*/];
79
+ }
80
+ });
81
+ });
82
+ }
83
+ exports.updateHistory = updateHistory;
84
+ function getNormalizedURL(location) {
85
+ var origin = globals_1.getOrigin();
86
+ if (typeof location === 'string') {
87
+ return new URL(location, origin);
88
+ }
89
+ var pathname = location.pathname, search = location.search, hash = location.hash;
90
+ return new URL("" + pathname + search + hash, origin);
91
+ }