cm-chessboard 7.6.7 → 7.6.8

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
@@ -208,7 +208,7 @@ board.enableMoveInput((event) => {
208
208
 
209
209
  The event has the following **`event.type`**:
210
210
 
211
- - **`INPUT_EVENT_TYPE.moveInputStarted`**: User started the move input, `event.square` contains the coordinates. Return true or false to validate the start square.
211
+ - **`INPUT_EVENT_TYPE.moveInputStarted`**: User started the move input, `event.squareFrom` contains the coordinates. Return true or false to validate the start square.
212
212
  - **`INPUT_EVENT_TYPE.validateMoveInput`**: User finished the move input, `event.squareFrom` and `event.squareTo` contain the coordinates. Return true or false to validate the move input.
213
213
  - **`INPUT_EVENT_TYPE.moveInputCanceled`**: User canceled the move with clicking again on the start square or clicking outside the board.
214
214
 
@@ -216,7 +216,7 @@ The event has the following **`event.type`**:
216
216
  chessboard.enableMoveInput((event) => {
217
217
  switch (event.type) {
218
218
  case INPUT_EVENT_TYPE.moveInputStarted:
219
- console.log(`moveInputStarted: ${event.square}`)
219
+ console.log(`moveInputStarted: ${event.squareFrom}`)
220
220
  // return `true`, if input is accepted/valid, `false` aborts the interaction, the piece will not move
221
221
  return true
222
222
  case INPUT_EVENT_TYPE.validateMoveInput:
@@ -30,7 +30,7 @@ function inputHandler(event) {
30
30
  window.board.removeMarkers(MARKER_TYPE.frame)
31
31
  switch (event.type) {
32
32
  case INPUT_EVENT_TYPE.moveInputStarted:
33
- log(`moveInputStarted: ${event.square}`)
33
+ log(`moveInputStarted: ${event.squareFrom}`)
34
34
  return true
35
35
  case INPUT_EVENT_TYPE.validateMoveInput:
36
36
  log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
@@ -62,7 +62,7 @@ function inputHandler(event) {
62
62
  // console.log(event)
63
63
  switch (event.type) {
64
64
  case INPUT_EVENT_TYPE.moveInputStarted:
65
- log(`moveInputStarted: ${event.square}`)
65
+ log(`moveInputStarted: ${event.squareFrom}`)
66
66
  return true
67
67
  case INPUT_EVENT_TYPE.validateMoveInput:
68
68
  log(`validateMoveInput: ${event.squareFrom}-${event.squareTo}`)
@@ -40,11 +40,12 @@
40
40
 
41
41
  function inputHandler(event) {
42
42
  console.log("inputHandler", event)
43
- console.log("fen", event.chessboard.getPosition())
44
- event.chessboard.removeMarkers(MARKER_TYPE.dot)
45
- event.chessboard.removeMarkers(MARKER_TYPE.bevel)
43
+ if(event.type !== INPUT_EVENT_TYPE.moveInputFinished) {
44
+ event.chessboard.removeMarkers(MARKER_TYPE.dot)
45
+ event.chessboard.removeMarkers(MARKER_TYPE.bevel)
46
+ }
46
47
  if (event.type === INPUT_EVENT_TYPE.moveInputStarted) {
47
- const moves = chess.moves({square: event.square, verbose: true})
48
+ const moves = chess.moves({square: event.squareFrom, verbose: true})
48
49
  for (const move of moves) { // draw dots on possible squares
49
50
  if (move.promotion && move.promotion !== "q") {
50
51
  continue
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "7.6.7",
3
+ "version": "7.6.8",
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/lib/Svg.js CHANGED
@@ -28,10 +28,10 @@ export class Svg {
28
28
  * @param parent
29
29
  * @param name
30
30
  * @param attributes
31
- * @param sibling
31
+ * @param sibling // TODO remove this parameter (2023-05-22)
32
32
  * @returns {Element}
33
33
  */
34
- static addElement(parent, name, attributes, sibling = undefined) {
34
+ static addElement(parent, name, attributes = {}, sibling = undefined) {
35
35
  let element = document.createElementNS(SVG_NAMESPACE, name)
36
36
  if (name === "use") {
37
37
  attributes["xlink:href"] = attributes["href"] // fix for safari
@@ -335,6 +335,7 @@ export class ChessboardView {
335
335
  const data = {
336
336
  chessboard: this.chessboard,
337
337
  type: INPUT_EVENT_TYPE.moveInputStarted,
338
+ square: square, /** square is deprecated, use squareFrom (2023-05-22) */
338
339
  squareFrom: square,
339
340
  piece: this.chessboard.getPiece(square)
340
341
  }