@marimo-team/islands 0.23.17-dev0 → 0.23.17-dev3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/{common-CotPLtrU.js → common-D747zlkP.js} +4 -4
  2. package/dist/main.js +2 -2
  3. package/dist/{reveal-component-IoHipy82.js → reveal-component-CcSMtt1K.js} +1 -1
  4. package/dist/style.css +1 -1
  5. package/package.json +1 -1
  6. package/src/components/editor/actions/__tests__/pair-with-agent-commands.test.ts +1 -1
  7. package/src/components/editor/actions/export-dialog/__tests__/export-command.test.ts +115 -0
  8. package/src/components/editor/actions/export-dialog/__tests__/export-dialog.test.tsx +423 -0
  9. package/src/components/editor/actions/export-dialog/__tests__/export-notebook.test.ts +178 -0
  10. package/src/components/editor/actions/export-dialog/__tests__/state.test.ts +234 -0
  11. package/src/components/editor/actions/export-dialog/__tests__/use-export-dialog.test.tsx +287 -0
  12. package/src/components/editor/actions/export-dialog/export-command.ts +149 -0
  13. package/src/components/editor/actions/export-dialog/export-dialog.tsx +190 -0
  14. package/src/components/editor/actions/export-dialog/export-notebook.ts +98 -0
  15. package/src/components/editor/actions/export-dialog/format-notice.tsx +138 -0
  16. package/src/components/editor/actions/export-dialog/format-options.tsx +531 -0
  17. package/src/components/editor/actions/export-dialog/state.ts +321 -0
  18. package/src/components/editor/actions/export-dialog/use-export-dialog.ts +380 -0
  19. package/src/components/editor/actions/pair-with-agent-commands.ts +1 -21
  20. package/src/components/editor/actions/useNotebookActions.tsx +72 -170
  21. package/src/components/editor/connections/add-connection-dialog.tsx +1 -1
  22. package/src/components/editor/connections/quick-add-data-sources.tsx +14 -7
  23. package/src/components/editor/controls/__tests__/notebook-menu-dropdown.test.tsx +187 -0
  24. package/src/components/editor/controls/notebook-menu-dropdown.tsx +4 -2
  25. package/src/utils/__tests__/download.test.tsx +6 -4
  26. package/src/utils/download.ts +3 -1
  27. package/src/utils/shell.ts +17 -0
