cm-chessboard 8.12.3 → 8.12.5

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
@@ -152,10 +152,9 @@ this.props = {
152
152
 
153
153
  ### setPiece(square, piece, animated = false)
154
154
 
155
- Sets a piece on a square. Example: `board.setPiece("e4", PIECE.blackKnight, true)` or
156
- `board.setPiece("e4", "bn")`. Remove a Piece with `board.setPiece("e4", null)`. Returns a **Promise**, which is
157
- resolved,
158
- after the animation finished.
155
+ Sets a piece on a square. Example: `board.setPiece("e4", PIECE.bn, true)` or
156
+ `board.setPiece("e4", "bn")`. Remove a piece with `board.setPiece("e4", null)`. Returns a **Promise**, which is
157
+ resolved after the animation finished.
159
158
 
160
159
  ### getPiece(square)
161
160
 
@@ -177,9 +176,9 @@ Sets the position as `fen` or only the position part of a `fen`. Returns a **Pro
177
176
 
178
177
  Returns the board position in form of the position part of a `fen`.
179
178
 
180
- ### setOrientation(color)
179
+ ### setOrientation(color, animated = false)
181
180
 
182
- Sets the board orientation (color at bottom). Allowed values are `COLOR.white` or `COLOR.black`.
181
+ Sets the board orientation (color at bottom). Allowed values are `COLOR.white` or `COLOR.black`. When `animated` is `true`, the board turns with an animation. Returns a **Promise**, which is resolved after the animation finished.
183
182
 
184
183
  [Example for **setOrientation**](https://shaack.com/projekte/cm-chessboard/examples/enable-input.html)
185
184
 
@@ -187,12 +186,6 @@ Sets the board orientation (color at bottom). Allowed values are `COLOR.white` o
187
186
 
188
187
  Returns the board orientation.
189
188
 
190
- ### destroy()
191
-
192
- Removes the board from the DOM.
193
-
194
- [Example for **destroy**](https://shaack.com/projekte/cm-chessboard/examples/destroy-many-boards.html)
195
-
196
189
  ### enableMoveInput(eventHandler, color = undefined)
197
190
 
198
191
  Enables moves via user input (mouse or touch). Set optional `color`, if you want to enable the move input for a specific
@@ -247,6 +240,44 @@ chessboard.enableMoveInput((event) => {
247
240
 
248
241
  Disables moves via user input.
249
242
 
243
+ ### isMoveInputEnabled()
244
+
245
+ Returns `true` if move input is currently enabled for white or black.
246
+
247
+ ### enableSquareSelect(eventType, eventHandler)
248
+
249
+ Listens for pointer events on squares and calls `eventHandler` with an object `{eventType, event, chessboard, square}`. `eventType` defaults to `POINTER_EVENTS.pointerdown`; allowed values are in `POINTER_EVENTS` (e.g. `pointerdown`, `pointerup`, `pointermove`, …).
250
+
251
+ ```javascript
252
+ board.enableSquareSelect(POINTER_EVENTS.pointerdown, (event) => {
253
+ console.log(event.square)
254
+ })
255
+ ```
256
+
257
+ [Example for **enableSquareSelect**](https://shaack.com/projekte/cm-chessboard/examples/pointer-events.html)
258
+
259
+ ### disableSquareSelect(eventType)
260
+
261
+ Stops listening for the given pointer event type.
262
+
263
+ ### isSquareSelectEnabled()
264
+
265
+ Returns `true` if square select is currently enabled.
266
+
267
+ ### addExtension(extensionClass, props)
268
+
269
+ Adds an extension at runtime. Throws if the extension class is already added.
270
+
271
+ ### getExtension(extensionClass)
272
+
273
+ Returns the instance of an added extension, or `null` if not found.
274
+
275
+ ### destroy()
276
+
277
+ Removes the board from the DOM.
278
+
279
+ [Example for **destroy**](https://shaack.com/projekte/cm-chessboard/examples/destroy-many-boards.html)
280
+
250
281
  ## Piece sets
251
282
 
252
283
  cm-chessboard supports alternative piece sets. A piece set is defined in an SVG sprite. cm-chessboard is shipped with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cm-chessboard",
3
- "version": "8.12.3",
3
+ "version": "8.12.5",
4
4
  "description": "A JavaScript chessboard which is lightweight, ES6 module based, responsive, SVG rendered and without dependencies.",
5
5
  "keywords": [
6
6
  "chess",
@@ -28,6 +28,33 @@ Removes markers from the board.
28
28
  Only set `type` to remove all markers of `type` from the board. Set `type` to `undefined`, to remove all types
29
29
  of markers from a square. Call without parameters to remove all markers from the board.
30
30
 
31
+ ## Marker type identity
32
+
33
+ Marker types are matched by **object reference**, not by structural
34
+ equality. Two type objects that only *look* the same are intentionally
35
+ treated as different types — this lets you have several visually
36
+ identical marker types that can be managed independently.
37
+
38
+ Always keep your marker types as module-level constants and pass the
39
+ **same reference** to `addMarker` and `removeMarkers`:
40
+
41
+ ```js
42
+ // ✅ works — same reference
43
+ const myType = {class: "marker-frame", slice: "markerFrame"}
44
+ board.addMarker(myType, "e4")
45
+ board.removeMarkers(myType) // removed
46
+
47
+ // ❌ silently does nothing — different reference, even though the
48
+ // object looks identical
49
+ board.addMarker({class: "marker-frame", slice: "markerFrame"}, "e4")
50
+ board.removeMarkers({class: "marker-frame", slice: "markerFrame"})
51
+ ```
52
+
53
+ The same applies to the exported `MARKER_TYPE.*` constants: import them
54
+ once and reuse that reference — don't clone them (e.g. via
55
+ `JSON.parse(JSON.stringify(...))` or a framework store that
56
+ deep-copies), or `removeMarkers` won't find a match.
57
+
31
58
  ## Create your own custom markers
32
59
 
33
60
  Just create an object like `const myMarker = {class: "markerCssClass", slice: "markerSliceId"}`, where `class` is the