Files
nanobot/webui/src/components/WebPreviewPanel.tsx
T
chengyongru 30e43aec82 refactor(webui): separate presentation views and expand component gallery (#6179)
* refactor(webui): organize shared components with an internal gallery

* refactor(webui): decouple views and expand component gallery

* fix(docker): include channel sources in WebUI build

* refactor(webui): cover all channel interfaces in gallery

* docs(webui): remove manual paragraph wrapping
2026-10-14 00:11:00 +08:00

25 lines
1.2 KiB
TypeScript

import { useState } from "react";
import { useTranslation } from "react-i18next";
import { WebPreviewPanelView } from "@/components/WebPreviewPanelView";
import { isLoopbackHost } from "@/lib/network";
import { currentWebPreviewRestriction, parseWebLink } from "@/lib/web-preview";
interface WebPreviewPanelProps {
url: string;
}
export function WebPreviewPanel({ url: value }: WebPreviewPanelProps) {
const { t } = useTranslation();
const [revision, setRevision] = useState(0);
const url = parseWebLink(value);
const restriction = currentWebPreviewRestriction(url);
return <WebPreviewPanelView url={url} restriction={restriction} loopback={!!url && isLoopbackHost(url.hostname)}
onRefresh={() => setRevision((n) => n + 1)}>
{!restriction ? <iframe key={`${value}:${revision}`} title={t("webPreview.frame", { host: url!.host })}
{...{ credentialless: "" }} sandbox="allow-scripts" referrerPolicy="no-referrer"
allow="camera 'none'; microphone 'none'; geolocation 'none'; clipboard-read 'none'; clipboard-write 'none'; payment 'none'; fullscreen 'none'; display-capture 'none'; usb 'none'; serial 'none'; hid 'none'"
src={url!.href} className="min-h-0 w-full flex-1 border-0 bg-white" /> : null}
</WebPreviewPanelView>;
}