@0xkey-io/react-wallet-kit 0.1.0
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/LICENSE +201 -0
- package/README.MD +116 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs +307 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.mjs.map +1 -0
- package/dist/components/auth/Action.d.ts +10 -0
- package/dist/components/auth/Action.d.ts.map +1 -0
- package/dist/components/auth/Action.js +76 -0
- package/dist/components/auth/Action.js.map +1 -0
- package/dist/components/auth/Action.mjs +97 -0
- package/dist/components/auth/Action.mjs.map +1 -0
- package/dist/components/auth/Email.d.ts +6 -0
- package/dist/components/auth/Email.d.ts.map +1 -0
- package/dist/components/auth/Email.js +77 -0
- package/dist/components/auth/Email.js.map +1 -0
- package/dist/components/auth/Email.mjs +98 -0
- package/dist/components/auth/Email.mjs.map +1 -0
- package/dist/components/auth/OAuth.d.ts +13 -0
- package/dist/components/auth/OAuth.d.ts.map +1 -0
- package/dist/components/auth/OAuth.js +63 -0
- package/dist/components/auth/OAuth.js.map +1 -0
- package/dist/components/auth/OAuth.mjs +68 -0
- package/dist/components/auth/OAuth.mjs.map +1 -0
- package/dist/components/auth/OTP.d.ts +21 -0
- package/dist/components/auth/OTP.d.ts.map +1 -0
- package/dist/components/auth/OTP.js +218 -0
- package/dist/components/auth/OTP.js.map +1 -0
- package/dist/components/auth/OTP.mjs +301 -0
- package/dist/components/auth/OTP.mjs.map +1 -0
- package/dist/components/auth/OrSeparator.d.ts +2 -0
- package/dist/components/auth/OrSeparator.d.ts.map +1 -0
- package/dist/components/auth/OrSeparator.js +20 -0
- package/dist/components/auth/OrSeparator.js.map +1 -0
- package/dist/components/auth/OrSeparator.mjs +18 -0
- package/dist/components/auth/OrSeparator.mjs.map +1 -0
- package/dist/components/auth/Passkey.d.ts +7 -0
- package/dist/components/auth/Passkey.d.ts.map +1 -0
- package/dist/components/auth/Passkey.js +34 -0
- package/dist/components/auth/Passkey.js.map +1 -0
- package/dist/components/auth/Passkey.mjs +30 -0
- package/dist/components/auth/Passkey.mjs.map +1 -0
- package/dist/components/auth/Phone.d.ts +6 -0
- package/dist/components/auth/Phone.d.ts.map +1 -0
- package/dist/components/auth/Phone.js +67 -0
- package/dist/components/auth/Phone.js.map +1 -0
- package/dist/components/auth/Phone.mjs +92 -0
- package/dist/components/auth/Phone.mjs.map +1 -0
- package/dist/components/auth/Wallet.d.ts +34 -0
- package/dist/components/auth/Wallet.d.ts.map +1 -0
- package/dist/components/auth/Wallet.js +517 -0
- package/dist/components/auth/Wallet.js.map +1 -0
- package/dist/components/auth/Wallet.mjs +618 -0
- package/dist/components/auth/Wallet.mjs.map +1 -0
- package/dist/components/auth/index.d.ts +9 -0
- package/dist/components/auth/index.d.ts.map +1 -0
- package/dist/components/auth/index.js +457 -0
- package/dist/components/auth/index.js.map +1 -0
- package/dist/components/auth/index.mjs +672 -0
- package/dist/components/auth/index.mjs.map +1 -0
- package/dist/components/design/Buttons.d.ts +29 -0
- package/dist/components/design/Buttons.d.ts.map +1 -0
- package/dist/components/design/Buttons.js +87 -0
- package/dist/components/design/Buttons.js.map +1 -0
- package/dist/components/design/Buttons.mjs +79 -0
- package/dist/components/design/Buttons.mjs.map +1 -0
- package/dist/components/design/Failure.d.ts +9 -0
- package/dist/components/design/Failure.d.ts.map +1 -0
- package/dist/components/design/Failure.js +33 -0
- package/dist/components/design/Failure.js.map +1 -0
- package/dist/components/design/Failure.mjs +34 -0
- package/dist/components/design/Failure.mjs.map +1 -0
- package/dist/components/design/Inputs.d.ts +9 -0
- package/dist/components/design/Inputs.d.ts.map +1 -0
- package/dist/components/design/Inputs.js +135 -0
- package/dist/components/design/Inputs.js.map +1 -0
- package/dist/components/design/Inputs.mjs +133 -0
- package/dist/components/design/Inputs.mjs.map +1 -0
- package/dist/components/design/Lottie/Dynamic.d.ts +2 -0
- package/dist/components/design/Lottie/Dynamic.d.ts.map +1 -0
- package/dist/components/design/Lottie/Dynamic.js +9 -0
- package/dist/components/design/Lottie/Dynamic.js.map +1 -0
- package/dist/components/design/Lottie/Dynamic.mjs +24 -0
- package/dist/components/design/Lottie/Dynamic.mjs.map +1 -0
- package/dist/components/design/Lottie/Wrapper.d.ts +8 -0
- package/dist/components/design/Lottie/Wrapper.d.ts.map +1 -0
- package/dist/components/design/Lottie/Wrapper.js +26 -0
- package/dist/components/design/Lottie/Wrapper.js.map +1 -0
- package/dist/components/design/Lottie/Wrapper.mjs +42 -0
- package/dist/components/design/Lottie/Wrapper.mjs.map +1 -0
- package/dist/components/design/Spinners.d.ts +9 -0
- package/dist/components/design/Spinners.d.ts.map +1 -0
- package/dist/components/design/Spinners.js +38 -0
- package/dist/components/design/Spinners.js.map +1 -0
- package/dist/components/design/Spinners.mjs +37 -0
- package/dist/components/design/Spinners.mjs.map +1 -0
- package/dist/components/design/Success.d.ts +8 -0
- package/dist/components/design/Success.d.ts.map +1 -0
- package/dist/components/design/Success.js +82 -0
- package/dist/components/design/Success.js.map +1 -0
- package/dist/components/design/Success.mjs +86 -0
- package/dist/components/design/Success.mjs.map +1 -0
- package/dist/components/design/Svg.d.ts +13 -0
- package/dist/components/design/Svg.d.ts.map +1 -0
- package/dist/components/design/Svg.js +165 -0
- package/dist/components/design/Svg.js.map +1 -0
- package/dist/components/design/Svg.mjs +161 -0
- package/dist/components/design/Svg.mjs.map +1 -0
- package/dist/components/export/Export.d.ts +13 -0
- package/dist/components/export/Export.d.ts.map +1 -0
- package/dist/components/export/Export.js +169 -0
- package/dist/components/export/Export.js.map +1 -0
- package/dist/components/export/Export.mjs +213 -0
- package/dist/components/export/Export.mjs.map +1 -0
- package/dist/components/export/ExportWarning.d.ts +15 -0
- package/dist/components/export/ExportWarning.d.ts.map +1 -0
- package/dist/components/export/ExportWarning.js +141 -0
- package/dist/components/export/ExportWarning.js.map +1 -0
- package/dist/components/export/ExportWarning.mjs +174 -0
- package/dist/components/export/ExportWarning.mjs.map +1 -0
- package/dist/components/import/Import.d.ts +20 -0
- package/dist/components/import/Import.d.ts.map +1 -0
- package/dist/components/import/Import.js +290 -0
- package/dist/components/import/Import.js.map +1 -0
- package/dist/components/import/Import.mjs +422 -0
- package/dist/components/import/Import.mjs.map +1 -0
- package/dist/components/onramp/OnRamp.d.ts +14 -0
- package/dist/components/onramp/OnRamp.d.ts.map +1 -0
- package/dist/components/onramp/OnRamp.js +61 -0
- package/dist/components/onramp/OnRamp.js.map +1 -0
- package/dist/components/onramp/OnRamp.mjs +79 -0
- package/dist/components/onramp/OnRamp.mjs.map +1 -0
- package/dist/components/send-transaction/SendTransaction.d.ts +12 -0
- package/dist/components/send-transaction/SendTransaction.d.ts.map +1 -0
- package/dist/components/send-transaction/SendTransaction.js +65 -0
- package/dist/components/send-transaction/SendTransaction.js.map +1 -0
- package/dist/components/send-transaction/SendTransaction.mjs +89 -0
- package/dist/components/send-transaction/SendTransaction.mjs.map +1 -0
- package/dist/components/send-transaction/helpers.d.ts +4 -0
- package/dist/components/send-transaction/helpers.d.ts.map +1 -0
- package/dist/components/send-transaction/helpers.js +37 -0
- package/dist/components/send-transaction/helpers.js.map +1 -0
- package/dist/components/send-transaction/helpers.mjs +34 -0
- package/dist/components/send-transaction/helpers.mjs.map +1 -0
- package/dist/components/sign/Message.d.ts +18 -0
- package/dist/components/sign/Message.d.ts.map +1 -0
- package/dist/components/sign/Message.js +132 -0
- package/dist/components/sign/Message.js.map +1 -0
- package/dist/components/sign/Message.mjs +148 -0
- package/dist/components/sign/Message.mjs.map +1 -0
- package/dist/components/user/ConnectWallet.d.ts +8 -0
- package/dist/components/user/ConnectWallet.d.ts.map +1 -0
- package/dist/components/user/ConnectWallet.js +114 -0
- package/dist/components/user/ConnectWallet.js.map +1 -0
- package/dist/components/user/ConnectWallet.mjs +194 -0
- package/dist/components/user/ConnectWallet.mjs.map +1 -0
- package/dist/components/user/RemoveEmail.d.ts +12 -0
- package/dist/components/user/RemoveEmail.d.ts.map +1 -0
- package/dist/components/user/RemoveEmail.js +105 -0
- package/dist/components/user/RemoveEmail.js.map +1 -0
- package/dist/components/user/RemoveEmail.mjs +124 -0
- package/dist/components/user/RemoveEmail.mjs.map +1 -0
- package/dist/components/user/RemoveOAuthProvider.d.ts +12 -0
- package/dist/components/user/RemoveOAuthProvider.d.ts.map +1 -0
- package/dist/components/user/RemoveOAuthProvider.js +110 -0
- package/dist/components/user/RemoveOAuthProvider.js.map +1 -0
- package/dist/components/user/RemoveOAuthProvider.mjs +131 -0
- package/dist/components/user/RemoveOAuthProvider.mjs.map +1 -0
- package/dist/components/user/RemovePasskey.d.ts +12 -0
- package/dist/components/user/RemovePasskey.d.ts.map +1 -0
- package/dist/components/user/RemovePasskey.js +114 -0
- package/dist/components/user/RemovePasskey.js.map +1 -0
- package/dist/components/user/RemovePasskey.mjs +135 -0
- package/dist/components/user/RemovePasskey.mjs.map +1 -0
- package/dist/components/user/RemovePhoneNumber.d.ts +12 -0
- package/dist/components/user/RemovePhoneNumber.d.ts.map +1 -0
- package/dist/components/user/RemovePhoneNumber.js +105 -0
- package/dist/components/user/RemovePhoneNumber.js.map +1 -0
- package/dist/components/user/RemovePhoneNumber.mjs +124 -0
- package/dist/components/user/RemovePhoneNumber.mjs.map +1 -0
- package/dist/components/user/UpdateEmail.d.ts +12 -0
- package/dist/components/user/UpdateEmail.d.ts.map +1 -0
- package/dist/components/user/UpdateEmail.js +154 -0
- package/dist/components/user/UpdateEmail.js.map +1 -0
- package/dist/components/user/UpdateEmail.mjs +197 -0
- package/dist/components/user/UpdateEmail.mjs.map +1 -0
- package/dist/components/user/UpdatePhoneNumber.d.ts +12 -0
- package/dist/components/user/UpdatePhoneNumber.d.ts.map +1 -0
- package/dist/components/user/UpdatePhoneNumber.js +151 -0
- package/dist/components/user/UpdatePhoneNumber.js.map +1 -0
- package/dist/components/user/UpdatePhoneNumber.mjs +198 -0
- package/dist/components/user/UpdatePhoneNumber.mjs.map +1 -0
- package/dist/components/user/UpdateUserName.d.ts +13 -0
- package/dist/components/user/UpdateUserName.d.ts.map +1 -0
- package/dist/components/user/UpdateUserName.js +113 -0
- package/dist/components/user/UpdateUserName.js.map +1 -0
- package/dist/components/user/UpdateUserName.mjs +139 -0
- package/dist/components/user/UpdateUserName.mjs.map +1 -0
- package/dist/components/verify/Verify.d.ts +9 -0
- package/dist/components/verify/Verify.d.ts.map +1 -0
- package/dist/components/verify/Verify.js +121 -0
- package/dist/components/verify/Verify.js.map +1 -0
- package/dist/components/verify/Verify.mjs +149 -0
- package/dist/components/verify/Verify.mjs.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -0
- package/dist/providers/ZeroXKeyProvider.d.ts +9 -0
- package/dist/providers/ZeroXKeyProvider.d.ts.map +1 -0
- package/dist/providers/ZeroXKeyProvider.js +36 -0
- package/dist/providers/ZeroXKeyProvider.js.map +1 -0
- package/dist/providers/ZeroXKeyProvider.mjs +34 -0
- package/dist/providers/ZeroXKeyProvider.mjs.map +1 -0
- package/dist/providers/client/Hook.d.ts +4 -0
- package/dist/providers/client/Hook.d.ts.map +1 -0
- package/dist/providers/client/Hook.js +15 -0
- package/dist/providers/client/Hook.js.map +1 -0
- package/dist/providers/client/Hook.mjs +13 -0
- package/dist/providers/client/Hook.mjs.map +1 -0
- package/dist/providers/client/Provider.d.ts +39 -0
- package/dist/providers/client/Provider.d.ts.map +1 -0
- package/dist/providers/client/Provider.js +3934 -0
- package/dist/providers/client/Provider.js.map +1 -0
- package/dist/providers/client/Provider.mjs +6895 -0
- package/dist/providers/client/Provider.mjs.map +1 -0
- package/dist/providers/client/Types.d.ts +711 -0
- package/dist/providers/client/Types.d.ts.map +1 -0
- package/dist/providers/client/Types.js +10 -0
- package/dist/providers/client/Types.js.map +1 -0
- package/dist/providers/client/Types.mjs +8 -0
- package/dist/providers/client/Types.mjs.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/modal/Hook.d.ts +4 -0
- package/dist/providers/modal/Hook.d.ts.map +1 -0
- package/dist/providers/modal/Hook.js +15 -0
- package/dist/providers/modal/Hook.js.map +1 -0
- package/dist/providers/modal/Hook.mjs +13 -0
- package/dist/providers/modal/Hook.mjs.map +1 -0
- package/dist/providers/modal/Provider.d.ts +27 -0
- package/dist/providers/modal/Provider.d.ts.map +1 -0
- package/dist/providers/modal/Provider.js +48 -0
- package/dist/providers/modal/Provider.js.map +1 -0
- package/dist/providers/modal/Provider.mjs +68 -0
- package/dist/providers/modal/Provider.mjs.map +1 -0
- package/dist/providers/modal/Root.d.ts +7 -0
- package/dist/providers/modal/Root.d.ts.map +1 -0
- package/dist/providers/modal/Root.js +345 -0
- package/dist/providers/modal/Root.js.map +1 -0
- package/dist/providers/modal/Root.mjs +352 -0
- package/dist/providers/modal/Root.mjs.map +1 -0
- package/dist/providers/theme/Overrides.d.ts +18 -0
- package/dist/providers/theme/Overrides.d.ts.map +1 -0
- package/dist/providers/theme/Overrides.js +35 -0
- package/dist/providers/theme/Overrides.js.map +1 -0
- package/dist/providers/theme/Overrides.mjs +37 -0
- package/dist/providers/theme/Overrides.mjs.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/tests/oauth-test.d.ts +2 -0
- package/dist/tests/oauth-test.d.ts.map +1 -0
- package/dist/tests/timers-test.d.ts +2 -0
- package/dist/tests/timers-test.d.ts.map +1 -0
- package/dist/tests/utils-test.d.ts +2 -0
- package/dist/tests/utils-test.d.ts.map +1 -0
- package/dist/typedoc-entry/index.d.ts +5 -0
- package/dist/typedoc-entry/index.d.ts.map +1 -0
- package/dist/types/base.d.ts +178 -0
- package/dist/types/base.d.ts.map +1 -0
- package/dist/types/base.js +55 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/base.mjs +50 -0
- package/dist/types/base.mjs.map +1 -0
- package/dist/types/method-types.d.ts +258 -0
- package/dist/types/method-types.d.ts.map +1 -0
- package/dist/utils/oauth/completion.d.ts +132 -0
- package/dist/utils/oauth/completion.d.ts.map +1 -0
- package/dist/utils/oauth/completion.js +136 -0
- package/dist/utils/oauth/completion.js.map +1 -0
- package/dist/utils/oauth/completion.mjs +176 -0
- package/dist/utils/oauth/completion.mjs.map +1 -0
- package/dist/utils/oauth/config.d.ts +34 -0
- package/dist/utils/oauth/config.d.ts.map +1 -0
- package/dist/utils/oauth/config.js +69 -0
- package/dist/utils/oauth/config.js.map +1 -0
- package/dist/utils/oauth/config.mjs +54 -0
- package/dist/utils/oauth/config.mjs.map +1 -0
- package/dist/utils/oauth/helpers.d.ts +13 -0
- package/dist/utils/oauth/helpers.d.ts.map +1 -0
- package/dist/utils/oauth/helpers.js +38 -0
- package/dist/utils/oauth/helpers.js.map +1 -0
- package/dist/utils/oauth/helpers.mjs +35 -0
- package/dist/utils/oauth/helpers.mjs.map +1 -0
- package/dist/utils/oauth/index.d.ts +7 -0
- package/dist/utils/oauth/index.d.ts.map +1 -0
- package/dist/utils/oauth/pkce.d.ts +14 -0
- package/dist/utils/oauth/pkce.d.ts.map +1 -0
- package/dist/utils/oauth/pkce.js +48 -0
- package/dist/utils/oauth/pkce.js.map +1 -0
- package/dist/utils/oauth/pkce.mjs +85 -0
- package/dist/utils/oauth/pkce.mjs.map +1 -0
- package/dist/utils/oauth/storage.d.ts +48 -0
- package/dist/utils/oauth/storage.d.ts.map +1 -0
- package/dist/utils/oauth/storage.js +87 -0
- package/dist/utils/oauth/storage.js.map +1 -0
- package/dist/utils/oauth/storage.mjs +78 -0
- package/dist/utils/oauth/storage.mjs.map +1 -0
- package/dist/utils/oauth/url.d.ts +94 -0
- package/dist/utils/oauth/url.d.ts.map +1 -0
- package/dist/utils/oauth/url.js +224 -0
- package/dist/utils/oauth/url.js.map +1 -0
- package/dist/utils/oauth/url.mjs +230 -0
- package/dist/utils/oauth/url.mjs.map +1 -0
- package/dist/utils/timers.d.ts +73 -0
- package/dist/utils/timers.d.ts.map +1 -0
- package/dist/utils/timers.js +133 -0
- package/dist/utils/timers.js.map +1 -0
- package/dist/utils/timers.mjs +142 -0
- package/dist/utils/timers.mjs.map +1 -0
- package/dist/utils/utils.d.ts +40 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +116 -0
- package/dist/utils/utils.js.map +1 -0
- package/dist/utils/utils.mjs +164 -0
- package/dist/utils/utils.mjs.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sdkTypes = require('@0xkey-io/sdk-types');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var core = require('@0xkey-io/core');
|
|
6
|
+
|
|
7
|
+
const SESSION_WARNING_THRESHOLD_MS = 60 * 1000; // 1 minute in milliseconds
|
|
8
|
+
const useDebouncedCallback = (fn, wait = 100) => {
|
|
9
|
+
const timer = react.useRef(null);
|
|
10
|
+
const fnRef = react.useRef(fn);
|
|
11
|
+
fnRef.current = fn;
|
|
12
|
+
return react.useCallback((...args) => {
|
|
13
|
+
if (timer.current) clearTimeout(timer.current);
|
|
14
|
+
timer.current = setTimeout(() => {
|
|
15
|
+
fnRef.current(...args);
|
|
16
|
+
timer.current = null;
|
|
17
|
+
}, wait);
|
|
18
|
+
}, [wait]);
|
|
19
|
+
};
|
|
20
|
+
const isValidSession = session => {
|
|
21
|
+
return session?.expiry !== undefined && session.expiry * 1000 > Date.now();
|
|
22
|
+
};
|
|
23
|
+
async function withZeroXKeyErrorHandling(fn, sessionExpireFn, callbacks, fallbackMessage = "An unknown error occurred", fallbackCode = sdkTypes.ZeroXKeyErrorCodes.UNKNOWN) {
|
|
24
|
+
try {
|
|
25
|
+
return await fn();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
let tkError;
|
|
28
|
+
if (error instanceof sdkTypes.ZeroXKeyError) {
|
|
29
|
+
tkError = error;
|
|
30
|
+
if (tkError.code === sdkTypes.ZeroXKeyErrorCodes.SESSION_EXPIRED) {
|
|
31
|
+
if (sessionExpireFn) {
|
|
32
|
+
await sessionExpireFn();
|
|
33
|
+
} else {
|
|
34
|
+
// this should never happen. If it does, it means an SDK function is making
|
|
35
|
+
// a session-based API call without providing a `sessionExpireFn()` for handling
|
|
36
|
+
// SESSION_EXPIRED errors in `withZeroXKeyErrorHandling()`
|
|
37
|
+
throw new sdkTypes.ZeroXKeyError("SESSION_EXPIRED received without sessionExpireFn handler", sdkTypes.ZeroXKeyErrorCodes.INTERNAL_ERROR, error);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// skip onError for WalletConnect expired errors
|
|
41
|
+
if (tkError.code !== sdkTypes.ZeroXKeyErrorCodes.WALLET_CONNECT_EXPIRED) {
|
|
42
|
+
callbacks?.onError?.(tkError);
|
|
43
|
+
}
|
|
44
|
+
throw tkError;
|
|
45
|
+
}
|
|
46
|
+
// we wrap non-ZeroXKey errors
|
|
47
|
+
tkError = new sdkTypes.ZeroXKeyError(fallbackMessage, fallbackCode, error);
|
|
48
|
+
callbacks?.onError?.(tkError);
|
|
49
|
+
throw tkError;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Custom hook to get the current screen size
|
|
53
|
+
function useScreenSize() {
|
|
54
|
+
const [width, setWidth] = react.useState(typeof window !== "undefined" ? window.innerWidth : 1024);
|
|
55
|
+
const [height, setHeight] = react.useState(typeof window !== "undefined" ? window.innerHeight : 768);
|
|
56
|
+
react.useEffect(() => {
|
|
57
|
+
const handleResize = () => {
|
|
58
|
+
setWidth(window.innerWidth);
|
|
59
|
+
setHeight(window.innerHeight);
|
|
60
|
+
};
|
|
61
|
+
window.addEventListener("resize", handleResize);
|
|
62
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
63
|
+
}, []);
|
|
64
|
+
return {
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
// I have no idea why but, Tailwind's responsive design breakpoints do not work. Throughout the modal components, you will see conditional styling using this `isMobile` variable.
|
|
68
|
+
// This is fine since we only need to style for 2 screen sizes: mobile and desktop. If anyone can figure out why Tailwind's responsive design breakpoints do not work, please fix it and restyle the components accordingly, changing the `isMobile` to the Tailwind stuff when applicable.
|
|
69
|
+
isMobile: width < 640
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function isWalletConnect(wallet) {
|
|
73
|
+
return wallet.interfaceType == core.WalletInterfaceType.WalletConnect;
|
|
74
|
+
}
|
|
75
|
+
function useWalletProviderState(initialState = []) {
|
|
76
|
+
const [walletProviders, setWalletProviders] = react.useState(initialState);
|
|
77
|
+
const prevProvidersRef = react.useRef(initialState);
|
|
78
|
+
function isSameWalletProvider(a, b) {
|
|
79
|
+
if (a.length !== b.length) return false;
|
|
80
|
+
const key = provider => {
|
|
81
|
+
const name = provider.info.name;
|
|
82
|
+
const namespace = provider.chainInfo.namespace;
|
|
83
|
+
const interfaceType = provider.interfaceType;
|
|
84
|
+
const connectedAddresses = [...provider.connectedAddresses].map(x => x.toLowerCase()).sort().join(",");
|
|
85
|
+
const uri = provider.uri || "";
|
|
86
|
+
return `${namespace}|${interfaceType}|${name}|${connectedAddresses}|${uri}`;
|
|
87
|
+
};
|
|
88
|
+
const A = a.map(key).sort();
|
|
89
|
+
const B = b.map(key).sort();
|
|
90
|
+
for (let i = 0; i < A.length; i++) if (A[i] !== B[i]) return false;
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
const updateWalletProviders = react.useCallback(newProviders => {
|
|
94
|
+
if (!isSameWalletProvider(prevProvidersRef.current, newProviders)) {
|
|
95
|
+
prevProvidersRef.current = newProviders;
|
|
96
|
+
setWalletProviders(newProviders);
|
|
97
|
+
}
|
|
98
|
+
// we do nothing if the wallet providers are the same
|
|
99
|
+
}, []);
|
|
100
|
+
return [walletProviders, updateWalletProviders];
|
|
101
|
+
}
|
|
102
|
+
function mergeWalletsWithoutDuplicates(existingWallets, newWallets) {
|
|
103
|
+
const existingWalletIds = new Set(existingWallets.map(w => w.walletId));
|
|
104
|
+
const uniqueNewWallets = newWallets.filter(w => !existingWalletIds.has(w.walletId));
|
|
105
|
+
return [...existingWallets, ...uniqueNewWallets];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
exports.SESSION_WARNING_THRESHOLD_MS = SESSION_WARNING_THRESHOLD_MS;
|
|
109
|
+
exports.isValidSession = isValidSession;
|
|
110
|
+
exports.isWalletConnect = isWalletConnect;
|
|
111
|
+
exports.mergeWalletsWithoutDuplicates = mergeWalletsWithoutDuplicates;
|
|
112
|
+
exports.useDebouncedCallback = useDebouncedCallback;
|
|
113
|
+
exports.useScreenSize = useScreenSize;
|
|
114
|
+
exports.useWalletProviderState = useWalletProviderState;
|
|
115
|
+
exports.withZeroXKeyErrorHandling = withZeroXKeyErrorHandling;
|
|
116
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils/utils.ts"],"sourcesContent":[null],"names":["SESSION_WARNING_THRESHOLD_MS","useDebouncedCallback","fn","wait","timer","useRef","fnRef","current","useCallback","args","clearTimeout","setTimeout","isValidSession","session","expiry","undefined","Date","now","withZeroXKeyErrorHandling","sessionExpireFn","callbacks","fallbackMessage","fallbackCode","ZeroXKeyErrorCodes","UNKNOWN","error","tkError","ZeroXKeyError","code","SESSION_EXPIRED","INTERNAL_ERROR","WALLET_CONNECT_EXPIRED","onError","useScreenSize","width","setWidth","useState","window","innerWidth","height","setHeight","innerHeight","useEffect","handleResize","addEventListener","removeEventListener","isMobile","isWalletConnect","wallet","interfaceType","WalletInterfaceType","WalletConnect","useWalletProviderState","initialState","walletProviders","setWalletProviders","prevProvidersRef","isSameWalletProvider","a","b","length","key","provider","name","info","namespace","chainInfo","connectedAddresses","map","x","toLowerCase","sort","join","uri","A","B","i","updateWalletProviders","newProviders","mergeWalletsWithoutDuplicates","existingWallets","newWallets","existingWalletIds","Set","w","walletId","uniqueNewWallets","filter","has"],"mappings":";;;;;;MAYaA,4BAA4B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C,CAACS,GAAG,CAACP,GAAG,CAAC,CAACU,IAAI,EAAE;IAC3B,KAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,CAAC,CAACd,MAAM,EAAEgB,CAAC,EAAE,EAAE,IAAIF,CAAC,CAACE,CAAC,CAAC,KAAKD,CAAC,CAACC,CAAC,CAAC,EAAE,OAAO,KAAK;AAClE,IAAA,OAAO,IAAI;AACb,EAAA;AAEA,EAAA,MAAMC,qBAAqB,GAAGrE,iBAAW,CACtCsE,YAA8B,IAAI;IACjC,IAAI,CAACrB,oBAAoB,CAACD,gBAAgB,CAACjD,OAAO,EAAEuE,YAAY,CAAC,EAAE;MACjEtB,gBAAgB,CAACjD,OAAO,GAAGuE,YAAY;MACvCvB,kBAAkB,CAACuB,YAAY,CAAC;AAClC,IAAA;AACA;EACF,CAAC,EACD,EAAE,CACH;AAED,EAAA,OAAO,CAACxB,eAAe,EAAEuB,qBAAqB,CAAU;AAC1D;AAEM,SAAUE,6BAA6BA,CAC3CC,eAAyB,EACzBC,UAAoB,EAAA;AAEpB,EAAA,MAAMC,iBAAiB,GAAG,IAAIC,GAAG,CAACH,eAAe,CAACZ,GAAG,CAAEgB,CAAC,IAAKA,CAAC,CAACC,QAAQ,CAAC,CAAC;AACzE,EAAA,MAAMC,gBAAgB,GAAGL,UAAU,CAACM,MAAM,CACvCH,CAAC,IAAK,CAACF,iBAAiB,CAACM,GAAG,CAACJ,CAAC,CAACC,QAAQ,CAAC,CAC1C;AACD,EAAA,OAAO,CAAC,GAAGL,eAAe,EAAE,GAAGM,gBAAgB,CAAC;AAClD;;;;;;;;;;;"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regenerator as _regenerator } from '../_virtual/_rollupPluginBabelHelpers.mjs';
|
|
2
|
+
import { ZeroXKeyError, ZeroXKeyErrorCodes } from '@0xkey-io/sdk-types';
|
|
3
|
+
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
4
|
+
import { WalletInterfaceType } from '@0xkey-io/core';
|
|
5
|
+
|
|
6
|
+
var SESSION_WARNING_THRESHOLD_MS = 60 * 1000; // 1 minute in milliseconds
|
|
7
|
+
var useDebouncedCallback = function useDebouncedCallback(fn) {
|
|
8
|
+
var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
|
|
9
|
+
var timer = useRef(null);
|
|
10
|
+
var fnRef = useRef(fn);
|
|
11
|
+
fnRef.current = fn;
|
|
12
|
+
return useCallback(function () {
|
|
13
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
14
|
+
args[_key] = arguments[_key];
|
|
15
|
+
}
|
|
16
|
+
if (timer.current) clearTimeout(timer.current);
|
|
17
|
+
timer.current = setTimeout(function () {
|
|
18
|
+
fnRef.current.apply(fnRef, args);
|
|
19
|
+
timer.current = null;
|
|
20
|
+
}, wait);
|
|
21
|
+
}, [wait]);
|
|
22
|
+
};
|
|
23
|
+
var isValidSession = function isValidSession(session) {
|
|
24
|
+
return (session === null || session === void 0 ? void 0 : session.expiry) !== undefined && session.expiry * 1000 > Date.now();
|
|
25
|
+
};
|
|
26
|
+
function withZeroXKeyErrorHandling(_x, _x2, _x3) {
|
|
27
|
+
return _withZeroXKeyErrorHandling.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
// Custom hook to get the current screen size
|
|
30
|
+
function _withZeroXKeyErrorHandling() {
|
|
31
|
+
_withZeroXKeyErrorHandling = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fn, sessionExpireFn, callbacks) {
|
|
32
|
+
var fallbackMessage,
|
|
33
|
+
fallbackCode,
|
|
34
|
+
_callbacks$onError2,
|
|
35
|
+
tkError,
|
|
36
|
+
_callbacks$onError,
|
|
37
|
+
_args = arguments,
|
|
38
|
+
_t;
|
|
39
|
+
return _regenerator().w(function (_context) {
|
|
40
|
+
while (1) switch (_context.p = _context.n) {
|
|
41
|
+
case 0:
|
|
42
|
+
fallbackMessage = _args.length > 3 && _args[3] !== undefined ? _args[3] : "An unknown error occurred";
|
|
43
|
+
fallbackCode = _args.length > 4 && _args[4] !== undefined ? _args[4] : ZeroXKeyErrorCodes.UNKNOWN;
|
|
44
|
+
_context.p = 1;
|
|
45
|
+
_context.n = 2;
|
|
46
|
+
return fn();
|
|
47
|
+
case 2:
|
|
48
|
+
return _context.a(2, _context.v);
|
|
49
|
+
case 3:
|
|
50
|
+
_context.p = 3;
|
|
51
|
+
_t = _context.v;
|
|
52
|
+
if (!(_t instanceof ZeroXKeyError)) {
|
|
53
|
+
_context.n = 7;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
tkError = _t;
|
|
57
|
+
if (!(tkError.code === ZeroXKeyErrorCodes.SESSION_EXPIRED)) {
|
|
58
|
+
_context.n = 6;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
if (!sessionExpireFn) {
|
|
62
|
+
_context.n = 5;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
_context.n = 4;
|
|
66
|
+
return sessionExpireFn();
|
|
67
|
+
case 4:
|
|
68
|
+
_context.n = 6;
|
|
69
|
+
break;
|
|
70
|
+
case 5:
|
|
71
|
+
throw new ZeroXKeyError("SESSION_EXPIRED received without sessionExpireFn handler", ZeroXKeyErrorCodes.INTERNAL_ERROR, _t);
|
|
72
|
+
case 6:
|
|
73
|
+
// skip onError for WalletConnect expired errors
|
|
74
|
+
if (tkError.code !== ZeroXKeyErrorCodes.WALLET_CONNECT_EXPIRED) {
|
|
75
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError = callbacks.onError) === null || _callbacks$onError === void 0 ? void 0 : _callbacks$onError.call(callbacks, tkError);
|
|
76
|
+
}
|
|
77
|
+
throw tkError;
|
|
78
|
+
case 7:
|
|
79
|
+
// we wrap non-ZeroXKey errors
|
|
80
|
+
tkError = new ZeroXKeyError(fallbackMessage, fallbackCode, _t);
|
|
81
|
+
callbacks === null || callbacks === void 0 ? void 0 : (_callbacks$onError2 = callbacks.onError) === null || _callbacks$onError2 === void 0 ? void 0 : _callbacks$onError2.call(callbacks, tkError);
|
|
82
|
+
throw tkError;
|
|
83
|
+
case 8:
|
|
84
|
+
return _context.a(2);
|
|
85
|
+
}
|
|
86
|
+
}, _callee, null, [[1, 3]]);
|
|
87
|
+
}));
|
|
88
|
+
return _withZeroXKeyErrorHandling.apply(this, arguments);
|
|
89
|
+
}
|
|
90
|
+
function useScreenSize() {
|
|
91
|
+
var _useState = useState(typeof window !== "undefined" ? window.innerWidth : 1024),
|
|
92
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
93
|
+
width = _useState2[0],
|
|
94
|
+
setWidth = _useState2[1];
|
|
95
|
+
var _useState3 = useState(typeof window !== "undefined" ? window.innerHeight : 768),
|
|
96
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
+
height = _useState4[0],
|
|
98
|
+
setHeight = _useState4[1];
|
|
99
|
+
useEffect(function () {
|
|
100
|
+
var handleResize = function handleResize() {
|
|
101
|
+
setWidth(window.innerWidth);
|
|
102
|
+
setHeight(window.innerHeight);
|
|
103
|
+
};
|
|
104
|
+
window.addEventListener("resize", handleResize);
|
|
105
|
+
return function () {
|
|
106
|
+
return window.removeEventListener("resize", handleResize);
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
return {
|
|
110
|
+
width: width,
|
|
111
|
+
height: height,
|
|
112
|
+
// I have no idea why but, Tailwind's responsive design breakpoints do not work. Throughout the modal components, you will see conditional styling using this `isMobile` variable.
|
|
113
|
+
// This is fine since we only need to style for 2 screen sizes: mobile and desktop. If anyone can figure out why Tailwind's responsive design breakpoints do not work, please fix it and restyle the components accordingly, changing the `isMobile` to the Tailwind stuff when applicable.
|
|
114
|
+
isMobile: width < 640
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function isWalletConnect(wallet) {
|
|
118
|
+
return wallet.interfaceType == WalletInterfaceType.WalletConnect;
|
|
119
|
+
}
|
|
120
|
+
function useWalletProviderState() {
|
|
121
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
122
|
+
var _useState5 = useState(initialState),
|
|
123
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
124
|
+
walletProviders = _useState6[0],
|
|
125
|
+
setWalletProviders = _useState6[1];
|
|
126
|
+
var prevProvidersRef = useRef(initialState);
|
|
127
|
+
function isSameWalletProvider(a, b) {
|
|
128
|
+
if (a.length !== b.length) return false;
|
|
129
|
+
var key = function key(provider) {
|
|
130
|
+
var name = provider.info.name;
|
|
131
|
+
var namespace = provider.chainInfo.namespace;
|
|
132
|
+
var interfaceType = provider.interfaceType;
|
|
133
|
+
var connectedAddresses = _toConsumableArray(provider.connectedAddresses).map(function (x) {
|
|
134
|
+
return x.toLowerCase();
|
|
135
|
+
}).sort().join(",");
|
|
136
|
+
var uri = provider.uri || "";
|
|
137
|
+
return "".concat(namespace, "|").concat(interfaceType, "|").concat(name, "|").concat(connectedAddresses, "|").concat(uri);
|
|
138
|
+
};
|
|
139
|
+
var A = a.map(key).sort();
|
|
140
|
+
var B = b.map(key).sort();
|
|
141
|
+
for (var i = 0; i < A.length; i++) if (A[i] !== B[i]) return false;
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
var updateWalletProviders = useCallback(function (newProviders) {
|
|
145
|
+
if (!isSameWalletProvider(prevProvidersRef.current, newProviders)) {
|
|
146
|
+
prevProvidersRef.current = newProviders;
|
|
147
|
+
setWalletProviders(newProviders);
|
|
148
|
+
}
|
|
149
|
+
// we do nothing if the wallet providers are the same
|
|
150
|
+
}, []);
|
|
151
|
+
return [walletProviders, updateWalletProviders];
|
|
152
|
+
}
|
|
153
|
+
function mergeWalletsWithoutDuplicates(existingWallets, newWallets) {
|
|
154
|
+
var existingWalletIds = new Set(existingWallets.map(function (w) {
|
|
155
|
+
return w.walletId;
|
|
156
|
+
}));
|
|
157
|
+
var uniqueNewWallets = newWallets.filter(function (w) {
|
|
158
|
+
return !existingWalletIds.has(w.walletId);
|
|
159
|
+
});
|
|
160
|
+
return [].concat(_toConsumableArray(existingWallets), _toConsumableArray(uniqueNewWallets));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export { SESSION_WARNING_THRESHOLD_MS, isValidSession, isWalletConnect, mergeWalletsWithoutDuplicates, useDebouncedCallback, useScreenSize, useWalletProviderState, withZeroXKeyErrorHandling };
|
|
164
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils/utils.ts"],"sourcesContent":[null],"names":["SESSION_WARNING_THRESHOLD_MS","useDebouncedCallback","fn","wait","arguments","length","undefined","timer","useRef","fnRef","current","useCallback","_len","args","Array","_key","clearTimeout","setTimeout","apply","isValidSession","session","expiry","Date","now","withZeroXKeyErrorHandling","_x","_x2","_x3","_withZeroXKeyErrorHandling","_asyncToGenerator","_regenerator","m","_callee","sessionExpireFn","callbacks","fallbackMessage","fallbackCode","_callbacks$onError2","tkError","_callbacks$onError","_args","_t","w","_context","p","n","ZeroXKeyErrorCodes","UNKNOWN","a","v","ZeroXKeyError","code","SESSION_EXPIRED","INTERNAL_ERROR","WALLET_CONNECT_EXPIRED","onError","call","useScreenSize","_useState","useState","window","innerWidth","_useState2","_slicedToArray","width","setWidth","_useState3","innerHeight","_useState4","height","setHeight","useEffect","handleResize","addEventListener","removeEventListener","isMobile","isWalletConnect","wallet","interfaceType","WalletInterfaceType","WalletConnect","useWalletProviderState","initialState","_useState5","_useState6","walletProviders","setWalletProviders","prevProvidersRef","isSameWalletProvider","b","key","provider","name","info","namespace","chainInfo","connectedAddresses","_toConsumableArray","map","x","toLowerCase","sort","join","uri","concat","A","B","i","updateWalletProviders","newProviders","mergeWalletsWithoutDuplicates","existingWallets","newWallets","existingWalletIds","Set","walletId","uniqueNewWallets","filter","has"],"mappings":";;;;;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GmG,YAAY;MACvCvB,kBAAkB,CAACuB,YAAY,CAAC;AAClC,IAAA;AACA;EACF,CAAC,EACD,EAAE,CACH;AAED,EAAA,OAAO,CAACxB,eAAe,EAAEuB,qBAAqB,CAAU;AAC1D;AAEM,SAAUE,6BAA6BA,CAC3CC,eAAyB,EACzBC,UAAoB,EAAA;EAEpB,IAAMC,iBAAiB,GAAG,IAAIC,GAAG,CAACH,eAAe,CAACb,GAAG,CAAC,UAACxD,CAAC,EAAA;IAAA,OAAKA,CAAC,CAACyE,QAAQ;AAAA,EAAA,CAAA,CAAC,CAAC;AACzE,EAAA,IAAMC,gBAAgB,GAAGJ,UAAU,CAACK,MAAM,CACxC,UAAC3E,CAAC,EAAA;IAAA,OAAK,CAACuE,iBAAiB,CAACK,GAAG,CAAC5E,CAAC,CAACyE,QAAQ,CAAC;EAAA,CAAA,CAC1C;EACD,OAAA,EAAA,CAAAX,MAAA,CAAAP,kBAAA,CAAWc,eAAe,CAAA,EAAAd,kBAAA,CAAKmB,gBAAgB,CAAA,CAAA;AACjD;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xkey-io/react-wallet-kit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "The easiest and most powerful way to integrate 0xkey's Embedded Wallets into your React applications.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./styles.css": "./dist/styles.css"
|
|
15
|
+
},
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "0xkey",
|
|
18
|
+
"url": "https://0xkey.com/"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/0xkey-io/sdk-js/tree/main/packages/react-wallet-kit",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/0xkey-io/sdk-js/issues"
|
|
23
|
+
},
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/0xkey-io/sdk-js.git",
|
|
27
|
+
"directory": "packages/react-wallet-kit"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
33
|
+
"keywords": [
|
|
34
|
+
"0xkey"
|
|
35
|
+
],
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
|
39
|
+
"@fortawesome/free-brands-svg-icons": "^6.7.2",
|
|
40
|
+
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
|
41
|
+
"@fortawesome/react-fontawesome": "^0.2.2",
|
|
42
|
+
"@headlessui/react": "^2.2.6",
|
|
43
|
+
"@lottiefiles/react-lottie-player": "^3.6.0",
|
|
44
|
+
"@noble/hashes": "^1.8.0",
|
|
45
|
+
"buffer": "^6.0.3",
|
|
46
|
+
"clsx": "^2.1.1",
|
|
47
|
+
"libphonenumber-js": "^1.11.14",
|
|
48
|
+
"qrcode.react": "^4.2.0",
|
|
49
|
+
"react-international-phone": "^4.3.0",
|
|
50
|
+
"viem": "^2.40.2",
|
|
51
|
+
"@0xkey-io/core": "0.1.0",
|
|
52
|
+
"@0xkey-io/sdk-types": "0.1.0",
|
|
53
|
+
"@0xkey-io/iframe-stamper": "^0.1.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@rollup/plugin-babel": "5.3.0",
|
|
57
|
+
"@rollup/plugin-node-resolve": "16.0.0",
|
|
58
|
+
"@rollup/plugin-strip": "^3.0.4",
|
|
59
|
+
"@tailwindcss/postcss": "^4.1.10",
|
|
60
|
+
"@types/react": "^18.2.75",
|
|
61
|
+
"@types/react-dom": "^18.2.7",
|
|
62
|
+
"autoprefixer": "^10.0.1",
|
|
63
|
+
"glob": "^8.0.3",
|
|
64
|
+
"postcss": "^8.4.38",
|
|
65
|
+
"react": "^18.2.0",
|
|
66
|
+
"react-dom": "^18.2.0",
|
|
67
|
+
"tailwindcss": "^4.1.10",
|
|
68
|
+
"typescript": "5.4.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependencies": {
|
|
71
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
72
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"@types/react": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=18.0.0"
|
|
81
|
+
},
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public"
|
|
84
|
+
},
|
|
85
|
+
"scripts": {
|
|
86
|
+
"build": "rollup -c",
|
|
87
|
+
"clean": "rimraf ./dist ./.cache",
|
|
88
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
89
|
+
"test": "jest"
|
|
90
|
+
}
|
|
91
|
+
}
|