import React, { useState } from "react"; import { NonDeletedExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { useDeviceType } from "./App"; import { AppState, ExportOpts, BinaryFiles } from "../types"; import { Dialog } from "./Dialog"; import { exportFile, exportToFileIcon, link } 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, files, actionManager, exportOpts, canvas, }: { appState: AppState; files: BinaryFiles; elements: readonly NonDeletedExcalidrawElement[]; actionManager: ActionManager; onCloseRequest: () => void; exportOpts: ExportOpts; canvas: HTMLCanvasElement | null; }) => { const { onExportToBackend } = exportOpts; return (
{exportOpts.saveFileToDisk && (
{exportToFileIcon}

{t("exportDialog.disk_title")}

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

{t("exportDialog.link_title")}

{t("exportDialog.link_details")}
{ onExportToBackend(elements, appState, files, canvas); trackEvent("export", "link", `ui (${getFrame()})`); }} />
)} {exportOpts.renderCustomUI && exportOpts.renderCustomUI(elements, appState, files, canvas)}
); }; export const JSONExportDialog = ({ elements, appState, files, actionManager, exportOpts, canvas, }: { elements: readonly NonDeletedExcalidrawElement[]; appState: AppState; files: BinaryFiles; actionManager: ActionManager; exportOpts: ExportOpts; canvas: HTMLCanvasElement | null; }) => { const [modalIsShown, setModalIsShown] = useState(false); const handleClose = React.useCallback(() => { setModalIsShown(false); }, []); return ( <> { setModalIsShown(true); }} data-testid="json-export-button" icon={exportFile} type="button" aria-label={t("buttons.export")} showAriaLabel={useDeviceType().isMobile} title={t("buttons.export")} /> {modalIsShown && ( )} ); };