@frak-labs/components 0.0.26-beta.b38eef2e → 0.0.26-beta.d2556d47
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/cdn/ButtonShare.Chxmap9H.js +1 -0
- package/cdn/ButtonWallet.Bgt7hfbh.js +40 -0
- package/cdn/OpenInAppButton.CGXLv0k_.js +1 -0
- package/cdn/components.js +1 -1
- package/cdn/jsxRuntime.module.feNUq6Nq.js +58 -0
- package/cdn/loader.css +0 -14
- package/cdn/loader.js +66 -1
- package/dist/buttonShare.d.ts +7 -5
- package/dist/buttonShare.js +53 -54
- package/dist/buttonWallet.d.ts +9 -1
- package/dist/buttonWallet.js +77 -32
- package/dist/openInApp.d.ts +2 -0
- package/dist/openInApp.js +22 -20
- package/dist/useLightDomStyles-ZGaYUErZ.js +44 -0
- package/dist/usePlacement-D99UDsVs.js +290 -0
- package/package.json +11 -15
- package/cdn/ButtonShare.CSPl5Bi5.js +0 -1
- package/cdn/ButtonWallet.3Hp62hGr.js +0 -1
- package/cdn/OpenInAppButton.BTvukMkp.js +0 -1
- package/cdn/Spinner.DQogVqic.js +0 -1
- package/cdn/initFrakSdk.CMgrZQwQ.js +0 -14
- package/cdn/useClientReady.CKKC4IMk.js +0 -1
- package/dist/Spinner-Btnwk01x.js +0 -36
- package/dist/Spinner-CHZD3tMn.css +0 -1
- package/dist/buttonShare.css +0 -1
- package/dist/buttonWallet.css +0 -1
- package/dist/openInApp.css +0 -1
- package/dist/useClientReady-0vKBG0-p.js +0 -197
package/dist/buttonShare.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as preact from "preact";
|
|
|
7
7
|
* @inline
|
|
8
8
|
*/
|
|
9
9
|
type ButtonShareProps = {
|
|
10
|
+
placement?: string;
|
|
10
11
|
/**
|
|
11
12
|
* Text to display on the button
|
|
12
13
|
* - To specify where the reward should be displayed, use the placeholder `{REWARD}`, e.g. `Share and earn up to \{REWARD\}!`
|
|
@@ -31,10 +32,10 @@ type ButtonShareProps = {
|
|
|
31
32
|
*/
|
|
32
33
|
targetInteraction?: InteractionTypeKey;
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
-
* @defaultValue `
|
|
35
|
+
* Which UI to open on click
|
|
36
|
+
* @defaultValue `"embedded-wallet"`
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
clickAction?: "embedded-wallet" | "share-modal";
|
|
38
39
|
};
|
|
39
40
|
//#endregion
|
|
40
41
|
//#region src/components/ButtonShare/ButtonShare.d.ts
|
|
@@ -80,13 +81,14 @@ type ButtonShareProps = {
|
|
|
80
81
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
81
82
|
*/
|
|
82
83
|
declare function ButtonShare({
|
|
84
|
+
placement: placementId,
|
|
83
85
|
text,
|
|
84
86
|
classname,
|
|
85
87
|
useReward: rawUseReward,
|
|
86
88
|
noRewardText,
|
|
87
89
|
targetInteraction,
|
|
88
|
-
|
|
89
|
-
}: ButtonShareProps): preact.JSX.Element;
|
|
90
|
+
clickAction: rawClickAction
|
|
91
|
+
}: ButtonShareProps): preact.JSX.Element | null;
|
|
90
92
|
//#endregion
|
|
91
93
|
//#region src/components/ButtonShare/index.d.ts
|
|
92
94
|
/**
|
package/dist/buttonShare.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { a as registerWebComponent, i as useClientReady, s as openEmbeddedWallet, t as usePlacement } from "./usePlacement-D99UDsVs.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-ZGaYUErZ.js";
|
|
3
3
|
import { t as useReward } from "./useReward-DAkT-7wT.js";
|
|
4
4
|
import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
|
|
5
|
-
import {
|
|
6
|
-
import { cx } from "class-variance-authority";
|
|
5
|
+
import { modalBuilder } from "@frak-labs/core-sdk/actions";
|
|
7
6
|
import { useCallback, useMemo, useState } from "preact/hooks";
|
|
8
7
|
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
9
8
|
import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
|
|
10
9
|
|
|
11
|
-
//#region src/components/ButtonShare/ButtonShare.module.css?css_module
|
|
12
|
-
const classes = { "buttonShare": "nOB7Uq_buttonShare" };
|
|
13
|
-
const _buttonShare0 = classes["buttonShare"];
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
10
|
//#region src/hooks/useCopyToClipboard.ts
|
|
17
11
|
function useCopyToClipboard(options = {}) {
|
|
18
12
|
const { successDuration = 2e3 } = options;
|
|
@@ -171,9 +165,9 @@ function ErrorMessage({ debugInfo }) {
|
|
|
171
165
|
* Open the share modal
|
|
172
166
|
*
|
|
173
167
|
* @description
|
|
174
|
-
* This function will open the share modal
|
|
168
|
+
* This function will open the share modal, lazily creating a modal builder on demand.
|
|
175
169
|
*/
|
|
176
|
-
function useShareModal(targetInteraction) {
|
|
170
|
+
function useShareModal(targetInteraction, placement) {
|
|
177
171
|
const [debugInfo, setDebugInfo] = useState(void 0);
|
|
178
172
|
const [isError, setIsError] = useState(false);
|
|
179
173
|
return {
|
|
@@ -184,13 +178,12 @@ function useShareModal(targetInteraction) {
|
|
|
184
178
|
setIsError(true);
|
|
185
179
|
return;
|
|
186
180
|
}
|
|
187
|
-
const
|
|
188
|
-
if (!modalBuilderSteps) throw new Error("modalBuilderSteps not found");
|
|
181
|
+
const builder = modalBuilder(window.FrakSetup.client, {});
|
|
189
182
|
try {
|
|
190
|
-
await
|
|
183
|
+
await builder.sharing({}).display((metadata) => ({
|
|
191
184
|
...metadata,
|
|
192
185
|
targetInteraction
|
|
193
|
-
}));
|
|
186
|
+
}), placement);
|
|
194
187
|
} catch (e) {
|
|
195
188
|
if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
|
|
196
189
|
console.debug("User aborted the modal");
|
|
@@ -205,7 +198,7 @@ function useShareModal(targetInteraction) {
|
|
|
205
198
|
setIsError(true);
|
|
206
199
|
console.error("Error while opening the modal", e);
|
|
207
200
|
}
|
|
208
|
-
}, [targetInteraction]),
|
|
201
|
+
}, [targetInteraction, placement]),
|
|
209
202
|
isError,
|
|
210
203
|
debugInfo
|
|
211
204
|
};
|
|
@@ -214,16 +207,6 @@ function useShareModal(targetInteraction) {
|
|
|
214
207
|
//#endregion
|
|
215
208
|
//#region src/components/ButtonShare/ButtonShare.tsx
|
|
216
209
|
/**
|
|
217
|
-
* Open the embedded wallet modal
|
|
218
|
-
*
|
|
219
|
-
* @description
|
|
220
|
-
* This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
|
|
221
|
-
*/
|
|
222
|
-
async function modalEmbeddedWallet() {
|
|
223
|
-
if (!window.FrakSetup?.client) throw new Error("Frak client not found");
|
|
224
|
-
await displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
210
|
* Button to share the current page
|
|
228
211
|
*
|
|
229
212
|
* @param args
|
|
@@ -264,48 +247,64 @@ async function modalEmbeddedWallet() {
|
|
|
264
247
|
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
265
248
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
266
249
|
*/
|
|
267
|
-
function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction,
|
|
268
|
-
const
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
const
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
250
|
+
function ButtonShare({ placement: placementId, text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, clickAction: rawClickAction }) {
|
|
251
|
+
const placement = usePlacement(placementId);
|
|
252
|
+
const componentConfig = placement?.components?.buttonShare;
|
|
253
|
+
useLightDomStyles("frak-button-share", placementId, componentConfig?.css);
|
|
254
|
+
const resolvedTargetInteraction = useMemo(() => placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction, [placement?.targetInteraction, targetInteraction]);
|
|
255
|
+
const resolvedText = componentConfig?.text ?? text;
|
|
256
|
+
const resolvedNoRewardText = componentConfig?.noRewardText ?? noRewardText;
|
|
257
|
+
const shouldUseReward = useMemo(() => componentConfig?.useReward ?? rawUseReward === true, [componentConfig?.useReward, rawUseReward]);
|
|
258
|
+
const resolvedClickAction = useMemo(() => componentConfig?.clickAction ?? rawClickAction ?? "embedded-wallet", [componentConfig?.clickAction, rawClickAction]);
|
|
259
|
+
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
260
|
+
const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
|
|
261
|
+
const { handleShare, isError, debugInfo } = useShareModal(resolvedTargetInteraction, placementId);
|
|
276
262
|
const btnText = useMemo(() => {
|
|
277
|
-
if (!shouldUseReward) return
|
|
278
|
-
if (!reward) return
|
|
279
|
-
return
|
|
263
|
+
if (!shouldUseReward) return resolvedText;
|
|
264
|
+
if (!reward) return resolvedNoRewardText ?? resolvedText.replace("{REWARD}", "");
|
|
265
|
+
return resolvedText.includes("{REWARD}") ? resolvedText.replace("{REWARD}", reward) : `${resolvedText} ${reward}`;
|
|
280
266
|
}, [
|
|
281
267
|
shouldUseReward,
|
|
282
|
-
|
|
283
|
-
|
|
268
|
+
resolvedText,
|
|
269
|
+
resolvedNoRewardText,
|
|
284
270
|
reward
|
|
285
271
|
]);
|
|
286
|
-
/**
|
|
287
|
-
* The action when the button is clicked
|
|
288
|
-
*/
|
|
289
272
|
const onClick = useCallback(async () => {
|
|
290
273
|
trackEvent(window.FrakSetup.client, "share_button_clicked");
|
|
291
|
-
if (
|
|
292
|
-
else
|
|
293
|
-
}, [
|
|
294
|
-
|
|
274
|
+
if (resolvedClickAction === "share-modal") await handleShare();
|
|
275
|
+
else openEmbeddedWallet(resolvedTargetInteraction, placementId);
|
|
276
|
+
}, [
|
|
277
|
+
resolvedClickAction,
|
|
278
|
+
handleShare,
|
|
279
|
+
resolvedTargetInteraction,
|
|
280
|
+
placementId
|
|
281
|
+
]);
|
|
282
|
+
if (!shouldRender || isHidden) return null;
|
|
283
|
+
const buttonClass = [
|
|
284
|
+
"button",
|
|
285
|
+
"button__fadeIn",
|
|
286
|
+
classname
|
|
287
|
+
].filter(Boolean).join(" ");
|
|
288
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("button", {
|
|
295
289
|
type: "button",
|
|
296
|
-
|
|
290
|
+
disabled: !isClientReady,
|
|
291
|
+
class: buttonClass,
|
|
297
292
|
onClick,
|
|
298
|
-
children:
|
|
299
|
-
!isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
|
|
300
|
-
" ",
|
|
301
|
-
btnText
|
|
302
|
-
]
|
|
293
|
+
children: btnText
|
|
303
294
|
}), isError && /* @__PURE__ */ jsx(ErrorMessage, { debugInfo })] });
|
|
304
295
|
}
|
|
305
296
|
|
|
306
297
|
//#endregion
|
|
307
298
|
//#region src/components/ButtonShare/index.ts
|
|
308
|
-
registerWebComponent(ButtonShare, "frak-button-share", [
|
|
299
|
+
registerWebComponent(ButtonShare, "frak-button-share", [
|
|
300
|
+
"text",
|
|
301
|
+
"placement",
|
|
302
|
+
"classname",
|
|
303
|
+
"clickAction",
|
|
304
|
+
"useReward",
|
|
305
|
+
"noRewardText",
|
|
306
|
+
"targetInteraction"
|
|
307
|
+
], { shadow: false });
|
|
309
308
|
|
|
310
309
|
//#endregion
|
|
311
310
|
export { ButtonShare };
|
package/dist/buttonWallet.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import * as preact from "preact";
|
|
|
7
7
|
* @inline
|
|
8
8
|
*/
|
|
9
9
|
type ButtonWalletProps = {
|
|
10
|
+
placement?: string;
|
|
10
11
|
/**
|
|
11
12
|
* Classname to apply to the button
|
|
12
13
|
*/
|
|
@@ -55,14 +56,21 @@ type ButtonWalletProps = {
|
|
|
55
56
|
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
56
57
|
* ```
|
|
57
58
|
*
|
|
59
|
+
* @example
|
|
60
|
+
* Using placement:
|
|
61
|
+
* ```html
|
|
62
|
+
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
58
65
|
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
59
66
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
60
67
|
*/
|
|
61
68
|
declare function ButtonWallet({
|
|
69
|
+
placement: placementId,
|
|
62
70
|
classname,
|
|
63
71
|
useReward: rawUseReward,
|
|
64
72
|
targetInteraction
|
|
65
|
-
}: ButtonWalletProps): preact.JSX.Element;
|
|
73
|
+
}: ButtonWalletProps): preact.JSX.Element | null;
|
|
66
74
|
//#endregion
|
|
67
75
|
//#region src/components/ButtonWallet/index.d.ts
|
|
68
76
|
/**
|
package/dist/buttonWallet.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { i as
|
|
1
|
+
import { a as registerWebComponent, i as useClientReady, n as buildStyleContent, o as openWalletModal, t as usePlacement } from "./usePlacement-D99UDsVs.js";
|
|
2
2
|
import { t as useReward } from "./useReward-DAkT-7wT.js";
|
|
3
3
|
import { trackEvent } from "@frak-labs/core-sdk";
|
|
4
|
-
import { cx } from "class-variance-authority";
|
|
5
4
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
|
6
|
-
import { jsx, jsxs } from "preact/jsx-runtime";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
7
6
|
|
|
8
7
|
//#region src/components/ButtonWallet/assets/GiftIcon.tsx
|
|
9
8
|
function GiftIcon(props) {
|
|
@@ -23,21 +22,48 @@ function GiftIcon(props) {
|
|
|
23
22
|
});
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/components/ButtonWallet/ButtonWallet.module.css?css_module
|
|
28
|
-
const classes = {
|
|
29
|
-
"button__left": "Kl62ia_button__left",
|
|
30
|
-
"button__right": "Kl62ia_button__right",
|
|
31
|
-
"button": "Kl62ia_button",
|
|
32
|
-
"reward": "Kl62ia_reward"
|
|
33
|
-
};
|
|
34
|
-
const _button__left0 = classes["button__left"];
|
|
35
|
-
const _button__right0 = classes["button__right"];
|
|
36
|
-
const _button0 = classes["button"];
|
|
37
|
-
const _reward0 = classes["reward"];
|
|
38
|
-
|
|
39
25
|
//#endregion
|
|
40
26
|
//#region src/components/ButtonWallet/ButtonWallet.tsx
|
|
27
|
+
const componentCss = `
|
|
28
|
+
.button {
|
|
29
|
+
all: unset;
|
|
30
|
+
position: fixed;
|
|
31
|
+
bottom: 20px;
|
|
32
|
+
z-index: 2000000;
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
align-items: center;
|
|
36
|
+
background-color: #3e557e;
|
|
37
|
+
width: 45px;
|
|
38
|
+
height: 45px;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
text-align: center;
|
|
42
|
+
font-size: 24px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.button__left {
|
|
46
|
+
left: 20px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.button__right {
|
|
50
|
+
right: 20px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.reward {
|
|
54
|
+
position: absolute;
|
|
55
|
+
top: -4px;
|
|
56
|
+
right: 27px;
|
|
57
|
+
padding: 2px 3px;
|
|
58
|
+
border-radius: 5px;
|
|
59
|
+
background: #ff3f3f;
|
|
60
|
+
font-size: 9px;
|
|
61
|
+
color: #fff;
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
white-space: nowrap;
|
|
64
|
+
line-height: 9px;
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
41
67
|
/**
|
|
42
68
|
* Button to open wallet modal
|
|
43
69
|
*
|
|
@@ -70,40 +96,59 @@ const _reward0 = classes["reward"];
|
|
|
70
96
|
* <frak-button-wallet use-reward target-interaction="custom.customerMeeting"></frak-button-wallet>
|
|
71
97
|
* ```
|
|
72
98
|
*
|
|
99
|
+
* @example
|
|
100
|
+
* Using placement:
|
|
101
|
+
* ```html
|
|
102
|
+
* <frak-button-wallet placement="hero-wallet"></frak-button-wallet>
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
73
105
|
* @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
|
|
74
106
|
* @see {@link @frak-labs/core-sdk!actions.getMerchantInformation | `getMerchantInformation()`} for more info about the estimated reward fetching
|
|
75
107
|
*/
|
|
76
|
-
function ButtonWallet({ classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
const
|
|
108
|
+
function ButtonWallet({ placement: placementId, classname = "", useReward: rawUseReward, targetInteraction }) {
|
|
109
|
+
const placement = usePlacement(placementId);
|
|
110
|
+
const resolvedTargetInteraction = useMemo(() => placement?.targetInteraction !== void 0 ? placement.targetInteraction : targetInteraction, [placement?.targetInteraction, targetInteraction]);
|
|
111
|
+
const shouldUseReward = useMemo(() => rawUseReward === true, [rawUseReward]);
|
|
112
|
+
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
113
|
+
const { reward } = useReward(shouldUseReward && isClientReady, resolvedTargetInteraction);
|
|
80
114
|
const [position, setPosition] = useState("right");
|
|
81
|
-
/**
|
|
82
|
-
* Setup the position of the button
|
|
83
|
-
*/
|
|
84
115
|
useEffect(() => {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
116
|
+
const placementPosition = placement?.components?.buttonWallet?.position;
|
|
117
|
+
const configPosition = window.FrakSetup?.modalWalletConfig?.metadata?.position;
|
|
118
|
+
setPosition(placementPosition ?? configPosition ?? "right");
|
|
119
|
+
}, [placement?.components?.buttonWallet?.position]);
|
|
120
|
+
if (!shouldRender || isHidden) return null;
|
|
121
|
+
const buttonClass = [
|
|
122
|
+
"button",
|
|
123
|
+
"button__fadeIn",
|
|
124
|
+
position === "left" ? "button__left" : "button__right",
|
|
125
|
+
classname
|
|
126
|
+
].filter(Boolean).join(" ");
|
|
127
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("style", { children: buildStyleContent(componentCss, placement?.components?.buttonWallet?.css) }), /* @__PURE__ */ jsxs("button", {
|
|
89
128
|
type: "button",
|
|
90
129
|
"aria-label": "Open wallet",
|
|
91
|
-
|
|
130
|
+
part: "button",
|
|
92
131
|
disabled: !isClientReady,
|
|
132
|
+
class: buttonClass,
|
|
93
133
|
onClick: () => {
|
|
94
134
|
trackEvent(window.FrakSetup.client, "wallet_button_clicked");
|
|
95
|
-
openWalletModal();
|
|
135
|
+
openWalletModal(resolvedTargetInteraction, placementId);
|
|
96
136
|
},
|
|
97
137
|
children: [/* @__PURE__ */ jsx(GiftIcon, {}), reward && /* @__PURE__ */ jsx("span", {
|
|
98
|
-
|
|
138
|
+
class: "reward",
|
|
99
139
|
children: reward
|
|
100
140
|
})]
|
|
101
|
-
});
|
|
141
|
+
})] });
|
|
102
142
|
}
|
|
103
143
|
|
|
104
144
|
//#endregion
|
|
105
145
|
//#region src/components/ButtonWallet/index.ts
|
|
106
|
-
registerWebComponent(ButtonWallet, "frak-button-wallet", [
|
|
146
|
+
registerWebComponent(ButtonWallet, "frak-button-wallet", [
|
|
147
|
+
"placement",
|
|
148
|
+
"classname",
|
|
149
|
+
"useReward",
|
|
150
|
+
"targetInteraction"
|
|
151
|
+
], { shadow: true });
|
|
107
152
|
|
|
108
153
|
//#endregion
|
|
109
154
|
export { ButtonWallet };
|
package/dist/openInApp.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import * as preact from "preact";
|
|
|
6
6
|
* @inline
|
|
7
7
|
*/
|
|
8
8
|
type OpenInAppButtonProps = {
|
|
9
|
+
placement?: string;
|
|
9
10
|
/**
|
|
10
11
|
* Text to display on the button
|
|
11
12
|
* @defaultValue `"Open in App"`
|
|
@@ -45,6 +46,7 @@ type OpenInAppButtonProps = {
|
|
|
45
46
|
* ```
|
|
46
47
|
*/
|
|
47
48
|
declare function OpenInAppButton({
|
|
49
|
+
placement: placementId,
|
|
48
50
|
text,
|
|
49
51
|
classname
|
|
50
52
|
}: OpenInAppButtonProps): preact.JSX.Element | null;
|
package/dist/openInApp.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { a as registerWebComponent, i as useClientReady, t as usePlacement } from "./usePlacement-D99UDsVs.js";
|
|
2
|
+
import { t as useLightDomStyles } from "./useLightDomStyles-ZGaYUErZ.js";
|
|
3
3
|
import { DEEP_LINK_SCHEME, trackEvent, triggerDeepLinkWithFallback } from "@frak-labs/core-sdk";
|
|
4
|
-
import { cx } from "class-variance-authority";
|
|
5
4
|
import { useMemo } from "preact/hooks";
|
|
6
|
-
import { jsx
|
|
5
|
+
import { jsx } from "preact/jsx-runtime";
|
|
7
6
|
|
|
8
7
|
//#region src/utils/isMobile.ts
|
|
9
8
|
/**
|
|
@@ -48,11 +47,6 @@ function openFrakWalletApp(path = DEFAULT_PATH) {
|
|
|
48
47
|
} });
|
|
49
48
|
}
|
|
50
49
|
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/components/OpenInAppButton/OpenInAppButton.module.css?css_module
|
|
53
|
-
const classes = { "button": "XYfqGq_button" };
|
|
54
|
-
const _button0 = classes["button"];
|
|
55
|
-
|
|
56
50
|
//#endregion
|
|
57
51
|
//#region src/components/OpenInAppButton/OpenInAppButton.tsx
|
|
58
52
|
/**
|
|
@@ -81,30 +75,38 @@ const _button0 = classes["button"];
|
|
|
81
75
|
* <frak-open-in-app classname="button button-primary"></frak-open-in-app>
|
|
82
76
|
* ```
|
|
83
77
|
*/
|
|
84
|
-
function OpenInAppButton({ text = "Open in App", classname = "" }) {
|
|
85
|
-
const
|
|
78
|
+
function OpenInAppButton({ placement: placementId, text = "Open in App", classname = "" }) {
|
|
79
|
+
const placement = usePlacement(placementId);
|
|
80
|
+
const { shouldRender, isHidden, isClientReady } = useClientReady();
|
|
86
81
|
const { isMobile } = useIsMobile();
|
|
87
|
-
|
|
82
|
+
useLightDomStyles("frak-open-in-app", placementId, placement?.components?.openInApp?.css);
|
|
83
|
+
const resolvedText = placement?.components?.openInApp?.text ?? text;
|
|
84
|
+
if (!isMobile || !shouldRender || isHidden) return null;
|
|
88
85
|
const handleClick = () => {
|
|
89
86
|
openFrakWalletApp();
|
|
90
87
|
};
|
|
91
|
-
|
|
88
|
+
const buttonClass = [
|
|
89
|
+
"button",
|
|
90
|
+
"button__fadeIn",
|
|
91
|
+
classname
|
|
92
|
+
].filter(Boolean).join(" ");
|
|
93
|
+
return /* @__PURE__ */ jsx("button", {
|
|
92
94
|
type: "button",
|
|
93
95
|
"aria-label": "Open in Frak Wallet app",
|
|
94
|
-
className: cx(classes.button, classname, "override"),
|
|
95
96
|
disabled: !isClientReady,
|
|
97
|
+
class: buttonClass,
|
|
96
98
|
onClick: handleClick,
|
|
97
|
-
children:
|
|
98
|
-
!isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
|
|
99
|
-
" ",
|
|
100
|
-
text
|
|
101
|
-
]
|
|
99
|
+
children: resolvedText
|
|
102
100
|
});
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
//#endregion
|
|
106
104
|
//#region src/components/OpenInAppButton/index.ts
|
|
107
|
-
registerWebComponent(OpenInAppButton, "frak-open-in-app", [
|
|
105
|
+
registerWebComponent(OpenInAppButton, "frak-open-in-app", [
|
|
106
|
+
"text",
|
|
107
|
+
"placement",
|
|
108
|
+
"classname"
|
|
109
|
+
], { shadow: false });
|
|
108
110
|
|
|
109
111
|
//#endregion
|
|
110
112
|
export { OpenInAppButton };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { r as lightDomBaseCss } from "./usePlacement-D99UDsVs.js";
|
|
2
|
+
import { useEffect } from "preact/hooks";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/styleManager.ts
|
|
5
|
+
function ensureStyle(id, css) {
|
|
6
|
+
const existing = document.getElementById(id);
|
|
7
|
+
if (existing) {
|
|
8
|
+
if (existing.textContent !== css) existing.textContent = css;
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const style = document.createElement("style");
|
|
12
|
+
style.id = id;
|
|
13
|
+
style.textContent = css;
|
|
14
|
+
document.head.appendChild(style);
|
|
15
|
+
}
|
|
16
|
+
function injectBase(tag, css) {
|
|
17
|
+
ensureStyle(`frak-base-${tag}`, css);
|
|
18
|
+
}
|
|
19
|
+
function injectPlacement(tag, placementId, scopedCss) {
|
|
20
|
+
ensureStyle(`frak-placement-${tag}-${placementId}`, scopedCss);
|
|
21
|
+
}
|
|
22
|
+
const styleManager = {
|
|
23
|
+
injectBase,
|
|
24
|
+
injectPlacement
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/hooks/useLightDomStyles.ts
|
|
29
|
+
function useLightDomStyles(tag, placementId, placementCss) {
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
styleManager.injectBase(tag, lightDomBaseCss);
|
|
32
|
+
}, [tag]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (!placementId || !placementCss) return;
|
|
35
|
+
styleManager.injectPlacement(tag, placementId, placementCss);
|
|
36
|
+
}, [
|
|
37
|
+
tag,
|
|
38
|
+
placementId,
|
|
39
|
+
placementCss
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { useLightDomStyles as t };
|