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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/components/ClientRouter/ClientRouter.d.ts +21 -0
  3. package/components/ClientRouter/ClientRouter.js +52 -0
  4. package/components/ClientRouter/hook.d.ts +10 -0
  5. package/components/ClientRouter/hook.js +20 -0
  6. package/components/ClientRouter/index.d.ts +3 -0
  7. package/components/ClientRouter/index.js +10 -0
  8. package/components/ClientRouter/router.d.ts +5 -0
  9. package/components/ClientRouter/router.js +11 -0
  10. package/components/ContextualSaveBar/ContextualSaveBar.d.ts +13 -0
  11. package/components/ContextualSaveBar/ContextualSaveBar.js +64 -0
  12. package/components/ContextualSaveBar/index.d.ts +3 -0
  13. package/components/ContextualSaveBar/index.js +7 -0
  14. package/components/Loading/Loading.d.ts +17 -0
  15. package/components/Loading/Loading.js +55 -0
  16. package/components/Loading/index.d.ts +2 -0
  17. package/components/Loading/index.js +7 -0
  18. package/components/Modal/Modal.d.ts +32 -0
  19. package/components/Modal/Modal.js +139 -0
  20. package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
  21. package/components/Modal/ModalContent/ModalContent.js +61 -0
  22. package/components/Modal/ModalContent/index.d.ts +2 -0
  23. package/components/Modal/ModalContent/index.js +7 -0
  24. package/components/Modal/index.d.ts +4 -0
  25. package/components/Modal/index.js +10 -0
  26. package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
  27. package/components/NavigationMenu/NavigationMenu.js +40 -0
  28. package/components/NavigationMenu/index.d.ts +3 -0
  29. package/components/NavigationMenu/index.js +7 -0
  30. package/components/Provider/Provider.d.ts +81 -0
  31. package/components/Provider/Provider.js +70 -0
  32. package/components/Provider/index.d.ts +3 -0
  33. package/components/Provider/index.js +7 -0
  34. package/components/ResourcePicker/ResourcePicker.d.ts +68 -0
  35. package/components/ResourcePicker/ResourcePicker.js +114 -0
  36. package/components/ResourcePicker/index.d.ts +3 -0
  37. package/components/ResourcePicker/index.js +7 -0
  38. package/components/RoutePropagator/RoutePropagator.d.ts +20 -0
  39. package/components/RoutePropagator/RoutePropagator.js +54 -0
  40. package/components/RoutePropagator/globals.d.ts +3 -0
  41. package/components/RoutePropagator/globals.js +15 -0
  42. package/components/RoutePropagator/hook.d.ts +10 -0
  43. package/components/RoutePropagator/hook.js +20 -0
  44. package/components/RoutePropagator/index.d.ts +3 -0
  45. package/components/RoutePropagator/index.js +10 -0
  46. package/components/RoutePropagator/route-propagator.d.ts +7 -0
  47. package/components/RoutePropagator/route-propagator.js +91 -0
  48. package/components/TitleBar/TitleBar.d.ts +27 -0
  49. package/components/TitleBar/TitleBar.js +108 -0
  50. package/components/TitleBar/index.d.ts +3 -0
  51. package/components/TitleBar/index.js +7 -0
  52. package/components/Toast/Toast.d.ts +31 -0
  53. package/components/Toast/Toast.js +59 -0
  54. package/components/Toast/index.d.ts +3 -0
  55. package/components/Toast/index.js +7 -0
  56. package/components/index.d.ts +10 -0
  57. package/components/index.js +35 -0
  58. package/context.d.ts +13 -0
  59. package/context.js +10 -0
  60. package/hooks/index.d.ts +8 -0
  61. package/hooks/index.js +17 -0
  62. package/hooks/useAppBridgeState/index.d.ts +1 -0
  63. package/hooks/useAppBridgeState/index.js +13 -0
  64. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
  65. package/hooks/useAppBridgeState/useAppBridgeState.js +89 -0
  66. package/hooks/useContextualSaveBar/index.d.ts +1 -0
  67. package/hooks/useContextualSaveBar/index.js +5 -0
  68. package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +13 -0
  69. package/hooks/useContextualSaveBar/useContextualSaveBar.js +68 -0
  70. package/hooks/useFeatureRequest/index.d.ts +1 -0
  71. package/hooks/useFeatureRequest/index.js +13 -0
  72. package/hooks/useFeatureRequest/useFeatureRequest.d.ts +13 -0
  73. package/hooks/useFeatureRequest/useFeatureRequest.js +49 -0
  74. package/hooks/useFeaturesAvailable/index.d.ts +2 -0
  75. package/hooks/useFeaturesAvailable/index.js +5 -0
  76. package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +12 -0
  77. package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +101 -0
  78. package/hooks/useLocale/index.d.ts +1 -0
  79. package/hooks/useLocale/index.js +5 -0
  80. package/hooks/useLocale/useLocale.d.ts +1 -0
  81. package/hooks/useLocale/useLocale.js +8 -0
  82. package/hooks/useNavigate/index.d.ts +1 -0
  83. package/hooks/useNavigate/index.js +5 -0
  84. package/hooks/useNavigate/useNavigate.d.ts +24 -0
  85. package/hooks/useNavigate/useNavigate.js +109 -0
  86. package/hooks/useNavigationHistory/index.d.ts +1 -0
  87. package/hooks/useNavigationHistory/index.js +5 -0
  88. package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
  89. package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
  90. package/hooks/useToast/index.d.ts +1 -0
  91. package/hooks/useToast/index.js +5 -0
  92. package/hooks/useToast/useToast.d.ts +15 -0
  93. package/hooks/useToast/useToast.js +38 -0
  94. package/index.d.ts +4 -0
  95. package/index.js +19 -0
  96. package/package.json +3 -3
  97. package/types.d.ts +35 -0
  98. package/types.js +5 -0
  99. package/umd/index.js +14 -0
  100. package/useAppBridge.d.ts +1 -0
  101. package/useAppBridge.js +13 -0
  102. package/utilities/transformers.d.ts +20 -0
  103. package/utilities/transformers.js +105 -0
