kokopu-react 1.2.0 → 1.4.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/CHANGELOG.md +17 -0
- package/dist/lib/ArrowMarkerIcon.js +5 -7
- package/dist/lib/Chessboard.js +27 -33
- package/dist/lib/{impl/ErrorBox.js → ErrorBox.js} +2 -2
- package/dist/lib/SquareMarkerIcon.js +1 -1
- package/dist/lib/TextMarkerIcon.js +12 -11
- package/dist/lib/css/arrow.css +1 -1
- package/dist/lib/css/chessboard.css +1 -1
- package/dist/lib/css/error_box.css +1 -1
- package/dist/lib/css/label.css +1 -1
- package/dist/lib/css/symbol.css +25 -0
- package/dist/lib/i18n.js +35 -0
- package/dist/lib/impl/ArrowTip.js +3 -8
- package/dist/lib/impl/TextSymbol.js +100 -0
- package/dist/lib/impl/colorsets.js +1 -1
- package/dist/lib/impl/piecesets.js +1 -1
- package/dist/lib/impl/util.js +6 -6
- package/dist/lib/index.js +34 -18
- package/dist/lib/markers.js +10 -10
- package/doc_src/{demo/.eslintrc.yml → .eslintrc.yml} +0 -0
- package/doc_src/demo/PageChessboardBase.js +36 -41
- package/doc_src/demo/PageChessboardEdition.js +59 -71
- package/doc_src/demo/PageChessboardMove.js +21 -28
- package/doc_src/demo/PageChessboardSmallScreens.js +16 -17
- package/doc_src/demo/demo.css +1 -1
- package/doc_src/demo/util.js +1 -1
- package/doc_src/examples/ErrorBox.md +3 -0
- package/doc_src/theming/LogoRenderer.js +50 -0
- package/doc_src/theming/kokopu-react-favicon.png +0 -0
- package/doc_src/theming/kokopu-react-logo.png +0 -0
- package/doc_src/theming/theming.css +29 -0
- package/graphic_test_app/01_marker_icons.js +6 -4
- package/graphic_test_app/02_chessboard_simple.js +1 -1
- package/graphic_test_app/03_chessboard_flipped.js +1 -1
- package/graphic_test_app/04_chessboard_annotations.js +2 -2
- package/graphic_test_app/05_chessboard_move.js +1 -1
- package/graphic_test_app/06_chessboard_theme.js +1 -1
- package/graphic_test_app/07_chessboard_click_squares.js +1 -1
- package/graphic_test_app/08_chessboard_move_pieces.js +1 -1
- package/graphic_test_app/09_chessboard_edit_arrows.js +1 -1
- package/graphic_test_app/10_chessboard_play_moves.js +1 -1
- package/graphic_test_app/11_chessboard_play_promotions.js +1 -1
- package/graphic_test_app/common/test_app.css +1 -1
- package/graphic_test_app/common/test_app.js +1 -1
- package/package.json +23 -22
- package/scripts/test_graphic/clean-graphic-output.js +1 -1
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +2 -1
- package/scripts/test_headless.webpack-config.js +2 -1
- package/src/ArrowMarkerIcon.js +2 -2
- package/src/Chessboard.js +16 -14
- package/src/{impl/ErrorBox.js → ErrorBox.js} +2 -2
- package/src/SquareMarkerIcon.js +1 -1
- package/src/TextMarkerIcon.js +7 -7
- package/src/css/arrow.css +1 -1
- package/src/css/chessboard.css +1 -1
- package/src/css/error_box.css +1 -1
- package/src/css/label.css +1 -1
- package/src/css/symbol.css +25 -0
- package/src/i18n.js +30 -0
- package/src/impl/ArrowTip.js +3 -7
- package/src/impl/TextSymbol.js +77 -0
- package/src/impl/colorsets.js +1 -1
- package/src/impl/piecesets.js +1 -1
- package/src/impl/util.js +2 -2
- package/src/index.js +3 -1
- package/src/markers.js +8 -7
- package/test/1_markers.js +20 -1
- package/test/2_chessboard_util.js +1 -1
- package/test/3_marker_icons_graphic.js +2 -2
- package/test/4_chessboard_graphic.js +1 -1
- package/test/5_chessboard_interaction.js +1 -1
- package/test/6_chessboard_play_moves.js +1 -1
- package/test/common/graphic.js +1 -1
- package/test/references/01_marker_icons/10.png +0 -0
- package/test/references/01_marker_icons/9.png +0 -0
- package/test/references/02_chessboard_simple/2.png +0 -0
- package/test/references/02_chessboard_simple/5.png +0 -0
- package/test/references/03_chessboard_flipped/2.png +0 -0
- package/test/references/04_chessboard_annotations/4.png +0 -0
- package/test/references/04_chessboard_annotations/5.png +0 -0
package/dist/lib/index.js
CHANGED
|
@@ -3,28 +3,34 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
Object.defineProperty(exports, "
|
|
6
|
+
Object.defineProperty(exports, "ArrowMarkerIcon", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function get() {
|
|
9
|
-
return
|
|
9
|
+
return _ArrowMarkerIcon["default"];
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "Chessboard", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return
|
|
15
|
+
return _Chessboard["default"];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "ErrorBox", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function get() {
|
|
21
|
-
return
|
|
21
|
+
return _ErrorBox["default"];
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
Object.defineProperty(exports, "
|
|
24
|
+
Object.defineProperty(exports, "SquareMarkerIcon", {
|
|
25
25
|
enumerable: true,
|
|
26
26
|
get: function get() {
|
|
27
|
-
return
|
|
27
|
+
return _SquareMarkerIcon["default"];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "TextMarkerIcon", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _TextMarkerIcon["default"];
|
|
28
34
|
}
|
|
29
35
|
});
|
|
30
36
|
Object.defineProperty(exports, "flattenArrowMarkers", {
|
|
@@ -33,41 +39,51 @@ Object.defineProperty(exports, "flattenArrowMarkers", {
|
|
|
33
39
|
return _markers.flattenArrowMarkers;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "flattenSquareMarkers", {
|
|
37
43
|
enumerable: true,
|
|
38
44
|
get: function get() {
|
|
39
|
-
return _markers.
|
|
45
|
+
return _markers.flattenSquareMarkers;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
|
-
Object.defineProperty(exports, "
|
|
48
|
+
Object.defineProperty(exports, "flattenTextMarkers", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
get: function get() {
|
|
45
|
-
return
|
|
51
|
+
return _markers.flattenTextMarkers;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
|
-
Object.defineProperty(exports, "
|
|
54
|
+
Object.defineProperty(exports, "i18n", {
|
|
49
55
|
enumerable: true,
|
|
50
56
|
get: function get() {
|
|
51
|
-
return
|
|
57
|
+
return _i18n["default"];
|
|
52
58
|
}
|
|
53
59
|
});
|
|
54
|
-
Object.defineProperty(exports, "
|
|
60
|
+
Object.defineProperty(exports, "parseArrowMarkers", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function get() {
|
|
57
|
-
return
|
|
63
|
+
return _markers.parseArrowMarkers;
|
|
58
64
|
}
|
|
59
65
|
});
|
|
60
|
-
Object.defineProperty(exports, "
|
|
66
|
+
Object.defineProperty(exports, "parseSquareMarkers", {
|
|
61
67
|
enumerable: true,
|
|
62
68
|
get: function get() {
|
|
63
|
-
return
|
|
69
|
+
return _markers.parseSquareMarkers;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "parseTextMarkers", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function get() {
|
|
75
|
+
return _markers.parseTextMarkers;
|
|
64
76
|
}
|
|
65
77
|
});
|
|
66
78
|
|
|
67
79
|
var _markers = require("./markers");
|
|
68
80
|
|
|
81
|
+
var _i18n = _interopRequireDefault(require("./i18n"));
|
|
82
|
+
|
|
69
83
|
var _Chessboard = _interopRequireDefault(require("./Chessboard"));
|
|
70
84
|
|
|
85
|
+
var _ErrorBox = _interopRequireDefault(require("./ErrorBox"));
|
|
86
|
+
|
|
71
87
|
var _SquareMarkerIcon = _interopRequireDefault(require("./SquareMarkerIcon"));
|
|
72
88
|
|
|
73
89
|
var _TextMarkerIcon = _interopRequireDefault(require("./TextMarkerIcon"));
|
package/dist/lib/markers.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.flattenArrowMarkers = flattenArrowMarkers;
|
|
6
7
|
exports.flattenSquareMarkers = flattenSquareMarkers;
|
|
7
8
|
exports.flattenTextMarkers = flattenTextMarkers;
|
|
8
|
-
exports.
|
|
9
|
+
exports.parseArrowMarkers = parseArrowMarkers;
|
|
9
10
|
exports.parseSquareMarkers = parseSquareMarkers;
|
|
10
11
|
exports.parseTextMarkers = parseTextMarkers;
|
|
11
|
-
exports.parseArrowMarkers = parseArrowMarkers;
|
|
12
12
|
|
|
13
13
|
var _util = require("./impl/util");
|
|
14
14
|
|
|
@@ -50,8 +50,8 @@ function flattenSquareMarkers(markers) {
|
|
|
50
50
|
/**
|
|
51
51
|
* Transform a set of text markers defined as a "square -> (symbol, color)" struct into a comma-separated string.
|
|
52
52
|
*
|
|
53
|
-
* @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
|
|
54
|
-
* @returns {string} For example: `'Rzd5,GAe4'`
|
|
53
|
+
* @param {object} markers For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
|
|
54
|
+
* @returns {string} For example: `'Rzd5,GAe4,Y(plus)h3'`
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
|
|
@@ -69,7 +69,7 @@ function flattenTextMarkers(markers) {
|
|
|
69
69
|
sq = _ref8[0],
|
|
70
70
|
desc = _ref8[1];
|
|
71
71
|
|
|
72
|
-
return desc.color.toUpperCase() + desc.symbol + sq;
|
|
72
|
+
return desc.color.toUpperCase() + (desc.symbol.length === 1 ? desc.symbol : '(' + desc.symbol + ')') + sq;
|
|
73
73
|
}).join(',');
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -130,17 +130,17 @@ function parseSquareMarkers(markers) {
|
|
|
130
130
|
/**
|
|
131
131
|
* Parse a set of text markers defined as a comma-separated string into a "square -> (symbol, color)" struct.
|
|
132
132
|
*
|
|
133
|
-
* @param {string} markers For example: `'Rzd5,GAe4'`
|
|
134
|
-
* @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }}`
|
|
133
|
+
* @param {string} markers For example: `'Rzd5,GAe4,Y(plus)h3'`
|
|
134
|
+
* @returns {object} For example: `{ e4: { symbol: 'A', color: 'g' }, d5: { symbol: 'z', color: 'r' }, h3: { symbol: 'plus', color: 'y' } }`
|
|
135
135
|
*/
|
|
136
136
|
|
|
137
137
|
|
|
138
138
|
function parseTextMarkers(markers) {
|
|
139
139
|
return parseMarkers(markers, function (token) {
|
|
140
|
-
return /^([GRY])([A-Za-z0-9])([a-h][1-8])$/.test(token) ? {
|
|
141
|
-
key: RegExp.$
|
|
140
|
+
return /^([GRY])(?:([A-Za-z0-9])|\((plus|times|dot|circle)\))([a-h][1-8])$/.test(token) ? {
|
|
141
|
+
key: RegExp.$4,
|
|
142
142
|
value: {
|
|
143
|
-
symbol: RegExp.$2,
|
|
143
|
+
symbol: RegExp.$2 || RegExp.$3,
|
|
144
144
|
color: RegExp.$1.toLowerCase()
|
|
145
145
|
}
|
|
146
146
|
} : undefined;
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -25,15 +25,18 @@ import React from 'react';
|
|
|
25
25
|
import { Chessboard } from '../../src/index';
|
|
26
26
|
import { buildComponentDemoCode } from './util';
|
|
27
27
|
|
|
28
|
-
import Box from '@material
|
|
29
|
-
import Button from '@material
|
|
30
|
-
import ButtonGroup from '@material
|
|
31
|
-
import
|
|
32
|
-
import
|
|
33
|
-
import
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import
|
|
28
|
+
import Box from '@mui/material/Box';
|
|
29
|
+
import Button from '@mui/material/Button';
|
|
30
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
31
|
+
import FormControl from '@mui/material/FormControl';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import InputLabel from '@mui/material/InputLabel';
|
|
34
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
35
|
+
import Select from '@mui/material/Select';
|
|
36
|
+
import Slider from '@mui/material/Slider';
|
|
37
|
+
import Stack from '@mui/material/Stack';
|
|
38
|
+
import Switch from '@mui/material/Switch';
|
|
39
|
+
import Typography from '@mui/material/Typography';
|
|
37
40
|
|
|
38
41
|
import './demo.css';
|
|
39
42
|
|
|
@@ -59,17 +62,17 @@ export default class Page extends React.Component {
|
|
|
59
62
|
|
|
60
63
|
render() {
|
|
61
64
|
return (
|
|
62
|
-
<
|
|
65
|
+
<Stack spacing={2} mt={2}>
|
|
63
66
|
{this.renderControls()}
|
|
64
67
|
{this.renderChessboard()}
|
|
65
68
|
{this.renderCode()}
|
|
66
|
-
</
|
|
69
|
+
</Stack>
|
|
67
70
|
);
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
renderControls() {
|
|
71
74
|
return (<>
|
|
72
|
-
<
|
|
75
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
73
76
|
<FormControlLabel label="Flip"
|
|
74
77
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
75
78
|
/>
|
|
@@ -79,42 +82,40 @@ export default class Page extends React.Component {
|
|
|
79
82
|
<FormControlLabel label="Show annotations"
|
|
80
83
|
control={<Switch checked={this.state.annotationVisible} onChange={() => this.set('annotationVisible', !this.state.annotationVisible)} color="primary" />}
|
|
81
84
|
/>
|
|
82
|
-
</
|
|
83
|
-
<Box
|
|
85
|
+
</Stack>
|
|
86
|
+
<Box>
|
|
84
87
|
<Typography gutterBottom>Square size</Typography>
|
|
85
88
|
<Slider
|
|
86
89
|
value={this.state.squareSize} onChange={(_, newValue) => this.set('squareSize', newValue)}
|
|
87
90
|
min={Chessboard.minSquareSize()} max={Chessboard.maxSquareSize()} step={1} valueLabelDisplay="on" color="primary"
|
|
88
91
|
/>
|
|
89
92
|
</Box>
|
|
90
|
-
<
|
|
91
|
-
<
|
|
92
|
-
<
|
|
93
|
-
<Select value={this.state.colorset} onChange={evt => this.set('colorset', evt.target.value)}>
|
|
93
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
94
|
+
<FormControl variant="standard">
|
|
95
|
+
<InputLabel id="colorset-label">Colorset</InputLabel>
|
|
96
|
+
<Select labelId="colorset-label" sx={{ width: '8em' }} value={this.state.colorset} onChange={evt => this.set('colorset', evt.target.value)}>
|
|
94
97
|
{Object.keys(Chessboard.colorsets()).sort().map(colorset => <MenuItem key={colorset} value={colorset}>{colorset}</MenuItem>)}
|
|
95
98
|
</Select>
|
|
96
|
-
</
|
|
97
|
-
<
|
|
98
|
-
<
|
|
99
|
-
<Select value={this.state.pieceset} onChange={evt => this.set('pieceset', evt.target.value)}>
|
|
99
|
+
</FormControl>
|
|
100
|
+
<FormControl variant="standard">
|
|
101
|
+
<InputLabel id="pieceset-label">Pieceset</InputLabel>
|
|
102
|
+
<Select labelId="pieceset-label" sx={{ width: '8em' }} value={this.state.pieceset} onChange={evt => this.set('pieceset', evt.target.value)}>
|
|
100
103
|
{Object.keys(Chessboard.piecesets()).sort().map(pieceset => <MenuItem key={pieceset} value={pieceset}>{pieceset}</MenuItem>)}
|
|
101
104
|
</Select>
|
|
102
|
-
</
|
|
103
|
-
<
|
|
104
|
-
<
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
</Box>
|
|
111
|
-
</Box>
|
|
105
|
+
</FormControl>
|
|
106
|
+
<ButtonGroup color="primary" size="small">
|
|
107
|
+
<Button onClick={() => this.set('position', 'empty')}>Clear</Button>
|
|
108
|
+
<Button onClick={() => this.set('position', 'start')}>Reset</Button>
|
|
109
|
+
<Button onClick={() => this.set('position', '8/8/8/8/8/4k3/q7/4K3 b - - 0 1')}>Set FEN</Button>
|
|
110
|
+
<Button onClick={() => this.set('position', 'I\'m an invalid FEN string')}>Set ill-formed FEN</Button>
|
|
111
|
+
</ButtonGroup>
|
|
112
|
+
</Stack>
|
|
112
113
|
</>);
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
renderChessboard() {
|
|
116
117
|
return (
|
|
117
|
-
<Box
|
|
118
|
+
<Box>
|
|
118
119
|
<Chessboard
|
|
119
120
|
position={this.state.position}
|
|
120
121
|
flipped={this.state.flipped}
|
|
@@ -145,13 +146,7 @@ export default class Page extends React.Component {
|
|
|
145
146
|
attributes.push(`coordinateVisible={${this.state.coordinateVisible}}`);
|
|
146
147
|
attributes.push(`colorset="${this.state.colorset}"`);
|
|
147
148
|
attributes.push(`pieceset="${this.state.pieceset}"`);
|
|
148
|
-
return (
|
|
149
|
-
<Box my={2}>
|
|
150
|
-
<pre className="kokopu-demoCode">
|
|
151
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
152
|
-
</pre>
|
|
153
|
-
</Box>
|
|
154
|
-
);
|
|
149
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
155
150
|
}
|
|
156
151
|
|
|
157
152
|
set(attributeName, newValue) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -26,18 +26,19 @@ import kokopu from 'kokopu';
|
|
|
26
26
|
import { Chessboard, SquareMarkerIcon, TextMarkerIcon, ArrowMarkerIcon, flattenSquareMarkers, flattenTextMarkers, flattenArrowMarkers } from '../../src/index';
|
|
27
27
|
import { buildComponentDemoCode } from './util';
|
|
28
28
|
|
|
29
|
-
import Box from '@material
|
|
30
|
-
import Button from '@material
|
|
31
|
-
import ButtonGroup from '@material
|
|
32
|
-
import FormControlLabel from '@material
|
|
33
|
-
import MenuItem from '@material
|
|
34
|
-
import Radio from '@material
|
|
35
|
-
import RadioGroup from '@material
|
|
36
|
-
import Select from '@material
|
|
37
|
-
import
|
|
38
|
-
import
|
|
39
|
-
import
|
|
40
|
-
import
|
|
29
|
+
import Box from '@mui/material/Box';
|
|
30
|
+
import Button from '@mui/material/Button';
|
|
31
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
34
|
+
import Radio from '@mui/material/Radio';
|
|
35
|
+
import RadioGroup from '@mui/material/RadioGroup';
|
|
36
|
+
import Select from '@mui/material/Select';
|
|
37
|
+
import Stack from '@mui/material/Stack';
|
|
38
|
+
import Switch from '@mui/material/Switch';
|
|
39
|
+
import ToggleButton from '@mui/material/ToggleButton';
|
|
40
|
+
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
|
|
41
|
+
import Typography from '@mui/material/Typography';
|
|
41
42
|
|
|
42
43
|
import './demo.css';
|
|
43
44
|
|
|
@@ -68,55 +69,53 @@ export default class Page extends React.Component {
|
|
|
68
69
|
|
|
69
70
|
render() {
|
|
70
71
|
return (
|
|
71
|
-
<
|
|
72
|
+
<Stack spacing={2} mt={2}>
|
|
72
73
|
{this.renderControls()}
|
|
73
74
|
{this.renderChessboard()}
|
|
74
75
|
{this.renderCode()}
|
|
75
|
-
</
|
|
76
|
+
</Stack>
|
|
76
77
|
);
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
renderControls() {
|
|
80
81
|
return (<>
|
|
81
|
-
<
|
|
82
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
82
83
|
<FormControlLabel label="Flip"
|
|
83
84
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
84
85
|
/>
|
|
85
86
|
<Button color="primary" size="small" variant="contained" onClick={() => this.handleTurnClicked(kokopu.oppositeColor(this.state.position.turn()))}>
|
|
86
87
|
Change turn
|
|
87
88
|
</Button>
|
|
88
|
-
<
|
|
89
|
-
<
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</Box>
|
|
95
|
-
<Box my={2}>
|
|
89
|
+
<ButtonGroup color="primary" size="small">
|
|
90
|
+
<Button onClick={() => this.set('position', new kokopu.Position('empty'))}>Clear</Button>
|
|
91
|
+
<Button onClick={() => this.set('position', new kokopu.Position())}>Reset</Button>
|
|
92
|
+
</ButtonGroup>
|
|
93
|
+
</Stack>
|
|
94
|
+
<Box>
|
|
96
95
|
<Typography gutterBottom>
|
|
97
96
|
Edition mode
|
|
98
97
|
</Typography>
|
|
99
98
|
<RadioGroup value={this.state.interactionMode} onChange={evt => this.set('interactionMode', evt.target.value)}>
|
|
100
99
|
<FormControlLabel value="" control={<Radio color="primary" />} label="None" />
|
|
101
|
-
<
|
|
100
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
102
101
|
<FormControlLabel value="addRemovePieces" control={<Radio color="primary" />} label="Add/remove pieces" />
|
|
103
102
|
{this.renderPieceSelector()}
|
|
104
|
-
</
|
|
103
|
+
</Stack>
|
|
105
104
|
<FormControlLabel value="movePieces" control={<Radio color="primary" />} label="Move pieces" />
|
|
106
105
|
<FormControlLabel value="playMoves" control={<Radio color="primary" />} label="Move pieces (obeying chess rules)" />
|
|
107
|
-
<
|
|
106
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
108
107
|
<FormControlLabel value="editSquareMarkers" control={<Radio color="primary" />} label="Edit square annotations" />
|
|
109
108
|
{this.renderMarkerColorSelector('squareMarkerColor', 'editSquareMarkers')}
|
|
110
|
-
</
|
|
111
|
-
<
|
|
109
|
+
</Stack>
|
|
110
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
112
111
|
<FormControlLabel value="editTextMarkers" control={<Radio color="primary" />} label="Edit text annotations" />
|
|
113
112
|
{this.renderMarkerColorSelector('textMarkerColor', 'editTextMarkers')}
|
|
114
113
|
{this.renderTextMarkerSymbolSelector()}
|
|
115
|
-
</
|
|
116
|
-
<
|
|
114
|
+
</Stack>
|
|
115
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
117
116
|
<FormControlLabel value="editArrowMarkers" control={<Radio color="primary" />} label="Edit arrow annotations" />
|
|
118
117
|
{this.renderMarkerColorSelector('arrowMarkerColor', 'editArrowMarkers')}
|
|
119
|
-
</
|
|
118
|
+
</Stack>
|
|
120
119
|
</RadioGroup>
|
|
121
120
|
</Box>
|
|
122
121
|
</>);
|
|
@@ -128,28 +127,24 @@ export default class Page extends React.Component {
|
|
|
128
127
|
}
|
|
129
128
|
let pieceset = Chessboard.piecesets()['cburnett'];
|
|
130
129
|
return (
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
<
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<ToggleButton value="bp"><img src={pieceset.bp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
150
|
-
</ToggleButtonGroup>
|
|
151
|
-
</Box>
|
|
152
|
-
</Box>
|
|
130
|
+
<Stack spacing={0.5}>
|
|
131
|
+
<ToggleButtonGroup value={this.state.pieceEditMode} exclusive size="small" onChange={(_, newMode) => this.setIfNonNull('pieceEditMode', newMode)}>
|
|
132
|
+
<ToggleButton value="wk"><img src={pieceset.wk} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
133
|
+
<ToggleButton value="wq"><img src={pieceset.wq} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
134
|
+
<ToggleButton value="wr"><img src={pieceset.wr} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
135
|
+
<ToggleButton value="wb"><img src={pieceset.wb} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
136
|
+
<ToggleButton value="wn"><img src={pieceset.wn} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
137
|
+
<ToggleButton value="wp"><img src={pieceset.wp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
138
|
+
</ToggleButtonGroup>
|
|
139
|
+
<ToggleButtonGroup value={this.state.pieceEditMode} exclusive size="small" onChange={(_, newMode) => this.setIfNonNull('pieceEditMode', newMode)}>
|
|
140
|
+
<ToggleButton value="bk"><img src={pieceset.bk} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
141
|
+
<ToggleButton value="bq"><img src={pieceset.bq} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
142
|
+
<ToggleButton value="br"><img src={pieceset.br} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
143
|
+
<ToggleButton value="bb"><img src={pieceset.bb} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
144
|
+
<ToggleButton value="bn"><img src={pieceset.bn} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
145
|
+
<ToggleButton value="bp"><img src={pieceset.bp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
146
|
+
</ToggleButtonGroup>
|
|
147
|
+
</Stack>
|
|
153
148
|
);
|
|
154
149
|
}
|
|
155
150
|
|
|
@@ -157,9 +152,10 @@ export default class Page extends React.Component {
|
|
|
157
152
|
if (this.state.interactionMode !== 'editTextMarkers') {
|
|
158
153
|
return undefined;
|
|
159
154
|
}
|
|
155
|
+
let availableSymbols = [ 'plus', 'times', 'dot', 'circle' ].concat([...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789']);
|
|
160
156
|
return (
|
|
161
|
-
<Select value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
162
|
-
{
|
|
157
|
+
<Select variant="standard" value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
158
|
+
{availableSymbols.map(mode => <MenuItem key={mode} value={mode}>{mode}</MenuItem>)}
|
|
163
159
|
</Select>
|
|
164
160
|
);
|
|
165
161
|
}
|
|
@@ -170,13 +166,11 @@ export default class Page extends React.Component {
|
|
|
170
166
|
}
|
|
171
167
|
let colorset = Chessboard.colorsets()['original'];
|
|
172
168
|
return (
|
|
173
|
-
<
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
</ToggleButtonGroup>
|
|
179
|
-
</Box>
|
|
169
|
+
<ToggleButtonGroup value={this.state[attributeName]} exclusive size="small" onChange={(_, newColor) => this.setIfNonNull(attributeName, newColor)}>
|
|
170
|
+
<ToggleButton className="kokopu-fixTextTransform" value="g">{this.renderColorButtonLabel(colorset.g)}</ToggleButton>
|
|
171
|
+
<ToggleButton className="kokopu-fixTextTransform" value="r">{this.renderColorButtonLabel(colorset.r)}</ToggleButton>
|
|
172
|
+
<ToggleButton className="kokopu-fixTextTransform" value="y">{this.renderColorButtonLabel(colorset.y)}</ToggleButton>
|
|
173
|
+
</ToggleButtonGroup>
|
|
180
174
|
);
|
|
181
175
|
}
|
|
182
176
|
|
|
@@ -195,7 +189,7 @@ export default class Page extends React.Component {
|
|
|
195
189
|
|
|
196
190
|
renderChessboard() {
|
|
197
191
|
return (
|
|
198
|
-
<Box
|
|
192
|
+
<Box>
|
|
199
193
|
<Chessboard
|
|
200
194
|
position={this.state.position}
|
|
201
195
|
flipped={this.state.flipped}
|
|
@@ -257,13 +251,7 @@ export default class Page extends React.Component {
|
|
|
257
251
|
default:
|
|
258
252
|
break;
|
|
259
253
|
}
|
|
260
|
-
return (
|
|
261
|
-
<Box my={2}>
|
|
262
|
-
<pre className="kokopu-demoCode">
|
|
263
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
264
|
-
</pre>
|
|
265
|
-
</Box>
|
|
266
|
-
);
|
|
254
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
267
255
|
}
|
|
268
256
|
|
|
269
257
|
set(attributeName, newValue) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/******************************************************************************
|
|
2
2
|
* *
|
|
3
3
|
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
4
|
-
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net>
|
|
4
|
+
* Copyright (C) 2021-2022 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
5
5
|
* *
|
|
6
6
|
* This program is free software: you can redistribute it and/or *
|
|
7
7
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
@@ -26,12 +26,13 @@ import kokopu from 'kokopu';
|
|
|
26
26
|
import { Chessboard } from '../../src/index';
|
|
27
27
|
import { buildComponentDemoCode } from './util';
|
|
28
28
|
|
|
29
|
-
import Box from '@material
|
|
30
|
-
import Button from '@material
|
|
31
|
-
import ButtonGroup from '@material
|
|
32
|
-
import FormControlLabel from '@material
|
|
33
|
-
import
|
|
34
|
-
import
|
|
29
|
+
import Box from '@mui/material/Box';
|
|
30
|
+
import Button from '@mui/material/Button';
|
|
31
|
+
import ButtonGroup from '@mui/material/ButtonGroup';
|
|
32
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
33
|
+
import Stack from '@mui/material/Stack';
|
|
34
|
+
import Switch from '@mui/material/Switch';
|
|
35
|
+
import TextField from '@mui/material/TextField';
|
|
35
36
|
|
|
36
37
|
import './demo.css';
|
|
37
38
|
|
|
@@ -56,17 +57,17 @@ export default class Page extends React.Component {
|
|
|
56
57
|
|
|
57
58
|
render() {
|
|
58
59
|
return (
|
|
59
|
-
<
|
|
60
|
+
<Stack spacing={2} mt={2}>
|
|
60
61
|
{this.renderControls()}
|
|
61
62
|
{this.renderChessboard()}
|
|
62
63
|
{this.renderCode()}
|
|
63
|
-
</
|
|
64
|
+
</Stack>
|
|
64
65
|
);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
renderControls() {
|
|
68
69
|
return (<>
|
|
69
|
-
<
|
|
70
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
70
71
|
<FormControlLabel label="Flip"
|
|
71
72
|
control={<Switch checked={this.state.flipped} onChange={() => this.set('flipped', !this.state.flipped)} color="primary" />}
|
|
72
73
|
/>
|
|
@@ -76,23 +77,21 @@ export default class Page extends React.Component {
|
|
|
76
77
|
<FormControlLabel label="Animation" disabled={!this.state.positionAfter}
|
|
77
78
|
control={<Switch checked={this.state.animated} onChange={() => this.set('animated', !this.state.animated)} color="primary" />}
|
|
78
79
|
/>
|
|
79
|
-
</
|
|
80
|
-
<
|
|
81
|
-
<TextField label="Move" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
|
|
80
|
+
</Stack>
|
|
81
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
82
|
+
<TextField label="Move" variant="standard" value={this.state.editedMove} onChange={evt => this.set('editedMove', evt.target.value)} />
|
|
82
83
|
<Button color="primary" size="small" variant="contained" onClick={() => this.handlePlayClicked()}>Play</Button>
|
|
83
|
-
<
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
</Box>
|
|
89
|
-
</Box>
|
|
84
|
+
<ButtonGroup color="primary" size="small">
|
|
85
|
+
<Button onClick={() => this.setPosition(new kokopu.Position('empty'))}>Clear</Button>
|
|
86
|
+
<Button onClick={() => this.setPosition(new kokopu.Position())}>Reset</Button>
|
|
87
|
+
</ButtonGroup>
|
|
88
|
+
</Stack>
|
|
90
89
|
</>);
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
renderChessboard() {
|
|
94
93
|
return (
|
|
95
|
-
<Box
|
|
94
|
+
<Box>
|
|
96
95
|
<Chessboard
|
|
97
96
|
position={this.state.position}
|
|
98
97
|
move={this.state.playedMove}
|
|
@@ -115,13 +114,7 @@ export default class Page extends React.Component {
|
|
|
115
114
|
}
|
|
116
115
|
attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
|
|
117
116
|
attributes.push(`animated={${this.state.animated}}`);
|
|
118
|
-
return (
|
|
119
|
-
<Box my={2}>
|
|
120
|
-
<pre className="kokopu-demoCode">
|
|
121
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
122
|
-
</pre>
|
|
123
|
-
</Box>
|
|
124
|
-
);
|
|
117
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
125
118
|
}
|
|
126
119
|
|
|
127
120
|
set(attributeName, newValue) {
|