cm-chessboard 4.3.1 → 4.3.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/README.md +25 -9
- package/package.json +1 -1
- package/src/cm-chessboard/Chessboard.js +1 -1
package/README.md
CHANGED
|
@@ -102,7 +102,8 @@ let defaultProps = {
|
|
|
102
102
|
url: "./assets/images/chessboard-sprite.svg", // pieces and markers are stored in a sprite file
|
|
103
103
|
size: 40, // the sprite tiles size, defaults to 40x40px
|
|
104
104
|
cache: true // cache the sprite
|
|
105
|
-
}
|
|
105
|
+
},
|
|
106
|
+
extensions: [ /* {class: ExtensionClass, props: { ... }} */] // add extensions here
|
|
106
107
|
}
|
|
107
108
|
```
|
|
108
109
|
|
|
@@ -335,24 +336,39 @@ cm-chessboard provides the ability to extend its functionality with extensions.
|
|
|
335
336
|
and have access to the chessboard and can register extension points.
|
|
336
337
|
|
|
337
338
|
```js
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
class MyCoolChessboardExtension extends Extension {
|
|
340
|
+
constructor(chessboard, props) {
|
|
341
|
+
super(chessboard, props)
|
|
342
|
+
this.registerExtensionPoint(EXTENSION_POINT.moveInputStateChanged, (data) => {
|
|
343
|
+
// do something on move [start | cancel | done]
|
|
344
|
+
console.log(data)
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
}
|
|
342
348
|
```
|
|
343
349
|
|
|
344
|
-
|
|
350
|
+
Currently possible extension points are defined in `Extension.js`.
|
|
351
|
+
|
|
352
|
+
```js
|
|
353
|
+
export const EXTENSION_POINT = {
|
|
354
|
+
positionChanged: "positionChanged",
|
|
355
|
+
boardChanged: "boardChanged",
|
|
356
|
+
moveInputStateChanged: "moveInputStateChanged",
|
|
357
|
+
destroy: "destroy"
|
|
358
|
+
}
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Enable extensions via the chessboard props.
|
|
345
362
|
|
|
346
363
|
```js
|
|
347
364
|
const chessboard = new Chessboard(document.getElementById("board"), {
|
|
348
365
|
position: "start",
|
|
349
366
|
extensions: // list of used extensions
|
|
350
367
|
[{
|
|
351
|
-
class:
|
|
368
|
+
class: MyCoolChessboardExtension, // the class of the extension
|
|
352
369
|
props: {
|
|
353
|
-
// configure
|
|
370
|
+
// configure the extension here
|
|
354
371
|
}
|
|
355
|
-
|
|
356
372
|
}]
|
|
357
373
|
})
|
|
358
374
|
```
|
package/package.json
CHANGED
|
@@ -67,7 +67,7 @@ export class Chessboard {
|
|
|
67
67
|
size: 40, // the sprite tiles size, defaults to 40x40px
|
|
68
68
|
cache: true // cache the sprite
|
|
69
69
|
},
|
|
70
|
-
extensions: [ /* {class: ExtensionClass, props: { ... }} */ ] // add extensions here
|
|
70
|
+
extensions: [ /* {class: ExtensionClass, props: { ... }} */ ] // add extensions here
|
|
71
71
|
}
|
|
72
72
|
this.props = {}
|
|
73
73
|
Object.assign(this.props, defaultProps)
|