@@ -0,0 +1,27 @@
1
+ import { ActionProps, ActionGroupProps, Target } from '../../types';
2
+ export interface Breadcrumb {
3
+ /** Content the action displays */
4
+ content?: string;
5
+ /** A destination to link to */
6
+ url?: string;
7
+ /**
8
+ * Where to display the target link
9
+ * @default 'APP'
10
+ */
11
+ target?: Target;
12
+ /** Callback when an action takes place */
13
+ onAction?(): void;
14
+ }
15
+ export interface Props {
16
+ /** TitleBar title */
17
+ title: string;
18
+ /** The current breadcrumb; only displays the last item in array */
19
+ breadcrumbs?: Breadcrumb | Breadcrumb[];
20
+ /** Primary TitleBar action */
21
+ primaryAction?: ActionProps;
22
+ /** Collection of secondary TitleBar actions */
23
+ secondaryActions?: ActionProps[];
24
+ /** Collection of TitleBar groups of secondary actions */
25
+ actionGroups?: ActionGroupProps[];
26
+ }
27
+ export default function TitleBar(props: Props): null;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
4
+ var Button_1 = require("@shopify/app-bridge/actions/Button");
5
+ var TitleBar_1 = require("@shopify/app-bridge/actions/TitleBar");
6
+ var ButtonGroup_1 = require("@shopify/app-bridge/actions/ButtonGroup");
7
+ var transformers_1 = require("../../utilities/transformers");
8
+ var useAppBridge_1 = require("../../useAppBridge");
9
+ function TitleBar(props) {
10
+ var title = props.title;
11
+ var app = useAppBridge_1.useAppBridge();
12
+ var currentProps = react_1.useRef({ title: title });
13
+ var titleBar = react_1.useMemo(function () {
14
+ /**
15
+ * We purposely don't pass buttons here as they will be replaced
16
+ * by the subsequent useEffect to call `set` to update the options.
17
+ * If we pass them in here button subscriptions will be created without
18
+ * being cleaned up.
19
+ */
20
+ return TitleBar_1.create(app, {});
21
+ }, [app]);
22
+ /**
23
+ * All option updates are handled in this useEffect so they can be cleaned up.
24
+ */
25
+ react_1.useEffect(function () {
26
+ var _a;
27
+ var propsChanged = JSON.stringify(currentProps.current) !== JSON.stringify(props);
28
+ currentProps.current = props;
29
+ if (propsChanged) {
30
+ titleBar.set(transformProps(app, props));
31
+ }
32
+ else {
33
+ /**
34
+ * We manually update the button callbacks when no props have changed aside from the
35
+ * callbacks to avoid sending an unnecessary UPDATE action to the host
36
+ */
37
+ var primaryAction = props.primaryAction, secondaryActions = props.secondaryActions, actionGroups = props.actionGroups, breadcrumbs = props.breadcrumbs;
38
+ var breadcrumb = Array.isArray(breadcrumbs)
39
+ ? breadcrumbs[breadcrumbs.length - 1]
40
+ : breadcrumbs;
41
+ updateButton(breadcrumb, titleBar.options.breadcrumbs);
42
+ updateButton(primaryAction, (_a = titleBar.options.buttons) === null || _a === void 0 ? void 0 : _a.primary);
43
+ updateSecondaryActions(titleBar, secondaryActions);
44
+ updateActionGroups(titleBar, actionGroups);
45
+ }
46
+ return function () {
47
+ titleBar.unsubscribe();
48
+ };
49
+ }, [titleBar, props]);
50
+ return null;
51
+ }
52
+ exports.default = TitleBar;
53
+ function updateSecondaryActions(titleBar, secondaryActions) {
54
+ var _a, _b;
55
+ var secondaryButtons = ((_b = (_a = titleBar.options.buttons) === null || _a === void 0 ? void 0 : _a.secondary) === null || _b === void 0 ? void 0 : _b.filter(function (button) { return !ButtonGroup_1.isGroupedButton(button); })) || [];
56
+ secondaryButtons === null || secondaryButtons === void 0 ? void 0 : secondaryButtons.forEach(function (secondaryButton, index) {
57
+ return updateButton(secondaryActions === null || secondaryActions === void 0 ? void 0 : secondaryActions[index],
58
+ // This needs to be casted as the React TitleBar component doesn't accept button groups for secondary actions
59
+ secondaryButton);
60
+ });
61
+ }
62
+ function updateActionGroups(titleBar, actionGroups) {
63
+ var _a, _b;
64
+ var actionGroupButtons = ((_b = (_a = titleBar.options.buttons) === null || _a === void 0 ? void 0 : _a.secondary) === null || _b === void 0 ? void 0 : _b.filter(ButtonGroup_1.isGroupedButton)) ||
65
+ [];
66
+ actionGroupButtons === null || actionGroupButtons === void 0 ? void 0 : actionGroupButtons.forEach(function (actionBroupButton, index) {
67
+ var actionGroup = actionGroups === null || actionGroups === void 0 ? void 0 : actionGroups[index];
68
+ if (!actionGroup) {
69
+ return;
70
+ }
71
+ actionBroupButton.options.buttons.forEach(function (nestedButton, nestedIndex) {
72
+ return updateButton(actionGroup.actions[nestedIndex], nestedButton);
73
+ });
74
+ });
75
+ }
76
+ function transformProps(app, _a) {
77
+ var actionGroups = _a.actionGroups, breadcrumbs = _a.breadcrumbs, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, title = _a.title;
78
+ var breadcrumb = Array.isArray(breadcrumbs) ? breadcrumbs[breadcrumbs.length - 1] : breadcrumbs;
79
+ return {
80
+ title: title,
81
+ buttons: transformers_1.transformActions(app, {
82
+ primaryAction: primaryAction,
83
+ secondaryActions: secondaryActions,
84
+ actionGroups: actionGroups,
85
+ }),
86
+ breadcrumbs: breadcrumb ? transformBreadcrumb(app, breadcrumb) : undefined,
87
+ };
88
+ }
89
+ function transformBreadcrumb(app, breadcrumb, updateBreadcrumb) {
90
+ var button = updateBreadcrumb ||
91
+ Button_1.create(app, {
92
+ label: breadcrumb.content || '',
93
+ });
94
+ updateButton(breadcrumb, button);
95
+ return button;
96
+ }
97
+ function updateButton(actionProps, button) {
98
+ if (!actionProps || !button) {
99
+ return;
100
+ }
101
+ var redirect = transformers_1.generateRedirect(button.app, actionProps.url, actionProps.target, actionProps.external);
102
+ if (redirect) {
103
+ button.subscribe(Button_1.Action.CLICK, redirect, button);
104
+ }
105
+ if (actionProps === null || actionProps === void 0 ? void 0 : actionProps.onAction) {
106
+ button.subscribe(Button_1.Action.CLICK, actionProps.onAction, button);
107
+ }
108
+ }
@@ -0,0 +1,3 @@
1
+ import TitleBar from './TitleBar';
2
+ export { Props } from './TitleBar';
3
+ export default TitleBar;
@@ -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 TitleBar_1 = __importDefault(require("./TitleBar"));
7
+ exports.default = TitleBar_1.default;
@@ -0,0 +1,31 @@
1
+ import React from 'react';
2
+ export interface Props {
3
+ /** The content that should appear in the toast message */
4
+ content: string;
5
+ /**
6
+ * The length of time in milliseconds the toast message should persist
7
+ * @default 5000
8
+ */
9
+ duration?: number;
10
+ /** Display an error toast. */
11
+ error?: boolean;
12
+ /** Callback when the dismiss icon is clicked */
13
+ onDismiss(): void;
14
+ }
15
+ export declare const DEFAULT_TOAST_DURATION = 5000;
16
+ /**
17
+ * Toast component
18
+ *
19
+ * @remarks
20
+ * React component which wraps the Shopify App Bridge Toast action.
21
+ *
22
+ * @public
23
+ */
24
+ declare class Toast extends React.PureComponent<Props, never> {
25
+ static contextType: React.Context<import("../../context").IAppBridgeContext>;
26
+ private toast;
27
+ componentDidMount(): void;
28
+ componentWillUnmount(): void;
29
+ render(): null;
30
+ }
31
+ export default Toast;
@@ -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 (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
+ exports.DEFAULT_TOAST_DURATION = void 0;
22
+ var react_1 = __importDefault(require("react"));
23
+ var actions_1 = require("@shopify/app-bridge/actions");
24
+ var context_1 = require("../../context");
25
+ exports.DEFAULT_TOAST_DURATION = 5000;
26
+ /**
27
+ * Toast component
28
+ *
29
+ * @remarks
30
+ * React component which wraps the Shopify App Bridge Toast action.
31
+ *
32
+ * @public
33
+ */
34
+ var Toast = /** @class */ (function (_super) {
35
+ __extends(Toast, _super);
36
+ function Toast() {
37
+ return _super !== null && _super.apply(this, arguments) || this;
38
+ }
39
+ Toast.prototype.componentDidMount = function () {
40
+ var app = this.context;
41
+ 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;
42
+ this.toast = actions_1.Toast.create(app, {
43
+ message: content,
44
+ duration: duration,
45
+ isError: error,
46
+ });
47
+ this.toast.subscribe(actions_1.Toast.Action.CLEAR, onDismiss);
48
+ this.toast.dispatch(actions_1.Toast.Action.SHOW);
49
+ };
50
+ Toast.prototype.componentWillUnmount = function () {
51
+ this.toast.unsubscribe();
52
+ };
53
+ Toast.prototype.render = function () {
54
+ return null;
55
+ };
56
+ Toast.contextType = context_1.AppBridgeContext;
57
+ return Toast;
58
+ }(react_1.default.PureComponent));
59
+ 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,10 @@
1
+ export { default as ContextualSaveBar, Props as ContextualSaveBarProps } from './ContextualSaveBar';
2
+ export { default as Loading } from './Loading';
3
+ export { default as Modal, Props as ModalProps, ModalContent } from './Modal';
4
+ export { default as NavigationMenu, Props as NavigationMenuProps } from './NavigationMenu';
5
+ export { default as Provider, Props as ProviderProps } from './Provider';
6
+ export { default as ResourcePicker, Props as ResourcePickerProps } from './ResourcePicker';
7
+ export { default as TitleBar } from './TitleBar';
8
+ export { default as Toast, Props as ToastProps } from './Toast';
9
+ export * from './RoutePropagator';
10
+ export * from './ClientRouter';
@@ -0,0 +1,35 @@
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
17
+ var ContextualSaveBar_1 = require("./ContextualSaveBar");
18
+ Object.defineProperty(exports, "ContextualSaveBar", { enumerable: true, get: function () { return __importDefault(ContextualSaveBar_1).default; } });
19
+ var Loading_1 = require("./Loading");
20
+ Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return __importDefault(Loading_1).default; } });
21
+ var Modal_1 = require("./Modal");
22
+ Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return __importDefault(Modal_1).default; } });
23
+ Object.defineProperty(exports, "ModalContent", { enumerable: true, get: function () { return Modal_1.ModalContent; } });
24
+ var NavigationMenu_1 = require("./NavigationMenu");
25
+ Object.defineProperty(exports, "NavigationMenu", { enumerable: true, get: function () { return __importDefault(NavigationMenu_1).default; } });
26
+ var Provider_1 = require("./Provider");
27
+ Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return __importDefault(Provider_1).default; } });
28
+ var ResourcePicker_1 = require("./ResourcePicker");
29
+ Object.defineProperty(exports, "ResourcePicker", { enumerable: true, get: function () { return __importDefault(ResourcePicker_1).default; } });
30
+ var TitleBar_1 = require("./TitleBar");
31
+ Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return __importDefault(TitleBar_1).default; } });
32
+ var Toast_1 = require("./Toast");
33
+ Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return __importDefault(Toast_1).default; } });
34
+ __exportStar(require("./RoutePropagator"), exports);
35
+ __exportStar(require("./ClientRouter"), exports);
package/context.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { ClientApplication } from '@shopify/app-bridge/client';
2
+ /**
3
+ * App Bridge context consumer type.
4
+ *
5
+ * @public
6
+ */
7
+ export declare type IAppBridgeContext = ClientApplication | 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,8 @@
1
+ export { useContextualSaveBar } from './useContextualSaveBar';
2
+ export { useFeaturesAvailable } from './useFeaturesAvailable';
3
+ export { useFeatureRequest } from './useFeatureRequest';
4
+ export type { FeaturesAvailable } from './useFeaturesAvailable';
5
+ export { useNavigationHistory } from './useNavigationHistory';
6
+ export { useToast } from './useToast';
7
+ export { useAppBridgeState } from './useAppBridgeState';
8
+ export { useNavigate } from './useNavigate';
package/hooks/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNavigate = exports.useAppBridgeState = exports.useToast = exports.useNavigationHistory = exports.useFeatureRequest = exports.useFeaturesAvailable = exports.useContextualSaveBar = void 0;
4
+ var useContextualSaveBar_1 = require("./useContextualSaveBar");
5
+ Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
6
+ var useFeaturesAvailable_1 = require("./useFeaturesAvailable");
7
+ Object.defineProperty(exports, "useFeaturesAvailable", { enumerable: true, get: function () { return useFeaturesAvailable_1.useFeaturesAvailable; } });
8
+ var useFeatureRequest_1 = require("./useFeatureRequest");
9
+ Object.defineProperty(exports, "useFeatureRequest", { enumerable: true, get: function () { return useFeatureRequest_1.useFeatureRequest; } });
10
+ var useNavigationHistory_1 = require("./useNavigationHistory");
11
+ Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
12
+ var useToast_1 = require("./useToast");
13
+ Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
14
+ var useAppBridgeState_1 = require("./useAppBridgeState");
15
+ Object.defineProperty(exports, "useAppBridgeState", { enumerable: true, get: function () { return useAppBridgeState_1.useAppBridgeState; } });
16
+ var useNavigate_1 = require("./useNavigate");
17
+ Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return useNavigate_1.useNavigate; } });
@@ -0,0 +1 @@
1
+ export * from './useAppBridgeState';
@@ -0,0 +1,13 @@
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./useAppBridgeState"), exports);
@@ -0,0 +1,10 @@
1
+ import type { AppBridgeState, Path, PathValue, StateWithoutFeatures } from '@shopify/app-bridge';
2
+ declare type Query = keyof AppBridgeState | Path<StateWithoutFeatures<AppBridgeState>>;
3
+ declare type State<K extends Query> = K extends keyof AppBridgeState ? AppBridgeState[K] : K extends Path<StateWithoutFeatures<AppBridgeState>> ? PathValue<StateWithoutFeatures<AppBridgeState>, K> : K extends never ? AppBridgeState : never;
4
+ interface UseAppBridgeState {
5
+ (): AppBridgeState | undefined;
6
+ <K extends Query>(query: K): State<K> | undefined;
7
+ <PartialState>(query: keyof AppBridgeState): PartialState | undefined;
8
+ }
9
+ export declare const useAppBridgeState: UseAppBridgeState;
10
+ export {};
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.useAppBridgeState = void 0;
40
+ var react_1 = require("react");
41
+ var useAppBridge_1 = require("../../useAppBridge");
42
+ var useAppBridgeState = function (query) {
43
+ var app = useAppBridge_1.useAppBridge();
44
+ var _a = react_1.useState(), state = _a[0], setState = _a[1];
45
+ var isUnmounted = react_1.useRef(false);
46
+ var refresh = react_1.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
47
+ var newState, _a;
48
+ return __generator(this, function (_b) {
49
+ switch (_b.label) {
50
+ case 0:
51
+ if (!query) return [3 /*break*/, 2];
52
+ return [4 /*yield*/, app.getState(query)];
53
+ case 1:
54
+ _a = _b.sent();
55
+ return [3 /*break*/, 4];
56
+ case 2: return [4 /*yield*/, app.getState()];
57
+ case 3:
58
+ _a = _b.sent();
59
+ _b.label = 4;
60
+ case 4:
61
+ newState = _a;
62
+ if (isUnmounted.current) {
63
+ return [2 /*return*/];
64
+ }
65
+ setState(function (currentState) {
66
+ if (JSON.stringify(newState) === JSON.stringify(currentState)) {
67
+ return currentState;
68
+ }
69
+ return newState;
70
+ });
71
+ return [2 /*return*/];
72
+ }
73
+ });
74
+ }); }, [app, query]);
75
+ react_1.useEffect(function () {
76
+ refresh();
77
+ // Automatically check to see if the state has changed every time an action has been dispatched
78
+ return app.subscribe(function () {
79
+ refresh();
80
+ });
81
+ }, [app, refresh]);
82
+ react_1.useEffect(function () {
83
+ return function () {
84
+ isUnmounted.current = true;
85
+ };
86
+ }, [app]);
87
+ return state;
88
+ };
89
+ exports.useAppBridgeState = useAppBridgeState;
@@ -0,0 +1 @@
1
+ export { useContextualSaveBar } from './useContextualSaveBar';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useContextualSaveBar = void 0;
4
+ var useContextualSaveBar_1 = require("./useContextualSaveBar");
5
+ Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
@@ -0,0 +1,13 @@
1
+ import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
2
+ export interface Props {
3
+ discardAction: DiscardAction & {
4
+ onAction(): void;
5
+ };
6
+ saveAction: ContextAction & {
7
+ onAction(): void;
8
+ };
9
+ fullWidth?: boolean;
10
+ leaveConfirmationDisable?: boolean;
11
+ visible?: boolean;
12
+ }
13
+ export declare function useContextualSaveBar({ discardAction, saveAction, fullWidth, leaveConfirmationDisable, visible, }: Props): null;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.useContextualSaveBar = void 0;
15
+ var react_1 = require("react");
16
+ var ContextualSaveBar_1 = require("@shopify/app-bridge/actions/ContextualSaveBar");
17
+ var useAppBridge_1 = require("../../useAppBridge");
18
+ function useContextualSaveBar(_a) {
19
+ var discardAction = _a.discardAction, saveAction = _a.saveAction, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
20
+ var app = useAppBridge_1.useAppBridge();
21
+ var onSaveAction = saveAction.onAction, saveActionProps = __rest(saveAction, ["onAction"]);
22
+ var onDiscardAction = discardAction.onAction, discardActionProps = __rest(discardAction, ["onAction"]);
23
+ /* We want to reuse the same ContextualSaveBar instance, even when props change
24
+ * (so we don't include all the props in the dependency array).
25
+ * Instead of recreating the component on every change, we use the set method,
26
+ * in the useEffect block below, to dispatch updates when props change.
27
+ */
28
+ var contextualSaveBar = react_1.useMemo(function () {
29
+ return ContextualSaveBar_1.create(app, {
30
+ saveAction: saveActionProps,
31
+ discardAction: discardActionProps,
32
+ fullWidth: fullWidth,
33
+ leaveConfirmationDisable: leaveConfirmationDisable,
34
+ });
35
+ }, [app]);
36
+ react_1.useEffect(function () {
37
+ contextualSaveBar.set({
38
+ saveAction: saveActionProps,
39
+ discardAction: discardActionProps,
40
+ fullWidth: fullWidth,
41
+ leaveConfirmationDisable: leaveConfirmationDisable,
42
+ }, Boolean(visible));
43
+ }, [
44
+ contextualSaveBar,
45
+ saveActionProps,
46
+ discardActionProps,
47
+ fullWidth,
48
+ leaveConfirmationDisable,
49
+ visible,
50
+ ]);
51
+ react_1.useEffect(function () {
52
+ contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, onDiscardAction);
53
+ contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, onSaveAction);
54
+ return function () {
55
+ contextualSaveBar.unsubscribe();
56
+ };
57
+ }, [contextualSaveBar]);
58
+ react_1.useEffect(function () {
59
+ if (visible) {
60
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
61
+ }
62
+ else {
63
+ contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
64
+ }
65
+ }, [contextualSaveBar, visible]);
66
+ return null;
67
+ }
68
+ exports.useContextualSaveBar = useContextualSaveBar;
@@ -0,0 +1 @@
1
+ export * from './useFeatureRequest';
@@ -0,0 +1,13 @@
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" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./useFeatureRequest"), exports);
@@ -0,0 +1,13 @@
1
+ import type { FeaturePermission, FeaturesAction } from '@shopify/app-bridge';
2
+ import { Group } from '@shopify/app-bridge/actions';
3
+ /**
4
+ * useFeatureRequest hook
5
+ *
6
+ * @public
7
+ * @remarks
8
+ * React hook performs a feature request and then returns
9
+ * the requested feature when permissions has been updated
10
+ * @param {Group} group - The requested group enum
11
+ * @param {string} action - The requested action. This param is optional
12
+ */
13
+ export declare function useFeatureRequest(group: Group, action?: string): FeaturesAction | FeaturePermission | undefined;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFeatureRequest = void 0;
4
+ var react_1 = require("react");
5
+ var Features_1 = require("@shopify/app-bridge/actions/Features");
6
+ var useAppBridge_1 = require("../../useAppBridge");
7
+ var useFeaturesAvailable_1 = require("../useFeaturesAvailable");
8
+ /**
9
+ * useFeatureRequest hook
10
+ *
11
+ * @public
12
+ * @remarks
13
+ * React hook performs a feature request and then returns
14
+ * the requested feature when permissions has been updated
15
+ * @param {Group} group - The requested group enum
16
+ * @param {string} action - The requested action. This param is optional
17
+ */
18
+ function useFeatureRequest(group, action) {
19
+ var app = useAppBridge_1.useAppBridge();
20
+ var featuresAvailable = useFeaturesAvailable_1.useFeaturesAvailable();
21
+ var _a = react_1.useState(), feature = _a[0], setFeature = _a[1];
22
+ var handleFeatureUpdate = react_1.useCallback(function (featuresAvailable) {
23
+ var updatedFeatures = featuresAvailable === null || featuresAvailable === void 0 ? void 0 : featuresAvailable[group];
24
+ if (action && (updatedFeatures === null || updatedFeatures === void 0 ? void 0 : updatedFeatures[action])) {
25
+ var actionPermission_1 = updatedFeatures === null || updatedFeatures === void 0 ? void 0 : updatedFeatures[action];
26
+ setFeature(function (currentState) {
27
+ if (JSON.stringify(actionPermission_1) !== JSON.stringify(currentState)) {
28
+ return actionPermission_1;
29
+ }
30
+ return currentState;
31
+ });
32
+ return;
33
+ }
34
+ setFeature(function (currentState) {
35
+ if (JSON.stringify(updatedFeatures) !== JSON.stringify(currentState)) {
36
+ return updatedFeatures;
37
+ }
38
+ return currentState;
39
+ });
40
+ }, [group, action]);
41
+ react_1.useEffect(function () {
42
+ Features_1.create(app).dispatch(Features_1.Action.REQUEST, { feature: group, action: action });
43
+ }, [app, group, action]);
44
+ react_1.useEffect(function () {
45
+ handleFeatureUpdate(featuresAvailable);
46
+ }, [featuresAvailable, handleFeatureUpdate]);
47
+ return feature;
48
+ }
49
+ exports.useFeatureRequest = useFeatureRequest;