next-chessground
Version:
React and Next wrapper for Chessground with chessboard and pieces out of the box
142 lines (129 loc) • 4.42 kB
TypeScript
import { ReactNode } from 'react';
// Basic type definitions for chess components
interface ChessgroundConfig {
fen?: string;
orientation?: 'white' | 'black';
turnColor?: 'white' | 'black';
check?: boolean | string;
lastMove?: [string, string];
selected?: string;
coordinates?: boolean;
autoCastle?: boolean;
viewOnly?: boolean;
disableContextMenu?: boolean;
resizable?: boolean;
addPieceZIndex?: boolean;
highlight?: {
lastMove?: boolean;
check?: boolean;
};
animation?: {
enabled?: boolean;
duration?: number;
};
movable?: {
free?: boolean;
color?: 'white' | 'black' | 'both';
showDests?: boolean;
events?: {
after?: (orig: string, dest: string, metadata: any) => void;
afterNewPiece?: (role: string, key: string, metadata: any) => void;
};
rookCastle?: boolean;
};
premovable?: {
enabled?: boolean;
showDests?: boolean;
castle?: boolean;
events?: {
set?: (orig: string, dest: string, metadata: any) => void;
unset?: () => void;
};
};
predroppable?: {
enabled?: boolean;
events?: {
set?: (role: string, key: string) => void;
unset?: () => void;
};
};
draggable?: {
enabled?: boolean;
distance?: number;
autoDistance?: boolean;
showGhost?: boolean;
deleteOnDropOff?: boolean;
};
selectable?: {
enabled?: boolean;
};
drawable?: {
enabled?: boolean;
visible?: boolean;
defaultSnapToValidMove?: boolean;
eraseOnClick?: boolean;
shapes?: any[];
autoShapes?: any[];
brushes?: any;
pieces?: {
baseUrl?: string;
};
};
onChange?: (shapes: any[]) => void;
onMove?: (orig: string, dest: string, capturedPiece?: any) => void;
onDropNewPiece?: (piece: any, key: string) => void;
onSelect?: (key: string) => void;
items?: any;
shapes?: any[];
}
interface NextChessgroundProps extends ChessgroundConfig {
width?: string | number;
height?: string | number;
style?: React.CSSProperties;
}
interface Theme {
board: string;
pieces: string;
playSounds: boolean;
sounds: string;
highlight: boolean;
coordinates: boolean;
}
interface ThemeContextType {
theme: Theme;
setTheme: (theme: Theme | ((prev: Theme) => Theme)) => void;
}
// Component declarations
declare const NextChessground: React.ForwardRefExoticComponent<NextChessgroundProps & React.RefAttributes<any>>;
declare const NextEditor: React.ForwardRefExoticComponent<NextChessgroundProps & React.RefAttributes<any>>;
// Hook declarations
declare function useChess(): any;
declare function useChessground(): ThemeContextType;
// Context declarations
declare const ChessProvider: React.ComponentType<{ children: ReactNode }>;
declare function useChessContext(): any;
declare const DrillProvider: React.ComponentType<{ children: ReactNode }>;
declare function useDrillContext(): any;
declare const PuzzleProvider: React.ComponentType<{ children: ReactNode }>;
declare function usePuzzleContext(): any;
// Utility declarations
declare const constants: any;
declare const Stockfish: any;
declare function isValidFen(fen: string): boolean;
// Function declarations
declare function getNextMoment(...args: any[]): any;
declare function checkDrillMove(...args: any[]): any;
declare function getNextShape(...args: any[]): any;
declare function parseFen(fen: string): any;
declare function extractFen(...args: any[]): any;
declare function getMoveNumber(...args: any[]): any;
declare function isMoveActive(...args: any[]): any;
declare function showMoveIndex(...args: any[]): any;
declare function getMoveSuffix(...args: any[]): any;
declare function compareMoves(...args: any[]): any;
declare function goodMove(...args: any[]): any;
declare function badMove(...args: any[]): any;
declare function replyMove(...args: any[]): any;
declare function wasSolved(...args: any[]): any;
declare function getMoveArrow(...args: any[]): any;
export { ChessProvider, ChessgroundConfig, DrillProvider, NextChessground, NextChessgroundProps, NextEditor, PuzzleProvider, Stockfish, Theme, ThemeContextType, badMove, checkDrillMove, compareMoves, constants, NextChessground as default, extractFen, getMoveArrow, getMoveNumber, getMoveSuffix, getNextMoment, getNextShape, goodMove, isMoveActive, isValidFen, parseFen, replyMove, showMoveIndex, useChess, useChessContext, useChessground, useDrillContext, usePuzzleContext, wasSolved };