@shopify/app-bridge-react 2.1.0 → 3.1.0
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 +51 -0
- package/README.md +90 -2
- package/components/ContextualSaveBar/ContextualSaveBar.d.ts +2 -2
- package/components/ContextualSaveBar/ContextualSaveBar.js +2 -2
- package/components/Provider/Provider.js +9 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +3 -1
- package/components/unstable_Picker/index.d.ts +3 -0
- package/components/unstable_Picker/index.js +7 -0
- package/components/unstable_Picker/unstable_Picker.d.ts +23 -0
- package/components/unstable_Picker/unstable_Picker.js +78 -0
- package/hooks/index.d.ts +4 -3
- package/hooks/index.js +7 -5
- package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +27 -9
- package/hooks/useContextualSaveBar/useContextualSaveBar.js +49 -43
- package/hooks/useToast/useToast.d.ts +1 -3
- package/hooks/useToast/useToast.js +14 -11
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +3 -3
- package/umd/index.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,57 @@
|
|
|
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
|
+
# [3.1.0](https://github.com/Shopify/app-bridge/compare/v3.0.1...v3.1.0) (2022-06-13)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fixed issue with host not being provided upon redirect of apps ([0fc846a](https://github.com/Shopify/app-bridge/commit/0fc846a91faf959ebcff11e089862c2d52d888d7))
|
|
12
|
+
* remove global unsubscribe from useContextualSaveBar ([3d315ed](https://github.com/Shopify/app-bridge/commit/3d315ed14cf2f210d2d6febd6fecd17326d71331))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* adding loadMore to picker ([c4488e2](https://github.com/Shopify/app-bridge/commit/c4488e2c7ba83b8eba1cacf7c918bd38fe01d537))
|
|
18
|
+
* adds a picker example for playgrounds ([4a65e36](https://github.com/Shopify/app-bridge/commit/4a65e360014d04539e56d249661225b92746cd86))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [3.0.1](https://github.com/Shopify/app-bridge/compare/v3.0.0...v3.0.1) (2022-06-02)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* add types for useRef ([9a421ac](https://github.com/Shopify/app-bridge/commit/9a421ac22ef03ce2d409d203e9498fc51b917ad9))
|
|
30
|
+
* rename Picker to unstable_Picker ([f82eab7](https://github.com/Shopify/app-bridge/commit/f82eab7629f64ae312847e0e49dd6d21f11aef8b))
|
|
31
|
+
* update missing picker ([7fefc00](https://github.com/Shopify/app-bridge/commit/7fefc00a0ec11fa21b8b83c9e5df8d2e8edb20e7))
|
|
32
|
+
* update preProps and args for useEffect ([c44ef10](https://github.com/Shopify/app-bridge/commit/c44ef102d4964f837dbbe434e1ea8e51fc211bd1))
|
|
33
|
+
* use default items for picker ([5cf5eae](https://github.com/Shopify/app-bridge/commit/5cf5eae18114a546586fe7534c27213fb7008d3d))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Features
|
|
37
|
+
|
|
38
|
+
* add input props ([d2ebb13](https://github.com/Shopify/app-bridge/commit/d2ebb130dfddee65d9d3ad7c39d716a219d29a9d))
|
|
39
|
+
* add Picker react component ([bea5429](https://github.com/Shopify/app-bridge/commit/bea542924e845f7b98ca76d1ff3b5b532121da27))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# [3.0.0](https://github.com/Shopify/app-bridge/compare/v2.1.0...v3.0.0) (2022-05-24)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* update useContextualSaveBar API ([4a5477f](https://github.com/Shopify/app-bridge/commit/4a5477f06f879b377bcc18e197205fbd3bc1b5d6))
|
|
51
|
+
* update useToast API to match UI Extensions pattern ([157363d](https://github.com/Shopify/app-bridge/commit/157363d1439acfc14cf5c44d452c1bbb3b9a2cf1))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
6
57
|
# [2.1.0](https://github.com/Shopify/app-bridge/compare/v2.0.30...v2.1.0) (2022-05-24)
|
|
7
58
|
|
|
8
59
|
**Note:** Version bump only for package @shopify/app-bridge-react
|
package/README.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# `@shopify/app-bridge-react`
|
|
2
2
|
|
|
3
|
-
**Shopify is doubling our engineering staff in 2021! [Join our team and work on libraries like this one.](https://smrtr.io/5GGrc)**
|
|
4
|
-
|
|
5
3
|
Shopify App Bridge offers React component wrappers for some App Bridge actions. This is a great option if you are already using React and want to follow familiar patterns.
|
|
6
4
|
|
|
7
5
|
Instead of using App Bridge actions directly:
|
|
@@ -74,6 +72,96 @@ function RedirectButton() {
|
|
|
74
72
|
}
|
|
75
73
|
```
|
|
76
74
|
|
|
75
|
+
## Migrating from 2.x.x to 3.0.0
|
|
76
|
+
|
|
77
|
+
There are two breaking API changes in version 3.0.0.
|
|
78
|
+
|
|
79
|
+
- `useContextualSaveBar`
|
|
80
|
+
- `useToast`
|
|
81
|
+
|
|
82
|
+
### useContextualSaveBar
|
|
83
|
+
|
|
84
|
+
In version 2.x.x, `useContextualSaveBar` was called with all of its options. It then created the contextual save bar and dispatched show and hide functions as an internal side effect based on the `visible` prop and any changes in options. It did not return anything.
|
|
85
|
+
|
|
86
|
+
#### Example code
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
useContextualSaveBar({
|
|
90
|
+
discardAction,
|
|
91
|
+
saveAction,
|
|
92
|
+
fullWidth,
|
|
93
|
+
leaveConfirmationDisable,
|
|
94
|
+
visible,
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
In version 3.0.0, `useContextualSaveBar` becomes more declarative. The hook is called without any props and it returns several objects and methods that can be used to update contextual save bar options, as well as to show and hide the component.
|
|
99
|
+
|
|
100
|
+
#### Example code
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
const {show, hide, saveAction, discardAction} = useContextualSaveBar();
|
|
104
|
+
const fullWidth = true;
|
|
105
|
+
const leaveConfirmationDisabled = false;
|
|
106
|
+
|
|
107
|
+
<Button
|
|
108
|
+
primary
|
|
109
|
+
onClick={() => {
|
|
110
|
+
show(fullWidth, leaveConfirmationDisabled);
|
|
111
|
+
discardAction.setOptions({onAction: () => console.log('On discard')});
|
|
112
|
+
saveAction.setOptions({onAction: () => console.log('On save')});
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
Show ContextualSaveBar
|
|
116
|
+
</Button>
|
|
117
|
+
<Button onClick={hide}>Hide ContextualSaveBar</Button>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
See [useContextualSaveBar docs](https://shopify.dev/apps/tools/app-bridge/react-components/contextual-save-bar) for more details.
|
|
121
|
+
|
|
122
|
+
### useToast
|
|
123
|
+
|
|
124
|
+
In version 2.x.x, `useToast` returns a `show` method that accepts one prop - an object with the following properties:
|
|
125
|
+
|
|
126
|
+
- `content`
|
|
127
|
+
- `duration`
|
|
128
|
+
- `isError`
|
|
129
|
+
- `onDismiss`
|
|
130
|
+
|
|
131
|
+
All the props except `content` are optional.
|
|
132
|
+
|
|
133
|
+
#### Example code
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
const {show} = useToast
|
|
137
|
+
|
|
138
|
+
show({
|
|
139
|
+
content: 'Success!,
|
|
140
|
+
duration: 2000,
|
|
141
|
+
isError: false,
|
|
142
|
+
onDismiss: () => console.log('Dismissed'),
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
In version 3.0.0, the `content` moves to a top-level prop and the remaining properties are passed in as an optional options prop (all properties in the options object remain optional).
|
|
147
|
+
`
|
|
148
|
+
|
|
149
|
+
#### Example code
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
const {show} = useToast;
|
|
153
|
+
|
|
154
|
+
show('Success!', {
|
|
155
|
+
duration: 2000,
|
|
156
|
+
isError: false,
|
|
157
|
+
onDismiss: () => console.log('Dismissed'),
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
See [useToast docs](https://shopify.dev/apps/tools/app-bridge/react-components/toast) for more details.
|
|
162
|
+
|
|
163
|
+
## Legacy support
|
|
164
|
+
|
|
77
165
|
If you are using App Bridge `v1.24.0` and below, or your project does not support React hooks, alternative methods on how to access `app` can be found in the [Provider docs](https://shopify.dev/tools/app-bridge/react-components/provider#accessing-the-app-bridge-client-directly).
|
|
78
166
|
|
|
79
167
|
See [Shopify Developers](https://shopify.dev/tools/app-bridge/react-components) for full documentation.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
|
|
2
2
|
export interface Props {
|
|
3
|
-
discardAction
|
|
3
|
+
discardAction?: DiscardAction & {
|
|
4
4
|
onAction(): void;
|
|
5
5
|
};
|
|
6
|
-
saveAction
|
|
6
|
+
saveAction?: ContextAction & {
|
|
7
7
|
onAction(): void;
|
|
8
8
|
};
|
|
9
9
|
fullWidth?: boolean;
|
|
@@ -16,7 +16,7 @@ var actions_1 = require("@shopify/app-bridge/actions");
|
|
|
16
16
|
var useAppBridge_1 = require("../../useAppBridge");
|
|
17
17
|
var Action = actions_1.ContextualSaveBar.Action, create = actions_1.ContextualSaveBar.create;
|
|
18
18
|
function ContextualSaveBar(_a) {
|
|
19
|
-
var
|
|
19
|
+
var _b = _a.discardAction, discardAction = _b === void 0 ? { onAction: function () { return null; } } : _b, _c = _a.saveAction, saveAction = _c === void 0 ? { onAction: function () { return null; } } : _c, fullWidth = _a.fullWidth, leaveConfirmationDisable = _a.leaveConfirmationDisable, visible = _a.visible;
|
|
20
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"]);
|
|
@@ -50,7 +50,7 @@ function ContextualSaveBar(_a) {
|
|
|
50
50
|
return function () {
|
|
51
51
|
contextualSaveBar.unsubscribe();
|
|
52
52
|
};
|
|
53
|
-
}, [contextualSaveBar]);
|
|
53
|
+
}, [contextualSaveBar, onDiscardAction, onSaveAction]);
|
|
54
54
|
react_1.useEffect(function () {
|
|
55
55
|
if (visible) {
|
|
56
56
|
contextualSaveBar.dispatch(Action.SHOW);
|
|
@@ -35,7 +35,15 @@ var packageJson = require('../../package.json');
|
|
|
35
35
|
*/
|
|
36
36
|
function Provider(_a) {
|
|
37
37
|
var config = _a.config, router = _a.router, children = _a.children;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* We are intentionally ignoring the `config` prop here as it yields a
|
|
40
|
+
* bug on apps build with Next.js which loses the `host` query param
|
|
41
|
+
* upon redirect.
|
|
42
|
+
*
|
|
43
|
+
* This was the behavior of the original `Provider` component prior to
|
|
44
|
+
* the refactor in version 2.0.25.
|
|
45
|
+
*/
|
|
46
|
+
var app = react_1.useMemo(function () { return app_bridge_1.default(config); }, []);
|
|
39
47
|
react_1.useEffect(function () {
|
|
40
48
|
if (app === null || app === void 0 ? void 0 : app.hooks) {
|
|
41
49
|
app.hooks.set(app_bridge_1.LifecycleHook.DispatchAction, exports.setClientInterfaceHook);
|
package/components/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export { default as Provider, Props as ProviderProps } from './Provider';
|
|
|
6
6
|
export { default as ResourcePicker, Props as ResourcePickerProps } from './ResourcePicker';
|
|
7
7
|
export { default as TitleBar } from './TitleBar';
|
|
8
8
|
export { default as Toast, Props as ToastProps } from './Toast';
|
|
9
|
+
export { default as unstable_Picker } from './unstable_Picker';
|
|
9
10
|
export * from './RoutePropagator';
|
|
10
11
|
export * from './ClientRouter';
|
package/components/index.js
CHANGED
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
|
|
16
|
+
exports.unstable_Picker = exports.Toast = exports.TitleBar = exports.ResourcePicker = exports.Provider = exports.NavigationMenu = exports.ModalContent = exports.Modal = exports.Loading = exports.ContextualSaveBar = void 0;
|
|
17
17
|
var ContextualSaveBar_1 = require("./ContextualSaveBar");
|
|
18
18
|
Object.defineProperty(exports, "ContextualSaveBar", { enumerable: true, get: function () { return __importDefault(ContextualSaveBar_1).default; } });
|
|
19
19
|
var Loading_1 = require("./Loading");
|
|
@@ -31,5 +31,7 @@ var TitleBar_1 = require("./TitleBar");
|
|
|
31
31
|
Object.defineProperty(exports, "TitleBar", { enumerable: true, get: function () { return __importDefault(TitleBar_1).default; } });
|
|
32
32
|
var Toast_1 = require("./Toast");
|
|
33
33
|
Object.defineProperty(exports, "Toast", { enumerable: true, get: function () { return __importDefault(Toast_1).default; } });
|
|
34
|
+
var unstable_Picker_1 = require("./unstable_Picker");
|
|
35
|
+
Object.defineProperty(exports, "unstable_Picker", { enumerable: true, get: function () { return __importDefault(unstable_Picker_1).default; } });
|
|
34
36
|
__exportStar(require("./RoutePropagator"), exports);
|
|
35
37
|
__exportStar(require("./ClientRouter"), exports);
|
|
@@ -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 unstable_Picker_1 = __importDefault(require("./unstable_Picker"));
|
|
7
|
+
exports.default = unstable_Picker_1.default;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SearchPayload, SelectPayload, EmptySearchLabel } from '@shopify/app-bridge/actions/Picker';
|
|
2
|
+
import type { BaseResource } from '@shopify/app-bridge/actions/Picker';
|
|
3
|
+
/**
|
|
4
|
+
* @unstable This API may be updated without warning in the future
|
|
5
|
+
*/
|
|
6
|
+
export interface Props {
|
|
7
|
+
open: boolean;
|
|
8
|
+
items: BaseResource[];
|
|
9
|
+
selectedItems?: BaseResource[];
|
|
10
|
+
maxSelectable?: number;
|
|
11
|
+
title?: string;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
searchQueryPlaceholder?: string;
|
|
14
|
+
searchQuery?: string;
|
|
15
|
+
primaryActionLabel?: string;
|
|
16
|
+
secondaryActionLabel?: string;
|
|
17
|
+
emptySearchLabel?: EmptySearchLabel;
|
|
18
|
+
onCancel?(): void;
|
|
19
|
+
onSelect?(selectPayload: SelectPayload): void;
|
|
20
|
+
onSearch?(searchPayload: SearchPayload): void;
|
|
21
|
+
onLoadMore?(): void;
|
|
22
|
+
}
|
|
23
|
+
export default function Picker(props: Props): null;
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
var react_1 = require("react");
|
|
15
|
+
var Picker_1 = require("@shopify/app-bridge/actions/Picker");
|
|
16
|
+
var useAppBridge_1 = require("../../useAppBridge");
|
|
17
|
+
function Picker(props) {
|
|
18
|
+
var app = useAppBridge_1.useAppBridge();
|
|
19
|
+
var prevProps = react_1.useRef({ open: false });
|
|
20
|
+
var picker = react_1.useMemo(function () { return Picker_1.create(app, getActionOptions(props)); }, [app]);
|
|
21
|
+
react_1.useEffect(function () {
|
|
22
|
+
var _a;
|
|
23
|
+
if (!props.open && ((_a = prevProps.current) === null || _a === void 0 ? void 0 : _a.open) === props.open) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (props.open) {
|
|
27
|
+
picker.dispatch(Picker_1.Action.OPEN);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
picker.dispatch(Picker_1.Action.CANCEL);
|
|
31
|
+
}
|
|
32
|
+
}, [props.open]);
|
|
33
|
+
react_1.useEffect(function () {
|
|
34
|
+
var unsubscribeList = [];
|
|
35
|
+
if (props.onSelect) {
|
|
36
|
+
unsubscribeList.push(picker.subscribe(Picker_1.Action.SELECT, props.onSelect));
|
|
37
|
+
}
|
|
38
|
+
if (props.onCancel) {
|
|
39
|
+
unsubscribeList.push(picker.subscribe(Picker_1.Action.CANCEL, props.onCancel));
|
|
40
|
+
}
|
|
41
|
+
if (props.onSearch) {
|
|
42
|
+
unsubscribeList.push(picker.subscribe(Picker_1.Action.SEARCH, props.onSearch));
|
|
43
|
+
}
|
|
44
|
+
if (props.onLoadMore) {
|
|
45
|
+
unsubscribeList.push(picker.subscribe(Picker_1.Action.LOAD_MORE, props.onLoadMore));
|
|
46
|
+
}
|
|
47
|
+
return function () {
|
|
48
|
+
unsubscribeList.forEach(function (unsubscribe) { return unsubscribe(); });
|
|
49
|
+
};
|
|
50
|
+
}, [props.onSelect, props.onCancel, props.onSearch]);
|
|
51
|
+
react_1.useEffect(function () {
|
|
52
|
+
var shouldUpdate = JSON.stringify(__assign(__assign({}, prevProps.current), { open: undefined })) !==
|
|
53
|
+
JSON.stringify(__assign(__assign({}, props), { open: undefined }));
|
|
54
|
+
if (!shouldUpdate) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
picker.set(getActionOptions(props));
|
|
58
|
+
prevProps.current = props;
|
|
59
|
+
}, [props]);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
exports.default = Picker;
|
|
63
|
+
function getActionOptions(_a) {
|
|
64
|
+
var items = _a.items, selectedItems = _a.selectedItems, maxSelectable = _a.maxSelectable, title = _a.title, loading = _a.loading, searchQueryPlaceholder = _a.searchQueryPlaceholder, searchQuery = _a.searchQuery, primaryActionLabel = _a.primaryActionLabel, secondaryActionLabel = _a.secondaryActionLabel, emptySearchLabel = _a.emptySearchLabel;
|
|
65
|
+
var result = {
|
|
66
|
+
items: items,
|
|
67
|
+
selectedItems: selectedItems,
|
|
68
|
+
maxSelectable: maxSelectable,
|
|
69
|
+
title: title,
|
|
70
|
+
loading: loading,
|
|
71
|
+
searchQueryPlaceholder: searchQueryPlaceholder,
|
|
72
|
+
searchQuery: searchQuery,
|
|
73
|
+
primaryActionLabel: primaryActionLabel,
|
|
74
|
+
secondaryActionLabel: secondaryActionLabel,
|
|
75
|
+
emptySearchLabel: emptySearchLabel,
|
|
76
|
+
};
|
|
77
|
+
return result;
|
|
78
|
+
}
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
export { useAppBridgeState } from './useAppBridgeState';
|
|
1
2
|
export { useContextualSaveBar } from './useContextualSaveBar';
|
|
2
3
|
export { useFeaturesAvailable } from './useFeaturesAvailable';
|
|
3
|
-
export { useFeatureRequest } from './useFeatureRequest';
|
|
4
4
|
export type { FeaturesAvailable } from './useFeaturesAvailable';
|
|
5
|
+
export { useFeatureRequest } from './useFeatureRequest';
|
|
6
|
+
export { useLocale } from './useLocale';
|
|
7
|
+
export { useNavigate } from './useNavigate';
|
|
5
8
|
export { useNavigationHistory } from './useNavigationHistory';
|
|
6
9
|
export { useToast } from './useToast';
|
|
7
|
-
export { useAppBridgeState } from './useAppBridgeState';
|
|
8
|
-
export { useNavigate } from './useNavigate';
|
package/hooks/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.useToast = exports.useNavigationHistory = exports.useNavigate = exports.useLocale = exports.useFeatureRequest = exports.useFeaturesAvailable = exports.useContextualSaveBar = exports.useAppBridgeState = void 0;
|
|
4
|
+
var useAppBridgeState_1 = require("./useAppBridgeState");
|
|
5
|
+
Object.defineProperty(exports, "useAppBridgeState", { enumerable: true, get: function () { return useAppBridgeState_1.useAppBridgeState; } });
|
|
4
6
|
var useContextualSaveBar_1 = require("./useContextualSaveBar");
|
|
5
7
|
Object.defineProperty(exports, "useContextualSaveBar", { enumerable: true, get: function () { return useContextualSaveBar_1.useContextualSaveBar; } });
|
|
6
8
|
var useFeaturesAvailable_1 = require("./useFeaturesAvailable");
|
|
7
9
|
Object.defineProperty(exports, "useFeaturesAvailable", { enumerable: true, get: function () { return useFeaturesAvailable_1.useFeaturesAvailable; } });
|
|
8
10
|
var useFeatureRequest_1 = require("./useFeatureRequest");
|
|
9
11
|
Object.defineProperty(exports, "useFeatureRequest", { enumerable: true, get: function () { return useFeatureRequest_1.useFeatureRequest; } });
|
|
12
|
+
var useLocale_1 = require("./useLocale");
|
|
13
|
+
Object.defineProperty(exports, "useLocale", { enumerable: true, get: function () { return useLocale_1.useLocale; } });
|
|
14
|
+
var useNavigate_1 = require("./useNavigate");
|
|
15
|
+
Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return useNavigate_1.useNavigate; } });
|
|
10
16
|
var useNavigationHistory_1 = require("./useNavigationHistory");
|
|
11
17
|
Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
|
|
12
18
|
var useToast_1 = require("./useToast");
|
|
13
19
|
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; } });
|
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import type { ContextAction, DiscardAction } from '@shopify/app-bridge/actions/ContextualSaveBar';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
interface ShowOptions {
|
|
3
|
+
fullWidth?: boolean;
|
|
4
|
+
leaveConfirmationDisabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
interface SaveActionOptions extends ContextAction {
|
|
7
|
+
onAction?: () => void;
|
|
8
|
+
}
|
|
9
|
+
interface DiscardActionOptions extends DiscardAction {
|
|
10
|
+
onAction?: () => void;
|
|
11
|
+
}
|
|
12
|
+
interface ContextualSaveBarHook {
|
|
13
|
+
show: ({ fullWidth, leaveConfirmationDisabled }?: ShowOptions) => void;
|
|
14
|
+
hide: () => void;
|
|
15
|
+
saveAction: {
|
|
16
|
+
setOptions: (options: Partial<SaveActionOptions>) => void;
|
|
5
17
|
};
|
|
6
|
-
|
|
7
|
-
|
|
18
|
+
discardAction: {
|
|
19
|
+
setOptions: (options: Partial<DiscardActionOptions>) => void;
|
|
8
20
|
};
|
|
9
|
-
fullWidth?: boolean;
|
|
10
|
-
leaveConfirmationDisable?: boolean;
|
|
11
|
-
visible?: boolean;
|
|
12
21
|
}
|
|
13
|
-
|
|
22
|
+
/**
|
|
23
|
+
* useContextualSaveBar hook
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* React hook which wraps the Shopify App Bridge ContextualSaveBar action.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare function useContextualSaveBar(): ContextualSaveBarHook;
|
|
31
|
+
export {};
|
|
@@ -15,54 +15,60 @@ exports.useContextualSaveBar = void 0;
|
|
|
15
15
|
var react_1 = require("react");
|
|
16
16
|
var ContextualSaveBar_1 = require("@shopify/app-bridge/actions/ContextualSaveBar");
|
|
17
17
|
var useAppBridge_1 = require("../../useAppBridge");
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* useContextualSaveBar hook
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* React hook which wraps the Shopify App Bridge ContextualSaveBar action.
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
function useContextualSaveBar() {
|
|
20
27
|
var app = useAppBridge_1.useAppBridge();
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
/* We want to reuse the same ContextualSaveBar instance, even when props change
|
|
24
|
-
* (so we don't include all the props in the dependency array).
|
|
25
|
-
* Instead of recreating the component on every change, we use the set method,
|
|
26
|
-
* in the useEffect block below, to dispatch updates when props change.
|
|
27
|
-
*/
|
|
28
|
+
var _a = react_1.useState(), onSaveAction = _a[0], setOnSaveAction = _a[1];
|
|
29
|
+
var _b = react_1.useState(), onDiscardAction = _b[0], setOnDiscardAction = _b[1];
|
|
28
30
|
var contextualSaveBar = react_1.useMemo(function () {
|
|
29
|
-
return ContextualSaveBar_1.create(app
|
|
30
|
-
saveAction: saveActionProps,
|
|
31
|
-
discardAction: discardActionProps,
|
|
32
|
-
fullWidth: fullWidth,
|
|
33
|
-
leaveConfirmationDisable: leaveConfirmationDisable,
|
|
34
|
-
});
|
|
31
|
+
return ContextualSaveBar_1.create(app);
|
|
35
32
|
}, [app]);
|
|
36
|
-
react_1.
|
|
37
|
-
contextualSaveBar.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
contextualSaveBar,
|
|
45
|
-
saveActionProps,
|
|
46
|
-
discardActionProps,
|
|
47
|
-
fullWidth,
|
|
48
|
-
leaveConfirmationDisable,
|
|
49
|
-
visible,
|
|
50
|
-
]);
|
|
51
|
-
react_1.useEffect(function () {
|
|
52
|
-
contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, onDiscardAction);
|
|
53
|
-
contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, onSaveAction);
|
|
54
|
-
return function () {
|
|
55
|
-
contextualSaveBar.unsubscribe();
|
|
56
|
-
};
|
|
33
|
+
var show = react_1.useCallback(function (options) {
|
|
34
|
+
contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
|
|
35
|
+
if (options) {
|
|
36
|
+
contextualSaveBar.set(options);
|
|
37
|
+
}
|
|
38
|
+
}, [contextualSaveBar]);
|
|
39
|
+
var hide = react_1.useCallback(function () {
|
|
40
|
+
contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
|
|
57
41
|
}, [contextualSaveBar]);
|
|
42
|
+
var saveAction = react_1.useMemo(function () { return ({
|
|
43
|
+
setOptions: function (_a) {
|
|
44
|
+
var onAction = _a.onAction, saveAction = __rest(_a, ["onAction"]);
|
|
45
|
+
setOnSaveAction(function () { return onAction; });
|
|
46
|
+
if (Object.keys(saveAction).length) {
|
|
47
|
+
contextualSaveBar.set({ saveAction: saveAction });
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
}); }, [contextualSaveBar]);
|
|
51
|
+
var discardAction = react_1.useMemo(function () { return ({
|
|
52
|
+
setOptions: function (_a) {
|
|
53
|
+
var onAction = _a.onAction, discardAction = __rest(_a, ["onAction"]);
|
|
54
|
+
setOnDiscardAction(function () { return onAction; });
|
|
55
|
+
if (Object.keys(discardAction).length) {
|
|
56
|
+
contextualSaveBar.set({ discardAction: discardAction });
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
}); }, [contextualSaveBar]);
|
|
58
60
|
react_1.useEffect(function () {
|
|
59
|
-
|
|
60
|
-
contextualSaveBar.dispatch(ContextualSaveBar_1.Action.SHOW);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
61
|
+
return contextualSaveBar.subscribe(ContextualSaveBar_1.Action.DISCARD, function () {
|
|
63
62
|
contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
onDiscardAction === null || onDiscardAction === void 0 ? void 0 : onDiscardAction();
|
|
64
|
+
});
|
|
65
|
+
}, [contextualSaveBar, onDiscardAction]);
|
|
66
|
+
react_1.useEffect(function () {
|
|
67
|
+
return contextualSaveBar.subscribe(ContextualSaveBar_1.Action.SAVE, function () {
|
|
68
|
+
contextualSaveBar.dispatch(ContextualSaveBar_1.Action.HIDE);
|
|
69
|
+
onSaveAction === null || onSaveAction === void 0 ? void 0 : onSaveAction();
|
|
70
|
+
});
|
|
71
|
+
}, [contextualSaveBar, onSaveAction]);
|
|
72
|
+
return { show: show, hide: hide, saveAction: saveAction, discardAction: discardAction };
|
|
67
73
|
}
|
|
68
74
|
exports.useContextualSaveBar = useContextualSaveBar;
|
|
@@ -9,7 +9,5 @@ export declare const DEFAULT_TOAST_DURATION = 5000;
|
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
export declare function useToast(): {
|
|
12
|
-
show: (
|
|
13
|
-
content: string;
|
|
14
|
-
}) => void;
|
|
12
|
+
show: (content: string, options?: Partial<Omit<Payload, "message">> | undefined) => void;
|
|
15
13
|
};
|
|
@@ -15,22 +15,25 @@ exports.DEFAULT_TOAST_DURATION = 5000;
|
|
|
15
15
|
*/
|
|
16
16
|
function useToast() {
|
|
17
17
|
var app = useAppBridge_1.useAppBridge();
|
|
18
|
-
var
|
|
19
|
-
var show = react_1.useCallback(function (
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
duration: duration,
|
|
18
|
+
var toastList = react_1.useRef([]);
|
|
19
|
+
var show = react_1.useCallback(function (content, options) {
|
|
20
|
+
var toast = Toast_1.create(app, {
|
|
21
|
+
message: content,
|
|
22
|
+
isError: options === null || options === void 0 ? void 0 : options.isError,
|
|
23
|
+
duration: (options === null || options === void 0 ? void 0 : options.duration) || exports.DEFAULT_TOAST_DURATION,
|
|
25
24
|
});
|
|
26
25
|
toast.dispatch(Toast_1.Action.SHOW);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
toastList.current.push(toast);
|
|
27
|
+
toast.subscribe(Toast_1.Action.CLEAR, function () {
|
|
28
|
+
var _a;
|
|
29
|
+
(_a = options === null || options === void 0 ? void 0 : options.onDismiss) === null || _a === void 0 ? void 0 : _a.call(options);
|
|
30
|
+
toastList.current.splice(toastList.current.indexOf(toast), 1);
|
|
31
|
+
toast.unsubscribe();
|
|
32
|
+
});
|
|
30
33
|
}, [app]);
|
|
31
34
|
react_1.useEffect(function () {
|
|
32
35
|
return function () {
|
|
33
|
-
toast.unsubscribe();
|
|
36
|
+
toastList.current.forEach(function (toast) { return toast === null || toast === void 0 ? void 0 : toast.unsubscribe(); });
|
|
34
37
|
};
|
|
35
38
|
}, []);
|
|
36
39
|
return { show: show };
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -11,9 +11,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.useAppBridge = exports.Context = void 0;
|
|
14
|
-
__exportStar(require("./components"), exports);
|
|
15
14
|
var context_1 = require("./context");
|
|
16
15
|
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
|
|
17
16
|
var useAppBridge_1 = require("./useAppBridge");
|
|
18
17
|
Object.defineProperty(exports, "useAppBridge", { enumerable: true, get: function () { return useAppBridge_1.useAppBridge; } });
|
|
18
|
+
__exportStar(require("./components"), exports);
|
|
19
19
|
__exportStar(require("./hooks"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/app-bridge-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
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": "^
|
|
48
|
+
"@shopify/app-bridge": "^3.1.0"
|
|
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 || ^18.0.0"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "96e96d4f031f7598c3561c808f4960faa0f9cfb2"
|
|
59
59
|
}
|