Skip to content

Commit 87b495f

Browse files
fix: BROS-777: Disallow adding more points for locked Vectors (#9320)
Co-authored-by: nick-skriabin <nick-skriabin@users.noreply.github.com>
1 parent 84e2aa4 commit 87b495f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

web/libs/editor/src/components/KonvaVector/KonvaVector.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,9 +1609,19 @@ export const KonvaVector = forwardRef<KonvaVectorRef, KonvaVectorProps>((props,
16091609
};
16101610
},
16111611
// Programmatic point creation methods
1612-
startPoint: (x: number, y: number) => pointCreationManager.startPoint(x, y),
1613-
updatePoint: (x: number, y: number) => pointCreationManager.updatePoint(x, y),
1614-
commitPoint: (x: number, y: number) => pointCreationManager.commitPoint(x, y),
1612+
// These check the disabled prop to prevent point creation when the region is locked
1613+
startPoint: (x: number, y: number) => {
1614+
if (disabled) return false;
1615+
return pointCreationManager.startPoint(x, y);
1616+
},
1617+
updatePoint: (x: number, y: number) => {
1618+
if (disabled) return;
1619+
pointCreationManager.updatePoint(x, y);
1620+
},
1621+
commitPoint: (x: number, y: number) => {
1622+
if (disabled) return;
1623+
pointCreationManager.commitPoint(x, y);
1624+
},
16151625
// Programmatic point transformation methods
16161626
translatePoints: (dx: number, dy: number, pointIds?: string[]) => {
16171627
const pointsToTransform = pointIds ? initialPoints.filter((p) => pointIds.includes(p.id)) : initialPoints;

web/libs/editor/src/regions/VectorRegion.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ const Model = types
456456
},
457457

458458
addPoint(x, y) {
459+
// Don't allow adding points when region is locked or readonly
460+
if (self.locked || self.isReadOnly()) {
461+
return null;
462+
}
463+
459464
const image = self.parent.currentImageEntity;
460465
const width = image.naturalWidth;
461466
const height = image.naturalHeight;
@@ -483,6 +488,10 @@ const Model = types
483488
// Uses KonvaVector startPoint to start drawing
484489
// This will only initiate point drawing, but won't create actual point
485490
startPoint(x, y) {
491+
// Don't allow adding points when region is locked or readonly
492+
if (self.locked || self.isReadOnly()) {
493+
return;
494+
}
486495
self.vectorRef.startPoint(x, y);
487496
},
488497

@@ -492,13 +501,21 @@ const Model = types
492501
//
493502
// This method is designed to create Bezier curve
494503
updatePoint(x, y) {
504+
// Don't allow modifying points when region is locked or readonly
505+
if (self.locked || self.isReadOnly()) {
506+
return;
507+
}
495508
self.vectorRef.updatePoint(x, y);
496509
},
497510

498511
// Commits previously created point and resets the state
499512
//
500513
// Will create a new point if it was started but never updated (regular click)
501514
commitPoint(x, y) {
515+
// Don't allow adding points when region is locked or readonly
516+
if (self.locked || self.isReadOnly()) {
517+
return;
518+
}
502519
self.vectorRef?.commitPoint(x, y);
503520
},
504521

0 commit comments

Comments
 (0)