Skip to content

Commit 022f50a

Browse files
committed
Fix: image resize limitations
1 parent 107bc8e commit 022f50a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/hooks/interactions.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
import { useEffect } from "react";
2+
import { selectors } from "@/constants";
3+
import { d3Extended } from "@/utils";
24
import "@interactjs/actions/resize";
35
import "@interactjs/auto-start";
46
import { default as interact } from "@interactjs/interact";
57

68
export const resizeCursors = ["ns-resize", "ew-resize", "nwse-resize", "nesw-resize"];
79

10+
const resizeAttributes = ["width", "height"];
11+
812
const useInteractions = () => {
913
useEffect(() => {
1014
interact(".resizable").resizable({
1115
edges: { left: true, right: true, bottom: true, top: true },
16+
invert: "reposition",
1217
listeners: {
1318
move(event) {
1419
const target = event.target;
15-
target.setAttribute("width", event.rect.width);
16-
target.setAttribute("height", event.rect.height);
20+
const zoom = d3Extended.zoomTransform(document.querySelector(selectors.workspaceGroup));
21+
for (const attr of resizeAttributes) {
22+
let v = +target.getAttribute(attr);
23+
v += (event.deltaRect[attr] * 1) / zoom.k;
24+
target.setAttribute(attr, Math.round(v / 10) * 10);
25+
}
1726
}
1827
}
1928
});

0 commit comments

Comments
 (0)