kokopu-react 3.0.2 → 3.2.0
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/.eslintrc.yml +1 -1
- package/CHANGELOG.md +13 -1
- package/dist/lib/chessboard/BoardProperties.d.ts +91 -0
- package/dist/lib/chessboard/BoardProperties.js +43 -0
- package/dist/lib/chessboard/BoardProperties.js.map +1 -0
- package/dist/lib/chessboard/Chessboard.css +13 -13
- package/dist/lib/chessboard/Chessboard.d.ts +14 -58
- package/dist/lib/chessboard/Chessboard.js +26 -92
- package/dist/lib/chessboard/Chessboard.js.map +1 -1
- package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
- package/dist/lib/chessboard/Draggable.js.map +1 -1
- package/dist/lib/chessboard/Motion.js.map +1 -1
- package/dist/lib/chessboard/colorsets.js.map +1 -1
- package/dist/lib/chessboard/piecesets.js.map +1 -1
- package/dist/lib/errorbox/ErrorBox.css +18 -18
- package/dist/lib/errorbox/ErrorBox.js.map +1 -1
- package/dist/lib/errorbox/parsing.d.ts +57 -0
- package/dist/lib/errorbox/parsing.js +140 -0
- package/dist/lib/errorbox/parsing.js.map +1 -0
- package/dist/lib/exception.js.map +1 -1
- package/dist/lib/i18n.d.ts +6 -0
- package/dist/lib/i18n.js +7 -0
- package/dist/lib/i18n.js.map +1 -1
- package/dist/lib/icons/AnnotationSymbolShape.css +6 -6
- package/dist/lib/icons/AnnotationSymbolShape.js.map +1 -1
- package/dist/lib/icons/ArrowMarkerIcon.js.map +1 -1
- package/dist/lib/icons/ArrowTip.js.map +1 -1
- package/dist/lib/icons/ChessPieceIcon.js.map +1 -1
- package/dist/lib/icons/SquareMarkerIcon.js.map +1 -1
- package/dist/lib/icons/TextMarkerIcon.js.map +1 -1
- package/dist/lib/icons/arrow.css +1 -1
- package/dist/lib/index.d.ts +5 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/movetext/Movetext.css +27 -40
- package/dist/lib/movetext/Movetext.d.ts +9 -43
- package/dist/lib/movetext/Movetext.js +15 -67
- package/dist/lib/movetext/Movetext.js.map +1 -1
- package/dist/lib/movetext/MovetextImpl.d.ts +7 -28
- package/dist/lib/movetext/MovetextImpl.js +15 -94
- package/dist/lib/movetext/MovetextImpl.js.map +1 -1
- package/dist/lib/movetext/fonts.css +7 -7
- package/dist/lib/movetext/htmlFilter.js.map +1 -1
- package/dist/lib/movetext/moveFormatter.js.map +1 -1
- package/dist/lib/navigationboard/NavigationBoard.d.ts +156 -0
- package/dist/lib/navigationboard/NavigationBoard.js +195 -0
- package/dist/lib/navigationboard/NavigationBoard.js.map +1 -0
- package/dist/lib/navigationboard/NavigationButton.d.ts +54 -0
- package/dist/lib/navigationboard/NavigationButton.js +35 -0
- package/dist/lib/navigationboard/NavigationButton.js.map +1 -0
- package/dist/lib/navigationboard/NavigationField.css +36 -0
- package/dist/lib/navigationboard/NavigationField.d.ts +81 -0
- package/dist/lib/navigationboard/NavigationField.js +154 -0
- package/dist/lib/navigationboard/NavigationField.js.map +1 -0
- package/dist/lib/navigationboard/NavigationToolbar.css +54 -0
- package/dist/lib/navigationboard/NavigationToolbar.d.ts +34 -0
- package/dist/lib/navigationboard/NavigationToolbar.js +73 -0
- package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -0
- package/dist/lib/navigationboard/iconPaths.d.ts +29 -0
- package/dist/lib/navigationboard/iconPaths.js +91 -0
- package/dist/lib/navigationboard/iconPaths.js.map +1 -0
- package/dist/lib/sanitization.js.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/util.js.map +1 -1
- package/doc_src/demo/PageChessboardBase.tsx +115 -115
- package/doc_src/demo/PageChessboardInteraction.tsx +303 -303
- package/doc_src/demo/PageChessboardMove.tsx +173 -156
- package/doc_src/demo/PageChessboardSmallScreens.tsx +94 -94
- package/doc_src/demo/PageMovetextBase.tsx +180 -180
- package/doc_src/demo/PageMovetextInteraction.tsx +123 -123
- package/doc_src/demo/PageNavigationBoardBase.tsx +201 -0
- package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +114 -0
- package/doc_src/demo/decs.d.ts +4 -4
- package/doc_src/demo/demo.css +12 -12
- package/doc_src/demo/game-3.pgn +10 -0
- package/doc_src/demo/util.ts +1 -1
- package/doc_src/examples/Movetext.md +1 -1
- package/doc_src/examples/NavigationBoard.md +15 -0
- package/doc_src/theming/LogoRenderer.js +13 -13
- package/doc_src/theming/theming.css +5 -5
- package/package.json +95 -95
- package/scripts/doc.styleguide.config.js +133 -123
- package/scripts/doc.tsconfig.json +5 -5
- package/scripts/docker-compose.yml +1 -1
- package/scripts/test-graphic.tsconfig.json +5 -5
- package/scripts/test-graphic.webpack.config.js +57 -57
- package/scripts/test-headless.webpack.config.js +29 -29
- package/src/chessboard/BoardProperties.ts +131 -0
- package/src/chessboard/Chessboard.css +13 -13
- package/src/chessboard/Chessboard.tsx +389 -518
- package/src/chessboard/ChessboardImpl.tsx +557 -557
- package/src/chessboard/Draggable.tsx +185 -185
- package/src/chessboard/Motion.tsx +67 -67
- package/src/chessboard/colorsets.ts +66 -66
- package/src/chessboard/piecesets.ts +84 -84
- package/src/decs.d.ts +2 -2
- package/src/errorbox/ErrorBox.css +18 -18
- package/src/errorbox/ErrorBox.tsx +75 -75
- package/src/errorbox/parsing.tsx +158 -0
- package/src/exception.ts +17 -17
- package/src/i18n.ts +8 -0
- package/src/icons/AnnotationSymbolShape.css +6 -6
- package/src/icons/AnnotationSymbolShape.tsx +31 -31
- package/src/icons/ArrowMarkerIcon.tsx +34 -34
- package/src/icons/ArrowTip.tsx +14 -14
- package/src/icons/ChessPieceIcon.tsx +45 -45
- package/src/icons/SquareMarkerIcon.tsx +20 -20
- package/src/icons/TextMarkerIcon.tsx +29 -29
- package/src/icons/arrow.css +1 -1
- package/src/index.ts +8 -3
- package/src/movetext/Movetext.css +27 -40
- package/src/movetext/Movetext.tsx +163 -228
- package/src/movetext/MovetextImpl.tsx +351 -438
- package/src/movetext/fonts.css +7 -7
- package/src/movetext/htmlFilter.tsx +129 -129
- package/src/movetext/moveFormatter.tsx +37 -37
- package/src/navigationboard/NavigationBoard.tsx +350 -0
- package/src/navigationboard/NavigationButton.ts +72 -0
- package/src/navigationboard/NavigationField.css +36 -0
- package/src/navigationboard/NavigationField.tsx +185 -0
- package/src/navigationboard/NavigationToolbar.css +54 -0
- package/src/navigationboard/NavigationToolbar.tsx +117 -0
- package/src/navigationboard/iconPaths.ts +98 -0
- package/src/sanitization.ts +17 -17
- package/src/types.ts +116 -116
- package/src/util.ts +11 -11
- package/test/01_types.js +167 -167
- package/test/02_chessboard_util.js +114 -114
- package/test/03_error_box_graphic.js +16 -16
- package/test/04_icons_graphic.js +32 -32
- package/test/05_chessboard_graphic.js +60 -58
- package/test/06_chessboard_animation.js +36 -36
- package/test/07_chessboard_interaction.js +101 -101
- package/test/08_chessboard_play_moves.js +62 -62
- package/test/09_chessboard_small_screens.js +42 -21
- package/test/10_movetext_graphic.js +36 -31
- package/test/11_movetext_interaction.js +100 -96
- package/test/12_navigation_board_base.js +151 -0
- package/test/13_navigation_board_graphic.js +68 -0
- package/test/14_navigation_board_autoplay.js +100 -0
- package/test/common/graphic.js +106 -97
- package/test/graphic_references/05_chessboard_graphic/move/illegal_null-move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/null-move.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_bottom_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_top_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_bottom_component.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_top_component.png +0 -0
- package/test/graphic_references/10_movetext_graphic/format_move/format_text.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/wrong_piece_symbol_value.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected_without_callback.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/default.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/forbidden_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/forbidden_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/invalid_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/no_callback_defined_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/no_callback_defined_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/overriding_initial_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board_base/controlled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_beginning_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_beginning_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_beginning_2.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_end_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_end_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/forbidden_navigation_at_end_2.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/initial_state_at_end.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/initial_state_at_specific_id.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/initial_state_default.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/initial_state_default_with_game_index.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/initial_state_on_null-move.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/navigation_with_keys_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/navigation_with_keys_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/navigation_with_keys_2.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/navigation_with_keys_3.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/navigation_with_keys_4.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_flipping_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_flipping_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_4.png +0 -0
- package/test/graphic_references/12_navigation_board_base/uncontrolled/regular_navigation_5.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/additional_buttons/error_1.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/additional_buttons/error_2.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/additional_buttons/multiple_buttons.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/additional_buttons/single_button.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/error/pgn_parsing_error.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/error/wrong_game_type.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/theme/custom_1.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/theme/custom_2.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/theme/large.png +0 -0
- package/test/graphic_references/13_navigation_board_graphic/theme/small.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/after_1_move_acknowledging_is-playing_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/after_1_move_not_acknowledging_is-playing_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/after_2_moves_acknowledging_node_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/after_2_moves_not_acknowledging_node_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/after_reaching_the_end.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/already_at_the_end.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_acknowledging_is-playing_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_acknowledging_node_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_at_the_end.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_close_to_end.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_not_acknowledging_is-playing_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/controlled/initial_state_not_acknowledging_node_changes.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/after_2_moves_from_beginning_after_stop.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/after_2_moves_from_beginning_before_stop.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/after_reaching_the_end_after_stop.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/after_reaching_the_end_before_stop.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/initial_state_close_to_end.png +0 -0
- package/test/graphic_references/14_navigation_board_autoplay/uncontrolled/initial_state_default.png +0 -0
- package/test/graphic_test_app/03_error_box_graphic/base.tsx +14 -14
- package/test/graphic_test_app/03_error_box_graphic/localization.tsx +1 -1
- package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +7 -7
- package/test/graphic_test_app/04_icons_graphic/marker.tsx +15 -15
- package/test/graphic_test_app/05_chessboard_graphic/annotations.tsx +7 -7
- package/test/graphic_test_app/05_chessboard_graphic/base.tsx +6 -6
- package/test/graphic_test_app/05_chessboard_graphic/chess_variants.tsx +7 -7
- package/test/graphic_test_app/05_chessboard_graphic/flipped.tsx +5 -5
- package/test/graphic_test_app/05_chessboard_graphic/move.tsx +12 -10
- package/test/graphic_test_app/05_chessboard_graphic/theme.tsx +12 -12
- package/test/graphic_test_app/06_chessboard_animation/base_1.tsx +6 -6
- package/test/graphic_test_app/06_chessboard_animation/base_2.tsx +6 -6
- package/test/graphic_test_app/06_chessboard_animation/base_3.tsx +6 -6
- package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +16 -16
- package/test/graphic_test_app/07_chessboard_interaction/click_squares.tsx +5 -5
- package/test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx +4 -4
- package/test/graphic_test_app/07_chessboard_interaction/error.tsx +2 -2
- package/test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx +5 -5
- package/test/graphic_test_app/08_chessboard_play_moves/base.tsx +8 -8
- package/test/graphic_test_app/08_chessboard_play_moves/promotions.tsx +4 -4
- package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +9 -9
- package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +48 -0
- package/test/graphic_test_app/10_movetext_graphic/base.tsx +4 -4
- package/test/graphic_test_app/10_movetext_graphic/error.tsx +6 -6
- package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +31 -0
- package/test/graphic_test_app/10_movetext_graphic/html.tsx +5 -5
- package/test/graphic_test_app/10_movetext_graphic/options.tsx +10 -9
- package/test/graphic_test_app/11_movetext_interaction/error.tsx +1 -1
- package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +11 -10
- package/test/graphic_test_app/12_navigation_board_base/controlled.tsx +43 -0
- package/test/graphic_test_app/12_navigation_board_base/uncontrolled.tsx +56 -0
- package/test/graphic_test_app/13_navigation_board_graphic/additional_buttons.tsx +49 -0
- package/test/graphic_test_app/13_navigation_board_graphic/error.tsx +34 -0
- package/test/graphic_test_app/13_navigation_board_graphic/theme.tsx +38 -0
- package/test/graphic_test_app/14_navigation_board_autoplay/controlled.tsx +73 -0
- package/test/graphic_test_app/14_navigation_board_autoplay/uncontrolled.tsx +34 -0
- package/test/graphic_test_app/common/decs.d.ts +2 -2
- package/test/graphic_test_app/common/test_app.css +15 -15
- package/test/graphic_test_app/common/test_app.tsx +48 -48
- package/tsconfig.json +13 -13
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
3
|
+
* *
|
|
4
|
+
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
|
+
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
+
* Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
|
+
* *
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
10
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
11
|
+
* the License, or (at your option) any later version. *
|
|
12
|
+
* *
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
16
|
+
* GNU Lesser General Public License for more details. *
|
|
17
|
+
* *
|
|
18
|
+
* You should have received a copy of the GNU Lesser General *
|
|
19
|
+
* Public License along with this program. If not, see *
|
|
20
|
+
* <http://www.gnu.org/licenses/>. *
|
|
21
|
+
* *
|
|
22
|
+
* -------------------------------------------------------------------------- */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import * as React from 'react';
|
|
26
|
+
|
|
27
|
+
import { AnnotationColor, ArrowMarkerIcon, Chessboard, NavigationBoard } from '../../src/index';
|
|
28
|
+
import { buildComponentDemoCode } from './util';
|
|
29
|
+
|
|
30
|
+
import Box from '@mui/material/Box';
|
|
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 ToggleButton from '@mui/material/ToggleButton';
|
|
40
|
+
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
|
|
41
|
+
import Typography from '@mui/material/Typography';
|
|
42
|
+
|
|
43
|
+
import './demo.css';
|
|
44
|
+
import pgn from './game-3.pgn';
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const COLOR_ICON_SIZE = 16;
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
interface PageState {
|
|
51
|
+
squareSize: number;
|
|
52
|
+
coordinateVisible: boolean;
|
|
53
|
+
turnVisible: boolean;
|
|
54
|
+
colorset: string;
|
|
55
|
+
pieceset: string;
|
|
56
|
+
moveArrowVisible: boolean;
|
|
57
|
+
moveArrowColor: AnnotationColor;
|
|
58
|
+
animated: boolean;
|
|
59
|
+
playButtonVisible: boolean;
|
|
60
|
+
flipButtonVisible: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
export default class Page extends React.Component<object, PageState> {
|
|
65
|
+
|
|
66
|
+
constructor(props: object) {
|
|
67
|
+
super(props);
|
|
68
|
+
this.state = {
|
|
69
|
+
squareSize: 40,
|
|
70
|
+
coordinateVisible: true,
|
|
71
|
+
turnVisible: true,
|
|
72
|
+
colorset: 'original',
|
|
73
|
+
pieceset: 'cburnett',
|
|
74
|
+
moveArrowVisible: true,
|
|
75
|
+
moveArrowColor: 'b',
|
|
76
|
+
animated: true,
|
|
77
|
+
playButtonVisible: true,
|
|
78
|
+
flipButtonVisible: true,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
render() {
|
|
83
|
+
return (
|
|
84
|
+
<Stack spacing={2} mt={2}>
|
|
85
|
+
{this.renderControls()}
|
|
86
|
+
{this.renderNavigationBoard()}
|
|
87
|
+
{this.renderCode()}
|
|
88
|
+
</Stack>
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private renderControls() {
|
|
93
|
+
return (<>
|
|
94
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
95
|
+
<FormControlLabel label="Show play/stop button"
|
|
96
|
+
control={<Switch checked={this.state.playButtonVisible} onChange={() => this.setState({ playButtonVisible: !this.state.playButtonVisible })} color="primary" />}
|
|
97
|
+
/>
|
|
98
|
+
<FormControlLabel label="Show flip button"
|
|
99
|
+
control={<Switch checked={this.state.flipButtonVisible} onChange={() => this.setState({ flipButtonVisible: !this.state.flipButtonVisible })} color="primary" />}
|
|
100
|
+
/>
|
|
101
|
+
<FormControlLabel label="Show coordinates"
|
|
102
|
+
control={<Switch checked={this.state.coordinateVisible} onChange={() => this.setState({ coordinateVisible: !this.state.coordinateVisible })} color="primary" />}
|
|
103
|
+
/>
|
|
104
|
+
<FormControlLabel label="Show turn"
|
|
105
|
+
control={<Switch checked={this.state.turnVisible} onChange={() => this.setState({ turnVisible: !this.state.turnVisible })} color="primary" />}
|
|
106
|
+
/>
|
|
107
|
+
<FormControlLabel label="Animated"
|
|
108
|
+
control={<Switch checked={this.state.animated} onChange={() => this.setState({ animated: !this.state.animated })} color="primary" />}
|
|
109
|
+
/>
|
|
110
|
+
</Stack>
|
|
111
|
+
<Box>
|
|
112
|
+
<Typography gutterBottom>Square size</Typography>
|
|
113
|
+
<Slider
|
|
114
|
+
value={this.state.squareSize} onChange={(_, newValue) => this.setState({ squareSize: newValue as number })}
|
|
115
|
+
min={Chessboard.minSquareSize()} max={Chessboard.maxSquareSize()} step={1} valueLabelDisplay="on" color="primary"
|
|
116
|
+
/>
|
|
117
|
+
</Box>
|
|
118
|
+
<Stack direction="row" spacing={2} alignItems="center">
|
|
119
|
+
<FormControl variant="standard">
|
|
120
|
+
<InputLabel id="colorset-label">Colorset</InputLabel>
|
|
121
|
+
<Select labelId="colorset-label" sx={{ width: '8em' }} value={this.state.colorset} onChange={evt => this.setState({ colorset: evt.target.value })}>
|
|
122
|
+
{Object.keys(Chessboard.colorsets()).sort().map(colorset => <MenuItem key={colorset} value={colorset}>{colorset}</MenuItem>)}
|
|
123
|
+
</Select>
|
|
124
|
+
</FormControl>
|
|
125
|
+
<FormControl variant="standard">
|
|
126
|
+
<InputLabel id="pieceset-label">Pieceset</InputLabel>
|
|
127
|
+
<Select labelId="pieceset-label" sx={{ width: '8em' }} value={this.state.pieceset} onChange={evt => this.setState({ pieceset: evt.target.value })}>
|
|
128
|
+
{Object.keys(Chessboard.piecesets()).sort().map(pieceset => <MenuItem key={pieceset} value={pieceset}>{pieceset}</MenuItem>)}
|
|
129
|
+
</Select>
|
|
130
|
+
</FormControl>
|
|
131
|
+
<FormControlLabel label="Show move arrow"
|
|
132
|
+
control={<Switch checked={this.state.moveArrowVisible} onChange={() => this.setState({ moveArrowVisible: !this.state.moveArrowVisible })} color="primary" />}
|
|
133
|
+
/>
|
|
134
|
+
{this.renderMoveArrowColorSelector()}
|
|
135
|
+
</Stack>
|
|
136
|
+
</>);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private renderMoveArrowColorSelector() {
|
|
140
|
+
if (!this.state.moveArrowVisible) {
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
const colorset = Chessboard.colorsets()['original'];
|
|
144
|
+
return (
|
|
145
|
+
<ToggleButtonGroup value={this.state.moveArrowColor} exclusive size="small" onChange={(_, newColor) => this.handleMoveArrowColorChanged(newColor)}>
|
|
146
|
+
<ToggleButton value="b"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cb} /></ToggleButton>
|
|
147
|
+
<ToggleButton value="g"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cg} /></ToggleButton>
|
|
148
|
+
<ToggleButton value="r"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cr} /></ToggleButton>
|
|
149
|
+
<ToggleButton value="y"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cy} /></ToggleButton>
|
|
150
|
+
</ToggleButtonGroup>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private renderNavigationBoard() {
|
|
155
|
+
return (
|
|
156
|
+
<Box>
|
|
157
|
+
<NavigationBoard
|
|
158
|
+
game={pgn}
|
|
159
|
+
initialNodeId="end"
|
|
160
|
+
squareSize={this.state.squareSize}
|
|
161
|
+
coordinateVisible={this.state.coordinateVisible}
|
|
162
|
+
turnVisible={this.state.turnVisible}
|
|
163
|
+
colorset={this.state.colorset}
|
|
164
|
+
pieceset={this.state.pieceset}
|
|
165
|
+
moveArrowVisible={this.state.moveArrowVisible}
|
|
166
|
+
moveArrowColor={this.state.moveArrowColor}
|
|
167
|
+
animated={this.state.animated}
|
|
168
|
+
playButtonVisible={this.state.playButtonVisible}
|
|
169
|
+
flipButtonVisible={this.state.flipButtonVisible}
|
|
170
|
+
/>
|
|
171
|
+
</Box>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private renderCode() {
|
|
176
|
+
const attributes: string[] = [];
|
|
177
|
+
attributes.push('game={pgn}');
|
|
178
|
+
attributes.push('initialNodeId="end"');
|
|
179
|
+
attributes.push(`squareSize={${this.state.squareSize}}`);
|
|
180
|
+
attributes.push(`coordinateVisible={${this.state.coordinateVisible}}`);
|
|
181
|
+
attributes.push(`turnVisible={${this.state.turnVisible}}`);
|
|
182
|
+
attributes.push(`colorset="${this.state.colorset}"`);
|
|
183
|
+
attributes.push(`pieceset="${this.state.pieceset}"`);
|
|
184
|
+
attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
|
|
185
|
+
if (this.state.moveArrowVisible) {
|
|
186
|
+
attributes.push(`moveArrowColor="${this.state.moveArrowColor}"`);
|
|
187
|
+
}
|
|
188
|
+
attributes.push(`animated={${this.state.animated}}`);
|
|
189
|
+
attributes.push(`playButtonVisible={${this.state.playButtonVisible}}`);
|
|
190
|
+
attributes.push(`flipButtonVisible={${this.state.flipButtonVisible}}`);
|
|
191
|
+
const pgnDeclaration = 'const pgn = `\n' + pgn.trim() + '`;\n\n';
|
|
192
|
+
return <pre className="kokopu-demoCode">{pgnDeclaration + buildComponentDemoCode('NavigationBoard', attributes)}</pre>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private handleMoveArrowColorChanged(newColor: AnnotationColor | null) {
|
|
196
|
+
if (newColor !== null) {
|
|
197
|
+
this.setState({ moveArrowColor: newColor });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
3
|
+
* *
|
|
4
|
+
* Kokopu-React - A React-based library of chess-related components. *
|
|
5
|
+
* <https://www.npmjs.com/package/kokopu-react> *
|
|
6
|
+
* Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
|
|
7
|
+
* *
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
9
|
+
* modify it under the terms of the GNU Lesser General Public License *
|
|
10
|
+
* as published by the Free Software Foundation, either version 3 of *
|
|
11
|
+
* the License, or (at your option) any later version. *
|
|
12
|
+
* *
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
16
|
+
* GNU Lesser General Public License for more details. *
|
|
17
|
+
* *
|
|
18
|
+
* You should have received a copy of the GNU Lesser General *
|
|
19
|
+
* Public License along with this program. If not, see *
|
|
20
|
+
* <http://www.gnu.org/licenses/>. *
|
|
21
|
+
* *
|
|
22
|
+
* -------------------------------------------------------------------------- */
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import * as React from 'react';
|
|
26
|
+
|
|
27
|
+
import { NavigationBoard } from '../../src/index';
|
|
28
|
+
import { buildComponentDemoCode } from './util';
|
|
29
|
+
|
|
30
|
+
import Box from '@mui/material/Box';
|
|
31
|
+
import Stack from '@mui/material/Stack';
|
|
32
|
+
import Typography from '@mui/material/Typography';
|
|
33
|
+
|
|
34
|
+
import './demo.css';
|
|
35
|
+
import pgn from './game-3.pgn';
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
interface PageState {
|
|
39
|
+
nodeId: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export default class Page extends React.Component<object, PageState> {
|
|
44
|
+
|
|
45
|
+
constructor(props: object) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.state = {
|
|
48
|
+
nodeId: '9b',
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
render() {
|
|
53
|
+
return (
|
|
54
|
+
<Stack spacing={2} mt={2}>
|
|
55
|
+
{this.renderControls()}
|
|
56
|
+
{this.renderNavigationBoards()}
|
|
57
|
+
{this.renderCode()}
|
|
58
|
+
</Stack>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private renderControls() {
|
|
63
|
+
return (<>
|
|
64
|
+
<Typography>
|
|
65
|
+
In uncontrolled mode, the current node ID (aka. the current move) of the <code>NavigationBoard</code> component is managed internally.
|
|
66
|
+
No additional code is needed to make the navigation buttons work.
|
|
67
|
+
</Typography>
|
|
68
|
+
<Typography>
|
|
69
|
+
In controlled mode, the current node ID is defined by the <code>nodeId</code> attribute, and a callback must be set
|
|
70
|
+
on the <code>onNodeIdChanged</code> attribute to respond to clicks on the navigation buttons.
|
|
71
|
+
This mode requires more code, as a state variable holding the current node ID must be explicitely managed out of the component,
|
|
72
|
+
but it allows to define more complex behaviors (e.g. synchronizing the node ID on the <code>NavigationBoard</code> with another component).
|
|
73
|
+
</Typography>
|
|
74
|
+
<Typography>
|
|
75
|
+
Whether the component is in uncontrolled mode or controlled mode depends on the presence of the <code>nodeId</code> attribute.
|
|
76
|
+
</Typography>
|
|
77
|
+
</>);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private renderNavigationBoards() {
|
|
81
|
+
return (
|
|
82
|
+
<Box display="flex" alignItems="top" justifyContent="space-around">
|
|
83
|
+
<Box>
|
|
84
|
+
<NavigationBoard game={pgn} animated initialNodeId="9b" />
|
|
85
|
+
<Typography mt={2} textAlign="center">Uncontrolled</Typography>
|
|
86
|
+
</Box>
|
|
87
|
+
<Box>
|
|
88
|
+
<NavigationBoard game={pgn} animated nodeId={this.state.nodeId} onNodeIdChanged={nodeId => this.setState({ nodeId: nodeId })} />
|
|
89
|
+
<Typography mt={2} textAlign="center">Controlled</Typography>
|
|
90
|
+
<Typography textAlign="center">{`Current node ID: ${this.state.nodeId}`}</Typography>
|
|
91
|
+
</Box>
|
|
92
|
+
</Box>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private renderCode() {
|
|
97
|
+
|
|
98
|
+
const uncontrolledAttributes: string[] = [];
|
|
99
|
+
uncontrolledAttributes.push('game={pgn}');
|
|
100
|
+
uncontrolledAttributes.push('animated');
|
|
101
|
+
uncontrolledAttributes.push('initialNodeId="9b"');
|
|
102
|
+
|
|
103
|
+
const controlledAttributes: string[] = [];
|
|
104
|
+
controlledAttributes.push('game={pgn}');
|
|
105
|
+
controlledAttributes.push('animated');
|
|
106
|
+
controlledAttributes.push(`nodeId="${this.state.nodeId}"`);
|
|
107
|
+
controlledAttributes.push('onNodeIdChanged={nodeId => handleNodeIdChanged(nodeId)}');
|
|
108
|
+
|
|
109
|
+
const pgnDeclaration = 'const pgn = `\n' + pgn.trim() + '`;\n\n';
|
|
110
|
+
return <pre className="kokopu-demoCode">{pgnDeclaration + '// Uncontrolled\n' + buildComponentDemoCode('NavigationBoard', uncontrolledAttributes)
|
|
111
|
+
+ '\n\n// Controlled\n' + buildComponentDemoCode('NavigationBoard', controlledAttributes)}</pre>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
package/doc_src/demo/decs.d.ts
CHANGED
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
declare module '*.pgn' {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const pgnText: string;
|
|
27
|
+
export default pgnText;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
declare module '*.png' {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const path: string;
|
|
32
|
+
export default path;
|
|
33
33
|
}
|
package/doc_src/demo/demo.css
CHANGED
|
@@ -23,25 +23,25 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
.kokopu-demoCode {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
border: 1px solid rgb(232, 232, 232);
|
|
27
|
+
border-radius: 3px;
|
|
28
|
+
background-color: rgb(245, 245, 245);
|
|
29
|
+
font-size: 13px;
|
|
30
|
+
padding: 16px;
|
|
31
|
+
white-space: pre-wrap;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
.MuiToggleButton-root.kokopu-fixTextTransform {
|
|
35
|
-
|
|
35
|
+
text-transform: none;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
.MuiToggleButton-root.Mui-disabled.kokopu-fixOpacity .kokopu-arrowMarkerIcon {
|
|
39
|
-
|
|
39
|
+
opacity: 0.3;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
.kokopu-fixedPopup {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
position: fixed;
|
|
44
|
+
bottom: 20px;
|
|
45
|
+
right: 20px;
|
|
46
|
+
padding: 10px;
|
|
47
47
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[Event "Television Exhibition"]
|
|
2
|
+
[Site "London ENG"]
|
|
3
|
+
[Date "2014.01.23"]
|
|
4
|
+
[Round "?"]
|
|
5
|
+
[White "Bill Gates"]
|
|
6
|
+
[Black "Magnus Carlsen"]
|
|
7
|
+
[Result "0-1"]
|
|
8
|
+
|
|
9
|
+
1.e4 Nc6 2.Nf3 d5 3.Bd3 Nf6 4.exd5 Qxd5 5.Nc3 Qh5 6.O-O Bg4
|
|
10
|
+
7.h3 Ne5 8.hxg4 Nfxg4 9.Nxe5 Qh2# 0-1
|
package/doc_src/demo/util.ts
CHANGED
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
export function buildComponentDemoCode(componentName: string, attributes: string[]) {
|
|
26
|
-
|
|
26
|
+
return attributes.length === 0 ? `<${componentName} />` : `<${componentName} ${attributes.join(' ')} />`;
|
|
27
27
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
```js
|
|
2
|
+
const pgn = `
|
|
3
|
+
[Event "Television Exhibition"]
|
|
4
|
+
[Site "London ENG"]
|
|
5
|
+
[Date "2014.01.23"]
|
|
6
|
+
[Round "?"]
|
|
7
|
+
[White "Bill Gates"]
|
|
8
|
+
[Black "Magnus Carlsen"]
|
|
9
|
+
[Result "0-1"]
|
|
10
|
+
|
|
11
|
+
1.e4 Nc6 2.Nf3 d5 3.Bd3 Nf6 4.exd5 Qxd5 5.Nc3 Qh5 6.O-O Bg4
|
|
12
|
+
7.h3 Ne5 8.hxg4 Nfxg4 9.Nxe5 Qh2# 0-1`;
|
|
13
|
+
|
|
14
|
+
<NavigationBoard game={pgn} initialNodeId="end" playButtonVisible />
|
|
15
|
+
```
|
|
@@ -31,22 +31,22 @@ import './theming.css';
|
|
|
31
31
|
/* eslint-disable react/prop-types */
|
|
32
32
|
|
|
33
33
|
const styles = ({ color, fontFamily, fontSize }) => ({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
logo: {
|
|
35
|
+
color: color.base,
|
|
36
|
+
margin: 0,
|
|
37
|
+
fontFamily: fontFamily.base,
|
|
38
|
+
fontSize: fontSize.h4,
|
|
39
|
+
fontWeight: 'normal',
|
|
40
|
+
},
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
function LogoRenderer({ classes, children }) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
return (<>
|
|
45
|
+
<div className="kokopu-logo">
|
|
46
|
+
<img src="kokopu-react-logo.png" />
|
|
47
|
+
</div>
|
|
48
|
+
<h1 className={classes.logo}>{children}</h1>
|
|
49
|
+
</>);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export default Styled(styles)(LogoRenderer);
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
.kokopu-logo {
|
|
26
|
-
|
|
26
|
+
text-align: center;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
footer {
|
|
30
|
-
|
|
30
|
+
display: none !important;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
#changelog h2 {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
font-size: inherit;
|
|
35
|
+
font-weight: bold;
|
|
36
|
+
margin-top: 24px;
|
|
37
37
|
}
|