feat:脚本文件预览

This commit is contained in:
xiaozhu
2026-08-31 18:48:19 +08:00
parent 4ff0f344af
commit 690de643ad
12 changed files with 1138 additions and 65 deletions
@@ -1,6 +1,7 @@
import {
BookOpen,
Database,
Eye,
FileCode,
FileText,
Folder,
@@ -10,6 +11,7 @@ import {
X,
} from "lucide-react";
import type { ScriptItem, ScriptType } from "../../services/api";
import { canPreviewDataResource } from "./dataResourcePreview";
type ContextMenuState = {
x: number;
@@ -29,6 +31,7 @@ type TreeContextMenuProps = {
onChooseUpload: (parentPath: string) => void;
onRemoveDirectory: (path: string) => void;
onCopyResourcePath?: (jupyterPath: string) => void;
onPreviewResource?: (script: ScriptItem) => void;
onRemoveResource?: (resourceId: string) => void;
onClose: () => void;
};
@@ -49,12 +52,15 @@ export function TreeContextMenu({
onChooseUpload,
onRemoveDirectory,
onCopyResourcePath,
onPreviewResource,
onRemoveResource,
onClose,
}: TreeContextMenuProps) {
if (!contextMenu) return null;
const isDataResource = !!contextMenu.script?.script_id.startsWith("data:");
const canPreview =
isDataResource && canPreviewDataResource(contextMenu.script?.script_name);
const LockToggleIcon = contextMenu.script?.is_locked ? Unlock : Lock;
return (
@@ -71,6 +77,20 @@ export function TreeContextMenu({
<>
{isDataResource ? (
<>
{canPreview && onPreviewResource && (
<button
type="button"
role="menuitem"
className={menuItemClass}
onClick={() => {
onPreviewResource(contextMenu.script!);
onClose();
}}
>
<Eye size={16} />
</button>
)}
<button
type="button"
role="menuitem"