@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
@@ -0,0 +1,57 @@
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
+ exports.DEFAULT_TOAST_DURATION = void 0;
20
+ var react_1 = __importDefault(require("react"));
21
+ var actions_1 = require("@shopify/app-bridge/actions");
22
+ var context_1 = require("../../context");
23
+ exports.DEFAULT_TOAST_DURATION = 5000;
24
+ /**
25
+ * Toast component
26
+ *
27
+ * @remarks
28
+ * React component which wraps the Shopify App Bridge Toast action.
29
+ *
30
+ * @public
31
+ */
32
+ var Toast = /** @class */ (function (_super) {
33
+ __extends(Toast, _super);
34
+ function Toast() {
35
+ return _super !== null && _super.apply(this, arguments) || this;
36
+ }
37
+ Toast.prototype.componentDidMount = function () {
38
+ var app = this.context;
39
+ var _a = this.props, error = _a.error, content = _a.content, _b = _a.duration, duration = _b === void 0 ? exports.DEFAULT_TOAST_DURATION : _b, onDismiss = _a.onDismiss;
40
+ this.toast = actions_1.Toast.create(app, {
41
+ message: content,
42
+ duration: duration,
43
+ isError: error,
44
+ });
45
+ this.toast.subscribe(actions_1.Toast.Action.CLEAR, onDismiss);
46
+ this.toast.dispatch(actions_1.Toast.Action.SHOW);
47
+ };
48
+ Toast.prototype.componentWillUnmount = function () {
49
+ this.toast.unsubscribe();
50
+ };
51
+ Toast.prototype.render = function () {
52
+ return null;
53
+ };
54
+ Toast.contextType = context_1.AppBridgeContext;
55
+ return Toast;
56
+ }(react_1.default.PureComponent));
57
+ exports.default = Toast;
@@ -0,0 +1,3 @@
1
+ import Toast from './Toast';
2
+ export { Props } from './Toast';
3
+ export default Toast;
@@ -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 Toast_1 = __importDefault(require("./Toast"));
7
+ exports.default = Toast_1.default;
@@ -0,0 +1,8 @@
1
+ export { default as Provider, Props as ProviderProps } from './Provider';
2
+ export { default as Loading } from './Loading';
3
+ export { default as Toast, Props as ToastProps } from './Toast';
4
+ export { default as TitleBar } from './TitleBar';
5
+ export { default as Modal, Props as ModalProps, ModalContent } from './Modal';
6
+ export { default as ResourcePicker, Props as ResourcePickerProps } from './ResourcePicker';
7
+ export * from './RoutePropagator';
8
+ export * from './ClientRouter';
@@ -0,0 +1,27 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ var Provider_1 = require("./Provider");
14
+ Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return Provider_1.default; } });
15
+ var Loading_1 = require("./Loading");
16
+ Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return Loading_1.default; } });
17
+ var Toast_1 = require("./Toast");
18
+ Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return Toast_1.default; } });
19
+ var TitleBar_1 = require("./TitleBar");
20
+ Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return TitleBar_1.default; } });
21
+ var Modal_1 = require("./Modal");
22
+ Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return Modal_1.default; } });
23
+ Object.defineProperty(exports, "ModalContent", { enumerable: true, get: function () { return Modal_1.ModalContent; } });
24
+ var ResourcePicker_1 = require("./ResourcePicker");
25
+ Object.defineProperty(exports, "ResourcePicker", { enumerable: true, get: function () { return ResourcePicker_1.default; } });
26
+ __exportStar(require("./RoutePropagator"), exports);
27
+ __exportStar(require("./ClientRouter"), exports);
package/context.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { ClientApplication } from '@shopify/app-bridge/client';
2
+ /**
3
+ * App Bridge context consumer type.
4
+ *
5
+ * @public
6
+ */
7
+ export declare type IAppBridgeContext = ClientApplication<any> | null;
8
+ /**
9
+ * App Bridge context.
10
+ *
11
+ * @public
12
+ */
13
+ export declare const AppBridgeContext: import("react").Context<IAppBridgeContext>;
package/context.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppBridgeContext = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * App Bridge context.
7
+ *
8
+ * @public
9
+ */
10
+ exports.AppBridgeContext = react_1.createContext(null);
@@ -0,0 +1,2 @@
1
+ export { useNavigationHistory } from './useNavigationHistory';
2
+ export { useToast } from './useToast';
package/hooks/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useNavigationHistory_1 = require("./useNavigationHistory");
4
+ Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
5
+ var useToast_1 = require("./useToast");
6
+ Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
@@ -0,0 +1 @@
1
+ export { useNavigationHistory } from './useNavigationHistory';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useNavigationHistory_1 = require("./useNavigationHistory");
4
+ Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
@@ -0,0 +1,16 @@
1
+ /**
2
+ * useNavigationHistory hook
3
+ *
4
+ * @remarks
5
+ * React hook which wraps the Shopify App Bridge History action.
6
+ *
7
+ * @public
8
+ */
9
+ export declare function useNavigationHistory(): {
10
+ push: (location: {
11
+ pathname: string;
12
+ }) => void;
13
+ replace: (location: {
14
+ pathname: string;
15
+ }) => void;
16
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNavigationHistory = void 0;
4
+ var react_1 = require("react");
5
+ var actions_1 = require("@shopify/app-bridge/actions");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ /**
8
+ * useNavigationHistory hook
9
+ *
10
+ * @remarks
11
+ * React hook which wraps the Shopify App Bridge History action.
12
+ *
13
+ * @public
14
+ */
15
+ function useNavigationHistory() {
16
+ var app = useAppBridge_1.useAppBridge();
17
+ return react_1.useMemo(function () {
18
+ var history = actions_1.History.create(app);
19
+ function push(location) {
20
+ history.dispatch(actions_1.History.Action.PUSH, location.pathname);
21
+ }
22
+ function replace(location) {
23
+ history.dispatch(actions_1.History.Action.REPLACE, location.pathname);
24
+ }
25
+ return { push: push, replace: replace };
26
+ }, []);
27
+ }
28
+ exports.useNavigationHistory = useNavigationHistory;
@@ -0,0 +1 @@
1
+ export { useToast } from './useToast';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var useToast_1 = require("./useToast");
4
+ Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
@@ -0,0 +1,15 @@
1
+ import type { Payload } from '@shopify/app-bridge/actions/Toast';
2
+ export declare const DEFAULT_TOAST_DURATION = 5000;
3
+ /**
4
+ * useToast hook
5
+ *
6
+ * @remarks
7
+ * React hook which wraps the Shopify App Bridge Toast action.
8
+ *
9
+ * @public
10
+ */
11
+ export declare function useToast(): {
12
+ show: ({ content: message, duration, isError, onDismiss, }: Omit<Payload, 'message'> & {
13
+ content: string;
14
+ }) => void;
15
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToast = exports.DEFAULT_TOAST_DURATION = void 0;
4
+ var react_1 = require("react");
5
+ var Toast_1 = require("@shopify/app-bridge/actions/Toast");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ exports.DEFAULT_TOAST_DURATION = 5000;
8
+ /**
9
+ * useToast hook
10
+ *
11
+ * @remarks
12
+ * React hook which wraps the Shopify App Bridge Toast action.
13
+ *
14
+ * @public
15
+ */
16
+ function useToast() {
17
+ var app = useAppBridge_1.useAppBridge();
18
+ var toast;
19
+ var show = react_1.useCallback(function (_a) {
20
+ var message = _a.content, _b = _a.duration, duration = _b === void 0 ? exports.DEFAULT_TOAST_DURATION : _b, isError = _a.isError, onDismiss = _a.onDismiss;
21
+ toast = Toast_1.create(app, {
22
+ message: message,
23
+ isError: isError,
24
+ duration: duration,
25
+ });
26
+ toast.dispatch(Toast_1.Action.SHOW);
27
+ if (onDismiss) {
28
+ toast.subscribe(Toast_1.Action.CLEAR, onDismiss);
29
+ }
30
+ }, [app]);
31
+ react_1.useEffect(function () {
32
+ return function () {
33
+ toast.unsubscribe();
34
+ };
35
+ }, []);
36
+ return { show: show };
37
+ }
38
+ exports.useToast = useToast;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './components';
2
+ export { AppBridgeContext as Context } from './context';
3
+ export { useAppBridge } from './useAppBridge';
package/index.js ADDED
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./components"), exports);
14
+ var context_1 = require("./context");
15
+ Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
16
+ var useAppBridge_1 = require("./useAppBridge");
17
+ Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/app-bridge-react",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "types": "index.d.ts",
5
5
  "main": "index.js",
6
6
  "unpkg": "umd/index.js",
@@ -8,6 +8,7 @@
8
8
  "files": [
9
9
  "/components/",
10
10
  "/umd/",
11
+ "/hooks/",
11
12
  "/utilities/",
12
13
  "/context.d.ts",
13
14
  "/context.js",
@@ -44,7 +45,7 @@
44
45
  }
45
46
  ],
46
47
  "dependencies": {
47
- "@shopify/app-bridge": "^2.0.18"
48
+ "@shopify/app-bridge": "^2.0.19"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/react": "^17.0.38",
@@ -54,5 +55,5 @@
54
55
  "peerDependencies": {
55
56
  "react": "^16.0.0 || ^17.0.0"
56
57
  },
57
- "gitHead": "9d45b5643e94febbccc111e198db7fafe309c2a0"
58
+ "gitHead": "7b9604f253934c22ef88630eaa3eb891bdfc6f7a"
58
59
  }
package/types.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { Redirect } from '@shopify/app-bridge/actions';
2
+ export declare type Target = Exclude<keyof typeof Redirect.Action, 'ADMIN_SECTION'>;
3
+ export interface ActionProps {
4
+ /** Content the action displays */
5
+ content?: string;
6
+ /** Should the action be styled as destructive */
7
+ destructive?: boolean;
8
+ /** Should the action be disabled */
9
+ disabled?: boolean;
10
+ /** Should the action be loading */
11
+ loading?: boolean;
12
+ /** Forces url to open in a new tab */
13
+ external?: boolean;
14
+ /** Use Polaris plain styling */
15
+ plain?: boolean;
16
+ /**
17
+ * Where to display the target link
18
+ * @default 'APP'
19
+ */
20
+ target?: Target;
21
+ /** A destination to link to */
22
+ url?: string;
23
+ /** Callback when an action takes place */
24
+ onAction?(): void;
25
+ }
26
+ export interface ActionGroupProps {
27
+ /** Action group title */
28
+ title: string;
29
+ /** Use Polaris plain styling */
30
+ plain?: boolean;
31
+ /** List of actions */
32
+ actions: ActionProps[];
33
+ }
package/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });