@yuno-payments/dashboard-embed-sdk 0.2.6 → 0.2.7
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 +5 -0
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -41,10 +41,13 @@ interface YunoDashboardConfig {
|
|
|
41
41
|
lang?: string;
|
|
42
42
|
path?: string;
|
|
43
43
|
onReady?: () => void;
|
|
44
|
+
loading?: boolean | HTMLElement;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
declare class YunoDashboard {
|
|
47
48
|
private iframe;
|
|
49
|
+
private wrapper;
|
|
50
|
+
private overlay;
|
|
48
51
|
private baseUrl;
|
|
49
52
|
private ready;
|
|
50
53
|
private queue;
|
|
@@ -64,6 +67,8 @@ declare class YunoDashboard {
|
|
|
64
67
|
private flush;
|
|
65
68
|
private onReady;
|
|
66
69
|
private onTokenApplied;
|
|
70
|
+
private hideOverlay;
|
|
71
|
+
private createDefaultOverlay;
|
|
67
72
|
private buildSrc;
|
|
68
73
|
}
|
|
69
74
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/yuno-dashboard.ts
|
|
2
2
|
var YunoDashboard = class {
|
|
3
3
|
constructor(config) {
|
|
4
|
+
this.overlay = null;
|
|
4
5
|
this.ready = false;
|
|
5
6
|
this.queue = [];
|
|
6
7
|
this.baseUrl = config.baseUrl;
|
|
@@ -9,12 +10,28 @@ var YunoDashboard = class {
|
|
|
9
10
|
this.initialPath = config.path ?? "/";
|
|
10
11
|
this.token = config.token;
|
|
11
12
|
this.onReadyCallback = config.onReady;
|
|
13
|
+
this.wrapper = document.createElement("div");
|
|
14
|
+
this.wrapper.style.position = "relative";
|
|
15
|
+
this.wrapper.style.width = "100%";
|
|
16
|
+
this.wrapper.style.height = "100%";
|
|
12
17
|
this.iframe = document.createElement("iframe");
|
|
13
18
|
this.iframe.style.width = "100%";
|
|
14
19
|
this.iframe.style.height = "100%";
|
|
15
20
|
this.iframe.style.border = "none";
|
|
16
21
|
this.iframe.title = "Yuno Dashboard";
|
|
17
22
|
this.iframe.src = this.buildSrc();
|
|
23
|
+
this.wrapper.appendChild(this.iframe);
|
|
24
|
+
if (config.loading !== false) {
|
|
25
|
+
if (config.loading instanceof HTMLElement) {
|
|
26
|
+
this.overlay = config.loading;
|
|
27
|
+
} else {
|
|
28
|
+
this.overlay = this.createDefaultOverlay();
|
|
29
|
+
}
|
|
30
|
+
this.overlay.style.position = "absolute";
|
|
31
|
+
this.overlay.style.inset = "0";
|
|
32
|
+
this.overlay.style.zIndex = "1";
|
|
33
|
+
this.wrapper.appendChild(this.overlay);
|
|
34
|
+
}
|
|
18
35
|
this.messageHandler = (e) => {
|
|
19
36
|
if (e.origin !== this.baseUrl) return;
|
|
20
37
|
if (e.data?.action === "ready") {
|
|
@@ -25,7 +42,7 @@ var YunoDashboard = class {
|
|
|
25
42
|
}
|
|
26
43
|
};
|
|
27
44
|
window.addEventListener("message", this.messageHandler);
|
|
28
|
-
config.container.appendChild(this.
|
|
45
|
+
config.container.appendChild(this.wrapper);
|
|
29
46
|
}
|
|
30
47
|
setTheme(theme) {
|
|
31
48
|
if (theme.tokens || theme.typography) {
|
|
@@ -53,7 +70,7 @@ var YunoDashboard = class {
|
|
|
53
70
|
}
|
|
54
71
|
destroy() {
|
|
55
72
|
window.removeEventListener("message", this.messageHandler);
|
|
56
|
-
this.
|
|
73
|
+
this.wrapper.remove();
|
|
57
74
|
this.queue = [];
|
|
58
75
|
this.ready = false;
|
|
59
76
|
}
|
|
@@ -90,9 +107,35 @@ var YunoDashboard = class {
|
|
|
90
107
|
if (this.initialPath !== "/") {
|
|
91
108
|
this.post({ action: "navigate", path: this.initialPath });
|
|
92
109
|
}
|
|
110
|
+
this.hideOverlay();
|
|
93
111
|
this.onReadyCallback?.();
|
|
94
112
|
}, 1e3);
|
|
95
113
|
}
|
|
114
|
+
hideOverlay() {
|
|
115
|
+
if (!this.overlay) return;
|
|
116
|
+
this.overlay.style.transition = "opacity 0.3s";
|
|
117
|
+
this.overlay.style.opacity = "0";
|
|
118
|
+
setTimeout(() => this.overlay?.remove(), 300);
|
|
119
|
+
}
|
|
120
|
+
createDefaultOverlay() {
|
|
121
|
+
const overlay = document.createElement("div");
|
|
122
|
+
overlay.style.background = "#ffffff";
|
|
123
|
+
overlay.style.display = "flex";
|
|
124
|
+
overlay.style.alignItems = "center";
|
|
125
|
+
overlay.style.justifyContent = "center";
|
|
126
|
+
const spinner = document.createElement("div");
|
|
127
|
+
spinner.style.width = "32px";
|
|
128
|
+
spinner.style.height = "32px";
|
|
129
|
+
spinner.style.border = "3px solid #e0e0e0";
|
|
130
|
+
spinner.style.borderTopColor = "#666";
|
|
131
|
+
spinner.style.borderRadius = "50%";
|
|
132
|
+
spinner.style.animation = "yuno-spin 0.8s linear infinite";
|
|
133
|
+
const style = document.createElement("style");
|
|
134
|
+
style.textContent = "@keyframes yuno-spin { to { transform: rotate(360deg); } }";
|
|
135
|
+
overlay.appendChild(style);
|
|
136
|
+
overlay.appendChild(spinner);
|
|
137
|
+
return overlay;
|
|
138
|
+
}
|
|
96
139
|
buildSrc() {
|
|
97
140
|
const params = new URLSearchParams({
|
|
98
141
|
embed: "true",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/yuno-dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, YunoDashboardConfig } from \"./types\";\n\nexport class YunoDashboard {\n private iframe: HTMLIFrameElement;\n private baseUrl: string;\n private ready = false;\n private queue: Record<string, unknown>[] = [];\n private messageHandler: (e: MessageEvent) => void;\n private initialTheme?: DashboardTheme;\n private initialLang?: string;\n private initialPath: string;\n private token?: string;\n private onReadyCallback?: () => void;\n\n constructor(config: YunoDashboardConfig) {\n this.baseUrl = config.baseUrl;\n this.initialTheme = config.theme;\n this.initialLang = config.lang;\n this.initialPath = config.path ?? \"/\";\n this.token = config.token;\n this.onReadyCallback = config.onReady;\n\n this.iframe = document.createElement(\"iframe\");\n this.iframe.style.width = \"100%\";\n this.iframe.style.height = \"100%\";\n this.iframe.style.border = \"none\";\n this.iframe.title = \"Yuno Dashboard\";\n this.iframe.src = this.buildSrc();\n\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.baseUrl) return;\n if (e.data?.action === \"ready\") {\n this.onReady();\n }\n if (e.data?.action === \"tokenApplied\") {\n this.onTokenApplied();\n }\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n config.container.appendChild(this.
|
|
1
|
+
{"version":3,"sources":["../src/yuno-dashboard.ts","../src/singleton.ts"],"sourcesContent":["import type { DashboardTheme, YunoDashboardConfig } from \"./types\";\n\nexport class YunoDashboard {\n private iframe: HTMLIFrameElement;\n private wrapper: HTMLDivElement;\n private overlay: HTMLElement | null = null;\n private baseUrl: string;\n private ready = false;\n private queue: Record<string, unknown>[] = [];\n private messageHandler: (e: MessageEvent) => void;\n private initialTheme?: DashboardTheme;\n private initialLang?: string;\n private initialPath: string;\n private token?: string;\n private onReadyCallback?: () => void;\n\n constructor(config: YunoDashboardConfig) {\n this.baseUrl = config.baseUrl;\n this.initialTheme = config.theme;\n this.initialLang = config.lang;\n this.initialPath = config.path ?? \"/\";\n this.token = config.token;\n this.onReadyCallback = config.onReady;\n\n this.wrapper = document.createElement(\"div\");\n this.wrapper.style.position = \"relative\";\n this.wrapper.style.width = \"100%\";\n this.wrapper.style.height = \"100%\";\n\n this.iframe = document.createElement(\"iframe\");\n this.iframe.style.width = \"100%\";\n this.iframe.style.height = \"100%\";\n this.iframe.style.border = \"none\";\n this.iframe.title = \"Yuno Dashboard\";\n this.iframe.src = this.buildSrc();\n\n this.wrapper.appendChild(this.iframe);\n\n if (config.loading !== false) {\n if (config.loading instanceof HTMLElement) {\n this.overlay = config.loading;\n } else {\n this.overlay = this.createDefaultOverlay();\n }\n this.overlay.style.position = \"absolute\";\n this.overlay.style.inset = \"0\";\n this.overlay.style.zIndex = \"1\";\n this.wrapper.appendChild(this.overlay);\n }\n\n this.messageHandler = (e: MessageEvent) => {\n if (e.origin !== this.baseUrl) return;\n if (e.data?.action === \"ready\") {\n this.onReady();\n }\n if (e.data?.action === \"tokenApplied\") {\n this.onTokenApplied();\n }\n };\n window.addEventListener(\"message\", this.messageHandler);\n\n config.container.appendChild(this.wrapper);\n }\n\n setTheme(theme: DashboardTheme): void {\n if (theme.tokens || theme.typography) {\n const themePayload: Record<string, unknown> = {};\n if (theme.tokens) themePayload.colors = theme.tokens;\n if (theme.typography) themePayload.typography = theme.typography;\n this.post({ action: \"setTheme\", theme: themePayload });\n }\n if (theme.mode) {\n this.post({ action: \"setMode\", mode: theme.mode });\n }\n if (theme.styles !== undefined) {\n this.post({ action: \"setExternalStyles\", css: theme.styles });\n }\n }\n\n setLang(lang: string): void {\n this.post({ action: \"setLang\", lang });\n }\n\n setToken(token: string): void {\n this.token = token;\n this.post({ action: \"setToken\", token });\n }\n\n navigate(path: string): void {\n this.post({ action: \"navigate\", path });\n }\n\n destroy(): void {\n window.removeEventListener(\"message\", this.messageHandler);\n this.wrapper.remove();\n this.queue = [];\n this.ready = false;\n }\n\n private post(message: Record<string, unknown>): void {\n if (this.ready && this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n } else {\n this.queue.push(message);\n }\n }\n\n private flush(): void {\n const pending = this.queue.splice(0);\n for (const message of pending) {\n if (this.iframe.contentWindow) {\n this.iframe.contentWindow.postMessage(message, this.baseUrl);\n }\n }\n }\n\n private onReady(): void {\n this.ready = true;\n if (this.token) {\n this.post({ action: \"setToken\", token: this.token });\n }\n if (this.initialTheme) {\n this.setTheme(this.initialTheme);\n }\n if (this.initialLang) {\n this.setLang(this.initialLang);\n }\n this.flush();\n }\n\n private onTokenApplied(): void {\n setTimeout(() => {\n if (this.initialPath !== \"/\") {\n this.post({ action: \"navigate\", path: this.initialPath });\n }\n this.hideOverlay();\n this.onReadyCallback?.();\n }, 1000);\n }\n\n private hideOverlay(): void {\n if (!this.overlay) return;\n this.overlay.style.transition = \"opacity 0.3s\";\n this.overlay.style.opacity = \"0\";\n setTimeout(() => this.overlay?.remove(), 300);\n }\n\n private createDefaultOverlay(): HTMLElement {\n const overlay = document.createElement(\"div\");\n overlay.style.background = \"#ffffff\";\n overlay.style.display = \"flex\";\n overlay.style.alignItems = \"center\";\n overlay.style.justifyContent = \"center\";\n\n const spinner = document.createElement(\"div\");\n spinner.style.width = \"32px\";\n spinner.style.height = \"32px\";\n spinner.style.border = \"3px solid #e0e0e0\";\n spinner.style.borderTopColor = \"#666\";\n spinner.style.borderRadius = \"50%\";\n spinner.style.animation = \"yuno-spin 0.8s linear infinite\";\n\n const style = document.createElement(\"style\");\n style.textContent = \"@keyframes yuno-spin { to { transform: rotate(360deg); } }\";\n\n overlay.appendChild(style);\n overlay.appendChild(spinner);\n return overlay;\n }\n\n private buildSrc(): string {\n const params = new URLSearchParams({\n embed: \"true\",\n theme: \"light\",\n lang: this.initialLang ?? \"en\",\n });\n return `${this.baseUrl}/?${params.toString()}`;\n }\n}\n","import { YunoDashboard } from \"./yuno-dashboard\";\nimport type { YunoDashboardConfig } from \"./types\";\n\nlet instance: YunoDashboard | null = null;\n\nexport function initYunoDashboard(config: YunoDashboardConfig): YunoDashboard {\n if (instance) {\n instance.destroy();\n }\n instance = new YunoDashboard(config);\n return instance;\n}\n\nexport function getYunoDashboard(): YunoDashboard | null {\n return instance;\n}\n\nexport function destroyYunoDashboard(): void {\n if (instance) {\n instance.destroy();\n instance = null;\n }\n}\n"],"mappings":";AAEO,IAAM,gBAAN,MAAoB;AAAA,EAczB,YAAY,QAA6B;AAXzC,SAAQ,UAA8B;AAEtC,SAAQ,QAAQ;AAChB,SAAQ,QAAmC,CAAC;AAS1C,SAAK,UAAU,OAAO;AACtB,SAAK,eAAe,OAAO;AAC3B,SAAK,cAAc,OAAO;AAC1B,SA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