kokopu-react 3.0.1 → 3.1.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/CHANGELOG.md +10 -0
- 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 +7 -5
- package/dist/lib/chessboard/Chessboard.d.ts +36 -58
- package/dist/lib/chessboard/Chessboard.js +33 -97
- package/dist/lib/chessboard/Chessboard.js.map +1 -1
- package/dist/lib/chessboard/ChessboardImpl.d.ts +22 -0
- package/dist/lib/chessboard/ChessboardImpl.js +8 -6
- package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
- package/dist/lib/chessboard/Draggable.d.ts +22 -0
- package/dist/lib/chessboard/Draggable.js +7 -5
- package/dist/lib/chessboard/Draggable.js.map +1 -1
- package/dist/lib/chessboard/Motion.d.ts +22 -0
- package/dist/lib/chessboard/Motion.js +7 -5
- package/dist/lib/chessboard/Motion.js.map +1 -1
- package/dist/lib/chessboard/colorsets.d.ts +22 -0
- package/dist/lib/chessboard/colorsets.js +7 -5
- package/dist/lib/chessboard/colorsets.js.map +1 -1
- package/dist/lib/chessboard/piecesets.d.ts +22 -0
- package/dist/lib/chessboard/piecesets.js +7 -5
- package/dist/lib/chessboard/piecesets.js.map +1 -1
- package/dist/lib/errorbox/ErrorBox.css +7 -5
- package/dist/lib/errorbox/ErrorBox.d.ts +22 -0
- package/dist/lib/errorbox/ErrorBox.js +7 -5
- 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.d.ts +22 -0
- package/dist/lib/exception.js +7 -5
- package/dist/lib/exception.js.map +1 -1
- package/dist/lib/i18n.d.ts +27 -0
- package/dist/lib/i18n.js +13 -5
- package/dist/lib/i18n.js.map +1 -1
- package/dist/lib/icons/AnnotationSymbolShape.css +7 -5
- package/dist/lib/icons/AnnotationSymbolShape.d.ts +22 -0
- package/dist/lib/icons/AnnotationSymbolShape.js +7 -5
- package/dist/lib/icons/AnnotationSymbolShape.js.map +1 -1
- package/dist/lib/icons/ArrowMarkerIcon.d.ts +22 -0
- package/dist/lib/icons/ArrowMarkerIcon.js +7 -5
- package/dist/lib/icons/ArrowMarkerIcon.js.map +1 -1
- package/dist/lib/icons/ArrowTip.d.ts +22 -0
- package/dist/lib/icons/ArrowTip.js +7 -5
- package/dist/lib/icons/ArrowTip.js.map +1 -1
- package/dist/lib/icons/ChessPieceIcon.d.ts +22 -0
- package/dist/lib/icons/ChessPieceIcon.js +7 -5
- package/dist/lib/icons/ChessPieceIcon.js.map +1 -1
- package/dist/lib/icons/SquareMarkerIcon.d.ts +22 -0
- package/dist/lib/icons/SquareMarkerIcon.js +7 -5
- package/dist/lib/icons/SquareMarkerIcon.js.map +1 -1
- package/dist/lib/icons/TextMarkerIcon.d.ts +22 -0
- package/dist/lib/icons/TextMarkerIcon.js +7 -5
- package/dist/lib/icons/TextMarkerIcon.js.map +1 -1
- package/dist/lib/icons/arrow.css +7 -5
- package/dist/lib/index.d.ts +26 -1
- package/dist/lib/index.js +9 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/movetext/Movetext.css +7 -18
- package/dist/lib/movetext/Movetext.d.ts +31 -43
- package/dist/lib/movetext/Movetext.js +22 -72
- package/dist/lib/movetext/Movetext.js.map +1 -1
- package/dist/lib/movetext/MovetextImpl.d.ts +29 -28
- package/dist/lib/movetext/MovetextImpl.js +22 -99
- package/dist/lib/movetext/MovetextImpl.js.map +1 -1
- package/dist/lib/movetext/fonts.css +7 -5
- package/dist/lib/movetext/htmlFilter.d.ts +22 -0
- package/dist/lib/movetext/htmlFilter.js +21 -19
- package/dist/lib/movetext/htmlFilter.js.map +1 -1
- package/dist/lib/movetext/moveFormatter.d.ts +22 -0
- package/dist/lib/movetext/moveFormatter.js +7 -5
- package/dist/lib/movetext/moveFormatter.js.map +1 -1
- package/dist/lib/navigationboard/NavigationBoard.d.ts +118 -0
- package/dist/lib/navigationboard/NavigationBoard.js +112 -0
- package/dist/lib/navigationboard/NavigationBoard.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 +51 -0
- package/dist/lib/navigationboard/NavigationToolbar.d.ts +41 -0
- package/dist/lib/navigationboard/NavigationToolbar.js +124 -0
- package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -0
- package/dist/lib/sanitization.d.ts +22 -0
- package/dist/lib/sanitization.js +7 -5
- package/dist/lib/sanitization.js.map +1 -1
- package/dist/lib/types.d.ts +22 -0
- package/dist/lib/types.js +7 -5
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/util.d.ts +22 -0
- package/dist/lib/util.js +7 -5
- package/dist/lib/util.js.map +1 -1
- package/doc_src/demo/PageChessboardBase.tsx +7 -5
- package/doc_src/demo/PageChessboardInteraction.tsx +32 -22
- package/doc_src/demo/PageChessboardMove.tsx +24 -5
- package/doc_src/demo/PageChessboardSmallScreens.tsx +7 -5
- package/doc_src/demo/PageMovetextBase.tsx +7 -5
- package/doc_src/demo/PageMovetextInteraction.tsx +7 -5
- package/doc_src/demo/PageNavigationBoardBase.tsx +194 -0
- package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +114 -0
- package/doc_src/demo/decs.d.ts +7 -5
- package/doc_src/demo/demo.css +7 -5
- package/doc_src/demo/game-3.pgn +10 -0
- package/doc_src/demo/util.ts +7 -5
- package/doc_src/examples/Movetext.md +1 -1
- package/doc_src/examples/NavigationBoard.md +15 -0
- package/doc_src/theming/LogoRenderer.js +7 -5
- package/doc_src/theming/theming.css +7 -5
- package/package.json +27 -26
- package/scripts/doc.styleguide.config.js +19 -7
- package/scripts/docker-compose.yml +3 -3
- package/scripts/test-graphic.webpack.config.js +7 -5
- package/scripts/test-headless.webpack.config.js +7 -5
- package/src/chessboard/BoardProperties.ts +131 -0
- package/src/chessboard/Chessboard.css +7 -5
- package/src/chessboard/Chessboard.tsx +48 -175
- package/src/chessboard/ChessboardImpl.tsx +7 -5
- package/src/chessboard/Draggable.tsx +7 -5
- package/src/chessboard/Motion.tsx +7 -5
- package/src/chessboard/colorsets.ts +7 -5
- package/src/chessboard/piecesets.ts +7 -5
- package/src/decs.d.ts +7 -5
- package/src/errorbox/ErrorBox.css +7 -5
- package/src/errorbox/ErrorBox.tsx +7 -5
- package/src/errorbox/parsing.tsx +158 -0
- package/src/exception.ts +7 -5
- package/src/i18n.ts +14 -5
- package/src/icons/AnnotationSymbolShape.css +7 -5
- package/src/icons/AnnotationSymbolShape.tsx +7 -5
- package/src/icons/ArrowMarkerIcon.tsx +7 -5
- package/src/icons/ArrowTip.tsx +7 -5
- package/src/icons/ChessPieceIcon.tsx +7 -5
- package/src/icons/SquareMarkerIcon.tsx +7 -5
- package/src/icons/TextMarkerIcon.tsx +7 -5
- package/src/icons/arrow.css +7 -5
- package/src/index.ts +12 -6
- package/src/movetext/Movetext.css +7 -18
- package/src/movetext/Movetext.tsx +27 -90
- package/src/movetext/MovetextImpl.tsx +35 -120
- package/src/movetext/fonts.css +7 -5
- package/src/movetext/htmlFilter.tsx +7 -5
- package/src/movetext/moveFormatter.tsx +7 -5
- package/src/navigationboard/NavigationBoard.tsx +231 -0
- package/src/navigationboard/NavigationField.css +36 -0
- package/src/navigationboard/NavigationField.tsx +185 -0
- package/src/navigationboard/NavigationToolbar.css +51 -0
- package/src/navigationboard/NavigationToolbar.tsx +174 -0
- package/src/sanitization.ts +7 -5
- package/src/types.ts +7 -5
- package/src/util.ts +7 -5
- package/test/01_types.js +7 -5
- package/test/02_chessboard_util.js +7 -5
- package/test/03_error_box_graphic.js +7 -5
- package/test/04_icons_graphic.js +7 -5
- package/test/05_chessboard_graphic.js +9 -5
- package/test/06_chessboard_animation.js +7 -5
- package/test/07_chessboard_interaction.js +7 -5
- package/test/08_chessboard_play_moves.js +7 -5
- package/test/09_chessboard_small_screens.js +28 -5
- package/test/10_movetext_graphic.js +12 -5
- package/test/11_movetext_interaction.js +19 -13
- package/test/12_navigation_board.js +168 -0
- package/test/common/graphic.js +7 -5
- 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/controlled/default.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/invalid_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/overriding_initial_node_id.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board/controlled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board/error/pgn_parsing_error.png +0 -0
- package/test/graphic_references/12_navigation_board/error/wrong_game_type.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/custom_1.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/custom_2.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/large.png +0 -0
- package/test/graphic_references/12_navigation_board/theme/small.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_end.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_specific_id.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default_with_game_index.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_on_null-move.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_3.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_4.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_0.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_1.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_2.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_3.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_4.png +0 -0
- package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_5.png +0 -0
- package/test/graphic_test_app/03_error_box_graphic/base.tsx +7 -5
- package/test/graphic_test_app/03_error_box_graphic/localization.tsx +7 -5
- package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +7 -5
- package/test/graphic_test_app/04_icons_graphic/marker.tsx +7 -5
- package/test/graphic_test_app/05_chessboard_graphic/annotations.tsx +7 -5
- package/test/graphic_test_app/05_chessboard_graphic/base.tsx +7 -5
- package/test/graphic_test_app/05_chessboard_graphic/chess_variants.tsx +7 -5
- package/test/graphic_test_app/05_chessboard_graphic/flipped.tsx +7 -5
- package/test/graphic_test_app/05_chessboard_graphic/move.tsx +9 -5
- package/test/graphic_test_app/05_chessboard_graphic/theme.tsx +7 -5
- package/test/graphic_test_app/06_chessboard_animation/base_1.tsx +7 -5
- package/test/graphic_test_app/06_chessboard_animation/base_2.tsx +7 -5
- package/test/graphic_test_app/06_chessboard_animation/base_3.tsx +7 -5
- package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +7 -5
- package/test/graphic_test_app/07_chessboard_interaction/click_squares.tsx +7 -5
- package/test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx +7 -5
- package/test/graphic_test_app/07_chessboard_interaction/error.tsx +7 -5
- package/test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx +7 -5
- package/test/graphic_test_app/08_chessboard_play_moves/base.tsx +7 -5
- package/test/graphic_test_app/08_chessboard_play_moves/promotions.tsx +7 -5
- package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +7 -5
- 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 +7 -5
- package/test/graphic_test_app/10_movetext_graphic/error.tsx +7 -5
- package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +31 -0
- package/test/graphic_test_app/10_movetext_graphic/html.tsx +7 -5
- package/test/graphic_test_app/10_movetext_graphic/options.tsx +8 -5
- package/test/graphic_test_app/11_movetext_interaction/error.tsx +7 -5
- package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +8 -5
- package/test/graphic_test_app/12_navigation_board/controlled.tsx +43 -0
- package/test/graphic_test_app/12_navigation_board/error.tsx +34 -0
- package/test/graphic_test_app/12_navigation_board/theme.tsx +38 -0
- package/test/graphic_test_app/12_navigation_board/uncontrolled.tsx +56 -0
- package/test/graphic_test_app/common/decs.d.ts +7 -5
- package/test/graphic_test_app/common/test_app.css +7 -5
- package/test/graphic_test_app/common/test_app.tsx +7 -5
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
2
3
|
* *
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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> *
|
|
5
7
|
* *
|
|
6
|
-
*
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
7
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
10
|
* as published by the Free Software Foundation, either version 3 of *
|
|
9
11
|
* the License, or (at your option) any later version. *
|
|
10
12
|
* *
|
|
11
|
-
*
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
12
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
16
|
* GNU Lesser General Public License for more details. *
|
|
@@ -22,17 +24,17 @@
|
|
|
22
24
|
|
|
23
25
|
import * as React from 'react';
|
|
24
26
|
|
|
25
|
-
import {
|
|
27
|
+
import { Database, Game } from 'kokopu';
|
|
26
28
|
|
|
27
29
|
import { IllegalArgument } from '../exception';
|
|
28
|
-
import { i18n } from '../i18n';
|
|
29
30
|
import { sanitizeString, sanitizeBoolean, sanitizeOptional } from '../sanitization';
|
|
30
31
|
import { PieceSymbolMapping } from '../types';
|
|
31
32
|
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
33
|
+
import { StaticBoardGraphicProps } from '../chessboard/BoardProperties';
|
|
34
|
+
import { parseGame } from '../errorbox/parsing';
|
|
35
|
+
import { firstNodeId as firstNodeIdImpl, previousNodeId as previousNodeIdImpl, nextNodeId as nextNodeIdImpl, lastNodeId as lastNodeIdImpl } from '../navigationboard/NavigationField';
|
|
34
36
|
import { moveFormatter } from './moveFormatter';
|
|
35
|
-
import { MovetextImpl
|
|
37
|
+
import { MovetextImpl } from './MovetextImpl';
|
|
36
38
|
|
|
37
39
|
import './Movetext.css';
|
|
38
40
|
|
|
@@ -46,7 +48,7 @@ export type MoveSelectEventOrigin = 'key-first' | 'key-previous' | 'key-next' |
|
|
|
46
48
|
export interface MovetextProps {
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
|
-
* Displayed
|
|
51
|
+
* Displayed game. Can be a [kokopu.Game](https://kokopu.yo35.org/docs/current/classes/Game.html) object,
|
|
50
52
|
* a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html) object,
|
|
51
53
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation).
|
|
52
54
|
*/
|
|
@@ -62,14 +64,8 @@ export interface MovetextProps {
|
|
|
62
64
|
/**
|
|
63
65
|
* Options applicable to the diagrams in the comments. See [Chessboard](#/Components/Chessboard) for more details about each option.
|
|
64
66
|
*/
|
|
65
|
-
diagramOptions: {
|
|
66
|
-
flipped?:
|
|
67
|
-
squareSize?: ChessboardProps['squareSize'],
|
|
68
|
-
coordinateVisible?: ChessboardProps['coordinateVisible'],
|
|
69
|
-
turnVisible?: ChessboardProps['turnVisible'],
|
|
70
|
-
colorset?: ChessboardProps['colorset'],
|
|
71
|
-
pieceset?: ChessboardProps['pieceset'],
|
|
72
|
-
smallScreenLimits?: ChessboardProps['smallScreenLimits'],
|
|
67
|
+
diagramOptions: Partial<StaticBoardGraphicProps> & {
|
|
68
|
+
flipped?: boolean,
|
|
73
69
|
};
|
|
74
70
|
|
|
75
71
|
/**
|
|
@@ -88,7 +84,7 @@ export interface MovetextProps {
|
|
|
88
84
|
headerVisible: boolean;
|
|
89
85
|
|
|
90
86
|
/**
|
|
91
|
-
* ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
87
|
+
* ID of the selected move (or `'start'`/`'end'` for the beginning/end of the main variation).
|
|
92
88
|
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id) to get the ID of a game move.
|
|
93
89
|
*/
|
|
94
90
|
selection?: string;
|
|
@@ -136,14 +132,9 @@ export class Movetext extends React.Component<MovetextProps> {
|
|
|
136
132
|
render() {
|
|
137
133
|
|
|
138
134
|
// Validate the game and game-index attributes.
|
|
139
|
-
const info = parseGame(this.props.game, this.props.gameIndex);
|
|
135
|
+
const info = parseGame(this.props.game, this.props.gameIndex, 'Movetext');
|
|
140
136
|
if (info.error) {
|
|
141
|
-
return
|
|
142
|
-
<ErrorBox
|
|
143
|
-
title={i18n.INVALID_PGN_ERROR_TITLE} message={info.pgnException.message} text={info.pgnException.pgn}
|
|
144
|
-
errorIndex={info.pgnException.index} lineNumber={info.pgnException.lineNumber}
|
|
145
|
-
/>
|
|
146
|
-
);
|
|
137
|
+
return info.errorBox;
|
|
147
138
|
}
|
|
148
139
|
|
|
149
140
|
// Validate the appearance attributes.
|
|
@@ -185,96 +176,42 @@ export class Movetext extends React.Component<MovetextProps> {
|
|
|
185
176
|
*/
|
|
186
177
|
focus() {
|
|
187
178
|
const movetextImpl = this.implRef.current;
|
|
179
|
+
// istanbul ignore else
|
|
188
180
|
if (movetextImpl) {
|
|
189
181
|
movetextImpl.focus();
|
|
190
182
|
}
|
|
191
183
|
}
|
|
192
184
|
|
|
193
185
|
/**
|
|
194
|
-
*
|
|
195
|
-
* If the given selection corresponds already at the main variation, `undefined` is returned.
|
|
196
|
-
*
|
|
197
|
-
* This corresponds to the operation performed when the user presses key "home" on a `Movetext` component.
|
|
198
|
-
*
|
|
199
|
-
* @param game - Considered chess game.
|
|
200
|
-
* @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
201
|
-
* @public
|
|
186
|
+
* @deprecated
|
|
202
187
|
*/
|
|
188
|
+
// istanbul ignore next
|
|
203
189
|
static firstNodeId(game: Game, selection: string): string | undefined {
|
|
204
190
|
return firstNodeIdImpl(game, selection);
|
|
205
191
|
}
|
|
206
192
|
|
|
207
193
|
/**
|
|
208
|
-
*
|
|
209
|
-
* If no such node exists, `undefined` is returned.
|
|
210
|
-
*
|
|
211
|
-
* This corresponds to the operation performed when the user presses key "arrow left" on a `Movetext` component.
|
|
212
|
-
*
|
|
213
|
-
* @param game - Considered chess game.
|
|
214
|
-
* @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
215
|
-
* @public
|
|
194
|
+
* @deprecated
|
|
216
195
|
*/
|
|
196
|
+
// istanbul ignore next
|
|
217
197
|
static previousNodeId(game: Game, selection: string): string | undefined {
|
|
218
198
|
return previousNodeIdImpl(game, selection);
|
|
219
199
|
}
|
|
220
200
|
|
|
221
201
|
/**
|
|
222
|
-
*
|
|
223
|
-
* If no such node exists, `undefined` is returned.
|
|
224
|
-
*
|
|
225
|
-
* This corresponds to the operation performed when the user presses key "arrow right" on a `Movetext` component.
|
|
226
|
-
*
|
|
227
|
-
* @param game - Considered chess game.
|
|
228
|
-
* @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
229
|
-
* @public
|
|
202
|
+
* @deprecated
|
|
230
203
|
*/
|
|
204
|
+
// istanbul ignore next
|
|
231
205
|
static nextNodeId(game: Game, selection: string): string | undefined {
|
|
232
206
|
return nextNodeIdImpl(game, selection);
|
|
233
207
|
}
|
|
234
208
|
|
|
235
209
|
/**
|
|
236
|
-
*
|
|
237
|
-
* If the selection is already at the end its variation, `undefined` is returned.
|
|
238
|
-
*
|
|
239
|
-
* This corresponds to the operation performed when the user presses key "end" on a `Movetext` component.
|
|
240
|
-
*
|
|
241
|
-
* @param game - Considered chess game.
|
|
242
|
-
* @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
|
|
243
|
-
* @public
|
|
210
|
+
* @deprecated
|
|
244
211
|
*/
|
|
212
|
+
// istanbul ignore next
|
|
245
213
|
static lastNodeId(game: Game, selection: string): string | undefined {
|
|
246
214
|
return lastNodeIdImpl(game, selection);
|
|
247
215
|
}
|
|
248
216
|
|
|
249
217
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Try to interpret the given object as a chess game.
|
|
254
|
-
*/
|
|
255
|
-
function parseGame(game: Game | Database | string, gameIndex: number): { error: true, pgnException: kokopuException.InvalidPGN } | { error: false, game: Game } {
|
|
256
|
-
if (game instanceof Game) {
|
|
257
|
-
return { error: false, game: game };
|
|
258
|
-
}
|
|
259
|
-
else if (game instanceof Database || typeof game === 'string') {
|
|
260
|
-
if (!Number.isInteger(gameIndex) || gameIndex < 0) {
|
|
261
|
-
throw new IllegalArgument('Movetext', 'gameIndex');
|
|
262
|
-
}
|
|
263
|
-
try {
|
|
264
|
-
const result = game instanceof Database ? game.game(gameIndex) : pgnRead(game, gameIndex);
|
|
265
|
-
return { error: false, game: result };
|
|
266
|
-
}
|
|
267
|
-
catch (e) {
|
|
268
|
-
// istanbul ignore else
|
|
269
|
-
if (e instanceof kokopuException.InvalidPGN) {
|
|
270
|
-
return { error: true, pgnException: e };
|
|
271
|
-
}
|
|
272
|
-
else {
|
|
273
|
-
throw e;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
throw new IllegalArgument('Movetext', 'game');
|
|
279
|
-
}
|
|
280
|
-
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
2
3
|
* *
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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> *
|
|
5
7
|
* *
|
|
6
|
-
*
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
7
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
10
|
* as published by the Free Software Foundation, either version 3 of *
|
|
9
11
|
* the License, or (at your option) any later version. *
|
|
10
12
|
* *
|
|
11
|
-
*
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
12
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
16
|
* GNU Lesser General Public License for more details. *
|
|
@@ -27,7 +29,9 @@ import { Game, Color, GameResult, Node as GameNode, Variation, nagSymbol } from
|
|
|
27
29
|
import { i18n } from '../i18n';
|
|
28
30
|
import { fillPlaceholder } from '../util';
|
|
29
31
|
|
|
30
|
-
import {
|
|
32
|
+
import { StaticBoardGraphicProps } from '../chessboard/BoardProperties';
|
|
33
|
+
import { Chessboard } from '../chessboard/Chessboard';
|
|
34
|
+
import { NavigationField, firstNodeId, previousNodeId, nextNodeId, lastNodeId } from '../navigationboard/NavigationField';
|
|
31
35
|
import { htmlFilter } from './htmlFilter';
|
|
32
36
|
|
|
33
37
|
import './Movetext.css';
|
|
@@ -37,14 +41,8 @@ interface MovetextImplProps {
|
|
|
37
41
|
|
|
38
42
|
game: Game;
|
|
39
43
|
|
|
40
|
-
diagramOptions: {
|
|
41
|
-
flipped?:
|
|
42
|
-
squareSize?: ChessboardProps['squareSize'],
|
|
43
|
-
coordinateVisible?: ChessboardProps['coordinateVisible'],
|
|
44
|
-
turnVisible?: ChessboardProps['turnVisible'],
|
|
45
|
-
colorset?: ChessboardProps['colorset'],
|
|
46
|
-
pieceset?: ChessboardProps['pieceset'],
|
|
47
|
-
smallScreenLimits?: ChessboardProps['smallScreenLimits'],
|
|
44
|
+
diagramOptions: Partial<StaticBoardGraphicProps> & {
|
|
45
|
+
flipped?: boolean,
|
|
48
46
|
};
|
|
49
47
|
moveFormatter: (notation: string) => React.ReactNode;
|
|
50
48
|
diagramVisible: boolean;
|
|
@@ -64,14 +62,14 @@ interface MovetextImplProps {
|
|
|
64
62
|
*/
|
|
65
63
|
export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
66
64
|
|
|
67
|
-
private
|
|
65
|
+
private navigationFieldRef: React.RefObject<NavigationField> = React.createRef();
|
|
68
66
|
|
|
69
67
|
render() {
|
|
70
68
|
return (
|
|
71
69
|
<div className="kokopu-movetext">
|
|
72
70
|
{this.renderHeaders()}
|
|
73
71
|
{this.renderBody()}
|
|
74
|
-
{this.
|
|
72
|
+
{this.renderNavigationField()}
|
|
75
73
|
</div>
|
|
76
74
|
);
|
|
77
75
|
}
|
|
@@ -153,15 +151,17 @@ export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
|
153
151
|
return <div className="kokopu-header-annotator" key="annotator">{filter(fillPlaceholder(i18n.ANNOTATED_BY, annotator))}</div>;
|
|
154
152
|
}
|
|
155
153
|
|
|
156
|
-
private
|
|
154
|
+
private renderNavigationField() {
|
|
157
155
|
if (this.props.interactionMode !== 'selectMove') {
|
|
158
156
|
return undefined;
|
|
159
157
|
}
|
|
160
|
-
return
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
158
|
+
return <NavigationField ref={this.navigationFieldRef}
|
|
159
|
+
onFirstPressed={() => this.handleNavigationPressed(firstNodeId, 'key-first')}
|
|
160
|
+
onPreviousPressed={() => this.handleNavigationPressed(previousNodeId, 'key-previous')}
|
|
161
|
+
onNextPressed={() => this.handleNavigationPressed(nextNodeId, 'key-next')}
|
|
162
|
+
onLastPressed={() => this.handleNavigationPressed(lastNodeId, 'key-last')}
|
|
163
|
+
onExitPressed={() => this.handleExitPressed()}
|
|
164
|
+
/>;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
private renderBody() {
|
|
@@ -313,15 +313,16 @@ export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
|
313
313
|
for (let textSegment of comment.split('[#]')) {
|
|
314
314
|
if (!isFirstTextSegment) {
|
|
315
315
|
const position = node instanceof Variation ? node.initialPosition() : node.position();
|
|
316
|
-
const diagram = <Chessboard
|
|
316
|
+
const diagram = <Chessboard
|
|
317
|
+
position={position}
|
|
317
318
|
squareMarkers={node.tag('csl')} arrowMarkers={node.tag('cal')} textMarkers={node.tag('ctl')}
|
|
318
319
|
flipped={this.props.diagramOptions.flipped}
|
|
319
320
|
squareSize={this.props.diagramOptions.squareSize}
|
|
320
321
|
coordinateVisible={this.props.diagramOptions.coordinateVisible}
|
|
321
322
|
turnVisible={this.props.diagramOptions.turnVisible}
|
|
322
|
-
smallScreenLimits={this.props.diagramOptions.smallScreenLimits}
|
|
323
323
|
colorset={this.props.diagramOptions.colorset}
|
|
324
324
|
pieceset={this.props.diagramOptions.pieceset}
|
|
325
|
+
smallScreenLimits={this.props.diagramOptions.smallScreenLimits}
|
|
325
326
|
/>;
|
|
326
327
|
segmentElements.push(<div className="kokopu-diagram" key={'diagram-' + (diagramIndex++)}>{diagram}</div>);
|
|
327
328
|
}
|
|
@@ -355,30 +356,15 @@ export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
|
355
356
|
return comment ? comment : undefined;
|
|
356
357
|
}
|
|
357
358
|
|
|
358
|
-
private
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
}
|
|
362
|
-
evt.preventDefault();
|
|
363
|
-
if (!this.props.selection) {
|
|
364
|
-
return;
|
|
359
|
+
private handleNavigationPressed(transition: (game: Game, nodeId: string) => string | undefined, evtOrigin: 'key-first' | 'key-previous' | 'key-next' | 'key-last') {
|
|
360
|
+
if (this.props.selection) {
|
|
361
|
+
this.fireMoveSelected(transition(this.props.game, this.props.selection), evtOrigin);
|
|
365
362
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
this.fireMoveSelected(
|
|
371
|
-
}
|
|
372
|
-
else if (evt.key === 'ArrowRight') {
|
|
373
|
-
this.fireMoveSelected(nextNodeIdImpl(this.props.game, this.props.selection), 'key-next');
|
|
374
|
-
}
|
|
375
|
-
else if (evt.key === 'End') {
|
|
376
|
-
this.fireMoveSelected(lastNodeIdImpl(this.props.game, this.props.selection), 'key-last');
|
|
377
|
-
}
|
|
378
|
-
else { // evt.key === 'Escape'
|
|
379
|
-
if (this.props.game.findById(this.props.selection)) {
|
|
380
|
-
this.fireMoveSelected(undefined, 'key-exit');
|
|
381
|
-
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
private handleExitPressed() {
|
|
366
|
+
if (this.props.selection && this.props.game.findById(this.props.selection)) {
|
|
367
|
+
this.fireMoveSelected(undefined, 'key-exit');
|
|
382
368
|
}
|
|
383
369
|
}
|
|
384
370
|
|
|
@@ -399,7 +385,8 @@ export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
|
399
385
|
* Set the focus to the current component.
|
|
400
386
|
*/
|
|
401
387
|
focus(): void {
|
|
402
|
-
const target = this.
|
|
388
|
+
const target = this.navigationFieldRef.current;
|
|
389
|
+
// istanbul ignore else
|
|
403
390
|
if (target) {
|
|
404
391
|
target.focus();
|
|
405
392
|
}
|
|
@@ -408,78 +395,6 @@ export class MovetextImpl extends React.Component<MovetextImplProps> {
|
|
|
408
395
|
}
|
|
409
396
|
|
|
410
397
|
|
|
411
|
-
/**
|
|
412
|
-
* See {@link Movetext.firstNodeId}.
|
|
413
|
-
*/
|
|
414
|
-
export function firstNodeIdImpl(game: Game, selection: string): string | undefined {
|
|
415
|
-
if (!game.findById(selection)) {
|
|
416
|
-
return undefined;
|
|
417
|
-
}
|
|
418
|
-
return selection === 'start' ? undefined : 'start';
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
/**
|
|
423
|
-
* See {@link Movetext.previousNodeId}.
|
|
424
|
-
*/
|
|
425
|
-
export function previousNodeIdImpl(game: Game, selection: string): string | undefined {
|
|
426
|
-
let currentNode = game.findById(selection);
|
|
427
|
-
if (!currentNode) {
|
|
428
|
-
return undefined;
|
|
429
|
-
}
|
|
430
|
-
if (currentNode instanceof Variation) {
|
|
431
|
-
currentNode = currentNode.parentNode();
|
|
432
|
-
if (!currentNode) {
|
|
433
|
-
return undefined; // This case corresponds to the first variation being selected initially.
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
while (currentNode) {
|
|
437
|
-
const previousNode = currentNode.previous();
|
|
438
|
-
if (previousNode) {
|
|
439
|
-
return previousNode.id();
|
|
440
|
-
}
|
|
441
|
-
currentNode = currentNode.parentVariation().parentNode();
|
|
442
|
-
}
|
|
443
|
-
return 'start';
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* See {@link Movetext.nextNodeId}.
|
|
449
|
-
*/
|
|
450
|
-
export function nextNodeIdImpl(game: Game, selection: string): string | undefined {
|
|
451
|
-
const currentNode = game.findById(selection);
|
|
452
|
-
if (!currentNode) {
|
|
453
|
-
return undefined;
|
|
454
|
-
}
|
|
455
|
-
const nextNode = currentNode instanceof Variation ? currentNode.first() : currentNode.next();
|
|
456
|
-
return nextNode ? nextNode.id() : undefined;
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* See {@link Movetext.lastNodeId}.
|
|
462
|
-
*/
|
|
463
|
-
export function lastNodeIdImpl(game: Game, selection: string): string | undefined {
|
|
464
|
-
let currentNode = game.findById(selection);
|
|
465
|
-
if (!currentNode) {
|
|
466
|
-
return undefined;
|
|
467
|
-
}
|
|
468
|
-
currentNode = currentNode instanceof Variation ? currentNode.first() : currentNode.next();
|
|
469
|
-
if (!currentNode) { // Ensure that the input node is not already the last one.
|
|
470
|
-
return undefined;
|
|
471
|
-
}
|
|
472
|
-
let currentNodeNotNull = currentNode;
|
|
473
|
-
while (true) {
|
|
474
|
-
const nextNode = currentNodeNotNull.next();
|
|
475
|
-
if (!nextNode) {
|
|
476
|
-
return currentNodeNotNull.id();
|
|
477
|
-
}
|
|
478
|
-
currentNodeNotNull = nextNode;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
|
|
483
398
|
/**
|
|
484
399
|
* Example: `'hello world'` is turned into `'Hello world'`.
|
|
485
400
|
*/
|
package/src/movetext/fonts.css
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
2
3
|
* *
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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> *
|
|
5
7
|
* *
|
|
6
|
-
*
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
7
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
10
|
* as published by the Free Software Foundation, either version 3 of *
|
|
9
11
|
* the License, or (at your option) any later version. *
|
|
10
12
|
* *
|
|
11
|
-
*
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
12
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
16
|
* GNU Lesser General Public License for more details. *
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
2
3
|
* *
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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> *
|
|
5
7
|
* *
|
|
6
|
-
*
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
7
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
10
|
* as published by the Free Software Foundation, either version 3 of *
|
|
9
11
|
* the License, or (at your option) any later version. *
|
|
10
12
|
* *
|
|
11
|
-
*
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
12
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
16
|
* GNU Lesser General Public License for more details. *
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* -------------------------------------------------------------------------- *
|
|
2
3
|
* *
|
|
3
|
-
*
|
|
4
|
-
*
|
|
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> *
|
|
5
7
|
* *
|
|
6
|
-
*
|
|
8
|
+
* Kokopu-React is free software: you can redistribute it and/or *
|
|
7
9
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
8
10
|
* as published by the Free Software Foundation, either version 3 of *
|
|
9
11
|
* the License, or (at your option) any later version. *
|
|
10
12
|
* *
|
|
11
|
-
*
|
|
13
|
+
* Kokopu-React is distributed in the hope that it will be useful, *
|
|
12
14
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
13
15
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
14
16
|
* GNU Lesser General Public License for more details. *
|