diff --git a/package/README.md b/package/README.md index eb5e858..1ed0428 100644 --- a/package/README.md +++ b/package/README.md @@ -164,7 +164,7 @@ For more advanced code usage examples, please see example boards shown in [`exam | onPieceClick | function: (piece) => {} | | User function that is run when piece is clicked. | | onPieceDragBegin | function: (piece, sourceSquare) => {} | | User function that is run when piece is grabbed to start dragging. | | onPieceDragEnd | function: (piece, sourceSquare) => {} | | User function that is run when piece is let go after dragging. | -| onPieceDrop | function: (sourceSquare, targetSquare, piece) => true | returns [true, false] | User function that is run when piece is dropped on a square. Must return whether the move was successful or not. | +| onPieceDrop | function: (sourceSquare, targetSquare, piece) => true | returns [true, false] | User function that is run when piece is dropped on a square. Must return whether the move was successful or not. This return value does not control whether or not the piece was placed (as that is controlled by the `position` prop) but instead controls premove logic. | | onSquareClick | function: (square) => {} | | User function that is run when a square is clicked. | | onSquareRightClick | function: (square) => {} | | User function that is run when a square is right clicked. | | position | string: 'start' | ['start', FEN string, { e5: 'wK', e4: 'wP', ... }] | FEN string or position object notating where the chess pieces are on the board. Start position can also be notated with the string: 'start'. | diff --git a/package/dist/index.d.ts b/package/dist/index.d.ts index f7bf401..69b44e6 100644 --- a/package/dist/index.d.ts +++ b/package/dist/index.d.ts @@ -1,7 +1,7 @@ import { ReactElement, CSSProperties, RefObject } from 'react'; import { BackendFactory } from 'dnd-core'; -export type Square = +type Square = | 'a8' | 'b8' | 'c8' @@ -67,9 +67,9 @@ export type Square = | 'g1' | 'h1'; -export type Pieces = 'wP' | 'wB' | 'wN' | 'wR' | 'wQ' | 'wK' | 'bP' | 'bB' | 'bN' | 'bR' | 'bQ' | 'bK'; +type Pieces = 'wP' | 'wB' | 'wN' | 'wR' | 'wQ' | 'wK' | 'bP' | 'bB' | 'bN' | 'bR' | 'bQ' | 'bK'; -export interface CustomPieceFnArgs { +interface CustomPieceFnArgs { isDragging: boolean; squareWidth: number; droppedPiece: Pieces; @@ -77,13 +77,13 @@ export interface CustomPieceFnArgs { sourceSquare: Square; } -export type CustomPieceFn = (args: CustomPieceFnArgs) => ReactElement; +type CustomPieceFn = (args: CustomPieceFnArgs) => ReactElement; -export type CustomPieces = { +type CustomPieces = { [key in Pieces]?: CustomPieceFn; }; -export type CustomSquareStyles = { +type CustomSquareStyles = { [key in Square]?: CSSProperties; }; @@ -91,7 +91,7 @@ type CurrentPosition = { [key in Square]: Pieces; }; -export interface ChessBoardProps { +interface ChessBoardProps { /** * Time in milliseconds for piece to slide to target square. Only used when the position is programmatically changed. If a new position is set before the animation is complete, the board will cancel the current animation and snap to the new position. */ @@ -235,4 +235,4 @@ export interface ChessBoardProps { } declare function Chessboard(props: ChessBoardProps): ReactElement; -export { Chessboard }; +export { ChessBoardProps, Chessboard, CurrentPosition, CustomPieceFn, CustomPieceFnArgs, CustomPieces, CustomSquareStyles, Pieces, Square }; diff --git a/package/package-lock.json b/package/package-lock.json index faee8ec..6a78858 100644 --- a/package/package-lock.json +++ b/package/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-chessboard", - "version": "1.2.2", + "version": "1.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package/package.json b/package/package.json index 848b4da..d426aea 100644 --- a/package/package.json +++ b/package/package.json @@ -1,6 +1,6 @@ { "name": "react-chessboard", - "version": "1.2.2", + "version": "1.2.3", "repository": "https://github.com/Clariity/react-chessboard", "author": "Ryan Gregory ", "license": "MIT", diff --git a/package/src/types/index.d.ts b/package/src/types/index.d.ts index 67015cf..9fb19c1 100644 --- a/package/src/types/index.d.ts +++ b/package/src/types/index.d.ts @@ -1,8 +1,75 @@ import { CSSProperties, ReactElement, RefObject } from 'react'; import { BackendFactory } from 'dnd-core'; -import { Pieces, Square } from './options'; -interface CustomPieceFnArgs { +export type Square = + | 'a8' + | 'b8' + | 'c8' + | 'd8' + | 'e8' + | 'f8' + | 'g8' + | 'h8' + | 'a7' + | 'b7' + | 'c7' + | 'd7' + | 'e7' + | 'f7' + | 'g7' + | 'h7' + | 'a6' + | 'b6' + | 'c6' + | 'd6' + | 'e6' + | 'f6' + | 'g6' + | 'h6' + | 'a5' + | 'b5' + | 'c5' + | 'd5' + | 'e5' + | 'f5' + | 'g5' + | 'h5' + | 'a4' + | 'b4' + | 'c4' + | 'd4' + | 'e4' + | 'f4' + | 'g4' + | 'h4' + | 'a3' + | 'b3' + | 'c3' + | 'd3' + | 'e3' + | 'f3' + | 'g3' + | 'h3' + | 'a2' + | 'b2' + | 'c2' + | 'd2' + | 'e2' + | 'f2' + | 'g2' + | 'h2' + | 'a1' + | 'b1' + | 'c1' + | 'd1' + | 'e1' + | 'f1' + | 'g1' + | 'h1'; + +export type Pieces = 'wP' | 'wB' | 'wN' | 'wR' | 'wQ' | 'wK' | 'bP' | 'bB' | 'bN' | 'bR' | 'bQ' | 'bK'; + +export interface CustomPieceFnArgs { isDragging: boolean; squareWidth: number; droppedPiece: Pieces; @@ -10,21 +77,21 @@ interface CustomPieceFnArgs { sourceSquare: Square; } -type CustomPieceFn = (args: CustomPieceFnArgs) => ReactElement; +export type CustomPieceFn = (args: CustomPieceFnArgs) => ReactElement; -type CustomPieces = { +export type CustomPieces = { [key in Pieces]?: CustomPieceFn; }; -type CustomSquareStyles = { +export type CustomSquareStyles = { [key in Square]?: CSSProperties; }; -type CurrentPosition = { +export type CurrentPosition = { [key in Square]: Pieces; }; -interface ChessBoardProps { +export interface ChessBoardProps { /** * Time in milliseconds for piece to slide to target square. Only used when the position is programmatically changed. If a new position is set before the animation is complete, the board will cancel the current animation and snap to the new position. */ diff --git a/package/src/types/options.d.ts b/package/src/types/options.d.ts deleted file mode 100644 index ada0c59..0000000 --- a/package/src/types/options.d.ts +++ /dev/null @@ -1,67 +0,0 @@ -export type Square = - | 'a8' - | 'b8' - | 'c8' - | 'd8' - | 'e8' - | 'f8' - | 'g8' - | 'h8' - | 'a7' - | 'b7' - | 'c7' - | 'd7' - | 'e7' - | 'f7' - | 'g7' - | 'h7' - | 'a6' - | 'b6' - | 'c6' - | 'd6' - | 'e6' - | 'f6' - | 'g6' - | 'h6' - | 'a5' - | 'b5' - | 'c5' - | 'd5' - | 'e5' - | 'f5' - | 'g5' - | 'h5' - | 'a4' - | 'b4' - | 'c4' - | 'd4' - | 'e4' - | 'f4' - | 'g4' - | 'h4' - | 'a3' - | 'b3' - | 'c3' - | 'd3' - | 'e3' - | 'f3' - | 'g3' - | 'h3' - | 'a2' - | 'b2' - | 'c2' - | 'd2' - | 'e2' - | 'f2' - | 'g2' - | 'h2' - | 'a1' - | 'b1' - | 'c1' - | 'd1' - | 'e1' - | 'f1' - | 'g1' - | 'h1'; - -export type Pieces = 'wP' | 'wB' | 'wN' | 'wR' | 'wQ' | 'wK' | 'bP' | 'bB' | 'bN' | 'bR' | 'bQ' | 'bK';