// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { Markdown } from "@/element/markdown"; import { getBackendHostPort, globalStore, useBlockAtom, useBlockCache } from "@/store/global"; import * as services from "@/store/services"; import * as WOS from "@/store/wos"; import * as util from "@/util/util"; import clsx from "clsx"; import * as jotai from "jotai"; import { useRef } from "react"; import { CenteredDiv } from "../element/quickelems"; import { CodeEdit } from "./codeedit"; import { CSVView } from "./csvview"; import { DirectoryPreview } from "./directorypreview"; import "./view.less"; const MaxFileSize = 1024 * 1024 * 10; // 10MB function DirNav({ cwdAtom }: { cwdAtom: jotai.WritableAtom }) { const [cwd, setCwd] = jotai.useAtom(cwdAtom); if (cwd == null || cwd == "") { return null; } let splitNav = [cwd]; let remaining = cwd; let idx = remaining.lastIndexOf("/"); while (idx !== -1) { remaining = remaining.substring(0, idx); splitNav.unshift(remaining); idx = remaining.lastIndexOf("/"); } if (splitNav.length === 0) { splitNav = [cwd]; } return (
{splitNav.map((item, idx) => { let splitPath = item.split("/"); if (splitPath.length === 0) { splitPath = [item]; } const isLast = idx == splitNav.length - 1; let baseName = splitPath[splitPath.length - 1]; if (!isLast) { baseName += "/"; } return (
setCwd(item)} > {baseName}
); })}
); } function MarkdownPreview({ contentAtom }: { contentAtom: jotai.Atom> }) { const readmeText = jotai.useAtomValue(contentAtom); return (
); } function StreamingPreview({ fileInfo }: { fileInfo: FileInfo }) { const filePath = fileInfo.path; const streamingUrl = getBackendHostPort() + "/wave/stream-file?path=" + encodeURIComponent(filePath); if (fileInfo.mimetype == "application/pdf") { return (