react-chessboard-ui 1.1.2 → 1.2.1
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.
- package/dist/ChessBoard/ChessBoardFiguresLayout.d.ts +1 -0
- package/dist/ChessBoard/useChessBoardInteractive.d.ts +2 -0
- package/dist/JSChessEngine/JSChessEngine.d.ts +1 -1
- package/dist/index.js +44 -9
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +44 -9
- package/dist/index.modern.js.map +1 -1
- package/package.json +2 -3
package/dist/index.modern.js
CHANGED
|
@@ -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,11 +2132,11 @@ 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 &&
|
|
2135
|
+
transition: !!change && animated ? 'all .15s ease-out' : 'none',
|
|
2132
2136
|
width: boardConfig.cellSize,
|
|
2133
2137
|
height: boardConfig.cellSize
|
|
2134
2138
|
}
|
|
2135
|
-
}, boardConfig.piecesMap[getFigureCSS(figure)]('80%'));
|
|
2139
|
+
}, boardConfig.piecesMap[getFigureCSS(figure)] && boardConfig.piecesMap[getFigureCSS(figure)]('80%'));
|
|
2136
2140
|
}));
|
|
2137
2141
|
};
|
|
2138
2142
|
|
|
@@ -2290,6 +2294,9 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2290
2294
|
var _useState21 = useState([-1, -1]),
|
|
2291
2295
|
targetPos = _useState21[0],
|
|
2292
2296
|
setTargetPos = _useState21[1];
|
|
2297
|
+
var _useState22 = useState(false),
|
|
2298
|
+
animated = _useState22[0],
|
|
2299
|
+
setAnimated = _useState22[1];
|
|
2293
2300
|
var clearFromPos = function clearFromPos() {
|
|
2294
2301
|
return setFromPos([-1, -1]);
|
|
2295
2302
|
};
|
|
@@ -2506,6 +2513,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2506
2513
|
return;
|
|
2507
2514
|
}
|
|
2508
2515
|
onChange(moveData);
|
|
2516
|
+
setAnimated(withTransition);
|
|
2509
2517
|
setNewMove({
|
|
2510
2518
|
move: moveData,
|
|
2511
2519
|
withTransition: withTransition,
|
|
@@ -2529,6 +2537,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2529
2537
|
attackedPos = _moveFigureByClick.attackedPos;
|
|
2530
2538
|
if (!moveData) return;
|
|
2531
2539
|
onChange(moveData);
|
|
2540
|
+
setAnimated(withTransition);
|
|
2532
2541
|
setNewMove({
|
|
2533
2542
|
move: moveData,
|
|
2534
2543
|
withTransition: withTransition,
|
|
@@ -2626,6 +2635,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2626
2635
|
return {
|
|
2627
2636
|
fromPos: fromPos,
|
|
2628
2637
|
newMove: newMove,
|
|
2638
|
+
animated: animated,
|
|
2629
2639
|
boardConfig: boardConfig,
|
|
2630
2640
|
markedCells: markedCells,
|
|
2631
2641
|
grabbingPos: grabbingPos,
|
|
@@ -2641,6 +2651,7 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2641
2651
|
showFigurePicker: showFigurePicker,
|
|
2642
2652
|
markCell: markCell,
|
|
2643
2653
|
setNewMove: setNewMove,
|
|
2654
|
+
setAnimated: setAnimated,
|
|
2644
2655
|
handleClick: handleClick,
|
|
2645
2656
|
clearFromPos: clearFromPos,
|
|
2646
2657
|
handleGrabEnd: handleGrabEnd,
|
|
@@ -2819,6 +2830,7 @@ var ChessBoard = function ChessBoard(props) {
|
|
|
2819
2830
|
}),
|
|
2820
2831
|
fromPos = _useChessBoardInterac.fromPos,
|
|
2821
2832
|
newMove = _useChessBoardInterac.newMove,
|
|
2833
|
+
animated = _useChessBoardInterac.animated,
|
|
2822
2834
|
boardConfig = _useChessBoardInterac.boardConfig,
|
|
2823
2835
|
markedCells = _useChessBoardInterac.markedCells,
|
|
2824
2836
|
grabbingPos = _useChessBoardInterac.grabbingPos,
|
|
@@ -2832,6 +2844,7 @@ var ChessBoard = function ChessBoard(props) {
|
|
|
2832
2844
|
showFigurePicker = _useChessBoardInterac.showFigurePicker,
|
|
2833
2845
|
markCell = _useChessBoardInterac.markCell,
|
|
2834
2846
|
setNewMove = _useChessBoardInterac.setNewMove,
|
|
2847
|
+
setAnimated = _useChessBoardInterac.setAnimated,
|
|
2835
2848
|
handleClick = _useChessBoardInterac.handleClick,
|
|
2836
2849
|
handleGrabEnd = _useChessBoardInterac.handleGrabEnd,
|
|
2837
2850
|
handleGrabbing = _useChessBoardInterac.handleGrabbing,
|
|
@@ -2846,22 +2859,43 @@ var ChessBoard = function ChessBoard(props) {
|
|
|
2846
2859
|
handleGrabbingCell = _useChessBoardInterac.handleGrabbingCell,
|
|
2847
2860
|
getHasCheckByCellPos = _useChessBoardInterac.getHasCheckByCellPos,
|
|
2848
2861
|
handleSelectFigurePicker = _useChessBoardInterac.handleSelectFigurePicker;
|
|
2849
|
-
|
|
2850
|
-
setPlayerColor(playerColor);
|
|
2851
|
-
}, [playerColor]);
|
|
2852
|
-
useEffect(function () {
|
|
2862
|
+
var handleUpdateFEN = function handleUpdateFEN(FEN) {
|
|
2853
2863
|
var _FENtoGameState = FENtoGameState(FEN),
|
|
2854
2864
|
boardState = _FENtoGameState.boardState,
|
|
2855
2865
|
currentColor = _FENtoGameState.currentColor;
|
|
2856
2866
|
setInitialState(boardState);
|
|
2857
2867
|
setActualState(boardState);
|
|
2858
2868
|
setCurrentColor(currentColor);
|
|
2869
|
+
};
|
|
2870
|
+
useEffect(function () {
|
|
2871
|
+
setPlayerColor(playerColor);
|
|
2872
|
+
}, [playerColor]);
|
|
2873
|
+
useEffect(function () {
|
|
2874
|
+
handleUpdateFEN(FEN);
|
|
2859
2875
|
}, [FEN]);
|
|
2860
2876
|
useEffect(function () {
|
|
2861
2877
|
if (reversed) reverseChessBoard();
|
|
2862
2878
|
}, [reversed]);
|
|
2863
2879
|
useEffect(function () {
|
|
2864
|
-
|
|
2880
|
+
if (!change) return;
|
|
2881
|
+
var updatedChange = _extends({}, change, {
|
|
2882
|
+
move: reversed ? JSChessEngine.reverseMove(change.move) : change.move
|
|
2883
|
+
});
|
|
2884
|
+
if (change.withTransition) {
|
|
2885
|
+
setAnimated(true);
|
|
2886
|
+
setTimeout(function () {
|
|
2887
|
+
setNewMove(updatedChange);
|
|
2888
|
+
}, 10);
|
|
2889
|
+
setTimeout(function () {
|
|
2890
|
+
setAnimated(false);
|
|
2891
|
+
}, 160);
|
|
2892
|
+
setTimeout(function () {
|
|
2893
|
+
handleUpdateFEN(updatedChange.move.FEN);
|
|
2894
|
+
}, 170);
|
|
2895
|
+
} else {
|
|
2896
|
+
setNewMove(updatedChange);
|
|
2897
|
+
handleUpdateFEN(updatedChange.move.FEN);
|
|
2898
|
+
}
|
|
2865
2899
|
}, [change]);
|
|
2866
2900
|
return React.createElement("div", {
|
|
2867
2901
|
className: styles.chessBoard
|
|
@@ -2871,7 +2905,8 @@ var ChessBoard = function ChessBoard(props) {
|
|
|
2871
2905
|
initialState: initialState,
|
|
2872
2906
|
change: newMove,
|
|
2873
2907
|
reversed: reversed,
|
|
2874
|
-
boardConfig: boardConfig
|
|
2908
|
+
boardConfig: boardConfig,
|
|
2909
|
+
animated: animated
|
|
2875
2910
|
}), React.createElement(ChessBoardInteractiveLayout, {
|
|
2876
2911
|
selectedPos: fromPos,
|
|
2877
2912
|
possibleMoves: possibleMoves,
|