@mhamz.01/easyflow-whiteboard 2.56.0 → 2.57.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCopyPaste.d.ts","sourceRoot":"","sources":["../../src/hooks/useCopyPaste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAE9C,UAAU,iBAAiB;IACzB,YAAY,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,YAAY,GAAI,kBAAkB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"useCopyPaste.d.ts","sourceRoot":"","sources":["../../src/hooks/useCopyPaste.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,MAAM,EAAgB,MAAM,QAAQ,CAAC;AAE9C,UAAU,iBAAiB;IACzB,YAAY,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACxC;AAED,eAAO,MAAM,YAAY,GAAI,kBAAkB,iBAAiB,SA2F/D,CAAC"}
|
|
@@ -22,37 +22,54 @@ export const useCopyPaste = ({ fabricCanvas }) => {
|
|
|
22
22
|
clipboardRef.current = cloned;
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
// ── Paste
|
|
25
|
+
// ── Paste ─────────────────────────────────────────────────────────────────
|
|
26
26
|
if ((e.ctrlKey || e.metaKey) && e.key === "v") {
|
|
27
27
|
const copied = clipboardRef.current;
|
|
28
28
|
if (!copied)
|
|
29
29
|
return;
|
|
30
|
-
|
|
30
|
+
canvas.discardActiveObject();
|
|
31
31
|
const cloned = await copied.clone();
|
|
32
|
-
|
|
33
|
-
cloned.set({
|
|
34
|
-
left: (cloned.left ?? 0) + 20,
|
|
35
|
-
top: (cloned.top ?? 0) + 20,
|
|
36
|
-
// Clear any active selection state from the cloned object
|
|
37
|
-
evented: true,
|
|
38
|
-
});
|
|
39
|
-
// If it's a group/active selection, ungroup into individual objects
|
|
32
|
+
const offset = 20;
|
|
40
33
|
if (cloned.type === "activeSelection" && "getObjects" in cloned) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
cloned.
|
|
34
|
+
const objects = cloned.getObjects();
|
|
35
|
+
// Apply the group's transform to each child to get absolute positions
|
|
36
|
+
const groupLeft = cloned.left ?? 0;
|
|
37
|
+
const groupTop = cloned.top ?? 0;
|
|
38
|
+
const groupAngle = cloned.angle ?? 0;
|
|
39
|
+
const addedObjects = [];
|
|
40
|
+
for (const obj of objects) {
|
|
41
|
+
const childClone = await obj.clone();
|
|
42
|
+
// Convert from group-local to canvas-absolute coords
|
|
43
|
+
// Fabric stores child positions relative to group center
|
|
44
|
+
childClone.set({
|
|
45
|
+
left: (obj.left ?? 0) + groupLeft + offset,
|
|
46
|
+
top: (obj.top ?? 0) + groupTop + offset,
|
|
47
|
+
angle: (obj.angle ?? 0) + groupAngle,
|
|
48
|
+
});
|
|
49
|
+
childClone.setCoords();
|
|
50
|
+
canvas.add(childClone);
|
|
51
|
+
addedObjects.push(childClone);
|
|
52
|
+
}
|
|
53
|
+
// Select all pasted objects together
|
|
54
|
+
if (addedObjects.length > 0) {
|
|
55
|
+
const { ActiveSelection } = await import("fabric");
|
|
56
|
+
const newSelection = new ActiveSelection(addedObjects, { canvas });
|
|
57
|
+
canvas.setActiveObject(newSelection);
|
|
58
|
+
// Update clipboard to new clones for cascading offset on next paste
|
|
59
|
+
clipboardRef.current = newSelection;
|
|
60
|
+
}
|
|
46
61
|
}
|
|
47
62
|
else {
|
|
63
|
+
cloned.set({
|
|
64
|
+
left: (cloned.left ?? 0) + offset,
|
|
65
|
+
top: (cloned.top ?? 0) + offset,
|
|
66
|
+
});
|
|
67
|
+
cloned.setCoords();
|
|
48
68
|
canvas.add(cloned);
|
|
69
|
+
canvas.setActiveObject(cloned);
|
|
70
|
+
clipboardRef.current = cloned;
|
|
49
71
|
}
|
|
50
|
-
// Select the newly pasted object(s)
|
|
51
|
-
canvas.setActiveObject(cloned);
|
|
52
72
|
canvas.requestRenderAll();
|
|
53
|
-
// Update clipboard to the new clone so next paste offsets again
|
|
54
|
-
clipboardRef.current = cloned;
|
|
55
|
-
return;
|
|
56
73
|
}
|
|
57
74
|
};
|
|
58
75
|
window.addEventListener("keydown", handleKeyDown);
|