cm-chessboard 7.7.3 → 7.7.5
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 +15 -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,8 @@ export class VisualMoveInput {
|
|
|
41
41
|
if (result) {
|
|
42
42
|
this.chessboard.state.moveInputProcess = Utils.createTask()
|
|
43
43
|
this.chessboard.state.moveInputProcess.then((result) => {
|
|
44
|
-
if(this.moveInputState === MOVE_INPUT_STATE.waitForInputStart
|
|
44
|
+
if (this.moveInputState === MOVE_INPUT_STATE.waitForInputStart ||
|
|
45
|
+
this.moveInputState === MOVE_INPUT_STATE.moveDone) {
|
|
45
46
|
view.moveInputFinishedCallback(this.fromSquare, this.toSquare, result)
|
|
46
47
|
}
|
|
47
48
|
})
|
|
@@ -109,7 +110,7 @@ export class VisualMoveInput {
|
|
|
109
110
|
} else {
|
|
110
111
|
throw Error("4b74af")
|
|
111
112
|
}
|
|
112
|
-
if(!this.contextMenuListener) {
|
|
113
|
+
if (!this.contextMenuListener) {
|
|
113
114
|
this.contextMenuListener = this.onContextMenu.bind(this)
|
|
114
115
|
this.chessboard.view.svg.addEventListener("contextmenu", this.contextMenuListener)
|
|
115
116
|
}
|
|
@@ -323,7 +324,10 @@ export class VisualMoveInput {
|
|
|
323
324
|
if (this.moveInputState === MOVE_INPUT_STATE.pieceClickedThreshold || this.moveInputState === MOVE_INPUT_STATE.secondClickThreshold) {
|
|
324
325
|
if (Math.abs(this.startPoint.x - clientX) > DRAG_THRESHOLD || Math.abs(this.startPoint.y - clientY) > DRAG_THRESHOLD) {
|
|
325
326
|
if (this.moveInputState === MOVE_INPUT_STATE.secondClickThreshold) {
|
|
326
|
-
this.setMoveInputState(MOVE_INPUT_STATE.clickDragTo, {
|
|
327
|
+
this.setMoveInputState(MOVE_INPUT_STATE.clickDragTo, {
|
|
328
|
+
square: this.fromSquare,
|
|
329
|
+
piece: this.movedPiece
|
|
330
|
+
})
|
|
327
331
|
} else {
|
|
328
332
|
this.setMoveInputState(MOVE_INPUT_STATE.dragTo, {square: this.fromSquare, piece: this.movedPiece})
|
|
329
333
|
}
|