react-chessboard-ui 1.5.1 → 1.7.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.
@@ -5,6 +5,7 @@ declare type ChessBoardProps = {
5
5
  FEN: string;
6
6
  onChange: (moveData: MoveData) => void;
7
7
  onEndGame: (result: GameResult) => void;
8
+ showMovesTrail?: boolean;
8
9
  change?: ChangeMove;
9
10
  reversed?: boolean;
10
11
  config?: Partial<ChessBoardConfig>;
@@ -1,8 +1,10 @@
1
1
  import { FC } from "react";
2
2
  import { ChessBoardConfig } from "./models";
3
+ import { CellPos } from "../JSChessEngine";
3
4
  declare type ChessBoardCellsLayoutProps = {
4
- size?: number;
5
5
  boardConfig: ChessBoardConfig;
6
+ size?: number;
7
+ movesTrail?: [CellPos, CellPos];
6
8
  };
7
9
  export declare const ChessBoardCellsLayout: FC<ChessBoardCellsLayoutProps>;
8
10
  export {};
@@ -1,3 +1,4 @@
1
+ import { Figure } from "../JSChessEngine";
1
2
  import { ChessBoardConfig } from "./models";
2
3
  export declare const DEFAULT_CELL_SIZE = 92;
3
4
  export declare const DEFAULT_FIGURE_SIZE_PERCENT = 80;
@@ -11,4 +12,6 @@ export declare const DEFAULT_ARROW_COLOR = "#6ac2fd";
11
12
  export declare const DEFAULT_MARKED_CELL_COLOR = "#3697ce";
12
13
  export declare const DEFAULT_CHECKED_CELL_COLOR = "#e95b5c";
13
14
  export declare const DEFAULT_PIECES_MAP: import("./models").ChessPiecesMap;
15
+ export declare const DEFAULT_CSS_HIDE_PIECES_EFFECT: string;
16
+ export declare const DEFAULT_HIDE_PIECES_HANDLER: (figure: Figure) => void;
14
17
  export declare const DEFAULT_CHESSBORD_CONFIG: ChessBoardConfig;
@@ -10,6 +10,7 @@ export declare const useChessBoardInteractive: (props: UseChessBoardInteractiveP
10
10
  fromPos: CellPos;
11
11
  newMove: ChangeMove;
12
12
  animated: boolean;
13
+ movesTrail: [CellPos, CellPos];
13
14
  boardConfig: ChessBoardConfig;
14
15
  markedCells: CellPos[];
15
16
  grabbingPos: CellPos;
package/dist/index.css CHANGED
@@ -92,7 +92,7 @@
92
92
  opacity: .4;
93
93
  }
94
94
 
95
- ._1cIvE {
95
+ ._2YKzU {
96
96
  opacity: 0;
97
97
  transform: rotate(-90deg);
98
98
  }
@@ -144,4 +144,11 @@
144
144
  display: flex;
145
145
  justify-content: center;
146
146
  align-items: center;
147
- }
147
+ }
148
+
149
+ ._1RqCc {
150
+ width: 100%;
151
+ height: 100%;
152
+ box-shadow: inset 0 0 11px #3697ce80 !important;
153
+ background-color: #B8E6FE;
154
+ }
package/dist/index.js CHANGED
@@ -1675,7 +1675,7 @@ var stateToFEN = function stateToFEN(state, currentColor, countMoves) {
1675
1675
  return positionsFEN + " " + colorFEN + " " + casttlingFEN + " " + beatedFieldFEN + " " + blackMoves + " " + countMoves;
1676
1676
  };
1677
1677
 
1678
- var styles = {"chessBoard":"_3XI6H","figuresLayout":"_2SyRK","controlLayout":"_3OVc8","controlLayoutGrabbing":"_G0IIl","interactiveLayout":"_3THn5","selectedCell":"_3vcXe","controlCell":"_2yJs1","interactiveCell":"_27yHq","possibleMoveMark":"_UYGA_","row":"_2XKSc","cell":"_ssFQn","cellLight":"_1407I","figure":"_19mE-","holdedFigure":"_3u_-s","bluredFigure":"_3SfMJ","hiddenFigure":"_1cIvE","markedCell":"_Zly-L","checkedCell":"_31pmr","arrow":"_12Bbd","arrowEnd":"_1BC3I","figurePicker":"_13OXq","figurePickerItem":"_16zCe","chessBoardFigurePicker":"_1ZGj2"};
1678
+ var styles = {"chessBoard":"_3XI6H","figuresLayout":"_2SyRK","controlLayout":"_3OVc8","controlLayoutGrabbing":"_G0IIl","interactiveLayout":"_3THn5","selectedCell":"_3vcXe","controlCell":"_2yJs1","interactiveCell":"_27yHq","possibleMoveMark":"_UYGA_","row":"_2XKSc","cell":"_ssFQn","cellLight":"_1407I","figure":"_19mE-","holdedFigure":"_3u_-s","bluredFigure":"_3SfMJ","hiddenFigureEffect":"_2YKzU","markedCell":"_Zly-L","checkedCell":"_31pmr","arrow":"_12Bbd","arrowEnd":"_1BC3I","figurePicker":"_13OXq","figurePickerItem":"_16zCe","chessBoardFigurePicker":"_1ZGj2","movesTrail":"_1RqCc"};
1679
1679
 
