@@ -59,6 +59,10 @@ export class CanvasEngine {
5959 | ( ( participants : RoomParticipants [ ] ) => void )
6060 | null ;
6161 private onConnectionChange : ( ( isConnected : boolean ) => void ) | null ;
62+ private onShapeCountChange : ( ( count : number ) => void ) | null = null ;
63+ public setOnShapeCountChange ( callback : ( count : number ) => void ) {
64+ this . onShapeCountChange = callback ;
65+ }
6266
6367 private clicked : boolean ;
6468 public outputScale : number = 1 ;
@@ -704,6 +708,7 @@ export class CanvasEngine {
704708 }
705709
706710 this . existingShapes . push ( shape ) ;
711+ this . notifyShapeCountChange ( ) ;
707712
708713 if ( this . isStandalone ) {
709714 try {
@@ -1084,6 +1089,7 @@ export class CanvasEngine {
10841089 } ;
10851090
10861091 this . existingShapes . push ( newShape ) ;
1092+ this . notifyShapeCountChange ( ) ;
10871093
10881094 if ( this . isStandalone ) {
10891095 localStorage . setItem (
@@ -1712,6 +1718,7 @@ export class CanvasEngine {
17121718 if ( shapeIndex !== - 1 ) {
17131719 const erasedShape = this . existingShapes [ shapeIndex ] ;
17141720 this . existingShapes . splice ( shapeIndex , 1 ) ;
1721+ this . notifyShapeCountChange ( ) ;
17151722 this . clearCanvas ( ) ;
17161723
17171724 if ( this . isStandalone ) {
@@ -1791,6 +1798,7 @@ export class CanvasEngine {
17911798
17921799 clearAllShapes ( ) {
17931800 this . existingShapes = [ ] ;
1801+ this . notifyShapeCountChange ( ) ;
17941802 this . clearCanvas ( ) ;
17951803 if ( this . isStandalone ) {
17961804 localStorage . removeItem ( LOCALSTORAGE_CANVAS_KEY ) ;
@@ -1835,7 +1843,6 @@ export class CanvasEngine {
18351843 }
18361844 }
18371845 } ) ;
1838-
18391846 this . clearCanvas ( ) ;
18401847 }
18411848
@@ -1845,4 +1852,8 @@ export class CanvasEngine {
18451852 ) ;
18461853 this . clearCanvas ( ) ;
18471854 }
1855+
1856+ private notifyShapeCountChange ( ) {
1857+ this . onShapeCountChange ?.( this . existingShapes . length ) ;
1858+ }
18481859}
0 commit comments