import React, { useState } from "react"; import { ActionsManagerInterface } from "../actions/types"; import { NonDeletedExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { useIsMobile } from "./App"; import { AppState } from "../types"; import { Dialog } from "./Dialog"; import { exportFile, exportToFileIcon, link } from "./icons"; import { ToolButton } from "./ToolButton"; import { actionSaveAsScene } from "../actions/actionExport"; import { Card } from "./Card"; import "./ExportDialog.scss"; import { supported as fsSupported } from "browser-fs-access"; export type ExportCB = ( elements: readonly NonDeletedExcalidrawElement[], scale?: number, ) => void; const JSONExportModal = ({ elements, appState, actionManager, onExportToBackend, }: { appState: AppState; elements: readonly NonDeletedExcalidrawElement[]; actionManager: ActionsManagerInterface; onExportToBackend?: ExportCB; onCloseRequest: () => void; }) => { return (
{exportToFileIcon}

{t("exportDialog.disk_title")}

{t("exportDialog.disk_details")} {!fsSupported && actionManager.renderAction("changeProjectName")}
{ actionManager.executeAction(actionSaveAsScene); }} />
{onExportToBackend && (
{link}

{t("exportDialog.link_title")}

{t("exportDialog.link_details")}
onExportToBackend(elements)} />
)}
); }; export const JSONExportDialog = ({ elements, appState, actionManager, onExportToBackend, }: { appState: AppState; elements: readonly NonDeletedExcalidrawElement[]; actionManager: ActionsManagerInterface; onExportToBackend?: ExportCB; }) => { 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={useIsMobile()} title={t("buttons.export")} /> {modalIsShown && ( )} ); };