chore: bump version to v0.9.62 and add showPopup feature to widget

This commit is contained in:
haorwen
2026-03-15 06:53:05 +08:00
committed by cnb
parent a1f8f1f0ff
commit 09313a336f
6 changed files with 30 additions and 5 deletions
+15
View File
@@ -1,3 +1,18 @@
// 在 Shadow DOM 模式下,动态设置 webpack 的 publicPath
// 这样 webpack 运行时加载的动态资源(如代码分割的 chunk)会从正确的源服务器加载
if (typeof document !== 'undefined') {
const currentScript = document.currentScript as HTMLScriptElement;
if (currentScript && currentScript.src) {
try {
const scriptUrl = new URL(currentScript.src);
// 设置为脚本所在的目录路径
__webpack_public_path__ = scriptUrl.origin + '/';
} catch (e) {
console.warn('Failed to set webpack public path:', e);
}
}
}
import ReactDOM from "react-dom/client";
import { Toaster } from "react-hot-toast";
import { Provider } from "react-redux";
+4
View File
@@ -33,6 +33,10 @@ interface BeforeInstallPromptEvent extends Event {
export declare global {
import { PrecacheEntry } from "workbox-precaching/src/_types";
import localforage from "localforage";
// Webpack public path for dynamic imports
var __webpack_public_path__: string;
interface Document {
webkitHidden: boolean;
}
+3 -3
View File
@@ -10,7 +10,7 @@ type Props = {
const Icon = ({ handleClick }: Props) => {
const serverLogo = useAppSelector((store) => store.server.logo, shallowEqual);
const { popupTitle, popupSubtitle, popupImage, logo: customLogo, popupClosable } = useWidget();
const { popupTitle, popupSubtitle, popupImage, logo: customLogo, popupClosable, showPopup } = useWidget();
const [tooltipVisible, setTooltipVisible] = useState(true);
// 优先使用自定义 logo,否则使用服务器 logo
@@ -19,8 +19,8 @@ const Icon = ({ handleClick }: Props) => {
// 检测是否是移动端
const isMobile = typeof window !== 'undefined' && window.innerWidth < 768;
// 是否显示 tooltip(桌面端 + 有内容 + 用户未关闭)
const showTooltip = !isMobile && tooltipVisible && (popupTitle || popupSubtitle);
// 是否显示 tooltip(桌面端 + 有内容 + 用户未关闭 + showPopup 开关打开
const showTooltip = !isMobile && tooltipVisible && (popupTitle || popupSubtitle) && showPopup;
if (!logo) return null;
+3
View File
@@ -22,6 +22,7 @@ const popupTitle = decodeURIComponent(query.get("popupTitle") || "Need help?");
const popupSubtitle = decodeURIComponent(query.get("popupSubtitle") || "Our staff are always ready to help!");
const popupImage = decodeURIComponent(query.get("popupImage") || "");
const popupClosable = decodeURIComponent(query.get("popupClosable") || "true") == "true";
const showPopup = decodeURIComponent(query.get("showPopup") || "true") == "true";
const fgColor = getContrastColor(color);
// 从 URL 参数读取 embed 状态,如果没有则检测是否在 iframe 中
const embedParam = query.get("embed");
@@ -49,6 +50,7 @@ const WidgetContext = createContext({
popupSubtitle,
popupImage,
popupClosable,
showPopup,
serverVersion: "",
openWidth,
openHeight,
@@ -84,6 +86,7 @@ function WidgetProvider({ children }: { children: ReactNode }) {
popupSubtitle,
popupImage,
popupClosable,
showPopup,
serverVersion: data,
openWidth,
openHeight,