import React from "react"; import { NonDeletedExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { ExportOpts, BinaryFiles, UIAppState } from "../types"; import { Dialog } from "./Dialog"; import { exportToFileIcon, LinkIcon } from "./icons"; import { ToolButton } from "./ToolButton"; import { actionSaveFileToDisk } from "../actions/actionExport"; import { Card } from "./Card"; import "./ExportDialog.scss"; import { nativeFileSystemSupported } from "../data/filesystem"; import { trackEvent } from "../analytics"; import { ActionManager } from "../actions/manager"; import { getFrame } from "../utils"; export type ExportCB = ( elements: readonly NonDeletedExcalidrawElement[], scale?: number, ) => void; const JSONExportModal = ({ elements, appState, setAppState, files, actionManager, exportOpts, canvas, onCloseRequest, }: { appState: UIAppState; setAppState: React.Component["setState"]; files: BinaryFiles; elements: readonly NonDeletedExcalidrawElement[]; actionManager: ActionManager; onCloseRequest: () => void; exportOpts: ExportOpts; canvas: HTMLCanvasElement; }) => { const { onExportToBackend } = exportOpts; return (
{exportOpts.saveFileToDisk && (
{exportToFileIcon}

{t("exportDialog.disk_title")}

{t("exportDialog.disk_details")} {!nativeFileSystemSupported && actionManager.renderAction("changeProjectName")}
{ actionManager.executeAction(actionSaveFileToDisk, "ui"); }} />
)} {onExportToBackend && (
{LinkIcon}

{t("exportDialog.link_title")}

{t("exportDialog.link_details")}
{ try { trackEvent("export", "link", `ui (${getFrame()})`); await onExportToBackend(elements, appState, files, canvas); onCloseRequest(); } catch (error: any) { setAppState({ errorMessage: error.message }); } }} />
)} {exportOpts.renderCustomUI && exportOpts.renderCustomUI(elements, appState, files, canvas)}
); }; export const JSONExportDialog = ({ elements, appState, files, actionManager, exportOpts, canvas, setAppState, }: { elements: readonly NonDeletedExcalidrawElement[]; appState: UIAppState; files: BinaryFiles; actionManager: ActionManager; exportOpts: ExportOpts; canvas: HTMLCanvasElement; setAppState: React.Component["setState"]; }) => { const handleClose = React.useCallback(() => { setAppState({ openDialog: null }); }, [setAppState]); return ( <> {appState.openDialog === "jsonExport" && ( )} ); };