1680
1680
  var CHESS_PIECES_MAP = {
1681
1681
  'pawn-white': function pawnWhite(size) {
@@ -1889,6 +1889,10 @@ var DEFAULT_ARROW_COLOR = '#6ac2fd';
1889
1889
  var DEFAULT_MARKED_CELL_COLOR = '#3697ce';
1890
1890
  var DEFAULT_CHECKED_CELL_COLOR = '#e95b5c';
1891
1891
  var DEFAULT_PIECES_MAP = CHESS_PIECES_MAP;
1892
+ var DEFAULT_CSS_HIDE_PIECES_EFFECT = styles.hiddenFigureEffect;
1893
+ var DEFAULT_HIDE_PIECES_HANDLER = function DEFAULT_HIDE_PIECES_HANDLER(figure) {
1894
+ figure.color === 'white' ? figure.position = [8, figure.position[1]] : figure.position = [-1, figure.position[1]];
1895
+ };
1892
1896
  var DEFAULT_CHESSBORD_CONFIG = {
1893
1897
  cellSize: DEFAULT_CELL_SIZE,
1894
1898
  figureSizePercent: DEFAULT_FIGURE_SIZE_PERCENT,
@@ -1900,7 +1904,9 @@ var DEFAULT_CHESSBORD_CONFIG = {
1900
1904
  arrowColor: DEFAULT_ARROW_COLOR,
1901
1905
  markedCellColor: DEFAULT_MARKED_CELL_COLOR,
1902
1906
  checkedCellColor: DEFAULT_CHECKED_CELL_COLOR,
1903
- piecesMap: DEFAULT_PIECES_MAP
1907
+ piecesMap: DEFAULT_PIECES_MAP,
1908
+ cssHidePieceEffect: DEFAULT_CSS_HIDE_PIECES_EFFECT,
1909
+ onHidePieces: DEFAULT_HIDE_PIECES_HANDLER
1904
1910
  };
1905
1911
 
1906
1912
  var getFigureCSS = function getFigureCSS(figure) {
@@ -2157,7 +2163,8 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2157
2163
  return figure.position[0] === to[0] && figure.position[1] === to[1];
2158
2164
  });
2159
2165
  if (foundAttactedFigure && foundAttactedFigure.color !== move.figure.color) {
2160
- foundAttactedFigure.color === 'white' ? foundAttactedFigure.position = [8, foundAttactedFigure.position[1]] : foundAttactedFigure.position = [-1, foundAttactedFigure.position[1]];
2166
+ foundAttactedFigure.beated = true;
2167
+ boardConfig.onHidePieces(foundAttactedFigure);
2161
2168
  }
2162
2169
  var foundFigureByPositionFrom = updatedState.find(function (figure) {
2163
2170
  return figure.position[0] === from[0] && figure.position[1] === from[1];
@@ -2189,7 +2196,7 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2189
2196
  var _cn;
2190
2197
  return React__default.createElement("div", {
2191
2198
  key: i,
2192
- className: cn([styles.figure], (_cn = {}, _cn[styles.hiddenFigure] = figure.position[0] === -1 || figure.position[0] === 8, _cn)),
2199
+ className: cn([styles.figure], (_cn = {}, _cn[boardConfig.cssHidePieceEffect] = figure.beated, _cn)),
2193
2200
  style: {
2194
2201
  top: boardConfig.cellSize * figure.position[1] + "px",
2195
2202
  left: boardConfig.cellSize * figure.position[0] + "px",
@@ -2325,39 +2332,42 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2325
2332
  var _useState11 = React.useState(),
2326
2333
  newMove = _useState11[0],
2327
2334
  setNewMove = _useState11[1];
2328
- var _useState12 = React.useState([]),
2329
- linesWithCheck = _useState12[0],
2330
- setLinesWithCheck = _useState12[1];
2335
+ var _useState12 = React.useState(),
2336
+ movesTrail = _useState12[0],
2337
+ setMovesTrail = _useState12[1];
2331
2338
  var _useState13 = React.useState([]),
2332
- markedCells = _useState13[0],
2333
- setMarkedCells = _useState13[1];
2334
- var _useState14 = React.useState([-1, -1]),
2335
- grabbingCell = _useState14[0],
2336
- setGrabbingCell = _useState14[1];
2339
+ linesWithCheck = _useState13[0],
2340
+ setLinesWithCheck = _useState13[1];
2341
+ var _useState14 = React.useState([]),
2342
+ markedCells = _useState14[0],
2343
+ setMarkedCells = _useState14[1];
2337
2344
  var _useState15 = React.useState([-1, -1]),
2338
- clickedPos = _useState15[0],
2339
- setClickedPos = _useState15[1];
2340
- var _useState16 = React.useState(),
2341
- clickedFigure = _useState16[0],
2342
- setClickedFigure = _useState16[1];
2343
- var _useState17 = React.useState([]),
2344
- clickPossibleMoves = _useState17[0],
2345
- setClickPossibleMoves = _useState17[1];
2346
- var _useState18 = React.useState([-1, -1]),
2347
- startArrowCoord = _useState18[0],
2348
- setStartArrowCoord = _useState18[1];
2349
- var _useState19 = React.useState([]),
2350
- arrowsCoords = _useState19[0],
2351
- setArrowsCoords = _useState19[1];
2352
- var _useState20 = React.useState(false),
2353
- showFigurePicker = _useState20[0],
2354
- setShowFigurePicker = _useState20[1];
2355
- var _useState21 = React.useState([-1, -1]),
2356
- targetPos = _useState21[0],
2357
- setTargetPos = _useState21[1];
2358
- var _useState22 = React.useState(false),
2359
- animated = _useState22[0],
2360
- setAnimated = _useState22[1];
2345
+ grabbingCell = _useState15[0],
2346
+ setGrabbingCell = _useState15[1];
2347
+ var _useState16 = React.useState([-1, -1]),
2348
+ clickedPos = _useState16[0],
2349
+ setClickedPos = _useState16[1];
2350
+ var _useState17 = React.useState(),
2351
+ clickedFigure = _useState17[0],
2352
+ setClickedFigure = _useState17[1];
2353
+ var _useState18 = React.useState([]),
2354
+ clickPossibleMoves = _useState18[0],
2355
+ setClickPossibleMoves = _useState18[1];
2356
+ var _useState19 = React.useState([-1, -1]),
2357
+ startArrowCoord = _useState19[0],
2358
+ setStartArrowCoord = _useState19[1];
2359
+ var _useState20 = React.useState([]),
2360
+ arrowsCoords = _useState20[0],
2361
+ setArrowsCoords = _useState20[1];
2362
+ var _useState21 = React.useState(false),
2363
+ showFigurePicker = _useState21[0],
2364
+ setShowFigurePicker = _useState21[1];
2365
+ var _useState22 = React.useState([-1, -1]),
2366
+ targetPos = _useState22[0],
2367
+ setTargetPos = _useState22[1];
2368
+ var _useState23 = React.useState(false),
2369
+ animated = _useState23[0],
2370
+ setAnimated = _useState23[1];
2361
2371
  var clearFromPos = function clearFromPos() {
2362
2372
  return setFromPos([-1, -1]);
2363
2373
  };
@@ -2519,6 +2529,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2519
2529
  move: boardReversed ? JSChessEngine.reverseMove(change.move) : change.move
2520
2530
  });
2521
2531
  setNewMove(updatedChange);
2532
+ setMovesTrail([from, to]);
2522
2533
  };
2523
2534
  var moveFigureByClick = function moveFigureByClick(from, to, figure) {
2524
2535
  if (!!playerColor && currentColor !== playerColor) {
@@ -2630,6 +2641,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2630
2641
  withTransition: withTransition,
2631
2642
  attackedPos: attackedPos
2632
2643
  });
2644
+ setMovesTrail([moveData.from, moveData.to]);
2633
2645
  clearGrabbingPos();
2634
2646
  clearPossibleMoves();
2635
2647
  };
@@ -2644,6 +2656,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2644
2656
  transformTo: moveData.type === 'transform' ? moveData.figure : undefined
2645
2657
  };
2646
2658
  setNewMove(change);
2659
+ setMovesTrail([moveData.from, moveData.to]);
2647
2660
  clearClickedPos();
2648
2661
  setHoldedFigure(undefined);
2649
2662
  clearFromPos();
@@ -2671,6 +2684,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2671
2684
  withTransition: withTransition,
2672
2685
  attackedPos: attackedPos
2673
2686
  });
2687
+ setMovesTrail([moveData.from, moveData.to]);
2674
2688
  clearClickedPos();
2675
2689
  clearClickPossibleMoves();
2676
2690
  };
@@ -2752,6 +2766,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2752
2766
  withTransition: false,
2753
2767
  transformTo: figure
2754
2768
  });
2769
+ setMovesTrail([moveData.from, moveData.to]);
2755
2770
  var linesWithCheck = JSChessEngine.getLinesWithCheck(updatedCells, currentColor, boardReversed);
2756
2771
  setLinesWithCheck(linesWithCheck);
2757
2772
  clearGrabbingPos();
@@ -2771,6 +2786,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2771
2786
  fromPos: fromPos,
2772
2787
  newMove: newMove,
2773
2788
  animated: animated,
2789
+ movesTrail: movesTrail,
2774
2790
  boardConfig: boardConfig,
2775
2791
  markedCells: markedCells,
2776
2792
  grabbingPos: grabbingPos,