cm-chessboard 7.10.1 → 7.11.0
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.
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<script type="module">
|
|
20
20
|
import {INPUT_EVENT_TYPE, COLOR, Chessboard, BORDER_TYPE} from "../src/Chessboard.js"
|
|
21
21
|
import {MARKER_TYPE, Markers} from "../src/extensions/markers/Markers.js"
|
|
22
|
-
import {PromotionDialog} from "../src/extensions/promotion-dialog/PromotionDialog.js"
|
|
22
|
+
import {PROMOTION_DIALOG_RESULT_TYPE, PromotionDialog} from "../src/extensions/promotion-dialog/PromotionDialog.js"
|
|
23
23
|
import {Accessibility} from "../src/extensions/accessibility/Accessibility.js"
|
|
24
24
|
import {Chess} from "https://cdn.jsdelivr.net/npm/chess.mjs@1/src/chess.mjs/Chess.js"
|
|
25
25
|
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
if (possibleMove.promotion && possibleMove.to === event.squareTo) {
|
|
74
74
|
event.chessboard.showPromotionDialog(event.squareTo, COLOR.white, (result) => {
|
|
75
75
|
console.log("promotion result", result)
|
|
76
|
-
if (result) {
|
|
76
|
+
if (result.type === PROMOTION_DIALOG_RESULT_TYPE.pieceSelected) {
|
|
77
77
|
chess.move({from: event.squareFrom, to: event.squareTo, promotion: result.piece.charAt(1)})
|
|
78
78
|
event.chessboard.setPosition(chess.fen(), true)
|
|
79
79
|
makeEngineMove(event.chessboard)
|
package/package.json
CHANGED
|
@@ -14,6 +14,11 @@ const DISPLAY_STATE = {
|
|
|
14
14
|
shown: "shown"
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export const PROMOTION_DIALOG_RESULT_TYPE = {
|
|
18
|
+
pieceSelected: "pieceSelected",
|
|
19
|
+
canceled: "canceled"
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
export class PromotionDialog extends Extension {
|
|
18
23
|
|
|
19
24
|
/** @constructor */
|
|
@@ -138,7 +143,13 @@ export class PromotionDialog extends Extension {
|
|
|
138
143
|
promotionDialogOnClickPiece(event) {
|
|
139
144
|
if (event.button !== 2) {
|
|
140
145
|
if (event.target.dataset.piece) {
|
|
141
|
-
this.state.callback
|
|
146
|
+
if(this.state.callback) {
|
|
147
|
+
this.state.callback({
|
|
148
|
+
type: PROMOTION_DIALOG_RESULT_TYPE.pieceSelected,
|
|
149
|
+
square: this.state.dialogParams.square,
|
|
150
|
+
piece: event.target.dataset.piece
|
|
151
|
+
})
|
|
152
|
+
}
|
|
142
153
|
this.setDisplayState(DISPLAY_STATE.hidden)
|
|
143
154
|
} else {
|
|
144
155
|
this.promotionDialogOnCancel(event)
|
|
@@ -150,14 +161,18 @@ export class PromotionDialog extends Extension {
|
|
|
150
161
|
if (this.state.displayState === DISPLAY_STATE.shown) {
|
|
151
162
|
event.preventDefault()
|
|
152
163
|
this.setDisplayState(DISPLAY_STATE.hidden)
|
|
153
|
-
this.state.callback
|
|
164
|
+
if(this.state.callback) {
|
|
165
|
+
this.state.callback({type: PROMOTION_DIALOG_RESULT_TYPE.canceled})
|
|
166
|
+
}
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
contextMenu(event) {
|
|
158
171
|
event.preventDefault()
|
|
159
172
|
this.setDisplayState(DISPLAY_STATE.hidden)
|
|
160
|
-
this.state.callback
|
|
173
|
+
if(this.state.callback) {
|
|
174
|
+
this.state.callback({type: PROMOTION_DIALOG_RESULT_TYPE.canceled})
|
|
175
|
+
}
|
|
161
176
|
}
|
|
162
177
|
|
|
163
178
|
setDisplayState(displayState) {
|