Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,796 changes: 2,191 additions & 605 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@
"dev": "vite",
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.app.json && ./format.sh",
"preview": "vite preview",
"prepare": "npm run build",
"test": "vitest --environment jsdom --root src/",
"build-only": "vite build",
"format": "prettier --write src/",
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --ignore-path .eslintignore"
},
"dependencies": {
"chess.js": "^1.0.0-beta.6",
"chessground": "^9.0.2"
"@lichess-org/chessground": "^9.9.0",
"chess.js": "^1.2.0"
},
"peerDependencies": {
"vue": "^3.2.47"
Expand All @@ -64,7 +65,7 @@
"@vitejs/plugin-vue": "^4.0.0",
"@vue/eslint-config-prettier": "^7.0.0",
"@vue/eslint-config-typescript": "^11.0.0",
"@vue/test-utils": "^2.1.0",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.1.3",
"eslint": "^8.34.0",
"eslint-plugin-vue": "^9.9.0",
Expand All @@ -73,7 +74,7 @@
"prettier": "^2.8.3",
"typescript": "^5.0.2",
"vite": "^4.0.4",
"vitest": "^0.29.1",
"vitest": "^3.0.5",
"vue-tsc": "^1.1.3"
},
"prettier": {
Expand Down
14 changes: 7 additions & 7 deletions src/classes/BoardApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {
type Color as ShortColor,
type Square,
} from 'chess.js';
import type { Api } from 'chessground/api';
import { Chessground } from 'chessground/chessground';
import type { Color, Key, MoveMetadata, Role } from 'chessground/types';
import type { Api } from '@lichess-org/chessground/api';
import { Chessground } from '@lichess-org/chessground/chessground';
import type { Color, Key, MoveMetadata, Role } from '@lichess-org/chessground/types';
import { nextTick } from 'vue';

/**
Expand Down Expand Up @@ -143,7 +143,7 @@ export class BoardApi {
_: MoveMetadata
): Promise<void> {
let selectedPromotion: Promotion | undefined = undefined;
if (isPromotion(dest, this.game.get(orig as Square))) {
if (isPromotion(dest, this.game.get(orig as Square) ?? null)) {
selectedPromotion = await new Promise((resolve) => {
this.boardState.promotionDialogState = {
isEnabled: true,
Expand Down Expand Up @@ -513,7 +513,7 @@ export class BoardApi {
* Returns the piece on the square or null if there is no piece
*/
getSquare(square: Square): Piece | null {
return this.game.get(square);
return this.game.get(square) ?? null;
}

/**
Expand Down Expand Up @@ -607,7 +607,7 @@ export class BoardApi {
* }
*/
getPgnInfo(): {
[key: string]: string | undefined;
[key: string]: string | null;
} {
return this.game.header();
}
Expand All @@ -618,7 +618,7 @@ export class BoardApi {
* @param changes a record of key value pairs to change in the PGN, eg. `{ White: 'Deep Blue', Black: 'Kasparov, Garry' }`
*/
setPgnInfo(changes: { [key: string]: string }): {
[key: string]: string | undefined;
[key: string]: string | null;
} {
return this.game.header(...Object.entries(changes).flat());
}
Expand Down
2 changes: 1 addition & 1 deletion src/helper/Board.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SQUARES, type Chess, type Move, type Piece } from 'chess.js';
import type { Color, Key } from 'chessground/types';
import type { Color, Key } from '@lichess-org/chessground/types';
import type { Threat } from '@/typings/Chessboard';

export function getThreats(moves: Move[]): Threat[] {
Expand Down
2 changes: 1 addition & 1 deletion src/helper/DefaultConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Key } from 'chessground/types';
import type { Key } from '@lichess-org/chessground/types';
import type { BoardConfig } from '@/typings/BoardConfig';

export const possibleMovesWhite: Map<Key, Key[]> = new Map([
Expand Down
8 changes: 4 additions & 4 deletions src/tests/BoardApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { initialPos } from '@/helper/DefaultConfig';
import { beforeEach, describe, expect, it } from 'vitest';
import { makeStalemate, mountComponent, resetBoard } from './helper/Helper';

describe.concurrent('Test the board API', () => {
describe.sequential('Test the board API', () => {
const wrapper = mountComponent();
const boardApi = wrapper.emitted<BoardApi[]>('boardCreated')?.[0][0];
if (typeof boardApi === 'undefined') {
Expand Down Expand Up @@ -170,15 +170,15 @@ describe.concurrent('Test the board API', () => {
expect(boardApi.getFen()).toBe(
'rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2'
);
expect(boardApi?.getPgn()).toBe(pgn);
expect(boardApi?.getPgn()).toContain(pgn);
expect(boardApi.getTurnColor()).toBe('white');
expect(boardApi.getCurrentTurnNumber()).toBe(2);
});

it('should return the last move', () => {
expect(boardApi.getLastMove()).toBe(undefined);
boardApi.move('e4');
expect(boardApi.getLastMove()).toStrictEqual({
expect(boardApi.getLastMove()).toEqual({
color: 'w',
piece: 'p',
from: 'e2',
Expand All @@ -190,7 +190,7 @@ describe.concurrent('Test the board API', () => {
after: 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1',
});
boardApi.move('e5');
expect(boardApi.getLastMove()).toStrictEqual({
expect(boardApi.getLastMove()).toEqual({
color: 'b',
piece: 'p',
from: 'e7',
Expand Down
2 changes: 1 addition & 1 deletion src/tests/BoardEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, it, describe, beforeEach } from 'vitest';
import { makeStalemate, mountComponent, resetBoard } from './helper/Helper';
import { moves } from './helper/Constants';

describe.concurrent('Test the board events', () => {
describe.sequential('Test the board events', () => {
const wrapper = mountComponent();
const boardApi = wrapper.emitted<BoardApi[]>('boardCreated')?.[0][0];
if (typeof boardApi === 'undefined') {
Expand Down
Loading