cm-chessboard 8.3.3 → 8.4.0

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
@@ -87,29 +87,16 @@ To enable the user to move the pieces, you have to enable the move input.
87
87
  const board = new Chessboard(document.getElementById("board"), {
88
88
  position: FEN.start,
89
89
  assetsUrl: "../assets/",
90
- extensions: [{class: Markers}] // Looks better with markers
90
+ extensions: [{class: Markers}] // Looks better with markers. (Don't forget to also include the CSS for the markers)
91
91
  })
92
92
 
93
93
  board.enableMoveInput(inputHandler) // This enables the move input
94
94
 
95
95
  function inputHandler(event) {
96
96
  console.log(event)
97
- switch (event.type) {
98
- case INPUT_EVENT_TYPE.moveInputStarted:
99
- log(`moveInputStarted: ${event.squareFrom}`)
100
- return true // false cancels move
101
- case INPUT_EVENT_TYPE.validateMoveInput:
102
- log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
103
- return true // false cancels move
104
- case INPUT_EVENT_TYPE.moveInputCanceled:
105
- log(`moveInputCanceled`)
106
- break
107
- case INPUT_EVENT_TYPE.moveInputFinished:
108
- log(`moveInputFinished`)
109
- break
110
- case INPUT_EVENT_TYPE.movingOverSquare:
111
- log(`movingOverSquare: ${event.square}`)
112
- break
97
+ if(event.type === INPUT_EVENT_TYPE.moveInputStarted ||
98
+ event.type === INPUT_EVENT_TYPE.validateMoveInput) {
99
+ return true // false cancels move
113
100
  }
114
101
  }
115
102
  ```
@@ -223,30 +210,30 @@ The event has the following **`event.type`**:
223
210
  contain the coordinates. Return `true` or `false` to validate the move. `false` cancels the move.
224
211
  - **`INPUT_EVENT_TYPE.moveInputCanceled`**: The user canceled the move with clicking again on the start square, clicking
225
212
  outside the board or right click.
226
- - **`INPUT_EVENT_TYPE.moveInputFinished`**: Fired after the move was made.
227
- - **`INPUT_EVENT_TYPE.movingOverSquare`**: Fired, when the user moves the piece over a square. `event.square` contains
213
+ - **`INPUT_EVENT_TYPE.moveInputFinished`**: Fired after the move was made, also when canceled.
214
+ - **`INPUT_EVENT_TYPE.movingOverSquare`**: Fired, when the user moves the piece over a square. `event.squareTo` contains
228
215
  the coordinates.
229
216
 
230
217
  ```javascript
231
218
  chessboard.enableMoveInput((event) => {
232
219
  console.log("move input", event)
233
- switch (event.type) {
234
- case INPUT_EVENT_TYPE.moveInputStarted:
235
- log(`moveInputStarted: ${event.squareFrom}`)
236
- return true // false cancels move
237
- case INPUT_EVENT_TYPE.validateMoveInput:
238
- log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
239
- return true // false cancels move
240
- case INPUT_EVENT_TYPE.moveInputCanceled:
241
- log(`moveInputCanceled`)
242
- break
243
- case INPUT_EVENT_TYPE.moveInputFinished:
244
- log(`moveInputFinished`)
245
- break
246
- case INPUT_EVENT_TYPE.movingOverSquare:
247
- log(`movingOverSquare: ${event.square}`)
248
- break
249
- }
220
+ switch (event.type) {
221
+ case INPUT_EVENT_TYPE.moveInputStarted:
222
+ console.log(`moveInputStarted: ${event.squareFrom}`)
223
+ return true // false cancels move
224
+ case INPUT_EVENT_TYPE.validateMoveInput:
225
+ console.log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
226
+ return true // false cancels move
227
+ case INPUT_EVENT_TYPE.moveInputCanceled:
228
+ console.log(`moveInputCanceled`)
229
+ break
230
+ case INPUT_EVENT_TYPE.moveInputFinished:
231
+ console.log(`moveInputFinished`)
232
+ break
233
+ case INPUT_EVENT_TYPE.movingOverSquare:
234
+ console.log(`movingOverSquare: ${event.squareTo}`)
235
+ break
236
+ }
250
237
  }, COLOR.white)
251
238
  ```
252
239
 
@@ -27,16 +27,22 @@ const board = new Chessboard(document.getElementById("board"), {
27
27
  board.enableMoveInput(inputHandler)
28
28
  function inputHandler(event) {
29
29
  console.log(event)
30
- window.board.removeMarkers(MARKER_TYPE.frame)
31
30
  switch (event.type) {
32
31
  case INPUT_EVENT_TYPE.moveInputStarted:
33
32
  log(`moveInputStarted: ${event.squareFrom}`)
34
- return true
33
+ return true // false cancels move
35
34
  case INPUT_EVENT_TYPE.validateMoveInput:
36
35
  log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
37
- return true
36
+ return true // false cancels move
38
37
  case INPUT_EVENT_TYPE.moveInputCanceled:
39
38
  log(`moveInputCanceled`)
39
+ break
40
+ case INPUT_EVENT_TYPE.moveInputFinished:
41
+ log(`moveInputFinished`)
42
+ break
43
+ case INPUT_EVENT_TYPE.movingOverSquare:
44
+ log(`movingOverSquare: ${event.squareTo}`)
45
+ break
40
46
  }
41
47
  }
42
48
  </pre>
@@ -63,12 +69,19 @@ function inputHandler(event) {
63
69
  switch (event.type) {
64
70
  case INPUT_EVENT_TYPE.moveInputStarted:
65
71
  log(`moveInputStarted: ${event.squareFrom}`)
66
- return true
72
+ return true // false cancels move
67
73
  case INPUT_EVENT_TYPE.validateMoveInput:
68
74
  log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
69
- return true
75
+ return true // false cancels move
70
76
  case INPUT_EVENT_TYPE.moveInputCanceled:
71
77
  log(`moveInputCanceled`)
78
+ break
79
+ case INPUT_EVENT_TYPE.moveInputFinished:
80
+ log(`moveInputFinished`)
81
+ break
82
+ case INPUT_EVENT_TYPE.movingOverSquare:
83
+ log(`movingOverSquare: ${event.squareTo}`)
84
+ break
72
85
  }
73
86
  }
74
87
 
@@ -45,6 +45,9 @@
45
45
 
46
46
  function inputHandler(event) {
47
47
  console.log("inputHandler", event)
48
+ if(event.type === INPUT_EVENT_TYPE.movingOverSquare) {
49
+ return // ignore this event
50
+ }
48
51
  if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
49
52
  event.chessboard.removeMarkers(MARKER_TYPE.dot)
50
53
  event.chessboard.removeMarkers(MARKER_TYPE.bevel)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.3.3",
3
+ "version": "8.4.0",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -12,7 +12,7 @@ export const EXTENSION_POINT = {
12
12
  beforeRedrawBoard: "beforeRedrawBoard", // called before redrawing the board
13
13
  afterRedrawBoard: "afterRedrawBoard", // called after redrawing the board
14
14
  redrawBoard: "redrawBoard", // called after redrawing the board, DEPRECATED, use afterRedrawBoard 2023-09-18
15
- animation: "animation", // called on animation start, end and on every animation frame
15
+ animation: "animation", // called on animation start, end, and on every animation frame
16
16
  destroy: "destroy" // called, before the board is destroyed
17
17
  }
18
18
 
@@ -23,7 +23,7 @@ export class Extension {
23
23
  }
24
24
 
25
25
  registerExtensionPoint(name, callback) {
26
- if(name === EXTENSION_POINT.redrawBoard) {
26
+ if(name === EXTENSION_POINT.redrawBoard) { // deprecated 2023-09-18
27
27
  console.warn("EXTENSION_POINT.redrawBoard is deprecated, use EXTENSION_POINT.afterRedrawBoard")
28
28
  name = EXTENSION_POINT.afterRedrawBoard
29
29
  }
@@ -352,6 +352,9 @@ export class ChessboardView {
352
352
  squareTo: squareTo,
353
353
  piece: this.chessboard.getPiece(squareFrom)
354
354
  }
355
+ if (this.chessboard.state.moveInputCallback) {
356
+ data.moveInputCallbackResult = this.chessboard.state.moveInputCallback(data)
357
+ }
355
358
  this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.moveInput, data)
356
359
  }
357
360