@alepot55/chessboardjs 2.3.2 → 2.3.4

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.
@@ -7650,6 +7650,39 @@ let Chessboard$1 = class Chessboard {
7650
7650
  const squares = this.boardService.getAllSquares();
7651
7651
  const gameStateBefore = this.positionService.getGame().fen();
7652
7652
 
7653
+ // PATCH ROBUSTA: se la board è completamente vuota, forza la rimozione di TUTTI i pezzi
7654
+ if (/^8\/8\/8\/8\/8\/8\/8\/8/.test(gameStateBefore)) {
7655
+ console.log('Board vuota rilevata - rimozione forzata di tutti i pezzi dal DOM');
7656
+
7657
+ // 1. Rimuovi tutti gli elementi DOM dei pezzi dal contenitore della board
7658
+ const boardContainer = document.getElementById(this.config.id_div);
7659
+ if (boardContainer) {
7660
+ const pieceElements = boardContainer.querySelectorAll('.piece');
7661
+ pieceElements.forEach(element => {
7662
+ console.log('Rimozione forzata elemento DOM pezzo:', element);
7663
+ element.remove();
7664
+ });
7665
+ }
7666
+
7667
+ // 2. Azzera tutti i riferimenti JS ai pezzi
7668
+ Object.values(squares).forEach(sq => {
7669
+ if (sq && sq.piece) {
7670
+ console.log('Azzero riferimento pezzo su casella:', sq.id);
7671
+ sq.piece = null;
7672
+ }
7673
+ });
7674
+
7675
+ // 3. Forza la pulizia di eventuali selezioni/hint
7676
+ this._clearVisualState();
7677
+
7678
+ // 4. Aggiungi i listener e notifica il cambio
7679
+ this._addListeners();
7680
+ if (this.config.onChange) this.config.onChange(gameStateBefore);
7681
+
7682
+ console.log('Rimozione forzata completata');
7683
+ return;
7684
+ }
7685
+
7653
7686
  console.log('_doUpdateBoardPieces - current FEN:', gameStateBefore);
7654
7687
  console.log('_doUpdateBoardPieces - animation:', animation, 'style:', this.config.animationStyle, 'isPositionLoad:', isPositionLoad);
7655
7688
 
@@ -8241,6 +8274,12 @@ let Chessboard$1 = class Chessboard {
8241
8274
  }
8242
8275
  if (this._clearVisualState) this._clearVisualState();
8243
8276
  this.positionService.getGame().clear();
8277
+ // Forza la rimozione di tutti i pezzi dal DOM
8278
+ if (this.boardService && this.boardService.squares) {
8279
+ Object.values(this.boardService.squares).forEach(sq => {
8280
+ if (sq && sq.piece) sq.piece = null;
8281
+ });
8282
+ }
8244
8283
  if (this._updateBoardPieces) {
8245
8284
  this._updateBoardPieces(animate, true);
8246
8285
  }
@@ -7646,6 +7646,39 @@ let Chessboard$1 = class Chessboard {
7646
7646
  const squares = this.boardService.getAllSquares();
7647
7647
  const gameStateBefore = this.positionService.getGame().fen();
7648
7648
 
7649
+ // PATCH ROBUSTA: se la board è completamente vuota, forza la rimozione di TUTTI i pezzi
7650
+ if (/^8\/8\/8\/8\/8\/8\/8\/8/.test(gameStateBefore)) {
7651
+ console.log('Board vuota rilevata - rimozione forzata di tutti i pezzi dal DOM');
7652
+
7653
+ // 1. Rimuovi tutti gli elementi DOM dei pezzi dal contenitore della board
7654
+ const boardContainer = document.getElementById(this.config.id_div);
7655
+ if (boardContainer) {
7656
+ const pieceElements = boardContainer.querySelectorAll('.piece');
7657
+ pieceElements.forEach(element => {
7658
+ console.log('Rimozione forzata elemento DOM pezzo:', element);
7659
+ element.remove();
7660
+ });
7661
+ }
7662
+
7663
+ // 2. Azzera tutti i riferimenti JS ai pezzi
7664
+ Object.values(squares).forEach(sq => {
7665
+ if (sq && sq.piece) {
7666
+ console.log('Azzero riferimento pezzo su casella:', sq.id);
7667
+ sq.piece = null;
7668
+ }
7669
+ });
7670
+
7671
+ // 3. Forza la pulizia di eventuali selezioni/hint
7672
+ this._clearVisualState();
7673
+
7674
+ // 4. Aggiungi i listener e notifica il cambio
7675
+ this._addListeners();
7676
+ if (this.config.onChange) this.config.onChange(gameStateBefore);
7677
+
7678
+ console.log('Rimozione forzata completata');
7679
+ return;
7680
+ }
7681
+
7649
7682
  console.log('_doUpdateBoardPieces - current FEN:', gameStateBefore);
7650
7683
  console.log('_doUpdateBoardPieces - animation:', animation, 'style:', this.config.animationStyle, 'isPositionLoad:', isPositionLoad);
7651
7684
 
@@ -8237,6 +8270,12 @@ let Chessboard$1 = class Chessboard {
8237
8270
  }
8238
8271
  if (this._clearVisualState) this._clearVisualState();
8239
8272
  this.positionService.getGame().clear();
8273
+ // Forza la rimozione di tutti i pezzi dal DOM
8274
+ if (this.boardService && this.boardService.squares) {
8275
+ Object.values(this.boardService.squares).forEach(sq => {
8276
+ if (sq && sq.piece) sq.piece = null;
8277
+ });
8278
+ }
8240
8279
  if (this._updateBoardPieces) {
8241
8280
  this._updateBoardPieces(animate, true);
8242
8281
  }
@@ -7649,6 +7649,39 @@ var Chessboard = (function (exports) {
7649
7649
  const squares = this.boardService.getAllSquares();
7650
7650
  const gameStateBefore = this.positionService.getGame().fen();
7651
7651
 
7652
+ // PATCH ROBUSTA: se la board è completamente vuota, forza la rimozione di TUTTI i pezzi
7653
+ if (/^8\/8\/8\/8\/8\/8\/8\/8/.test(gameStateBefore)) {
7654
+ console.log('Board vuota rilevata - rimozione forzata di tutti i pezzi dal DOM');
7655
+
7656
+ // 1. Rimuovi tutti gli elementi DOM dei pezzi dal contenitore della board
7657
+ const boardContainer = document.getElementById(this.config.id_div);
7658
+ if (boardContainer) {
7659
+ const pieceElements = boardContainer.querySelectorAll('.piece');
7660
+ pieceElements.forEach(element => {
7661
+ console.log('Rimozione forzata elemento DOM pezzo:', element);
7662
+ element.remove();
7663
+ });
7664
+ }
7665
+
7666
+ // 2. Azzera tutti i riferimenti JS ai pezzi
7667
+ Object.values(squares).forEach(sq => {
7668
+ if (sq && sq.piece) {
7669
+ console.log('Azzero riferimento pezzo su casella:', sq.id);
7670
+ sq.piece = null;
7671
+ }
7672
+ });
7673
+
7674
+ // 3. Forza la pulizia di eventuali selezioni/hint
7675
+ this._clearVisualState();
7676
+
7677
+ // 4. Aggiungi i listener e notifica il cambio
7678
+ this._addListeners();
7679
+ if (this.config.onChange) this.config.onChange(gameStateBefore);
7680
+
7681
+ console.log('Rimozione forzata completata');
7682
+ return;
7683
+ }
7684
+
7652
7685
  console.log('_doUpdateBoardPieces - current FEN:', gameStateBefore);
7653
7686
  console.log('_doUpdateBoardPieces - animation:', animation, 'style:', this.config.animationStyle, 'isPositionLoad:', isPositionLoad);
7654
7687
 
@@ -8240,6 +8273,12 @@ var Chessboard = (function (exports) {
8240
8273
  }
8241
8274
  if (this._clearVisualState) this._clearVisualState();
8242
8275
  this.positionService.getGame().clear();
8276
+ // Forza la rimozione di tutti i pezzi dal DOM
8277
+ if (this.boardService && this.boardService.squares) {
8278
+ Object.values(this.boardService.squares).forEach(sq => {
8279
+ if (sq && sq.piece) sq.piece = null;
8280
+ });
8281
+ }
8243
8282
  if (this._updateBoardPieces) {
8244
8283
  this._updateBoardPieces(animate, true);
8245
8284
  }
@@ -7652,6 +7652,39 @@
7652
7652
  const squares = this.boardService.getAllSquares();
7653
7653
  const gameStateBefore = this.positionService.getGame().fen();
7654
7654
 
7655
+ // PATCH ROBUSTA: se la board è completamente vuota, forza la rimozione di TUTTI i pezzi
7656
+ if (/^8\/8\/8\/8\/8\/8\/8\/8/.test(gameStateBefore)) {
7657
+ console.log('Board vuota rilevata - rimozione forzata di tutti i pezzi dal DOM');
7658
+
7659
+ // 1. Rimuovi tutti gli elementi DOM dei pezzi dal contenitore della board
7660
+ const boardContainer = document.getElementById(this.config.id_div);
7661
+ if (boardContainer) {
7662
+ const pieceElements = boardContainer.querySelectorAll('.piece');
7663
+ pieceElements.forEach(element => {
7664
+ console.log('Rimozione forzata elemento DOM pezzo:', element);
7665
+ element.remove();
7666
+ });
7667
+ }
7668
+
7669
+ // 2. Azzera tutti i riferimenti JS ai pezzi
7670
+ Object.values(squares).forEach(sq => {
7671
+ if (sq && sq.piece) {
7672
+ console.log('Azzero riferimento pezzo su casella:', sq.id);
7673
+ sq.piece = null;
7674
+ }
7675
+ });
7676
+
7677
+ // 3. Forza la pulizia di eventuali selezioni/hint
7678
+ this._clearVisualState();
7679
+
7680
+ // 4. Aggiungi i listener e notifica il cambio
7681
+ this._addListeners();
7682
+ if (this.config.onChange) this.config.onChange(gameStateBefore);
7683
+
7684
+ console.log('Rimozione forzata completata');
7685
+ return;
7686
+ }
7687
+
7655
7688
  console.log('_doUpdateBoardPieces - current FEN:', gameStateBefore);
7656
7689
  console.log('_doUpdateBoardPieces - animation:', animation, 'style:', this.config.animationStyle, 'isPositionLoad:', isPositionLoad);
7657
7690
 
@@ -8243,6 +8276,12 @@
8243
8276
  }
8244
8277
  if (this._clearVisualState) this._clearVisualState();
8245
8278
  this.positionService.getGame().clear();
8279
+ // Forza la rimozione di tutti i pezzi dal DOM
8280
+ if (this.boardService && this.boardService.squares) {
8281
+ Object.values(this.boardService.squares).forEach(sq => {
8282
+ if (sq && sq.piece) sq.piece = null;
8283
+ });
8284
+ }
8246
8285
  if (this._updateBoardPieces) {
8247
8286
  this._updateBoardPieces(animate, true);
8248
8287
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "chess.js": "^1.0.0"
4
4
  },
5
5
  "name": "@alepot55/chessboardjs",
6
- "version": "2.3.2",
6
+ "version": "2.3.4",
7
7
  "main": "src/index.js",
8
8
  "type": "module",
9
9
  "scripts": {
@@ -671,6 +671,39 @@ class Chessboard {
671
671
  const squares = this.boardService.getAllSquares();
672
672
  const gameStateBefore = this.positionService.getGame().fen();
673
673
 
674
+ // PATCH ROBUSTA: se la board è completamente vuota, forza la rimozione di TUTTI i pezzi
675
+ if (/^8\/8\/8\/8\/8\/8\/8\/8/.test(gameStateBefore)) {
676
+ console.log('Board vuota rilevata - rimozione forzata di tutti i pezzi dal DOM');
677
+
678
+ // 1. Rimuovi tutti gli elementi DOM dei pezzi dal contenitore della board
679
+ const boardContainer = document.getElementById(this.config.id_div);
680
+ if (boardContainer) {
681
+ const pieceElements = boardContainer.querySelectorAll('.piece');
682
+ pieceElements.forEach(element => {
683
+ console.log('Rimozione forzata elemento DOM pezzo:', element);
684
+ element.remove();
685
+ });
686
+ }
687
+
688
+ // 2. Azzera tutti i riferimenti JS ai pezzi
689
+ Object.values(squares).forEach(sq => {
690
+ if (sq && sq.piece) {
691
+ console.log('Azzero riferimento pezzo su casella:', sq.id);
692
+ sq.piece = null;
693
+ }
694
+ });
695
+
696
+ // 3. Forza la pulizia di eventuali selezioni/hint
697
+ this._clearVisualState();
698
+
699
+ // 4. Aggiungi i listener e notifica il cambio
700
+ this._addListeners();
701
+ if (this.config.onChange) this.config.onChange(gameStateBefore);
702
+
703
+ console.log('Rimozione forzata completata');
704
+ return;
705
+ }
706
+
674
707
  console.log('_doUpdateBoardPieces - current FEN:', gameStateBefore);
675
708
  console.log('_doUpdateBoardPieces - animation:', animation, 'style:', this.config.animationStyle, 'isPositionLoad:', isPositionLoad);
676
709
 
@@ -1262,6 +1295,12 @@ class Chessboard {
1262
1295
  }
1263
1296
  if (this._clearVisualState) this._clearVisualState();
1264
1297
  this.positionService.getGame().clear();
1298
+ // Forza la rimozione di tutti i pezzi dal DOM
1299
+ if (this.boardService && this.boardService.squares) {
1300
+ Object.values(this.boardService.squares).forEach(sq => {
1301
+ if (sq && sq.piece) sq.piece = null;
1302
+ });
1303
+ }
1265
1304
  if (this._updateBoardPieces) {
1266
1305
  this._updateBoardPieces(animate, true);
1267
1306
  }