cm-chessboard 4.3.4 → 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/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and **without dependencies**.
|
|
4
4
|
|
|
5
|
-
It works on desktop (current versions of Chrome, Firefox, Safari, Edge), and mobile (Android and iOS).
|
|
6
|
-
|
|
7
5
|
cm-chessboard is the main chessboard of
|
|
8
6
|
[chessmail.eu](https://www.chessmail.eu) and [chessmail.de](https://www.chessmail.de). It is also used
|
|
9
7
|
in [chess-console](https://shaack.com/projekte/chess-console/examples/load-pgn.html) and in
|
|
@@ -395,7 +393,7 @@ const chessboard = new Chessboard(document.getElementById("board"), {
|
|
|
395
393
|
[{
|
|
396
394
|
class: Accessibility,
|
|
397
395
|
props: {
|
|
398
|
-
brailleNotationInAlt: true, // show the braille notation of the
|
|
396
|
+
brailleNotationInAlt: true, // show the braille notation of the position in the alt attribute of the SVG image
|
|
399
397
|
boardAsTable: true, // display the board additionally as HTML table
|
|
400
398
|
movePieceForm: true, // display a form to move a piece (from, to, move)
|
|
401
399
|
piecesAsList: true, // display the pieces additionally as List
|
package/package.json
CHANGED
|
@@ -37,7 +37,7 @@ export class Accessibility extends Extension {
|
|
|
37
37
|
constructor(chessboard, props) {
|
|
38
38
|
super(chessboard, props)
|
|
39
39
|
this.props = {
|
|
40
|
-
brailleNotationInAlt: true, // show the braille notation of the
|
|
40
|
+
brailleNotationInAlt: true, // show the braille notation of the position in the alt attribute of the SVG image
|
|
41
41
|
boardAsTable: false, // display the board additionally as HTML table
|
|
42
42
|
movePieceForm: false, // display a form to move a piece (from, to, move)
|
|
43
43
|
piecesAsList: false, // display the pieces additionally as List
|
|
@@ -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) {
|