@shopify/app-bridge-react 2.0.22 → 2.0.25

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 (57) hide show
  1. package/CHANGELOG.md +44 -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 +58 -13
  11. package/components/Provider/Provider.js +24 -54
  12. package/components/ResourcePicker/ResourcePicker.d.ts +7 -16
  13. package/components/ResourcePicker/ResourcePicker.js +77 -94
  14. package/components/RoutePropagator/RoutePropagator.js +2 -2
  15. package/components/RoutePropagator/globals.d.ts +1 -1
  16. package/components/RoutePropagator/hook.js +3 -3
  17. package/components/RoutePropagator/route-propagator.js +5 -5
  18. package/components/TitleBar/TitleBar.d.ts +3 -14
  19. package/components/TitleBar/TitleBar.js +50 -75
  20. package/components/index.d.ts +4 -3
  21. package/components/index.js +10 -12
  22. package/context.d.ts +1 -1
  23. package/context.js +1 -1
  24. package/hooks/index.d.ts +5 -0
  25. package/hooks/index.js +9 -1
  26. package/hooks/useAppBridgeState/index.d.ts +1 -0
  27. package/hooks/useAppBridgeState/index.js +13 -0
  28. package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
  29. package/hooks/useAppBridgeState/useAppBridgeState.js +89 -0
  30. package/hooks/useContextualSaveBar/useContextualSaveBar.js +6 -6
  31. package/hooks/useFeatureRequest/index.d.ts +1 -0
  32. package/hooks/useFeatureRequest/index.js +13 -0
  33. package/hooks/useFeatureRequest/useFeatureRequest.d.ts +13 -0
  34. package/hooks/useFeatureRequest/useFeatureRequest.js +49 -0
  35. package/hooks/useFeaturesAvailable/index.d.ts +2 -0
  36. package/hooks/useFeaturesAvailable/index.js +5 -0
  37. package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +12 -0
  38. package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +101 -0
  39. package/hooks/useLocale/index.d.ts +1 -0
  40. package/hooks/useLocale/index.js +5 -0
  41. package/hooks/useLocale/useLocale.d.ts +1 -0
  42. package/hooks/useLocale/useLocale.js +8 -0
  43. package/hooks/useNavigate/index.d.ts +1 -0
  44. package/hooks/useNavigate/index.js +5 -0
  45. package/hooks/useNavigate/useNavigate.d.ts +24 -0
  46. package/hooks/useNavigate/useNavigate.js +109 -0
  47. package/hooks/useNavigationHistory/useNavigationHistory.js +2 -2
  48. package/hooks/useToast/useToast.js +4 -4
  49. package/index.d.ts +1 -0
  50. package/index.js +2 -5
  51. package/package.json +3 -3
  52. package/types.d.ts +2 -0
  53. package/types.js +3 -0
  54. package/umd/index.js +3 -3
  55. package/useAppBridge.js +1 -1
  56. package/utilities/transformers.d.ts +3 -2
  57. package/utilities/transformers.js +37 -20
