Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit d2a1ec7

Browse files
authored
Merge pull request #35 from PsycleResearch/fix/initial-rect-feature
fix: Initial rect feature
2 parents 7f99c94 + add9bff commit d2a1ec7

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@psycle/repsycle",
3-
"version": "0.0.27",
3+
"version": "0.0.28",
44
"description": "Psycle Research front-end toolkit",
55
"author": "Psycle Research",
66
"keywords": [

src/draw-zone/components.tsx

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,23 @@ function SvgZone({
303303
const polyline = useRef<Polyline>()
304304
const { contentHidden, move, scale, setPosition } = useControls()
305305

306+
const localOnInitialRectChange = useCallback(
307+
(elem: Pick<DrawZoneElement, 'id' | 'label' | 'rect'>) => {
308+
if (onInitialRectChange) {
309+
onInitialRectChange({
310+
...elem,
311+
rect: {
312+
height: Math.round(elem.rect.height),
313+
width: Math.round(elem.rect.width),
314+
x: Math.round(elem.rect.x),
315+
y: Math.round(elem.rect.y),
316+
},
317+
})
318+
}
319+
},
320+
[onInitialRectChange],
321+
)
322+
306323
const unselectElements = useCallback(() => {
307324
onChange(elements.map(unSelectElement))
308325
}, [elements, onChange])
@@ -785,13 +802,11 @@ function SvgZone({
785802

786803
if (drawOnPointerDown && lastRect && lastRect.rect) {
787804
currentPosition.x = Math.min(
788-
startPosition.current.x +
789-
(lastRect.rect.width * svgRect.width) / 100,
805+
startPosition.current.x + lastRect.rect.width * scale,
790806
svgRect.width,
791807
)
792808
currentPosition.y = Math.min(
793-
startPosition.current.y +
794-
(lastRect.rect.height * svgRect.height) / 100,
809+
startPosition.current.y + lastRect.rect.height * scale,
795810
svgRect.height,
796811
)
797812
} else {
@@ -834,13 +849,11 @@ function SvgZone({
834849
selected: true,
835850
}
836851

837-
if (onInitialRectChange) {
838-
onInitialRectChange({
839-
rect: newElement.rect,
840-
label: newElement.label,
841-
id: newElement.id,
842-
})
843-
}
852+
localOnInitialRectChange({
853+
rect: newElement.rect,
854+
label: newElement.label,
855+
id: newElement.id,
856+
})
844857

845858
onChange([...elements.map(unSelectElement), newElement])
846859
}
@@ -868,7 +881,7 @@ function SvgZone({
868881
mode,
869882
move,
870883
onChange,
871-
onInitialRectChange,
884+
localOnInitialRectChange,
872885
scale,
873886
setPosition,
874887
shape,
@@ -1308,7 +1321,7 @@ function DrawPolygonElement({
13081321
}
13091322
},
13101323
})
1311-
}, [cleanHandles, createHandles, element, elements, onChange, scale])
1324+
}, [cleanHandles, createHandles, element, elements, mode, onChange, scale])
13121325

13131326
const onPointerDown: React.PointerEventHandler<SVGPolygonElement> =
13141327
useCallback(

0 commit comments

Comments
 (0)