react-chessboard-ui 1.7.3 → 2.0.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.
@@ -1672,7 +1672,7 @@ var stateToFEN = function stateToFEN(state, currentColor, countMoves) {
1672
1672
  return positionsFEN + " " + colorFEN + " " + casttlingFEN + " " + beatedFieldFEN + " " + blackMoves + " " + countMoves;
1673
1673
  };
1674
1674
 
1675
- 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"};
1675
+ var styles = {"chessBoard":"_3XI6H","figuresLayout":"_2SyRK","controlLayout":"_3OVc8","controlLayoutGrabbing":"_G0IIl","interactiveLayout":"_3THn5","selectedSquare":"_1YsOr","pickedSquare":"_3MMcp","checkedSquare":"_KLkVN","interactiveCell":"_27yHq","possibleMoveMark":"_UYGA_","row":"_2XKSc","piece":"_2QHnf","holdedPiece":"_3z25q","bluredPiece":"_10meo","hiddenFigureEffect":"_2YKzU","arrow":"_12Bbd","arrowEnd":"_1BC3I","piecePicker":"_3gVhA","piecePickerItem":"_3EtmA","chessBoardPiecePicker":"_2xZM1","movesTrail":"_1RqCc","lightSquare":"_1B0qo","darkSquare":"_1NBqS"};
1676
1676
 
