cm-chessboard 8.12.12 → 8.12.15
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.
|
@@ -8,7 +8,19 @@
|
|
|
8
8
|
"Bash(npm publish:*)",
|
|
9
9
|
"Bash(gh search:*)",
|
|
10
10
|
"Skill(schedule)",
|
|
11
|
-
"Bash(npm whoami *)"
|
|
11
|
+
"Bash(npm whoami *)",
|
|
12
|
+
"Bash(cat)",
|
|
13
|
+
"Bash(rm /tmp/pr165-comment.md)",
|
|
14
|
+
"Read(//Users/shaack/Development/repositories/MyProjects/**)",
|
|
15
|
+
"Bash(gh release *)",
|
|
16
|
+
"Bash(gh api *)",
|
|
17
|
+
"Bash(pkill -f \"http.server 8731\")",
|
|
18
|
+
"Bash(rm -f /tmp/bis-server.log)",
|
|
19
|
+
"Bash(rm /tmp/issue56.md)",
|
|
20
|
+
"Bash([ -d \"$d\" ])",
|
|
21
|
+
"Bash(pkill -f \"http.server 8732\")",
|
|
22
|
+
"Bash(rm -f /tmp/bsm-server.log)",
|
|
23
|
+
"Bash(rm -f c26.md c19.md)"
|
|
12
24
|
],
|
|
13
25
|
"deny": [],
|
|
14
26
|
"ask": []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cm-chessboard",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.15",
|
|
4
4
|
"description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chess",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/shaack/cm-chessboard#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"teevi": "^2.
|
|
32
|
+
"teevi": "^2.4.1"
|
|
33
33
|
}
|
|
34
34
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Combines Arrows and Markers to draw/toggle arrows and circle markers with right-click + modifiers.
|
|
4
4
|
* Colors:
|
|
5
5
|
* - Green: Right-click
|
|
6
|
-
* - Blue: Alt + Right-click
|
|
6
|
+
* - Blue: Alt, Cmd or AltGr + Right-click
|
|
7
7
|
* - Red: Shift + Right-click
|
|
8
8
|
* - Orange: Shift + Alt + Right-click
|
|
9
9
|
* Redrawing the same arrow or marker removes it.
|
|
@@ -65,8 +65,8 @@ export class RightClickAnnotator extends Extension {
|
|
|
65
65
|
})
|
|
66
66
|
|
|
67
67
|
// register public API
|
|
68
|
-
this.chessboard.getAnnotations = this.getAnnotations.bind(this
|
|
69
|
-
this.chessboard.setAnnotations = this.setAnnotations.bind(this
|
|
68
|
+
this.chessboard.getAnnotations = this.getAnnotations.bind(this)
|
|
69
|
+
this.chessboard.setAnnotations = this.setAnnotations.bind(this)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
getAnnotations() {
|
|
@@ -120,7 +120,7 @@ export class RightClickAnnotator extends Extension {
|
|
|
120
120
|
this.dragStart = {
|
|
121
121
|
square,
|
|
122
122
|
modifiers: {
|
|
123
|
-
alt: event.altKey,
|
|
123
|
+
alt: event.altKey || event.metaKey || (event.getModifierState && event.getModifierState("AltGraph")),
|
|
124
124
|
shift: event.shiftKey || event.ctrlKey
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -23,7 +23,8 @@ export const MOVE_CANCELED_REASON = {
|
|
|
23
23
|
secondaryClick: "secondaryClick", // right click while moving
|
|
24
24
|
movedOutOfBoard: "movedOutOfBoard",
|
|
25
25
|
draggedBack: "draggedBack", // dragged to the start square
|
|
26
|
-
clickedAnotherPiece: "clickedAnotherPiece" // of the same color
|
|
26
|
+
clickedAnotherPiece: "clickedAnotherPiece", // of the same color
|
|
27
|
+
touchCanceled: "touchCanceled"
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
const DRAG_THRESHOLD = 4
|
|
@@ -90,6 +91,10 @@ export class VisualMoveInput {
|
|
|
90
91
|
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
91
92
|
this.pointerUpListener = null
|
|
92
93
|
}
|
|
94
|
+
if (this.pointerCancelListener) {
|
|
95
|
+
removeEventListener(this.pointerCancelListener.type, this.pointerCancelListener)
|
|
96
|
+
this.pointerCancelListener = null
|
|
97
|
+
}
|
|
93
98
|
this.fromSquare = params.square
|
|
94
99
|
this.toSquare = null
|
|
95
100
|
this.movedPiece = params.piece
|
|
@@ -109,6 +114,9 @@ export class VisualMoveInput {
|
|
|
109
114
|
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
110
115
|
this.pointerUpListener.type = "touchend"
|
|
111
116
|
addEventListener("touchend", this.pointerUpListener)
|
|
117
|
+
this.pointerCancelListener = this.onPointerCancel.bind(this)
|
|
118
|
+
this.pointerCancelListener.type = "touchcancel"
|
|
119
|
+
addEventListener("touchcancel", this.pointerCancelListener)
|
|
112
120
|
} else {
|
|
113
121
|
throw Error("4b74af")
|
|
114
122
|
}
|
|
@@ -195,6 +203,10 @@ export class VisualMoveInput {
|
|
|
195
203
|
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
196
204
|
this.pointerUpListener = null
|
|
197
205
|
}
|
|
206
|
+
if (this.pointerCancelListener) {
|
|
207
|
+
removeEventListener(this.pointerCancelListener.type, this.pointerCancelListener)
|
|
208
|
+
this.pointerCancelListener = null
|
|
209
|
+
}
|
|
198
210
|
if (this.contextMenuListener) {
|
|
199
211
|
removeEventListener("contextmenu", this.contextMenuListener)
|
|
200
212
|
this.contextMenuListener = null
|
|
@@ -401,6 +413,13 @@ export class VisualMoveInput {
|
|
|
401
413
|
}
|
|
402
414
|
}
|
|
403
415
|
|
|
416
|
+
onPointerCancel() {
|
|
417
|
+
this.view.redrawPieces()
|
|
418
|
+
const moveStartSquare = this.fromSquare
|
|
419
|
+
this.setMoveInputState(MOVE_INPUT_STATE.reset)
|
|
420
|
+
this.moveInputCanceledCallback(moveStartSquare, null, MOVE_CANCELED_REASON.touchCanceled)
|
|
421
|
+
}
|
|
422
|
+
|
|
404
423
|
onContextMenu(e) { // while moving
|
|
405
424
|
e.preventDefault()
|
|
406
425
|
this.view.redrawPieces()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Author and copyright: Stefan Haack (https://shaack.com)
|
|
3
|
+
* Repository: https://github.com/shaack/cm-chessboard
|
|
4
|
+
* License: MIT, see file 'LICENSE'
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {describe, it, assert} from "../node_modules/teevi/src/teevi.js"
|
|
8
|
+
import {Chessboard} from "../src/Chessboard.js"
|
|
9
|
+
import {FEN} from "../src/model/Position.js"
|
|
10
|
+
|
|
11
|
+
const STATE_WAIT_FOR_INPUT_START = "waitForInputStart"
|
|
12
|
+
const STATE_PIECE_CLICKED_THRESHOLD = "pieceClickedThreshold"
|
|
13
|
+
|
|
14
|
+
describe("TestVisualMoveInput", () => {
|
|
15
|
+
|
|
16
|
+
it("should reset move input state on touchcancel", async () => {
|
|
17
|
+
const chessboard = new Chessboard(document.getElementById("TestBoard"), {
|
|
18
|
+
assetsUrl: "../assets/",
|
|
19
|
+
position: FEN.start
|
|
20
|
+
})
|
|
21
|
+
chessboard.enableMoveInput(() => true)
|
|
22
|
+
const visualMoveInput = chessboard.view.visualMoveInput
|
|
23
|
+
|
|
24
|
+
visualMoveInput.onPointerDown({
|
|
25
|
+
type: "touchstart",
|
|
26
|
+
target: {getAttribute: (name) => (name === "data-square" ? "e2" : null)},
|
|
27
|
+
touches: [{clientX: 100, clientY: 100}],
|
|
28
|
+
preventDefault: () => {}
|
|
29
|
+
})
|
|
30
|
+
assert.equal(visualMoveInput.moveInputState, STATE_PIECE_CLICKED_THRESHOLD)
|
|
31
|
+
|
|
32
|
+
window.dispatchEvent(new Event("touchcancel"))
|
|
33
|
+
|
|
34
|
+
assert.equal(visualMoveInput.moveInputState, STATE_WAIT_FOR_INPUT_START)
|
|
35
|
+
|
|
36
|
+
await new Promise((resolve) => setTimeout(resolve))
|
|
37
|
+
chessboard.destroy()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
})
|