@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
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import register from "preact-custom-element";
|
|
2
|
-
import { setupClient } from "@frak-labs/core-sdk";
|
|
3
|
-
import * as coreSdk from "@frak-labs/core-sdk/bundle";
|
|
4
|
-
import { displayEmbeddedWallet, modalBuilder, referralInteraction } from "@frak-labs/core-sdk/actions";
|
|
5
|
-
import { useCallback, useEffect, useState } from "preact/hooks";
|
|
6
|
-
|
|
7
|
-
//#region ../../packages/ui/utils/onDocumentReady.ts
|
|
8
|
-
/**
|
|
9
|
-
* When the document is ready, run the callback
|
|
10
|
-
* @param callback
|
|
11
|
-
*/
|
|
12
|
-
function onDocumentReady(callback) {
|
|
13
|
-
if (document.readyState === "complete" || document.readyState === "interactive") setTimeout(callback, 1);
|
|
14
|
-
else if (document.addEventListener) document.addEventListener("DOMContentLoaded", callback);
|
|
15
|
-
else document.attachEvent("onreadystatechange", () => {
|
|
16
|
-
if (document.readyState === "complete") callback();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
//#region src/utils/safeVibrate.ts
|
|
22
|
-
/**
|
|
23
|
-
* Attempt to vibrate the device
|
|
24
|
-
*/
|
|
25
|
-
function safeVibrate() {
|
|
26
|
-
if ("vibrate" in navigator) navigator.vibrate(10);
|
|
27
|
-
else console.log("Vibration not supported");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region src/components/ButtonWallet/utils.ts
|
|
32
|
-
/**
|
|
33
|
-
* Open the wallet modal
|
|
34
|
-
*
|
|
35
|
-
* @description
|
|
36
|
-
* This function will open the wallet modal with the configuration provided in the `window.FrakSetup.modalWalletConfig` object.
|
|
37
|
-
*/
|
|
38
|
-
function openWalletModal() {
|
|
39
|
-
if (!window.FrakSetup?.client) {
|
|
40
|
-
console.error("Frak client not found");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
safeVibrate();
|
|
44
|
-
displayEmbeddedWallet(window.FrakSetup.client, window.FrakSetup?.modalWalletConfig ?? {});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/utils/clientReady.ts
|
|
49
|
-
const CUSTOM_EVENT_NAME = "frakClientReady";
|
|
50
|
-
/**
|
|
51
|
-
* Dispatch a custom event when the Frak client is ready
|
|
52
|
-
*/
|
|
53
|
-
function dispatchClientReadyEvent() {
|
|
54
|
-
const event = new CustomEvent(CUSTOM_EVENT_NAME);
|
|
55
|
-
window.dispatchEvent(event);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Add or remove an event listener for when the Frak client is ready
|
|
59
|
-
* @param action
|
|
60
|
-
* @param callback
|
|
61
|
-
*/
|
|
62
|
-
function onClientReady(action, callback) {
|
|
63
|
-
if (window.FrakSetup?.client && action === "add") {
|
|
64
|
-
callback();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
(action === "add" ? window.addEventListener : window.removeEventListener)(CUSTOM_EVENT_NAME, callback, false);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
//#endregion
|
|
71
|
-
//#region src/utils/setup.ts
|
|
72
|
-
/**
|
|
73
|
-
* Setup the modal config
|
|
74
|
-
* @param client
|
|
75
|
-
*/
|
|
76
|
-
function setupModalConfig(client) {
|
|
77
|
-
window.modalBuilderSteps = modalBuilder(client, window.FrakSetup?.modalConfig ?? {});
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Setup the referral
|
|
81
|
-
* @param client
|
|
82
|
-
*/
|
|
83
|
-
async function setupReferral(client) {
|
|
84
|
-
const referral = await referralInteraction(client);
|
|
85
|
-
console.log("referral", referral);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Return the modal builder steps
|
|
89
|
-
*/
|
|
90
|
-
function getModalBuilderSteps() {
|
|
91
|
-
if (!window.modalBuilderSteps) throw new Error("modalBuilderSteps not found");
|
|
92
|
-
return window.modalBuilderSteps;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/utils/initFrakSdk.ts
|
|
97
|
-
/**
|
|
98
|
-
* Initializes the Frak SDK client and sets up necessary configurations.
|
|
99
|
-
* This function handles the one-time setup of the Frak client and related features.
|
|
100
|
-
*
|
|
101
|
-
* @returns {Promise<void>}
|
|
102
|
-
*/
|
|
103
|
-
async function initFrakSdk() {
|
|
104
|
-
window.FrakSetup.core = coreSdk;
|
|
105
|
-
if (!preChecks()) return;
|
|
106
|
-
console.log("[Frak SDK] Starting initialization");
|
|
107
|
-
if (!window.FrakSetup.config) {
|
|
108
|
-
console.error("[Frak SDK] Configuration not found");
|
|
109
|
-
window.frakSetupInProgress = false;
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const client = await setupClient({ config: window.FrakSetup.config });
|
|
113
|
-
if (!client) {
|
|
114
|
-
console.error("[Frak SDK] Failed to create client");
|
|
115
|
-
window.frakSetupInProgress = false;
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
window.FrakSetup.client = client;
|
|
119
|
-
console.log("[Frak SDK] Client initialized successfully");
|
|
120
|
-
dispatchClientReadyEvent();
|
|
121
|
-
setupModalConfig(client);
|
|
122
|
-
setupReferral(client);
|
|
123
|
-
window.frakSetupInProgress = false;
|
|
124
|
-
handleActionQueryParam();
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Pre-checks for the Frak SDK initialization
|
|
128
|
-
* Sets frakSetupInProgress flag atomically to prevent race conditions
|
|
129
|
-
*/
|
|
130
|
-
function preChecks() {
|
|
131
|
-
if (window.frakSetupInProgress) {
|
|
132
|
-
console.log("[Frak SDK] Initialization already in progress");
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
window.frakSetupInProgress = true;
|
|
136
|
-
if (window.FrakSetup?.client) {
|
|
137
|
-
console.log("[Frak SDK] Client already initialized");
|
|
138
|
-
window.frakSetupInProgress = false;
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
if (!window.FrakSetup?.config) {
|
|
142
|
-
console.error("[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.");
|
|
143
|
-
window.frakSetupInProgress = false;
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Check the query param contain params for an auto opening of the frak modal
|
|
150
|
-
*/
|
|
151
|
-
function handleActionQueryParam() {
|
|
152
|
-
const frakAction = new URLSearchParams(window.location.search).get("frakAction");
|
|
153
|
-
if (!frakAction) return;
|
|
154
|
-
if (frakAction === "share") {
|
|
155
|
-
console.log("[Frak SDK] Auto open query param found");
|
|
156
|
-
openWalletModal();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region src/utils/registerWebComponent.ts
|
|
162
|
-
/**
|
|
163
|
-
* Registers a Preact component as a custom web component
|
|
164
|
-
*
|
|
165
|
-
* @param component - The Preact component to register
|
|
166
|
-
* @param tagName - The custom element tag name (e.g., "frak-button-wallet")
|
|
167
|
-
* @param observedAttributes - Array of attribute names to observe for changes
|
|
168
|
-
* @param options - Registration options (e.g., { shadow: false })
|
|
169
|
-
*/
|
|
170
|
-
function registerWebComponent(component, tagName, observedAttributes = [], options = { shadow: false }) {
|
|
171
|
-
if (typeof window !== "undefined") {
|
|
172
|
-
onDocumentReady(initFrakSdk);
|
|
173
|
-
if (!customElements.get(tagName)) register(component, tagName, observedAttributes, options);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/hooks/useClientReady.ts
|
|
179
|
-
/**
|
|
180
|
-
* Hook to manage client readiness state for the wallet button
|
|
181
|
-
* Handles subscription to client ready events and manages readiness state
|
|
182
|
-
* @returns Object containing the readiness state of the client
|
|
183
|
-
*/
|
|
184
|
-
function useClientReady() {
|
|
185
|
-
const [disabled, setDisabled] = useState(true);
|
|
186
|
-
const handleClientReady = useCallback(() => {
|
|
187
|
-
setDisabled(false);
|
|
188
|
-
}, []);
|
|
189
|
-
useEffect(() => {
|
|
190
|
-
onClientReady("add", handleClientReady);
|
|
191
|
-
return () => onClientReady("remove", handleClientReady);
|
|
192
|
-
}, [handleClientReady]);
|
|
193
|
-
return { isClientReady: !disabled };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
//#endregion
|
|
197
|
-
export { openWalletModal as i, registerWebComponent as n, getModalBuilderSteps as r, useClientReady as t };
|