kokopu-react 3.0.2 → 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 (120) hide show
  1. package/CHANGELOG.md +7 -1
  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.d.ts +14 -58
  6. package/dist/lib/chessboard/Chessboard.js +26 -92
  7. package/dist/lib/chessboard/Chessboard.js.map +1 -1
  8. package/dist/lib/errorbox/parsing.d.ts +57 -0
  9. package/dist/lib/errorbox/parsing.js +140 -0
  10. package/dist/lib/errorbox/parsing.js.map +1 -0
  11. package/dist/lib/i18n.d.ts +5 -0
  12. package/dist/lib/i18n.js +6 -0
  13. package/dist/lib/i18n.js.map +1 -1
  14. package/dist/lib/index.d.ts +4 -1
  15. package/dist/lib/index.js +2 -0
  16. package/dist/lib/index.js.map +1 -1
  17. package/dist/lib/movetext/Movetext.css +0 -13
  18. package/dist/lib/movetext/Movetext.d.ts +9 -43
  19. package/dist/lib/movetext/Movetext.js +15 -67
  20. package/dist/lib/movetext/Movetext.js.map +1 -1
  21. package/dist/lib/movetext/MovetextImpl.d.ts +7 -28
  22. package/dist/lib/movetext/MovetextImpl.js +15 -94
  23. package/dist/lib/movetext/MovetextImpl.js.map +1 -1
  24. package/dist/lib/navigationboard/NavigationBoard.d.ts +118 -0
  25. package/dist/lib/navigationboard/NavigationBoard.js +112 -0
  26. package/dist/lib/navigationboard/NavigationBoard.js.map +1 -0
  27. package/dist/lib/navigationboard/NavigationField.css +36 -0
  28. package/dist/lib/navigationboard/NavigationField.d.ts +81 -0
  29. package/dist/lib/navigationboard/NavigationField.js +154 -0
  30. package/dist/lib/navigationboard/NavigationField.js.map +1 -0
  31. package/dist/lib/navigationboard/NavigationToolbar.css +51 -0
  32. package/dist/lib/navigationboard/NavigationToolbar.d.ts +41 -0
  33. package/dist/lib/navigationboard/NavigationToolbar.js +124 -0
  34. package/dist/lib/navigationboard/NavigationToolbar.js.map +1 -0
  35. package/doc_src/demo/PageChessboardMove.tsx +17 -0
  36. package/doc_src/demo/PageNavigationBoardBase.tsx +194 -0
  37. package/doc_src/demo/PageNavigationBoardUncontrolledVsControlled.tsx +114 -0
  38. package/doc_src/demo/game-3.pgn +10 -0
  39. package/doc_src/examples/Movetext.md +1 -1
  40. package/doc_src/examples/NavigationBoard.md +15 -0
  41. package/package.json +16 -16
  42. package/scripts/doc.styleguide.config.js +12 -2
  43. package/scripts/docker-compose.yml +1 -1
  44. package/src/chessboard/BoardProperties.ts +131 -0
  45. package/src/chessboard/Chessboard.tsx +41 -170
  46. package/src/errorbox/parsing.tsx +158 -0
  47. package/src/i18n.ts +7 -0
  48. package/src/index.ts +5 -1
  49. package/src/movetext/Movetext.css +0 -13
  50. package/src/movetext/Movetext.tsx +20 -85
  51. package/src/movetext/MovetextImpl.tsx +28 -115
  52. package/src/navigationboard/NavigationBoard.tsx +231 -0
  53. package/src/navigationboard/NavigationField.css +36 -0
  54. package/src/navigationboard/NavigationField.tsx +185 -0
  55. package/src/navigationboard/NavigationToolbar.css +51 -0
  56. package/src/navigationboard/NavigationToolbar.tsx +174 -0
  57. package/test/05_chessboard_graphic.js +2 -0
  58. package/test/09_chessboard_small_screens.js +21 -0
  59. package/test/10_movetext_graphic.js +5 -0
  60. package/test/11_movetext_interaction.js +12 -8
  61. package/test/12_navigation_board.js +168 -0
  62. package/test/graphic_references/05_chessboard_graphic/move/illegal_null-move.png +0 -0
  63. package/test/graphic_references/05_chessboard_graphic/move/null-move.png +0 -0
  64. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_bottom_component.png +0 -0
  65. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/default_top_component.png +0 -0
  66. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_bottom_component.png +0 -0
  67. package/test/graphic_references/09_chessboard_small_screens/top_bottom_components/reduced_top_component.png +0 -0
  68. package/test/graphic_references/10_movetext_graphic/format_move/format_text.png +0 -0
  69. package/test/graphic_references/10_movetext_graphic/options/wrong_piece_symbol_value.png +0 -0
  70. package/test/graphic_references/11_movetext_interaction/select_moves/click_on_unselected_without_callback.png +0 -0
  71. package/test/graphic_references/12_navigation_board/controlled/default.png +0 -0
  72. package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_0.png +0 -0
  73. package/test/graphic_references/12_navigation_board/controlled/forbidden_navigation_1.png +0 -0
  74. package/test/graphic_references/12_navigation_board/controlled/invalid_node_id.png +0 -0
  75. package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_0.png +0 -0
  76. package/test/graphic_references/12_navigation_board/controlled/no_callback_defined_1.png +0 -0
  77. package/test/graphic_references/12_navigation_board/controlled/overriding_initial_node_id.png +0 -0
  78. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_0.png +0 -0
  79. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_1.png +0 -0
  80. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_2.png +0 -0
  81. package/test/graphic_references/12_navigation_board/controlled/regular_navigation_3.png +0 -0
  82. package/test/graphic_references/12_navigation_board/error/pgn_parsing_error.png +0 -0
  83. package/test/graphic_references/12_navigation_board/error/wrong_game_type.png +0 -0
  84. package/test/graphic_references/12_navigation_board/theme/custom_1.png +0 -0
  85. package/test/graphic_references/12_navigation_board/theme/custom_2.png +0 -0
  86. package/test/graphic_references/12_navigation_board/theme/large.png +0 -0
  87. package/test/graphic_references/12_navigation_board/theme/small.png +0 -0
  88. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_0.png +0 -0
  89. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_1.png +0 -0
  90. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_beginning_2.png +0 -0
  91. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_0.png +0 -0
  92. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_1.png +0 -0
  93. package/test/graphic_references/12_navigation_board/uncontrolled/forbidden_navigation_at_end_2.png +0 -0
  94. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_end.png +0 -0
  95. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_at_specific_id.png +0 -0
  96. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default.png +0 -0
  97. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_default_with_game_index.png +0 -0
  98. package/test/graphic_references/12_navigation_board/uncontrolled/initial_state_on_null-move.png +0 -0
  99. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_0.png +0 -0
  100. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_1.png +0 -0
  101. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_2.png +0 -0
  102. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_3.png +0 -0
  103. package/test/graphic_references/12_navigation_board/uncontrolled/navigation_with_keys_4.png +0 -0
  104. package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_0.png +0 -0
  105. package/test/graphic_references/12_navigation_board/uncontrolled/regular_flipping_1.png +0 -0
  106. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_0.png +0 -0
  107. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_1.png +0 -0
  108. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_2.png +0 -0
  109. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_3.png +0 -0
  110. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_4.png +0 -0
  111. package/test/graphic_references/12_navigation_board/uncontrolled/regular_navigation_5.png +0 -0
  112. package/test/graphic_test_app/05_chessboard_graphic/move.tsx +2 -0
  113. package/test/graphic_test_app/09_chessboard_small_screens/top_bottom_components.tsx +48 -0
  114. package/test/graphic_test_app/10_movetext_graphic/format_move.tsx +31 -0
  115. package/test/graphic_test_app/10_movetext_graphic/options.tsx +1 -0
  116. package/test/graphic_test_app/11_movetext_interaction/select_moves.tsx +1 -0
  117. package/test/graphic_test_app/12_navigation_board/controlled.tsx +43 -0
  118. package/test/graphic_test_app/12_navigation_board/error.tsx +34 -0
  119. package/test/graphic_test_app/12_navigation_board/theme.tsx +38 -0
  120. package/test/graphic_test_app/12_navigation_board/uncontrolled.tsx +56 -0
