cm-chessboard 4.3.6 → 4.3.7
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/package.json
CHANGED
|
@@ -26,14 +26,42 @@ export const MOVE_CANCELED_REASON = {
|
|
|
26
26
|
|
|
27
27
|
const DRAG_THRESHOLD = 4
|
|
28
28
|
|
|
29
|
+
function createTask() {
|
|
30
|
+
let resolve, reject
|
|
31
|
+
const promise = new Promise(function (_resolve, _reject) {
|
|
32
|
+
resolve = _resolve
|
|
33
|
+
reject = _reject
|
|
34
|
+
})
|
|
35
|
+
promise.resolve = resolve
|
|
36
|
+
promise.reject = reject
|
|
37
|
+
return promise
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
export class VisualMoveInput {
|
|
30
41
|
|
|
31
42
|
constructor(view, moveStartCallback, moveDoneCallback, moveCanceledCallback) {
|
|
32
43
|
this.view = view
|
|
33
44
|
this.chessboard = view.chessboard
|
|
34
|
-
this.moveStartCallback =
|
|
35
|
-
|
|
36
|
-
|
|
45
|
+
this.moveStartCallback = (square) => {
|
|
46
|
+
const result = moveStartCallback(square)
|
|
47
|
+
if(result) {
|
|
48
|
+
this.chessboard.moveTask = createTask()
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
|
+
}
|
|
52
|
+
this.moveDoneCallback = (fromSquare, toSquare) => {
|
|
53
|
+
const result = moveDoneCallback(fromSquare, toSquare)
|
|
54
|
+
if(result) {
|
|
55
|
+
this.chessboard.moveTask.resolve()
|
|
56
|
+
} else {
|
|
57
|
+
this.chessboard.moveTask.reject()
|
|
58
|
+
}
|
|
59
|
+
return result
|
|
60
|
+
}
|
|
61
|
+
this.moveCanceledCallback = (reason, fromSquare, toSquare) => {
|
|
62
|
+
moveCanceledCallback(reason, fromSquare, toSquare)
|
|
63
|
+
this.chessboard.moveTask.reject()
|
|
64
|
+
}
|
|
37
65
|
this.setMoveInputState(STATE.waitForInputStart)
|
|
38
66
|
}
|
|
39
67
|
|
|
@@ -138,7 +166,7 @@ export class VisualMoveInput {
|
|
|
138
166
|
}
|
|
139
167
|
this.toSquare = params.square
|
|
140
168
|
if (this.toSquare && this.moveDoneCallback(this.fromSquare, this.toSquare)) {
|
|
141
|
-
if(prevState === STATE.clickTo) {
|
|
169
|
+
if (prevState === STATE.clickTo) {
|
|
142
170
|
this.chessboard.movePiece(this.fromSquare, this.toSquare, true).then(() => {
|
|
143
171
|
this.setMoveInputState(STATE.reset)
|
|
144
172
|
})
|
|
@@ -365,10 +393,10 @@ export class VisualMoveInput {
|
|
|
365
393
|
}
|
|
366
394
|
|
|
367
395
|
updateStartEndMarkers() {
|
|
368
|
-
if(this.chessboard.props.style.moveFromMarker) {
|
|
396
|
+
if (this.chessboard.props.style.moveFromMarker) {
|
|
369
397
|
this.chessboard.state.removeMarkers(undefined, this.chessboard.props.style.moveFromMarker)
|
|
370
398
|
}
|
|
371
|
-
if(this.chessboard.props.style.moveToMarker) {
|
|
399
|
+
if (this.chessboard.props.style.moveToMarker) {
|
|
372
400
|
this.chessboard.state.removeMarkers(undefined, this.chessboard.props.style.moveToMarker)
|
|
373
401
|
}
|
|
374
402
|
if (this.chessboard.props.style.moveFromMarker) {
|