react-chessboard-ui 1.1.2 → 1.2.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.
@@ -114,6 +114,9 @@ JSChessEngine.reverseChessBoard = function (state) {
114
114
  });
115
115
  };
116
116
  JSChessEngine.reverseMove = function (moveData, boardSize) {
117
+ if (boardSize === void 0) {
118
+ boardSize = 8;
119
+ }
117
120
  var from = moveData.from,
118
121
  to = moveData.to,
119
122
  figure = moveData.figure,
@@ -2028,7 +2031,8 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2028
2031
  var initialState = props.initialState,
2029
2032
  change = props.change,
2030
2033
  reversed = props.reversed,
2031
- boardConfig = props.boardConfig;
2034
+ boardConfig = props.boardConfig,
2035
+ animated = props.animated;
2032
2036
  var _useState = useState([]),
2033
2037
  actualState = _useState[0],
2034
2038
  setActualState = _useState[1];
@@ -2128,7 +2132,7 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2128
2132
  style: {
2129
2133
  top: boardConfig.cellSize * figure.position[1] + "px",
2130
2134
  left: boardConfig.cellSize * figure.position[0] + "px",
2131
- transition: !!change && change.withTransition ? 'all .15s ease-out' : 'none',
2135
+ transition: !!change && animated ? 'all .15s ease-out' : 'none',
2132
2136
  width: boardConfig.cellSize,
2133
2137
  height: boardConfig.cellSize
2134
2138
  }
@@ -2812,6 +2816,9 @@ var ChessBoard = function ChessBoard(props) {
2812
2816
  reversed = props.reversed,
2813
2817
  config = props.config,
2814
2818
  playerColor = props.playerColor;
2819
+ var _useState = useState(false),
2820
+ animated = _useState[0],
2821
+ setAnimated = _useState[1];
2815
2822
  var _useChessBoardInterac = useChessBoardInteractive({
2816
2823
  onChange: onChange,
2817
2824
  onEndGame: onEndGame,
@@ -2846,22 +2853,43 @@ var ChessBoard = function ChessBoard(props) {
2846
2853
  handleGrabbingCell = _useChessBoardInterac.handleGrabbingCell,
2847
2854
  getHasCheckByCellPos = _useChessBoardInterac.getHasCheckByCellPos,
2848
2855
  handleSelectFigurePicker = _useChessBoardInterac.handleSelectFigurePicker;
2849
- useEffect(function () {
2850
- setPlayerColor(playerColor);
2851
- }, [playerColor]);
2852
- useEffect(function () {
2856
+ var handleUpdateFEN = function handleUpdateFEN(FEN) {
2853
2857
  var _FENtoGameState = FENtoGameState(FEN),
2854
2858
  boardState = _FENtoGameState.boardState,
2855
2859
  currentColor = _FENtoGameState.currentColor;
2856
2860
  setInitialState(boardState);
2857
2861
  setActualState(boardState);
2858
2862
  setCurrentColor(currentColor);
2863
+ };
2864
+ useEffect(function () {
2865
+ setPlayerColor(playerColor);
2866
+ }, [playerColor]);
2867
+ useEffect(function () {
2868
+ handleUpdateFEN(FEN);
2859
2869
  }, [FEN]);
2860
2870
  useEffect(function () {
2861
2871
  if (reversed) reverseChessBoard();
2862
2872
  }, [reversed]);
2863
2873
  useEffect(function () {
2864
- setNewMove(change);
2874
+ if (!change) return;
2875
+ var updatedChange = _extends({}, change, {
2876
+ move: reversed ? JSChessEngine.reverseMove(change.move) : change.move
2877
+ });
2878
+ if (change.withTransition) {
2879
+ setAnimated(true);
2880
+ setTimeout(function () {
2881
+ setNewMove(updatedChange);
2882
+ }, 10);
2883
+ setTimeout(function () {
2884
+ setAnimated(false);
2885
+ }, 160);
2886
+ setTimeout(function () {
2887
+ handleUpdateFEN(updatedChange.move.FEN);
2888
+ }, 170);
2889
+ } else {
2890
+ setNewMove(updatedChange);
2891
+ handleUpdateFEN(updatedChange.move.FEN);
2892
+ }
2865
2893
  }, [change]);
2866
2894
  return React.createElement("div", {
2867
2895
  className: styles.chessBoard
@@ -2871,7 +2899,8 @@ var ChessBoard = function ChessBoard(props) {
2871
2899
  initialState: initialState,
2872
2900
  change: newMove,
2873
2901
  reversed: reversed,
2874
- boardConfig: boardConfig
2902
+ boardConfig: boardConfig,
2903
+ animated: animated
2875
2904
  }), React.createElement(ChessBoardInteractiveLayout, {
2876
2905
  selectedPos: fromPos,
2877
2906
  possibleMoves: possibleMoves,