@@ -0,0 +1,149 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { Filenames } from "@/utils/filenames";
4
+ import { shellQuote } from "@/utils/shell";
5
+ import type { ExportFormat, ExportOptions, MarkdownFlavor } from "./state";
6
+
7
+ const MARKDOWN_EXTENSIONS: Record<MarkdownFlavor, string> = {
8
+ pymdown: "md",
9
+ qmd: "qmd",
10
+ mystmd: "myst.md",
11
+ mdx: "mdx",
12
+ };
13
+
14
+ const MARKDOWN_SUFFIXES = [".myst.md", ".markdown", ".qmd", ".mdx", ".md"];
15
+
16
+ function inferMarkdownFlavor(filename: string): MarkdownFlavor {
17
+ if (filename.endsWith(".myst.md")) {
18
+ return "mystmd";
19
+ }
20
+ if (filename.endsWith(".qmd")) {
21
+ return "qmd";
22
+ }
23
+ if (filename.endsWith(".mdx")) {
24
+ return "mdx";
25
+ }
26
+ return "pymdown";
27
+ }
28
+
29
+ function markdownOutputFilename(
30
+ filename: string,
31
+ selectedFlavor: MarkdownFlavor | null,
32
+ ): string {
33
+ const flavor = selectedFlavor ?? inferMarkdownFlavor(filename);
34
+ const extension = MARKDOWN_EXTENSIONS[flavor];
35
+ const suffix = MARKDOWN_SUFFIXES.find((candidate) =>
36
+ filename.endsWith(candidate),
37
+ );
38
+ let stem = Filenames.withoutExtension(filename);
39
+ if (suffix) {
40
+ stem = filename.slice(0, -suffix.length);
41
+ }
42
+ const output = `${stem}.${extension}`;
43
+ if (output !== filename) {
44
+ return output;
45
+ }
46
+ return `${filename.slice(0, -(extension.length + 1))}.export.${extension}`;
47
+ }
48
+
49
+ type FlagValue = boolean | string | null;
50
+
51
+ function translateFlags(values: Record<string, FlagValue>): string[] {
52
+ return Object.entries(values).flatMap(([name, value]) => {
53
+ if (value === null) {
54
+ return [];
55
+ }
56
+ if (value === true) {
57
+ return [`--${name}`];
58
+ }
59
+ if (value === false) {
60
+ return [`--no-${name}`];
61
+ }
62
+ return [`--${name}=${value}`];
63
+ });
64
+ }
65
+
66
+ function webPDFFlagValue(pdf: ExportOptions["pdf"]): boolean | null {
67
+ if (pdf.preset === "document") {
68
+ return pdf.webpdf;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ type CommandFormat = Exclude<ExportFormat, "png">;
74
+
75
+ interface ExportCommandDefinition {
76
+ subcommand: string;
77
+ flags: (options: ExportOptions) => Record<string, FlagValue>;
78
+ outputFilename: (source: string, options: ExportOptions) => string;
79
+ }
80
+
81
+ const EXPORT_COMMAND_DEFINITIONS: Record<
82
+ CommandFormat,
83
+ ExportCommandDefinition
84
+ > = {
85
+ html: {
86
+ subcommand: "html",
87
+ flags: ({ html }) => ({ "include-code": html.includeCode }),
88
+ outputFilename: (source) => Filenames.toHTML(source),
89
+ },
90
+ markdown: {
91
+ subcommand: "md",
92
+ flags: ({ markdown }) => ({ flavor: markdown.flavor }),
93
+ outputFilename: (source, { markdown }) =>
94
+ markdownOutputFilename(source, markdown.flavor),
95
+ },
96
+ ipynb: {
97
+ subcommand: "ipynb",
98
+ flags: ({ ipynb }) => ({
99
+ sort: ipynb.sortMode,
100
+ "include-outputs": ipynb.includeOutputs,
101
+ }),
102
+ outputFilename: (source) => Filenames.toIPYNB(source),
103
+ },
104
+ pdf: {
105
+ subcommand: "pdf",
106
+ flags: ({ pdf }) => ({
107
+ as: pdf.preset,
108
+ "include-inputs": pdf.includeInputs,
109
+ "include-outputs": pdf.includeOutputs,
110
+ webpdf: webPDFFlagValue(pdf),
111
+ }),
112
+ outputFilename: (source) => Filenames.toPDF(source),
113
+ },
114
+ script: {
115
+ subcommand: "script",
116
+ flags: () => ({}),
117
+ outputFilename: (source) =>
118
+ `${Filenames.withoutExtension(source)}.script.py`,
119
+ },
120
+ };
121
+
122
+ export function getExportCommand({
123
+ format,
124
+ filename,
125
+ options,
126
+ }: {
127
+ format: ExportFormat;
128
+ filename: string | null;
129
+ options: ExportOptions;
130
+ }): string | null {
131
+ if (
132
+ format === "png" ||
133
+ (format === "script" && options.script.type === "source") ||
134
+ !filename
135
+ ) {
136
+ return null;
137
+ }
138
+
139
+ const definition = EXPORT_COMMAND_DEFINITIONS[format];
140
+ return [
141
+ "marimo",
142
+ "export",
143
+ definition.subcommand,
144
+ shellQuote(filename),
145
+ ...translateFlags(definition.flags(options)),
146
+ "-o",
147
+ shellQuote(definition.outputFilename(filename, options)),
148
+ ].join(" ");
149
+ }
@@ -0,0 +1,190 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { useMediaQuery } from "@uidotdev/usehooks";
4
+ import type React from "react";
5
+ import { CopyClipboardIcon } from "@/components/icons/copy-icon";
6
+ import { Spinner } from "@/components/icons/spinner";
7
+ import { Button, buttonVariants } from "@/components/ui/button";
8
+ import {
9
+ DialogContent,
10
+ DialogDescription,
11
+ DialogHeader,
12
+ DialogTitle,
13
+ } from "@/components/ui/dialog";
14
+ import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
15
+ import { cn } from "@/utils/cn";
16
+ import { FORMAT_DEFINITIONS } from "./format-options";
17
+ import { FormatNotice, FormatStatusIcon } from "./format-notice";
18
+ import type { ExportFormat } from "./state";
19
+ import { useExportDialog } from "./use-export-dialog";
20
+
21
+ const DESKTOP_LAYOUT_QUERY = "(min-width: 640px)";
22
+
23
+ export const ExportDialog: React.FC<{
24
+ initialFormat?: ExportFormat;
25
+ onClose: () => void;
26
+ returnFocusRef?: React.RefObject<HTMLElement | null>;
27
+ }> = ({ initialFormat, onClose, returnFocusRef }) => {
28
+ const {
29
+ dialogRef,
30
+ isExporting,
31
+ formats,
32
+ options,
33
+ selected,
34
+ selectFormat,
35
+ updateOptions,
36
+ submit,
37
+ } = useExportDialog({ initialFormat, onClose });
38
+ const desktopLayout = useMediaQuery(DESKTOP_LAYOUT_QUERY);
39
+ const {
40
+ format,
41
+ status,
42
+ usesBrowserPrint,
43
+ actionLabel,
44
+ command,
45
+ footerDescription,
46
+ } = selected;
47
+ const definition = FORMAT_DEFINITIONS[format];
48
+ const FormatOptions = definition.Options;
49
+
50
+ const returnFocusProps = returnFocusRef
51
+ ? {
52
+ onCloseAutoFocus: (event: Event) => {
53
+ event.preventDefault();
54
+ returnFocusRef.current?.focus();
55
+ },
56
+ }
57
+ : {};
58
+
59
+ return (
60
+ <DialogContent
61
+ ref={dialogRef}
62
+ className="grid h-dvh max-h-[760px] min-w-0 w-[calc(100vw-2rem)] grid-rows-[auto_minmax(0,1fr)_auto] gap-0 overflow-hidden p-0 sm:top-[5vh] sm:h-[90vh] sm:max-h-[640px] sm:max-w-3xl"
63
+ data-testid="export-dialog"
64
+ {...returnFocusProps}
65
+ >
66
+ <DialogHeader className="border-b px-5 py-4 pr-12">
67
+ <DialogTitle>Export notebook</DialogTitle>
68
+ <DialogDescription>
69
+ Choose a format and adjust its options.
70
+ </DialogDescription>
71
+ </DialogHeader>
72
+
73
+ <Tabs
74
+ value={format}
75
+ onValueChange={selectFormat}
76
+ orientation={desktopLayout ? "vertical" : "horizontal"}
77
+ className="flex min-h-0 min-w-0 flex-col overflow-hidden sm:grid sm:grid-cols-[168px_minmax(0,1fr)]"
78
+ >
79
+ <TabsList
80
+ aria-label="Export format"
81
+ className="grid max-h-none shrink-0 grid-cols-2 items-stretch justify-start gap-1 overflow-auto rounded-none border-b bg-muted/20 p-2 min-[360px]:grid-cols-3 sm:flex sm:h-full sm:flex-col sm:border-b-0 sm:border-r"
82
+ >
83
+ {formats.map(({ format: candidate, status: candidateStatus }) => {
84
+ const candidateDefinition = FORMAT_DEFINITIONS[candidate];
85
+ return (
86
+ <TabsTrigger
87
+ key={candidate}
88
+ value={candidate}
89
+ disabled={isExporting}
90
+ className="min-w-0 justify-start gap-2 px-2.5 py-2 text-xs data-[state=active]:shadow-xs sm:w-full sm:text-sm"
91
+ data-testid={`export-format-${candidate}`}
92
+ >
93
+ <candidateDefinition.Icon
94
+ className="size-3.5 shrink-0"
95
+ strokeWidth={1.5}
96
+ />
97
+ <span className="truncate">{candidateDefinition.label}</span>
98
+ <FormatStatusIcon status={candidateStatus} />
99
+ </TabsTrigger>
100
+ );
101
+ })}
102
+ </TabsList>
103
+
104
+ <TabsContent
105
+ value={format}
106
+ className="mt-0 min-h-0 min-w-0 overflow-y-auto px-4 py-3"
107
+ >
108
+ <div className="mb-3">
109
+ <h3 className="text-base font-semibold">{definition.label}</h3>
110
+ <p className="mt-0.5 text-sm text-muted-foreground">
111
+ {definition.description}
112
+ </p>
113
+ </div>
114
+
115
+ <FormatNotice
116
+ format={format}
117
+ formatLabel={definition.label}
118
+ status={status}
119
+ />
120
+
121
+ {usesBrowserPrint ? null : (
122
+ <FormatOptions
123
+ options={options}
124
+ updateOptions={updateOptions}
125
+ disabled={isExporting}
126
+ />
127
+ )}
128
+ </TabsContent>
129
+ </Tabs>
130
+
131
+ <footer className="min-w-0 border-t bg-muted/20 px-4 py-3">
132
+ {command ? (
133
+ <div className="flex min-w-0 items-center gap-2 rounded-md border bg-background px-2.5 py-2 font-mono text-xs">
134
+ <span
135
+ className="select-none text-muted-foreground"
136
+ aria-hidden={true}
137
+ >
138
+ $
139
+ </span>
140
+ <code
141
+ className="min-w-0 flex-1 overflow-x-auto whitespace-nowrap"
142
+ data-testid="export-cli-command"
143
+ aria-label="Equivalent POSIX shell command"
144
+ >
145
+ {command}
146
+ </code>
147
+ <CopyClipboardIcon
148
+ value={command}
149
+ className="size-3.5"
150
+ buttonClassName={cn(
151
+ buttonVariants({ variant: "ghost", size: "icon" }),
152
+ "shrink-0",
153
+ )}
154
+ tooltip="Copy POSIX shell command"
155
+ ariaLabel="Copy POSIX shell command"
156
+ toastTitle="Command copied"
157
+ />
158
+ </div>
159
+ ) : null}
160
+
161
+ <div
162
+ className={cn(
163
+ "flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
164
+ command && "mt-3",
165
+ )}
166
+ >
167
+ {footerDescription ? (
168
+ <p className="text-xs text-muted-foreground">{footerDescription}</p>
169
+ ) : null}
170
+ <Button
171
+ type="button"
172
+ disabled={!status.available || isExporting}
173
+ aria-busy={isExporting}
174
+ onClick={submit}
175
+ className={cn(
176
+ "border-(--blue-11) bg-(--blue-11) hover:border-(--blue-12) hover:bg-(--blue-12) sm:min-w-36 dark:border-(--blue-7) dark:bg-(--blue-5) dark:text-(--blue-12) dark:hover:border-(--blue-8) dark:hover:bg-(--blue-6)",
177
+ !footerDescription && "sm:ml-auto",
178
+ )}
179
+ data-testid="export-submit"
180
+ >
181
+ {isExporting && (
182
+ <Spinner size="small" className="mr-2" aria-hidden={true} />
183
+ )}
184
+ {usesBrowserPrint ? "Print to PDF" : actionLabel}
185
+ </Button>
186
+ </div>
187
+ </footer>
188
+ </DialogContent>
189
+ );
190
+ };
@@ -0,0 +1,98 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import type { EditRequests, ExportedFile } from "@/core/network/types";
4
+ import { assertNever } from "@/utils/assertNever";
5
+ import { runServerSidePDFDownload } from "../pdf-export";
6
+ import type { ExportFormat, ExportOptions } from "./state";
7
+
8
+ type ExportRequests = Pick<
9
+ EditRequests,
10
+ | "exportAsHTML"
11
+ | "exportAsMarkdown"
12
+ | "exportAsIPYNB"
13
+ | "exportAsPDF"
14
+ | "exportAsScript"
15
+ | "readCode"
16
+ >;
17
+
18
+ export async function exportNotebook({
19
+ format,
20
+ options,
21
+ requests,
22
+ sourceFilename,
23
+ htmlFiles,
24
+ captureOutputs,
25
+ capturePNG,
26
+ downloadFile,
27
+ }: {
28
+ format: ExportFormat;
29
+ options: ExportOptions;
30
+ requests: ExportRequests;
31
+ sourceFilename: string;
32
+ htmlFiles: string[];
33
+ captureOutputs: () => Promise<void>;
34
+ capturePNG: () => Promise<void>;
35
+ downloadFile: (file: ExportedFile) => void;
36
+ }): Promise<void> {
37
+ switch (format) {
38
+ case "html": {
39
+ const file = await requests.exportAsHTML({
40
+ download: false,
41
+ files: htmlFiles,
42
+ includeCode: options.html.includeCode,
43
+ });
44
+ downloadFile(file);
45
+ return;
46
+ }
47
+ case "markdown": {
48
+ const file = await requests.exportAsMarkdown({
49
+ download: false,
50
+ flavor: options.markdown.flavor,
51
+ });
52
+ downloadFile(file);
53
+ return;
54
+ }
55
+ case "ipynb": {
56
+ if (options.ipynb.includeOutputs) {
57
+ await captureOutputs();
58
+ }
59
+ const file = await requests.exportAsIPYNB({
60
+ download: false,
61
+ sortMode: options.ipynb.sortMode,
62
+ includeOutputs: options.ipynb.includeOutputs,
63
+ });
64
+ downloadFile(file);
65
+ return;
66
+ }
67
+ case "pdf":
68
+ await runServerSidePDFDownload({
69
+ exportOptions: options.pdf,
70
+ captureOutputs,
71
+ downloadPDF: async (exportOptions) => {
72
+ const file = await requests.exportAsPDF(exportOptions);
73
+ downloadFile(file);
74
+ },
75
+ });
76
+ return;
77
+
78
+ case "script": {
79
+ if (options.script.type === "source") {
80
+ const source = await requests.readCode();
81
+ downloadFile({
82
+ contents: source.contents,
83
+ filename: sourceFilename,
84
+ mediaType: "text/plain",
85
+ });
86
+ return;
87
+ }
88
+ const file = await requests.exportAsScript({ download: false });
89
+ downloadFile(file);
90
+ return;
91
+ }
92
+ case "png":
93
+ await capturePNG();
94
+ return;
95
+ default:
96
+ assertNever(format);
97
+ }
98
+ }
@@ -0,0 +1,138 @@
1
+ /* Copyright 2026 Marimo. All rights reserved. */
2
+
3
+ import { AlertCircleIcon } from "lucide-react";
4
+ import type { PropsWithChildren } from "react";
5
+ import { Spinner } from "@/components/icons/spinner";
6
+ import { Alert, AlertDescription } from "@/components/ui/alert";
7
+ import { assertNever } from "@/utils/assertNever";
8
+ import { cn } from "@/utils/cn";
9
+ import type {
10
+ ExportBlockReason,
11
+ ExportFormat,
12
+ ExportFormatStatus,
13
+ } from "./state";
14
+
15
+ export function FormatStatusIcon({ status }: { status: ExportFormatStatus }) {
16
+ if (status.available && !status.availabilityCheckFailed) {
17
+ return null;
18
+ }
19
+ if (status.reason?.type === "checking-requirements") {
20
+ return (
21
+ <span className="ml-auto flex shrink-0">
22
+ <Spinner size="small" className="size-3" />
23
+ <span className="sr-only">Checking requirements</span>
24
+ </span>
25
+ );
26
+ }
27
+ const statusLabel = status.availabilityCheckFailed
28
+ ? "Requirements unknown"
29
+ : "Unavailable";
30
+ return (
31
+ <span className="ml-auto flex shrink-0">
32
+ <AlertCircleIcon
33
+ className={cn(
34
+ "size-3",
35
+ status.availabilityCheckFailed
36
+ ? "text-muted-foreground"
37
+ : "text-(--yellow-11)",
38
+ )}
39
+ />
40
+ <span className="sr-only">{statusLabel}</span>
41
+ </span>
42
+ );
43
+ }
44
+
45
+ export function FormatNotice({
46
+ format,
47
+ formatLabel,
48
+ status,
49
+ }: {
50
+ format: ExportFormat;
51
+ formatLabel: string;
52
+ status: ExportFormatStatus;
53
+ }) {
54
+ if (status.availabilityCheckFailed) {
55
+ return (
56
+ <div className="mb-2.5">
57
+ <Notice>
58
+ Couldn't check whether this export is available. You can still try it.
59
+ </Notice>
60
+ </div>
61
+ );
62
+ }
63
+ if (!status.reason) {
64
+ return null;
65
+ }
66
+
67
+ return (
68
+ <div className="mb-2.5">
69
+ <ReasonNotice
70
+ format={format}
71
+ formatLabel={formatLabel}
72
+ reason={status.reason}
73
+ />
74
+ </div>
75
+ );
76
+ }
77
+
78
+ function Notice({ children }: PropsWithChildren) {
79
+ return (
80
+ <Alert
81
+ variant="warning"
82
+ className="flex items-start gap-2.5 p-3 text-(--yellow-12) has-[svg]:pl-3 sm:items-center [&>svg]:static [&>svg+div]:translate-y-0"
83
+ >
84
+ <AlertCircleIcon className="mt-0.5 size-4 shrink-0 sm:mt-0" />
85
+ <AlertDescription className="min-w-0 flex-1 text-sm leading-5">
86
+ {children}
87
+ </AlertDescription>
88
+ </Alert>
89
+ );
90
+ }
91
+
92
+ function ReasonNotice({
93
+ format,
94
+ formatLabel,
95
+ reason,
96
+ }: {
97
+ format: ExportFormat;
98
+ formatLabel: string;
99
+ reason: ExportBlockReason;
100
+ }) {
101
+ switch (reason.type) {
102
+ case "checking-requirements":
103
+ return (
104
+ <Alert
105
+ role="status"
106
+ variant="info"
107
+ className="flex items-center gap-2.5 p-3 has-[svg]:pl-3 [&>svg]:static [&>svg+div]:translate-y-0"
108
+ >
109
+ <Spinner className="size-4 shrink-0" size="small" />
110
+ <AlertDescription className="min-w-0 flex-1 text-sm leading-5">
111
+ Checking {formatLabel} requirements…
112
+ </AlertDescription>
113
+ </Alert>
114
+ );
115
+ case "notebook-must-be-named":
116
+ return <Notice>Name and save this notebook before exporting.</Notice>;
117
+ case "missing-packages":
118
+ return (
119
+ <Notice>
120
+ Install{" "}
121
+ <code className="break-words font-mono">
122
+ {reason.packages.join(", ")}
123
+ </code>{" "}
124
+ where marimo is running to use this export.
125
+ </Notice>
126
+ );
127
+ case "wasm-runtime":
128
+ return (
129
+ <Notice>
130
+ {format === "pdf"
131
+ ? "Use your browser's print dialog to save the current app view as a PDF."
132
+ : "Open this notebook in a local marimo session to use this export."}
133
+ </Notice>
134
+ );
135
+ default:
136
+ assertNever(reason);
137
+ }
138
+ }