cm-chessboard 8.5.4 → 8.5.6

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.
@@ -49,21 +49,12 @@
49
49
  return // ignore this event
50
50
  }
51
51
  if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
52
- event.chessboard.removeMarkers(MARKER_TYPE.dot)
53
- event.chessboard.removeMarkers(MARKER_TYPE.bevel)
52
+ event.chessboard.removeLegalMovesMarkers()
54
53
  }
55
54
  if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
55
+ // mark legal moves
56
56
  const moves = chess.moves({square: event.squareFrom, verbose: true})
57
- for (const move of moves) { // draw dots on possible squares
58
- if (move.promotion && move.promotion !== "q") {
59
- continue
60
- }
61
- if (event.chessboard.getPiece(move.to)) {
62
- event.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
63
- } else {
64
- event.chessboard.addMarker(MARKER_TYPE.dot, move.to)
65
- }
66
- }
57
+ event.chessboard.addLegalMovesMarkers(moves)
67
58
  return moves.length > 0
68
59
  } else if (event.type === INPUT_EVENT_TYPE.validateMoveInput) {
69
60
  const move = {from: event.squareFrom, to: event.squareTo, promotion: event.promotion}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.5.4",
3
+ "version": "8.5.6",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
package/src/Chessboard.js CHANGED
@@ -147,8 +147,12 @@ export class Chessboard {
147
147
  this.view.disableMoveInput()
148
148
  }
149
149
 
150
+ isMoveInputEnabled() {
151
+ return this.state.inputWhiteEnabled || this.state.inputBlackEnabled
152
+ }
153
+
150
154
  addExtension(extensionClass, props) {
151
- if(this.getExtension(extensionClass)) {
155
+ if (this.getExtension(extensionClass)) {
152
156
  throw Error("extension \"" + extensionClass.name + "\" already added")
153
157
  }
154
158
  this.extensions.push(new extensionClass(this, props))
@@ -39,6 +39,8 @@ export class Markers extends Extension {
39
39
  chessboard.addMarker = this.addMarker.bind(this)
40
40
  chessboard.getMarkers = this.getMarkers.bind(this)
41
41
  chessboard.removeMarkers = this.removeMarkers.bind(this)
42
+ chessboard.addLegalMovesMarkers = this.addLegalMovesMarkers.bind(this)
43
+ chessboard.removeLegalMovesMarkers = this.removeLegalMovesMarkers.bind(this)
42
44
  this.markerGroupDown = Svg.addElement(chessboard.view.markersLayer, "g", {class: "markers"})
43
45
  this.markerGroupUp = Svg.addElement(chessboard.view.markersTopLayer, "g", {class: "markers"})
44
46
  this.markers = []
@@ -82,6 +84,24 @@ export class Markers extends Extension {
82
84
  )
83
85
  }
84
86
 
87
+ addLegalMovesMarkers(moves) {
88
+ for (const move of moves) {
89
+ if (move.promotion && move.promotion !== "q") {
90
+ continue
91
+ }
92
+ if (this.chessboard.getPiece(move.to)) {
93
+ this.chessboard.addMarker(MARKER_TYPE.bevel, move.to)
94
+ } else {
95
+ this.chessboard.addMarker(MARKER_TYPE.dot, move.to)
96
+ }
97
+ }
98
+ }
99
+
100
+ removeLegalMovesMarkers() {
101
+ this.chessboard.removeMarkers(MARKER_TYPE.bevel)
102
+ this.chessboard.removeMarkers(MARKER_TYPE.dot)
103
+ }
104
+
85
105
  drawMarker(marker) {
86
106
  let markerGroup
87
107
  if (marker.type.position === 'above') {