@unifold/connect-svelte 0.1.30
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/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/lib/UnifoldProvider.svelte +71 -0
- package/dist/lib/UnifoldProvider.svelte.d.ts +31 -0
- package/dist/lib/context.d.ts +8 -0
- package/dist/lib/context.js +9 -0
- package/dist/styles-base.css +1 -0
- package/dist/styles.css +1 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { default as UnifoldProvider } from "./lib/UnifoldProvider.svelte";
|
|
2
|
+
export { getUnifold } from "./lib/context.js";
|
|
3
|
+
export type { UnifoldContext } from "./lib/context.js";
|
|
4
|
+
export type { DepositConfig, DepositResult, DepositError, UnifoldConfig, UnifoldConnectProviderConfig, } from "@unifold/ui-web";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy, setContext } from "svelte";
|
|
3
|
+
import { UNIFOLD_CONTEXT_KEY, type UnifoldContext } from "./context.js";
|
|
4
|
+
import type { UnifoldConfig, UnifoldInstance } from "@unifold/ui-web";
|
|
5
|
+
|
|
6
|
+
export let publishableKey: string;
|
|
7
|
+
export let config: UnifoldConfig | undefined = undefined;
|
|
8
|
+
|
|
9
|
+
let unifold: UnifoldInstance | null = null;
|
|
10
|
+
let destroyed = false;
|
|
11
|
+
let initStarted = false;
|
|
12
|
+
|
|
13
|
+
let resolveReady!: () => void;
|
|
14
|
+
let rejectReady!: (err: unknown) => void;
|
|
15
|
+
const readyPromise = new Promise<void>((resolve, reject) => {
|
|
16
|
+
resolveReady = resolve;
|
|
17
|
+
rejectReady = reject;
|
|
18
|
+
});
|
|
19
|
+
readyPromise.catch(() => {});
|
|
20
|
+
|
|
21
|
+
const ctx: UnifoldContext = {
|
|
22
|
+
beginDeposit: async (depositConfig) => {
|
|
23
|
+
await readyPromise;
|
|
24
|
+
if (destroyed || !unifold) {
|
|
25
|
+
throw new Error("UnifoldProvider has been destroyed");
|
|
26
|
+
}
|
|
27
|
+
return unifold.beginDeposit(depositConfig);
|
|
28
|
+
},
|
|
29
|
+
closeDeposit: () => {
|
|
30
|
+
unifold?.closeDeposit();
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
setContext(UNIFOLD_CONTEXT_KEY, ctx);
|
|
35
|
+
|
|
36
|
+
// onMount is browser-only — it never fires during SSR.
|
|
37
|
+
onMount(async () => {
|
|
38
|
+
initStarted = true;
|
|
39
|
+
try {
|
|
40
|
+
const { createUnifold } = await import("@unifold/ui-web");
|
|
41
|
+
if (destroyed) return;
|
|
42
|
+
|
|
43
|
+
const instance = await createUnifold(publishableKey, config);
|
|
44
|
+
if (destroyed) {
|
|
45
|
+
instance.destroy();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
unifold = instance;
|
|
50
|
+
resolveReady();
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (destroyed) return;
|
|
53
|
+
console.error("[UnifoldProvider] Failed to initialize:", err);
|
|
54
|
+
rejectReady(err);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// onDestroy fires during both SSR and browser. Only reject the ready
|
|
59
|
+
// promise if onMount actually ran (browser), otherwise the unhandled
|
|
60
|
+
// rejection crashes the SSR process.
|
|
61
|
+
onDestroy(() => {
|
|
62
|
+
destroyed = true;
|
|
63
|
+
unifold?.destroy();
|
|
64
|
+
unifold = null;
|
|
65
|
+
if (initStarted) {
|
|
66
|
+
rejectReady(new Error("UnifoldProvider was destroyed before initialization completed"));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<slot />
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { UnifoldConfig } from "@unifold/ui-web";
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
16
|
+
default: any;
|
|
17
|
+
} ? Props extends Record<string, never> ? any : {
|
|
18
|
+
children?: any;
|
|
19
|
+
} : {});
|
|
20
|
+
declare const UnifoldProvider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
21
|
+
publishableKey: string;
|
|
22
|
+
config?: UnifoldConfig | undefined;
|
|
23
|
+
}, {
|
|
24
|
+
default: {};
|
|
25
|
+
}>, {
|
|
26
|
+
[evt: string]: CustomEvent<any>;
|
|
27
|
+
}, {
|
|
28
|
+
default: {};
|
|
29
|
+
}, {}, string>;
|
|
30
|
+
type UnifoldProvider = InstanceType<typeof UnifoldProvider>;
|
|
31
|
+
export default UnifoldProvider;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DepositConfig, DepositResult, DepositError } from "@unifold/ui-web";
|
|
2
|
+
export declare const UNIFOLD_CONTEXT_KEY: unique symbol;
|
|
3
|
+
export interface UnifoldContext {
|
|
4
|
+
beginDeposit: (config: DepositConfig) => Promise<DepositResult>;
|
|
5
|
+
closeDeposit: () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function getUnifold(): UnifoldContext;
|
|
8
|
+
export type { DepositConfig, DepositResult, DepositError };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getContext } from "svelte";
|
|
2
|
+
export const UNIFOLD_CONTEXT_KEY = Symbol("unifold");
|
|
3
|
+
export function getUnifold() {
|
|
4
|
+
const ctx = getContext(UNIFOLD_CONTEXT_KEY);
|
|
5
|
+
if (!ctx) {
|
|
6
|
+
throw new Error("getUnifold() must be called inside a component wrapped by <UnifoldProvider>");
|
|
7
|
+
}
|
|
8
|
+
return ctx;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@unifold/ui-web/styles-base.css";
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@unifold/ui-web/styles.css";
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unifold/connect-svelte",
|
|
3
|
+
"version": "0.1.30",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Unifold Connect for Svelte - Native Svelte SDK for the Unifold deposit widget",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"svelte": "./dist/index.js",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./styles.css": "./dist/styles.css",
|
|
13
|
+
"./styles-base.css": "./dist/styles-base.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@unifold/ui-web": "0.1.30"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"svelte": "^4.0.0 || ^5.0.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@sveltejs/kit": "^2.0.0",
|
|
26
|
+
"@sveltejs/package": "^2.5.7",
|
|
27
|
+
"@sveltejs/vite-plugin-svelte": "^4.0.0",
|
|
28
|
+
"svelte": "^5.0.0",
|
|
29
|
+
"svelte-check": "^4.0.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"unifold",
|
|
34
|
+
"sdk",
|
|
35
|
+
"crypto",
|
|
36
|
+
"deposit",
|
|
37
|
+
"svelte"
|
|
38
|
+
],
|
|
39
|
+
"author": "Unifold",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "svelte-package -i src",
|
|
43
|
+
"dev": "svelte-package -i src --watch",
|
|
44
|
+
"type-check": "svelte-check --tsconfig ./tsconfig.json",
|
|
45
|
+
"clean": "rm -rf dist"
|
|
46
|
+
}
|
|
47
|
+
}
|