From d38f5a037b1ebece2a5402bb61f4a941d2f7efa9 Mon Sep 17 00:00:00 2001 From: Jang Min Date: Fri, 3 Feb 2023 01:14:39 +0900 Subject: [PATCH] feat: export menu accessibility (#1121) * Move export submenu(Edit -> File) * Add export menu to context menu with no selection * Add export shortcuts --- .../components/ContextMenu/ContextMenu.tsx | 23 ++++++++ .../src/components/TopPanel/Menu/Menu.tsx | 42 +++++++-------- .../tldraw/src/hooks/useKeyboardShortcuts.tsx | 54 ++++++++++++++++++- 3 files changed, 97 insertions(+), 22 deletions(-) diff --git a/packages/tldraw/src/components/ContextMenu/ContextMenu.tsx b/packages/tldraw/src/components/ContextMenu/ContextMenu.tsx index 2b0997909..79b578c4b 100644 --- a/packages/tldraw/src/components/ContextMenu/ContextMenu.tsx +++ b/packages/tldraw/src/components/ContextMenu/ContextMenu.tsx @@ -280,6 +280,29 @@ const InnerMenu = React.memo(function InnerMenu() { + + + SVG + + + PNG + + + JPG + + + WEBP + + {isDebugMode && ( + + JSON + + )} + )} diff --git a/packages/tldraw/src/components/TopPanel/Menu/Menu.tsx b/packages/tldraw/src/components/TopPanel/Menu/Menu.tsx index 4bcd9820f..db25db0a0 100644 --- a/packages/tldraw/src/components/TopPanel/Menu/Menu.tsx +++ b/packages/tldraw/src/components/TopPanel/Menu/Menu.tsx @@ -161,6 +161,27 @@ export const Menu = React.memo(function Menu({ readOnly }: MenuProps) { ... )} + + + SVG + + + PNG + + + JPG + + + WEBP + + + JSON + + {!disableAssets && ( <> @@ -233,27 +254,6 @@ export const Menu = React.memo(function Menu({ readOnly }: MenuProps) { JSON - - - SVG - - - PNG - - - JPG - - - WEBP - - - JSON - - ) { const app = useTldrawApp() @@ -227,6 +227,58 @@ export function useKeyboardShortcuts(ref: React.RefObject) { undefined, [app] ) + + useHotkeys( + 'ctrl+alt+1,⌘+alt+1', + (e) => { + if (!canHandleEvent()) return + + app.exportImage(TDExportType.SVG, { scale: 2, quality: 1 }) + }, + undefined, + [app] + ) + useHotkeys( + 'ctrl+alt+2,⌘+alt+2', + (e) => { + if (!canHandleEvent()) return + + app.exportImage(TDExportType.PNG, { scale: 2, quality: 1 }) + }, + undefined, + [app] + ) + useHotkeys( + 'ctrl+alt+3,⌘+alt+3', + (e) => { + if (!canHandleEvent()) return + + app.exportImage(TDExportType.JPG, { scale: 2, quality: 1 }) + }, + undefined, + [app] + ) + useHotkeys( + 'ctrl+alt+4,⌘+alt+4', + (e) => { + if (!canHandleEvent()) return + + app.exportImage(TDExportType.WEBP, { scale: 2, quality: 1 }) + }, + undefined, + [app] + ) + useHotkeys( + 'ctrl+alt+5,⌘+alt+5', + (e) => { + if (!canHandleEvent()) return + + app.exportJson() + }, + undefined, + [app] + ) + useHotkeys( 'ctrl+o,⌘+o', (e) => {