@shopify/app-bridge-react 0.0.0-snapshot-20221220002610

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 (107) hide show
  1. package/README.md +171 -0
  2. package/components/ClientRouter/ClientRouter.d.ts +23 -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 +9 -0
  11. package/components/ContextualSaveBar/ContextualSaveBar.js +24 -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 +19 -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 +24 -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 +78 -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 +36 -0
  35. package/components/ResourcePicker/ResourcePicker.js +120 -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 +22 -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 +107 -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 +38 -0
  53. package/components/Toast/Toast.js +67 -0
  54. package/components/Toast/index.d.ts +3 -0
  55. package/components/Toast/index.js +7 -0
  56. package/components/index.d.ts +11 -0
  57. package/components/index.js +37 -0
  58. package/components/unstable_Picker/index.d.ts +3 -0
  59. package/components/unstable_Picker/index.js +7 -0
  60. package/components/unstable_Picker/unstable_Picker.d.ts +13 -0
  61. package/components/unstable_Picker/unstable_Picker.js +85 -0
  62. package/context.d.ts +14 -0
  63. package/context.js +10 -0
  64. package/hooks/index.d.ts +9 -0
  65. package/hooks/index.js +19 -0
  66. package/hooks/useAppBridgeState/index.d.ts +1 -0
  67. package/hooks/useAppBridgeState/index.js +13 -0
  68. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
  69. package/hooks/useAppBridgeState/useAppBridgeState.js +89 -0
  70. package/hooks/useContextualSaveBar/index.d.ts +1 -0
  71. package/hooks/useContextualSaveBar/index.js +5 -0
  72. package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +10 -0
  73. package/hooks/useContextualSaveBar/useContextualSaveBar.js +87 -0
  74. package/hooks/useFeatureRequest/index.d.ts +1 -0
  75. package/hooks/useFeatureRequest/index.js +13 -0
  76. package/hooks/useFeatureRequest/useFeatureRequest.d.ts +13 -0
  77. package/hooks/useFeatureRequest/useFeatureRequest.js +49 -0
  78. package/hooks/useFeaturesAvailable/index.d.ts +2 -0
  79. package/hooks/useFeaturesAvailable/index.js +5 -0
  80. package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +12 -0
  81. package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +101 -0
  82. package/hooks/useLocale/index.d.ts +1 -0
  83. package/hooks/useLocale/index.js +5 -0
  84. package/hooks/useLocale/useLocale.d.ts +1 -0
  85. package/hooks/useLocale/useLocale.js +8 -0
  86. package/hooks/useNavigate/index.d.ts +1 -0
  87. package/hooks/useNavigate/index.js +5 -0
  88. package/hooks/useNavigate/useNavigate.d.ts +3 -0
  89. package/hooks/useNavigate/useNavigate.js +63 -0
  90. package/hooks/useNavigationHistory/index.d.ts +1 -0
  91. package/hooks/useNavigationHistory/index.js +5 -0
  92. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
  93. package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
  94. package/hooks/useToast/index.d.ts +1 -0
  95. package/hooks/useToast/index.js +5 -0
  96. package/hooks/useToast/useToast.d.ts +20 -0
  97. package/hooks/useToast/useToast.js +46 -0
  98. package/index.d.ts +4 -0
  99. package/index.js +19 -0
  100. package/package.json +58 -0
  101. package/types.d.ts +35 -0
  102. package/types.js +5 -0
  103. package/umd/index.js +10 -0
  104. package/useAppBridge.d.ts +1 -0
  105. package/useAppBridge.js +13 -0
  106. package/utilities/transformers.d.ts +20 -0
  107. package/utilities/transformers.js +105 -0
