cm-chessboard 7.7.2 → 7.7.4
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/examples/enable-input.html +1 -1
- package/package.json +1 -1
- package/src/Chessboard.js +1 -0
- package/src/view/VisualMoveInput.js +17 -11
|
@@ -59,7 +59,7 @@ function inputHandler(event) {
|
|
|
59
59
|
window.board.enableMoveInput(inputHandler)
|
|
60
60
|
|
|
61
61
|
function inputHandler(event) {
|
|
62
|
-
|
|
62
|
+
console.log(event)
|
|
63
63
|
switch (event.type) {
|
|
64
64
|
case INPUT_EVENT_TYPE.moveInputStarted:
|
|
65
65
|
log(`moveInputStarted: ${event.squareFrom}`)
|
package/package.json
CHANGED
package/src/Chessboard.js
CHANGED
|
@@ -8,14 +8,14 @@ import {Svg} from "../lib/Svg.js"
|
|
|
8
8
|
import {Utils} from "../lib/Utils.js"
|
|
9
9
|
|
|
10
10
|
const MOVE_INPUT_STATE = {
|
|
11
|
-
waitForInputStart:
|
|
12
|
-
pieceClickedThreshold:
|
|
13
|
-
clickTo:
|
|
14
|
-
secondClickThreshold:
|
|
15
|
-
dragTo:
|
|
16
|
-
clickDragTo:
|
|
17
|
-
moveDone:
|
|
18
|
-
reset:
|
|
11
|
+
waitForInputStart: "waitForInputStart",
|
|
12
|
+
pieceClickedThreshold: "pieceClickedThreshold",
|
|
13
|
+
clickTo: "clickTo",
|
|
14
|
+
secondClickThreshold: "secondClickThreshold",
|
|
15
|
+
dragTo: "dragTo",
|
|
16
|
+
clickDragTo: "clickDragTo",
|
|
17
|
+
moveDone: "moveDone",
|
|
18
|
+
reset: "reset"
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const MOVE_CANCELED_REASON = {
|
|
@@ -41,7 +41,10 @@ export class VisualMoveInput {
|
|
|
41
41
|
if (result) {
|
|
42
42
|
this.chessboard.state.moveInputProcess = Utils.createTask()
|
|
43
43
|
this.chessboard.state.moveInputProcess.then((result) => {
|
|
44
|
-
|
|
44
|
+
if (this.moveInputState === MOVE_INPUT_STATE.waitForInputStart ||
|
|
45
|
+
this.moveInputState === MOVE_INPUT_STATE.moveDone) {
|
|
46
|
+
view.moveInputFinishedCallback(this.fromSquare, this.toSquare, result)
|
|
47
|
+
}
|
|
45
48
|
})
|
|
46
49
|
}
|
|
47
50
|
return result
|
|
@@ -107,7 +110,7 @@ export class VisualMoveInput {
|
|
|
107
110
|
} else {
|
|
108
111
|
throw Error("4b74af")
|
|
109
112
|
}
|
|
110
|
-
if(!this.contextMenuListener) {
|
|
113
|
+
if (!this.contextMenuListener) {
|
|
111
114
|
this.contextMenuListener = this.onContextMenu.bind(this)
|
|
112
115
|
this.chessboard.view.svg.addEventListener("contextmenu", this.contextMenuListener)
|
|
113
116
|
}
|
|
@@ -321,7 +324,10 @@ export class VisualMoveInput {
|
|
|
321
324
|
if (this.moveInputState === MOVE_INPUT_STATE.pieceClickedThreshold || this.moveInputState === MOVE_INPUT_STATE.secondClickThreshold) {
|
|
322
325
|
if (Math.abs(this.startPoint.x - clientX) > DRAG_THRESHOLD || Math.abs(this.startPoint.y - clientY) > DRAG_THRESHOLD) {
|
|
323
326
|
if (this.moveInputState === MOVE_INPUT_STATE.secondClickThreshold) {
|
|
324
|
-
this.setMoveInputState(MOVE_INPUT_STATE.clickDragTo, {
|
|
327
|
+
this.setMoveInputState(MOVE_INPUT_STATE.clickDragTo, {
|
|
328
|
+
square: this.fromSquare,
|
|
329
|
+
piece: this.movedPiece
|
|
330
|
+
})
|
|
325
331
|
} else {
|
|
326
332
|
this.setMoveInputState(MOVE_INPUT_STATE.dragTo, {square: this.fromSquare, piece: this.movedPiece})
|
|
327
333
|
}
|