@@ -0,0 +1,154 @@
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
3
+ * *
4
+ * Kokopu-React - A React-based library of chess-related components. *
5
+ * <https://www.npmjs.com/package/kokopu-react> *
6
+ * Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
7
+ * *
8
+ * Kokopu-React is free software: you can redistribute it and/or *
9
+ * modify it under the terms of the GNU Lesser General Public License *
10
+ * as published by the Free Software Foundation, either version 3 of *
11
+ * the License, or (at your option) any later version. *
12
+ * *
13
+ * Kokopu-React is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU Lesser General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU Lesser General *
19
+ * Public License along with this program. If not, see *
20
+ * <http://www.gnu.org/licenses/>. *
21
+ * *
22
+ * -------------------------------------------------------------------------- */
23
+ import * as React from 'react';
24
+ import { Variation } from 'kokopu';
25
+ import './NavigationField.css';
26
+ /**
27
+ * Invisible field, to capture keyboard events.
28
+ */
29
+ export class NavigationField extends React.Component {
30
+ constructor() {
31
+ super(...arguments);
32
+ this.focusFieldRef = React.createRef();
33
+ }
34
+ render() {
35
+ return (React.createElement("div", { className: "kokopu-focusFieldContainer" },
36
+ React.createElement("a", { className: "kokopu-focusField", href: "#", ref: this.focusFieldRef, onKeyDown: evt => this.handleKeyDown(evt) })));
37
+ }
38
+ handleKeyDown(evt) {
39
+ /* eslint-disable no-unused-expressions */
40
+ doHandleKeyDown(evt, 'Home', this.props.onFirstPressed) ||
41
+ doHandleKeyDown(evt, 'ArrowLeft', this.props.onPreviousPressed) ||
42
+ doHandleKeyDown(evt, 'ArrowRight', this.props.onNextPressed) ||
43
+ doHandleKeyDown(evt, 'End', this.props.onLastPressed) ||
44
+ doHandleKeyDown(evt, 'Escape', this.props.onExitPressed);
45
+ /* eslint-enable */
46
+ }
47
+ /**
48
+ * Set the focus to the component.
49
+ */
50
+ focus() {
51
+ const target = this.focusFieldRef.current;
52
+ // istanbul ignore else
53
+ if (target) {
54
+ target.focus();
55
+ }
56
+ }
57
+ }
58
+ function doHandleKeyDown(evt, targetKey, targetCallback) {
59
+ // Skip if the pressed key does not match the target key.
60
+ if (evt.key !== targetKey) {
61
+ return false;
62
+ }
63
+ // Otherwise, invoke the callback.
64
+ if (targetCallback) {
65
+ evt.preventDefault();
66
+ targetCallback();
67
+ }
68
+ return true;
69
+ }
70
+ /**
71
+ * Return the ID of the main variation in the given chess game.
72
+ * If the given selection corresponds already at the main variation, `undefined` is returned.
73
+ *
74
+ * @param game - Considered chess game.
75
+ * @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
76
+ * @public
77
+ */
78
+ export function firstNodeId(game, selection) {
79
+ if (!game.findById(selection)) {
80
+ return undefined;
81
+ }
82
+ return selection === 'start' ? undefined : 'start';
83
+ }
84
+ /**
85
+ * Return the ID of the node immediately preceding the given selection in the given chess game.
86
+ * If no such node exists, `undefined` is returned.
87
+ *
88
+ * @param game - Considered chess game.
89
+ * @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
90
+ * @public
91
+ */
92
+ export function previousNodeId(game, selection) {
93
+ let currentNode = game.findById(selection);
94
+ if (!currentNode) {
95
+ return undefined;
96
+ }
97
+ if (currentNode instanceof Variation) {
98
+ currentNode = currentNode.parentNode();
99
+ if (!currentNode) {
100
+ return undefined; // This case corresponds to the first variation being selected initially.
101
+ }
102
+ }
103
+ while (currentNode) {
104
+ const previousNode = currentNode.previous();
105
+ if (previousNode) {
106
+ return previousNode.id();
107
+ }
108
+ currentNode = currentNode.parentVariation().parentNode();
109
+ }
110
+ return 'start';
111
+ }
112
+ /**
113
+ * Return the ID of the node immediately following the given selection in the given chess game.
114
+ * If no such node exists, `undefined` is returned.
115
+ *
116
+ * @param game - Considered chess game.
117
+ * @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
118
+ * @public
119
+ */
120
+ export function nextNodeId(game, selection) {
121
+ const currentNode = game.findById(selection);
122
+ if (!currentNode) {
123
+ return undefined;
124
+ }
125
+ const nextNode = currentNode instanceof Variation ? currentNode.first() : currentNode.next();
126
+ return nextNode ? nextNode.id() : undefined;
127
+ }
128
+ /**
129
+ * Return the ID of the node at then end of the variation in which lies the given selection in the given chess game.
130
+ * If the selection is already at the end its variation, `undefined` is returned.
131
+ *
132
+ * @param game - Considered chess game.
133
+ * @param selection - ID of the selected move (or `'start'` for the beginning of the main variation).
134
+ * @public
135
+ */
136
+ export function lastNodeId(game, selection) {
137
+ let currentNode = game.findById(selection);
138
+ if (!currentNode) {
139
+ return undefined;
140
+ }
141
+ currentNode = currentNode instanceof Variation ? currentNode.first() : currentNode.next();
142
+ if (!currentNode) { // Ensure that the input node is not already the last one.
143
+ return undefined;
144
+ }
145
+ let currentNodeNotNull = currentNode;
146
+ while (true) {
147
+ const nextNode = currentNodeNotNull.next();
148
+ if (!nextNode) {
149
+ return currentNodeNotNull.id();
150
+ }
151
+ currentNodeNotNull = nextNode;
152
+ }
153
+ }
154
+ //# sourceMappingURL=NavigationField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavigationField.js","sourceRoot":"","sources":["../../../src/navigationboard/NavigationField.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;gFAqBgF;AAGhF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAC;AAEzC,OAAO,uBAAuB,CAAC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C7C,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,QAAQ,GAAG,WAAW,YAAY,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAC7F,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC7C,CAAC;AAGD;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,SAAiB;IACvD,IAAI,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,IAAI,CAAC,WAAW,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,WAAW,GAAG,WAAW,YAAY,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAC1F,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,0DAA0D;QAC7E,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,kBAAkB,GAAG,WAAW,CAAC;IACrC,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,OAAO,kBAAkB,CAAC,EAAE,EAAE,CAAC;QAChC,CAAC;QACD,kBAAkB,GAAG,QAAQ,CAAC;IAC/B,CAAC;AACF,CAAC"}
@@ -0,0 +1,51 @@
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
3
+ * *
4
+ * Kokopu-React - A React-based library of chess-related components. *
5
+ * <https://www.npmjs.com/package/kokopu-react> *
6
+ * Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
7
+ * *
8
+ * Kokopu-React is free software: you can redistribute it and/or *
9
+ * modify it under the terms of the GNU Lesser General Public License *
10
+ * as published by the Free Software Foundation, either version 3 of *
11
+ * the License, or (at your option) any later version. *
12
+ * *
13
+ * Kokopu-React is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU Lesser General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU Lesser General *
19
+ * Public License along with this program. If not, see *
20
+ * <http://www.gnu.org/licenses/>. *
21
+ * *
22
+ * -------------------------------------------------------------------------- */
23
+
24
+
25
+ .kokopu-navigationBoard {
26
+ display: flex;
27
+ flex-direction: column;
28
+ align-items: center;
29
+ }
30
+
31
+ .kokopu-navigationToolbar {
32
+ line-height: 0px;
33
+ }
34
+
35
+ .kokopu-navigationButton {
36
+ display: inline-block;
37
+ cursor: pointer;
38
+ }
39
+
40
+ .kokopu-navigationButton:hover {
41
+ opacity: 0.6;
42
+ }
43
+
44
+ * + .kokopu-navigationButton {
45
+ margin-left: 2px;
46
+ }
47
+
48
+ .kokopu-navigationSpacer {
49
+ display: inline-block;
50
+ width: 10px;
51
+ }
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
3
+ * *
4
+ * Kokopu-React - A React-based library of chess-related components. *
5
+ * <https://www.npmjs.com/package/kokopu-react> *
6
+ * Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
7
+ * *
8
+ * Kokopu-React is free software: you can redistribute it and/or *
9
+ * modify it under the terms of the GNU Lesser General Public License *
10
+ * as published by the Free Software Foundation, either version 3 of *
11
+ * the License, or (at your option) any later version. *
12
+ * *
13
+ * Kokopu-React is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU Lesser General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU Lesser General *
19
+ * Public License along with this program. If not, see *
20
+ * <http://www.gnu.org/licenses/>. *
21
+ * *
22
+ * -------------------------------------------------------------------------- */
23
+ import * as React from 'react';
24
+ import './NavigationToolbar.css';
25
+ interface NavigationToolbarProps {
26
+ flipButtonVisible: boolean;
27
+ squareSize: number;
28
+ onFirstClicked?: () => void;
29
+ onPreviousClicked?: () => void;
30
+ onNextClicked?: () => void;
31
+ onLastClicked?: () => void;
32
+ onFlipClicked?: () => void;
33
+ }
34
+ /**
35
+ * Toolbar below the navigation board.
36
+ */
37
+ export declare class NavigationToolbar extends React.Component<NavigationToolbarProps> {
38
+ render(): React.JSX.Element;
39
+ private renderFlipButton;
40
+ }
41
+ export {};
@@ -0,0 +1,124 @@
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
3
+ * *
4
+ * Kokopu-React - A React-based library of chess-related components. *
5
+ * <https://www.npmjs.com/package/kokopu-react> *
6
+ * Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
7
+ * *
8
+ * Kokopu-React is free software: you can redistribute it and/or *
9
+ * modify it under the terms of the GNU Lesser General Public License *
10
+ * as published by the Free Software Foundation, either version 3 of *
11
+ * the License, or (at your option) any later version. *
12
+ * *
13
+ * Kokopu-React is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU Lesser General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU Lesser General *
19
+ * Public License along with this program. If not, see *
20
+ * <http://www.gnu.org/licenses/>. *
21
+ * *
22
+ * -------------------------------------------------------------------------- */
23
+ import * as React from 'react';
24
+ import { i18n } from '../i18n';
25
+ import './NavigationToolbar.css';
26
+ const THICKNESS = 2;
27
+ const CHEVRON_SIZE = 7;
28
+ const ARROW_SIZE = 5;
29
+ const ARROW_LENGTH = 16;
30
+ /**
31
+ * Toolbar below the navigation board.
32
+ */
33
+ export class NavigationToolbar extends React.Component {
34
+ render() {
35
+ const buttonSize = computeButtonSize(this.props.squareSize);
36
+ const marginTop = Math.round(buttonSize / 4);
37
+ return (React.createElement("div", { className: "kokopu-navigationToolbar", style: { marginTop: marginTop } },
38
+ React.createElement(NavigationButton, { size: buttonSize, tooltip: i18n.TOOLTIP_GO_FIRST, path: chevronPath(14, 16, -1) + ' ' + chevronPath(10, 16, -1), onClick: this.props.onFirstClicked }),
39
+ React.createElement(NavigationButton, { size: buttonSize, tooltip: i18n.TOOLTIP_GO_PREVIOUS, path: chevronPath(12, 16, -1), onClick: this.props.onPreviousClicked }),
40
+ React.createElement(NavigationButton, { size: buttonSize, tooltip: i18n.TOOLTIP_GO_NEXT, path: chevronPath(20, 16, 1), onClick: this.props.onNextClicked }),
41
+ React.createElement(NavigationButton, { size: buttonSize, tooltip: i18n.TOOLTIP_GO_LAST, path: chevronPath(18, 16, 1) + ' ' + chevronPath(22, 16, 1), onClick: this.props.onLastClicked }),
42
+ this.renderFlipButton(buttonSize)));
43
+ }
44
+ renderFlipButton(buttonSize) {
45
+ if (!this.props.flipButtonVisible) {
46
+ return undefined;
47
+ }
48
+ return (React.createElement(React.Fragment, null,
49
+ React.createElement("div", { className: "kokopu-navigationSpacer" }),
50
+ React.createElement(NavigationButton, { size: buttonSize, tooltip: i18n.TOOLTIP_FLIP, path: arrowPath(11, 25, 1) + ' ' + arrowPath(21, 7, -1), onClick: this.props.onFlipClicked })));
51
+ }
52
+ }
53
+ /**
54
+ * Button for the navigation toolbar.
55
+ */
56
+ function NavigationButton({ size, tooltip, path, onClick }) {
57
+ return (React.createElement("div", { className: "kokopu-navigationButton", title: tooltip, onClick: onClick },
58
+ React.createElement("svg", { viewBox: "0 0 32 32", width: size, height: size },
59
+ React.createElement("path", { d: `M 16 0 A 16 16 0 0 0 16 32 A 16 16 0 0 0 16 0 Z ${path}`, fill: "currentcolor" }))));
60
+ }
61
+ /**
62
+ * * C
63
+ * / \
64
+ * B * \
65
+ * \ \
66
+ * \ \
67
+ * A * * D
68
+ * / /
69
+ * / /
70
+ * F * /
71
+ * \ /
72
+ * * E
73
+ *
74
+ * (x,y) = middle of [AD]
75
+ */
76
+ function chevronPath(x, y, direction) {
77
+ const xA = x - direction * THICKNESS * Math.sqrt(2) / 2;
78
+ const xB = x - direction * (CHEVRON_SIZE + THICKNESS / Math.sqrt(2) / 2);
79
+ const xC = x - direction * (CHEVRON_SIZE - THICKNESS / Math.sqrt(2) / 2);
80
+ const xD = x + direction * THICKNESS * Math.sqrt(2) / 2;
81
+ const yB = y - direction * (CHEVRON_SIZE - THICKNESS / Math.sqrt(2) / 2);
82
+ const yC = y - direction * (CHEVRON_SIZE + THICKNESS / Math.sqrt(2) / 2);
83
+ const yE = y + direction * (CHEVRON_SIZE + THICKNESS / Math.sqrt(2) / 2);
84
+ const yF = y + direction * (CHEVRON_SIZE - THICKNESS / Math.sqrt(2) / 2);
85
+ return `M ${xA} ${y} L ${xB} ${yB} L ${xC} ${yC} L ${xD} ${y} L ${xC} ${yE} L ${xB} ${yF} Z`;
86
+ }
87
+ /**
88
+ * D +---+ E
89
+ * | |
90
+ * | |
91
+ * | |
92
+ * B * | | * G
93
+ * / \ | | / \
94
+ * A * \| |/ * H
95
+ * \ * * /
96
+ * \ C F /
97
+ * \ O /
98
+ * \ * /
99
+ * \ /
100
+ * \ /
101
+ * *
102
+ * (x,y)
103
+ */
104
+ function arrowPath(x, y, direction) {
105
+ const xA = x - direction * (ARROW_SIZE + THICKNESS / Math.sqrt(2) / 2);
106
+ const xB = x - direction * (ARROW_SIZE - THICKNESS / Math.sqrt(2) / 2);
107
+ const xC = x - direction * THICKNESS / 2;
108
+ const xF = x + direction * THICKNESS / 2;
109
+ const xG = x + direction * (ARROW_SIZE - THICKNESS / Math.sqrt(2) / 2);
110
+ const xH = x + direction * (ARROW_SIZE + THICKNESS / Math.sqrt(2) / 2);
111
+ const y0 = y - direction * THICKNESS * Math.sqrt(2) / 2;
112
+ const yA = y0 - direction * (ARROW_SIZE - THICKNESS / Math.sqrt(2) / 2);
113
+ const yB = y0 - direction * (ARROW_SIZE + THICKNESS / Math.sqrt(2) / 2);
114
+ const yC = yB + (xC - xB);
115
+ const yD = y - direction * ARROW_LENGTH;
116
+ return `M ${x} ${y} L ${xA} ${yA} L ${xB} ${yB} L ${xC} ${yC} V ${yD} H ${xF} V ${yC} L ${xG} ${yB} L ${xH} ${yA} Z`;
117
+ }
118
+ /**
119
+ * Return the height/width of the buttons assuming the given square size.
120
+ */
121
+ function computeButtonSize(squareSize) {
122
+ return Math.round((squareSize * 2 + 116) / 7);
123
+ }
124
+ //# sourceMappingURL=NavigationToolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavigationToolbar.js","sourceRoot":"","sources":["../../../src/navigationboard/NavigationToolbar.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;gFAqBgF;AAIhF,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,yBAAyB,CAAC;AAEjC,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,MAAM,YAAY,GAAG,CAAC,CAAC;AACvB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,YAAY,GAAG,EAAE,CAAC;AAcxB;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK,CAAC,SAAiC;IAE7E,MAAM;QACL,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAC7C,OAAO,CACN,6BAAK,SAAS,EAAC,0BAA0B,EAAC,KAAK,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE;YACxE,oBAAC,gBAAgB,IAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,gB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(move === '--') {
184
+ const positionAfter = new Position(currentPosition);
185
+ if (positionAfter.playNullMove()) {
186
+ this.setState({
187
+ position: currentPosition,
188
+ playedMove: '--',
189
+ positionAfter: positionAfter,
190
+ });
191
+ }
192
+ else {
193
+ this.setState({
194
+ position: currentPosition,
195
+ playedMove: '',
196
+ positionAfter: null,
197
+ });
198
+ }
199
+ }
183
200
  else {
184
201
  try {
185
202
  const moveDescriptor = currentPosition.notation(move);
@@ -0,0 +1,194 @@
1
+ /*!
2
+ * -------------------------------------------------------------------------- *
3
+ * *
4
+ * Kokopu-React - A React-based library of chess-related components. *
5
+ * <https://www.npmjs.com/package/kokopu-react> *
6
+ * Copyright (C) 2021-2024 Yoann Le Montagner <yo35 -at- melix.net> *
7
+ * *
8
+ * Kokopu-React is free software: you can redistribute it and/or *
9
+ * modify it under the terms of the GNU Lesser General Public License *
10
+ * as published by the Free Software Foundation, either version 3 of *
11
+ * the License, or (at your option) any later version. *
12
+ * *
13
+ * Kokopu-React is distributed in the hope that it will be useful, *
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
+ * GNU Lesser General Public License for more details. *
17
+ * *
18
+ * You should have received a copy of the GNU Lesser General *
19
+ * Public License along with this program. If not, see *
20
+ * <http://www.gnu.org/licenses/>. *
21
+ * *
22
+ * -------------------------------------------------------------------------- */
23
+
24
+
25
+ import * as React from 'react';
26
+
27
+ import { AnnotationColor, ArrowMarkerIcon, Chessboard, NavigationBoard } from '../../src/index';
28
+ import { buildComponentDemoCode } from './util';
29
+
30
+ import Box from '@mui/material/Box';
31
+ import FormControl from '@mui/material/FormControl';
32
+ import FormControlLabel from '@mui/material/FormControlLabel';
33
+ import InputLabel from '@mui/material/InputLabel';
34
+ import MenuItem from '@mui/material/MenuItem';
35
+ import Select from '@mui/material/Select';
36
+ import Slider from '@mui/material/Slider';
37
+ import Stack from '@mui/material/Stack';
38
+ import Switch from '@mui/material/Switch';
39
+ import ToggleButton from '@mui/material/ToggleButton';
40
+ import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
41
+ import Typography from '@mui/material/Typography';
42
+
43
+ import './demo.css';
44
+ import pgn from './game-3.pgn';
45
+
46
+
47
+ const COLOR_ICON_SIZE = 16;
48
+
49
+
50
+ interface PageState {
51
+ squareSize: number;
52
+ coordinateVisible: boolean;
53
+ turnVisible: boolean;
54
+ colorset: string;
55
+ pieceset: string;
56
+ moveArrowVisible: boolean;
57
+ moveArrowColor: AnnotationColor;
58
+ animated: boolean;
59
+ flipButtonVisible: boolean;
60
+ }
61
+
62
+
63
+ export default class Page extends React.Component<object, PageState> {
64
+
65
+ constructor(props: object) {
66
+ super(props);
67
+ this.state = {
68
+ squareSize: 40,
69
+ coordinateVisible: true,
70
+ turnVisible: true,
71
+ colorset: 'original',
72
+ pieceset: 'cburnett',
73
+ moveArrowVisible: true,
74
+ moveArrowColor: 'b',
75
+ animated: true,
76
+ flipButtonVisible: true,
77
+ };
78
+ }
79
+
80
+ render() {
81
+ return (
82
+ <Stack spacing={2} mt={2}>
83
+ {this.renderControls()}
84
+ {this.renderNavigationBoard()}
85
+ {this.renderCode()}
86
+ </Stack>
87
+ );
88
+ }
89
+
90
+ private renderControls() {
91
+ return (<>
92
+ <Stack direction="row" spacing={2} alignItems="center">
93
+ <FormControlLabel label="Show flip button"
94
+ control={<Switch checked={this.state.flipButtonVisible} onChange={() => this.setState({ flipButtonVisible: !this.state.flipButtonVisible })} color="primary" />}
95
+ />
96
+ <FormControlLabel label="Show coordinates"
97
+ control={<Switch checked={this.state.coordinateVisible} onChange={() => this.setState({ coordinateVisible: !this.state.coordinateVisible })} color="primary" />}
98
+ />
99
+ <FormControlLabel label="Show turn"
100
+ control={<Switch checked={this.state.turnVisible} onChange={() => this.setState({ turnVisible: !this.state.turnVisible })} color="primary" />}
101
+ />
102
+ <FormControlLabel label="Animated"
103
+ control={<Switch checked={this.state.animated} onChange={() => this.setState({ animated: !this.state.animated })} color="primary" />}
104
+ />
105
+ </Stack>
106
+ <Box>
107
+ <Typography gutterBottom>Square size</Typography>
108
+ <Slider
109
+ value={this.state.squareSize} onChange={(_, newValue) => this.setState({ squareSize: newValue as number })}
110
+ min={Chessboard.minSquareSize()} max={Chessboard.maxSquareSize()} step={1} valueLabelDisplay="on" color="primary"
111
+ />
112
+ </Box>
113
+ <Stack direction="row" spacing={2} alignItems="center">
114
+ <FormControl variant="standard">
115
+ <InputLabel id="colorset-label">Colorset</InputLabel>
116
+ <Select labelId="colorset-label" sx={{ width: '8em' }} value={this.state.colorset} onChange={evt => this.setState({ colorset: evt.target.value })}>
117
+ {Object.keys(Chessboard.colorsets()).sort().map(colorset => <MenuItem key={colorset} value={colorset}>{colorset}</MenuItem>)}
118
+ </Select>
119
+ </FormControl>
120
+ <FormControl variant="standard">
121
+ <InputLabel id="pieceset-label">Pieceset</InputLabel>
122
+ <Select labelId="pieceset-label" sx={{ width: '8em' }} value={this.state.pieceset} onChange={evt => this.setState({ pieceset: evt.target.value })}>
123
+ {Object.keys(Chessboard.piecesets()).sort().map(pieceset => <MenuItem key={pieceset} value={pieceset}>{pieceset}</MenuItem>)}
124
+ </Select>
125
+ </FormControl>
126
+ <FormControlLabel label="Show move arrow"
127
+ control={<Switch checked={this.state.moveArrowVisible} onChange={() => this.setState({ moveArrowVisible: !this.state.moveArrowVisible })} color="primary" />}
128
+ />
129
+ {this.renderMoveArrowColorSelector()}
130
+ </Stack>
131
+ </>);
132
+ }
133
+
134
+ private renderMoveArrowColorSelector() {
135
+ if (!this.state.moveArrowVisible) {
136
+ return undefined;
137
+ }
138
+ const colorset = Chessboard.colorsets()['original'];
139
+ return (
140
+ <ToggleButtonGroup value={this.state.moveArrowColor} exclusive size="small" onChange={(_, newColor) => this.handleMoveArrowColorChanged(newColor)}>
141
+ <ToggleButton value="b"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cb} /></ToggleButton>
142
+ <ToggleButton value="g"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cg} /></ToggleButton>
143
+ <ToggleButton value="r"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cr} /></ToggleButton>
144
+ <ToggleButton value="y"><ArrowMarkerIcon size={COLOR_ICON_SIZE} color={colorset.cy} /></ToggleButton>
145
+ </ToggleButtonGroup>
146
+ );
147
+ }
148
+
149
+ private renderNavigationBoard() {
150
+ return (
151
+ <Box>
152
+ <NavigationBoard
153
+ game={pgn}
154
+ initialNodeId="end"
155
+ squareSize={this.state.squareSize}
156
+ coordinateVisible={this.state.coordinateVisible}
157
+ turnVisible={this.state.turnVisible}
158
+ colorset={this.state.colorset}
159
+ pieceset={this.state.pieceset}
160
+ moveArrowVisible={this.state.moveArrowVisible}
161
+ moveArrowColor={this.state.moveArrowColor}
162
+ animated={this.state.animated}
163
+ flipButtonVisible={this.state.flipButtonVisible}
164
+ />
165
+ </Box>
166
+ );
167
+ }
168
+
169
+ private renderCode() {
170
+ const attributes: string[] = [];
171
+ attributes.push('game={pgn}');
172
+ attributes.push('initialNodeId="end"');
173
+ attributes.push(`squareSize={${this.state.squareSize}}`);
174
+ attributes.push(`coordinateVisible={${this.state.coordinateVisible}}`);
175
+ attributes.push(`turnVisible={${this.state.turnVisible}}`);
176
+ attributes.push(`colorset="${this.state.colorset}"`);
177
+ attributes.push(`pieceset="${this.state.pieceset}"`);
178
+ attributes.push(`moveArrowVisible={${this.state.moveArrowVisible}}`);
179
+ if (this.state.moveArrowVisible) {
180
+ attributes.push(`moveArrowColor="${this.state.moveArrowColor}"`);
181
+ }
182
+ attributes.push(`animated={${this.state.animated}}`);
183
+ attributes.push(`flipButtonVisible={${this.state.flipButtonVisible}}`);
184
+ const pgnDeclaration = 'const pgn = `\n' + pgn.trim() + '`;\n\n';
185
+ return <pre className="kokopu-demoCode">{pgnDeclaration + buildComponentDemoCode('NavigationBoard', attributes)}</pre>;
186
+ }
187
+
188
+ private handleMoveArrowColorChanged(newColor: AnnotationColor | null) {
189
+ if (newColor !== null) {
190
+ this.setState({ moveArrowColor: newColor });
191
+ }
192
+ }
193
+
194
+ }