2020-04-05 15:58:00 +03:00
|
|
|
import React from "react";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
import { isDarwin } from "../keys";
|
|
|
|
import { Dialog } from "./Dialog";
|
|
|
|
import { getShortcutKey } from "../utils";
|
|
|
|
|
|
|
|
const ShortcutIsland = (props: {
|
2020-04-07 14:39:06 +03:00
|
|
|
caption: string;
|
2020-04-05 15:58:00 +03:00
|
|
|
children: React.ReactNode;
|
|
|
|
}) => (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
width: "49%",
|
|
|
|
border: "1px solid #ced4da",
|
|
|
|
marginBottom: "16px",
|
2020-04-09 16:23:10 +08:00
|
|
|
height: "-webkit-fill-available",
|
2020-04-05 15:58:00 +03:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<h3
|
|
|
|
style={{
|
|
|
|
margin: "0",
|
|
|
|
padding: "4px",
|
|
|
|
backgroundColor: "#e9ecef",
|
|
|
|
textAlign: "center",
|
|
|
|
}}
|
|
|
|
>
|
2020-04-07 14:39:06 +03:00
|
|
|
{props.caption}
|
2020-04-05 15:58:00 +03:00
|
|
|
</h3>
|
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-04-07 14:39:06 +03:00
|
|
|
const Shortcut = (props: {
|
|
|
|
label: string;
|
|
|
|
shortcuts: string[];
|
|
|
|
isOr: boolean;
|
|
|
|
}) => (
|
2020-04-05 15:58:00 +03:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
borderTop: "1px solid #ced4da",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
margin: "0",
|
|
|
|
padding: "4px",
|
|
|
|
alignItems: "center",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
flexBasis: 0,
|
|
|
|
flexGrow: 2,
|
|
|
|
lineHeight: 1.4,
|
|
|
|
}}
|
|
|
|
>
|
2020-04-07 14:39:06 +03:00
|
|
|
{props.label}
|
2020-04-05 15:58:00 +03:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexBasis: 0,
|
|
|
|
flexGrow: 1,
|
|
|
|
justifyContent: "center",
|
|
|
|
}}
|
|
|
|
>
|
2020-04-07 14:39:06 +03:00
|
|
|
{props.shortcuts.map((shortcut, index) => (
|
2020-04-08 21:31:40 +09:00
|
|
|
<React.Fragment key={index}>
|
2020-04-07 14:39:06 +03:00
|
|
|
<ShortcutKey>{shortcut}</ShortcutKey>
|
|
|
|
{props.isOr &&
|
|
|
|
index !== props.shortcuts.length - 1 &&
|
|
|
|
t("shortcutsDialog.or")}
|
2020-04-08 21:31:40 +09:00
|
|
|
</React.Fragment>
|
2020-04-05 15:58:00 +03:00
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2020-04-07 14:39:06 +03:00
|
|
|
Shortcut.defaultProps = {
|
|
|
|
isOr: true,
|
|
|
|
};
|
|
|
|
|
2020-04-05 15:58:00 +03:00
|
|
|
const ShortcutKey = (props: { children: React.ReactNode }) => (
|
|
|
|
<span
|
|
|
|
style={{
|
2020-04-09 16:23:10 +08:00
|
|
|
wordBreak: "keep-all",
|
2020-04-05 15:58:00 +03:00
|
|
|
border: "1px solid #ced4da",
|
|
|
|
padding: "2px 8px",
|
2020-04-06 17:26:05 +03:00
|
|
|
margin: "0 4px",
|
2020-04-05 15:58:00 +03:00
|
|
|
backgroundColor: "#e9ecef",
|
|
|
|
borderRadius: "2px",
|
|
|
|
fontSize: "0.8em",
|
|
|
|
}}
|
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const Footer = () => (
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
2020-04-07 14:39:06 +03:00
|
|
|
justifyContent: "space-evenly",
|
2020-04-05 15:58:00 +03:00
|
|
|
borderTop: "1px solid #ced4da",
|
|
|
|
marginTop: 8,
|
|
|
|
paddingTop: 16,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<a
|
|
|
|
href="https://blog.excalidraw.com"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t("shortcutsDialog.blog")}
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
href="https://howto.excalidraw.com"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t("shortcutsDialog.howto")}
|
|
|
|
</a>
|
|
|
|
<a
|
|
|
|
href="https://github.com/excalidraw/excalidraw/issues"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t("shortcutsDialog.github")}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
export const ShortcutsDialog = ({ onClose }: { onClose?: () => void }) => {
|
|
|
|
const handleClose = React.useCallback(() => {
|
|
|
|
if (onClose) {
|
|
|
|
onClose();
|
|
|
|
}
|
|
|
|
}, [onClose]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Dialog
|
|
|
|
maxWidth={800}
|
|
|
|
onCloseRequest={handleClose}
|
|
|
|
title={t("shortcutsDialog.title")}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
flexWrap: "wrap",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
}}
|
|
|
|
>
|
2020-04-07 14:39:06 +03:00
|
|
|
<ShortcutIsland caption={t("shortcutsDialog.shapes")}>
|
|
|
|
<Shortcut label={t("toolBar.selection")} shortcuts={["S", "1"]} />
|
|
|
|
<Shortcut label={t("toolBar.rectangle")} shortcuts={["R", "2"]} />
|
|
|
|
<Shortcut label={t("toolBar.diamond")} shortcuts={["D", "3"]} />
|
|
|
|
<Shortcut label={t("toolBar.ellipse")} shortcuts={["E", "4"]} />
|
|
|
|
<Shortcut label={t("toolBar.arrow")} shortcuts={["A", "5"]} />
|
|
|
|
<Shortcut label={t("toolBar.line")} shortcuts={["L", "6"]} />
|
|
|
|
<Shortcut label={t("toolBar.text")} shortcuts={["T", "7"]} />
|
|
|
|
<Shortcut
|
|
|
|
label={t("shortcutsDialog.curvedArrow")}
|
2020-04-07 16:40:37 +03:00
|
|
|
shortcuts={[
|
|
|
|
"A",
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
]}
|
2020-04-07 14:39:06 +03:00
|
|
|
isOr={false}
|
2020-04-06 17:26:05 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("shortcutsDialog.curvedLine")}
|
2020-04-07 16:40:37 +03:00
|
|
|
shortcuts={[
|
|
|
|
"L",
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
t("shortcutsDialog.click"),
|
|
|
|
]}
|
2020-04-07 14:39:06 +03:00
|
|
|
isOr={false}
|
2020-04-06 17:26:05 +03:00
|
|
|
/>
|
2020-04-07 14:39:06 +03:00
|
|
|
<Shortcut label={t("toolBar.lock")} shortcuts={["Q"]} />
|
2020-04-05 15:58:00 +03:00
|
|
|
</ShortcutIsland>
|
2020-04-07 14:39:06 +03:00
|
|
|
<ShortcutIsland caption={t("shortcutsDialog.editor")}>
|
2020-04-06 15:07:28 +03:00
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.selectAll")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+A")]}
|
2020-04-06 15:07:28 +03:00
|
|
|
/>
|
2020-04-05 15:58:00 +03:00
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.copy")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+C")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.paste")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+V")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.copyAsPng")}
|
|
|
|
shortcuts={[getShortcutKey("Shift+Alt+C")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.copyStyles")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+C")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.pasteStyles")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+Shift+V")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.delete")}
|
|
|
|
shortcuts={[getShortcutKey("Del")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.sendToBack")}
|
2020-04-05 15:58:00 +03:00
|
|
|
shortcuts={[
|
|
|
|
isDarwin
|
2020-04-07 14:39:06 +03:00
|
|
|
? getShortcutKey("CtrlOrCmd+Alt+[")
|
|
|
|
: getShortcutKey("CtrlOrCmd+Shift+["),
|
2020-04-05 15:58:00 +03:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.bringToFront")}
|
2020-04-05 15:58:00 +03:00
|
|
|
shortcuts={[
|
|
|
|
isDarwin
|
2020-04-07 14:39:06 +03:00
|
|
|
? getShortcutKey("CtrlOrCmd+Alt+]")
|
|
|
|
: getShortcutKey("CtrlOrCmd+Shift+]"),
|
2020-04-05 15:58:00 +03:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.sendBackward")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+[")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.bringForward")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+]")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("labels.duplicateSelection")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+D")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
</ShortcutIsland>
|
2020-04-07 14:39:06 +03:00
|
|
|
<ShortcutIsland caption={t("shortcutsDialog.view")}>
|
2020-04-05 15:58:00 +03:00
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("buttons.zoomIn")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd++")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("buttons.zoomOut")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+-")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
|
|
|
<Shortcut
|
2020-04-07 14:39:06 +03:00
|
|
|
label={t("buttons.resetZoom")}
|
|
|
|
shortcuts={[getShortcutKey("CtrlOrCmd+0")]}
|
2020-04-05 15:58:00 +03:00
|
|
|
/>
|
2020-04-07 14:39:06 +03:00
|
|
|
<Shortcut label={t("buttons.toggleFullScreen")} shortcuts={["F"]} />
|
2020-04-05 15:58:00 +03:00
|
|
|
</ShortcutIsland>
|
|
|
|
</div>
|
|
|
|
<Footer />
|
|
|
|
</Dialog>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|