Skip to content

Commit

Permalink
Merge pull request #16387 from schlawg/ui-massage-imports
Browse files Browse the repository at this point in the history
import as type and use named imports when possible
  • Loading branch information
ornicar authored Nov 10, 2024
2 parents 9adb6f9 + 28c06d6 commit 082be62
Show file tree
Hide file tree
Showing 451 changed files with 1,785 additions and 1,933 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@typescript-eslint/parser": "^8.13.0",
"ab": "github:lichess-org/ab-stub",
"chessground": "^9.1.1",
"chessops": "^0.14.2",
"eslint": "^9.14.0",
"lint-staged": "^15.2.10",
"onchange": "^7.1.0",
Expand Down
42 changes: 4 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions ui/@types/lichess/chessground.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import * as cg from '../../../node_modules/chessground/dist/types';
declare global {
type CgApi = Api;
type CgConfig = Config;
namespace Cg {
type Role = cg.Role;
type Key = cg.Key;
type FEN = cg.FEN;
}
type Color = cg.Color;
type Role = cg.Role;
type Key = cg.Key;
type FEN = cg.FEN;
type Files = cg.File;
type Ranks = cg.Rank;
type Dests = cg.Dests;
type Piece = cg.Piece;
}
30 changes: 12 additions & 18 deletions ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface EsmModuleOpts extends AssetUrlOpts {
type PairOf<T> = [T, T];

type Flair = string;

type Redraw = () => void;
type RedirectTo = string | { url: string; cookie: Cookie };

interface LichessMousetrap {
Expand Down Expand Up @@ -95,7 +95,6 @@ type SoundMoveOpts = {
};

type SoundMove = (opts?: SoundMoveOpts) => void;

type SoundListener = (event: 'start' | 'stop', text?: string) => void;

interface SoundI {
Expand All @@ -113,7 +112,7 @@ interface SoundI {
speech(v?: boolean): boolean;
changeSet(s: string): void;
say(text: string, cut?: boolean, force?: boolean, translated?: boolean): boolean;
saySan(san?: San, cut?: boolean): void;
saySan(san?: San, cut?: boolean, force?: boolean): void;
sayOrPlay(name: string, text: string): void;
preloadBoardSounds(): void;
url(name: string): string;
Expand Down Expand Up @@ -146,7 +145,7 @@ interface AssetUrlOpts {

type Timeout = ReturnType<typeof setTimeout>;

declare type SocketSend = (type: string, data?: any, opts?: any, noRetry?: boolean) => void;
type SocketSend = (type: string, data?: any, opts?: any, noRetry?: boolean) => void;

interface LichessAnnouncement {
msg?: string;
Expand Down Expand Up @@ -231,7 +230,7 @@ interface Navigator {
deviceMemory?: number; // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/deviceMemory
}

declare type VariantKey =
type VariantKey =
| 'standard'
| 'chess960'
| 'antichess'
Expand All @@ -243,21 +242,16 @@ declare type VariantKey =
| 'racingKings'
| 'crazyhouse';

declare type Speed = 'ultraBullet' | 'bullet' | 'blitz' | 'rapid' | 'classical' | 'correspondence';

declare type Perf = Exclude<VariantKey, 'standard'> | Speed;
type Speed = 'ultraBullet' | 'bullet' | 'blitz' | 'rapid' | 'classical' | 'correspondence';

declare type Color = 'white' | 'black';
type Perf = Exclude<VariantKey, 'standard'> | Speed;

declare type Files = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h';
declare type Ranks = '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8';
declare type Key = 'a0' | `${Files}${Ranks}`;
declare type Uci = string;
declare type San = string;
declare type Ply = number;
declare type Seconds = number;
declare type Centis = number;
declare type Millis = number;
type Uci = string;
type San = string;
type Ply = number;
type Seconds = number;
type Centis = number;
type Millis = number;

interface Variant {
key: VariantKey;
Expand Down
6 changes: 3 additions & 3 deletions ui/@types/lichess/tree.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare namespace Tree {
export type Path = string;

interface ClientEvalBase extends EvalScore {
fen: Cg.FEN;
fen: FEN;
depth: number;
nodes: number;
pvs: PvData[];
Expand All @@ -21,7 +21,7 @@ declare namespace Tree {

export interface ServerEval extends EvalScore {
best?: Uci;
fen: Cg.FEN;
fen: FEN;
knodes: number;
depth: number;
pvs: PvDataServer[];
Expand All @@ -45,7 +45,7 @@ declare namespace Tree {
id: string;
ply: Ply;
uci?: Uci;
fen: Cg.FEN;
fen: FEN;
comments?: Comment[];
gamebook?: Gamebook;
dests?: string;
Expand Down
1 change: 0 additions & 1 deletion ui/analyse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"chart": "workspace:*",
"chat": "workspace:*",
"chess": "workspace:*",
"chessops": "^0.14.2",
"common": "workspace:*",
"debounce-promise": "^3.1.2",
"editor": "workspace:*",
Expand Down
7 changes: 3 additions & 4 deletions ui/analyse/src/autoShape.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { parseUci, makeSquare } from 'chessops/util';
import { isDrop } from 'chessops/types';
import { winningChances } from 'ceval';
import * as cg from 'chessground/types';
import { opposite } from 'chessground/util';
import { DrawModifiers, DrawShape } from 'chessground/draw';
import type { DrawModifiers, DrawShape } from 'chessground/draw';
import { annotationShapes } from 'chess/glyphs';
import AnalyseCtrl from './ctrl';
import type AnalyseCtrl from './ctrl';

const pieceDrop = (key: cg.Key, role: cg.Role, color: Color): DrawShape => ({
const pieceDrop = (key: Key, role: Role, color: Color): DrawShape => ({
orig: key,
piece: {
color,
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/autoplay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AnalyseCtrl from './ctrl';
import type AnalyseCtrl from './ctrl';

export type AutoplayDelay = number | 'realtime' | 'cpl';

Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/boot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnalyseApi, AnalyseOpts } from './interfaces';
import type { AnalyseApi, AnalyseOpts } from './interfaces';
import StrongSocket from 'common/socket';

export default function (start: (opts: AnalyseOpts) => AnalyseApi) {
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/control.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AnalyseCtrl from './ctrl';
import type AnalyseCtrl from './ctrl';

import { path as treePath } from 'tree';

Expand Down
13 changes: 6 additions & 7 deletions ui/analyse/src/crazy/crazyCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { dragNewPiece } from 'chessground/drag';
import { readDrops } from 'chess';
import AnalyseCtrl from '../ctrl';
import * as cg from 'chessground/types';
import { Api as ChessgroundApi } from 'chessground/api';
import type AnalyseCtrl from '../ctrl';
import type { MouchEvent } from 'chessground/types';

export function drag(ctrl: AnalyseCtrl, color: Color, e: cg.MouchEvent): void {
export function drag(ctrl: AnalyseCtrl, color: Color, e: MouchEvent): void {
if (e.button !== undefined && e.button !== 0) return; // only touch or left click
if (ctrl.chessground.state.movable.color !== color) return;
const el = e.target as HTMLElement;
const role = el.getAttribute('data-role') as cg.Role,
const role = el.getAttribute('data-role') as Role,
number = el.getAttribute('data-nb');
if (!role || !color || number === '0') return;
e.stopPropagation();
Expand All @@ -17,9 +16,9 @@ export function drag(ctrl: AnalyseCtrl, color: Color, e: cg.MouchEvent): void {
}

export function valid(
chessground: ChessgroundApi,
chessground: CgApi,
possibleDrops: string | undefined | null,
piece: cg.Piece,
piece: Piece,
pos: Key,
): boolean {
if (piece.color !== chessground.state.movable.color) return false;
Expand Down
4 changes: 2 additions & 2 deletions ui/analyse/src/crazy/crazyView.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { drag } from './crazyCtrl';
import { h } from 'snabbdom';
import { MouchEvent } from 'chessground/types';
import type { MouchEvent } from 'chessground/types';
import { onInsert } from 'common/snabbdom';
import AnalyseCtrl from '../ctrl';
import type AnalyseCtrl from '../ctrl';

const eventNames = ['mousedown', 'touchstart'];
const oKeys = ['pawn', 'knight', 'bishop', 'rook', 'queen'];
Expand Down
Loading

0 comments on commit 082be62

Please sign in to comment.