@shopify/app-bridge-react 2.0.18 → 2.0.19

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 (71) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/components/ClientRouter/ClientRouter.d.ts +21 -0
  3. package/components/ClientRouter/ClientRouter.js +50 -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 +6 -0
  8. package/components/ClientRouter/router.d.ts +5 -0
  9. package/components/ClientRouter/router.js +11 -0
  10. package/components/Loading/Loading.d.ts +17 -0
  11. package/components/Loading/Loading.js +53 -0
  12. package/components/Loading/index.d.ts +2 -0
  13. package/components/Loading/index.js +7 -0
  14. package/components/Modal/Modal.d.ts +43 -0
  15. package/components/Modal/Modal.js +131 -0
  16. package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
  17. package/components/Modal/ModalContent/ModalContent.js +59 -0
  18. package/components/Modal/ModalContent/index.d.ts +2 -0
  19. package/components/Modal/ModalContent/index.js +7 -0
  20. package/components/Modal/index.d.ts +4 -0
  21. package/components/Modal/index.js +9 -0
  22. package/components/Provider/Provider.d.ts +36 -0
  23. package/components/Provider/Provider.js +93 -0
  24. package/components/Provider/index.d.ts +3 -0
  25. package/components/Provider/index.js +7 -0
  26. package/components/ResourcePicker/ResourcePicker.d.ts +77 -0
  27. package/components/ResourcePicker/ResourcePicker.js +129 -0
  28. package/components/ResourcePicker/index.d.ts +3 -0
  29. package/components/ResourcePicker/index.js +7 -0
  30. package/components/RoutePropagator/RoutePropagator.d.ts +20 -0
  31. package/components/RoutePropagator/RoutePropagator.js +52 -0
  32. package/components/RoutePropagator/globals.d.ts +3 -0
  33. package/components/RoutePropagator/globals.js +15 -0
  34. package/components/RoutePropagator/hook.d.ts +10 -0
  35. package/components/RoutePropagator/hook.js +20 -0
  36. package/components/RoutePropagator/index.d.ts +3 -0
  37. package/components/RoutePropagator/index.js +6 -0
  38. package/components/RoutePropagator/route-propagator.d.ts +7 -0
  39. package/components/RoutePropagator/route-propagator.js +91 -0
  40. package/components/TitleBar/TitleBar.d.ts +38 -0
  41. package/components/TitleBar/TitleBar.js +78 -0
  42. package/components/TitleBar/index.d.ts +3 -0
  43. package/components/TitleBar/index.js +7 -0
  44. package/components/Toast/Toast.d.ts +31 -0
  45. package/components/Toast/Toast.js +57 -0
  46. package/components/Toast/index.d.ts +3 -0
  47. package/components/Toast/index.js +7 -0
  48. package/components/index.d.ts +8 -0
  49. package/components/index.js +27 -0
  50. package/context.d.ts +13 -0
  51. package/context.js +10 -0
  52. package/hooks/index.d.ts +2 -0
  53. package/hooks/index.js +6 -0
  54. package/hooks/useNavigationHistory/index.d.ts +1 -0
  55. package/hooks/useNavigationHistory/index.js +4 -0
  56. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
  57. package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
  58. package/hooks/useToast/index.d.ts +1 -0
  59. package/hooks/useToast/index.js +4 -0
  60. package/hooks/useToast/useToast.d.ts +15 -0
  61. package/hooks/useToast/useToast.js +38 -0
  62. package/index.d.ts +3 -0
  63. package/index.js +17 -0
  64. package/package.json +4 -3
  65. package/types.d.ts +33 -0
  66. package/types.js +2 -0
  67. package/umd/index.js +14 -0
  68. package/useAppBridge.d.ts +1 -0
  69. package/useAppBridge.js +13 -0
  70. package/utilities/transformers.d.ts +19 -0
  71. package/utilities/transformers.js +86 -0
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [2.0.18](https://github.com/Shopify/app-bridge/compare/v2.0.17...v2.0.18) (2022-03-15)
6
+ ## [2.0.19](https://github.com/Shopify/app-bridge/compare/v2.0.17...v2.0.19) (2022-03-15)
7
7
 
8
8
  **Note:** Version bump only for package @shopify/app-bridge-react
9
9
 
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { Unsubscribe } from '@shopify/app-bridge';
3
+ import { History } from './router';
4
+ export interface Props {
5
+ history: History;
6
+ }
7
+ /**
8
+ * ClientRouter component
9
+ *
10
+ * @remarks
11
+ * React component which keeps the Shopify admin url in sync with the app url
12
+ *
13
+ * @public
14
+ */
15
+ export default class ClientRouter extends React.Component<Props, never> {
16
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
17
+ unsubscribe?: Unsubscribe;
18
+ componentDidMount(): void;
19
+ componentWillUnmount(): void;
20
+ render(): null;
21
+ }
@@ -0,0 +1,50 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var react_1 = __importDefault(require("react"));
20
+ var context_1 = require("../../context");
21
+ var router_1 = require("./router");
22
+ /**
23
+ * ClientRouter component
24
+ *
25
+ * @remarks
26
+ * React component which keeps the Shopify admin url in sync with the app url
27
+ *
28
+ * @public
29
+ */
30
+ var ClientRouter = /** @class */ (function (_super) {
31
+ __extends(ClientRouter, _super);
32
+ function ClientRouter() {
33
+ return _super !== null && _super.apply(this, arguments) || this;
34
+ }
35
+ ClientRouter.prototype.componentDidMount = function () {
36
+ var history = this.props.history;
37
+ this.unsubscribe = router_1.handleRouteChange(this.context, history);
38
+ };
39
+ ClientRouter.prototype.componentWillUnmount = function () {
40
+ if (this.unsubscribe) {
41
+ this.unsubscribe();
42
+ }
43
+ };
44
+ ClientRouter.prototype.render = function () {
45
+ return null;
46
+ };
47
+ ClientRouter.contextType = context_1.AppBridgeContext;
48
+ return ClientRouter;
49
+ }(react_1.default.Component));
50
+ exports.default = ClientRouter;
@@ -0,0 +1,10 @@
1
+ import { History } from './router';
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 useClientRouting(history: History): 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 router_1 = require("./router");
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 useClientRouting(history) {
15
+ var app = useAppBridge_1.useAppBridge();
16
+ react_1.useEffect(function () {
17
+ return router_1.handleRouteChange(app, history);
18
+ }, [app, history]);
19
+ }
20
+ exports.default = useClientRouting;
@@ -0,0 +1,3 @@
1
+ export { default as ClientRouter } from './ClientRouter';
2
+ export { default as useClientRouting } from './hook';
3
+ export { History } from './router';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var ClientRouter_1 = require("./ClientRouter");
4
+ Object.defineProperty(exports, "ClientRouter", { enumerable: true, get: function () { return ClientRouter_1.default; } });
5
+ var hook_1 = require("./hook");
6
+ Object.defineProperty(exports, "useClientRouting", { enumerable: true, get: function () { return hook_1.default; } });
@@ -0,0 +1,5 @@
1
+ import { ClientApplication } from '@shopify/app-bridge';
2
+ export interface History {
3
+ replace(path: string): void;
4
+ }
5
+ export declare function handleRouteChange(app: ClientApplication<any>, history: History): import("@shopify/app-bridge").Unsubscribe;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRouteChange = void 0;
4
+ var actions_1 = require("@shopify/app-bridge/actions");
5
+ function handleRouteChange(app, history) {
6
+ return app.subscribe(actions_1.Redirect.Action.APP, function (_a) {
7
+ var path = _a.path;
8
+ history.replace(path);
9
+ });
10
+ }
11
+ exports.handleRouteChange = handleRouteChange;
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ /**
3
+ * Loading component
4
+ *
5
+ * @remarks
6
+ * React component which wraps the Shopify App Bridge Loading action.
7
+ *
8
+ * @public
9
+ */
10
+ declare class Loading extends React.Component {
11
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
12
+ private loading;
13
+ componentDidMount(): void;
14
+ componentWillUnmount(): void;
15
+ render(): null;
16
+ }
17
+ export default Loading;
@@ -0,0 +1,53 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var react_1 = __importDefault(require("react"));
20
+ var actions_1 = require("@shopify/app-bridge/actions");
21
+ var context_1 = require("../../context");
22
+ /**
23
+ * Loading component
24
+ *
25
+ * @remarks
26
+ * React component which wraps the Shopify App Bridge Loading action.
27
+ *
28
+ * @public
29
+ */
30
+ var Loading = /** @class */ (function (_super) {
31
+ __extends(Loading, _super);
32
+ function Loading() {
33
+ return _super !== null && _super.apply(this, arguments) || this;
34
+ }
35
+ Loading.prototype.componentDidMount = function () {
36
+ var app = this.context;
37
+ this.loading = actions_1.Loading.create(app);
38
+ if (this.loading != null) {
39
+ this.loading.dispatch(actions_1.Loading.Action.START);
40
+ }
41
+ };
42
+ Loading.prototype.componentWillUnmount = function () {
43
+ if (this.loading != null) {
44
+ this.loading.dispatch(actions_1.Loading.Action.STOP);
45
+ }
46
+ };
47
+ Loading.prototype.render = function () {
48
+ return null;
49
+ };
50
+ Loading.contextType = context_1.AppBridgeContext;
51
+ return Loading;
52
+ }(react_1.default.Component));
53
+ exports.default = Loading;
@@ -0,0 +1,2 @@
1
+ import Loading from './Loading';
2
+ export default Loading;
@@ -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 Loading_1 = __importDefault(require("./Loading"));
7
+ exports.default = Loading_1.default;
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { Modal as AppBridgeModal } from '@shopify/app-bridge/actions';
3
+ import { ActionProps } from '../../types';
4
+ declare type Size = keyof typeof AppBridgeModal.Size;
5
+ export interface Props {
6
+ /** Whether the modal is open or not */
7
+ open: boolean;
8
+ /** The url that will be loaded as the content of the modal */
9
+ src?: string;
10
+ /** The content for the title of the modal */
11
+ title?: string;
12
+ /** Controls the size of the modal */
13
+ size?: Size;
14
+ /** Message to display inside modal */
15
+ message?: string;
16
+ /** Primary action */
17
+ primaryAction?: ActionProps;
18
+ /** Collection of secondary actions */
19
+ secondaryActions?: ActionProps[];
20
+ /** Callback when the modal is closed */
21
+ onClose?(): void;
22
+ /** Enable loading behaviour, when `true` bear in mind you will need to use `Modal Content` to dismiss the loading after the iframe page is fully loaded */
23
+ loading?: boolean;
24
+ }
25
+ /**
26
+ * Modal component
27
+ *
28
+ * @remarks
29
+ * React component which wraps the Shopify App Bridge Modal action.
30
+ *
31
+ * @public
32
+ */
33
+ declare class Modal extends React.PureComponent<Props, never> {
34
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
35
+ private focusReturnPoint;
36
+ private modal;
37
+ componentDidMount(): void;
38
+ componentDidUpdate(prevProps: Props): void;
39
+ componentWillUnmount(): void;
40
+ render(): null;
41
+ private transformProps;
42
+ }
43
+ export default Modal;
@@ -0,0 +1,131 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __assign = (this && this.__assign) || function () {
16
+ __assign = Object.assign || function(t) {
17
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
18
+ s = arguments[i];
19
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
+ t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ var react_1 = __importDefault(require("react"));
31
+ var actions_1 = require("@shopify/app-bridge/actions");
32
+ var transformers_1 = require("../../utilities/transformers");
33
+ var context_1 = require("../../context");
34
+ /**
35
+ * Modal component
36
+ *
37
+ * @remarks
38
+ * React component which wraps the Shopify App Bridge Modal action.
39
+ *
40
+ * @public
41
+ */
42
+ var Modal = /** @class */ (function (_super) {
43
+ __extends(Modal, _super);
44
+ function Modal() {
45
+ var _this = _super !== null && _super.apply(this, arguments) || this;
46
+ _this.focusReturnPoint = null;
47
+ return _this;
48
+ }
49
+ Modal.prototype.componentDidMount = function () {
50
+ var _a = this.props, open = _a.open, onClose = _a.onClose;
51
+ var app = this.context;
52
+ this.modal = actions_1.Modal.create(app, this.transformProps());
53
+ if (onClose != null) {
54
+ this.modal.subscribe(actions_1.Modal.Action.CLOSE, onClose);
55
+ }
56
+ if (open) {
57
+ this.focusReturnPoint = document.activeElement;
58
+ this.modal.dispatch(actions_1.Modal.Action.OPEN);
59
+ }
60
+ };
61
+ Modal.prototype.componentDidUpdate = function (prevProps) {
62
+ var _a = this.props, open = _a.open, onClose = _a.onClose;
63
+ var wasOpen = prevProps.open;
64
+ var transformedProps = this.transformProps(wasOpen);
65
+ this.modal.unsubscribe();
66
+ if (isIframeModal(transformedProps)) {
67
+ this.modal.set(transformedProps, open);
68
+ }
69
+ else {
70
+ this.modal.set(transformedProps, open);
71
+ }
72
+ if (onClose != null) {
73
+ this.modal.subscribe(actions_1.Modal.Action.CLOSE, onClose);
74
+ }
75
+ if (wasOpen !== open) {
76
+ if (open) {
77
+ this.modal.dispatch(actions_1.Modal.Action.OPEN);
78
+ }
79
+ else {
80
+ this.modal.dispatch(actions_1.Modal.Action.CLOSE);
81
+ }
82
+ }
83
+ if (!wasOpen && open) {
84
+ this.focusReturnPoint = document.activeElement;
85
+ }
86
+ else if (wasOpen &&
87
+ !open &&
88
+ this.focusReturnPoint != null &&
89
+ document.contains(this.focusReturnPoint)) {
90
+ this.focusReturnPoint.focus();
91
+ this.focusReturnPoint = null;
92
+ }
93
+ };
94
+ Modal.prototype.componentWillUnmount = function () {
95
+ this.modal.unsubscribe();
96
+ if (this.props.open) {
97
+ this.modal.dispatch(actions_1.Modal.Action.CLOSE);
98
+ }
99
+ };
100
+ Modal.prototype.render = function () {
101
+ return null;
102
+ };
103
+ Modal.prototype.transformProps = function (wasOpen) {
104
+ var _a = this.props, title = _a.title, size = _a.size, message = _a.message, src = _a.src, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, loading = _a.loading;
105
+ var app = this.context;
106
+ var safeSize = size == null ? undefined : actions_1.Modal.Size[size];
107
+ var srcPayload = {};
108
+ if (src != null) {
109
+ if (src.match('^https?://')) {
110
+ srcPayload.url = src;
111
+ }
112
+ else {
113
+ srcPayload.path = src;
114
+ }
115
+ }
116
+ return __assign(__assign({ title: title,
117
+ message: message, size: safeSize }, srcPayload), { footer: {
118
+ buttons: transformers_1.transformActions(app, {
119
+ primaryAction: primaryAction,
120
+ secondaryActions: secondaryActions,
121
+ }),
122
+ }, loading: wasOpen ? undefined : loading });
123
+ };
124
+ Modal.contextType = context_1.AppBridgeContext;
125
+ return Modal;
126
+ }(react_1.default.PureComponent));
127
+ function isIframeModal(options) {
128
+ return (typeof options.url === 'string' ||
129
+ typeof options.path === 'string');
130
+ }
131
+ exports.default = Modal;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ export interface Props {
3
+ /** Show/Dismiss loading spinner */
4
+ loading: boolean;
5
+ }
6
+ /**
7
+ * Modal Content component
8
+ *
9
+ * @remarks
10
+ * React component which wraps the Shopify App Bridge Modal Content action.
11
+ *
12
+ * @public
13
+ */
14
+ declare class ModalContent extends React.Component<Props> {
15
+ static contextType: React.Context<import("../../../context").IAppBridgeContext>;
16
+ private modalContent;
17
+ componentDidMount(): void;
18
+ componentDidUpdate(): void;
19
+ syncLoadingStatus(): void;
20
+ render(): null;
21
+ }
22
+ export default ModalContent;
@@ -0,0 +1,59 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __importDefault = (this && this.__importDefault) || function (mod) {
16
+ return (mod && mod.__esModule) ? mod : { "default": mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ var react_1 = __importDefault(require("react"));
20
+ var actions_1 = require("@shopify/app-bridge/actions");
21
+ var context_1 = require("../../../context");
22
+ /**
23
+ * Modal Content component
24
+ *
25
+ * @remarks
26
+ * React component which wraps the Shopify App Bridge Modal Content action.
27
+ *
28
+ * @public
29
+ */
30
+ var ModalContent = /** @class */ (function (_super) {
31
+ __extends(ModalContent, _super);
32
+ function ModalContent() {
33
+ return _super !== null && _super.apply(this, arguments) || this;
34
+ }
35
+ ModalContent.prototype.componentDidMount = function () {
36
+ var app = this.context;
37
+ this.modalContent = actions_1.ModalContent.create(app);
38
+ this.syncLoadingStatus();
39
+ };
40
+ ModalContent.prototype.componentDidUpdate = function () {
41
+ this.syncLoadingStatus();
42
+ };
43
+ ModalContent.prototype.syncLoadingStatus = function () {
44
+ if (!this.modalContent)
45
+ return;
46
+ if (this.props.loading) {
47
+ this.modalContent.loading();
48
+ }
49
+ else {
50
+ this.modalContent.loaded();
51
+ }
52
+ };
53
+ ModalContent.prototype.render = function () {
54
+ return null;
55
+ };
56
+ ModalContent.contextType = context_1.AppBridgeContext;
57
+ return ModalContent;
58
+ }(react_1.default.Component));
59
+ 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,9 @@
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 Modal_1 = __importDefault(require("./Modal"));
7
+ var ModalContent_1 = require("./ModalContent");
8
+ Object.defineProperty(exports, "ModalContent", { enumerable: true, get: function () { return ModalContent_1.default; } });
9
+ exports.default = Modal_1.default;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { DispatchActionHook } from '@shopify/app-bridge';
3
+ import { AppConfigV2 } from '@shopify/app-bridge/client';
4
+ /**
5
+ * Provider props
6
+ *
7
+ * @public
8
+ */
9
+ export interface Props {
10
+ /** Application configuration */
11
+ config: AppConfigV2;
12
+ /** The child elements to render. */
13
+ children?: React.ReactNode;
14
+ }
15
+ /**
16
+ * Create an App Bridge client application from a config and pass it as the
17
+ * value to the context provider.
18
+ *
19
+ * @remarks
20
+ * You'll probably want something a little more robust than storing the current
21
+ * app instance in a module-level global.
22
+ *
23
+ * @public
24
+ */
25
+ declare class Provider extends React.Component<Props> {
26
+ private app;
27
+ private get appInstance();
28
+ render(): JSX.Element;
29
+ }
30
+ export default Provider;
31
+ /**
32
+ * Augment actions with clientInterface metadata, identifying use of this library
33
+ *
34
+ * @internal
35
+ */
36
+ export declare const setClientInterfaceHook: DispatchActionHook;
@@ -0,0 +1,93 @@
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ extendStatics(d, b);
11
+ function __() { this.constructor = d; }
12
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
+ };
14
+ })();
15
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
18
+ }) : (function(o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ }));
22
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
24
+ }) : function(o, v) {
25
+ o["default"] = v;
26
+ });
27
+ var __importStar = (this && this.__importStar) || function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.setClientInterfaceHook = void 0;
39
+ var react_1 = __importDefault(require("react"));
40
+ var app_bridge_1 = __importStar(require("@shopify/app-bridge"));
41
+ var context_1 = require("../../context");
42
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
43
+ var packageJson = require('../../package.json');
44
+ /**
45
+ * Create an App Bridge client application from a config and pass it as the
46
+ * value to the context provider.
47
+ *
48
+ * @remarks
49
+ * You'll probably want something a little more robust than storing the current
50
+ * app instance in a module-level global.
51
+ *
52
+ * @public
53
+ */
54
+ var Provider = /** @class */ (function (_super) {
55
+ __extends(Provider, _super);
56
+ function Provider() {
57
+ var _this = _super !== null && _super.apply(this, arguments) || this;
58
+ _this.app = _this.appInstance;
59
+ return _this;
60
+ }
61
+ Object.defineProperty(Provider.prototype, "appInstance", {
62
+ get: function () {
63
+ if (!this.app) {
64
+ this.app = app_bridge_1.default(this.props.config);
65
+ if (this.app && this.app.hooks) {
66
+ this.app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
67
+ }
68
+ }
69
+ return this.app;
70
+ },
71
+ enumerable: false,
72
+ configurable: true
73
+ });
74
+ Provider.prototype.render = function () {
75
+ return (react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: this.appInstance }, this.props.children));
76
+ };
77
+ return Provider;
78
+ }(react_1.default.Component));
79
+ exports.default = Provider;
80
+ /**
81
+ * Augment actions with clientInterface metadata, identifying use of this library
82
+ *
83
+ * @internal
84
+ */
85
+ exports.setClientInterfaceHook = function (next) {
86
+ return function (action) {
87
+ action.clientInterface = {
88
+ name: '@shopify/app-bridge-react',
89
+ version: packageJson.version,
90
+ };
91
+ return next(action);
92
+ };
93
+ };
@@ -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;