@@ -0,0 +1,61 @@
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 actions_1 = require("@shopify/app-bridge/actions");
23
+ var context_1 = require("../../../context");
24
+ /**
25
+ * Modal Content component
26
+ *
27
+ * @remarks
28
+ * React component which wraps the Shopify App Bridge Modal Content action.
29
+ *
30
+ * @public
31
+ */
32
+ var ModalContent = /** @class */ (function (_super) {
33
+ __extends(ModalContent, _super);
34
+ function ModalContent() {
35
+ return _super !== null && _super.apply(this, arguments) || this;
36
+ }
37
+ ModalContent.prototype.componentDidMount = function () {
38
+ var app = this.context;
39
+ this.modalContent = actions_1.ModalContent.create(app);
40
+ this.syncLoadingStatus();
41
+ };
42
+ ModalContent.prototype.componentDidUpdate = function () {
43
+ this.syncLoadingStatus();
44
+ };
45
+ ModalContent.prototype.syncLoadingStatus = function () {
46
+ if (!this.modalContent)
47
+ return;
48
+ if (this.props.loading) {
49
+ this.modalContent.loading();
50
+ }
51
+ else {
52
+ this.modalContent.loaded();
53
+ }
54
+ };
55
+ ModalContent.prototype.render = function () {
56
+ return null;
57
+ };
58
+ ModalContent.contextType = context_1.AppBridgeContext;
59
+ return ModalContent;
60
+ }(react_1.default.Component));
61
+ exports.default = ModalContent;
@@ -0,0 +1,2 @@
1
+ import ModalContent from './ModalContent';
2
+ export default ModalContent;
@@ -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 ModalContent_1 = __importDefault(require("./ModalContent"));
7
+ exports.default = ModalContent_1.default;
@@ -0,0 +1,4 @@
1
+ import Modal from './Modal';
2
+ export { default as ModalContent } from './ModalContent';
3
+ export { Props } from './Modal';
4
+ export default Modal;
@@ -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.ModalContent = void 0;
7
+ var Modal_1 = __importDefault(require("./Modal"));
8
+ var ModalContent_1 = require("./ModalContent");
9
+ Object.defineProperty(exports, "ModalContent", { enumerable: true, get: function () { return __importDefault(ModalContent_1).default; } });
10
+ exports.default = Modal_1.default;
@@ -0,0 +1,17 @@
1
+ export interface NavigationLink {
2
+ label: string;
3
+ destination: string;
4
+ }
5
+ export interface Props {
6
+ /**
7
+ * List of links in navigation menu
8
+ */
9
+ navigationLinks: NavigationLink[];
10
+ /**
11
+ * Custom matcher to set active link.
12
+ * This function will be called with each link and the current location.
13
+ * If it returns true the current link will be set to the active link.
14
+ */
15
+ matcher?: (link: NavigationLink, location: Location) => boolean;
16
+ }
17
+ export default function NavigationMenu({ navigationLinks, matcher }: Props): null;
@@ -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,78 @@
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
+ /**
39
+ * We are intentionally ignoring the `config` prop here as it yields a
40
+ * bug on apps build with Next.js which loses the `host` query param
41
+ * upon redirect.
42
+ *
43
+ * This was the behavior of the original `Provider` component prior to
44
+ * the refactor in version 2.0.25.
45
+ */
46
+ var app = react_1.useMemo(function () { return app_bridge_1.default(config); }, []);
47
+ react_1.useEffect(function () {
48
+ if (app === null || app === void 0 ? void 0 : app.hooks) {
49
+ app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
50
+ }
51
+ }, [app]);
52
+ 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;
53
+ return (react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: app },
54
+ routerMarkup,
55
+ children));
56
+ }
57
+ /**
58
+ * Augment actions with clientInterface metadata, identifying use of this library
59
+ *
60
+ * @internal
61
+ */
62
+ var setClientInterfaceHook = function (next) {
63
+ return function (action) {
64
+ action.clientInterface = {
65
+ name: '@shopify/app-bridge-react',
66
+ version: packageJson.version,
67
+ };
68
+ return next(action);
69
+ };
70
+ };
71
+ exports.setClientInterfaceHook = setClientInterfaceHook;
72
+ function Router(_a) {
73
+ var history = _a.history, location = _a.location;
74
+ ClientRouter_1.useClientRouting(history);
75
+ RoutePropagator_1.useRoutePropagation(location);
76
+ return null;
77
+ }
78
+ 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,36 @@
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
+ selection: ResourceSelection[];
5
+ }
6
+ interface BaseProps extends Options {
7
+ open: boolean;
8
+ /**
9
+ * @deprecated as of 1.28.0
10
+ */
11
+ allowMultiple?: boolean;
12
+ onSelection?(selectPayload: SelectPayload): void;
13
+ onCancel?(): void;
14
+ }
15
+ export interface ProductPickerProps extends BaseProps, ProductOptions {
16
+ resourceType: 'Product';
17
+ }
18
+ export interface ProductVariantProps extends BaseProps {
19
+ resourceType: 'ProductVariant';
20
+ }
21
+ export interface CollectionPickerProps extends BaseProps {
22
+ resourceType: 'Collection';
23
+ }
24
+ export declare type Props = ProductPickerProps | ProductVariantProps | CollectionPickerProps;
25
+ /**
26
+ * ResourcePicker component
27
+ *
28
+ * @remarks
29
+ * React component which wraps the Shopify App Bridge ResourcePicker action.
30
+ *
31
+ * @public
32
+ */
33
+ declare function ResourcePicker({ open, resourceType, onSelection, onCancel, allowMultiple, selectMultiple, ...props }: Props): null;
34
+ export default ResourcePicker;
35
+ export type { BaseResource, Options, ProductOptions };
36
+ export { ActionVerb, ResourceType };
@@ -0,0 +1,120 @@
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
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.ResourceType = exports.ActionVerb = void 0;
26
+ var react_1 = require("react");
27
+ var ResourcePicker_1 = require("@shopify/app-bridge/actions/ResourcePicker");
28
+ Object.defineProperty(exports, "ActionVerb", { enumerable: true, get: function () { return ResourcePicker_1.ActionVerb; } });
29
+ Object.defineProperty(exports, "ResourceType", { enumerable: true, get: function () { return ResourcePicker_1.ResourceType; } });
30
+ var useAppBridge_1 = require("../../useAppBridge");
31
+ /**
32
+ * ResourcePicker component
33
+ *
34
+ * @remarks
35
+ * React component which wraps the Shopify App Bridge ResourcePicker action.
36
+ *
37
+ * @public
38
+ */
39
+ function ResourcePicker(_a) {
40
+ var open = _a.open, resourceType = _a.resourceType, onSelection = _a.onSelection, onCancel = _a.onCancel, allowMultiple = _a.allowMultiple, selectMultiple = _a.selectMultiple, props = __rest(_a, ["open", "resourceType", "onSelection", "onCancel", "allowMultiple", "selectMultiple"]);
41
+ var options = react_1.useMemo(function () { return (__assign(__assign({}, props), { selectMultiple: selectMultiple !== null && selectMultiple !== void 0 ? selectMultiple : allowMultiple })); }, [allowMultiple, props, selectMultiple]);
42
+ var app = useAppBridge_1.useAppBridge();
43
+ var isUnmountedRef = react_1.useRef(false);
44
+ react_1.useEffect(function () { return function () {
45
+ isUnmountedRef.current = true;
46
+ }; }, []);
47
+ var openRef = react_1.useRef(false);
48
+ var optionsRef = react_1.useRef(options);
49
+ var picker = react_1.useMemo(function () {
50
+ return ResourcePicker_1.create(app, {
51
+ resourceType: ResourcePicker_1.ResourceType[resourceType],
52
+ options: optionsRef.current,
53
+ });
54
+ }, [app, resourceType]);
55
+ react_1.useEffect(function () {
56
+ openRef.current = false;
57
+ return function () {
58
+ if (openRef.current && isUnmountedRef.current) {
59
+ picker.dispatch(ResourcePicker_1.Action.CANCEL);
60
+ }
61
+ };
62
+ }, [picker]);
63
+ var focusReturnPointRef = react_1.useRef(null);
64
+ var storeFocusReturnPoint = react_1.useCallback(function () {
65
+ if (document.activeElement instanceof HTMLElement) {
66
+ focusReturnPointRef.current = document.activeElement;
67
+ }
68
+ }, []);
69
+ var applyFocusReturnPoint = react_1.useCallback(function () {
70
+ var focusReturnPoint = focusReturnPointRef.current;
71
+ focusReturnPointRef.current = null;
72
+ if (focusReturnPoint && document.contains(focusReturnPoint)) {
73
+ focusReturnPoint.focus();
74
+ }
75
+ }, []);
76
+ react_1.useEffect(function () {
77
+ if (open === openRef.current)
78
+ return;
79
+ openRef.current = open;
80
+ if (open) {
81
+ picker.dispatch(ResourcePicker_1.Action.OPEN);
82
+ storeFocusReturnPoint();
83
+ }
84
+ else {
85
+ picker.dispatch(ResourcePicker_1.Action.CLOSE);
86
+ applyFocusReturnPoint();
87
+ }
88
+ }, [picker, open, storeFocusReturnPoint, applyFocusReturnPoint]);
89
+ react_1.useEffect(function () {
90
+ if (!onSelection)
91
+ return;
92
+ return picker.subscribe(ResourcePicker_1.Action.SELECT, function () {
93
+ var args = [];
94
+ for (var _i = 0; _i < arguments.length; _i++) {
95
+ args[_i] = arguments[_i];
96
+ }
97
+ openRef.current = false;
98
+ applyFocusReturnPoint();
99
+ return onSelection.apply(void 0, args);
100
+ });
101
+ }, [picker, onSelection, applyFocusReturnPoint]);
102
+ react_1.useEffect(function () {
103
+ if (!onCancel)
104
+ return;
105
+ return picker.subscribe(ResourcePicker_1.Action.CANCEL, function () {
106
+ openRef.current = false;
107
+ applyFocusReturnPoint();
108
+ return onCancel();
109
+ });
110
+ }, [picker, onCancel, applyFocusReturnPoint]);
111
+ react_1.useEffect(function () {
112
+ var shouldUpdate = JSON.stringify(options) !== JSON.stringify(optionsRef.current);
113
+ if (!shouldUpdate)
114
+ return;
115
+ optionsRef.current = options;
116
+ picker.set(options);
117
+ }, [picker, options]);
118
+ return null;
119
+ }
120
+ 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,22 @@
1
+ import React from 'react';
2
+ import { AppBridgeContext } from '../../context';
3
+ import { LocationOrHref } from './route-propagator';
4
+ export interface Props {
5
+ location: LocationOrHref;
6
+ }
7
+ /**
8
+ * RoutePropagator component
9
+ *
10
+ * @remarks
11
+ * React component which keeps the Shopify admin url in sync with the app url
12
+ *
13
+ * @public
14
+ */
15
+ declare class RoutePropagator extends React.Component<Props, never> {
16
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
17
+ context: React.ContextType<typeof AppBridgeContext>;
18
+ componentDidMount(): void;
19
+ componentDidUpdate({ location: prevLocation }: Props): void;
20
+ render(): null;
21
+ }
22
+ 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>;