@shopify/app-bridge-react 2.0.21 → 2.0.24

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 (47) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/components/ClientRouter/ClientRouter.js +3 -1
  3. package/components/ClientRouter/index.js +6 -2
  4. package/components/ClientRouter/router.d.ts +1 -1
  5. package/components/Loading/Loading.js +3 -1
  6. package/components/Modal/Modal.js +4 -3
  7. package/components/Modal/ModalContent/ModalContent.js +3 -1
  8. package/components/Modal/index.js +2 -1
  9. package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
  10. package/components/NavigationMenu/NavigationMenu.js +55 -0
  11. package/components/NavigationMenu/index.d.ts +3 -0
  12. package/components/NavigationMenu/index.js +7 -0
  13. package/components/Provider/Provider.d.ts +1 -2
  14. package/components/Provider/Provider.js +6 -3
  15. package/components/ResourcePicker/ResourcePicker.js +3 -1
  16. package/components/RoutePropagator/RoutePropagator.js +3 -1
  17. package/components/RoutePropagator/index.js +6 -2
  18. package/components/RoutePropagator/route-propagator.d.ts +1 -1
  19. package/components/TitleBar/TitleBar.js +3 -1
  20. package/components/Toast/Toast.js +3 -1
  21. package/components/index.d.ts +4 -3
  22. package/components/index.js +17 -11
  23. package/context.d.ts +2 -2
  24. package/hooks/index.d.ts +2 -0
  25. package/hooks/index.js +5 -0
  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 +75 -0
  30. package/hooks/useContextualSaveBar/index.js +1 -0
  31. package/hooks/useLocale/index.d.ts +1 -0
  32. package/hooks/useLocale/index.js +5 -0
  33. package/hooks/useLocale/useLocale.d.ts +1 -0
  34. package/hooks/useLocale/useLocale.js +8 -0
  35. package/hooks/useNavigate/index.d.ts +1 -0
  36. package/hooks/useNavigate/index.js +5 -0
  37. package/hooks/useNavigate/useNavigate.d.ts +24 -0
  38. package/hooks/useNavigate/useNavigate.js +109 -0
  39. package/hooks/useNavigationHistory/index.js +1 -0
  40. package/hooks/useToast/index.js +1 -0
  41. package/index.d.ts +1 -0
  42. package/index.js +3 -1
  43. package/package.json +3 -3
  44. package/umd/index.js +3 -3
  45. package/useAppBridge.d.ts +1 -1
  46. package/utilities/transformers.d.ts +3 -3
  47. package/utilities/transformers.js +7 -9
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ Object.defineProperty(exports, "__esModule", { value: true });
33
+ exports.isAdminSection = exports.useNavigate = void 0;
34
+ var react_1 = require("react");
35
+ var Redirect = __importStar(require("@shopify/app-bridge/actions/Navigation/Redirect"));
36
+ var useAppBridge_1 = require("../../useAppBridge");
37
+ var useNavigationHistory_1 = require("../useNavigationHistory");
38
+ function useNavigate() {
39
+ var app = useAppBridge_1.useAppBridge();
40
+ var history = useNavigationHistory_1.useNavigationHistory();
41
+ var redirect = react_1.useMemo(function () {
42
+ return Redirect.create(app);
43
+ }, [app]);
44
+ var handleRedirect = react_1.useCallback(function (to, options) {
45
+ var url = normalizeUrl(to);
46
+ var isAppUrl = url.startsWith(app.localOrigin);
47
+ var isHostUrl = url.startsWith(app.hostOrigin);
48
+ var isRelative = url.startsWith('/');
49
+ if (isAppUrl || isHostUrl || isRelative) {
50
+ var path = getRelativePath(url);
51
+ if (isHostUrl || (options === null || options === void 0 ? void 0 : options.target) === 'new' || (options === null || options === void 0 ? void 0 : options.target) === 'host') {
52
+ redirect.dispatch(Redirect.Action.ADMIN_PATH, {
53
+ path: path.replace(/^\/admin/, ''),
54
+ newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new',
55
+ });
56
+ return;
57
+ }
58
+ if (((options === null || options === void 0 ? void 0 : options.target) === 'self' || !(options === null || options === void 0 ? void 0 : options.target)) && (options === null || options === void 0 ? void 0 : options.replace)) {
59
+ history.replace({ pathname: path });
60
+ return;
61
+ }
62
+ redirect.dispatch(Redirect.Action.APP, path);
63
+ return;
64
+ }
65
+ redirect.dispatch(Redirect.Action.REMOTE, {
66
+ url: url,
67
+ newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new',
68
+ });
69
+ }, [redirect, history]);
70
+ return react_1.useCallback(function (to, options) {
71
+ if (isAdminSection(to)) {
72
+ var convertedSection = __assign(__assign({}, to), { name: Redirect.ResourceType[to.name] });
73
+ redirect.dispatch(Redirect.Action.ADMIN_SECTION, {
74
+ section: convertedSection,
75
+ newContext: (options === null || options === void 0 ? void 0 : options.target) === 'new',
76
+ });
77
+ return;
78
+ }
79
+ handleRedirect(to, options);
80
+ }, [handleRedirect, redirect]);
81
+ }
82
+ exports.useNavigate = useNavigate;
83
+ function isAdminSection(to) {
84
+ return typeof to === 'object' && typeof (to === null || to === void 0 ? void 0 : to.name) === 'string';
85
+ }
86
+ exports.isAdminSection = isAdminSection;
87
+ function getPathWithSearchAndHash(_a) {
88
+ var pathname = _a.pathname, search = _a.search, hash = _a.hash;
89
+ return "" + pathname + (search || '') + (hash || '');
90
+ }
91
+ function normalizeUrl(to) {
92
+ if (to instanceof URL) {
93
+ return to.toString();
94
+ }
95
+ if (typeof to === 'string') {
96
+ return to;
97
+ }
98
+ return getRelativePath(to);
99
+ }
100
+ function getRelativePath(to) {
101
+ if (typeof to === 'string') {
102
+ if (to.startsWith('/')) {
103
+ return to;
104
+ }
105
+ return getPathWithSearchAndHash(new URL(to));
106
+ }
107
+ var search = to.search instanceof URLSearchParams ? to.search.toString() : to.search;
108
+ return getPathWithSearchAndHash(__assign(__assign({}, to), { search: search }));
109
+ }
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useNavigationHistory = void 0;
3
4
  var useNavigationHistory_1 = require("./useNavigationHistory");
