@shopify/app-bridge-react 3.7.11-snapshot-20240220213625 → 4.0.0

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 (121) hide show
  1. package/LICENSE.md +7 -0
  2. package/README.md +98 -128
  3. package/dist/index.cjs +28 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +88 -0
  6. package/dist/index.js +700 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +45 -42
  9. package/components/ClientRouter/ClientRouter.d.ts +0 -23
  10. package/components/ClientRouter/ClientRouter.js +0 -52
  11. package/components/ClientRouter/hook.d.ts +0 -10
  12. package/components/ClientRouter/hook.js +0 -20
  13. package/components/ClientRouter/index.d.ts +0 -3
  14. package/components/ClientRouter/index.js +0 -10
  15. package/components/ClientRouter/router.d.ts +0 -5
  16. package/components/ClientRouter/router.js +0 -11
  17. package/components/ContextualSaveBar/ContextualSaveBar.d.ts +0 -9
  18. package/components/ContextualSaveBar/ContextualSaveBar.js +0 -24
  19. package/components/ContextualSaveBar/index.d.ts +0 -3
  20. package/components/ContextualSaveBar/index.js +0 -7
  21. package/components/Loading/Loading.d.ts +0 -19
  22. package/components/Loading/Loading.js +0 -55
  23. package/components/Loading/index.d.ts +0 -2
  24. package/components/Loading/index.js +0 -7
  25. package/components/Modal/Modal.d.ts +0 -32
  26. package/components/Modal/Modal.js +0 -140
  27. package/components/Modal/ModalContent/ModalContent.d.ts +0 -24
  28. package/components/Modal/ModalContent/ModalContent.js +0 -61
  29. package/components/Modal/ModalContent/index.d.ts +0 -2
  30. package/components/Modal/ModalContent/index.js +0 -7
  31. package/components/Modal/index.d.ts +0 -4
  32. package/components/Modal/index.js +0 -10
  33. package/components/NavigationMenu/NavigationMenu.d.ts +0 -18
  34. package/components/NavigationMenu/NavigationMenu.js +0 -44
  35. package/components/NavigationMenu/index.d.ts +0 -3
  36. package/components/NavigationMenu/index.js +0 -7
  37. package/components/Provider/Provider.d.ts +0 -87
  38. package/components/Provider/Provider.js +0 -81
  39. package/components/Provider/index.d.ts +0 -3
  40. package/components/Provider/index.js +0 -7
  41. package/components/ResourcePicker/ResourcePicker.d.ts +0 -36
  42. package/components/ResourcePicker/ResourcePicker.js +0 -120
  43. package/components/ResourcePicker/index.d.ts +0 -3
  44. package/components/ResourcePicker/index.js +0 -7
  45. package/components/RoutePropagator/RoutePropagator.d.ts +0 -22
  46. package/components/RoutePropagator/RoutePropagator.js +0 -54
  47. package/components/RoutePropagator/globals.d.ts +0 -3
  48. package/components/RoutePropagator/globals.js +0 -15
  49. package/components/RoutePropagator/hook.d.ts +0 -10
  50. package/components/RoutePropagator/hook.js +0 -20
  51. package/components/RoutePropagator/index.d.ts +0 -3
  52. package/components/RoutePropagator/index.js +0 -10
  53. package/components/RoutePropagator/route-propagator.d.ts +0 -7
  54. package/components/RoutePropagator/route-propagator.js +0 -91
  55. package/components/TitleBar/TitleBar.d.ts +0 -27
  56. package/components/TitleBar/TitleBar.js +0 -107
  57. package/components/TitleBar/index.d.ts +0 -3
  58. package/components/TitleBar/index.js +0 -7
  59. package/components/Toast/Toast.d.ts +0 -38
  60. package/components/Toast/Toast.js +0 -67
  61. package/components/Toast/index.d.ts +0 -3
  62. package/components/Toast/index.js +0 -7
  63. package/components/index.d.ts +0 -11
  64. package/components/index.js +0 -37
  65. package/components/unstable_Picker/index.d.ts +0 -3
  66. package/components/unstable_Picker/index.js +0 -7
  67. package/components/unstable_Picker/unstable_Picker.d.ts +0 -13
  68. package/components/unstable_Picker/unstable_Picker.js +0 -85
  69. package/context.d.ts +0 -14
  70. package/context.js +0 -10
  71. package/hooks/index.d.ts +0 -10
  72. package/hooks/index.js +0 -21
  73. package/hooks/useAppBridgeState/index.d.ts +0 -1
  74. package/hooks/useAppBridgeState/index.js +0 -13
  75. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +0 -10
  76. package/hooks/useAppBridgeState/useAppBridgeState.js +0 -89
  77. package/hooks/useAuthenticatedFetch/index.d.ts +0 -1
  78. package/hooks/useAuthenticatedFetch/index.js +0 -13
  79. package/hooks/useAuthenticatedFetch/useAuthenticatedFetch.d.ts +0 -11
  80. package/hooks/useAuthenticatedFetch/useAuthenticatedFetch.js +0 -22
  81. package/hooks/useContextualSaveBar/index.d.ts +0 -1
  82. package/hooks/useContextualSaveBar/index.js +0 -5
  83. package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +0 -10
  84. package/hooks/useContextualSaveBar/useContextualSaveBar.js +0 -85
  85. package/hooks/useFeatureRequest/index.d.ts +0 -1
  86. package/hooks/useFeatureRequest/index.js +0 -13
  87. package/hooks/useFeatureRequest/useFeatureRequest.d.ts +0 -13
  88. package/hooks/useFeatureRequest/useFeatureRequest.js +0 -49
  89. package/hooks/useFeaturesAvailable/index.d.ts +0 -2
  90. package/hooks/useFeaturesAvailable/index.js +0 -5
  91. package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +0 -12
  92. package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +0 -101
  93. package/hooks/useLocale/index.d.ts +0 -1
  94. package/hooks/useLocale/index.js +0 -5
  95. package/hooks/useLocale/useLocale.d.ts +0 -1
  96. package/hooks/useLocale/useLocale.js +0 -8
  97. package/hooks/useNavigate/index.d.ts +0 -1
  98. package/hooks/useNavigate/index.js +0 -5
  99. package/hooks/useNavigate/useNavigate.d.ts +0 -3
  100. package/hooks/useNavigate/useNavigate.js +0 -63
  101. package/hooks/useNavigationHistory/index.d.ts +0 -1
  102. package/hooks/useNavigationHistory/index.js +0 -5
  103. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +0 -16
  104. package/hooks/useNavigationHistory/useNavigationHistory.js +0 -28
  105. package/hooks/useOnceEffect/index.d.ts +0 -1
  106. package/hooks/useOnceEffect/index.js +0 -13
  107. package/hooks/useOnceEffect/useOnceEffect.d.ts +0 -5
  108. package/hooks/useOnceEffect/useOnceEffect.js +0 -11
  109. package/hooks/useToast/index.d.ts +0 -1
  110. package/hooks/useToast/index.js +0 -5
  111. package/hooks/useToast/useToast.d.ts +0 -20
  112. package/hooks/useToast/useToast.js +0 -46
  113. package/index.d.ts +0 -4
  114. package/index.js +0 -19
  115. package/types.d.ts +0 -35
  116. package/types.js +0 -5
  117. package/umd/index.js +0 -10
  118. package/useAppBridge.d.ts +0 -1
  119. package/useAppBridge.js +0 -13
  120. package/utilities/transformers.d.ts +0 -20
  121. package/utilities/transformers.js +0 -105
