cm-chessboard 5.3.0 → 5.3.2

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/index.html CHANGED
@@ -28,8 +28,9 @@ It works, it is cool and it is easy to use. 👍</p>
28
28
  </ul>
29
29
  <h3>Examples of extensions</h3>
30
30
  <ul>
31
- <li><a href="examples/extensions/chessboard-accessibility-extension.html">Accessibility extension</a> 🆕</li>
32
- <li><a href="examples/extensions/chessboard-arrows-extension.html">Arrows extension</a> 🆕</li>
31
+ <li><a href="examples/extensions/chessboard-accessibility-extension.html">Accessibility extension</a></li>
32
+ <li><a href="examples/extensions/chessboard-arrows-extension.html">Arrows extension</a></li>
33
+ <li><a href="examples/extensions/chessboard-promotion-extension.html">Promotion extension</a> 🆕</li>
33
34
  </ul>
34
35
  </div>
35
36
  <h2>Chessboard</h2>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "5.3.0",
3
+ "version": "5.3.2",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -4,19 +4,33 @@
4
4
  * License: MIT, see file 'LICENSE'
5
5
  */
6
6
  import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
7
- import {INPUT_EVENT_TYPE} from "../../Chessboard.js"
7
+ import {INPUT_EVENT_TYPE, PIECE} from "../../Chessboard.js"
8
8
 
9
9
  export class Promotion extends Extension {
10
10
 
11
11
  constructor(chessboard, props) {
12
12
  super(chessboard, props)
13
- this.registerExtensionPoint(EXTENSION_POINT.moveInput, this.onMoveInput)
13
+ this.registerExtensionPoint(EXTENSION_POINT.moveInput, this.onMoveInput.bind(this))
14
14
  }
15
15
 
16
16
  onMoveInput(event) {
17
17
  if(event.type === INPUT_EVENT_TYPE.validateMoveInput) {
18
- console.log("976000", event)
19
- return false // todo show flashing marker and return move
18
+ console.log(this)
19
+ console.log("976000", event,
20
+ this.chessboard.getPiece(event.squareFrom),
21
+ this.chessboard.getPiece(event.squareTo))
22
+ if(event.piece === PIECE.wp && event.squareTo.charAt(1) === "8") {
23
+ return false
24
+ }
20
25
  }
21
26
  }
27
+
28
+ showPromotionDialog(event) {
29
+ this.promotionDialog = document.createElement("div")
30
+ this.promotionDialog.style.width = "50px"
31
+ this.promotionDialog.style.height = "50px"
32
+ this.promotionDialog.style.backgroundColor = "white"
33
+ // this.chessboard.view.
34
+ }
35
+
22
36
  }
@@ -82,11 +82,15 @@ export class ChessboardState {
82
82
  const extensionPoints = this.extensionPoints[name]
83
83
  const dataCloned = Object.assign({}, data)
84
84
  dataCloned.extensionPoint = name
85
+ let returnValue = true
85
86
  if (extensionPoints) {
86
87
  for (const extensionPoint of extensionPoints) {
87
- extensionPoint(dataCloned)
88
+ if(extensionPoint(dataCloned) === false) {
89
+ returnValue = false
90
+ }
88
91
  }
89
92
  }
93
+ return returnValue
90
94
  }
91
95
 
92
96
  }
@@ -8,8 +8,8 @@ export const EXTENSION_POINT = {
8
8
  positionChanged: "positionChanged", // the positions of the pieces was changed
9
9
  boardChanged: "boardChanged", // the board (orientation) was changed
10
10
  moveInputToggled: "moveInputToggled", // move input was enabled or disabled
11
- moveInput: "moveInput", // move started, to validate or canceled // TODO validation not possible for now, see https://github.com/shaack/cm-chessboard/issues/82
12
- moveInputStateChanged: "moveInput", // TODO deprecated, use `moveInput`
11
+ moveInput: "moveInput", // move started, to validate or canceled
12
+ // moveInputStateChanged: "moveInput", // TODO deprecated, use `moveInput`
13
13
  redrawBoard: "redrawBoard", // called after redrawing the board
14
14
  destroy: "destroy" // called, before the board is destroyed
15
15
  }
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import {VisualMoveInput} from "./VisualMoveInput.js"
8
- import {COLOR, INPUT_EVENT_TYPE, BORDER_TYPE} from "../Chessboard.js"
8
+ import {BORDER_TYPE, COLOR, INPUT_EVENT_TYPE} from "../Chessboard.js"
9
9
  import {Position} from "../model/Position.js"
10
10
  import {EXTENSION_POINT} from "../model/Extension.js"
11
11
 
@@ -410,14 +410,18 @@ export class ChessboardView {
410
410
  chessboard: this.chessboard,
411
411
  type: INPUT_EVENT_TYPE.validateMoveInput,
412
412
  squareFrom: squareFrom,
413
- squareTo: squareTo
413
+ squareTo: squareTo,
414
+ piece: this.chessboard.getPiece(squareFrom)
414
415
  }
415
- const result = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data) // TODO use the return value of this EP
416
416
  if (this.moveInputCallback) {
417
- return this.moveInputCallback(data)
418
- } else {
419
- return true
420
- }
417
+ // the "oldschool" move input validator
418
+ data.moveInputCallbackResult = this.moveInputCallback(data)
419
+ }
420
+ // the new extension points
421
+ const extensionPointsResult = this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
422
+ console.log("5b0d1f", extensionPointsResult, data.moveInputCallbackResult)
423
+ // validates, when moveInputCallbackResult and extensionPointsResult are true
424
+ return !(extensionPointsResult === false || !data.moveInputCallbackResult);
421
425
  }
422
426
 
423
427
  moveInputCanceledCallback(reason, squareFrom, squareTo) {