@mhamz.01/easyflow-whiteboard 2.95.0 → 2.96.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":"useLiveUpdate.d.ts","sourceRoot":"","sources":["../../src/hooks/useLiveUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,
|
|
1
|
+
{"version":3,"file":"useLiveUpdate.d.ts","sourceRoot":"","sources":["../../src/hooks/useLiveUpdate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAU,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,MAAM,EAA6B,MAAM,QAAQ,CAAC;AAI3D,UAAU,kBAAkB;IAC1B,YAAY,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvC,WAAW,EAAE,GAAG,CAAC;CAClB;AAED,eAAO,MAAM,aAAa,GAAI,+BAA+B,kBAAkB,SA6D9E,CAAC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
2
|
import { FabricImage } from "fabric";
|
|
3
3
|
import { Frame } from "../lib/fabric-frame";
|
|
4
4
|
import { calculateDashArray } from "../lib/fabric-utils";
|
|
5
5
|
export const useLiveUpdate = ({ fabricCanvas, toolOptions }) => {
|
|
6
|
+
const prevToolOptionsRef = useRef(null);
|
|
6
7
|
useEffect(() => {
|
|
7
8
|
const canvas = fabricCanvas.current;
|
|
8
9
|
if (!canvas)
|
|
@@ -10,6 +11,12 @@ export const useLiveUpdate = ({ fabricCanvas, toolOptions }) => {
|
|
|
10
11
|
const activeObject = canvas.getActiveObject();
|
|
11
12
|
if (!activeObject)
|
|
12
13
|
return;
|
|
14
|
+
// ← FIX: Only update if toolOptions actually changed
|
|
15
|
+
const prevOptions = prevToolOptionsRef.current;
|
|
16
|
+
if (prevOptions && JSON.stringify(prevOptions) === JSON.stringify(toolOptions)) {
|
|
17
|
+
return; // No changes, skip update
|
|
18
|
+
}
|
|
19
|
+
prevToolOptionsRef.current = toolOptions;
|
|
13
20
|
const updateObjectStyle = (obj) => {
|
|
14
21
|
let options = null;
|
|
15
22
|
if (obj.type === "rect")
|
|
@@ -37,10 +44,7 @@ export const useLiveUpdate = ({ fabricCanvas, toolOptions }) => {
|
|
|
37
44
|
update.stroke = options.color || options.strokeColor;
|
|
38
45
|
}
|
|
39
46
|
else {
|
|
40
|
-
update.fill =
|
|
41
|
-
options.fillColor === "transparent"
|
|
42
|
-
? "transparent"
|
|
43
|
-
: options.fillColor;
|
|
47
|
+
update.fill = options.fillColor === "transparent" ? "transparent" : options.fillColor;
|
|
44
48
|
update.stroke = options.strokeColor;
|
|
45
49
|
}
|
|
46
50
|
update.strokeWidth = options.strokeWidth;
|
|
@@ -51,9 +55,7 @@ export const useLiveUpdate = ({ fabricCanvas, toolOptions }) => {
|
|
|
51
55
|
obj.dirty = true;
|
|
52
56
|
};
|
|
53
57
|
if (activeObject.type === "activeSelection") {
|
|
54
|
-
activeObject
|
|
55
|
-
.getObjects()
|
|
56
|
-
.forEach((obj) => updateObjectStyle(obj));
|
|
58
|
+
activeObject.getObjects().forEach((obj) => updateObjectStyle(obj));
|
|
57
59
|
}
|
|
58
60
|
else {
|
|
59
61
|
updateObjectStyle(activeObject);
|