@@ -1,140 +0,0 @@
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
- var react_1 = require("react");
26
- var Modal_1 = require("@shopify/app-bridge/actions/Modal");
27
- var transformers_1 = require("../../utilities/transformers");
28
- var useAppBridge_1 = require("../../useAppBridge");
29
- var useOnceEffect_1 = require("../../hooks/useOnceEffect");
30
- /**
31
- * Modal component
32
- *
33
- * @remarks
34
- * React component which wraps the Shopify App Bridge Modal action.
35
- *
36
- * @public
37
- */
38
- function Modal(props) {
39
- var app = useAppBridge_1.useAppBridge();
40
- var focusReturnPoint = react_1.useRef(null);
41
- // Initialize with open: false so the open action will dispatch on initial load
42
- var prevProps = react_1.useRef({ open: false });
43
- var open = props.open;
44
- var isUnmounted = react_1.useRef(false);
45
- var modal = react_1.useMemo(function () {
46
- /**
47
- * We purposely don't pass buttons here as they will be replaced
48
- * by the subsequent useEffect to call `set` to update the options.
49
- * If we pass them in here button subscriptions will be created without
50
- * being cleaned up.
51
- */
52
- var primaryAction = props.primaryAction, secondaryActions = props.secondaryActions, rest = __rest(props, ["primaryAction", "secondaryActions"]);
53
- return Modal_1.create(app, transformProps(app, rest));
54
- }, [app]);
55
- /**
56
- * All option updates are handled in this useEffect to avoid race conditions.
57
- * For example, we need to call `modal.unsubscribe` to clean up button subscriptions
58
- * but we calling it will also unsubscribe the onClose handler. Therefore we want
59
- * to ensure all callbacks are handled in a single useEffect with a single clean up
60
- * call to unsubscribe.
61
- */
62
- react_1.useEffect(function () {
63
- if (isUnmounted.current) {
64
- prevProps.current = props;
65
- return;
66
- }
67
- var wasOpen = prevProps.current.open;
68
- var openUpdated = wasOpen !== open;
69
- /** We only call `set` to update the options if the modal is open.
70
- * This is because while the modal is closed updates don't take effect on screen.
71
- */
72
- if (open) {
73
- var transformedProps = transformProps(app, props, wasOpen);
74
- /** We skip dispatching the update action if we're about to update the open state.
75
- * This is because the OPEN action will always sends the updated options
76
- * so we don't need to send it twice.
77
- */
78
- var shouldSendUpdate = !openUpdated;
79
- if (isIframeModal(transformedProps)) {
80
- modal.set(transformedProps, shouldSendUpdate);
81
- }
82
- else {
83
- modal.set(transformedProps, shouldSendUpdate);
84
- }
85
- }
86
- if (openUpdated) {
87
- if (open) {
88
- modal.dispatch(Modal_1.Action.OPEN);
89
- focusReturnPoint.current = document.activeElement;
90
- }
91
- else {
92
- modal.dispatch(Modal_1.Action.CLOSE);
93
- if (focusReturnPoint.current != null && document.contains(focusReturnPoint.current)) {
94
- focusReturnPoint.current.focus();
95
- focusReturnPoint.current = null;
96
- }
97
- }
98
- }
99
- if (props.onClose != null) {
100
- modal.subscribe(Modal_1.Action.CLOSE, props.onClose);
101
- }
102
- prevProps.current = props;
103
- return function () {
104
- // This is important to clean up previous buttons and onClose subscriptions
105
- modal.unsubscribe();
106
- };
107
- }, [props, open]);
108
- useOnceEffect_1.useOnceEffect(function () {
109
- return function () {
110
- if (prevProps.current.open) {
111
- modal.dispatch(Modal_1.Action.CLOSE);
112
- }
113
- };
114
- }, []);
115
- return null;
116
- }
117
- function isIframeModal(options) {
118
- return (typeof options.url === 'string' ||
119
- typeof options.path === 'string');
120
- }
121
- function transformProps(app, props, wasOpen) {
122
- var title = props.title, size = props.size, message = props.message, src = props.src, primaryAction = props.primaryAction, secondaryActions = props.secondaryActions, loading = props.loading;
123
- var safeSize = size == null ? undefined : Modal_1.Size[size];
124
- var srcPayload = {};
125
- if (src != null) {
126
- if (src.match('^https?://')) {
127
- srcPayload.url = src;
128
- }
129
- else {
130
- srcPayload.path = src;
131
- }
132
- }
133
- return __assign(__assign({ title: title, message: message, size: safeSize }, srcPayload), { footer: {
134
- buttons: transformers_1.transformActions(app, {
135
- primaryAction: primaryAction,
136
- secondaryActions: secondaryActions,
137
- }),
138
- }, loading: wasOpen ? undefined : loading });
139
- }
140
- exports.default = Modal;
@@ -1,24 +0,0 @@
1
- import React from 'react';
2
- import { AppBridgeContext } from '../../../context';
3
- export interface Props {
4
- /** Show/Dismiss loading spinner */
5
- loading: boolean;
6
- }
7
- /**
8
- * Modal Content component
9
- *
10
- * @remarks
11
- * React component which wraps the Shopify App Bridge Modal Content action.
12
- *
13
- * @public
14
- */
15
- declare class ModalContent extends React.Component<Props> {
16
- static contextType: React.Context<import("../../../context").IAppBridgeContext>;
17
- context: React.ContextType<typeof AppBridgeContext>;
18
- private modalContent;
19
- componentDidMount(): void;
20
- componentDidUpdate(): void;
21
- syncLoadingStatus(): void;
22
- render(): null;
23
- }
24
- export default ModalContent;
@@ -1,61 +0,0 @@
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;
@@ -1,2 +0,0 @@
1
- import ModalContent from './ModalContent';
2
- export default ModalContent;
@@ -1,7 +0,0 @@
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;
@@ -1,4 +0,0 @@
1
- import Modal from './Modal';
2
- export { default as ModalContent } from './ModalContent';
3
- export { Props } from './Modal';
4
- export default Modal;
@@ -1,10 +0,0 @@
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;
@@ -1,18 +0,0 @@
1
- import { LocationOrHref } from '../RoutePropagator';
2
- export interface NavigationLink {
3
- label: string;
4
- destination: string;
5
- }
6
- export interface Props {
7
- /**
8
- * List of links in navigation menu
9
- */
10
- navigationLinks: NavigationLink[];
11
- /**
12
- * Custom matcher to set active link.
13
- * This function will be called with each link and the current location.
14
- * If it returns true the current link will be set to the active link.
15
- */
16
- matcher?: (link: NavigationLink, location: LocationOrHref) => boolean;
17
- }
18
- export default function NavigationMenu({ navigationLinks, matcher }: Props): null;
@@ -1,44 +0,0 @@
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
- var Provider_1 = require("../Provider/Provider");
8
- function defaultMatcher(link, location) {
9
- var pathname = typeof location === 'string' ? new URL(location).pathname : location.pathname;
10
- return link.destination.replace(/\/$/, '') === pathname.replace(/\/$/, '');
11
- }
12
- function NavigationMenu(_a) {
13
- var navigationLinks = _a.navigationLinks, _b = _a.matcher, matcher = _b === void 0 ? defaultMatcher : _b;
14
- var app = useAppBridge_1.useAppBridge();
15
- var _c = react_1.useState(), items = _c[0], setItems = _c[1];
16
- var locationOrHref = (Provider_1.useRouter() || {}).location;
17
- var location = react_1.useMemo(function () { return locationOrHref !== null && locationOrHref !== void 0 ? locationOrHref : window.location; }, [locationOrHref]);
18
- react_1.useEffect(function () {
19
- var items = navigationLinks.map(function (link) { return AppLink_1.create(app, link); });
20
- setItems(items);
21
- }, [app, JSON.stringify(navigationLinks)]);
22
- var activeLink = react_1.useMemo(function () {
23
- var activeLinkIndex = (items || []).findIndex(function (link) {
24
- return matcher(link, location);
25
- });
26
- if (activeLinkIndex >= 0) {
27
- return items === null || items === void 0 ? void 0 : items[activeLinkIndex];
28
- }
29
- }, [items, matcher, location]);
30
- react_1.useEffect(function () {
31
- // Skip creating the navigation menu on initial render
32
- if (!items) {
33
- return;
34
- }
35
- /**
36
- * There isn't any advantage to keeping around a consistent instance of
37
- * the navigation menu as when we create a new one it results in
38
- * the same UPDATE action to be dispatched
39
- */
40
- NavigationMenu_1.create(app, { items: items, active: activeLink });
41
- }, [items, activeLink, app]);
42
- return null;
43
- }
44
- exports.default = NavigationMenu;
@@ -1,3 +0,0 @@
1
- import NavigationMenu from './NavigationMenu';
2
- export { Props } from './NavigationMenu';
3
- export default NavigationMenu;
@@ -1,7 +0,0 @@
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;
@@ -1,87 +0,0 @@
1
- import React from 'react';
2
- import type { PropsWithChildren } from 'react';
3
- import type { AppConfigV2, DispatchActionHook } from '@shopify/app-bridge/client';
4
- import type { History } from '../ClientRouter';
5
- import type { LocationOrHref } from '../RoutePropagator';
6
- /**
7
- * Provider props
8
- *
9
- * @public
10
- */
11
- export interface Props {
12
- /** Application configuration */
13
- config: AppConfigV2;
14
- /** The child elements to render. */
15
- children?: React.ReactNode;
16
- /**
17
- * Option to set up client routing and route propagation automatically.
18
- * Passing in a router will allow you to bypass setting these
19
- * utilities up yourself.
20
- *
21
- * If you are using React Router, ensure that the Provider is a child
22
- * of the router component. For example:
23
- *
24
- * import {useMemo} from 'react';
25
- * import {useLocation, useNavigate, BrowserRouter} from 'react-router-dom';
26
- * import {Provider} from '@shopify/app-bridge-react';
27
- * import Routes from './Routes';
28
- *
29
- * export function App() {
30
- * const navigate = useNavigate();
31
- * const location = useLocation();
32
- * const history = useMemo(
33
- * () => ({replace: (path: string) => navigate(path, {replace: true})}),
34
- * [navigate],
35
- * );
36
- * const router = useMemo(
37
- * () => ({
38
- * location,
39
- * history,
40
- * }),
41
- * [location, navigate],
42
- * );
43
- * return (
44
- * <Provider
45
- * apiKey={{
46
- * apiKey: 'API key from Shopify Partner Dashboard',
47
- * host: host,
48
- * }}
49
- * router={router}
50
- * >
51
- * <Routes />
52
- * </Provider>
53
- * );
54
- * }
55
- *
56
- * export default function AppWrapper() {
57
- * return (
58
- * <BrowserRouter>
59
- * <App />
60
- * </BrowserRouter>
61
- * );
62
- * }
63
- */
64
- router?: {
65
- location: LocationOrHref;
66
- history: History;
67
- };
68
- }
69
- /**
70
- * Create an App Bridge client application from a config and pass it as the
71
- * value to the context provider.
72
- *
73
- * @public
74
- */
75
- declare function Provider({ config, router, children }: PropsWithChildren<Props>): JSX.Element;
76
- /**
77
- * Augment actions with clientInterface metadata, identifying use of this library
78
- *
79
- * @internal
80
- */
81
- export declare const setClientInterfaceHook: DispatchActionHook;
82
- interface RouterProps {
83
- location: LocationOrHref;
84
- history: History;
85
- }
86
- export declare function useRouter(): RouterProps | undefined;
87
- export default Provider;
@@ -1,81 +0,0 @@
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.useRouter = 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, { router: router }, children) : children;
53
- return react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: app }, routerMarkup);
54
- }
55
- /**
56
- * Augment actions with clientInterface metadata, identifying use of this library
57
- *
58
- * @internal
59
- */
60
- var setClientInterfaceHook = function (next) {
61
- return function (action) {
62
- action.clientInterface = {
63
- name: '@shopify/app-bridge-react',
64
- version: packageJson.version,
65
- };
66
- return next(action);
67
- };
68
- };
69
- exports.setClientInterfaceHook = setClientInterfaceHook;
70
- var RouterContext = react_1.createContext(undefined);
71
- function useRouter() {
72
- return react_1.useContext(RouterContext);
73
- }
74
- exports.useRouter = useRouter;
75
- function Router(_a) {
76
- var router = _a.router, children = _a.children;
77
- ClientRouter_1.useClientRouting(router.history);
78
- RoutePropagator_1.useRoutePropagation(router.location);
79
- return react_1.default.createElement(RouterContext.Provider, { value: router }, children);
80
- }
81
- exports.default = Provider;
@@ -1,3 +0,0 @@
1
- import Provider from './Provider';
2
- export { Props } from './Provider';
3
- export default Provider;
@@ -1,7 +0,0 @@
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;
@@ -1,36 +0,0 @@
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 };
@@ -1,120 +0,0 @@
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;