2021-05-25 21:37:14 +02:00
|
|
|
import React, { useState } from "react";
|
|
|
|
import { ActionsManagerInterface } from "../actions/types";
|
|
|
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
import { useIsMobile } from "./App";
|
2021-05-29 02:56:25 +05:30
|
|
|
import { AppState, ExportOpts } from "../types";
|
2021-05-25 21:37:14 +02:00
|
|
|
import { Dialog } from "./Dialog";
|
|
|
|
import { exportFile, exportToFileIcon, link } from "./icons";
|
|
|
|
import { ToolButton } from "./ToolButton";
|
2021-05-29 02:56:25 +05:30
|
|
|
import { actionSaveFileToDisk } from "../actions/actionExport";
|
2021-05-25 21:37:14 +02:00
|
|
|
import { Card } from "./Card";
|
|
|
|
|
|
|
|
import "./ExportDialog.scss";
|
2021-10-07 13:19:40 +02:00
|
|
|
import { nativeFileSystemSupported } from "../data/filesystem";
|
2021-05-25 21:37:14 +02:00
|
|
|
|
|
|
|
export type ExportCB = (
|
|
|
|
elements: readonly NonDeletedExcalidrawElement[],
|
|
|
|
scale?: number,
|
|
|
|
) => void;
|
|
|
|
|
|
|
|
const JSONExportModal = ({
|
|
|
|
elements,
|
|
|
|
appState,
|
|
|
|
actionManager,
|
2021-05-29 02:56:25 +05:30
|
|
|
exportOpts,
|
2021-05-30 00:37:38 +05:30
|
|
|
canvas,
|
2021-05-25 21:37:14 +02:00
|
|
|
}: {
|
|
|
|
appState: AppState;
|
|
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
|
|
|
actionManager: ActionsManagerInterface;
|
|
|
|
onCloseRequest: () => void;
|
2021-05-29 02:56:25 +05:30
|
|
|
exportOpts: ExportOpts;
|
2021-05-30 00:37:38 +05:30
|
|
|
canvas: HTMLCanvasElement | null;
|
2021-05-25 21:37:14 +02:00
|
|
|
}) => {
|
2021-05-30 00:37:38 +05:30
|
|
|
const { onExportToBackend } = exportOpts;
|
2021-05-25 21:37:14 +02:00
|
|
|
return (
|
|
|
|
<div className="ExportDialog ExportDialog--json">
|
|
|
|
<div className="ExportDialog-cards">
|
2021-05-29 02:56:25 +05:30
|
|
|
{exportOpts.saveFileToDisk && (
|
|
|
|
<Card color="lime">
|
|
|
|
<div className="Card-icon">{exportToFileIcon}</div>
|
|
|
|
<h2>{t("exportDialog.disk_title")}</h2>
|
|
|
|
<div className="Card-details">
|
|
|
|
{t("exportDialog.disk_details")}
|
2021-10-07 13:19:40 +02:00
|
|
|
{!nativeFileSystemSupported &&
|
|
|
|
actionManager.renderAction("changeProjectName")}
|
2021-05-29 02:56:25 +05:30
|
|
|
</div>
|
|
|
|
<ToolButton
|
|
|
|
className="Card-button"
|
|
|
|
type="button"
|
|
|
|
title={t("exportDialog.disk_button")}
|
|
|
|
aria-label={t("exportDialog.disk_button")}
|
|
|
|
showAriaLabel={true}
|
|
|
|
onClick={() => {
|
|
|
|
actionManager.executeAction(actionSaveFileToDisk);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
)}
|
2021-05-30 00:37:38 +05:30
|
|
|
{onExportToBackend && (
|
2021-05-25 21:37:14 +02:00
|
|
|
<Card color="pink">
|
|
|
|
<div className="Card-icon">{link}</div>
|
|
|
|
<h2>{t("exportDialog.link_title")}</h2>
|
|
|
|
<div className="Card-details">{t("exportDialog.link_details")}</div>
|
|
|
|
<ToolButton
|
|
|
|
className="Card-button"
|
|
|
|
type="button"
|
|
|
|
title={t("exportDialog.link_button")}
|
|
|
|
aria-label={t("exportDialog.link_button")}
|
|
|
|
showAriaLabel={true}
|
2021-05-30 00:37:38 +05:30
|
|
|
onClick={() => onExportToBackend(elements, appState, canvas)}
|
2021-05-25 21:37:14 +02:00
|
|
|
/>
|
|
|
|
</Card>
|
|
|
|
)}
|
2021-05-30 00:37:38 +05:30
|
|
|
{exportOpts.renderCustomUI &&
|
|
|
|
exportOpts.renderCustomUI(elements, appState, canvas)}
|
2021-05-25 21:37:14 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const JSONExportDialog = ({
|
|
|
|
elements,
|
|
|
|
appState,
|
|
|
|
actionManager,
|
2021-05-29 02:56:25 +05:30
|
|
|
exportOpts,
|
2021-05-30 00:37:38 +05:30
|
|
|
canvas,
|
2021-05-25 21:37:14 +02:00
|
|
|
}: {
|
|
|
|
appState: AppState;
|
|
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
|
|
|
actionManager: ActionsManagerInterface;
|
2021-05-29 02:56:25 +05:30
|
|
|
exportOpts: ExportOpts;
|
2021-05-30 00:37:38 +05:30
|
|
|
canvas: HTMLCanvasElement | null;
|
2021-05-25 21:37:14 +02:00
|
|
|
}) => {
|
|
|
|
const [modalIsShown, setModalIsShown] = useState(false);
|
|
|
|
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
|
|
setModalIsShown(false);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ToolButton
|
|
|
|
onClick={() => {
|
|
|
|
setModalIsShown(true);
|
|
|
|
}}
|
|
|
|
data-testid="json-export-button"
|
|
|
|
icon={exportFile}
|
|
|
|
type="button"
|
|
|
|
aria-label={t("buttons.export")}
|
|
|
|
showAriaLabel={useIsMobile()}
|
|
|
|
title={t("buttons.export")}
|
|
|
|
/>
|
|
|
|
{modalIsShown && (
|
|
|
|
<Dialog onCloseRequest={handleClose} title={t("buttons.export")}>
|
|
|
|
<JSONExportModal
|
|
|
|
elements={elements}
|
|
|
|
appState={appState}
|
|
|
|
actionManager={actionManager}
|
|
|
|
onCloseRequest={handleClose}
|
2021-05-29 02:56:25 +05:30
|
|
|
exportOpts={exportOpts}
|
2021-05-30 00:37:38 +05:30
|
|
|
canvas={canvas}
|
2021-05-25 21:37:14 +02:00
|
|
|
/>
|
|
|
|
</Dialog>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|