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.
Files changed (250) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/lib/chessboard/BoardProperties.d.ts +91 -0
  3. package/dist/lib/chessboard/BoardProperties.js +43 -0
  4. package/dist/lib/chessboard/BoardProperties.js.map +1 -0
  5. package/dist/lib/chessboard/Chessboard.css +7 -5
  6. package/dist/lib/chessboard/Chessboard.d.ts +36 -58
  7. package/dist/lib/chessboard/Chessboard.js +33 -97
  8. package/dist/lib/chessboard/Chessboard.js.map +1 -1
  9. package/dist/lib/chessboard/ChessboardImpl.d.ts +22 -0
  10. package/dist/lib/chessboard/ChessboardImpl.js +8 -6
  11. package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
  12. package/dist/lib/chessboard/Draggable.d.ts +22 -0
  13. package/dist/lib/chessboard/Draggable.js +7 -5
  14. package/dist/lib/chessboard/Draggable.js.map +1 -1
  15. package/dist/lib/chessboard/Motion.d.ts +22 -0
  16. package/dist/lib/chessboard/Motion.js +7 -5
  17. package/dist/lib/chessboard/Motion.js.map +1 -1
  18. package/dist/lib/chessboard/colorsets.d.ts +22 -0
  19. package/dist/lib/chessboard/colorsets.js +7 -5
  20. package/dist/lib/chessboard/colorsets.js.map +1 -1
  21. package/dist/lib/chessboard/piecesets.d.ts +22 -0
  22. package/dist/lib/chessboard/piecesets.js +7 -5
  23. package/dist/lib/chessboard/piecesets.js.map +1 -1
  24. package/dist/lib/errorbox/ErrorBox.css +7 -5
  25. package/dist/lib/errorbox/ErrorBox.d.ts +22 -0
  26. package/dist/lib/errorbox/ErrorBox.js +7 -5
  27. package/dist/lib/errorbox/ErrorBox.js.map +1 -1
  28. package/dist/lib/errorbox/parsing.d.ts +57 -0
  29. package/dist/lib/errorbox/parsing.js +140 -0
  30. package/dist/lib/errorbox/parsing.js.map +1 -0
  31. package/dist/lib/exception.d.ts +22 -0
  32. package/dist/lib/exception.js +7 -5
  33. package/dist/lib/exception.js.map +1 -1
  34. package/dist/lib/i18n.d.ts +27 -0
  35. package/dist/lib/i18n.js +13 -5
  36. package/dist/lib/i18n.js.map +1 -1
  37. package/dist/lib/icons/AnnotationSymbolShape.css +7 -5
  38. package/dist/lib/icons/AnnotationSymbolShape.d.ts +22 -0
  39. package/dist/lib/icons/AnnotationSymbolShape.js +7 -5
  40. package/dist/lib/icons/AnnotationSymbolShape.js.map +1 -1
  41. package/dist/lib/icons/ArrowMarkerIcon.d.ts +22 -0
  42. package/dist/lib/icons/ArrowMarkerIcon.js +7 -5
  43. package/dist/lib/icons/ArrowMarkerIcon.js.map +1 -1
  44. package/dist/lib/icons/ArrowTip.d.ts +22 -0
  45. package/dist/lib/icons/ArrowTip.js +7 -5
  46. package/dist/lib/icons/ArrowTip.js.map +1 -1
  47. package/dist/lib/icons/ChessPieceIcon.d.ts +22 -0
  48. package/dist/lib/icons/ChessPieceIcon.js +7 -5
  49. package/dist/lib/icons/ChessPieceIcon.js.map +1 -1
  50. package/dist/lib/icons/SquareMarkerIcon.d.ts +22 -0
  51. package/dist/lib/icons/SquareMarkerIcon.js +7 -5
  52. package/dist/lib/icons/SquareMarkerIcon.js.map +1 -1
  53. package/dist/lib/icons/TextMarkerIcon.d.ts +22 -0
  54. package/dist/lib/icons/TextMarkerIcon.js +7 -5
  55. package/dist/lib/icons/TextMarkerIcon.js.map +1 -1
  56. package/dist/lib/icons/arrow.css +7 -5
  57. package/dist/lib/index.d.ts +26 -1
  58. package/dist/lib/index.js +9 -5
  59. package/dist/lib/index.js.map +1 -1
  60. package/dist/lib/movetext/Movetext.css +7 -18
  61. package/dist/lib/movetext/Movetext.d.ts +31 -43
  62. package/dist/lib/movetext/Movetext.js +22 -72
  63. package/dist/lib/movetext/Movetext.js.map +1 -1
  64. package/dist/lib/movetext/MovetextImpl.d.ts +29 -28
  65. package/dist/lib/movetext/MovetextImpl.js +22 -99
  66. package/dist/lib/movetext/MovetextImpl.js.map +1 -1
  67. package/dist/lib/movetext/fonts.css +7 -5
  68. package/dist/lib/movetext/htmlFilter.d.ts +22 -0
  69. package/dist/lib/movetext/htmlFilter.js +21 -19
  70. package/dist/lib/movetext/htmlFilter.js.map +1 -1
  71. package/dist/lib/movetext/moveFormatter.d.ts +22 -0
  72. package/dist/lib/movetext/moveFormatter.js +7 -5
  73. package/dist/lib/movetext/moveFormatter.js.map +1 -1
  74. package/dist/lib/navigationboard/NavigationBoard.d.ts +118 -0
  75. package/dist/lib/navigationboard/NavigationBoard.js +112 -0
  76. package/dist/lib/navigationboard/NavigationBoard.js.map +1 -0
  77. package/dist/lib/navigationboard/NavigationField.css +36 -0
  78. package/dist/lib/navigationboard/NavigationField.d.ts +81 -0
  79. package/dist/lib/navigationboard/NavigationField.js +154 -0
  80. package/dist/lib/navigationboard/NavigationField.js.map +1 -0
  81. package/dist/lib/navigationboard/NavigationToolbar.css +51 -0
  82. package/dist/lib/navigationboard/NavigationToolbar.d.ts +41 -0
  83. package/dist/lib/navigationboard/NavigationToolbar.js +124 -0
  84. package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -0
  85. package/dist/lib/sanitization.d.ts +22 -0
  86. package/dist/lib/sanitization.js +7 -5
  87. package/dist/lib/sanitization.js.map +1 -1
  88. package/dist/lib/types.d.ts +22 -0
  89. package/dist/lib/types.js +7 -5
  90. package/dist/lib/types.js.map +1 -1
  91. package/dist/lib/util.d.ts +22 -0
  92. package/dist/lib/util.js +7 -5
  93. package/dist/lib/util.js.map +1 -1
  94. package/doc_src/demo/PageChessboardBase.tsx +7 -5
  95. package/doc_src/demo/PageChessboardInteraction.tsx +32 -22
  96. package/doc_src/demo/PageChessboardMove.tsx +24 -5
  97. package/doc_src/demo/PageChessboardSmallScreens.tsx +7 -5
  98. package/doc_src/demo/PageMovetextBase.tsx +7 -5
  99. package/doc_src/demo/PageMovetextInteraction.tsx +7 -5
  100. package/doc_src/demo/PageNavigationBoardBase.tsx +194 -0
  101. package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +114 -0
  102. package/doc_src/demo/decs.d.ts +7 -5
  103. package/doc_src/demo/demo.css +7 -5
  104. package/doc_src/demo/game-3.pgn +10 -0
  105. package/doc_src/demo/util.ts +7 -5
  106. package/doc_src/examples/Movetext.md +1 -1
  107. package/doc_src/examples/NavigationBoard.md +15 -0
  108. package/doc_src/theming/LogoRenderer.js +7 -5
  109. package/doc_src/theming/theming.css +7 -5
  110. package/package.json +27 -26
  111. package/scripts/doc.styleguide.config.js +19 -7
  112. package/scripts/docker-compose.yml +3 -3
  113. package/scripts/test-graphic.webpack.config.js +7 -5
  114. package/scripts/test-headless.webpack.config.js +7 -5
  115. package/src/chessboard/BoardProperties.ts +131 -0
  116. package/src/chessboard/Chessboard.css +7 -5
  117. package/src/chessboard/Chessboard.tsx +48 -175
  118. package/src/chessboard/ChessboardImpl.tsx +7 -5
  119. package/src/chessboard/Draggable.tsx +7 -5
  120. package/src/chessboard/Motion.tsx +7 -5
  121. package/src/chessboard/colorsets.ts +7 -5
  122. package/src/chessboard/piecesets.ts +7 -5
  123. package/src/decs.d.ts +7 -5
  124. package/src/errorbox/ErrorBox.css +7 -5
  125. package/src/errorbox/ErrorBox.tsx +7 -5
  126. package/src/errorbox/parsing.tsx +158 -0
  127. package/src/exception.ts +7 -5
  128. package/src/i18n.ts +14 -5
  129. package/src/icons/AnnotationSymbolShape.css +7 -5
  130. package/src/icons/AnnotationSymbolShape.tsx +7 -5
  131. package/src/icons/ArrowMarkerIcon.tsx +7 -5
  132. package/src/icons/ArrowTip.tsx +7 -5
  133. package/src/icons/ChessPieceIcon.tsx +7 -5
  134. package/src/icons/SquareMarkerIcon.tsx +7 -5
  135. package/src/icons/TextMarkerIcon.tsx +7 -5
  136. package/src/icons/arrow.css +7 -5
  137. package/src/index.ts +12 -6
  138. package/src/movetext/Movetext.css +7 -18
  139. package/src/movetext/Movetext.tsx +27 -90
  140. package/src/movetext/MovetextImpl.tsx +35 -120
  141. package/src/movetext/fonts.css +7 -5
  142. package/src/movetext/htmlFilter.tsx +7 -5
  143. package/src/movetext/moveFormatter.tsx +7 -5
  144. package/src/navigationboard/NavigationBoard.tsx +231 -0
  145. package/src/navigationboard/NavigationField.css +36 -0
  146. package/src/navigationboard/NavigationField.tsx +185 -0
  147. package/src/navigationboard/NavigationToolbar.css +51 -0
  148. package/src/navigationboard/NavigationToolbar.tsx +174 -0
  149. package/src/sanitization.ts +7 -5
  150. package/src/types.ts +7 -5
  151. package/src/util.ts +7 -5
  152. package/test/01_types.js +7 -5
  153. package/test/02_chessboard_util.js +7 -5
  154. package/test/03_error_box_graphic.js +7 -5
  155. package/test/04_icons_graphic.js +7 -5
  156. package/test/05_chessboard_graphic.js +9 -5
  157. package/test/06_chessboard_animation.js +7 -5
  158. package/test/07_chessboard_interaction.js +7 -5
  159. package/test/08_chessboard_play_moves.js +7 -5
  160. package/test/09_chessboard_small_screens.js +28 -5
  161. package/test/10_movetext_graphic.js +12 -5
  162. package/test/11_movetext_interaction.js +19 -13
  163. package/test/12_navigation_board.js +168 -0
  164. package/test/common/graphic.js +7 -5
  165. package/test/graphic_references/05_chessboard_graphic/move/illegal_null-move.png +0 -0
  166. package/test/graphic_references/05_chessboard_graphic/move/null-move.png +0 -0
  167. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_bottom_component.png +0 -0
  168. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_top_component.png +0 -0
  169. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_bottom_component.png +0 -0
  170. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_top_component.png +0 -0
  171. package/test/graphic_references/10_movetext_graphic/format_move/format_text.png +0 -0
  172. package/test/graphic_references/10_movetext_graphic/options/wrong_piece_symbol_value.png +0 -0
  173. package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected_without_callback.png +0 -0
  174. package/test/graphic_references/12_navigation_board/controlled/default.png +0 -0
  175. package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_0.png +0 -0
  176. package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_1.png +0 -0
  177. package/test/graphic_references/12_navigation_board/controlled/invalid_node_id.png +0 -0
  178. package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_0.png +0 -0
  179. package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_1.png +0 -0
  180. package/test/graphic_references/12_navigation_board/controlled/overriding_initial_node_id.png +0 -0
  181. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_0.png +0 -0
  182. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_1.png +0 -0
  183. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_2.png +0 -0
  184. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_3.png +0 -0
  185. package/test/graphic_references/12_navigation_board/error/pgn_parsing_error.png +0 -0
  186. package/test/graphic_references/12_navigation_board/error/wrong_game_type.png +0 -0
  187. package/test/graphic_references/12_navigation_board/theme/custom_1.png +0 -0
  188. package/test/graphic_references/12_navigation_board/theme/custom_2.png +0 -0
  189. package/test/graphic_references/12_navigation_board/theme/large.png +0 -0
  190. package/test/graphic_references/12_navigation_board/theme/small.png +0 -0
  191. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_0.png +0 -0
  192. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_1.png +0 -0
  193. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_2.png +0 -0
  194. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_0.png +0 -0
  195. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_1.png +0 -0
  196. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_2.png +0 -0
  197. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_end.png +0 -0
  198. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_specific_id.png +0 -0
  199. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default.png +0 -0
  200. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default_with_game_index.png +0 -0
  201. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_on_null-move.png +0 -0
  202. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_0.png +0 -0
  203. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_1.png +0 -0
  204. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_2.png +0 -0
  205. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_3.png +0 -0
  206. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_4.png +0 -0
  207. package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_0.png +0 -0
  208. package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_1.png +0 -0
  209. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_0.png +0 -0
  210. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_1.png +0 -0
  211. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_2.png +0 -0
  212. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_3.png +0 -0
  213. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_4.png +0 -0
  214. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_5.png +0 -0
  215. package/test/graphic_test_app/03_error_box_graphic/base.tsx +7 -5
  216. package/test/graphic_test_app/03_error_box_graphic/localization.tsx +7 -5
  217. package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +7 -5
  218. package/test/graphic_test_app/04_icons_graphic/marker.tsx +7 -5
  219. package/test/graphic_test_app/05_chessboard_graphic/annotations.tsx +7 -5
  220. package/test/graphic_test_app/05_chessboard_graphic/base.tsx +7 -5
  221. package/test/graphic_test_app/05_chessboard_graphic/chess_variants.tsx +7 -5
  222. package/test/graphic_test_app/05_chessboard_graphic/flipped.tsx +7 -5
  223. package/test/graphic_test_app/05_chessboard_graphic/move.tsx +9 -5
  224. package/test/graphic_test_app/05_chessboard_graphic/theme.tsx +7 -5
  225. package/test/graphic_test_app/06_chessboard_animation/base_1.tsx +7 -5
  226. package/test/graphic_test_app/06_chessboard_animation/base_2.tsx +7 -5
  227. package/test/graphic_test_app/06_chessboard_animation/base_3.tsx +7 -5
  228. package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +7 -5
  229. package/test/graphic_test_app/07_chessboard_interaction/click_squares.tsx +7 -5
  230. package/test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx +7 -5
  231. package/test/graphic_test_app/07_chessboard_interaction/error.tsx +7 -5
  232. package/test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx +7 -5
  233. package/test/graphic_test_app/08_chessboard_play_moves/base.tsx +7 -5
  234. package/test/graphic_test_app/08_chessboard_play_moves/promotions.tsx +7 -5
  235. package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +7 -5
  236. package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +48 -0
  237. package/test/graphic_test_app/10_movetext_graphic/base.tsx +7 -5
  238. package/test/graphic_test_app/10_movetext_graphic/error.tsx +7 -5
  239. package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +31 -0
  240. package/test/graphic_test_app/10_movetext_graphic/html.tsx +7 -5
  241. package/test/graphic_test_app/10_movetext_graphic/options.tsx +8 -5
  242. package/test/graphic_test_app/11_movetext_interaction/error.tsx +7 -5
  243. package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +8 -5
  244. package/test/graphic_test_app/12_navigation_board/controlled.tsx +43 -0
  245. package/test/graphic_test_app/12_navigation_board/error.tsx +34 -0
  246. package/test/graphic_test_app/12_navigation_board/theme.tsx +38 -0
  247. package/test/graphic_test_app/12_navigation_board/uncontrolled.tsx +56 -0
  248. package/test/graphic_test_app/common/decs.d.ts +7 -5
  249. package/test/graphic_test_app/common/test_app.css +7 -5
  250. package/test/graphic_test_app/common/test_app.tsx +7 -5
