cm-chessboard 7.6.9 → 7.6.11
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
|
@@ -451,10 +451,12 @@ you can call `chessboard.removeArrows(undefined, "e2")` and so on...
|
|
|
451
451
|
|
|
452
452
|
To get all arrows, call `chessboard.getArrows()` without parameters, as with `removeArrows(type, from, to)`.
|
|
453
453
|
|
|
454
|
-
## Usage with
|
|
454
|
+
## Usage with JS Frameworks
|
|
455
455
|
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
- Works with **Vue** out of the box
|
|
457
|
+
- Works with **Svelte** out of the box
|
|
458
|
+
- I don't use **React**, but there exists a ticket from someone who is using cm-chessboard with react: https://github.com/shaack/cm-chessboard/issues/20
|
|
459
|
+
- It should work also with **all other JS frameworks**, because cm-chessboard is written in standard ES6 and has **no dependencies**.
|
|
458
460
|
|
|
459
461
|
## Licenses
|
|
460
462
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,6 @@ import {Extension, EXTENSION_POINT} from "../../model/Extension.js"
|
|
|
7
7
|
import {COLOR, PIECE} from "../../Chessboard.js"
|
|
8
8
|
import {Svg} from "../../lib/Svg.js"
|
|
9
9
|
import {Utils} from "../../lib/Utils.js"
|
|
10
|
-
import {ANIMATION_EVENT_TYPE} from "../../view/PositionAnimationsQueue.js"
|
|
11
10
|
|
|
12
11
|
const DISPLAY_STATE = {
|
|
13
12
|
hidden: "hidden",
|
|
@@ -21,7 +20,6 @@ export class PromotionDialog extends Extension {
|
|
|
21
20
|
constructor(chessboard) {
|
|
22
21
|
super(chessboard)
|
|
23
22
|
this.registerExtensionPoint(EXTENSION_POINT.redrawBoard, this.extensionPointRedrawBoard.bind(this))
|
|
24
|
-
this.registerExtensionPoint(EXTENSION_POINT.animation, this.extensionPointAnimation.bind(this))
|
|
25
23
|
chessboard.showPromotionDialog = this.showPromotionDialog.bind(this)
|
|
26
24
|
chessboard.isPromotionDialogShown = this.isPromotionDialogShown.bind(this)
|
|
27
25
|
this.promotionDialogGroup = Svg.addElement(chessboard.view.interactiveTopLayer, "g", {class: "promotion-dialog-group"})
|
|
@@ -35,14 +33,21 @@ export class PromotionDialog extends Extension {
|
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
// public (
|
|
36
|
+
// public (chessboard.showPromotionDialog)
|
|
39
37
|
showPromotionDialog(square, color, callback) {
|
|
40
38
|
this.state.dialogParams.square = square
|
|
41
39
|
this.state.dialogParams.color = color
|
|
42
40
|
this.state.callback = callback
|
|
43
41
|
this.setDisplayState(DISPLAY_STATE.displayRequested)
|
|
42
|
+
setTimeout(() => {
|
|
43
|
+
this.chessboard.view.positionsAnimationTask.then(() => {
|
|
44
|
+
this.setDisplayState(DISPLAY_STATE.shown)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
)
|
|
44
48
|
}
|
|
45
49
|
|
|
50
|
+
// public (chessboard.isPromotionDialogShown)
|
|
46
51
|
isPromotionDialogShown() {
|
|
47
52
|
return this.state.displayState === DISPLAY_STATE.shown ||
|
|
48
53
|
this.state.displayState === DISPLAY_STATE.displayRequested
|
|
@@ -53,14 +58,6 @@ export class PromotionDialog extends Extension {
|
|
|
53
58
|
this.redrawDialog()
|
|
54
59
|
}
|
|
55
60
|
|
|
56
|
-
extensionPointAnimation(event) {
|
|
57
|
-
if (event.type === ANIMATION_EVENT_TYPE.end) {
|
|
58
|
-
if (this.state.displayState === DISPLAY_STATE.displayRequested) {
|
|
59
|
-
this.setDisplayState(DISPLAY_STATE.shown)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
61
|
drawPieceButton(piece, point) {
|
|
65
62
|
const squareWidth = this.chessboard.view.squareWidth
|
|
66
63
|
const squareHeight = this.chessboard.view.squareHeight
|
|
@@ -30,7 +30,7 @@ export class ChessboardView {
|
|
|
30
30
|
window.addEventListener("resize", this.resizeListener)
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
this.positionsAnimationTask = Promise.resolve()
|
|
34
34
|
this.pointerDownListener = this.pointerDownHandler.bind(this)
|
|
35
35
|
this.pointerDownListener = this.pointerDownHandler.bind(this)
|
|
36
36
|
this.context.addEventListener("mousedown", this.pointerDownListener)
|
|
@@ -64,7 +64,7 @@ export class ChessboardView {
|
|
|
64
64
|
cacheSpriteToDiv(wrapperId, url) {
|
|
65
65
|
if (!document.getElementById(wrapperId)) {
|
|
66
66
|
const wrapper = document.createElement("div")
|
|
67
|
-
wrapper.style.
|
|
67
|
+
wrapper.style.transform = "scale(0)"
|
|
68
68
|
wrapper.id = wrapperId
|
|
69
69
|
document.body.appendChild(wrapper)
|
|
70
70
|
const xhr = new XMLHttpRequest()
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import {FEN, Position} from "../model/Position.js"
|
|
7
7
|
import {Svg} from "../lib/Svg.js"
|
|
8
8
|
import {EXTENSION_POINT} from "../model/Extension.js"
|
|
9
|
+
import {Utils} from "../lib/Utils.js"
|
|
9
10
|
|
|
10
11
|
/*
|
|
11
12
|
* Thanks to markosyan for the idea of the PromiseQueue
|
|
@@ -92,6 +93,10 @@ export class PositionsAnimation {
|
|
|
92
93
|
} else {
|
|
93
94
|
console.error("fromPosition", fromPosition, "toPosition", toPosition)
|
|
94
95
|
}
|
|
96
|
+
this.view.positionsAnimationTask = Utils.createTask()
|
|
97
|
+
this.view.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.animation, {
|
|
98
|
+
type: ANIMATION_EVENT_TYPE.start
|
|
99
|
+
})
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
static seekChanges(fromSquares, toSquares) {
|
|
@@ -173,21 +178,18 @@ export class PositionsAnimation {
|
|
|
173
178
|
}
|
|
174
179
|
if (!this.startTime) {
|
|
175
180
|
this.startTime = time
|
|
176
|
-
this.view.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.animation, {
|
|
177
|
-
type: ANIMATION_EVENT_TYPE.start
|
|
178
|
-
})
|
|
179
181
|
}
|
|
180
182
|
const timeDiff = time - this.startTime
|
|
181
183
|
if (timeDiff <= this.duration) {
|
|
182
184
|
this.frameHandle = requestAnimationFrame(this.animationStep.bind(this))
|
|
183
185
|
} else {
|
|
184
186
|
cancelAnimationFrame(this.frameHandle)
|
|
185
|
-
// console.log("ANIMATION FINISHED")
|
|
186
187
|
this.animatedElements.forEach((animatedItem) => {
|
|
187
188
|
if (animatedItem.type === CHANGE_TYPE.disappear) {
|
|
188
189
|
Svg.removeElement(animatedItem.element)
|
|
189
190
|
}
|
|
190
191
|
})
|
|
192
|
+
this.view.positionsAnimationTask.resolve()
|
|
191
193
|
this.view.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.animation, {
|
|
192
194
|
type: ANIMATION_EVENT_TYPE.end
|
|
193
195
|
})
|