Skip to content

开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.

feat(creation): support creation mode hotkey #183 (#185)

pubuzhixing88601e3c14dda
diff --git a/packages/drawnix/src/components/shape-picker.tsx b/packages/drawnix/src/components/shape-picker.tsx
index 5659d37..2bb37ff 100644
--- a/packages/drawnix/src/components/shape-picker.tsx
+++ b/packages/drawnix/src/components/shape-picker.tsx
@@ -27,17 +27,17 @@ export interface ShapeProps {
const SHAPES: ShapeProps[] = [
{
icon: RectangleIcon,
- title: 'Rectangle',
+ title: 'Rectangle — R',
pointer: BasicShapes.rectangle,
},
{
icon: EllipseIcon,
- title: 'Ellipse',
+ title: 'Ellipse — O',
pointer: BasicShapes.ellipse,
},
{
icon: TriangleIcon,
- title: 'Triangle',
+ title: 'Triangle — T',
pointer: BasicShapes.triangle,
},
{
diff --git a/packages/drawnix/src/components/toolbar/creation-toolbar.tsx b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx
index 4750fbd..4860b86 100644
--- a/packages/drawnix/src/components/toolbar/creation-toolbar.tsx
+++ b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx
@@ -38,10 +38,8 @@ import {
useDrawnix,
useSetPointer,
} from '../../hooks/use-drawnix';
-import { fileOpen } from '../../data/filesystem';
-import { IMAGE_MIME_TYPES } from '../../constants';
-import { insertImage } from '../../data/image';
import { ExtraToolsButton } from './extra-tools/extra-tools-button';
+import { addImage } from '../../utils/image';
export enum PopupKey {
'shape' = 'shape',
@@ -66,17 +64,17 @@ export const BUTTONS: AppToolButtonProps[] = [
{
icon: HandIcon,
pointer: PlaitPointerType.hand,
- title: 'Hand',
+ title: 'Hand — H',
},
{
icon: SelectionIcon,
pointer: PlaitPointerType.selection,
- title: 'Selection',
+ title: 'Selection — V',
},
{
icon: MindIcon,
pointer: MindPointerType.mind,
- title: 'Mind',
+ title: 'Mind — M',
},
{
icon: TextIcon,
@@ -86,11 +84,11 @@ export const BUTTONS: AppToolButtonProps[] = [
{
icon: FeltTipPenIcon,
pointer: FreehandShape.feltTipPen,
- title: 'Freehand',
+ title: 'Pen — P',
},
{
icon: StraightArrowLineIcon,
- title: 'Arrow Line',
+ title: 'Arrow — A',
key: PopupKey.arrow,
pointer: ArrowLineShape.straight,
},
@@ -102,12 +100,12 @@ export const BUTTONS: AppToolButtonProps[] = [
},
{
icon: ImageIcon,
- title: 'Image',
+ title: 'Image — Cmd+U',
key: 'image',
},
{
icon: ExtraToolsIcon,
- title: '更多工具',
+ title: 'More Tools',
key: 'extra-tools',
},
];
@@ -150,18 +148,6 @@ export const CreationToolbar = () => {
);
};
- const addImage = async () => {
- const imageFile = await fileOpen({
- description: 'Image',
- extensions: Object.keys(
- IMAGE_MIME_TYPES
- ) as (keyof typeof IMAGE_MIME_TYPES)[],
- });
- insertImage(board, imageFile);
- };
-
- const [dialogOpen, setDialogOpen] = useState(false);
-
return (
<Island
padding={1}
@@ -226,8 +212,8 @@ export const CreationToolbar = () => {
visible={true}
selected={arrowOpen || isArrowLinePointer(board)}
icon={button.icon}
- title={`Arrow`}
- aria-label={`Arrow`}
+ title={button.title!}
+ aria-label={button.title!}
onPointerDown={() => {
setArrowOpen(!shapeOpen);
}}
@@ -268,7 +254,7 @@ export const CreationToolbar = () => {
setPointer(button.pointer);
}
if (button.key === 'image') {
- addImage();
+ addImage(board);
}
}}
/>
diff --git a/packages/drawnix/src/plugins/with-hotkey.ts b/packages/drawnix/src/plugins/with-hotkey.ts
index fa17ee4..0d12245 100644
--- a/packages/drawnix/src/plugins/with-hotkey.ts
+++ b/packages/drawnix/src/plugins/with-hotkey.ts
@@ -1,8 +1,12 @@
-import { PlaitBoard } from '@plait/core';
+import { BoardTransforms, PlaitBoard, PlaitPointerType } from '@plait/core';
import { isHotkey } from 'is-hotkey';
-import { saveAsImage } from '../utils/image';
+import { addImage, saveAsImage } from '../utils/image';
import { saveAsJSON } from '../data/json';
import { DrawnixState } from '../hooks/use-drawnix';
+import { BoardCreationMode, setCreationMode } from '@plait/common';
+import { MindPointerType } from '@plait/mind';
+import { FreehandShape } from './freehand/type';
+import { ArrowLineShape, BasicShapes } from '@plait/draw';
export const buildDrawnixHotkeyPlugin = (
updateAppState: (appState: Partial<DrawnixState>) => void
@@ -34,6 +38,42 @@ export const buildDrawnixHotkeyPlugin = (
event.preventDefault();
return;
}
+ if (event.key === 'h') {
+ BoardTransforms.updatePointerType(board, PlaitPointerType.hand);
+ updateAppState({ pointer: PlaitPointerType.hand });
+ }
+ if (event.key === 'v') {
+ BoardTransforms.updatePointerType(board, PlaitPointerType.selection);
+ updateAppState({ pointer: PlaitPointerType.selection });
+ }
+ if (event.key === 'm') {
+ setCreationMode(board, BoardCreationMode.dnd);
+ BoardTransforms.updatePointerType(board, MindPointerType.mind);
+ updateAppState({ pointer: MindPointerType.mind });
+ }
+ if (event.key === 'p') {
+ setCreationMode(board, BoardCreationMode.drawing);
+ BoardTransforms.updatePointerType(board, FreehandShape.feltTipPen);
+ updateAppState({ pointer: FreehandShape.feltTipPen });
+ }
+ if (event.key === 'a') {
+ setCreationMode(board, BoardCreationMode.drawing);
+ BoardTransforms.updatePointerType(board, ArrowLineShape.straight);
+ updateAppState({ pointer: ArrowLineShape.straight });
+ }
+ if (event.key === 'r' || event.key === 'o' || event.key === 't') {
+ const keyToPointer = {
+ r: BasicShapes.rectangle,
+ o: BasicShapes.ellipse,
+ t: BasicShapes.triangle,
+ };
+ setCreationMode(board, BoardCreationMode.drawing);
+ BoardTransforms.updatePointerType(board, keyToPointer[event.key]);
+ updateAppState({ pointer: keyToPointer[event.key] });
+ }
+ if (isHotkey(['mod+u'])(event)) {
+ addImage(board);
+ }
}
globalKeyDown(event);
};
diff --git a/packages/drawnix/src/plugins/with-text-link.tsx b/packages/drawnix/src/plugins/with-text-link.tsx
index 22f672d..7804673 100644
--- a/packages/drawnix/src/plugins/with-text-link.tsx
+++ b/packages/drawnix/src/plugins/with-text-link.tsx
@@ -41,11 +41,6 @@ export const buildTextLinkPlugin = (
let timeoutId: any | null = null;
board.pointerMove = (event: PointerEvent) => {
- // const { appState } = board as DrawnixBoard;
- // const isEditing =
- // appState && appState.linkState && appState.linkState.isEditing;
- // const isHovering =
- // appState && appState.linkState && appState.linkState.isEditing;
if (
(PlaitBoard.isPointer(board, PlaitPointerType.selection) ||
PlaitBoard.isPointer(board, PlaitPointerType.hand)) &&
diff --git a/packages/drawnix/src/utils/image.ts b/packages/drawnix/src/utils/image.ts
index 19954cc..e2ddc0a 100644
--- a/packages/drawnix/src/utils/image.ts
+++ b/packages/drawnix/src/utils/image.ts
@@ -1,5 +1,8 @@
import { getSelectedElements, PlaitBoard } from '@plait/core';
import { base64ToBlob, boardToImage, download } from './common';
+import { fileOpen } from '../data/filesystem';
+import { IMAGE_MIME_TYPES } from '../constants';
+import { insertImage } from '../data/image';
export const saveAsImage = (board: PlaitBoard, isTransparent: boolean) => {
const selectedElements = getSelectedElements(board);
@@ -15,3 +18,13 @@ export const saveAsImage = (board: PlaitBoard, isTransparent: boolean) => {
}
});
};
+
+export const addImage = async (board: PlaitBoard) => {
+ const imageFile = await fileOpen({
+ description: 'Image',
+ extensions: Object.keys(
+ IMAGE_MIME_TYPES
+ ) as (keyof typeof IMAGE_MIME_TYPES)[],
+ });
+ insertImage(board, imageFile);
+};