@@ -1,19 +1,4 @@
1
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
2
  var __assign = (this && this.__assign) || function () {
18
3
  __assign = Object.assign || function(t) {
19
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -25,13 +10,13 @@ var __assign = (this && this.__assign) || function () {
25
10
  };
26
11
  return __assign.apply(this, arguments);
27
12
  };
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
13
  Object.defineProperty(exports, "__esModule", { value: true });
32
- var react_1 = __importDefault(require("react"));
33
- var actions_1 = require("@shopify/app-bridge/actions");
34
- var context_1 = require("../../context");
14
+ exports.ResourceType = exports.ActionVerb = void 0;
15
+ var react_1 = require("react");
16
+ var ResourcePicker_1 = require("@shopify/app-bridge/actions/ResourcePicker");
17
+ Object.defineProperty(exports, "ActionVerb", { enumerable: true, get: function () { return ResourcePicker_1.ActionVerb; } });
18
+ Object.defineProperty(exports, "ResourceType", { enumerable: true, get: function () { return ResourcePicker_1.ResourceType; } });
19
+ var useAppBridge_1 = require("../../useAppBridge");
35
20
  /**
36
21
  * ResourcePicker component
37
22
  *
@@ -40,92 +25,90 @@ var context_1 = require("../../context");
40
25
  *
41
26
  * @public
42
27
  */
43
- var ResourcePicker = /** @class */ (function (_super) {
44
- __extends(ResourcePicker, _super);
45
- function ResourcePicker() {
46
- var _this = _super !== null && _super.apply(this, arguments) || this;
47
- _this.focusReturnPoint = null;
48
- return _this;
49
- }
50
- ResourcePicker.prototype.componentDidMount = function () {
51
- var _a = this.props, open = _a.open, resourceType = _a.resourceType, onSelection = _a.onSelection, onCancel = _a.onCancel;
52
- var app = this.context;
53
- this.picker = actions_1.ResourcePicker.create(app, {
54
- resourceType: actions_1.ResourcePicker.ResourceType[resourceType],
55
- options: this.getActionOptions(),
28
+ function ResourcePicker(props) {
29
+ var app = useAppBridge_1.useAppBridge();
30
+ var focusReturnPoint = react_1.useRef(null);
31
+ var resourceType = props.resourceType, onSelection = props.onSelection, onCancel = props.onCancel, open = props.open;
32
+ // Initialize with open: false so the open action will dispatch on initial load
33
+ var prevProps = react_1.useRef({ open: false });
34
+ var picker = react_1.useMemo(function () {
35
+ return ResourcePicker_1.create(app, {
36
+ resourceType: ResourcePicker_1.ResourceType[resourceType],
37
+ options: getActionOptions(props),
56
38
  });
57
- if (onSelection != null) {
58
- this.picker.subscribe(actions_1.ResourcePicker.Action.SELECT, onSelection);
59
- }
60
- if (onCancel != null) {
61
- this.picker.subscribe(actions_1.ResourcePicker.Action.CANCEL, onCancel);
62
- }
63
- if (open) {
64
- this.focusReturnPoint = document.activeElement;
65
- this.picker.dispatch(actions_1.ResourcePicker.Action.OPEN);
66
- }
67
- };
68
- ResourcePicker.prototype.componentDidUpdate = function (prevProps) {
69
- var wasOpen = prevProps.open;
70
- var _a = this.props, open = _a.open, onCancel = _a.onCancel, onSelection = _a.onSelection;
71
- this.picker.unsubscribe();
72
- this.picker.set(this.getActionOptions());
73
- if (onSelection != null) {
74
- this.picker.subscribe(actions_1.ResourcePicker.Action.SELECT, onSelection);
75
- }
76
- if (onCancel != null) {
77
- this.picker.subscribe(actions_1.ResourcePicker.Action.CANCEL, onCancel);
78
- }
39
+ // We purposely want to reuse the same picker instance
40
+ // and use a useEffect to call `picker.set` when needed
41
+ }, [app]);
42
+ react_1.useEffect(function () {
43
+ var _a;
44
+ var wasOpen = (_a = prevProps.current) === null || _a === void 0 ? void 0 : _a.open;
79
45
  if (wasOpen !== open) {
80
46
  if (open) {
81
- this.picker.dispatch(actions_1.ResourcePicker.Action.OPEN);
47
+ picker.dispatch(ResourcePicker_1.Action.OPEN);
82
48
  }
83
49
  else {
84
- this.picker.dispatch(actions_1.ResourcePicker.Action.CLOSE);
50
+ picker.dispatch(ResourcePicker_1.Action.CLOSE);
85
51
  }
86
52
  }
87
53
  if (!wasOpen && open) {
88
- this.focusReturnPoint = document.activeElement;
54
+ focusReturnPoint.current = document.activeElement;
89
55
  }
90
56
  else if (wasOpen &&
91
57
  !open &&
92
- this.focusReturnPoint != null &&
93
- document.contains(this.focusReturnPoint)) {
94
- this.focusReturnPoint.focus();
95
- this.focusReturnPoint = null;
58
+ focusReturnPoint.current != null &&
59
+ document.contains(focusReturnPoint.current)) {
60
+ focusReturnPoint.current.focus();
61
+ focusReturnPoint.current = null;
96
62
  }
97
- };
98
- ResourcePicker.prototype.componentWillUnmount = function () {
99
- this.picker.unsubscribe();
100
- };
101
- ResourcePicker.prototype.render = function () {
102
- return null;
103
- };
104
- ResourcePicker.prototype.getActionOptions = function () {
105
- var _a = this.props, initialQuery = _a.initialQuery, initialSelectionIds = _a.initialSelectionIds, showHidden = _a.showHidden, allowMultiple = _a.allowMultiple, selectMultiple = _a.selectMultiple, actionVerb = _a.actionVerb;
106
- var sharedOptions = {
107
- initialQuery: initialQuery,
108
- initialSelectionIds: initialSelectionIds,
109
- showHidden: showHidden,
110
- selectMultiple: selectMultiple !== null && selectMultiple !== void 0 ? selectMultiple : allowMultiple,
111
- actionVerb: actionVerb,
63
+ }, [open]);
64
+ react_1.useEffect(function () {
65
+ var unsubscribeList = [];
66
+ if (onSelection != null) {
67
+ unsubscribeList.push(picker.subscribe(ResourcePicker_1.Action.SELECT, onSelection));
68
+ }
69
+ if (onCancel != null) {
70
+ unsubscribeList.push(picker.subscribe(ResourcePicker_1.Action.CANCEL, onCancel));
71
+ }
72
+ return function () {
73
+ var unsubscribe = unsubscribeList.pop();
74
+ while (unsubscribe) {
75
+ unsubscribe();
76
+ unsubscribe = unsubscribeList.pop();
77
+ }
112
78
  };
113
- var result = sharedOptions;
114
- if (this.props.resourceType === 'Product') {
115
- var _b = this.props, showVariants = _b.showVariants, showDraft = _b.showDraft, showArchived = _b.showArchived, showDraftBadge = _b.showDraftBadge, showArchivedBadge = _b.showArchivedBadge;
116
- var productSpecificOptions = {
117
- showVariants: showVariants,
118
- showDraft: showDraft,
119
- showArchived: showArchived,
120
- showDraftBadge: showDraftBadge,
121
- showArchivedBadge: showArchivedBadge,
122
- };
123
- result = __assign(__assign({}, sharedOptions), productSpecificOptions);
79
+ }, [onSelection, onCancel]);
80
+ react_1.useEffect(function () {
81
+ var shouldUpdate = JSON.stringify(__assign(__assign({}, prevProps.current), { open: undefined })) !==
82
+ JSON.stringify(__assign(__assign({}, props), { open: undefined }));
83
+ if (!shouldUpdate) {
84
+ return;
124
85
  }
125
- return result;
86
+ picker.set(getActionOptions(props));
87
+ prevProps.current = props;
88
+ }, [props]);
89
+ return null;
90
+ }
91
+ function getActionOptions(props) {
92
+ var initialQuery = props.initialQuery, initialSelectionIds = props.initialSelectionIds, showHidden = props.showHidden, allowMultiple = props.allowMultiple, selectMultiple = props.selectMultiple, actionVerb = props.actionVerb;
93
+ var sharedOptions = {
94
+ initialQuery: initialQuery,
95
+ initialSelectionIds: initialSelectionIds,
96
+ showHidden: showHidden,
97
+ selectMultiple: selectMultiple !== null && selectMultiple !== void 0 ? selectMultiple : allowMultiple,
98
+ actionVerb: actionVerb,
126
99
  };
127
- ResourcePicker.contextType = context_1.AppBridgeContext;
128
- ResourcePicker.ActionVerb = actions_1.ResourcePicker.ActionVerb;
129
- return ResourcePicker;
130
- }(react_1.default.PureComponent));
100
+ var result = sharedOptions;
101
+ if (props.resourceType === 'Product') {
102
+ var showVariants = props.showVariants, showDraft = props.showDraft, showArchived = props.showArchived, showDraftBadge = props.showDraftBadge, showArchivedBadge = props.showArchivedBadge;
103
+ var productSpecificOptions = {
104
+ showVariants: showVariants,
105
+ showDraft: showDraft,
106
+ showArchived: showArchived,
107
+ showDraftBadge: showDraftBadge,
108
+ showArchivedBadge: showArchivedBadge,
109
+ };
110
+ result = __assign(__assign({}, sharedOptions), productSpecificOptions);
111
+ }
112
+ return result;
113
+ }
131
114
  exports.default = ResourcePicker;
@@ -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
  }
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { ActionProps, ActionGroupProps, Target } from '../../types';
3
2
  export interface Breadcrumb {
4
3
  /** Content the action displays */
@@ -16,8 +15,8 @@ export interface Breadcrumb {
16
15
  export interface Props {
17
16
  /** TitleBar title */
18
17
  title: string;
19
- /** Collection of breadcrumbs */
20
- breadcrumbs?: Breadcrumb[];
18
+ /** The current breadcrumb; only displays the last item in array */
19
+ breadcrumbs?: Breadcrumb | Breadcrumb[];
21
20
  /** Primary TitleBar action */
22
21
  primaryAction?: ActionProps;
23
22
  /** Collection of secondary TitleBar actions */
@@ -25,14 +24,4 @@ export interface Props {
25
24
  /** Collection of TitleBar groups of secondary actions */
26
25
  actionGroups?: ActionGroupProps[];
27
26
  }
28
- declare class TitleBar extends React.PureComponent<Props, never> {
29
- static contextType: React.Context<import("../../context").IAppBridgeContext>;
30
- private titleBar;
31
- componentDidMount(): void;
32
- componentDidUpdate(): void;
33
- componentWillUnmount(): void;
34
- render(): null;
35
- private transformProps;
36
- private transformBreadcrumbs;
37
- }
38
- export default TitleBar;
27
+ export default function TitleBar(props: Props): null;
@@ -1,80 +1,55 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
21
- var react_1 = __importDefault(require("react"));
22
- var actions_1 = require("@shopify/app-bridge/actions");
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");
23
6
  var transformers_1 = require("../../utilities/transformers");
24
- var context_1 = require("../../context");
25
- var TitleBar = /** @class */ (function (_super) {
26
- __extends(TitleBar, _super);
27
- function TitleBar() {
28
- return _super !== null && _super.apply(this, arguments) || this;
29
- }
30
- TitleBar.prototype.componentDidMount = function () {
31
- var app = this.context;
32
- this.titleBar = actions_1.TitleBar.create(app, this.transformProps());
33
- };
34
- TitleBar.prototype.componentDidUpdate = function () {
35
- this.titleBar.unsubscribe();
36
- this.titleBar.set(this.transformProps());
37
- };
38
- TitleBar.prototype.componentWillUnmount = function () {
39
- this.titleBar.unsubscribe();
40
- };
41
- TitleBar.prototype.render = function () {
42
- return null;
43
- };
44
- TitleBar.prototype.transformProps = function () {
45
- var app = this.context;
46
- var _a = this.props, title = _a.title, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, actionGroups = _a.actionGroups;
47
- return {
48
- title: title,
49
- buttons: (0, transformers_1.transformActions)(app, {
50
- primaryAction: primaryAction,
51
- secondaryActions: secondaryActions,
52
- actionGroups: actionGroups,
53
- }),
54
- breadcrumbs: this.transformBreadcrumbs(),
55
- };
56
- };
57
- TitleBar.prototype.transformBreadcrumbs = function () {
58
- var app = this.context;
59
- var breadcrumbs = this.props.breadcrumbs;
60
- if (breadcrumbs == null || breadcrumbs.length === 0) {
61
- return undefined;
62
- }
63
- var breadcrumb = breadcrumbs[breadcrumbs.length - 1];
64
- var url = breadcrumb.url, onAction = breadcrumb.onAction, target = breadcrumb.target, content = breadcrumb.content;
65
- var button = actions_1.Button.create(app, {
66
- label: content || '',
67
- });
68
- var redirect = (0, transformers_1.generateRedirect)(app, url, target);
69
- if (redirect != null) {
70
- button.subscribe(actions_1.Button.Action.CLICK, redirect);
7
+ var useAppBridge_1 = require("../../useAppBridge");
8
+ function TitleBar(props) {
9
+ var app = useAppBridge_1.useAppBridge();
10
+ var titleBar = react_1.useMemo(function () {
11
+ return TitleBar_1.create(app, transformProps(app, props));
12
+ }, [app]);
13
+ var currentProps = react_1.useRef(props);
14
+ react_1.useEffect(function () {
15
+ var propsChanged = JSON.stringify(currentProps.current) !== JSON.stringify(props);
16
+ if (propsChanged) {
17
+ currentProps.current = props;
71
18
  }
72
- if (onAction != null) {
73
- button.subscribe(actions_1.Button.Action.CLICK, onAction);
74
- }
75
- return button;
76
- };
77
- TitleBar.contextType = context_1.AppBridgeContext;
78
- return TitleBar;
79
- }(react_1.default.PureComponent));
19
+ titleBar.set(transformProps(app, props), propsChanged);
20
+ }, [titleBar, props]);
21
+ react_1.useEffect(function () {
22
+ return function () {
23
+ titleBar.unsubscribe();
24
+ };
25
+ }, [titleBar]);
26
+ return null;
27
+ }
80
28
  exports.default = TitleBar;
29
+ function transformProps(app, _a) {
30
+ var actionGroups = _a.actionGroups, breadcrumbs = _a.breadcrumbs, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, title = _a.title;
31
+ var breadcrumb = Array.isArray(breadcrumbs) ? breadcrumbs[breadcrumbs.length - 1] : breadcrumbs;
32
+ return {
33
+ title: title,
34
+ buttons: transformers_1.transformActions(app, {
35
+ primaryAction: primaryAction,
36
+ secondaryActions: secondaryActions,
37
+ actionGroups: actionGroups,
38
+ }),
39
+ breadcrumbs: breadcrumb ? transformBreadcrumb(app, breadcrumb) : undefined,
40
+ };
41
+ }
42
+ function transformBreadcrumb(app, breadcrumb) {
43
+ var url = breadcrumb.url, onAction = breadcrumb.onAction, target = breadcrumb.target, content = breadcrumb.content;
44
+ var button = Button_1.create(app, {
45
+ label: content || '',
46
+ });
47
+ var redirect = transformers_1.generateRedirect(app, url, target);
48
+ if (redirect) {
49
+ button.subscribe(Button_1.Action.CLICK, redirect);
50
+ }
51
+ if (onAction) {
52
+ button.subscribe(Button_1.Action.CLICK, onAction);
53
+ }
54
+ return button;
55
+ }
@@ -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,8 @@
1
1
  export { useContextualSaveBar } from './useContextualSaveBar';
2
+ export { useFeaturesAvailable } from './useFeaturesAvailable';
3
+ export { useFeatureRequest } from './useFeatureRequest';
4
+ export type { FeaturesAvailable } from './useFeaturesAvailable';
2
5
  export { useNavigationHistory } from './useNavigationHistory';
3
6
  export { useToast } from './useToast';
7
+ export { useAppBridgeState } from './useAppBridgeState';
8
+ export { useNavigate } from './useNavigate';
package/hooks/index.js CHANGED
@@ -1,9 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useToast = exports.useNavigationHistory = exports.useContextualSaveBar = void 0;
3
+ exports.useNavigate = exports.useAppBridgeState = exports.useToast = exports.useNavigationHistory = exports.useFeatureRequest = exports.useFeaturesAvailable = 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
+ 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; } });
6
10
  var useNavigationHistory_1 = require("./useNavigationHistory");
7
11
  Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
8
12
  var useToast_1 = require("./useToast");
9
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 {};