@frak-labs/components 0.0.23-beta.6e0d8026 → 0.0.23-beta.9f335831

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.
@@ -1,85 +1,100 @@
1
- import type { FullInteractionTypesKey } from '@frak-labs/core-sdk';
2
- import { JSX } from 'preact';
3
-
4
- /**
5
- * Button to share the current page
6
- *
7
- * @param args
8
- * @returns The share button with `<button>` tag
9
- *
10
- * @group components
11
- *
12
- * @example
13
- * Basic usage:
14
- * ```html
15
- * <frak-button-share></frak-button-share>
16
- * ```
17
- *
18
- * @example
19
- * Using a custom text:
20
- * ```html
21
- * <frak-button-share text="Share and earn!"></frak-button-share>
22
- * ```
23
- *
24
- * @example
25
- * Using a custom class:
26
- * ```html
27
- * <frak-button-share classname="button button-primary"></frak-button-share>
28
- * ```
29
- *
30
- * @example
31
- * Using reward information and fallback text:
32
- * ```html
33
- * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!"></frak-button-share>
34
- * ```
35
- *
36
- * @example
37
- * Using reward information for specific reward and fallback text:
38
- * ```html
39
- * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="retail.customerMeeting"></frak-button-share>
40
- * ```
41
- *
42
- * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
43
- * @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the estimated reward fetching
44
- */
45
- export declare function ButtonShare({ text, classname, useReward: rawUseReward, noRewardText, targetInteraction, showWallet: rawShowWallet, }: ButtonShareProps): JSX.Element;
46
-
47
- export declare interface ButtonShareElement extends HTMLElement, ButtonShareProps {
48
- }
49
-
50
- /**
51
- * The props type for {@link ButtonShare}.
52
- * @inline
53
- */
54
- declare type ButtonShareProps = {
55
- /**
56
- * Text to display on the button
57
- * - To specify where the reward should be displayed, use the placeholder `{REWARD}`, e.g. `Share and earn up to {REWARD}!`
58
- * @defaultValue `"Share and earn!"`
59
- */
60
- text?: string;
61
- /**
62
- * Classname to apply to the button
63
- */
64
- classname?: string;
65
- /**
66
- * Do we display the reward on the share modal?
67
- * @defaultValue `false`
68
- */
69
- useReward?: boolean;
70
- /**
71
- * Fallback text if the reward isn't found
72
- */
73
- noRewardText?: string;
74
- /**
75
- * Target interaction behind this sharing action (will be used to get the right reward to display)
76
- */
77
- targetInteraction?: FullInteractionTypesKey;
78
- /**
79
- * Do we display the wallet modal instead of the share modal?
80
- * @defaultValue `false`
81
- */
82
- showWallet?: boolean;
83
- };
84
-
85
- export { }
1
+ import { FullInteractionTypesKey } from "@frak-labs/core-sdk";
2
+ import * as preact0 from "preact";
3
+
4
+ //#region src/components/ButtonShare/types.d.ts
5
+
6
+ /**
7
+ * The props type for {@link ButtonShare}.
8
+ * @inline
9
+ */
10
+ type ButtonShareProps = {
11
+ /**
12
+ * Text to display on the button
13
+ * - To specify where the reward should be displayed, use the placeholder `{REWARD}`, e.g. `Share and earn up to \{REWARD\}!`
14
+ * @defaultValue `"Share and earn!"`
15
+ */
16
+ text?: string;
17
+ /**
18
+ * Classname to apply to the button
19
+ */
20
+ classname?: string;
21
+ /**
22
+ * Do we display the reward on the share modal?
23
+ * @defaultValue `false`
24
+ */
25
+ useReward?: boolean;
26
+ /**
27
+ * Fallback text if the reward isn't found
28
+ */
29
+ noRewardText?: string;
30
+ /**
31
+ * Target interaction behind this sharing action (will be used to get the right reward to display)
32
+ */
33
+ targetInteraction?: FullInteractionTypesKey;
34
+ /**
35
+ * Do we display the wallet modal instead of the share modal?
36
+ * @defaultValue `false`
37
+ */
38
+ showWallet?: boolean;
39
+ };
40
+ //#endregion
41
+ //#region src/components/ButtonShare/ButtonShare.d.ts
42
+ /**
43
+ * Button to share the current page
44
+ *
45
+ * @param args
46
+ * @returns The share button with `<button>` tag
47
+ *
48
+ * @group components
49
+ *
50
+ * @example
51
+ * Basic usage:
52
+ * ```html
53
+ * <frak-button-share></frak-button-share>
54
+ * ```
55
+ *
56
+ * @example
57
+ * Using a custom text:
58
+ * ```html
59
+ * <frak-button-share text="Share and earn!"></frak-button-share>
60
+ * ```
61
+ *
62
+ * @example
63
+ * Using a custom class:
64
+ * ```html
65
+ * <frak-button-share classname="button button-primary"></frak-button-share>
66
+ * ```
67
+ *
68
+ * @example
69
+ * Using reward information and fallback text:
70
+ * ```html
71
+ * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!"></frak-button-share>
72
+ * ```
73
+ *
74
+ * @example
75
+ * Using reward information for specific reward and fallback text:
76
+ * ```html
77
+ * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="retail.customerMeeting"></frak-button-share>
78
+ * ```
79
+ *
80
+ * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
81
+ * @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the estimated reward fetching
82
+ */
83
+ declare function ButtonShare({
84
+ text,
85
+ classname,
86
+ useReward: rawUseReward,
87
+ noRewardText,
88
+ targetInteraction,
89
+ showWallet: rawShowWallet
90
+ }: ButtonShareProps): preact0.JSX.Element;
91
+ //#endregion
92
+ //#region src/components/ButtonShare/index.d.ts
93
+ interface ButtonShareElement extends HTMLElement, ButtonShareProps {}
94
+ declare global {
95
+ interface HTMLElementTagNameMap {
96
+ "frak-button-share": ButtonShareElement;
97
+ }
98
+ }
99
+ //#endregion
100
+ export { ButtonShare, ButtonShareElement };
@@ -1 +1,343 @@
1
- import e from"preact-custom-element";import{DebugInfoGatherer as t,formatAmount as n,getCurrencyAmountKey as o,setupClient as r,trackEvent as a}from"@frak-labs/core-sdk";import{displayEmbeddedWallet as i,getProductInformation as l,modalBuilder as d,referralInteraction as s}from"@frak-labs/core-sdk/actions";import{Fragment as c,jsx as u,jsxs as p}from"preact/jsx-runtime";import{cx as f}from"class-variance-authority";import{useCallback as m,useEffect as w,useMemo as g,useState as k}from"preact/hooks";import{FrakRpcError as h,RpcErrorCodes as S}from"@frak-labs/frame-connector";import*as y from"@frak-labs/core-sdk/bundle";let b="frakClientReady";function F(e,t){if(window.FrakSetup?.client&&"add"===e)return void t();("add"===e?window.addEventListener:window.removeEventListener)(b,t,!1)}async function v(e){console.log("referral",await s(e,{modalConfig:window.FrakSetup?.modalWalletConfig}))}async function x(){if(window.FrakSetup.core=y,!(window.frakSetupInProgress?(console.log("[Frak SDK] Initialization already in progress"),!1):window.FrakSetup?.client?(console.log("[Frak SDK] Client already initialized"),!1):!!window.FrakSetup?.config||(console.error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set."),!1)))return;if(console.log("[Frak SDK] Starting initialization"),window.frakSetupInProgress=!0,!window.FrakSetup.config){console.error("[Frak SDK] Configuration not found"),window.frakSetupInProgress=!1;return}let e=await r({config:window.FrakSetup.config});if(!e){console.error("[Frak SDK] Failed to create client"),window.frakSetupInProgress=!1;return}window.FrakSetup.client=e,console.log("[Frak SDK] Client initialized successfully");let t=new CustomEvent(b);window.dispatchEvent(t),window.modalBuilderSteps=d(e,window.FrakSetup?.modalConfig??{}),v(e),window.frakSetupInProgress=!1,function(){let e=new URLSearchParams(window.location.search).get("frakAction");e&&"share"===e&&(console.log("[Frak SDK] Auto open query param found"),function(){if(!window.FrakSetup?.client)return console.error("Frak client not found");"vibrate"in navigator?navigator.vibrate(10):console.log("Vibration not supported"),i(window.FrakSetup.client,window.FrakSetup?.modalWalletConfig??{})}())}()}let C="spinner__leaf-xtOJmT",D=({ref:e,className:t,...n})=>p("span",{...n,ref:e,className:f("spinner-KHk8mw"),children:[u("span",{className:C}),u("span",{className:C}),u("span",{className:C}),u("span",{className:C}),u("span",{className:C}),u("span",{className:C}),u("span",{className:C}),u("span",{className:C})]});async function E({targetInteraction:e}){let t=window.FrakSetup?.client;if(!t)return void console.warn("Frak client not ready yet");let{maxReferrer:r,rewards:a}=await l(t);if(!r)return;let i=o(t.config.metadata?.currency),d=Math.round(r[i]);if(e){let t=a.filter(t=>t.interactionTypeKey===e).map(e=>e.referrer[i]).reduce((e,t)=>t>e?t:e,0);t>0&&(d=Math.round(t))}return n(d,t.config.metadata?.currency)}D.displayName="Spinner";let I={marginTop:"16px",padding:"16px",backgroundColor:"#FEE2E2",border:"1px solid #FCA5A5",borderRadius:"4px",color:"#991B1B"},B={display:"flex",alignItems:"center",gap:"8px",marginBottom:"12px"},N={margin:0,fontSize:"16px",fontWeight:500},R={fontSize:"14px",lineHeight:"1.5",margin:"0 0 12px 0"},z={color:"#991B1B",textDecoration:"underline",textUnderlineOffset:"2px"},K={display:"inline-flex",alignItems:"center",gap:"8px",marginBottom:"10px",padding:"8px 12px",backgroundColor:"white",border:"1px solid #D1D5DB",borderRadius:"4px",color:"black",fontSize:"14px",fontWeight:500};function W({debugInfo:e}){let[t,n]=k(!1);return p("div",{children:[u("button",{type:"button",style:K,onClick:()=>n(!t),children:"Ouvrir les informations"}),t&&u("textarea",{style:{display:"block",width:"100%",height:"200px",fontSize:"12px"},children:e})]})}function A({debugInfo:e}){let{copied:t,copy:n}=function(e={}){let{successDuration:t=2e3}=e,[n,o]=k(!1);return{copy:m(async e=>{try{if(navigator.clipboard&&window.isSecureContext)await navigator.clipboard.writeText(e),o(!0);else{let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.focus(),t.select();try{document.execCommand("copy"),o(!0)}catch(e){return console.error("Failed to copy text:",e),!1}finally{t.remove()}}return setTimeout(()=>{o(!1)},t),!0}catch(e){return console.error("Failed to copy text:",e),!1}},[t]),copied:n}}();return p("div",{style:I,children:[u("div",{style:B,children:u("h3",{style:N,children:"Oups ! Nous avons rencontr\xe9 un petit probl\xe8me"})}),p("p",{style:R,children:["Impossible d'ouvrir le menu de partage pour le moment. Si le probl\xe8me persiste, copiez les informations ci-dessous et collez-les dans votre mail \xe0"," ",u("a",{href:"mailto:help@frak-labs.com?subject=Debug",style:z,children:"help@frak-labs.com"})," ",u("br",{}),"Merci pour votre retour, nous traitons votre demande dans les plus brefs d\xe9lais."]}),u("button",{type:"button",onClick:()=>n(e??""),style:K,children:t?"Informations copi\xe9es !":"Copier les informations de d\xe9bogage"}),u(W,{debugInfo:e})]})}async function P(){if(!window.FrakSetup?.client)throw Error("Frak client not found");await i(window.FrakSetup.client,window.FrakSetup?.modalWalletConfig??{})}function L({text:e="Share and earn!",classname:n="",useReward:o,noRewardText:r,targetInteraction:i,showWallet:l}){let d=g(()=>void 0!==o,[o]),s=g(()=>void 0!==l,[l]),{isClientReady:y}=function(){let[e,t]=k(!0),n=m(()=>{t(!1)},[]);return w(()=>(F("add",n),()=>F("remove",n)),[n]),{isClientReady:!e}}(),{reward:b}=function(e,t){let[n,o]=k(void 0);return w(()=>{e&&E({targetInteraction:t}).then(e=>{e&&o(e)})},[e,t]),{reward:n}}(d&&y,i),{handleShare:v,isError:x,debugInfo:C}=function(e){let[n,o]=k(void 0),[r,i]=k(!1);return{handleShare:m(async()=>{if(!window.FrakSetup?.client){console.error("Frak client not found"),o(t.empty().formatDebugInfo("Frak client not found")),i(!0);return}let n=function(){if(!window.modalBuilderSteps)throw Error("modalBuilderSteps not found");return window.modalBuilderSteps}();if(!n)throw Error("modalBuilderSteps not found");try{await n.sharing(window.FrakSetup?.modalShareConfig??{}).display(t=>({...t,targetInteraction:e}))}catch(t){if(t instanceof h&&t.code===S.clientAborted)return void console.debug("User aborted the modal");let e=window.FrakSetup.client.debugInfo.formatDebugInfo(t);a(window.FrakSetup.client,"share_modal_error",{error:t instanceof Object&&"message"in t?t.message:"Unknown error",debugInfo:e}),o(e),i(!0),console.error("Error while opening the modal",t)}},[e]),isError:r,debugInfo:n}}(i),I=g(()=>d?b?e.includes("{REWARD}")?e.replace("{REWARD}",b):`${e} ${b}`:r??e.replace("{REWARD}",""):e,[d,e,r,b]),B=m(async()=>{a(window.FrakSetup.client,"share_button_clicked"),s?await P():await v()},[s,v]);return p(c,{children:[p("button",{type:"button",className:f("buttonShare-F23Y9m",n,"override"),onClick:B,children:[!y&&u(D,{})," ",I]}),x&&u(A,{debugInfo:C})]})}!function(t,n,o=[],r={shadow:!1}){"undefined"!=typeof window&&("complete"===document.readyState||"interactive"===document.readyState?setTimeout(x,1):document.addEventListener?document.addEventListener("DOMContentLoaded",x):document.attachEvent("onreadystatechange",()=>{"complete"===document.readyState&&x()}),customElements.get(n)||e(t,n,o,r))}(L,"frak-button-share",["text"],{shadow:!1});export{L as ButtonShare};
1
+ import { i as getModalBuilderSteps, n as useClientReady, r as registerWebComponent, t as useReward } from "./useReward-1io3tiHR.js";
2
+ import { DebugInfoGatherer, trackEvent } from "@frak-labs/core-sdk";
3
+ import { displayEmbeddedWallet } from "@frak-labs/core-sdk/actions";
4
+ import { cx } from "class-variance-authority";
5
+ import { useCallback, useMemo, useState } from "preact/hooks";
6
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
7
+ import { FrakRpcError, RpcErrorCodes } from "@frak-labs/frame-connector";
8
+
9
+ //#region src/components/Spinner/index.module.css?css_module
10
+ const classes$1 = {
11
+ "spinner__leaf": "M4fSKa_spinner__leaf",
12
+ "rt-spinner-leaf-fade": "M4fSKa_rt-spinner-leaf-fade",
13
+ "spinner": "M4fSKa_spinner"
14
+ };
15
+ var index_module_default = classes$1;
16
+ const _spinner__leaf0 = classes$1["spinner__leaf"];
17
+ const _rt_spinner_leaf_fade0 = classes$1["rt-spinner-leaf-fade"];
18
+ const _spinner0 = classes$1["spinner"];
19
+
20
+ //#endregion
21
+ //#region src/components/Spinner/index.tsx
22
+ const Spinner = ({ ref, className, ...props }) => {
23
+ return /* @__PURE__ */ jsxs("span", {
24
+ ...props,
25
+ ref,
26
+ className: cx(index_module_default.spinner),
27
+ children: [
28
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
29
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
30
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
31
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
32
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
33
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
34
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf }),
35
+ /* @__PURE__ */ jsx("span", { className: index_module_default.spinner__leaf })
36
+ ]
37
+ });
38
+ };
39
+ Spinner.displayName = "Spinner";
40
+
41
+ //#endregion
42
+ //#region src/components/ButtonShare/ButtonShare.module.css?css_module
43
+ const classes = { "buttonShare": "nOB7Uq_buttonShare" };
44
+ var ButtonShare_module_default = classes;
45
+ const _buttonShare0 = classes["buttonShare"];
46
+
47
+ //#endregion
48
+ //#region src/hooks/useCopyToClipboard.ts
49
+ function useCopyToClipboard(options = {}) {
50
+ const { successDuration = 2e3 } = options;
51
+ const [copied, setCopied] = useState(false);
52
+ return {
53
+ copy: useCallback(async (text) => {
54
+ try {
55
+ if (navigator.clipboard && window.isSecureContext) {
56
+ await navigator.clipboard.writeText(text);
57
+ setCopied(true);
58
+ } else {
59
+ const textArea = document.createElement("textarea");
60
+ textArea.value = text;
61
+ textArea.style.position = "fixed";
62
+ textArea.style.opacity = "0";
63
+ document.body.appendChild(textArea);
64
+ textArea.focus();
65
+ textArea.select();
66
+ try {
67
+ document.execCommand("copy");
68
+ setCopied(true);
69
+ } catch (err) {
70
+ console.error("Failed to copy text:", err);
71
+ return false;
72
+ } finally {
73
+ textArea.remove();
74
+ }
75
+ }
76
+ setTimeout(() => {
77
+ setCopied(false);
78
+ }, successDuration);
79
+ return true;
80
+ } catch (err) {
81
+ console.error("Failed to copy text:", err);
82
+ return false;
83
+ }
84
+ }, [successDuration]),
85
+ copied
86
+ };
87
+ }
88
+
89
+ //#endregion
90
+ //#region src/components/ButtonShare/components/ErrorMessage.tsx
91
+ const styles = {
92
+ errorContainer: {
93
+ marginTop: "16px",
94
+ padding: "16px",
95
+ backgroundColor: "#FEE2E2",
96
+ border: "1px solid #FCA5A5",
97
+ borderRadius: "4px",
98
+ color: "#991B1B"
99
+ },
100
+ header: {
101
+ display: "flex",
102
+ alignItems: "center",
103
+ gap: "8px",
104
+ marginBottom: "12px"
105
+ },
106
+ title: {
107
+ margin: 0,
108
+ fontSize: "16px",
109
+ fontWeight: 500
110
+ },
111
+ message: {
112
+ fontSize: "14px",
113
+ lineHeight: "1.5",
114
+ margin: "0 0 12px 0"
115
+ },
116
+ link: {
117
+ color: "#991B1B",
118
+ textDecoration: "underline",
119
+ textUnderlineOffset: "2px"
120
+ },
121
+ copyButton: {
122
+ display: "inline-flex",
123
+ alignItems: "center",
124
+ gap: "8px",
125
+ marginBottom: "10px",
126
+ padding: "8px 12px",
127
+ backgroundColor: "white",
128
+ border: "1px solid #D1D5DB",
129
+ borderRadius: "4px",
130
+ color: "black",
131
+ fontSize: "14px",
132
+ fontWeight: 500
133
+ }
134
+ };
135
+ /**
136
+ * Renders a toggleable debug information section
137
+ * @param {Object} props - Component props
138
+ * @param {string} [props.debugInfo] - Debug information to display in textarea
139
+ */
140
+ function ToggleMessage({ debugInfo }) {
141
+ const [showInfo, setShowInfo] = useState(false);
142
+ return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("button", {
143
+ type: "button",
144
+ style: styles.copyButton,
145
+ onClick: () => setShowInfo(!showInfo),
146
+ children: "Ouvrir les informations"
147
+ }), showInfo && /* @__PURE__ */ jsx("textarea", {
148
+ style: {
149
+ display: "block",
150
+ width: "100%",
151
+ height: "200px",
152
+ fontSize: "12px"
153
+ },
154
+ children: debugInfo
155
+ })] });
156
+ }
157
+ /**
158
+ * Displays an error message with debug information and copy functionality
159
+ * @param {Object} props - Component props
160
+ * @param {string} [props.debugInfo] - Debug information that can be copied or displayed
161
+ */
162
+ function ErrorMessage({ debugInfo }) {
163
+ const { copied, copy } = useCopyToClipboard();
164
+ return /* @__PURE__ */ jsxs("div", {
165
+ style: styles.errorContainer,
166
+ children: [
167
+ /* @__PURE__ */ jsx("div", {
168
+ style: styles.header,
169
+ children: /* @__PURE__ */ jsx("h3", {
170
+ style: styles.title,
171
+ children: "Oups ! Nous avons rencontré un petit problème"
172
+ })
173
+ }),
174
+ /* @__PURE__ */ jsxs("p", {
175
+ style: styles.message,
176
+ children: [
177
+ "Impossible d'ouvrir le menu de partage pour le moment. Si le problème persiste, copiez les informations ci-dessous et collez-les dans votre mail à",
178
+ " ",
179
+ /* @__PURE__ */ jsx("a", {
180
+ href: "mailto:help@frak-labs.com?subject=Debug",
181
+ style: styles.link,
182
+ children: "help@frak-labs.com"
183
+ }),
184
+ " ",
185
+ /* @__PURE__ */ jsx("br", {}),
186
+ "Merci pour votre retour, nous traitons votre demande dans les plus brefs délais."
187
+ ]
188
+ }),
189
+ /* @__PURE__ */ jsx("button", {
190
+ type: "button",
191
+ onClick: () => copy(debugInfo ?? ""),
192
+ style: styles.copyButton,
193
+ children: copied ? "Informations copiées !" : "Copier les informations de débogage"
194
+ }),
195
+ /* @__PURE__ */ jsx(ToggleMessage, { debugInfo })
196
+ ]
197
+ });
198
+ }
199
+
200
+ //#endregion
201
+ //#region src/components/ButtonShare/hooks/useShareModal.ts
202
+ /**
203
+ * Open the share modal
204
+ *
205
+ * @description
206
+ * This function will open the share modal with the configuration provided in the `window.FrakSetup.modalShareConfig` object.
207
+ */
208
+ function useShareModal(targetInteraction) {
209
+ const [debugInfo, setDebugInfo] = useState(void 0);
210
+ const [isError, setIsError] = useState(false);
211
+ return {
212
+ handleShare: useCallback(async () => {
213
+ if (!window.FrakSetup?.client) {
214
+ console.error("Frak client not found");
215
+ setDebugInfo(DebugInfoGatherer.empty().formatDebugInfo("Frak client not found"));
216
+ setIsError(true);
217
+ return;
218
+ }
219
+ const modalBuilderSteps = getModalBuilderSteps();
220
+ if (!modalBuilderSteps) throw new Error("modalBuilderSteps not found");
221
+ try {
222
+ await modalBuilderSteps.sharing(window.FrakSetup?.modalShareConfig ?? {}).display((metadata) => ({
223
+ ...metadata,
224
+ targetInteraction
225
+ }));
226
+ } catch (e) {
227
+ if (e instanceof FrakRpcError && e.code === RpcErrorCodes.clientAborted) {
228
+ console.debug("User aborted the modal");
229
+ return;
230
+ }
231
+ const debugInfo$1 = window.FrakSetup.client.debugInfo.formatDebugInfo(e);
232
+ trackEvent(window.FrakSetup.client, "share_modal_error", {
233
+ error: e instanceof Object && "message" in e ? e.message : "Unknown error",
234
+ debugInfo: debugInfo$1
235
+ });
236
+ setDebugInfo(debugInfo$1);
237
+ setIsError(true);
238
+ console.error("Error while opening the modal", e);
239
+ }
240
+ }, [targetInteraction]),
241
+ isError,
242
+ debugInfo
243
+ };
244
+ }
245
+
246
+ //#endregion
247
+ //#region src/components/ButtonShare/ButtonShare.tsx
248
+ /**
249
+ * Open the embedded wallet modal
250
+ *
251
+ * @description
252
+ * This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
253
+ */
254
+ async function modalEmbeddedWallet() {
255
+ if (!window.FrakSetup?.client) throw new Error("Frak client not found");
256
+ await displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
257
+ }
258
+ /**
259
+ * Button to share the current page
260
+ *
261
+ * @param args
262
+ * @returns The share button with `<button>` tag
263
+ *
264
+ * @group components
265
+ *
266
+ * @example
267
+ * Basic usage:
268
+ * ```html
269
+ * <frak-button-share></frak-button-share>
270
+ * ```
271
+ *
272
+ * @example
273
+ * Using a custom text:
274
+ * ```html
275
+ * <frak-button-share text="Share and earn!"></frak-button-share>
276
+ * ```
277
+ *
278
+ * @example
279
+ * Using a custom class:
280
+ * ```html
281
+ * <frak-button-share classname="button button-primary"></frak-button-share>
282
+ * ```
283
+ *
284
+ * @example
285
+ * Using reward information and fallback text:
286
+ * ```html
287
+ * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!"></frak-button-share>
288
+ * ```
289
+ *
290
+ * @example
291
+ * Using reward information for specific reward and fallback text:
292
+ * ```html
293
+ * <frak-button-share use-reward text="Share and earn up to {REWARD}!" no-reward-text="Share and earn!" target-interaction="retail.customerMeeting"></frak-button-share>
294
+ * ```
295
+ *
296
+ * @see {@link @frak-labs/core-sdk!actions.modalBuilder | `modalBuilder()`} for more info about the modal display
297
+ * @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the estimated reward fetching
298
+ */
299
+ function ButtonShare({ text = "Share and earn!", classname = "", useReward: rawUseReward, noRewardText, targetInteraction, showWallet: rawShowWallet }) {
300
+ const shouldUseReward = useMemo(() => rawUseReward !== void 0, [rawUseReward]);
301
+ const showWallet = useMemo(() => rawShowWallet !== void 0, [rawShowWallet]);
302
+ const { isClientReady } = useClientReady();
303
+ const { reward } = useReward(shouldUseReward && isClientReady, targetInteraction);
304
+ const { handleShare, isError, debugInfo } = useShareModal(targetInteraction);
305
+ /**
306
+ * Compute the text we will display
307
+ */
308
+ const btnText = useMemo(() => {
309
+ if (!shouldUseReward) return text;
310
+ if (!reward) return noRewardText ?? text.replace("{REWARD}", "");
311
+ return text.includes("{REWARD}") ? text.replace("{REWARD}", reward) : `${text} ${reward}`;
312
+ }, [
313
+ shouldUseReward,
314
+ text,
315
+ noRewardText,
316
+ reward
317
+ ]);
318
+ /**
319
+ * The action when the button is clicked
320
+ */
321
+ const onClick = useCallback(async () => {
322
+ trackEvent(window.FrakSetup.client, "share_button_clicked");
323
+ if (showWallet) await modalEmbeddedWallet();
324
+ else await handleShare();
325
+ }, [showWallet, handleShare]);
326
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("button", {
327
+ type: "button",
328
+ className: cx(ButtonShare_module_default.buttonShare, classname, "override"),
329
+ onClick,
330
+ children: [
331
+ !isClientReady && /* @__PURE__ */ jsx(Spinner, {}),
332
+ " ",
333
+ btnText
334
+ ]
335
+ }), isError && /* @__PURE__ */ jsx(ErrorMessage, { debugInfo })] });
336
+ }
337
+
338
+ //#endregion
339
+ //#region src/components/ButtonShare/index.ts
340
+ registerWebComponent(ButtonShare, "frak-button-share", ["text"], { shadow: false });
341
+
342
+ //#endregion
343
+ export { ButtonShare };
@@ -1 +1 @@
1
- .button-aPZnsb{all:unset;z-index:2000000;cursor:pointer;text-align:center;background-color:#3e557e;border-radius:50%;justify-content:center;align-items:center;width:45px;height:45px;font-size:24px;display:flex;position:fixed;bottom:20px}.button__left-fQJUnK{left:20px}.button__right-TkFFFK{right:20px}.reward-w5dm3K{color:#fff;white-space:nowrap;background:#ff3f3f;border-radius:5px;padding:2px 3px;font-size:9px;font-weight:600;line-height:9px;position:absolute;top:-4px;right:27px}
1
+ .Kl62ia_button{all:unset;z-index:2000000;cursor:pointer;text-align:center;background-color:#3e557e;border-radius:50%;justify-content:center;align-items:center;width:45px;height:45px;font-size:24px;display:flex;position:fixed;bottom:20px}.Kl62ia_button__left{left:20px}.Kl62ia_button__right{right:20px}.Kl62ia_reward{color:#fff;white-space:nowrap;background:#ff3f3f;border-radius:5px;padding:2px 3px;font-size:9px;font-weight:600;line-height:9px;position:absolute;top:-4px;right:27px}