@deepnoid/canvas 0.1.49 → 0.1.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/AnnotationCanvas/_utils/createHistory.d.ts +1 -1
- package/dist/components/AnnotationCanvas/_utils/createHistory.js +2 -4
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangle.js +1 -1
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.d.ts +1 -2
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.js +1 -3
- package/dist/components/AnnotationLayer/_hooks/useMouse.js +2 -1
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ export type CoordinateHistory = {
|
|
|
5
5
|
setHistoryIndex: (index: number) => void;
|
|
6
6
|
init: (coordinates?: Coordinate[]) => void;
|
|
7
7
|
add: (coordinates: Coordinate[]) => void;
|
|
8
|
-
undo: () => Coordinate[]
|
|
8
|
+
undo: () => Coordinate[];
|
|
9
9
|
redo: () => Coordinate[] | undefined;
|
|
10
10
|
};
|
|
11
11
|
export declare const createHistory: () => CoordinateHistory;
|
|
@@ -17,11 +17,9 @@ export const createHistory = () => {
|
|
|
17
17
|
historyIndex++;
|
|
18
18
|
},
|
|
19
19
|
undo: () => {
|
|
20
|
-
if (historyIndex >
|
|
20
|
+
if (historyIndex > -1)
|
|
21
21
|
historyIndex--;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
22
|
+
return history[historyIndex] || [];
|
|
25
23
|
},
|
|
26
24
|
redo: () => {
|
|
27
25
|
if (historyIndex < history.length - 1) {
|
|
@@ -50,7 +50,7 @@ export const handleMouseUpRectangle = ({ canvasRef, canvasStateRef, mouseActionR
|
|
|
50
50
|
if (!currentCoordinateRef.current) {
|
|
51
51
|
const label = drawLabelRef.current;
|
|
52
52
|
const newCoordinate = { label, type: DrawMode.RECTANGLE, x, y, width, height, selected: false };
|
|
53
|
-
createCoordinate(newCoordinate, setCoordinates, coordinatesRef,
|
|
53
|
+
createCoordinate(newCoordinate, setCoordinates, coordinatesRef, currentCoordinateRef);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { RefObject } from 'react';
|
|
2
2
|
import { Coordinate, Point, Rectangle, CanvasState } from '../../../../types';
|
|
3
|
-
import { CoordinateHistory } from '../../../AnnotationCanvas/_utils/createHistory';
|
|
4
3
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
5
4
|
import { RectangleAnchor } from '../../../../enum/common';
|
|
6
5
|
export declare const ACTIVE_POINT_SIZE = 10;
|
|
@@ -10,7 +9,7 @@ export declare const getRectangleCorners: ({ x, y, width, height }: Rectangle) =
|
|
|
10
9
|
}[];
|
|
11
10
|
export declare const selectRectangleAtPoint: (zoom: number, mousePoint: Point, coordinatesRef: RefObject<Coordinate[]>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
|
|
12
11
|
export declare const updateActiveRectangleAnchor: (zoom: number, mousePointRef: Point, currentCoordinateRef: RefObject<Coordinate | null>, rectangleAnchorRef: RefObject<RectangleAnchor | null>) => void;
|
|
13
|
-
export declare const createCoordinate: (coordinate: Coordinate, setCoordinates: (dataSet: Coordinate[]) => void, coordinatesRef: RefObject<Coordinate[]>,
|
|
12
|
+
export declare const createCoordinate: (coordinate: Coordinate, setCoordinates: (dataSet: Coordinate[]) => void, coordinatesRef: RefObject<Coordinate[]>, currentCoordinateRef: RefObject<Coordinate | null>) => void;
|
|
14
13
|
export declare const clampBoundingBoxToImage: (x: number, y: number, width: number, height: number, dw: number, dh: number) => Rectangle & {
|
|
15
14
|
selected?: boolean;
|
|
16
15
|
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MouseAction } from '../../../../utils/mouseActions';
|
|
2
|
-
import { cloneDeep } from '../../../../utils/common/cloneDeep';
|
|
3
2
|
import { DrawMode, RectangleAnchor } from '../../../../enum/common';
|
|
4
3
|
import { getMousePointTransform } from '../../../../utils/pointTransform';
|
|
5
4
|
export const ACTIVE_POINT_SIZE = 10;
|
|
@@ -96,9 +95,8 @@ export const updateActiveRectangleAnchor = (zoom, mousePointRef, currentCoordina
|
|
|
96
95
|
rectangleAnchorRef.current = null;
|
|
97
96
|
}
|
|
98
97
|
};
|
|
99
|
-
export const createCoordinate = (coordinate, setCoordinates, coordinatesRef,
|
|
98
|
+
export const createCoordinate = (coordinate, setCoordinates, coordinatesRef, currentCoordinateRef) => {
|
|
100
99
|
coordinatesRef.current.push(coordinate);
|
|
101
|
-
historyRef.current.add(cloneDeep(coordinatesRef.current));
|
|
102
100
|
setCoordinates(coordinatesRef.current);
|
|
103
101
|
currentCoordinateRef.current = null;
|
|
104
102
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { isMouseClickAction, mapButtonToMouseAction, MouseAction } from '../../../utils/mouseActions';
|
|
3
3
|
import { DrawMode } from '../../../enum/common';
|
|
4
|
+
import { cloneDeep } from '../../../utils/common/cloneDeep';
|
|
4
5
|
export const INIT_POINT = { x: 0, y: 0, selected: false };
|
|
5
6
|
export function useMouse({ canvasRef, mouseActionRef, setMousePoint, coordinatesRef, setCoordinates, historyRef, selectedDrawMode, }) {
|
|
6
7
|
const handleMouseDown = useCallback((event) => {
|
|
@@ -14,7 +15,7 @@ export function useMouse({ canvasRef, mouseActionRef, setMousePoint, coordinates
|
|
|
14
15
|
if (canvasRef.current && isMouseClickAction(event.button, MouseAction.LEFT) && selectedDrawMode) {
|
|
15
16
|
if (selectedDrawMode === DrawMode.RECTANGLE && coordinatesRef?.current && setCoordinates) {
|
|
16
17
|
setCoordinates(coordinatesRef.current);
|
|
17
|
-
historyRef.current.add(
|
|
18
|
+
historyRef.current.add(cloneDeep(coordinatesRef.current));
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
mouseActionRef.current = null;
|