开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.
fix(freehand): disable freehand and erase functionalities when user is using two fingers This pr will fix the issue mentioned in #331. 1. Maintain the status of two fingers pressing 2. Prevent freehand drawing and erasing when `isTwoFingerMode` is `true`.
pubuzhixing892a2215ea6af
diff --git a/packages/drawnix/src/plugins/freehand/with-freehand-create.ts b/packages/drawnix/src/plugins/freehand/with-freehand-create.tsindex 485ecb7..01596a7 100644--- a/packages/drawnix/src/plugins/freehand/with-freehand-create.ts+++ b/packages/drawnix/src/plugins/freehand/with-freehand-create.ts@@ -11,6 +11,7 @@ import { createFreehandElement, getFreehandPointers } from './utils';import { Freehand, FreehandShape } from './type';import { FreehandGenerator } from './freehand.generator';import { FreehandSmoother } from './smoother';+import { isTwoFingerMode } from '@plait-board/react-board';export const withFreehandCreate = (board: PlaitBoard) => {const { pointerDown, pointerMove, pointerUp, globalPointerUp, touchStart } =@@ -77,7 +78,7 @@ export const withFreehandCreate = (board: PlaitBoard) => {};board.pointerMove = (event: PointerEvent) => {- if (isDrawing) {+ if (isDrawing && !isTwoFingerMode(board)) {const currentScreenPoint: Point = [event.x, event.y];if (originScreenPoint &&@@ -109,8 +110,9 @@ export const withFreehandCreate = (board: PlaitBoard) => {}return;}-- pointerMove(event);+ if (isTwoFingerMode(board) && isDrawing) {+ complete(true);+ }};board.pointerUp = (event: PointerEvent) => {diff --git a/packages/drawnix/src/plugins/freehand/with-freehand-erase.ts b/packages/drawnix/src/plugins/freehand/with-freehand-erase.tsindex d215052..8ad5316 100644--- a/packages/drawnix/src/plugins/freehand/with-freehand-erase.ts+++ b/packages/drawnix/src/plugins/freehand/with-freehand-erase.ts@@ -11,6 +11,7 @@ import { isHitFreehand } from './utils';import { Freehand, FreehandShape } from './type';import { CoreTransforms } from '@plait/core';import { LaserPointer } from '../../utils/laser-pointer';+import { isTwoFingerMode } from '@plait-board/react-board';export const withFreehandErase = (board: PlaitBoard) => {const { pointerDown, pointerMove, pointerUp, globalPointerUp, touchStart } =@@ -91,14 +92,17 @@ export const withFreehandErase = (board: PlaitBoard) => {};board.pointerMove = (event: PointerEvent) => {- if (isErasing) {+ if (isErasing && !isTwoFingerMode(board)) {throttleRAF(board, 'with-freehand-erase', () => {const currentPoint: Point = [event.x, event.y];checkAndMarkFreehandElementsForDeletion(currentPoint);});return;}-+ if (isErasing && isTwoFingerMode(board)) {+ complete();+ return;+ }pointerMove(event);};diff --git a/packages/react-board/src/index.ts b/packages/react-board/src/index.tsindex 1d00e07..683befc 100644--- a/packages/react-board/src/index.ts+++ b/packages/react-board/src/index.ts@@ -1,4 +1,5 @@export * from './board';export * from './plugins/board';export * from './wrapper';-export * from './hooks/use-board';\ No newline at end of file+export * from './hooks/use-board';+export * from './plugins/with-pinch-zoom-plugin';diff --git a/packages/react-board/src/plugins/with-pinch-zoom-plugin.ts b/packages/react-board/src/plugins/with-pinch-zoom-plugin.tsindex eb45a03..abc2692 100644--- a/packages/react-board/src/plugins/with-pinch-zoom-plugin.ts+++ b/packages/react-board/src/plugins/with-pinch-zoom-plugin.ts@@ -16,6 +16,13 @@ interface PointerRecord {hasMoved: boolean;}+export const TOUCH_RECORDS = new WeakMap<PlaitBoard, PointerRecord[]>();++export const isTwoFingerMode = (board: PlaitBoard) => {+ const pointerRecords = TOUCH_RECORDS.get(board);+ return pointerRecords?.length === 2;+};+export const withPinchZoom = (board: PlaitBoard) => {const { touchStart, touchMove, touchEnd } = board;@@ -30,6 +37,7 @@ export const withPinchZoom = (board: PlaitBoard) => {currentPoint: [touch.clientX, touch.clientY],hasMoved: false,}));+ TOUCH_RECORDS.set(board, pointerRecords);if (pointerRecords.length >= 2) {initializeZoom = board.viewport.zoom;}@@ -150,7 +158,7 @@ export const withPinchZoom = (board: PlaitBoard) => {if (index !== -1) {pointerRecords.splice(index, 1);}-+ TOUCH_RECORDS.set(board, pointerRecords);touchEnd(event);};