/* Copyright 2026 Marimo. All rights reserved. */
import { useAtomValue } from "jotai";
import { CopyIcon, DownloadIcon } from "lucide-react";
import type React from "react";
import { Constants } from "@/core/constants";
import { useResolvedMarimoConfig } from "@/core/config/config";
import { codeAtom } from "@/core/saving/file-state";
import { useFilename } from "@/core/saving/filename";
import { isStaticNotebook } from "@/core/static/static-state";
import { createShareableLink } from "@/core/wasm/share";
import { copyToClipboard } from "@/utils/copy";
import { downloadBlob } from "@/utils/download";
import { Paths } from "@/utils/paths";
import { shellQuote } from "@/utils/shell";
import { MarimoPlusIcon } from "../icons/marimo-icons";
import { Button } from "../ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "../ui/dialog";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "../ui/tabs";
import { toast } from "../ui/use-toast";
export const StaticBanner: React.FC = () => {
const code = useAtomValue(codeAtom);
if (!isStaticNotebook()) {
return null;
}
if (!code) {
return null;
}
return (
Static{" "}
marimo
{" "}
notebook - Run or edit for full interactivity
);
};
const StaticBannerDialog = ({ code }: { code: string }) => {
const filename = Paths.basename(useFilename() || "notebook.py");
const [resolvedConfig] = useResolvedMarimoConfig();
const molabEnabled = resolvedConfig.sharing?.molab ?? true;
const runTarget = getStaticNotebookRunTarget(window.location.href, filename);
const runsFromUrl = runTarget !== filename;
const quotedRunTarget = shellQuote(runTarget);
return (
);
};
/** Keep this in sync with StaticNotebookReader in marimo/_cli/files/file_path.py. */
export function getStaticNotebookRunTarget(
href: string,
filename: string,
): string {
const url = new URL(href);
const isHttp = url.protocol === "http:" || url.protocol === "https:";
if (!isHttp) {
return filename;
}
const isHtmlFile = url.pathname.endsWith(".html") && url.search === "";
const matchesSupportedUrlPattern =
url.protocol === "https:" &&
(url.hostname === "marimo.app" ||
url.hostname === "links.marimo.app" ||
(url.hostname === "static.marimo.app" &&
url.pathname.startsWith("/static")) ||
url.pathname.includes("/notebooks/nb"));
if (!isHtmlFile && !matchesSupportedUrlPattern) {
return filename;
}
url.hash = "";
return url.href;
}
const CommandBlock = ({ command }: { command: string }) => (
{command}
);
const MolabCallout = ({ code }: { code: string }) => {
const molabLink = createShareableLink({
code,
baseUrl: `${Constants.molab}/new`,
});
return (
Run this notebook in molab,
marimo's cloud-hosted notebook platform.
);
};