@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.
- package/CHANGELOG.md +44 -0
- package/components/ClientRouter/ClientRouter.js +1 -1
- package/components/ClientRouter/hook.js +3 -3
- package/components/ContextualSaveBar/ContextualSaveBar.js +5 -5
- package/components/Modal/Modal.js +1 -1
- package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
- package/components/NavigationMenu/NavigationMenu.js +55 -0
- package/components/NavigationMenu/index.d.ts +3 -0
- package/components/NavigationMenu/index.js +7 -0
- package/components/Provider/Provider.d.ts +58 -13
- package/components/Provider/Provider.js +24 -54
- package/components/ResourcePicker/ResourcePicker.d.ts +7 -16
- package/components/ResourcePicker/ResourcePicker.js +77 -94
- package/components/RoutePropagator/RoutePropagator.js +2 -2
- package/components/RoutePropagator/globals.d.ts +1 -1
- package/components/RoutePropagator/hook.js +3 -3
- package/components/RoutePropagator/route-propagator.js +5 -5
- package/components/TitleBar/TitleBar.d.ts +3 -14
- package/components/TitleBar/TitleBar.js +50 -75
- package/components/index.d.ts +4 -3
- package/components/index.js +10 -12
- package/context.d.ts +1 -1
- package/context.js +1 -1
- package/hooks/index.d.ts +5 -0
- package/hooks/index.js +9 -1
- package/hooks/useAppBridgeState/index.d.ts +1 -0
- package/hooks/useAppBridgeState/index.js +13 -0
- package/hooks/useAppBridgeState/useAppBridgeState.d.ts +10 -0
- package/hooks/useAppBridgeState/useAppBridgeState.js +89 -0
- package/hooks/useContextualSaveBar/useContextualSaveBar.js +6 -6
- package/hooks/useFeatureRequest/index.d.ts +1 -0
- package/hooks/useFeatureRequest/index.js +13 -0
- package/hooks/useFeatureRequest/useFeatureRequest.d.ts +13 -0
- package/hooks/useFeatureRequest/useFeatureRequest.js +49 -0
- package/hooks/useFeaturesAvailable/index.d.ts +2 -0
- package/hooks/useFeaturesAvailable/index.js +5 -0
- package/hooks/useFeaturesAvailable/useFeaturesAvailable.d.ts +12 -0
- package/hooks/useFeaturesAvailable/useFeaturesAvailable.js +101 -0
- package/hooks/useLocale/index.d.ts +1 -0
- package/hooks/useLocale/index.js +5 -0
- package/hooks/useLocale/useLocale.d.ts +1 -0
- package/hooks/useLocale/useLocale.js +8 -0
- package/hooks/useNavigate/index.d.ts +1 -0
- package/hooks/useNavigate/index.js +5 -0
- package/hooks/useNavigate/useNavigate.d.ts +24 -0
- package/hooks/useNavigate/useNavigate.js +109 -0
- package/hooks/useNavigationHistory/useNavigationHistory.js +2 -2
- package/hooks/useToast/useToast.js +4 -4
- package/index.d.ts +1 -0
- package/index.js +2 -5
- package/package.json +3 -3
- package/types.d.ts +2 -0
- package/types.js +3 -0
- package/umd/index.js +3 -3
- package/useAppBridge.js +1 -1
- package/utilities/transformers.d.ts +3 -2
- package/utilities/transformers.js +37 -20
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,50 @@
|
|
|
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.25](https://github.com/Shopify/app-bridge/compare/v2.0.24...v2.0.25) (2022-04-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **app-bridge-react:** prevent Resource Picker from sending unecessary updates ([62abe7f](https://github.com/Shopify/app-bridge/commit/62abe7f4116bf4c78934b8eb86e9a74fc0ea03d5))
|
|
12
|
+
* refactor useFeaturesAvailable to always return state ([2634016](https://github.com/Shopify/app-bridge/commit/2634016ccc9b883dd979c82585833b0fdf73d6d0))
|
|
13
|
+
* **app-bridge-react:** ensure useAppState only modifies the state when it has actually changed ([0a2f017](https://github.com/Shopify/app-bridge/commit/0a2f017c35e7d5dda8642eb68801d25158cb7539))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* Add optional router prop to Provider ([4d032b1](https://github.com/Shopify/app-bridge/commit/4d032b1e0cc940ab02a07339ed48cc23e21e26ae))
|
|
19
|
+
* **app-bridge-react:** add useFeatureRequest hook ([adc03c9](https://github.com/Shopify/app-bridge/commit/adc03c9c4d1b2b9e3a2ea44a9ed2eaf4b75b99bf))
|
|
20
|
+
* useFeature hook, refactor React playground ([e1b7c71](https://github.com/Shopify/app-bridge/commit/e1b7c71a4e3f3fb3a6b0373ea6aedc05a34baaea))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## [2.0.24](https://github.com/Shopify/app-bridge/compare/v2.0.23...v2.0.24) (2022-04-08)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Features
|
|
30
|
+
|
|
31
|
+
* **app-bridge-react:** add useNavigate hook ([ae818cb](https://github.com/Shopify/app-bridge/commit/ae818cb7b26e4f416bf9dfa9153940775bdf98df))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## [2.0.23](https://github.com/Shopify/app-bridge/compare/v2.0.22...v2.0.23) (2022-04-07)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* NavigationMenu component ([0205cb3](https://github.com/Shopify/app-bridge/commit/0205cb396d8b4ed679dd465348a6dc45227cedb9))
|
|
43
|
+
* **app-bridge-react:** add useAppBridgeState hook ([1fc64f1](https://github.com/Shopify/app-bridge/commit/1fc64f142cbd0a72adccb75fec36d31cde1ed552))
|
|
44
|
+
* **app-bridge-react:** add useLocale hook ([e17dbad](https://github.com/Shopify/app-bridge/commit/e17dbadedbded9d274744738821bef49e52eb43b))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
6
50
|
## [2.0.22](https://github.com/Shopify/app-bridge/compare/v2.0.21...v2.0.22) (2022-03-30)
|
|
7
51
|
|
|
8
52
|
|
|
@@ -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 =
|
|
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 =
|
|
16
|
-
|
|
17
|
-
return
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
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,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,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { DispatchActionHook } from '@shopify/app-bridge';
|
|
3
|
-
import {
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import type { AppConfigV2, DispatchActionHook } from '@shopify/app-bridge/client';
|
|
3
|
+
import type { History } from '../ClientRouter';
|
|
4
|
+
import type { LocationOrHref } from '../RoutePropagator';
|
|
4
5
|
/**
|
|
5
6
|
* Provider props
|
|
6
7
|
*
|
|
@@ -11,26 +12,70 @@ export interface Props {
|
|
|
11
12
|
config: AppConfigV2;
|
|
12
13
|
/** The child elements to render. */
|
|
13
14
|
children?: React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Option to set up client routing and route propagation automatically.
|
|
17
|
+
* Passing in a router will allow you to bypass setting these
|
|
18
|
+
* utilities up yourself.
|
|
19
|
+
*
|
|
20
|
+
* If you are using React Router, ensure that the Provider is a child
|
|
21
|
+
* of the router component. For example:
|
|
22
|
+
*
|
|
23
|
+
* import {useMemo} from 'react';
|
|
24
|
+
* import {useLocation, useNavigate, BrowserRouter} from 'react-router-dom';
|
|
25
|
+
* import {Provider} from '@shopify/app-bridge-react';
|
|
26
|
+
* import Routes from './Routes';
|
|
27
|
+
*
|
|
28
|
+
* export function App() {
|
|
29
|
+
* const navigate = useNavigate();
|
|
30
|
+
* const location = useLocation();
|
|
31
|
+
* const history = useMemo(
|
|
32
|
+
* () => ({replace: (path: string) => navigate(path, {replace: true})}),
|
|
33
|
+
* [navigate],
|
|
34
|
+
* );
|
|
35
|
+
* const router = useMemo(
|
|
36
|
+
* () => ({
|
|
37
|
+
* location,
|
|
38
|
+
* history,
|
|
39
|
+
* }),
|
|
40
|
+
* [location, navigate],
|
|
41
|
+
* );
|
|
42
|
+
* return (
|
|
43
|
+
* <Provider
|
|
44
|
+
* apiKey={{
|
|
45
|
+
* apiKey: 'API key from Shopify Partner Dashboard',
|
|
46
|
+
* host: host,
|
|
47
|
+
* }}
|
|
48
|
+
* router={router}
|
|
49
|
+
* >
|
|
50
|
+
* <Routes />
|
|
51
|
+
* </Provider>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* export default function AppWrapper() {
|
|
56
|
+
* return (
|
|
57
|
+
* <BrowserRouter>
|
|
58
|
+
* <App />
|
|
59
|
+
* </BrowserRouter>
|
|
60
|
+
* );
|
|
61
|
+
* }
|
|
62
|
+
*/
|
|
63
|
+
router?: {
|
|
64
|
+
location: LocationOrHref;
|
|
65
|
+
history: History;
|
|
66
|
+
};
|
|
14
67
|
}
|
|
15
68
|
/**
|
|
16
69
|
* Create an App Bridge client application from a config and pass it as the
|
|
17
70
|
* value to the context provider.
|
|
18
71
|
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* You'll probably want something a little more robust than storing the current
|
|
21
|
-
* app instance in a module-level global.
|
|
22
|
-
*
|
|
23
72
|
* @public
|
|
24
73
|
*/
|
|
25
|
-
declare
|
|
26
|
-
private app;
|
|
27
|
-
private get appInstance();
|
|
28
|
-
render(): JSX.Element;
|
|
29
|
-
}
|
|
30
|
-
export default Provider;
|
|
74
|
+
declare function Provider({ config, router, children }: PropsWithChildren<Props>): JSX.Element;
|
|
31
75
|
/**
|
|
32
76
|
* Augment actions with clientInterface metadata, identifying use of this library
|
|
33
77
|
*
|
|
34
78
|
* @internal
|
|
35
79
|
*/
|
|
36
80
|
export declare const setClientInterfaceHook: DispatchActionHook;
|
|
81
|
+
export default Provider;
|
|
@@ -1,26 +1,7 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
3
|
if (k2 === undefined) k2 = k;
|
|
19
|
-
|
|
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);
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
24
5
|
}) : (function(o, m, k, k2) {
|
|
25
6
|
if (k2 === undefined) k2 = k;
|
|
26
7
|
o[k2] = m[k];
|
|
@@ -37,52 +18,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
37
18
|
__setModuleDefault(result, mod);
|
|
38
19
|
return result;
|
|
39
20
|
};
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
22
|
exports.setClientInterfaceHook = void 0;
|
|
45
|
-
var react_1 =
|
|
23
|
+
var react_1 = __importStar(require("react"));
|
|
46
24
|
var app_bridge_1 = __importStar(require("@shopify/app-bridge"));
|
|
47
25
|
var context_1 = require("../../context");
|
|
26
|
+
var ClientRouter_1 = require("../ClientRouter");
|
|
27
|
+
var RoutePropagator_1 = require("../RoutePropagator");
|
|
48
28
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
49
29
|
var packageJson = require('../../package.json');
|
|
50
30
|
/**
|
|
51
31
|
* Create an App Bridge client application from a config and pass it as the
|
|
52
32
|
* value to the context provider.
|
|
53
33
|
*
|
|
54
|
-
* @remarks
|
|
55
|
-
* You'll probably want something a little more robust than storing the current
|
|
56
|
-
* app instance in a module-level global.
|
|
57
|
-
*
|
|
58
34
|
* @public
|
|
59
35
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return this.app;
|
|
76
|
-
},
|
|
77
|
-
enumerable: false,
|
|
78
|
-
configurable: true
|
|
79
|
-
});
|
|
80
|
-
Provider.prototype.render = function () {
|
|
81
|
-
return (react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: this.appInstance }, this.props.children));
|
|
82
|
-
};
|
|
83
|
-
return Provider;
|
|
84
|
-
}(react_1.default.Component));
|
|
85
|
-
exports.default = Provider;
|
|
36
|
+
function Provider(_a) {
|
|
37
|
+
var config = _a.config, router = _a.router, children = _a.children;
|
|
38
|
+
var app = react_1.useMemo(function () { return app_bridge_1.default(config); }, [JSON.stringify(config)]);
|
|
39
|
+
react_1.useEffect(function () {
|
|
40
|
+
if (app === null || app === void 0 ? void 0 : app.hooks) {
|
|
41
|
+
app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
|
|
42
|
+
}
|
|
43
|
+
}, [app]);
|
|
44
|
+
var routerMarkup = (router === null || router === void 0 ? void 0 : router.history) && (router === null || router === void 0 ? void 0 : router.location) ? (react_1.default.createElement(Router, { history: router.history, location: router.location })) : null;
|
|
45
|
+
return (react_1.default.createElement(context_1.AppBridgeContext.Provider, { value: app },
|
|
46
|
+
routerMarkup,
|
|
47
|
+
children));
|
|
48
|
+
}
|
|
86
49
|
/**
|
|
87
50
|
* Augment actions with clientInterface metadata, identifying use of this library
|
|
88
51
|
*
|
|
@@ -98,3 +61,10 @@ var setClientInterfaceHook = function (next) {
|
|
|
98
61
|
};
|
|
99
62
|
};
|
|
100
63
|
exports.setClientInterfaceHook = setClientInterfaceHook;
|
|
64
|
+
function Router(_a) {
|
|
65
|
+
var history = _a.history, location = _a.location;
|
|
66
|
+
ClientRouter_1.useClientRouting(history);
|
|
67
|
+
RoutePropagator_1.useRoutePropagation(location);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
exports.default = Provider;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { BaseResource } from '@shopify/app-bridge/actions/ResourcePicker';
|
|
1
|
+
import { ActionVerb, ResourceType } from '@shopify/app-bridge/actions/ResourcePicker';
|
|
2
|
+
import type { BaseResource, Options, ResourceSelection, ProductOptions } from '@shopify/app-bridge/actions/ResourcePicker';
|
|
4
3
|
export interface SelectPayload {
|
|
5
4
|
/** The selected resources
|
|
6
5
|
* @see {@link https://help.shopify.com/en/api/embedded-apps/app-bridge/actions/resourcepicker|resource picker documentation} for more information
|
|
7
6
|
*/
|
|
8
|
-
selection:
|
|
7
|
+
selection: ResourceSelection[];
|
|
9
8
|
}
|
|
10
9
|
interface BaseProps {
|
|
11
10
|
/** Whether the picker is open or not */
|
|
@@ -26,7 +25,7 @@ interface BaseProps {
|
|
|
26
25
|
/** Whether to allow selection of multiple items, or the maximum number of selected items */
|
|
27
26
|
selectMultiple?: boolean | number;
|
|
28
27
|
/** Override default action verb `Add`. The actionVerb appears in the title `<actionVerb>` `<resourceType>` and as the primary action of the resource picker. */
|
|
29
|
-
actionVerb?:
|
|
28
|
+
actionVerb?: ActionVerb;
|
|
30
29
|
/** Callback when a selection has been made */
|
|
31
30
|
onSelection?(selectPayload: SelectPayload): void;
|
|
32
31
|
/** Callback when the picker is closed without selection */
|
|
@@ -63,15 +62,7 @@ export declare type Props = ProductPickerProps | ProductVariantProps | Collectio
|
|
|
63
62
|
*
|
|
64
63
|
* @public
|
|
65
64
|
*/
|
|
66
|
-
declare
|
|
67
|
-
static contextType: React.Context<import("../../context").IAppBridgeContext>;
|
|
68
|
-
static ActionVerb: typeof AppBridgeResourcePicker.ActionVerb;
|
|
69
|
-
private focusReturnPoint;
|
|
70
|
-
private picker;
|
|
71
|
-
componentDidMount(): void;
|
|
72
|
-
componentDidUpdate(prevProps: Props): void;
|
|
73
|
-
componentWillUnmount(): void;
|
|
74
|
-
render(): null;
|
|
75
|
-
getActionOptions(): AppBridgeResourcePicker.Options | AppBridgeResourcePicker.ProductOptions;
|
|
76
|
-
}
|
|
65
|
+
declare function ResourcePicker(props: Props): null;
|
|
77
66
|
export default ResourcePicker;
|
|
67
|
+
export type { BaseResource, Options, ProductOptions };
|
|
68
|
+
export { ActionVerb, ResourceType };
|