@shopify/app-bridge-react 2.1.1-alpha.0 → 2.1.1-alpha.1
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 +8 -0
- package/components/ClientRouter/ClientRouter.d.ts +21 -0
- package/components/ClientRouter/ClientRouter.js +52 -0
- package/components/ClientRouter/hook.d.ts +10 -0
- package/components/ClientRouter/hook.js +20 -0
- package/components/ClientRouter/index.d.ts +3 -0
- package/components/ClientRouter/index.js +10 -0
- package/components/ClientRouter/router.d.ts +5 -0
- package/components/ClientRouter/router.js +11 -0
- package/components/ContextualSaveBar/ContextualSaveBar.d.ts +13 -0
- package/components/ContextualSaveBar/ContextualSaveBar.js +64 -0
- package/components/ContextualSaveBar/index.d.ts +3 -0
- package/components/ContextualSaveBar/index.js +7 -0
- package/components/Loading/Loading.d.ts +17 -0
- package/components/Loading/Loading.js +55 -0
- package/components/Loading/index.d.ts +2 -0
- package/components/Loading/index.js +7 -0
- package/components/Modal/Modal.d.ts +32 -0
- package/components/Modal/Modal.js +139 -0
- package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
- package/components/Modal/ModalContent/ModalContent.js +61 -0
- package/components/Modal/ModalContent/index.d.ts +2 -0
- package/components/Modal/ModalContent/index.js +7 -0
- package/components/Modal/index.d.ts +4 -0
- package/components/Modal/index.js +10 -0
- package/components/NavigationMenu/NavigationMenu.d.ts +17 -0
- package/components/NavigationMenu/NavigationMenu.js +40 -0
- package/components/NavigationMenu/index.d.ts +3 -0
- package/components/NavigationMenu/index.js +7 -0
- package/components/Provider/Provider.d.ts +81 -0
- package/components/Provider/Provider.js +70 -0
- package/components/Provider/index.d.ts +3 -0
- package/components/Provider/index.js +7 -0
- package/components/ResourcePicker/ResourcePicker.d.ts +68 -0
- package/components/ResourcePicker/ResourcePicker.js +114 -0
- package/components/ResourcePicker/index.d.ts +3 -0
- package/components/ResourcePicker/index.js +7 -0
- package/components/RoutePropagator/RoutePropagator.d.ts +20 -0
- package/components/RoutePropagator/RoutePropagator.js +54 -0
- package/components/RoutePropagator/globals.d.ts +3 -0
- package/components/RoutePropagator/globals.js +15 -0
- package/components/RoutePropagator/hook.d.ts +10 -0
- package/components/RoutePropagator/hook.js +20 -0
- package/components/RoutePropagator/index.d.ts +3 -0
- package/components/RoutePropagator/index.js +10 -0
- package/components/RoutePropagator/route-propagator.d.ts +7 -0
- package/components/RoutePropagator/route-propagator.js +91 -0
- package/components/TitleBar/TitleBar.d.ts +27 -0
- package/components/TitleBar/TitleBar.js +108 -0
- package/components/TitleBar/index.d.ts +3 -0
- package/components/TitleBar/index.js +7 -0
- package/components/Toast/Toast.d.ts +31 -0
- package/components/Toast/Toast.js +59 -0
- package/components/Toast/index.d.ts +3 -0
- package/components/Toast/index.js +7 -0
- package/components/index.d.ts +10 -0
- package/components/index.js +35 -0
- package/context.d.ts +13 -0
- package/context.js +10 -0
- package/hooks/index.d.ts +8 -0
- package/hooks/index.js +17 -0
- 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/index.d.ts +1 -0
- package/hooks/useContextualSaveBar/index.js +5 -0
- package/hooks/useContextualSaveBar/useContextualSaveBar.d.ts +13 -0
- package/hooks/useContextualSaveBar/useContextualSaveBar.js +68 -0
- 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/index.d.ts +1 -0
- package/hooks/useNavigationHistory/index.js +5 -0
- package/hooks/useNavigationHistory/useNavigationHistory.d.ts +16 -0
- package/hooks/useNavigationHistory/useNavigationHistory.js +28 -0
- package/hooks/useToast/index.d.ts +1 -0
- package/hooks/useToast/index.js +5 -0
- package/hooks/useToast/useToast.d.ts +15 -0
- package/hooks/useToast/useToast.js +38 -0
- package/index.d.ts +4 -0
- package/index.js +19 -0
- package/package.json +3 -3
- package/types.d.ts +35 -0
- package/types.js +5 -0
- package/umd/index.js +14 -0
- package/useAppBridge.d.ts +1 -0
- package/useAppBridge.js +13 -0
- package/utilities/transformers.d.ts +20 -0
- package/utilities/transformers.js +105 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFeaturesAvailable = void 0;
|
|
4
|
+
var useFeaturesAvailable_1 = require("./useFeaturesAvailable");
|
|
5
|
+
Object.defineProperty(exports, "useFeaturesAvailable", { enumerable: true, get: function () { return useFeaturesAvailable_1.useFeaturesAvailable; } });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Group } from '@shopify/app-bridge/actions/types';
|
|
2
|
+
import { AppBridgeState } from '@shopify/app-bridge/client';
|
|
3
|
+
export declare type FeaturesAvailable = AppBridgeState['features'];
|
|
4
|
+
/**
|
|
5
|
+
* useFeaturesAvailable hook
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* React hook that wraps the Shopify App Bridge getFeaturesAvailable method.
|
|
9
|
+
*
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
12
|
+
export declare function useFeaturesAvailable(...query: Group[]): import("@shopify/app-bridge/client").FeaturesAvailable<Group> | undefined;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.useFeaturesAvailable = void 0;
|
|
40
|
+
var react_1 = require("react");
|
|
41
|
+
var types_1 = require("@shopify/app-bridge/actions/Features/types");
|
|
42
|
+
var useAppBridge_1 = require("../../useAppBridge");
|
|
43
|
+
/**
|
|
44
|
+
* useFeaturesAvailable hook
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* React hook that wraps the Shopify App Bridge getFeaturesAvailable method.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
function useFeaturesAvailable() {
|
|
52
|
+
var _this = this;
|
|
53
|
+
var query = [];
|
|
54
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
55
|
+
query[_i] = arguments[_i];
|
|
56
|
+
}
|
|
57
|
+
var app = useAppBridge_1.useAppBridge();
|
|
58
|
+
var _a = react_1.useState(), state = _a[0], setState = _a[1];
|
|
59
|
+
var queryRef = react_1.useRef([]);
|
|
60
|
+
var refresh = react_1.useCallback(function () {
|
|
61
|
+
var isUnmounted = false;
|
|
62
|
+
(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var features;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, app.featuresAvailable.apply(app, queryRef.current)];
|
|
67
|
+
case 1:
|
|
68
|
+
features = _a.sent();
|
|
69
|
+
if (!isUnmounted) {
|
|
70
|
+
setState(function (currentFeatures) {
|
|
71
|
+
if (JSON.stringify(currentFeatures) === JSON.stringify(features)) {
|
|
72
|
+
return currentFeatures;
|
|
73
|
+
}
|
|
74
|
+
return features;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return [2 /*return*/];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}); })();
|
|
81
|
+
return function () {
|
|
82
|
+
isUnmounted = true;
|
|
83
|
+
};
|
|
84
|
+
}, [app]);
|
|
85
|
+
react_1.useEffect(function () {
|
|
86
|
+
queryRef.current = query;
|
|
87
|
+
return refresh();
|
|
88
|
+
}, [JSON.stringify(query)]);
|
|
89
|
+
react_1.useEffect(function () {
|
|
90
|
+
var onRefreshCleanup;
|
|
91
|
+
var unsubscribe = app.subscribe(types_1.Action.UPDATE, function () {
|
|
92
|
+
onRefreshCleanup = refresh();
|
|
93
|
+
});
|
|
94
|
+
return function () {
|
|
95
|
+
unsubscribe();
|
|
96
|
+
onRefreshCleanup === null || onRefreshCleanup === void 0 ? void 0 : onRefreshCleanup();
|
|
97
|
+
};
|
|
98
|
+
}, [app, refresh]);
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
exports.useFeaturesAvailable = useFeaturesAvailable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useLocale } from './useLocale';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocale = void 0;
|
|
4
|
+
var useLocale_1 = require("./useLocale");
|
|
5
|
+
Object.defineProperty(exports, "useLocale", { enumerable: true, get: function () { return useLocale_1.useLocale; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useLocale(): string | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocale = void 0;
|
|
4
|
+
var useAppBridgeState_1 = require("../useAppBridgeState");
|
|
5
|
+
function useLocale() {
|
|
6
|
+
return useAppBridgeState_1.useAppBridgeState('staffMember.locale');
|
|
7
|
+
}
|
|
8
|
+
exports.useLocale = useLocale;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useNavigate } from './useNavigate';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNavigate = void 0;
|
|
4
|
+
var useNavigate_1 = require("./useNavigate");
|
|
5
|
+
Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return useNavigate_1.useNavigate; } });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as Redirect from '@shopify/app-bridge/actions/Navigation/Redirect';
|
|
2
|
+
export interface Location {
|
|
3
|
+
pathname: string;
|
|
4
|
+
search?: string | URLSearchParams;
|
|
5
|
+
hash?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AppOptions {
|
|
8
|
+
replace?: boolean;
|
|
9
|
+
target?: 'self';
|
|
10
|
+
}
|
|
11
|
+
export interface HostOptions {
|
|
12
|
+
target: 'host' | 'new';
|
|
13
|
+
}
|
|
14
|
+
export declare type Options = AppOptions | HostOptions;
|
|
15
|
+
export declare type To = Location | URL | string;
|
|
16
|
+
export interface SectionStringName extends Omit<Redirect.Section, 'name'> {
|
|
17
|
+
name: keyof typeof Redirect.ResourceType;
|
|
18
|
+
}
|
|
19
|
+
export interface Navigate {
|
|
20
|
+
(to: To, options?: AppOptions): void;
|
|
21
|
+
(to: To | SectionStringName, options?: HostOptions): void;
|
|
22
|
+
}
|
|
23
|
+
export declare function useNavigate(): Navigate;
|
|
24
|
+
export declare function isAdminSection(to: any): to is SectionStringName;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useNavigationHistory } from './useNavigationHistory';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNavigationHistory = void 0;
|
|
4
|
+
var useNavigationHistory_1 = require("./useNavigationHistory");
|
|
5
|
+
Object.defineProperty(exports, "useNavigationHistory", { enumerable: true, get: function () { return useNavigationHistory_1.useNavigationHistory; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useNavigationHistory hook
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* React hook which wraps the Shopify App Bridge History action.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare function useNavigationHistory(): {
|
|
10
|
+
push: (location: {
|
|
11
|
+
pathname: string;
|
|
12
|
+
}) => void;
|
|
13
|
+
replace: (location: {
|
|
14
|
+
pathname: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNavigationHistory = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var actions_1 = require("@shopify/app-bridge/actions");
|
|
6
|
+
var useAppBridge_1 = require("../../useAppBridge");
|
|
7
|
+
/**
|
|
8
|
+
* useNavigationHistory hook
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* React hook which wraps the Shopify App Bridge History action.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
function useNavigationHistory() {
|
|
16
|
+
var app = useAppBridge_1.useAppBridge();
|
|
17
|
+
return react_1.useMemo(function () {
|
|
18
|
+
var history = actions_1.History.create(app);
|
|
19
|
+
function push(location) {
|
|
20
|
+
history.dispatch(actions_1.History.Action.PUSH, location.pathname);
|
|
21
|
+
}
|
|
22
|
+
function replace(location) {
|
|
23
|
+
history.dispatch(actions_1.History.Action.REPLACE, location.pathname);
|
|
24
|
+
}
|
|
25
|
+
return { push: push, replace: replace };
|
|
26
|
+
}, []);
|
|
27
|
+
}
|
|
28
|
+
exports.useNavigationHistory = useNavigationHistory;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useToast } from './useToast';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Payload } from '@shopify/app-bridge/actions/Toast';
|
|
2
|
+
export declare const DEFAULT_TOAST_DURATION = 5000;
|
|
3
|
+
/**
|
|
4
|
+
* useToast hook
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* React hook which wraps the Shopify App Bridge Toast action.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare function useToast(): {
|
|
12
|
+
show: ({ content: message, duration, isError, onDismiss, }: Omit<Payload, 'message'> & {
|
|
13
|
+
content: string;
|
|
14
|
+
}) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useToast = exports.DEFAULT_TOAST_DURATION = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
var Toast_1 = require("@shopify/app-bridge/actions/Toast");
|
|
6
|
+
var useAppBridge_1 = require("../../useAppBridge");
|
|
7
|
+
exports.DEFAULT_TOAST_DURATION = 5000;
|
|
8
|
+
/**
|
|
9
|
+
* useToast hook
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* React hook which wraps the Shopify App Bridge Toast action.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
function useToast() {
|
|
17
|
+
var app = useAppBridge_1.useAppBridge();
|
|
18
|
+
var toast;
|
|
19
|
+
var show = react_1.useCallback(function (_a) {
|
|
20
|
+
var message = _a.content, _b = _a.duration, duration = _b === void 0 ? exports.DEFAULT_TOAST_DURATION : _b, isError = _a.isError, onDismiss = _a.onDismiss;
|
|
21
|
+
toast = Toast_1.create(app, {
|
|
22
|
+
message: message,
|
|
23
|
+
isError: isError,
|
|
24
|
+
duration: duration,
|
|
25
|
+
});
|
|
26
|
+
toast.dispatch(Toast_1.Action.SHOW);
|
|
27
|
+
if (onDismiss) {
|
|
28
|
+
toast.subscribe(Toast_1.Action.CLEAR, onDismiss);
|
|
29
|
+
}
|
|
30
|
+
}, [app]);
|
|
31
|
+
react_1.useEffect(function () {
|
|
32
|
+
return function () {
|
|
33
|
+
toast.unsubscribe();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return { show: show };
|
|
37
|
+
}
|
|
38
|
+
exports.useToast = useToast;
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
exports.useAppBridge = exports.Context = void 0;
|
|
14
|
+
__exportStar(require("./components"), exports);
|
|
15
|
+
var context_1 = require("./context");
|
|
16
|
+
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.AppBridgeContext; } });
|
|
17
|
+
var useAppBridge_1 = require("./useAppBridge");
|
|
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.1.1-alpha.
|
|
3
|
+
"version": "2.1.1-alpha.1",
|
|
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.1.1-alpha.
|
|
48
|
+
"@shopify/app-bridge": "^2.1.1-alpha.1"
|
|
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": "6dd83d2fd64ef387e1902a14db27473525182f36"
|
|
59
59
|
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Redirect } from '@shopify/app-bridge/actions';
|
|
2
|
+
import { Group } from '@shopify/app-bridge/actions/types';
|
|
3
|
+
export declare type Target = Exclude<keyof typeof Redirect.Action, 'ADMIN_SECTION'>;
|
|
4
|
+
export interface ActionProps {
|
|
5
|
+
/** Content the action displays */
|
|
6
|
+
content?: string;
|
|
7
|
+
/** Should the action be styled as destructive */
|
|
8
|
+
destructive?: boolean;
|
|
9
|
+
/** Should the action be disabled */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Should the action be loading */
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
/** Forces url to open in a new tab */
|
|
14
|
+
external?: boolean;
|
|
15
|
+
/** Use Polaris plain styling */
|
|
16
|
+
plain?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Where to display the target link
|
|
19
|
+
* @default 'APP'
|
|
20
|
+
*/
|
|
21
|
+
target?: Target;
|
|
22
|
+
/** A destination to link to */
|
|
23
|
+
url?: string;
|
|
24
|
+
/** Callback when an action takes place */
|
|
25
|
+
onAction?(): void;
|
|
26
|
+
}
|
|
27
|
+
export interface ActionGroupProps {
|
|
28
|
+
/** Action group title */
|
|
29
|
+
title: string;
|
|
30
|
+
/** Use Polaris plain styling */
|
|
31
|
+
plain?: boolean;
|
|
32
|
+
/** List of actions */
|
|
33
|
+
actions: ActionProps[];
|
|
34
|
+
}
|
|
35
|
+
export { Group };
|
package/types.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Group = void 0;
|
|
4
|
+
var types_1 = require("@shopify/app-bridge/actions/types");
|
|
5
|
+
Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return types_1.Group; } });
|