@shopify/app-bridge-react 2.0.22 → 2.0.23

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 (39) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/components/ClientRouter/ClientRouter.js +1 -1
  3. package/components/ClientRouter/hook.js +3 -3
  4. package/components/ContextualSaveBar/ContextualSaveBar.js +5 -5
  5. package/components/Modal/Modal.js +1 -1
  6. package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
  7. package/components/NavigationMenu/NavigationMenu.js +55 -0
  8. package/components/NavigationMenu/index.d.ts +3 -0
  9. package/components/NavigationMenu/index.js +7 -0
  10. package/components/Provider/Provider.d.ts +1 -2
  11. package/components/Provider/Provider.js +2 -6
  12. package/components/RoutePropagator/RoutePropagator.js +2 -2
  13. package/components/RoutePropagator/globals.d.ts +1 -1
  14. package/components/RoutePropagator/hook.js +3 -3
  15. package/components/RoutePropagator/route-propagator.js +5 -5
  16. package/components/TitleBar/TitleBar.js +2 -2
  17. package/components/index.d.ts +4 -3
  18. package/components/index.js +10 -12
  19. package/context.d.ts +1 -1
  20. package/context.js +1 -1
  21. package/hooks/index.d.ts +1 -0
  22. package/hooks/index.js +3 -1
  23. package/hooks/useAppBridgeState/index.d.ts +1 -0
  24. package/hooks/useAppBridgeState/index.js +13 -0
  25. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
  26. package/hooks/useAppBridgeState/useAppBridgeState.js +75 -0
  27. package/hooks/useContextualSaveBar/useContextualSaveBar.js +6 -6
  28. package/hooks/useLocale/index.d.ts +1 -0
  29. package/hooks/useLocale/index.js +5 -0
  30. package/hooks/useLocale/useLocale.d.ts +1 -0
  31. package/hooks/useLocale/useLocale.js +8 -0
  32. package/hooks/useNavigationHistory/useNavigationHistory.js +2 -2
  33. package/hooks/useToast/useToast.js +4 -4
  34. package/index.d.ts +1 -0
  35. package/index.js +2 -5
  36. package/package.json +3 -3
  37. package/umd/index.js +3 -3
  38. package/useAppBridge.js +1 -1
  39. package/utilities/transformers.js +7 -11
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
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.23](https://github.com/Shopify/app-bridge/compare/v2.0.22...v2.0.23) (2022-04-07)
7
+
8
+
9
+ ### Features
10
+
11
+ * NavigationMenu component ([0205cb3](https://github.com/Shopify/app-bridge/commit/0205cb396d8b4ed679dd465348a6dc45227cedb9))
12
+ * **app-bridge-react:** add useAppBridgeState hook ([1fc64f1](https://github.com/Shopify/app-bridge/commit/1fc64f142cbd0a72adccb75fec36d31cde1ed552))
13
+ * **app-bridge-react:** add useLocale hook ([e17dbad](https://github.com/Shopify/app-bridge/commit/e17dbadedbded9d274744738821bef49e52eb43b))
14
+
15
+
16
+
17
+
18
+
6
19
  ## [2.0.22](https://github.com/Shopify/app-bridge/compare/v2.0.21...v2.0.22) (2022-03-30)
7
20
 
8
21
 
@@ -36,7 +36,7 @@ var ClientRouter = /** @class */ (function (_super) {
36
36
  }
37
37
  ClientRouter.prototype.componentDidMount = function () {
38
38
  var history = this.props.history;
39
- this.unsubscribe = (0, router_1.handleRouteChange)(this.context, history);
39
+ this.unsubscribe = router_1.handleRouteChange(this.context, history);
40
40
  };
41
41
  ClientRouter.prototype.componentWillUnmount = function () {
42
42
  if (this.unsubscribe) {
@@ -12,9 +12,9 @@ var router_1 = require("./router");
12
12
  * @public
13
13
  */
14
14
  function useClientRouting(history) {
15
- var app = (0, useAppBridge_1.useAppBridge)();
16
- (0, react_1.useEffect)(function () {
17
- return (0, router_1.handleRouteChange)(app, history);
15
+ var app = useAppBridge_1.useAppBridge();
16
+ react_1.useEffect(function () {
17
+ return router_1.handleRouteChange(app, history);
18
18
  }, [app, history]);
19
19
  }
20
20
  exports.default = useClientRouting;
@@ -17,10 +17,10 @@ var useAppBridge_1 = require("../../useAppBridge");
17
17
  var Action = actions_1.ContextualSaveBar.Action, create = actions_1.ContextualSaveBar.create;
18
18
  function ContextualSaveBar(_a) {
19
19
  var discardAction = _a.discardAction, saveAction = _a.saveAction, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
20
- var app = (0, useAppBridge_1.useAppBridge)();
20
+ var app = useAppBridge_1.useAppBridge();
21
21
  var onSaveAction = saveAction.onAction, saveActionProps = __rest(saveAction, ["onAction"]);
22
22
  var onDiscardAction = discardAction.onAction, discardActionProps = __rest(discardAction, ["onAction"]);
23
- var contextualSaveBar = (0, react_1.useMemo)(function () {
23
+ var contextualSaveBar = react_1.useMemo(function () {
24
24
  return create(app, {
25
25
  saveAction: saveActionProps,
26
26
  discardAction: discardActionProps,
@@ -28,7 +28,7 @@ function ContextualSaveBar(_a) {
28
28
  leaveConfirmationDisable: leaveConfirmationDisable,
29
29
  });
30
30
  }, [app]);
31
- (0, react_1.useEffect)(function () {
31
+ react_1.useEffect(function () {
32
32
  contextualSaveBar.set({
33
33
  saveAction: saveActionProps,
34
34
  discardAction: discardActionProps,
@@ -44,14 +44,14 @@ function ContextualSaveBar(_a) {
44
44
  leaveConfirmationDisable,
45
45
  visible,
46
46
  ]);
47
- (0, react_1.useEffect)(function () {
47
+ react_1.useEffect(function () {
48
48
  contextualSaveBar.subscribe(Action.DISCARD, onDiscardAction);
49
49
  contextualSaveBar.subscribe(Action.SAVE, onSaveAction);
50
50
  return function () {
51
51
  contextualSaveBar.unsubscribe();
52
52
  };
53
53
  }, [contextualSaveBar]);
54
- (0, react_1.useEffect)(function () {
54
+ react_1.useEffect(function () {
55
55
  if (visible) {
56
56
  contextualSaveBar.dispatch(Action.SHOW);
57
57
  }
@@ -116,7 +116,7 @@ var Modal = /** @class */ (function (_super) {
116
116
  }
117
117
  }
118
118
  return __assign(__assign({ title: title, message: message, size: safeSize }, srcPayload), { footer: {
119
- buttons: (0, transformers_1.transformActions)(app, {
119
+ buttons: transformers_1.transformActions(app, {
120
120
  primaryAction: primaryAction,
121
121
  secondaryActions: secondaryActions,
122
122
  }),
@@ -0,0 +1,17 @@
1
+ export interface NavigationLink {
2
+ label: string;
3
+ destination: string;
4
+ }
5
+ export interface Props {
6
+ /**
7
+ * List of links in navigation menu
8
+ */
9
+ navigationLinks: NavigationLink[];
10
+ /**
11
+ * Custom matcher to set active link.
12
+ * This function will be called with each link and the current location.
13
+ * If it returns true the current link will be set to the active link.
14
+ */
15
+ matcher?: (link: NavigationLink, location: Location) => boolean;
16
+ }
17
+ export default function NavigationMenu({ navigationLinks, matcher }: Props): null;
@@ -0,0 +1,55 @@
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
+ var react_1 = require("react");
23
+ var AppBridgeAppLinks = __importStar(require("@shopify/app-bridge/actions/Link/AppLink"));
24
+ var AppBridgeNavigationMenu = __importStar(require("@shopify/app-bridge/actions/Menu/NavigationMenu"));
25
+ var useAppBridge_1 = require("../../useAppBridge");
26
+ function NavigationMenu(_a) {
27
+ var navigationLinks = _a.navigationLinks, matcher = _a.matcher;
28
+ var app = useAppBridge_1.useAppBridge();
29
+ var _b = react_1.useState(), activeLink = _b[0], setActiveLink = _b[1];
30
+ var items = react_1.useMemo(function () {
31
+ return navigationLinks.map(function (link) {
32
+ var appLink = AppBridgeAppLinks.create(app, link);
33
+ if ((matcher === null || matcher === void 0 ? void 0 : matcher(link, location)) || link.destination === location.pathname) {
34
+ setActiveLink(appLink);
35
+ }
36
+ return appLink;
37
+ });
38
+ }, [app, location.pathname, matcher, navigationLinks]);
39
+ var navigationMenu = react_1.useMemo(function () {
40
+ return AppBridgeNavigationMenu.create(app, {
41
+ items: items,
42
+ active: activeLink,
43
+ });
44
+ /* We want to reuse the same NavigationMenu instance, even when props change
45
+ * (so we don't include all the props in the dependency array).
46
+ * Instead of recreating the component on every change, we use the set method,
47
+ * in the useEffect block below, to dispatch updates when props change.
48
+ */
49
+ }, [app]);
50
+ react_1.useEffect(function () {
51
+ navigationMenu.set({ items: items, active: activeLink });
52
+ }, [activeLink, items]);
53
+ return null;
54
+ }
55
+ exports.default = NavigationMenu;
@@ -0,0 +1,3 @@
1
+ import NavigationMenu from './NavigationMenu';
2
+ export { Props } from './NavigationMenu';
3
+ export default NavigationMenu;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var NavigationMenu_1 = __importDefault(require("./NavigationMenu"));
7
+ exports.default = NavigationMenu_1.default;
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { DispatchActionHook } from '@shopify/app-bridge';
3
- import { AppConfigV2 } from '@shopify/app-bridge/client';
2
+ import type { AppConfigV2, DispatchActionHook } from '@shopify/app-bridge/client';
4
3
  /**
5
4
  * Provider props
6
5
  *
@@ -16,11 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
18
  if (k2 === undefined) k2 = k;
19
- var desc = Object.getOwnPropertyDescriptor(m, k);
20
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
- desc = { enumerable: true, get: function() { return m[k]; } };
22
- }
23
- Object.defineProperty(o, k2, desc);
19
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
24
20
  }) : (function(o, m, k, k2) {
25
21
  if (k2 === undefined) k2 = k;
26
22
  o[k2] = m[k];
@@ -67,7 +63,7 @@ var Provider = /** @class */ (function (_super) {
67
63
  Object.defineProperty(Provider.prototype, "appInstance", {
68
64
  get: function () {
69
65
  if (!this.app) {
70
- this.app = (0, app_bridge_1.default)(this.props.config);
66
+ this.app = app_bridge_1.default(this.props.config);
71
67
  if (this.app && this.app.hooks) {
72
68
  this.app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
73
69
  }
@@ -36,13 +36,13 @@ var RoutePropagator = /** @class */ (function (_super) {
36
36
  }
37
37
  RoutePropagator.prototype.componentDidMount = function () {
38
38
  var location = this.props.location;
39
- (0, route_propagator_1.updateHistory)(this.context, location);
39
+ route_propagator_1.updateHistory(this.context, location);
40
40
  };
41
41
  RoutePropagator.prototype.componentDidUpdate = function (_a) {
42
42
  var prevLocation = _a.location;
43
43
  var location = this.props.location;
44
44
  if (location !== prevLocation) {
45
- (0, route_propagator_1.updateHistory)(this.context, location);
45
+ route_propagator_1.updateHistory(this.context, location);
46
46
  }
47
47
  };
48
48
  RoutePropagator.prototype.render = function () {
@@ -1,3 +1,3 @@
1
1
  export declare function getSelfWindow(): Window & typeof globalThis;
2
- export declare function getTopWindow(): Window | null;
2
+ export declare function getTopWindow(): Window;
3
3
  export declare function getOrigin(): string;
@@ -12,9 +12,9 @@ var route_propagator_1 = require("./route-propagator");
12
12
  * @public
13
13
  */
14
14
  function useRoutePropagation(location) {
15
- var app = (0, useAppBridge_1.useAppBridge)();
16
- (0, react_1.useEffect)(function () {
17
- (0, route_propagator_1.updateHistory)(app, location);
15
+ var app = useAppBridge_1.useAppBridge();
16
+ react_1.useEffect(function () {
17
+ route_propagator_1.updateHistory(app, location);
18
18
  }, [app, location]);
19
19
  }
20
20
  exports.default = useRoutePropagation;
@@ -59,8 +59,8 @@ function updateHistory(app, location) {
59
59
  return __generator(this, function (_a) {
60
60
  switch (_a.label) {
61
61
  case 0:
62
- selfWindow = (0, globals_1.getSelfWindow)();
63
- topWindow = (0, globals_1.getTopWindow)();
62
+ selfWindow = globals_1.getSelfWindow();
63
+ topWindow = globals_1.getTopWindow();
64
64
  renderedInTheTopWindow = selfWindow === topWindow;
65
65
  return [4 /*yield*/, app.getState('context').then(function (context) {
66
66
  return context === MessageTransport_1.Context.Main;
@@ -73,7 +73,7 @@ function updateHistory(app, location) {
73
73
  normalizedLocation = getNormalizedURL(location);
74
74
  embeddedFrameParamsToRemove.forEach(function (param) { return normalizedLocation.searchParams.delete(param); });
75
75
  pathname = normalizedLocation.pathname, search = normalizedLocation.search, hash = normalizedLocation.hash;
76
- locationStr = "".concat(pathname).concat(search).concat(hash);
76
+ locationStr = "" + pathname + search + hash;
77
77
  actions_1.History.create(app).dispatch(actions_1.History.Action.REPLACE, locationStr);
78
78
  return [2 /*return*/];
79
79
  }
@@ -82,10 +82,10 @@ function updateHistory(app, location) {
82
82
  }
83
83
  exports.updateHistory = updateHistory;
84
84
  function getNormalizedURL(location) {
85
- var origin = (0, globals_1.getOrigin)();
85
+ var origin = globals_1.getOrigin();
86
86
  if (typeof location === 'string') {
87
87
  return new URL(location, origin);
88
88
  }
89
89
  var pathname = location.pathname, search = location.search, hash = location.hash;
90
- return new URL("".concat(pathname).concat(search).concat(hash), origin);
90
+ return new URL("" + pathname + search + hash, origin);
91
91
  }
@@ -46,7 +46,7 @@ var TitleBar = /** @class */ (function (_super) {
46
46
  var _a = this.props, title = _a.title, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, actionGroups = _a.actionGroups;
47
47
  return {
48
48
  title: title,
49
- buttons: (0, transformers_1.transformActions)(app, {
49
+ buttons: transformers_1.transformActions(app, {
50
50
  primaryAction: primaryAction,
51
51
  secondaryActions: secondaryActions,
52
52
  actionGroups: actionGroups,
@@ -65,7 +65,7 @@ var TitleBar = /** @class */ (function (_super) {
65
65
  var button = actions_1.Button.create(app, {
66
66
  label: content || '',
67
67
  });
68
- var redirect = (0, transformers_1.generateRedirect)(app, url, target);
68
+ var redirect = transformers_1.generateRedirect(app, url, target);
69
69
  if (redirect != null) {
70
70
  button.subscribe(actions_1.Button.Action.CLICK, redirect);
71
71
  }
@@ -1,9 +1,10 @@
1
1
  export { default as ContextualSaveBar, Props as ContextualSaveBarProps } from './ContextualSaveBar';
2
- export { default as Provider, Props as ProviderProps } from './Provider';
3
2
  export { default as Loading } from './Loading';
4
- export { default as Toast, Props as ToastProps } from './Toast';
5
- export { default as TitleBar } from './TitleBar';
6
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';
7
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';
8
9
  export * from './RoutePropagator';
9
10
  export * from './ClientRouter';
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -17,21 +13,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
14
  };
19
15
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ResourcePicker = exports.ModalContent = exports.Modal = exports.TitleBar = exports.Toast = exports.Loading = exports.Provider = exports.ContextualSaveBar = void 0;
16
+ exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
21
17
  var ContextualSaveBar_1 = require("./ContextualSaveBar");
22
18
  Object.defineProperty(exports, "ContextualSaveBar", { enumerable: true, get: function () { return __importDefault(ContextualSaveBar_1).default; } });
23
- var Provider_1 = require("./Provider");
24
- Object.defineProperty(exports, "Provider", { enumerable: true, get: function () { return __importDefault(Provider_1).default; } });
25
19
  var Loading_1 = require("./Loading");
26
20
  Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return __importDefault(Loading_1).default; } });
27
- var Toast_1 = require("./Toast");
28
- Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return __importDefault(Toast_1).default; } });
29
- var TitleBar_1 = require("./TitleBar");
30
- Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return __importDefault(TitleBar_1).default; } });
31
21
  var Modal_1 = require("./Modal");
32
22
  Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return __importDefault(Modal_1).default; } });
33
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; } });
34
28
  var ResourcePicker_1 = require("./ResourcePicker");
35
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; } });
36
34
  __exportStar(require("./RoutePropagator"), exports);
37
35
  __exportStar(require("./ClientRouter"), exports);
package/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ClientApplication } from '@shopify/app-bridge/client';
1
+ import type { ClientApplication } from '@shopify/app-bridge/client';
2
2
  /**
3
3
  * App Bridge context consumer type.
4
4
  *
package/context.js CHANGED
@@ -7,4 +7,4 @@ var react_1 = require("react");
7
7
  *
8
8
  * @public
9
9
  */
10
- exports.AppBridgeContext = (0, react_1.createContext)(null);
10
+ exports.AppBridgeContext = react_1.createContext(null);
package/hooks/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { useContextualSaveBar } from './useContextualSaveBar';
2
2
  export { useNavigationHistory } from './useNavigationHistory';
3
3
  export { useToast } from './useToast';
4
+ export { useAppBridgeState } from './useAppBridgeState';
package/hooks/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useToast = exports.useNavigationHistory = exports.useContextualSaveBar = void 0;
3
+ exports.useAppBridgeState = exports.useToast = exports.useNavigationHistory = exports.useContextualSaveBar = void 0;
4
4
  var useContextualSaveBar_1 = require("./useContextualSaveBar");
5
5
  Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
6
6
  var useNavigationHistory_1 = require("./useNavigationHistory");
7
7
  Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
8
8
  var useToast_1 = require("./useToast");
9
9
  Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
10
+ var useAppBridgeState_1 = require("./useAppBridgeState");
11
+ Object.defineProperty(exports, "useAppBridgeState", { enumerable: true, get: function () { return useAppBridgeState_1.useAppBridgeState; } });
@@ -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,75 @@
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 refresh = react_1.useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
46
+ var state, _a;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ if (!query) return [3 /*break*/, 2];
51
+ return [4 /*yield*/, app.getState(query)];
52
+ case 1:
53
+ _a = _b.sent();
54
+ return [3 /*break*/, 4];
55
+ case 2: return [4 /*yield*/, app.getState()];
56
+ case 3:
57
+ _a = _b.sent();
58
+ _b.label = 4;
59
+ case 4:
60
+ state = _a;
61
+ setState(state);
62
+ return [2 /*return*/, state];
63
+ }
64
+ });
65
+ }); }, [app, query]);
66
+ react_1.useEffect(function () {
67
+ refresh();
68
+ // Automatically check to see if the state has changed every time an action has been dispatched
69
+ return app.subscribe(function () {
70
+ refresh();
71
+ });
72
+ }, [app, refresh]);
73
+ return state;
74
+ };
75
+ exports.useAppBridgeState = useAppBridgeState;
@@ -17,7 +17,7 @@ var ContextualSaveBar_1 = require("@shopify/app-bridge/actions/ContextualSaveBar
17
17
  var useAppBridge_1 = require("../../useAppBridge");
18
18
  function useContextualSaveBar(_a) {
19
19
  var discardAction = _a.discardAction, saveAction = _a.saveAction, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
20
- var app = (0, useAppBridge_1.useAppBridge)();
20
+ var app = useAppBridge_1.useAppBridge();
21
21
  var onSaveAction = saveAction.onAction, saveActionProps = __rest(saveAction, ["onAction"]);
22
22
  var onDiscardAction = discardAction.onAction, discardActionProps = __rest(discardAction, ["onAction"]);
23
23
  /* We want to reuse the same ContextualSaveBar instance, even when props change
@@ -25,15 +25,15 @@ function useContextualSaveBar(_a) {
25
25
  * Instead of recreating the component on every change, we use the set method,
26
26
  * in the useEffect block below, to dispatch updates when props change.
27
27
  */
28
- var contextualSaveBar = (0, react_1.useMemo)(function () {
29
- return (0, ContextualSaveBar_1.create)(app, {
28
+ var contextualSaveBar = react_1.useMemo(function () {
29
+ return ContextualSaveBar_1.create(app, {
30
30
  saveAction: saveActionProps,
31
31
  discardAction: discardActionProps,
32
32
  fullWidth: fullWidth,
33
33
  leaveConfirmationDisable: leaveConfirmationDisable,
34
34
  });
35
35
  }, [app]);
36
- (0, react_1.useEffect)(function () {
36
+ react_1.useEffect(function () {
37
37
  contextualSaveBar.set({
38
38
  saveAction: saveActionProps,
39
39
  discardAction: discardActionProps,
@@ -48,14 +48,14 @@ function useContextualSaveBar(_a) {
48
48
  leaveConfirmationDisable,
49
49
  visible,
50
50
  ]);
51
- (0, react_1.useEffect)(function () {
51
+ react_1.useEffect(function () {
52
52
  contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, onDiscardAction);
53
53
  contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, onSaveAction);
54
54
  return function () {
55
55
  contextualSaveBar.unsubscribe();
56
56
  };
57
57
  }, [contextualSaveBar]);
58
- (0, react_1.useEffect)(function () {
58
+ react_1.useEffect(function () {
59
59
  if (visible) {
60
60
  contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
61
61
  }
@@ -0,0 +1 @@
1
+ export { useLocale } from './useLocale';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLocale = void 0;
4
+ var useLocale_1 = require("./useLocale");
5
+ Object.defineProperty(exports, "useLocale", { enumerable: true, get: function () { return useLocale_1.useLocale; } });
@@ -0,0 +1 @@
1
+ export declare function useLocale(): string | undefined;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLocale = void 0;
4
+ var useAppBridgeState_1 = require("../useAppBridgeState");
5
+ function useLocale() {
6
+ return useAppBridgeState_1.useAppBridgeState('staffMember.locale');
7
+ }
8
+ exports.useLocale = useLocale;
@@ -13,8 +13,8 @@ var useAppBridge_1 = require("../../useAppBridge");
13
13
  * @public
14
14
  */
15
15
  function useNavigationHistory() {
16
- var app = (0, useAppBridge_1.useAppBridge)();
17
- return (0, react_1.useMemo)(function () {
16
+ var app = useAppBridge_1.useAppBridge();
17
+ return react_1.useMemo(function () {
18
18
  var history = actions_1.History.create(app);
19
19
  function push(location) {
20
20
  history.dispatch(actions_1.History.Action.PUSH, location.pathname);
@@ -14,11 +14,11 @@ exports.DEFAULT_TOAST_DURATION = 5000;
14
14
  * @public
15
15
  */
16
16
  function useToast() {
17
- var app = (0, useAppBridge_1.useAppBridge)();
17
+ var app = useAppBridge_1.useAppBridge();
18
18
  var toast;
19
- var show = (0, react_1.useCallback)(function (_a) {
19
+ var show = react_1.useCallback(function (_a) {
20
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 = (0, Toast_1.create)(app, {
21
+ toast = Toast_1.create(app, {
22
22
  message: message,
23
23
  isError: isError,
24
24
  duration: duration,
@@ -28,7 +28,7 @@ function useToast() {
28
28
  toast.subscribe(Toast_1.Action.CLEAR, onDismiss);
29
29
  }
30
30
  }, [app]);
31
- (0, react_1.useEffect)(function () {
31
+ react_1.useEffect(function () {
32
32
  return function () {
33
33
  toast.unsubscribe();
34
34
  };
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
2
  export { AppBridgeContext as Context } from './context';
3
3
  export { useAppBridge } from './useAppBridge';
4
+ export * from './hooks';
package/index.js CHANGED
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
5
  }) : (function(o, m, k, k2) {
10
6
  if (k2 === undefined) k2 = k;
11
7
  o[k2] = m[k];
@@ -20,3 +16,4 @@ var context_1 = require("./context");
20
16
  Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
21
17
  var useAppBridge_1 = require("./useAppBridge");
22
18
  Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
19
+ __exportStar(require("./hooks"), exports);