cm-chessboard 8.0.3 → 8.1.1
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 +4 -1
- package/examples/extensions/markers-extension.html +1 -1
- package/package.json +1 -1
- package/src/extensions/arrows/Arrows.js +1 -1
- package/src/extensions/markers/Markers.js +1 -1
- package/src/extensions/promotion-dialog/PromotionDialog.js +1 -1
- package/src/model/Extension.js +7 -1
- package/src/view/ChessboardView.js +4 -3
package/README.md
CHANGED
|
@@ -344,9 +344,12 @@ Currently possible extension points are defined in `Extension.js`.
|
|
|
344
344
|
export const EXTENSION_POINT = {
|
|
345
345
|
positionChanged: "positionChanged", // the positions of the pieces was changed
|
|
346
346
|
boardChanged: "boardChanged", // the board (orientation) was changed
|
|
347
|
+
boardResized: "boardResized", // the board was resized
|
|
347
348
|
moveInputToggled: "moveInputToggled", // move input was enabled or disabled
|
|
348
349
|
moveInput: "moveInput", // move started, moving over a square, validating or canceled
|
|
349
|
-
|
|
350
|
+
beforeRedrawBoard: "beforeRedrawBoard", // called before redrawing the board
|
|
351
|
+
afterRedrawBoard: "afterRedrawBoard", // called after redrawing the board
|
|
352
|
+
redrawBoard: "redrawBoard", // called after redrawing the board, DEPRECATED, use afterRedrawBoard
|
|
350
353
|
animation: "animation", // called on animation start, end and on every animation frame
|
|
351
354
|
destroy: "destroy" // called, before the board is destroyed
|
|
352
355
|
}
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
const board1 = new Chessboard(document.getElementById("board1"), {
|
|
25
25
|
position: FEN.start,
|
|
26
|
+
assetsCache: false,
|
|
26
27
|
assetsUrl: "../../assets/",
|
|
27
28
|
extensions: [{class: Markers}]
|
|
28
29
|
})
|
|
@@ -50,7 +51,6 @@
|
|
|
50
51
|
}
|
|
51
52
|
const board2 = new Chessboard(document.getElementById("board2"), {
|
|
52
53
|
position: "rn2k1r1/ppp1pp1p/3p2p1/5bn1/P7/2N2B2/1PPPPP2/2BNK1RR",
|
|
53
|
-
assetsCache: false,
|
|
54
54
|
assetsUrl: "../../assets/",
|
|
55
55
|
style: {pieces: {file: "pieces/staunty.svg"}},
|
|
56
56
|
extensions: [{class: Markers, autoMarkers: MARKER_TYPE.frame}]
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ export class Arrows extends Extension {
|
|
|
19
19
|
/** @constructor */
|
|
20
20
|
constructor(chessboard, props = {}) {
|
|
21
21
|
super(chessboard)
|
|
22
|
-
this.registerExtensionPoint(EXTENSION_POINT.
|
|
22
|
+
this.registerExtensionPoint(EXTENSION_POINT.afterRedrawBoard, () => {
|
|
23
23
|
this.onRedrawBoard()
|
|
24
24
|
})
|
|
25
25
|
this.props = {
|
|
@@ -26,7 +26,7 @@ export class Markers extends Extension {
|
|
|
26
26
|
/** @constructor */
|
|
27
27
|
constructor(chessboard, props = {}) {
|
|
28
28
|
super(chessboard)
|
|
29
|
-
this.registerExtensionPoint(EXTENSION_POINT.
|
|
29
|
+
this.registerExtensionPoint(EXTENSION_POINT.afterRedrawBoard, () => {
|
|
30
30
|
this.onRedrawBoard()
|
|
31
31
|
})
|
|
32
32
|
this.props = {
|
|
@@ -24,7 +24,7 @@ export class PromotionDialog extends Extension {
|
|
|
24
24
|
/** @constructor */
|
|
25
25
|
constructor(chessboard) {
|
|
26
26
|
super(chessboard)
|
|
27
|
-
this.registerExtensionPoint(EXTENSION_POINT.
|
|
27
|
+
this.registerExtensionPoint(EXTENSION_POINT.afterRedrawBoard, this.extensionPointRedrawBoard.bind(this))
|
|
28
28
|
chessboard.showPromotionDialog = this.showPromotionDialog.bind(this)
|
|
29
29
|
chessboard.isPromotionDialogShown = this.isPromotionDialogShown.bind(this)
|
|
30
30
|
this.promotionDialogGroup = Svg.addElement(chessboard.view.interactiveTopLayer, "g", {class: "promotion-dialog-group"})
|
package/src/model/Extension.js
CHANGED
|
@@ -9,7 +9,9 @@ export const EXTENSION_POINT = {
|
|
|
9
9
|
boardChanged: "boardChanged", // the board (orientation) was changed
|
|
10
10
|
moveInputToggled: "moveInputToggled", // move input was enabled or disabled
|
|
11
11
|
moveInput: "moveInput", // move started, moving over a square, validating or canceled
|
|
12
|
-
|
|
12
|
+
beforeRedrawBoard: "beforeRedrawBoard", // called before redrawing the board
|
|
13
|
+
afterRedrawBoard: "afterRedrawBoard", // called after redrawing the board
|
|
14
|
+
redrawBoard: "redrawBoard", // called after redrawing the board, DEPRECATED, use afterRedrawBoard
|
|
13
15
|
animation: "animation", // called on animation start, end and on every animation frame
|
|
14
16
|
destroy: "destroy" // called, before the board is destroyed
|
|
15
17
|
}
|
|
@@ -21,6 +23,10 @@ export class Extension {
|
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
registerExtensionPoint(name, callback) {
|
|
26
|
+
if(name === EXTENSION_POINT.redrawBoard) {
|
|
27
|
+
console.warn("EXTENSION_POINT.redrawBoard is deprecated, use EXTENSION_POINT.afterRedrawBoard")
|
|
28
|
+
name = EXTENSION_POINT.afterRedrawBoard
|
|
29
|
+
}
|
|
24
30
|
if (!this.chessboard.state.extensionPoints[name]) {
|
|
25
31
|
this.chessboard.state.extensionPoints[name] = []
|
|
26
32
|
}
|
|
@@ -38,9 +38,9 @@ export class ChessboardView {
|
|
|
38
38
|
this.container.addEventListener("touchstart", this.pointerDownListener, {passive: false})
|
|
39
39
|
|
|
40
40
|
this.createSvgAndGroups()
|
|
41
|
-
this.updateMetrics()
|
|
41
|
+
// this.updateMetrics()
|
|
42
42
|
this.handleResize()
|
|
43
|
-
this.redrawBoard()
|
|
43
|
+
// this.redrawBoard()
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
pointerDownHandler(e) {
|
|
@@ -132,9 +132,10 @@ export class ChessboardView {
|
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
redrawBoard() {
|
|
135
|
+
this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.beforeRedrawBoard)
|
|
135
136
|
this.redrawSquares()
|
|
136
137
|
this.drawCoordinates()
|
|
137
|
-
this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.
|
|
138
|
+
this.chessboard.state.invokeExtensionPoints(EXTENSION_POINT.afterRedrawBoard)
|
|
138
139
|
this.visualizeInputState()
|
|
139
140
|
}
|
|
140
141
|
|