1677
1677
  var CHESS_PIECES_MAP = {
1678
1678
  'pawn-white': function pawnWhite(size) {
@@ -1874,36 +1874,41 @@ var CHESS_PIECES_MAP = {
1874
1874
  }
1875
1875
  };
1876
1876
 
1877
- var DEFAULT_CELL_SIZE = 92;
1878
- var DEFAULT_FIGURE_SIZE_PERCENT = 80;
1879
- var FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1877
+ var DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK = 4.6;
1880
1878
  var DEFAULT_CIRCLE_MARK_COLOR = '#3697ce';
1881
- var DEFAULT_WHITE_CELL_COLOR = '#fafafc';
1882
- var DEFAULT_BLACK_CELL_COLOR = '#d8d9e6';
1883
- var DEFAULT_SELECTED_CELL_COLOR = '#e3f1fe';
1884
- var DEFAULT_SELECTED_CELL_BORDER = '3px solid #6ac2fd';
1885
1879
  var DEFAULT_ARROW_COLOR = '#6ac2fd';
1886
- var DEFAULT_MARKED_CELL_COLOR = '#3697ce';
1887
- var DEFAULT_CHECKED_CELL_COLOR = '#e95b5c';
1888
1880
  var DEFAULT_PIECES_MAP = CHESS_PIECES_MAP;
1889
- var DEFAULT_CSS_HIDE_PIECES_EFFECT = styles.hiddenFigureEffect;
1890
1881
  var DEFAULT_SHOW_MOVES_TRAIL = true;
1891
1882
  var DEFAULT_HIDE_PIECES_HANDLER = function DEFAULT_HIDE_PIECES_HANDLER(figure) {
1892
1883
  figure.color === 'white' ? figure.position = [8, figure.position[1]] : figure.position = [-1, figure.position[1]];
1893
1884
  };
1885
+ var DEFAULT_SQUARE_SIZE = 92;
1886
+ var DEFAULT_PIECE_SIZE_PERCENT = 80;
1887
+ var DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME = styles.hiddenFigureEffect;
1888
+ var DEFAULT_LIGHT_SQUARE_CLASS_NAME = undefined;
1889
+ var DEFAULT_DARK_SQUARE_CLASS_NAME = undefined;
1890
+ var DEFAULT_PICKED_SQUARE_CLASS_NAME = undefined;
1891
+ var DEFAULT_CHECKED_SQUARE_CLASS_NAME = undefined;
1892
+ var DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME = undefined;
1893
+ var DEFAULT_SELECTED_SQUARE_CLASS_NAME = undefined;
1894
+ var DEFAULT_HOLDED_PIECE_CLASS_NAME = undefined;
1895
+ var DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME = undefined;
1894
1896
  var DEFAULT_CHESSBORD_CONFIG = {
1895
- cellSize: DEFAULT_CELL_SIZE,
1896
- figureSizePercent: DEFAULT_FIGURE_SIZE_PERCENT,
1897
+ squareSize: DEFAULT_SQUARE_SIZE,
1898
+ pieceSizePercent: DEFAULT_PIECE_SIZE_PERCENT,
1899
+ lightSquareClassName: DEFAULT_LIGHT_SQUARE_CLASS_NAME,
1900
+ darkSquareClassName: DEFAULT_DARK_SQUARE_CLASS_NAME,
1901
+ pickedSquareClassName: DEFAULT_PICKED_SQUARE_CLASS_NAME,
1902
+ selectedSquareClassName: DEFAULT_SELECTED_SQUARE_CLASS_NAME,
1903
+ holdedPieceClassName: DEFAULT_HOLDED_PIECE_CLASS_NAME,
1904
+ checkedSquareClassName: DEFAULT_CHECKED_SQUARE_CLASS_NAME,
1905
+ squareHighlightClassName: DEFAULT_SQUARE_HIGLIGHT_CLASS_NAME,
1897
1906
  circleMarkColor: DEFAULT_CIRCLE_MARK_COLOR,
1898
- whiteCellColor: DEFAULT_WHITE_CELL_COLOR,
1899
- blackCellColor: DEFAULT_BLACK_CELL_COLOR,
1900
- selectedCellColor: DEFAULT_SELECTED_CELL_COLOR,
1901
- selectedCellBorder: DEFAULT_SELECTED_CELL_BORDER,
1907
+ factorForSizeCircleMark: DEFAULT_FACTOR_FOR_SIZE_CIRCLE_MARK,
1908
+ possibleMoveMarkClassName: DEFAULT_POSSIBLE_MOVE_MARK_CLASS_NAME,
1902
1909
  arrowColor: DEFAULT_ARROW_COLOR,
1903
- markedCellColor: DEFAULT_MARKED_CELL_COLOR,
1904
- checkedCellColor: DEFAULT_CHECKED_CELL_COLOR,
1905
1910
  piecesMap: DEFAULT_PIECES_MAP,
1906
- cssHidePieceEffect: DEFAULT_CSS_HIDE_PIECES_EFFECT,
1911
+ hidePieceEffectClassName: DEFAULT_HIDE_PIECE_EFFECT_CLASS_NAME,
1907
1912
  showMovesTrail: DEFAULT_SHOW_MOVES_TRAIL,
1908
1913
  onHidePieces: DEFAULT_HIDE_PIECES_HANDLER
1909
1914
  };
@@ -1983,12 +1988,7 @@ var calcAngle = function calcAngle(start, end) {
1983
1988
  };
1984
1989
  var getChessBoardConfig = function getChessBoardConfig(config) {
1985
1990
  if (!config) return DEFAULT_CHESSBORD_CONFIG;
1986
- var configKeyes = Object.keys(DEFAULT_CHESSBORD_CONFIG);
1987
- var buildedConfig = {};
1988
- configKeyes.forEach(function (key) {
1989
- buildedConfig[key] = config[key] || DEFAULT_CHESSBORD_CONFIG[key];
1990
- });
1991
- return buildedConfig;
1991
+ return _extends({}, DEFAULT_CHESSBORD_CONFIG, config);
1992
1992
  };
1993
1993
  var getFiguresByColor = function getFiguresByColor(color, forPawnTransform) {
1994
1994
  if (forPawnTransform === void 0) {
@@ -2018,7 +2018,7 @@ var correctGrabbingPosByScroll = function correctGrabbingPosByScroll(pos) {
2018
2018
  return [pos[0] - window.scrollX, pos[1] - window.scrollY];
2019
2019
  };
2020
2020
  var correctGrabbingPosForArrow = function correctGrabbingPosForArrow(pos, boardConfig) {
2021
- return [pos[0] * boardConfig.cellSize + (boardConfig.cellSize / 2 - 10), pos[1] * boardConfig.cellSize + boardConfig.cellSize / 2];
2021
+ return [pos[0] * boardConfig.squareSize + (boardConfig.squareSize / 2 - 10), pos[1] * boardConfig.squareSize + boardConfig.squareSize / 2];
2022
2022
  };
2023
2023
  var createHtmlReversedStateHolder = function createHtmlReversedStateHolder() {
2024
2024
  if (!window) return;
@@ -2042,21 +2042,25 @@ var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
2042
2042
  var _ref$size = _ref.size,
2043
2043
  size = _ref$size === void 0 ? BASE_BOARD_SIZE : _ref$size,
2044
2044
  boardConfig = _ref.boardConfig,
2045
- movesTrail = _ref.movesTrail;
2045
+ movesTrail = _ref.movesTrail,
2046
+ moveHighlight = _ref.moveHighlight;
2046
2047
  return React.createElement("div", null, getFilledArrayBySize(size).map(function (_, j) {
2047
2048
  return React.createElement("div", {
2048
2049
  className: styles.row,
2049
2050
  key: "cells-layout-" + j
2050
2051
  }, getFilledArrayBySize(size).map(function (_, i) {
2052
+ var _cn;
2051
2053
  return React.createElement("div", {
2052
2054
  style: {
2053
- width: boardConfig.cellSize,
2054
- height: boardConfig.cellSize,
2055
- backgroundColor: getIsLightCell(j, i) ? boardConfig.whiteCellColor : boardConfig.blackCellColor
2055
+ width: boardConfig.squareSize,
2056
+ height: boardConfig.squareSize
2056
2057
  },
2058
+ className: cn((_cn = {}, _cn[styles.lightSquare] = !boardConfig.lightSquareClassName && getIsLightCell(j, i), _cn[styles.darkSquare] = !boardConfig.darkSquareClassName && !getIsLightCell(j, i), _cn[boardConfig.lightSquareClassName] = !!boardConfig.lightSquareClassName && getIsLightCell(j, i), _cn[boardConfig.darkSquareClassName] = !!boardConfig.darkSquareClassName && !getIsLightCell(j, i), _cn)),
2057
2059
  key: "cells-layout-" + i
2058
2060
  }, movesTrail && (movesTrail[0][0] === i && movesTrail[0][1] === j || movesTrail[1][0] === i && movesTrail[1][1] === j) && React.createElement("div", {
2059
- className: styles.movesTrail
2061
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2062
+ }), moveHighlight && (moveHighlight[0][0] === i && moveHighlight[0][1] === j || moveHighlight[1][0] === i && moveHighlight[1][1] === j) && React.createElement("div", {
2063
+ className: cn(styles.movesTrail, boardConfig.squareHighlightClassName)
2060
2064
  }));
2061
2065
  }));
2062
2066
  }));
@@ -2193,20 +2197,20 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
2193
2197
  });
2194
2198
  }, [reversed, initialState]);