@@ -1,14 +1,16 @@
1
- /* -------------------------------------------------------------------------- *
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
2
3
  * *
3
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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,32 +24,21 @@
22
24
 
23
25
  import * as React from 'react';
24
26
 
25
- import { exception as kokopuException, MoveDescriptor, Position, Square, GameVariant, isSquare, isSquareCouple, isGameVariant } from 'kokopu';
27
+ import { MoveDescriptor, Position, Square, isSquare, isSquareCouple } from 'kokopu';
26
28
 
27
29
  import { IllegalArgument } from '../exception';
28
- import { i18n } from '../i18n';
29
30
  import { sanitizeString, sanitizeBoolean, sanitizePartialObject, sanitizeInteger, sanitizeBoundedInteger, sanitizeOptional } from '../sanitization';
30
31
  import { MIN_SQUARE_SIZE, MAX_SQUARE_SIZE, Colorset, Pieceset, AnnotationColor, AnnotationSymbol, SquareMarkerSet, TextMarkerSet, ArrowMarkerSet,
31
32
  isAnnotationColor, isAnnotationSymbol, parseSquareMarkers, parseTextMarkers, parseArrowMarkers } from '../types';
32
33
 
33
- import { colorsets, DEFAULT_COLORSET } from './colorsets';
34
- import { piecesets, DEFAULT_PIECESET } from './piecesets';
34
+ import { StaticBoardGraphicProps, DynamicBoardGraphicProps, SmallScreenLimit, DEFAULT_SQUARE_SIZE, defaultDynamicBoardProps } from './BoardProperties';
35
+ import { colorsets } from './colorsets';
36
+ import { piecesets } from './piecesets';
35
37
  import { ChessboardImpl, chessboardSize } from './ChessboardImpl';
36
- import { ErrorBox } from '../errorbox/ErrorBox';
38
+ import { parsePosition, parseMove } from '../errorbox/parsing';
37
39
 
38
40
 
39
- /**
40
- * Define a limit applicable to the parameters of a {@link Chessboard} on small-screen devices.
41
- */
42
- export interface SmallScreenLimit {
43
- width: number;
44
- squareSize?: number;
45
- coordinateVisible?: boolean;
46
- turnVisible?: boolean;
47
- }
48
-
49
-
50
- export interface ChessboardProps {
41
+ export interface ChessboardProps extends DynamicBoardGraphicProps {
51
42
 
52
43
  /**
53
44
  * Displayed position. Can be a [kokopu.Position](https://kokopu.yo35.org/docs/current/classes/Position.html) object,
@@ -62,8 +53,8 @@ export interface ChessboardProps {
62
53
 
63
54
  /**
64
55
  * Displayed move (optional), defined either as a [kokopu.MoveDescriptor](https://kokopu.yo35.org/docs/current/classes/MoveDescriptor.html) object
65
- * or as a [SAN string](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) (e.g. `'Nf3'`). In both cases, it must represent
66
- * a legal move in position defined in attribute `position`.
56
+ * or as a [SAN string](https://en.wikipedia.org/wiki/Algebraic_notation_(chess)) (e.g. `'Nf3'`). Use `'--'` for a null-move.
57
+ * In all cases, the move must be a legal move in position defined in attribute `position`.
67
58
  */
68
59
  move?: MoveDescriptor | string;
69
60
 
@@ -89,61 +80,6 @@ export interface ChessboardProps {
89
80
  */
90
81
  flipped: boolean;
91
82
 
92
- /**
93
- * Size of the squares (in pixels). Must be an integer between `Chessboard.minSquareSize()` and `Chessboard.maxSquareSize()`.
94
- */
95
- squareSize: number;
96
-
97
- /**
98
- * Whether the row and column coordinates are visible or not.
99
- */
100
- coordinateVisible: boolean;
101
-
102
- /**
103
- * Whether the turn flag is visible or not.
104
- */
105
- turnVisible: boolean;
106
-
107
- /**
108
- * Whether moves are highlighted with an arrow or not.
109
- */
110
- moveArrowVisible: boolean;
111
-
112
- /**
113
- * Color of the move arrow.
114
- */
115
- moveArrowColor: AnnotationColor;
116
-
117
- /**
118
- * Whether moves are animated or not.
119
- */
120
- animated: boolean;
121
-
122
- /**
123
- * Color theme ID. Must be a property of `Chessboard.colorsets()`.
124
- */
125
- colorset: string;
126
-
127
- /**
128
- * Piece theme ID. Must be a property of `Chessboard.piecesets()`.
129
- */
130
- pieceset: string;
131
-
132
- /**
133
- * Limits applicable on small-screen devices. For instance, if set to
134
- * ```
135
- * [
136
- * { width: 768, squareSize: 40 },
137
- * { width: 375, squareSize: 24, coordinateVisible: false }
138
- * ]
139
- * ```
140
- * then on screens with resolution ≤768 pixels, the square size will be limited to 40 (whatever the value
141
- * of the `squareSize` attribute); in addition, on screens with resolution ≤375 pixels, the square size
142
- * will be limited to 24 and the row and column coordinates will always be hidden (whatever the value of the
143
- * `coordinateVisible` attribute).
144
- */
145
- smallScreenLimits?: SmallScreenLimit[];
146
-
147
83
  /**
148
84
  * Type of action allowed with the mouse on the chessboard. If undefined, then the user cannot interact with the component.
149
85
  *
@@ -178,6 +114,18 @@ export interface ChessboardProps {
178
114
  * Callback invoked when a move is played (only if `interactionMode` is set to `'playMoves'`).
179
115
  */
180
116
  onMovePlayed?: (move: string) => void;
117
+
118
+ /**
119
+ * Optional component, to be rendered above the chessboard, and customized with the same square-size / coordinate-visible / turn-visible
120
+ * parameter values as actually used for the chessboard (which may be different from what is defined in props because of small-screen limits).
121
+ */
122
+ topComponent?: (attr: Pick<StaticBoardGraphicProps, 'squareSize' | 'coordinateVisible' | 'turnVisible'>) => JSX.Element;
123
+
124
+ /**
125
+ * Optional component, to be rendered below the chessboard, and customized with the same square-size / coordinate-visible / turn-visible
126
+ * parameter values as actually used for the chessboard (which may be different from what is defined in props because of small-screen limits).
127
+ */
128
+ bottomComponent?: (attr: Pick<StaticBoardGraphicProps, 'squareSize' | 'coordinateVisible' | 'turnVisible'>) => JSX.Element;
181
129
  }
182
130
 
183
131
 
@@ -186,9 +134,6 @@ interface ChessboardState {
186
134
  }
187
135
 
188
136
 
189
- const DEFAULT_SQUARE_SIZE = 40;
190
-
191
-
192
137
  /**
193
138
  * SVG image representing a chessboard diagram. Optionally, the user may interact with the board (move pieces, click on squares...).
194
139
  * Annotations such as square markers or arrows can also be added to the board.
@@ -196,16 +141,9 @@ const DEFAULT_SQUARE_SIZE = 40;
196
141
  export class Chessboard extends React.Component<ChessboardProps, ChessboardState> {
197
142
 
198
143
  static defaultProps: Partial<ChessboardProps> = {
144
+ ...defaultDynamicBoardProps(),
199
145
  position: 'start',
200
146
  flipped: false,
201
- squareSize: DEFAULT_SQUARE_SIZE,
202
- coordinateVisible: true,
203
- turnVisible: true,
204
- moveArrowVisible: true,
205
- moveArrowColor: 'b',
206
- animated: false,
207
- colorset: DEFAULT_COLORSET,
208
- pieceset: DEFAULT_PIECESET,
209
147
  };
210
148
 
211
149
  private windowResizeListener = () => this.handleWindowResize();
@@ -232,16 +170,20 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
232
170
  render() {
233
171
 
234
172
  // Validate the position and move attributes.
235
- const positionInfo = parsePosition(this.props.position);
173
+ const positionInfo = parsePosition(this.props.position, 'Chessboard');
236
174
  if (positionInfo.error) {
237
- return <ErrorBox title={i18n.INVALID_FEN_ERROR_TITLE} message={positionInfo.message} />;
175
+ return positionInfo.errorBox;
238
176
  }
239
- const position = positionInfo.position;
240
- const moveInfo = parseMove(position, this.props.move);
177
+ let position = positionInfo.position;
178
+ const moveInfo = parseMove(position, this.props.move, 'Chessboard');
241
179
  if (moveInfo.error) {
242
- return <ErrorBox title={i18n.INVALID_NOTATION_ERROR_TITLE} message={moveInfo.message} />;
180
+ return moveInfo.errorBox;
181
+ }
182
+ const move = moveInfo.type === 'regular' ? moveInfo.move : undefined;
183
+ if (moveInfo.type === 'null-move') {
184
+ position = new Position(position);
185
+ position.playNullMove();
243
186
  }
244
- const move = moveInfo.move;
245
187
 
246
188
  // Validate the markers
247
189
  const sqm = parseMarkers(this.props.squareMarkers, 'squareMarkers', parseSquareMarkers, isSquare, isAnnotationColor);
@@ -272,6 +214,11 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
272
214
  const actualSquareSize = computeSquareSizeForSmallScreens(squareSize, smallScreenLimits, this.state.windowWidth);
273
215
  const actualCoordinateVisible = computeCoordinateVisibleForSmallScreens(coordinateVisible, smallScreenLimits, this.state.windowWidth);
274
216
  const actualTurnVisible = computeTurnVisibleForSmallScreens(turnVisible, smallScreenLimits, this.state.windowWidth);
217
+ const auxilliaryComponentAttr = {
218
+ squareSize: actualSquareSize,
219
+ coordinateVisible: actualCoordinateVisible,
220
+ turnVisible: actualTurnVisible,
221
+ };
275
222
 
276
223
  // Validate the interaction attributes and the callbacks.
277
224
  const interactionMode = this.getInteractionModeAndValidateEditedArrowColor();
@@ -281,7 +228,8 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
281
228
  // (mandatory to ensure that the move animation works properly and that the internal state of the component remains consistent).
282
229
  const key = `${position.variant()}|${position.fen()}|${move ? position.notation(move) : ''}`;
283
230
 
284
- return (
231
+ return (<>
232
+ {this.props.topComponent ? this.props.topComponent(auxilliaryComponentAttr) : undefined}
285
233
  <ChessboardImpl key={key}
286
234
  position={position} move={move} squareMarkers={sqm} textMarkers={txtm} arrowMarkers={arm} flipped={flipped}
287
235
  squareSize={actualSquareSize} coordinateVisible={actualCoordinateVisible} turnVisible={actualTurnVisible}
@@ -290,7 +238,8 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
290
238
  interactionMode={interactionMode} editedArrowColor={this.props.editedArrowColor}
291
239
  onPieceMoved={onPieceMoved} onSquareClicked={onSquareClicked} onArrowEdited={onArrowEdited} onMovePlayed={onMovePlayed}
292
240
  />
293
- );
241
+ {this.props.bottomComponent ? this.props.bottomComponent(auxilliaryComponentAttr) : undefined}
242
+ </>);
294
243
  }
295
244
 
296
245
  private getInteractionModeAndValidateEditedArrowColor() {
@@ -337,7 +286,7 @@ export class Chessboard extends React.Component<ChessboardProps, ChessboardState
337
286
  * Return the maximum square size that would allow the chessboard to fit in a rectangle of size `width x height`.
338
287
  */
339
288
  static adaptSquareSize(width: number, height: number, attr?: Partial<Pick<ChessboardProps, 'coordinateVisible' | 'turnVisible' | 'smallScreenLimits'>>): number {
340
- let { coordinateVisible, turnVisible, smallScreenLimits } = sanitizePartialObject(attr, () => new IllegalArgument('Chessboard.size()', 'attr'));
289
+ let { coordinateVisible, turnVisible, smallScreenLimits } = sanitizePartialObject(attr, () => new IllegalArgument('Chessboard.adaptSquareSize()', 'attr'));
341
290
 
342
291
  // Sanitize the arguments.
343
292
  width = sanitizeInteger(width, () => new IllegalArgument('Chessboard.adaptSquareSize()', 'width'));
@@ -471,82 +420,6 @@ function computeSmallScreenLimits<T>(smallScreenLimits: SmallScreenLimit[], wind
471
420
  }
472
421
 
473
422
 
474
- /**
475
- * Try to interpret the given object as a chess position.
476
- */
477
- function parsePosition(position: Position | string): { error: true, message: string } | { error: false, position: Position } {
478
- if (position instanceof Position) {
479
- return { error: false, position: position };
480
- }
481
- else if (position === 'start' || position === 'empty') {
482
- return { error: false, position: new Position(position) };
483
- }
484
- else if (typeof position === 'string') {
485
- try {
486
- const { variant, fen } = splitGameVariantAndFEN(position);
487
- const result = new Position(variant, 'empty');
488
- result.fen(fen);
489
- return { error: false, position: result };
490
- }
491
- catch (e) {
492
- // istanbul ignore else
493
- if (e instanceof kokopuException.InvalidFEN) {
494
- return { error: true, message: e.message };
495
- }
496
- else {
497
- throw e;
498
- }
499
- }
500
- }
501
- else {
502
- throw new IllegalArgument('Chessboard', 'position');
503
- }
504
- }
505
-
506
-
507
- /**
508
- * Look for an optional 'chess-variant:' prefix in the position attribute.
509
- */
510
- function splitGameVariantAndFEN(position: string): { variant: GameVariant, fen: string } {
511
- const separatorIndex = position.indexOf(':');
512
- if (separatorIndex < 0) {
513
- return { variant: 'regular', fen: position };
514
- }
515
- const variant = position.substring(0, separatorIndex);
516
- return isGameVariant(variant) ? { variant: variant, fen: position.substring(separatorIndex + 1) } : { variant: 'regular', fen: position };
517
- }
518
-
519
-
520
- /**
521
- * Try to interpret the given object `move` as a move descriptor based on the given position.
522
- */
523
- function parseMove(position: Position, move: MoveDescriptor | string | undefined): { error: true, message: string } | { error: false, move: MoveDescriptor | undefined } {
524
- if (move === undefined || move === null) {
525
- return { error: false, move: undefined };
526
- }
527
- else if (move instanceof MoveDescriptor) {
528
- return { error: false, move: move };
529
- }
530
- else if (typeof move === 'string') {
531
- try {
532
- return { error: false, move: position.notation(move) };
533
- }
534
- catch (e) {
535
- // istanbul ignore else
536
- if (e instanceof kokopuException.InvalidNotation) {
537
- return { error: true, message: e.message };
538
- }
539
- else {
540
- throw e;
541
- }
542
- }
543
- }
544
- else {
545
- throw new IllegalArgument('Chessboard', 'move');
546
- }
547
- }
548
-
549
-
550
423
  /**
551
424
  * Try to interpret the given object as a list of markers.
552
425
  */
@@ -1,14 +1,16 @@
1
- /* -------------------------------------------------------------------------- *
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
2
3
  * *
3
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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. *
package/src/decs.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- /* -------------------------------------------------------------------------- *
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
2
3
  * *
3
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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
- * This file is part of Kokopu-React, a JavaScript chess library. *
4
- * Copyright (C) 2021-2023 Yoann Le Montagner <yo35 -at- melix.net> *
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
- * This program is free software: you can redistribute it and/or *
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
- * This program is distributed in the hope that it will be useful, *
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. *