cm-chessboard 7.6.7 → 7.6.9
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 +2 -2
- package/examples/enable-input.html +2 -2
- package/examples/validate-moves.html +5 -4
- package/package.json +1 -1
- package/src/lib/Svg.js +2 -7
- package/src/view/ChessboardView.js +1 -0
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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.
|
|
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
package/src/lib/Svg.js
CHANGED
|
@@ -28,10 +28,9 @@ export class Svg {
|
|
|
28
28
|
* @param parent
|
|
29
29
|
* @param name
|
|
30
30
|
* @param attributes
|
|
31
|
-
* @param sibling
|
|
32
31
|
* @returns {Element}
|
|
33
32
|
*/
|
|
34
|
-
static addElement(parent, name, attributes
|
|
33
|
+
static addElement(parent, name, attributes = {}) {
|
|
35
34
|
let element = document.createElementNS(SVG_NAMESPACE, name)
|
|
36
35
|
if (name === "use") {
|
|
37
36
|
attributes["xlink:href"] = attributes["href"] // fix for safari
|
|
@@ -46,11 +45,7 @@ export class Svg {
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
parent.appendChild(element)
|
|
51
|
-
} else {
|
|
52
|
-
parent.insertBefore(element, sibling)
|
|
53
|
-
}
|
|
48
|
+
parent.appendChild(element)
|
|
54
49
|
return element
|
|
55
50
|
}
|
|
56
51
|
|
|
@@ -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
|
}
|