2195
2199
  return React.createElement("div", {
2196
- className: styles.figuresLayout
2200
+ className: styles.piecesLayout
2197
2201
  }, actualState.map(function (figure, i) {
2198
2202
  var _cn;
2199
2203
  return React.createElement("div", {
2200
2204
  key: i,
2201
- className: cn([styles.figure], (_cn = {}, _cn[boardConfig.cssHidePieceEffect] = figure.beated, _cn)),
2205
+ className: cn([styles.piece], (_cn = {}, _cn[boardConfig.hidePieceEffectClassName] = figure.beated, _cn)),
2202
2206
  style: {
2203
- top: boardConfig.cellSize * figure.position[1] + "px",
2204
- left: boardConfig.cellSize * figure.position[0] + "px",
2207
+ top: boardConfig.squareSize * figure.position[1] + "px",
2208
+ left: boardConfig.squareSize * figure.position[0] + "px",
2205
2209
  transition: !!change && animated ? 'all .15s ease-out' : 'none',
2206
- width: boardConfig.cellSize,
2207
- height: boardConfig.cellSize
2210
+ width: boardConfig.squareSize,
2211
+ height: boardConfig.squareSize
2208
2212
  }
2209
- }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2213
+ }, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2210
2214
  }));
2211
2215
  };
2212
2216
 
