@shopify/app-bridge-react 2.0.18 → 2.0.19
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 +1 -1
- package/components/ClientRouter/ClientRouter.d.ts +21 -0
- package/components/ClientRouter/ClientRouter.js +50 -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 +6 -0
- package/components/ClientRouter/router.d.ts +5 -0
- package/components/ClientRouter/router.js +11 -0
- package/components/Loading/Loading.d.ts +17 -0
- package/components/Loading/Loading.js +53 -0
- package/components/Loading/index.d.ts +2 -0
- package/components/Loading/index.js +7 -0
- package/components/Modal/Modal.d.ts +43 -0
- package/components/Modal/Modal.js +131 -0
- package/components/Modal/ModalContent/ModalContent.d.ts +22 -0
- package/components/Modal/ModalContent/ModalContent.js +59 -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 +9 -0
- package/components/Provider/Provider.d.ts +36 -0
- package/components/Provider/Provider.js +93 -0
- package/components/Provider/index.d.ts +3 -0
- package/components/Provider/index.js +7 -0
- package/components/ResourcePicker/ResourcePicker.d.ts +77 -0
- package/components/ResourcePicker/ResourcePicker.js +129 -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 +52 -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 +6 -0
- package/components/RoutePropagator/route-propagator.d.ts +7 -0
- package/components/RoutePropagator/route-propagator.js +91 -0
- package/components/TitleBar/TitleBar.d.ts +38 -0
- package/components/TitleBar/TitleBar.js +78 -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 +57 -0
- package/components/Toast/index.d.ts +3 -0
- package/components/Toast/index.js +7 -0
- package/components/index.d.ts +8 -0
- package/components/index.js +27 -0
- package/context.d.ts +13 -0
- package/context.js +10 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +6 -0
- package/hooks/useNavigationHistory/index.d.ts +1 -0
- package/hooks/useNavigationHistory/index.js +4 -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 +4 -0
- package/hooks/useToast/useToast.d.ts +15 -0
- package/hooks/useToast/useToast.js +38 -0
- package/index.d.ts +3 -0
- package/index.js +17 -0
- package/package.json +4 -3
- package/types.d.ts +33 -0
- package/types.js +2 -0
- package/umd/index.js +14 -0
- package/useAppBridge.d.ts +1 -0
- package/useAppBridge.js +13 -0
- package/utilities/transformers.d.ts +19 -0
- package/utilities/transformers.js +86 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ResourcePicker as AppBridgeResourcePicker } from '@shopify/app-bridge/actions';
|
|
3
|
+
import { BaseResource } from '@shopify/app-bridge/actions/ResourcePicker';
|
|
4
|
+
export interface SelectPayload {
|
|
5
|
+
/** The selected resources
|
|
6
|
+
* @see {@link https://help.shopify.com/en/api/embedded-apps/app-bridge/actions/resourcepicker|resource picker documentation} for more information
|
|
7
|
+
*/
|
|
8
|
+
selection: AppBridgeResourcePicker.ResourceSelection[];
|
|
9
|
+
}
|
|
10
|
+
interface BaseProps {
|
|
11
|
+
/** Whether the picker is open or not */
|
|
12
|
+
open: boolean;
|
|
13
|
+
/** GraphQL initial search query for filtering resources available in the picker
|
|
14
|
+
* @see {@link https://help.shopify.com/en/api/getting-started/search-syntax|search syntax} for more information
|
|
15
|
+
*/
|
|
16
|
+
initialQuery?: string;
|
|
17
|
+
/** Resources that should already be selected when the picker is opened */
|
|
18
|
+
initialSelectionIds?: BaseResource[];
|
|
19
|
+
/** Show products that are not published on the Online Store */
|
|
20
|
+
showHidden?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated as of 1.28.0
|
|
23
|
+
*/
|
|
24
|
+
/** Whether to allow selection of multiple items */
|
|
25
|
+
allowMultiple?: boolean;
|
|
26
|
+
/** Whether to allow selection of multiple items, or the maximum number of selected items */
|
|
27
|
+
selectMultiple?: boolean | number;
|
|
28
|
+
/** Override default action verb `Add`. The actionVerb appears in the title `<actionVerb>` `<resourceType>` and as the primary action of the resource picker. */
|
|
29
|
+
actionVerb?: AppBridgeResourcePicker.ActionVerb;
|
|
30
|
+
/** Callback when a selection has been made */
|
|
31
|
+
onSelection?(selectPayload: SelectPayload): void;
|
|
32
|
+
/** Callback when the picker is closed without selection */
|
|
33
|
+
onCancel?(): void;
|
|
34
|
+
}
|
|
35
|
+
export interface ProductPickerProps extends BaseProps {
|
|
36
|
+
/** The type of resource you want to pick */
|
|
37
|
+
resourceType: 'Product';
|
|
38
|
+
/** Whether to show product variants or not. Only applies to the product resource type picker */
|
|
39
|
+
showVariants?: boolean;
|
|
40
|
+
/** Whether to show draft products or not. Only applies to the product resource type picker */
|
|
41
|
+
showDraft?: boolean;
|
|
42
|
+
/** Whether to show archived products or not. Only applies to the product resource type picker */
|
|
43
|
+
showArchived?: boolean;
|
|
44
|
+
/** Whether to show draft badge for draft products or not. Only works when `showDraft` prop is set, and only applies to the product resource type picker */
|
|
45
|
+
showDraftBadge?: boolean;
|
|
46
|
+
/** Whether to show archived badge for archived products or not. Only works when `showArchived` prop is set, and only applies to the product resource type picker */
|
|
47
|
+
showArchivedBadge?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface ProductVariantProps extends BaseProps {
|
|
50
|
+
/** The type of resource you want to pick */
|
|
51
|
+
resourceType: 'ProductVariant';
|
|
52
|
+
}
|
|
53
|
+
export interface CollectionPickerProps extends BaseProps {
|
|
54
|
+
/** The type of resource you want to pick */
|
|
55
|
+
resourceType: 'Collection';
|
|
56
|
+
}
|
|
57
|
+
export declare type Props = ProductPickerProps | ProductVariantProps | CollectionPickerProps;
|
|
58
|
+
/**
|
|
59
|
+
* ResourcePicker component
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* React component which wraps the Shopify App Bridge ResourcePicker action.
|
|
63
|
+
*
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
declare class ResourcePicker extends React.PureComponent<Props, never> {
|
|
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
|
+
}
|
|
77
|
+
export default ResourcePicker;
|
|
@@ -0,0 +1,129 @@
|
|
|
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __assign = (this && this.__assign) || function () {
|
|
16
|
+
__assign = Object.assign || function(t) {
|
|
17
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
+
s = arguments[i];
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
26
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
var react_1 = __importDefault(require("react"));
|
|
31
|
+
var actions_1 = require("@shopify/app-bridge/actions");
|
|
32
|
+
var context_1 = require("../../context");
|
|
33
|
+
/**
|
|
34
|
+
* ResourcePicker component
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* React component which wraps the Shopify App Bridge ResourcePicker action.
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
var ResourcePicker = /** @class */ (function (_super) {
|
|
42
|
+
__extends(ResourcePicker, _super);
|
|
43
|
+
function ResourcePicker() {
|
|
44
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
45
|
+
_this.focusReturnPoint = null;
|
|
46
|
+
return _this;
|
|
47
|
+
}
|
|
48
|
+
ResourcePicker.prototype.componentDidMount = function () {
|
|
49
|
+
var _a = this.props, open = _a.open, resourceType = _a.resourceType, onSelection = _a.onSelection, onCancel = _a.onCancel;
|
|
50
|
+
var app = this.context;
|
|
51
|
+
this.picker = actions_1.ResourcePicker.create(app, {
|
|
52
|
+
resourceType: actions_1.ResourcePicker.ResourceType[resourceType],
|
|
53
|
+
options: this.getActionOptions(),
|
|
54
|
+
});
|
|
55
|
+
if (onSelection != null) {
|
|
56
|
+
this.picker.subscribe(actions_1.ResourcePicker.Action.SELECT, onSelection);
|
|
57
|
+
}
|
|
58
|
+
if (onCancel != null) {
|
|
59
|
+
this.picker.subscribe(actions_1.ResourcePicker.Action.CANCEL, onCancel);
|
|
60
|
+
}
|
|
61
|
+
if (open) {
|
|
62
|
+
this.focusReturnPoint = document.activeElement;
|
|
63
|
+
this.picker.dispatch(actions_1.ResourcePicker.Action.OPEN);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
ResourcePicker.prototype.componentDidUpdate = function (prevProps) {
|
|
67
|
+
var wasOpen = prevProps.open;
|
|
68
|
+
var _a = this.props, open = _a.open, onCancel = _a.onCancel, onSelection = _a.onSelection;
|
|
69
|
+
this.picker.unsubscribe();
|
|
70
|
+
this.picker.set(this.getActionOptions());
|
|
71
|
+
if (onSelection != null) {
|
|
72
|
+
this.picker.subscribe(actions_1.ResourcePicker.Action.SELECT, onSelection);
|
|
73
|
+
}
|
|
74
|
+
if (onCancel != null) {
|
|
75
|
+
this.picker.subscribe(actions_1.ResourcePicker.Action.CANCEL, onCancel);
|
|
76
|
+
}
|
|
77
|
+
if (wasOpen !== open) {
|
|
78
|
+
if (open) {
|
|
79
|
+
this.picker.dispatch(actions_1.ResourcePicker.Action.OPEN);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.picker.dispatch(actions_1.ResourcePicker.Action.CLOSE);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (!wasOpen && open) {
|
|
86
|
+
this.focusReturnPoint = document.activeElement;
|
|
87
|
+
}
|
|
88
|
+
else if (wasOpen &&
|
|
89
|
+
!open &&
|
|
90
|
+
this.focusReturnPoint != null &&
|
|
91
|
+
document.contains(this.focusReturnPoint)) {
|
|
92
|
+
this.focusReturnPoint.focus();
|
|
93
|
+
this.focusReturnPoint = null;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
ResourcePicker.prototype.componentWillUnmount = function () {
|
|
97
|
+
this.picker.unsubscribe();
|
|
98
|
+
};
|
|
99
|
+
ResourcePicker.prototype.render = function () {
|
|
100
|
+
return null;
|
|
101
|
+
};
|
|
102
|
+
ResourcePicker.prototype.getActionOptions = function () {
|
|
103
|
+
var _a = this.props, initialQuery = _a.initialQuery, initialSelectionIds = _a.initialSelectionIds, showHidden = _a.showHidden, allowMultiple = _a.allowMultiple, selectMultiple = _a.selectMultiple, actionVerb = _a.actionVerb;
|
|
104
|
+
var sharedOptions = {
|
|
105
|
+
initialQuery: initialQuery,
|
|
106
|
+
initialSelectionIds: initialSelectionIds,
|
|
107
|
+
showHidden: showHidden,
|
|
108
|
+
selectMultiple: selectMultiple !== null && selectMultiple !== void 0 ? selectMultiple : allowMultiple,
|
|
109
|
+
actionVerb: actionVerb,
|
|
110
|
+
};
|
|
111
|
+
var result = sharedOptions;
|
|
112
|
+
if (this.props.resourceType === 'Product') {
|
|
113
|
+
var _b = this.props, showVariants = _b.showVariants, showDraft = _b.showDraft, showArchived = _b.showArchived, showDraftBadge = _b.showDraftBadge, showArchivedBadge = _b.showArchivedBadge;
|
|
114
|
+
var productSpecificOptions = {
|
|
115
|
+
showVariants: showVariants,
|
|
116
|
+
showDraft: showDraft,
|
|
117
|
+
showArchived: showArchived,
|
|
118
|
+
showDraftBadge: showDraftBadge,
|
|
119
|
+
showArchivedBadge: showArchivedBadge,
|
|
120
|
+
};
|
|
121
|
+
result = __assign(__assign({}, sharedOptions), productSpecificOptions);
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
ResourcePicker.contextType = context_1.AppBridgeContext;
|
|
126
|
+
ResourcePicker.ActionVerb = actions_1.ResourcePicker.ActionVerb;
|
|
127
|
+
return ResourcePicker;
|
|
128
|
+
}(react_1.default.PureComponent));
|
|
129
|
+
exports.default = ResourcePicker;
|
|
@@ -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 ResourcePicker_1 = __importDefault(require("./ResourcePicker"));
|
|
7
|
+
exports.default = ResourcePicker_1.default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { LocationOrHref } from './route-propagator';
|
|
3
|
+
export interface Props {
|
|
4
|
+
location: LocationOrHref;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* RoutePropagator component
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* React component which keeps the Shopify admin url in sync with the app url
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
declare class RoutePropagator extends React.Component<Props, never> {
|
|
15
|
+
static contextType: React.Context<import("../../context").IAppBridgeContext>;
|
|
16
|
+
componentDidMount(): void;
|
|
17
|
+
componentDidUpdate({ location: prevLocation }: Props): void;
|
|
18
|
+
render(): null;
|
|
19
|
+
}
|
|
20
|
+
export default RoutePropagator;
|
|
@@ -0,0 +1,52 @@
|
|
|
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
var react_1 = __importDefault(require("react"));
|
|
20
|
+
var context_1 = require("../../context");
|
|
21
|
+
var route_propagator_1 = require("./route-propagator");
|
|
22
|
+
/**
|
|
23
|
+
* RoutePropagator component
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* React component which keeps the Shopify admin url in sync with the app url
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
var RoutePropagator = /** @class */ (function (_super) {
|
|
31
|
+
__extends(RoutePropagator, _super);
|
|
32
|
+
function RoutePropagator() {
|
|
33
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
34
|
+
}
|
|
35
|
+
RoutePropagator.prototype.componentDidMount = function () {
|
|
36
|
+
var location = this.props.location;
|
|
37
|
+
route_propagator_1.updateHistory(this.context, location);
|
|
38
|
+
};
|
|
39
|
+
RoutePropagator.prototype.componentDidUpdate = function (_a) {
|
|
40
|
+
var prevLocation = _a.location;
|
|
41
|
+
var location = this.props.location;
|
|
42
|
+
if (location !== prevLocation) {
|
|
43
|
+
route_propagator_1.updateHistory(this.context, location);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
RoutePropagator.prototype.render = function () {
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
RoutePropagator.contextType = context_1.AppBridgeContext;
|
|
50
|
+
return RoutePropagator;
|
|
51
|
+
}(react_1.default.Component));
|
|
52
|
+
exports.default = RoutePropagator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOrigin = exports.getTopWindow = exports.getSelfWindow = void 0;
|
|
4
|
+
function getSelfWindow() {
|
|
5
|
+
return window.self;
|
|
6
|
+
}
|
|
7
|
+
exports.getSelfWindow = getSelfWindow;
|
|
8
|
+
function getTopWindow() {
|
|
9
|
+
return window.top;
|
|
10
|
+
}
|
|
11
|
+
exports.getTopWindow = getTopWindow;
|
|
12
|
+
function getOrigin() {
|
|
13
|
+
return location.origin;
|
|
14
|
+
}
|
|
15
|
+
exports.getOrigin = getOrigin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LocationOrHref } from './route-propagator';
|
|
2
|
+
/**
|
|
3
|
+
* useRoutePropagation
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* A hook which keeps the Shopify admin url in sync with the app url
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export default function useRoutePropagation(location: LocationOrHref): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var react_1 = require("react");
|
|
4
|
+
var useAppBridge_1 = require("../../useAppBridge");
|
|
5
|
+
var route_propagator_1 = require("./route-propagator");
|
|
6
|
+
/**
|
|
7
|
+
* useRoutePropagation
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A hook which keeps the Shopify admin url in sync with the app url
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
function useRoutePropagation(location) {
|
|
15
|
+
var app = useAppBridge_1.useAppBridge();
|
|
16
|
+
react_1.useEffect(function () {
|
|
17
|
+
route_propagator_1.updateHistory(app, location);
|
|
18
|
+
}, [app, location]);
|
|
19
|
+
}
|
|
20
|
+
exports.default = useRoutePropagation;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var RoutePropagator_1 = require("./RoutePropagator");
|
|
4
|
+
Object.defineProperty(exports, "RoutePropagator", { enumerable: true, get: function () { return RoutePropagator_1.default; } });
|
|
5
|
+
var hook_1 = require("./hook");
|
|
6
|
+
Object.defineProperty(exports, "useRoutePropagation", { enumerable: true, get: function () { return hook_1.default; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ClientApplication } from '@shopify/app-bridge';
|
|
2
|
+
export declare type LocationOrHref = string | {
|
|
3
|
+
search: string;
|
|
4
|
+
hash: string;
|
|
5
|
+
pathname: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function updateHistory(app: ClientApplication<any>, location: LocationOrHref): Promise<void>;
|
|
@@ -0,0 +1,91 @@
|
|
|
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.updateHistory = void 0;
|
|
40
|
+
var MessageTransport_1 = require("@shopify/app-bridge/MessageTransport");
|
|
41
|
+
var actions_1 = require("@shopify/app-bridge/actions");
|
|
42
|
+
var globals_1 = require("./globals");
|
|
43
|
+
// These parameters are added to the iframe url but we don't want to propagate
|
|
44
|
+
// them up to the address bar as they are not provided by the application
|
|
45
|
+
// Removing hmac is especially important as its presence may cause infinite
|
|
46
|
+
// oauth authentication loops
|
|
47
|
+
var embeddedFrameParamsToRemove = [
|
|
48
|
+
'hmac',
|
|
49
|
+
'locale',
|
|
50
|
+
'protocol',
|
|
51
|
+
'session',
|
|
52
|
+
'shop',
|
|
53
|
+
'timestamp',
|
|
54
|
+
'host',
|
|
55
|
+
];
|
|
56
|
+
function updateHistory(app, location) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var selfWindow, topWindow, renderedInTheTopWindow, renderedAsMainApp, normalizedLocation, pathname, search, hash, locationStr;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
selfWindow = globals_1.getSelfWindow();
|
|
63
|
+
topWindow = globals_1.getTopWindow();
|
|
64
|
+
renderedInTheTopWindow = selfWindow === topWindow;
|
|
65
|
+
return [4 /*yield*/, app.getState('context').then(function (context) {
|
|
66
|
+
return context === MessageTransport_1.Context.Main;
|
|
67
|
+
})];
|
|
68
|
+
case 1:
|
|
69
|
+
renderedAsMainApp = _a.sent();
|
|
70
|
+
if (renderedInTheTopWindow || !renderedAsMainApp) {
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}
|
|
73
|
+
normalizedLocation = getNormalizedURL(location);
|
|
74
|
+
embeddedFrameParamsToRemove.forEach(function (param) { return normalizedLocation.searchParams.delete(param); });
|
|
75
|
+
pathname = normalizedLocation.pathname, search = normalizedLocation.search, hash = normalizedLocation.hash;
|
|
76
|
+
locationStr = "" + pathname + search + hash;
|
|
77
|
+
actions_1.History.create(app).dispatch(actions_1.History.Action.REPLACE, locationStr);
|
|
78
|
+
return [2 /*return*/];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.updateHistory = updateHistory;
|
|
84
|
+
function getNormalizedURL(location) {
|
|
85
|
+
var origin = globals_1.getOrigin();
|
|
86
|
+
if (typeof location === 'string') {
|
|
87
|
+
return new URL(location, origin);
|
|
88
|
+
}
|
|
89
|
+
var pathname = location.pathname, search = location.search, hash = location.hash;
|
|
90
|
+
return new URL("" + pathname + search + hash, origin);
|
|
91
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ActionProps, ActionGroupProps, Target } from '../../types';
|
|
3
|
+
export interface Breadcrumb {
|
|
4
|
+
/** Content the action displays */
|
|
5
|
+
content?: string;
|
|
6
|
+
/** A destination to link to */
|
|
7
|
+
url?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Where to display the target link
|
|
10
|
+
* @default 'APP'
|
|
11
|
+
*/
|
|
12
|
+
target?: Target;
|
|
13
|
+
/** Callback when an action takes place */
|
|
14
|
+
onAction?(): void;
|
|
15
|
+
}
|
|
16
|
+
export interface Props {
|
|
17
|
+
/** TitleBar title */
|
|
18
|
+
title: string;
|
|
19
|
+
/** Collection of breadcrumbs */
|
|
20
|
+
breadcrumbs?: Breadcrumb[];
|
|
21
|
+
/** Primary TitleBar action */
|
|
22
|
+
primaryAction?: ActionProps;
|
|
23
|
+
/** Collection of secondary TitleBar actions */
|
|
24
|
+
secondaryActions?: ActionProps[];
|
|
25
|
+
/** Collection of TitleBar groups of secondary actions */
|
|
26
|
+
actionGroups?: ActionGroupProps[];
|
|
27
|
+
}
|
|
28
|
+
declare class TitleBar extends React.PureComponent<Props, never> {
|
|
29
|
+
static contextType: React.Context<import("../../context").IAppBridgeContext>;
|
|
30
|
+
private titleBar;
|
|
31
|
+
componentDidMount(): void;
|
|
32
|
+
componentDidUpdate(): void;
|
|
33
|
+
componentWillUnmount(): void;
|
|
34
|
+
render(): null;
|
|
35
|
+
private transformProps;
|
|
36
|
+
private transformBreadcrumbs;
|
|
37
|
+
}
|
|
38
|
+
export default TitleBar;
|
|
@@ -0,0 +1,78 @@
|
|
|
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
var react_1 = __importDefault(require("react"));
|
|
20
|
+
var actions_1 = require("@shopify/app-bridge/actions");
|
|
21
|
+
var transformers_1 = require("../../utilities/transformers");
|
|
22
|
+
var context_1 = require("../../context");
|
|
23
|
+
var TitleBar = /** @class */ (function (_super) {
|
|
24
|
+
__extends(TitleBar, _super);
|
|
25
|
+
function TitleBar() {
|
|
26
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
}
|
|
28
|
+
TitleBar.prototype.componentDidMount = function () {
|
|
29
|
+
var app = this.context;
|
|
30
|
+
this.titleBar = actions_1.TitleBar.create(app, this.transformProps());
|
|
31
|
+
};
|
|
32
|
+
TitleBar.prototype.componentDidUpdate = function () {
|
|
33
|
+
this.titleBar.unsubscribe();
|
|
34
|
+
this.titleBar.set(this.transformProps());
|
|
35
|
+
};
|
|
36
|
+
TitleBar.prototype.componentWillUnmount = function () {
|
|
37
|
+
this.titleBar.unsubscribe();
|
|
38
|
+
};
|
|
39
|
+
TitleBar.prototype.render = function () {
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
TitleBar.prototype.transformProps = function () {
|
|
43
|
+
var app = this.context;
|
|
44
|
+
var _a = this.props, title = _a.title, primaryAction = _a.primaryAction, secondaryActions = _a.secondaryActions, actionGroups = _a.actionGroups;
|
|
45
|
+
return {
|
|
46
|
+
title: title,
|
|
47
|
+
buttons: transformers_1.transformActions(app, {
|
|
48
|
+
primaryAction: primaryAction,
|
|
49
|
+
secondaryActions: secondaryActions,
|
|
50
|
+
actionGroups: actionGroups,
|
|
51
|
+
}),
|
|
52
|
+
breadcrumbs: this.transformBreadcrumbs(),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
TitleBar.prototype.transformBreadcrumbs = function () {
|
|
56
|
+
var app = this.context;
|
|
57
|
+
var breadcrumbs = this.props.breadcrumbs;
|
|
58
|
+
if (breadcrumbs == null || breadcrumbs.length === 0) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
var breadcrumb = breadcrumbs[breadcrumbs.length - 1];
|
|
62
|
+
var url = breadcrumb.url, onAction = breadcrumb.onAction, target = breadcrumb.target, content = breadcrumb.content;
|
|
63
|
+
var button = actions_1.Button.create(app, {
|
|
64
|
+
label: content || '',
|
|
65
|
+
});
|
|
66
|
+
var redirect = transformers_1.generateRedirect(app, url, target);
|
|
67
|
+
if (redirect != null) {
|
|
68
|
+
button.subscribe(actions_1.Button.Action.CLICK, redirect);
|
|
69
|
+
}
|
|
70
|
+
if (onAction != null) {
|
|
71
|
+
button.subscribe(actions_1.Button.Action.CLICK, onAction);
|
|
72
|
+
}
|
|
73
|
+
return button;
|
|
74
|
+
};
|
|
75
|
+
TitleBar.contextType = context_1.AppBridgeContext;
|
|
76
|
+
return TitleBar;
|
|
77
|
+
}(react_1.default.PureComponent));
|
|
78
|
+
exports.default = TitleBar;
|
|
@@ -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 TitleBar_1 = __importDefault(require("./TitleBar"));
|
|
7
|
+
exports.default = TitleBar_1.default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface Props {
|
|
3
|
+
/** The content that should appear in the toast message */
|
|
4
|
+
content: string;
|
|
5
|
+
/**
|
|
6
|
+
* The length of time in milliseconds the toast message should persist
|
|
7
|
+
* @default 5000
|
|
8
|
+
*/
|
|
9
|
+
duration?: number;
|
|
10
|
+
/** Display an error toast. */
|
|
11
|
+
error?: boolean;
|
|
12
|
+
/** Callback when the dismiss icon is clicked */
|
|
13
|
+
onDismiss(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const DEFAULT_TOAST_DURATION = 5000;
|
|
16
|
+
/**
|
|
17
|
+
* Toast component
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* React component which wraps the Shopify App Bridge Toast action.
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
declare class Toast extends React.PureComponent<Props, never> {
|
|
25
|
+
static contextType: React.Context<import("../../context").IAppBridgeContext>;
|
|
26
|
+
private toast;
|
|
27
|
+
componentDidMount(): void;
|
|
28
|
+
componentWillUnmount(): void;
|
|
29
|
+
render(): null;
|
|
30
|
+
}
|
|
31
|
+
export default Toast;
|