4
5
  Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useToast = void 0;
3
4
  var useToast_1 = require("./useToast");
4
5
  Object.defineProperty(exports, "useToast", { enumerable: true, get: function () { return useToast_1.useToast; } });
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
@@ -7,11 +7,13 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
7
7
  o[k2] = m[k];
8
8
  }));
9
9
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.useAppBridge = exports.Context = void 0;
13
14
  __exportStar(require("./components"), exports);
14
15
  var context_1 = require("./context");
15
16
  Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
16
17
  var useAppBridge_1 = require("./useAppBridge");
17
18
  Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
19
+ __exportStar(require("./hooks"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopify/app-bridge-react",
3
- "version": "2.0.21",
3
+ "version": "2.0.24",
4
4
  "types": "index.d.ts",
5
5
  "main": "index.js",
6
6
  "unpkg": "umd/index.js",
@@ -45,7 +45,7 @@
45
45
  }
46
46
  ],
47
47
  "dependencies": {
48
- "@shopify/app-bridge": "^2.0.21"
48
+ "@shopify/app-bridge": "^2.0.24"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/react": "^17.0.38",
@@ -55,5 +55,5 @@
55
55
  "peerDependencies": {
56
56
  "react": "^16.0.0 || ^17.0.0"
57
57
  },
58
- "gitHead": "343a8216ef007c80076142c5da308f012ab15d37"
58
+ "gitHead": "0c3aa24d39c86120c8823bd43f439cda0ab7df5e"
59
59
  }