@@ -2280,8 +2284,8 @@ var ChessBoardControlLayout = function ChessBoardControlLayout(props) {
2280
2284
  key: "control-layout-" + i,
2281
2285
  className: styles.controlCell,
2282
2286
  style: {
2283
- width: boardConfig.cellSize,
2284
- height: boardConfig.cellSize
2287
+ width: boardConfig.squareSize,
2288
+ height: boardConfig.squareSize
2285
2289
  },
2286
2290
  onClick: function onClick() {
2287
2291
  return handleClick([i, j]);
@@ -2735,7 +2739,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
2735
2739
  return hasCheck(cell, currentColor, linesWithCheck);
2736
2740
  };
2737
2741
  var startRenderArrow = function startRenderArrow(pos) {
2738
- var startPos = [(pos[0] + 1) * boardConfig.cellSize - boardConfig.cellSize / 2 - 10, (pos[1] + 1) * boardConfig.cellSize - boardConfig.cellSize / 2];
2742
+ var startPos = [(pos[0] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2 - 10, (pos[1] + 1) * boardConfig.squareSize - boardConfig.squareSize / 2];
2739
2743
  setStartArrowCoord(startPos);
2740
2744
  };
2741
2745
  var endRenderArrow = function endRenderArrow(_ref3) {
@@ -2838,16 +2842,16 @@ var HoldedFigure = function HoldedFigure(props) {
2838
2842
  boardConfig = props.boardConfig;
2839
2843
  var isCanShowFigure = holdedFigure && grabbingPos[0] > -1 && grabbingPos[1] > -1;
2840
2844
  return isCanShowFigure && React.createElement("div", {
2841
- className: cn([styles.figure, styles.holdedFigure]),
2845
+ className: cn([styles.piece, styles.holdedPiece]),
2842
2846
  style: {
2843
2847
  position: 'fixed',
2844
2848
  zIndex: 6,
2845
- top: grabbingPos[1] - boardConfig.cellSize / 2 + "px",
2846
- left: grabbingPos[0] - boardConfig.cellSize / 2 + "px",
2847
- width: boardConfig.cellSize,
2848
- height: boardConfig.cellSize
2849
+ top: grabbingPos[1] - boardConfig.squareSize / 2 + "px",
2850
+ left: grabbingPos[0] - boardConfig.squareSize / 2 + "px",
2851
+ width: boardConfig.squareSize,
2852
+ height: boardConfig.squareSize
2849
2853
  }
2850
- }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%"));
2854
+ }, " ", boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%"));
2851
2855
  };
2852
2856
 
2853
2857
  var BASE_BOARD_SIZE$2 = 8;
@@ -2874,27 +2878,23 @@ var ChessBoardInteractiveLayout = function ChessBoardInteractiveLayout(props) {
2874
2878
  }, getFilledArrayBySize(size).map(function (_, i) {
2875
2879
  var _cn, _cn2;
2876
2880
  return React.createElement("div", {
2877
- className: cn(styles.interactiveCell, (_cn = {}, _cn[styles.selectedCell] = selectedPos[0] === i && selectedPos[1] === j, _cn[styles.markedCell] = checkIsPossibleMove(markedCells, [i, j]), _cn[styles.checkedCell] = onHasCheck([i, j]), _cn)),
2881
+ className: cn(styles.interactiveCell, (_cn = {}, _cn[styles.selectedSquare + " " + boardConfig.selectedSquareClassName] = selectedPos[0] === i && selectedPos[1] === j, _cn[styles.pickedSquare + " " + boardConfig.pickedSquareClassName] = checkIsPossibleMove(markedCells, [i, j]), _cn[styles.checkedSquare + " " + boardConfig.checkedSquareClassName] = onHasCheck([i, j]), _cn)),
2878
2882
  key: "interactive-layout-" + i,
2879
2883
  style: {
2880
- width: boardConfig.cellSize,
2881
- height: boardConfig.cellSize,
2882
- backgroundColor: selectedPos[0] === i && selectedPos[1] === j ? boardConfig.selectedCellColor : 'transparent',
2883
- border: selectedPos[0] === i && selectedPos[1] === j ? boardConfig.selectedCellBorder : 'none',
2884
- boxShadow: checkIsPossibleMove(markedCells, [i, j]) ? "inset 0 0 30px " + boardConfig.markedCellColor : onHasCheck([i, j]) ? "inset 0 0 30px " + boardConfig.checkedCellColor : 'none'
2884
+ width: boardConfig.squareSize,
2885
+ height: boardConfig.squareSize
2885
2886
  }
2886
2887
  }, selectedPos[0] === i && selectedPos[1] === j && holdedFigure && React.createElement("div", {
2887
- className: cn([styles.figure, styles.holdedFigure], (_cn2 = {}, _cn2[styles.bluredFigure] = grabbingPos[0] !== -1, _cn2)),
2888
+ className: cn([styles.piece, styles.holdedPiece], (_cn2 = {}, _cn2[styles.bluredPiece] = grabbingPos[0] !== -1, _cn2)),
2888
2889
  style: {
2889
- width: boardConfig.cellSize,
2890
- height: boardConfig.cellSize
2890
+ width: boardConfig.squareSize,
2891
+ height: boardConfig.squareSize
2891
2892
  }
2892
- }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.figureSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2893
- className: styles.possibleMoveMark,
2893
+ }, boardConfig.piecesMap[getFigureCSS(holdedFigure)](boardConfig.pieceSizePercent + "%")), checkIsPossibleMove(possibleMoves, [i, j]) && React.createElement("div", {
2894
+ className: cn([styles.possibleMoveMark, boardConfig.possibleMoveMarkClassName]),
2894
2895
  style: {
2895
- width: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2896
- height: boardConfig.cellSize / FACTOR_FOR_SIZE_CIRCLE_MARK,
2897
- backgroundColor: boardConfig.circleMarkColor
2896
+ width: boardConfig.squareSize / boardConfig.factorForSizeCircleMark,
2897
+ height: boardConfig.squareSize / boardConfig.factorForSizeCircleMark
2898
2898
  }
2899
2899
  }));
2900
2900
  }));
@@ -2960,19 +2960,19 @@ var FigurePicker = function FigurePicker(props) {
2960
2960
  onSelect(figure);
2961
2961
  }, [onSelect]);
