@howone/sdk 0.1.17 → 0.1.19
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.mts +67 -24
- package/dist/index.d.ts +67 -24
- package/dist/index.js +657 -290
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +654 -292
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -2
package/dist/index.mjs
CHANGED
|
@@ -232,7 +232,7 @@ var FloatingButton = ({
|
|
|
232
232
|
{
|
|
233
233
|
onClick,
|
|
234
234
|
id: "floating-howone-btn",
|
|
235
|
-
className: `fixed flex bg-white gap-2 items-center right-4 z-50 text-black px-3 py-2 rounded-lg shadow-lg transition-colors duration-200 ${className}`,
|
|
235
|
+
className: `fixed flex bg-white dark:bg-gray-800 gap-2 items-center right-4 z-50 text-black dark:text-white px-3 py-2 rounded-lg shadow-lg transition-colors duration-200 border border-gray-200 dark:border-gray-700 ${className}`,
|
|
236
236
|
style: {
|
|
237
237
|
fontSize: "14px",
|
|
238
238
|
fontWeight: "bold",
|
|
@@ -245,7 +245,7 @@ var FloatingButton = ({
|
|
|
245
245
|
e.stopPropagation();
|
|
246
246
|
const btn = document.getElementById("floating-howone-btn");
|
|
247
247
|
if (btn) btn.style.display = "none";
|
|
248
|
-
}, className: "w-5 h-5 font-bold pointer-events-auto" })
|
|
248
|
+
}, className: "w-5 h-5 font-bold pointer-events-auto text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-200" })
|
|
249
249
|
] })
|
|
250
250
|
}
|
|
251
251
|
);
|
|
@@ -328,10 +328,8 @@ var UnifiedAuthService = class {
|
|
|
328
328
|
};
|
|
329
329
|
popupCheckInterval = window.setInterval(checkPopupStatus, 1e3);
|
|
330
330
|
const messageHandler = (event) => {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
"https://create-x-backend-dev.fly.dev"
|
|
334
|
-
];
|
|
331
|
+
console.log("messageHandler", event);
|
|
332
|
+
const validOrigins = [window.location.origin, "https://create-x-backend-dev.fly.dev"];
|
|
335
333
|
const isValidOrigin = validOrigins.some(
|
|
336
334
|
(origin) => event.origin === origin || event.origin.includes("localhost") || event.origin.includes("127.0.0.1") || event.origin.includes("fly.dev")
|
|
337
335
|
);
|
|
@@ -591,7 +589,7 @@ var UnifiedAuthService = class {
|
|
|
591
589
|
const response = await fetch(`${this.API_BASE_URL}/api/auth/verify`, {
|
|
592
590
|
method: "GET",
|
|
593
591
|
headers: {
|
|
594
|
-
|
|
592
|
+
Authorization: `Bearer ${token}`
|
|
595
593
|
}
|
|
596
594
|
});
|
|
597
595
|
if (response.ok) {
|
|
@@ -622,8 +620,8 @@ var UnifiedAuthService = class {
|
|
|
622
620
|
}
|
|
623
621
|
}
|
|
624
622
|
/**
|
|
625
|
-
|
|
626
|
-
|
|
623
|
+
* 保存认证数据到本地存储
|
|
624
|
+
*/
|
|
627
625
|
saveAuthData(token) {
|
|
628
626
|
try {
|
|
629
627
|
try {
|
|
@@ -644,7 +642,7 @@ var UnifiedAuthService = class {
|
|
|
644
642
|
await fetch(`${this.API_BASE_URL}/api/auth/logout`, {
|
|
645
643
|
method: "POST",
|
|
646
644
|
headers: {
|
|
647
|
-
|
|
645
|
+
Authorization: `Bearer ${token}`
|
|
648
646
|
}
|
|
649
647
|
});
|
|
650
648
|
} catch (error) {
|
|
@@ -992,12 +990,25 @@ function setupClearUrlTokenListener(opts) {
|
|
|
992
990
|
}
|
|
993
991
|
|
|
994
992
|
// src/services/index.ts
|
|
993
|
+
function getGlobalAvailableToken() {
|
|
994
|
+
try {
|
|
995
|
+
return getToken() || null;
|
|
996
|
+
} catch {
|
|
997
|
+
return null;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
995
1000
|
var request = new request_default({
|
|
996
1001
|
baseURL: "https://create-x-backend-dev.fly.dev/api",
|
|
997
1002
|
timeout: 6e4,
|
|
998
1003
|
interceptors: {
|
|
999
1004
|
requestInterceptor: (config) => {
|
|
1000
1005
|
config.headers = config.headers || {};
|
|
1006
|
+
if (!config.headers["Authorization"]) {
|
|
1007
|
+
const availableToken = getGlobalAvailableToken();
|
|
1008
|
+
if (availableToken) {
|
|
1009
|
+
config.headers["Authorization"] = `Bearer ${availableToken}`;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1001
1012
|
return config;
|
|
1002
1013
|
},
|
|
1003
1014
|
requestInterceptorCatch: (err) => {
|
|
@@ -1017,6 +1028,12 @@ var aiRequest = new request_default({
|
|
|
1017
1028
|
interceptors: {
|
|
1018
1029
|
requestInterceptor: (config) => {
|
|
1019
1030
|
config.headers = config.headers || {};
|
|
1031
|
+
if (!config.headers["Authorization"]) {
|
|
1032
|
+
const availableToken = getGlobalAvailableToken();
|
|
1033
|
+
if (availableToken) {
|
|
1034
|
+
config.headers["Authorization"] = `Bearer ${availableToken}`;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1020
1037
|
return config;
|
|
1021
1038
|
},
|
|
1022
1039
|
requestInterceptorCatch: (err) => {
|
|
@@ -1072,6 +1089,12 @@ function createClient(opts) {
|
|
|
1072
1089
|
interceptors: {
|
|
1073
1090
|
requestInterceptor: (config) => {
|
|
1074
1091
|
config.headers = config.headers || {};
|
|
1092
|
+
if (!config.headers["Authorization"]) {
|
|
1093
|
+
const availableToken = getAvailableToken();
|
|
1094
|
+
if (availableToken) {
|
|
1095
|
+
config.headers["Authorization"] = `Bearer ${availableToken}`;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1075
1098
|
return config;
|
|
1076
1099
|
},
|
|
1077
1100
|
requestInterceptorCatch: (err) => Promise.reject(err),
|
|
@@ -1084,12 +1107,23 @@ function createClient(opts) {
|
|
|
1084
1107
|
const ai = opts?.aiRequestInstance || makeRequestFromBase(opts?.aiBaseUrl) || aiRequest;
|
|
1085
1108
|
const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
|
|
1086
1109
|
let token = null;
|
|
1110
|
+
function getAvailableToken() {
|
|
1111
|
+
return token || getGlobalAvailableToken();
|
|
1112
|
+
}
|
|
1087
1113
|
try {
|
|
1088
1114
|
if (opts?.projectId) {
|
|
1089
1115
|
setDefaultProjectId(String(opts.projectId));
|
|
1090
1116
|
}
|
|
1091
1117
|
} catch {
|
|
1092
1118
|
}
|
|
1119
|
+
try {
|
|
1120
|
+
const existingToken = getToken();
|
|
1121
|
+
if (existingToken) {
|
|
1122
|
+
token = existingToken;
|
|
1123
|
+
applyToken(token);
|
|
1124
|
+
}
|
|
1125
|
+
} catch {
|
|
1126
|
+
}
|
|
1093
1127
|
function applyToken(t) {
|
|
1094
1128
|
try {
|
|
1095
1129
|
try {
|
|
@@ -1109,7 +1143,8 @@ function createClient(opts) {
|
|
|
1109
1143
|
const runtimeMode = (() => {
|
|
1110
1144
|
if (opts?.mode) return opts.mode;
|
|
1111
1145
|
try {
|
|
1112
|
-
if (typeof window !== "undefined")
|
|
1146
|
+
if (typeof window !== "undefined")
|
|
1147
|
+
return window.self !== window.top ? "embedded" : "standalone";
|
|
1113
1148
|
} catch (_e) {
|
|
1114
1149
|
return "standalone";
|
|
1115
1150
|
}
|
|
@@ -1463,111 +1498,13 @@ var LoginForm = ({
|
|
|
1463
1498
|
};
|
|
1464
1499
|
|
|
1465
1500
|
// src/components/auth/AuthProvider.tsx
|
|
1466
|
-
import { createContext, useContext, useEffect as useEffect3, useState as useState3 } from "react";
|
|
1467
1501
|
init_auth();
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
// src/components/ui/Loading.tsx
|
|
1471
|
-
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1472
|
-
var Loading = ({
|
|
1473
|
-
size = "md",
|
|
1474
|
-
text = "Loading...",
|
|
1475
|
-
className = "",
|
|
1476
|
-
fullScreen = false
|
|
1477
|
-
}) => {
|
|
1478
|
-
const sizeClasses = {
|
|
1479
|
-
sm: "h-4 w-4",
|
|
1480
|
-
md: "h-8 w-8",
|
|
1481
|
-
lg: "h-12 w-12"
|
|
1482
|
-
};
|
|
1483
|
-
const containerClasses = fullScreen ? "fixed inset-0 flex items-center justify-center bg-white/80 backdrop-blur-sm z-50" : "flex items-center justify-center p-4";
|
|
1484
|
-
return /* @__PURE__ */ jsx3("div", { className: `${containerClasses} ${className}`, children: /* @__PURE__ */ jsxs3("div", { className: "text-center", children: [
|
|
1485
|
-
/* @__PURE__ */ jsx3(
|
|
1486
|
-
"div",
|
|
1487
|
-
{
|
|
1488
|
-
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 mx-auto ${sizeClasses[size]}`
|
|
1489
|
-
}
|
|
1490
|
-
),
|
|
1491
|
-
text && /* @__PURE__ */ jsx3("p", { className: "mt-2 text-sm text-gray-600", children: text })
|
|
1492
|
-
] }) });
|
|
1493
|
-
};
|
|
1494
|
-
var LoadingSpinner = ({
|
|
1495
|
-
size = "md",
|
|
1496
|
-
className = ""
|
|
1497
|
-
}) => {
|
|
1498
|
-
const sizeClasses = {
|
|
1499
|
-
sm: "h-4 w-4",
|
|
1500
|
-
md: "h-8 w-8",
|
|
1501
|
-
lg: "h-12 w-12"
|
|
1502
|
-
};
|
|
1503
|
-
return /* @__PURE__ */ jsx3(
|
|
1504
|
-
"div",
|
|
1505
|
-
{
|
|
1506
|
-
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 ${sizeClasses[size]} ${className}`
|
|
1507
|
-
}
|
|
1508
|
-
);
|
|
1509
|
-
};
|
|
1510
|
-
|
|
1511
|
-
// src/components/auth/AuthProvider.tsx
|
|
1512
|
-
import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1502
|
+
import { createContext, useContext, useState as useState3 } from "react";
|
|
1503
|
+
import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1513
1504
|
var AuthContext = createContext(null);
|
|
1514
|
-
var AuthProvider = ({ children,
|
|
1505
|
+
var AuthProvider = ({ children, showFloatingButton = true }) => {
|
|
1515
1506
|
const [user, setUser] = useState3(() => parseUserFromToken(getToken()));
|
|
1516
1507
|
const [token, setTokenState] = useState3(() => getToken());
|
|
1517
|
-
const [isLoading, setIsLoading] = useState3(false);
|
|
1518
|
-
useEffect3(() => {
|
|
1519
|
-
try {
|
|
1520
|
-
if (projectId) setDefaultProjectId(String(projectId));
|
|
1521
|
-
} catch {
|
|
1522
|
-
}
|
|
1523
|
-
setIsLoading(true);
|
|
1524
|
-
try {
|
|
1525
|
-
const cb = unifiedAuth.checkOAuthCallback();
|
|
1526
|
-
if (cb && cb.success) {
|
|
1527
|
-
setTokenState(cb.token ?? getToken());
|
|
1528
|
-
setUser(cb.user ?? parseUserFromToken(cb.token ?? getToken()));
|
|
1529
|
-
setIsLoading(false);
|
|
1530
|
-
return;
|
|
1531
|
-
}
|
|
1532
|
-
} catch {
|
|
1533
|
-
}
|
|
1534
|
-
const unsubscribe = onAuthStateChanged((state) => {
|
|
1535
|
-
try {
|
|
1536
|
-
setTokenState(getToken());
|
|
1537
|
-
setUser(state.user ?? parseUserFromToken(getToken()));
|
|
1538
|
-
} catch {
|
|
1539
|
-
}
|
|
1540
|
-
setIsLoading(false);
|
|
1541
|
-
if (autoRedirect && !state.user) {
|
|
1542
|
-
try {
|
|
1543
|
-
const root = getAuthRoot();
|
|
1544
|
-
const authUrl = new URL("/auth", String(root));
|
|
1545
|
-
authUrl.searchParams.set("redirect_uri", window.location.href);
|
|
1546
|
-
const pid = getDefaultProjectId();
|
|
1547
|
-
if (pid) authUrl.searchParams.set("project_id", pid);
|
|
1548
|
-
try {
|
|
1549
|
-
if (window.top && window.top !== window) {
|
|
1550
|
-
window.top.location.replace(authUrl.toString());
|
|
1551
|
-
} else {
|
|
1552
|
-
window.location.replace(authUrl.toString());
|
|
1553
|
-
}
|
|
1554
|
-
} catch (e) {
|
|
1555
|
-
try {
|
|
1556
|
-
window.location.replace(authUrl.toString());
|
|
1557
|
-
} catch {
|
|
1558
|
-
}
|
|
1559
|
-
}
|
|
1560
|
-
} catch {
|
|
1561
|
-
}
|
|
1562
|
-
}
|
|
1563
|
-
});
|
|
1564
|
-
return () => {
|
|
1565
|
-
try {
|
|
1566
|
-
unsubscribe();
|
|
1567
|
-
} catch {
|
|
1568
|
-
}
|
|
1569
|
-
};
|
|
1570
|
-
}, [autoRedirect]);
|
|
1571
1508
|
const logout = () => {
|
|
1572
1509
|
try {
|
|
1573
1510
|
setToken(null);
|
|
@@ -1582,12 +1519,9 @@ var AuthProvider = ({ children, autoRedirect = true, showFloatingButton = true,
|
|
|
1582
1519
|
isAuthenticated: !!token,
|
|
1583
1520
|
logout
|
|
1584
1521
|
};
|
|
1585
|
-
return /* @__PURE__ */
|
|
1586
|
-
/* @__PURE__ */ jsx4(Loading, { fullScreen: true, text: "Checking authentication..." }),
|
|
1587
|
-
showFloatingButton && /* @__PURE__ */ jsx4(FloatingButton, { onClick: () => window.open("https://howone.ai", "_blank") })
|
|
1588
|
-
] }) : /* @__PURE__ */ jsxs4(Fragment, { children: [
|
|
1522
|
+
return /* @__PURE__ */ jsx3(AuthContext.Provider, { value, children: /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
1589
1523
|
children,
|
|
1590
|
-
showFloatingButton && /* @__PURE__ */
|
|
1524
|
+
showFloatingButton && /* @__PURE__ */ jsx3(FloatingButton, { onClick: () => window.open("https://howone.ai", "_blank") })
|
|
1591
1525
|
] }) });
|
|
1592
1526
|
};
|
|
1593
1527
|
function useAuthContext() {
|
|
@@ -1694,6 +1628,47 @@ var howone = {
|
|
|
1694
1628
|
};
|
|
1695
1629
|
var client_default = howone;
|
|
1696
1630
|
|
|
1631
|
+
// src/components/ui/Loading.tsx
|
|
1632
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1633
|
+
var Loading = ({
|
|
1634
|
+
size = "md",
|
|
1635
|
+
text = "Loading...",
|
|
1636
|
+
className = "",
|
|
1637
|
+
fullScreen = false
|
|
1638
|
+
}) => {
|
|
1639
|
+
const sizeClasses = {
|
|
1640
|
+
sm: "h-4 w-4",
|
|
1641
|
+
md: "h-8 w-8",
|
|
1642
|
+
lg: "h-12 w-12"
|
|
1643
|
+
};
|
|
1644
|
+
const containerClasses = fullScreen ? "fixed inset-0 flex items-center justify-center bg-white/80 backdrop-blur-sm z-50" : "flex items-center justify-center p-4";
|
|
1645
|
+
return /* @__PURE__ */ jsx4("div", { className: `${containerClasses} ${className}`, children: /* @__PURE__ */ jsxs4("div", { className: "text-center", children: [
|
|
1646
|
+
/* @__PURE__ */ jsx4(
|
|
1647
|
+
"div",
|
|
1648
|
+
{
|
|
1649
|
+
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 mx-auto ${sizeClasses[size]}`
|
|
1650
|
+
}
|
|
1651
|
+
),
|
|
1652
|
+
text && /* @__PURE__ */ jsx4("p", { className: "mt-2 text-sm text-gray-600", children: text })
|
|
1653
|
+
] }) });
|
|
1654
|
+
};
|
|
1655
|
+
var LoadingSpinner = ({
|
|
1656
|
+
size = "md",
|
|
1657
|
+
className = ""
|
|
1658
|
+
}) => {
|
|
1659
|
+
const sizeClasses = {
|
|
1660
|
+
sm: "h-4 w-4",
|
|
1661
|
+
md: "h-8 w-8",
|
|
1662
|
+
lg: "h-12 w-12"
|
|
1663
|
+
};
|
|
1664
|
+
return /* @__PURE__ */ jsx4(
|
|
1665
|
+
"div",
|
|
1666
|
+
{
|
|
1667
|
+
className: `animate-spin rounded-full border-2 border-gray-300 border-t-blue-600 ${sizeClasses[size]} ${className}`
|
|
1668
|
+
}
|
|
1669
|
+
);
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1697
1672
|
// src/components/ui/ErrorBoundary.tsx
|
|
1698
1673
|
import { Component } from "react";
|
|
1699
1674
|
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
@@ -1752,12 +1727,273 @@ var DefaultErrorFallback = ({ retry }) => /* @__PURE__ */ jsx5("div", { classNam
|
|
|
1752
1727
|
)
|
|
1753
1728
|
] }) });
|
|
1754
1729
|
|
|
1755
|
-
// src/
|
|
1730
|
+
// src/components/theme/ThemeProvider.tsx
|
|
1731
|
+
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, useState as useState4 } from "react";
|
|
1732
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
1733
|
+
var initialState = {
|
|
1734
|
+
theme: "system",
|
|
1735
|
+
setTheme: () => null
|
|
1736
|
+
};
|
|
1737
|
+
var ThemeProviderContext = createContext2(initialState);
|
|
1738
|
+
function ThemeProvider({
|
|
1739
|
+
children,
|
|
1740
|
+
defaultTheme = "system",
|
|
1741
|
+
storageKey = "vite-ui-theme",
|
|
1742
|
+
...props
|
|
1743
|
+
}) {
|
|
1744
|
+
const [theme, setTheme] = useState4(
|
|
1745
|
+
() => localStorage.getItem(storageKey) || defaultTheme
|
|
1746
|
+
);
|
|
1747
|
+
useEffect3(() => {
|
|
1748
|
+
const root = window.document.documentElement;
|
|
1749
|
+
root.classList.remove("light", "dark");
|
|
1750
|
+
if (theme === "system") {
|
|
1751
|
+
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1752
|
+
root.classList.add(systemTheme);
|
|
1753
|
+
return;
|
|
1754
|
+
}
|
|
1755
|
+
root.classList.add(theme);
|
|
1756
|
+
}, [theme]);
|
|
1757
|
+
const value = {
|
|
1758
|
+
theme,
|
|
1759
|
+
setTheme: (theme2) => {
|
|
1760
|
+
localStorage.setItem(storageKey, theme2);
|
|
1761
|
+
setTheme(theme2);
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
return /* @__PURE__ */ jsx6(ThemeProviderContext.Provider, { ...props, value, children });
|
|
1765
|
+
}
|
|
1766
|
+
var useTheme = () => {
|
|
1767
|
+
const context = useContext2(ThemeProviderContext);
|
|
1768
|
+
if (context === void 0)
|
|
1769
|
+
throw new Error("useTheme must be used within a ThemeProvider");
|
|
1770
|
+
return context;
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
// src/components/theme/ThemeToggle.tsx
|
|
1756
1774
|
import * as React4 from "react";
|
|
1775
|
+
import { useTheme as useTheme2 } from "next-themes";
|
|
1776
|
+
import { Icon as Icon3 } from "@iconify/react";
|
|
1777
|
+
import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1778
|
+
function ThemeToggle({ className }) {
|
|
1779
|
+
const { setTheme, theme } = useTheme2();
|
|
1780
|
+
const [mounted, setMounted] = React4.useState(false);
|
|
1781
|
+
React4.useEffect(() => {
|
|
1782
|
+
setMounted(true);
|
|
1783
|
+
}, []);
|
|
1784
|
+
if (!mounted) {
|
|
1785
|
+
return /* @__PURE__ */ jsxs6(
|
|
1786
|
+
"button",
|
|
1787
|
+
{
|
|
1788
|
+
className: `relative inline-flex h-10 w-12 items-center justify-center rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground ${className || ""}`,
|
|
1789
|
+
disabled: true,
|
|
1790
|
+
children: [
|
|
1791
|
+
/* @__PURE__ */ jsx7(Icon3, { icon: "solar:sun-2-linear", width: 20, height: 20 }),
|
|
1792
|
+
/* @__PURE__ */ jsx7("span", { className: "sr-only", children: "Toggle theme" })
|
|
1793
|
+
]
|
|
1794
|
+
}
|
|
1795
|
+
);
|
|
1796
|
+
}
|
|
1797
|
+
return /* @__PURE__ */ jsxs6(
|
|
1798
|
+
"button",
|
|
1799
|
+
{
|
|
1800
|
+
className: `inline-flex h-10 w-12 items-center justify-center rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors ${className || ""}`,
|
|
1801
|
+
onClick: () => setTheme(theme === "light" ? "dark" : "light"),
|
|
1802
|
+
children: [
|
|
1803
|
+
theme === "light" ? /* @__PURE__ */ jsx7(Icon3, { icon: "solar:sun-2-linear", width: 20, height: 20 }) : /* @__PURE__ */ jsx7(Icon3, { icon: "solar:moon-linear", width: 20, height: 20 }),
|
|
1804
|
+
/* @__PURE__ */ jsx7("span", { className: "sr-only", children: "Toggle theme" })
|
|
1805
|
+
]
|
|
1806
|
+
}
|
|
1807
|
+
);
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1810
|
+
// src/components/ui/Toast/GlobalToastContainer.tsx
|
|
1811
|
+
import { ToastContainer } from "react-toastify";
|
|
1812
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1813
|
+
function GlobalToastContainer() {
|
|
1814
|
+
return /* @__PURE__ */ jsx8(
|
|
1815
|
+
ToastContainer,
|
|
1816
|
+
{
|
|
1817
|
+
newestOnTop: false,
|
|
1818
|
+
closeButton: false
|
|
1819
|
+
}
|
|
1820
|
+
);
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// src/components/ui/Toast/ClayxToast.tsx
|
|
1824
|
+
import React5, { useCallback } from "react";
|
|
1825
|
+
import { Bounce, toast } from "react-toastify";
|
|
1826
|
+
import { Icon as Icon4 } from "@iconify/react";
|
|
1827
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1828
|
+
var TOAST_ICONS = {
|
|
1829
|
+
success: {
|
|
1830
|
+
icon: "mdi:success",
|
|
1831
|
+
color: "text-green-400",
|
|
1832
|
+
className: "text-green-400",
|
|
1833
|
+
bgGradient: "bg-[#14181df2]",
|
|
1834
|
+
gradientColor: "#389726",
|
|
1835
|
+
borderGradient: "border-[#389726]",
|
|
1836
|
+
borderGradientColor: "#389726"
|
|
1837
|
+
},
|
|
1838
|
+
error: {
|
|
1839
|
+
icon: "ic:outline-close",
|
|
1840
|
+
color: "text-red-400",
|
|
1841
|
+
className: "text-red-400",
|
|
1842
|
+
bgGradient: "bg-[#14181df2]",
|
|
1843
|
+
gradientColor: "#ef4444",
|
|
1844
|
+
borderGradient: "border-[#ef4444]",
|
|
1845
|
+
borderGradientColor: "#ef4444"
|
|
1846
|
+
},
|
|
1847
|
+
warning: {
|
|
1848
|
+
icon: "mi:warning",
|
|
1849
|
+
color: "text-yellow-400",
|
|
1850
|
+
className: "text-yellow-400",
|
|
1851
|
+
bgGradient: "bg-[#14181df2]",
|
|
1852
|
+
gradientColor: "#facc15",
|
|
1853
|
+
borderGradient: "border-[#facc15]",
|
|
1854
|
+
borderGradientColor: "#facc15"
|
|
1855
|
+
},
|
|
1856
|
+
info: {
|
|
1857
|
+
icon: "ic:outline-info",
|
|
1858
|
+
color: "text-blue-400",
|
|
1859
|
+
className: "text-blue-400",
|
|
1860
|
+
bgGradient: "bg-[#14181df2]",
|
|
1861
|
+
gradientColor: "#60a5fa",
|
|
1862
|
+
borderGradient: "border-[#60a5fa]",
|
|
1863
|
+
borderGradientColor: "#f0f0f0"
|
|
1864
|
+
},
|
|
1865
|
+
default: {
|
|
1866
|
+
icon: "ic:round-notifications",
|
|
1867
|
+
color: "text-gray-400",
|
|
1868
|
+
className: "text-gray-400",
|
|
1869
|
+
bgGradient: "bg-[#14181df2]",
|
|
1870
|
+
gradientColor: "#9ca3af",
|
|
1871
|
+
borderGradient: "border-[#9ca3af]",
|
|
1872
|
+
borderGradientColor: "#9ca3af"
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
var CloseButton = React5.memo(({ closeToast }) => {
|
|
1876
|
+
const handleClick = useCallback((e) => {
|
|
1877
|
+
e.preventDefault();
|
|
1878
|
+
e.stopPropagation();
|
|
1879
|
+
closeToast?.();
|
|
1880
|
+
}, [closeToast]);
|
|
1881
|
+
return /* @__PURE__ */ jsx9(
|
|
1882
|
+
Icon4,
|
|
1883
|
+
{
|
|
1884
|
+
icon: "vaadin:close",
|
|
1885
|
+
className: "flex items-center justify-center rounded-full relative z-10 flex-shrink-0 cursor-pointer \n !text-[#b4b4b4] hover:text-white transition-colors duration-200 drop-shadow-sm",
|
|
1886
|
+
onClick: handleClick,
|
|
1887
|
+
width: 14,
|
|
1888
|
+
height: 14
|
|
1889
|
+
}
|
|
1890
|
+
);
|
|
1891
|
+
});
|
|
1892
|
+
CloseButton.displayName = "CloseButton";
|
|
1893
|
+
var ToastContent = ({ type, title, message, component, closeToast }) => {
|
|
1894
|
+
const iconConfig = TOAST_ICONS[type];
|
|
1895
|
+
const handleClose = useCallback(() => {
|
|
1896
|
+
closeToast?.();
|
|
1897
|
+
}, [closeToast]);
|
|
1898
|
+
console.log(iconConfig, "????????");
|
|
1899
|
+
if (component) {
|
|
1900
|
+
return /* @__PURE__ */ jsxs7("div", { className: `flex items-start gap-3 min-h-[80px] w-full backdrop-blur-md
|
|
1901
|
+
rounded-xl p-4 shadow-2xl relative overflow-hidden ${iconConfig.bgGradient}`, children: [
|
|
1902
|
+
/* @__PURE__ */ jsx9("div", { className: "flex-1 relative z-10", children: component }),
|
|
1903
|
+
/* @__PURE__ */ jsx9("div", { className: "relative z-10", children: /* @__PURE__ */ jsx9(CloseButton, { closeToast: handleClose }) })
|
|
1904
|
+
] });
|
|
1905
|
+
}
|
|
1906
|
+
return /* @__PURE__ */ jsxs7("div", { className: `flex items-start gap-3 min-h-[60px] w-full backdrop-blur-md
|
|
1907
|
+
rounded-xl p-4 shadow-2xl relative overflow-hidden ${iconConfig.bgGradient}`, children: [
|
|
1908
|
+
/* @__PURE__ */ jsx9(
|
|
1909
|
+
"div",
|
|
1910
|
+
{
|
|
1911
|
+
className: "absolute left-0 top-0 w-full h-full pointer-events-none rounded-xl",
|
|
1912
|
+
style: {
|
|
1913
|
+
background: `linear-gradient(135deg, ${iconConfig.gradientColor}30 0%, ${iconConfig.gradientColor}20 15%, #14181df2 30%)`
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
),
|
|
1917
|
+
/* @__PURE__ */ jsx9(
|
|
1918
|
+
"div",
|
|
1919
|
+
{
|
|
1920
|
+
className: "absolute left-0 top-0 w-full h-full pointer-events-none rounded-xl",
|
|
1921
|
+
style: {
|
|
1922
|
+
border: "2px solid transparent",
|
|
1923
|
+
backgroundImage: `linear-gradient(135deg, ${iconConfig.borderGradientColor}60 0%, ${iconConfig.borderGradientColor}40 5%, transparent 22%)`,
|
|
1924
|
+
backgroundOrigin: "border-box",
|
|
1925
|
+
backgroundClip: "border-box",
|
|
1926
|
+
WebkitMask: "linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0)",
|
|
1927
|
+
WebkitMaskComposite: "xor",
|
|
1928
|
+
mask: "linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0)",
|
|
1929
|
+
maskComposite: "exclude"
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
),
|
|
1933
|
+
/* @__PURE__ */ jsx9("div", { className: "flex-shrink-0 mt-0.5 relative z-10 ", children: /* @__PURE__ */ jsx9("div", { className: "w-7 h-7 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsx9(
|
|
1934
|
+
Icon4,
|
|
1935
|
+
{
|
|
1936
|
+
icon: iconConfig.icon,
|
|
1937
|
+
width: 16,
|
|
1938
|
+
height: 16,
|
|
1939
|
+
className: iconConfig.color
|
|
1940
|
+
}
|
|
1941
|
+
) }) }),
|
|
1942
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex flex-col gap-1 flex-1 relative z-10", children: [
|
|
1943
|
+
title && /* @__PURE__ */ jsx9("div", { className: "text-[16px] font-semibold leading-tight text-white/95 drop-shadow-sm", children: title }),
|
|
1944
|
+
message && /* @__PURE__ */ jsx9("div", { className: "text-[13px] font-normal leading-relaxed text-white/75 drop-shadow-sm", children: message })
|
|
1945
|
+
] }),
|
|
1946
|
+
/* @__PURE__ */ jsx9("div", { className: "relative z-10", children: /* @__PURE__ */ jsx9(CloseButton, { closeToast: handleClose }) })
|
|
1947
|
+
] });
|
|
1948
|
+
};
|
|
1949
|
+
var defaultToastOptions = {
|
|
1950
|
+
position: "bottom-right",
|
|
1951
|
+
autoClose: 3e3,
|
|
1952
|
+
hideProgressBar: true,
|
|
1953
|
+
closeOnClick: false,
|
|
1954
|
+
pauseOnHover: true,
|
|
1955
|
+
draggable: true,
|
|
1956
|
+
pauseOnFocusLoss: false,
|
|
1957
|
+
theme: "dark",
|
|
1958
|
+
transition: Bounce
|
|
1959
|
+
};
|
|
1960
|
+
var createToast = (type) => {
|
|
1961
|
+
return (params) => {
|
|
1962
|
+
const { title, message, component, options } = params;
|
|
1963
|
+
toast(
|
|
1964
|
+
({ closeToast }) => /* @__PURE__ */ jsx9(
|
|
1965
|
+
ToastContent,
|
|
1966
|
+
{
|
|
1967
|
+
type,
|
|
1968
|
+
title,
|
|
1969
|
+
message: message || "",
|
|
1970
|
+
component,
|
|
1971
|
+
closeToast
|
|
1972
|
+
}
|
|
1973
|
+
),
|
|
1974
|
+
{
|
|
1975
|
+
...defaultToastOptions,
|
|
1976
|
+
...options,
|
|
1977
|
+
className: "!bg-transparent !p-0 !shadow-none",
|
|
1978
|
+
style: { background: "transparent", padding: 0 }
|
|
1979
|
+
}
|
|
1980
|
+
);
|
|
1981
|
+
};
|
|
1982
|
+
};
|
|
1983
|
+
var ClayxToast = {
|
|
1984
|
+
success: createToast("success"),
|
|
1985
|
+
error: createToast("error"),
|
|
1986
|
+
warning: createToast("warning"),
|
|
1987
|
+
info: createToast("info"),
|
|
1988
|
+
default: createToast("default")
|
|
1989
|
+
};
|
|
1990
|
+
|
|
1991
|
+
// src/hooks/use-mobile.ts
|
|
1992
|
+
import * as React6 from "react";
|
|
1757
1993
|
var MOBILE_BREAKPOINT = 768;
|
|
1758
1994
|
function useIsMobile() {
|
|
1759
|
-
const [isMobile, setIsMobile] =
|
|
1760
|
-
|
|
1995
|
+
const [isMobile, setIsMobile] = React6.useState(void 0);
|
|
1996
|
+
React6.useEffect(() => {
|
|
1761
1997
|
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
1762
1998
|
const onChange = () => {
|
|
1763
1999
|
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
@@ -1770,10 +2006,10 @@ function useIsMobile() {
|
|
|
1770
2006
|
}
|
|
1771
2007
|
|
|
1772
2008
|
// src/hooks/use-debounce.ts
|
|
1773
|
-
import { useState as
|
|
2009
|
+
import { useState as useState7, useEffect as useEffect6 } from "react";
|
|
1774
2010
|
function useDebounce(value, delay) {
|
|
1775
|
-
const [debouncedValue, setDebouncedValue] =
|
|
1776
|
-
|
|
2011
|
+
const [debouncedValue, setDebouncedValue] = useState7(value);
|
|
2012
|
+
useEffect6(() => {
|
|
1777
2013
|
const handler = setTimeout(() => {
|
|
1778
2014
|
setDebouncedValue(value);
|
|
1779
2015
|
}, delay);
|
|
@@ -1784,214 +2020,335 @@ function useDebounce(value, delay) {
|
|
|
1784
2020
|
return debouncedValue;
|
|
1785
2021
|
}
|
|
1786
2022
|
|
|
1787
|
-
// src/utils/
|
|
1788
|
-
function
|
|
1789
|
-
|
|
1790
|
-
const
|
|
1791
|
-
(
|
|
1792
|
-
const isIframe = window.self !== window.top;
|
|
1793
|
-
console.log("isIframe", isIframe);
|
|
2023
|
+
// src/utils/errorHandler.ts
|
|
2024
|
+
var ERROR_HANDLER_SCRIPT = `(function () {
|
|
2025
|
+
// \u68C0\u67E5\u662F\u5426\u5728 iframe \u4E2D\u8FD0\u884C
|
|
2026
|
+
const isIframe = window.self !== window.top;
|
|
2027
|
+
console.log("isIframe", isIframe);
|
|
1794
2028
|
|
|
1795
|
-
|
|
2029
|
+
console.log("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u521D\u59CB\u5316");
|
|
1796
2030
|
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
2031
|
+
// \u76F4\u63A5\u53D1\u9001\u9519\u8BEF\u5230\u7236\u7A97\u53E3\u7684\u51FD\u6570
|
|
2032
|
+
window.__SEND_ERROR_TO_PARENT__ = function (error, details) {
|
|
2033
|
+
try {
|
|
2034
|
+
const errorPayload = {
|
|
2035
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2036
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
2037
|
+
filename: details?.file || details?.filename,
|
|
2038
|
+
lineno: details?.line,
|
|
2039
|
+
colno: details?.column,
|
|
2040
|
+
timestamp: Date.now(),
|
|
2041
|
+
type: details?.type || "compile-error",
|
|
2042
|
+
details: details,
|
|
2043
|
+
};
|
|
1809
2044
|
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
2045
|
+
window.parent.postMessage(
|
|
2046
|
+
{
|
|
2047
|
+
type: "ERROR_EVENT",
|
|
2048
|
+
payload: errorPayload,
|
|
2049
|
+
},
|
|
2050
|
+
"*"
|
|
2051
|
+
);
|
|
2052
|
+
|
|
2053
|
+
console.log("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u9519\u8BEF\u5DF2\u53D1\u9001\u5230\u7236\u7A97\u53E3:", errorPayload);
|
|
2054
|
+
} catch (e) {
|
|
2055
|
+
console.error("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u53D1\u9001\u9519\u8BEF\u5230\u7236\u7A97\u53E3\u5931\u8D25:", e);
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
1816
2058
|
|
|
1817
|
-
|
|
1818
|
-
|
|
2059
|
+
// \u8BBE\u7F6E MutationObserver \u76D1\u542C vite-error-overlay
|
|
2060
|
+
function setupViteOverlayObserver() {
|
|
2061
|
+
if (!window.MutationObserver) return;
|
|
1819
2062
|
|
|
1820
|
-
|
|
2063
|
+
console.log("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u8BBE\u7F6E Vite \u9519\u8BEF overlay \u76D1\u542C\u5668");
|
|
1821
2064
|
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
const shadowRoot = overlay.shadowRoot;
|
|
1826
|
-
if (!shadowRoot) return;
|
|
2065
|
+
function processViteErrorOverlay(overlay) {
|
|
2066
|
+
try {
|
|
2067
|
+
if (overlay.hasAttribute("data-error-sent")) return;
|
|
1827
2068
|
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
2069
|
+
const shadowRoot = overlay.shadowRoot;
|
|
2070
|
+
if (!shadowRoot) {
|
|
2071
|
+
console.log("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] vite-error-overlay \u6CA1\u6709 Shadow DOM");
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
1832
2074
|
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
2075
|
+
const messageElement = shadowRoot.querySelector("pre.message");
|
|
2076
|
+
const fileElement = shadowRoot.querySelector("pre.file");
|
|
2077
|
+
const frameElements = shadowRoot.querySelectorAll("pre.frame");
|
|
2078
|
+
const stackElement = shadowRoot.querySelector("pre.stack");
|
|
2079
|
+
|
|
2080
|
+
const message = messageElement ? messageElement.textContent : "";
|
|
2081
|
+
const file = fileElement ? fileElement.textContent : "";
|
|
2082
|
+
const frames = Array.from(frameElements)
|
|
2083
|
+
.map((el) => el.textContent)
|
|
2084
|
+
.join("
|
|
1836
2085
|
");
|
|
1837
|
-
|
|
2086
|
+
const stack = stackElement ? stackElement.textContent : "";
|
|
1838
2087
|
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
2088
|
+
let line, column;
|
|
2089
|
+
const fileStr = file || "";
|
|
2090
|
+
const lineColMatch = fileStr.match(/(?:line|at|:)(?:.*?)(?::| )(d+)(?::| )(d+)/i);
|
|
2091
|
+
if (lineColMatch) {
|
|
2092
|
+
line = parseInt(lineColMatch[1], 10);
|
|
2093
|
+
column = parseInt(lineColMatch[2], 10);
|
|
2094
|
+
}
|
|
1846
2095
|
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
2096
|
+
const messageStr = message || "";
|
|
2097
|
+
const isReactError =
|
|
2098
|
+
messageStr.includes("React") ||
|
|
2099
|
+
messageStr.includes("JSX") ||
|
|
2100
|
+
messageStr.includes("Unexpected token") ||
|
|
2101
|
+
messageStr.includes("vite:react-babel");
|
|
1853
2102
|
|
|
1854
|
-
|
|
2103
|
+
const viteError = new Error(messageStr);
|
|
1855
2104
|
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2105
|
+
window.__SEND_ERROR_TO_PARENT__(viteError, {
|
|
2106
|
+
file,
|
|
2107
|
+
line,
|
|
2108
|
+
column,
|
|
2109
|
+
frames,
|
|
2110
|
+
stack,
|
|
2111
|
+
isReactError,
|
|
2112
|
+
type: isReactError ? "react-syntax" : "vite-error-overlay",
|
|
2113
|
+
});
|
|
1865
2114
|
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
}
|
|
2115
|
+
overlay.setAttribute("data-error-sent", "true");
|
|
2116
|
+
} catch (e) {
|
|
2117
|
+
console.error("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u5904\u7406 vite-error-overlay \u5931\u8D25:", e);
|
|
1870
2118
|
}
|
|
2119
|
+
}
|
|
1871
2120
|
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
}
|
|
2121
|
+
function checkExistingOverlays() {
|
|
2122
|
+
const viteErrorOverlays = document.querySelectorAll("vite-error-overlay");
|
|
2123
|
+
if (viteErrorOverlays.length > 0) {
|
|
2124
|
+
viteErrorOverlays.forEach((overlay) => {
|
|
2125
|
+
if (!overlay.hasAttribute("data-error-sent")) {
|
|
2126
|
+
processViteErrorOverlay(overlay);
|
|
2127
|
+
}
|
|
2128
|
+
});
|
|
1881
2129
|
}
|
|
2130
|
+
}
|
|
1882
2131
|
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
2132
|
+
const observer = new MutationObserver((mutations) => {
|
|
2133
|
+
for (const mutation of mutations) {
|
|
2134
|
+
if (mutation.addedNodes.length > 0) {
|
|
2135
|
+
for (const node of Array.from(mutation.addedNodes)) {
|
|
2136
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
2137
|
+
const element = node;
|
|
2138
|
+
|
|
2139
|
+
if (
|
|
2140
|
+
element.tagName === "VITE-ERROR-OVERLAY" &&
|
|
2141
|
+
!element.hasAttribute("data-error-sent")
|
|
2142
|
+
) {
|
|
2143
|
+
setTimeout(() => processViteErrorOverlay(element), 100);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
const viteErrorOverlays = element.querySelectorAll("vite-error-overlay");
|
|
2147
|
+
for (const viteErrorOverlay of Array.from(viteErrorOverlays)) {
|
|
2148
|
+
if (!viteErrorOverlay.hasAttribute("data-error-sent")) {
|
|
2149
|
+
setTimeout(() => processViteErrorOverlay(viteErrorOverlay), 100);
|
|
1897
2150
|
}
|
|
1898
2151
|
}
|
|
1899
2152
|
}
|
|
1900
2153
|
}
|
|
1901
2154
|
}
|
|
1902
|
-
}
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
1903
2157
|
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2158
|
+
observer.observe(document.documentElement, {
|
|
2159
|
+
childList: true,
|
|
2160
|
+
subtree: true,
|
|
2161
|
+
attributes: true,
|
|
2162
|
+
characterData: true,
|
|
2163
|
+
});
|
|
1908
2164
|
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
const target = event && (event.target || event.srcElement);
|
|
1913
|
-
const tagName = target && target.tagName;
|
|
1914
|
-
if (tagName) {
|
|
1915
|
-
const url = (target && (target.src || target.href || target.currentSrc)) || (target && target.getAttribute && (target.getAttribute('src') || target.getAttribute('href')));
|
|
1916
|
-
const preview = target && target.outerHTML ? String(target.outerHTML).slice(0, 300) : undefined;
|
|
1917
|
-
const resourceError = new Error('Resource load error: ' + tagName + ' ' + (url || 'unknown'));
|
|
1918
|
-
window.__SEND_ERROR_TO_PARENT__(resourceError, { filename: url, tagName: tagName, element: preview, type: "resource" });
|
|
1919
|
-
return;
|
|
1920
|
-
}
|
|
2165
|
+
setTimeout(checkExistingOverlays, 500);
|
|
2166
|
+
setInterval(checkExistingOverlays, 2000);
|
|
2167
|
+
}
|
|
1921
2168
|
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2169
|
+
window.addEventListener(
|
|
2170
|
+
"error",
|
|
2171
|
+
function (event) {
|
|
2172
|
+
const target = event && (event.target || event.srcElement);
|
|
2173
|
+
const tagName = target && target.tagName;
|
|
2174
|
+
if (tagName) {
|
|
2175
|
+
const url = (target && (target.src || target.href || target.currentSrc)) ||
|
|
2176
|
+
(target && target.getAttribute && (target.getAttribute('src') || target.getAttribute('href')));
|
|
2177
|
+
const preview = target && target.outerHTML ? String(target.outerHTML).slice(0, 300) : undefined;
|
|
2178
|
+
const resourceError = new Error('Resource load error: ' + tagName + ' ' + (url || 'unknown'));
|
|
2179
|
+
window.__SEND_ERROR_TO_PARENT__(resourceError, {
|
|
2180
|
+
filename: url,
|
|
2181
|
+
tagName: tagName,
|
|
2182
|
+
element: preview,
|
|
2183
|
+
type: "resource"
|
|
2184
|
+
});
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
1925
2187
|
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
2188
|
+
var stack = (event && event.error && event.error.stack) || "";
|
|
2189
|
+
var message = typeof event.message === "string" ? event.message : "";
|
|
2190
|
+
if ((stack && stack.indexOf('error-handler') !== -1) || !message) return;
|
|
2191
|
+
|
|
2192
|
+
window.__SEND_ERROR_TO_PARENT__(event.error || new Error(event.message), {
|
|
2193
|
+
filename: event.filename,
|
|
2194
|
+
line: event.lineno,
|
|
2195
|
+
column: event.colno,
|
|
2196
|
+
type: "runtime",
|
|
2197
|
+
});
|
|
2198
|
+
},
|
|
2199
|
+
true
|
|
2200
|
+
);
|
|
2201
|
+
|
|
2202
|
+
window.addEventListener("unhandledrejection", function (event) {
|
|
2203
|
+
const reason = event.reason;
|
|
2204
|
+
window.__SEND_ERROR_TO_PARENT__(
|
|
2205
|
+
reason instanceof Error ? reason : new Error(String(reason)),
|
|
2206
|
+
{ type: "promise" }
|
|
1929
2207
|
);
|
|
2208
|
+
});
|
|
1930
2209
|
|
|
1931
|
-
|
|
1932
|
-
const reason = event.reason;
|
|
1933
|
-
window.__SEND_ERROR_TO_PARENT__(reason instanceof Error ? reason : new Error(String(reason)), { type: "promise" });
|
|
1934
|
-
});
|
|
2210
|
+
setupViteOverlayObserver();
|
|
1935
2211
|
|
|
1936
|
-
|
|
2212
|
+
if (!window.__FETCH_INTERCEPTED__) {
|
|
2213
|
+
window.__FETCH_INTERCEPTED__ = true;
|
|
2214
|
+
const originalFetch = window.fetch;
|
|
2215
|
+
|
|
2216
|
+
function handleFetchError(error, url, response = null) {
|
|
2217
|
+
const errorDetails = {
|
|
2218
|
+
type: "network",
|
|
2219
|
+
method: "fetch",
|
|
2220
|
+
url: url
|
|
2221
|
+
};
|
|
2222
|
+
|
|
2223
|
+
if (response && !response.ok) {
|
|
2224
|
+
errorDetails.status = response.status;
|
|
2225
|
+
errorDetails.statusText = response.statusText;
|
|
2226
|
+
errorDetails.networkError = false;
|
|
2227
|
+
} else {
|
|
2228
|
+
errorDetails.networkError = true;
|
|
2229
|
+
}
|
|
2230
|
+
window.__SEND_ERROR_TO_PARENT__(error, errorDetails);
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
window.fetch = function(...args) {
|
|
2234
|
+
const url = args[0] instanceof Request ? args[0].url : args[0];
|
|
2235
|
+
|
|
2236
|
+
return originalFetch.apply(this, args)
|
|
2237
|
+
.then(response => {
|
|
2238
|
+
if (!response.ok) {
|
|
2239
|
+
const networkError = new Error(\`HTTP \${response.status}: \${response.statusText}\`);
|
|
2240
|
+
handleFetchError(networkError, url, response);
|
|
2241
|
+
}
|
|
2242
|
+
return response;
|
|
2243
|
+
})
|
|
2244
|
+
.catch(error => {
|
|
2245
|
+
handleFetchError(error, url);
|
|
2246
|
+
throw error;
|
|
2247
|
+
});
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
1937
2250
|
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
2251
|
+
if (!window.__XHR_INTERCEPTED__) {
|
|
2252
|
+
window.__XHR_INTERCEPTED__ = true;
|
|
2253
|
+
const originalXHROpen = XMLHttpRequest.prototype.open;
|
|
2254
|
+
const originalXHRSend = XMLHttpRequest.prototype.send;
|
|
2255
|
+
|
|
2256
|
+
function handleXHRError(error, xhr, isNetworkError = false) {
|
|
2257
|
+
const errorDetails = {
|
|
2258
|
+
type: "network",
|
|
2259
|
+
method: "xhr",
|
|
2260
|
+
url: xhr.__intercepted_url__
|
|
2261
|
+
};
|
|
2262
|
+
|
|
2263
|
+
if (!isNetworkError && xhr.status >= 400) {
|
|
2264
|
+
errorDetails.status = xhr.status;
|
|
2265
|
+
errorDetails.statusText = xhr.statusText;
|
|
2266
|
+
errorDetails.networkError = false;
|
|
2267
|
+
} else {
|
|
2268
|
+
errorDetails.networkError = true;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
window.__SEND_ERROR_TO_PARENT__(error, errorDetails);
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
XMLHttpRequest.prototype.open = function(method, url, ...args) {
|
|
2275
|
+
this.__intercepted_method__ = method;
|
|
2276
|
+
this.__intercepted_url__ = url;
|
|
2277
|
+
return originalXHROpen.apply(this, [method, url, ...args]);
|
|
2278
|
+
};
|
|
2279
|
+
|
|
2280
|
+
XMLHttpRequest.prototype.send = function(...args) {
|
|
2281
|
+
const xhr = this;
|
|
2282
|
+
|
|
2283
|
+
const originalOnReadyStateChange = xhr.onreadystatechange;
|
|
2284
|
+
xhr.onreadystatechange = function() {
|
|
2285
|
+
if (xhr.readyState === 4) {
|
|
2286
|
+
if (xhr.status >= 400) {
|
|
2287
|
+
const networkError = new Error(\`HTTP \${xhr.status}: \${xhr.statusText}\`);
|
|
2288
|
+
handleXHRError(networkError, xhr, false);
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
if (originalOnReadyStateChange) {
|
|
2293
|
+
return originalOnReadyStateChange.apply(this, arguments);
|
|
2294
|
+
}
|
|
2295
|
+
};
|
|
2296
|
+
|
|
2297
|
+
const originalOnError = xhr.onerror;
|
|
2298
|
+
xhr.onerror = function() {
|
|
2299
|
+
const networkError = new Error(\`Network error for \${xhr.__intercepted_method__} \${xhr.__intercepted_url__}\`);
|
|
2300
|
+
handleXHRError(networkError, xhr, true);
|
|
2301
|
+
|
|
2302
|
+
if (originalOnError) {
|
|
2303
|
+
return originalOnError.apply(this, arguments);
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
|
|
2307
|
+
return originalXHRSend.apply(this, args);
|
|
2308
|
+
};
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
if (!window.__CONSOLE_ERROR_INTERCEPTED__) {
|
|
2312
|
+
window.__CONSOLE_ERROR_INTERCEPTED__ = true;
|
|
2313
|
+
const originalConsoleError = console.error;
|
|
2314
|
+
console.error = function () {
|
|
2315
|
+
try {
|
|
2316
|
+
var args = Array.prototype.slice.call(arguments);
|
|
2317
|
+
var first = args[0];
|
|
2318
|
+
var firstStr = typeof first === "string" ? first : "";
|
|
2319
|
+
var isReact = firstStr.indexOf("React") !== -1;
|
|
2320
|
+
var isVite = firstStr.indexOf("[vite]") !== -1 || firstStr.indexOf("Failed to reload") !== -1;
|
|
2321
|
+
if (isReact || isVite) {
|
|
2322
|
+
var joined = args
|
|
2323
|
+
.map(function (a) {
|
|
1950
2324
|
if (a instanceof Error) return a.message;
|
|
1951
2325
|
if (typeof a === "string") return a;
|
|
1952
2326
|
if (a && typeof a.message === "string") return a.message;
|
|
1953
|
-
try { return JSON.stringify(a); } catch (
|
|
1954
|
-
})
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
}
|
|
2327
|
+
try { return JSON.stringify(a); } catch (_) { return String(a); }
|
|
2328
|
+
})
|
|
2329
|
+
.join(" ");
|
|
2330
|
+
var errorForReport = new Error(joined);
|
|
2331
|
+
window.__SEND_ERROR_TO_PARENT__(errorForReport, { type: "runtime", viteErrorType: "console" });
|
|
2332
|
+
}
|
|
2333
|
+
} catch (_) {}
|
|
2334
|
+
return originalConsoleError.apply(console, arguments);
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
1962
2337
|
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2338
|
+
console.log("[\u65E9\u671F\u9519\u8BEF\u5904\u7406] \u521D\u59CB\u5316\u5B8C\u6210");
|
|
2339
|
+
})();`;
|
|
2340
|
+
function injectEarlyErrorHandler() {
|
|
2341
|
+
if (typeof document === "undefined") return;
|
|
1966
2342
|
try {
|
|
1967
|
-
|
|
1968
|
-
try {
|
|
1969
|
-
const external = document.createElement("script");
|
|
1970
|
-
external.type = "text/javascript";
|
|
1971
|
-
external.src = "/error-handler.js";
|
|
1972
|
-
external.async = false;
|
|
1973
|
-
parent.prepend(external);
|
|
1974
|
-
return;
|
|
1975
|
-
} catch (e) {
|
|
1976
|
-
void e;
|
|
1977
|
-
}
|
|
2343
|
+
if (window.__EARLY_ERROR_HANDLER_INJECTED__) return;
|
|
1978
2344
|
const script = document.createElement("script");
|
|
1979
2345
|
script.type = "text/javascript";
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
}
|
|
1986
|
-
} catch (e) {
|
|
1987
|
-
try {
|
|
1988
|
-
script.appendChild(document.createTextNode(code));
|
|
1989
|
-
} catch {
|
|
1990
|
-
}
|
|
1991
|
-
}
|
|
1992
|
-
parent.prepend(script);
|
|
2346
|
+
script.text = ERROR_HANDLER_SCRIPT;
|
|
2347
|
+
const head = document.head || document.getElementsByTagName("head")[0];
|
|
2348
|
+
if (head && head.firstChild) head.insertBefore(script, head.firstChild);
|
|
2349
|
+
else if (head) head.appendChild(script);
|
|
2350
|
+
window.__EARLY_ERROR_HANDLER_INJECTED__ = true;
|
|
1993
2351
|
} catch (e) {
|
|
1994
|
-
void e;
|
|
1995
2352
|
}
|
|
1996
2353
|
}
|
|
1997
2354
|
|
|
@@ -2002,12 +2359,16 @@ export {
|
|
|
2002
2359
|
AUTH_ROOT,
|
|
2003
2360
|
AUTH_TOKEN_KEY,
|
|
2004
2361
|
AuthProvider,
|
|
2362
|
+
ClayxToast,
|
|
2005
2363
|
DefaultErrorFallback,
|
|
2006
2364
|
ErrorBoundary,
|
|
2007
2365
|
FloatingButton,
|
|
2366
|
+
GlobalToastContainer,
|
|
2008
2367
|
Loading,
|
|
2009
2368
|
LoadingSpinner,
|
|
2010
2369
|
LoginForm,
|
|
2370
|
+
ThemeProvider,
|
|
2371
|
+
ThemeToggle,
|
|
2011
2372
|
aiRequest,
|
|
2012
2373
|
aiWorkflow,
|
|
2013
2374
|
canAccessArtifact,
|
|
@@ -2036,6 +2397,7 @@ export {
|
|
|
2036
2397
|
useAuthContext,
|
|
2037
2398
|
useDebounce,
|
|
2038
2399
|
useIsMobile,
|
|
2400
|
+
useTheme,
|
|
2039
2401
|
workflowRequest
|
|
2040
2402
|
};
|
|
2041
2403
|
//# sourceMappingURL=index.mjs.map
|