react-chessboard-ui 1.7.2 → 1.7.4

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.
@@ -1,4 +1,4 @@
1
- import { FigureColor, GameResult, MoveData } from "../JSChessEngine";
1
+ import { FigureColor, GameResult, MoveData, CellPos } from "../JSChessEngine";
2
2
  import { FC } from "react";
3
3
  import { ChangeMove, ChessBoardConfig } from "./models";
4
4
  declare type ChessBoardProps = {
@@ -10,6 +10,7 @@ declare type ChessBoardProps = {
10
10
  config?: Partial<ChessBoardConfig>;
11
11
  playerColor?: FigureColor;
12
12
  viewOnly?: boolean;
13
+ moveHighlight?: [CellPos, CellPos];
13
14
  };
14
15
  export declare const ChessBoard: FC<ChessBoardProps>;
15
16
  export {};
@@ -5,6 +5,7 @@ declare type ChessBoardCellsLayoutProps = {
5
5
  boardConfig: ChessBoardConfig;
6
6
  size?: number;
7
7
  movesTrail?: [CellPos, CellPos];
8
+ moveHighlight?: [CellPos, CellPos];
8
9
  };
9
10
  export declare const ChessBoardCellsLayout: FC<ChessBoardCellsLayoutProps>;
10
11
  export {};
@@ -46,7 +46,7 @@ export declare const useChessBoardInteractive: (props: UseChessBoardInteractiveP
46
46
  moveFigureByChange: (change: ChangeMove) => void;
47
47
  getHasCheckByCellPos: ([x, y]: CellPos) => boolean;
48
48
  handleSelectFigurePicker: (figure: Figure) => void;
49
- handleChangeFromExternal: (moveData: MoveData) => void;
49
+ handleChangeFromExternal: (moveData: MoveData, withTransition?: boolean) => void;
50
50
  moveFigureByExternalChange: (from: CellPos, to: CellPos, figure: Figure) => {
51
51
  moveData?: undefined;
52
52
  attackedPos?: undefined;
package/dist/index.js CHANGED
@@ -2045,7 +2045,8 @@ var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
2045
2045
  var _ref$size = _ref.size,
2046
2046
  size = _ref$size === void 0 ? BASE_BOARD_SIZE : _ref$size,
2047
2047
  boardConfig = _ref.boardConfig,
2048
- movesTrail = _ref.movesTrail;
2048
+ movesTrail = _ref.movesTrail,
2049
+ moveHighlight = _ref.moveHighlight;
2049
2050
  return React__default.createElement("div", null, getFilledArrayBySize(size).map(function (_, j) {
2050
2051
  return React__default.createElement("div", {
2051
2052
  className: styles.row,
@@ -2060,6 +2061,8 @@ var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
2060
2061
  key: "cells-layout-" + i
2061
2062
  }, movesTrail && (movesTrail[0][0] === i && movesTrail[0][1] === j || movesTrail[1][0] === i && movesTrail[1][1] === j) && React__default.createElement("div", {
2062
2063
  className: styles.movesTrail
2064
+ }), moveHighlight && (moveHighlight[0][0] === i && moveHighlight[0][1] === j || moveHighlight[1][0] === i && moveHighlight[1][1] === j) && React__default.createElement("div", {
2065
+ className: styles.movesTrail
2063
2066
  }));
2064
2067
  }));
2065
2068
  }));
@@ -2650,10 +2653,13 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2650
2653
  clearGrabbingPos();
2651
2654
  clearPossibleMoves();
2652
2655
  };
2653
- var handleChangeFromExternal = function handleChangeFromExternal(moveData) {
2656
+ var handleChangeFromExternal = function handleChangeFromExternal(moveData, withTransition) {
2657
+ if (withTransition === void 0) {
2658
+ withTransition = true;
2659
+ }
2654
2660
  var _moveFigureByExternal = moveFigureByExternalChange(moveData.from, moveData.to, moveData.figure),
2655
2661
  attackedPos = _moveFigureByExternal.attackedPos;
2656
- setAnimated(true);
2662
+ setAnimated(withTransition);
2657
2663
  var change = {
2658
2664
  move: moveData,
2659
2665
  withTransition: true,
@@ -2984,7 +2990,8 @@ var ChessBoard = function ChessBoard(props) {
2984
2990
  reversed = props.reversed,
2985
2991
  config = props.config,
2986
2992
  playerColor = props.playerColor,
2987
- viewOnly = props.viewOnly;
2993
+ viewOnly = props.viewOnly,
2994
+ moveHighlight = props.moveHighlight;
2988
2995
  var _useChessBoardInterac = useChessBoardInteractive({
2989
2996
  onChange: onChange,
2990
2997
  onEndGame: onEndGame,
@@ -3007,6 +3014,7 @@ var ChessBoard = function ChessBoard(props) {
3007
3014
  showFigurePicker = _useChessBoardInterac.showFigurePicker,
3008
3015
  markCell = _useChessBoardInterac.markCell,
3009
3016
  handleClick = _useChessBoardInterac.handleClick,
3017
+ setAnimated = _useChessBoardInterac.setAnimated,
3010
3018
  handleGrabEnd = _useChessBoardInterac.handleGrabEnd,
3011
3019
  handleGrabbing = _useChessBoardInterac.handleGrabbing,
3012
3020
  endRenderArrow = _useChessBoardInterac.endRenderArrow,
@@ -3027,6 +3035,7 @@ var ChessBoard = function ChessBoard(props) {
3027
3035
  boardState = _FENtoGameState.boardState,
3028
3036
  currentColor = _FENtoGameState.currentColor;
3029
3037
  cleanAllForFigure();
3038
+ setAnimated(false);
3030
3039
  setInitialState(boardState);
3031
3040
  setActualState(boardState);
3032
3041
  setCurrentColor(currentColor);
@@ -3045,13 +3054,14 @@ var ChessBoard = function ChessBoard(props) {
3045
3054
  React.useEffect(function () {
3046
3055
  if (!change) return;
3047
3056
  var reversedChange = reversed ? JSChessEngine.reverseMove(change.move) : change.move;
3048
- handleChangeFromExternal(reversedChange);
3057
+ handleChangeFromExternal(reversedChange, change.withTransition);
3049
3058
  }, [change]);
3050
3059
  return React__default.createElement("div", {
3051
3060
  className: styles.chessBoard
3052
3061
  }, React__default.createElement(ChessBoardCellsLayout, {
3053
3062
  boardConfig: boardConfig,
3054
- movesTrail: boardConfig.showMovesTrail && movesTrail
3063
+ movesTrail: boardConfig.showMovesTrail && movesTrail,
3064
+ moveHighlight: moveHighlight
3055
3065
  }), React__default.createElement(ChessBoardFiguresLayout, {
3056
3066
  initialState: initialState,
3057
3067
  change: newMove,