kokopu-react 3.2.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/lib/chessboard/Chessboard.d.ts +27 -2
- package/dist/lib/chessboard/Chessboard.js +38 -18
- package/dist/lib/chessboard/Chessboard.js.map +1 -1
- package/dist/lib/chessboard/ChessboardImpl.js +1 -1
- package/dist/lib/chessboard/ChessboardImpl.js.map +1 -1
- package/dist/lib/chessboard/Motion.js +1 -1
- package/dist/lib/chessboard/Motion.js.map +1 -1
- package/dist/lib/i18n.js +2 -2
- package/dist/lib/i18n.js.map +1 -1
- package/dist/lib/icons/ArrowMarkerIcon.js.map +1 -1
- package/dist/lib/icons/ChessPieceIcon.d.ts +1 -4
- package/dist/lib/icons/ChessPieceIcon.js +1 -5
- package/dist/lib/icons/ChessPieceIcon.js.map +1 -1
- package/dist/lib/icons/SquareMarkerIcon.d.ts +1 -4
- package/dist/lib/icons/SquareMarkerIcon.js +1 -5
- package/dist/lib/icons/SquareMarkerIcon.js.map +1 -1
- package/dist/lib/icons/TextMarkerIcon.d.ts +1 -4
- package/dist/lib/icons/TextMarkerIcon.js +1 -5
- package/dist/lib/icons/TextMarkerIcon.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/movetext/Movetext.js.map +1 -1
- package/dist/lib/movetext/MovetextImpl.js +4 -3
- package/dist/lib/movetext/MovetextImpl.js.map +1 -1
- package/dist/lib/movetext/htmlFilter.js +1 -1
- package/dist/lib/movetext/htmlFilter.js.map +1 -1
- package/dist/lib/navigationboard/NavigationBoard.d.ts +37 -8
- package/dist/lib/navigationboard/NavigationBoard.js +67 -22
- package/dist/lib/navigationboard/NavigationBoard.js.map +1 -1
- package/dist/lib/navigationboard/NavigationButton.d.ts +13 -1
- package/dist/lib/navigationboard/NavigationButton.js +32 -0
- package/dist/lib/navigationboard/NavigationButton.js.map +1 -1
- package/dist/lib/navigationboard/NavigationField.js +1 -1
- package/dist/lib/navigationboard/NavigationField.js.map +1 -1
- package/dist/lib/navigationboard/NavigationToolbar.d.ts +9 -2
- package/dist/lib/navigationboard/NavigationToolbar.js +34 -1
- package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -1
- package/dist/lib/util.js +2 -2
- package/dist/lib/util.js.map +1 -1
- package/doc_src/demo/PageChessboardBase.tsx +57 -51
- package/doc_src/demo/PageChessboardInteraction.tsx +78 -63
- package/doc_src/demo/PageChessboardMove.tsx +35 -30
- package/doc_src/demo/PageChessboardSmallScreens.tsx +3 -3
- package/doc_src/demo/PageMovetextBase.tsx +91 -81
- package/doc_src/demo/PageMovetextInteraction.tsx +23 -21
- package/doc_src/demo/PageNavigationBoardBase.tsx +62 -54
- package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +24 -18
- package/doc_src/theming/LogoRenderer.js +8 -9
- package/package.json +30 -28
- package/scripts/docker-compose.yml +1 -3
- package/src/chessboard/BoardProperties.ts +13 -13
- package/src/chessboard/Chessboard.tsx +106 -46
- package/src/chessboard/ChessboardImpl.tsx +58 -41
- package/src/chessboard/Draggable.tsx +15 -15
- package/src/chessboard/Motion.tsx +4 -4
- package/src/errorbox/ErrorBox.tsx +5 -5
- package/src/errorbox/parsing.tsx +6 -6
- package/src/i18n.ts +2 -2
- package/src/icons/AnnotationSymbolShape.tsx +5 -5
- package/src/icons/ArrowMarkerIcon.tsx +8 -4
- package/src/icons/ArrowTip.tsx +2 -2
- package/src/icons/ChessPieceIcon.tsx +4 -11
- package/src/icons/SquareMarkerIcon.tsx +3 -10
- package/src/icons/TextMarkerIcon.tsx +4 -11
- package/src/index.ts +1 -1
- package/src/movetext/Movetext.tsx +11 -10
- package/src/movetext/MovetextImpl.tsx +34 -28
- package/src/movetext/htmlFilter.tsx +4 -4
- package/src/navigationboard/NavigationBoard.tsx +150 -58
- package/src/navigationboard/NavigationButton.ts +47 -5
- package/src/navigationboard/NavigationField.tsx +6 -6
- package/src/navigationboard/NavigationToolbar.tsx +62 -15
- package/src/types.ts +26 -26
- package/src/util.ts +2 -2
- package/test/01_types.js +83 -61
- package/test/02_chessboard_util.js +79 -1
- package/test/03_error_box_graphic.js +1 -1
- package/test/07_chessboard_interaction.js +1 -2
- package/test/13_navigation_board_graphic.js +3 -3
- package/test/common/graphic.js +11 -11
- package/test/graphic_references/03_error_box_graphic/base/cut_beginning_of_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/cut_end_of_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/cut_on_line_breaks.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/error_index_not_integer.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/full.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/minimal.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/missing_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/missing_error_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/negative_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/single_character_text.png +0 -0
- package/test/graphic_references/03_error_box_graphic/base/too_large_error_index.png +0 -0
- package/test/graphic_references/03_error_box_graphic/localization/default.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/customized_pieceset.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/invalid_multiple_pieces.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/invalid_pieceset.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/invalid_single_piece.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/invalid_size.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/multiple_pieces.png +0 -0
- package/test/graphic_references/04_icons_graphic/chess_piece/single_piece.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/colorized_arrow.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/colorized_square.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/colorized_symbol.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/colorized_text.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/default_arrow.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/default_square.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/default_text.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/invalid_arrow_size.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/invalid_square_size.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/invalid_symbol.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/invalid_text_size.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/wrapped_arrow.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/wrapped_square.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/wrapped_symbol.png +0 -0
- package/test/graphic_references/04_icons_graphic/marker/wrapped_text.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/overlap.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/overlap_and_flip.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/with_coordinates.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/with_coordinates_and_flip.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/without_coordinates.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/annotations/without_coordinates_and_flip.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/default.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/empty.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/from_fen.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/from_kokopu_object.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/parsing_error.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/base/wrong_position_type.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/chess960.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/chess960_with_move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/invalid_variant.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/invalid_variant_with_fen.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/special_code.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/variant_with_std_initial_position.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/chess_variants/variant_without_std_initial_position.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/default.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/empty.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/from_fen.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/from_kokopu_object.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/flipped/parsing_error.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/capture.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/castling_move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/default.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/en-passant.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/illegal_null-move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/no_move_arrow.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/null-move.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/parsing_error.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/promotion.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/with_forced_move_arrow_and_flip.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/wrong_move_arrow_color_type.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/move/wrong_move_type.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_1.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_2.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_3.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_4.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_5.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/custom_6.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/default.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/large.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/small.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_colorset.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_pieceset.png +0 -0
- package/test/graphic_references/05_chessboard_graphic/theme/wrong_square_size_type.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/capture.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/castling_move.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/en-passant.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/move_1.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/move_2.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_1/promotion.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/capture.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/castling_move.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/en-passant.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/move_1.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/move_2.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_2/promotion.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/capture.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/castling_move.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/en-passant.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/move_1.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/move_2.png +0 -0
- package/test/graphic_references/06_chessboard_animation/base_3/promotion.png +0 -0
- package/test/graphic_references/06_chessboard_animation/on_redraw/final_state.png +0 -0
- package/test/graphic_references/06_chessboard_animation/on_redraw/initial_state.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/base_1.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/base_2.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/from_==_to.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/out_of_board.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/over_arrow_marker.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/edit_arrows/over_square_marker.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/error/edit_color_not_set.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/error/wrong_interaction_mode.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/after_move.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/from_==_to.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/move_empty_square.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/out_of_board.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_arrow_marker.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_empty.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_non-empty_1.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_non-empty_2.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_square_marker.png +0 -0
- package/test/graphic_references/07_chessboard_interaction/move_pieces/over_text_marker.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/castling_move.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/chess960_ambiguous_king_move.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/chess960_castling_move_1.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/chess960_castling_move_2.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/chess960_non-kxr_castling.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/from_==_to.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/illegal_move.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/illegal_position.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/out_of_board.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/regular_move_1.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/regular_move_2.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/base/wrong_color_moved.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/promotions/antichess_promotion.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/promotions/cancel_promotion.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/promotions/regular_promotion_1.png +0 -0
- package/test/graphic_references/08_chessboard_play_moves/promotions/regular_promotion_2.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/default.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/invalid_limits.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_690.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_700.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_710.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_720.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_730.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_740.png +0 -0
- package/test/graphic_references/09_chessboard_small_screens/base/width_750.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/base/game_1.png +0 -0
- package/test/graphic_references/10_movetext_graphic/base/game_2.png +0 -0
- package/test/graphic_references/10_movetext_graphic/base/game_3.png +0 -0
- package/test/graphic_references/10_movetext_graphic/base/game_4.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/pgn_parsing_error_1.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/pgn_parsing_error_2.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/wrong_game_index_1.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/wrong_game_index_2.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/wrong_game_index_type.png +0 -0
- package/test/graphic_references/10_movetext_graphic/error/wrong_game_type.png +0 -0
- package/test/graphic_references/10_movetext_graphic/format_move/format_text.png +0 -0
- package/test/graphic_references/10_movetext_graphic/html/filtered_tags_and_attributes.png +0 -0
- package/test/graphic_references/10_movetext_graphic/html/html_in_comments.png +0 -0
- package/test/graphic_references/10_movetext_graphic/html/html_in_headers.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/custom_piece_symbols.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/figurine_piece_symbols_and_diagram_options.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/hidden_diagrams.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/localized_piece_symbols.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/other_diagram_options.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/wrong_diagram_options_1.png +0 -0
- package/test/graphic_references/10_movetext_graphic/options/wrong_diagram_options_2.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/error/wrong_interaction_mode.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_disabled.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected_without_callback.png +0 -0
- package/test/graphic_references/11_movetext_interaction/select_moves/click_on_with_variations.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 +18 -6
- package/test/graphic_test_app/04_icons_graphic/chess_piece.tsx +12 -3
- package/test/graphic_test_app/04_icons_graphic/marker.tsx +14 -4
- package/test/graphic_test_app/05_chessboard_graphic/annotations.tsx +7 -3
- package/test/graphic_test_app/05_chessboard_graphic/base.tsx +1 -1
- package/test/graphic_test_app/05_chessboard_graphic/move.tsx +9 -2
- package/test/graphic_test_app/05_chessboard_graphic/theme.tsx +1 -1
- package/test/graphic_test_app/06_chessboard_animation/on_redraw.tsx +8 -6
- package/test/graphic_test_app/07_chessboard_interaction/click_squares.tsx +4 -2
- package/test/graphic_test_app/07_chessboard_interaction/edit_arrows.tsx +4 -2
- package/test/graphic_test_app/07_chessboard_interaction/error.tsx +3 -1
- package/test/graphic_test_app/07_chessboard_interaction/move_pieces.tsx +4 -2
- package/test/graphic_test_app/08_chessboard_play_moves/base.tsx +12 -6
- package/test/graphic_test_app/08_chessboard_play_moves/promotions.tsx +12 -3
- package/test/graphic_test_app/09_chessboard_small_screens/base.tsx +3 -1
- package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +8 -6
- package/test/graphic_test_app/10_movetext_graphic/error.tsx +1 -1
- package/test/graphic_test_app/10_movetext_graphic/options.tsx +16 -6
- package/test/graphic_test_app/11_movetext_interaction/error.tsx +4 -1
- package/test/graphic_test_app/13_navigation_board_graphic/additional_buttons.tsx +24 -17
- package/test/graphic_test_app/13_navigation_board_graphic/error.tsx +1 -1
- package/test/graphic_test_app/14_navigation_board_autoplay/controlled.tsx +34 -18
- package/test/graphic_test_app/common/test_app.tsx +4 -4
- package/.eslintrc.yml +0 -83
- package/test/.eslintrc.yml +0 -8
- package/test/graphic_test_app/.eslintrc.yml +0 -3
|
@@ -28,15 +28,15 @@ import { Database, Game, Node as GameNode, Variation } from 'kokopu';
|
|
|
28
28
|
|
|
29
29
|
import { IllegalArgument } from '../exception';
|
|
30
30
|
import { i18n } from '../i18n';
|
|
31
|
-
import { sanitizeBoolean, sanitizeOptional, sanitizeString } from '../sanitization';
|
|
31
|
+
import { sanitizeBoolean, sanitizeOptional, sanitizeString, sanitizePartialObject } from '../sanitization';
|
|
32
32
|
|
|
33
33
|
import { DynamicBoardGraphicProps, defaultDynamicBoardProps } from '../chessboard/BoardProperties';
|
|
34
34
|
import { Chessboard } from '../chessboard/Chessboard';
|
|
35
35
|
import { parseGame } from '../errorbox/parsing';
|
|
36
36
|
import { NavigationField, firstNodeId, previousNodeId, nextNodeId, lastNodeId } from '../navigationboard/NavigationField';
|
|
37
37
|
import { GO_FIRST_ICON_PATH, GO_PREVIOUS_ICON_PATH, GO_NEXT_ICON_PATH, GO_LAST_ICON_PATH, PLAY_ICON_PATH, STOP_ICON_PATH, FLIP_ICON_PATH } from './iconPaths';
|
|
38
|
-
import {
|
|
39
|
-
import { NavigationToolbar } from './NavigationToolbar';
|
|
38
|
+
import { NavigationBar, NavigationBarScheme, isNavigationBar, isNavigationBarScheme } from './NavigationButton';
|
|
39
|
+
import { NavigationToolbar, navigationToolbarSize } from './NavigationToolbar';
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
const INTER_MOVE_DURATION = 1000;
|
|
@@ -49,28 +49,28 @@ export interface NavigationBoardProps extends DynamicBoardGraphicProps {
|
|
|
49
49
|
* a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html) object,
|
|
50
50
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation).
|
|
51
51
|
*/
|
|
52
|
-
game: Game | Database | string
|
|
52
|
+
game: Game | Database | string,
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Index of the game to display (only if attribute `game` is a [kokopu.Database](https://kokopu.yo35.org/docs/current/classes/Database.html)
|
|
56
56
|
* or a [PGN string](https://en.wikipedia.org/wiki/Portable_Game_Notation)): `0` for the first game of the database/PGN, `1` for the second one, etc.
|
|
57
57
|
* If omitted, the first game of the database/PGN is displayed.
|
|
58
58
|
*/
|
|
59
|
-
gameIndex: number
|
|
59
|
+
gameIndex: number,
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* ID of the move initially selected (or `'start'`/`'end'` for the beginning/end of the main variation) when the component is uncontrolled.
|
|
63
63
|
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id) to get the ID of a game move.
|
|
64
64
|
* Ignored if the `nodeId` attribute is provided.
|
|
65
65
|
*/
|
|
66
|
-
initialNodeId: string
|
|
66
|
+
initialNodeId: string,
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
69
|
* ID of the selected move (or `'start'`/`'end'` for the beginning/end of the main variation).
|
|
70
70
|
* Use [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id) to get the ID of a game move.
|
|
71
71
|
* If provided (i.e. if the component is controlled), the attribute `onNodeIdChanged` must be provided as well.
|
|
72
72
|
*/
|
|
73
|
-
nodeId?: string
|
|
73
|
+
nodeId?: string,
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Callback invoked in controlled-component mode, when the user changes the selected move.
|
|
@@ -78,67 +78,94 @@ export interface NavigationBoardProps extends DynamicBoardGraphicProps {
|
|
|
78
78
|
* @param nodeId - ID of the selected move (as returned by [kokopu.Node#id](https://kokopu.yo35.org/docs/current/classes/Node.html#id)),
|
|
79
79
|
* or `'start'` for the beginning of the main variation.
|
|
80
80
|
*/
|
|
81
|
-
onNodeIdChanged?: (nodeId: string) => void
|
|
81
|
+
onNodeIdChanged?: (nodeId: string) => void,
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
84
|
* Whether auto-play is initially enabled or not.
|
|
85
85
|
* Ignored if the `isPlaying` attribute is provided.
|
|
86
86
|
*/
|
|
87
|
-
initialIsPlaying: boolean
|
|
87
|
+
initialIsPlaying: boolean,
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
90
|
* Whether auto-play is enabled or not.
|
|
91
91
|
* If provided (i.e. if the is-playing state is controlled), the attribute `onIsPlayingChanged` must be provided as well.
|
|
92
92
|
*/
|
|
93
|
-
isPlaying?: boolean
|
|
93
|
+
isPlaying?: boolean,
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* Callback invoked in controlled-is-playing-state mode, when the user clicks on the play/stop button.
|
|
97
97
|
*
|
|
98
98
|
* @param isPlaying - New is-playing state.
|
|
99
99
|
*/
|
|
100
|
-
onIsPlayingChanged?: (isPlaying: boolean) => void
|
|
100
|
+
onIsPlayingChanged?: (isPlaying: boolean) => void,
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Whether the board is initially flipped (i.e. seen from Black's point of view) or not, when the flip state is uncontrolled.
|
|
104
104
|
* Ignored if the `flipped` attribute is provided.
|
|
105
105
|
*/
|
|
106
|
-
initialFlipped: boolean
|
|
106
|
+
initialFlipped: boolean,
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Whether the board is flipped (i.e. seen from Black's point of view) or not.
|
|
110
110
|
* If provided (i.e. if the flip state is controlled), the attribute `onFlippedChanged` must be provided as well.
|
|
111
111
|
*/
|
|
112
|
-
flipped?: boolean
|
|
112
|
+
flipped?: boolean,
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* Callback invoked in controlled-flip-state mode, when the user flips the board.
|
|
116
116
|
*
|
|
117
117
|
* @param flipped - New flip state.
|
|
118
118
|
*/
|
|
119
|
-
onFlippedChanged?: (flipped: boolean) => void
|
|
119
|
+
onFlippedChanged?: (flipped: boolean) => void,
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* Whether the play/stop button is visible or not in the toolbar.
|
|
123
123
|
*/
|
|
124
|
-
playButtonVisible: boolean
|
|
124
|
+
playButtonVisible: boolean,
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* Whether the flip button is visible or not in the toolbar.
|
|
128
128
|
*/
|
|
129
|
-
flipButtonVisible: boolean
|
|
129
|
+
flipButtonVisible: boolean,
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
132
|
* Additional buttons to be added to the toolbar.
|
|
133
133
|
*/
|
|
134
|
-
additionalButtons:
|
|
134
|
+
additionalButtons: NavigationBar,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Attributes for method `NavigationBoard.size()`.
|
|
140
|
+
*/
|
|
141
|
+
interface NavigationBoardSizeAttr {
|
|
142
|
+
squareSize?: NavigationBoardProps['squareSize'],
|
|
143
|
+
coordinateVisible?: NavigationBoardProps['coordinateVisible'],
|
|
144
|
+
turnVisible?: NavigationBoardProps['turnVisible'],
|
|
145
|
+
smallScreenLimits?: NavigationBoardProps['smallScreenLimits'],
|
|
146
|
+
playButtonVisible?: NavigationBoardProps['playButtonVisible'],
|
|
147
|
+
flipButtonVisible?: NavigationBoardProps['flipButtonVisible'],
|
|
148
|
+
additionalButtons?: NavigationBarScheme,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Attributes for method `NavigationBoard.adaptSquareSize()`.
|
|
154
|
+
*/
|
|
155
|
+
interface NavigationBoardAdaptSquareSizeAttr {
|
|
156
|
+
coordinateVisible?: NavigationBoardProps['coordinateVisible'],
|
|
157
|
+
turnVisible?: NavigationBoardProps['turnVisible'],
|
|
158
|
+
smallScreenLimits?: NavigationBoardProps['smallScreenLimits'],
|
|
159
|
+
playButtonVisible?: NavigationBoardProps['playButtonVisible'],
|
|
160
|
+
flipButtonVisible?: NavigationBoardProps['flipButtonVisible'],
|
|
161
|
+
additionalButtons?: NavigationBarScheme,
|
|
135
162
|
}
|
|
136
163
|
|
|
137
164
|
|
|
138
165
|
interface NavigationBoardState {
|
|
139
|
-
nodeIdAsUncontrolled: string
|
|
140
|
-
isPlayingAsUncontrolled: boolean
|
|
141
|
-
flippedAsUncontrolled: boolean
|
|
166
|
+
nodeIdAsUncontrolled: string,
|
|
167
|
+
isPlayingAsUncontrolled: boolean,
|
|
168
|
+
flippedAsUncontrolled: boolean,
|
|
142
169
|
}
|
|
143
170
|
|
|
144
171
|
|
|
@@ -203,33 +230,40 @@ export class NavigationBoard extends React.Component<NavigationBoardProps, Navig
|
|
|
203
230
|
private renderBoard(game: Game, node: GameNode | Variation, isPlaying: boolean, flipped: boolean) {
|
|
204
231
|
const position = node instanceof GameNode ? node.positionBefore() : node.initialPosition();
|
|
205
232
|
const move = node instanceof GameNode ? node.notation() : undefined;
|
|
206
|
-
return
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
233
|
+
return (
|
|
234
|
+
<Chessboard
|
|
235
|
+
position={position} move={move} flipped={flipped}
|
|
236
|
+
squareMarkers={node.tag('csl')} arrowMarkers={node.tag('cal')} textMarkers={node.tag('ctl')}
|
|
237
|
+
squareSize={this.props.squareSize}
|
|
238
|
+
coordinateVisible={this.props.coordinateVisible}
|
|
239
|
+
turnVisible={this.props.turnVisible}
|
|
240
|
+
colorset={this.props.colorset}
|
|
241
|
+
pieceset={this.props.pieceset}
|
|
242
|
+
smallScreenLimits={this.props.smallScreenLimits}
|
|
243
|
+
moveArrowVisible={this.props.moveArrowVisible}
|
|
244
|
+
moveArrowColor={this.props.moveArrowColor}
|
|
245
|
+
animated={this.props.animated}
|
|
246
|
+
bottomComponent={({ squareSize }) => this.renderToolbar(game, node, squareSize, isPlaying)}
|
|
247
|
+
/>
|
|
248
|
+
);
|
|
220
249
|
}
|
|
221
250
|
|
|
222
251
|
private renderNavigationField(game: Game, currentNodeId: string) {
|
|
223
|
-
return
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
252
|
+
return (
|
|
253
|
+
<NavigationField
|
|
254
|
+
ref={this.navigationFieldRef}
|
|
255
|
+
onFirstPressed={() => this.handleNavClicked(firstNodeId(game, currentNodeId))}
|
|
256
|
+
onPreviousPressed={() => this.handleNavClicked(previousNodeId(game, currentNodeId))}
|
|
257
|
+
onNextPressed={() => this.handleNavClicked(nextNodeId(game, currentNodeId))}
|
|
258
|
+
onLastPressed={() => this.handleNavClicked(lastNodeId(game, currentNodeId))}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
229
261
|
}
|
|
230
262
|
|
|
231
263
|
private renderToolbar(game: Game, node: GameNode | Variation, squareSize: number, isPlaying: boolean) {
|
|
232
|
-
|
|
264
|
+
|
|
265
|
+
// WARNING: the logic here must be the same as the one in `computeBarScheme()`.
|
|
266
|
+
const buttons: NavigationBar = [];
|
|
233
267
|
|
|
234
268
|
// Core navigation buttons
|
|
235
269
|
const currentNodeId = node.id();
|
|
@@ -260,8 +294,10 @@ export class NavigationBoard extends React.Component<NavigationBoardProps, Navig
|
|
|
260
294
|
}
|
|
261
295
|
|
|
262
296
|
// Additional buttons.
|
|
263
|
-
|
|
264
|
-
|
|
297
|
+
if (!isNavigationBar(this.props.additionalButtons)) {
|
|
298
|
+
throw new IllegalArgument('NavigationBoard', 'additionalButtons');
|
|
299
|
+
}
|
|
300
|
+
for (const button of this.props.additionalButtons) {
|
|
265
301
|
buttons.push(button);
|
|
266
302
|
}
|
|
267
303
|
|
|
@@ -326,25 +362,81 @@ export class NavigationBoard extends React.Component<NavigationBoardProps, Navig
|
|
|
326
362
|
}
|
|
327
363
|
}
|
|
328
364
|
|
|
329
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Return the size of the {@link NavigationBoard}, assuming it is built with the given attributes.
|
|
367
|
+
*/
|
|
368
|
+
static size(attr?: NavigationBoardSizeAttr): { width: number, height: number } {
|
|
369
|
+
const { squareSize, coordinateVisible, turnVisible, smallScreenLimits, playButtonVisible, flipButtonVisible, additionalButtons } =
|
|
370
|
+
sanitizePartialObject(attr, () => new IllegalArgument('NavigationBoard.size()', 'attr'));
|
|
371
|
+
|
|
372
|
+
// Sanitization
|
|
373
|
+
const actualPlayButtonVisible = sanitizeOptional(playButtonVisible, sanitizeBoolean);
|
|
374
|
+
const actualFlipButtonVisible = sanitizeOptional(flipButtonVisible, sanitizeBoolean);
|
|
375
|
+
if (additionalButtons !== undefined && !isNavigationBarScheme(additionalButtons)) {
|
|
376
|
+
throw new IllegalArgument('NavigationBoard.size()', 'additionalButtons');
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const buttons = computeBarScheme(actualPlayButtonVisible, actualFlipButtonVisible, additionalButtons);
|
|
380
|
+
return Chessboard.size({
|
|
381
|
+
squareSize: squareSize,
|
|
382
|
+
coordinateVisible: coordinateVisible,
|
|
383
|
+
turnVisible: turnVisible,
|
|
384
|
+
smallScreenLimits: smallScreenLimits,
|
|
385
|
+
bottomComponent: ({ squareSize: sz }) => navigationToolbarSize(sz, buttons),
|
|
386
|
+
});
|
|
387
|
+
}
|
|
330
388
|
|
|
389
|
+
/**
|
|
390
|
+
* Return the maximum square size that would allow the {@link NavigationBoard} to fit in a rectangle of size `width x height`.
|
|
391
|
+
*/
|
|
392
|
+
static adaptSquareSize(width: number, height: number, attr?: NavigationBoardAdaptSquareSizeAttr): number {
|
|
331
393
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
394
|
+
const { coordinateVisible, turnVisible, smallScreenLimits, playButtonVisible, flipButtonVisible, additionalButtons } =
|
|
395
|
+
sanitizePartialObject(attr, () => new IllegalArgument('NavigationBoard.adaptSquareSize()', 'attr'));
|
|
396
|
+
|
|
397
|
+
// Sanitization
|
|
398
|
+
const actualPlayButtonVisible = sanitizeOptional(playButtonVisible, sanitizeBoolean);
|
|
399
|
+
const actualFlipButtonVisible = sanitizeOptional(flipButtonVisible, sanitizeBoolean);
|
|
400
|
+
if (additionalButtons !== undefined && !isNavigationBarScheme(additionalButtons)) {
|
|
401
|
+
throw new IllegalArgument('NavigationBoard.adaptSquareSize()', 'additionalButtons');
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
const buttons = computeBarScheme(actualPlayButtonVisible, actualFlipButtonVisible, additionalButtons);
|
|
405
|
+
return Chessboard.adaptSquareSize(width, height, {
|
|
406
|
+
coordinateVisible: coordinateVisible,
|
|
407
|
+
turnVisible: turnVisible,
|
|
408
|
+
smallScreenLimits: smallScreenLimits,
|
|
409
|
+
bottomComponent: ({ squareSize: sz }) => navigationToolbarSize(sz, buttons),
|
|
342
410
|
});
|
|
343
411
|
}
|
|
344
|
-
|
|
345
|
-
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
function computeBarScheme(playButtonVisible: boolean | undefined, flipButtonVisible: boolean | undefined,
|
|
417
|
+
additionalButtons: NavigationBarScheme | undefined): NavigationBarScheme {
|
|
418
|
+
|
|
419
|
+
// WARNING: the logic here must be the same as the one in `renderToolbar()`.
|
|
420
|
+
const buttons: NavigationBarScheme = [];
|
|
421
|
+
|
|
422
|
+
buttons.push('button'); // go-first
|
|
423
|
+
buttons.push('button'); // go-previous
|
|
424
|
+
if (playButtonVisible ?? NavigationBoard.defaultProps.playButtonVisible) {
|
|
425
|
+
buttons.push('button');
|
|
426
|
+
}
|
|
427
|
+
buttons.push('button'); // go-next
|
|
428
|
+
buttons.push('button'); // go-last
|
|
429
|
+
buttons.push('spacer');
|
|
430
|
+
if (flipButtonVisible ?? NavigationBoard.defaultProps.flipButtonVisible) {
|
|
431
|
+
buttons.push('button');
|
|
346
432
|
}
|
|
347
|
-
|
|
348
|
-
|
|
433
|
+
buttons.push('spacer');
|
|
434
|
+
|
|
435
|
+
if (additionalButtons !== undefined) {
|
|
436
|
+
for (const button of additionalButtons) {
|
|
437
|
+
buttons.push(button);
|
|
438
|
+
}
|
|
349
439
|
}
|
|
440
|
+
|
|
441
|
+
return buttons;
|
|
350
442
|
}
|
|
@@ -33,29 +33,35 @@ export type NavigationButton = {
|
|
|
33
33
|
*
|
|
34
34
|
* The path is rendered within 32 x 32 viewbox (defined as `viewbox="0 0 32 32"`). It must be be a closed path, and must fit within the viewbox incircle.
|
|
35
35
|
*/
|
|
36
|
-
iconPath: string
|
|
36
|
+
iconPath: string,
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Human-readable tooltip.
|
|
40
40
|
*/
|
|
41
|
-
tooltip?: string
|
|
41
|
+
tooltip?: string,
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Whether or not the button is enabled (true by default).
|
|
45
45
|
*/
|
|
46
|
-
enabled?: boolean
|
|
46
|
+
enabled?: boolean,
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Callback invoked when the user clicks on the button.
|
|
50
50
|
*/
|
|
51
|
-
onClick?: () => void
|
|
51
|
+
onClick?: () => void,
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* List of additional buttons to be added to the toolbar of {@link NavigationBoard}, together with optional spacers in-between.
|
|
57
57
|
*/
|
|
58
|
-
export type
|
|
58
|
+
export type NavigationBar = (NavigationButton | 'spacer')[];
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Scheme of additional button list to be added to the toolbar of {@link NavigationBoard}, together with optional spacers in-between.
|
|
63
|
+
*/
|
|
64
|
+
export type NavigationBarScheme = ('button' | 'spacer')[];
|
|
59
65
|
|
|
60
66
|
|
|
61
67
|
/**
|
|
@@ -70,3 +76,39 @@ export function isNavigationButton(button: unknown): button is NavigationButton
|
|
|
70
76
|
((button as NavigationButton).enabled === undefined || typeof (button as NavigationButton).enabled === 'boolean') &&
|
|
71
77
|
((button as NavigationButton).onClick === undefined || typeof (button as NavigationButton).onClick === 'function');
|
|
72
78
|
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Whether the given object is a {@link NavigationBar} or not.
|
|
83
|
+
*/
|
|
84
|
+
export function isNavigationBar(buttons: unknown): buttons is NavigationBar {
|
|
85
|
+
if (Array.isArray(buttons)) {
|
|
86
|
+
for (const button of buttons) {
|
|
87
|
+
if (!(isNavigationButton(button) || button === 'spacer')) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether the given object is a {@link NavigationBarScheme} or not.
|
|
101
|
+
*/
|
|
102
|
+
export function isNavigationBarScheme(buttons: unknown): buttons is NavigationBarScheme {
|
|
103
|
+
if (Array.isArray(buttons)) {
|
|
104
|
+
for (const button of buttons) {
|
|
105
|
+
if (!(button === 'button' || button === 'spacer')) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -30,11 +30,11 @@ import './NavigationField.css';
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
interface NavigationFieldProps {
|
|
33
|
-
onFirstPressed?: () => void
|
|
34
|
-
onPreviousPressed?: () => void
|
|
35
|
-
onNextPressed?: () => void
|
|
36
|
-
onLastPressed?: () => void
|
|
37
|
-
onExitPressed?: () => void
|
|
33
|
+
onFirstPressed?: () => void,
|
|
34
|
+
onPreviousPressed?: () => void,
|
|
35
|
+
onNextPressed?: () => void,
|
|
36
|
+
onLastPressed?: () => void,
|
|
37
|
+
onExitPressed?: () => void,
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
|
|
@@ -54,7 +54,7 @@ export class NavigationField extends React.Component<NavigationFieldProps> {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
private handleKeyDown(evt: React.KeyboardEvent<HTMLAnchorElement>) {
|
|
57
|
-
/* eslint-disable no-unused-expressions */
|
|
57
|
+
/* eslint-disable @typescript-eslint/no-unused-expressions */
|
|
58
58
|
doHandleKeyDown(evt, 'Home', this.props.onFirstPressed) ||
|
|
59
59
|
doHandleKeyDown(evt, 'ArrowLeft', this.props.onPreviousPressed) ||
|
|
60
60
|
doHandleKeyDown(evt, 'ArrowRight', this.props.onNextPressed) ||
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
|
|
25
25
|
import * as React from 'react';
|
|
26
26
|
|
|
27
|
-
import { NavigationButton,
|
|
27
|
+
import { NavigationButton, NavigationBar, NavigationBarScheme } from './NavigationButton';
|
|
28
28
|
|
|
29
29
|
import './NavigationToolbar.css';
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
interface NavigationToolbarProps {
|
|
33
|
-
squareSize: number
|
|
34
|
-
buttons:
|
|
33
|
+
squareSize: number,
|
|
34
|
+
buttons: NavigationBar,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
|
|
@@ -62,23 +62,25 @@ export function NavigationToolbar({ squareSize, buttons }: NavigationToolbarProp
|
|
|
62
62
|
atLeastOneButtonEncountered = true;
|
|
63
63
|
|
|
64
64
|
// Enqueue the button node.
|
|
65
|
-
buttonNodes.push(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
buttonNodes.push(
|
|
66
|
+
<NavigationButtonImpl
|
|
67
|
+
key={buttonNodes.length}
|
|
68
|
+
tooltip={button.tooltip} iconPath={button.iconPath} enabled={button.enabled} onClick={button.onClick}
|
|
69
|
+
size={buttonSize}
|
|
70
|
+
spaceOnLeft={i === 0 || buttons[i - 1] === 'spacer'}
|
|
71
|
+
spaceOnRight={i === buttons.length - 1 || buttons[i + 1] === 'spacer'}
|
|
72
|
+
/>,
|
|
73
|
+
);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
return <div className="kokopu-navigationToolbar" style={{ marginTop:
|
|
76
|
+
return <div className="kokopu-navigationToolbar" style={{ marginTop: computeMarginTop(squareSize) }}>{buttonNodes}</div>;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
|
|
78
80
|
interface NavigationButtonImplProps extends NavigationButton {
|
|
79
|
-
size: number
|
|
80
|
-
spaceOnLeft: boolean
|
|
81
|
-
spaceOnRight: boolean
|
|
81
|
+
size: number,
|
|
82
|
+
spaceOnLeft: boolean,
|
|
83
|
+
spaceOnRight: boolean,
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
|
|
@@ -90,7 +92,9 @@ function NavigationButtonImpl({ size, spaceOnLeft, spaceOnRight, iconPath, toolt
|
|
|
90
92
|
const rightBoundary = spaceOnRight ? 'A 16 16 0 0 0 16 0' : 'L 31 32 L 31 0 L 16 0';
|
|
91
93
|
const actuallyEnabled = enabled ?? true;
|
|
92
94
|
return (
|
|
93
|
-
<div
|
|
95
|
+
<div
|
|
96
|
+
className={actuallyEnabled ? 'kokopu-enabledNavigationButton' : 'kokopu-disabledNavigationButton'}
|
|
97
|
+
title={tooltip}
|
|
94
98
|
onClick={actuallyEnabled ? onClick : undefined}
|
|
95
99
|
>
|
|
96
100
|
<svg viewBox="0 0 32 32" width={size} height={size}>
|
|
@@ -101,6 +105,41 @@ function NavigationButtonImpl({ size, spaceOnLeft, spaceOnRight, iconPath, toolt
|
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Size of the navigation toolbar (taking into account the margin between the toolbar and the chessboard), assuming the given square size.
|
|
110
|
+
*/
|
|
111
|
+
export function navigationToolbarSize(squareSize: number, buttons: NavigationBarScheme): { width: number, height: number } {
|
|
112
|
+
|
|
113
|
+
const buttonSize = computeButtonSize(squareSize);
|
|
114
|
+
const spacerSize = computeSpacerSize(squareSize);
|
|
115
|
+
let width = 0;
|
|
116
|
+
|
|
117
|
+
let atLeastOneButtonEncountered = false;
|
|
118
|
+
for (let i = 0; i < buttons.length; ++i) {
|
|
119
|
+
|
|
120
|
+
// Skip the spacers.
|
|
121
|
+
if (buttons[i] === 'spacer') {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Enqueue a spacer if necessary.
|
|
126
|
+
// Remark: consecutive spacers are collapsed into a single one for rendering, and spacers at the begin and end of the button list are not rendered.
|
|
127
|
+
if (atLeastOneButtonEncountered && buttons[i - 1] === 'spacer') {
|
|
128
|
+
width += spacerSize;
|
|
129
|
+
}
|
|
130
|
+
atLeastOneButtonEncountered = true;
|
|
131
|
+
|
|
132
|
+
// Enqueue the button node.
|
|
133
|
+
width += buttonSize;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
width: width,
|
|
138
|
+
height: buttonSize + computeMarginTop(squareSize),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
104
143
|
/**
|
|
105
144
|
* Return the height/width of the buttons assuming the given square size.
|
|
106
145
|
*/
|
|
@@ -115,3 +154,11 @@ function computeButtonSize(squareSize: number) {
|
|
|
115
154
|
function computeSpacerSize(squareSize: number) {
|
|
116
155
|
return Math.round((squareSize * 2 + 116) / 14);
|
|
117
156
|
}
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Return the height of the margin between the toolbar and the chessboard.
|
|
161
|
+
*/
|
|
162
|
+
function computeMarginTop(squareSize: number) {
|
|
163
|
+
return Math.round((squareSize * 2 + 116) / 28);
|
|
164
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -62,22 +62,22 @@ export function isChessPieceIconType(iconType: unknown): iconType is ChessPieceI
|
|
|
62
62
|
export type Colorset = {
|
|
63
63
|
|
|
64
64
|
/** Color of the black squares. */
|
|
65
|
-
b: string
|
|
65
|
+
b: string,
|
|
66
66
|
|
|
67
67
|
/** Color of the white squares. */
|
|
68
|
-
w: string
|
|
68
|
+
w: string,
|
|
69
69
|
|
|
70
70
|
/** Color of the blue markers. */
|
|
71
|
-
cb: string
|
|
71
|
+
cb: string,
|
|
72
72
|
|
|
73
73
|
/** Color of the green markers. */
|
|
74
|
-
cg: string
|
|
74
|
+
cg: string,
|
|
75
75
|
|
|
76
76
|
/** Color of the red markers. */
|
|
77
|
-
cr: string
|
|
77
|
+
cr: string,
|
|
78
78
|
|
|
79
79
|
/** Color of the yellow markers. */
|
|
80
|
-
cy: string
|
|
80
|
+
cy: string,
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
|
|
@@ -89,46 +89,46 @@ export type Colorset = {
|
|
|
89
89
|
export type Pieceset = {
|
|
90
90
|
|
|
91
91
|
/** Image for the black bishops. */
|
|
92
|
-
bb: string
|
|
92
|
+
bb: string,
|
|
93
93
|
|
|
94
94
|
/** Image for the black kings. */
|
|
95
|
-
bk: string
|
|
95
|
+
bk: string,
|
|
96
96
|
|
|
97
97
|
/** Image for the black knights. */
|
|
98
|
-
bn: string
|
|
98
|
+
bn: string,
|
|
99
99
|
|
|
100
100
|
/** Image for the black pawns. */
|
|
101
|
-
bp: string
|
|
101
|
+
bp: string,
|
|
102
102
|
|
|
103
103
|
/** Image for the black queens. */
|
|
104
|
-
bq: string
|
|
104
|
+
bq: string,
|
|
105
105
|
|
|
106
106
|
/** Image for the black rooks. */
|
|
107
|
-
br: string
|
|
107
|
+
br: string,
|
|
108
108
|
|
|
109
109
|
/** Image for the black turn flags. */
|
|
110
|
-
bx: string
|
|
110
|
+
bx: string,
|
|
111
111
|
|
|
112
112
|
/** Image for the white bishops. */
|
|
113
|
-
wb: string
|
|
113
|
+
wb: string,
|
|
114
114
|
|
|
115
115
|
/** Image for the white kings. */
|
|
116
|
-
wk: string
|
|
116
|
+
wk: string,
|
|
117
117
|
|
|
118
118
|
/** Image for the white knights. */
|
|
119
|
-
wn: string
|
|
119
|
+
wn: string,
|
|
120
120
|
|
|
121
121
|
/** Image for the white pawns. */
|
|
122
|
-
wp: string
|
|
122
|
+
wp: string,
|
|
123
123
|
|
|
124
124
|
/** Image for the white queens. */
|
|
125
|
-
wq: string
|
|
125
|
+
wq: string,
|
|
126
126
|
|
|
127
127
|
/** Image for the white rooks. */
|
|
128
|
-
wr: string
|
|
128
|
+
wr: string,
|
|
129
129
|
|
|
130
130
|
/** Image for the white turn flags. */
|
|
131
|
-
wx: string
|
|
131
|
+
wx: string,
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
|
|
@@ -136,12 +136,12 @@ export type Pieceset = {
|
|
|
136
136
|
* Set of aliases for chess pieces symbols.
|
|
137
137
|
*/
|
|
138
138
|
export type PieceSymbolMapping = {
|
|
139
|
-
K: string
|
|
140
|
-
Q: string
|
|
141
|
-
R: string
|
|
142
|
-
B: string
|
|
143
|
-
N: string
|
|
144
|
-
P: string
|
|
139
|
+
K: string,
|
|
140
|
+
Q: string,
|
|
141
|
+
R: string,
|
|
142
|
+
B: string,
|
|
143
|
+
N: string,
|
|
144
|
+
P: string,
|
|
145
145
|
};
|
|
146
146
|
|
|
147
147
|
|