react-chessboard-ui 1.4.4 → 1.4.6
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/utils.d.ts +15 -0
- package/dist/index.js +64 -8
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +64 -8
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
|
@@ -58,3 +58,18 @@ export declare const correctGrabbingPosByScroll: (pos: CellPos) => CellPos;
|
|
|
58
58
|
* Корректирует указатели стрелки
|
|
59
59
|
*/
|
|
60
60
|
export declare const correctGrabbingPosForArrow: (pos: CellPos, boardConfig: ChessBoardConfig) => CellPos;
|
|
61
|
+
/**
|
|
62
|
+
* Создание тэга для хранение состояния
|
|
63
|
+
* разворота доски
|
|
64
|
+
*
|
|
65
|
+
* На момент создания, есть проблема с заданием
|
|
66
|
+
* разворота доски для слоя фигур - происходит двойной
|
|
67
|
+
* рендер. Из-за этого доска возврщает в тоже положение
|
|
68
|
+
* при reversed = true, но состояние игры разворачивается
|
|
69
|
+
*
|
|
70
|
+
* Поэтому принято решение вынести хранение и задание
|
|
71
|
+
* разворота доски на уровень data-атрибутов html
|
|
72
|
+
*/
|
|
73
|
+
export declare const createHtmlReversedStateHolder: () => void;
|
|
74
|
+
export declare const setHtmlReversedStateHolderValue: (reversed: boolean) => void;
|
|
75
|
+
export declare const getHtmlReversedStateHolderValue: () => boolean;
|
package/dist/index.js
CHANGED
|
@@ -2012,6 +2012,22 @@ var correctGrabbingPosByScroll = function correctGrabbingPosByScroll(pos) {
|
|
|
2012
2012
|
var correctGrabbingPosForArrow = function correctGrabbingPosForArrow(pos, boardConfig) {
|
|
2013
2013
|
return [pos[0] * boardConfig.cellSize + (boardConfig.cellSize / 2 - 10), pos[1] * boardConfig.cellSize + boardConfig.cellSize / 2];
|
|
2014
2014
|
};
|
|
2015
|
+
var createHtmlReversedStateHolder = function createHtmlReversedStateHolder() {
|
|
2016
|
+
if (!window) return;
|
|
2017
|
+
var reversedStateHolder = document.createElement('div');
|
|
2018
|
+
reversedStateHolder.setAttribute('id', 'reversed-state-holder');
|
|
2019
|
+
reversedStateHolder.setAttribute('data-reversed-state', 'false');
|
|
2020
|
+
document.body.append(reversedStateHolder);
|
|
2021
|
+
};
|
|
2022
|
+
var setHtmlReversedStateHolderValue = function setHtmlReversedStateHolderValue(reversed) {
|
|
2023
|
+
if (!window) return;
|
|
2024
|
+
document.getElementById('reversed-state-holder').setAttribute('data-reversed-state', JSON.stringify(reversed));
|
|
2025
|
+
};
|
|
2026
|
+
var getHtmlReversedStateHolderValue = function getHtmlReversedStateHolderValue() {
|
|
2027
|
+
if (!window) return false;
|
|
2028
|
+
var chessboardReversed = document.getElementById('reversed-state-holder') && document.getElementById('reversed-state-holder').getAttribute('data-reversed-state') === 'true';
|
|
2029
|
+
return chessboardReversed;
|
|
2030
|
+
};
|
|
2015
2031
|
|
|
2016
2032
|
var BASE_BOARD_SIZE = 8;
|
|
2017
2033
|
var ChessBoardCellsLayout = function ChessBoardCellsLayout(_ref) {
|
|
@@ -2048,6 +2064,7 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
|
|
|
2048
2064
|
setActualState(mapCellsToFiguresArray(initialState));
|
|
2049
2065
|
}, [initialState]);
|
|
2050
2066
|
React.useEffect(function () {
|
|
2067
|
+
var chessboardReversed = getHtmlReversedStateHolderValue();
|
|
2051
2068
|
if (!!change) {
|
|
2052
2069
|
setActualState(function (prevState) {
|
|
2053
2070
|
var updatedState = [].concat(prevState);
|
|
@@ -2061,11 +2078,28 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
|
|
|
2061
2078
|
var kingIndex = updatedState.findIndex(function (figure) {
|
|
2062
2079
|
return figure.color === 'white' && figure.type === 'king';
|
|
2063
2080
|
});
|
|
2081
|
+
if (chessboardReversed) {
|
|
2082
|
+
if (castlingType === '0-0') {
|
|
2083
|
+
var _rookIndex = updatedState.findIndex(function (figure) {
|
|
2084
|
+
return figure.color === color && figure.type === 'rook' && figure.position[0] === 7;
|
|
2085
|
+
});
|
|
2086
|
+
updatedState[_rookIndex].position[0] = 4;
|
|
2087
|
+
updatedState[kingIndex].position[0] = 5;
|
|
2088
|
+
return updatedState;
|
|
2089
|
+
}
|
|
2090
|
+
var _rookIndex2 = updatedState.findIndex(function (figure) {
|
|
2091
|
+
return figure.color === color && figure.type === 'rook' && figure.position[0] === 0;
|
|
2092
|
+
});
|
|
2093
|
+
console.log('WHITE', _rookIndex2);
|
|
2094
|
+
updatedState[_rookIndex2].position[0] = 2;
|
|
2095
|
+
updatedState[kingIndex].position[0] = 1;
|
|
2096
|
+
return updatedState;
|
|
2097
|
+
}
|
|
2064
2098
|
if (castlingType === '0-0') {
|
|
2065
|
-
var
|
|
2099
|
+
var _rookIndex3 = updatedState.findIndex(function (figure) {
|
|
2066
2100
|
return figure.color === color && figure.type === 'rook' && figure.position[0] === 7;
|
|
2067
2101
|
});
|
|
2068
|
-
updatedState[
|
|
2102
|
+
updatedState[_rookIndex3].position[0] = 5;
|
|
2069
2103
|
updatedState[kingIndex].position[0] = 6;
|
|
2070
2104
|
return updatedState;
|
|
2071
2105
|
}
|
|
@@ -2080,18 +2114,34 @@ var ChessBoardFiguresLayout = function ChessBoardFiguresLayout(props) {
|
|
|
2080
2114
|
var _kingIndex = updatedState.findIndex(function (figure) {
|
|
2081
2115
|
return figure.color === 'black' && figure.type === 'king';
|
|
2082
2116
|
});
|
|
2117
|
+
if (chessboardReversed) {
|
|
2118
|
+
if (castlingType === '0-0') {
|
|
2119
|
+
var _rookIndex4 = updatedState.findIndex(function (figure) {
|
|
2120
|
+
return figure.color === color && figure.type === 'rook' && figure.position[0] === 7;
|
|
2121
|
+
});
|
|
2122
|
+
updatedState[_rookIndex4].position[0] = 4;
|
|
2123
|
+
updatedState[_kingIndex].position[0] = 5;
|
|
2124
|
+
return updatedState;
|
|
2125
|
+
}
|
|
2126
|
+
var _rookIndex5 = updatedState.findIndex(function (figure) {
|
|
2127
|
+
return figure.color === color && figure.type === 'rook' && figure.position[0] === 0;
|
|
2128
|
+
});
|
|
2129
|
+
updatedState[_rookIndex5].position[0] = 2;
|
|
2130
|
+
updatedState[_kingIndex].position[0] = 1;
|
|
2131
|
+
return updatedState;
|
|
2132
|
+
}
|
|
2083
2133
|
if (castlingType === '0-0') {
|
|
2084
|
-
var
|
|
2134
|
+
var _rookIndex6 = updatedState.findIndex(function (figure) {
|
|
2085
2135
|
return figure.color === color && figure.type === 'rook' && figure.position[0] === 7;
|
|
2086
2136
|
});
|
|
2087
|
-
updatedState[
|
|
2137
|
+
updatedState[_rookIndex6].position[0] = 5;
|
|
2088
2138
|
updatedState[_kingIndex].position[0] = 6;
|
|
2089
2139
|
return updatedState;
|
|
2090
2140
|
}
|
|
2091
|
-
var
|
|
2141
|
+
var _rookIndex7 = updatedState.findIndex(function (figure) {
|
|
2092
2142
|
return figure.color === color && figure.type === 'rook' && figure.position[0] === 0;
|
|
2093
2143
|
});
|
|
2094
|
-
updatedState[
|
|
2144
|
+
updatedState[_rookIndex7].position[0] = 3;
|
|
2095
2145
|
updatedState[_kingIndex].position[0] = 2;
|
|
2096
2146
|
return updatedState;
|
|
2097
2147
|
}
|
|
@@ -2431,7 +2481,8 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2431
2481
|
return {};
|
|
2432
2482
|
}
|
|
2433
2483
|
var colorFEN = currentColor === 'white' ? 'black' : 'white';
|
|
2434
|
-
var
|
|
2484
|
+
var reversedUpdatedCells = boardReversed ? JSChessEngine.reverseChessBoard(updatedCells) : updatedCells;
|
|
2485
|
+
var FEN = stateToFEN(reversedUpdatedCells, colorFEN);
|
|
2435
2486
|
var moveData = {
|
|
2436
2487
|
figure: figure,
|
|
2437
2488
|
from: from,
|
|
@@ -2486,7 +2537,8 @@ var useChessBoardInteractive = function useChessBoardInteractive(props) {
|
|
|
2486
2537
|
return {};
|
|
2487
2538
|
}
|
|
2488
2539
|
var colorFEN = currentColor === 'white' ? 'black' : 'white';
|
|
2489
|
-
var
|
|
2540
|
+
var reversedUpdatedCells = boardReversed ? JSChessEngine.reverseChessBoard(updatedCells) : updatedCells;
|
|
2541
|
+
var FEN = stateToFEN(reversedUpdatedCells, colorFEN);
|
|
2490
2542
|
var moveData = {
|
|
2491
2543
|
figure: figure,
|
|
2492
2544
|
from: from,
|
|
@@ -2946,11 +2998,15 @@ var ChessBoard = function ChessBoard(props) {
|
|
|
2946
2998
|
setCurrentColor(currentColor);
|
|
2947
2999
|
setBoardReversed(reversed);
|
|
2948
3000
|
};
|
|
3001
|
+
React.useEffect(function () {
|
|
3002
|
+
createHtmlReversedStateHolder();
|
|
3003
|
+
}, []);
|
|
2949
3004
|
React.useEffect(function () {
|
|
2950
3005
|
setPlayerColor(playerColor);
|
|
2951
3006
|
}, [playerColor]);
|
|
2952
3007
|
React.useEffect(function () {
|
|
2953
3008
|
handleUpdateFEN(FEN, reversed);
|
|
3009
|
+
setHtmlReversedStateHolderValue(reversed);
|
|
2954
3010
|
}, [FEN, reversed]);
|
|
2955
3011
|
React.useEffect(function () {
|
|
2956
3012
|
if (!change) return;
|