cm-chessboard 8.15.2 → 8.15.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/package.json
CHANGED
|
@@ -190,6 +190,9 @@ export class PromotionDialog extends Extension {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
if (piece) {
|
|
193
|
+
// Without this iOS fires compatibility mousedown/mouseup at the tap
|
|
194
|
+
// position after the dialog closed, they select the piece below it
|
|
195
|
+
event.preventDefault()
|
|
193
196
|
this.selectPiece(piece)
|
|
194
197
|
} else {
|
|
195
198
|
this.promotionDialogOnCancel(event)
|
|
@@ -86,50 +86,11 @@ export class VisualMoveInput {
|
|
|
86
86
|
if (MOVE_INPUT_STATE.waitForInputStart !== prevState && MOVE_INPUT_STATE.clickTo !== prevState) {
|
|
87
87
|
throw new Error("moveInputState")
|
|
88
88
|
}
|
|
89
|
-
if (this.pointerMoveListener) {
|
|
90
|
-
removeEventListener(this.pointerMoveListener.type, this.pointerMoveListener)
|
|
91
|
-
this.pointerMoveListener = null
|
|
92
|
-
}
|
|
93
|
-
if (this.pointerUpListener) {
|
|
94
|
-
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
95
|
-
this.pointerUpListener = null
|
|
96
|
-
}
|
|
97
|
-
if (this.pointerCancelListener) {
|
|
98
|
-
removeEventListener(this.pointerCancelListener.type, this.pointerCancelListener)
|
|
99
|
-
this.pointerCancelListener = null
|
|
100
|
-
}
|
|
101
89
|
this.fromSquare = params.square
|
|
102
90
|
this.toSquare = null
|
|
103
91
|
this.movedPiece = params.piece
|
|
104
92
|
this.startPoint = params.point
|
|
105
|
-
|
|
106
|
-
if (params.type === "mousedown") {
|
|
107
|
-
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
108
|
-
this.pointerMoveListener.type = "mousemove"
|
|
109
|
-
addEventListener("mousemove", this.pointerMoveListener)
|
|
110
|
-
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
111
|
-
this.pointerUpListener.type = "mouseup"
|
|
112
|
-
addEventListener("mouseup", this.pointerUpListener)
|
|
113
|
-
} else if (params.type === "touchstart") {
|
|
114
|
-
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
115
|
-
this.pointerMoveListener.type = "touchmove"
|
|
116
|
-
addEventListener("touchmove", this.pointerMoveListener)
|
|
117
|
-
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
118
|
-
this.pointerUpListener.type = "touchend"
|
|
119
|
-
addEventListener("touchend", this.pointerUpListener)
|
|
120
|
-
this.pointerCancelListener = this.onPointerCancel.bind(this)
|
|
121
|
-
this.pointerCancelListener.type = "touchcancel"
|
|
122
|
-
addEventListener("touchcancel", this.pointerCancelListener)
|
|
123
|
-
} else {
|
|
124
|
-
throw Error("4b74af")
|
|
125
|
-
}
|
|
126
|
-
if (!this.contextMenuListener) {
|
|
127
|
-
this.contextMenuListener = this.onContextMenu.bind(this)
|
|
128
|
-
this.chessboard.view.svg.addEventListener("contextmenu", this.contextMenuListener)
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
throw Error("94ad0c")
|
|
132
|
-
}
|
|
93
|
+
this.setPointerListeners(params.type)
|
|
133
94
|
break
|
|
134
95
|
|
|
135
96
|
case MOVE_INPUT_STATE.clickTo:
|
|
@@ -147,6 +108,11 @@ export class VisualMoveInput {
|
|
|
147
108
|
throw new Error("moveInputState")
|
|
148
109
|
}
|
|
149
110
|
this.startPoint = params.point
|
|
111
|
+
// The piece may have been selected with another input type than the one
|
|
112
|
+
// continuing now, e.g. by the compatibility mouse events iOS fires after a
|
|
113
|
+
// tap, followed by a finger drag. Listen to the current type, otherwise the
|
|
114
|
+
// drag is never seen and the input hangs in this state.
|
|
115
|
+
this.setPointerListeners(params.type)
|
|
150
116
|
break
|
|
151
117
|
|
|
152
118
|
case MOVE_INPUT_STATE.dragTo:
|
|
@@ -204,18 +170,7 @@ export class VisualMoveInput {
|
|
|
204
170
|
Svg.removeElement(this.draggablePiece)
|
|
205
171
|
this.draggablePiece = null
|
|
206
172
|
}
|
|
207
|
-
|
|
208
|
-
removeEventListener(this.pointerMoveListener.type, this.pointerMoveListener)
|
|
209
|
-
this.pointerMoveListener = null
|
|
210
|
-
}
|
|
211
|
-
if (this.pointerUpListener) {
|
|
212
|
-
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
213
|
-
this.pointerUpListener = null
|
|
214
|
-
}
|
|
215
|
-
if (this.pointerCancelListener) {
|
|
216
|
-
removeEventListener(this.pointerCancelListener.type, this.pointerCancelListener)
|
|
217
|
-
this.pointerCancelListener = null
|
|
218
|
-
}
|
|
173
|
+
this.removePointerListeners()
|
|
219
174
|
if (this.contextMenuListener) {
|
|
220
175
|
this.chessboard.view.svg.removeEventListener("contextmenu", this.contextMenuListener)
|
|
221
176
|
this.contextMenuListener = null
|
|
@@ -233,6 +188,51 @@ export class VisualMoveInput {
|
|
|
233
188
|
}
|
|
234
189
|
}
|
|
235
190
|
|
|
191
|
+
// (Re)install the move/up/cancel listeners of the input type that started the
|
|
192
|
+
// current step ("mousedown" or "touchstart")
|
|
193
|
+
setPointerListeners(type) {
|
|
194
|
+
this.removePointerListeners()
|
|
195
|
+
if (type === "mousedown") {
|
|
196
|
+
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
197
|
+
this.pointerMoveListener.type = "mousemove"
|
|
198
|
+
addEventListener("mousemove", this.pointerMoveListener)
|
|
199
|
+
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
200
|
+
this.pointerUpListener.type = "mouseup"
|
|
201
|
+
addEventListener("mouseup", this.pointerUpListener)
|
|
202
|
+
} else if (type === "touchstart") {
|
|
203
|
+
this.pointerMoveListener = this.onPointerMove.bind(this)
|
|
204
|
+
this.pointerMoveListener.type = "touchmove"
|
|
205
|
+
addEventListener("touchmove", this.pointerMoveListener)
|
|
206
|
+
this.pointerUpListener = this.onPointerUp.bind(this)
|
|
207
|
+
this.pointerUpListener.type = "touchend"
|
|
208
|
+
addEventListener("touchend", this.pointerUpListener)
|
|
209
|
+
this.pointerCancelListener = this.onPointerCancel.bind(this)
|
|
210
|
+
this.pointerCancelListener.type = "touchcancel"
|
|
211
|
+
addEventListener("touchcancel", this.pointerCancelListener)
|
|
212
|
+
} else {
|
|
213
|
+
throw Error("4b74af")
|
|
214
|
+
}
|
|
215
|
+
if (!this.contextMenuListener) {
|
|
216
|
+
this.contextMenuListener = this.onContextMenu.bind(this)
|
|
217
|
+
this.chessboard.view.svg.addEventListener("contextmenu", this.contextMenuListener)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
removePointerListeners() {
|
|
222
|
+
if (this.pointerMoveListener) {
|
|
223
|
+
removeEventListener(this.pointerMoveListener.type, this.pointerMoveListener)
|
|
224
|
+
this.pointerMoveListener = null
|
|
225
|
+
}
|
|
226
|
+
if (this.pointerUpListener) {
|
|
227
|
+
removeEventListener(this.pointerUpListener.type, this.pointerUpListener)
|
|
228
|
+
this.pointerUpListener = null
|
|
229
|
+
}
|
|
230
|
+
if (this.pointerCancelListener) {
|
|
231
|
+
removeEventListener(this.pointerCancelListener.type, this.pointerCancelListener)
|
|
232
|
+
this.pointerCancelListener = null
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
236
|
createDraggablePiece(pieceName) {
|
|
237
237
|
// maybe I should use the existing piece from the board and don't create a new one
|
|
238
238
|
if (this.draggablePiece) {
|