cm-chessboard 8.12.5 → 8.12.7

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.
package/README.md CHANGED
@@ -289,6 +289,10 @@ chessboard-sprite-staunty.svg) and a sprite of the
289
289
  Sprites must be 40x40px in size where the piece elements must have ids like
290
290
  "bp" (black pawn) or "wq" (white queen). Just open the sprite in a text editor, SVG is readable like HTML.
291
291
 
292
+ ### More piece sets
293
+
294
+ [piece-packager](https://github.com/deverac/piece-packager) by @deverac ships 80+ prepackaged piece sets ready to drop into `assets/pieces/`, plus a tool to bundle your own 12 individual piece files (SVG or PNG) into a cm-chessboard-compatible sprite.
295
+
292
296
  ## Extensions
293
297
 
294
298
  cm-chessboard provides the ability to extend its functionality with extensions. Extensions extend the class `Extension`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.12.5",
3
+ "version": "8.12.7",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -246,7 +246,10 @@ export class PositionAnimationsQueue extends PromiseQueue {
246
246
 
247
247
  async enqueuePositionChange(positionFrom, positionTo, animated) {
248
248
  if(positionFrom.getFen() === positionTo.getFen()) {
249
- return Promise.resolve()
249
+ // No diff to animate. Still go through the queue so the promise
250
+ // resolves after any animations already in flight (e.g. an
251
+ // earlier movePiece from a drag). See issue #154.
252
+ return super.enqueue(() => Promise.resolve())
250
253
  } else {
251
254
  return super.enqueue(() => new Promise((resolve) => {
252
255
  let duration = animated ? this.chessboard.props.style.animationDuration : 0
@@ -69,6 +69,36 @@ describe("TestChessboard", () => {
69
69
  chessboard.destroy()
70
70
  })
71
71
 
72
+ // Regression for https://github.com/shaack/cm-chessboard/issues/154
73
+ //
74
+ // A setPosition() call with a null diff (positionFrom === positionTo)
75
+ // used to bypass the animation queue entirely and resolve on the next
76
+ // microtask. That's wrong when an earlier animation — here the animated
77
+ // movePiece — is still in the queue: the setPosition promise must wait
78
+ // for that to drain before resolving, otherwise callers following the
79
+ // "await setPosition(...); then continue" pattern run their
80
+ // continuation before the board is visually settled.
81
+ it("setPosition should wait for pending animations even on a null diff (#154)", async () => {
82
+ const chessboard = new Chessboard(document.getElementById("TestPosition"), {
83
+ assetsUrl: "../assets/",
84
+ position: FEN.start,
85
+ style: {animationDuration: 100}
86
+ })
87
+ let movePieceResolved = false
88
+ const movePromise = chessboard.movePiece("e2", "e4", true).then(() => {
89
+ movePieceResolved = true
90
+ })
91
+ // Same FEN as the position after movePiece → null diff inside
92
+ // setPosition. The animated movePiece above is still queued.
93
+ const targetFen = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR"
94
+ const setPromise = chessboard.setPosition(targetFen, true).then(() => {
95
+ assert.equal(movePieceResolved, true,
96
+ "setPosition resolved before the pending movePiece animation finished")
97
+ })
98
+ await Promise.all([movePromise, setPromise])
99
+ chessboard.destroy()
100
+ })
101
+
72
102
  // Regression for a production crash: the ResizeObserver callback defers
73
103
  // handleResize() via setTimeout to avoid "ResizeObserver loop completed"
74
104
  // warnings. If destroy() is called between the observer firing and the