2962
2962
  return React.createElement("div", {
2963
- className: styles.figurePicker
2963
+ className: styles.piecePicker
2964
2964
  }, getFiguresByColor(color, forPawnTransform).map(function (figure) {
2965
2965
  return React.createElement("div", {
2966
2966
  key: figure.type,
2967
- className: styles.figurePickerItem,
2967
+ className: styles.piecePickerItem,
2968
2968
  style: {
2969
- width: boardConfig.cellSize,
2970
- height: boardConfig.cellSize
2969
+ width: boardConfig.squareSize,
2970
+ height: boardConfig.squareSize
2971
2971
  },
2972
2972
  onClick: function onClick() {
2973
2973
  return handleChange(figure);
2974
2974
  }
2975
- }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.figureSizePercent + "%"));
2975
+ }, boardConfig.piecesMap[getFigureCSS(figure)](boardConfig.pieceSizePercent + "%"));
2976
2976
  }));
2977
2977
  };
2978
2978
 
@@ -2984,7 +2984,8 @@ var ChessBoard = function ChessBoard(props) {
2984
2984
  reversed = props.reversed,
2985
2985
  config = props.config,
2986
2986
  playerColor = props.playerColor,
2987
- viewOnly = props.viewOnly;
2987
+ viewOnly = props.viewOnly,
2988
+ moveHighlight = props.moveHighlight;
2988
2989
  var _useChessBoardInterac = useChessBoardInteractive({
2989
2990
  onChange: onChange,
2990
2991
  onEndGame: onEndGame,
@@ -3053,7 +3054,8 @@ var ChessBoard = function ChessBoard(props) {
3053
3054
  className: styles.chessBoard
3054
3055
  }, React.createElement(ChessBoardCellsLayout, {
3055
3056
  boardConfig: boardConfig,
3056
- movesTrail: boardConfig.showMovesTrail && movesTrail
3057
+ movesTrail: boardConfig.showMovesTrail && movesTrail,
3058
+ moveHighlight: moveHighlight
3057
3059
  }), React.createElement(ChessBoardFiguresLayout, {
3058
3060
  initialState: initialState,
3059
3061
  change: newMove,
@@ -3085,7 +3087,7 @@ var ChessBoard = function ChessBoard(props) {
3085
3087
  onRightClick: markCell,
3086
3088
  onGrabbingCell: handleGrabbingCell
3087
3089
  }), showFigurePicker && React.createElement("div", {
3088
- className: styles.chessBoardFigurePicker
3090
+ className: styles.chessBoardPiecePicker
3089
3091
  }, React.createElement(FigurePicker, {
3090
3092
  boardConfig: boardConfig,
3091
3093
  color: currentColor,