kokopu-react 1.0.2 → 1.3.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/.nycrc.yml +13 -0
- package/CHANGELOG.md +18 -0
- package/README.md +3 -0
- package/dist/lib/ArrowMarkerIcon.js +1 -1
- package/dist/lib/Chessboard.js +267 -89
- package/dist/lib/{impl/ErrorBox.js → ErrorBox.js} +6 -7
- package/dist/lib/css/chessboard.css +4 -0
- package/dist/lib/i18n.js +35 -0
- package/dist/lib/index.js +16 -0
- package/doc_src/{demo/.eslintrc.yml → .eslintrc.yml} +0 -0
- package/doc_src/demo/PageChessboardBase.js +35 -40
- package/doc_src/demo/PageChessboardEdition.js +70 -70
- package/doc_src/demo/PageChessboardMove.js +20 -27
- package/doc_src/demo/PageChessboardSmallScreens.js +15 -16
- package/doc_src/examples/ErrorBox.md +3 -0
- package/doc_src/theming/LogoRenderer.js +50 -0
- package/doc_src/theming/kokopu-react-logo.png +0 -0
- package/doc_src/theming/theming.css +29 -0
- package/graphic_test_app/02_chessboard_simple.js +1 -0
- package/graphic_test_app/04_chessboard_annotations.js +1 -1
- package/graphic_test_app/05_chessboard_move.js +1 -0
- package/graphic_test_app/07_chessboard_click_squares.js +36 -0
- package/graphic_test_app/08_chessboard_move_pieces.js +36 -0
- package/graphic_test_app/09_chessboard_edit_arrows.js +36 -0
- package/graphic_test_app/10_chessboard_play_moves.js +39 -0
- package/graphic_test_app/11_chessboard_play_promotions.js +35 -0
- package/graphic_test_app/common/test_app.js +14 -0
- package/graphics/logo-small.svg +14 -0
- package/graphics/logo.svg +26 -0
- package/package.json +26 -20
- package/scripts/test_graphic/docker-compose.yml +1 -1
- package/scripts/test_graphic/webpack-config.js +6 -1
- package/scripts/test_headless.webpack-config.js +6 -1
- package/src/Chessboard.js +156 -40
- package/src/{impl/ErrorBox.js → ErrorBox.js} +4 -5
- package/src/css/chessboard.css +4 -0
- package/src/i18n.js +30 -0
- package/src/index.js +2 -0
- package/test/4_chessboard_graphic.js +2 -2
- package/test/5_chessboard_interaction.js +135 -0
- package/test/6_chessboard_play_moves.js +107 -0
- package/test/common/graphic.js +75 -15
- 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/05_chessboard_move/8.png +0 -0
- package/test/references/08_chessboard_move_pieces/after_move.png +0 -0
- package/test/references/08_chessboard_move_pieces/empty_square.png +0 -0
- package/test/references/08_chessboard_move_pieces/null_vector.png +0 -0
- package/test/references/08_chessboard_move_pieces/out_of_board.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_arrow_marker.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_empty.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_non_empty_1.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_non_empty_2.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_square_marker.png +0 -0
- package/test/references/08_chessboard_move_pieces/over_text_marker.png +0 -0
- package/test/references/09_chessboard_edit_arrows/base_1.png +0 -0
- package/test/references/09_chessboard_edit_arrows/base_2.png +0 -0
- package/test/references/09_chessboard_edit_arrows/edit_color_not_set.png +0 -0
- package/test/references/09_chessboard_edit_arrows/null_vector.png +0 -0
- package/test/references/09_chessboard_edit_arrows/out_of_board.png +0 -0
- package/test/references/09_chessboard_edit_arrows/over_arrow_marker.png +0 -0
- package/test/references/09_chessboard_edit_arrows/over_square_marker.png +0 -0
- package/test/references/10_chessboard_play_moves/castling_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_ambiguous_king_move.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_castling_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/chess960_non_kxr_castling.png +0 -0
- package/test/references/10_chessboard_play_moves/illegal_move.png +0 -0
- package/test/references/10_chessboard_play_moves/illegal_position.png +0 -0
- package/test/references/10_chessboard_play_moves/null_vector.png +0 -0
- package/test/references/10_chessboard_play_moves/out_of_board.png +0 -0
- package/test/references/10_chessboard_play_moves/regular_move_1.png +0 -0
- package/test/references/10_chessboard_play_moves/regular_move_2.png +0 -0
- package/test/references/10_chessboard_play_moves/wrong_color.png +0 -0
- package/test/references/11_chessboard_play_promotions/antichess_promotion.png +0 -0
- package/test/references/11_chessboard_play_promotions/cancel_promotion.png +0 -0
- package/test/references/11_chessboard_play_promotions/regular_promotion_1.png +0 -0
- package/test/references/11_chessboard_play_promotions/regular_promotion_2.png +0 -0
|
@@ -9,7 +9,7 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
9
9
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
|
|
12
|
-
require("
|
|
12
|
+
require("./css/error_box.css");
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
15
|
|
|
@@ -38,14 +38,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
|
|
|
38
38
|
* Display an error message.
|
|
39
39
|
*/
|
|
40
40
|
function ErrorBox(props) {
|
|
41
|
-
var message = 'message' in props ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
42
|
-
className: "kokopu-errorMessage"
|
|
43
|
-
}, props.message) : undefined;
|
|
44
41
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
45
42
|
className: "kokopu-errorBox"
|
|
46
43
|
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
47
44
|
className: "kokopu-errorTitle"
|
|
48
|
-
}, props.title),
|
|
45
|
+
}, props.title), /*#__PURE__*/_react["default"].createElement("div", {
|
|
46
|
+
className: "kokopu-errorMessage"
|
|
47
|
+
}, props.message));
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
ErrorBox.propTypes = {
|
|
@@ -55,7 +54,7 @@ ErrorBox.propTypes = {
|
|
|
55
54
|
title: _propTypes["default"].string.isRequired,
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
|
-
*
|
|
57
|
+
* Additional message providing details about the error.
|
|
59
58
|
*/
|
|
60
|
-
message: _propTypes["default"].string
|
|
59
|
+
message: _propTypes["default"].string.isRequired
|
|
61
60
|
};
|
package/dist/lib/i18n.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
* *
|
|
10
|
+
* This file is part of Kokopu-React, a JavaScript chess library. *
|
|
11
|
+
* Copyright (C) 2021 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
12
|
+
* *
|
|
13
|
+
* This program is free software: you can redistribute it and/or *
|
|
14
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
15
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
16
|
+
* the License, or (at your option) any later version. *
|
|
17
|
+
* *
|
|
18
|
+
* This program is distributed in the hope that it will be useful, *
|
|
19
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
20
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
21
|
+
* GNU Lesser General Public License for more details. *
|
|
22
|
+
* *
|
|
23
|
+
* You should have received a copy of the GNU Lesser General *
|
|
24
|
+
* Public License along with this program. If not, see *
|
|
25
|
+
* <http://www.gnu.org/licenses/>. *
|
|
26
|
+
* *
|
|
27
|
+
******************************************************************************/
|
|
28
|
+
var i18n = {
|
|
29
|
+
INVALID_FEN_ERROR_TITLE: 'Invalid FEN string.',
|
|
30
|
+
INVALID_NOTATION_ERROR_TITLE: 'Invalid move notation.',
|
|
31
|
+
INVALID_POSITION_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "position" attribute.',
|
|
32
|
+
INVALID_MOVE_ATTRIBUTE_ERROR_MESSAGE: 'Invalid "move" attribute.'
|
|
33
|
+
};
|
|
34
|
+
var _default = i18n;
|
|
35
|
+
exports["default"] = _default;
|
package/dist/lib/index.js
CHANGED
|
@@ -39,12 +39,24 @@ Object.defineProperty(exports, "parseArrowMarkers", {
|
|
|
39
39
|
return _markers.parseArrowMarkers;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "i18n", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function get() {
|
|
45
|
+
return _i18n["default"];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
42
48
|
Object.defineProperty(exports, "Chessboard", {
|
|
43
49
|
enumerable: true,
|
|
44
50
|
get: function get() {
|
|
45
51
|
return _Chessboard["default"];
|
|
46
52
|
}
|
|
47
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "ErrorBox", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _ErrorBox["default"];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
48
60
|
Object.defineProperty(exports, "SquareMarkerIcon", {
|
|
49
61
|
enumerable: true,
|
|
50
62
|
get: function get() {
|
|
@@ -66,8 +78,12 @@ Object.defineProperty(exports, "ArrowMarkerIcon", {
|
|
|
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"));
|
|
File without changes
|
|
@@ -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) {
|
|
@@ -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,54 +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)" />
|
|
106
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
107
107
|
<FormControlLabel value="editSquareMarkers" control={<Radio color="primary" />} label="Edit square annotations" />
|
|
108
108
|
{this.renderMarkerColorSelector('squareMarkerColor', 'editSquareMarkers')}
|
|
109
|
-
</
|
|
110
|
-
<
|
|
109
|
+
</Stack>
|
|
110
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
111
111
|
<FormControlLabel value="editTextMarkers" control={<Radio color="primary" />} label="Edit text annotations" />
|
|
112
112
|
{this.renderMarkerColorSelector('textMarkerColor', 'editTextMarkers')}
|
|
113
113
|
{this.renderTextMarkerSymbolSelector()}
|
|
114
|
-
</
|
|
115
|
-
<
|
|
114
|
+
</Stack>
|
|
115
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
116
116
|
<FormControlLabel value="editArrowMarkers" control={<Radio color="primary" />} label="Edit arrow annotations" />
|
|
117
117
|
{this.renderMarkerColorSelector('arrowMarkerColor', 'editArrowMarkers')}
|
|
118
|
-
</
|
|
118
|
+
</Stack>
|
|
119
119
|
</RadioGroup>
|
|
120
120
|
</Box>
|
|
121
121
|
</>);
|
|
@@ -127,28 +127,24 @@ export default class Page extends React.Component {
|
|
|
127
127
|
}
|
|
128
128
|
let pieceset = Chessboard.piecesets()['cburnett'];
|
|
129
129
|
return (
|
|
130
|
-
<
|
|
131
|
-
<
|
|
132
|
-
<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
<ToggleButton value="bp"><img src={pieceset.bp} width={PIECE_ICON_SIZE} height={PIECE_ICON_SIZE} /></ToggleButton>
|
|
149
|
-
</ToggleButtonGroup>
|
|
150
|
-
</Box>
|
|
151
|
-
</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>
|
|
152
148
|
);
|
|
153
149
|
}
|
|
154
150
|
|
|
@@ -157,7 +153,7 @@ export default class Page extends React.Component {
|
|
|
157
153
|
return undefined;
|
|
158
154
|
}
|
|
159
155
|
return (
|
|
160
|
-
<Select value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
156
|
+
<Select variant="standard" value={this.state.textMarkerSymbol} onChange={evt => this.set('textMarkerSymbol', evt.target.value)}>
|
|
161
157
|
{[...'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'].map(mode => <MenuItem key={mode} value={mode}>{mode}</MenuItem>)}
|
|
162
158
|
</Select>
|
|
163
159
|
);
|
|
@@ -169,13 +165,11 @@ export default class Page extends React.Component {
|
|
|
169
165
|
}
|
|
170
166
|
let colorset = Chessboard.colorsets()['original'];
|
|
171
167
|
return (
|
|
172
|
-
<
|
|
173
|
-
<
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
</ToggleButtonGroup>
|
|
178
|
-
</Box>
|
|
168
|
+
<ToggleButtonGroup value={this.state[attributeName]} exclusive size="small" onChange={(_, newColor) => this.setIfNonNull(attributeName, newColor)}>
|
|
169
|
+
<ToggleButton className="kokopu-fixTextTransform" value="g">{this.renderColorButtonLabel(colorset.g)}</ToggleButton>
|
|
170
|
+
<ToggleButton className="kokopu-fixTextTransform" value="r">{this.renderColorButtonLabel(colorset.r)}</ToggleButton>
|
|
171
|
+
<ToggleButton className="kokopu-fixTextTransform" value="y">{this.renderColorButtonLabel(colorset.y)}</ToggleButton>
|
|
172
|
+
</ToggleButtonGroup>
|
|
179
173
|
);
|
|
180
174
|
}
|
|
181
175
|
|
|
@@ -194,7 +188,7 @@ export default class Page extends React.Component {
|
|
|
194
188
|
|
|
195
189
|
renderChessboard() {
|
|
196
190
|
return (
|
|
197
|
-
<Box
|
|
191
|
+
<Box>
|
|
198
192
|
<Chessboard
|
|
199
193
|
position={this.state.position}
|
|
200
194
|
flipped={this.state.flipped}
|
|
@@ -204,6 +198,7 @@ export default class Page extends React.Component {
|
|
|
204
198
|
interactionMode={this.getChessboardInterationMode()}
|
|
205
199
|
editedArrowColor={this.state.arrowMarkerColor}
|
|
206
200
|
onPieceMoved={(from, to) => this.handlePieceMoved(from, to)}
|
|
201
|
+
onMovePlayed={move => this.handleMovePlayed(move)}
|
|
207
202
|
onArrowEdited={(from, to) => this.handleArrowEdited(from, to)}
|
|
208
203
|
onSquareClicked={sq => this.handleSquareClicked(sq)}
|
|
209
204
|
/>
|
|
@@ -248,16 +243,14 @@ export default class Page extends React.Component {
|
|
|
248
243
|
attributes.push('interactionMode="movePieces"');
|
|
249
244
|
attributes.push('onPieceMoved={(from, to) => handlePieceMoved(from, to)}');
|
|
250
245
|
break;
|
|
246
|
+
case 'playMoves':
|
|
247
|
+
attributes.push('interactionMode="playMoves"');
|
|
248
|
+
attributes.push('onMovePlayed={move => handleMovePlayed(move)}');
|
|
249
|
+
break;
|
|
251
250
|
default:
|
|
252
251
|
break;
|
|
253
252
|
}
|
|
254
|
-
return (
|
|
255
|
-
<Box my={2}>
|
|
256
|
-
<pre className="kokopu-demoCode">
|
|
257
|
-
{buildComponentDemoCode('Chessboard', attributes)}
|
|
258
|
-
</pre>
|
|
259
|
-
</Box>
|
|
260
|
-
);
|
|
253
|
+
return <pre className="kokopu-demoCode">{buildComponentDemoCode('Chessboard', attributes)}</pre>;
|
|
261
254
|
}
|
|
262
255
|
|
|
263
256
|
set(attributeName, newValue) {
|
|
@@ -285,6 +278,12 @@ export default class Page extends React.Component {
|
|
|
285
278
|
this.set('position', newPosition);
|
|
286
279
|
}
|
|
287
280
|
|
|
281
|
+
handleMovePlayed(move) {
|
|
282
|
+
let newPosition = new kokopu.Position(this.state.position);
|
|
283
|
+
newPosition.play(move);
|
|
284
|
+
this.set('position', newPosition);
|
|
285
|
+
}
|
|
286
|
+
|
|
288
287
|
handleArrowEdited(from, to) {
|
|
289
288
|
let newArrowMarkers = {...this.state.arrowMarkers};
|
|
290
289
|
let key = from + to;
|
|
@@ -334,7 +333,8 @@ export default class Page extends React.Component {
|
|
|
334
333
|
case 'editArrowMarkers':
|
|
335
334
|
return 'editArrows';
|
|
336
335
|
case 'movePieces':
|
|
337
|
-
|
|
336
|
+
case 'playMoves':
|
|
337
|
+
return this.state.interactionMode;
|
|
338
338
|
default:
|
|
339
339
|
return undefined;
|
|
340
340
|
}
|
|
@@ -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) {
|